From 08d3918e91ee3438af37345c94a002dec77fe9bb Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 11 Dec 2004 20:41:38 +0000 Subject: [PATCH] add 'send_if_newest' invoice event, closes: Bug#977 --- FS/FS/cust_bill.pm | 23 +++++++++++++++++++++++ FS/FS/part_bill_event.pm | 2 +- httemplate/edit/part_bill_event.cgi | 8 ++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 5b5d3765d..0306c010c 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -377,6 +377,29 @@ sub send { } +=item send_if_newest [ TEMPLATENAME [ , AGENTNUM [ , INVOICE_FROM ] ] ] + +Like B, but only sends the invoice if it is the newest open invoice for +this customer. + +=cut + +sub send_if_newest { + my $self = shift; + + return '' + if scalar( + grep { $_->owed > 0 } + qsearch('cust_bill', { + 'custnum' => $self->custnum, + #'_date' => { op=>'>', value=>$self->_date }, + 'invnum' => { op=>'>', value=>$self->invnum }, + } ) + ); + + $self->send(@_); +} + =item send_csv OPTIONS Sends invoice as a CSV data-file to a remote host with the specified protocol. diff --git a/FS/FS/part_bill_event.pm b/FS/FS/part_bill_event.pm index f90882817..7dfea5066 100644 --- a/FS/FS/part_bill_event.pm +++ b/FS/FS/part_bill_event.pm @@ -126,7 +126,7 @@ sub check { or $c =~ /^\s*\$cust_bill\->(comp|realtime_(card|ach|lec)|batch_card|send)\(\);\s*$/ - or $c =~ /^\s*\$cust_bill\->send\(\'[\w\-\s]+\'\s*(,\s*\d+\s*,\s*'[\w\@\.\-\+]*'\s*)?\);\s*$/ + or $c =~ /^\s*\$cust_bill\->send(_if_newest)?\(\'[\w\-\s]+\'\s*(,\s*\d+\s*,\s*'[\w\@\.\-\+]*'\s*)?\);\s*$/ or $c =~ /^\s*\$cust_main\->apply_payments; \$cust_main->apply_credits; "";\s*$/ diff --git a/httemplate/edit/part_bill_event.cgi b/httemplate/edit/part_bill_event.cgi index 2f99ca58f..59a20cecf 100755 --- a/httemplate/edit/part_bill_event.cgi +++ b/httemplate/edit/part_bill_event.cgi @@ -177,6 +177,14 @@ tie my %events, 'Tie::IxHash', 'weight' => 50, }, + 'send_if_newest' => { + 'name' => 'Send invoice (email/print) with alternate template, if it is still the newest invoice (useful for late notices)', + 'code' => '$cust_bill->send_if_newest(\'%%%if_newest_templatename%%%\');', + 'html' => + '', + 'weight' => 50, + }, + 'send_agent' => { 'name' => 'Send invoice (email/print) ', 'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', %%%agentnum%%%, \'%%%agent_invoice_from%%%\');', -- 2.11.0