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