multiple payment options, RT#23741
[freeside.git] / FS / FS / part_event_condition.pm
index b51c6b9..200049d 100644 (file)
@@ -243,16 +243,17 @@ sub all_conditionnames {
        keys %conditions
 }
 
-=item join_conditions_sql [ EVENTTABLE ]
+=item join_conditions_sql [ EVENTTABLE [, OPTIONS ] ]
 
 Returns an SQL fragment selecting joining all condition options for an event as
 tables titled "cond_I<conditionname>".  Typically used in conjunction with
-B<where_conditions_sql>.
+B<where_conditions_sql>.  OPTIONS should include 'time', the time to use
+in testing event conditions.
 
 =cut
 
 sub join_conditions_sql {
-  my ( $class, $eventtable ) = @_;
+  my ( $class, $eventtable, %options ) = @_;
 
   join(' ',
     map {
@@ -261,7 +262,7 @@ sub join_conditions_sql {
           "       AND cond_$_.conditionname = ". dbh->quote($_).
           "     )";
         }
-      map $_->[0], $class->_where_conditions( $eventtable ) #, %options )
+      map $_->[0], $class->_where_conditions( $eventtable, %options )
 
   );
 
@@ -353,6 +354,45 @@ sub order_conditions_sql {
 
 }
 
+sub _upgrade_data { #class method
+  my ($class, %opts) = @_;
+
+  foreach my $part_event_condition (
+    qsearch('part_event_condition', { 'conditionname' => 'payby' } )
+  ) {
+
+    my $payby = $part_event_condition->option('payby');
+
+    if ( scalar( keys %$payby ) == 1 ) {
+
+      if ( $payby->{'CARD'} ) {
+
+        $part_event_condition->conditionname('has_cust_payby_auto');
+
+      } elsif ( $payby->{'CHEK'} ) {
+
+        $part_event_condition->conditionname('has_cust_payby_auto');
+
+      }
+
+    } elsif ( $payby->{'BILL'} && ! $payby->{'CARD'} && ! $payby->{'CHEK'} ) {
+
+      $part_event_condition->conditionname('hasnt_cust_payby_auto');
+
+    } else {
+
+      die 'Unable to automatically convert payby condition for event #'.
+          $part_event_condition->eventpart. "\n";
+
+    }
+
+    my $error = $part_event_condition->replace;
+    die $error if $error;
+
+  }
+
+}
+
 =back
 
 =head1 BUGS