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