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 {
48 'invoice' => 'invoice_edit',
49 'sales_order' => 'sales_order_edit',
50 'sales_quotation' => 'sales_quotation_edit',
51 'purchase_order' => 'purchase_order_edit',
52 'request_quotation' => 'request_quotation_edit',
57 if ($::form->{type} && $access_map{$::form->{type}}) {
58 $::auth->assert($access_map{$::form->{type}});
61 $::auth->assert('DOES_NOT_EXIST');
66 $::lxdebug->enter_sub;
70 # setup customer/vendor selection
71 BP->get_vc(\%::myconfig, $::form);
74 invoice => { title => $::locale->text('Sales Invoices'), invnumber => 1, ordnumber => 1 },
75 sales_order => { title => $::locale->text('Sales Orders'), ordnumber => 1, },
76 purchase_order => { title => $::locale->text('Purchase Orders'), ordnumber => 1, },
77 sales_quotation => { title => $::locale->text('Quotations'), quonumber => 1, },
78 request_quotation => { title => $::locale->text('RFQs'), quonumber => 1, },
79 check => { title => $::locale->text('Checks'), chknumber => 1, },
80 receipt => { title => $::locale->text('Receipts'), rctnumber => 1, },
83 my $bp_accounts = $::form->{type} =~ /check|receipt/
84 && BP->payment_accounts(\%::myconfig, $::form);
87 print $::form->parse_html_template('bp/search', {
89 show_accounts => $bp_accounts,
90 account_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
91 vc_keys => sub { "$_[0]{name}--$_[0]{id}" },
94 $::lxdebug->leave_sub;
98 $::lxdebug->enter_sub;
101 $::form->info($::locale->text('Removing marked entries from queue ...'));
102 $::form->{callback} .= "&header=1" if $::form->{callback};
104 $::form->redirect($::locale->text('Removed spoolfiles!'))
105 if BP->delete_spool(\%::myconfig, $::form);
106 $::form->error($::locale->text('Cannot remove files!'));
108 $::lxdebug->leave_sub;
112 $::lxdebug->enter_sub;
115 $::form->get_lists(printers => 'ALL_PRINTERS');
116 # use the command stored in the databse or fall back to $myconfig{printer}
117 my $selected_printer = first { $_ } map ({ $_ ->{printer_command} }
118 grep { $_->{id} eq $::form->{printer} }
119 @{ $::form->{ALL_PRINTERS} }),
120 $::myconfig{printer};
122 if ($::form->{callback}) {
123 map { $::form->{callback} .= "&checked_$_=1" if $::form->{"checked_$_"} }
124 (1 .. $::form->{rowcount});
125 $::form->{callback} .= "&header=1";
128 for my $i (1 .. $::form->{rowcount}) {
129 if ($::form->{"checked_$i"}) {
130 $::form->info($::locale->text('Printing ... '));
132 if (BP->print_spool(\%::myconfig, $::form, "| $selected_printer")) {
133 print $::locale->text('done');
134 $::form->redirect($::locale->text('Marked entries printed!'));
140 $::form->error('Nothing selected!');
142 $::lxdebug->leave_sub;
146 $::lxdebug->enter_sub;
149 # parse old vc picker
150 $::form->{ $::form->{vc} } = $::form->unescape($::form->{ $::form->{vc} });
151 ($::form->{ $::form->{vc} }, $::form->{"$::form->{vc}_id"}) = split(/--/, $::form->{ $::form->{vc} });
153 BP->get_spoolfiles(\%::myconfig, $::form);
155 my @href_options = ('vc', 'type', 'title', $::form->{vc});
158 customer => sub { $::locale->text('Customer') . " : $::form->{customer}" },
159 vendor => sub { $::locale->text('Customer') . " : $::form->{vendor}" },
160 account => sub { $::locale->text('Account') . " : $::form->{account}" },
161 invnumber => sub { $::locale->text('Invoice Number') . " : $::form->{invnumber}" },
162 ordnumber => sub { $::locale->text('Order Number') . " : $::form->{ordnumber}" },
163 quonumber => sub { $::locale->text('Quotation Number') . " : $::form->{quonumber}" },
164 transdatefrom => sub { $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{transdatefrom}, 1) },
165 transdateto => sub { $::locale->text('To') . " " . $::locale->date(\%::myconfig, $::form->{transdateto}, 1) },
169 for my $key ($::form->{vc}, qw(account invnumber ordnumber quonumber transdatefrom transdateto)) {
170 next unless $::form->{$key};
171 push @href_options, $key;
172 push @options, $option_texts{$key} ? $option_texts{$key}->() : '';
176 for my $ref (@{ $::form->{SPOOL} }) {
177 $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir" if $ref->{invoice};
178 $ref->{new_file} = $last_spoolfile ne $ref->{spoolfile};
180 $last_spoolfile = $ref->{spoolfile};
183 $::form->get_lists(printers => "ALL_PRINTERS");
186 print $::form->parse_html_template('bp/list_spool', {
187 spool => $::lx_office_conf{paths}->{spool},
188 href => build_std_url('bp.pl', @href_options),
189 is_invoice => scalar ($::form->{type} =~ /^invoice$/),
190 is_order => scalar ($::form->{type} =~ /_order$/),
191 is_quotation => scalar ($::form->{type} =~ /_quotation$/),
192 options => \@options,
195 $::lxdebug->leave_sub;
198 sub continue { call_sub($::form->{"nextsub"}); }