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