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