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')
94 # $form->parse_html_template('rp/html_report_susa')
97 'projects' => 'report',
98 'ar_aging' => 'general_ledger',
99 'ap_aging' => 'general_ledger',
100 'receipts' => 'cash',
101 'payments' => 'cash',
102 'trial_balance' => 'report',
103 'income_statement' => 'report',
105 'balance_sheet' => 'report',
108 sub check_rp_access {
109 my $right = $rp_access_map->{$form->{report}};
110 $right ||= 'DOES_NOT_EXIST';
112 $auth->assert($right);
116 $lxdebug->enter_sub();
120 %title = ('balance_sheet' => 'Balance Sheet',
121 'income_statement' => 'Income Statement',
122 'trial_balance' => 'Trial Balance',
123 'ar_aging' => 'AR Aging',
124 'ap_aging' => 'Offene Verbindlichkeiten',
125 'tax_collected' => 'Tax collected',
126 'tax_paid' => 'Tax paid',
127 'nontaxable_sales' => 'Non-taxable Sales',
128 'nontaxable_purchases' => 'Non-taxable Purchases',
129 'receipts' => 'Receipts',
130 'payments' => 'Payments',
131 'projects' => 'Project Transactions',
132 'bwa' => 'Betriebswirtschaftliche Auswertung',);
134 $form->{title} = $locale->text($title{ $form->{report} });
136 $accrual = ($eur) ? "" : "checked";
137 $cash = ($eur) ? "checked" : "";
139 $year = (localtime)[5] + 1900;
142 $form->all_departments(\%myconfig);
143 if (@{ $form->{all_departments} }) {
144 $form->{selectdepartment} = "<option>\n";
147 $form->{selectdepartment} .=
148 "<option>$_->{description}--$_->{id}\n"
149 } (@{ $form->{all_departments} });
154 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
155 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
157 | if $form->{selectdepartment};
159 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
162 my %project_labels = ();
163 my @project_values = ("");
164 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
165 push(@project_values, $item->{"id"});
166 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
170 NTI($cgi->popup_menu('-name' => "project_id",
171 '-values' => \@project_values,
172 '-labels' => \%project_labels));
174 # use JavaScript Calendar or not
175 $form->{jsscript} = 1;
177 if ($form->{report} eq "balance_sheet") {
178 $name_1 = "asofdate";
180 $value_1 = "$form->{asofdate}";
181 $trigger_1 = "trigger1";
182 $name_2 = "compareasofdate";
183 $id_2 = "compareasofdate";
184 $value_2 = "$form->{compareasofdate}";
185 $trigger_2 = "trigger2";
186 } elsif ($form->{report} =~ /(receipts|payments)$/) {
187 $name_1 = "fromdate";
189 $value_1 = "$form->{fromdate}";
190 $trigger_1 = "trigger1";
194 $trigger_2 = "trigger2";
195 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
203 $trigger_2 = "trigger2";
206 $name_1 = "fromdate";
208 $value_1 = "$form->{fromdate}";
209 $trigger_1 = "trigger1";
213 $trigger_2 = "trigger2";
216 # with JavaScript Calendar
217 if ($form->{jsscript}) {
221 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
223 <input type=button name=$name_2 id="$trigger_2" value=|
224 . $locale->text('button') . qq|>|;
228 Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
231 <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
233 <input type=button name=$name_1 id="$trigger_1" value=|
234 . $locale->text('button') . qq|>|;
236 <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
238 <input type=button name=$name_2 id="$trigger_2" value=|
239 . $locale->text('button') . qq|>
244 Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
245 "$name_2", "BL", "$trigger_2");
249 # without JavaScript Calendar
252 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
255 qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
257 qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
260 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
262 $onload = qq|focus()|;
263 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
264 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
266 <body onLoad="$onload">
268 <form method=post action=$form->{script}>
270 <input type=hidden name=title value="$form->{title}">
274 <th class=listtop>$form->{title}</th>
283 if ($form->{report} eq "projects") {
286 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
287 <td colspan=5><input name=projectnumber size=25</td>
289 <input type=hidden name=nextsub value=generate_projects>
291 <th align=right>| . $locale->text('From') . qq|</th>
294 <th align=right>| . $locale->text('Bis') . qq|</th>
305 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
306 <td><input name=l_heading class=checkbox type=checkbox value=Y> |
307 . $locale->text('Heading') . qq|
308 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
309 . $locale->text('Subtotal') . qq|</td>
316 if ($form->{report} eq "income_statement") {
319 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
320 <td colspan=3>$projectnumber</td>
322 <input type=hidden name=nextsub value=generate_income_statement>
326 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
327 . $locale->text('Customized Report') . qq|</th>
330 <th colspan=1>| . $locale->text('Year') . qq|</th>
331 <td><input name=year size=11 title="|
332 . $locale->text('YYYY') . qq|" value="$year"></td>
339 <b> | . $locale->text('Yearly') . qq|</b> </td>
340 <th align=left>| . $locale->text('Quarterly') . qq|</th>
341 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
344 <td align=right> <input name=duetyp class=radio type=radio value="13"
346 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
347 . $locale->text('Quarter') . qq|</td>
351 <td><input name=duetyp class=radio type=radio value="1" $checked > |
352 . $locale->text('January') . qq|</td>
356 <td><input name=duetyp class=radio type=radio value="5" $checked > |
357 . $locale->text('May') . qq|</td>
358 <td><input name=duetyp class=radio type=radio value="9" $checked > |
359 . $locale->text('September') . qq|</td>
363 <td align= right> </td>
364 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
365 . $locale->text('Quarter') . qq|</td>
366 <td><input name=duetyp class=radio type=radio value="2" $checked > |
367 . $locale->text('February') . qq|</td>
368 <td><input name=duetyp class=radio type=radio value="6" $checked > |
369 . $locale->text('June') . qq|</td>
370 <td><input name=duetyp class=radio type=radio value="10" $checked > |
371 . $locale->text('October') . qq|</td>
375 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
376 . $locale->text('Quarter') . qq|</td>
377 <td><input name=duetyp class=radio type=radio value="3" $checked > |
378 . $locale->text('March') . qq|</td>
379 <td><input name=duetyp class=radio type=radio value="7" $checked > |
380 . $locale->text('July') . qq|</td>
381 <td><input name=duetyp class=radio type=radio value="11" $checked > |
382 . $locale->text('November') . qq|</td>
387 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
388 . $locale->text('Quarter') . qq| </td>
389 <td><input name=duetyp class=radio type=radio value="4" $checked > |
390 . $locale->text('April') . qq|</td>
391 <td><input name=duetyp class=radio type=radio value="8" $checked > |
392 . $locale->text('August') . qq|</td>
393 <td><input name=duetyp class=radio type=radio value="12" $checked > |
394 . $locale->text('December') . qq|</td>
398 <td colspan=5><hr size=3 noshade></td>
401 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
402 . $locale->text('Free report period') . qq|</th>
403 <td align=left colspan=4>| . $locale->text('From') . qq|
406 | . $locale->text('Bis') . qq|
412 <td colspan=5><hr size=3 noshade></td>
415 <th align=leftt>| . $locale->text('Method') . qq|</th>
416 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
417 . $locale->text('Accrual') . qq|
418 <input name=method class=radio type=radio value=cash $cash>|
419 . $locale->text('EUR') . qq|</td>
426 if ($form->{report} eq "bwa") {
429 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
430 <td colspan=3>$projectnumber</td>
432 <input type=hidden name=nextsub value=generate_bwa>
436 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
437 . $locale->text('Customized Report') . qq|</th>
440 <th colspan=1>| . $locale->text('Year') . qq|</th>
441 <td><input name=year size=11 title="|
442 . $locale->text('YYYY') . qq|" value="$year"></td>
449 <b> | . $locale->text('Yearly') . qq|</b> </td>
450 <th align=left>| . $locale->text('Quarterly') . qq|</th>
451 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
454 <td align=right> <input name=duetyp class=radio type=radio value="13"
456 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
457 . $locale->text('Quarter') . qq|</td>
459 $checked = "checked";
461 <td><input name=duetyp class=radio type=radio value="1" $checked > |
462 . $locale->text('January') . qq|</td>
466 <td><input name=duetyp class=radio type=radio value="5" $checked > |
467 . $locale->text('May') . qq|</td>
468 <td><input name=duetyp class=radio type=radio value="9" $checked > |
469 . $locale->text('September') . qq|</td>
473 <td align= right> </td>
474 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
475 . $locale->text('Quarter') . qq|</td>
476 <td><input name=duetyp class=radio type=radio value="2" $checked > |
477 . $locale->text('February') . qq|</td>
478 <td><input name=duetyp class=radio type=radio value="6" $checked > |
479 . $locale->text('June') . qq|</td>
480 <td><input name=duetyp class=radio type=radio value="10" $checked > |
481 . $locale->text('October') . qq|</td>
485 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
486 . $locale->text('Quarter') . qq|</td>
487 <td><input name=duetyp class=radio type=radio value="3" $checked > |
488 . $locale->text('March') . qq|</td>
489 <td><input name=duetyp class=radio type=radio value="7" $checked > |
490 . $locale->text('July') . qq|</td>
491 <td><input name=duetyp class=radio type=radio value="11" $checked > |
492 . $locale->text('November') . qq|</td>
497 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
498 . $locale->text('Quarter') . qq| </td>
499 <td><input name=duetyp class=radio type=radio value="4" $checked > |
500 . $locale->text('April') . qq|</td>
501 <td><input name=duetyp class=radio type=radio value="8" $checked > |
502 . $locale->text('August') . qq|</td>
503 <td><input name=duetyp class=radio type=radio value="12" $checked > |
504 . $locale->text('December') . qq|</td>
508 <td colspan=5><hr size=3 noshade></td>
511 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
512 . $locale->text('Free report period') . qq|</th>
513 <td align=left colspan=4>| . $locale->text('From') . qq|
516 | . $locale->text('Bis') . qq|
522 <td colspan=5><hr size=3 noshade></td>
525 <th align=leftt>| . $locale->text('Method') . qq|</th>
526 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
527 . $locale->text('Accrual') . qq|
528 <input name=method class=radio type=radio value=cash $cash>|
529 . $locale->text('EUR') . qq|</td>
532 <th align=right colspan=4>|
533 . $locale->text('Decimalplaces')
535 <td><input name=decimalplaces size=3 value="2"></td>
542 if ($form->{report} eq "balance_sheet") {
544 <input type=hidden name=nextsub value=generate_balance_sheet>
546 <th align=right>| . $locale->text('as at') . qq|</th>
551 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
558 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
559 <td><input name=decimalplaces size=3 value="2"></td>
568 <th align=right>| . $locale->text('Method') . qq|</th>
569 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
570 . $locale->text('Accrual') . qq|
571 <input name=method class=radio type=radio value=cash $cash>|
572 . $locale->text('EUR') . qq|</td>
576 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
577 <td><input name=l_heading class=checkbox type=checkbox value=Y> |
578 . $locale->text('Heading') . qq|
579 <input name=l_subtotal class=checkbox type=checkbox value=Y> |
580 . $locale->text('Subtotal') . qq|
581 <input name=l_accno class=checkbox type=checkbox value=Y> |
582 . $locale->text('Account Number') . qq|</td>
589 if ($form->{report} eq "trial_balance") {
592 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
593 <td colspan=3>$projectnumber</td>
595 <input type=hidden name=nextsub value=generate_trial_balance>
599 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
600 . $locale->text('Customized Report') . qq|</th>
603 <th colspan=1>| . $locale->text('Year') . qq|</th>
604 <td><input name=year size=11 title="|
605 . $locale->text('YYYY') . qq|" value="$year"></td>
612 <b> | . $locale->text('Yearly') . qq|</b> </td>
613 <th align=left>| . $locale->text('Quarterly') . qq|</th>
614 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
617 <td align=right> <input name=duetyp class=radio type=radio value="13"
619 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
620 . $locale->text('Quarter') . qq|</td>
622 $checked = "checked";
624 <td><input name=duetyp class=radio type=radio value="1" $checked > |
625 . $locale->text('January') . qq|</td>
629 <td><input name=duetyp class=radio type=radio value="5" $checked > |
630 . $locale->text('May') . qq|</td>
631 <td><input name=duetyp class=radio type=radio value="9" $checked > |
632 . $locale->text('September') . qq|</td>
636 <td align= right> </td>
637 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
638 . $locale->text('Quarter') . qq|</td>
639 <td><input name=duetyp class=radio type=radio value="2" $checked > |
640 . $locale->text('February') . qq|</td>
641 <td><input name=duetyp class=radio type=radio value="6" $checked > |
642 . $locale->text('June') . qq|</td>
643 <td><input name=duetyp class=radio type=radio value="10" $checked > |
644 . $locale->text('October') . qq|</td>
648 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
649 . $locale->text('Quarter') . qq|</td>
650 <td><input name=duetyp class=radio type=radio value="3" $checked > |
651 . $locale->text('March') . qq|</td>
652 <td><input name=duetyp class=radio type=radio value="7" $checked > |
653 . $locale->text('July') . qq|</td>
654 <td><input name=duetyp class=radio type=radio value="11" $checked > |
655 . $locale->text('November') . qq|</td>
660 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
661 . $locale->text('Quarter') . qq| </td>
662 <td><input name=duetyp class=radio type=radio value="4" $checked > |
663 . $locale->text('April') . qq|</td>
664 <td><input name=duetyp class=radio type=radio value="8" $checked > |
665 . $locale->text('August') . qq|</td>
666 <td><input name=duetyp class=radio type=radio value="12" $checked > |
667 . $locale->text('December') . qq|</td>
671 <td colspan=5><hr size=3 noshade></td>
674 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
675 . $locale->text('Free report period') . qq|</th>
676 <td align=left colspan=4>| . $locale->text('From') . qq|
679 | . $locale->text('Bis') . qq|
685 <td colspan=5><hr size=3 noshade></td>
688 <th align=leftt>| . $locale->text('Method') . qq|</th>
689 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
690 . $locale->text('Accrual') . qq|
691 <input name=method class=radio type=radio value=cash $cash>|
692 . $locale->text('EUR') . qq|</td>
695 <th align=right colspan=4>|
696 . $locale->text('All Accounts')
698 <td><input name=all_accounts type=checkbox value=1></td>
701 <th align=right colspan=4>|
702 . $locale->text('Decimalplaces')
704 <td><input name=decimalplaces size=3 value="2"></td>
711 if ($form->{report} =~ /^tax_/) {
712 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
714 RP->get_taxaccounts(\%myconfig, \%$form);
717 <input type=hidden name=nextsub value=generate_tax_report>
719 <th align=right>| . $locale->text('From') . qq|</th>
720 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
721 <th align=right>| . $locale->text('Bis') . qq|</th>
722 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
725 <th align=right>| . $locale->text('Report for') . qq|</th>
729 $checked = "checked";
730 foreach $ref (@{ $form->{taxaccounts} }) {
733 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
735 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
736 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
743 <input type=hidden name=db value=$form->{db}>
744 <input type=hidden name=sort value=transdate>
749 <th align=right>| . $locale->text('Method') . qq|</th>
750 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
751 . $locale->text('Accrual') . qq|
752 <input name=method class=radio type=radio value=cash $cash>|
753 . $locale->text('EUR') . qq|</td>
762 <th align=right>| . $locale->text('Include in Report') . qq|</th>
766 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
767 <td>| . $locale->text('ID') . qq|</td>
768 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
769 <td>| . $locale->text('Invoice') . qq|</td>
770 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
771 <td>| . $locale->text('Date') . qq|</td>
774 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
777 if ($form->{db} eq 'ar') {
778 print $locale->text('Customer');
780 if ($form->{db} eq 'ap') {
781 print $locale->text('Vendor');
785 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
786 <td>| . $locale->text('Amount') . qq|</td>
787 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
788 <td>| . $locale->text('Tax') . qq|</td>
789 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
790 <td>| . $locale->text('Total') . qq|</td>
793 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
794 <td>| . $locale->text('Subtotal') . qq|</td>
803 if ($form->{report} =~ /^nontaxable_/) {
804 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
807 <input type=hidden name=nextsub value=generate_tax_report>
809 <input type=hidden name=db value=$form->{db}>
810 <input type=hidden name=sort value=transdate>
811 <input type=hidden name=report value=$form->{report}>
814 <th align=right>| . $locale->text('From') . qq|</th>
815 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
816 <th align=right>| . $locale->text('Bis') . qq|</th>
817 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
820 <th align=right>| . $locale->text('Method') . qq|</th>
821 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
822 . $locale->text('Accrual') . qq|
823 <input name=method class=radio type=radio value=cash $cash>|
824 . $locale->text('EUR') . qq|</td>
827 <th align=right>| . $locale->text('Include in Report') . qq|</th>
831 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
832 <td>| . $locale->text('ID') . qq|</td>
833 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
834 <td>| . $locale->text('Invoice') . qq|</td>
835 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
836 <td>| . $locale->text('Date') . qq|</td>
839 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
842 if ($form->{db} eq 'ar') {
843 print $locale->text('Customer');
845 if ($form->{db} eq 'ap') {
846 print $locale->text('Vendor');
850 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
851 <td>| . $locale->text('Amount') . qq|</td>
852 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
853 <td>| . $locale->text('Total') . qq|</td>
856 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
857 <td>| . $locale->text('Subtotal') . qq|</td>
866 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
867 if ($form->{report} eq 'ar_aging') {
868 $label = $locale->text('Customer');
869 $form->{vc} = 'customer';
871 $label = $locale->text('Vendor');
872 $form->{vc} = 'vendor';
875 $nextsub = "generate_$form->{report}";
878 $form->all_vc(\%myconfig, $form->{vc},
879 ($form->{vc} eq 'customer') ? "AR" : "AP");
881 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
882 @{ $form->{"all_$form->{vc}"} };
886 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
887 : qq|<input name=$form->{vc} size=35>|;
891 <th align=right>| . $locale->text($label) . qq|</th>
895 <th align=right>| . $locale->text('Bis') . qq|</th>
901 <input type=hidden name=type value=statement>
902 <input type=hidden name=format value=html>
903 <input type=hidden name=media value=screen>
905 <input type=hidden name=nextsub value=$nextsub>
906 <input type=hidden name=action value=$nextsub>
912 # above action can be removed if there is more than one input field
914 if ($form->{report} =~ /(receipts|payments)$/) {
915 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
917 RP->paymentaccounts(\%myconfig, \%$form);
919 $selection = "<option>\n";
920 foreach $ref (@{ $form->{PR} }) {
921 $paymentaccounts .= "$ref->{accno} ";
922 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
925 chop $paymentaccounts;
928 <input type=hidden name=nextsub value=list_payments>
930 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
931 <td colspan=3><select name=account>$selection</select>
932 <input type=hidden name=paymentaccounts value="$paymentaccounts">
936 <th align=right>| . $locale->text('Reference') . qq|</th>
937 <td colspan=3><input name=reference></td>
940 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
941 <td colspan=3><input name=source></td>
944 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
945 <td colspan=3><input name=memo size=30></td>
948 <th align=right>| . $locale->text('From') . qq|</th>
953 <th align=right>| . $locale->text('Bis') . qq|</th>
960 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
961 <th align=left colspan=3>|
962 . $locale->text('Include Exchangerate Difference') . qq|</td>
967 <input type=hidden name=db value=$form->{db}>
968 <input type=hidden name=sort value=transdate>
979 <td><hr size=3 noshade></td>
984 <input type=submit class=submit name=action value="|
985 . $locale->text('Continue') . qq|">
993 $lxdebug->leave_sub();
996 sub continue { call_sub($form->{"nextsub"}); }
999 $lxdebug->enter_sub();
1001 $auth->assert('report');
1003 my $nextsub = shift;
1005 $form->{project_id} = $form->{project_id_1};
1006 if ($form->{projectnumber} && !$form->{project_id}) {
1007 $form->{rowcount} = 1;
1009 # call this instead of update
1010 $form->{update} = $nextsub;
1011 $form->{projectnumber_1} = $form->{projectnumber};
1013 delete $form->{sort};
1016 # if there is one only, assign id
1017 $form->{project_id} = $form->{project_id_1};
1020 $lxdebug->leave_sub();
1023 sub generate_income_statement {
1024 $lxdebug->enter_sub();
1026 $auth->assert('report');
1028 $form->{padding} = " ";
1029 $form->{bold} = "<b>";
1030 $form->{endbold} = "</b>";
1031 $form->{br} = "<br>";
1033 if ($form->{reporttype} eq "custom") {
1035 #forgotten the year --> thisyear
1036 if ($form->{year} !~ m/^\d\d\d\d$/) {
1037 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1043 if ($form->{duetyp} eq "13") {
1044 $form->{fromdate} = "1.1.$form->{year}";
1045 $form->{todate} = "31.12.$form->{year}";
1049 if ($form->{duetyp} eq "A") {
1050 $form->{fromdate} = "1.1.$form->{year}";
1051 $form->{todate} = "31.3.$form->{year}";
1053 if ($form->{duetyp} eq "B") {
1054 $form->{fromdate} = "1.4.$form->{year}";
1055 $form->{todate} = "30.6.$form->{year}";
1057 if ($form->{duetyp} eq "C") {
1058 $form->{fromdate} = "1.7.$form->{year}";
1059 $form->{todate} = "30.9.$form->{year}";
1061 if ($form->{duetyp} eq "D") {
1062 $form->{fromdate} = "1.10.$form->{year}";
1063 $form->{todate} = "31.12.$form->{year}";
1068 $form->{duetyp} eq "1" && do {
1069 $form->{fromdate} = "1.1.$form->{year}";
1070 $form->{todate} = "31.1.$form->{year}";
1073 $form->{duetyp} eq "2" && do {
1074 $form->{fromdate} = "1.2.$form->{year}";
1076 #this works from 1901 to 2099, 1900 and 2100 fail.
1077 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1078 $form->{todate} = "$leap.2.$form->{year}";
1081 $form->{duetyp} eq "3" && do {
1082 $form->{fromdate} = "1.3.$form->{year}";
1083 $form->{todate} = "31.3.$form->{year}";
1086 $form->{duetyp} eq "4" && do {
1087 $form->{fromdate} = "1.4.$form->{year}";
1088 $form->{todate} = "30.4.$form->{year}";
1091 $form->{duetyp} eq "5" && do {
1092 $form->{fromdate} = "1.5.$form->{year}";
1093 $form->{todate} = "31.5.$form->{year}";
1096 $form->{duetyp} eq "6" && do {
1097 $form->{fromdate} = "1.6.$form->{year}";
1098 $form->{todate} = "30.6.$form->{year}";
1101 $form->{duetyp} eq "7" && do {
1102 $form->{fromdate} = "1.7.$form->{year}";
1103 $form->{todate} = "31.7.$form->{year}";
1106 $form->{duetyp} eq "8" && do {
1107 $form->{fromdate} = "1.8.$form->{year}";
1108 $form->{todate} = "31.8.$form->{year}";
1111 $form->{duetyp} eq "9" && do {
1112 $form->{fromdate} = "1.9.$form->{year}";
1113 $form->{todate} = "30.9.$form->{year}";
1116 $form->{duetyp} eq "10" && do {
1117 $form->{fromdate} = "1.10.$form->{year}";
1118 $form->{todate} = "31.10.$form->{year}";
1121 $form->{duetyp} eq "11" && do {
1122 $form->{fromdate} = "1.11.$form->{year}";
1123 $form->{todate} = "30.11.$form->{year}";
1126 $form->{duetyp} eq "12" && do {
1127 $form->{fromdate} = "1.12.$form->{year}";
1128 $form->{todate} = "31.12.$form->{year}";
1134 RP->income_statement(\%myconfig, \%$form);
1136 ($form->{department}) = split /--/, $form->{department};
1139 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1140 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1142 # if there are any dates construct a where
1143 if ($form->{fromdate} || $form->{todate}) {
1145 unless ($form->{todate}) {
1146 $form->{todate} = $form->current_date(\%myconfig);
1149 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1150 $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1152 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1153 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1155 $form->{this_period} = "$shortfromdate\n$shorttodate";
1157 $locale->text('for Period')
1158 . qq|\n$longfromdate |
1159 . $locale->text('Bis')
1163 if ($form->{comparefromdate} || $form->{comparetodate}) {
1164 $longcomparefromdate =
1165 $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1166 $shortcomparefromdate =
1167 $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1169 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1170 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1172 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1174 "\n$longcomparefromdate "
1175 . $locale->text('Bis')
1176 . qq| $longcomparetodate|;
1179 # setup variables for the form
1180 @a = qw(company address businessnumber);
1181 map { $form->{$_} = $myconfig{$_} } @a;
1183 $form->{templates} = $myconfig{templates};
1185 $form->{IN} = "income_statement.html";
1187 $form->parse_template;
1189 $lxdebug->leave_sub();
1192 sub generate_balance_sheet {
1193 $lxdebug->enter_sub();
1195 $auth->assert('report');
1197 RP->balance_sheet(\%myconfig, \%$form);
1199 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1201 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1203 ($form->{department}) = split /--/, $form->{department};
1205 # define Current Earnings account
1206 $padding = ($form->{l_heading}) ? $form->{padding} : "";
1207 push(@{ $form->{equity_account} },
1208 $padding . $locale->text('Current Earnings'));
1210 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1211 $form->{last_period} =
1212 $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1214 my $attachment_basename;
1216 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1218 my @hidden_variables = ();
1219 push @hidden_variables, qw(fromdate todate year cash );
1221 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1224 'accno' => { 'text' => $locale->text('Account Number'), },
1225 'description' => { 'text' => $locale->text('Description'), },
1226 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1227 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1228 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1229 'soll' => { 'text' => $locale->text('Debit'), },
1230 'haben' => { 'text' => $locale->text('Credit'), },
1231 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1232 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1233 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1234 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1239 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1241 map { $column_defs{$_}->{visible} = 1 } @columns;
1243 $report->set_columns(%column_defs);
1244 $report->set_column_order(@columns);
1246 $report->set_export_options('trial_balance', @hidden_variables);
1248 $report->set_sort_indicator($form->{sort}, 1);
1253 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1254 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1256 $report->set_options('output_format' => 'HTML',
1257 'title' => $form->{title},
1258 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1260 $report->set_options_from_form();
1261 # $form->parse_html_template('report_generator/html_report_bilanz', $variables));
1262 $form->{report_template} = 'report_generator/html_report_bilanz';
1263 # add sort and escape callback, this one we use for the add sub
1264 $form->{callback} = $href .= "&sort=$form->{sort}";
1266 # escape callback for href
1267 $callback = $form->escape($href);
1269 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1271 my %totals = map { $_ => 0 } @subtotal_columns;
1273 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1275 # foreach $accno (@{ $form->{TB} }) {
1277 # $accno->{soll} = $accno->{debit};
1278 # $accno->{haben} = $accno->{credit};
1279 # map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1281 # map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1283 # map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1287 # foreach my $column (@columns) {
1288 # $row->{$column} = {
1289 # 'data' => $accno->{$column},
1290 # 'align' => $column_alignment{$column},
1295 # $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1297 # my $row_set = [ $row ];
1300 # $report->add_data($row_set);
1305 # $report->add_separator();
1307 # $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1309 $report->generate_with_headers();
1312 $lxdebug->leave_sub();
1315 sub generate_projects {
1316 $lxdebug->enter_sub();
1318 $auth->assert('report');
1320 &get_project(generate_projects);
1321 $form->{projectnumber} = $form->{projectnumber_1};
1323 $form->{nextsub} = "generate_projects";
1324 $form->{title} = $locale->text('Project Transactions');
1325 RP->trial_balance(\%myconfig, \%$form);
1327 list_accounts('generate_projects');
1329 $lxdebug->leave_sub();
1335 # included links to display transactions for period entered
1336 # added headers and subtotals
1338 sub generate_trial_balance {
1339 $lxdebug->enter_sub();
1341 $auth->assert('report');
1343 if ($form->{reporttype} eq "custom") {
1345 #forgotten the year --> thisyear
1346 if ($form->{year} !~ m/^\d\d\d\d$/) {
1347 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1353 if ($form->{duetyp} eq "13") {
1354 $form->{fromdate} = "1.1.$form->{year}";
1355 $form->{todate} = "31.12.$form->{year}";
1359 if ($form->{duetyp} eq "A") {
1360 $form->{fromdate} = "1.1.$form->{year}";
1361 $form->{todate} = "31.3.$form->{year}";
1363 if ($form->{duetyp} eq "B") {
1364 $form->{fromdate} = "1.4.$form->{year}";
1365 $form->{todate} = "30.6.$form->{year}";
1367 if ($form->{duetyp} eq "C") {
1368 $form->{fromdate} = "1.7.$form->{year}";
1369 $form->{todate} = "30.9.$form->{year}";
1371 if ($form->{duetyp} eq "D") {
1372 $form->{fromdate} = "1.10.$form->{year}";
1373 $form->{todate} = "31.12.$form->{year}";
1378 $form->{duetyp} eq "1" && do {
1379 $form->{fromdate} = "1.1.$form->{year}";
1380 $form->{todate} = "31.1.$form->{year}";
1383 $form->{duetyp} eq "2" && do {
1384 $form->{fromdate} = "1.2.$form->{year}";
1386 #this works from 1901 to 2099, 1900 and 2100 fail.
1387 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1388 $form->{todate} = "$leap.2.$form->{year}";
1391 $form->{duetyp} eq "3" && do {
1392 $form->{fromdate} = "1.3.$form->{year}";
1393 $form->{todate} = "31.3.$form->{year}";
1396 $form->{duetyp} eq "4" && do {
1397 $form->{fromdate} = "1.4.$form->{year}";
1398 $form->{todate} = "30.4.$form->{year}";
1401 $form->{duetyp} eq "5" && do {
1402 $form->{fromdate} = "1.5.$form->{year}";
1403 $form->{todate} = "31.5.$form->{year}";
1406 $form->{duetyp} eq "6" && do {
1407 $form->{fromdate} = "1.6.$form->{year}";
1408 $form->{todate} = "30.6.$form->{year}";
1411 $form->{duetyp} eq "7" && do {
1412 $form->{fromdate} = "1.7.$form->{year}";
1413 $form->{todate} = "31.7.$form->{year}";
1416 $form->{duetyp} eq "8" && do {
1417 $form->{fromdate} = "1.8.$form->{year}";
1418 $form->{todate} = "31.8.$form->{year}";
1421 $form->{duetyp} eq "9" && do {
1422 $form->{fromdate} = "1.9.$form->{year}";
1423 $form->{todate} = "30.9.$form->{year}";
1426 $form->{duetyp} eq "10" && do {
1427 $form->{fromdate} = "1.10.$form->{year}";
1428 $form->{todate} = "31.10.$form->{year}";
1431 $form->{duetyp} eq "11" && do {
1432 $form->{fromdate} = "1.11.$form->{year}";
1433 $form->{todate} = "30.11.$form->{year}";
1436 $form->{duetyp} eq "12" && do {
1437 $form->{fromdate} = "1.12.$form->{year}";
1438 $form->{todate} = "31.12.$form->{year}";
1445 # get for each account initial balance, debits and credits
1446 RP->trial_balance(\%myconfig, \%$form);
1449 $form->{rowcount} = scalar @{ $form->{TB} };
1450 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1453 "accno", "description",
1454 "last_transaction", "soll_eb",
1457 "soll_kumuliert", "haben_kumuliert",
1458 "soll_saldo", "haben_saldo"
1462 my $attachment_basename;
1463 $attachment_basename = $locale->text('trial_balance');
1464 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1466 my @hidden_variables = ();
1467 push @hidden_variables, qw(fromdate todate year cash );
1469 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1472 'accno' => { 'text' => $locale->text('Account Number'), },
1473 'description' => { 'text' => $locale->text('Description'), },
1474 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1475 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1476 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1477 'soll' => { 'text' => $locale->text('Debit'), },
1478 'haben' => { 'text' => $locale->text('Credit'), },
1479 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1480 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1481 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1482 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1487 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1489 map { $column_defs{$_}->{visible} = 1 } @columns;
1491 $report->set_columns(%column_defs);
1492 $report->set_column_order(@columns);
1494 $report->set_export_options('generate_trial_balance', @hidden_variables);
1496 $report->set_sort_indicator($form->{sort}, 1);
1501 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1502 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1504 $report->set_options('output_format' => 'HTML',
1505 'title' => $form->{title},
1506 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1507 'html_template' => 'rp/html_report_susa',
1508 'pdf_template' => 'rp/html_report_susa',
1510 $report->set_options_from_form();
1512 # add sort and escape callback, this one we use for the add sub
1513 $form->{callback} = $href .= "&sort=$form->{sort}";
1515 # escape callback for href
1516 $callback = $form->escape($href);
1518 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1520 my %totals = map { $_ => 0 } @subtotal_columns;
1522 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1524 foreach $accno (@{ $form->{TB} }) {
1526 $accno->{soll} = $accno->{debit};
1527 $accno->{haben} = $accno->{credit};
1528 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1530 map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1532 map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1536 foreach my $column (@columns) {
1538 'data' => $accno->{$column},
1539 'align' => $column_alignment{$column},
1544 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1546 my $row_set = [ $row ];
1549 $report->add_data($row_set);
1554 $report->add_separator();
1556 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1558 $report->generate_with_headers();
1560 $lxdebug->leave_sub();
1564 sub create_subtotal_row {
1565 $lxdebug->enter_sub();
1567 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1569 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1571 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1573 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1575 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1577 $lxdebug->leave_sub();
1582 sub create_list_accounts_subtotal_row {
1583 $lxdebug->enter_sub();
1585 my ($subtotals, $columns, $fields, $class) = @_;
1587 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1589 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1591 $lxdebug->leave_sub();
1597 $lxdebug->enter_sub();
1602 if ($form->{department}) {
1603 my ($department) = split /--/, $form->{department};
1604 push @options, $locale->text('Department') . " : $department";
1606 if ($form->{projectnumber}) {
1607 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1610 # if there are any dates
1611 if ($form->{fromdate} || $form->{todate}) {
1612 my ($fromdate, $todate);
1614 if ($form->{fromdate}) {
1615 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1617 if ($form->{todate}) {
1618 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1621 push @options, "$fromdate - $todate";
1624 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1627 my @columns = qw(accno description begbalance debit credit endbalance);
1629 'accno' => { 'text' => $locale->text('Account'), },
1630 'description' => { 'text' => $locale->text('Description'), },
1631 'debit' => { 'text' => $locale->text('Debit'), },
1632 'credit' => { 'text' => $locale->text('Credit'), },
1633 'begbalance' => { 'text' => $locale->text('Balance'), },
1634 'endbalance' => { 'text' => $locale->text('Balance'), },
1636 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1638 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1640 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1642 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1644 $report->set_options('top_info_text' => join("\n", @options),
1645 'output_format' => 'HTML',
1646 'title' => $form->{title},
1647 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1648 'std_column_visibility' => 1,
1650 $report->set_options_from_form();
1652 $report->set_columns(%column_defs);
1653 $report->set_column_order(@columns);
1655 $report->set_export_options($action, @hidden_variables);
1657 $report->set_sort_indicator('accno', 1);
1659 my @totals_columns = qw(credit debit begbalance endbalance);
1660 my %subtotals = map { $_ => 0 } @totals_columns;
1661 my %totals = map { $_ => 0 } @totals_columns;
1662 my $found_heading = 0;
1663 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1665 # sort the whole thing by account numbers and display
1666 foreach my $idx (0 .. scalar(@tb) - 1) {
1667 my $ref = $tb[$idx];
1668 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1670 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1672 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1674 if ($ref->{charttype} eq 'H') {
1675 next unless ($form->{l_heading});
1677 %subtotals = map { $_ => 0 } @totals_columns;
1679 $row->{description}->{class} = 'listheading';
1680 $row->{description}->{data} = $ref->{description};
1682 $report->add_data($row);
1687 foreach (qw(debit credit)) {
1688 $subtotals{$_} += $ref->{$_};
1689 $totals{$_} += $ref->{$_};
1692 $subtotals{begbalance} += $ref->{balance} * $ml;
1693 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1695 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1696 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1698 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1699 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1701 $report->add_data($row);
1703 if ($form->{l_heading} && $found_heading &&
1704 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1705 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1709 $report->add_separator();
1711 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1713 $report->generate_with_headers();
1715 $lxdebug->leave_sub();
1718 sub generate_ar_aging {
1719 $lxdebug->enter_sub();
1721 $auth->assert('general_ledger');
1724 ($form->{customer}) = split(/--/, $form->{customer});
1726 $form->{ct} = "customer";
1727 $form->{arap} = "ar";
1729 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1731 RP->aging(\%myconfig, \%$form);
1734 $lxdebug->leave_sub();
1737 sub generate_ap_aging {
1738 $lxdebug->enter_sub();
1740 $auth->assert('general_ledger');
1743 ($form->{vendor}) = split(/--/, $form->{vendor});
1745 $form->{ct} = "vendor";
1746 $form->{arap} = "ap";
1748 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1750 RP->aging(\%myconfig, \%$form);
1753 $lxdebug->leave_sub();
1756 sub create_aging_subtotal_row {
1757 $lxdebug->enter_sub();
1759 my ($subtotals, $columns, $periods, $class) = @_;
1761 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1763 foreach (@{ $periods }) {
1764 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1765 $subtotals->{$_} = 0;
1768 $lxdebug->leave_sub();
1774 $lxdebug->enter_sub();
1775 print(STDERR "Bin in Aging\n");
1776 $auth->assert('general_ledger');
1778 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1780 my @columns = qw(statement ct invnumber transdate duedate amount open);
1783 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1784 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1785 'invnumber' => { 'text' => $locale->text('Invoice'), },
1786 'transdate' => { 'text' => $locale->text('Date'), },
1787 'duedate' => { 'text' => $locale->text('Due'), },
1788 'amount' => { 'text' => $locale->text('Amount'), },
1789 'open' => { 'text' => $locale->text('Open'), },
1792 my %column_alignment = ('statement' => 'center',
1793 map { $_ => 'right' } qw(open amount));
1795 $report->set_options('std_column_visibility' => 1);
1796 $report->set_columns(%column_defs);
1797 $report->set_column_order(@columns);
1799 my @hidden_variables = qw(todate customer vendor arap title ct);
1800 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1803 my $attachment_basename;
1805 if ($form->{department}) {
1806 my ($department) = split /--/, $form->{department};
1807 push @options, $locale->text('Department') . " : $department";
1808 $form->{callback} .= "&department=" . E($department);
1811 if (($form->{arap} eq 'ar') && $form->{customer}) {
1812 push @options, $form->{customer};
1813 $attachment_basename = $locale->text('ar_aging_list');
1814 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1817 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1818 push @options, $form->{vendor};
1819 $attachment_basename = $locale->text('ap_aging_list');
1820 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1823 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1825 my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1827 $report->set_options('top_info_text' => join("\n", @options),
1828 'output_format' => 'HTML',
1829 'title' => $form->{title},
1830 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1833 my $previous_ctid = 0;
1835 my @periods = qw(open amount);
1836 my %subtotals = map { $_ => 0 } @periods;
1837 my %totals = map { $_ => 0 } @periods;
1839 foreach $ref (@{ $form->{AG} }) {
1840 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1841 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1844 foreach my $key (@periods) {
1845 $subtotals{$key} += $ref->{"$key"};
1846 $totals{$key} += $ref->{"$key"};
1847 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1852 foreach my $column (@columns) {
1854 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1855 'align' => $column_alignment{$column},
1856 'valign' => $column eq 'statement' ? 'center' : '',
1860 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1862 if ($previous_ctid != $ref->{ctid}) {
1863 $row->{statement}->{raw_data} =
1864 $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
1865 . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1866 $row->{ct}->{data} = $ref->{name};
1871 $previous_ctid = $ref->{ctid};
1873 $report->add_data($row);
1876 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1878 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1880 if ($form->{arap} eq 'ar') {
1881 $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1882 $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1883 'PRINT_OPTIONS' => print_options(inline => 1), });
1884 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1885 'raw_bottom_info_text' => $raw_bottom_info_text);
1888 $report->set_options_from_form();
1890 $report->generate_with_headers();
1892 $lxdebug->leave_sub();
1896 $lxdebug->enter_sub();
1898 RP->aging(\%myconfig, \%$form);
1900 map { $_->{checked} = "checked" } @{ $form->{AG} };
1904 $lxdebug->leave_sub();
1908 $lxdebug->enter_sub();
1910 $auth->assert('general_ledger');
1912 # get name and email addresses
1913 for $i (1 .. $form->{rowcount}) {
1914 if ($form->{"statement_$i"}) {
1915 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1916 RP->get_customer(\%myconfig, \%$form);
1922 $form->error($locale->text('Nothing selected!')) unless $selected;
1924 if ($myconfig{role} eq 'admin') {
1926 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1927 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1931 $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1933 $form->{media} = "email";
1940 <form method=post action=$form->{script}>
1946 <tr height="5"></tr>
1951 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1952 <td><input name=email size=30 value="$form->{email}"></td>
1953 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1954 <td><input name=cc size=30 value="$form->{cc}"></td>
1957 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1958 <td><input name=subject size=30 value="$form->{subject}"></td>
1968 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1971 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1982 map { delete $form->{$_} }
1983 qw(action email cc bcc subject message type sendmode format header);
1985 # save all other variables
1986 foreach $key (keys %$form) {
1987 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1988 $form->{$key} =~ s/\"/"/g;
1989 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1996 <td><hr size=3 noshade></td>
2000 <input type=hidden name=nextsub value=send_email>
2003 <input name=action class=submit type=submit value="|
2004 . $locale->text('Continue') . qq|">
2011 $lxdebug->leave_sub();
2015 $lxdebug->enter_sub();
2017 $auth->assert('general_ledger');
2019 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
2020 unless $form->{subject};
2022 RP->aging(\%myconfig, \%$form);
2024 $form->{"statement_1"} = 1;
2026 $form->{media} = 'email';
2029 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
2031 $lxdebug->leave_sub();
2035 $lxdebug->enter_sub();
2037 $auth->assert('general_ledger');
2039 if ($form->{media} eq 'printer') {
2040 $form->error($locale->text('Select postscript or PDF!'))
2041 if ($form->{format} !~ /(postscript|pdf)/);
2044 for $i (1 .. $form->{rowcount}) {
2045 if ($form->{"statement_$i"}) {
2046 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
2052 $form->error($locale->text('Nothing selected!')) unless $selected;
2054 if ($form->{media} eq 'printer') {
2055 $form->{"$form->{ct}_id"} = "";
2057 $form->{"statement_1"} = 1;
2060 RP->aging(\%myconfig, \%$form);
2064 $form->redirect($locale->text('Statements sent to printer!'))
2065 if ($form->{media} eq 'printer');
2067 $lxdebug->leave_sub();
2071 $lxdebug->enter_sub();
2073 $auth->assert('general_ledger');
2075 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
2077 $form->{templates} = "$myconfig{templates}";
2079 my $suffix = "html";
2080 my $attachment_suffix = "html";
2081 if ($form->{format} eq 'postscript') {
2082 $form->{postscript} = 1;
2084 $attachment_suffix = "ps";
2085 } elsif ($form->{format} eq 'pdf') {
2088 $attachment_suffix = "pdf";
2091 $form->{IN} = "$form->{type}.$suffix";
2092 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
2094 # Save $form->{email} because it will be overwritten.
2095 $form->{EMAIL_RECIPIENT} = $form->{email};
2098 while (@{ $form->{AG} }) {
2100 $ref = shift @{ $form->{AG} };
2102 if ($ctid != $ref->{ctid}) {
2104 $ctid = $ref->{ctid};
2107 if ($form->{"statement_$i"}) {
2110 (name, street, zipcode, city, country, contact, email,
2111 "$form->{ct}phone", "$form->{ct}fax");
2112 map { $form->{$_} = $ref->{$_} } @a;
2114 $form->{ $form->{ct} } = $form->{name};
2115 $form->{"$form->{ct}_id"} = $ref->{ctid};
2117 map { $form->{$_} = () } qw(invnumber invdate duedate);
2119 foreach $item (qw(c0 c30 c60 c90)) {
2120 $form->{$item} = ();
2121 $form->{"${item}total"} = 0;
2124 &statement_details($ref);
2128 if (scalar(@{ $form->{AG} }) > 0) {
2130 # one or more left to go
2131 if ($ctid == $form->{AG}->[0]->{ctid}) {
2132 $ref = shift @{ $form->{AG} };
2133 &statement_details($ref);
2136 $ref = scalar(@{ $form->{AG} });
2142 # set initial ref to 0
2149 $form->{"${_}total"} =
2150 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2151 } (c0, c30, c60, c90, "");
2153 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2154 $form->{attachment_filename} =~ s/\s+/_/g;
2156 $form->parse_template(\%myconfig, $userspath);
2161 # saving the history
2162 if(!exists $form->{addition} && $form->{id} ne "") {
2163 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2164 $form->{addition} = "PRINTED";
2165 $form->{what_done} = $form->{type};
2166 $form->save_history($form->dbconnect(\%myconfig));
2168 # /saving the history
2169 $lxdebug->leave_sub();
2172 sub statement_details {
2173 $lxdebug->enter_sub();
2175 $auth->assert('general_ledger');
2179 push @{ $form->{invnumber} }, $ref->{invnumber};
2180 push @{ $form->{invdate} }, $ref->{transdate};
2181 push @{ $form->{duedate} }, $ref->{duedate};
2183 foreach $item (qw(c0 c30 c60 c90)) {
2184 if ($ref->{exchangerate} * 1) {
2186 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2188 $form->{"${item}total"} += $ref->{$item};
2189 $form->{total} += $ref->{$item};
2190 push @{ $form->{$item} },
2191 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2194 $lxdebug->leave_sub();
2197 sub generate_tax_report {
2198 $lxdebug->enter_sub();
2200 $auth->assert('report');
2202 RP->tax_report(\%myconfig, \%$form);
2204 $descvar = "$form->{accno}_description";
2205 $description = $form->escape($form->{$descvar});
2206 $ratevar = "$form->{accno}_rate";
2208 $department = $form->escape($form->{department});
2212 "$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}";
2214 # construct callback
2215 $description = $form->escape($form->{$descvar}, 1);
2216 $department = $form->escape($form->{department}, 1);
2218 "$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}";
2220 $title = $form->escape($form->{title});
2221 $href .= "&title=$title";
2222 $title = $form->escape($form->{title}, 1);
2223 $callback .= "&title=$title";
2225 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2228 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2230 foreach $item (@columns) {
2231 if ($form->{"l_$item"} eq "Y") {
2232 push @column_index, $item;
2234 # add column to href and callback
2235 $callback .= "&l_$item=Y";
2236 $href .= "&l_$item=Y";
2240 if ($form->{l_subtotal} eq 'Y') {
2241 $callback .= "&l_subtotal=Y";
2242 $href .= "&l_subtotal=Y";
2245 if ($form->{department}) {
2246 ($department) = split /--/, $form->{department};
2247 $option = $locale->text('Department') . " : $department";
2250 # if there are any dates
2251 if ($form->{fromdate} || $form->{todate}) {
2252 if ($form->{fromdate}) {
2253 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2255 if ($form->{todate}) {
2256 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2259 $form->{period} = "$fromdate - $todate";
2262 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2265 if ($form->{db} eq 'ar') {
2266 $name = $locale->text('Customer');
2270 if ($form->{db} eq 'ap') {
2271 $name = $locale->text('Vendor');
2276 $option .= "<br>" if $option;
2277 $option .= "$form->{period}";
2279 $column_header{id} =
2280 qq|<th><a class=listheading href=$href&sort=id>|
2281 . $locale->text('ID')
2283 $column_header{invnumber} =
2284 qq|<th><a class=listheading href=$href&sort=invnumber>|
2285 . $locale->text('Invoice')
2287 $column_header{transdate} =
2288 qq|<th><a class=listheading href=$href&sort=transdate>|
2289 . $locale->text('Date')
2291 $column_header{netamount} =
2292 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2293 $column_header{tax} =
2294 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2295 $column_header{amount} =
2296 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2298 $column_header{name} =
2299 qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2308 <th class=listtop colspan=$colspan>$form->{title}</th>
2310 <tr height="5"></tr>
2317 <tr class=listheading>
2320 map { print "$column_header{$_}\n" } @column_index;
2326 # add sort and escape callback
2327 $callback = $form->escape($callback . "&sort=$form->{sort}");
2329 if (@{ $form->{TR} }) {
2330 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2333 foreach $ref (@{ $form->{TR} }) {
2335 $module = ($ref->{invoice}) ? $invoice : $arap;
2337 if ($form->{l_subtotal} eq 'Y') {
2338 if ($sameitem ne $ref->{ $form->{sort} }) {
2340 $sameitem = $ref->{ $form->{sort} };
2344 $totalnetamount += $ref->{netamount};
2345 $totaltax += $ref->{tax};
2346 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2348 $subtotalnetamount += $ref->{netamount};
2349 $subtotaltax += $ref->{tax};
2352 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2353 } qw(netamount tax amount);
2355 $column_data{id} = qq|<td>$ref->{id}</td>|;
2356 $column_data{invnumber} =
2357 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2358 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2359 $column_data{name} = qq|<td>$ref->{name} </td>|;
2361 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2362 qw(netamount tax amount);
2367 <tr class=listrow$i>
2370 map { print "$column_data{$_}\n" } @column_index;
2378 if ($form->{l_subtotal} eq 'Y') {
2382 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2386 <tr class=listtotal>
2390 $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2392 $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2393 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2395 $column_data{netamount} =
2396 qq|<th class=listtotal align=right>$totalnetamount</th>|;
2397 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2398 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2400 map { print "$column_data{$_}\n" } @column_index;
2408 <td><hr size=3 noshade></td>
2416 $lxdebug->leave_sub();
2420 $lxdebug->enter_sub();
2422 map { $column_data{$_} = "<td> </td>" } @column_index;
2424 $subtotalnetamount =
2425 $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
2426 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
2428 $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2431 $column_data{netamount} =
2432 "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2433 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2434 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2436 $subtotalnetamount = 0;
2440 <tr class=listsubtotal>
2442 map { print "\n$column_data{$_}" } @column_index;
2448 $lxdebug->leave_sub();
2452 $lxdebug->enter_sub();
2454 $auth->assert('cash');
2456 if ($form->{account}) {
2457 ($form->{paymentaccounts}) = split /--/, $form->{account};
2459 if ($form->{department}) {
2460 ($department, $form->{department_id}) = split /--/, $form->{department};
2461 $option = $locale->text('Department') . " : $department";
2464 RP->payments(\%myconfig, \%$form);
2466 my @hidden_variables = qw(account title department reference source memo fromdate todate
2467 fx_transaction db prepayment paymentaccounts sort);
2469 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2470 $form->{callback} = $href;
2472 my @columns = qw(transdate invnumber name paid source memo);
2474 'name' => { 'text' => $locale->text('Description'), },
2475 'invnumber' => { 'text' => $locale->text('Reference'), },
2476 'transdate' => { 'text' => $locale->text('Date'), },
2477 'paid' => { 'text' => $locale->text('Amount'), },
2478 'source' => { 'text' => $locale->text('Source'), },
2479 'memo' => { 'text' => $locale->text('Memo'), },
2481 my %column_alignment = ('paid' => 'right');
2483 map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns;
2486 if ($form->{fromdate}) {
2487 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2489 if ($form->{todate}) {
2490 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2493 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2495 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2497 $report->set_options('top_info_text' => join("\n", @options),
2498 'output_format' => 'HTML',
2499 'title' => $form->{title},
2500 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2501 'std_column_visibility' => 1,
2503 $report->set_options_from_form();
2505 $report->set_columns(%column_defs);
2506 $report->set_column_order(@columns);
2508 $report->set_export_options('list_payments', @hidden_variables);
2510 $report->set_sort_indicator($form->{sort}, 1);
2514 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2515 next unless @{ $form->{ $ref->{id} } };
2517 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2519 my $subtotal_paid = 0;
2521 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2522 my $module = $payment->{module};
2523 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2524 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2526 $subtotal_paid += $payment->{paid};
2527 $total_paid += $payment->{paid};
2529 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2533 foreach my $column (@columns) {
2535 'data' => $payment->{$column},
2536 'align' => $column_alignment{$column},
2540 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2542 $report->add_data($row);
2545 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2547 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2549 'class' => 'listsubtotal',
2552 $report->add_data($row);
2555 $report->add_separator();
2557 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2559 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2561 'class' => 'listtotal',
2564 $report->add_data($row);
2566 $report->generate_with_headers();
2568 $lxdebug->leave_sub();
2572 $lxdebug->enter_sub();
2574 my ($dont_print) = @_;
2576 $form->{sendmode} = "attachment";
2579 $form->{"format"} ? $form->{"format"} :
2580 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2584 $form->{"copies"} ? $form->{"copies"} :
2585 $myconfig{"copies"} ? $myconfig{"copies"} :
2588 $form->{PD}{ $form->{type} } = "selected";
2589 $form->{DF}{ $form->{format} } = "selected";
2590 $form->{OP}{ $form->{media} } = "selected";
2591 $form->{SM}{ $form->{sendmode} } = "selected";
2594 <option value=statement $form->{PD}{statement}>|
2595 . $locale->text('Statement');
2597 if ($form->{media} eq 'email') {
2599 <option value=attachment $form->{SM}{attachment}>|
2600 . $locale->text('Attachment') . qq|
2601 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2604 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2605 if ($myconfig{printer} && $latex_templates) {
2607 <option value=printer $form->{OP}{printer}>|
2608 . $locale->text('Printer');
2612 if ($latex_templates) {
2614 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2615 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2616 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2622 <td><select name=type>$type</select></td>
2623 <td><select name=format>$format</select></td>
2624 <td><select name=media>$media</select></td>
2627 if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2629 <td>| . $locale->text('Copies') . qq|
2630 <input name=copies size=2 value=$form->{copies}></td>
2639 print $output unless $dont_print;
2641 $lxdebug->leave_sub();
2647 $lxdebug->enter_sub();
2649 $auth->assert('report');
2651 $form->{padding} = " ";
2652 $form->{bold} = "<b>";
2653 $form->{endbold} = "</b>";
2654 $form->{br} = "<br>";
2656 if ($form->{reporttype} eq "custom") {
2658 #forgotten the year --> thisyear
2659 if ($form->{year} !~ m/^\d\d\d\d$/) {
2660 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2666 if ($form->{duetyp} eq "13") {
2667 $form->{fromdate} = "1.1.$form->{year}";
2668 $form->{todate} = "31.12.$form->{year}";
2669 $form->{comparefromdate} = "1.01.$form->{year}";
2670 $form->{comparetodate} = "31.12.$form->{year}";
2674 if ($form->{duetyp} eq "A") {
2675 $form->{fromdate} = "1.1.$form->{year}";
2676 $form->{todate} = "31.3.$form->{year}";
2677 $form->{comparefromdate} = "1.01.$form->{year}";
2678 $form->{comparetodate} = "31.03.$form->{year}";
2680 if ($form->{duetyp} eq "B") {
2681 $form->{fromdate} = "1.4.$form->{year}";
2682 $form->{todate} = "30.6.$form->{year}";
2683 $form->{comparefromdate} = "1.01.$form->{year}";
2684 $form->{comparetodate} = "30.06.$form->{year}";
2686 if ($form->{duetyp} eq "C") {
2687 $form->{fromdate} = "1.7.$form->{year}";
2688 $form->{todate} = "30.9.$form->{year}";
2689 $form->{comparefromdate} = "1.01.$form->{year}";
2690 $form->{comparetodate} = "30.09.$form->{year}";
2692 if ($form->{duetyp} eq "D") {
2693 $form->{fromdate} = "1.10.$form->{year}";
2694 $form->{todate} = "31.12.$form->{year}";
2695 $form->{comparefromdate} = "1.01.$form->{year}";
2696 $form->{comparetodate} = "31.12.$form->{year}";
2701 $form->{duetyp} eq "1" && do {
2702 $form->{fromdate} = "1.1.$form->{year}";
2703 $form->{todate} = "31.1.$form->{year}";
2704 $form->{comparefromdate} = "1.01.$form->{year}";
2705 $form->{comparetodate} = "31.01.$form->{year}";
2708 $form->{duetyp} eq "2" && do {
2709 $form->{fromdate} = "1.2.$form->{year}";
2711 #this works from 1901 to 2099, 1900 and 2100 fail.
2712 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2713 $form->{todate} = "$leap.2.$form->{year}";
2714 $form->{comparefromdate} = "1.01.$form->{year}";
2715 $form->{comparetodate} = "$leap.02.$form->{year}";
2718 $form->{duetyp} eq "3" && do {
2719 $form->{fromdate} = "1.3.$form->{year}";
2720 $form->{todate} = "31.3.$form->{year}";
2721 $form->{comparefromdate} = "1.01.$form->{year}";
2722 $form->{comparetodate} = "31.03.$form->{year}";
2725 $form->{duetyp} eq "4" && do {
2726 $form->{fromdate} = "1.4.$form->{year}";
2727 $form->{todate} = "30.4.$form->{year}";
2728 $form->{comparefromdate} = "1.01.$form->{year}";
2729 $form->{comparetodate} = "30.04.$form->{year}";
2732 $form->{duetyp} eq "5" && do {
2733 $form->{fromdate} = "1.5.$form->{year}";
2734 $form->{todate} = "31.5.$form->{year}";
2735 $form->{comparefromdate} = "1.01.$form->{year}";
2736 $form->{comparetodate} = "31.05.$form->{year}";
2739 $form->{duetyp} eq "6" && do {
2740 $form->{fromdate} = "1.6.$form->{year}";
2741 $form->{todate} = "30.6.$form->{year}";
2742 $form->{comparefromdate} = "1.01.$form->{year}";
2743 $form->{comparetodate} = "30.06.$form->{year}";
2746 $form->{duetyp} eq "7" && do {
2747 $form->{fromdate} = "1.7.$form->{year}";
2748 $form->{todate} = "31.7.$form->{year}";
2749 $form->{comparefromdate} = "1.01.$form->{year}";
2750 $form->{comparetodate} = "31.07.$form->{year}";
2753 $form->{duetyp} eq "8" && do {
2754 $form->{fromdate} = "1.8.$form->{year}";
2755 $form->{todate} = "31.8.$form->{year}";
2756 $form->{comparefromdate} = "1.01.$form->{year}";
2757 $form->{comparetodate} = "31.08.$form->{year}";
2760 $form->{duetyp} eq "9" && do {
2761 $form->{fromdate} = "1.9.$form->{year}";
2762 $form->{todate} = "30.9.$form->{year}";
2763 $form->{comparefromdate} = "1.01.$form->{year}";
2764 $form->{comparetodate} = "30.09.$form->{year}";
2767 $form->{duetyp} eq "10" && do {
2768 $form->{fromdate} = "1.10.$form->{year}";
2769 $form->{todate} = "31.10.$form->{year}";
2770 $form->{comparefromdate} = "1.01.$form->{year}";
2771 $form->{comparetodate} = "31.10.$form->{year}";
2774 $form->{duetyp} eq "11" && do {
2775 $form->{fromdate} = "1.11.$form->{year}";
2776 $form->{todate} = "30.11.$form->{year}";
2777 $form->{comparefromdate} = "1.01.$form->{year}";
2778 $form->{comparetodate} = "30.11.$form->{year}";
2781 $form->{duetyp} eq "12" && do {
2782 $form->{fromdate} = "1.12.$form->{year}";
2783 $form->{todate} = "31.12.$form->{year}";
2784 $form->{comparefromdate} = "1.01.$form->{year}";
2785 $form->{comparetodate} = "31.12.$form->{year}";
2790 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2791 $form->{fromdate} = "${dd}.${mm}.${yy}";
2792 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2793 $form->{todate} = "${dd}.${mm}.${yy}";
2794 $form->{comparefromdate} = "01.01.$yy";
2795 $form->{comparetodate} = $form->{todate};
2798 RP->bwa(\%myconfig, \%$form);
2800 ($form->{department}) = split /--/, $form->{department};
2803 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2804 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2806 # if there are any dates construct a where
2807 if ($form->{fromdate} || $form->{todate}) {
2809 unless ($form->{todate}) {
2810 $form->{todate} = $form->current_date(\%myconfig);
2813 my %germandate = ("dateformat" => "dd.mm.yyyy");
2815 $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2816 $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2818 $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2819 $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2821 $form->{this_period} = "$shortfromdate\n$shorttodate";
2823 $locale->text('for Period')
2824 . qq|\n$longfromdate |
2825 . $locale->text('bis')
2829 # setup variables for the form
2830 @a = qw(company address businessnumber);
2831 map { $form->{$_} = $myconfig{$_} } @a;
2832 $form->{templates} = $myconfig{templates};
2834 $form->{IN} = "bwa.html";
2836 $form->parse_template;
2838 $lxdebug->leave_sub();