X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FAction%2Fcust_bill_send_if_newest.pm;h=f946f7e2c6c8f5be7b82f324aced40e88745961c;hp=083da8b083b6faeda18b432c0df455ebda93a0d8;hb=39fe6499bd38e6e7c468f549b1d4919a7cf2c44d;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c diff --git a/FS/FS/part_event/Action/cust_bill_send_if_newest.pm b/FS/FS/part_event/Action/cust_bill_send_if_newest.pm index 083da8b08..f946f7e2c 100644 --- a/FS/FS/part_event/Action/cust_bill_send_if_newest.pm +++ b/FS/FS/part_event/Action/cust_bill_send_if_newest.pm @@ -12,12 +12,18 @@ sub description { # 1; #} +## declaring that this action will send out an invoice +sub will_send_invoice { 1; } + sub eventtable_hashref { { 'cust_bill' => 1 }; } sub option_fields { ( + 'modenum' => { label => 'Invoice mode', + type => 'select-invoice_mode', + }, 'if_newest_templatename' => { label => 'Template', type => 'select-invoice_template', }, @@ -29,10 +35,17 @@ sub default_weight { 50; } sub do_action { my( $self, $cust_bill ) = @_; - #my $cust_main = $self->cust_main($cust_bill); - my $cust_main = $cust_bill->cust_main; - - $cust_bill->send( $self->option('templatename') ); + my $invnum = $cust_bill->invnum; + my $custnum = $cust_bill->custnum; + return '' if scalar( + grep { $_->owed > 0 } + qsearch('cust_bill', { + 'custnum' => $custnum, + 'invnum' => { op=>'>', value=>$invnum }, + }) + ); + $cust_bill->set('mode' => $self->option('modenum')); + $cust_bill->send( 'template' => $self->option('templatename') ); } 1;