summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2004-12-11 20:41:38 +0000
committerivan <ivan>2004-12-11 20:41:38 +0000
commit08d3918e91ee3438af37345c94a002dec77fe9bb (patch)
treecfabf2c9314f2c7d3241440f4303e2317e4d20fd
parentc21b6e69583bec632de7fcd340c29982c868f73d (diff)
add 'send_if_newest' invoice event, closes: Bug#977
-rw-r--r--FS/FS/cust_bill.pm23
-rw-r--r--FS/FS/part_bill_event.pm2
-rwxr-xr-xhttemplate/edit/part_bill_event.cgi8
3 files changed, 32 insertions, 1 deletions
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<send>, 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' =>
+ '<INPUT TYPE="text" NAME="if_newest_templatename" VALUE="%%%if_newest_templatename%%%">',
+ 'weight' => 50,
+ },
+
'send_agent' => {
'name' => 'Send invoice (email/print) ',
'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', %%%agentnum%%%, \'%%%agent_invoice_from%%%\');',