3 In order_pkg.html or similar:
5 <& /elements/tr-select-pkg-discount.html,
6 curr_value_setup => ($cgi->param('setup_discountnum') || ''),
7 curr_value_recur => ($cgi->param('recur_discountnum') || ''),
10 disable_waive_setup => 0
13 This provides the following:
14 - If the user can waive setup fees or apply a discount, they get a
15 select box for the setup discount, with "Waive setup fee" as an option.
16 - If they can custom discount, they will also get "Custom discount" as an
17 option. If selected, this will show fields to enter the custom discount
19 - If they can waive setup fees but NOT apply a discount, they only get a
20 checkbox to waive setup fee.
21 - Same for recurring fee, but without the "waive setup fee" stuff, obviously.
22 - Custom recurring discounts also have an option for a duration in months.
24 "disable_setup" locks the setup discount, but will still show a static
25 description if curr_value_setup is set. Likewise "disable_recur".
30 % # select-discount knows about the "custom discount" ACL
31 % if ( $curuser->access_right('Discount customer package')
32 % and !$opt{disable_setup} )
34 % my $pre_options = [ '' => '(none)' ];
35 % push @$pre_options, -2 => 'Waive setup fee'
36 % if $curuser->access_right('Waive setup fee')
37 % && ! $opt{'disable_waive_setup'};
38 <& tr-td-label.html, label => $opt{setup_label} || emt('Setup fee') &>
40 <& select-discount.html,
41 field => 'setup_discountnum',
42 id => 'setup_discountnum',
43 hashref => { disabled => '',
46 extra_sql => ' AND (percent > 0 OR months = 1)',
47 curr_value => $opt{'curr_value_setup'},
49 pre_options => $pre_options,
54 <tr class="setup_discount_custom">
56 <td>Amount <% $money_char %>
58 field => 'setup_discountnum_amount',
59 curr_value => ($cgi->param('setup_discountnum_amount') || ''),
64 field => 'setup_discountnum_percent',
65 curr_value => ($cgi->param('setup_discountnum_percent') || ''),
71 % } elsif ( $curuser->access_right('Waive setup fee')
72 % && !$opt{disable_waive_setup}
73 % && !$opt{disable_setup}
77 <& tr-td-label.html, label => emt('Waive setup fee') &>
80 field => 'setup_discountnum',
81 id => 'setup_discountnum',
83 curr_value => $opt{'curr_value_setup'},
88 % } elsif ( $opt{'curr_value_setup'} ) { # user can't do anything
90 % my $discount = FS::discount->by_key($opt{'curr_value_setup'});
92 <INPUT TYPE="hidden" NAME="setup_discountnum" VALUE="<% $opt{curr_value_setup} %>">
94 <% $discount->description_short %>
100 % if ( $curuser->access_right('Discount customer package')
101 % and !$opt{disable_recur} ) {
103 <& tr-td-label.html, label => $opt{recur_label} || emt('Recurring fee') &>
105 <& select-discount.html,
106 field => 'recur_discountnum',
107 id => 'recur_discountnum',
108 hashref => { disabled => '' },
109 curr_value => $opt{'curr_value_recur'},
115 <tr class="recur_discount_custom">
117 <td>Amount <% $money_char %>
119 field => 'recur_discountnum_amount',
120 curr_value => ($cgi->param('recur_discountnum_amount') || ''),
125 field => 'recur_discountnum_percent',
126 curr_value => ($cgi->param('recur_discountnum_percent') || ''),
131 <tr class="recur_discount_custom">
134 <& /elements/select-months.html,
135 field => 'recur_discountnum_months',
136 curr_value => ($cgi->param('recur_discountnum_months') || ''),
141 % } elsif ( $opt{'curr_value_recur'} ) {
143 % my $discount = FS::discount->by_key($opt{'curr_value_recur'});
145 <INPUT TYPE="hidden" NAME="recur_discountnum" VALUE="<% $opt{curr_value_recur} %>">
147 <% $discount->description %>
151 <SCRIPT TYPE="text/javascript">
152 $(document).ready(function() {
153 ['setup', 'recur'].forEach(function(x) {
154 var discountnum = $('#'+x+'_discountnum');
156 // if it's been set to a custom discount, show custom discount inputs
157 var discountnum_changed = function() {
158 var val = this.value;
159 var custom = $('.'+x+'_discount_custom');
167 discountnum.on('change', discountnum_changed);
168 discountnum.trigger('change');
170 // if amount contains a value, disable percent, and vice versa
171 var amount_percent_keyup = function(event) {
172 var other = event.data;
173 if (this.value.length > 0) {
174 other.disabled = true;
176 other.disabled = false;
179 var amount = $('#'+x+'_discountnum_amount');
180 var percent = $('#'+x+'_discountnum_percent');
181 amount.on('keyup', percent, amount_percent_keyup);
182 percent.on('keyup', amount, amount_percent_keyup);
184 amount.trigger('keyup');
185 percent.trigger('keyup');
192 'curr_value_setup' => ($cgi->param('setup_discountnum') || ''),
193 'curr_value_recur' => ($cgi->param('recur_discountnum') || ''),
196 my $curuser = $FS::CurrentUser::CurrentUser;
197 my $money_char = FS::Conf->new->config('money_char') || '$';