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";
44 sub assert_bp_access {
46 'invoice' => 'invoice_edit',
47 'sales_order' => 'sales_order_edit',
48 'sales_quotation' => 'sales_quotation_edit',
49 'purchase_order' => 'purchase_order_edit',
50 'request_quotation' => 'request_quotation_edit',
55 if ($form->{type} && $access_map{$form->{type}}) {
56 $auth->assert($access_map{$form->{type}});
58 } elsif ($form->{type} eq 'packing_list') {
59 $lxdebug->message(0, "1");
60 if (!$auth->assert('sales_order_edit', 1)) {
61 $lxdebug->message(0, "2");
62 $auth->assert('invoice_edit') ;
64 $lxdebug->message(0, "3");
67 $auth->assert('DOES_NOT_EXIST');
72 $lxdebug->enter_sub();
76 # $locale->text('Sales Invoices')
77 # $locale->text('Packing Lists')
78 # $locale->text('Sales Orders')
79 # $locale->text('Purchase Orders')
80 # $locale->text('Quotations')
81 # $locale->text('RFQs')
82 # $locale->text('Checks')
83 # $locale->text('Receipts')
85 # setup customer/vendor selection
86 BP->get_vc(\%myconfig, \%$form);
88 if (@{ $form->{"all_$form->{vc}"} }) {
89 map { $name .= "<option>$_->{name}--$_->{id}\n" }
90 @{ $form->{"all_$form->{vc}"} };
91 $name = qq|<select name=$form->{vc}><option>\n$name</select>|;
93 $name = qq|<input name=$form->{vc} size=35>|;
96 # $locale->text('Customer')
97 # $locale->text('Vendor')
101 { title => 'Sales Invoices', name => 'Customer', l_invnumber => 'Y' },
103 { title => 'Packing Lists', name => 'Customer', l_invnumber => 'Y' },
105 { title => 'Sales Orders', name => 'Customer', l_ordnumber => 'Y' },
107 { title => 'Purchase Orders', name => 'Vendor', l_ordnumber => 'Y' },
109 { title => 'Quotations', name => 'Customer', l_quonumber => 'Y' },
111 { title => 'RFQs', name => 'Vendor', l_quonumber => 'Y' },
112 check => { title => 'Checks', name => 'Vendor' },
113 receipt => { title => 'Receipts', name => 'Customer' });
115 $label{invoice}{invnumber} = qq|
117 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
118 <td colspan=3><input name=invnumber size=20></td>
121 $label{invoice}{ordnumber} = qq|
123 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
124 <td colspan=3><input name=ordnumber size=20></td>
127 $label{sales_quotation}{quonumber} = qq|
129 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
130 <td colspan=3><input name=quonumber size=20></td>
134 $label{check}{chknumber} = qq|
136 <th align=right nowrap>| . $locale->text('Reference') . qq|</th>
137 <td colspan=3><input name=chknumber size=20></td>
141 $label{packing_list}{invnumber} = $label{invoice}{invnumber};
142 $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
143 $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
144 $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
145 $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
146 $label{receipt}{rctnumber} = $label{check}{chknumber};
148 # do one call to text
150 $locale->text('Print') . " "
151 . $locale->text($label{ $form->{type} }{title});
153 if ($form->{type} =~ /(check|receipt)/) {
154 if (BP->payment_accounts(\%myconfig, \%$form)) {
157 <th align=right>| . $locale->text('Account') . qq|</th>
160 if ($form->{accounts}) {
162 <td colspan=3><select name=account>
164 foreach $ref (@{ $form->{accounts} }) {
166 <option>$ref->{accno}--$ref->{description}
175 <td colspan=3><input name=account></td>
187 # use JavaScript Calendar or not
188 $form->{jsscript} = 1;
190 if ($form->{jsscript}) {
192 # with JavaScript Calendar
194 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
195 <input type=button name=transdatefrom id="trigger1" value=|
196 . $locale->text('button') . qq|></td>
199 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
200 <input type=button name=transdateto name=transdateto id="trigger2" value=|
201 . $locale->text('button') . qq|></td>
206 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
207 "transdateto", "BL", "trigger2");
210 # without JavaScript Calendar
212 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
214 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
216 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
218 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
219 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
221 <body onLoad="$onload">
223 <form method=post action=bp.pl>
225 <input type=hidden name=vc value=$form->{vc}>
226 <input type=hidden name=type value=$form->{type}>
227 <input type=hidden name=title value="$form->{title}">
230 <tr><th class=listtop>$form->{title}</th></tr>
236 <th align=right>Kunde</th>
237 <td colspan=3>$name</td>
240 $label{$form->{type}}{invnumber}
241 $label{$form->{type}}{ordnumber}
242 $label{$form->{type}}{quonumber}
243 $label{$form->{type}}{chknumber}
244 $label{$form->{type}}{rctnumber}
246 <th align=right nowrap>| . $locale->text('From') . qq|</th>
248 <th align=right>| . $locale->text('Bis') . qq|</th>
251 <input type=hidden name=sort value=transdate>
256 <td><hr size=3 noshade></td>
260 <input type=hidden name=nextsub value=list_spool>
263 <input class=submit type=submit name=action value="|
264 . $locale->text('Continue') . qq|">
275 $lxdebug->leave_sub();
279 $lxdebug->enter_sub();
285 for $i (1 .. $form->{rowcount}) {
286 if ($form->{"checked_$i"}) {
292 $form->error('Nothing selected!') unless $selected;
294 $form->{title} = $locale->text('Confirm!');
301 <form method=post action=bp.pl>
304 map { delete $form->{$_} } qw(action header);
306 foreach $key (keys %$form) {
307 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
308 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
312 <h2 class=confirm>$form->{title}</h2>
316 'Are you sure you want to remove the marked entries from the queue?')
319 <input name=action class=submit type=submit value="|
320 . $locale->text('Yes') . qq|">
327 $lxdebug->leave_sub();
331 $lxdebug->enter_sub();
335 $form->info($locale->text('Removing marked entries from queue ...'));
336 $form->{callback} .= "&header=1" if $form->{callback};
338 $form->redirect($locale->text('Removed spoolfiles!'))
339 if (BP->delete_spool(\%myconfig, \%$form, $spool));
340 $form->error($locale->text('Cannot remove files!'));
342 $lxdebug->leave_sub();
346 $lxdebug->enter_sub();
350 $form->get_lists(printers => 'ALL_PRINTERS');
351 # use the command stored in the databse or fall back to $myconfig{printer}
352 my $selected_printer = first { $_ } map ({ $_ ->{printer_command} }
353 grep { $_->{id} eq $form->{printer} }
354 @{ $form->{ALL_PRINTERS} }),
357 if ($form->{callback}) {
358 map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
359 (1 .. $form->{rowcount});
360 $form->{callback} .= "&header=1";
363 for $i (1 .. $form->{rowcount}) {
364 if ($form->{"checked_$i"}) {
365 $form->info($locale->text('Printing ... '));
367 if (BP->print_spool(\%myconfig, \%$form, $spool, "| $selected_printer")) {
368 print $locale->text('done');
369 $form->redirect($locale->text('Marked entries printed!'));
375 $form->error('Nothing selected!');
377 $lxdebug->leave_sub();
381 $lxdebug->enter_sub();
385 $form->{ $form->{vc} } = $form->unescape($form->{ $form->{vc} });
386 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
387 split(/--/, $form->{ $form->{vc} });
389 BP->get_spoolfiles(\%myconfig, \%$form);
391 $title = $form->escape($form->{title});
392 $href = "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
394 $title = $form->escape($form->{title}, 1);
396 "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
398 if ($form->{ $form->{vc} }) {
399 $callback .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} }, 1);
400 $href .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} });
402 ($form->{vc} eq 'customer')
403 ? $locale->text('Customer')
404 : $locale->text('Vendor');
405 $option .= " : $form->{$form->{vc}}";
407 if ($form->{account}) {
408 $callback .= "&account=" . $form->escape($form->{account}, 1);
409 $href .= "&account=" . $form->escape($form->{account});
410 $option .= "\n<br>" if ($option);
411 $option .= $locale->text('Account') . " : $form->{account}";
413 if ($form->{invnumber}) {
414 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
415 $href .= "&invnumber=" . $form->escape($form->{invnumber});
416 $option .= "\n<br>" if ($option);
417 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
419 if ($form->{ordnumber}) {
420 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
421 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
422 $option .= "\n<br>" if ($option);
423 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
425 if ($form->{quonumber}) {
426 $callback .= "&quonumber=" . $form->escape($form->{quonumber}, 1);
427 $href .= "&quonumber=" . $form->escape($form->{quonumber});
428 $option .= "\n<br>" if ($option);
429 $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
432 if ($form->{transdatefrom}) {
433 $callback .= "&transdatefrom=$form->{transdatefrom}";
434 $href .= "&transdatefrom=$form->{transdatefrom}";
435 $option .= "\n<br>" if ($option);
437 $locale->text('From') . " "
438 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
440 if ($form->{transdateto}) {
441 $callback .= "&transdateto=$form->{transdateto}";
442 $href .= "&transdateto=$form->{transdateto}";
443 $option .= "\n<br>" if ($option);
445 $locale->text('To') . " "
446 . $locale->date(\%myconfig, $form->{transdateto}, 1);
449 $name = ucfirst $form->{vc};
451 @columns = (transdate);
452 if ($form->{type} =~ /(invoice|packing_list|check|receipt)/) {
453 push @columns, "invnumber";
455 if ($form->{type} =~ /_order$/) {
456 push @columns, "ordnumber";
458 if ($form->{type} =~ /_quotation$/) {
459 push @columns, "quonumber";
462 push @columns, (name, spoolfile);
463 @column_index = $form->sort_columns(@columns);
464 unshift @column_index, "checked";
466 $column_header{checked} = "<th class=listheading> </th>";
467 $column_header{transdate} =
468 "<th><a class=listheading href=$href&sort=transdate>"
469 . $locale->text('Date')
471 $column_header{invnumber} =
472 "<th><a class=listheading href=$href&sort=invnumber>"
473 . $locale->text('Invoice')
475 $column_header{ordnumber} =
476 "<th><a class=listheading href=$href&sort=ordnumber>"
477 . $locale->text('Order')
479 $column_header{quonumber} =
480 "<th><a class=listheading href=$href&sort=quonumber>"
481 . $locale->text('Quotation')
483 $column_header{name} =
484 "<th><a class=listheading href=$href&sort=name>"
485 . $locale->text($name)
487 $column_header{spoolfile} =
488 "<th class=listheading>" . $locale->text('Spoolfile') . "</th>";
495 <form method=post action=bp.pl>
499 <th class=listtop>$form->{title}</th>
508 <tr class=listheading>
511 map { print "\n$column_header{$_}" } @column_index;
517 # add sort and escape callback, this one we use for the add sub
518 $form->{callback} = $callback .= "&sort=$form->{sort}";
520 # escape callback for href
521 $callback = $form->escape($callback);
525 foreach $ref (@{ $form->{SPOOL} }) {
529 $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
531 if ($ref->{invoice}) {
532 $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
534 $module = "$ref->{module}.pl";
536 $column_data{transdate} = "<td>$ref->{transdate} </td>";
538 if ($spoolfile eq $ref->{spoolfile}) {
539 $column_data{checked} = qq|<td></td>|;
541 $column_data{checked} =
542 qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
545 $column_data{invnumber} =
546 "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td>";
547 $column_data{ordnumber} =
548 "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td>";
549 $column_data{quonumber} =
550 "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>";
551 $column_data{name} = "<td>$ref->{name}</td>";
552 $column_data{spoolfile} =
553 qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
554 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
557 $spoolfile = $ref->{spoolfile};
565 map { print "\n$column_data{$_}" } @column_index;
574 <input type=hidden name=rowcount value=$i>
580 <td><hr size=3 noshade></td>
586 <input name=callback type=hidden value="$form->{callback}">
588 <input type=hidden name=title value="$form->{title}">
589 <input type=hidden name=vc value="$form->{vc}">
590 <input type=hidden name=type value="$form->{type}">
591 <input type=hidden name=sort value="$form->{sort}">
593 <input type=hidden name=account value="$form->{account}">
596 # if ($myconfig{printer}) {
598 <input type=hidden name=transdateto value=$form->{transdateto}>
599 <input type=hidden name=transdatefrom value=$form->{transdatefrom}>
600 <input type=hidden name=invnumber value=$form->{invnumber}>
601 <input type=hidden name=ordnumber value=$form->{ordnumber}>
602 <input type=hidden name=quonumber value=$form->{quonumber}>
603 <input type=hidden name=customer value=$form->{customer}>
604 <input type=hidden name=vendor value=$form->{vendor}>
605 <input class=submit type=submit name=action value="|
606 . $locale->text('Select all') . qq|">
607 <input class=submit type=submit name=action value="|
608 . $locale->text('Remove') . qq|">
609 <input class=submit type=submit name=action value="|
610 . $locale->text('Print') . qq|">
613 $form->get_lists(printers=>"ALL_PRINTERS");
614 print qq|<select name="printer">|;
615 print map(qq|<option value="$_->{id}">| . H($_->{printer_description}) . qq|</option>|, @{ $form->{ALL_PRINTERS} });
627 $main::lxdebug->leave_sub();
631 $lxdebug->enter_sub();
635 map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
638 $lxdebug->leave_sub();
641 sub continue { call_sub($form->{"nextsub"}); }