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