X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FAction%2Ffee.pm;h=cd9e200c8d620c01eecb8ef5f2e26d818cee68e2;hb=63973c641c4be00765fa27e55c57cc5b9aa4da19;hp=68288d090f7495c2a184754862240a2b92b034e3;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/FS/FS/part_event/Action/fee.pm b/FS/FS/part_event/Action/fee.pm index 68288d090..cd9e200c8 100644 --- a/FS/FS/part_event/Action/fee.pm +++ b/FS/FS/part_event/Action/fee.pm @@ -17,14 +17,25 @@ sub option_fields { type=>'checkbox', value=>'Y' }, 'nextbill' => { label=>'Hold late fee until next invoice', type=>'checkbox', value=>'Y' }, + 'limit_to_credit'=> + { label=>"Charge no more than the customer's credit balance", + type=>'checkbox', value=>'Y' }, ); } sub default_weight { 10; } sub _calc_fee { - #my( $self, $cust_object ) = @_; - my $self = shift; + my( $self, $cust_object ) = @_; + if ( $self->option('limit_to_credit') ) { + my $balance = $cust_object->cust_main->balance; + if ( $balance >= 0 ) { + return 0; + } elsif ( (-1 * $balance) < $self->option('charge') ) { + return -1 * $balance; + } + } + $self->option('charge'); } @@ -44,6 +55,9 @@ sub do_action { 'setuptax' => $self->option('setuptax'), ); + # amazingly, FS::cust_main::charge will allow a charge of zero + return '' if $charge{'amount'} == 0; + #unless its more than N months away? $charge{'start_date'} = $cust_main->next_bill_date if $self->option('nextbill');