From 1d61483cd82a5d2dd59a2218ea85b4f8773e177e Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Mon, 3 Apr 2017 17:23:57 -0700 Subject: [PATCH] discounts on one-time charges< RT#75448 --- 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(-) diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 806db00bd..f4990a418 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -3267,6 +3267,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}; @@ -3287,6 +3288,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 = ''; @@ -3350,13 +3354,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 c61e001c6..2f95425cc 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 79c347813..173922133 100755 --- a/httemplate/edit/cust_pkg_discount.html +++ b/httemplate/edit/cust_pkg_discount.html @@ -18,12 +18,16 @@ <& /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'), &> @@ -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 39628cae7..b28d22530 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 2d38203fa..0045b1fb7 100644 --- a/httemplate/edit/quick-charge.html +++ b/httemplate/edit/quick-charge.html @@ -118,6 +118,9 @@ function bill_now_changed (what) { +
+ +<% mt('Charge') |h %> % 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'), &> - + @@ -201,7 +204,10 @@ function bill_now_changed (what) { 'label' => emt('Tax product'), 'curr_value' => $part_pkg->get('taxproductnum') &> -% } +% } + +
<% mt('Tax exempt') |h %> <% mt('Tax exempt') |h %> param('setuptax') ? 'CHECKED' : '' %>>
+
% } else { # new one-time charge @@ -219,13 +225,6 @@ function bill_now_changed (what) { % 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 ) { - - - <% mt('Invoice now') |h %> - - 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, - &> - - - -% # false laziness w/misc/order_pkg.html - - <% mt('Charge date') |h %> - - param('bill_now') - ? 'STYLE = "background-color:#dddddd" DISABLED' - : '' - %> - > - - param('bill_now') ? '' : 'STYLE="display:none"' %> - > - (<% mt('leave blank to charge immediately') |h %>) - - - - - -<& /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)); - - <% mt("Disable automatic $what charge") |h %> - - -% } - - - <% mt('Tax exempt') |h %> - param('setuptax') ? 'CHECKED' : '' %>> - - -<& /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 - <% mt('Description') |h %> @@ -377,17 +284,9 @@ function bill_now_changed (what) { % } % } - -
-% my $label = $cust_pkg -% ? emt('Modify one-time charge') -% : emt('Add one-time charge'); -param('error') || $cust_pkg) ? '' :' DISABLED' %>> - - + + +% if ( $curuser->access_right('Edit package definition costs') ) { + + + + Taxation + + + + + + + + <& /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')), + &> + +
<% mt('Tax exempt') |h %> param('setuptax') ? 'CHECKED' : '' %>>
+ +
+ <% mt('Cost Accounting') |h %> + + + <& /elements/tr-input-text.html, + label => mt('Cost'), + field => 'setup_cost', + value => $setup_cost, + size => 8, + prefix => $money_char, + &> + +
+ + + +% } + + + + +% if ( $curuser->access_right('Discount customer package') ) { +
+ <% mt('Discounting') |h %> + + <& /elements/tr-select-pkg-discount.html, + 'setup_label' => emt('Discount'), + 'disable_recur' => 1, + 'disable_waive_setup' => 1, + &> +
+% } + + +% unless ( $quotationnum ) { + +
+ <% mt('Invoicing') |h %> + + + + + + + +% # false laziness w/misc/order_pkg.html + + + + + + + + <& /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)); + + + + +% } + +
<% mt('Invoice now') |h %> + 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, + &> +
<% mt('Charge date') |h %> + param('bill_now') + ? 'STYLE = "background-color:#dddddd" DISABLED' + : '' + %> + > + + param('bill_now') ? '' : 'STYLE="display:none"' %> + > + (<% mt('leave blank to charge immediately') |h %>) +
<% mt("Disable automatic $what charge") |h %>
+ +% } + +% } # if !$cust_pkg + +
+% my $label = $cust_pkg +% ? emt('Modify one-time charge') +% : emt('Add one-time charge'); +param('error') || $cust_pkg) ? '' :' DISABLED' %>> + + + %my %footer_args = ( % formvalidation => { % QuickChargeForm => { diff --git a/httemplate/elements/tr-select-pkg-discount.html b/httemplate/elements/tr-select-pkg-discount.html index 0c57fd89e..39b0ff31f 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') &> <& select-discount.html, @@ -68,7 +69,9 @@ description if curr_value_setup is set. Likewise "disable_recur". % } 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') &> -- 2.11.0