[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 88df244c8078f6db7701ff6deb928e4b7edecf58

Mark Wells mark at 420.am
Mon May 20 16:21:38 PDT 2013


The branch, FREESIDE_2_3_BRANCH has been updated
       via  88df244c8078f6db7701ff6deb928e4b7edecf58 (commit)
      from  4c989c092b2db59669dd0829daf04d354a7e4017 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 88df244c8078f6db7701ff6deb928e4b7edecf58
Author: Mark Wells <mark at freeside.biz>
Date:   Mon May 20 16:19:55 2013 -0700

    option for inactive_age condition to ignore some kinds of charges, #19873

diff --git a/FS/FS/part_event/Condition/inactive_age.pm b/FS/FS/part_event/Condition/inactive_age.pm
index 8918a1a..cbf4b9e 100644
--- a/FS/FS/part_event/Condition/inactive_age.pm
+++ b/FS/FS/part_event/Condition/inactive_age.pm
@@ -11,6 +11,10 @@ sub option_fields {
     'age'  =>  { 'label'   => 'No activity within',
                  'type'    => 'freq',
                },
+    'ignore_pkgclass' =>
+               { 'label' => 'Except charges of class',
+                 'type'  => 'select-pkg_class',
+               },
     # flags to select kinds of activity, 
     # like if you just want "no payments since"?
     # not relevant yet
@@ -22,23 +26,51 @@ sub condition {
   my $custnum = $obj->custnum;
   my $age = $self->option_age_from('age', $opt{'time'} );
 
-  foreach my $t (qw(cust_bill cust_pay cust_credit cust_refund)) {
+  my $ignore_pkgclass = $self->option('ignore_pkgclass');
+
+  my $where = "custnum = $custnum AND _date >= $age";
+
+  foreach my $t (qw(cust_pay cust_credit cust_refund)) {
     my $class = "FS::$t";
-    return 0 if $class->count("custnum = $custnum AND _date >= $age");
+    return 0 if $class->count($where);
   }
+
+  # cust_bill: handle the ignore_pkgclass option
+  if ( $ignore_pkgclass =~ /^\d+$/ ) {
+    $where .= " AND EXISTS( ".
+      "SELECT 1 FROM cust_bill_pkg JOIN cust_pkg USING (pkgnum) " .
+      "JOIN part_pkg USING (pkgpart) " .
+      "WHERE cust_bill_pkg.invnum = cust_bill.invnum " .
+      "AND COALESCE(part_pkg.classnum, -1) != $ignore_pkgclass" .
+      " )";
+  }
+  #warn "$where\n";
+  return 0 if FS::cust_bill->count($where);
+
   1;
 }
 
 sub condition_sql {
   my( $class, $table, %opt ) = @_;
   my $age   = $class->condition_sql_option_age_from('age', $opt{'time'});
+  my $ignore_pkgclass = $class->condition_sql_option_integer('ignore_pkgclass');
+  # will evaluate to zero if there isn't one
   my @sql;
-  for my $t (qw(cust_bill cust_pay cust_credit cust_refund)) {
+  for my $t (qw(cust_pay cust_credit cust_refund)) {
     push @sql,
       "NOT EXISTS( SELECT 1 FROM $t ".
       "WHERE $t.custnum = cust_main.custnum AND $t._date >= $age".
       ")";
   }
+  #cust_bill
+  push @sql,
+    "NOT EXISTS( ".
+    "SELECT 1 FROM cust_bill JOIN cust_bill_pkg USING (invnum) ".
+    "JOIN cust_pkg USING (pkgnum) JOIN part_pkg USING (pkgpart) ".
+    "WHERE cust_bill.custnum = cust_main.custnum ".
+    "AND cust_bill._date >= $age ".
+    "AND COALESCE(part_pkg.classnum, -1) != $ignore_pkgclass ".
+    ")";
   join(' AND ', @sql);
 }
 

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event/Condition/inactive_age.pm |   38 +++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 3 deletions(-)




More information about the freeside-commits mailing list