1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
9 # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
10 # Benjamin Lee <benjaminlee@consultant.com>
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #======================================================================
26 # module for preparing Income Statement and Balance Sheet
28 #======================================================================
30 require "$form->{path}/arap.pl";
38 # this is for our long dates
39 # $locale->text('January')
40 # $locale->text('February')
41 # $locale->text('March')
42 # $locale->text('April')
43 # $locale->text('May ')
44 # $locale->text('June')
45 # $locale->text('July')
46 # $locale->text('August')
47 # $locale->text('September')
48 # $locale->text('October')
49 # $locale->text('November')
50 # $locale->text('December')
52 # this is for our short month
53 # $locale->text('Jan')
54 # $locale->text('Feb')
55 # $locale->text('Mar')
56 # $locale->text('Apr')
57 # $locale->text('May')
58 # $locale->text('Jun')
59 # $locale->text('Jul')
60 # $locale->text('Aug')
61 # $locale->text('Sep')
62 # $locale->text('Oct')
63 # $locale->text('Nov')
64 # $locale->text('Dec')
66 # $locale->text('Balance Sheet')
67 # $locale->text('Income Statement')
68 # $locale->text('Trial Balance')
69 # $locale->text('AR Aging')
70 # $locale->text('AP Aging')
71 # $locale->text('Tax collected')
72 # $locale->text('Tax paid')
73 # $locale->text('Receipts')
74 # $locale->text('Payments')
75 # $locale->text('Project Transactions')
76 # $locale->text('Non-taxable Sales')
77 # $locale->text('Non-taxable Purchases')
82 %title = ( balance_sheet => 'Balance Sheet',
83 income_statement => 'Income Statement',
84 trial_balance => 'Trial Balance',
85 ar_aging => 'AR Aging',
86 ap_aging => 'AP Aging',
87 tax_collected => 'Tax collected',
88 tax_paid => 'Tax paid',
89 nontaxable_sales => 'Non-taxable Sales',
90 nontaxable_purchases => 'Non-taxable Purchases',
91 receipts => 'Receipts',
92 payments => 'Payments',
93 projects => 'Project Transactions',
96 $form->{title} = $locale->text($title{$form->{report}});
100 <th align=right>|.$locale->text('Accounts').qq|</th>
101 <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq|
103 <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq|
109 $form->all_departments(\%myconfig);
110 if (@{ $form->{all_departments} }) {
111 $form->{selectdepartment} = "<option>\n";
113 map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });
118 <th align=right nowrap>|.$locale->text('Department').qq|</th>
119 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
121 | if $form->{selectdepartment};
124 $form->{selectaccountingyear} = "<option>\n";
125 map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} };
127 $form->{selectaccountingmonth} = "<option>\n";
128 map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} };
132 <th align=right>|.$locale->text('Period').qq|</th>
134 <select name=month>$form->{selectaccountingmonth}</select>
135 <select name=year>$form->{selectaccountingyear}</select>
136 <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
137 <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
138 <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
139 <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
146 <th align=right></th>
148 <select name=month>$form->{selectaccountingmonth}</select>
149 <select name=year>$form->{selectaccountingyear}</select>
158 <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
159 <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
165 $form->all_projects(\%myconfig);
166 if (@{ $form->{all_projects} }) {
167 $form->{selectproject} = "<option>\n";
168 map { $form->{selectproject} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} };
172 <th align=right nowrap>|.$locale->text('Project').qq|</th>
173 <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td>
183 <form method=post action=$form->{script}>
185 <input type=hidden name=title value="$form->{title}">
189 <th class=listtop>$form->{title}</th>
198 if ($form->{report} eq "projects") {
201 <input type=hidden name=nextsub value=generate_projects>
203 <th align=right>|.$locale->text('From').qq|</th>
204 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
205 <th align=right>|.$locale->text('To').qq|</th>
206 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
216 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
217 <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|
218 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
223 if ($form->{report} eq "income_statement") {
226 <input type=hidden name=nextsub value=generate_income_statement>
228 <th align=right>|.$locale->text('From').qq|</th>
229 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
230 <th align=right>|.$locale->text('To').qq|</th>
231 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
234 <th align=right>|.$locale->text('Period').qq|</th>
236 <select name=frommonth>$form->{selectaccountingmonth}</select>
237 <select name=fromyear>$form->{selectaccountingyear}</select>
238 <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
239 <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
240 <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
241 <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
245 <th align=right>|.$locale->text('Compare to').qq|</th>
248 <th align=right>|.$locale->text('From').qq|</th>
249 <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
250 <th align=right>|.$locale->text('To').qq|</th>
251 <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>
254 <th align=right>|.$locale->text('Period').qq|</th>
256 <select name=comparemonth>$form->{selectaccountingmonth}</select>
257 <select name=compareyear>$form->{selectaccountingyear}</select>
261 <th align=right>|.$locale->text('Decimalplaces').qq|</th>
262 <td><input name=decimalplaces size=3 value=2></td>
271 <th align=right>|.$locale->text('Method').qq|</th>
272 <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
273 <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
277 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
278 <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|
279 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|
280 <input name=l_accno class=checkbox type=checkbox value=Y> |.$locale->text('Account Number').qq|</td>
286 if ($form->{report} eq "balance_sheet") {
288 <input type=hidden name=nextsub value=generate_balance_sheet>
290 <th align=right>|.$locale->text('as at').qq|</th>
291 <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
293 <select name=asofmonth>$form->{selectaccountingmonth}</select>
294 <select name=asofyear>$form->{selectaccountingyear}</select>
298 <th align=right nowrap>|.$locale->text('Compare to').qq|</th>
299 <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
301 <select name=compareasofmonth>$form->{selectaccountingmonth}</select>
302 <select name=compareasofyear>$form->{selectaccountingyear}</select>
307 <th align=right>|.$locale->text('Decimalplaces').qq|</th>
308 <td><input name=decimalplaces size=3 value=2></td>
317 <th align=right>|.$locale->text('Method').qq|</th>
318 <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
319 <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
323 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
324 <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|
325 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|
326 <input name=l_accno class=checkbox type=checkbox value=Y> |.$locale->text('Account Number').qq|</td>
332 if ($form->{report} eq "trial_balance") {
334 <input type=hidden name=nextsub value=generate_trial_balance>
336 <th align=right>|.$locale->text('From').qq|</th>
337 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
338 <th align=right>|.$locale->text('To').qq|</th>
339 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
349 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
350 <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|
351 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|
352 <input name=all_accounts class=checkbox type=checkbox value=Y> |.$locale->text('All Accounts').qq|</td>
358 if ($form->{report} =~ /^tax_/) {
361 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
363 RP->get_taxaccounts(\%myconfig, \%$form);
366 <input type=hidden name=nextsub value=generate_tax_report>
368 <th align=right>|.$locale->text('From').qq|</th>
369 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
370 <th align=right>|.$locale->text('To').qq|</th>
371 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
376 <th align=right>|.$locale->text('Report for').qq|</th>
380 $checked = "checked";
381 foreach $ref (@{ $form->{taxaccounts} }) {
383 print qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
385 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
386 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
393 <input type=hidden name=db value=$form->{db}>
394 <input type=hidden name=sort value=transdate>
401 if (@{ $form->{gifi_taxaccounts} }) {
404 <th align=right>|.$locale->text('GIFI').qq|</th>
408 foreach $ref (@{ $form->{gifi_taxaccounts} }) {
410 print qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}"> $ref->{description}
412 <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
413 <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
426 <th align=right>|.$locale->text('Method').qq|</th>
427 <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
428 <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
437 <th align=right>|.$locale->text('Include in Report').qq|</th>
441 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
442 <td>|.$locale->text('ID').qq|</td>
443 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
444 <td>|.$locale->text('Invoice').qq|</td>
445 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
446 <td>|.$locale->text('Date').qq|</td>
449 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
452 if ($form->{db} eq 'ar') {
453 print qq|<td>|.$locale->text('Customer').qq|</td>|;
455 if ($form->{db} eq 'ap') {
456 print qq|<td>|.$locale->text('Vendor').qq|</td>|;
460 <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
461 <td>|.$locale->text('Description').qq|</td>
462 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
463 <td>|.$locale->text('Amount').qq|</td>
465 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
466 <td>|.$locale->text('Tax').qq|</td>
468 <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>
469 <td>|.$locale->text('Total').qq|</td>
474 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
475 <td>|.$locale->text('Subtotal').qq|</td>
485 if ($form->{report} =~ /^nontaxable_/) {
488 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
491 <input type=hidden name=nextsub value=generate_tax_report>
493 <input type=hidden name=db value=$form->{db}>
494 <input type=hidden name=sort value=transdate>
495 <input type=hidden name=report value=$form->{report}>
498 <th align=right>|.$locale->text('From').qq|</th>
499 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
500 <th align=right>|.$locale->text('To').qq|</th>
501 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
506 <th align=right>|.$locale->text('Method').qq|</th>
507 <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
508 <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
511 <th align=right>|.$locale->text('Include in Report').qq|</th>
515 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
516 <td>|.$locale->text('ID').qq|</td>
517 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
518 <td>|.$locale->text('Invoice').qq|</td>
519 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
520 <td>|.$locale->text('Date').qq|</td>
523 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
526 if ($form->{db} eq 'ar') {
527 print qq|<td>|.$locale->text('Customer').qq|</td>|;
529 if ($form->{db} eq 'ap') {
530 print qq|<td>|.$locale->text('Vendor').qq|</td>|;
534 <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
535 <td>|.$locale->text('Description').qq|</td>
536 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
537 <td>|.$locale->text('Amount').qq|</td>
540 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
541 <td>|.$locale->text('Subtotal').qq|</td>
551 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
554 if ($form->{report} eq 'ar_aging') {
555 $label = $locale->text('Customer');
556 $form->{vc} = 'customer';
558 $label = $locale->text('Vendor');
559 $form->{vc} = 'vendor';
562 $nextsub = "generate_$form->{report}";
565 $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
567 map { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{"all_$form->{vc}"} };
569 $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
571 $postscript = "postscript" if $myconfig{printer};
575 <th align=right>|.$locale->text($label).qq|</th>
579 <th align=right>|.$locale->text('To').qq|</th>
580 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
583 <input type=hidden name=type value=statement>
584 <input type=hidden name=format value=$postscript>
585 <input type=hidden name=media value="$myconfig{printer}">
587 <input type=hidden name=nextsub value=$nextsub>
588 <input type=hidden name=action value=$nextsub>
593 # above action can be removed if there is more than one input field
596 if ($form->{report} =~ /(receipts|payments)$/) {
599 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
601 RP->paymentaccounts(\%myconfig, \%$form);
603 $selection = "<option>\n";
604 foreach $ref (@{ $form->{PR} }) {
605 $paymentaccounts .= "$ref->{accno} ";
606 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
609 chop $paymentaccounts;
612 <input type=hidden name=nextsub value=list_payments>
614 <th align=right nowrap>|.$locale->text('Account').qq|</th>
615 <td colspan=3><select name=account>$selection</select>
616 <input type=hidden name=paymentaccounts value="$paymentaccounts">
620 <th align=right nowrap>|.$locale->text('Description').qq|</th>
621 <td colspan=3><input name=description size=35></td>
624 <th align=right nowrap>|.$locale->text('Source').qq|</th>
625 <td colspan=3><input name=source></td>
628 <th align=right nowrap>|.$locale->text('Memo').qq|</th>
629 <td colspan=3><input name=memo size=30></td>
632 <th align=right>|.$locale->text('From').qq|</th>
633 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
634 <th align=right>|.$locale->text('To').qq|</th>
635 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
639 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
640 <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td>
643 <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td>
644 <td align=left colspan=3>|.$locale->text('Subtotal').qq|</th>
647 <input type=hidden name=db value=$form->{db}>
648 <input type=hidden name=sort value=transdate>
662 <td><hr size=3 noshade></td>
667 <input type=hidden name=path value=$form->{path}>
668 <input type=hidden name=login value=$form->{login}>
669 <input type=hidden name=sessionid value=$form->{sessionid}>
671 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
682 sub continue { &{$form->{nextsub}} };
685 sub generate_income_statement {
687 $form->{padding} = " ";
688 $form->{bold} = "<b>";
689 $form->{endbold} = "</b>";
690 $form->{br} = "<br>";
692 RP->income_statement(\%myconfig, \%$form);
694 ($form->{department}) = split /--/, $form->{department};
695 ($form->{projectnumber}) = split /--/, $form->{projectnumber};
697 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
698 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
700 # if there are any dates construct a where
701 if ($form->{fromdate} || $form->{todate}) {
703 unless ($form->{todate}) {
704 $form->{todate} = $form->current_date(\%myconfig);
707 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
708 $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
710 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
711 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
713 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
714 $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('To').qq| $longtodate|;
717 if ($form->{comparefromdate} || $form->{comparetodate}) {
718 $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
719 $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
721 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
722 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
724 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
725 $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('To').qq| $longcomparetodate|;
728 # setup variables for the form
729 @a = qw(company address businessnumber);
730 map { $form->{$_} = $myconfig{$_} } @a;
731 $form->{address} =~ s/\\n/<br>/g;
733 $form->{templates} = $myconfig{templates};
735 $form->{IN} = "income_statement.html";
737 $form->parse_template;
742 sub generate_balance_sheet {
744 $form->{padding} = " ";
745 $form->{bold} = "<b>";
746 $form->{endbold} = "</b>";
747 $form->{br} = "<br>";
749 RP->balance_sheet(\%myconfig, \%$form);
751 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
752 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
754 ($form->{department}) = split /--/, $form->{department};
756 # define Current Earnings account
757 $padding = ($form->{l_heading}) ? $form->{padding} : "";
758 push(@{$form->{equity_account}}, $padding.$locale->text('Current Earnings'));
760 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
761 $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
763 $form->{IN} = "balance_sheet.html";
765 # setup company variables for the form
766 map { $form->{$_} = $myconfig{$_} } (qw(company address businessnumber nativecurr));
767 $form->{address} =~ s/\\n/<br>/g;
769 $form->{templates} = $myconfig{templates};
771 $form->parse_template;
776 sub generate_projects {
778 $form->{nextsub} = "generate_projects";
779 $form->{title} = $locale->text('Project Transactions');
780 RP->trial_balance(\%myconfig, \%$form);
790 # included links to display transactions for period entered
791 # added headers and subtotals
793 sub generate_trial_balance {
795 # get for each account initial balance, debits and credits
796 RP->trial_balance(\%myconfig, \%$form);
798 $form->{nextsub} = "generate_trial_balance";
799 $form->{title} = $locale->text('Trial Balance');
807 $title = $form->escape($form->{title});
809 if ($form->{department}) {
810 ($department) = split /--/, $form->{department};
811 $options = $locale->text('Department')." : $department<br>";
812 $department = $form->escape($form->{department});
814 if ($form->{projectnumber}) {
815 ($projectnumber) = split /--/, $form->{projectnumber};
816 $options .= $locale->text('Project Number')." : $projectnumber<br>";
817 $projectnumber = $form->escape($form->{projectnumber});
820 # if there are any dates
821 if ($form->{fromdate} || $form->{todate}) {
822 if ($form->{fromdate}) {
823 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
825 if ($form->{todate}) {
826 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
829 $form->{period} = "$fromdate - $todate";
831 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
834 $options .= $form->{period};
836 @column_index = qw(accno description begbalance debit credit endbalance);
838 $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|;
839 $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
840 $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
841 $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
842 $column_header{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
843 $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
846 if ($form->{accounttype} eq 'gifi') {
847 $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|;
858 <th class=listtop>$form->{title}</th>
869 map { print "$column_header{$_}\n" } @column_index;
877 # sort the whole thing by account numbers and display
878 foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
880 $description = $form->escape($ref->{description});
882 $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
884 if ($form->{accounttype} eq 'gifi') {
885 $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
886 $na = $locale->text('N/A');
887 map { $ref->{$_} = $na } qw(accno description) unless $ref->{accno};
889 $href .= "&accno=$ref->{accno}&description=$description";
892 $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
894 $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
895 $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
896 $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, " ");
897 $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, " ");
900 if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
904 map { $column_data{$_} = "<th> </th>" } qw(accno begbalance endbalance);
906 $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " ");
907 $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");
908 $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
909 $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
911 $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
912 $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
913 $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
914 $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
915 $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
918 <tr class=listsubtotal>
920 map { print "$column_data{$_}\n" } @column_index;
928 if ($ref->{charttype} eq "H") {
930 $subtotaldescription = $ref->{description};
931 $subtotaldebit = $ref->{debit};
932 $subtotalcredit = $ref->{credit};
933 $subtotalbegbalance = 0;
934 $subtotalendbalance = 0;
936 if ($form->{l_heading}) {
937 if (! $form->{all_accounts}) {
938 if (($subtotaldebit + $subtotalcredit) == 0) {
945 if ($form->{all_accounts} || ($form->{l_subtotal} && (($subtotaldebit + $subtotalcredit) != 0))) {
951 map { $column_data{$_} = "<th> </th>" } qw(accno debit credit begbalance endbalance);
952 $column_data{description} = "<th class=listheading>$ref->{description}</th>";
955 if ($ref->{charttype} eq "A") {
956 $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
957 $column_data{description} = "<td>$ref->{description}</td>";
958 $column_data{debit} = "<td align=right>$debit</td>";
959 $column_data{credit} = "<td align=right>$credit</td>";
960 $column_data{begbalance} = "<td align=right>$begbalance</td>";
961 $column_data{endbalance} = "<td align=right>$endbalance</td>";
963 $totaldebit += $ref->{debit};
964 $totalcredit += $ref->{credit};
966 $cml = ($ref->{category} eq 'C') ? -1 : 1;
967 $subtotalbegbalance += $ref->{balance} * $ml * $cml;
968 $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml * $cml;
973 if ($ref->{charttype} eq "H") {
975 <tr class=listheading>
978 if ($ref->{charttype} eq "A") {
985 map { print "$column_data{$_}\n" } @column_index;
993 # print last subtotal
994 if ($subtotal && $form->{l_subtotal}) {
995 map { $column_data{$_} = "<th> </th>" } qw(accno begbalance endbalance);
996 $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " ");
997 $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");
998 $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
999 $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
1000 $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
1001 $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
1002 $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
1003 $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
1004 $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
1007 <tr class=listsubtotal>
1009 map { print "$column_data{$_}\n" } @column_index;
1016 $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, " ");
1017 $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, " ");
1019 map { $column_data{$_} = "<th> </th>" } qw(accno description begbalance endbalance);
1021 $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
1022 $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
1025 <tr class=listtotal>
1028 map { print "$column_data{$_}\n" } @column_index;
1036 <td><hr size=3 noshade></td>
1047 sub generate_ar_aging {
1050 ($form->{customer}) = split(/--/, $form->{customer});
1051 $customer = $form->escape($form->{customer},1);
1052 $title = $form->escape($form->{title},1);
1053 $media = $form->escape($form->{media},1);
1055 $form->{ct} = "customer";
1056 $form->{arap} = "ar";
1058 RP->aging(\%myconfig, \%$form);
1060 $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&customer=$customer&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
1067 sub generate_ap_aging {
1070 ($form->{vendor}) = split(/--/, $form->{vendor});
1071 $vendor = $form->escape($form->{vendor},1);
1072 $title = $form->escape($form->{title},1);
1073 $media = $form->escape($form->{media},1);
1075 $form->{ct} = "vendor";
1076 $form->{arap} = "ap";
1078 RP->aging(\%myconfig, \%$form);
1080 $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&vendor=$vendor&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
1091 $column_header{statement} = qq|<th class=listheading width=1%> </th>|;
1092 $column_header{ct} = qq|<th class=listheading width=60%>|.$locale->text(ucfirst $form->{ct}).qq|</th>|;
1093 $column_header{language} = qq|<th class=listheading>|.$locale->text('Language').qq|</th>|;
1094 $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|;
1095 $column_header{ordnumber} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
1096 $column_header{transdate} = qq|<th class=listheading nowrap>|.$locale->text('Date').qq|</th>|;
1097 $column_header{duedate} = qq|<th class=listheading nowrap>|.$locale->text('Due Date').qq|</th>|;
1098 $column_header{c0} = qq|<th class=listheading width=10%>|.$locale->text('Current').qq|</th>|;
1099 $column_header{c30} = qq|<th class=listheading width=10%>30</th>|;
1100 $column_header{c60} = qq|<th class=listheading width=10%>60</th>|;
1101 $column_header{c90} = qq|<th class=listheading width=10%>90</th>|;
1103 @column_index = qw(statement ct);
1105 if (@{ $form->{all_language} } && $form->{arap} eq 'ar') {
1106 push @column_index, "language";
1107 $form->{selectlanguage} = qq|<option>\n|;
1109 map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_language} };
1112 if ($form->{summary}) {
1113 push @column_index, qw(c0 c30 c60 c90);
1115 push @column_index, qw(invnumber ordnumber transdate duedate c0 c30 c60 c90);
1118 if ($form->{department}) {
1119 $option .= "\n<br>" if $option;
1120 ($department) = split /--/, $form->{department};
1121 $option .= $locale->text('Department')." : $department";
1122 $department = $form->escape($form->{department},1);
1123 $form->{callback} .= "&department=$department";
1126 if ($form->{arap} eq 'ar') {
1127 if ($form->{customer}) {
1128 $option .= "\n<br>" if $option;
1129 $option .= $form->{customer};
1132 if ($form->{arap} eq 'ap') {
1133 shift @column_index;
1134 if ($form->{vendor}) {
1135 $option .= "\n<br>" if $option;
1136 $option .= $form->{vendor};
1140 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1141 $option .= "\n<br>" if $option;
1142 $option .= $locale->text('for Period')." ".$locale->text('To')." $todate";
1147 <form method=post action=$form->{script}>
1151 <th class=listtop>$form->{title}</th>
1153 <tr height="5"></tr>
1160 <tr class=listheading>
1163 map { print "$column_header{$_}\n" } @column_index;
1173 $l = $#{ $form->{AG} };
1175 foreach $ref (@{ $form->{AG} }) {
1179 if ($ctid != $ref->{ctid}) {
1183 $column_data{ct} = qq|<td>$ref->{name}</td>|;
1185 if ($form->{selectlanguage}) {
1186 $form->{"selectlanguage_$i"} = $form->{selectlanguage};
1187 $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
1188 $column_data{language} = qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
1191 $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
1192 <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
1197 $ctid = $ref->{ctid};
1199 $c0subtotal += $ref->{c0};
1200 $c30subtotal += $ref->{c30};
1201 $c60subtotal += $ref->{c60};
1202 $c90subtotal += $ref->{c90};
1204 $c0total += $ref->{c0};
1205 $c30total += $ref->{c30};
1206 $c60total += $ref->{c60};
1207 $c90total += $ref->{c90};
1209 $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, " ");
1210 $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, " ");
1211 $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, " ");
1212 $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, " ");
1214 $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|.$form->escape($form->{callback});
1216 $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
1217 map { $column_data{$_} = qq|<td>$ref->{$_}</td>| } qw(ordnumber transdate duedate);
1218 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(c0 c30 c60 c90);
1220 if (!$form->{summary}) {
1224 <tr class=listrow$j>
1227 map { print "$column_data{$_}\n" } @column_index;
1233 map { $column_data{$_} = qq|<td> </td>| } qw(ct statement language);
1238 $nextid = ($k <= $l) ? $form->{AG}->[$k]->{ctid} : 0;
1239 if ($ctid != $nextid) {
1241 $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " ");
1242 $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " ");
1243 $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " ");
1244 $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " ");
1246 if ($form->{summary}) {
1247 $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
1248 $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
1249 $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
1250 $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
1254 <tr class=listrow$j>
1257 map { print "$column_data{$_}\n" } @column_index;
1265 map { $column_data{$_} = qq|<th> </th>| } @column_index;
1267 $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
1268 $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
1269 $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
1270 $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
1274 <tr class=listsubtotal>
1276 map { print "$column_data{$_}\n" } @column_index;
1294 <tr class=listtotal>
1297 map { $column_data{$_} = qq|<th> </th>| } @column_index;
1299 $c0total = $form->format_amount(\%myconfig, $c0total, 2, " ");
1300 $c30total = $form->format_amount(\%myconfig, $c30total, 2, " ");
1301 $c60total = $form->format_amount(\%myconfig, $c60total, 2, " ");
1302 $c90total = $form->format_amount(\%myconfig, $c90total, 2, " ");
1304 $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
1305 $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
1306 $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
1307 $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
1309 map { print "$column_data{$_}\n" } @column_index;
1312 <input type=hidden name=rowcount value=$i>
1321 &print_options if ($form->{arap} eq 'ar');
1327 <td><hr size=3 noshade></td>
1332 if ($form->{arap} eq 'ar') {
1334 <input type=hidden name=todate value=$form->{todate}>
1336 <input type=hidden name=title value="$form->{title}">
1337 <input type=hidden name=summary value=$form->{summary}>
1339 <input type=hidden name=callback value=$form->{callback}>
1341 <input type=hidden name=arap value=$form->{arap}>
1342 <input type=hidden name=ct value=$form->{ct}>
1343 <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
1345 <input type=hidden name=department value="$form->{department}">
1347 <input type=hidden name=path value=$form->{path}>
1348 <input type=hidden name=login value=$form->{login}>
1349 <input type=hidden name=sessionid value=$form->{sessionid}>
1352 <input class=submit type=submit name=action value="|.$locale->text('Select all').qq|">
1353 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
1354 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
1358 if ($form->{menubar}) {
1359 require "$form->{path}/menu.pl";
1375 RP->aging(\%myconfig, \%$form);
1377 map { $_->{checked} = "checked" } @{ $form->{AG} };
1386 $form->{sendmode} = "attachment";
1387 $form->{copies} = 1 unless $form->{copies};
1389 $form->{PD}{$form->{type}} = "selected";
1390 $form->{DF}{$form->{format}} = "selected";
1391 $form->{SM}{$form->{sendmode}} = "selected";
1394 <option value=html $form->{PD}{format}>html|;
1397 <option value=statement $form->{PD}{statement}>|.$locale->text('Statement');
1400 if ($form->{media} eq 'email') {
1402 <td><select name=sendmode>
1403 <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
1404 <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
1407 <td><select name=media>
1408 <option value=screen>|.$locale->text('Screen');
1409 if (%printer && $latex) {
1411 <option value="$_">$_| } keys %printer;
1415 $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
1416 $media .= qq|</select></td>|;
1420 <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
1421 <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
1427 <td><select name=type>$type</select></td>
1428 <td><select name=format>$format</select></td>
1432 if (%printer && $latex && $form->{media} ne 'email') {
1434 <td>|.$locale->text('Copies').qq|
1435 <input name=copies size=2 value=$form->{copies}></td>
1449 # get name and email addresses
1450 for $i (1 .. $form->{rowcount}) {
1451 if ($form->{"statement_$i"}) {
1452 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1453 RP->get_customer(\%myconfig, \%$form);
1459 $form->error($locale->text('Nothing selected!')) unless $selected;
1461 if ($myconfig{role} =~ /(admin|manager)/) {
1463 <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
1464 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1468 $title = $locale->text('E-mail Statement to')." $form->{$form->{ct}}";
1470 $form->{media} = "email";
1477 <form method=post action=$form->{script}>
1483 <tr height="5"></tr>
1488 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1489 <td><input name=email size=30 value="$form->{email}"></td>
1490 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
1491 <td><input name=cc size=30 value="$form->{cc}"></td>
1494 <th align=right nowrap>|.$locale->text('Subject').qq|</th>
1495 <td><input name=subject size=30 value="$form->{subject}"></td>
1505 <th align=left nowrap>|.$locale->text('Message').qq|</th>
1508 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1519 map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format header);
1527 <td><hr size=3 noshade></td>
1531 <input type=hidden name=nextsub value=send_email>
1534 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
1546 $form->{OUT} = "$sendmail";
1548 $form->{subject} = $locale->text('Statement').qq| - $form->{todate}| unless $form->{subject};
1549 $form->isblank("email", $locale->text('E-mail address missing!'));
1551 RP->aging(\%myconfig, \%$form);
1553 $form->{"statement_1"} = 1;
1557 $form->redirect($locale->text('Statement sent to')." $form->{$form->{ct}}");
1565 if ($form->{media} !~ /(screen|email)/) {
1566 $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
1569 for $i (1 .. $form->{rowcount}) {
1570 if ($form->{"statement_$i"}) {
1571 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1572 $language_code = $form->{"language_code_$i"};
1578 $form->error($locale->text('Nothing selected!')) unless $selected;
1581 if ($form->{media} !~ /(screen|email)/) {
1582 $form->{OUT} = "| $printer{$form->{media}}";
1583 $form->{"$form->{ct}_id"} = "";
1584 $SIG{INT} = 'IGNORE';
1586 $form->{"statement_1"} = 1;
1587 $form->{"language_code_1"} = $language_code;
1590 RP->aging(\%myconfig, \%$form);
1594 $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} !~ /(screen|email)/);
1601 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1603 $form->{templates} = "$myconfig{templates}";
1605 # setup variables for the form
1606 @a = qw(company address businessnumber tel fax);
1607 map { $form->{$_} = $myconfig{$_} } @a;
1608 $form->format_string(@a);
1610 $form->{IN} = "$form->{type}.html";
1612 if ($form->{format} eq 'postscript') {
1613 $form->{IN} =~ s/html$/tex/;
1615 if ($form->{format} eq 'pdf') {
1616 $form->{IN} =~ s/html$/tex/;
1619 @a = qw(name address1 address2 city state zipcode country contact);
1620 push @a, "$form->{ct}phone", "$form->{ct}fax";
1621 push @a, 'email' if ! $form->{media} eq 'email';
1624 while (@{ $form->{AG} }) {
1626 $ref = shift @{ $form->{AG} };
1628 if ($ctid != $ref->{ctid}) {
1630 $ctid = $ref->{ctid};
1633 if ($form->{"statement_$i"}) {
1635 map { $form->{$_} = $ref->{$_} } @a;
1636 $form->format_string(@a);
1638 $form->{$form->{ct}} = $form->{name};
1639 $form->{"$form->{ct}_id"} = $ref->{ctid};
1640 $form->{language_code} = $form->{"language_code_$i"};
1642 map { $form->{$_} = () } qw(invnumber ordnumber notes invdate duedate);
1644 foreach $item (qw(c0 c30 c60 c90)) {
1645 $form->{$item} = ();
1646 $form->{"${item}total"} = 0;
1649 &statement_details($ref);
1653 if (scalar (@{ $form->{AG} }) > 0) {
1654 # one or more left to go
1655 if ($ctid == $form->{AG}->[0]->{ctid}) {
1656 $ref = shift @{ $form->{AG} };
1657 &statement_details($ref);
1659 $ref = scalar (@{ $form->{AG} });
1664 # set initial ref to 0
1670 map { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) } (c0, c30, c60, c90, "");
1672 $form->parse_template(\%myconfig, $userspath);
1681 sub statement_details {
1684 $ref->{invdate} = $ref->{transdate};
1685 my @a = qw(invnumber ordnumber notes invdate duedate);
1686 map { $form->{"${_}_1"} = $ref->{$_} } @a;
1687 $form->format_string(qw(invnumber_1 ordnumber_1 notes_1));
1688 map { push @{ $form->{$_} }, $form->{"${_}_1"} } @a;
1690 foreach $item (qw(c0 c30 c60 c90)) {
1691 eval { $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2) };
1692 $form->{"${item}total"} += $ref->{$item};
1693 $form->{total} += $ref->{$item};
1694 push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2);
1700 sub generate_tax_report {
1702 RP->tax_report(\%myconfig, \%$form);
1704 $descvar = "$form->{accno}_description";
1705 $description = $form->escape($form->{$descvar});
1706 $ratevar = "$form->{accno}_rate";
1707 $taxrate = $form->{"$form->{accno}_rate"};
1709 if ($form->{accno} =~ /^gifi_/) {
1710 $descvar = "gifi_$form->{accno}_description";
1711 $description = $form->escape($form->{$descvar});
1712 $ratevar = "gifi_$form->{accno}_rate";
1713 $taxrate = $form->{"gifi_$form->{accno}_rate"};
1716 $department = $form->escape($form->{department});
1719 $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
1721 # construct callback
1722 $description = $form->escape($form->{$descvar},1);
1723 $department = $form->escape($form->{department},1);
1725 $form->sort_order();
1727 $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
1729 $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/);
1731 $title = $form->escape($form->{title});
1732 $href .= "&title=$title";
1733 $title = $form->escape($form->{title},1);
1734 $callback .= "&title=$title";
1736 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
1738 @columns = $form->sort_columns(qw(id transdate invnumber name description netamount tax total));
1740 $form->{"l_description"} = "" if $form->{summary};
1742 foreach $item (@columns) {
1743 if ($form->{"l_$item"} eq "Y") {
1744 push @column_index, $item;
1746 # add column to href and callback
1747 $callback .= "&l_$item=Y";
1748 $href .= "&l_$item=Y";
1753 if ($form->{l_subtotal} eq 'Y') {
1754 $callback .= "&l_subtotal=Y";
1755 $href .= "&l_subtotal=Y";
1759 if ($form->{department}) {
1760 ($department) = split /--/, $form->{department};
1761 $option = $locale->text('Department')." : $department";
1764 # if there are any dates
1765 if ($form->{fromdate} || $form->{todate}) {
1766 if ($form->{fromdate}) {
1767 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1769 if ($form->{todate}) {
1770 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1773 $form->{period} = "$fromdate - $todate";
1775 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1779 if ($form->{db} eq 'ar') {
1780 $name = $locale->text('Customer');
1784 if ($form->{db} eq 'ap') {
1785 $name = $locale->text('Vendor');
1790 $option .= "<br>" if $option;
1791 $option .= "$form->{period}";
1794 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;
1795 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;
1796 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;
1797 $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
1798 $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
1799 $column_header{total} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
1801 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
1803 $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
1813 <th class=listtop colspan=$colspan>$form->{title}</th>
1815 <tr height="5"></tr>
1822 <tr class=listheading>
1825 map { print "$column_header{$_}\n" } @column_index;
1831 # add sort and escape callback
1832 $callback = $form->escape($callback . "&sort=$form->{sort}");
1834 if (@{ $form->{TR} }) {
1835 $sameitem = $form->{TR}->[0]->{$form->{sort}};
1838 foreach $ref (@{ $form->{TR} }) {
1840 $module = ($ref->{invoice}) ? $invoice : $arap;
1841 $module = 'ps.pl' if $ref->{till};
1843 if ($form->{l_subtotal} eq 'Y') {
1844 if ($sameitem ne $ref->{$form->{sort}}) {
1846 $sameitem = $ref->{$form->{sort}};
1850 $totalnetamount += $ref->{netamount};
1851 $totaltax += $ref->{tax};
1852 $ref->{total} = $ref->{netamount} + $ref->{tax};
1854 $subtotalnetamount += $ref->{netamount};
1855 $subtotaltax += $ref->{tax};
1857 map { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " "); } qw(netamount tax total);
1859 $column_data{id} = qq|<td>$ref->{id}</td>|;
1860 $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}</a></td>|;
1862 map { $column_data{$_} = qq|<td>$ref->{$_}</td>| } qw(id transdate name partnumber description);
1864 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(netamount tax total);
1868 <tr class=listrow$i>
1871 map { print "$column_data{$_}\n" } @column_index;
1879 if ($form->{l_subtotal} eq 'Y') {
1884 map { $column_data{$_} = qq|<th> </th>| } @column_index;
1888 <tr class=listtotal>
1891 $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
1892 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
1893 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
1895 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
1896 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
1897 $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
1899 map { print "$column_data{$_}\n" } @column_index;
1908 <td><hr size=3 noshade></td>
1921 map { $column_data{$_} = "<td> </td>" } @column_index;
1923 $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, " ");
1924 $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
1925 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
1927 $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
1928 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
1929 $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
1931 $subtotalnetamount = 0;
1935 <tr class=listsubtotal>
1937 map { print "\n$column_data{$_}" } @column_index;
1950 if ($form->{account}) {
1951 ($form->{paymentaccounts}) = split /--/, $form->{account};
1953 if ($form->{department}) {
1954 ($department, $form->{department_id}) = split /--/, $form->{department};
1955 $option = $locale->text('Department')." : $department";
1958 RP->payments(\%myconfig, \%$form);
1960 @columns = $form->sort_columns(qw(transdate name paid source memo));
1962 if ($form->{till}) {
1963 @columns = $form->sort_columns(qw(transdate name paid curr source till));
1964 if ($myconfig{role} ne 'user') {
1965 @columns = $form->sort_columns(qw(transdate name paid curr source till employee));
1970 $account = $form->escape($form->{account});
1971 $title = $form->escape($form->{title});
1972 $department = $form->escape($form->{department});
1973 $form->{paymentaccounts} =~ s/ /%20/g;
1974 $source = $form->escape($form->{source});
1975 $memo = $form->escape($form->{memo});
1977 $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_cubtotal}&prepayment=$form->{prepayment}&title=$title&account=$account&department=$department&paymentaccounts=$form->{paymentaccounts}&source=$source&memo=$memo";
1979 # construct callback
1980 $account = $form->escape($form->{account},1);
1981 $title = $form->escape($form->{title},1);
1982 $department = $form->escape($form->{department},1);
1983 $source = $form->escape($form->{source},1);
1984 $memo = $form->escape($form->{memo},1);
1986 $form->sort_order();
1988 $form->{callback} = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&title=$title&account=$account&department=$department&paymentaccounts=$form->{paymentaccounts}&source=$source&memo=$memo&sort=$form->{sort}";
1989 $callback = $form->escape($form->{callback});
1992 $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>";
1993 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
1994 $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>";
1995 $column_header{curr} = "<th class=listheading>".$locale->text('Curr')."</a></th>";
1996 $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
1997 $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
1999 $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</a></th>";
2000 $column_header{till} = "<th><a class=listheading href=$href&sort=till>".$locale->text('Till')."</a></th>";
2003 if ($form->{fromdate}) {
2004 $option .= "\n<br>" if ($option);
2005 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{fromdate}, 1);
2007 if ($form->{todate}) {
2008 $option .= "\n<br>" if ($option);
2009 $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{todate}, 1);
2012 @column_index = @columns;
2013 $colspan = $#column_index + 1;
2022 <th class=listtop>$form->{title}</th>
2024 <tr height="5"></tr>
2031 <tr class=listheading>
2034 map { print "\n$column_header{$_}" } @column_index;
2041 foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2043 next unless @{ $form->{$ref->{id}} };
2047 <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
2051 if (@{ $form->{$ref->{id}} }) {
2052 $sameitem = $form->{$ref->{id}}[0]->{$form->{sort}};
2055 foreach $payment (@{ $form->{$ref->{id}} }) {
2057 if ($form->{l_subtotal}) {
2058 if ($payment->{$form->{sort}} ne $sameitem) {
2064 next if ($form->{till} && ! $payment->{till});
2066 $column_data{name} = "<td>$payment->{name} </td>";
2067 $column_data{transdate} = "<td>$payment->{transdate} </td>";
2068 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, " ")."</td>";
2069 $column_data{curr} = "<td>$payment->{curr}</td>";
2070 $column_data{source} = "<td>$payment->{source} </td>";
2071 $column_data{memo} = "<td>$payment->{memo} </td>";
2072 $column_data{employee} = "<td>$payment->{employee} </td>";
2073 $column_data{till} = "<td>$payment->{till} </td>";
2075 $subtotalpaid += $payment->{paid};
2076 $accounttotalpaid += $payment->{paid};
2077 $totalpaid += $payment->{paid};
2081 <tr class=listrow$i>
2084 map { print "\n$column_data{$_}" } @column_index;
2090 $sameitem = $payment->{$form->{sort}};
2094 &payment_subtotal if $form->{l_subtotal};
2096 # print account totals
2097 map { $column_data{$_} = "<td> </td>" } @column_index;
2099 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $accounttotalpaid, 2, " ")."</th>";
2102 <tr class=listtotal>
2105 map { print "\n$column_data{$_}" } @column_index;
2111 $accounttotalpaid = 0;
2117 map { $column_data{$_} = "<td> </td>" } @column_index;
2119 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>";
2122 <tr class=listtotal>
2125 map { print "\n$column_data{$_}" } @column_index;
2134 <td><hr size=3 noshade></td>
2145 sub payment_subtotal {
2147 if ($subtotalpaid != 0) {
2148 map { $column_data{$_} = "<td> </td>" } @column_index;
2150 $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>";
2153 <tr class=listsubtotal>
2156 map { print "\n$column_data{$_}" } @column_index;