4868f663693f923fa44a976e96fe9f3853f4c6f0
[freeside.git] / FS / FS / part_event / Condition / invoice_has_not_been_sent.pm
1 package FS::part_event::Condition::invoice_has_not_been_sent;
2
3 use strict;
4 use FS::Record qw( qsearchs );
5 use FS::cust_bill;
6 use Time::Local 'timelocal';
7
8 use base qw( FS::part_event::Condition );
9
10 sub description {
11   'Invoice has not been sent previously';
12 }
13
14 sub eventtable_hashref {
15     { 'cust_main' => 0,
16       'cust_bill' => 1,
17       'cust_pkg'  => 0,
18     };
19 }
20
21 sub condition {
22   my($self, $cust_bill, %opt) = @_;
23
24   ## search actions for invoice send events.
25   my @send_actions = (
26     "action LIKE 'cust_bill_send%'",
27     "action LIKE 'cust_bill_email%'",
28     "action LIKE 'cust_bill_print%'",
29     "action LIKE 'cust_bill_fsinc_print%'",
30   );
31   my $actions = join ' OR ', @send_actions;
32   my $extra_sql = " AND ($actions)";
33
34   my $event = qsearchs( {
35     'table'     => 'cust_event',
36     'addl_from' => 'LEFT JOIN part_event USING ( eventpart )',
37     'hashref'   => {
38       'tablenum'   => $cust_bill->{Hash}->{invnum},
39       'eventtable' => 'cust_bill',
40       'status'     => 'done',
41     },
42     'order_by'  => " LIMIT 1",
43     'extra_sql' => $extra_sql,
44   } );
45
46   return 0 if $event;
47
48   1;
49
50 }
51
52 1;