X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition.pm;h=9155a7d42ddbcf44cbf6bc5bd7be632a81c99dd7;hb=b286341305ba302c4a555aeef288f84c7141ccdd;hp=2b71fbb77cad560e7f01b98219a5a36a49c7d589;hpb=c648976f0b7975f2328ebd7ba8c711fad0ca4195;p=freeside.git diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm index 2b71fbb77..9155a7d42 100644 --- a/FS/FS/part_event/Condition.pm +++ b/FS/FS/part_event/Condition.pm @@ -2,7 +2,7 @@ package FS::part_event::Condition; use strict; use base qw( FS::part_event_condition ); - +use Time::Local qw(timelocal_nocheck); use FS::UID qw( driver_name ); =head1 NAME @@ -41,6 +41,7 @@ of eventtables (values set true indicate the condition can be tested): 'cust_bill' => 1, 'cust_pkg' => 0, 'cust_pay_batch' => 0, + 'cust_statement' => 0, }; } @@ -52,6 +53,7 @@ sub eventtable_hashref { 'cust_bill' => 1, 'cust_pkg' => 1, 'cust_pay_batch' => 1, + 'cust_statement' => 1, }; } @@ -251,6 +253,40 @@ sub option_label { =back +=item option_age_from OPTION FROM_TIMESTAMP + +Retreives a condition option, parses it from a frequency (such as "1d", "1w" or +"12m"), and subtracts that interval from the supplied timestamp. It is +primarily intended for use in B. + +=cut + +sub option_age_from { + my( $self, $option, $time ) = @_; + my $age = $self->option($option); + $age = '0m' unless length($age); + + my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($time) )[0,1,2,3,4,5]; + + if ( $age =~ /^(\d+)m$/i ) { + $mon -= $1; + until ( $mon >= 0 ) { $mon += 12; $year--; } + } elsif ( $age =~ /^(\d+)y$/i ) { + $year -= $1; + } elsif ( $age =~ /^(\d+)w$/i ) { + $mday -= $1 * 7; + } elsif ( $age =~ /^(\d+)d$/i ) { + $mday -= $1; + } elsif ( $age =~ /^(\d+)h$/i ) { + $hour -= $hour; + } else { + die "unparsable age: $age"; + } + + timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year); + +} + =item condition_sql_option OPTION This is a class method that returns an SQL fragment for retreiving a condition @@ -270,6 +306,28 @@ sub condition_sql_option { )"; } +#c.f. part_event_condition_option.pm / part_event_condition_option_option +#used for part_event/Condition/payby.pm +sub condition_sql_option_option { + my( $class, $option ) = @_; + + ( my $condname = $class ) =~ s/^.*:://; + + my $optionnum = + "( SELECT optionnum FROM part_event_condition_option + WHERE part_event_condition_option.eventconditionnum = + cond_$condname.eventconditionnum + AND part_event_condition_option.optionname = '$option' + AND part_event_condition_option.optionvalue = 'HASH' + )"; + + "( SELECT optionname FROM part_event_condition_option_option + WHERE optionnum = $optionnum + )"; + +} + + =item condition_sql_option_age_from OPTION FROM_TIMESTAMP This is a class method that returns an SQL fragment that will retreive a @@ -399,6 +457,18 @@ sub age2seconds_sql { } +=item condition_sql_option_integer + +As I, but cast the option value to an integer so that +comparison to other integers is type-correct. + +=cut + +sub condition_sql_option_integer { + my ($class, $option) = @_; + 'CAST ('.$class->condition_sql_option($option).' AS INTEGER)'; +} + =head1 NEW CONDITION CLASSES A module should be added in FS/FS/part_event/Condition/ which implements the