[freeside-commits] branch master updated. 2457752a82358108aa078f175a4e866f1786299a

Ivan ivan at 420.am
Fri Dec 12 19:20:23 PST 2014


The branch, master has been updated
       via  2457752a82358108aa078f175a4e866f1786299a (commit)
      from  e2213aaeab76983c26d92c1e1d928fe4e062accf (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 2457752a82358108aa078f175a4e866f1786299a
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Dec 12 19:20:22 2014 -0800

    costs for one-time charges, RT#31429

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index f446b88..9370460 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -3476,7 +3476,7 @@ Old-style:
 
 sub charge {
   my $self = shift;
-  my ( $amount, $quantity, $start_date, $classnum );
+  my ( $amount, $setup_cost, $quantity, $start_date, $classnum );
   my ( $pkg, $comment, $additional );
   my ( $setuptax, $taxclass );   #internal taxes
   my ( $taxproduct, $override ); #vendor (CCH) taxes
@@ -3486,6 +3486,7 @@ sub charge {
   my $locationnum;
   if ( ref( $_[0] ) ) {
     $amount     = $_[0]->{amount};
+    $setup_cost = $_[0]->{setup_cost};
     $quantity   = exists($_[0]->{quantity}) ? $_[0]->{quantity} : 1;
     $start_date = exists($_[0]->{start_date}) ? $_[0]->{start_date} : '';
     $no_auto    = exists($_[0]->{no_auto}) ? $_[0]->{no_auto} : '';
@@ -3504,6 +3505,7 @@ sub charge {
     $locationnum = $_[0]->{locationnum} || $self->ship_locationnum;
   } else {
     $amount     = shift;
+    $setup_cost = '';
     $quantity   = 1;
     $start_date = '';
     $pkg        = @_ ? shift : 'One-time charge';
@@ -3534,6 +3536,7 @@ sub charge {
     'setuptax'      => $setuptax,
     'taxclass'      => $taxclass,
     'taxproductnum' => $taxproduct,
+    'setup_cost'    => $setup_cost,
   } );
 
   my %options = ( ( map { ("additional_info$_" => $additional->[$_] ) }
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index a810f5a..d8fda3e 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -2362,27 +2362,37 @@ sub modify_charge {
   }
 
   if ( !$self->get('setup') ) {
-    # not yet billed, so allow amount and quantity
+    # not yet billed, so allow amount, setup_cost, quantity and start_date
+
+    if ( exists($opt{'amount'}) 
+          and $part_pkg->option('setup_fee') != $opt{'amount'}
+          and $opt{'amount'} > 0 ) {
+
+      $pkg_opt{'setup_fee'} = $opt{'amount'};
+      $pkg_opt_modified = 1;
+    }
+
+    if ( exists($opt{'setup_cost'}) 
+          and $part_pkg->setup_cost != $opt{'setup_cost'}
+          and $opt{'setup_cost'} > 0 ) {
+
+      $part_pkg->set('setup_cost', $opt{'setup_cost'});
+    }
+
     if ( exists($opt{'quantity'})
           and $opt{'quantity'} != $self->quantity
           and $opt{'quantity'} > 0 ) {
         
       $self->set('quantity', $opt{'quantity'});
     }
+
     if ( exists($opt{'start_date'})
           and $opt{'start_date'} != $self->start_date ) {
 
       $self->set('start_date', $opt{'start_date'});
     }
 
-    if ( exists($opt{'amount'}) 
-          and $part_pkg->option('setup_fee') != $opt{'amount'}
-          and $opt{'amount'} > 0 ) {
-
-      $pkg_opt{'setup_fee'} = $opt{'amount'};
-      $pkg_opt_modified = 1;
 
-    }
   } # else simply ignore them; the UI shouldn't allow editing the fields
 
   my $error;
diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi
index 07797d0..e87be62 100644
--- a/httemplate/edit/process/quick-charge.cgi
+++ b/httemplate/edit/process/quick-charge.cgi
@@ -36,7 +36,7 @@ exists($curuser->agentnums_href->{$cust_main->agentnum})
 
 my $message;
 
-if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
+if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
   $message = "One-time charge changed";
   my $pkgnum = $1;
   die "access denied"
@@ -48,18 +48,20 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
   my $part_pkg = $cust_pkg->part_pkg;
   die "pkgnum $pkgnum is not a one-time charge" unless $part_pkg->freq eq '0';
 
-  my ($amount, $quantity, $start_date);
+  my ($amount, $setup_cost, $quantity);
   if ( $cgi->param('amount') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
     $amount = sprintf('%.2f', $1);
   }
+  if ( $cgi->param('setup_cost') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
+    $setup_cost = sprintf('%.2f', $1);
+  }
   if ( $cgi->param('quantity') =~ /^\s*(\d*)\s*$/ ) {
     $quantity = $1 || 1;
   }
-  if ( $cgi->param('start_date') ) {
-    $start_date = parse_datetime($cgi->param('start_date'));
-  } else {
-    $start_date = time;
-  }
+
+  my $start_date = $cgi->param('start_date')
+                     ? parse_datetime($cgi->param('start_date'))
+                     : time;
 
   $error = $cust_pkg->modify_charge(
       'pkg'               => scalar($cgi->param('pkg')),
@@ -67,17 +69,24 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
       'additional'        => \@description,
       'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
       'amount'            => $amount,
+      'setup_cost'        => $setup_cost,
       'quantity'          => $quantity,
       'start_date'        => $start_date,
   );
 
-} else {
+} else { # the usual case: new one-time charge
+
   $message = "One-time charge added";
-  # the usual case: new one-time charge
+
   $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
     or $error .= "Illegal amount " . $param->{"amount"} . "  ";
   my $amount = $1;
 
+  my $setup_cost = '';
+  $param->{"setup_cost"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
+    or $error .= "Illegal setup_cost " . $param->{"setup_cost"} . "  ";
+  my $setup_cost = $1;
+
   my $quantity = 1;
   if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
     $quantity = $1;
@@ -101,6 +110,7 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
 
     $error ||= $cust_main->charge( {
       'amount'        => $amount,
+      'setup_cost'    => $setup_cost,
       'quantity'      => $quantity,
       'bill_now'      => scalar($cgi->param('bill_now')),
       'invoice_terms' => scalar($cgi->param('invoice_terms')),
diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html
index da9ac6e..ec1a580 100644
--- a/httemplate/edit/quick-charge.html
+++ b/httemplate/edit/quick-charge.html
@@ -111,13 +111,23 @@ function bill_now_changed (what) {
 % # don't allow changing these after the fact
 % $field = '/elements/tr-fixed.html' if $billed;
 <& $field,
-  label => 'Amount',
-  field => 'amount',
-  value => sprintf('%.2f',$part_pkg->option('setup_fee')),
-  size  => 8,
-  prefix  => $money_char,
+  label  => mt('Amount to charge'),
+  field  => 'amount',
+  value  => sprintf('%.2f',$part_pkg->option('setup_fee')),
+  size   => 8,
+  prefix => $money_char,
 &> 
 
+% if ( $curuser->access_right('Edit package definition costs') ) {
+  <& $field,
+    label  => mt('Cost'),
+    field  => 'setup_cost',
+    value  => sprintf('%.2f',$part_pkg->setup_cost),
+    size   => 8,
+    prefix => $money_char,
+  &> 
+% }
+
 %   if ( $conf->exists('invoice-unitprice') ) {
 <& $field,
   label => 'Quantity',
@@ -158,20 +168,31 @@ function bill_now_changed (what) {
         }
       &>
 %   }
+
 % } else { # new one-time charge
 
-<TR>
-  <TD ALIGN="right"><% mt('Amount') |h %> </TD>
-  <TD>
-    <% $money_char %><INPUT TYPE       = "text"
-                            NAME       = "amount"
-                            SIZE       = 6
-                            VALUE      = "<% $amount %>"
-                            onChange   = "return enable_quick_charge(event)"
-                            onKeyPress = "return enable_quick_charge(event)"
-                     >
-  </TD>
-</TR>
+    <TR>
+      <TD ALIGN="right"><% mt('Amount to charge') |h %> </TD>
+      <TD>
+        <% $money_char %><INPUT TYPE       = "text"
+                                NAME       = "amount"
+                                SIZE       = 8
+                                VALUE      = "<% $amount %>"
+                                onChange   = "return enable_quick_charge(event)"
+                                onKeyPress = "return enable_quick_charge(event)"
+                         >
+      </TD>
+    </TR>
+
+%   if ( $curuser->access_right('Edit package definition costs') ) {
+      <& /elements/tr-input-text.html,
+           label  => mt('Cost'),
+           field  => 'setup_cost',
+           value  => $setup_cost,
+           size   => 8,
+           prefix => $money_char,
+      &> 
+%   }
 
 %   if ( $conf->exists('invoice-unitprice') ) {
     <TR>
@@ -417,6 +438,11 @@ if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
   $amount = $1;
 }
 
+my $setup_cost = '';
+if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
+  $setup_cost = $1;
+}
+
 my $quantity = 1;
 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
   $quantity = $1;

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

Summary of changes:
 FS/FS/cust_main.pm                       |    5 ++-
 FS/FS/cust_pkg.pm                        |   26 +++++++++----
 httemplate/edit/process/quick-charge.cgi |   28 +++++++++-----
 httemplate/edit/quick-charge.html        |   60 +++++++++++++++++++++---------
 4 files changed, 84 insertions(+), 35 deletions(-)




More information about the freeside-commits mailing list