1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
25 # Batch printing module backend routines
27 #======================================================================
33 my ($self, $myconfig, $form) = @_;
36 my $dbh = $form->dbconnect($myconfig);
38 my %arap = ( invoice => ['ar'],
39 packing_list => ['oe', 'ar'],
40 sales_order => ['oe'],
42 pick_list => ['oe', 'ar'],
43 purchase_order => ['oe'],
45 sales_quotation => ['oe'],
46 request_quotation => ['oe'],
57 foreach $item (@{ $arap{$form->{type}} }) {
60 FROM (SELECT DISTINCT vc.id
61 FROM $form->{vc} vc, $item a, status s
62 WHERE a.$form->{vc}_id = vc.id
64 AND s.formname = '$form->{type}'
65 AND s.spoolfile IS NOT NULL) AS total|;
66 ($n) = $dbh->selectrow_array($query);
71 # build selection list
74 if ($count < $myconfig->{vclimit}) {
75 foreach $item (@{ $arap{$form->{type}} }) {
78 SELECT DISTINCT vc.id, vc.name
79 FROM $form->{vc} vc, $item a, status s
80 WHERE a.$form->{vc}_id = vc.id
82 AND s.formname = '$form->{type}'
83 AND s.spoolfile IS NOT NULL|;
87 $sth = $dbh->prepare($query);
88 $sth->execute || $form->dberror($query);
90 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
91 push @{ $form->{"all_$form->{vc}"} }, $ref;
96 $form->all_years($dbh, $myconfig);
104 sub payment_accounts {
105 my ($self, $myconfig, $form) = @_;
107 # connect to database
108 my $dbh = $form->dbconnect($myconfig);
110 my $query = qq|SELECT DISTINCT c.accno, c.description
111 FROM status s, chart c
112 WHERE s.chart_id = c.id
113 AND s.formname = '$form->{type}'|;
114 my $sth = $dbh->prepare($query);
115 $sth->execute || $form->dberror($query);
117 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
118 push @{ $form->{accounts} }, $ref;
128 my ($self, $myconfig, $form) = @_;
130 # connect to database
131 my $dbh = $form->dbconnect($myconfig);
134 my $invnumber = "invnumber";
137 my %arap = ( invoice => ['ar'],
138 packing_list => ['oe', 'ar'],
139 sales_order => ['oe'],
140 work_order => ['oe'],
141 pick_list => ['oe', 'ar'],
142 purchase_order => ['oe'],
144 sales_quotation => ['oe'],
145 request_quotation => ['oe'],
151 if ($form->{type} eq 'check' || $form->{type} eq 'receipt') {
153 my ($accno) = split /--/, $form->{account};
155 $query = qq|SELECT a.id, vc.name, a.invnumber, ac.transdate, s.spoolfile,
156 a.invoice, '$arap{$form->{type}}[0]' AS module
158 JOIN chart c ON (c.id = ac.chart_id)
159 JOIN $arap{$form->{type}}[0] a ON (a.id = ac.trans_id)
160 JOIN status s ON (s.trans_id = a.id)
161 JOIN $form->{vc} vc ON (vc.id = a.$form->{vc}_id)
162 WHERE s.formname = '$form->{type}'
163 AND c.accno = '$accno'
164 AND NOT ac.fx_transaction|;
166 if ($form->{"$form->{vc}_id"}) {
167 $query .= qq| AND a.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
169 if ($form->{$form->{vc}}) {
170 $item = $form->like(lc $form->{$form->{vc}});
171 $query .= " AND lower(vc.name) LIKE '$item'";
174 if ($form->{invnumber}) {
175 $item = $form->like(lc $form->{invnumber});
176 $query .= " AND lower(a.invnumber) LIKE '$item'";
178 if ($form->{ordnumber}) {
179 $item = $form->like(lc $form->{ordnumber});
180 $query .= " AND lower(a.ordnumber) LIKE '$item'";
182 if ($form->{quonumber}) {
183 $item = $form->like(lc $form->{quonumber});
184 $query .= " AND lower(a.quonumber) LIKE '$item'";
187 $query .= " AND a.transdate >= '$form->{transdatefrom}'" if $form->{transdatefrom};
188 $query .= " AND a.transdate <= '$form->{transdateto}'" if $form->{transdateto};
193 foreach $item (@{ $arap{$form->{type}} }) {
195 $invoice = "a.invoice";
196 $invnumber = "invnumber";
199 $invnumber = "ordnumber";
205 SELECT a.id, vc.name, a.$invnumber AS invnumber, a.transdate,
206 a.ordnumber, a.quonumber, $invoice AS invoice,
207 '$item' AS module, s.spoolfile
208 FROM $item a, $form->{vc} vc, status s
209 WHERE s.trans_id = a.id
210 AND s.spoolfile IS NOT NULL
211 AND s.formname = '$form->{type}'
212 AND a.$form->{vc}_id = vc.id|;
214 if ($form->{"$form->{vc}_id"}) {
215 $query .= qq| AND a.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
217 if ($form->{$form->{vc}}) {
218 $item = $form->like(lc $form->{$form->{vc}});
219 $query .= " AND lower(vc.name) LIKE '$item'";
222 if ($form->{invnumber}) {
223 $item = $form->like(lc $form->{invnumber});
224 $query .= " AND lower(a.invnumber) LIKE '$item'";
226 if ($form->{ordnumber}) {
227 $item = $form->like(lc $form->{ordnumber});
228 $query .= " AND lower(a.ordnumber) LIKE '$item'";
230 if ($form->{quonumber}) {
231 $item = $form->like(lc $form->{quonumber});
232 $query .= " AND lower(a.quonumber) LIKE '$item'";
235 $query .= " AND a.transdate >= '$form->{transdatefrom}'" if $form->{transdatefrom};
236 $query .= " AND a.transdate <= '$form->{transdateto}'" if $form->{transdateto};
243 my %ordinal = ( 'name' => 2,
249 my @a = (transdate, $invnumber, name);
250 my $sortorder = $form->sort_order(\@a, \%ordinal);
252 $query .= " ORDER by $sortorder";
254 my $sth = $dbh->prepare($query);
255 $sth->execute || $form->dberror($query);
257 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
258 push @{ $form->{SPOOL} }, $ref;
268 my ($self, $myconfig, $form, $spool) = @_;
270 # connect to database, turn AutoCommit off
271 my $dbh = $form->dbconnect_noauto($myconfig);
276 if ($form->{type} =~ /(check|receipt)/) {
277 $query = qq|DELETE FROM status
278 WHERE spoolfile = ?|;
280 $query = qq|UPDATE status SET
283 WHERE spoolfile = ?|;
285 my $sth = $dbh->prepare($query) || $form->dberror($query);
288 foreach my $i (1 .. $form->{rowcount}) {
289 if ($form->{"checked_$i"}) {
290 $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query);
293 %audittrail = ( tablename => $form->{module},
294 reference => $form->{"reference_$i"},
295 formname => $form->{type},
296 action => 'dequeued',
297 id => $form->{"id_$i"} );
299 $form->audittrail($dbh, "", \%audittrail);
304 my $rc = $dbh->commit;
308 foreach my $i (1 .. $form->{rowcount}) {
309 $_ = qq|$spool/$form->{"spoolfile_$i"}|;
310 if ($form->{"checked_$i"}) {
322 my ($self, $myconfig, $form, $spool) = @_;
324 # connect to database
325 my $dbh = $form->dbconnect_noauto($myconfig);
329 my $query = qq|UPDATE status SET
331 WHERE formname = '$form->{type}'
333 my $sth = $dbh->prepare($query) || $form->dberror($query);
335 foreach my $i (1 .. $form->{rowcount}) {
336 if ($form->{"checked_$i"}) {
337 open(OUT, $form->{OUT}) or $form->error("$form->{OUT} : $!");
339 $spoolfile = qq|$spool/$form->{"spoolfile_$i"}|;
341 # send file to printer
342 open(IN, $spoolfile) or $form->error("$spoolfile : $!");
350 $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query);
353 %audittrail = ( tablename => $form->{module},
354 reference => $form->{"reference_$i"},
355 formname => $form->{type},
357 id => $form->{"id_$i"} );
359 $form->audittrail($dbh, "", \%audittrail);