1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
16 # Benjamin Lee <benjaminlee@consultant.com>
17 # Philip Reetz <p.reetz@linet-services.de>
20 # This program is free software; you can redistribute it and/or modify
21 # it under the terms of the GNU General Public License as published by
22 # the Free Software Foundation; either version 2 of the License, or
23 # (at your option) any later version.
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #======================================================================
34 # module for preparing Income Statement and Balance Sheet
36 #======================================================================
38 use POSIX qw(strftime);
43 use SL::ReportGenerator;
45 require "bin/mozilla/arap.pl";
46 require "bin/mozilla/common.pl";
47 require "bin/mozilla/reportgenerator.pl";
53 # this is for our long dates
54 # $locale->text('January')
55 # $locale->text('February')
56 # $locale->text('March')
57 # $locale->text('April')
58 # $locale->text('May ')
59 # $locale->text('June')
60 # $locale->text('July')
61 # $locale->text('August')
62 # $locale->text('September')
63 # $locale->text('October')
64 # $locale->text('November')
65 # $locale->text('December')
67 # this is for our short month
68 # $locale->text('Jan')
69 # $locale->text('Feb')
70 # $locale->text('Mar')
71 # $locale->text('Apr')
72 # $locale->text('May')
73 # $locale->text('Jun')
74 # $locale->text('Jul')
75 # $locale->text('Aug')
76 # $locale->text('Sep')
77 # $locale->text('Oct')
78 # $locale->text('Nov')
79 # $locale->text('Dec')
81 # $locale->text('Balance Sheet')
82 # $locale->text('Income Statement')
83 # $locale->text('Trial Balance')
84 # $locale->text('AR Aging')
85 # $locale->text('AP Aging')
86 # $locale->text('Tax collected')
87 # $locale->text('Tax paid')
88 # $locale->text('Receipts')
89 # $locale->text('Payments')
90 # $locale->text('Project Transactions')
91 # $locale->text('Non-taxable Sales')
92 # $locale->text('Non-taxable Purchases')
95 'projects' => 'report',
96 'ar_aging' => 'general_ledger',
97 'ap_aging' => 'general_ledger',
100 'trial_balance' => 'report',
101 'income_statement' => 'report',
103 'balance_sheet' => 'report',
106 sub check_rp_access {
107 my $right = $rp_access_map->{$form->{report}};
108 $right ||= 'DOES_NOT_EXIST';
110 $auth->assert($right);
114 $lxdebug->enter_sub();
118 %title = ('balance_sheet' => 'Balance Sheet',
119 'income_statement' => 'Income Statement',
120 'trial_balance' => 'Trial Balance',
121 'ar_aging' => 'AR Aging',
122 'ap_aging' => 'Offene Verbindlichkeiten',
123 'tax_collected' => 'Tax collected',
124 'tax_paid' => 'Tax paid',
125 'nontaxable_sales' => 'Non-taxable Sales',
126 'nontaxable_purchases' => 'Non-taxable Purchases',
127 'receipts' => 'Receipts',
128 'payments' => 'Payments',
129 'projects' => 'Project Transactions',
130 'bwa' => 'Betriebswirtschaftliche Auswertung',);
132 $form->{title} = $locale->text($title{ $form->{report} });
134 $accrual = ($eur) ? "" : "checked";
135 $cash = ($eur) ? "checked" : "";
137 $year = (localtime)[5] + 1900;
140 $form->all_departments(\%myconfig);
141 if (@{ $form->{all_departments} }) {
142 $form->{selectdepartment} = "<option>\n";
145 $form->{selectdepartment} .=
146 "<option>$_->{description}--$_->{id}\n"
147 } (@{ $form->{all_departments} });
152 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
153 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
155 | if $form->{selectdepartment};
157 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
160 my %project_labels = ();
161 my @project_values = ("");
162 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
163 push(@project_values, $item->{"id"});
164 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
168 NTI($cgi->popup_menu('-name' => "project_id",
169 '-values' => \@project_values,
170 '-labels' => \%project_labels));
172 # use JavaScript Calendar or not
173 $form->{jsscript} = 1;
175 if ($form->{report} eq "balance_sheet") {
176 $name_1 = "asofdate";
178 $value_1 = "$form->{asofdate}";
179 $trigger_1 = "trigger1";
180 $name_2 = "compareasofdate";
181 $id_2 = "compareasofdate";
182 $value_2 = "$form->{compareasofdate}";
183 $trigger_2 = "trigger2";
184 } elsif ($form->{report} =~ /(receipts|payments)$/) {
185 $name_1 = "fromdate";
187 $value_1 = "$form->{fromdate}";
188 $trigger_1 = "trigger1";
192 $trigger_2 = "trigger2";
193 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
201 $trigger_2 = "trigger2";
204 $name_1 = "fromdate";
206 $value_1 = "$form->{fromdate}";
207 $trigger_1 = "trigger1";
211 $trigger_2 = "trigger2";
214 # with JavaScript Calendar
215 if ($form->{jsscript}) {
219 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
221 <input type=button name=$name_2 id="$trigger_2" value=|
222 . $locale->text('button') . qq|>|;
226 Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
229 <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
231 <input type=button name=$name_1 id="$trigger_1" value=|
232 . $locale->text('button') . qq|>|;
234 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
236 <input type=button name=$name_2 id="$trigger_2" value=|
237 . $locale->text('button') . qq|>
242 Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
243 "$name_2", "BL", "$trigger_2");
247 # without JavaScript Calendar
250 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
253 qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
255 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
258 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
260 $onload = qq|focus()|;
261 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
262 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
264 <body onLoad="$onload">
266 <form method=post action=$form->{script}>
268 <input type=hidden name=title value="$form->{title}">
272 <th class=listtop>$form->{title}</th>
281 if ($form->{report} eq "projects") {
284 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
285 <td colspan=5><input name=projectnumber size=25</td>
287 <input type=hidden name=nextsub value=generate_projects>
289 <th align=right>| . $locale->text('From') . qq|</th>
292 <th align=right>| . $locale->text('Bis') . qq|</th>
303 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
304 <td><input name=l_heading class=checkbox type=checkbox value=Y> |
305 . $locale->text('Heading') . qq|
306 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
307 . $locale->text('Subtotal') . qq|</td>
314 if ($form->{report} eq "income_statement") {
317 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
318 <td colspan=3>$projectnumber</td>
320 <input type=hidden name=nextsub value=generate_income_statement>
324 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
325 . $locale->text('Customized Report') . qq|</th>
328 <th colspan=1>| . $locale->text('Year') . qq|</th>
329 <td><input name=year size=11 title="|
330 . $locale->text('YYYY') . qq|" value="$year"></td>
337 <b> | . $locale->text('Yearly') . qq|</b> </td>
338 <th align=left>| . $locale->text('Quarterly') . qq|</th>
339 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
342 <td align=right> <input name=duetyp class=radio type=radio value="13"
344 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
345 . $locale->text('Quarter') . qq|</td>
349 <td><input name=duetyp class=radio type=radio value="1" $checked > |
350 . $locale->text('January') . qq|</td>
354 <td><input name=duetyp class=radio type=radio value="5" $checked > |
355 . $locale->text('May') . qq|</td>
356 <td><input name=duetyp class=radio type=radio value="9" $checked > |
357 . $locale->text('September') . qq|</td>
361 <td align= right> </td>
362 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
363 . $locale->text('Quarter') . qq|</td>
364 <td><input name=duetyp class=radio type=radio value="2" $checked > |
365 . $locale->text('February') . qq|</td>
366 <td><input name=duetyp class=radio type=radio value="6" $checked > |
367 . $locale->text('June') . qq|</td>
368 <td><input name=duetyp class=radio type=radio value="10" $checked > |
369 . $locale->text('October') . qq|</td>
373 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
374 . $locale->text('Quarter') . qq|</td>
375 <td><input name=duetyp class=radio type=radio value="3" $checked > |
376 . $locale->text('March') . qq|</td>
377 <td><input name=duetyp class=radio type=radio value="7" $checked > |
378 . $locale->text('July') . qq|</td>
379 <td><input name=duetyp class=radio type=radio value="11" $checked > |
380 . $locale->text('November') . qq|</td>
385 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
386 . $locale->text('Quarter') . qq| </td>
387 <td><input name=duetyp class=radio type=radio value="4" $checked > |
388 . $locale->text('April') . qq|</td>
389 <td><input name=duetyp class=radio type=radio value="8" $checked > |
390 . $locale->text('August') . qq|</td>
391 <td><input name=duetyp class=radio type=radio value="12" $checked > |
392 . $locale->text('December') . qq|</td>
396 <td colspan=5><hr size=3 noshade></td>
399 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
400 . $locale->text('Free report period') . qq|</th>
401 <td align=left colspan=4>| . $locale->text('From') . qq|
404 | . $locale->text('Bis') . qq|
410 <td colspan=5><hr size=3 noshade></td>
413 <th align=leftt>| . $locale->text('Method') . qq|</th>
414 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
415 . $locale->text('Accrual') . qq|
416 <input name=method class=radio type=radio value=cash $cash>|
417 . $locale->text('EUR') . qq|</td>
424 if ($form->{report} eq "bwa") {
427 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
428 <td colspan=3>$projectnumber</td>
430 <input type=hidden name=nextsub value=generate_bwa>
434 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
435 . $locale->text('Customized Report') . qq|</th>
438 <th colspan=1>| . $locale->text('Year') . qq|</th>
439 <td><input name=year size=11 title="|
440 . $locale->text('YYYY') . qq|" value="$year"></td>
447 <b> | . $locale->text('Yearly') . qq|</b> </td>
448 <th align=left>| . $locale->text('Quarterly') . qq|</th>
449 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
452 <td align=right> <input name=duetyp class=radio type=radio value="13"
454 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
455 . $locale->text('Quarter') . qq|</td>
457 $checked = "checked";
459 <td><input name=duetyp class=radio type=radio value="1" $checked > |
460 . $locale->text('January') . qq|</td>
464 <td><input name=duetyp class=radio type=radio value="5" $checked > |
465 . $locale->text('May') . qq|</td>
466 <td><input name=duetyp class=radio type=radio value="9" $checked > |
467 . $locale->text('September') . qq|</td>
471 <td align= right> </td>
472 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
473 . $locale->text('Quarter') . qq|</td>
474 <td><input name=duetyp class=radio type=radio value="2" $checked > |
475 . $locale->text('February') . qq|</td>
476 <td><input name=duetyp class=radio type=radio value="6" $checked > |
477 . $locale->text('June') . qq|</td>
478 <td><input name=duetyp class=radio type=radio value="10" $checked > |
479 . $locale->text('October') . qq|</td>
483 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
484 . $locale->text('Quarter') . qq|</td>
485 <td><input name=duetyp class=radio type=radio value="3" $checked > |
486 . $locale->text('March') . qq|</td>
487 <td><input name=duetyp class=radio type=radio value="7" $checked > |
488 . $locale->text('July') . qq|</td>
489 <td><input name=duetyp class=radio type=radio value="11" $checked > |
490 . $locale->text('November') . qq|</td>
495 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
496 . $locale->text('Quarter') . qq| </td>
497 <td><input name=duetyp class=radio type=radio value="4" $checked > |
498 . $locale->text('April') . qq|</td>
499 <td><input name=duetyp class=radio type=radio value="8" $checked > |
500 . $locale->text('August') . qq|</td>
501 <td><input name=duetyp class=radio type=radio value="12" $checked > |
502 . $locale->text('December') . qq|</td>
506 <td colspan=5><hr size=3 noshade></td>
509 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
510 . $locale->text('Free report period') . qq|</th>
511 <td align=left colspan=4>| . $locale->text('From') . qq|
514 | . $locale->text('Bis') . qq|
520 <td colspan=5><hr size=3 noshade></td>
523 <th align=leftt>| . $locale->text('Method') . qq|</th>
524 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
525 . $locale->text('Accrual') . qq|
526 <input name=method class=radio type=radio value=cash $cash>|
527 . $locale->text('EUR') . qq|</td>
530 <th align=right colspan=4>|
531 . $locale->text('Decimalplaces')
533 <td><input name=decimalplaces size=3 value="2"></td>
540 if ($form->{report} eq "balance_sheet") {
542 <input type=hidden name=nextsub value=generate_balance_sheet>
544 <th align=right>| . $locale->text('as at') . qq|</th>
549 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
556 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
557 <td><input name=decimalplaces size=3 value="2"></td>
566 <th align=right>| . $locale->text('Method') . qq|</th>
567 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
568 . $locale->text('Accrual') . qq|
569 <input name=method class=radio type=radio value=cash $cash>|
570 . $locale->text('EUR') . qq|</td>
574 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
575 <td><input name=l_heading class=checkbox type=checkbox value=Y> |
576 . $locale->text('Heading') . qq|
577 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
578 . $locale->text('Subtotal') . qq|
579 <input name=l_accno class=checkbox type=checkbox value=Y> |
580 . $locale->text('Account Number') . qq|</td>
587 if ($form->{report} eq "trial_balance") {
589 <input type=hidden name=nextsub value=generate_trial_balance>
590 <input type=hidden name=eur value=$eur>
592 <th align=right>| . $locale->text('From') . qq|</th>
597 <th align=right>| . $locale->text('Bis') . qq|</th>
610 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
611 <td><input name=l_heading class=checkbox type=checkbox value=Y> |
612 . $locale->text('Heading') . qq|
613 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
614 . $locale->text('Subtotal') . qq|
615 <input name=all_accounts class=checkbox type=checkbox value=Y> |
616 . $locale->text('All Accounts') . qq|</td>
623 if ($form->{report} =~ /^tax_/) {
624 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
626 RP->get_taxaccounts(\%myconfig, \%$form);
629 <input type=hidden name=nextsub value=generate_tax_report>
631 <th align=right>| . $locale->text('From') . qq|</th>
632 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
633 <th align=right>| . $locale->text('Bis') . qq|</th>
634 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
637 <th align=right>| . $locale->text('Report for') . qq|</th>
641 $checked = "checked";
642 foreach $ref (@{ $form->{taxaccounts} }) {
645 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
647 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
648 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
655 <input type=hidden name=db value=$form->{db}>
656 <input type=hidden name=sort value=transdate>
661 <th align=right>| . $locale->text('Method') . qq|</th>
662 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
663 . $locale->text('Accrual') . qq|
664 <input name=method class=radio type=radio value=cash $cash>|
665 . $locale->text('EUR') . qq|</td>
674 <th align=right>| . $locale->text('Include in Report') . qq|</th>
678 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
679 <td>| . $locale->text('ID') . qq|</td>
680 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
681 <td>| . $locale->text('Invoice') . qq|</td>
682 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
683 <td>| . $locale->text('Date') . qq|</td>
686 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
689 if ($form->{db} eq 'ar') {
690 print $locale->text('Customer');
692 if ($form->{db} eq 'ap') {
693 print $locale->text('Vendor');
697 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
698 <td>| . $locale->text('Amount') . qq|</td>
699 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
700 <td>| . $locale->text('Tax') . qq|</td>
701 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
702 <td>| . $locale->text('Total') . qq|</td>
705 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
706 <td>| . $locale->text('Subtotal') . qq|</td>
715 if ($form->{report} =~ /^nontaxable_/) {
716 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
719 <input type=hidden name=nextsub value=generate_tax_report>
721 <input type=hidden name=db value=$form->{db}>
722 <input type=hidden name=sort value=transdate>
723 <input type=hidden name=report value=$form->{report}>
726 <th align=right>| . $locale->text('From') . qq|</th>
727 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
728 <th align=right>| . $locale->text('Bis') . qq|</th>
729 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
732 <th align=right>| . $locale->text('Method') . qq|</th>
733 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
734 . $locale->text('Accrual') . qq|
735 <input name=method class=radio type=radio value=cash $cash>|
736 . $locale->text('EUR') . qq|</td>
739 <th align=right>| . $locale->text('Include in Report') . qq|</th>
743 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
744 <td>| . $locale->text('ID') . qq|</td>
745 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
746 <td>| . $locale->text('Invoice') . qq|</td>
747 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
748 <td>| . $locale->text('Date') . qq|</td>
751 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
754 if ($form->{db} eq 'ar') {
755 print $locale->text('Customer');
757 if ($form->{db} eq 'ap') {
758 print $locale->text('Vendor');
762 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
763 <td>| . $locale->text('Amount') . qq|</td>
764 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
765 <td>| . $locale->text('Total') . qq|</td>
768 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
769 <td>| . $locale->text('Subtotal') . qq|</td>
778 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
779 if ($form->{report} eq 'ar_aging') {
780 $label = $locale->text('Customer');
781 $form->{vc} = 'customer';
783 $label = $locale->text('Vendor');
784 $form->{vc} = 'vendor';
787 $nextsub = "generate_$form->{report}";
790 $form->all_vc(\%myconfig, $form->{vc},
791 ($form->{vc} eq 'customer') ? "AR" : "AP");
793 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
794 @{ $form->{"all_$form->{vc}"} };
798 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
799 : qq|<input name=$form->{vc} size=35>|;
803 <th align=right>| . $locale->text($label) . qq|</th>
807 <th align=right>| . $locale->text('Bis') . qq|</th>
813 <input type=hidden name=type value=statement>
814 <input type=hidden name=format value=html>
815 <input type=hidden name=media value=screen>
817 <input type=hidden name=nextsub value=$nextsub>
818 <input type=hidden name=action value=$nextsub>
824 # above action can be removed if there is more than one input field
826 if ($form->{report} =~ /(receipts|payments)$/) {
827 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
829 RP->paymentaccounts(\%myconfig, \%$form);
831 $selection = "<option>\n";
832 foreach $ref (@{ $form->{PR} }) {
833 $paymentaccounts .= "$ref->{accno} ";
834 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
837 chop $paymentaccounts;
840 <input type=hidden name=nextsub value=list_payments>
842 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
843 <td colspan=3><select name=account>$selection</select>
844 <input type=hidden name=paymentaccounts value="$paymentaccounts">
848 <th align=right>| . $locale->text('Reference') . qq|</th>
849 <td colspan=3><input name=reference></td>
852 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
853 <td colspan=3><input name=source></td>
856 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
857 <td colspan=3><input name=memo size=30></td>
860 <th align=right>| . $locale->text('From') . qq|</th>
865 <th align=right>| . $locale->text('Bis') . qq|</th>
872 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
873 <th align=left colspan=3>|
874 . $locale->text('Include Exchangerate Difference') . qq|</td>
879 <input type=hidden name=db value=$form->{db}>
880 <input type=hidden name=sort value=transdate>
891 <td><hr size=3 noshade></td>
896 <input type=submit class=submit name=action value="|
897 . $locale->text('Continue') . qq|">
905 $lxdebug->leave_sub();
908 sub continue { call_sub($form->{"nextsub"}); }
911 $lxdebug->enter_sub();
913 $auth->assert('report');
917 $form->{project_id} = $form->{project_id_1};
918 if ($form->{projectnumber} && !$form->{project_id}) {
919 $form->{rowcount} = 1;
921 # call this instead of update
922 $form->{update} = $nextsub;
923 $form->{projectnumber_1} = $form->{projectnumber};
925 delete $form->{sort};
928 # if there is one only, assign id
929 $form->{project_id} = $form->{project_id_1};
932 $lxdebug->leave_sub();
935 sub generate_income_statement {
936 $lxdebug->enter_sub();
938 $auth->assert('report');
940 $form->{padding} = " ";
941 $form->{bold} = "<b>";
942 $form->{endbold} = "</b>";
943 $form->{br} = "<br>";
945 if ($form->{reporttype} eq "custom") {
947 #forgotten the year --> thisyear
948 if ($form->{year} !~ m/^\d\d\d\d$/) {
949 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
955 if ($form->{duetyp} eq "13") {
956 $form->{fromdate} = "1.1.$form->{year}";
957 $form->{todate} = "31.12.$form->{year}";
961 if ($form->{duetyp} eq "A") {
962 $form->{fromdate} = "1.1.$form->{year}";
963 $form->{todate} = "31.3.$form->{year}";
965 if ($form->{duetyp} eq "B") {
966 $form->{fromdate} = "1.4.$form->{year}";
967 $form->{todate} = "30.6.$form->{year}";
969 if ($form->{duetyp} eq "C") {
970 $form->{fromdate} = "1.7.$form->{year}";
971 $form->{todate} = "30.9.$form->{year}";
973 if ($form->{duetyp} eq "D") {
974 $form->{fromdate} = "1.10.$form->{year}";
975 $form->{todate} = "31.12.$form->{year}";
980 $form->{duetyp} eq "1" && do {
981 $form->{fromdate} = "1.1.$form->{year}";
982 $form->{todate} = "31.1.$form->{year}";
985 $form->{duetyp} eq "2" && do {
986 $form->{fromdate} = "1.2.$form->{year}";
988 #this works from 1901 to 2099, 1900 and 2100 fail.
989 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
990 $form->{todate} = "$leap.2.$form->{year}";
993 $form->{duetyp} eq "3" && do {
994 $form->{fromdate} = "1.3.$form->{year}";
995 $form->{todate} = "31.3.$form->{year}";
998 $form->{duetyp} eq "4" && do {
999 $form->{fromdate} = "1.4.$form->{year}";
1000 $form->{todate} = "30.4.$form->{year}";
1003 $form->{duetyp} eq "5" && do {
1004 $form->{fromdate} = "1.5.$form->{year}";
1005 $form->{todate} = "31.5.$form->{year}";
1008 $form->{duetyp} eq "6" && do {
1009 $form->{fromdate} = "1.6.$form->{year}";
1010 $form->{todate} = "30.6.$form->{year}";
1013 $form->{duetyp} eq "7" && do {
1014 $form->{fromdate} = "1.7.$form->{year}";
1015 $form->{todate} = "31.7.$form->{year}";
1018 $form->{duetyp} eq "8" && do {
1019 $form->{fromdate} = "1.8.$form->{year}";
1020 $form->{todate} = "31.8.$form->{year}";
1023 $form->{duetyp} eq "9" && do {
1024 $form->{fromdate} = "1.9.$form->{year}";
1025 $form->{todate} = "30.9.$form->{year}";
1028 $form->{duetyp} eq "10" && do {
1029 $form->{fromdate} = "1.10.$form->{year}";
1030 $form->{todate} = "31.10.$form->{year}";
1033 $form->{duetyp} eq "11" && do {
1034 $form->{fromdate} = "1.11.$form->{year}";
1035 $form->{todate} = "30.11.$form->{year}";
1038 $form->{duetyp} eq "12" && do {
1039 $form->{fromdate} = "1.12.$form->{year}";
1040 $form->{todate} = "31.12.$form->{year}";
1046 RP->income_statement(\%myconfig, \%$form);
1048 ($form->{department}) = split /--/, $form->{department};
1051 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1052 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1054 # if there are any dates construct a where
1055 if ($form->{fromdate} || $form->{todate}) {
1057 unless ($form->{todate}) {
1058 $form->{todate} = $form->current_date(\%myconfig);
1061 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1062 $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1064 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1065 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1067 $form->{this_period} = "$shortfromdate\n$shorttodate";
1069 $locale->text('for Period')
1070 . qq|\n$longfromdate |
1071 . $locale->text('Bis')
1075 if ($form->{comparefromdate} || $form->{comparetodate}) {
1076 $longcomparefromdate =
1077 $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1078 $shortcomparefromdate =
1079 $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1081 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1082 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1084 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1086 "\n$longcomparefromdate "
1087 . $locale->text('Bis')
1088 . qq| $longcomparetodate|;
1091 # setup variables for the form
1092 @a = qw(company address businessnumber);
1093 map { $form->{$_} = $myconfig{$_} } @a;
1095 $form->{templates} = $myconfig{templates};
1097 $form->{IN} = "income_statement.html";
1099 $form->parse_template;
1101 $lxdebug->leave_sub();
1104 sub generate_balance_sheet {
1105 $lxdebug->enter_sub();
1107 $auth->assert('report');
1109 $form->{padding} = " ";
1110 $form->{bold} = "<b>";
1111 $form->{endbold} = "</b>";
1112 $form->{br} = "<br>";
1114 RP->balance_sheet(\%myconfig, \%$form);
1116 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1118 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1120 ($form->{department}) = split /--/, $form->{department};
1122 # define Current Earnings account
1123 $padding = ($form->{l_heading}) ? $form->{padding} : "";
1124 push(@{ $form->{equity_account} },
1125 $padding . $locale->text('Current Earnings'));
1127 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1128 $form->{last_period} =
1129 $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1131 $form->{IN} = "balance_sheet.html";
1133 # setup company variables for the form
1134 map { $form->{$_} = $myconfig{$_}; } (qw(company address businessnumber nativecurr));
1136 $form->{templates} = $myconfig{templates};
1138 $form->parse_template;
1140 $lxdebug->leave_sub();
1143 sub generate_projects {
1144 $lxdebug->enter_sub();
1146 $auth->assert('report');
1148 &get_project(generate_projects);
1149 $form->{projectnumber} = $form->{projectnumber_1};
1151 $form->{nextsub} = "generate_projects";
1152 $form->{title} = $locale->text('Project Transactions');
1153 RP->trial_balance(\%myconfig, \%$form);
1155 list_accounts('generate_projects');
1157 $lxdebug->leave_sub();
1163 # included links to display transactions for period entered
1164 # added headers and subtotals
1166 sub generate_trial_balance {
1167 $lxdebug->enter_sub();
1169 $auth->assert('report');
1171 # get for each account initial balance, debits and credits
1172 RP->trial_balance(\%myconfig, \%$form);
1174 $form->{nextsub} = "generate_trial_balance";
1175 $form->{title} = $locale->text('Trial Balance');
1176 list_accounts('generate_trial_balance');
1178 $lxdebug->leave_sub();
1181 sub create_list_accounts_subtotal_row {
1182 $lxdebug->enter_sub();
1184 my ($subtotals, $columns, $fields, $class) = @_;
1186 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1188 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1190 $lxdebug->leave_sub();
1196 $lxdebug->enter_sub();
1201 if ($form->{department}) {
1202 my ($department) = split /--/, $form->{department};
1203 push @options, $locale->text('Department') . " : $department";
1205 if ($form->{projectnumber}) {
1206 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1209 # if there are any dates
1210 if ($form->{fromdate} || $form->{todate}) {
1211 my ($fromdate, $todate);
1213 if ($form->{fromdate}) {
1214 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1216 if ($form->{todate}) {
1217 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1220 push @options, "$fromdate - $todate";
1223 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1226 my @columns = qw(accno description begbalance debit credit endbalance);
1228 'accno' => { 'text' => $locale->text('Account'), },
1229 'description' => { 'text' => $locale->text('Description'), },
1230 'debit' => { 'text' => $locale->text('Debit'), },
1231 'credit' => { 'text' => $locale->text('Credit'), },
1232 'begbalance' => { 'text' => $locale->text('Balance'), },
1233 'endbalance' => { 'text' => $locale->text('Balance'), },
1235 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1237 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1239 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1241 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1243 $report->set_options('top_info_text' => join("\n", @options),
1244 'output_format' => 'HTML',
1245 'title' => $form->{title},
1246 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1247 'std_column_visibility' => 1,
1249 $report->set_options_from_form();
1251 $report->set_columns(%column_defs);
1252 $report->set_column_order(@columns);
1254 $report->set_export_options($action, @hidden_variables);
1256 $report->set_sort_indicator('accno', 1);
1258 my @totals_columns = qw(credit debit begbalance endbalance);
1259 my %subtotals = map { $_ => 0 } @totals_columns;
1260 my %totals = map { $_ => 0 } @totals_columns;
1261 my $found_heading = 0;
1262 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1264 # sort the whole thing by account numbers and display
1265 foreach my $idx (0 .. scalar(@tb) - 1) {
1266 my $ref = $tb[$idx];
1267 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1269 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1271 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1273 if ($ref->{charttype} eq 'H') {
1274 next unless ($form->{l_heading});
1276 %subtotals = map { $_ => 0 } @totals_columns;
1278 $row->{description}->{class} = 'listheading';
1279 $row->{description}->{data} = $ref->{description};
1281 $report->add_data($row);
1286 foreach (qw(debit credit)) {
1287 $subtotals{$_} += $ref->{$_};
1288 $totals{$_} += $ref->{$_};
1291 $subtotals{begbalance} += $ref->{balance} * $ml;
1292 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1294 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1295 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1297 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1298 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1300 $report->add_data($row);
1302 if ($form->{l_heading} && $found_heading &&
1303 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1304 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1308 $report->add_separator();
1310 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1312 $report->generate_with_headers();
1314 $lxdebug->leave_sub();
1317 sub generate_ar_aging {
1318 $lxdebug->enter_sub();
1320 $auth->assert('general_ledger');
1323 ($form->{customer}) = split(/--/, $form->{customer});
1325 $form->{ct} = "customer";
1326 $form->{arap} = "ar";
1328 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1330 RP->aging(\%myconfig, \%$form);
1333 $lxdebug->leave_sub();
1336 sub generate_ap_aging {
1337 $lxdebug->enter_sub();
1339 $auth->assert('general_ledger');
1342 ($form->{vendor}) = split(/--/, $form->{vendor});
1344 $form->{ct} = "vendor";
1345 $form->{arap} = "ap";
1347 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1349 RP->aging(\%myconfig, \%$form);
1352 $lxdebug->leave_sub();
1355 sub create_aging_subtotal_row {
1356 $lxdebug->enter_sub();
1358 my ($subtotals, $columns, $periods, $class) = @_;
1360 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1362 foreach (@{ $periods }) {
1363 $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1364 $subtotals->{$_} = 0;
1367 $lxdebug->leave_sub();
1373 $lxdebug->enter_sub();
1375 $auth->assert('general_ledger');
1377 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1379 my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
1382 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1383 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1384 'invnumber' => { 'text' => $locale->text('Invoice'), },
1385 'transdate' => { 'text' => $locale->text('Date'), },
1386 'duedate' => { 'text' => $locale->text('Due'), },
1387 'c0' => { 'text' => $locale->text('Current'), },
1388 'c30' => { 'text' => '30', },
1389 'c60' => { 'text' => '60', },
1390 'c90' => { 'text' => '90', },
1393 my %column_alignment = ('statement' => 'center',
1394 map { $_ => 'right' } qw(c0 c30 c60 c90));
1396 $report->set_options('std_column_visibility' => 1);
1397 $report->set_columns(%column_defs);
1398 $report->set_column_order(@columns);
1400 my @hidden_variables = qw(todate customer vendor arap title ct);
1401 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1405 if ($form->{department}) {
1406 my ($department) = split /--/, $form->{department};
1407 push @options, $locale->text('Department') . " : $department";
1408 $form->{callback} .= "&department=" . E($department);
1411 if (($form->{arap} eq 'ar') && $form->{customer}) {
1412 push @options, $form->{customer};
1415 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1416 push @options, $form->{vendor};
1419 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1421 my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1423 $report->set_options('top_info_text' => join("\n", @options),
1424 'output_format' => 'HTML',
1425 'title' => $form->{title},
1426 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1429 my $previous_ctid = 0;
1431 my @periods = qw(0 30 60 90);
1432 my %subtotals = map { $_ => 0 } @periods;
1433 my %totals = map { $_ => 0 } @periods;
1435 foreach $ref (@{ $form->{AG} }) {
1436 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1437 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1440 foreach my $key (@periods) {
1441 $subtotals{$key} += $ref->{"c${key}"};
1442 $totals{$key} += $ref->{"c${key}"};
1443 $ref->{"c${key}"} = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
1448 foreach my $column (@columns) {
1450 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1451 'align' => $column_alignment{$column},
1452 'valign' => $column eq 'statement' ? 'center' : '',
1456 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1458 if ($previous_ctid != $ref->{ctid}) {
1459 $row->{statement}->{raw_data} =
1460 $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
1461 . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1462 $row->{ct}->{data} = $ref->{name};
1467 $previous_ctid = $ref->{ctid};
1469 $report->add_data($row);
1472 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1474 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1476 if ($form->{arap} eq 'ar') {
1477 $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1478 $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1479 'PRINT_OPTIONS' => print_options(inline => 1), });
1480 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1481 'raw_bottom_info_text' => $raw_bottom_info_text);
1484 $report->set_options_from_form();
1486 $report->generate_with_headers();
1488 $lxdebug->leave_sub();
1492 $lxdebug->enter_sub();
1494 RP->aging(\%myconfig, \%$form);
1496 map { $_->{checked} = "checked" } @{ $form->{AG} };
1500 $lxdebug->leave_sub();
1504 $lxdebug->enter_sub();
1506 $auth->assert('general_ledger');
1508 # get name and email addresses
1509 for $i (1 .. $form->{rowcount}) {
1510 if ($form->{"statement_$i"}) {
1511 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1512 RP->get_customer(\%myconfig, \%$form);
1518 $form->error($locale->text('Nothing selected!')) unless $selected;
1520 if ($myconfig{role} eq 'admin') {
1522 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1523 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1527 $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1529 $form->{media} = "email";
1536 <form method=post action=$form->{script}>
1542 <tr height="5"></tr>
1547 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1548 <td><input name=email size=30 value="$form->{email}"></td>
1549 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1550 <td><input name=cc size=30 value="$form->{cc}"></td>
1553 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1554 <td><input name=subject size=30 value="$form->{subject}"></td>
1564 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1567 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1578 map { delete $form->{$_} }
1579 qw(action email cc bcc subject message type sendmode format header);
1581 # save all other variables
1582 foreach $key (keys %$form) {
1583 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1584 $form->{$key} =~ s/\"/"/g;
1585 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1592 <td><hr size=3 noshade></td>
1596 <input type=hidden name=nextsub value=send_email>
1599 <input name=action class=submit type=submit value="|
1600 . $locale->text('Continue') . qq|">
1607 $lxdebug->leave_sub();
1611 $lxdebug->enter_sub();
1613 $auth->assert('general_ledger');
1615 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1616 unless $form->{subject};
1618 RP->aging(\%myconfig, \%$form);
1620 $form->{"statement_1"} = 1;
1622 $form->{media} = 'email';
1625 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1627 $lxdebug->leave_sub();
1631 $lxdebug->enter_sub();
1633 $auth->assert('general_ledger');
1635 if ($form->{media} eq 'printer') {
1636 $form->error($locale->text('Select postscript or PDF!'))
1637 if ($form->{format} !~ /(postscript|pdf)/);
1640 for $i (1 .. $form->{rowcount}) {
1641 if ($form->{"statement_$i"}) {
1642 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1648 $form->error($locale->text('Nothing selected!')) unless $selected;
1650 if ($form->{media} eq 'printer') {
1651 $form->{"$form->{ct}_id"} = "";
1653 $form->{"statement_1"} = 1;
1656 RP->aging(\%myconfig, \%$form);
1660 $form->redirect($locale->text('Statements sent to printer!'))
1661 if ($form->{media} eq 'printer');
1663 $lxdebug->leave_sub();
1667 $lxdebug->enter_sub();
1669 $auth->assert('general_ledger');
1673 "ä" => "ae", "ö" => "oe", "ü" => "ue",
1674 "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
1679 foreach my $key (keys %replacements) {
1680 my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
1681 $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
1684 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1686 $form->{templates} = "$myconfig{templates}";
1688 my $suffix = "html";
1689 my $attachment_suffix = "html";
1690 if ($form->{format} eq 'postscript') {
1691 $form->{postscript} = 1;
1693 $attachment_suffix = "ps";
1694 } elsif ($form->{format} eq 'pdf') {
1697 $attachment_suffix = "pdf";
1700 $form->{IN} = "$form->{type}.$suffix";
1701 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1703 # Save $form->{email} because it will be overwritten.
1704 $form->{EMAIL_RECIPIENT} = $form->{email};
1707 while (@{ $form->{AG} }) {
1709 $ref = shift @{ $form->{AG} };
1711 if ($ctid != $ref->{ctid}) {
1713 $ctid = $ref->{ctid};
1716 if ($form->{"statement_$i"}) {
1719 (name, street, zipcode, city, country, contact, email,
1720 "$form->{ct}phone", "$form->{ct}fax");
1721 map { $form->{$_} = $ref->{$_} } @a;
1723 $form->{ $form->{ct} } = $form->{name};
1724 $form->{"$form->{ct}_id"} = $ref->{ctid};
1726 map { $form->{$_} = () } qw(invnumber invdate duedate);
1728 foreach $item (qw(c0 c30 c60 c90)) {
1729 $form->{$item} = ();
1730 $form->{"${item}total"} = 0;
1733 &statement_details($ref);
1737 if (scalar(@{ $form->{AG} }) > 0) {
1739 # one or more left to go
1740 if ($ctid == $form->{AG}->[0]->{ctid}) {
1741 $ref = shift @{ $form->{AG} };
1742 &statement_details($ref);
1745 $ref = scalar(@{ $form->{AG} });
1751 # set initial ref to 0
1758 $form->{"${_}total"} =
1759 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1760 } (c0, c30, c60, c90, "");
1762 $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
1763 map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
1765 $form->parse_template(\%myconfig, $userspath);
1770 # saving the history
1771 if(!exists $form->{addition} && $form->{id} ne "") {
1772 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1773 $form->{addition} = "PRINTED";
1774 $form->{what_done} = $form->{type};
1775 $form->save_history($form->dbconnect(\%myconfig));
1777 # /saving the history
1778 $lxdebug->leave_sub();
1781 sub statement_details {
1782 $lxdebug->enter_sub();
1784 $auth->assert('general_ledger');
1788 push @{ $form->{invnumber} }, $ref->{invnumber};
1789 push @{ $form->{invdate} }, $ref->{transdate};
1790 push @{ $form->{duedate} }, $ref->{duedate};
1792 foreach $item (qw(c0 c30 c60 c90)) {
1793 if ($ref->{exchangerate} * 1) {
1795 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
1797 $form->{"${item}total"} += $ref->{$item};
1798 $form->{total} += $ref->{$item};
1799 push @{ $form->{$item} },
1800 $form->format_amount(\%myconfig, $ref->{$item}, 2);
1803 $lxdebug->leave_sub();
1806 sub generate_tax_report {
1807 $lxdebug->enter_sub();
1809 $auth->assert('report');
1811 RP->tax_report(\%myconfig, \%$form);
1813 $descvar = "$form->{accno}_description";
1814 $description = $form->escape($form->{$descvar});
1815 $ratevar = "$form->{accno}_rate";
1817 $department = $form->escape($form->{department});
1821 "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
1823 # construct callback
1824 $description = $form->escape($form->{$descvar}, 1);
1825 $department = $form->escape($form->{department}, 1);
1827 "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
1829 $title = $form->escape($form->{title});
1830 $href .= "&title=$title";
1831 $title = $form->escape($form->{title}, 1);
1832 $callback .= "&title=$title";
1834 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
1837 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1839 foreach $item (@columns) {
1840 if ($form->{"l_$item"} eq "Y") {
1841 push @column_index, $item;
1843 # add column to href and callback
1844 $callback .= "&l_$item=Y";
1845 $href .= "&l_$item=Y";
1849 if ($form->{l_subtotal} eq 'Y') {
1850 $callback .= "&l_subtotal=Y";
1851 $href .= "&l_subtotal=Y";
1854 if ($form->{department}) {
1855 ($department) = split /--/, $form->{department};
1856 $option = $locale->text('Department') . " : $department";
1859 # if there are any dates
1860 if ($form->{fromdate} || $form->{todate}) {
1861 if ($form->{fromdate}) {
1862 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1864 if ($form->{todate}) {
1865 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1868 $form->{period} = "$fromdate - $todate";
1871 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1874 if ($form->{db} eq 'ar') {
1875 $name = $locale->text('Customer');
1879 if ($form->{db} eq 'ap') {
1880 $name = $locale->text('Vendor');
1885 $option .= "<br>" if $option;
1886 $option .= "$form->{period}";
1888 $column_header{id} =
1889 qq|<th><a class=listheading href=$href&sort=id>|
1890 . $locale->text('ID')
1892 $column_header{invnumber} =
1893 qq|<th><a class=listheading href=$href&sort=invnumber>|
1894 . $locale->text('Invoice')
1896 $column_header{transdate} =
1897 qq|<th><a class=listheading href=$href&sort=transdate>|
1898 . $locale->text('Date')
1900 $column_header{netamount} =
1901 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1902 $column_header{tax} =
1903 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1904 $column_header{amount} =
1905 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1907 $column_header{name} =
1908 qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
1917 <th class=listtop colspan=$colspan>$form->{title}</th>
1919 <tr height="5"></tr>
1926 <tr class=listheading>
1929 map { print "$column_header{$_}\n" } @column_index;
1935 # add sort and escape callback
1936 $callback = $form->escape($callback . "&sort=$form->{sort}");
1938 if (@{ $form->{TR} }) {
1939 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
1942 foreach $ref (@{ $form->{TR} }) {
1944 $module = ($ref->{invoice}) ? $invoice : $arap;
1946 if ($form->{l_subtotal} eq 'Y') {
1947 if ($sameitem ne $ref->{ $form->{sort} }) {
1949 $sameitem = $ref->{ $form->{sort} };
1953 $totalnetamount += $ref->{netamount};
1954 $totaltax += $ref->{tax};
1955 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1957 $subtotalnetamount += $ref->{netamount};
1958 $subtotaltax += $ref->{tax};
1961 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
1962 } qw(netamount tax amount);
1964 $column_data{id} = qq|<td>$ref->{id}</td>|;
1965 $column_data{invnumber} =
1966 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
1967 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
1968 $column_data{name} = qq|<td>$ref->{name} </td>|;
1970 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
1971 qw(netamount tax amount);
1976 <tr class=listrow$i>
1979 map { print "$column_data{$_}\n" } @column_index;
1987 if ($form->{l_subtotal} eq 'Y') {
1991 map { $column_data{$_} = qq|<th> </th>| } @column_index;
1995 <tr class=listtotal>
1999 $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2001 $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2002 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2004 $column_data{netamount} =
2005 qq|<th class=listtotal align=right>$totalnetamount</th>|;
2006 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2007 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2009 map { print "$column_data{$_}\n" } @column_index;
2017 <td><hr size=3 noshade></td>
2025 $lxdebug->leave_sub();
2029 $lxdebug->enter_sub();
2031 map { $column_data{$_} = "<td> </td>" } @column_index;
2033 $subtotalnetamount =
2034 $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
2035 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
2037 $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2040 $column_data{netamount} =
2041 "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2042 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2043 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2045 $subtotalnetamount = 0;
2049 <tr class=listsubtotal>
2051 map { print "\n$column_data{$_}" } @column_index;
2057 $lxdebug->leave_sub();
2061 $lxdebug->enter_sub();
2063 $auth->assert('cash');
2065 if ($form->{account}) {
2066 ($form->{paymentaccounts}) = split /--/, $form->{account};
2068 if ($form->{department}) {
2069 ($department, $form->{department_id}) = split /--/, $form->{department};
2070 $option = $locale->text('Department') . " : $department";
2073 RP->payments(\%myconfig, \%$form);
2075 my @hidden_variables = qw(account title department reference source memo fromdate todate
2076 fx_transaction db prepayment paymentaccounts sort);
2078 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2079 $form->{callback} = $href;
2081 my @columns = qw(transdate invnumber name paid source memo);
2083 'name' => { 'text' => $locale->text('Description'), },
2084 'invnumber' => { 'text' => $locale->text('Reference'), },
2085 'transdate' => { 'text' => $locale->text('Date'), },
2086 'paid' => { 'text' => $locale->text('Amount'), },
2087 'source' => { 'text' => $locale->text('Source'), },
2088 'memo' => { 'text' => $locale->text('Memo'), },
2090 my %column_alignment = ('paid' => 'right');
2092 map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns;
2095 if ($form->{fromdate}) {
2096 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2098 if ($form->{todate}) {
2099 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2102 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2104 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2106 $report->set_options('top_info_text' => join("\n", @options),
2107 'output_format' => 'HTML',
2108 'title' => $form->{title},
2109 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2110 'std_column_visibility' => 1,
2112 $report->set_options_from_form();
2114 $report->set_columns(%column_defs);
2115 $report->set_column_order(@columns);
2117 $report->set_export_options('list_payments', @hidden_variables);
2119 $report->set_sort_indicator($form->{sort}, 1);
2123 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2124 next unless @{ $form->{ $ref->{id} } };
2126 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2128 my $subtotal_paid = 0;
2130 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2131 my $module = $payment->{module};
2132 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2133 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2135 $subtotal_paid += $payment->{paid};
2136 $total_paid += $payment->{paid};
2138 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2142 foreach my $column (@columns) {
2144 'data' => $payment->{$column},
2145 'align' => $column_alignment{$column},
2149 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2151 $report->add_data($row);
2154 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2156 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2158 'class' => 'listsubtotal',
2161 $report->add_data($row);
2164 $report->add_separator();
2166 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2168 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2170 'class' => 'listtotal',
2173 $report->add_data($row);
2175 $report->generate_with_headers();
2177 $lxdebug->leave_sub();
2181 $lxdebug->enter_sub();
2183 my ($dont_print) = @_;
2185 $form->{sendmode} = "attachment";
2188 $form->{"format"} ? $form->{"format"} :
2189 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2193 $form->{"copies"} ? $form->{"copies"} :
2194 $myconfig{"copies"} ? $myconfig{"copies"} :
2197 $form->{PD}{ $form->{type} } = "selected";
2198 $form->{DF}{ $form->{format} } = "selected";
2199 $form->{OP}{ $form->{media} } = "selected";
2200 $form->{SM}{ $form->{sendmode} } = "selected";
2203 <option value=statement $form->{PD}{statement}>|
2204 . $locale->text('Statement');
2206 if ($form->{media} eq 'email') {
2208 <option value=attachment $form->{SM}{attachment}>|
2209 . $locale->text('Attachment') . qq|
2210 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2213 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2214 if ($myconfig{printer} && $latex_templates) {
2216 <option value=printer $form->{OP}{printer}>|
2217 . $locale->text('Printer');
2221 if ($latex_templates) {
2223 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2224 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2225 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2231 <td><select name=type>$type</select></td>
2232 <td><select name=format>$format</select></td>
2233 <td><select name=media>$media</select></td>
2236 if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2238 <td>| . $locale->text('Copies') . qq|
2239 <input name=copies size=2 value=$form->{copies}></td>
2248 print $output unless $dont_print;
2250 $lxdebug->leave_sub();
2256 $lxdebug->enter_sub();
2258 $auth->assert('report');
2260 $form->{padding} = " ";
2261 $form->{bold} = "<b>";
2262 $form->{endbold} = "</b>";
2263 $form->{br} = "<br>";
2265 if ($form->{reporttype} eq "custom") {
2267 #forgotten the year --> thisyear
2268 if ($form->{year} !~ m/^\d\d\d\d$/) {
2269 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2275 if ($form->{duetyp} eq "13") {
2276 $form->{fromdate} = "1.1.$form->{year}";
2277 $form->{todate} = "31.12.$form->{year}";
2278 $form->{comparefromdate} = "1.01.$form->{year}";
2279 $form->{comparetodate} = "31.12.$form->{year}";
2283 if ($form->{duetyp} eq "A") {
2284 $form->{fromdate} = "1.1.$form->{year}";
2285 $form->{todate} = "31.3.$form->{year}";
2286 $form->{comparefromdate} = "1.01.$form->{year}";
2287 $form->{comparetodate} = "31.03.$form->{year}";
2289 if ($form->{duetyp} eq "B") {
2290 $form->{fromdate} = "1.4.$form->{year}";
2291 $form->{todate} = "30.6.$form->{year}";
2292 $form->{comparefromdate} = "1.01.$form->{year}";
2293 $form->{comparetodate} = "30.06.$form->{year}";
2295 if ($form->{duetyp} eq "C") {
2296 $form->{fromdate} = "1.7.$form->{year}";
2297 $form->{todate} = "30.9.$form->{year}";
2298 $form->{comparefromdate} = "1.01.$form->{year}";
2299 $form->{comparetodate} = "30.09.$form->{year}";
2301 if ($form->{duetyp} eq "D") {
2302 $form->{fromdate} = "1.10.$form->{year}";
2303 $form->{todate} = "31.12.$form->{year}";
2304 $form->{comparefromdate} = "1.01.$form->{year}";
2305 $form->{comparetodate} = "31.12.$form->{year}";
2310 $form->{duetyp} eq "1" && do {
2311 $form->{fromdate} = "1.1.$form->{year}";
2312 $form->{todate} = "31.1.$form->{year}";
2313 $form->{comparefromdate} = "1.01.$form->{year}";
2314 $form->{comparetodate} = "31.01.$form->{year}";
2317 $form->{duetyp} eq "2" && do {
2318 $form->{fromdate} = "1.2.$form->{year}";
2320 #this works from 1901 to 2099, 1900 and 2100 fail.
2321 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2322 $form->{todate} = "$leap.2.$form->{year}";
2323 $form->{comparefromdate} = "1.01.$form->{year}";
2324 $form->{comparetodate} = "$leap.02.$form->{year}";
2327 $form->{duetyp} eq "3" && do {
2328 $form->{fromdate} = "1.3.$form->{year}";
2329 $form->{todate} = "31.3.$form->{year}";
2330 $form->{comparefromdate} = "1.01.$form->{year}";
2331 $form->{comparetodate} = "31.03.$form->{year}";
2334 $form->{duetyp} eq "4" && do {
2335 $form->{fromdate} = "1.4.$form->{year}";
2336 $form->{todate} = "30.4.$form->{year}";
2337 $form->{comparefromdate} = "1.01.$form->{year}";
2338 $form->{comparetodate} = "30.04.$form->{year}";
2341 $form->{duetyp} eq "5" && do {
2342 $form->{fromdate} = "1.5.$form->{year}";
2343 $form->{todate} = "31.5.$form->{year}";
2344 $form->{comparefromdate} = "1.01.$form->{year}";
2345 $form->{comparetodate} = "31.05.$form->{year}";
2348 $form->{duetyp} eq "6" && do {
2349 $form->{fromdate} = "1.6.$form->{year}";
2350 $form->{todate} = "30.6.$form->{year}";
2351 $form->{comparefromdate} = "1.01.$form->{year}";
2352 $form->{comparetodate} = "30.06.$form->{year}";
2355 $form->{duetyp} eq "7" && do {
2356 $form->{fromdate} = "1.7.$form->{year}";
2357 $form->{todate} = "31.7.$form->{year}";
2358 $form->{comparefromdate} = "1.01.$form->{year}";
2359 $form->{comparetodate} = "31.07.$form->{year}";
2362 $form->{duetyp} eq "8" && do {
2363 $form->{fromdate} = "1.8.$form->{year}";
2364 $form->{todate} = "31.8.$form->{year}";
2365 $form->{comparefromdate} = "1.01.$form->{year}";
2366 $form->{comparetodate} = "31.08.$form->{year}";
2369 $form->{duetyp} eq "9" && do {
2370 $form->{fromdate} = "1.9.$form->{year}";
2371 $form->{todate} = "30.9.$form->{year}";
2372 $form->{comparefromdate} = "1.01.$form->{year}";
2373 $form->{comparetodate} = "30.09.$form->{year}";
2376 $form->{duetyp} eq "10" && do {
2377 $form->{fromdate} = "1.10.$form->{year}";
2378 $form->{todate} = "31.10.$form->{year}";
2379 $form->{comparefromdate} = "1.01.$form->{year}";
2380 $form->{comparetodate} = "31.10.$form->{year}";
2383 $form->{duetyp} eq "11" && do {
2384 $form->{fromdate} = "1.11.$form->{year}";
2385 $form->{todate} = "30.11.$form->{year}";
2386 $form->{comparefromdate} = "1.01.$form->{year}";
2387 $form->{comparetodate} = "30.11.$form->{year}";
2390 $form->{duetyp} eq "12" && do {
2391 $form->{fromdate} = "1.12.$form->{year}";
2392 $form->{todate} = "31.12.$form->{year}";
2393 $form->{comparefromdate} = "1.01.$form->{year}";
2394 $form->{comparetodate} = "31.12.$form->{year}";
2399 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2400 $form->{fromdate} = "${dd}.${mm}.${yy}";
2401 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2402 $form->{todate} = "${dd}.${mm}.${yy}";
2403 $form->{comparefromdate} = "01.01.$yy";
2404 $form->{comparetodate} = $form->{todate};
2407 RP->bwa(\%myconfig, \%$form);
2409 ($form->{department}) = split /--/, $form->{department};
2412 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2413 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2415 # if there are any dates construct a where
2416 if ($form->{fromdate} || $form->{todate}) {
2418 unless ($form->{todate}) {
2419 $form->{todate} = $form->current_date(\%myconfig);
2422 my %germandate = ("dateformat" => "dd.mm.yyyy");
2424 $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2425 $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2427 $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2428 $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2430 $form->{this_period} = "$shortfromdate\n$shorttodate";
2432 $locale->text('for Period')
2433 . qq|\n$longfromdate |
2434 . $locale->text('bis')
2438 # setup variables for the form
2439 @a = qw(company address businessnumber);
2440 map { $form->{$_} = $myconfig{$_} } @a;
2441 $form->{templates} = $myconfig{templates};
2443 $form->{IN} = "bwa.html";
2445 $form->parse_template;
2447 $lxdebug->leave_sub();