[freeside-commits] branch FREESIDE_3_BRANCH updated. f7c791eed080d1533aab05c475e1fe23997d98b4

Ivan ivan at 420.am
Mon May 5 19:06:39 PDT 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  f7c791eed080d1533aab05c475e1fe23997d98b4 (commit)
      from  fffecdd9ff8380e16fa68cd99a929675b1184738 (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 f7c791eed080d1533aab05c475e1fe23997d98b4
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon May 5 19:06:37 2014 -0700

    add option to omit considering late paid invoices from "paid invoices" for purposes of commissions, RT#28963

diff --git a/FS/FS/part_event/Condition/once_perinv.pm b/FS/FS/part_event/Condition/once_perinv.pm
index 1ee53b8..b1ab90c 100644
--- a/FS/FS/part_event/Condition/once_perinv.pm
+++ b/FS/FS/part_event/Condition/once_perinv.pm
@@ -18,6 +18,10 @@ sub option_fields {
                 'type'  => 'checkbox',
                 'value' => 'Y',
               },
+    'no_late' => { 'label' => "But don't consider paid bills which were late.",
+                   'type'  => 'checkbox',
+                   'value' => 'Y',
+                 },
   )
 }
 
@@ -33,9 +37,31 @@ sub condition {
 
   my @cust_bill_pkg = qsearch('cust_bill_pkg', { pkgnum=>$cust_pkg->pkgnum });
 
-  @cust_bill_pkg = grep { ($_->owed_setup + $_->owed_recur) == 0 }
-                     @cust_bill_pkg
-    if $self->option('paid');
+  if ( $self->option('paid') ) {
+    @cust_bill_pkg = grep { ($_->owed_setup + $_->owed_recur) == 0 }
+                       @cust_bill_pkg;
+
+    if ( $self->option('no_late') ) {
+      @cust_bill_pkg = grep {
+        my $cust_bill_pkg = $_;
+
+        my @cust_bill_pay_pkg = ();
+        push @cust_bill_pay_pkg, $cust_bill_pkg->cust_bill_pay_pkg($_)
+          for qw( setup recur );
+        return 1 unless @cust_bill_pay_pkg; #no payments?  must be credits then
+                                            #not considering those "late"
+
+        my @cust_pay = sort { $a->_date <=> $b->_date }
+                         map { $_->cust_bill_pay->cust_pay }
+                           @cust_bill_pay_pkg;
+
+        #most recent payment less than due date?  okay, we were paid on time
+        $cust_pay[-1] <= $cust_bill_pkg->cust_bill->due_date;
+                 
+      } @cust_bill_pkg;
+    }
+
+  }
 
   my %invnum = ();
   $invnum{$_->invnum} = 1 foreach @cust_bill_pkg;

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

Summary of changes:
 FS/FS/part_event/Condition/once_perinv.pm |   32 ++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 3 deletions(-)




More information about the freeside-commits mailing list