[freeside-commits] branch FREESIDE_3_BRANCH updated. bb9e4d6e36cd509a307dbed69b2d3cee3078da17

Mitch Jackson mitch at freeside.biz
Wed Nov 28 16:35:15 PST 2018


The branch, FREESIDE_3_BRANCH has been updated
       via  bb9e4d6e36cd509a307dbed69b2d3cee3078da17 (commit)
       via  d60447e139ed0a8a9f026738d1b844f072673cff (commit)
       via  c5c306eb37fc18e5603074c1523623cad1887efb (commit)
      from  bbb719819a8fbf5ac15be88df56a783d22c1d24d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bb9e4d6e36cd509a307dbed69b2d3cee3078da17
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Wed Nov 28 19:31:41 2018 -0500

    RT# 32238 Billing Event cust_birthdate - Cleaner date compare window

diff --git a/FS/FS/part_event/Condition/cust_birthdate.pm b/FS/FS/part_event/Condition/cust_birthdate.pm
index 56ce857cf..e8ecb061a 100644
--- a/FS/FS/part_event/Condition/cust_birthdate.pm
+++ b/FS/FS/part_event/Condition/cust_birthdate.pm
@@ -43,8 +43,10 @@ sub condition {
     die "Unparsable timeframe given: ".$self->option('timeframe');
   }
 
-  my $ck_dt = DateTime->from_epoch( epoch => $opt{time} );
-  my $bd_dt = DateTime->from_epoch( epoch => $birthdate );
+  my $ck_dt = DateTime->from_epoch( epoch => $opt{time} )
+                      ->truncate( to => 'day' );
+  my $bd_dt = DateTime->from_epoch( epoch => $birthdate )
+                      ->truncate( to => 'day' );
 
   # Find the birthday for this calendar year.  If customer birthday
   # has already passed this year, find the birthday for next year.

commit d60447e139ed0a8a9f026738d1b844f072673cff
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Wed Nov 28 18:36:33 2018 -0500

    RT# 32238 Billing Event cust_birthdate - Amended labels

diff --git a/FS/FS/part_event/Condition/cust_birthdate.pm b/FS/FS/part_event/Condition/cust_birthdate.pm
index 874e3acd0..56ce857cf 100644
--- a/FS/FS/part_event/Condition/cust_birthdate.pm
+++ b/FS/FS/part_event/Condition/cust_birthdate.pm
@@ -16,13 +16,13 @@ birthday (cust_main.birthdate)
 =cut
 
 sub description {
-  'Customer birthdate occurs within the given timeframe';
+  'Customer birthday is within time window after billing date';
 }
 
 sub option_fields {
   (
     timeframe => {
-      label => 'Timeframe',
+      label => 'Time window after bill date',
       type   => 'freq',
       value  => '1m',
     }

commit c5c306eb37fc18e5603074c1523623cad1887efb
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Fri Jun 29 22:00:00 2018 -0500

    RT# 32238 Billing Event cust_birthdate

diff --git a/FS/FS/part_event/Condition/cust_birthdate.pm b/FS/FS/part_event/Condition/cust_birthdate.pm
new file mode 100644
index 000000000..874e3acd0
--- /dev/null
+++ b/FS/FS/part_event/Condition/cust_birthdate.pm
@@ -0,0 +1,64 @@
+package FS::part_event::Condition::cust_birthdate;
+use base qw( FS::part_event::Condition );
+use strict;
+use warnings;
+use DateTime;
+
+=head2 NAME
+
+FS::part_event::Condition::cust_birthdate
+
+=head1 DESCRIPTION
+
+Billing event triggered by the time until the customer's next
+birthday (cust_main.birthdate)
+
+=cut
+
+sub description {
+  'Customer birthdate occurs within the given timeframe';
+}
+
+sub option_fields {
+  (
+    timeframe => {
+      label => 'Timeframe',
+      type   => 'freq',
+      value  => '1m',
+    }
+  );
+}
+
+sub condition {
+  my( $self, $object, %opt ) = @_;
+  my $cust_main = $self->cust_main($object);
+
+  my $birthdate = $cust_main->birthdate || return 0;
+
+  my %timeframe;
+  if ( $self->option('timeframe') =~ /(\d+)([mwdh])/ ) {
+    my $k = {qw|m months w weeks d days h hours|}->{$2};
+    $timeframe{ $k } = $1;
+  } else {
+    die "Unparsable timeframe given: ".$self->option('timeframe');
+  }
+
+  my $ck_dt = DateTime->from_epoch( epoch => $opt{time} );
+  my $bd_dt = DateTime->from_epoch( epoch => $birthdate );
+
+  # Find the birthday for this calendar year.  If customer birthday
+  # has already passed this year, find the birthday for next year.
+  my $next_bd_dt = DateTime->new(
+    month => $bd_dt->month,
+    day   => $bd_dt->day,
+    year  => $ck_dt->year,
+  );
+  $next_bd_dt->add( years => 1 )
+    if DateTime->compare( $next_bd_dt, $ck_dt ) == -1;
+
+  # Does next birthday occur between now and specified duration?
+  $ck_dt->add( %timeframe );
+  DateTime->compare( $next_bd_dt, $ck_dt ) != 1 ? 1 : 0;
+}
+
+1;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event/Condition/cust_birthdate.pm | 66 ++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 FS/FS/part_event/Condition/cust_birthdate.pm




More information about the freeside-commits mailing list