Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / part_event / Condition.pm
index efe0d3c..b969cf6 100644 (file)
@@ -54,6 +54,7 @@ sub eventtable_hashref {
       'cust_pkg'       => 1,
       'cust_pay_batch' => 1,
       'cust_statement' => 1,
+      'svc_acct'       => 1,
     };
 }
 
@@ -234,6 +235,21 @@ sub cust_main {
 
 }
 
+=item cust_pkg OBJECT
+
+Return the package object (L<FS::cust_pkg>) associated with the provided 
+object.  The object must be either a service (L<FS::svc_Common>) 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 +269,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
@@ -469,7 +502,10 @@ sub condition_sql_option_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