1 package FS::part_event::Condition::cust_birthdate;
2 use base qw( FS::part_event::Condition );
9 FS::part_event::Condition::cust_birthdate
13 Billing event triggered by the time until the customer's next
14 birthday (cust_main.birthdate)
19 'Customer birthday is within time window after billing date';
25 label => 'Time window after bill date',
33 my( $self, $object, %opt ) = @_;
34 my $cust_main = $self->cust_main($object);
36 my $birthdate = $cust_main->birthdate || return 0;
39 if ( $self->option('timeframe') =~ /(\d+)([mwdh])/ ) {
40 my $k = {qw|m months w weeks d days h hours|}->{$2};
41 $timeframe{ $k } = $1;
43 die "Unparsable timeframe given: ".$self->option('timeframe');
46 my $ck_dt = DateTime->from_epoch( epoch => $opt{time} )
47 ->truncate( to => 'day' );
48 my $bd_dt = DateTime->from_epoch( epoch => $birthdate )
49 ->truncate( to => 'day' );
51 # Find the birthday for this calendar year. If customer birthday
52 # has already passed this year, find the birthday for next year.
53 my $next_bd_dt = DateTime->new(
54 month => $bd_dt->month,
58 $next_bd_dt->add( years => 1 )
59 if DateTime->compare( $next_bd_dt, $ck_dt ) == -1;
61 # Does next birthday occur between now and specified duration?
62 $ck_dt->add( %timeframe );
63 DateTime->compare( $next_bd_dt, $ck_dt ) != 1 ? 1 : 0;