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;
46 require "bin/mozilla/arap.pl";
47 require "bin/mozilla/common.pl";
48 require "bin/mozilla/reportgenerator.pl";
54 # this is for our long dates
55 # $locale->text('January')
56 # $locale->text('February')
57 # $locale->text('March')
58 # $locale->text('April')
59 # $locale->text('May ')
60 # $locale->text('June')
61 # $locale->text('July')
62 # $locale->text('August')
63 # $locale->text('September')
64 # $locale->text('October')
65 # $locale->text('November')
66 # $locale->text('December')
68 # this is for our short month
69 # $locale->text('Jan')
70 # $locale->text('Feb')
71 # $locale->text('Mar')
72 # $locale->text('Apr')
73 # $locale->text('May')
74 # $locale->text('Jun')
75 # $locale->text('Jul')
76 # $locale->text('Aug')
77 # $locale->text('Sep')
78 # $locale->text('Oct')
79 # $locale->text('Nov')
80 # $locale->text('Dec')
82 # $locale->text('Balance Sheet')
83 # $locale->text('Income Statement')
84 # $locale->text('Trial Balance')
85 # $locale->text('AR Aging')
86 # $locale->text('AP Aging')
87 # $locale->text('Tax collected')
88 # $locale->text('Tax paid')
89 # $locale->text('Receipts')
90 # $locale->text('Payments')
91 # $locale->text('Project Transactions')
92 # $locale->text('Non-taxable Sales')
93 # $locale->text('Non-taxable Purchases')
95 # $form->parse_html_template('rp/html_report_susa')
98 'projects' => 'report',
99 'ar_aging' => 'general_ledger',
100 'ap_aging' => 'general_ledger',
101 'receipts' => 'cash',
102 'payments' => 'cash',
103 'trial_balance' => 'report',
104 'income_statement' => 'report',
106 'balance_sheet' => 'report',
109 sub check_rp_access {
110 my $right = $rp_access_map->{$form->{report}};
111 $right ||= 'DOES_NOT_EXIST';
113 $auth->assert($right);
117 $lxdebug->enter_sub();
121 %title = ('balance_sheet' => 'Balance Sheet',
122 'income_statement' => 'Income Statement',
123 'trial_balance' => 'Trial Balance',
124 'ar_aging' => 'AR Aging',
125 'ap_aging' => 'Offene Verbindlichkeiten',
126 'tax_collected' => 'Tax collected',
127 'tax_paid' => 'Tax paid',
128 'nontaxable_sales' => 'Non-taxable Sales',
129 'nontaxable_purchases' => 'Non-taxable Purchases',
130 'receipts' => 'Receipts',
131 'payments' => 'Payments',
132 'projects' => 'Project Transactions',
133 'bwa' => 'Betriebswirtschaftliche Auswertung',);
135 $form->{title} = $locale->text($title{ $form->{report} });
137 $accrual = ($eur) ? "" : "checked";
138 $cash = ($eur) ? "checked" : "";
140 $year = (localtime)[5] + 1900;
143 $form->all_departments(\%myconfig);
144 if (@{ $form->{all_departments} }) {
145 $form->{selectdepartment} = "<option>\n";
146 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} };
151 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
152 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
154 | if $form->{selectdepartment};
156 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
159 my %project_labels = ();
160 my @project_values = ("");
161 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
162 push(@project_values, $item->{"id"});
163 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
167 NTI($cgi->popup_menu('-name' => "project_id",
168 '-values' => \@project_values,
169 '-labels' => \%project_labels));
171 # use JavaScript Calendar or not
172 $form->{jsscript} = 1;
174 if ($form->{report} eq "balance_sheet") {
175 $name_1 = "asofdate";
177 $value_1 = "$form->{asofdate}";
178 $trigger_1 = "trigger1";
179 $name_2 = "compareasofdate";
180 $id_2 = "compareasofdate";
181 $value_2 = "$form->{compareasofdate}";
182 $trigger_2 = "trigger2";
183 } elsif ($form->{report} =~ /(receipts|payments)$/) {
184 $name_1 = "fromdate";
186 $value_1 = "$form->{fromdate}";
187 $trigger_1 = "trigger1";
191 $trigger_2 = "trigger2";
192 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
193 $name_1 = "fromdate";
195 $value_1 = "$form->{fromdate}";
196 $trigger_1 = "trigger1";
200 $trigger_2 = "trigger2";
203 $name_1 = "fromdate";
205 $value_1 = "$form->{fromdate}";
206 $trigger_1 = "trigger1";
210 $trigger_2 = "trigger2";
213 # with JavaScript Calendar
214 if ($form->{jsscript}) {
216 $button1 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
217 $button1_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|>|;
220 $jsscript = Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
222 $button1 = qq| <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
223 $button1_2 = qq| <input type=button name=$name_1 id="$trigger_1" value=| . $locale->text('button') . qq|>|;
224 $button2 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
225 $button2_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|> |;
228 $jsscript = Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1", "$name_2", "BL", "$trigger_2");
232 # without JavaScript Calendar
234 $button1 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
236 $button1 = qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
237 $button2 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
240 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
242 $onload = qq|focus()|;
243 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
244 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
246 <body onLoad="$onload">
248 <form method=post action=$form->{script}>
250 <input type=hidden name=title value="$form->{title}">
254 <th class=listtop>$form->{title}</th>
263 if ($form->{report} eq "projects") {
266 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
267 <td colspan=5><input name=projectnumber size=25</td>
269 <input type=hidden name=nextsub value=generate_projects>
271 <th align=right>| . $locale->text('From') . qq|</th>
274 <th align=right>| . $locale->text('Bis') . qq|</th>
285 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
286 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
287 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
294 if ($form->{report} eq "income_statement") {
297 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
298 <td colspan=3>$projectnumber</td>
300 <input type=hidden name=nextsub value=generate_income_statement>
304 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
307 <th colspan=1>| . $locale->text('Year') . qq|</th>
308 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
314 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
315 <th align=left>| . $locale->text('Quarterly') . qq|</th>
316 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
319 <td align=right> <input name=duetyp class=radio type=radio value="13" "checked"></td>
320 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
324 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
328 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
329 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
333 <td align= right> </td>
334 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
335 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
336 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
337 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
341 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
342 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
343 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
344 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
349 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
350 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
351 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
352 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
356 <td colspan=5><hr size=3 noshade></td>
359 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
360 <td align=left colspan=4>| . $locale->text('From') . qq|
363 | . $locale->text('Bis') . qq|
369 <td colspan=5><hr size=3 noshade></td>
372 <th align=leftt>| . $locale->text('Method') . qq|</th>
373 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
374 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
381 if ($form->{report} eq "bwa") {
384 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
385 <td colspan=3>$projectnumber</td>
387 <input type=hidden name=nextsub value=generate_bwa>
391 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
394 <th colspan=1>| . $locale->text('Year') . qq|</th>
395 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
401 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
402 <th align=left>| . $locale->text('Quarterly') . qq|</th>
403 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
406 <td align=right> <input name=duetyp class=radio type=radio value="13"
408 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
410 $checked = "checked";
412 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
416 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
417 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
421 <td align= right> </td>
422 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
423 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
424 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
425 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
429 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
430 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
431 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
432 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
437 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
438 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
439 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
440 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
444 <td colspan=5><hr size=3 noshade></td>
447 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
448 <td align=left colspan=4>| . $locale->text('From') . qq|
451 | . $locale->text('Bis') . qq|
457 <td colspan=5><hr size=3 noshade></td>
460 <th align=leftt>| . $locale->text('Method') . qq|</th>
461 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
462 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
465 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
466 <td><input name=decimalplaces size=3 value="2"></td>
473 if ($form->{report} eq "balance_sheet") {
475 <input type=hidden name=nextsub value=generate_balance_sheet>
477 <th align=right>| . $locale->text('as at') . qq|</th>
482 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
489 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
490 <td><input name=decimalplaces size=3 value="2"></td>
499 <th align=right>| . $locale->text('Method') . qq|</th>
500 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
501 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
505 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
506 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
507 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|
508 <input name=l_accno class=checkbox type=checkbox value=Y> | . $locale->text('Account Number') . qq|</td>
515 if ($form->{report} eq "trial_balance") {
518 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
519 <td colspan=3>$projectnumber</td>
521 <input type=hidden name=nextsub value=generate_trial_balance>
525 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
528 <th colspan=1>| . $locale->text('Year') . qq|</th>
529 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
535 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
536 <th align=left>| . $locale->text('Quarterly') . qq|</th>
537 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
540 <td align=right> <input name=duetyp class=radio type=radio value="13" $checked></td>
541 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
543 $checked = "checked";
545 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
549 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
550 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
554 <td align= right> </td>
555 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
556 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
557 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
558 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
562 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
563 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
564 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
565 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
570 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
571 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
572 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
573 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
577 <td colspan=5><hr size=3 noshade></td>
580 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
581 <td align=left colspan=4>| . $locale->text('From') . qq|
584 | . $locale->text('Bis') . qq|
590 <td colspan=5><hr size=3 noshade></td>
593 <th align=leftt>| . $locale->text('Method') . qq|</th>
594 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
595 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
598 <th align=right colspan=4>| . $locale->text('All Accounts') . qq|</th>
599 <td><input name=all_accounts type=checkbox value=1></td>
602 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
603 <td><input name=decimalplaces size=3 value="2"></td>
610 if ($form->{report} =~ /^tax_/) {
611 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
613 RP->get_taxaccounts(\%myconfig, \%$form);
616 <input type=hidden name=nextsub value=generate_tax_report>
618 <th align=right>| . $locale->text('From') . qq|</th>
619 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
620 <th align=right>| . $locale->text('Bis') . qq|</th>
621 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
624 <th align=right>| . $locale->text('Report for') . qq|</th>
628 $checked = "checked";
629 foreach $ref (@{ $form->{taxaccounts} }) {
632 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
634 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
635 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
642 <input type=hidden name=db value=$form->{db}>
643 <input type=hidden name=sort value=transdate>
648 <th align=right>| . $locale->text('Method') . qq|</th>
649 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
650 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
659 <th align=right>| . $locale->text('Include in Report') . qq|</th>
663 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
664 <td>| . $locale->text('ID') . qq|</td>
665 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
666 <td>| . $locale->text('Invoice') . qq|</td>
667 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
668 <td>| . $locale->text('Date') . qq|</td>
671 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
674 if ($form->{db} eq 'ar') {
675 print $locale->text('Customer');
677 if ($form->{db} eq 'ap') {
678 print $locale->text('Vendor');
682 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
683 <td>| . $locale->text('Amount') . qq|</td>
684 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
685 <td>| . $locale->text('Tax') . qq|</td>
686 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
687 <td>| . $locale->text('Total') . qq|</td>
690 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
691 <td>| . $locale->text('Subtotal') . qq|</td>
700 if ($form->{report} =~ /^nontaxable_/) {
701 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
704 <input type=hidden name=nextsub value=generate_tax_report>
706 <input type=hidden name=db value=$form->{db}>
707 <input type=hidden name=sort value=transdate>
708 <input type=hidden name=report value=$form->{report}>
711 <th align=right>| . $locale->text('From') . qq|</th>
712 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
713 <th align=right>| . $locale->text('Bis') . qq|</th>
714 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
717 <th align=right>| . $locale->text('Method') . qq|</th>
718 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
719 . $locale->text('Accrual') . qq|
720 <input name=method class=radio type=radio value=cash $cash>|
721 . $locale->text('EUR') . qq|</td>
724 <th align=right>| . $locale->text('Include in Report') . qq|</th>
728 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
729 <td>| . $locale->text('ID') . qq|</td>
730 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
731 <td>| . $locale->text('Invoice') . qq|</td>
732 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
733 <td>| . $locale->text('Date') . qq|</td>
736 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
739 if ($form->{db} eq 'ar') {
740 print $locale->text('Customer');
742 if ($form->{db} eq 'ap') {
743 print $locale->text('Vendor');
747 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
748 <td>| . $locale->text('Amount') . qq|</td>
749 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
750 <td>| . $locale->text('Total') . qq|</td>
753 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
754 <td>| . $locale->text('Subtotal') . qq|</td>
763 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
764 if ($form->{report} eq 'ar_aging') {
765 $label = $locale->text('Customer');
766 $form->{vc} = 'customer';
768 $label = $locale->text('Vendor');
769 $form->{vc} = 'vendor';
772 $nextsub = "generate_$form->{report}";
775 $form->all_vc(\%myconfig, $form->{vc},
776 ($form->{vc} eq 'customer') ? "AR" : "AP");
778 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
779 @{ $form->{"all_$form->{vc}"} };
783 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
784 : qq|<input name=$form->{vc} size=35>|;
788 <th align=right>| . $locale->text($label) . qq|</th>
792 <td align=left colspan=4>| . $locale->text('From') . qq|
795 | . $locale->text('Bis') . qq|
800 <input type=hidden name=type value=statement>
801 <input type=hidden name=format value=html>
802 <input type=hidden name=media value=screen>
804 <input type=hidden name=nextsub value=$nextsub>
805 <input type=hidden name=action value=$nextsub>
811 # above action can be removed if there is more than one input field
813 if ($form->{report} =~ /(receipts|payments)$/) {
814 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
816 RP->paymentaccounts(\%myconfig, \%$form);
818 $selection = "<option>\n";
819 foreach $ref (@{ $form->{PR} }) {
820 $paymentaccounts .= "$ref->{accno} ";
821 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
824 chop $paymentaccounts;
827 <input type=hidden name=nextsub value=list_payments>
829 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
830 <td colspan=3><select name=account>$selection</select>
831 <input type=hidden name=paymentaccounts value="$paymentaccounts">
835 <th align=right>| . $locale->text('Reference') . qq|</th>
836 <td colspan=3><input name=reference></td>
839 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
840 <td colspan=3><input name=source></td>
843 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
844 <td colspan=3><input name=memo size=30></td>
847 <th align=right>| . $locale->text('From') . qq|</th>
852 <th align=right>| . $locale->text('Bis') . qq|</th>
859 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
860 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
865 <input type=hidden name=db value=$form->{db}>
866 <input type=hidden name=sort value=transdate>
877 <td><hr size=3 noshade></td>
882 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
890 $lxdebug->leave_sub();
893 sub continue { call_sub($form->{"nextsub"}); }
896 $lxdebug->enter_sub();
898 $auth->assert('report');
902 $form->{project_id} = $form->{project_id_1};
903 if ($form->{projectnumber} && !$form->{project_id}) {
904 $form->{rowcount} = 1;
906 # call this instead of update
907 $form->{update} = $nextsub;
908 $form->{projectnumber_1} = $form->{projectnumber};
910 delete $form->{sort};
913 # if there is one only, assign id
914 $form->{project_id} = $form->{project_id_1};
917 $lxdebug->leave_sub();
920 sub generate_income_statement {
921 $lxdebug->enter_sub();
923 $auth->assert('report');
925 $form->{padding} = " ";
926 $form->{bold} = "<b>";
927 $form->{endbold} = "</b>";
928 $form->{br} = "<br>";
930 if ($form->{reporttype} eq "custom") {
932 #forgotten the year --> thisyear
933 if ($form->{year} !~ m/^\d\d\d\d$/) {
934 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
940 if ($form->{duetyp} eq "13") {
941 $form->{fromdate} = "1.1.$form->{year}";
942 $form->{todate} = "31.12.$form->{year}";
946 if ($form->{duetyp} eq "A") {
947 $form->{fromdate} = "1.1.$form->{year}";
948 $form->{todate} = "31.3.$form->{year}";
950 if ($form->{duetyp} eq "B") {
951 $form->{fromdate} = "1.4.$form->{year}";
952 $form->{todate} = "30.6.$form->{year}";
954 if ($form->{duetyp} eq "C") {
955 $form->{fromdate} = "1.7.$form->{year}";
956 $form->{todate} = "30.9.$form->{year}";
958 if ($form->{duetyp} eq "D") {
959 $form->{fromdate} = "1.10.$form->{year}";
960 $form->{todate} = "31.12.$form->{year}";
965 $form->{duetyp} eq "1" && do {
966 $form->{fromdate} = "1.1.$form->{year}";
967 $form->{todate} = "31.1.$form->{year}";
970 $form->{duetyp} eq "2" && do {
971 $form->{fromdate} = "1.2.$form->{year}";
973 #this works from 1901 to 2099, 1900 and 2100 fail.
974 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
975 $form->{todate} = "$leap.2.$form->{year}";
978 $form->{duetyp} eq "3" && do {
979 $form->{fromdate} = "1.3.$form->{year}";
980 $form->{todate} = "31.3.$form->{year}";
983 $form->{duetyp} eq "4" && do {
984 $form->{fromdate} = "1.4.$form->{year}";
985 $form->{todate} = "30.4.$form->{year}";
988 $form->{duetyp} eq "5" && do {
989 $form->{fromdate} = "1.5.$form->{year}";
990 $form->{todate} = "31.5.$form->{year}";
993 $form->{duetyp} eq "6" && do {
994 $form->{fromdate} = "1.6.$form->{year}";
995 $form->{todate} = "30.6.$form->{year}";
998 $form->{duetyp} eq "7" && do {
999 $form->{fromdate} = "1.7.$form->{year}";
1000 $form->{todate} = "31.7.$form->{year}";
1003 $form->{duetyp} eq "8" && do {
1004 $form->{fromdate} = "1.8.$form->{year}";
1005 $form->{todate} = "31.8.$form->{year}";
1008 $form->{duetyp} eq "9" && do {
1009 $form->{fromdate} = "1.9.$form->{year}";
1010 $form->{todate} = "30.9.$form->{year}";
1013 $form->{duetyp} eq "10" && do {
1014 $form->{fromdate} = "1.10.$form->{year}";
1015 $form->{todate} = "31.10.$form->{year}";
1018 $form->{duetyp} eq "11" && do {
1019 $form->{fromdate} = "1.11.$form->{year}";
1020 $form->{todate} = "30.11.$form->{year}";
1023 $form->{duetyp} eq "12" && do {
1024 $form->{fromdate} = "1.12.$form->{year}";
1025 $form->{todate} = "31.12.$form->{year}";
1031 RP->income_statement(\%myconfig, \%$form);
1033 ($form->{department}) = split /--/, $form->{department};
1036 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1037 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1039 # if there are any dates construct a where
1040 if ($form->{fromdate} || $form->{todate}) {
1042 unless ($form->{todate}) {
1043 $form->{todate} = $form->current_date(\%myconfig);
1046 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1047 $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1049 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1050 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1052 $form->{this_period} = "$shortfromdate\n$shorttodate";
1054 $locale->text('for Period')
1055 . qq|\n$longfromdate |
1056 . $locale->text('Bis')
1060 if ($form->{comparefromdate} || $form->{comparetodate}) {
1061 $longcomparefromdate =
1062 $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1063 $shortcomparefromdate =
1064 $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1066 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1067 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1069 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1071 "\n$longcomparefromdate "
1072 . $locale->text('Bis')
1073 . qq| $longcomparetodate|;
1076 # setup variables for the form
1077 @a = qw(company address businessnumber);
1078 map { $form->{$_} = $myconfig{$_} } @a;
1080 $form->{templates} = $myconfig{templates};
1082 $form->{IN} = "income_statement.html";
1084 $form->parse_template;
1086 $lxdebug->leave_sub();
1089 sub generate_balance_sheet {
1090 $lxdebug->enter_sub();
1092 $auth->assert('report');
1094 $form->{decimalplaces} = $form->{decimalplaces} * 1 || 2;
1095 $form->{padding} = " ";
1096 $form->{bold} = "<b>";
1097 $form->{endbold} = "</b>";
1098 $form->{br} = "<br>";
1100 my $data = RP->balance_sheet(\%myconfig, \%$form);
1102 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1103 $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1105 ($form->{department}) = split /--/, $form->{department};
1107 # define Current Earnings account
1108 $padding = ($form->{l_heading}) ? $form->{padding} : "";
1109 push(@{ $form->{equity_account} }, $padding . $locale->text('Current Earnings'));
1111 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1112 $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1114 $form->{IN} = "balance_sheet.html";
1116 # setup company variables for the form
1117 map { $form->{$_} = $myconfig{$_}; } (qw(company address businessnumber nativecurr));
1119 $form->{templates} = $myconfig{templates};
1122 print $form->parse_html_template('rp/balance_sheet', $data);
1123 # $form->parse_template();
1125 $lxdebug->leave_sub();
1128 sub generate_projects {
1129 $lxdebug->enter_sub();
1131 $auth->assert('report');
1133 &get_project(generate_projects);
1134 $form->{projectnumber} = $form->{projectnumber_1};
1136 $form->{nextsub} = "generate_projects";
1137 $form->{title} = $locale->text('Project Transactions');
1138 RP->trial_balance(\%myconfig, \%$form);
1140 list_accounts('generate_projects');
1142 $lxdebug->leave_sub();
1148 # included links to display transactions for period entered
1149 # added headers and subtotals
1151 sub generate_trial_balance {
1152 $lxdebug->enter_sub();
1154 $auth->assert('report');
1156 if ($form->{reporttype} eq "custom") {
1158 #forgotten the year --> thisyear
1159 if ($form->{year} !~ m/^\d\d\d\d$/) {
1160 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1166 if ($form->{duetyp} eq "13") {
1167 $form->{fromdate} = "1.1.$form->{year}";
1168 $form->{todate} = "31.12.$form->{year}";
1172 if ($form->{duetyp} eq "A") {
1173 $form->{fromdate} = "1.1.$form->{year}";
1174 $form->{todate} = "31.3.$form->{year}";
1176 if ($form->{duetyp} eq "B") {
1177 $form->{fromdate} = "1.4.$form->{year}";
1178 $form->{todate} = "30.6.$form->{year}";
1180 if ($form->{duetyp} eq "C") {
1181 $form->{fromdate} = "1.7.$form->{year}";
1182 $form->{todate} = "30.9.$form->{year}";
1184 if ($form->{duetyp} eq "D") {
1185 $form->{fromdate} = "1.10.$form->{year}";
1186 $form->{todate} = "31.12.$form->{year}";
1191 $form->{duetyp} eq "1" && do {
1192 $form->{fromdate} = "1.1.$form->{year}";
1193 $form->{todate} = "31.1.$form->{year}";
1196 $form->{duetyp} eq "2" && do {
1197 $form->{fromdate} = "1.2.$form->{year}";
1199 #this works from 1901 to 2099, 1900 and 2100 fail.
1200 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1201 $form->{todate} = "$leap.2.$form->{year}";
1204 $form->{duetyp} eq "3" && do {
1205 $form->{fromdate} = "1.3.$form->{year}";
1206 $form->{todate} = "31.3.$form->{year}";
1209 $form->{duetyp} eq "4" && do {
1210 $form->{fromdate} = "1.4.$form->{year}";
1211 $form->{todate} = "30.4.$form->{year}";
1214 $form->{duetyp} eq "5" && do {
1215 $form->{fromdate} = "1.5.$form->{year}";
1216 $form->{todate} = "31.5.$form->{year}";
1219 $form->{duetyp} eq "6" && do {
1220 $form->{fromdate} = "1.6.$form->{year}";
1221 $form->{todate} = "30.6.$form->{year}";
1224 $form->{duetyp} eq "7" && do {
1225 $form->{fromdate} = "1.7.$form->{year}";
1226 $form->{todate} = "31.7.$form->{year}";
1229 $form->{duetyp} eq "8" && do {
1230 $form->{fromdate} = "1.8.$form->{year}";
1231 $form->{todate} = "31.8.$form->{year}";
1234 $form->{duetyp} eq "9" && do {
1235 $form->{fromdate} = "1.9.$form->{year}";
1236 $form->{todate} = "30.9.$form->{year}";
1239 $form->{duetyp} eq "10" && do {
1240 $form->{fromdate} = "1.10.$form->{year}";
1241 $form->{todate} = "31.10.$form->{year}";
1244 $form->{duetyp} eq "11" && do {
1245 $form->{fromdate} = "1.11.$form->{year}";
1246 $form->{todate} = "30.11.$form->{year}";
1249 $form->{duetyp} eq "12" && do {
1250 $form->{fromdate} = "1.12.$form->{year}";
1251 $form->{todate} = "31.12.$form->{year}";
1258 # get for each account initial balance, debits and credits
1259 RP->trial_balance(\%myconfig, \%$form);
1262 $form->{rowcount} = scalar @{ $form->{TB} };
1263 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1266 "accno", "description",
1267 "last_transaction", "soll_eb",
1270 "soll_kumuliert", "haben_kumuliert",
1271 "soll_saldo", "haben_saldo"
1275 my $attachment_basename = $locale->text('trial_balance');
1276 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1278 my @hidden_variables = qw(fromdate todate year cash);
1280 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1283 'accno' => { 'text' => $locale->text('Account Number'), },
1284 'description' => { 'text' => $locale->text('Description'), },
1285 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1286 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1287 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1288 'soll' => { 'text' => $locale->text('Debit'), },
1289 'haben' => { 'text' => $locale->text('Credit'), },
1290 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1291 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1292 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1293 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1298 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1300 map { $column_defs{$_}->{visible} = 1 } @columns;
1302 $report->set_columns(%column_defs);
1303 $report->set_column_order(@columns);
1305 $report->set_export_options('generate_trial_balance', @hidden_variables);
1310 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1311 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1313 $report->set_options('output_format' => 'HTML',
1314 'title' => $form->{title},
1315 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1316 'html_template' => 'rp/html_report_susa',
1317 'pdf_template' => 'rp/html_report_susa',
1319 $report->set_options_from_form();
1321 # add sort and escape callback, this one we use for the add sub
1322 $form->{callback} = $href .= "&sort=$form->{sort}";
1324 # escape callback for href
1325 $callback = $form->escape($href);
1327 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1329 my %totals = map { $_ => 0 } @subtotal_columns;
1331 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1333 foreach $accno (@{ $form->{TB} }) {
1335 $accno->{soll} = $accno->{debit};
1336 $accno->{haben} = $accno->{credit};
1337 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1339 map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1341 map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1345 foreach my $column (@columns) {
1347 'data' => $accno->{$column},
1348 'align' => $column_alignment{$column},
1353 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1355 my $row_set = [ $row ];
1358 $report->add_data($row_set);
1363 $report->add_separator();
1365 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1367 $report->generate_with_headers();
1369 $lxdebug->leave_sub();
1373 sub create_subtotal_row {
1374 $lxdebug->enter_sub();
1376 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1378 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1380 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1382 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1384 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1386 $lxdebug->leave_sub();
1391 sub create_list_accounts_subtotal_row {
1392 $lxdebug->enter_sub();
1394 my ($subtotals, $columns, $fields, $class) = @_;
1396 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1398 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1400 $lxdebug->leave_sub();
1406 $lxdebug->enter_sub();
1411 if ($form->{department}) {
1412 my ($department) = split /--/, $form->{department};
1413 push @options, $locale->text('Department') . " : $department";
1415 if ($form->{projectnumber}) {
1416 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1419 # if there are any dates
1420 if ($form->{fromdate} || $form->{todate}) {
1421 my ($fromdate, $todate);
1423 if ($form->{fromdate}) {
1424 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1426 if ($form->{todate}) {
1427 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1430 push @options, "$fromdate - $todate";
1433 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1436 my @columns = qw(accno description begbalance debit credit endbalance);
1438 'accno' => { 'text' => $locale->text('Account'), },
1439 'description' => { 'text' => $locale->text('Description'), },
1440 'debit' => { 'text' => $locale->text('Debit'), },
1441 'credit' => { 'text' => $locale->text('Credit'), },
1442 'begbalance' => { 'text' => $locale->text('Balance'), },
1443 'endbalance' => { 'text' => $locale->text('Balance'), },
1445 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1447 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1449 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1451 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1453 $report->set_options('top_info_text' => join("\n", @options),
1454 'output_format' => 'HTML',
1455 'title' => $form->{title},
1456 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1457 'std_column_visibility' => 1,
1459 $report->set_options_from_form();
1461 $report->set_columns(%column_defs);
1462 $report->set_column_order(@columns);
1464 $report->set_export_options($action, @hidden_variables);
1466 my @totals_columns = qw(credit debit begbalance endbalance);
1467 my %subtotals = map { $_ => 0 } @totals_columns;
1468 my %totals = map { $_ => 0 } @totals_columns;
1469 my $found_heading = 0;
1470 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1472 # sort the whole thing by account numbers and display
1473 foreach my $idx (0 .. scalar(@tb) - 1) {
1474 my $ref = $tb[$idx];
1475 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1477 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1479 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1481 if ($ref->{charttype} eq 'H') {
1482 next unless ($form->{l_heading});
1484 %subtotals = map { $_ => 0 } @totals_columns;
1486 $row->{description}->{class} = 'listheading';
1487 $row->{description}->{data} = $ref->{description};
1489 $report->add_data($row);
1494 foreach (qw(debit credit)) {
1495 $subtotals{$_} += $ref->{$_};
1496 $totals{$_} += $ref->{$_};
1499 $subtotals{begbalance} += $ref->{balance} * $ml;
1500 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1502 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1503 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1505 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1506 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1508 $report->add_data($row);
1510 if ($form->{l_heading} && $found_heading &&
1511 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1512 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1516 $report->add_separator();
1518 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1520 $report->generate_with_headers();
1522 $lxdebug->leave_sub();
1525 sub generate_ar_aging {
1526 $lxdebug->enter_sub();
1528 $auth->assert('general_ledger');
1531 ($form->{customer}) = split(/--/, $form->{customer});
1533 $form->{ct} = "customer";
1534 $form->{arap} = "ar";
1536 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1538 RP->aging(\%myconfig, \%$form);
1541 $lxdebug->leave_sub();
1544 sub generate_ap_aging {
1545 $lxdebug->enter_sub();
1547 $auth->assert('general_ledger');
1550 ($form->{vendor}) = split(/--/, $form->{vendor});
1552 $form->{ct} = "vendor";
1553 $form->{arap} = "ap";
1555 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1557 RP->aging(\%myconfig, \%$form);
1560 $lxdebug->leave_sub();
1563 sub create_aging_subtotal_row {
1564 $lxdebug->enter_sub();
1566 my ($subtotals, $columns, $periods, $class) = @_;
1568 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1570 foreach (@{ $periods }) {
1571 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1572 $subtotals->{$_} = 0;
1575 $lxdebug->leave_sub();
1581 $lxdebug->enter_sub();
1583 $auth->assert('general_ledger');
1585 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1587 my @columns = qw(statement ct invnumber transdate duedate amount open);
1590 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1591 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1592 'invnumber' => { 'text' => $locale->text('Invoice'), },
1593 'transdate' => { 'text' => $locale->text('Date'), },
1594 'duedate' => { 'text' => $locale->text('Due'), },
1595 'amount' => { 'text' => $locale->text('Amount'), },
1596 'open' => { 'text' => $locale->text('Open'), },
1599 my %column_alignment = ('statement' => 'center',
1600 map { $_ => 'right' } qw(open amount));
1602 $report->set_options('std_column_visibility' => 1);
1603 $report->set_columns(%column_defs);
1604 $report->set_column_order(@columns);
1606 my @hidden_variables = qw(todate customer vendor arap title ct);
1607 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1610 my $attachment_basename;
1612 if ($form->{department}) {
1613 my ($department) = split /--/, $form->{department};
1614 push @options, $locale->text('Department') . " : $department";
1615 $form->{callback} .= "&department=" . E($department);
1618 if (($form->{arap} eq 'ar') && $form->{customer}) {
1619 push @options, $form->{customer};
1620 $attachment_basename = $locale->text('ar_aging_list');
1621 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1624 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1625 push @options, $form->{vendor};
1626 $attachment_basename = $locale->text('ap_aging_list');
1627 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1630 if ($form->{fromdate}) {
1631 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1633 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1636 my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1638 $report->set_options('top_info_text' => join("\n", @options),
1639 'output_format' => 'HTML',
1640 'title' => $form->{title},
1641 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1644 my $previous_ctid = 0;
1646 my @periods = qw(open amount);
1647 my %subtotals = map { $_ => 0 } @periods;
1648 my %totals = map { $_ => 0 } @periods;
1650 foreach $ref (@{ $form->{AG} }) {
1651 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1652 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1655 foreach my $key (@periods) {
1656 $subtotals{$key} += $ref->{"$key"};
1657 $totals{$key} += $ref->{"$key"};
1658 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1663 foreach my $column (@columns) {
1665 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1666 'align' => $column_alignment{$column},
1667 'valign' => $column eq 'statement' ? 'center' : '',
1671 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1673 if ($previous_ctid != $ref->{ctid}) {
1674 $row->{statement}->{raw_data} =
1675 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1676 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1677 $row->{ct}->{data} = $ref->{name};
1682 $previous_ctid = $ref->{ctid};
1684 $report->add_data($row);
1687 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1689 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1691 if ($form->{arap} eq 'ar') {
1692 $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1693 $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1694 'PRINT_OPTIONS' => print_options(inline => 1), });
1695 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1696 'raw_bottom_info_text' => $raw_bottom_info_text);
1699 $report->set_options_from_form();
1701 $report->generate_with_headers();
1703 $lxdebug->leave_sub();
1707 $lxdebug->enter_sub();
1709 RP->aging(\%myconfig, \%$form);
1711 map { $_->{checked} = "checked" } @{ $form->{AG} };
1715 $lxdebug->leave_sub();
1719 $lxdebug->enter_sub();
1721 $auth->assert('general_ledger');
1723 # get name and email addresses
1724 for $i (1 .. $form->{rowcount}) {
1725 if ($form->{"statement_$i"}) {
1726 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1727 RP->get_customer(\%myconfig, \%$form);
1733 $form->error($locale->text('Nothing selected!')) unless $selected;
1735 if ($myconfig{role} eq 'admin') {
1737 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1738 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1742 $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1744 $form->{media} = "email";
1751 <form method=post action=$form->{script}>
1757 <tr height="5"></tr>
1762 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1763 <td><input name=email size=30 value="$form->{email}"></td>
1764 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1765 <td><input name=cc size=30 value="$form->{cc}"></td>
1768 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1769 <td><input name=subject size=30 value="$form->{subject}"></td>
1779 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1782 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1793 map { delete $form->{$_} }
1794 qw(action email cc bcc subject message type sendmode format header);
1796 # save all other variables
1797 foreach $key (keys %$form) {
1798 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1799 $form->{$key} =~ s/\"/"/g;
1800 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1807 <td><hr size=3 noshade></td>
1811 <input type=hidden name=nextsub value=send_email>
1814 <input name=action class=submit type=submit value="|
1815 . $locale->text('Continue') . qq|">
1822 $lxdebug->leave_sub();
1826 $lxdebug->enter_sub();
1828 $auth->assert('general_ledger');
1830 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1831 unless $form->{subject};
1833 RP->aging(\%myconfig, \%$form);
1835 $form->{"statement_1"} = 1;
1837 $form->{media} = 'email';
1840 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1842 $lxdebug->leave_sub();
1846 $lxdebug->enter_sub();
1848 $auth->assert('general_ledger');
1850 if ($form->{media} eq 'printer') {
1851 $form->error($locale->text('Select postscript or PDF!'))
1852 if ($form->{format} !~ /(postscript|pdf)/);
1855 for $i (1 .. $form->{rowcount}) {
1856 if ($form->{"statement_$i"}) {
1857 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1863 $form->error($locale->text('Nothing selected!')) unless $selected;
1865 if ($form->{media} eq 'printer') {
1866 $form->{"$form->{ct}_id"} = "";
1868 $form->{"statement_1"} = 1;
1871 RP->aging(\%myconfig, \%$form);
1875 $form->redirect($locale->text('Statements sent to printer!'))
1876 if ($form->{media} eq 'printer');
1878 $lxdebug->leave_sub();
1882 $lxdebug->enter_sub();
1884 $auth->assert('general_ledger');
1886 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1888 $form->{templates} = "$myconfig{templates}";
1890 my $suffix = "html";
1891 my $attachment_suffix = "html";
1892 if ($form->{format} eq 'postscript') {
1893 $form->{postscript} = 1;
1895 $attachment_suffix = "ps";
1896 } elsif ($form->{format} eq 'pdf') {
1899 $attachment_suffix = "pdf";
1902 $form->{IN} = "$form->{type}.$suffix";
1903 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1905 # Save $form->{email} because it will be overwritten.
1906 $form->{EMAIL_RECIPIENT} = $form->{email};
1909 while (@{ $form->{AG} }) {
1911 $ref = shift @{ $form->{AG} };
1913 if ($ctid != $ref->{ctid}) {
1915 $ctid = $ref->{ctid};
1918 if ($form->{"statement_$i"}) {
1921 (name, street, zipcode, city, country, contact, email,
1922 "$form->{ct}phone", "$form->{ct}fax");
1923 map { $form->{$_} = $ref->{$_} } @a;
1925 $form->{ $form->{ct} } = $form->{name};
1926 $form->{"$form->{ct}_id"} = $ref->{ctid};
1928 map { $form->{$_} = () } qw(invnumber invdate duedate);
1930 foreach $item (qw(c0 c30 c60 c90)) {
1931 $form->{$item} = ();
1932 $form->{"${item}total"} = 0;
1935 &statement_details($ref);
1939 if (scalar(@{ $form->{AG} }) > 0) {
1941 # one or more left to go
1942 if ($ctid == $form->{AG}->[0]->{ctid}) {
1943 $ref = shift @{ $form->{AG} };
1944 &statement_details($ref);
1947 $ref = scalar(@{ $form->{AG} });
1953 # set initial ref to 0
1960 $form->{"${_}total"} =
1961 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1962 } (c0, c30, c60, c90, "");
1964 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1965 $form->{attachment_filename} =~ s/\s+/_/g;
1967 $form->parse_template(\%myconfig, $userspath);
1972 # saving the history
1973 if(!exists $form->{addition} && $form->{id} ne "") {
1974 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1975 $form->{addition} = "PRINTED";
1976 $form->{what_done} = $form->{type};
1977 $form->save_history($form->dbconnect(\%myconfig));
1979 # /saving the history
1980 $lxdebug->leave_sub();
1983 sub statement_details {
1984 $lxdebug->enter_sub();
1986 $auth->assert('general_ledger');
1990 push @{ $form->{invnumber} }, $ref->{invnumber};
1991 push @{ $form->{invdate} }, $ref->{transdate};
1992 push @{ $form->{duedate} }, $ref->{duedate};
1994 foreach $item (qw(c0 c30 c60 c90)) {
1995 if ($ref->{exchangerate} * 1) {
1997 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
1999 $form->{"${item}total"} += $ref->{$item};
2000 $form->{total} += $ref->{$item};
2001 push @{ $form->{$item} },
2002 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2005 $lxdebug->leave_sub();
2008 sub generate_tax_report {
2009 $lxdebug->enter_sub();
2011 $auth->assert('report');
2013 RP->tax_report(\%myconfig, \%$form);
2015 $descvar = "$form->{accno}_description";
2016 $description = $form->escape($form->{$descvar});
2017 $ratevar = "$form->{accno}_rate";
2019 $department = $form->escape($form->{department});
2023 "$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}";
2025 # construct callback
2026 $description = $form->escape($form->{$descvar}, 1);
2027 $department = $form->escape($form->{department}, 1);
2029 "$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}";
2031 $title = $form->escape($form->{title});
2032 $href .= "&title=$title";
2033 $title = $form->escape($form->{title}, 1);
2034 $callback .= "&title=$title";
2036 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2039 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2041 foreach $item (@columns) {
2042 if ($form->{"l_$item"} eq "Y") {
2043 push @column_index, $item;
2045 # add column to href and callback
2046 $callback .= "&l_$item=Y";
2047 $href .= "&l_$item=Y";
2051 if ($form->{l_subtotal} eq 'Y') {
2052 $callback .= "&l_subtotal=Y";
2053 $href .= "&l_subtotal=Y";
2056 if ($form->{department}) {
2057 ($department) = split /--/, $form->{department};
2058 $option = $locale->text('Department') . " : $department";
2061 # if there are any dates
2062 if ($form->{fromdate} || $form->{todate}) {
2063 if ($form->{fromdate}) {
2064 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2066 if ($form->{todate}) {
2067 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2070 $form->{period} = "$fromdate - $todate";
2073 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2076 if ($form->{db} eq 'ar') {
2077 $name = $locale->text('Customer');
2081 if ($form->{db} eq 'ap') {
2082 $name = $locale->text('Vendor');
2087 $option .= "<br>" if $option;
2088 $option .= "$form->{period}";
2090 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2091 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2092 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2093 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2094 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2095 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2097 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2106 <th class=listtop colspan=$colspan>$form->{title}</th>
2108 <tr height="5"></tr>
2115 <tr class=listheading>
2118 map { print "$column_header{$_}\n" } @column_index;
2124 # add sort and escape callback
2125 $callback = $form->escape($callback . "&sort=$form->{sort}");
2127 if (@{ $form->{TR} }) {
2128 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2131 foreach $ref (@{ $form->{TR} }) {
2133 $module = ($ref->{invoice}) ? $invoice : $arap;
2135 if ($form->{l_subtotal} eq 'Y') {
2136 if ($sameitem ne $ref->{ $form->{sort} }) {
2138 $sameitem = $ref->{ $form->{sort} };
2142 $totalnetamount += $ref->{netamount};
2143 $totaltax += $ref->{tax};
2144 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2146 $subtotalnetamount += $ref->{netamount};
2147 $subtotaltax += $ref->{tax};
2150 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2151 } qw(netamount tax amount);
2153 $column_data{id} = qq|<td>$ref->{id}</td>|;
2154 $column_data{invnumber} =
2155 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2156 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2157 $column_data{name} = qq|<td>$ref->{name} </td>|;
2159 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2160 qw(netamount tax amount);
2165 <tr class=listrow$i>
2168 map { print "$column_data{$_}\n" } @column_index;
2176 if ($form->{l_subtotal} eq 'Y') {
2180 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2184 <tr class=listtotal>
2188 $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2190 $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2191 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2193 $column_data{netamount} =
2194 qq|<th class=listtotal align=right>$totalnetamount</th>|;
2195 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2196 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2198 map { print "$column_data{$_}\n" } @column_index;
2206 <td><hr size=3 noshade></td>
2214 $lxdebug->leave_sub();
2218 $lxdebug->enter_sub();
2220 map { $column_data{$_} = "<td> </td>" } @column_index;
2222 $subtotalnetamount =
2223 $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
2224 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
2226 $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2229 $column_data{netamount} =
2230 "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2231 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2232 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2234 $subtotalnetamount = 0;
2238 <tr class=listsubtotal>
2240 map { print "\n$column_data{$_}" } @column_index;
2246 $lxdebug->leave_sub();
2250 $lxdebug->enter_sub();
2252 $auth->assert('cash');
2254 if ($form->{account}) {
2255 ($form->{paymentaccounts}) = split /--/, $form->{account};
2257 if ($form->{department}) {
2258 ($department, $form->{department_id}) = split /--/, $form->{department};
2259 $option = $locale->text('Department') . " : $department";
2262 report_generator_set_default_sort('transdate', 1);
2264 RP->payments(\%myconfig, \%$form);
2266 my @hidden_variables = qw(account title department reference source memo fromdate todate
2267 fx_transaction db prepayment paymentaccounts sort);
2269 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2270 $form->{callback} = $href;
2272 my @columns = qw(transdate invnumber name paid source memo);
2274 'name' => { 'text' => $locale->text('Description'), },
2275 'invnumber' => { 'text' => $locale->text('Reference'), },
2276 'transdate' => { 'text' => $locale->text('Date'), },
2277 'paid' => { 'text' => $locale->text('Amount'), },
2278 'source' => { 'text' => $locale->text('Source'), },
2279 'memo' => { 'text' => $locale->text('Memo'), },
2281 my %column_alignment = ('paid' => 'right');
2283 foreach my $name (grep { $_ ne 'paid' } @columns) {
2284 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2285 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2289 if ($form->{fromdate}) {
2290 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2292 if ($form->{todate}) {
2293 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2296 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2298 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2300 $report->set_options('top_info_text' => join("\n", @options),
2301 'output_format' => 'HTML',
2302 'title' => $form->{title},
2303 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2304 'std_column_visibility' => 1,
2306 $report->set_options_from_form();
2308 $report->set_columns(%column_defs);
2309 $report->set_column_order(@columns);
2311 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2313 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2317 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2318 next unless @{ $form->{ $ref->{id} } };
2320 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2322 my $subtotal_paid = 0;
2324 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2325 my $module = $payment->{module};
2326 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2327 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2329 $subtotal_paid += $payment->{paid};
2330 $total_paid += $payment->{paid};
2332 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2336 foreach my $column (@columns) {
2338 'data' => $payment->{$column},
2339 'align' => $column_alignment{$column},
2343 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2345 $report->add_data($row);
2348 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2350 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2352 'class' => 'listsubtotal',
2355 $report->add_data($row);
2358 $report->add_separator();
2360 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2362 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2364 'class' => 'listtotal',
2367 $report->add_data($row);
2369 $report->generate_with_headers();
2371 $lxdebug->leave_sub();
2375 $lxdebug->enter_sub();
2377 my ($dont_print) = @_;
2379 $form->{sendmode} = "attachment";
2382 $form->{"format"} ? $form->{"format"} :
2383 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2387 $form->{"copies"} ? $form->{"copies"} :
2388 $myconfig{"copies"} ? $myconfig{"copies"} :
2391 $form->{PD}{ $form->{type} } = "selected";
2392 $form->{DF}{ $form->{format} } = "selected";
2393 $form->{OP}{ $form->{media} } = "selected";
2394 $form->{SM}{ $form->{sendmode} } = "selected";
2397 <option value=statement $form->{PD}{statement}>|
2398 . $locale->text('Statement');
2400 if ($form->{media} eq 'email') {
2402 <option value=attachment $form->{SM}{attachment}>|
2403 . $locale->text('Attachment') . qq|
2404 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2407 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2408 if ($myconfig{printer} && $latex_templates) {
2410 <option value=printer $form->{OP}{printer}>|
2411 . $locale->text('Printer');
2415 if ($latex_templates) {
2417 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2418 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2419 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2425 <td><select name=type>$type</select></td>
2426 <td><select name=format>$format</select></td>
2427 <td><select name=media>$media</select></td>
2430 if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2432 <td>| . $locale->text('Copies') . qq|
2433 <input name=copies size=2 value=$form->{copies}></td>
2442 print $output unless $dont_print;
2444 $lxdebug->leave_sub();
2450 $lxdebug->enter_sub();
2452 $auth->assert('report');
2454 $form->{padding} = " ";
2455 $form->{bold} = "<b>";
2456 $form->{endbold} = "</b>";
2457 $form->{br} = "<br>";
2459 if ($form->{reporttype} eq "custom") {
2461 #forgotten the year --> thisyear
2462 if ($form->{year} !~ m/^\d\d\d\d$/) {
2463 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2469 if ($form->{duetyp} eq "13") {
2470 $form->{fromdate} = "1.1.$form->{year}";
2471 $form->{todate} = "31.12.$form->{year}";
2472 $form->{comparefromdate} = "1.01.$form->{year}";
2473 $form->{comparetodate} = "31.12.$form->{year}";
2477 if ($form->{duetyp} eq "A") {
2478 $form->{fromdate} = "1.1.$form->{year}";
2479 $form->{todate} = "31.3.$form->{year}";
2480 $form->{comparefromdate} = "1.01.$form->{year}";
2481 $form->{comparetodate} = "31.03.$form->{year}";
2483 if ($form->{duetyp} eq "B") {
2484 $form->{fromdate} = "1.4.$form->{year}";
2485 $form->{todate} = "30.6.$form->{year}";
2486 $form->{comparefromdate} = "1.01.$form->{year}";
2487 $form->{comparetodate} = "30.06.$form->{year}";
2489 if ($form->{duetyp} eq "C") {
2490 $form->{fromdate} = "1.7.$form->{year}";
2491 $form->{todate} = "30.9.$form->{year}";
2492 $form->{comparefromdate} = "1.01.$form->{year}";
2493 $form->{comparetodate} = "30.09.$form->{year}";
2495 if ($form->{duetyp} eq "D") {
2496 $form->{fromdate} = "1.10.$form->{year}";
2497 $form->{todate} = "31.12.$form->{year}";
2498 $form->{comparefromdate} = "1.01.$form->{year}";
2499 $form->{comparetodate} = "31.12.$form->{year}";
2504 $form->{duetyp} eq "1" && do {
2505 $form->{fromdate} = "1.1.$form->{year}";
2506 $form->{todate} = "31.1.$form->{year}";
2507 $form->{comparefromdate} = "1.01.$form->{year}";
2508 $form->{comparetodate} = "31.01.$form->{year}";
2511 $form->{duetyp} eq "2" && do {
2512 $form->{fromdate} = "1.2.$form->{year}";
2514 #this works from 1901 to 2099, 1900 and 2100 fail.
2515 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2516 $form->{todate} = "$leap.2.$form->{year}";
2517 $form->{comparefromdate} = "1.01.$form->{year}";
2518 $form->{comparetodate} = "$leap.02.$form->{year}";
2521 $form->{duetyp} eq "3" && do {
2522 $form->{fromdate} = "1.3.$form->{year}";
2523 $form->{todate} = "31.3.$form->{year}";
2524 $form->{comparefromdate} = "1.01.$form->{year}";
2525 $form->{comparetodate} = "31.03.$form->{year}";
2528 $form->{duetyp} eq "4" && do {
2529 $form->{fromdate} = "1.4.$form->{year}";
2530 $form->{todate} = "30.4.$form->{year}";
2531 $form->{comparefromdate} = "1.01.$form->{year}";
2532 $form->{comparetodate} = "30.04.$form->{year}";
2535 $form->{duetyp} eq "5" && do {
2536 $form->{fromdate} = "1.5.$form->{year}";
2537 $form->{todate} = "31.5.$form->{year}";
2538 $form->{comparefromdate} = "1.01.$form->{year}";
2539 $form->{comparetodate} = "31.05.$form->{year}";
2542 $form->{duetyp} eq "6" && do {
2543 $form->{fromdate} = "1.6.$form->{year}";
2544 $form->{todate} = "30.6.$form->{year}";
2545 $form->{comparefromdate} = "1.01.$form->{year}";
2546 $form->{comparetodate} = "30.06.$form->{year}";
2549 $form->{duetyp} eq "7" && do {
2550 $form->{fromdate} = "1.7.$form->{year}";
2551 $form->{todate} = "31.7.$form->{year}";
2552 $form->{comparefromdate} = "1.01.$form->{year}";
2553 $form->{comparetodate} = "31.07.$form->{year}";
2556 $form->{duetyp} eq "8" && do {
2557 $form->{fromdate} = "1.8.$form->{year}";
2558 $form->{todate} = "31.8.$form->{year}";
2559 $form->{comparefromdate} = "1.01.$form->{year}";
2560 $form->{comparetodate} = "31.08.$form->{year}";
2563 $form->{duetyp} eq "9" && do {
2564 $form->{fromdate} = "1.9.$form->{year}";
2565 $form->{todate} = "30.9.$form->{year}";
2566 $form->{comparefromdate} = "1.01.$form->{year}";
2567 $form->{comparetodate} = "30.09.$form->{year}";
2570 $form->{duetyp} eq "10" && do {
2571 $form->{fromdate} = "1.10.$form->{year}";
2572 $form->{todate} = "31.10.$form->{year}";
2573 $form->{comparefromdate} = "1.01.$form->{year}";
2574 $form->{comparetodate} = "31.10.$form->{year}";
2577 $form->{duetyp} eq "11" && do {
2578 $form->{fromdate} = "1.11.$form->{year}";
2579 $form->{todate} = "30.11.$form->{year}";
2580 $form->{comparefromdate} = "1.01.$form->{year}";
2581 $form->{comparetodate} = "30.11.$form->{year}";
2584 $form->{duetyp} eq "12" && do {
2585 $form->{fromdate} = "1.12.$form->{year}";
2586 $form->{todate} = "31.12.$form->{year}";
2587 $form->{comparefromdate} = "1.01.$form->{year}";
2588 $form->{comparetodate} = "31.12.$form->{year}";
2593 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2594 $form->{fromdate} = "${dd}.${mm}.${yy}";
2595 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2596 $form->{todate} = "${dd}.${mm}.${yy}";
2597 $form->{comparefromdate} = "01.01.$yy";
2598 $form->{comparetodate} = $form->{todate};
2601 RP->bwa(\%myconfig, \%$form);
2603 ($form->{department}) = split /--/, $form->{department};
2606 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2607 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2609 # if there are any dates construct a where
2610 if ($form->{fromdate} || $form->{todate}) {
2612 unless ($form->{todate}) {
2613 $form->{todate} = $form->current_date(\%myconfig);
2616 my %germandate = ("dateformat" => "dd.mm.yyyy");
2618 $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2619 $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2621 $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2622 $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2624 $form->{this_period} = "$shortfromdate\n$shorttodate";
2626 $locale->text('for Period')
2627 . qq|\n$longfromdate |
2628 . $locale->text('bis')
2632 # setup variables for the form
2633 @a = qw(company address businessnumber);
2634 map { $form->{$_} = $myconfig{$_} } @a;
2635 $form->{templates} = $myconfig{templates};
2637 $form->{IN} = "bwa.html";
2639 $form->parse_template;
2641 $lxdebug->leave_sub();