Uebernahme der kompletten Version, so wie sie Philip als "Demo-Version" gezeigt hat...
[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') . qq|></td>
164       |;
165     $button2 = qq|
166        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
167        <input type=button name=transdateto name=transdateto id="trigger2" value=|
168       . $locale->text('button') . qq|></td>
169      |;
170
171     #write Trigger
172     $jsscript =
173       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
174                           "transdateto", "BL", "trigger2");
175   } else {
176
177     # without JavaScript Calendar
178     $button1 = qq|
179                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
180     $button2 = qq|
181                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
182   }
183
184   $form->header;
185
186   print qq|
187 <body>
188
189 <form method=post action=$form->{script}>
190
191 <input type=hidden name=vc value=$form->{vc}>
192 <input type=hidden name=type value=$form->{type}>
193 <input type=hidden name=title value="$form->{title}">
194
195 <table width=100%>
196   <tr><th class=listtop>$form->{title}</th></tr>
197   <tr height="5"></tr>
198   <tr>
199     <td>
200       <table>
201         <tr>
202           <th align=right>Kunde</th>
203           <td colspan=3>$name</td>
204         </tr>
205         $account
206         $label{$form->{type}}{invnumber}
207         $label{$form->{type}}{ordnumber}
208         $label{$form->{type}}{quonumber}
209         $label{$form->{type}}{chknumber}
210         $label{$form->{type}}{rctnumber}
211         <tr>
212           <th align=right nowrap>| . $locale->text('From') . qq|</th>
213           $button1
214           <th align=right>| . $locale->text('Bis') . qq|</th>
215           $button2
216         </tr>
217         <input type=hidden name=sort value=transdate>
218       </table>
219     </td>
220   </tr>
221   <tr>
222     <td><hr size=3 noshade></td>
223   </tr>
224 </table>
225
226 <input type=hidden name=nextsub value=list_spool>
227
228 <input type=hidden name=path value=$form->{path}>
229 <input type=hidden name=login value=$form->{login}>
230 <input type=hidden name=password value=$form->{password}>
231
232 <br>
233 <input class=submit type=submit name=action value="|
234     . $locale->text('Continue') . qq|">
235
236 </form>
237
238 </body>
239
240 $jsscript
241
242 </html>
243 |;
244
245   $lxdebug->leave_sub();
246 }
247
248 sub remove {
249   $lxdebug->enter_sub();
250
251   $selected = 0;
252
253   for $i (1 .. $form->{rowcount}) {
254     if ($form->{"checked_$i"}) {
255       $selected = 1;
256       last;
257     }
258   }
259
260   $form->error('Nothing selected!') unless $selected;
261
262   $form->{title} = $locale->text('Confirm!');
263
264   $form->header;
265
266   print qq|
267 <body>
268
269 <form method=post action=$form->{script}>
270 |;
271
272   map { delete $form->{$_} } qw(action header);
273
274   foreach $key (keys %$form) {
275     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
276   }
277
278   print qq|
279 <h2 class=confirm>$form->{title}</h2>
280
281 <h4>|
282     . $locale->text(
283           'Are you sure you want to remove the marked entries from the queue?')
284     . qq|</h4>
285
286 <input name=action class=submit type=submit value="|
287     . $locale->text('Yes') . qq|">
288 </form>
289
290 </body>
291 </html>
292 |;
293
294   $lxdebug->leave_sub();
295 }
296
297 sub yes {
298   $lxdebug->enter_sub();
299
300   $form->info($locale->text('Removing marked entries from queue ...'));
301   $form->{callback} .= "&header=1" if $form->{callback};
302
303   $form->redirect($locale->text('Removed spoolfiles!'))
304     if (BP->delete_spool(\%myconfig, \%$form, $spool));
305   $form->error($locale->text('Cannot remove files!'));
306
307   $lxdebug->leave_sub();
308 }
309
310 sub print {
311   $lxdebug->enter_sub();
312
313   if ($form->{callback}) {
314     map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
315       (1 .. $form->{rowcount});
316     $form->{callback} .= "&header=1";
317   }
318
319   for $i (1 .. $form->{rowcount}) {
320     if ($form->{"checked_$i"}) {
321       $form->{OUT} = "| $myconfig{printer}";
322       $form->info($locale->text('Printing ... '));
323
324       if (BP->print_spool(\%myconfig, \%$form, $spool)) {
325         print $locale->text('done');
326         $form->redirect($locale->text('Marked entries printed!'));
327       }
328       exit;
329     }
330   }
331
332   $form->error('Nothing selected!');
333
334   $lxdebug->leave_sub();
335 }
336
337 sub list_spool {
338   $lxdebug->enter_sub();
339
340   $form->{ $form->{vc} } = $form->unescape($form->{ $form->{vc} });
341   ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
342     split(/--/, $form->{ $form->{vc} });
343
344   BP->get_spoolfiles(\%myconfig, \%$form);
345
346   $title = $form->escape($form->{title});
347   $href  =
348     "$form->{script}?action=list_spool&path=$form->{path}&login=$form->{login}&password=$form->{password}&vc=$form->{vc}&type=$form->{type}&title=$title";
349
350   $title = $form->escape($form->{title}, 1);
351   $callback =
352     "$form->{script}?action=list_spool&path=$form->{path}&login=$form->{login}&password=$form->{password}&vc=$form->{vc}&type=$form->{type}&title=$title";
353
354   if ($form->{ $form->{vc} }) {
355     $callback .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} }, 1);
356     $href .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} });
357     $option =
358       ($form->{vc} eq 'customer')
359       ? $locale->text('Customer')
360       : $locale->text('Vendor');
361     $option .= " : $form->{$form->{vc}}";
362   }
363   if ($form->{account}) {
364     $callback .= "&account=" . $form->escape($form->{account}, 1);
365     $href .= "&account=" . $form->escape($form->{account});
366     $option .= "\n<br>" if ($option);
367     $option .= $locale->text('Account') . " : $form->{account}";
368   }
369   if ($form->{invnumber}) {
370     $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
371     $href .= "&invnumber=" . $form->escape($form->{invnumber});
372     $option .= "\n<br>" if ($option);
373     $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
374   }
375   if ($form->{ordnumber}) {
376     $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
377     $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
378     $option .= "\n<br>" if ($option);
379     $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
380   }
381   if ($form->{quonumber}) {
382     $callback .= "&quonumber=" . $form->escape($form->{quonumber}, 1);
383     $href .= "&quonumber=" . $form->escape($form->{quonumber});
384     $option .= "\n<br>" if ($option);
385     $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
386   }
387
388   if ($form->{transdatefrom}) {
389     $callback .= "&transdatefrom=$form->{transdatefrom}";
390     $href     .= "&transdatefrom=$form->{transdatefrom}";
391     $option   .= "\n<br>" if ($option);
392     $option   .=
393         $locale->text('From') . "&nbsp;"
394       . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
395   }
396   if ($form->{transdateto}) {
397     $callback .= "&transdateto=$form->{transdateto}";
398     $href     .= "&transdateto=$form->{transdateto}";
399     $option   .= "\n<br>" if ($option);
400     $option   .=
401         $locale->text('To') . "&nbsp;"
402       . $locale->date(\%myconfig, $form->{transdateto}, 1);
403   }
404
405   $name = ucfirst $form->{vc};
406
407   @columns = (transdate);
408   if ($form->{type} =~ /(invoice|packing_list|check|receipt)/) {
409     push @columns, "invnumber";
410   }
411   if ($form->{type} =~ /_order$/) {
412     push @columns, "ordnumber";
413   }
414   if ($form->{type} =~ /_quotation$/) {
415     push @columns, "quonumber";
416   }
417
418   push @columns, (name, spoolfile);
419   @column_index = $form->sort_columns(@columns);
420   unshift @column_index, "checked";
421
422   $column_header{checked}   = "<th class=listheading>&nbsp;</th>";
423   $column_header{transdate} =
424       "<th><a class=listheading href=$href&sort=transdate>"
425     . $locale->text('Date')
426     . "</a></th>";
427   $column_header{invnumber} =
428       "<th><a class=listheading href=$href&sort=invnumber>"
429     . $locale->text('Invoice')
430     . "</a></th>";
431   $column_header{ordnumber} =
432       "<th><a class=listheading href=$href&sort=ordnumber>"
433     . $locale->text('Order')
434     . "</a></th>";
435   $column_header{quonumber} =
436       "<th><a class=listheading href=$href&sort=quonumber>"
437     . $locale->text('Quotation')
438     . "</a></th>";
439   $column_header{name} =
440       "<th><a class=listheading href=$href&sort=name>"
441     . $locale->text($name)
442     . "</a></th>";
443   $column_header{spoolfile} =
444     "<th class=listheading>" . $locale->text('Spoolfile') . "</th>";
445
446   $form->header;
447
448   print qq|
449 <body>
450
451 <form method=post action=$form->{script}>
452
453 <table width=100%>
454   <tr>
455     <th class=listtop>$form->{title}</th>
456   </tr>
457   <tr height="5"></tr>
458   <tr>
459     <td>$option</td>
460   </tr>
461   <tr>
462     <td>
463       <table width=100%>
464         <tr class=listheading>
465 |;
466
467   map { print "\n$column_header{$_}" } @column_index;
468
469   print qq|
470         </tr>
471 |;
472
473   # add sort and escape callback, this one we use for the add sub
474   $form->{callback} = $callback .= "&sort=$form->{sort}";
475
476   # escape callback for href
477   $callback = $form->escape($callback);
478
479   $i = 0;
480
481   foreach $ref (@{ $form->{SPOOL} }) {
482
483     $i++;
484
485     $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
486
487     if ($ref->{invoice}) {
488       $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
489     }
490     $module = "$ref->{module}.pl";
491
492     $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
493
494     if ($spoolfile eq $ref->{spoolfile}) {
495       $column_data{checked} = qq|<td></td>|;
496     } else {
497       $column_data{checked} =
498         qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
499     }
500
501     $column_data{invnumber} =
502       "<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>";
503     $column_data{ordnumber} =
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->{ordnumber}</a></td>";
505     $column_data{quonumber} =
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->{quonumber}</a></td>";
507     $column_data{name}      = "<td>$ref->{name}</td>";
508     $column_data{spoolfile} =
509       qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
510 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
511 |;
512
513     $spoolfile = $ref->{spoolfile};
514
515     $j++;
516     $j %= 2;
517     print "
518         <tr class=listrow$j>
519 ";
520
521     map { print "\n$column_data{$_}" } @column_index;
522
523     print qq|
524         </tr>
525 |;
526
527   }
528
529   print qq|
530 <input type=hidden name=rowcount value=$i>
531
532       </table>
533     </td>
534   </tr>
535   <tr>
536     <td><hr size=3 noshade></td>
537   </tr>
538 </table>
539
540 <br>
541
542 <input name=callback type=hidden value="$form->{callback}">
543
544 <input type=hidden name=title value="$form->{title}">
545 <input type=hidden name=vc value="$form->{vc}">
546 <input type=hidden name=type value="$form->{type}">
547 <input type=hidden name=sort value="$form->{sort}">
548
549 <input type=hidden name=account value="$form->{account}">
550
551 <input type=hidden name=path value=$form->{path}>
552 <input type=hidden name=login value=$form->{login}>
553 <input type=hidden name=password value=$form->{password}>
554 |;
555
556   if ($myconfig{printer}) {
557     print qq|
558 <input class=submit type=submit name=action value="|
559       . $locale->text('Select all') . qq|">
560 <input class=submit type=submit name=action value="|
561       . $locale->text('Print') . qq|">
562 <input class=submit type=submit name=action value="|
563       . $locale->text('Remove') . qq|">
564 |;
565   }
566
567   if ($form->{menubar}) {
568     require "$form->{path}/menu.pl";
569     &menubar;
570   }
571
572   print qq|
573 </form>
574
575 </body>
576 </html>
577 |;
578
579   $lxdebug->leave_sub();
580 }
581
582 sub select_all {
583   $lxdebug->enter_sub();
584
585   map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
586   &list_spool;
587
588   $lxdebug->leave_sub();
589 }
590
591 sub continue { &{ $form->{nextsub} } }
592