[freeside-commits] branch FREESIDE_3_BRANCH updated. d1953d60d032b0b3066704c20ff75bf8585cd32e

Mark Wells mark at 420.am
Wed Sep 25 17:11:41 PDT 2013


The branch, FREESIDE_3_BRANCH has been updated
       via  d1953d60d032b0b3066704c20ff75bf8585cd32e (commit)
       via  9c793d18208df92f891b0fa658cfad6b5e0e1c4b (commit)
       via  29853384c68f936073d35d9d37f13b23d5d71771 (commit)
      from  d77b0c6d6abf8bb9b664ec827599c761aba790b7 (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 d1953d60d032b0b3066704c20ff75bf8585cd32e
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Sep 25 17:10:46 2013 -0700

    minor convenience for invoice templates, #24850

diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index f55fc66..356de5b 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -755,6 +755,7 @@ sub print_generic {
   my $taxtotal = 0;
   my $tax_section = { 'description' => $self->mt('Taxes, Surcharges, and Fees'),
                       'subtotal'    => $taxtotal,   # adjusted below
+                      'tax_section' => 1,
                     };
   my $tax_weight = _pkg_category($tax_section->{description})
                         ? _pkg_category($tax_section->{description})->weight

commit 9c793d18208df92f891b0fa658cfad6b5e0e1c4b
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Sep 25 17:00:15 2013 -0700

    allow for taxes when using "fee" event to negate credit balance, #24991

diff --git a/FS/FS/part_event/Action/fee.pm b/FS/FS/part_event/Action/fee.pm
index cd9e200..c2b4673 100644
--- a/FS/FS/part_event/Action/fee.pm
+++ b/FS/FS/part_event/Action/fee.pm
@@ -32,7 +32,48 @@ sub _calc_fee {
     if ( $balance >= 0 ) {
       return 0;
     } elsif ( (-1 * $balance) < $self->option('charge') ) {
-      return -1 * $balance;
+      my $total = -1 * $balance;
+      # if it's tax exempt, then we're done
+      # XXX we also bail out if you're using external tax tables, because
+      # they're definitely NOT linear and we haven't yet had a reason to 
+      # make that case work.
+      return $total if $self->option('setuptax') eq 'Y'
+                    or FS::Conf->new->exists('enable_taxproducts');
+
+      # estimate tax rate
+      # false laziness with xmlhttp-calculate_taxes, cust_main::Billing, etc.
+      # XXX not accurate with monthly exemptions
+      my $cust_main = $cust_object->cust_main;
+      my $taxlisthash = {};
+      my $charge = FS::cust_bill_pkg->new({
+          setup => $total,
+          recur => 0,
+          details => []
+      });
+      my $part_pkg = FS::part_pkg->new({
+          taxclass => $self->option('taxclass')
+      });
+      my $error = $cust_main->_handle_taxes(
+        FS::part_pkg->new({ taxclass => ($self->option('taxclass') || '') }),
+        $taxlisthash,
+        $charge,
+        FS::cust_pkg->new({custnum => $cust_main->custnum}),
+      );
+      if ( $error ) {
+        warn "error estimating taxes for breakage charge: custnum ".$cust_main->custnum."\n";
+        return $total;
+      }
+      # $taxlisthash: tax identifier => [ cust_main_county, cust_bill_pkg... ]
+      my $total_rate = 0;
+      my @taxes = map { $_->[0] } values %$taxlisthash;
+      foreach (@taxes) {
+        $total_rate += $_->tax;
+      }
+      return $total if $total_rate == 0; # no taxes apply
+
+      my $total_cents = $total * 100;
+      my $charge_cents = sprintf('%.0f', $total_cents * 100/(100 + $total_rate));
+      return ($charge_cents / 100);
     }
   }
 

commit 29853384c68f936073d35d9d37f13b23d5d71771
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Sep 25 16:52:24 2013 -0700

    optionally display payments/credits on invoice based on date received, #24850

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 51f9fc1..517395d 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4169,6 +4169,13 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'previous_balance-payments_since',
+    'section'     => 'invoicing',
+    'description' => 'Instead of showing payments (and credits) applied to the invoice, show those received since the previous invoice date.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'balance_due_below_line',
     'section'     => 'invoicing',
     'description' => 'Place the balance due message below a line.  Only meaningful when when invoice_sections is false.',
diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index db38854..f55fc66 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -608,23 +608,12 @@ sub print_generic {
   # summary formats
   $invoice_data{'last_bill'} = {};
 
-  # returns the last unpaid bill, not the last bill
-  #my $last_bill = $pr_cust_bill[-1];
-
   if ( $self->custnum && $self->invnum ) {
 
-    # THIS returns the customer's last bill before  this one
-    my $last_bill = qsearchs({
-        'table'   => 'cust_bill',
-        'hashref' => { 'custnum' => $self->custnum,
-                       'invnum'  => { op => '<', value => $self->invnum },
-                     },
-        'order_by'  => ' ORDER BY invnum DESC LIMIT 1'
-    });
-    if ( $last_bill ) {
+    if ( $self->previous_bill ) {
+      my $last_bill = $self->previous_bill;
       $invoice_data{'last_bill'} = {
         '_date'     => $last_bill->_date, #unformatted
-        # all we need for now
       };
       my (@payments, @credits);
       # for formats that itemize previous payments
@@ -1167,7 +1156,7 @@ sub print_generic {
         $adjust_section->{'pretotal'} = $self->mt('New charges total').' '.
           $other_money_char.  sprintf('%.2f', $self->charged );
       } 
-    }else{
+    } else {
       push @total_items, $total;
     }
     push @buf,['','-----------'];
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index fc6a7dd..97dd38b 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -422,6 +422,25 @@ sub display_invnum {
   }
 }
 
+=item previous_bill
+
+Returns the customer's last invoice before this one.
+
+=cut
+
+sub previous_bill {
+  my $self = shift;
+  if ( !$self->get('previous_bill') ) {
+    $self->set('previous_bill', qsearchs({
+          'table'     => 'cust_bill',
+          'hashref'   => { 'custnum'  => $self->custnum,
+                           '_date'    => { op=>'<', value=>$self->_date } },
+          'order_by'  => 'ORDER BY _date DESC LIMIT 1',
+    }) );
+  }
+  $self->get('previous_bill');
+}
+
 =item previous
 
 Returns a list consisting of the total previous balance for this customer, 
@@ -3109,12 +3128,25 @@ sub _items_credits {
 
   my @b;
   #credits
-  foreach ( $self->cust_credited ) {
+  my @objects;
+  if ( $self->conf->exists('previous_balance-payments_since') ) {
+    my $date = 0;
+    $date = $self->previous_bill->_date if $self->previous_bill;
+    @objects = qsearch('cust_credit', {
+        'custnum' => $self->custnum,
+        '_date'   => {op => '>=', value => $date},
+      });
+      # hard to do this in the qsearch...
+    @objects = grep { $_->_date < $self->_date } @objects;
+  } else {
+    @objects = $self->cust_credited;
+  }
 
-    #something more elaborate if $_->amount ne $_->cust_credit->credited ?
+  foreach my $obj ( @objects ) {
+    my $cust_credit = $obj->isa('FS::cust_credit') ? $obj : $obj->cust_credit;
 
-    my $reason = substr($_->cust_credit->reason, 0, $trim_len);
-    $reason .= '...' if length($reason) < length($_->cust_credit->reason);
+    my $reason = substr($cust_credit->reason, 0, $trim_len);
+    $reason .= '...' if length($reason) < length($cust_credit->reason);
     $reason = " ($reason) " if $reason;
 
     push @b, {
@@ -3122,8 +3154,8 @@ sub _items_credits {
       #                 " (". time2str("%x",$_->cust_credit->_date) .")".
       #                 $reason,
       'description' => $self->mt('Credit applied').' '.
-                       time2str($date_format,$_->cust_credit->_date). $reason,
-      'amount'      => sprintf("%.2f",$_->amount),
+                       time2str($date_format,$obj->_date). $reason,
+      'amount'      => sprintf("%.2f",$obj->amount),
     };
   }
 
@@ -3135,21 +3167,31 @@ sub _items_payments {
   my $self = shift;
 
   my @b;
-  #get & print payments
-  foreach ( $self->cust_bill_pay ) {
-
-    #something more elaborate if $_->amount ne ->cust_pay->paid ?
+  my $detailed = $self->conf->exists('invoice_payment_details');
+  my @objects;
+  if ( $self->conf->exists('previous_balance-payments_since') ) {
+    my $date = 0;
+    $date = $self->previous_bill->_date if $self->previous_bill;
+    @objects = qsearch('cust_pay', {
+        'custnum' => $self->custnum,
+        '_date'   => {op => '>=', value => $date},
+      });
+    @objects = grep { $_->_date < $self->_date } @objects;
+  } else {
+    @objects = $self->cust_bill_pay;
+  }
 
+  foreach my $obj (@objects) {
+    my $cust_pay = $obj->isa('FS::cust_pay') ? $obj : $obj->cust_pay;
     my $desc = $self->mt('Payment received').' '.
-               time2str($date_format,$_->cust_pay->_date );
-    $desc   .= $self->mt(' via ' . $_->cust_pay->payby_payinfo_pretty)
-      if ( $self->conf->exists('invoice_payment_details') );
- 
+               time2str($date_format, $cust_pay->_date );
+    $desc .= $self->mt(' via ' . $cust_pay->payby_payinfo_pretty)
+      if $detailed;
+
     push @b, {
       'description' => $desc,
-      'amount'      => sprintf("%.2f", $_->amount )
+      'amount'      => sprintf("%.2f", $obj->amount )
     };
-
   }
 
   @b;

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

Summary of changes:
 FS/FS/Conf.pm                  |    7 ++++
 FS/FS/Template_Mixin.pm        |   18 ++-------
 FS/FS/cust_bill.pm             |   74 +++++++++++++++++++++++++++++++---------
 FS/FS/part_event/Action/fee.pm |   43 ++++++++++++++++++++++-
 4 files changed, 111 insertions(+), 31 deletions(-)




More information about the freeside-commits mailing list