summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormark <mark>2010-09-18 04:25:37 +0000
committermark <mark>2010-09-18 04:25:37 +0000
commitb32f7f99fb92d3ffc5085d3abff45d48f77870cb (patch)
tree853417748ecfc68c9f957fd919f1a227a476e896
parentfe222cc914c17763670d7e21fb0d730c733275a2 (diff)
invoice past due event, RT#9931
-rw-r--r--FS/FS/cust_bill.pm19
-rw-r--r--FS/FS/part_event/Condition/cust_bill_past_due.pm41
2 files changed, 60 insertions, 0 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index e4215bf2b..bb392e83d 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -4462,6 +4462,25 @@ sub credited_sql {
WHERE cust_bill.invnum = cust_credit_bill.invnum $start $end )";
}
+=item due_date_sql
+
+Returns an SQL fragment to retrieve the due date of an invoice.
+Currently only supported on PostgreSQL.
+
+=cut
+
+sub due_date_sql {
+'COALESCE(
+ SUBSTRING(
+ COALESCE(
+ cust_bill.invoice_terms,
+ cust_main.invoice_terms,
+ \''.($conf->config('invoice_default_terms') || '').'\'
+ ), E\'Net (\\\\d+)\'
+ )::INTEGER, 0
+) * 86400 + cust_bill._date'
+}
+
=item search_sql_where HASHREF
Class method which returns an SQL WHERE fragment to search for parameters
diff --git a/FS/FS/part_event/Condition/cust_bill_past_due.pm b/FS/FS/part_event/Condition/cust_bill_past_due.pm
new file mode 100644
index 000000000..2a66a436d
--- /dev/null
+++ b/FS/FS/part_event/Condition/cust_bill_past_due.pm
@@ -0,0 +1,41 @@
+package FS::part_event::Condition::cust_bill_past_due;
+
+use strict;
+use FS::cust_bill;
+use Time::Local 'timelocal';
+
+use base qw( FS::part_event::Condition );
+
+sub description {
+ 'Invoice due date has passed';
+}
+
+sub eventtable_hashref {
+ { 'cust_main' => 0,
+ 'cust_bill' => 1,
+ 'cust_pkg' => 0,
+ };
+}
+
+sub condition {
+ my($self, $cust_bill, %opt) = @_;
+
+ # If the invoice date is 1/1 at noon and the terms are Net 15,
+ # the due_date will be 1/16 at noon. Past due events will not
+ # trigger until after the start of 1/17.
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5];
+ my $start_of_today = timelocal(0,0,0,$mday,$mon,$year)+1;
+ ($cust_bill->due_date || $cust_bill->_date) < $start_of_today;
+}
+
+sub condition_sql {
+ return '' if $FS::UID::driver_name ne 'Pg';
+ my( $class, $table, %opt ) = @_;
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5];
+ my $start_of_today = timelocal(0,0,0,$mday,$mon,$year)+1;
+
+ FS::cust_bill->due_date_sql . " < $start_of_today";
+
+}
+
+1;