import sql-ledger 2.4.4
[freeside.git] / sql-ledger / sql-ledger / bin / mozilla / bp.pl
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 2003
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
23 #
24 # Batch printing
25 #
26 #======================================================================
27
28
29 use SL::BP;
30
31 1;
32 # end of main
33
34
35 sub search {
36
37 # $locale->text('Sales Invoices')
38 # $locale->text('Packing Lists')
39 # $locale->text('Pick Lists')
40 # $locale->text('Sales Orders')
41 # $locale->text('Work Orders')
42 # $locale->text('Purchase Orders')
43 # $locale->text('Bin Lists')
44 # $locale->text('Quotations')
45 # $locale->text('RFQs')
46 # $locale->text('Checks')
47 # $locale->text('Receipts')
48
49   # setup customer/vendor selection
50   BP->get_vc(\%myconfig, \%$form);
51   
52   if (@{ $form->{"all_$form->{vc}"} }) { 
53     map { $name .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
54     $name = qq|<select name=$form->{vc}><option>\n$name</select>|;
55   } else {
56     $name = qq|<input name=$form->{vc} size=35>|;
57   }
58
59 # $locale->text('Customer')
60 # $locale->text('Vendor')
61
62   %label = ( invoice => { title => 'Sales Invoices', name => 'Customer' },
63              packing_list => { title => 'Packing Lists', name => 'Customer' },
64              pick_list => { title => 'Pick Lists', name => 'Customer' },
65              sales_order => { title => 'Sales Orders', name => 'Customer' },
66              work_order => { title => 'Work Orders', name => 'Customer' },
67              purchase_order => { title => 'Purchase Orders', name => 'Vendor' },
68              bin_list => { title => 'Bin Lists', name => 'Vendor' },
69              sales_quotation => { title => 'Quotations', name => 'Customer' },
70              request_quotation => { title => 'RFQs', name => 'Vendor' },
71              check => { title => 'Checks', name => 'Vendor' },
72              receipt => { title => 'Receipts', name => 'Customer' }
73            );
74
75   $label{invoice}{invnumber} = qq|
76         <tr>
77           <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
78           <td colspan=3><input name=invnumber size=20></td>
79         </tr>
80 |;
81   $label{invoice}{ordnumber} = qq|
82         <tr>
83           <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
84           <td colspan=3><input name=ordnumber size=20></td>
85         </tr>
86 |;
87   $label{sales_quotation}{quonumber} = qq|
88         <tr>
89           <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
90           <td colspan=3><input name=quonumber size=20></td>
91         </tr>
92 |;
93
94   $label{check}{chknumber} = qq|
95         <tr>
96           <th align=right nowrap>|.$locale->text('Reference').qq|</th>
97           <td colspan=3><input name=chknumber size=20></td>
98         </tr>
99 |;
100
101   $label{packing_list}{invnumber} = $label{invoice}{invnumber};
102   $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
103   $label{pick_list}{invnumber} = $label{invoice}{invnumber};
104   $label{pick_list}{ordnumber} = $label{invoice}{ordnumber};
105   $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
106   $label{work_order}{ordnumber} = $label{invoice}{ordnumber};
107   $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
108   $label{bin_list}{ordnumber} = $label{invoice}{ordnumber};
109   $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
110   $label{receipt}{rctnumber} = $label{check}{chknumber};
111   
112   # do one call to text
113   $form->{title} = $locale->text('Print')." ".$locale->text($label{$form->{type}}{title});
114
115   if ($form->{type} =~ /(check|receipt)/) {
116     if (BP->payment_accounts(\%myconfig, \%$form)) {
117       $account = qq|
118         <tr>
119           <th align=right>|.$locale->text('Account').qq|</th>
120 |;
121
122       if ($form->{accounts}) {
123         $account .= qq|
124           <td colspan=3><select name=account>
125 |;
126         foreach $ref (@{ $form->{accounts} }) {
127           $account .= qq|
128           <option>$ref->{accno}--$ref->{description}
129 |;
130         }
131
132         $account .= qq|
133           </select>
134 |;
135       } else {
136         $account .= qq|
137           <td colspan=3><input name=account></td>
138 |;
139
140       }
141       
142       $account .= qq|
143         </tr>
144 |;
145
146     }
147   }
148
149
150   # accounting years
151   $form->{selectaccountingyear} = "<option>\n";
152   map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} };
153   $form->{selectaccountingmonth} = "<option>\n";
154   map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} };
155
156   $selectfrom = qq|
157         <tr>
158         <th align=right>|.$locale->text('Period').qq|</th>
159         <td colspan=3>
160         <select name=month>$form->{selectaccountingmonth}</select>
161         <select name=year>$form->{selectaccountingyear}</select>
162         <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
163         <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
164         <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
165         <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
166         </td>
167       </tr>
168 |;
169
170   
171   $form->header;
172   
173   print qq|
174 <body>
175
176 <form method=post action=$form->{script}>
177
178 <input type=hidden name=vc value=$form->{vc}>
179 <input type=hidden name=type value=$form->{type}>
180 <input type=hidden name=title value="$form->{title}">
181
182 <table width=100%>
183   <tr><th class=listtop>$form->{title}</th></tr>
184   <tr height="5"></tr>
185   <tr>
186     <td>
187       <table>
188         <tr>
189           <th align=right>|.$locale->text($label{$form->{type}}{name}).qq|</th>
190           <td colspan=3>$name</td>
191         </tr>
192         $account
193         $label{$form->{type}}{invnumber}
194         $label{$form->{type}}{ordnumber}
195         $label{$form->{type}}{quonumber}
196         $label{$form->{type}}{chknumber}
197         $label{$form->{type}}{rctnumber}
198         <tr>
199           <th align=right nowrap>|.$locale->text('From').qq|</th>
200           <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
201           <th align=right>|.$locale->text('To').qq|</th>
202           <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
203         </tr>
204         <input type=hidden name=sort value=transdate>
205         $selectfrom
206       </table>
207     </td>
208   </tr>
209   <tr>
210     <td><hr size=3 noshade></td>
211   </tr>
212 </table>
213
214 <input type=hidden name=nextsub value=list_spool>
215
216 <input type=hidden name=path value=$form->{path}>
217 <input type=hidden name=login value=$form->{login}>
218 <input type=hidden name=sessionid value=$form->{sessionid}>
219
220 <br>
221 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
222
223 </form>
224
225 </body>
226 </html>
227 |;
228
229 }
230
231
232
233 sub remove {
234   
235   $selected = 0;
236   
237   for $i (1 .. $form->{rowcount}) {
238     if ($form->{"checked_$i"}) {
239       $selected = 1;
240       last;
241     }
242   }
243
244   $form->error('Nothing selected!') unless $selected;
245  
246   $form->{title} = $locale->text('Confirm!');
247   
248   $form->header;
249
250   print qq|
251 <body>
252
253 <form method=post action=$form->{script}>
254 |;
255
256   map { delete $form->{$_} } qw(action header);
257   
258   foreach $key (keys %$form) {
259     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
260   }
261
262   print qq|
263 <h2 class=confirm>$form->{title}</h2>
264
265 <h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4>
266
267 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
268 </form>
269
270 </body>
271 </html>
272 |;
273
274 }
275
276
277
278 sub yes {
279
280   $form->info($locale->text('Removing marked entries from queue ...'));
281   $form->{callback} .= "&header=1" if $form->{callback};
282
283   $form->redirect($locale->text('Removed spoolfiles!')) if (BP->delete_spool(\%myconfig, \%$form, $spool));
284   $form->error($locale->text('Cannot remove files!'));
285
286 }
287
288
289 sub print {
290
291   if ($form->{callback}) {
292     map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} } (1 .. $form->{rowcount});
293     $form->{callback} .= "&header=1";
294   }
295
296   for $i (1 .. $form->{rowcount}) {
297     if ($form->{"checked_$i"}) {
298       $form->{OUT} = "| $printer{$form->{media}}";
299       $form->info($locale->text('Printing ... '));
300
301       if (BP->print_spool(\%myconfig, \%$form, $spool)) {
302         print $locale->text('done');
303         $form->redirect($locale->text('Marked entries printed!'));
304       }
305       exit;
306     }
307   }
308
309   $form->error('Nothing selected!');
310
311 }
312
313
314 sub list_spool {
315
316   $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
317   ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
318
319   BP->get_spoolfiles(\%myconfig, \%$form);
320
321   $title = $form->escape($form->{title});
322   $href = "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title";
323  
324   $form->sort_order();
325   
326   $title = $form->escape($form->{title},1);
327   $callback = "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title";
328
329   if ($form->{$form->{vc}}) {
330     $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1);
331     $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}});
332     $option = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
333     $option .= " : $form->{$form->{vc}}";
334   }
335   if ($form->{account}) {
336     $callback .= "&account=".$form->escape($form->{account},1);
337     $href .= "&account=".$form->escape($form->{account});
338     $option .= "\n<br>" if ($option);
339     $option .= $locale->text('Account')." : $form->{account}";
340   }
341   if ($form->{invnumber}) {
342     $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
343     $href .= "&invnumber=".$form->escape($form->{invnumber});
344     $option .= "\n<br>" if ($option);
345     $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
346   }
347   if ($form->{ordnumber}) {
348     $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
349     $href .= "&ordnumber=".$form->escape($form->{ordnumber});
350     $option .= "\n<br>" if ($option);
351     $option .= $locale->text('Order Number')." : $form->{ordnumber}";
352   }
353   if ($form->{quonumber}) {
354     $callback .= "&quonumber=".$form->escape($form->{quonumber},1);
355     $href .= "&quonumber=".$form->escape($form->{quonumber});
356     $option .= "\n<br>" if ($option);
357     $option .= $locale->text('Quotation Number')." : $form->{quonumber}";
358   }
359  
360   if ($form->{transdatefrom}) {
361     $callback .= "&transdatefrom=$form->{transdatefrom}";
362     $href .= "&transdatefrom=$form->{transdatefrom}";
363     $option .= "\n<br>" if ($option);
364     $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
365   }
366   if ($form->{transdateto}) {
367     $callback .= "&transdateto=$form->{transdateto}";
368     $href .= "&transdateto=$form->{transdateto}";
369     $option .= "\n<br>" if ($option);
370     $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
371   }
372
373   $name = ucfirst $form->{vc};
374   
375   @columns = qw(transdate);
376   if ($form->{type} =~ /(invoice|check|receipt)/) {
377     push @columns, "invnumber";
378   }
379   if ($form->{type} =~ /(packing|pick)_list/) {
380     push @columns, "invnumber";
381   }
382   if ($form->{type} =~ /_(order|list)$/) {
383     push @columns, "ordnumber";
384   }
385   if ($form->{type} =~ /_quotation$/) {
386     push @columns, "quonumber";
387   }
388
389   push @columns, (name, spoolfile);
390   @column_index = $form->sort_columns(@columns);
391   unshift @column_index, "checked";
392
393   $column_header{checked} = "<th class=listheading>&nbsp;</th>";
394   $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
395   $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
396   $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
397   $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>";
398   $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text($name)."</a></th>";
399   $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>";
400
401
402   $form->header;
403
404   print qq|
405 <body>
406
407 <form method=post action=$form->{script}>
408
409 <table width=100%>
410   <tr>
411     <th class=listtop>$form->{title}</th>
412   </tr>
413   <tr height="5"></tr>
414   <tr>
415     <td>$option</td>
416   </tr>
417   <tr>
418     <td>
419       <table width=100%>
420         <tr class=listheading>
421 |;
422
423   map { print "\n$column_header{$_}" } @column_index;
424
425   print qq|
426         </tr>
427 |;
428
429
430   # add sort and escape callback, this one we use for the add sub
431   $form->{callback} = $callback .= "&sort=$form->{sort}";
432
433   # escape callback for href
434   $callback = $form->escape($callback);
435   
436   $i = 0;
437   
438   foreach $ref (@{ $form->{SPOOL} }) {
439
440     $i++;
441    
442     $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
443     
444     # this is for audittrail
445     $form->{module} = $ref->{module};
446     
447     if ($ref->{invoice}) {
448       $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
449     }
450     $module = "$ref->{module}.pl";
451     
452     $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
453
454     if ($spoolfile eq $ref->{spoolfile}) {
455       $column_data{checked} = qq|<td></td>|;
456     } else {
457       $column_data{checked} = qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
458     }
459     
460     if ($ref->{module} eq 'oe') {
461       $column_data{invnumber} = qq|<td>&nbsp</td>|;
462       $column_data{ordnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td>
463       <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|;
464       
465       $column_data{quonumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>
466     <input type=hidden name="reference_$i" value="$ref->{quonumber}">|;
467  
468     } else {
469       $column_data{ordnumber} = qq|<td>$ref->{ordnumber}</td>|;
470       $column_data{quonumber} = qq|<td>$ref->{quonumber}</td>|;
471       $column_data{invnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td>
472     <input type=hidden name="reference_$i" value="$ref->{invnumber}">|;
473     }
474     
475    
476     $column_data{name} = "<td>$ref->{name}</td>";
477     $column_data{spoolfile} = qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
478
479 |;
480
481     $spoolfile = $ref->{spoolfile};
482     
483     $j++; $j %= 2;
484     print "
485         <tr class=listrow$j>
486 ";
487
488     map { print "\n$column_data{$_}" } @column_index;
489
490     print qq|
491 <input type=hidden name="id_$i" value=$ref->{id}>
492 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
493
494         </tr>
495 |;
496
497   }
498
499   print qq|
500 <input type=hidden name=rowcount value=$i>
501
502       </table>
503     </td>
504   </tr>
505   <tr>
506     <td><hr size=3 noshade></td>
507   </tr>
508 </table>
509
510 <br>
511
512 <input name=callback type=hidden value="$form->{callback}">
513
514 <input type=hidden name=title value="$form->{title}">
515 <input type=hidden name=vc value="$form->{vc}">
516 <input type=hidden name=type value="$form->{type}">
517 <input type=hidden name=sort value="$form->{sort}">
518 <input type=hidden name=module value=$form->{module}>
519
520 <input type=hidden name=account value="$form->{account}">
521
522 <input type=hidden name=path value=$form->{path}>
523 <input type=hidden name=login value=$form->{login}>
524 <input type=hidden name=sessionid value=$form->{sessionid}>
525 |;
526
527   if (%printer && $latex) {
528     foreach $key (sort keys %printer) {
529       print qq|
530 <input name=media type=radio class=radio value="$key" |;
531       print qq|checked| if $key eq $myconfig{printer};
532       print qq|>$key|;
533     }
534     
535     print qq|
536 <p>
537 <input class=submit type=submit name=action value="|.$locale->text('Select all').qq|">
538 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
539 <input class=submit type=submit name=action value="|.$locale->text('Remove').qq|">
540 |;
541   }
542
543   if ($form->{menubar}) {
544     require "$form->{path}/menu.pl";
545     &menubar;
546   }
547
548   print qq|
549 </form>
550
551 </body>
552 </html>
553 |;
554
555 }
556
557
558 sub select_all {
559
560   map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
561   &list_spool;
562   
563 }
564
565
566 sub continue { &{ $form->{nextsub} } };
567