This commit was generated by cvs2svn to compensate for changes in r8593,
[freeside.git] / httemplate / edit / quick-charge.html
1 <% include("/elements/header-popup.html", 'One-time charge', '',
2             ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
3           )
4 %>
5
6 <LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
7 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
8 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
9 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
10
11 <% include('/elements/error.html') %>
12
13 <SCRIPT TYPE="text/javascript">
14
15 function enable_quick_charge () {
16   if (    document.QuickChargeForm.amount.value
17        && document.QuickChargeForm.pkg.value    ) {
18     document.QuickChargeForm.submit.disabled = false;
19   } else {
20     document.QuickChargeForm.submit.disabled = true;
21   }
22 }
23
24 function validate_quick_charge () {
25   var pkg = document.QuickChargeForm.pkg.value;
26   var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
27   var amount = document.QuickChargeForm.amount.value;
28   var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
29   var rval = true;
30
31   if ( ! amount_regex.test(amount) ) {
32     alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
33     return false;
34   }
35   if ( String(pkg).length < 1 ) {
36     rval = false;
37   }
38   if ( ! pkg_regex.test(pkg) ) {
39     rval = false;
40   }
41   var i=0;
42   for (i=0; i < rownum; i++) {
43     if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
44       rval = false;
45       break;
46     }
47   }
48   if (rval == true) {
49     return true;
50   }
51
52   if ( ! pkg ) {
53     alert('Enter a description for the one-time charge');
54     return false;
55   }
56
57   alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
58   return false;
59 }
60
61 function bill_now_changed (what) {
62   var form = what.form;
63   if ( what.checked ) {
64     form.start_date_text.disabled = true;
65     form.start_date.style.backgroundColor = '#dddddd';
66     form.start_date_button.style.display = 'none';
67     form.start_date_button_disabled.style.display = '';
68     form.invoice_terms.disabled = false;
69   } else {
70     form.start_date_text.disabled = false;
71     form.start_date.style.backgroundColor = '#ffffff';
72     form.start_date_button.style.display = '';
73     form.start_date_button_disabled.style.display = 'none';
74     form.invoice_terms.disabled = true;
75   }
76 }
77
78 </SCRIPT>
79
80 <FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">
81
82 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
83
84 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
85
86 <TR>
87   <TD ALIGN="right">Amount </TD>
88   <TD>
89     $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
90   </TD>
91 </TR>
92
93 % if ( $conf->exists('invoice-unitprice') ) {
94     <TR>
95       <TD ALIGN="right">Quantity </TD>
96       <TD>
97         <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
98       </TD>
99     </TR>
100 % }
101
102 <% include('/elements/tr-select-pkg_class.html', 'curr_value' => $cgi->param('classnum') ) %>
103
104 <TR>
105   <TD ALIGN="right">Invoice now</TD>
106   <TD>
107     <INPUT TYPE  = "checkbox"
108            NAME  = "bill_now"
109            VALUE = "1"
110            <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
111            onChange = "bill_now_changed(this);"
112     >
113     with terms 
114     <% include('/elements/select-terms.html',
115                  'curr_value'  => scalar($cgi->param('invoice_terms')),
116                  'empty_value' => $default_terms,
117                  'disabled'    => ( $cgi->param('bill_now') ? 0 : 1 ),
118               )
119     %>
120   </TD>
121 </TR>
122
123 %# false laziness w/misc/order_pkg.html
124 <TR>
125   <TD ALIGN="right">Charge date </TD>
126   <TD>
127     <INPUT TYPE  = "text"
128            NAME  = "start_date"
129            SIZE  = 32
130            ID    = "start_date_text"
131            VALUE = "<% $start_date %>"
132            <% $cgi->param('bill_now') ? 'STYLE = "background-color:#dddddd" DISABLED' : '' %>
133     >
134     <IMG SRC   = "<%$fsurl%>images/calendar.png"
135          ID    = "start_date_button"
136          TITLE = "Select date"
137          STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
138     >
139     <IMG SRC   = "<%$fsurl%>images/calendar-disabled.png"
140          ID    = "start_date_button_disabled"
141          <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
142     >
143     <FONT SIZE=-1>(leave blank to charge immediately)</FONT>
144   </TD>
145 </TR>
146
147 <SCRIPT TYPE="text/javascript">
148   Calendar.setup({
149     inputField: "start_date_text",
150     ifFormat:   "%m/%d/%Y",
151     button:     "start_date_button",
152     align:      "BR"
153   });
154 </SCRIPT>
155
156
157 <TR>
158   <TD ALIGN="right">Tax exempt </TD>
159   <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
160 </TR>
161
162 <% include('/elements/tr-select-taxclass.html', 'curr_value' => $cgi->param('taxclass') ) %>
163
164 <% include('/elements/tr-select-taxproduct.html', 'label' => 'Tax product', 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') ) %>
165
166 <% include('/elements/tr-select-taxoverride.html', 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') ) %>
167
168 <TR>
169   <TD ALIGN="right">Description </TD>
170   <TD>
171     <INPUT TYPE="text" NAME="pkg" SIZE="50" MAXLENGTH="50" VALUE="<% $pkg %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
172   </TD>
173 </TR>
174
175 <TR>
176   <TD></TD>
177   <TD><FONT SIZE="-1">Optional additional description (also printed on invoice): </FONT></TD>
178 </TR>
179
180 % my $row = 0;
181 %   if ( $cgi->param('error') || $cgi->param('magic') ) {
182 %     my $param = $cgi->Vars;
183 %
184 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) { 
185
186     <TR>
187       <TD></TD>
188       <TD>
189         <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} |h %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
190       </TD>
191     </TR>
192 % } 
193 % } 
194
195
196 </TABLE>
197
198 <BR>
199 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add one-time charge" <% $cgi->param('error') ? '' :' DISABLED' %>>
200
201 </FORM>
202
203
204 <SCRIPT TYPE="text/javascript">
205
206   var rownum = <% $row %>;
207
208   function possiblyAddRow() {
209     if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
210       addRow();
211     }
212   }
213
214   function addRow() {
215
216     var table = document.getElementById('QuickChargeTable');
217     var tablebody = table.getElementsByTagName('tbody').item(0);
218
219     var row = document.createElement('TR');
220
221     var empty_cell = document.createElement('TD');
222     row.appendChild(empty_cell);
223
224     var description_cell = document.createElement('TD');
225
226       var description_input = document.createElement('INPUT');
227       description_input.setAttribute('name', 'description'+rownum);
228       description_input.setAttribute('id',   'description'+rownum);
229       description_input.setAttribute('size', 60);
230       description_input.setAttribute('maxLength', 65);
231       description_input.setAttribute('rownum',   rownum);
232       description_input.onkeyup = possiblyAddRow;
233       description_cell.appendChild(description_input);
234
235     row.appendChild(description_cell);
236
237     tablebody.appendChild(row);
238
239     rownum++;
240
241   }
242
243 </SCRIPT>
244
245 </BODY>
246 </HTML>
247 <%init>
248
249 die "access denied"
250   unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
251
252 my $conf = new FS::Conf;
253
254 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
255 my $custnum = $1;
256 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); #XXX agent-virt
257
258 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
259 my $start_date = $cust_main->next_bill_date;
260 $start_date = $start_date ? time2str($format, $start_date) : '';
261
262 my $amount = '';
263 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
264   $amount = $1;
265 }
266
267 my $quantity = 1;
268 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
269   $quantity = $1;
270 }
271
272 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ 
273   or die 'illegal description';
274 my $pkg = $1;
275
276 my $default_terms;
277 if ( $cust_main->invoice_terms ) {
278   $default_terms = 'Customer default ('. $cust_main->invoice_terms. ')';
279 } else {
280   $default_terms =
281     'Default ('.
282        ($conf->config('invoice_default_terms') || 'Payable upon receipt').
283     ')';
284 }
285
286 </%init>