1 package FS::part_event::Condition::inactive_age;
4 use base qw( FS::part_event::Condition );
5 use FS::Record qw( qsearch );
7 sub description { 'Days without billing activity' }
11 'age' => { 'label' => 'No activity within',
15 { 'label' => 'Except charges of class',
16 'type' => 'select-pkg_class',
18 # flags to select kinds of activity,
19 # like if you just want "no payments since"?
25 my( $self, $obj, %opt ) = @_;
26 my $custnum = $obj->custnum;
27 my $age = $self->option_age_from('age', $opt{'time'} );
29 my $ignore_pkgclass = $self->option('ignore_pkgclass');
31 my $where = "custnum = $custnum AND _date >= $age";
33 foreach my $t (qw(cust_pay cust_credit cust_refund)) {
35 return 0 if $class->count($where);
38 # cust_bill: handle the ignore_pkgclass option
39 if ( $ignore_pkgclass =~ /^\d+$/ ) {
40 $where .= " AND EXISTS( ".
41 "SELECT 1 FROM cust_bill_pkg JOIN cust_pkg USING (pkgnum) " .
42 "JOIN part_pkg USING (pkgpart) " .
43 "WHERE cust_bill_pkg.invnum = cust_bill.invnum " .
44 "AND COALESCE(part_pkg.classnum, -1) != $ignore_pkgclass" .
48 return 0 if FS::cust_bill->count($where);
54 my( $class, $table, %opt ) = @_;
55 my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
56 my $ignore_pkgclass = $class->condition_sql_option_integer('ignore_pkgclass');
57 # will evaluate to zero if there isn't one
59 for my $t (qw(cust_pay cust_credit cust_refund)) {
61 "NOT EXISTS( SELECT 1 FROM $t ".
62 "WHERE $t.custnum = cust_main.custnum AND $t._date >= $age".
68 "SELECT 1 FROM cust_bill JOIN cust_bill_pkg USING (invnum) ".
69 "JOIN cust_pkg USING (pkgnum) JOIN part_pkg USING (pkgpart) ".
70 "WHERE cust_bill.custnum = cust_main.custnum ".
71 "AND cust_bill._date >= $age ".
72 "AND COALESCE(part_pkg.classnum, -1) != $ignore_pkgclass ".