[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 52fcd2eb6f389fa8223d6d10d24aed4595c801db

Ivan ivan at 420.am
Thu Dec 20 23:01:19 PST 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  52fcd2eb6f389fa8223d6d10d24aed4595c801db (commit)
      from  ada138aaa35f8d843c6e9b6acc83bae70fa13ef3 (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 52fcd2eb6f389fa8223d6d10d24aed4595c801db
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Dec 20 23:01:16 2012 -0800

    credit line items interface: set credit amounts, RT#18676

diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 1f54777..83e5d60 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -5,6 +5,7 @@ use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record );
 use vars qw( $conf $unsuspendauto $me $DEBUG
              $otaker_upgrade_kludge $ignore_empty_reasonnum
            );
+use List::Util qw( min );
 use Date::Format;
 use FS::UID qw( dbh getotaker );
 use FS::Misc qw(send_email);
@@ -878,13 +879,19 @@ sub credit_lineitems {
           my $old_loc = $xlocation_map{$taxid};
           if ( $old_loc ) {
             # then apply the amount of $new_loc to it
-            $amount -= $new_loc->amount;
 
-            $cust_credit_bill{$invnum} += $new_loc->amount;
+            #support partial credits: use $amount if smaller
+            # (so just distribute to the first location?   perhaps should
+            #  do so evenly...)
+            my $loc_amount = min( $amount, $new_loc->amount);
+
+            $amount -= $loc_amount;
+
+            $cust_credit_bill{$invnum} += $loc_amount;
             push @{ $cust_credit_bill_pkg{$invnum} },
               new FS::cust_credit_bill_pkg {
                 'billpkgnum'                => $tax_cust_bill_pkg->billpkgnum,
-                'amount'                    => $new_loc->amount,
+                'amount'                    => $loc_amount,
                 'setuprecur'                => 'setup',
                 'billpkgtaxlocationnum'     => $old_loc->billpkgtaxlocationnum,
                 'billpkgtaxratelocationnum' => $old_loc->billpkgtaxratelocationnum,
diff --git a/httemplate/edit/credit-cust_bill_pkg.html b/httemplate/edit/credit-cust_bill_pkg.html
index 1c6d5e5..77453a1 100644
--- a/httemplate/edit/credit-cust_bill_pkg.html
+++ b/httemplate/edit/credit-cust_bill_pkg.html
@@ -20,18 +20,18 @@
 %   next unless $amount > 0;
 
 %   if ( $cust_bill_pkg->invnum ne $old_invnum ) {
-      <TR><TD COLSPAN=3 BGCOLOR="#f8f8f8"> </TD></TR>
-      <TR><TH COLSPAN=3 BGCOLOR="#f8f8f8" ALIGN="left">Invoice #<% $cust_bill_pkg->invnum %> - <% time2str($date_format, $cust_bill_pkg->cust_bill->_date) %></TD></TR>
+      <TR><TD COLSPAN=4 BGCOLOR="#f8f8f8"> </TD></TR>
+      <TR><TH COLSPAN=4 BGCOLOR="#f8f8f8" ALIGN="left">Invoice #<% $cust_bill_pkg->invnum %> - <% time2str($date_format, $cust_bill_pkg->cust_bill->_date) %></TD></TR>
 %     $old_invnum = $cust_bill_pkg->invnum;
 %   }
 
+%   my $el_name = 'billpkgnum'. $cust_bill_pkg->billpkgnum. '-'. $setuprecur;
     <TR>
       <TD>
         <INPUT TYPE            = "checkbox"
-               NAME            = "billpkgnum<% $cust_bill_pkg->billpkgnum.'-'. $setuprecur %>"
-               VALUE           = "<% $amount %>"
+               NAME            = "<% $el_name %>"
+               ID              = "<% $el_name %>"
                onClick         = "calc_total(this)"
-               data-amount     = "<% $amount %>"
                data-billpkgnum = "<% $cust_bill_pkg->billpkgnum %>"
                data-setuprecur = "<% $setuprecur %>"
         >
@@ -39,24 +39,35 @@
       <TD BGCOLOR="#ffffff"><% $cust_bill_pkg->desc |h %></TD>
 %#    show one-time/setup vs recur vs usage?
       <TD BGCOLOR="#ffffff" ALIGN="right"><% $money_char. $amount %></TD>
+      <TD ALIGN="right">
+        <% $money_char %><INPUT TYPE     = "text"
+                                NAME     = "<% $el_name %>-amount"
+                                ID       = "<% $el_name %>-amount"
+                                VALUE    = "<% $amount %>"
+                                SIZE     = 6
+                                onChange = "calc_total(this)"
+                                STYLE    = "text-align:right;"
+                                DISABLED
+                         >
+      </TD>
     </TR>
 
 % }
 
-<TR><TD COLSPAN=3 BGCOLOR="#f8f8f8"> </TD></TR>
+<TR><TD COLSPAN=4 BGCOLOR="#f8f8f8"> </TD></TR>
 <TR>
   <TD></TD>
-  <TD ALIGN="right">Subtotal: </TD>
+  <TD ALIGN="right" COLSPAN=2>Subtotal: </TD>
   <TD ALIGN="right" ID="subtotal_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
 </TR>
 <TR>
   <TD></TD>
-  <TD ALIGN="right">Taxes: </TD>
+  <TD ALIGN="right" COLSPAN=2>Taxes: </TD>
   <TD ALIGN="right" ID="taxtotal_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
 </TR>
 <TR>
   <TD></TD>
-  <TH ALIGN="right">Total credit amount: </TD>
+  <TH ALIGN="right" COLSPAN=2>Total credit amount: </TD>
   <TH ALIGN="right" ID="total_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
 </TR>
 <INPUT TYPE="hidden" NAME="amount" ID="total_el" VALUE="0.00">
@@ -188,12 +199,21 @@ function calc_total(what) {
   var setuprecurs = [];
   var amounts = [];
   for (var i=0; i<el.length; i++) {
-    if ( el[i].type == 'checkbox' && el[i].checked ) {
-      subtotal += parseFloat( el[i].getAttribute('data-amount') );
-      amounts.push(     el[i].getAttribute('data-amount') );
-      billpkgnums.push( el[i].getAttribute('data-billpkgnum') );
-      setuprecurs.push( el[i].getAttribute('data-setuprecur') );
+
+    if ( el[i].type == 'checkbox' ) {
+      var amount_el = document.getElementById( el[i].id + '-amount' );
+      if ( el[i].checked ) {
+        amount_el.disabled = false;
+        var amount = amount_el.value;
+        subtotal += parseFloat( amount );
+        amounts.push( amount );
+        billpkgnums.push( el[i].getAttribute('data-billpkgnum') );
+        setuprecurs.push( el[i].getAttribute('data-setuprecur') );
+      } else {
+        amount_el.disabled = true;
+      }
     }
+
   }
 
   document.getElementById('subtotal_td').innerHTML =
diff --git a/httemplate/edit/process/credit-cust_bill_pkg.html b/httemplate/edit/process/credit-cust_bill_pkg.html
index 8b2f3f3..1b61997 100644
--- a/httemplate/edit/process/credit-cust_bill_pkg.html
+++ b/httemplate/edit/process/credit-cust_bill_pkg.html
@@ -20,7 +20,7 @@ my @billpkgnums = ();
 my @setuprecurs = ();
 my @amounts = ();
 foreach my $billpkgnum_setuprecur (@billpkgnum_setuprecurs) {
-  my $amount = $cgi->param("billpkgnum$billpkgnum_setuprecur");
+  my $amount = $cgi->param("billpkgnum$billpkgnum_setuprecur-amount");
   my( $billpkgnum, $setuprecur ) = split('-', $billpkgnum_setuprecur);
   push @billpkgnums, $billpkgnum;
   push @setuprecurs, $setuprecur;
diff --git a/httemplate/view/cust_main/payment_history.html b/httemplate/view/cust_main/payment_history.html
index ed07577..821309d 100644
--- a/httemplate/view/cust_main/payment_history.html
+++ b/httemplate/view/cust_main/payment_history.html
@@ -77,7 +77,7 @@
                'action'      => "${p}edit/credit-cust_bill_pkg.html",
                'cust_main'   => $cust_main,
                'actionlabel' => emt('Credit line items'),
-               'width'       => 884, #763,
+               'width'       => 968, #763,
                'height'      => 575,
   &>
   <BR>

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

Summary of changes:
 FS/FS/cust_credit.pm                              |   13 ++++-
 httemplate/edit/credit-cust_bill_pkg.html         |   48 +++++++++++++++------
 httemplate/edit/process/credit-cust_bill_pkg.html |    2 +-
 httemplate/view/cust_main/payment_history.html    |    2 +-
 4 files changed, 46 insertions(+), 19 deletions(-)




More information about the freeside-commits mailing list