Will things ever be the same again?
[freeside.git] / httemplate / misc / batch-cust_pay.html
1 <% include("/elements/header.html", 'Quick payment entry',
2             menubar(
3                      'Main Menu' => $p, #popurl(1),
4                    ),
5             ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
6           )
7 %>
8 % if ( $cgi->param('error') ) { 
9
10   <FONT SIZE="+1" COLOR="#ff0000"><% $cgi->param('error') %></FONT><BR><BR>
11 % } 
12
13
14
15 <FORM ACTION="process/batch-cust_pay.cgi" NAME="OneTrueForm" METHOD="POST" onsubmit="document.OneTrueForm.submit.disabled=true;">
16
17 <!-- <B>Batch</B> <INPUT TYPE="text" NAME="paybatch"><BR><BR> -->
18
19 <SCRIPT TYPE="text/javascript">
20
21   function clearhint_custnum() {
22
23     //this.style.color = '#000000';
24
25     if ( this.value == 'Not found' || this.value == 'Multiple' ) {
26       this.value = '';
27       this.style.color = '#000000';
28     }
29
30   }
31
32   function clearhint_customer() {
33
34     this.style.color = '#000000';
35
36     if ( this.value == '(last name or company)' || this.value == 'Not found' )
37       this.value = '';
38
39   }
40
41   function search_custnum() {
42
43     this.style.color = '#000000'
44
45     var custnum_obj = this;
46     var searchrow = this.getAttribute('rownum');
47     var custnum = this.value;
48
49     if ( custnum == 'searching...' || custnum == 'Not found' || custnum == '' )
50       return;
51
52     if ( this.getAttribute('magic') == 'nosearch' ) {
53       this.setAttribute('magic', '');
54       return;
55     }
56
57     if ( ( rownum - searchrow ) == 1 ) {
58       addRow();
59     }
60     var customer = document.getElementById('customer'+searchrow);
61     customer.value = 'searching...';
62     customer.disabled = true;
63     customer.style.color = '#000000';
64     customer.style.backgroundColor = '#dddddd';
65
66     var customer_select = document.getElementById('cust_select'+searchrow);
67
68     //alert('search for custnum ' + custnum + ', row#' + searchrow );
69
70     customer.style.display = '';
71     customer_select.style.display = 'none';
72
73     function search_custnum_update(name) {
74
75       var name = eval('(' + name + ')' );
76
77       customer.disabled = false;
78       customer.style.backgroundColor = '#ffffff';
79
80       if ( name.length > 0 ) {
81         //alert('custnum found: ' + name);
82         customer.value = name;
83         customer.setAttribute('magic', 'nosearch');
84       } else {
85         customer.value = 'Not found';
86         customer.style.color = '#ff0000';
87         custnum_obj.style.color = '#ff0000';
88
89       }
90
91     }
92
93     custnum_search( custnum, search_custnum_update );
94
95   }
96
97   function search_customer() {
98
99     var customer_obj = this;
100     var searchrow = this.getAttribute('rownum');
101     var customer = this.value;
102
103     if ( customer == 'searching...' || customer == 'Not found' || customer == '' )
104       return;
105
106     if ( this.getAttribute('magic') == 'nosearch' ) {
107       this.setAttribute('magic', '');
108       return;
109     }
110
111     if ( ( rownum - searchrow ) == 1 ) {
112       addRow();
113     }
114
115     var custnum_obj = document.getElementById('custnum'+searchrow);
116     custnum_obj.value = 'searching...';
117     custnum_obj.disabled = true;
118     custnum_obj.style.color = '#000000';
119     custnum_obj.style.backgroundColor = '#dddddd';
120
121     var customer_select = document.getElementById('cust_select'+searchrow);
122
123     //alert('search for customer ' + customer + ', row#' + searchrow );
124
125     function search_customer_update(customers) {
126
127       //alert('customers returned: ' + customers);
128
129       var customerArray = eval('(' + customers + ')');
130
131       custnum_obj.disabled = false;
132       custnum_obj.style.backgroundColor = '#ffffff';
133
134       if ( customerArray.length == 0 ) {
135
136         custnum_obj.value = 'Not found';
137         custnum_obj.style.color = '#ff0000';
138         customer_obj.style.color = '#ff0000';
139
140         customer_obj.style.display = '';
141         customer_select.style.display = 'none';
142
143
144       } else if ( customerArray.length == 1 ) {
145
146         //alert('one customer found: ' + customerArray[0]);
147
148         custnum_obj.value = customerArray[0][0];
149         customer_obj.value = customerArray[0][1];
150
151         customer_obj.style.display = '';
152         customer_select.style.display = 'none';
153
154
155       } else {
156
157         custnum_obj.value = 'Multiple'; // or something
158         custnum_obj.style.color = '#ff0000';
159
160         //alert('multiple customers found, have to create select dropdown');
161
162         //blank the current list
163         for ( var i = customer_select.length; i >= 0; i-- )
164           customer_select.options[i] = null;
165
166         opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000');
167
168         //add the multiple customers
169         for ( var s = 0; s < customerArray.length; s++ )
170           opt(customer_select, customerArray[s][0], customerArray[s][1], '#000000');
171
172         opt(customer_select, 'cancel', '(Edit search string)', '#000000');
173
174         customer_obj.style.display = 'none';
175
176         customer_select.style.display = '';
177
178       }
179
180     }
181
182     smart_search( customer, search_customer_update );
183
184   }
185
186   function select_customer() {
187
188     var custnum = this.options[this.selectedIndex].value;
189     var customer = this.options[this.selectedIndex].text;
190
191     var searchrow = this.getAttribute('rownum');
192     var custnum_obj = document.getElementById('custnum'+searchrow);
193     var customer_obj = document.getElementById('customer'+searchrow);
194
195     if ( custnum == '' ) {
196       //this.style.color = '#ff0000';
197
198     } else if ( custnum == 'cancel' ) {
199
200       custnum_obj.value = '';
201       custnum_obj.style.color = '#000000';
202
203       this.style.display = 'none';
204       customer_obj.style.display = '';
205       customer_obj.focus();
206
207     } else {
208
209
210       custnum_obj.value = custnum;
211       custnum_obj.style.color = '#000000';
212
213       customer_obj.value = customer;
214       customer_obj.style.color = '#000000';
215
216       this.style.display = 'none';
217       customer_obj.style.display = '';
218
219     }
220
221   }
222
223   function opt(what,value,text,color) {
224     var optionName = new Option(text, value, false, false);
225     optionName.style.color = color;
226     var length = what.length;
227     what.options[length] = optionName;
228   }
229
230 </SCRIPT>
231
232 <TABLE ID="OneTrueTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
233
234 <TR>
235   <TH>Cust #</TH>
236   <TH>Customer</TH>
237   <TH>Amount</TH>
238   <TH>Check #</TH>
239   <TH BGCOLOR="#e8e8e8"></TH>
240 </TR>
241 % my $row = 0;
242 %   if ( $cgi->param('error') ) {
243 %     my $param = $cgi->Vars;
244 %
245 % for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { 
246
247
248     <TR>
249
250       <TD>
251         <INPUT TYPE="text" NAME="custnum<% $row %>" ID="custnum<% $row %>" SIZE=8 MAXLENGTH=12 VALUE="<% $param->{"custnum$row"} %>" rownum="<% $row %>">
252           <SCRIPT TYPE="text/javascript">
253             var custnum_input<% $row %> = document.getElementById("custnum<% $row %>");
254             custnum_input<% $row %>.onfocus = clearhint_custnum;
255             custnum_input<% $row %>.onchange = search_custnum;
256           </SCRIPT>
257       </TD>
258
259       <TD>
260         <INPUT TYPE="text" NAME="customer<% $row %>" ID="customer<% $row %>" SIZE=64 VALUE="<% $param->{"customer$row"} %>" rownum="<% $row %>">
261           <SCRIPT TYPE="text/javascript">
262             var customer_input<% $row %> = document.getElementById("customer<% $row %>");
263             customer_input<% $row %>.onfocus = clearhint_customer;
264             customer_input<% $row %>.onclick = clearhint_customer;
265             customer_input<% $row %>.onchange = search_customer;
266           </SCRIPT>
267         <SELECT NAME="cust_select<% $row %>" ID="cust_select<% $row %>" rownum="<% $row %>" STYLE="color:#ff0000; display:none">
268         </SELECT>
269           <SCRIPT TYPE="text/javascript">
270             var customer_select<% $row %> = document.getElementById("cust_select<% $row %>");
271             customer_select<% $row %>.onchange = select_customer;
272           </SCRIPT>
273       </TD>
274
275       <TD>
276         $<INPUT TYPE="text" NAME="paid<% $row %>" SIZE=8 MAXLENGTH=8 VALUE="<% $param->{"paid$row"} %>" >
277       </TD>
278
279       <TD>
280         <INPUT TYPE="text" NAME="payinfo<% $row %>" SIZE=10 VALUE="<% $param->{"payinfo$row"} %>" >
281       </TD>
282
283       <TD BGCOLOR="#e8e8e8">
284 % if ( $param->{"error$row"} ) { 
285
286         <FONT SIZE="-1" COLOR="#ff0000">Error: <% $param->{"error$row"} %></FONT>
287 % } 
288
289       </TD>
290
291     </TR>
292 % } 
293 % } 
294
295
296 </TABLE>
297
298 <!-- <BR>
299 <INPUT TYPE="button" VALUE="TEST addrow" onclick="addRow()"> -->
300
301 <BR>
302 <INPUT TYPE="submit" NAME="submit" VALUE="Post payment batch">
303
304 </FORM>
305
306
307 <% include('/elements/xmlhttp.html',
308               'url'  => $p. 'misc/xmlhttp-cust_main-search.cgi',
309               'subs' => [qw( custnum_search smart_search )],
310            )
311 %>
312
313 <SCRIPT TYPE="text/javascript">
314
315   var rownum = <% $row %>;
316
317   function addRow() {
318
319     var table = document.getElementById('OneTrueTable');
320     var tablebody = table.getElementsByTagName('tbody').item(0);
321
322     var row = document.createElement('TR');
323
324     var custnum_cell = document.createElement('TD');
325
326       var custnum_input = document.createElement('INPUT');
327       custnum_input.setAttribute('name', 'custnum'+rownum);
328       custnum_input.setAttribute('id',   'custnum'+rownum);
329       custnum_input.setAttribute('size', 8);
330       custnum_input.setAttribute('maxlength', 12);
331       custnum_input.setAttribute('rownum', rownum);
332       custnum_input.onfocus = clearhint_custnum;
333       custnum_input.onchange = search_custnum;
334       custnum_cell.appendChild(custnum_input);
335
336     row.appendChild(custnum_cell);
337
338     var customer_cell = document.createElement('TD');
339
340       var customer_input = document.createElement('INPUT');
341       customer_input.setAttribute('name', 'customer'+rownum);
342       customer_input.setAttribute('id',   'customer'+rownum);
343       customer_input.setAttribute('size', 64);
344       customer_input.setAttribute('value', '(last name or company)' );
345       customer_input.setAttribute('rownum', rownum);
346       customer_input.onfocus = clearhint_customer;
347       customer_input.onclick = clearhint_customer;
348       customer_input.onchange = search_customer;
349       customer_cell.appendChild(customer_input);
350
351       var customer_select = document.createElement('SELECT');
352       customer_select.setAttribute('name', 'cust_select'+rownum);
353       customer_select.setAttribute('id',   'cust_select'+rownum);
354       customer_select.setAttribute('rownum', rownum);
355       customer_select.style.color = '#ff0000';
356       customer_select.style.display = 'none';
357       customer_select.onchange = select_customer;
358       customer_cell.appendChild(customer_select);
359
360     row.appendChild(customer_cell);
361
362     var paid_cell = document.createElement('TD');
363
364       var paid_text = document.createTextNode('$');
365       paid_cell.appendChild(paid_text);
366
367       var paid_input = document.createElement('INPUT');
368       paid_input.setAttribute('name', 'paid'+rownum);
369       paid_input.setAttribute('size', 8);
370       paid_input.setAttribute('maxlength', 8);
371       paid_cell.appendChild(paid_input);
372
373     row.appendChild(paid_cell);
374
375     var payinfo_cell = document.createElement('TD');
376       var payinfo_input = document.createElement('INPUT');
377       payinfo_input.setAttribute('name', 'payinfo'+rownum);
378       payinfo_input.setAttribute('size', 10);
379       payinfo_cell.appendChild(payinfo_input);
380     row.appendChild(payinfo_cell);
381
382     var error_cell = document.createElement('TD');
383     error_cell.style.backgroundColor = '#e8e8e8';
384     row.appendChild(error_cell);
385
386     tablebody.appendChild(row);
387
388     rownum++;
389
390   }
391
392 </SCRIPT>
393
394 </BODY>
395 </HTML>