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') || ''),
12 This provides the following:
13 - If the user can waive setup fees or apply a discount, they get a
14 select box for the setup discount, with "Waive setup fee" as an option.
15 - If they can custom discount, they will also get "Custom discount" as an
16 option. If selected, this will show fields to enter the custom discount
18 - If they can waive setup fees but NOT apply a discount, they only get a
19 checkbox to waive setup fee.
20 - Same for recurring fee, but without the "waive setup fee" stuff, obviously.
21 - Custom recurring discounts also have an option for a duration in months.
23 "disable_setup" locks the setup discount, but will still show a static
24 description if curr_value_setup is set. Likewise "disable_recur".
29 % # select-discount knows about the "custom discount" ACL
30 % if ( $curuser->access_right('Discount customer package')
31 % and !$opt{disable_setup} )
33 % my $pre_options = [ '' => '(none)' ];
34 % if ( $curuser->access_right('Waive setup fee') ) {
35 % push @$pre_options, -2 => 'Waive setup fee';
37 <& tr-td-label.html, label => emt('Setup fee') &>
39 <& select-discount.html,
40 field => 'setup_discountnum',
41 id => 'setup_discountnum',
42 hashref => { disabled => '',
45 extra_sql => ' AND (percent > 0 OR months = 1)',
46 curr_value => $opt{'curr_value_setup'},
48 pre_options => $pre_options,
53 <tr class="setup_discount_custom">
55 <td>Amount <% $money_char %>
57 field => 'setup_discountnum_amount',
58 curr_value => ($cgi->param('setup_discountnum_amount') || ''),
63 field => 'setup_discountnum_percent',
64 curr_value => ($cgi->param('setup_discountnum_percent') || ''),
70 % } elsif ( $curuser->access_right('Waive setup fee')
71 % and !$opt{disable_setup} )
74 <& tr-td-label.html, label => emt('Waive setup fee') &>
77 field => 'setup_discountnum',
78 id => 'setup_discountnum',
80 curr_value => $opt{'curr_value_setup'},
85 % } elsif ( $opt{'curr_value_setup'} ) { # user can't do anything
87 % my $discount = FS::discount->by_key($opt{'curr_value_setup'});
89 <INPUT TYPE="hidden" NAME="setup_discountnum" VALUE="<% $opt{curr_value_setup} %>">
91 <% $discount->description_short %>
97 % if ( $curuser->access_right('Discount customer package')
98 % and !$opt{disable_recur} ) {
100 <& tr-td-label.html, label => emt('Recurring fee') &>
102 <& select-discount.html,
103 field => 'recur_discountnum',
104 id => 'recur_discountnum',
105 hashref => { disabled => '' },
106 curr_value => $opt{'curr_value_recur'},
112 <tr class="recur_discount_custom">
114 <td>Amount <% $money_char %>
116 field => 'recur_discountnum_amount',
117 curr_value => ($cgi->param('recur_discountnum_amount') || ''),
122 field => 'recur_discountnum_percent',
123 curr_value => ($cgi->param('recur_discountnum_percent') || ''),
128 <tr class="recur_discount_custom">
131 <& /elements/select-months.html,
132 field => 'recur_discountnum_months',
133 curr_value => ($cgi->param('recur_discountnum_months') || ''),
138 % } elsif ( $opt{'curr_value_recur'} ) {
140 % my $discount = FS::discount->by_key($opt{'curr_value_recur'});
142 <INPUT TYPE="hidden" NAME="recur_discountnum" VALUE="<% $opt{curr_value_recur} %>">
144 <% $discount->description %>
148 <SCRIPT TYPE="text/javascript">
149 $(document).ready(function() {
150 ['setup', 'recur'].forEach(function(x) {
151 var discountnum = $('#'+x+'_discountnum');
153 // if it's been set to a custom discount, show custom discount inputs
154 var discountnum_changed = function() {
155 var val = this.value;
156 var custom = $('.'+x+'_discount_custom');
164 discountnum.on('change', discountnum_changed);
165 discountnum.trigger('change');
167 // if amount contains a value, disable percent, and vice versa
168 var amount_percent_keyup = function(event) {
169 var other = event.data;
170 if (this.value.length > 0) {
171 other.disabled = true;
173 other.disabled = false;
176 var amount = $('#'+x+'_discountnum_amount');
177 var percent = $('#'+x+'_discountnum_percent');
178 amount.on('keyup', percent, amount_percent_keyup);
179 percent.on('keyup', amount, amount_percent_keyup);
181 amount.trigger('keyup');
182 percent.trigger('keyup');
189 'curr_value_setup' => ($cgi->param('setup_discountnum') || ''),
190 'curr_value_recur' => ($cgi->param('recur_discountnum') || ''),
193 my $curuser = $FS::CurrentUser::CurrentUser;
194 my $money_char = FS::Conf->new->config('money_char') || '$';