X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event_condition.pm;h=200049da7a4f339bb0af9929a27a4c788d8f9dcf;hb=292ef074d01bb925e9a466ed771bf2ac418bb44f;hp=1efd0f8793c801cef36efd23007dd13fc8b1598e;hpb=9509e5bfb7f9331303153cac24d7bfecbe2ea9f1;p=freeside.git diff --git a/FS/FS/part_event_condition.pm b/FS/FS/part_event_condition.pm index 1efd0f879..200049da7 100644 --- a/FS/FS/part_event_condition.pm +++ b/FS/FS/part_event_condition.pm @@ -1,8 +1,8 @@ package FS::part_event_condition; use strict; -use vars qw( @ISA $DEBUG ); -use FS::UID qw(dbh); +use vars qw( @ISA $DEBUG @SKIP_CONDITION_SQL ); +use FS::UID qw( dbh driver_name ); use FS::Record qw( qsearch qsearchs ); use FS::option_Common; use FS::part_event; #for order_conditions_sql... @@ -10,6 +10,8 @@ use FS::part_event; #for order_conditions_sql... @ISA = qw( FS::option_Common ); # FS::Record ); $DEBUG = 0; +@SKIP_CONDITION_SQL = (); + =head1 NAME FS::part_event_condition - Object methods for part_event_condition records @@ -183,12 +185,20 @@ foreach my $INC ( @INC ) { }; my $mod = $1; my $fullmod = "FS::part_event::Condition::$mod"; + if ( $fullmod =~ /_(Mixin|Common)$/ ) { + #warn "skipping $1 class $fullmod\n"; + next; + } eval "use $fullmod;"; if ( $@ ) { die "error using $fullmod (skipping): $@\n" if $@; #warn "error using $fullmod (skipping): $@\n" if $@; #next; } + if ( $fullmod->disabled ) { + warn "$fullmod is disabled; skipping\n"; + next; + } #my $full_condition_sql = $fullmod. '::condition_sql'; my $condition_sql_coderef = sub { $fullmod->condition_sql(@_) }; my $order_sql_coderef = $fullmod->can('order_sql') @@ -214,8 +224,7 @@ sub conditions { my( $class, $eventtable ) = @_; ( map { $_ => $conditions{$_} } -# sort { $conditions{$a}->{'default_weight'}<=>$conditions{$b}->{'default_weight'} } -# sort by ? + sort {$conditions{$a}->{'description'} cmp $conditions{$b}->{'description'}} $class->all_conditionnames( $eventtable ) ); @@ -234,17 +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". Typically used in conjunction with -B. +B. OPTIONS should include 'time', the time to use +in testing event conditions. =cut sub join_conditions_sql { - my ( $class, $eventtable ) = @_; - my %conditions = $class->conditions( $eventtable ); + my ( $class, $eventtable, %options ) = @_; join(' ', map { @@ -253,7 +262,8 @@ sub join_conditions_sql { " AND cond_$_.conditionname = ". dbh->quote($_). " )"; } - keys %conditions + map $_->[0], $class->_where_conditions( $eventtable, %options ) + ); } @@ -271,22 +281,38 @@ as passed to freeside-daily), as a UNIX timestamp. sub where_conditions_sql { my ( $class, $eventtable, %options ) = @_; + join(' AND ', + map { my $conditionname = $_->[0]; + my $sql = $_->[1]; + "( cond_$conditionname.conditionname IS NULL OR $sql )"; + } + $class->_where_conditions( $eventtable, %options ) + ); +} + +sub _where_conditions { + my ( $class, $eventtable, %options ) = @_; + my $time = $options{'time'}; my %conditions = $class->conditions( $eventtable ); - my $where = join(' AND ', + grep { $_->[1] !~ /^\s*true\s*$/i + || $conditions{ $_->[0] }->{order_sql} + } map { my $conditionname = $_; my $coderef = $conditions{$conditionname}->{condition_sql}; - my $sql = &$coderef( $eventtable, 'time'=>$time ); - die "$coderef is not a CODEREF" unless ref($coderef) eq 'CODE'; - "( cond_$conditionname.conditionname IS NULL OR $sql )"; + #die "$coderef is not a CODEREF" unless ref($coderef) eq 'CODE'; + my $sql = &$coderef( $eventtable, 'time' => $time, + 'driver_name' => driver_name(), + ); + [ $_, $sql ]; } - keys %conditions - ); - - $where; + grep { my $cond = $_; + ! grep { $_ eq $cond } @SKIP_CONDITION_SQL + } + keys %conditions; } =item order_conditions_sql [ EVENTTABLE ] @@ -328,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