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") {
590 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
591 <td colspan=3>$projectnumber</td>
593 <input type=hidden name=nextsub value=generate_trial_balance>
597 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
598 . $locale->text('Customized Report') . qq|</th>
601 <th colspan=1>| . $locale->text('Year') . qq|</th>
602 <td><input name=year size=11 title="|
603 . $locale->text('YYYY') . qq|" value="$year"></td>
610 <b> | . $locale->text('Yearly') . qq|</b> </td>
611 <th align=left>| . $locale->text('Quarterly') . qq|</th>
612 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
615 <td align=right> <input name=duetyp class=radio type=radio value="13"
617 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
618 . $locale->text('Quarter') . qq|</td>
620 $checked = "checked";
622 <td><input name=duetyp class=radio type=radio value="1" $checked > |
623 . $locale->text('January') . qq|</td>
627 <td><input name=duetyp class=radio type=radio value="5" $checked > |
628 . $locale->text('May') . qq|</td>
629 <td><input name=duetyp class=radio type=radio value="9" $checked > |
630 . $locale->text('September') . qq|</td>
634 <td align= right> </td>
635 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
636 . $locale->text('Quarter') . qq|</td>
637 <td><input name=duetyp class=radio type=radio value="2" $checked > |
638 . $locale->text('February') . qq|</td>
639 <td><input name=duetyp class=radio type=radio value="6" $checked > |
640 . $locale->text('June') . qq|</td>
641 <td><input name=duetyp class=radio type=radio value="10" $checked > |
642 . $locale->text('October') . qq|</td>
646 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
647 . $locale->text('Quarter') . qq|</td>
648 <td><input name=duetyp class=radio type=radio value="3" $checked > |
649 . $locale->text('March') . qq|</td>
650 <td><input name=duetyp class=radio type=radio value="7" $checked > |
651 . $locale->text('July') . qq|</td>
652 <td><input name=duetyp class=radio type=radio value="11" $checked > |
653 . $locale->text('November') . qq|</td>
658 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
659 . $locale->text('Quarter') . qq| </td>
660 <td><input name=duetyp class=radio type=radio value="4" $checked > |
661 . $locale->text('April') . qq|</td>
662 <td><input name=duetyp class=radio type=radio value="8" $checked > |
663 . $locale->text('August') . qq|</td>
664 <td><input name=duetyp class=radio type=radio value="12" $checked > |
665 . $locale->text('December') . qq|</td>
669 <td colspan=5><hr size=3 noshade></td>
672 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
673 . $locale->text('Free report period') . qq|</th>
674 <td align=left colspan=4>| . $locale->text('From') . qq|
677 | . $locale->text('Bis') . qq|
683 <td colspan=5><hr size=3 noshade></td>
686 <th align=leftt>| . $locale->text('Method') . qq|</th>
687 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
688 . $locale->text('Accrual') . qq|
689 <input name=method class=radio type=radio value=cash $cash>|
690 . $locale->text('EUR') . qq|</td>
693 <th align=right colspan=4>|
694 . $locale->text('All Accounts')
696 <td><input name=all_accounts type=checkbox value=1></td>
699 <th align=right colspan=4>|
700 . $locale->text('Decimalplaces')
702 <td><input name=decimalplaces size=3 value="2"></td>
709 if ($form->{report} =~ /^tax_/) {
710 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
712 RP->get_taxaccounts(\%myconfig, \%$form);
715 <input type=hidden name=nextsub value=generate_tax_report>
717 <th align=right>| . $locale->text('From') . qq|</th>
718 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
719 <th align=right>| . $locale->text('Bis') . qq|</th>
720 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
723 <th align=right>| . $locale->text('Report for') . qq|</th>
727 $checked = "checked";
728 foreach $ref (@{ $form->{taxaccounts} }) {
731 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
733 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
734 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
741 <input type=hidden name=db value=$form->{db}>
742 <input type=hidden name=sort value=transdate>
747 <th align=right>| . $locale->text('Method') . qq|</th>
748 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
749 . $locale->text('Accrual') . qq|
750 <input name=method class=radio type=radio value=cash $cash>|
751 . $locale->text('EUR') . qq|</td>
760 <th align=right>| . $locale->text('Include in Report') . qq|</th>
764 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
765 <td>| . $locale->text('ID') . qq|</td>
766 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
767 <td>| . $locale->text('Invoice') . qq|</td>
768 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
769 <td>| . $locale->text('Date') . qq|</td>
772 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
775 if ($form->{db} eq 'ar') {
776 print $locale->text('Customer');
778 if ($form->{db} eq 'ap') {
779 print $locale->text('Vendor');
783 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
784 <td>| . $locale->text('Amount') . qq|</td>
785 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
786 <td>| . $locale->text('Tax') . qq|</td>
787 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
788 <td>| . $locale->text('Total') . qq|</td>
791 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
792 <td>| . $locale->text('Subtotal') . qq|</td>
801 if ($form->{report} =~ /^nontaxable_/) {
802 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
805 <input type=hidden name=nextsub value=generate_tax_report>
807 <input type=hidden name=db value=$form->{db}>
808 <input type=hidden name=sort value=transdate>
809 <input type=hidden name=report value=$form->{report}>
812 <th align=right>| . $locale->text('From') . qq|</th>
813 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
814 <th align=right>| . $locale->text('Bis') . qq|</th>
815 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
818 <th align=right>| . $locale->text('Method') . qq|</th>
819 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
820 . $locale->text('Accrual') . qq|
821 <input name=method class=radio type=radio value=cash $cash>|
822 . $locale->text('EUR') . qq|</td>
825 <th align=right>| . $locale->text('Include in Report') . qq|</th>
829 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
830 <td>| . $locale->text('ID') . qq|</td>
831 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
832 <td>| . $locale->text('Invoice') . qq|</td>
833 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
834 <td>| . $locale->text('Date') . qq|</td>
837 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
840 if ($form->{db} eq 'ar') {
841 print $locale->text('Customer');
843 if ($form->{db} eq 'ap') {
844 print $locale->text('Vendor');
848 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
849 <td>| . $locale->text('Amount') . qq|</td>
850 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
851 <td>| . $locale->text('Total') . qq|</td>
854 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
855 <td>| . $locale->text('Subtotal') . qq|</td>
864 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
865 if ($form->{report} eq 'ar_aging') {
866 $label = $locale->text('Customer');
867 $form->{vc} = 'customer';
869 $label = $locale->text('Vendor');
870 $form->{vc} = 'vendor';
873 $nextsub = "generate_$form->{report}";
876 $form->all_vc(\%myconfig, $form->{vc},
877 ($form->{vc} eq 'customer') ? "AR" : "AP");
879 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
880 @{ $form->{"all_$form->{vc}"} };
884 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
885 : qq|<input name=$form->{vc} size=35>|;
889 <th align=right>| . $locale->text($label) . qq|</th>
893 <th align=right>| . $locale->text('Bis') . qq|</th>
899 <input type=hidden name=type value=statement>
900 <input type=hidden name=format value=html>
901 <input type=hidden name=media value=screen>
903 <input type=hidden name=nextsub value=$nextsub>
904 <input type=hidden name=action value=$nextsub>
910 # above action can be removed if there is more than one input field
912 if ($form->{report} =~ /(receipts|payments)$/) {
913 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
915 RP->paymentaccounts(\%myconfig, \%$form);
917 $selection = "<option>\n";
918 foreach $ref (@{ $form->{PR} }) {
919 $paymentaccounts .= "$ref->{accno} ";
920 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
923 chop $paymentaccounts;
926 <input type=hidden name=nextsub value=list_payments>
928 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
929 <td colspan=3><select name=account>$selection</select>
930 <input type=hidden name=paymentaccounts value="$paymentaccounts">
934 <th align=right>| . $locale->text('Reference') . qq|</th>
935 <td colspan=3><input name=reference></td>
938 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
939 <td colspan=3><input name=source></td>
942 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
943 <td colspan=3><input name=memo size=30></td>
946 <th align=right>| . $locale->text('From') . qq|</th>
951 <th align=right>| . $locale->text('Bis') . qq|</th>
958 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
959 <th align=left colspan=3>|
960 . $locale->text('Include Exchangerate Difference') . qq|</td>
965 <input type=hidden name=db value=$form->{db}>
966 <input type=hidden name=sort value=transdate>
977 <td><hr size=3 noshade></td>
982 <input type=submit class=submit name=action value="|
983 . $locale->text('Continue') . qq|">
991 $lxdebug->leave_sub();
994 sub continue { call_sub($form->{"nextsub"}); }
997 $lxdebug->enter_sub();
999 $auth->assert('report');
1001 my $nextsub = shift;
1003 $form->{project_id} = $form->{project_id_1};
1004 if ($form->{projectnumber} && !$form->{project_id}) {
1005 $form->{rowcount} = 1;
1007 # call this instead of update
1008 $form->{update} = $nextsub;
1009 $form->{projectnumber_1} = $form->{projectnumber};
1011 delete $form->{sort};
1014 # if there is one only, assign id
1015 $form->{project_id} = $form->{project_id_1};
1018 $lxdebug->leave_sub();
1021 sub generate_income_statement {
1022 $lxdebug->enter_sub();
1024 $auth->assert('report');
1026 $form->{padding} = " ";
1027 $form->{bold} = "<b>";
1028 $form->{endbold} = "</b>";
1029 $form->{br} = "<br>";
1031 if ($form->{reporttype} eq "custom") {
1033 #forgotten the year --> thisyear
1034 if ($form->{year} !~ m/^\d\d\d\d$/) {
1035 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1041 if ($form->{duetyp} eq "13") {
1042 $form->{fromdate} = "1.1.$form->{year}";
1043 $form->{todate} = "31.12.$form->{year}";
1047 if ($form->{duetyp} eq "A") {
1048 $form->{fromdate} = "1.1.$form->{year}";
1049 $form->{todate} = "31.3.$form->{year}";
1051 if ($form->{duetyp} eq "B") {
1052 $form->{fromdate} = "1.4.$form->{year}";
1053 $form->{todate} = "30.6.$form->{year}";
1055 if ($form->{duetyp} eq "C") {
1056 $form->{fromdate} = "1.7.$form->{year}";
1057 $form->{todate} = "30.9.$form->{year}";
1059 if ($form->{duetyp} eq "D") {
1060 $form->{fromdate} = "1.10.$form->{year}";
1061 $form->{todate} = "31.12.$form->{year}";
1066 $form->{duetyp} eq "1" && do {
1067 $form->{fromdate} = "1.1.$form->{year}";
1068 $form->{todate} = "31.1.$form->{year}";
1071 $form->{duetyp} eq "2" && do {
1072 $form->{fromdate} = "1.2.$form->{year}";
1074 #this works from 1901 to 2099, 1900 and 2100 fail.
1075 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1076 $form->{todate} = "$leap.2.$form->{year}";
1079 $form->{duetyp} eq "3" && do {
1080 $form->{fromdate} = "1.3.$form->{year}";
1081 $form->{todate} = "31.3.$form->{year}";
1084 $form->{duetyp} eq "4" && do {
1085 $form->{fromdate} = "1.4.$form->{year}";
1086 $form->{todate} = "30.4.$form->{year}";
1089 $form->{duetyp} eq "5" && do {
1090 $form->{fromdate} = "1.5.$form->{year}";
1091 $form->{todate} = "31.5.$form->{year}";
1094 $form->{duetyp} eq "6" && do {
1095 $form->{fromdate} = "1.6.$form->{year}";
1096 $form->{todate} = "30.6.$form->{year}";
1099 $form->{duetyp} eq "7" && do {
1100 $form->{fromdate} = "1.7.$form->{year}";
1101 $form->{todate} = "31.7.$form->{year}";
1104 $form->{duetyp} eq "8" && do {
1105 $form->{fromdate} = "1.8.$form->{year}";
1106 $form->{todate} = "31.8.$form->{year}";
1109 $form->{duetyp} eq "9" && do {
1110 $form->{fromdate} = "1.9.$form->{year}";
1111 $form->{todate} = "30.9.$form->{year}";
1114 $form->{duetyp} eq "10" && do {
1115 $form->{fromdate} = "1.10.$form->{year}";
1116 $form->{todate} = "31.10.$form->{year}";
1119 $form->{duetyp} eq "11" && do {
1120 $form->{fromdate} = "1.11.$form->{year}";
1121 $form->{todate} = "30.11.$form->{year}";
1124 $form->{duetyp} eq "12" && do {
1125 $form->{fromdate} = "1.12.$form->{year}";
1126 $form->{todate} = "31.12.$form->{year}";
1132 RP->income_statement(\%myconfig, \%$form);
1134 ($form->{department}) = split /--/, $form->{department};
1137 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1138 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1140 # if there are any dates construct a where
1141 if ($form->{fromdate} || $form->{todate}) {
1143 unless ($form->{todate}) {
1144 $form->{todate} = $form->current_date(\%myconfig);
1147 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1148 $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1150 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1151 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1153 $form->{this_period} = "$shortfromdate\n$shorttodate";
1155 $locale->text('for Period')
1156 . qq|\n$longfromdate |
1157 . $locale->text('Bis')
1161 if ($form->{comparefromdate} || $form->{comparetodate}) {
1162 $longcomparefromdate =
1163 $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1164 $shortcomparefromdate =
1165 $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1167 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1168 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1170 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1172 "\n$longcomparefromdate "
1173 . $locale->text('Bis')
1174 . qq| $longcomparetodate|;
1177 # setup variables for the form
1178 @a = qw(company address businessnumber);
1179 map { $form->{$_} = $myconfig{$_} } @a;
1181 $form->{templates} = $myconfig{templates};
1183 $form->{IN} = "income_statement.html";
1185 $form->parse_template;
1187 $lxdebug->leave_sub();
1190 sub generate_balance_sheet {
1191 $lxdebug->enter_sub();
1193 $auth->assert('report');
1195 $form->{padding} = " ";
1196 $form->{bold} = "<b>";
1197 $form->{endbold} = "</b>";
1198 $form->{br} = "<br>";
1200 RP->balance_sheet(\%myconfig, \%$form);
1202 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1204 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1206 ($form->{department}) = split /--/, $form->{department};
1208 # define Current Earnings account
1209 $padding = ($form->{l_heading}) ? $form->{padding} : "";
1210 push(@{ $form->{equity_account} },
1211 $padding . $locale->text('Current Earnings'));
1213 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1214 $form->{last_period} =
1215 $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1217 $form->{IN} = "balance_sheet.html";
1219 # setup company variables for the form
1220 map { $form->{$_} = $myconfig{$_}; } (qw(company address businessnumber nativecurr));
1222 $form->{templates} = $myconfig{templates};
1224 $form->parse_template;
1226 $lxdebug->leave_sub();
1229 sub generate_projects {
1230 $lxdebug->enter_sub();
1232 $auth->assert('report');
1234 &get_project(generate_projects);
1235 $form->{projectnumber} = $form->{projectnumber_1};
1237 $form->{nextsub} = "generate_projects";
1238 $form->{title} = $locale->text('Project Transactions');
1239 RP->trial_balance(\%myconfig, \%$form);
1241 list_accounts('generate_projects');
1243 $lxdebug->leave_sub();
1249 # included links to display transactions for period entered
1250 # added headers and subtotals
1252 sub generate_trial_balance {
1253 $lxdebug->enter_sub();
1255 $auth->assert('report');
1257 if ($form->{reporttype} eq "custom") {
1259 #forgotten the year --> thisyear
1260 if ($form->{year} !~ m/^\d\d\d\d$/) {
1261 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1267 if ($form->{duetyp} eq "13") {
1268 $form->{fromdate} = "1.1.$form->{year}";
1269 $form->{todate} = "31.12.$form->{year}";
1273 if ($form->{duetyp} eq "A") {
1274 $form->{fromdate} = "1.1.$form->{year}";
1275 $form->{todate} = "31.3.$form->{year}";
1277 if ($form->{duetyp} eq "B") {
1278 $form->{fromdate} = "1.4.$form->{year}";
1279 $form->{todate} = "30.6.$form->{year}";
1281 if ($form->{duetyp} eq "C") {
1282 $form->{fromdate} = "1.7.$form->{year}";
1283 $form->{todate} = "30.9.$form->{year}";
1285 if ($form->{duetyp} eq "D") {
1286 $form->{fromdate} = "1.10.$form->{year}";
1287 $form->{todate} = "31.12.$form->{year}";
1292 $form->{duetyp} eq "1" && do {
1293 $form->{fromdate} = "1.1.$form->{year}";
1294 $form->{todate} = "31.1.$form->{year}";
1297 $form->{duetyp} eq "2" && do {
1298 $form->{fromdate} = "1.2.$form->{year}";
1300 #this works from 1901 to 2099, 1900 and 2100 fail.
1301 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1302 $form->{todate} = "$leap.2.$form->{year}";
1305 $form->{duetyp} eq "3" && do {
1306 $form->{fromdate} = "1.3.$form->{year}";
1307 $form->{todate} = "31.3.$form->{year}";
1310 $form->{duetyp} eq "4" && do {
1311 $form->{fromdate} = "1.4.$form->{year}";
1312 $form->{todate} = "30.4.$form->{year}";
1315 $form->{duetyp} eq "5" && do {
1316 $form->{fromdate} = "1.5.$form->{year}";
1317 $form->{todate} = "31.5.$form->{year}";
1320 $form->{duetyp} eq "6" && do {
1321 $form->{fromdate} = "1.6.$form->{year}";
1322 $form->{todate} = "30.6.$form->{year}";
1325 $form->{duetyp} eq "7" && do {
1326 $form->{fromdate} = "1.7.$form->{year}";
1327 $form->{todate} = "31.7.$form->{year}";
1330 $form->{duetyp} eq "8" && do {
1331 $form->{fromdate} = "1.8.$form->{year}";
1332 $form->{todate} = "31.8.$form->{year}";
1335 $form->{duetyp} eq "9" && do {
1336 $form->{fromdate} = "1.9.$form->{year}";
1337 $form->{todate} = "30.9.$form->{year}";
1340 $form->{duetyp} eq "10" && do {
1341 $form->{fromdate} = "1.10.$form->{year}";
1342 $form->{todate} = "31.10.$form->{year}";
1345 $form->{duetyp} eq "11" && do {
1346 $form->{fromdate} = "1.11.$form->{year}";
1347 $form->{todate} = "30.11.$form->{year}";
1350 $form->{duetyp} eq "12" && do {
1351 $form->{fromdate} = "1.12.$form->{year}";
1352 $form->{todate} = "31.12.$form->{year}";
1359 # get for each account initial balance, debits and credits
1360 RP->trial_balance(\%myconfig, \%$form);
1363 $form->{rowcount} = scalar @{ $form->{TB} };
1366 "accno", "description",
1367 "last_transaction", "soll_eb",
1370 "soll_kumuliert", "haben_kumuliert",
1371 "soll_saldo", "haben_saldo"
1375 my $attachment_basename;
1377 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1379 my @hidden_variables = ();
1380 push @hidden_variables, qw(fromdate todate year cash );
1382 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1385 'accno' => { 'text' => $locale->text('Account Number'), },
1386 'description' => { 'text' => $locale->text('Description'), },
1387 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1388 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1389 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1390 'soll' => { 'text' => $locale->text('Debit'), },
1391 'haben' => { 'text' => $locale->text('Credit'), },
1392 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1393 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1394 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1395 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1400 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1402 map { $column_defs{$_}->{visible} = 1 } @columns;
1404 $report->set_columns(%column_defs);
1405 $report->set_column_order(@columns);
1407 $report->set_export_options('trial_balance', @hidden_variables);
1409 $report->set_sort_indicator($form->{sort}, 1);
1414 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1415 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1417 $report->set_options('output_format' => 'HTML',
1418 'title' => $form->{title},
1419 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1421 $report->set_options_from_form();
1422 # $form->parse_html_template('report_generator/html_report_susa', $variables));
1423 $form->{report_template} = 'report_generator/html_report_susa';
1424 # add sort and escape callback, this one we use for the add sub
1425 $form->{callback} = $href .= "&sort=$form->{sort}";
1427 # escape callback for href
1428 $callback = $form->escape($href);
1430 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1432 my %totals = map { $_ => 0 } @subtotal_columns;
1434 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1436 foreach $accno (@{ $form->{TB} }) {
1438 $accno->{soll} = $accno->{debit};
1439 $accno->{haben} = $accno->{credit};
1440 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1442 map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1444 map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1448 foreach my $column (@columns) {
1450 'data' => $accno->{$column},
1451 'align' => $column_alignment{$column},
1456 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1458 my $row_set = [ $row ];
1461 $report->add_data($row_set);
1466 $report->add_separator();
1468 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1470 $report->generate_with_headers();
1472 $lxdebug->leave_sub();
1476 sub create_subtotal_row {
1477 $lxdebug->enter_sub();
1479 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1481 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1483 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1485 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1487 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1489 $lxdebug->leave_sub();
1494 sub create_list_accounts_subtotal_row {
1495 $lxdebug->enter_sub();
1497 my ($subtotals, $columns, $fields, $class) = @_;
1499 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1501 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1503 $lxdebug->leave_sub();
1509 $lxdebug->enter_sub();
1514 if ($form->{department}) {
1515 my ($department) = split /--/, $form->{department};
1516 push @options, $locale->text('Department') . " : $department";
1518 if ($form->{projectnumber}) {
1519 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1522 # if there are any dates
1523 if ($form->{fromdate} || $form->{todate}) {
1524 my ($fromdate, $todate);
1526 if ($form->{fromdate}) {
1527 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1529 if ($form->{todate}) {
1530 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1533 push @options, "$fromdate - $todate";
1536 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1539 my @columns = qw(accno description begbalance debit credit endbalance);
1541 'accno' => { 'text' => $locale->text('Account'), },
1542 'description' => { 'text' => $locale->text('Description'), },
1543 'debit' => { 'text' => $locale->text('Debit'), },
1544 'credit' => { 'text' => $locale->text('Credit'), },
1545 'begbalance' => { 'text' => $locale->text('Balance'), },
1546 'endbalance' => { 'text' => $locale->text('Balance'), },
1548 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1550 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1552 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1554 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1556 $report->set_options('top_info_text' => join("\n", @options),
1557 'output_format' => 'HTML',
1558 'title' => $form->{title},
1559 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1560 'std_column_visibility' => 1,
1562 $report->set_options_from_form();
1564 $report->set_columns(%column_defs);
1565 $report->set_column_order(@columns);
1567 $report->set_export_options($action, @hidden_variables);
1569 $report->set_sort_indicator('accno', 1);
1571 my @totals_columns = qw(credit debit begbalance endbalance);
1572 my %subtotals = map { $_ => 0 } @totals_columns;
1573 my %totals = map { $_ => 0 } @totals_columns;
1574 my $found_heading = 0;
1575 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1577 # sort the whole thing by account numbers and display
1578 foreach my $idx (0 .. scalar(@tb) - 1) {
1579 my $ref = $tb[$idx];
1580 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1582 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1584 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1586 if ($ref->{charttype} eq 'H') {
1587 next unless ($form->{l_heading});
1589 %subtotals = map { $_ => 0 } @totals_columns;
1591 $row->{description}->{class} = 'listheading';
1592 $row->{description}->{data} = $ref->{description};
1594 $report->add_data($row);
1599 foreach (qw(debit credit)) {
1600 $subtotals{$_} += $ref->{$_};
1601 $totals{$_} += $ref->{$_};
1604 $subtotals{begbalance} += $ref->{balance} * $ml;
1605 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1607 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1608 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1610 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1611 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1613 $report->add_data($row);
1615 if ($form->{l_heading} && $found_heading &&
1616 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1617 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1621 $report->add_separator();
1623 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1625 $report->generate_with_headers();
1627 $lxdebug->leave_sub();
1630 sub generate_ar_aging {
1631 $lxdebug->enter_sub();
1633 $auth->assert('general_ledger');
1636 ($form->{customer}) = split(/--/, $form->{customer});
1638 $form->{ct} = "customer";
1639 $form->{arap} = "ar";
1641 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1643 RP->aging(\%myconfig, \%$form);
1646 $lxdebug->leave_sub();
1649 sub generate_ap_aging {
1650 $lxdebug->enter_sub();
1652 $auth->assert('general_ledger');
1655 ($form->{vendor}) = split(/--/, $form->{vendor});
1657 $form->{ct} = "vendor";
1658 $form->{arap} = "ap";
1660 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1662 RP->aging(\%myconfig, \%$form);
1665 $lxdebug->leave_sub();
1668 sub create_aging_subtotal_row {
1669 $lxdebug->enter_sub();
1671 my ($subtotals, $columns, $periods, $class) = @_;
1673 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1675 foreach (@{ $periods }) {
1676 $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1677 $subtotals->{$_} = 0;
1680 $lxdebug->leave_sub();
1686 $lxdebug->enter_sub();
1688 $auth->assert('general_ledger');
1690 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1692 my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
1695 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1696 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1697 'invnumber' => { 'text' => $locale->text('Invoice'), },
1698 'transdate' => { 'text' => $locale->text('Date'), },
1699 'duedate' => { 'text' => $locale->text('Due'), },
1700 'c0' => { 'text' => $locale->text('Current'), },
1701 'c30' => { 'text' => '30', },
1702 'c60' => { 'text' => '60', },
1703 'c90' => { 'text' => '90', },
1706 my %column_alignment = ('statement' => 'center',
1707 map { $_ => 'right' } qw(c0 c30 c60 c90));
1709 $report->set_options('std_column_visibility' => 1);
1710 $report->set_columns(%column_defs);
1711 $report->set_column_order(@columns);
1713 my @hidden_variables = qw(todate customer vendor arap title ct);
1714 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1718 if ($form->{department}) {
1719 my ($department) = split /--/, $form->{department};
1720 push @options, $locale->text('Department') . " : $department";
1721 $form->{callback} .= "&department=" . E($department);
1724 if (($form->{arap} eq 'ar') && $form->{customer}) {
1725 push @options, $form->{customer};
1728 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1729 push @options, $form->{vendor};
1732 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1734 my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1736 $report->set_options('top_info_text' => join("\n", @options),
1737 'output_format' => 'HTML',
1738 'title' => $form->{title},
1739 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1742 my $previous_ctid = 0;
1744 my @periods = qw(0 30 60 90);
1745 my %subtotals = map { $_ => 0 } @periods;
1746 my %totals = map { $_ => 0 } @periods;
1748 foreach $ref (@{ $form->{AG} }) {
1749 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1750 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1753 foreach my $key (@periods) {
1754 $subtotals{$key} += $ref->{"c${key}"};
1755 $totals{$key} += $ref->{"c${key}"};
1756 $ref->{"c${key}"} = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
1761 foreach my $column (@columns) {
1763 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1764 'align' => $column_alignment{$column},
1765 'valign' => $column eq 'statement' ? 'center' : '',
1769 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1771 if ($previous_ctid != $ref->{ctid}) {
1772 $row->{statement}->{raw_data} =
1773 $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
1774 . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1775 $row->{ct}->{data} = $ref->{name};
1780 $previous_ctid = $ref->{ctid};
1782 $report->add_data($row);
1785 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1787 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1789 if ($form->{arap} eq 'ar') {
1790 $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1791 $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1792 'PRINT_OPTIONS' => print_options(inline => 1), });
1793 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1794 'raw_bottom_info_text' => $raw_bottom_info_text);
1797 $report->set_options_from_form();
1799 $report->generate_with_headers();
1801 $lxdebug->leave_sub();
1805 $lxdebug->enter_sub();
1807 RP->aging(\%myconfig, \%$form);
1809 map { $_->{checked} = "checked" } @{ $form->{AG} };
1813 $lxdebug->leave_sub();
1817 $lxdebug->enter_sub();
1819 $auth->assert('general_ledger');
1821 # get name and email addresses
1822 for $i (1 .. $form->{rowcount}) {
1823 if ($form->{"statement_$i"}) {
1824 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1825 RP->get_customer(\%myconfig, \%$form);
1831 $form->error($locale->text('Nothing selected!')) unless $selected;
1833 if ($myconfig{role} eq 'admin') {
1835 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1836 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1840 $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1842 $form->{media} = "email";
1849 <form method=post action=$form->{script}>
1855 <tr height="5"></tr>
1860 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1861 <td><input name=email size=30 value="$form->{email}"></td>
1862 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1863 <td><input name=cc size=30 value="$form->{cc}"></td>
1866 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1867 <td><input name=subject size=30 value="$form->{subject}"></td>
1877 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1880 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1891 map { delete $form->{$_} }
1892 qw(action email cc bcc subject message type sendmode format header);
1894 # save all other variables
1895 foreach $key (keys %$form) {
1896 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1897 $form->{$key} =~ s/\"/"/g;
1898 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1905 <td><hr size=3 noshade></td>
1909 <input type=hidden name=nextsub value=send_email>
1912 <input name=action class=submit type=submit value="|
1913 . $locale->text('Continue') . qq|">
1920 $lxdebug->leave_sub();
1924 $lxdebug->enter_sub();
1926 $auth->assert('general_ledger');
1928 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1929 unless $form->{subject};
1931 RP->aging(\%myconfig, \%$form);
1933 $form->{"statement_1"} = 1;
1935 $form->{media} = 'email';
1938 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1940 $lxdebug->leave_sub();
1944 $lxdebug->enter_sub();
1946 $auth->assert('general_ledger');
1948 if ($form->{media} eq 'printer') {
1949 $form->error($locale->text('Select postscript or PDF!'))
1950 if ($form->{format} !~ /(postscript|pdf)/);
1953 for $i (1 .. $form->{rowcount}) {
1954 if ($form->{"statement_$i"}) {
1955 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1961 $form->error($locale->text('Nothing selected!')) unless $selected;
1963 if ($form->{media} eq 'printer') {
1964 $form->{"$form->{ct}_id"} = "";
1966 $form->{"statement_1"} = 1;
1969 RP->aging(\%myconfig, \%$form);
1973 $form->redirect($locale->text('Statements sent to printer!'))
1974 if ($form->{media} eq 'printer');
1976 $lxdebug->leave_sub();
1980 $lxdebug->enter_sub();
1982 $auth->assert('general_ledger');
1986 "ä" => "ae", "ö" => "oe", "ü" => "ue",
1987 "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
1992 foreach my $key (keys %replacements) {
1993 my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
1994 $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
1997 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1999 $form->{templates} = "$myconfig{templates}";
2001 my $suffix = "html";
2002 my $attachment_suffix = "html";
2003 if ($form->{format} eq 'postscript') {
2004 $form->{postscript} = 1;
2006 $attachment_suffix = "ps";
2007 } elsif ($form->{format} eq 'pdf') {
2010 $attachment_suffix = "pdf";
2013 $form->{IN} = "$form->{type}.$suffix";
2014 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
2016 # Save $form->{email} because it will be overwritten.
2017 $form->{EMAIL_RECIPIENT} = $form->{email};
2020 while (@{ $form->{AG} }) {
2022 $ref = shift @{ $form->{AG} };
2024 if ($ctid != $ref->{ctid}) {
2026 $ctid = $ref->{ctid};
2029 if ($form->{"statement_$i"}) {
2032 (name, street, zipcode, city, country, contact, email,
2033 "$form->{ct}phone", "$form->{ct}fax");
2034 map { $form->{$_} = $ref->{$_} } @a;
2036 $form->{ $form->{ct} } = $form->{name};
2037 $form->{"$form->{ct}_id"} = $ref->{ctid};
2039 map { $form->{$_} = () } qw(invnumber invdate duedate);
2041 foreach $item (qw(c0 c30 c60 c90)) {
2042 $form->{$item} = ();
2043 $form->{"${item}total"} = 0;
2046 &statement_details($ref);
2050 if (scalar(@{ $form->{AG} }) > 0) {
2052 # one or more left to go
2053 if ($ctid == $form->{AG}->[0]->{ctid}) {
2054 $ref = shift @{ $form->{AG} };
2055 &statement_details($ref);
2058 $ref = scalar(@{ $form->{AG} });
2064 # set initial ref to 0
2071 $form->{"${_}total"} =
2072 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2073 } (c0, c30, c60, c90, "");
2075 $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
2076 map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
2078 $form->parse_template(\%myconfig, $userspath);
2083 # saving the history
2084 if(!exists $form->{addition} && $form->{id} ne "") {
2085 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2086 $form->{addition} = "PRINTED";
2087 $form->{what_done} = $form->{type};
2088 $form->save_history($form->dbconnect(\%myconfig));
2090 # /saving the history
2091 $lxdebug->leave_sub();
2094 sub statement_details {
2095 $lxdebug->enter_sub();
2097 $auth->assert('general_ledger');
2101 push @{ $form->{invnumber} }, $ref->{invnumber};
2102 push @{ $form->{invdate} }, $ref->{transdate};
2103 push @{ $form->{duedate} }, $ref->{duedate};
2105 foreach $item (qw(c0 c30 c60 c90)) {
2106 if ($ref->{exchangerate} * 1) {
2108 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2110 $form->{"${item}total"} += $ref->{$item};
2111 $form->{total} += $ref->{$item};
2112 push @{ $form->{$item} },
2113 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2116 $lxdebug->leave_sub();
2119 sub generate_tax_report {
2120 $lxdebug->enter_sub();
2122 $auth->assert('report');
2124 RP->tax_report(\%myconfig, \%$form);
2126 $descvar = "$form->{accno}_description";
2127 $description = $form->escape($form->{$descvar});
2128 $ratevar = "$form->{accno}_rate";
2130 $department = $form->escape($form->{department});
2134 "$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}";
2136 # construct callback
2137 $description = $form->escape($form->{$descvar}, 1);
2138 $department = $form->escape($form->{department}, 1);
2140 "$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}";
2142 $title = $form->escape($form->{title});
2143 $href .= "&title=$title";
2144 $title = $form->escape($form->{title}, 1);
2145 $callback .= "&title=$title";
2147 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2150 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2152 foreach $item (@columns) {
2153 if ($form->{"l_$item"} eq "Y") {
2154 push @column_index, $item;
2156 # add column to href and callback
2157 $callback .= "&l_$item=Y";
2158 $href .= "&l_$item=Y";
2162 if ($form->{l_subtotal} eq 'Y') {
2163 $callback .= "&l_subtotal=Y";
2164 $href .= "&l_subtotal=Y";
2167 if ($form->{department}) {
2168 ($department) = split /--/, $form->{department};
2169 $option = $locale->text('Department') . " : $department";
2172 # if there are any dates
2173 if ($form->{fromdate} || $form->{todate}) {
2174 if ($form->{fromdate}) {
2175 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2177 if ($form->{todate}) {
2178 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2181 $form->{period} = "$fromdate - $todate";
2184 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2187 if ($form->{db} eq 'ar') {
2188 $name = $locale->text('Customer');
2192 if ($form->{db} eq 'ap') {
2193 $name = $locale->text('Vendor');
2198 $option .= "<br>" if $option;
2199 $option .= "$form->{period}";
2201 $column_header{id} =
2202 qq|<th><a class=listheading href=$href&sort=id>|
2203 . $locale->text('ID')
2205 $column_header{invnumber} =
2206 qq|<th><a class=listheading href=$href&sort=invnumber>|
2207 . $locale->text('Invoice')
2209 $column_header{transdate} =
2210 qq|<th><a class=listheading href=$href&sort=transdate>|
2211 . $locale->text('Date')
2213 $column_header{netamount} =
2214 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2215 $column_header{tax} =
2216 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2217 $column_header{amount} =
2218 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2220 $column_header{name} =
2221 qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2230 <th class=listtop colspan=$colspan>$form->{title}</th>
2232 <tr height="5"></tr>
2239 <tr class=listheading>
2242 map { print "$column_header{$_}\n" } @column_index;
2248 # add sort and escape callback
2249 $callback = $form->escape($callback . "&sort=$form->{sort}");
2251 if (@{ $form->{TR} }) {
2252 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2255 foreach $ref (@{ $form->{TR} }) {
2257 $module = ($ref->{invoice}) ? $invoice : $arap;
2259 if ($form->{l_subtotal} eq 'Y') {
2260 if ($sameitem ne $ref->{ $form->{sort} }) {
2262 $sameitem = $ref->{ $form->{sort} };
2266 $totalnetamount += $ref->{netamount};
2267 $totaltax += $ref->{tax};
2268 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2270 $subtotalnetamount += $ref->{netamount};
2271 $subtotaltax += $ref->{tax};
2274 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2275 } qw(netamount tax amount);
2277 $column_data{id} = qq|<td>$ref->{id}</td>|;
2278 $column_data{invnumber} =
2279 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2280 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2281 $column_data{name} = qq|<td>$ref->{name} </td>|;
2283 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2284 qw(netamount tax amount);
2289 <tr class=listrow$i>
2292 map { print "$column_data{$_}\n" } @column_index;
2300 if ($form->{l_subtotal} eq 'Y') {
2304 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2308 <tr class=listtotal>
2312 $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2314 $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2315 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2317 $column_data{netamount} =
2318 qq|<th class=listtotal align=right>$totalnetamount</th>|;
2319 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2320 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2322 map { print "$column_data{$_}\n" } @column_index;
2330 <td><hr size=3 noshade></td>
2338 $lxdebug->leave_sub();
2342 $lxdebug->enter_sub();
2344 map { $column_data{$_} = "<td> </td>" } @column_index;
2346 $subtotalnetamount =
2347 $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
2348 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
2350 $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2353 $column_data{netamount} =
2354 "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2355 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2356 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2358 $subtotalnetamount = 0;
2362 <tr class=listsubtotal>
2364 map { print "\n$column_data{$_}" } @column_index;
2370 $lxdebug->leave_sub();
2374 $lxdebug->enter_sub();
2376 $auth->assert('cash');
2378 if ($form->{account}) {
2379 ($form->{paymentaccounts}) = split /--/, $form->{account};
2381 if ($form->{department}) {
2382 ($department, $form->{department_id}) = split /--/, $form->{department};
2383 $option = $locale->text('Department') . " : $department";
2386 RP->payments(\%myconfig, \%$form);
2388 my @hidden_variables = qw(account title department reference source memo fromdate todate
2389 fx_transaction db prepayment paymentaccounts sort);
2391 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2392 $form->{callback} = $href;
2394 my @columns = qw(transdate invnumber name paid source memo);
2396 'name' => { 'text' => $locale->text('Description'), },
2397 'invnumber' => { 'text' => $locale->text('Reference'), },
2398 'transdate' => { 'text' => $locale->text('Date'), },
2399 'paid' => { 'text' => $locale->text('Amount'), },
2400 'source' => { 'text' => $locale->text('Source'), },
2401 'memo' => { 'text' => $locale->text('Memo'), },
2403 my %column_alignment = ('paid' => 'right');
2405 map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns;
2408 if ($form->{fromdate}) {
2409 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2411 if ($form->{todate}) {
2412 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2415 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2417 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2419 $report->set_options('top_info_text' => join("\n", @options),
2420 'output_format' => 'HTML',
2421 'title' => $form->{title},
2422 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2423 'std_column_visibility' => 1,
2425 $report->set_options_from_form();
2427 $report->set_columns(%column_defs);
2428 $report->set_column_order(@columns);
2430 $report->set_export_options('list_payments', @hidden_variables);
2432 $report->set_sort_indicator($form->{sort}, 1);
2436 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2437 next unless @{ $form->{ $ref->{id} } };
2439 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2441 my $subtotal_paid = 0;
2443 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2444 my $module = $payment->{module};
2445 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2446 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2448 $subtotal_paid += $payment->{paid};
2449 $total_paid += $payment->{paid};
2451 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2455 foreach my $column (@columns) {
2457 'data' => $payment->{$column},
2458 'align' => $column_alignment{$column},
2462 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2464 $report->add_data($row);
2467 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2469 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2471 'class' => 'listsubtotal',
2474 $report->add_data($row);
2477 $report->add_separator();
2479 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2481 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2483 'class' => 'listtotal',
2486 $report->add_data($row);
2488 $report->generate_with_headers();
2490 $lxdebug->leave_sub();
2494 $lxdebug->enter_sub();
2496 my ($dont_print) = @_;
2498 $form->{sendmode} = "attachment";
2501 $form->{"format"} ? $form->{"format"} :
2502 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2506 $form->{"copies"} ? $form->{"copies"} :
2507 $myconfig{"copies"} ? $myconfig{"copies"} :
2510 $form->{PD}{ $form->{type} } = "selected";
2511 $form->{DF}{ $form->{format} } = "selected";
2512 $form->{OP}{ $form->{media} } = "selected";
2513 $form->{SM}{ $form->{sendmode} } = "selected";
2516 <option value=statement $form->{PD}{statement}>|
2517 . $locale->text('Statement');
2519 if ($form->{media} eq 'email') {
2521 <option value=attachment $form->{SM}{attachment}>|
2522 . $locale->text('Attachment') . qq|
2523 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2526 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2527 if ($myconfig{printer} && $latex_templates) {
2529 <option value=printer $form->{OP}{printer}>|
2530 . $locale->text('Printer');
2534 if ($latex_templates) {
2536 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2537 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2538 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2544 <td><select name=type>$type</select></td>
2545 <td><select name=format>$format</select></td>
2546 <td><select name=media>$media</select></td>
2549 if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2551 <td>| . $locale->text('Copies') . qq|
2552 <input name=copies size=2 value=$form->{copies}></td>
2561 print $output unless $dont_print;
2563 $lxdebug->leave_sub();
2569 $lxdebug->enter_sub();
2571 $auth->assert('report');
2573 $form->{padding} = " ";
2574 $form->{bold} = "<b>";
2575 $form->{endbold} = "</b>";
2576 $form->{br} = "<br>";
2578 if ($form->{reporttype} eq "custom") {
2580 #forgotten the year --> thisyear
2581 if ($form->{year} !~ m/^\d\d\d\d$/) {
2582 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2588 if ($form->{duetyp} eq "13") {
2589 $form->{fromdate} = "1.1.$form->{year}";
2590 $form->{todate} = "31.12.$form->{year}";
2591 $form->{comparefromdate} = "1.01.$form->{year}";
2592 $form->{comparetodate} = "31.12.$form->{year}";
2596 if ($form->{duetyp} eq "A") {
2597 $form->{fromdate} = "1.1.$form->{year}";
2598 $form->{todate} = "31.3.$form->{year}";
2599 $form->{comparefromdate} = "1.01.$form->{year}";
2600 $form->{comparetodate} = "31.03.$form->{year}";
2602 if ($form->{duetyp} eq "B") {
2603 $form->{fromdate} = "1.4.$form->{year}";
2604 $form->{todate} = "30.6.$form->{year}";
2605 $form->{comparefromdate} = "1.01.$form->{year}";
2606 $form->{comparetodate} = "30.06.$form->{year}";
2608 if ($form->{duetyp} eq "C") {
2609 $form->{fromdate} = "1.7.$form->{year}";
2610 $form->{todate} = "30.9.$form->{year}";
2611 $form->{comparefromdate} = "1.01.$form->{year}";
2612 $form->{comparetodate} = "30.09.$form->{year}";
2614 if ($form->{duetyp} eq "D") {
2615 $form->{fromdate} = "1.10.$form->{year}";
2616 $form->{todate} = "31.12.$form->{year}";
2617 $form->{comparefromdate} = "1.01.$form->{year}";
2618 $form->{comparetodate} = "31.12.$form->{year}";
2623 $form->{duetyp} eq "1" && do {
2624 $form->{fromdate} = "1.1.$form->{year}";
2625 $form->{todate} = "31.1.$form->{year}";
2626 $form->{comparefromdate} = "1.01.$form->{year}";
2627 $form->{comparetodate} = "31.01.$form->{year}";
2630 $form->{duetyp} eq "2" && do {
2631 $form->{fromdate} = "1.2.$form->{year}";
2633 #this works from 1901 to 2099, 1900 and 2100 fail.
2634 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2635 $form->{todate} = "$leap.2.$form->{year}";
2636 $form->{comparefromdate} = "1.01.$form->{year}";
2637 $form->{comparetodate} = "$leap.02.$form->{year}";
2640 $form->{duetyp} eq "3" && do {
2641 $form->{fromdate} = "1.3.$form->{year}";
2642 $form->{todate} = "31.3.$form->{year}";
2643 $form->{comparefromdate} = "1.01.$form->{year}";
2644 $form->{comparetodate} = "31.03.$form->{year}";
2647 $form->{duetyp} eq "4" && do {
2648 $form->{fromdate} = "1.4.$form->{year}";
2649 $form->{todate} = "30.4.$form->{year}";
2650 $form->{comparefromdate} = "1.01.$form->{year}";
2651 $form->{comparetodate} = "30.04.$form->{year}";
2654 $form->{duetyp} eq "5" && do {
2655 $form->{fromdate} = "1.5.$form->{year}";
2656 $form->{todate} = "31.5.$form->{year}";
2657 $form->{comparefromdate} = "1.01.$form->{year}";
2658 $form->{comparetodate} = "31.05.$form->{year}";
2661 $form->{duetyp} eq "6" && do {
2662 $form->{fromdate} = "1.6.$form->{year}";
2663 $form->{todate} = "30.6.$form->{year}";
2664 $form->{comparefromdate} = "1.01.$form->{year}";
2665 $form->{comparetodate} = "30.06.$form->{year}";
2668 $form->{duetyp} eq "7" && do {
2669 $form->{fromdate} = "1.7.$form->{year}";
2670 $form->{todate} = "31.7.$form->{year}";
2671 $form->{comparefromdate} = "1.01.$form->{year}";
2672 $form->{comparetodate} = "31.07.$form->{year}";
2675 $form->{duetyp} eq "8" && do {
2676 $form->{fromdate} = "1.8.$form->{year}";
2677 $form->{todate} = "31.8.$form->{year}";
2678 $form->{comparefromdate} = "1.01.$form->{year}";
2679 $form->{comparetodate} = "31.08.$form->{year}";
2682 $form->{duetyp} eq "9" && do {
2683 $form->{fromdate} = "1.9.$form->{year}";
2684 $form->{todate} = "30.9.$form->{year}";
2685 $form->{comparefromdate} = "1.01.$form->{year}";
2686 $form->{comparetodate} = "30.09.$form->{year}";
2689 $form->{duetyp} eq "10" && do {
2690 $form->{fromdate} = "1.10.$form->{year}";
2691 $form->{todate} = "31.10.$form->{year}";
2692 $form->{comparefromdate} = "1.01.$form->{year}";
2693 $form->{comparetodate} = "31.10.$form->{year}";
2696 $form->{duetyp} eq "11" && do {
2697 $form->{fromdate} = "1.11.$form->{year}";
2698 $form->{todate} = "30.11.$form->{year}";
2699 $form->{comparefromdate} = "1.01.$form->{year}";
2700 $form->{comparetodate} = "30.11.$form->{year}";
2703 $form->{duetyp} eq "12" && do {
2704 $form->{fromdate} = "1.12.$form->{year}";
2705 $form->{todate} = "31.12.$form->{year}";
2706 $form->{comparefromdate} = "1.01.$form->{year}";
2707 $form->{comparetodate} = "31.12.$form->{year}";
2712 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2713 $form->{fromdate} = "${dd}.${mm}.${yy}";
2714 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2715 $form->{todate} = "${dd}.${mm}.${yy}";
2716 $form->{comparefromdate} = "01.01.$yy";
2717 $form->{comparetodate} = $form->{todate};
2720 RP->bwa(\%myconfig, \%$form);
2722 ($form->{department}) = split /--/, $form->{department};
2725 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2726 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2728 # if there are any dates construct a where
2729 if ($form->{fromdate} || $form->{todate}) {
2731 unless ($form->{todate}) {
2732 $form->{todate} = $form->current_date(\%myconfig);
2735 my %germandate = ("dateformat" => "dd.mm.yyyy");
2737 $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2738 $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2740 $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2741 $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2743 $form->{this_period} = "$shortfromdate\n$shorttodate";
2745 $locale->text('for Period')
2746 . qq|\n$longfromdate |
2747 . $locale->text('bis')
2751 # setup variables for the form
2752 @a = qw(company address businessnumber);
2753 map { $form->{$_} = $myconfig{$_} } @a;
2754 $form->{templates} = $myconfig{templates};
2756 $form->{IN} = "bwa.html";
2758 $form->parse_template;
2760 $lxdebug->leave_sub();