Alle Dateien durch Perltidy laufen lassen. Die verwendeten Optionen sind am Ende...
[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(
285           'Are you sure you want to remove the marked entries from the queue?')
286     . qq|</h4>
287
288 <input name=action class=submit type=submit value="|
289     . $locale->text('Yes') . qq|">
290 </form>
291
292 </body>
293 </html>
294 |;
295
296   $lxdebug->leave_sub();
297 }
298
299 sub yes {
300   $lxdebug->enter_sub();
301
302   $form->info($locale->text('Removing marked entries from queue ...'));
303   $form->{callback} .= "&header=1" if $form->{callback};
304
305   $form->redirect($locale->text('Removed spoolfiles!'))
306     if (BP->delete_spool(\%myconfig, \%$form, $spool));
307   $form->error($locale->text('Cannot remove files!'));
308
309   $lxdebug->leave_sub();
310 }
311
312 sub print {
313   $lxdebug->enter_sub();
314
315   if ($form->{callback}) {
316     map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
317       (1 .. $form->{rowcount});
318     $form->{callback} .= "&header=1";
319   }
320
321   for $i (1 .. $form->{rowcount}) {
322     if ($form->{"checked_$i"}) {
323       $form->{OUT} = "| $myconfig{printer}";
324       $form->info($locale->text('Printing ... '));
325
326       if (BP->print_spool(\%myconfig, \%$form, $spool)) {
327         print $locale->text('done');
328         $form->redirect($locale->text('Marked entries printed!'));
329       }
330       exit;
331     }
332   }
333
334   $form->error('Nothing selected!');
335
336   $lxdebug->leave_sub();
337 }
338
339 sub list_spool {
340   $lxdebug->enter_sub();
341
342   $form->{ $form->{vc} } = $form->unescape($form->{ $form->{vc} });
343   ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
344     split(/--/, $form->{ $form->{vc} });
345
346   BP->get_spoolfiles(\%myconfig, \%$form);
347
348   $title = $form->escape($form->{title});
349   $href  =
350     "$form->{script}?action=list_spool&path=$form->{path}&login=$form->{login}&password=$form->{password}&vc=$form->{vc}&type=$form->{type}&title=$title";
351
352   $title = $form->escape($form->{title}, 1);
353   $callback =
354     "$form->{script}?action=list_spool&path=$form->{path}&login=$form->{login}&password=$form->{password}&vc=$form->{vc}&type=$form->{type}&title=$title";
355
356   if ($form->{ $form->{vc} }) {
357     $callback .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} }, 1);
358     $href .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} });
359     $option =
360       ($form->{vc} eq 'customer')
361       ? $locale->text('Customer')
362       : $locale->text('Vendor');
363     $option .= " : $form->{$form->{vc}}";
364   }
365   if ($form->{account}) {
366     $callback .= "&account=" . $form->escape($form->{account}, 1);
367     $href .= "&account=" . $form->escape($form->{account});
368     $option .= "\n<br>" if ($option);
369     $option .= $locale->text('Account') . " : $form->{account}";
370   }
371   if ($form->{invnumber}) {
372     $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
373     $href .= "&invnumber=" . $form->escape($form->{invnumber});
374     $option .= "\n<br>" if ($option);
375     $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
376   }
377   if ($form->{ordnumber}) {
378     $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
379     $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
380     $option .= "\n<br>" if ($option);
381     $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
382   }
383   if ($form->{quonumber}) {
384     $callback .= "&quonumber=" . $form->escape($form->{quonumber}, 1);
385     $href .= "&quonumber=" . $form->escape($form->{quonumber});
386     $option .= "\n<br>" if ($option);
387     $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
388   }
389
390   if ($form->{transdatefrom}) {
391     $callback .= "&transdatefrom=$form->{transdatefrom}";
392     $href     .= "&transdatefrom=$form->{transdatefrom}";
393     $option   .= "\n<br>" if ($option);
394     $option   .=
395         $locale->text('From') . "&nbsp;"
396       . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
397   }
398   if ($form->{transdateto}) {
399     $callback .= "&transdateto=$form->{transdateto}";
400     $href     .= "&transdateto=$form->{transdateto}";
401     $option   .= "\n<br>" if ($option);
402     $option   .=
403         $locale->text('To') . "&nbsp;"
404       . $locale->date(\%myconfig, $form->{transdateto}, 1);
405   }
406
407   $name = ucfirst $form->{vc};
408
409   @columns = (transdate);
410   if ($form->{type} =~ /(invoice|packing_list|check|receipt)/) {
411     push @columns, "invnumber";
412   }
413   if ($form->{type} =~ /_order$/) {
414     push @columns, "ordnumber";
415   }
416   if ($form->{type} =~ /_quotation$/) {
417     push @columns, "quonumber";
418   }
419
420   push @columns, (name, spoolfile);
421   @column_index = $form->sort_columns(@columns);
422   unshift @column_index, "checked";
423
424   $column_header{checked}   = "<th class=listheading>&nbsp;</th>";
425   $column_header{transdate} =
426       "<th><a class=listheading href=$href&sort=transdate>"
427     . $locale->text('Date')
428     . "</a></th>";
429   $column_header{invnumber} =
430       "<th><a class=listheading href=$href&sort=invnumber>"
431     . $locale->text('Invoice')
432     . "</a></th>";
433   $column_header{ordnumber} =
434       "<th><a class=listheading href=$href&sort=ordnumber>"
435     . $locale->text('Order')
436     . "</a></th>";
437   $column_header{quonumber} =
438       "<th><a class=listheading href=$href&sort=quonumber>"
439     . $locale->text('Quotation')
440     . "</a></th>";
441   $column_header{name} =
442       "<th><a class=listheading href=$href&sort=name>"
443     . $locale->text($name)
444     . "</a></th>";
445   $column_header{spoolfile} =
446     "<th class=listheading>" . $locale->text('Spoolfile') . "</th>";
447
448   $form->header;
449
450   print qq|
451 <body>
452
453 <form method=post action=$form->{script}>
454
455 <table width=100%>
456   <tr>
457     <th class=listtop>$form->{title}</th>
458   </tr>
459   <tr height="5"></tr>
460   <tr>
461     <td>$option</td>
462   </tr>
463   <tr>
464     <td>
465       <table width=100%>
466         <tr class=listheading>
467 |;
468
469   map { print "\n$column_header{$_}" } @column_index;
470
471   print qq|
472         </tr>
473 |;
474
475   # add sort and escape callback, this one we use for the add sub
476   $form->{callback} = $callback .= "&sort=$form->{sort}";
477
478   # escape callback for href
479   $callback = $form->escape($callback);
480
481   $i = 0;
482
483   foreach $ref (@{ $form->{SPOOL} }) {
484
485     $i++;
486
487     $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
488
489     if ($ref->{invoice}) {
490       $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
491     }
492     $module = "$ref->{module}.pl";
493
494     $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
495
496     if ($spoolfile eq $ref->{spoolfile}) {
497       $column_data{checked} = qq|<td></td>|;
498     } else {
499       $column_data{checked} =
500         qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
501     }
502
503     $column_data{invnumber} =
504       "<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>";
505     $column_data{ordnumber} =
506       "<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>";
507     $column_data{quonumber} =
508       "<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>";
509     $column_data{name}      = "<td>$ref->{name}</td>";
510     $column_data{spoolfile} =
511       qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
512 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
513 |;
514
515     $spoolfile = $ref->{spoolfile};
516
517     $j++;
518     $j %= 2;
519     print "
520         <tr class=listrow$j>
521 ";
522
523     map { print "\n$column_data{$_}" } @column_index;
524
525     print qq|
526         </tr>
527 |;
528
529   }
530
531   print qq|
532 <input type=hidden name=rowcount value=$i>
533
534       </table>
535     </td>
536   </tr>
537   <tr>
538     <td><hr size=3 noshade></td>
539   </tr>
540 </table>
541
542 <br>
543
544 <input name=callback type=hidden value="$form->{callback}">
545
546 <input type=hidden name=title value="$form->{title}">
547 <input type=hidden name=vc value="$form->{vc}">
548 <input type=hidden name=type value="$form->{type}">
549 <input type=hidden name=sort value="$form->{sort}">
550
551 <input type=hidden name=account value="$form->{account}">
552
553 <input type=hidden name=path value=$form->{path}>
554 <input type=hidden name=login value=$form->{login}>
555 <input type=hidden name=password value=$form->{password}>
556 |;
557
558   if ($myconfig{printer}) {
559     print qq|
560 <input class=submit type=submit name=action value="|
561       . $locale->text('Select all') . qq|">
562 <input class=submit type=submit name=action value="|
563       . $locale->text('Print') . qq|">
564 <input class=submit type=submit name=action value="|
565       . $locale->text('Remove') . qq|">
566 |;
567   }
568
569   if ($form->{menubar}) {
570     require "$form->{path}/menu.pl";
571     &menubar;
572   }
573
574   print qq|
575 </form>
576
577 </body>
578 </html>
579 |;
580
581   $lxdebug->leave_sub();
582 }
583
584 sub select_all {
585   $lxdebug->enter_sub();
586
587   map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
588   &list_spool;
589
590   $lxdebug->leave_sub();
591 }
592
593 sub continue { &{ $form->{nextsub} } }
594