1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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 #======================================================================
32 #======================================================================
36 use List::Util qw(first);
40 require "bin/mozilla/common.pl";
46 sub assert_bp_access {
47 my $form = $main::form;
50 'invoice' => 'invoice_edit',
51 'sales_order' => 'sales_order_edit',
52 'sales_quotation' => 'sales_quotation_edit',
53 'purchase_order' => 'purchase_order_edit',
54 'request_quotation' => 'request_quotation_edit',
59 if ($form->{type} && $access_map{$form->{type}}) {
60 $main::auth->assert($access_map{$form->{type}});
62 } elsif ($form->{type} eq 'packing_list') {
63 $main::lxdebug->message(0, "1");
64 if (!$main::auth->assert('sales_order_edit', 1)) {
65 $main::lxdebug->message(0, "2");
66 $main::auth->assert('invoice_edit') ;
68 $main::lxdebug->message(0, "3");
71 $main::auth->assert('DOES_NOT_EXIST');
76 $main::lxdebug->enter_sub();
78 my $form = $main::form;
79 my %myconfig = %main::myconfig;
80 my $locale = $main::locale;
82 my ($name, $account, $onload);
86 # $locale->text('Sales Invoices')
87 # $locale->text('Packing Lists')
88 # $locale->text('Sales Orders')
89 # $locale->text('Purchase Orders')
90 # $locale->text('Quotations')
91 # $locale->text('RFQs')
92 # $locale->text('Checks')
93 # $locale->text('Receipts')
95 # setup customer/vendor selection
96 BP->get_vc(\%myconfig, \%$form);
98 if (@{ $form->{"all_$form->{vc}"} || [] }) {
99 map { $name .= "<option>$_->{name}--$_->{id}\n" }
100 @{ $form->{"all_$form->{vc}"} };
101 $name = qq|<select name=$form->{vc}><option>\n$name</select>|;
103 $name = qq|<input name=$form->{vc} size=35>|;
106 # $locale->text('Customer')
107 # $locale->text('Vendor')
111 { title => 'Sales Invoices', name => 'Customer', l_invnumber => 'Y' },
113 { title => 'Packing Lists', name => 'Customer', l_invnumber => 'Y' },
115 { title => 'Sales Orders', name => 'Customer', l_ordnumber => 'Y' },
117 { title => 'Purchase Orders', name => 'Vendor', l_ordnumber => 'Y' },
119 { title => 'Quotations', name => 'Customer', l_quonumber => 'Y' },
121 { title => 'RFQs', name => 'Vendor', l_quonumber => 'Y' },
122 check => { title => 'Checks', name => 'Vendor' },
123 receipt => { title => 'Receipts', name => 'Customer' });
125 $label{invoice}{invnumber} = qq|
127 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
128 <td colspan=3><input name=invnumber size=20></td>
131 $label{invoice}{ordnumber} = qq|
133 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
134 <td colspan=3><input name=ordnumber size=20></td>
137 $label{sales_quotation}{quonumber} = qq|
139 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
140 <td colspan=3><input name=quonumber size=20></td>
144 $label{check}{chknumber} = qq|
146 <th align=right nowrap>| . $locale->text('Reference') . qq|</th>
147 <td colspan=3><input name=chknumber size=20></td>
151 $label{packing_list}{invnumber} = $label{invoice}{invnumber};
152 $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
153 $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
154 $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
155 $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
156 $label{receipt}{rctnumber} = $label{check}{chknumber};
158 # do one call to text
160 $locale->text('Print') . " "
161 . $locale->text($label{ $form->{type} }{title});
163 if ($form->{type} =~ /(check|receipt)/) {
164 if (BP->payment_accounts(\%myconfig, \%$form)) {
167 <th align=right>| . $locale->text('Account') . qq|</th>
170 if ($form->{accounts}) {
172 <td colspan=3><select name=account>
174 foreach my $ref (@{ $form->{accounts} }) {
176 <option>$ref->{accno}--$ref->{description}
185 <td colspan=3><input name=account></td>
197 # use JavaScript Calendar or not
198 $form->{jsscript} = 1;
200 my ($button1, $button2);
201 if ($form->{jsscript}) {
203 # with JavaScript Calendar
205 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
206 <input type=button name=transdatefrom id="trigger1" value=|
207 . $locale->text('button') . qq|></td>
210 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
211 <input type=button name=transdateto name=transdateto id="trigger2" value=|
212 . $locale->text('button') . qq|></td>
217 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
218 "transdateto", "BL", "trigger2");
221 # without JavaScript Calendar
223 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
225 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
227 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
229 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
230 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
232 <body onLoad="$onload">
234 <form method=post action=bp.pl>
236 <input type=hidden name=vc value=$form->{vc}>
237 <input type=hidden name=type value=$form->{type}>
238 <input type=hidden name=title value="$form->{title}">
241 <tr><th class=listtop>$form->{title}</th></tr>
247 <th align=right>Kunde</th>
248 <td colspan=3>$name</td>
251 $label{$form->{type}}{invnumber}
252 $label{$form->{type}}{ordnumber}
253 $label{$form->{type}}{quonumber}
254 $label{$form->{type}}{chknumber}
255 $label{$form->{type}}{rctnumber}
257 <th align=right nowrap>| . $locale->text('From') . qq|</th>
259 <th align=right>| . $locale->text('Bis') . qq|</th>
262 <input type=hidden name=sort value=transdate>
267 <td><hr size=3 noshade></td>
271 <input type=hidden name=nextsub value=list_spool>
274 <input class=submit type=submit name=action value="|
275 . $locale->text('Continue') . qq|">
286 $main::lxdebug->leave_sub();
290 $main::lxdebug->enter_sub();
292 my $form = $main::form;
293 my $locale = $main::locale;
299 for my $i (1 .. $form->{rowcount}) {
300 if ($form->{"checked_$i"}) {
306 $form->error('Nothing selected!') unless $selected;
308 $form->{title} = $locale->text('Confirm!');
315 <form method=post action=bp.pl>
318 map { delete $form->{$_} } qw(action header);
320 foreach my $key (keys %$form) {
321 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
322 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
326 <h2 class=confirm>$form->{title}</h2>
330 'Are you sure you want to remove the marked entries from the queue?')
333 <input name=action class=submit type=submit value="|
334 . $locale->text('Yes') . qq|">
341 $main::lxdebug->leave_sub();
345 $main::lxdebug->enter_sub();
347 my $form = $main::form;
348 my %myconfig = %main::myconfig;
349 my $locale = $main::locale;
353 $form->info($locale->text('Removing marked entries from queue ...'));
354 $form->{callback} .= "&header=1" if $form->{callback};
356 $form->redirect($locale->text('Removed spoolfiles!'))
357 if (BP->delete_spool(\%myconfig, \%$form, $main::spool));
358 $form->error($locale->text('Cannot remove files!'));
360 $main::lxdebug->leave_sub();
364 $main::lxdebug->enter_sub();
366 my $form = $main::form;
367 my %myconfig = %main::myconfig;
368 my $locale = $main::locale;
372 $form->get_lists(printers => 'ALL_PRINTERS');
373 # use the command stored in the databse or fall back to $myconfig{printer}
374 my $selected_printer = first { $_ } map ({ $_ ->{printer_command} }
375 grep { $_->{id} eq $form->{printer} }
376 @{ $form->{ALL_PRINTERS} }),
379 if ($form->{callback}) {
380 map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
381 (1 .. $form->{rowcount});
382 $form->{callback} .= "&header=1";
385 for my $i (1 .. $form->{rowcount}) {
386 if ($form->{"checked_$i"}) {
387 $form->info($locale->text('Printing ... '));
389 if (BP->print_spool(\%myconfig, \%$form, $main::spool, "| $selected_printer")) {
390 print $locale->text('done');
391 $form->redirect($locale->text('Marked entries printed!'));
397 $form->error('Nothing selected!');
399 $main::lxdebug->leave_sub();
403 $main::lxdebug->enter_sub();
405 my $form = $main::form;
406 my %myconfig = %main::myconfig;
407 my $locale = $main::locale;
411 $form->{ $form->{vc} } = $form->unescape($form->{ $form->{vc} });
412 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
413 split(/--/, $form->{ $form->{vc} });
415 BP->get_spoolfiles(\%myconfig, \%$form);
417 my $title = $form->escape($form->{title});
418 my $href = "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
420 $title = $form->escape($form->{title}, 1);
422 "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
425 if ($form->{ $form->{vc} }) {
426 $callback .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} }, 1);
427 $href .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} });
429 ($form->{vc} eq 'customer')
430 ? $locale->text('Customer')
431 : $locale->text('Vendor');
432 $option .= " : $form->{$form->{vc}}";
434 if ($form->{account}) {
435 $callback .= "&account=" . $form->escape($form->{account}, 1);
436 $href .= "&account=" . $form->escape($form->{account});
437 $option .= "\n<br>" if ($option);
438 $option .= $locale->text('Account') . " : $form->{account}";
440 if ($form->{invnumber}) {
441 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
442 $href .= "&invnumber=" . $form->escape($form->{invnumber});
443 $option .= "\n<br>" if ($option);
444 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
446 if ($form->{ordnumber}) {
447 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
448 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
449 $option .= "\n<br>" if ($option);
450 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
452 if ($form->{quonumber}) {
453 $callback .= "&quonumber=" . $form->escape($form->{quonumber}, 1);
454 $href .= "&quonumber=" . $form->escape($form->{quonumber});
455 $option .= "\n<br>" if ($option);
456 $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
459 if ($form->{transdatefrom}) {
460 $callback .= "&transdatefrom=$form->{transdatefrom}";
461 $href .= "&transdatefrom=$form->{transdatefrom}";
462 $option .= "\n<br>" if ($option);
464 $locale->text('From') . " "
465 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
467 if ($form->{transdateto}) {
468 $callback .= "&transdateto=$form->{transdateto}";
469 $href .= "&transdateto=$form->{transdateto}";
470 $option .= "\n<br>" if ($option);
472 $locale->text('To') . " "
473 . $locale->date(\%myconfig, $form->{transdateto}, 1);
476 my $name = ucfirst $form->{vc};
478 my @columns = qw(transdate);
479 if ($form->{type} =~ /(invoice|packing_list|check|receipt)/) {
480 push @columns, "invnumber";
482 if ($form->{type} =~ /_order$/) {
483 push @columns, "ordnumber";
485 if ($form->{type} =~ /_quotation$/) {
486 push @columns, "quonumber";
489 push @columns, qw(name spoolfile);
490 my @column_index = $form->sort_columns(@columns);
491 unshift @column_index, "checked";
496 $column_header{checked} = "<th class=listheading> </th>";
497 $column_header{transdate} =
498 "<th><a class=listheading href=$href&sort=transdate>"
499 . $locale->text('Date')
501 $column_header{invnumber} =
502 "<th><a class=listheading href=$href&sort=invnumber>"
503 . $locale->text('Invoice')
505 $column_header{ordnumber} =
506 "<th><a class=listheading href=$href&sort=ordnumber>"
507 . $locale->text('Order')
509 $column_header{quonumber} =
510 "<th><a class=listheading href=$href&sort=quonumber>"
511 . $locale->text('Quotation')
513 $column_header{name} =
514 "<th><a class=listheading href=$href&sort=name>"
515 . $locale->text($name)
517 $column_header{spoolfile} =
518 "<th class=listheading>" . $locale->text('Spoolfile') . "</th>";
525 <form method=post action=bp.pl>
529 <th class=listtop>$form->{title}</th>
538 <tr class=listheading>
541 map { print "\n$column_header{$_}" } @column_index;
547 # add sort and escape callback, this one we use for the add sub
548 $form->{callback} = $callback .= "&sort=$form->{sort}";
550 # escape callback for href
551 $callback = $form->escape($callback);
557 foreach my $ref (@{ $form->{SPOOL} }) {
561 $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
563 if ($ref->{invoice}) {
564 $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
566 my $module = "$ref->{module}.pl";
568 $column_data{transdate} = "<td>$ref->{transdate} </td>";
570 if ($spoolfile eq $ref->{spoolfile}) {
571 $column_data{checked} = qq|<td></td>|;
573 $column_data{checked} =
574 qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
577 $column_data{invnumber} =
578 "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td>";
579 $column_data{ordnumber} =
580 "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td>";
581 $column_data{quonumber} =
582 "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>";
583 $column_data{name} = "<td>$ref->{name}</td>";
584 $column_data{spoolfile} =
585 qq|<td><a href=$main::spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
586 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
589 $spoolfile = $ref->{spoolfile};
597 map { print "\n$column_data{$_}" } @column_index;
606 <input type=hidden name=rowcount value=$i>
612 <td><hr size=3 noshade></td>
618 <input name=callback type=hidden value="$form->{callback}">
620 <input type=hidden name=title value="$form->{title}">
621 <input type=hidden name=vc value="$form->{vc}">
622 <input type=hidden name=type value="$form->{type}">
623 <input type=hidden name=sort value="$form->{sort}">
625 <input type=hidden name=account value="$form->{account}">
628 # if ($myconfig{printer}) {
630 <input type=hidden name=transdateto value=$form->{transdateto}>
631 <input type=hidden name=transdatefrom value=$form->{transdatefrom}>
632 <input type=hidden name=invnumber value=$form->{invnumber}>
633 <input type=hidden name=ordnumber value=$form->{ordnumber}>
634 <input type=hidden name=quonumber value=$form->{quonumber}>
635 <input type=hidden name=customer value=$form->{customer}>
636 <input type=hidden name=vendor value=$form->{vendor}>
637 <input class=submit type=submit name=action value="|
638 . $locale->text('Select all') . qq|">
639 <input class=submit type=submit name=action value="|
640 . $locale->text('Remove') . qq|">
641 <input class=submit type=submit name=action value="|
642 . $locale->text('Print') . qq|">
645 $form->get_lists(printers=>"ALL_PRINTERS");
646 print qq|<select name="printer">|;
647 print map(qq|<option value="$_->{id}">| . H($_->{printer_description}) . qq|</option>|, @{ $form->{ALL_PRINTERS} });
659 $main::lxdebug->leave_sub();
663 $main::lxdebug->enter_sub();
665 my $form = $main::form;
669 map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
672 $main::lxdebug->leave_sub();
675 sub continue { call_sub($main::form->{"nextsub"}); }