invoice past due event, RT#9931
[freeside.git] / FS / FS / part_event / Condition / cust_bill_past_due.pm
1 package FS::part_event::Condition::cust_bill_past_due;
2
3 use strict;
4 use FS::cust_bill;
5 use Time::Local 'timelocal';
6
7 use base qw( FS::part_event::Condition );
8
9 sub description {
10   'Invoice due date has passed';
11 }
12
13 sub eventtable_hashref {
14     { 'cust_main' => 0,
15       'cust_bill' => 1,
16       'cust_pkg'  => 0,
17     };
18 }
19
20 sub condition {
21   my($self, $cust_bill, %opt) = @_;
22
23   # If the invoice date is 1/1 at noon and the terms are Net 15,
24   # the due_date will be 1/16 at noon.  Past due events will not 
25   # trigger until after the start of 1/17.
26   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5];
27   my $start_of_today = timelocal(0,0,0,$mday,$mon,$year)+1;
28   ($cust_bill->due_date || $cust_bill->_date) < $start_of_today;
29 }
30
31 sub condition_sql {
32   return '' if $FS::UID::driver_name ne 'Pg';
33   my( $class, $table, %opt ) = @_;
34   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5];
35   my $start_of_today = timelocal(0,0,0,$mday,$mon,$year)+1;
36
37   FS::cust_bill->due_date_sql . " < $start_of_today";
38
39 }
40
41 1;