1 % if ( scalar(@{ $opt{'discount'} }) == 0
2 % && ! $curuser->access_right('Custom discount customer package') ) {
4 <INPUT TYPE="hidden" NAME="<% $name %>" VALUE="<% $discountnum %>">
9 <TD ALIGN="right" WIDTH="176"><% $opt{'label'} || '<B>Discount</B>' %></TD>
11 <% include( '/elements/select-discount.html',
12 'curr_value' => $discountnum,
13 'onchange' => $onchange,
20 % # a weird kind of false laziness w/edit/discount.html
22 % # <INPUT TYPE="hidden" NAME="<% $name %>_disabled" VALUE="Y">
25 <% include( '/elements/tr-select.html',
26 'label' => '<B>Discount Type</B>',
27 'field' => $name. '__type',
28 'id' => $name. '__type',
29 'options' => \@_type_options,
30 'curr_value' => scalar($cgi->param($name.'__type')),
31 'onchange' => $name.'__type_changed',
32 'colspan' => $opt{'colspan'},
36 <% include( '/elements/tr-input-money.html',
37 'label' => '<B>Discount Amount </B>',
38 'field' => $name. '_amount',
39 'id' => $name. '_amount',
41 'curr_value' => scalar($cgi->param($name.'_amount')),
42 'colspan' => $opt{'colspan'},
46 <% include( '/elements/tr-input-percentage.html',
47 'label' => '<B>Discount Percentage</B>',
48 'field' => $name. '_percent',
49 'id' => $name. '_percent',
51 'curr_value' => scalar($cgi->param($name.'_percent')),
52 'colspan' => $opt{'colspan'},
56 <% include( '/elements/tr-input-text.html',
57 'label' => '<B>Discount duration (months)</B>',
58 'field' => $name. '_months',
59 'id' => $name. '_months',
61 'postfix' => qq(<FONT SIZE="-1" ID="${name}_months_postfix"><I>(blank for non-expiring discount)</I></FONT>),
62 'curr_value' => scalar($cgi->param($name.'_months')),
63 'colspan' => $opt{'colspan'},
67 <SCRIPT TYPE="text/javascript">
69 % my $ge = 'document.getElementById';
71 function <% $name %>_changed(what) {
72 var <% $name %> = what.options[what.selectedIndex].value;
74 if ( <% $name %> == '-1' ) {
75 <% $ge %>('<% $name %>__type_label0').style.display = '';
76 <% $ge %>('<% $name %>__type_label0').style.visibility = '';
77 <% $ge %>('<% $name %>__type').style.display = '';
78 <% $ge %>('<% $name %>__type').style.visibility = '';
79 % #XXX retrieve previous visibility for amount, percent :/
80 <% $ge %>('<% $name %>_months_label0').style.display = '';
81 <% $ge %>('<% $name %>_months_label0').style.visibility = '';
82 <% $ge %>('<% $name %>_months').style.display = '';
83 <% $ge %>('<% $name %>_months').style.visibility = '';
84 <% $ge %>('<% $name %>_months_postfix').style.display = '';
85 <% $ge %>('<% $name %>_months_postfix').style.visibility = '';
88 <% $ge %>('<% $name %>__type_label0').style.display = 'none';
89 <% $ge %>('<% $name %>__type_label0').style.visibility = 'hidden';
90 <% $ge %>('<% $name %>__type').style.display = 'none';
91 <% $ge %>('<% $name %>__type').style.visibility = 'hidden';
93 % #XXX save visibility settings for amount, percent :/
94 <% $ge %>('<% $name %>_amount_label0').style.display = 'none';
95 <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden';
96 <% $ge %>('<% $name %>_amount_input0').style.display = 'none';
97 <% $ge %>('<% $name %>_amount_input0').style.visibility = 'hidden';
98 <% $ge %>('<% $name %>_amount_input0').style.display = 'none';
99 <% $ge %>('<% $name %>_amount_input0').style.visibility = 'hidden';
100 <% $ge %>('<% $name %>_percent_label0').style.display = 'none';
101 <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden';
102 <% $ge %>('<% $name %>_percent_input0').style.display = 'none';
103 <% $ge %>('<% $name %>_percent_input0').style.visibility = 'hidden';
104 <% $ge %>('<% $name %>_percent_input0').style.display = 'none';
105 <% $ge %>('<% $name %>_percent_input0').style.visibility = 'hidden';
107 <% $ge %>('<% $name %>_months_label0').style.display = 'none';
108 <% $ge %>('<% $name %>_months_label0').style.visibility = 'hidden';
109 <% $ge %>('<% $name %>_months').style.display = 'none';
110 <% $ge %>('<% $name %>_months').style.visibility = 'hidden';
111 <% $ge %>('<% $name %>_months_postfix').style.display = 'none';
112 <% $ge %>('<% $name %>_months_postfix').style.visibility = 'hidden';
118 function <% $name %>__type_changed(what) {
119 var <% $name %>__type = what.options[what.selectedIndex].value;
121 if ( <% $name %>__type == '<% $select %>' ) {
122 <% $ge %>('<% $name %>_amount_label0').style.display = 'none';
123 <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden';
124 <% $ge %>('<% $name %>_amount').style.display = 'none';
125 <% $ge %>('<% $name %>_amount').style.visibility = 'hidden';
126 <% $ge %>('<% $name %>_percent_label0').style.display = 'none';
127 <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden';
128 <% $ge %>('<% $name %>_percent').style.display = 'none';
129 <% $ge %>('<% $name %>_percent').style.visibility = 'hidden';
130 } else if ( <% $name %>__type == 'Amount' ) {
131 <% $ge %>('<% $name %>_amount_label0').style.display = '';
132 <% $ge %>('<% $name %>_amount_label0').style.visibility = '';
133 <% $ge %>('<% $name %>_amount_input0').style.display = '';
134 <% $ge %>('<% $name %>_amount_input0').style.visibility = '';
135 <% $ge %>('<% $name %>_percent_label0').style.display = 'none';
136 <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden';
137 <% $ge %>('<% $name %>_percent_input0').style.display = 'none';
138 <% $ge %>('<% $name %>_percent_input0').style.visibility = 'hidden';
139 } else if ( <% $name %>__type == 'Percentage' ) {
140 <% $ge %>('<% $name %>_amount_label0').style.display = 'none';
141 <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden';
142 <% $ge %>('<% $name %>_amount_input0').style.display = 'none';
143 <% $ge %>('<% $name %>_amount_input0').style.visibility = 'hidden';
144 <% $ge %>('<% $name %>_percent_label0').style.display = '';
145 <% $ge %>('<% $name %>_percent_label0').style.visibility = '';
146 <% $ge %>('<% $name %>_percent_input0').style.display = '';
147 <% $ge %>('<% $name %>_percent_input0').style.visibility = '';
152 <% $name %>_changed(<% $ge %>('<% $name %>'));
160 my $cgi = $opt{'cgi'};
161 my $discountnum = $opt{'curr_value'} || $opt{'value'};
163 $opt{'discount'} ||= [ qsearch( 'discount', { disabled=>'' } ) ];
165 my $curuser = $FS::CurrentUser::CurrentUser;
167 my $name = $opt{'element_name'} || $opt{'field'} || 'discountnum';
169 my $select = 'Select discount type';
171 my @_type_options = ( 'Amount', 'Percentage' );
172 unshift @_type_options, $select;
174 my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';
176 my $onchange = ( $opt{'onchange'} ? delete($opt{'onchange'}).';' : '' ).
177 $name.'_changed(this);';