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