[freeside-commits] branch FREESIDE_4_BRANCH updated. ff6d9d364fbd070a3b632290ea9363b2ab1ae502

Ivan ivan at 420.am
Mon Apr 3 17:24:05 PDT 2017


The branch, FREESIDE_4_BRANCH has been updated
       via  ff6d9d364fbd070a3b632290ea9363b2ab1ae502 (commit)
      from  65e3d153162c86acc526849af93a027696f9b843 (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 ff6d9d364fbd070a3b632290ea9363b2ab1ae502
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon Apr 3 17:24:02 2017 -0700

    discounts on one-time charges< RT#75448

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 9e0fda4..44faa27 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -3481,6 +3481,7 @@ sub charge {
   my $cust_pkg_ref = '';
   my ( $bill_now, $invoice_terms ) = ( 0, '' );
   my $locationnum;
+  my ( $discountnum, $discountnum_amount, $discountnum_percent ) = ( '','','' );
   if ( ref( $_[0] ) ) {
     $amount     = $_[0]->{amount};
     $setup_cost = $_[0]->{setup_cost};
@@ -3501,6 +3502,9 @@ sub charge {
     $invoice_terms = exists($_[0]->{invoice_terms}) ? $_[0]->{invoice_terms} : '';
     $locationnum = $_[0]->{locationnum} || $self->ship_locationnum;
     $separate_bill = $_[0]->{separate_bill} || '';
+    $discountnum = $_[0]->{setup_discountnum};
+    $discountnum_amount = $_[0]->{setup_discountnum_amount};
+    $discountnum_percent = $_[0]->{setup_discountnum_percent};
   } else { # yuck
     $amount     = shift;
     $setup_cost = '';
@@ -3564,13 +3568,16 @@ sub charge {
   }
 
   my $cust_pkg = new FS::cust_pkg ( {
-    'custnum'    => $self->custnum,
-    'pkgpart'    => $pkgpart,
-    'quantity'   => $quantity,
-    'start_date' => $start_date,
-    'no_auto'    => $no_auto,
-    'separate_bill' => $separate_bill,
-    'locationnum'=> $locationnum,
+    'custnum'                   => $self->custnum,
+    'pkgpart'                   => $pkgpart,
+    'quantity'                  => $quantity,
+    'start_date'                => $start_date,
+    'no_auto'                   => $no_auto,
+    'separate_bill'             => $separate_bill,
+    'locationnum'               => $locationnum,
+    'setup_discountnum'         => $discountnum,
+    'setup_discountnum_amount'  => $discountnum_amount,
+    'setup_discountnum_percent' => $discountnum_percent,
   } );
 
   $error = $cust_pkg->insert;
diff --git a/FS/FS/quotation.pm b/FS/FS/quotation.pm
index c61e001..2f95425 100644
--- a/FS/FS/quotation.pm
+++ b/FS/FS/quotation.pm
@@ -510,6 +510,7 @@ sub charge {
   my $cust_pkg_ref = '';
   my ( $bill_now, $invoice_terms ) = ( 0, '' );
   my $locationnum;
+  my ( $discountnum, $discountnum_amount, $discountnum_percent ) = ( '','','' );
   if ( ref( $_[0] ) ) {
     $amount     = $_[0]->{amount};
     $setup_cost = $_[0]->{setup_cost};
@@ -529,6 +530,9 @@ sub charge {
     $bill_now = exists($_[0]->{bill_now}) ? $_[0]->{bill_now} : '';
     $invoice_terms = exists($_[0]->{invoice_terms}) ? $_[0]->{invoice_terms} : '';
     $locationnum = $_[0]->{locationnum};
+    $discountnum = $_->{setup_discountnum};
+    $discountnum_amount = $_->{setup_discountnum_amount};
+    $discountnum_percent = $_->{setup_discountnum_percent};
   } else {
     $amount     = shift;
     $setup_cost = '';
@@ -599,12 +603,15 @@ sub charge {
   # of ordering a customer package, no "bill now")
 
   my $quotation_pkg = new FS::quotation_pkg ( {
-    'quotationnum'  => $self->quotationnum,
-    'pkgpart'       => $pkgpart,
-    'quantity'      => $quantity,
-    #'start_date' => $start_date,
-    #'no_auto'    => $no_auto,
-    'locationnum'=> $locationnum,
+    'quotationnum'              => $self->quotationnum,
+    'pkgpart'                   => $pkgpart,
+    'quantity'                  => $quantity,
+    #'start_date'                => $start_date,
+    #'no_auto'                   => $no_auto,
+    'locationnum'               => $locationnum,
+    'setup_discountnum'         => $discountnum,
+    'setup_discountnum_amount'  => $discountnum_amount,
+    'setup_discountnum_percent' => $discountnum_percent,
   } );
 
   $error = $quotation_pkg->insert;
diff --git a/httemplate/edit/cust_pkg_discount.html b/httemplate/edit/cust_pkg_discount.html
index 79c3478..1739221 100755
--- a/httemplate/edit/cust_pkg_discount.html
+++ b/httemplate/edit/cust_pkg_discount.html
@@ -18,12 +18,16 @@
   </TR>
 
 <& /elements/tr-select-pkg-discount.html,
-  curr_value_setup  => $setup_discountnum,
-  curr_value_recur  => $recur_discountnum,
-  disable_setup     => $disable_setup,
-  disable_recur     => $disable_recur,
-  setup_label       => emt('Setup fee discount'),
-  recur_label       => emt('Recurring fee discount'),
+  curr_value_setup    => $setup_discountnum,
+  curr_value_recur    => $recur_discountnum,
+  disable_setup       => $disable_setup,
+  disable_recur       => $disable_recur,
+  disable_waive_setup => ($part_pkg->freq eq '0'),
+  setup_label         => ( $part_pkg->freq eq '0'
+                            ? emt('Discount')
+                            : emt('Setup fee discount')
+                         ),
+  recur_label         => emt('Recurring fee discount'),
 &>
   
 </TABLE>
@@ -81,7 +85,7 @@ if ( !$cust_pkg->get('setup') and $cust_pkg->base_setup > 0 ) {
   $disable_setup = 0;
 }
 my $disable_recur = 1;
-if ( $cust_pkg->base_recur > 0 ) {
+if ( $cust_pkg->base_recur > 0 && $part_pkg->freq ne '0' ) {
   $disable_recur = 0;
 }
 
diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi
index 39628ca..b28d225 100644
--- a/httemplate/edit/process/quick-charge.cgi
+++ b/httemplate/edit/process/quick-charge.cgi
@@ -123,21 +123,18 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
     'amount'        => $amount,
     'setup_cost'    => $setup_cost,
     'quantity'      => $quantity,
-    'bill_now'      => scalar($cgi->param('bill_now')),
-    'invoice_terms' => scalar($cgi->param('invoice_terms')),
     'start_date'    => ( scalar($cgi->param('start_date'))
                            ? parse_datetime($cgi->param('start_date'))
                            : ''
                        ),
-    'no_auto'       => scalar($cgi->param('no_auto')),
-    'separate_bill' => scalar($cgi->param('separate_bill')),
-    'pkg'           => scalar($cgi->param('pkg')),
-    'setuptax'      => scalar($cgi->param('setuptax')),
-    'taxclass'      => scalar($cgi->param('taxclass')),
-    'taxproductnum' => scalar($cgi->param('taxproductnum')),
     'tax_override'  => $override,
-    'classnum'      => scalar($cgi->param('classnum')),
     'additional'    => \@description,
+
+    map { $_ => scalar($cgi->param($_)), } qw(
+      bill_now invoice_terms no_auto separate_bill pkg
+      setuptax taxclass taxproductnum classnum
+      setup_discountnum setup_discountnum_amount setup_discountnum_percent
+    )
   );
 
   if ( $quotation ) {
diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html
index af6fd41..f7c956f 100644
--- a/httemplate/edit/quick-charge.html
+++ b/httemplate/edit/quick-charge.html
@@ -118,6 +118,9 @@ function bill_now_changed (what) {
 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
 
+<TABLE><TR><TD>
+
+<FONT CLASS="fsinnerbox-title"><% mt('Charge') |h %>
 <TABLE ID="QuickChargeTable" CLASS="fsinnerbox">
 
 % if ( $cust_pkg ) { #modify one-time charge
@@ -134,15 +137,15 @@ function bill_now_changed (what) {
   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 ( $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,
@@ -191,7 +194,7 @@ function bill_now_changed (what) {
         curr_value => $cust_pkg->get('separate_bill'),
       &>
       <TR>
-        <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
+        <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
         <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
       </TR>
 
@@ -201,7 +204,10 @@ function bill_now_changed (what) {
         'label' => emt('Tax product'),
         'curr_value' => $part_pkg->get('taxproductnum')
       &>
-% }
+%   }
+
+  </TABLE>
+  </TD></TR></TABLE>
 
 % } else { # new one-time charge
 
@@ -219,13 +225,6 @@ function bill_now_changed (what) {
     </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') ) {
@@ -243,98 +242,6 @@ function bill_now_changed (what) {
 
 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum  &>
 
-% unless ( $quotationnum ) {
-
-    <TR>
-      <TH ALIGN="right"><% mt('Invoice now') |h %></TH>
-      <TD>
-        <INPUT TYPE  = "checkbox"
-               NAME  = "bill_now"
-               VALUE = "1"
-               <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
-               onClick  = "bill_now_changed(this);"
-               onChange = "bill_now_changed(this);"
-        >
-        <% mt('with terms') |h %> 
-        <& /elements/select-terms.html,
-             'curr_value' => scalar($cgi->param('invoice_terms')),
-             'disabled'   => ( $cgi->param('bill_now') ? 0 : 1 ),
-             'agentnum'   => $cust_or_prospect->agentnum,
-        &>
-      </TD>
-    </TR>
-
-%   # false laziness w/misc/order_pkg.html
-    <TR>
-      <TH ALIGN="right"><% mt('Charge date') |h %> </TH>
-      <TD>
-        <INPUT TYPE  = "text"
-               NAME  = "start_date"
-               SIZE  = 32
-               ID    = "start_date_text"
-               VALUE = "<% $start_date %>"
-               onKeyPress="return enable_quick_charge(event)"
-               <% $cgi->param('bill_now')
-                    ? 'STYLE = "background-color:#dddddd" DISABLED'
-                    : ''
-               %>
-        >
-        <IMG SRC   = "<%$fsurl%>images/calendar.png"
-             ID    = "start_date_button"
-             TITLE = "<% mt('Select date') |h %>"
-             STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
-        >
-        <IMG SRC   = "<%$fsurl%>images/calendar-disabled.png"
-             ID    = "start_date_button_disabled"
-             <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
-        >
-        <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
-      </TD>
-    </TR>
-
-    <SCRIPT TYPE="text/javascript">
-      Calendar.setup({
-        inputField: "start_date_text",
-        ifFormat:   "<% $date_format %>",
-        button:     "start_date_button",
-        align:      "BR"
-      });
-    </SCRIPT>
-
-<& /elements/tr-checkbox.html,
-  label => emt('Invoice this charge separately'),
-  field => 'separate_bill',
-  value => 'Y'
-&>
-
-% }
-
-% if ( ! $quotationnum && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
-%   my $what = lc(FS::payby->shortname($cust_main->payby));
-    <TR>
-      <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
-      <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
-    </TR>
-% }
-
-<TR>
-  <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
-  <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
-</TR>
-
-<& /elements/tr-select-taxclass.html, 'curr_value' => scalar($cgi->param('taxclass')) &>
-
-<& /elements/tr-select-taxproduct.html,
-  'label'      => emt('Tax product'),
-  'curr_value' => scalar($cgi->param('taxproductnum')),
-&>
-
-<& /elements/tr-select-taxoverride.html,
-  'curr_value' => scalar($cgi->param('tax_override')),
-&>
-
-% } # if !$cust_pkg
-
 <TR>
   <TH ALIGN="right"><% mt('Description') |h %> </TH>
   <TD>
@@ -377,17 +284,9 @@ function bill_now_changed (what) {
 %   }
 % }
 
-
 </TABLE>
 
-<BR>
-% my $label = $cust_pkg
-%             ? emt('Modify one-time charge')
-%             : emt('Add one-time charge');
-<INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
-<% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
-
-</FORM>
+</TD>
 
 
 <SCRIPT TYPE="text/javascript">
@@ -449,6 +348,157 @@ function bill_now_changed (what) {
 
 </SCRIPT>
 
+
+% if ( $curuser->access_right('Edit package definition costs') ) {
+
+  <TD>
+
+    <FONT CLASS="fsinnerbox-title">Taxation</FONT>
+    <TABLE CLASS="fsinnerbox">
+
+    <TR>
+      <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
+      <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
+    </TR>
+
+    <& /elements/tr-select-taxclass.html, 'curr_value' => scalar($cgi->param('taxclass')) &>
+
+    <& /elements/tr-select-taxproduct.html,
+      'label'      => emt('Tax product'),
+      'curr_value' => scalar($cgi->param('taxproductnum')),
+    &>
+
+    <& /elements/tr-select-taxoverride.html,
+      'curr_value' => scalar($cgi->param('tax_override')),
+    &>
+
+    </TABLE>
+
+    <BR>
+    <FONT CLASS="fsinnerbox-title"><% mt('Cost Accounting') |h %>
+    <TABLE ID="QuickChargeTable" CLASS="fsinnerbox">
+
+    <& /elements/tr-input-text.html,
+         label  => mt('Cost'),
+         field  => 'setup_cost',
+         value  => $setup_cost,
+         size   => 8,
+         prefix => $money_char,
+    &> 
+
+    </TABLE>
+
+  </TD>
+
+% }
+
+</TR></TABLE>
+
+
+% if ( $curuser->access_right('Discount customer package') ) {
+    <BR>
+    <FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
+    <TABLE CLASS="fsinnerbox">
+      <& /elements/tr-select-pkg-discount.html,
+           'setup_label'         => emt('Discount'),
+           'disable_recur'       => 1,
+           'disable_waive_setup' => 1,
+      &>
+    </TABLE>
+% }
+
+
+% unless ( $quotationnum ) {
+
+    <BR>
+    <FONT CLASS="fsinnerbox-title"><% mt('Invoicing') |h %></FONT>
+    <TABLE CLASS="fsinnerbox">
+
+    <TR>
+      <TH ALIGN="right"><% mt('Invoice now') |h %></TH>
+      <TD>
+        <INPUT TYPE  = "checkbox"
+               NAME  = "bill_now"
+               VALUE = "1"
+               <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
+               onClick  = "bill_now_changed(this);"
+               onChange = "bill_now_changed(this);"
+        >
+        <FONT SIZE=-1><% mt('with terms') |h %></FONT>
+        <& /elements/select-terms.html,
+             'curr_value' => scalar($cgi->param('invoice_terms')),
+             'disabled'   => ( $cgi->param('bill_now') ? 0 : 1 ),
+             'agentnum'   => $cust_or_prospect->agentnum,
+        &>
+      </TD>
+    </TR>
+
+%   # false laziness w/misc/order_pkg.html
+    <TR>
+      <TH ALIGN="right"><% mt('Charge date') |h %> </TH>
+      <TD>
+        <INPUT TYPE  = "text"
+               NAME  = "start_date"
+               SIZE  = 32
+               ID    = "start_date_text"
+               VALUE = "<% $start_date %>"
+               onKeyPress="return enable_quick_charge(event)"
+               <% $cgi->param('bill_now')
+                    ? 'STYLE = "background-color:#dddddd" DISABLED'
+                    : ''
+               %>
+        >
+        <IMG SRC   = "<%$fsurl%>images/calendar.png"
+             ID    = "start_date_button"
+             TITLE = "<% mt('Select date') |h %>"
+             STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
+        >
+        <IMG SRC   = "<%$fsurl%>images/calendar-disabled.png"
+             ID    = "start_date_button_disabled"
+             <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
+        >
+        <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
+      </TD>
+    </TR>
+
+    <SCRIPT TYPE="text/javascript">
+      Calendar.setup({
+        inputField: "start_date_text",
+        ifFormat:   "<% $date_format %>",
+        button:     "start_date_button",
+        align:      "BR"
+      });
+    </SCRIPT>
+
+    <& /elements/tr-checkbox.html,
+      label => emt('Invoice this charge separately'),
+      field => 'separate_bill',
+      value => 'Y'
+    &>
+
+%   if (  $cust_main->has_cust_payby_auto ) {
+%     my $what = lc(FS::payby->shortname($cust_main->payby));
+      <TR>
+        <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
+        <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
+      </TR>
+%   }
+
+    </TABLE>
+
+% }
+
+% } # if !$cust_pkg
+
+<BR>
+% my $label = $cust_pkg
+%             ? emt('Modify one-time charge')
+%             : emt('Add one-time charge');
+<INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
+<% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
+
+</FORM>
+
 % if ( $quotationnum ) {
   <& /elements/footer.html &>
 % } else {
diff --git a/httemplate/elements/tr-select-pkg-discount.html b/httemplate/elements/tr-select-pkg-discount.html
index 0c57fd8..39b0ff3 100644
--- a/httemplate/elements/tr-select-pkg-discount.html
+++ b/httemplate/elements/tr-select-pkg-discount.html
@@ -3,10 +3,11 @@
 In order_pkg.html or similar:
 
 <& /elements/tr-select-pkg-discount.html,
-  curr_value_setup => ($cgi->param('setup_discountnum') || ''),
-  curr_value_recur => ($cgi->param('recur_discountnum') || ''),
-  disable_setup    => 0,
-  disable_recur    => 0,
+  curr_value_setup    => ($cgi->param('setup_discountnum') || ''),
+  curr_value_recur    => ($cgi->param('recur_discountnum') || ''),
+  disable_setup       => 0,
+  disable_recur       => 0,
+  disable_waive_setup => 0
 &>
 
 This provides the following:
@@ -31,9 +32,9 @@ description if curr_value_setup is set. Likewise "disable_recur".
 %      and !$opt{disable_setup} )
 % {
 %   my $pre_options = [ '' => '(none)' ];
-%   if ( $curuser->access_right('Waive setup fee') ) {
-%     push @$pre_options, -2 => 'Waive setup fee';
-%   }
+%   push @$pre_options, -2 => 'Waive setup fee'
+%     if $curuser->access_right('Waive setup fee')
+%     && ! $opt{'disable_waive_setup'};
 <& tr-td-label.html, label => $opt{setup_label} || emt('Setup fee') &>
   <td>
     <& select-discount.html,
@@ -68,7 +69,9 @@ description if curr_value_setup is set. Likewise "disable_recur".
 </tr>
 
 % } elsif ( $curuser->access_right('Waive setup fee')
-%           and !$opt{disable_setup} )
+%             && !$opt{disable_waive_setup}
+%             && !$opt{disable_setup}
+%         )
 % {
 
 <& tr-td-label.html, label => emt('Waive setup fee') &>

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

Summary of changes:
 FS/FS/cust_main.pm                              |   21 +-
 FS/FS/quotation.pm                              |   19 +-
 httemplate/edit/cust_pkg_discount.html          |   18 +-
 httemplate/edit/process/quick-charge.cgi        |   15 +-
 httemplate/edit/quick-charge.html               |  288 +++++++++++++----------
 httemplate/elements/tr-select-pkg-discount.html |   19 +-
 6 files changed, 224 insertions(+), 156 deletions(-)




More information about the freeside-commits mailing list