1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
25 # printing routines for ar, ap
28 # any custom scripts for this one
29 if (-f "$form->{path}/custom_arapprn.pl") {
30 eval { require "$form->{path}/custom_arapprn.pl"; };
32 if (-f "$form->{path}/$form->{login}_arapprn.pl") {
33 eval { require "$form->{path}/$form->{login}_arapprn.pl"; };
44 $form->{vc} = "vendor";
49 $form->{vc} = "customer";
54 if ($form->{media} !~ /screen/) {
55 $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
58 if ($form->{media} eq 'screen' && $form->{formname} =~ /(check|receipt)/) {
59 $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
62 if (! $form->{invnumber}) {
63 $form->{invnumber} = $form->update_defaults(\%myconfig, $invfld);
64 if ($form->{media} eq 'screen') {
65 if ($form->{media} eq 'screen') {
72 if ($form->{formname} =~ /(check|receipt)/) {
73 if ($form->{media} ne 'screen') {
74 map { delete $form->{$_} } qw(action header);
75 $form->{invtotal} = $form->{oldinvtotal};
77 foreach $key (keys %$form) {
78 $form->{$key} =~ s/&/%26/g;
79 $form->{previousform} .= qq|$key=$form->{$key}&|;
81 chop $form->{previousform};
82 $form->{previousform} = $form->escape($form->{previousform}, 1);
85 if ($form->{paidaccounts} > 1) {
86 if ($form->{"paid_$form->{paidaccounts}"}) {
89 } elsif ($form->{paidaccounts} > 2) {
95 $form->error($locale->text('Nothing to print!'));
100 &{ "print_$form->{formname}" }(1);
108 $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
110 if ($form->{"paid_$i"}) {
113 if (exists $form->{longformat}) {
114 $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
117 push @a, "source_$i", "memo_$i";
118 $form->format_string(@a);
121 $form->{amount} = $form->{"paid_$i"};
122 map { $form->{$_} = $form->{"${_}_$i"} } qw(datepaid source memo);
125 &{ "$form->{vc}_details" };
126 @a = qw(name address1 address2 city state zipcode country);
128 foreach $item (qw(invnumber ordnumber)) {
129 $temp{$item} = $form->{$item};
130 delete $form->{$item};
131 push(@{ $form->{$item} }, $temp{$item});
133 push(@{ $form->{invdate} }, $form->{transdate});
134 push(@{ $form->{due} }, $form->format_amount(\%myconfig, $form->{oldinvtotal}, 2));
135 push(@{ $form->{paid} }, $form->{"paid_$i"});
138 if ($form->{language_code}) {
139 $c = new CP $form->{language_code};
141 $c = new CP $myconfig->{countrycode};
144 ($whole, $form->{decimal}) = split /\./, $form->{amount};
145 $form->{decimal} .= "00";
146 $form->{decimal} = substr($form->{decimal}, 0, 2);
147 $form->{text_amount} = $c->num2text($whole);
149 ($form->{employee}) = split /--/, $form->{employee};
151 $form->{notes} =~ s/^\s+//g;
154 map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax businessnumber));
155 push @a, qw(company address tel fax businessnumber);
157 $form->format_string(@a);
159 $form->{templates} = "$myconfig{templates}";
160 $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
162 if ($form->{format} =~ /(postscript|pdf)/) {
163 $form->{IN} =~ s/html$/tex/;
166 if ($form->{media} !~ /(screen|queue)/) {
167 $form->{OUT} = "| $printer{$form->{media}}";
169 $reference = $form->{invnumber};
171 if ($form->{formname} =~ /(check|receipt)/) {
172 $form->{rowcount} = 1;
173 $form->{"id_1"} = $form->{id};
174 $form->{"checked_1"} = 1;
175 $form->{account} = $form->{"$form->{ARAP}_paid_$i"};
176 $reference = $form->{"source_$i"};
179 if ($form->{printed} !~ /$form->{formname}/) {
181 $form->{printed} .= " $form->{formname}";
182 $form->{printed} =~ s/^ //;
184 $form->update_status(\%myconfig);
187 %audittrail = ( tablename => lc $form->{ARAP},
188 reference => $reference,
189 formname => $form->{formname},
194 map { $status{$_} = $form->{$_} } qw(printed queued audittrail);
196 $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
200 if ($form->{media} eq 'queue') {
201 %queued = split / /, $form->{queued};
203 $reference = $form->{invnumber};
205 if ($form->{formname} =~ /(check|receipt)/) {
206 $form->{rowcount} = 1;
207 $form->{"id_1"} = $form->{id};
208 $form->{"checked_1"} = 1;
209 $form->{account} = $form->{"$form->{ARAP}_paid_$i"};
210 $reference = $form->{"source_$i"};
213 if ($filename = $queued{$form->{formname}}) {
214 $form->{queued} =~ s/$form->{formname} $filename//;
215 unlink "$spool/$filename";
216 $filename =~ s/\..*$//g;
222 $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
223 $form->{OUT} = ">$spool/$filename";
225 $form->{queued} .= " $form->{formname} $filename";
226 $form->{queued} =~ s/^ //;
229 $form->update_status(\%myconfig);
231 %audittrail = ( tablename => lc $form->{ARAP},
232 reference => $reference,
233 formname => $form->{formname},
238 map { $status{$_} = $form->{$_} } qw(printed queued audittrail);
240 $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
244 $form->{fileid} = $invnumber;
245 $form->{fileid} =~ s/(\s|\W)+//g;
247 $form->parse_template(\%myconfig, $userspath);
249 if ($form->{previousform}) {
251 $previousform = $form->unescape($form->{previousform});
253 map { delete $form->{$_} } keys %$form;
255 foreach $item (split /&/, $previousform) {
256 ($key, $value) = split /=/, $item, 2;
258 $form->{$key} = $value;
261 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
263 map { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) } (1 .. $form->{rowcount});
264 map { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } split / /, $form->{taxaccounts};
266 for $i (1 .. $form->{paidaccounts}) {
267 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
270 map { $form->{$_} = $status{$_} } qw(printed queued audittrail);
272 &{ "$display_form" };
279 sub print_receipt { &print_check; }
282 sub print_transaction {
284 $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
286 if ($form->{media} !~ /screen/) {
287 $old_form = new Form;
288 map { $old_form->{$_} = $form->{$_} } keys %$form;
291 &{ "$form->{vc}_details" };
292 @a = qw(name address1 address2 city state zipcode country);
295 $form->{invtotal} = 0;
296 foreach $i (1 .. $form->{rowcount} - 1) {
297 ($form->{tempaccno}, $form->{tempaccount}) = split /--/, $form->{"$form->{ARAP}_amount_$i"};
298 ($form->{tempprojectnumber}) = split /--/, $form->{"projectnumber_$i"};
300 $form->format_string(qw(tempaccno tempaccount tempprojectnumber));
302 push(@{ $form->{accno} }, $form->{tempaccno});
303 push(@{ $form->{account} }, $form->{tempaccount});
304 push(@{ $form->{projectnumber} }, $form->{tempprojectnumber});
306 push(@{ $form->{amount} }, $form->{"amount_$i"});
308 $form->{subtotal} += $form->parse_amount(\%myconfig, $form->{"amount_$i"});
312 foreach $accno (split / /, $form->{taxaccounts}) {
313 if ($form->{"tax_$accno"}) {
314 $tax += $form->parse_amount(\%myconfig, $form->{"tax_$accno"});
315 push(@{ $form->{tax} }, $form->{"tax_$accno"});
316 push(@{ $form->{taxdescription} }, $form->{"${accno}_description"});
317 push(@{ $form->{taxrate} }, $form->{"${accno}_rate"} * 100);
318 push(@{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"});
323 push @a, $form->{ARAP};
324 $form->format_string(@a);
327 for $i (1 .. $form->{paidaccounts} - 1) {
329 if ($form->{"paid_$i"}) {
331 $form->{paid} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
333 if (exists $form->{longformat}) {
334 $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
337 push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
338 $form->format_string(@a);
340 ($accno, $account) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
342 push(@{ $form->{payment} }, $form->{"paid_$i"});
343 push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"});
344 push(@{ $form->{paymentaccount} }, $account);
345 push(@{ $form->{paymentsource} }, $form->{"source_$i"});
346 push(@{ $form->{paymentmemo} }, $form->{"memo_$i"});
352 $form->{invtotal} = $form->{subtotal} + $tax;
353 $form->{total} = $form->{invtotal} - $form->{paid};
356 if ($form->{language_code}) {
357 $c = new CP $form->{language_code};
359 $c = new CP $myconfig->{countrycode};
362 ($whole, $form->{decimal}) = split /\./, $form->{invtotal};
363 $form->{decimal} .= "00";
364 $form->{decimal} = substr($form->{decimal}, 0, 2);
365 $form->{text_amount} = $c->num2text($whole);
367 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) } qw(invtotal subtotal paid total);
369 ($form->{employee}) = split /--/, $form->{employee};
371 if (exists $form->{longformat}) {
372 map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) } ("duedate", "transdate");
375 $form->{notes} =~ s/^\s+//g;
377 push @a, ("invnumber", "transdate", "duedate", "notes");
379 map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax businessnumber));
380 push @a, qw(company address tel fax businessnumber);
382 $form->format_string(@a);
384 $form->{invdate} = $form->{transdate};
386 $form->{templates} = "$myconfig{templates}";
387 $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
389 if ($form->{format} =~ /(postscript|pdf)/) {
390 $form->{IN} =~ s/html$/tex/;
393 if ($form->{media} !~ /(screen|queue)/) {
394 $form->{OUT} = "| $printer{$form->{media}}";
396 if ($form->{printed} !~ /$form->{formname}/) {
398 $form->{printed} .= " $form->{formname}";
399 $form->{printed} =~ s/^ //;
401 $form->update_status(\%myconfig);
404 $old_form->{printed} = $form->{printed};
406 %audittrail = ( tablename => lc $form->{ARAP},
407 reference => $form->{"invnumber"},
408 formname => $form->{formname},
412 $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
416 if ($form->{media} eq 'queue') {
417 %queued = split / /, $form->{queued};
419 if ($filename = $queued{$form->{formname}}) {
420 $form->{queued} =~ s/$form->{formname} $filename//;
421 unlink "$spool/$filename";
422 $filename =~ s/\..*$//g;
428 $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
429 $form->{OUT} = ">$spool/$filename";
431 $form->{queued} .= " $form->{formname} $filename";
432 $form->{queued} =~ s/^ //;
435 $form->update_status(\%myconfig);
437 $old_form->{queued} = $form->{queued};
439 %audittrail = ( tablename => lc $form->{ARAP},
440 reference => $form->{invnumber},
441 formname => $form->{formname},
444 $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
448 $form->{fileid} = $form->{invnumber};
449 $form->{fileid} =~ s/(\s|\W)+//g;
451 $form->parse_template(\%myconfig, $userspath);
454 $old_form->{invnumber} = $form->{invnumber};
455 $old_form->{invtotal} = $form->{invtotal};
457 map { delete $form->{$_} } keys %$form;
458 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
460 if (! $form->{printandpost}) {
461 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
463 map { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) } (1 .. $form->{rowcount});
464 map { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } split / /, $form->{taxaccounts};
466 for $i (1 .. $form->{paidaccounts}) {
467 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
471 &{ "$display_form" };
477 sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
478 sub customer_details { IS->customer_details(\%myconfig, \%$form) };
483 @column_index = ("ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid");
485 # list payments with radio button on a form
488 $title = $locale->text('Select payment');
490 $column_data{ndx} = qq|<th width=1%> </th>|;
491 $column_data{datepaid} = qq|<th>|.$locale->text('Date').qq|</th>|;
492 $column_data{source} = qq|<th>|.$locale->text('Source').qq|</th>|;
493 $column_data{memo} = qq|<th>|.$locale->text('Memo').qq|</th>|;
494 $column_data{paid} = qq|<th>|.$locale->text('Amount').qq|</th>|;
495 $column_data{"$form->{ARAP}_paid"} = qq|<th>|.$locale->text('Account').qq|</th>|;
500 <form method=post action=$form->{script}>
504 <th class=listtop>$title</th>
510 <tr class=listheading>|;
512 map { print "\n$column_data{$_}" } @column_index;
518 foreach $i (1 .. $form->{paidaccounts} - 1) {
519 $checked = ($i == 1) ? "checked" : "";
521 map { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| } @column_index;
522 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
523 $column_data{paid} = qq|<td align=right>$form->{"paid_$i"}</td>|;
527 <tr class=listrow$j>|;
529 map { print "\n$column_data{$_}" } @column_index;
542 <td><hr size=3 noshade></td>
547 $form->{nextsub} = "payment_selected";
554 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
563 sub payment_selected {
565 &{ "print_$form->{formname}" }($form->{ndx});
572 $form->{PD}{$form->{formname}} = "selected";
573 $form->{DF}{$form->{format}} = "selected";
575 if ($form->{selectlanguage}) {
576 $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
577 $form->{"selectlanguage"} =~ s/ selected//;
578 $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
579 $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
580 <input type=hidden name=selectlanguage value="|.
581 $form->escape($form->{selectlanguage},1).qq|">|;
584 $type = qq|<select name=formname>
585 <option value=transaction $form->{PD}{transaction}>|.$locale->text('Transaction');
589 <option value=receipt $form->{PD}{receipt}>|.$locale->text('Receipt').qq|</select>|;
594 <option value=check $form->{PD}{check}>|.$locale->text('Check').qq|</select>|;
597 $media = qq|<select name=media>
598 <option value=screen>|.$locale->text('Screen');
600 if (%printer && $latex) {
602 <option value="$_">$_| } sort keys %printer;
605 $format = qq|<select name=format>
606 <option value=html $form->{DF}{html}>html|;
611 # <option value="queue">|.$locale->text('Queue');
613 <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
614 <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
617 $format .= qq|</select>|;
618 $media .= qq|</select>|;
619 $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
633 if ($form->{printed} =~ /$form->{formname}/) {
634 print $locale->text('Printed').qq|<br>|;
637 if ($form->{queued} =~ /$form->{formname}/) {
638 print $locale->text('Queued');
652 $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
653 $form->error($locale->text('Select Printer or Queue!')) if $form->{media} eq 'screen';
655 $form->{printandpost} = 1;
656 $form->{display_form} = "post";