add 'send_if_newest' invoice event, closes: Bug#977
authorivan <ivan>
Sat, 11 Dec 2004 20:41:38 +0000 (20:41 +0000)
committerivan <ivan>
Sat, 11 Dec 2004 20:41:38 +0000 (20:41 +0000)
FS/FS/cust_bill.pm
FS/FS/part_bill_event.pm
httemplate/edit/part_bill_event.cgi

index 5b5d376..0306c01 100644 (file)
@@ -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.
index f908828..7dfea50 100644 (file)
@@ -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*$/
 
index 2f99ca5..59a20ce 100755 (executable)
@@ -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%%%\');',