1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
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 #======================================================================
36 # this is for our long dates
37 # $locale->text('January')
38 # $locale->text('February')
39 # $locale->text('March')
40 # $locale->text('April')
41 # $locale->text('May ')
42 # $locale->text('June')
43 # $locale->text('July')
44 # $locale->text('August')
45 # $locale->text('September')
46 # $locale->text('October')
47 # $locale->text('November')
48 # $locale->text('December')
50 # this is for our short month
51 # $locale->text('Jan')
52 # $locale->text('Feb')
53 # $locale->text('Mar')
54 # $locale->text('Apr')
55 # $locale->text('May')
56 # $locale->text('Jun')
57 # $locale->text('Jul')
58 # $locale->text('Aug')
59 # $locale->text('Sep')
60 # $locale->text('Oct')
61 # $locale->text('Nov')
62 # $locale->text('Dec')
64 # $locale->text('Balance Sheet')
65 # $locale->text('Income Statement')
66 # $locale->text('Trial Balance')
67 # $locale->text('AR Aging')
68 # $locale->text('AP Aging')
69 # $locale->text('Tax collected')
70 # $locale->text('Tax paid')
71 # $locale->text('Receipts')
72 # $locale->text('Payments')
77 %title = ( 'balance_sheet' => 'Balance Sheet',
78 'income_statement' => 'Income Statement',
79 'trial_balance' => 'Trial Balance',
80 'ar_aging' => 'AR Aging',
81 'ap_aging' => 'AP Aging',
82 'tax_collected' => 'Tax collected',
83 'tax_paid' => 'Tax paid',
84 'receipts' => 'Receipts',
85 'payments' => 'Payments',
88 $form->{title} = $locale->text($title{$form->{report}});
94 <th align=right>|.$locale->text('Accounts').qq|</th>
95 <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq|
97 <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq|
105 <form method=post action=$form->{script}>
107 <input type=hidden name=title value="$form->{title}">
111 <th class=listtop>$form->{title}</th>
119 if ($form->{report} eq "income_statement") {
121 <input type=hidden name=nextsub value=generate_income_statement>
123 <th align=right>|.$locale->text('From').qq|</th>
124 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
125 <th align=right>|.$locale->text('to').qq|</th>
126 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
129 <th colspan=4>|.$locale->text('Compare to').qq|</th>
132 <th align=right>|.$locale->text('From').qq|</th>
133 <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
134 <th align=right>|.$locale->text('to').qq|</th>
135 <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>
138 <th align=right>|.$locale->text('Decimalplaces').qq|</th>
139 <td><input name=decimalplaces size=3 maxsize=1></td>
148 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
149 <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|</td>
150 <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
156 if ($form->{report} eq "balance_sheet") {
158 <input type=hidden name=nextsub value=generate_balance_sheet>
160 <th align=right>|.$locale->text('as at').qq|</th>
161 <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
162 <th align=right nowrap>|.$locale->text('Compare to').qq|</th>
163 <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
166 <th align=right>|.$locale->text('Decimalplaces').qq|</th>
167 <td><input name=decimalplaces size=3 maxsize=1></td>
176 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
177 <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|</td>
178 <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
184 if ($form->{report} eq "trial_balance") {
186 <input type=hidden name=nextsub value=generate_trial_balance>
188 <th align=right>|.$locale->text('From').qq|</th>
189 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
190 <th align=right>|.$locale->text('to').qq|</th>
191 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
200 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
201 <td><input name=l_heading class=checkbox type=checkbox value=Y> |.$locale->text('Heading').qq|
202 <input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
208 if (($form->{report} eq "tax_paid") || ($form->{report} eq "tax_collected")) {
211 $form->{db} = ($form->{report} eq "tax_collected") ? "ar" : "ap";
213 RP->get_taxaccounts(\%myconfig, \%$form);
216 <input type=hidden name=nextsub value=generate_tax_report>
218 <th align=right>|.$locale->text('From').qq|</th>
219 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
220 <th align=right>|.$locale->text('to').qq|</th>
221 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
224 <th align=right>|.$locale->text('Cash based').qq|</th>
225 <td><input name=cashbased class=checkbox type=checkbox value=Y></td>
228 <th align=right>|.$locale->text('Report for').qq|</th>
232 $checked = "checked";
233 foreach $item (@{ $form->{taxaccounts} }) {
234 ($accno, $description) = split /--/, $item;
236 print qq|<input name=accno class=radio type=radio value=$accno $checked> $description
238 <input name="${accno}_description" type=hidden value="$description">|;
244 <input type=hidden name=db value=$form->{db}>
245 <input type=hidden name=sort value=transdate>
252 if (@{ $form->{gifi_taxaccounts} }) {
255 <th align=right>|.$locale->text('GIFI').qq|</th>
259 foreach $item (@{ $form->{gifi_taxaccounts} }) {
260 ($accno, $description) = split /--/, $item;
262 print qq|<input name=accno class=radio type=radio value="gifi_$accno" $checked> $description
264 <input name="gifi_${accno}_description" type=hidden value="$description">|;
283 <th align=right>|.$locale->text('Include in Report').qq|</th>
287 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
288 <td>|.$locale->text('ID').qq|</td>
289 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
290 <td>|.$locale->text('Invoice').qq|</td>
291 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
292 <td>|.$locale->text('Date').qq|</td>
295 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
298 if ($form->{db} eq 'ar') {
299 print $locale->text('Customer');
301 if ($form->{db} eq 'ap') {
302 print $locale->text('Vendor');
306 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
307 <td>|.$locale->text('Amount').qq|</td>
308 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
309 <td>|.$locale->text('Tax').qq|</td>
310 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
311 <td>|.$locale->text('Total').qq|</td>
314 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
315 <td>|.$locale->text('Subtotal').qq|</td>
325 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
328 if ($form->{report} eq 'ar_aging') {
329 $label = $locale->text('Customer');
330 $form->{vc} = 'customer';
332 $label = $locale->text('Vendor');
333 $form->{vc} = 'vendor';
336 $nextsub = "generate_$form->{report}";
339 $form->all_vc(\%myconfig, $form->{vc});
341 map { $vc .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
343 $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
347 <th align=right>|.$locale->text($label).qq|</th>
351 <th align=right>|.$locale->text('to').qq|</th>
352 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
354 <input type=hidden name=type value=statement>
355 <input type=hidden name=format value=html>
356 <input type=hidden name=media value=screen>
358 <input type=hidden name=nextsub value=$nextsub>
359 <input type=hidden name=action value=$nextsub>
363 # above action can be removed if there is more than one input field
366 if (($form->{report} eq "receipts") || ($form->{report} eq "payments")) {
369 $form->{db} = ($form->{report} eq "receipts") ? "ar" : "ap";
371 RP->paymentaccounts(\%myconfig, \%$form);
373 $selection = "<option>\n";
374 foreach $ref (@{ $form->{PR} }) {
375 $paymentaccounts .= "$ref->{accno} ";
376 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
379 chop $paymentaccounts;
382 <input type=hidden name=nextsub value=list_payments>
384 <th align=right nowrap>|.$locale->text('Account').qq|</th>
385 <td colspan=3><select name=account>$selection</select>
386 <input type=hidden name=paymentaccounts value="$paymentaccounts">
390 <th align=right>|.$locale->text('From').qq|</th>
391 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
392 <th align=right>|.$locale->text('to').qq|</th>
393 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
395 <input type=hidden name=db value=$form->{db}>
396 <input type=hidden name=sort value=transdate>
410 <td><hr size=3 noshade></td>
415 <input type=hidden name=path value=$form->{path}>
416 <input type=hidden name=login value=$form->{login}>
417 <input type=hidden name=password value=$form->{password}>
419 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
430 sub continue { &{$form->{nextsub}} };
433 sub generate_income_statement {
435 $form->{padding} = " ";
436 $form->{bold} = "<b>";
437 $form->{endbold} = "</b>";
438 $form->{br} = "<br>";
440 RP->income_statement(\%myconfig, \%$form);
443 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
444 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
446 # if there are any dates construct a where
447 if ($form->{fromdate} || $form->{todate}) {
449 unless ($form->{todate}) {
450 $form->{todate} = $form->current_date(\%myconfig);
453 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
454 $shorttodate = $locale->date(\%myconfig, $form->{todate});
456 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
457 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate});
459 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
460 $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('to').qq| $longtodate|;
463 if ($form->{comparefromdate} || $form->{comparetodate}) {
464 $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
465 $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate});
467 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
468 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate});
470 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
471 $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('to').qq| $longcomparetodate|;
475 # setup variables for the form
476 @a = qw(company address businessnumber);
477 map { $form->{$_} = $myconfig{$_} } @a;
478 $form->{address} =~ s/\\n/<br>/g;
480 $form->{templates} = $myconfig{templates};
482 $form->{IN} = "income_statement.html";
484 $form->parse_template;
489 sub generate_balance_sheet {
491 $form->{padding} = " ";
492 $form->{bold} = "<b>";
493 $form->{endbold} = "</b>";
494 $form->{br} = "<br>";
496 RP->balance_sheet(\%myconfig, \%$form);
498 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
499 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
501 # define Retained Earnings account
502 $padding = ($form->{l_heading}) ? $form->{padding} : "";
503 push(@{$form->{equity_account}}, $padding.$locale->text('Retained Earnings'));
505 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate});
506 $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate});
508 $form->{IN} = "balance_sheet.html";
510 # setup company variables for the form
511 map { $form->{$_} = $myconfig{$_} } (qw(company address businessnumber nativecurr));
512 $form->{address} =~ s/\\n/<br>/g;
514 $form->{templates} = $myconfig{templates};
516 $form->parse_template;
524 # included links to display transactions for period entered
525 # added headers and subtotals
527 sub generate_trial_balance {
529 # get for each account initial balance, debits and credits
530 RP->trial_balance_details(\%myconfig, \%$form);
532 $form->{nextsub} = "generate_trial_balance";
533 $form->{title} = $locale->text('Trial Balance');
541 $title = $form->escape($form->{title});
543 if ($form->{projectnumber}) {
544 $options .= $locale->text('Project Number')." : $form->{projectnumber}<br>";
545 $projectnumber = $form->escape($form->{projectnumber});
548 # if there are any dates
549 if ($form->{fromdate} || $form->{todate}) {
550 if ($form->{fromdate}) {
551 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
553 if ($form->{todate}) {
554 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
557 $form->{period} = "$fromdate - $todate";
559 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
562 $options .= $form->{period};
564 @column_index = qw(accno description begbalance debit credit endbalance);
566 $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|;
567 $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
568 $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
569 $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
570 $column_header{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
571 $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
574 if ($form->{accounttype} eq 'gifi') {
575 $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|;
586 <th class=listtop>$form->{title}</th>
597 map { print "$column_header{$_}\n" } @column_index;
605 # sort the whole thing by account numbers and display
606 foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
608 $description = $form->escape($ref->{description});
610 $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
612 if ($form->{accounttype} eq 'gifi') {
613 $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
614 $na = $locale->text('N/A');
615 map { $ref->{$_} = $na } qw(accno description) unless $ref->{accno};
617 $href .= "&accno=$ref->{accno}&description=$description";
620 $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
622 $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
623 $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
624 $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, " ");
625 $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, " ");
627 next if ($ref->{debit} == 0 && $ref->{credit} == 0);
629 if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
630 map { $column_data{$_} = "<th> </th>" } qw(accno begbalance endbalance);
632 $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " ");
633 $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");
634 $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
635 $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
636 $column_data{description} = "<th>$subtotaldescription</th>";
637 $column_data{begbalance} = "<th align=right>$subtotalbegbalance</th>";
638 $column_data{endbalance} = "<th align=right>$subtotalendbalance</th>";
639 $column_data{debit} = "<th align=right>$subtotaldebit</th>";
640 $column_data{credit} = "<th align=right>$subtotalcredit</th>";
643 <tr class=listsubtotal>
645 map { print "$column_data{$_}\n" } @column_index;
652 if ($ref->{charttype} eq "H") {
654 $subtotaldescription = $ref->{description};
655 $subtotaldebit = $ref->{debit};
656 $subtotalcredit = $ref->{credit};
657 $subtotalbegbalance = 0;
658 $subtotalendbalance = 0;
660 next unless $form->{l_heading};
662 map { $column_data{$_} = "<th> </th>" } qw(accno debit credit begbalance endbalance);
663 $column_data{description} = "<th class=listheading>$ref->{description}</th>";
666 if ($ref->{charttype} eq "A") {
667 $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
668 $column_data{description} = "<td>$ref->{description}</td>";
669 $column_data{debit} = "<td align=right>$debit</td>";
670 $column_data{credit} = "<td align=right>$credit</td>";
671 $column_data{begbalance} = "<td align=right>$begbalance</td>";
672 $column_data{endbalance} = "<td align=right>$endbalance</td>";
674 $totaldebit += $ref->{debit};
675 $totalcredit += $ref->{credit};
677 $subtotalbegbalance += $ref->{balance} * $ml;
678 $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml;
682 if ($ref->{charttype} eq "H") {
684 <tr class=listheading>
687 if ($ref->{charttype} eq "A") {
694 map { print "$column_data{$_}\n" } @column_index;
702 # print last subtotal
703 if ($subtotal && $form->{l_subtotal}) {
704 map { $column_data{$_} = "<th> </th>" } qw(accno begbalance endbalance);
705 $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " ");
706 $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");
707 $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
708 $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
709 $column_data{description} = "<th>$subdescription</th>";
710 $column_data{begbalance} = "<th align=right>$subtotalbegbalance</th>";
711 $column_data{endbalance} = "<th align=right>$subtotalendbalance</th>";
712 $column_data{debit} = "<th align=right>$subtotaldebit</th>";
713 $column_data{credit} = "<th align=right>$subtotalcredit</th>";
716 <tr class=listsubtotal>
718 map { print "$column_data{$_}\n" } @column_index;
725 $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, " ");
726 $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, " ");
728 map { $column_data{$_} = "<th> </th>" } qw(accno description begbalance endbalance);
730 $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
731 $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
737 map { print "$column_data{$_}\n" } @column_index;
745 <td><hr size=3 noshade></td>
757 sub generate_ar_aging {
760 ($form->{customer}) = split(/--/, $form->{customer});
762 $form->{ct} = "customer";
763 $form->{arap} = "ar";
765 $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&customer=|.$form->escape($form->{customer});
767 RP->aging(\%myconfig, \%$form);
773 sub generate_ap_aging {
776 ($form->{vendor}) = split(/--/, $form->{vendor});
778 $form->{ct} = "vendor";
779 $form->{arap} = "ap";
781 $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&vendor=|.$form->escape($form->{vendor});
783 RP->aging(\%myconfig, \%$form);
794 $column_header{statement} = qq|<th class=listheading> </th>|;
795 $column_header{ct} = qq|<th class=listheading>|.$locale->text(ucfirst $form->{ct}).qq|</th>|;
796 $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|;
797 $column_header{transdate} = qq|<th class=listheading>|.$locale->text('Date').qq|</th>|;
798 $column_header{duedate} = qq|<th class=listheading>|.$locale->text('Due').qq|</th>|;
799 $column_header{c0} = qq|<th class=listheading>|.$locale->text('Current').qq|</th>|;
800 $column_header{c30} = qq|<th class=listheading>30</th>|;
801 $column_header{c60} = qq|<th class=listheading>60</th>|;
802 $column_header{c90} = qq|<th class=listheading>90</th>|;
804 @column_index = (qw(statement ct invnumber transdate duedate c0 c30 c60 c90));
807 if ($form->{arap} eq 'ar') {
808 if ($form->{customer}) {
809 $option .= "\n<br>" if $option;
810 $option .= $form->{customer};
813 if ($form->{arap} eq 'ap') {
815 if ($form->{vendor}) {
816 $option .= "\n<br>" if $option;
817 $option .= $form->{vendor};
821 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
822 $option .= "\n<br>" if $option;
823 $option .= $locale->text('for Period')." ".$locale->text('to')." $todate";
828 <form method=post action=$form->{script}>
832 <th class=listtop>$form->{title}</th>
841 <tr class=listheading>
844 map { print "$column_header{$_}\n" } @column_index;
855 foreach $ref (@{ $form->{AG} }) {
857 if ($ctid != $ref->{ctid}) {
862 $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " ");
863 $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " ");
864 $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " ");
865 $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " ");
868 $column_data{ct} = qq|<th> </th>|;
869 $column_data{invnumber} = qq|<th> </th>|;
870 $column_data{transdate} = qq|<th> </th>|;
871 $column_data{duedate} = qq|<th> </th>|;
872 $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
873 $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
874 $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
875 $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
880 <tr class=listsubtotal>
883 map { print "$column_data{$_}\n" } @column_index;
885 $column_data{statement} = qq|<td> </td>|;
899 $column_data{ct} = qq|<td>$ref->{name}</td>|;
900 $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
901 <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
905 $c0subtotal += $ref->{c0};
906 $c30subtotal += $ref->{c30};
907 $c60subtotal += $ref->{c60};
908 $c90subtotal += $ref->{c90};
910 $c0total += $ref->{c0};
911 $c30total += $ref->{c30};
912 $c60total += $ref->{c60};
913 $c90total += $ref->{c90};
915 $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, " ");
916 $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, " ");
917 $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, " ");
918 $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, " ");
920 $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|.$form->escape($form->{callback});
922 $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
923 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
924 $column_data{duedate} = qq|<td>$ref->{duedate} </td>|;
925 $column_data{c0} = qq|<td align=right>$ref->{c0}</td>|;
926 $column_data{c30} = qq|<td align=right>$ref->{c30}</td>|;
927 $column_data{c60} = qq|<td align=right>$ref->{c60}</td>|;
928 $column_data{c90} = qq|<td align=right>$ref->{c90}</td>|;
935 map { print "$column_data{$_}\n" } @column_index;
941 $column_data{ct} = qq|<td> </td>|;
942 $column_data{statement} = qq|<td> </td>|;
944 $ctid = $ref->{ctid};
949 $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " ");
950 $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " ");
951 $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " ");
952 $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " ");
955 <tr class=listsubtotal>
958 map { $column_data{$_} = qq|<th> </th>| } @column_index;
960 $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
961 $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
962 $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
963 $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
965 map { print "$column_data{$_}\n" } @column_index;
973 $c0total = $form->format_amount(\%myconfig, $c0total, 2, " ");
974 $c30total = $form->format_amount(\%myconfig, $c30total, 2, " ");
975 $c60total = $form->format_amount(\%myconfig, $c60total, 2, " ");
976 $c90total = $form->format_amount(\%myconfig, $c90total, 2, " ");
978 $column_data{c0} = qq|<th class=listtotal align=right>$c0total</th>|;
979 $column_data{c30} = qq|<th class=listtotal align=right>$c30total</th>|;
980 $column_data{c60} = qq|<th class=listtotal align=right>$c60total</th>|;
981 $column_data{c90} = qq|<th class=listtotal align=right>$c90total</th>|;
984 map { print "$column_data{$_}\n" } @column_index;
988 <input type=hidden name=rowcount value=$i>
997 &print_options if ($form->{arap} eq 'ar');
1003 <td><hr size=3 noshade></td>
1008 if ($form->{arap} eq 'ar') {
1010 <input type=hidden name=todate value=$form->{todate}>
1012 <input type=hidden name=title value="$form->{title}">
1014 <input type=hidden name=arap value=$form->{arap}>
1015 <input type=hidden name=ct value=$form->{ct}>
1016 <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
1018 <input type=hidden name=path value=$form->{path}>
1019 <input type=hidden name=login value=$form->{login}>
1020 <input type=hidden name=password value=$form->{password}>
1023 <input class=submit type=submit name=action value="|.$locale->text('Select all').qq|">
1024 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
1025 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
1041 RP->aging(\%myconfig, \%$form);
1043 map { $_->{checked} = "checked" } @{ $form->{AG} };
1052 $form->{sendmode} = "attachment";
1053 $form->{copies} = 2 unless $form->{copies};
1055 $form->{PD}{$form->{type}} = "checked";
1056 $form->{DF}{$form->{format}} = "checked";
1057 $form->{OP}{$form->{media}} = "checked";
1058 $form->{SM}{$form->{sendmode}} = "checked";
1061 if ($form->{media} eq 'email') {
1063 <td><input class=radio type=radio name=sendmode value=attachment $form->{SM}{attachment}> |.$locale->text('Attachment')
1064 .qq| <input class=radio type=radio name=sendmode value=inline $form->{SM}{inline}> |.$locale->text('In-line').qq|</td>
1068 <td><input class=radio type=radio name=media value=screen $form->{OP}{screen}></td>
1069 <td>|.$locale->text('Screen').qq|</td>
1076 <td><input class=radio type=radio name=type value=statement $form->{PD}{statement}></td><td>|.$locale->text('Statement').qq|</td>
1077 <td><input class=radio type=radio name=format value=html $form->{DF}{html}></td>
1083 <td><input class=radio type=radio name=format value=postscript $form->{DF}{postscript}></td>
1084 <td>|.$locale->text('Postscript').qq|</td>
1085 <td><input class=radio type=radio name=format value=pdf $form->{DF}{pdf}></td>
1086 <td>|.$locale->text('PDF').qq|</td>
1095 if ($myconfig{printer} && $latex) {
1097 <td><input class=radio type=radio name=media value=printer $form->{OP}{printer}></td>
1098 <td>|.$locale->text('Printer')
1099 .qq| (|.$locale->text('Copies')
1100 .qq| <input name=copies size=2 value=$form->{copies}>)</td>
1116 # get name and email addresses
1117 for $i (1 .. $form->{rowcount}) {
1118 if ($form->{"statement_$i"}) {
1119 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1120 RP->get_customer(\%myconfig, \%$form);
1126 $form->error($locale->text('Nothing selected!')) unless $selected;
1128 if ($myconfig{admin}) {
1130 <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
1131 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1135 $title = $locale->text('E-mail Statement to')." $form->{$form->{ct}}";
1137 $form->{media} = "email";
1144 <form method=post action=$form->{script}>
1148 <th class=listtop>$title</th>
1150 <tr height="5"></tr>
1155 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1156 <td><input name=email size=30 value="$form->{email}"></td>
1157 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
1158 <td><input name=cc size=30 value="$form->{cc}"></td>
1161 <th align=right nowrap>|.$locale->text('Subject').qq|</th>
1162 <td><input name=subject size=30 value="$form->{subject}"></td>
1172 <th align=left nowrap>|.$locale->text('Message').qq|</th>
1175 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1186 map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format);
1188 # save all other variables
1189 foreach $key (keys %$form) {
1190 $form->{$key} =~ s/"/"/g;
1191 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1198 <td><hr size=3 noshade></td>
1202 <input type=hidden name=nextsub value=send_email>
1205 <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
1217 $form->{OUT} = "$sendmail";
1219 $form->{subject} = $locale->text('Statement').qq| - $form->{todate}| unless $form->{subject};
1221 RP->aging(\%myconfig, \%$form);
1223 $form->{"statement_1"} = 1;
1227 $form->redirect($locale->text('Statement sent to')." $form->{$form->{ct}}");
1235 if ($form->{media} eq 'printer') {
1236 $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
1239 for $i (1 .. $form->{rowcount}) {
1240 if ($form->{"statement_$i"}) {
1241 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1247 $form->error($locale->text('Nothing selected!')) unless $selected;
1250 if ($form->{media} eq 'printer') {
1251 $form->{OUT} = "| $myconfig{printer}";
1252 $form->{"$form->{ct}_id"} = "";
1254 $form->{"statement_1"} = 1;
1257 RP->aging(\%myconfig, \%$form);
1261 $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} eq 'printer');
1268 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1270 $form->{templates} = "$myconfig{templates}";
1272 # setup variables for the form
1273 @a = qw(company address businessnumber tel fax);
1274 map { $form->{$_} = $myconfig{$_} } @a;
1275 $form->format_string(@a);
1277 $form->{IN} = "$form->{type}.html";
1279 if ($form->{format} eq 'postscript') {
1280 $form->{postscript} = 1;
1281 $form->{IN} =~ s/html$/tex/;
1283 if ($form->{format} eq 'pdf') {
1285 $form->{IN} =~ s/html$/tex/;
1289 while (@{ $form->{AG} }) {
1291 $ref = shift @{ $form->{AG} };
1293 if ($ctid != $ref->{ctid}) {
1295 $ctid = $ref->{ctid};
1298 if ($form->{"statement_$i"}) {
1300 @a = (name, addr1, addr2, addr3, addr4, contact, "$form->{ct}phone", "$form->{ct}fax");
1301 map { $form->{$_} = $ref->{$_} } @a;
1302 $form->format_string(@a);
1304 $form->{$form->{ct}} = $form->{name};
1305 $form->{"$form->{ct}_id"} = $ref->{ctid};
1307 map { $form->{$_} = () } qw(invnumber invdate duedate);
1309 foreach $item (qw(c0 c30 c60 c90)) {
1310 $form->{$item} = ();
1311 $form->{"${item}total"} = 0;
1314 &statement_details($ref);
1318 if (scalar (@{ $form->{AG} }) > 0) {
1319 # one or more left to go
1320 if ($ctid == $form->{AG}->[0]->{ctid}) {
1321 $ref = shift @{ $form->{AG} };
1322 &statement_details($ref);
1324 $ref = scalar (@{ $form->{AG} });
1329 # set initial ref to 0
1335 map { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) } (c0, c30, c60, c90, "");
1337 $form->parse_template(\%myconfig, $userspath);
1346 sub statement_details {
1349 push @{ $form->{invnumber} }, $ref->{invnumber};
1350 push @{ $form->{invdate} }, $ref->{transdate};
1351 push @{ $form->{duedate} }, $ref->{duedate};
1353 foreach $item (qw(c0 c30 c60 c90)) {
1354 $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
1355 $form->{"${item}total"} += $ref->{$item};
1356 $form->{total} += $ref->{$item};
1357 push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2);
1363 sub generate_tax_report {
1365 RP->tax_report(\%myconfig, \%$form);
1367 $descvar = "$form->{accno}_description";
1368 $description = $form->escape($form->{$descvar});
1371 $href = "$form->{script}?path=$form->{path}&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&accno=$form->{accno}&$descvar=$description";
1373 # construct callback
1377 @columns = $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1379 foreach $item (@columns) {
1380 if ($form->{"l_$item"} eq "Y") {
1381 push @column_index, $item;
1383 # add column to href and callback
1384 $callback .= "&l_$item=Y";
1385 $href .= "&l_$item=Y";
1389 if ($form->{l_subtotal} eq 'Y') {
1390 $callback .= "&l_subtotal=Y";
1391 $href .= "&l_subtotal=Y";
1395 # if there are any dates
1396 if ($form->{fromdate} || $form->{todate}) {
1397 if ($form->{fromdate}) {
1398 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1400 if ($form->{todate}) {
1401 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1404 $form->{period} = "$fromdate - $todate";
1406 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1409 $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/);
1410 $form->{title} = qq|$form->{"$form->{accno}_description"} |;
1411 if ($form->{db} eq 'ar') {
1412 $form->{title} .= $locale->text('collected on sales');
1413 $name = $locale->text('Customer');
1417 if ($form->{db} eq 'ap') {
1418 $form->{title} .= $locale->text('paid on purchases');
1419 $name = $locale->text('Vendor');
1425 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;
1426 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;
1427 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;
1428 $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
1429 $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
1430 $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
1432 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
1442 <th class=listtop colspan=$colspan>$form->{title}</th>
1444 <tr height="5"></tr>
1446 <td>$form->{period}</td>
1451 <tr class=listheading>
1454 map { print "$column_header{$_}\n" } @column_index;
1460 # add sort and escape callback
1461 $callback = $form->escape($callback . "&sort=$form->{sort}");
1463 if (@{ $form->{TR} }) {
1464 $sameitem = $form->{TR}->[0]->{$form->{sort}};
1467 foreach $ref (@{ $form->{TR} }) {
1469 $module = ($ref->{invoice}) ? $invoice : $arap;
1471 if ($form->{l_subtotal} eq 'Y') {
1472 if ($sameitem ne $ref->{$form->{sort}}) {
1474 $sameitem = $ref->{$form->{sort}};
1478 $totalnetamount += $ref->{netamount};
1479 $totaltax += $ref->{tax};
1480 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1482 $subtotalnetamount += $ref->{netamount};
1483 $subtotaltax += $ref->{tax};
1485 map { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " "); } qw(netamount tax amount);
1487 $column_data{id} = qq|<td>$ref->{id}</td>|;
1488 $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>|;
1489 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
1490 $column_data{name} = qq|<td>$ref->{name} </td>|;
1492 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| } qw(netamount tax amount);
1496 <tr class=listrow$i>
1499 map { print "$column_data{$_}\n" } @column_index;
1507 if ($form->{l_subtotal} eq 'Y') {
1512 map { $column_data{$_} = qq|<th> </th>| } @column_index;
1516 <tr class=listtotal>
1519 $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
1520 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
1521 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
1523 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
1524 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
1525 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
1527 map { print "$column_data{$_}\n" } @column_index;
1536 <td><hr size=3 noshade></td>
1549 map { $column_data{$_} = "<td> </td>" } @column_index;
1551 $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
1552 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
1553 $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, " ");
1555 $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
1556 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
1557 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
1559 $subtotalnetamount = 0;
1563 <tr class=listsubtotal>
1565 map { print "\n$column_data{$_}" } @column_index;
1577 if ($form->{account}) {
1578 ($form->{paymentaccounts}) = split /--/, $form->{account};
1581 RP->payments(\%myconfig, \%$form);
1583 @columns = $form->sort_columns(qw(transdate invnumber name paid source));
1586 $href = "$form->{script}?path=$form->{path}&action=list_payments&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&title=".$form->escape($form->{title})."&account=".$form->escape($form->{account});
1588 $form->{paymentaccounts} =~ s/ /%20/g;
1589 $href .= "&paymentaccounts=$form->{paymentaccounts}";
1592 # construct callback
1593 $form->{callback} = "$href&sort=$form->{sort}";
1594 $callback = $form->escape($form->{callback});
1597 $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>";
1598 $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
1599 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
1600 $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>";
1601 $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
1604 if ($form->{fromdate}) {
1605 $option .= "\n<br>" if ($option);
1606 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{fromdate}, 1);
1608 if ($form->{todate}) {
1609 $option .= "\n<br>" if ($option);
1610 $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{todate}, 1);
1613 @column_index = @columns;
1614 $colspan = $#column_index + 1;
1623 <th class=listtop>$form->{title}</th>
1625 <tr height="5"></tr>
1632 <tr class=listheading>
1635 map { print "\n$column_header{$_}" } @column_index;
1642 foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1646 <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
1650 foreach $payment (@{ $form->{$ref->{id}} }) {
1652 $module = $payment->{module};
1653 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1654 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1656 $href = qq|${module}.pl?path=$form->{path}&action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|;
1659 $column_data{name} = "<td>$payment->{name} </td>";
1660 $column_data{invnumber} = qq|<td><a href=$href>$payment->{invnumber}</a></td>|;
1661 $column_data{transdate} = "<td>$payment->{transdate} </td>";
1662 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, " ")."</td>";
1663 $column_data{source} = "<td>$payment->{source} </td>";
1665 $subtotalpaid += $payment->{paid};
1666 $totalpaid += $payment->{paid};
1670 <tr class=listrow$i>
1673 map { print "\n$column_data{$_}" } @column_index;
1682 map { $column_data{$_} = "<td> </td>" } @column_index;
1684 $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>";
1687 <tr class=listsubtotal>
1690 map { print "\n$column_data{$_}" } @column_index;
1702 map { $column_data{$_} = "<td> </td>" } @column_index;
1704 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>";
1707 <tr class=listtotal>
1710 map { print "\n$column_data{$_}" } @column_index;
1719 <td><hr size=3 noshade></td>