X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition.pm;h=d1d519683f16ec29552b1c1a4a9761761b960db7;hb=501210e1bbf79d8a9d6308257124c44a261bf379;hp=efe0d3cf38b012269743410d75b5e71b43b04f6e;hpb=3fba2e94993ce7d1d5c54970817f48bcf81f42fb;p=freeside.git diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm index efe0d3cf3..d1d519683 100644 --- a/FS/FS/part_event/Condition.pm +++ b/FS/FS/part_event/Condition.pm @@ -52,8 +52,10 @@ sub eventtable_hashref { { 'cust_main' => 1, 'cust_bill' => 1, 'cust_pkg' => 1, + 'cust_pay' => 1, 'cust_pay_batch' => 1, 'cust_statement' => 1, + 'svc_acct' => 1, }; } @@ -234,6 +236,21 @@ sub cust_main { } +=item cust_pkg OBJECT + +Return the package object (L) associated with the provided +object. The object must be either a service (L) or a +package. + +=cut + +sub cust_pkg { + my( $self, $object ) = @_; + $object->isa('FS::cust_pkg') ? $object : + $object->isa('FS::svc_Common') ? $object->cust_svc->cust_pkg : + undef; +} + =item option_label OPTIONNAME Returns the label for the specified option name. @@ -253,6 +270,23 @@ sub option_label { =back +=item option_type OPTION + +Returns the type of the option, as a string: 'text', 'money', 'date', +or 'freq'. + +=cut + +sub option_type { + my( $self, $optionname ) = @_; + + my %option_fields = $self->option_fields; + + ref( $option_fields{$optionname} ) + ? $option_fields{$optionname}->{'type'} + : 'text' +} + =item option_age_from OPTION FROM_TIMESTAMP Retreives a condition option, parses it from a frequency (such as "1d", "1w" or @@ -278,7 +312,7 @@ sub option_age_from { } elsif ( $age =~ /^(\d+)d$/i ) { $mday -= $1; } elsif ( $age =~ /^(\d+)h$/i ) { - $hour -= $hour; + $hour -= $1; } else { die "unparsable age: $age"; } @@ -322,11 +356,35 @@ sub condition_sql_option_option { )"; "( SELECT optionname FROM part_event_condition_option_option - WHERE optionnum = $optionnum + WHERE optionnum IN $optionnum )"; } +#used for part_event/Condition/cust_bill_has_service.pm and has_cust_tag.pm +#a little false laziness w/above and condition_sql_option_integer +sub condition_sql_option_option_integer { + 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' + )"; + + my $integer = (driver_name =~ /^mysql/) ? 'UNSIGNED INTEGER' : 'INTEGER'; + + my $optionname = "CAST(optionname AS $integer)"; + + "( SELECT $optionname FROM part_event_condition_option_option + WHERE optionnum IN $optionnum + )"; + +} =item condition_sql_option_age_from OPTION FROM_TIMESTAMP @@ -467,9 +525,12 @@ comparison to other integers is type-correct. sub condition_sql_option_integer { my ($class, $option, $driver_name) = @_; - my $integer = ($driver_name =~ /^mysql/) ? 'UNSIGNED INTEGER' : 'INTEGER'; + my $integer = (driver_name() =~ /^mysql/) ? 'UNSIGNED INTEGER' : 'INTEGER'; - 'CAST('. $class->condition_sql_option($option). " AS $integer )"; + 'CAST( + COALESCE('. $class->condition_sql_option($option). + " ,'0') ". + " AS $integer )"; } =head1 NEW CONDITION CLASSES