fix credit card banning w/encryption
[freeside.git] / FS / FS / part_event / Condition.pm
index 9155a7d..914256f 100644 (file)
@@ -54,6 +54,7 @@ sub eventtable_hashref {
       'cust_pkg'       => 1,
       'cust_pay_batch' => 1,
       'cust_statement' => 1,
+      'svc_acct'       => 1,
     };
 }
 
@@ -145,7 +146,7 @@ passed as an argument.
 This method is used for optimizing event queries.  You may want to add indices
 for any columns referenced.  It is acceptable to return an SQL fragment which
 partially tests the condition; doing so will still reduce the number of
-records which much be returned and tested with the B<condition> method.
+records which must be returned and tested with the B<condition> method.
 
 =cut
 
@@ -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.
@@ -457,7 +473,7 @@ sub age2seconds_sql {
 
 }
 
-=item condition_sql_option_integer
+=item condition_sql_option_integer OPTION [ DRIVER_NAME ]
 
 As I<condition_sql_option>, but cast the option value to an integer so that
 comparison to other integers is type-correct.
@@ -465,8 +481,14 @@ comparison to other integers is type-correct.
 =cut
 
 sub condition_sql_option_integer {
-  my ($class, $option) = @_;
-  'CAST ('.$class->condition_sql_option($option).' AS INTEGER)';
+  my ($class, $option, $driver_name) = @_;
+
+  my $integer = ($driver_name =~ /^mysql/) ? 'UNSIGNED INTEGER' : 'INTEGER';
+
+  'CAST(
+         COALESCE('. $class->condition_sql_option($option).
+                " ,'0') ".
+       " AS $integer )";
 }
 
 =head1 NEW CONDITION CLASSES