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";
145 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} };
150 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
151 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
153 | if $form->{selectdepartment};
155 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
158 my %project_labels = ();
159 my @project_values = ("");
160 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
161 push(@project_values, $item->{"id"});
162 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
166 NTI($cgi->popup_menu('-name' => "project_id",
167 '-values' => \@project_values,
168 '-labels' => \%project_labels));
170 # use JavaScript Calendar or not
171 $form->{jsscript} = 1;
173 if ($form->{report} eq "balance_sheet") {
174 $name_1 = "asofdate";
176 $value_1 = "$form->{asofdate}";
177 $trigger_1 = "trigger1";
178 $name_2 = "compareasofdate";
179 $id_2 = "compareasofdate";
180 $value_2 = "$form->{compareasofdate}";
181 $trigger_2 = "trigger2";
182 } elsif ($form->{report} =~ /(receipts|payments)$/) {
183 $name_1 = "fromdate";
185 $value_1 = "$form->{fromdate}";
186 $trigger_1 = "trigger1";
190 $trigger_2 = "trigger2";
191 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
192 $name_1 = "fromdate";
194 $value_1 = "$form->{fromdate}";
195 $trigger_1 = "trigger1";
199 $trigger_2 = "trigger2";
202 $name_1 = "fromdate";
204 $value_1 = "$form->{fromdate}";
205 $trigger_1 = "trigger1";
209 $trigger_2 = "trigger2";
212 # with JavaScript Calendar
213 if ($form->{jsscript}) {
215 $button1 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
216 $button1_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|>|;
219 $jsscript = Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
221 $button1 = qq| <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
222 $button1_2 = qq| <input type=button name=$name_1 id="$trigger_1" value=| . $locale->text('button') . qq|>|;
223 $button2 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
224 $button2_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|> |;
227 $jsscript = Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1", "$name_2", "BL", "$trigger_2");
231 # without JavaScript Calendar
233 $button1 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
235 $button1 = qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
236 $button2 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
239 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
241 $onload = qq|focus()|;
242 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
243 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
245 <body onLoad="$onload">
247 <form method=post action=$form->{script}>
249 <input type=hidden name=title value="$form->{title}">
253 <th class=listtop>$form->{title}</th>
262 if ($form->{report} eq "projects") {
265 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
266 <td colspan=5><input name=projectnumber size=25</td>
268 <input type=hidden name=nextsub value=generate_projects>
270 <th align=right>| . $locale->text('From') . qq|</th>
273 <th align=right>| . $locale->text('Bis') . qq|</th>
284 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
285 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
286 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
293 if ($form->{report} eq "income_statement") {
296 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
297 <td colspan=3>$projectnumber</td>
299 <input type=hidden name=nextsub value=generate_income_statement>
303 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
306 <th colspan=1>| . $locale->text('Year') . qq|</th>
307 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
313 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
314 <th align=left>| . $locale->text('Quarterly') . qq|</th>
315 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
318 <td align=right> <input name=duetyp class=radio type=radio value="13" "checked"></td>
319 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
323 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
327 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
328 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
332 <td align= right> </td>
333 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
334 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
335 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
336 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
340 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
341 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
342 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
343 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
348 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
349 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
350 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
351 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
355 <td colspan=5><hr size=3 noshade></td>
358 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
359 <td align=left colspan=4>| . $locale->text('From') . qq|
362 | . $locale->text('Bis') . qq|
368 <td colspan=5><hr size=3 noshade></td>
371 <th align=leftt>| . $locale->text('Method') . qq|</th>
372 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
373 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
380 if ($form->{report} eq "bwa") {
383 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
384 <td colspan=3>$projectnumber</td>
386 <input type=hidden name=nextsub value=generate_bwa>
390 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
393 <th colspan=1>| . $locale->text('Year') . qq|</th>
394 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
400 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
401 <th align=left>| . $locale->text('Quarterly') . qq|</th>
402 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
405 <td align=right> <input name=duetyp class=radio type=radio value="13"
407 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
409 $checked = "checked";
411 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
415 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
416 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
420 <td align= right> </td>
421 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
422 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
423 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
424 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
428 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
429 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
430 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
431 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
436 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
437 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
438 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
439 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
443 <td colspan=5><hr size=3 noshade></td>
446 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
447 <td align=left colspan=4>| . $locale->text('From') . qq|
450 | . $locale->text('Bis') . qq|
456 <td colspan=5><hr size=3 noshade></td>
459 <th align=leftt>| . $locale->text('Method') . qq|</th>
460 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
461 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
464 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
465 <td><input name=decimalplaces size=3 value="2"></td>
472 if ($form->{report} eq "balance_sheet") {
474 <input type=hidden name=nextsub value=generate_balance_sheet>
476 <th align=right>| . $locale->text('as at') . qq|</th>
481 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
488 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
489 <td><input name=decimalplaces size=3 value="2"></td>
498 <th align=right>| . $locale->text('Method') . qq|</th>
499 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
500 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
504 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
505 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
506 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|
507 <input name=l_accno class=checkbox type=checkbox value=Y> | . $locale->text('Account Number') . qq|</td>
514 if ($form->{report} eq "trial_balance") {
517 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
518 <td colspan=3>$projectnumber</td>
520 <input type=hidden name=nextsub value=generate_trial_balance>
524 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
527 <th colspan=1>| . $locale->text('Year') . qq|</th>
528 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
534 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
535 <th align=left>| . $locale->text('Quarterly') . qq|</th>
536 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
539 <td align=right> <input name=duetyp class=radio type=radio value="13" $checked></td>
540 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
542 $checked = "checked";
544 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
548 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
549 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
553 <td align= right> </td>
554 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
555 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
556 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
557 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
561 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
562 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
563 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
564 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
569 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
570 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
571 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
572 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
576 <td colspan=5><hr size=3 noshade></td>
579 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
580 <td align=left colspan=4>| . $locale->text('From') . qq|
583 | . $locale->text('Bis') . qq|
589 <td colspan=5><hr size=3 noshade></td>
592 <th align=leftt>| . $locale->text('Method') . qq|</th>
593 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
594 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
597 <th align=right colspan=4>| . $locale->text('All Accounts') . qq|</th>
598 <td><input name=all_accounts type=checkbox value=1></td>
601 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
602 <td><input name=decimalplaces size=3 value="2"></td>
609 if ($form->{report} =~ /^tax_/) {
610 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
612 RP->get_taxaccounts(\%myconfig, \%$form);
615 <input type=hidden name=nextsub value=generate_tax_report>
617 <th align=right>| . $locale->text('From') . qq|</th>
618 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
619 <th align=right>| . $locale->text('Bis') . qq|</th>
620 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
623 <th align=right>| . $locale->text('Report for') . qq|</th>
627 $checked = "checked";
628 foreach $ref (@{ $form->{taxaccounts} }) {
631 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
633 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
634 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
641 <input type=hidden name=db value=$form->{db}>
642 <input type=hidden name=sort value=transdate>
647 <th align=right>| . $locale->text('Method') . qq|</th>
648 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
649 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
658 <th align=right>| . $locale->text('Include in Report') . qq|</th>
662 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
663 <td>| . $locale->text('ID') . qq|</td>
664 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
665 <td>| . $locale->text('Invoice') . qq|</td>
666 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
667 <td>| . $locale->text('Date') . qq|</td>
670 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
673 if ($form->{db} eq 'ar') {
674 print $locale->text('Customer');
676 if ($form->{db} eq 'ap') {
677 print $locale->text('Vendor');
681 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
682 <td>| . $locale->text('Amount') . qq|</td>
683 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
684 <td>| . $locale->text('Tax') . qq|</td>
685 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
686 <td>| . $locale->text('Total') . qq|</td>
689 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
690 <td>| . $locale->text('Subtotal') . qq|</td>
699 if ($form->{report} =~ /^nontaxable_/) {
700 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
703 <input type=hidden name=nextsub value=generate_tax_report>
705 <input type=hidden name=db value=$form->{db}>
706 <input type=hidden name=sort value=transdate>
707 <input type=hidden name=report value=$form->{report}>
710 <th align=right>| . $locale->text('From') . qq|</th>
711 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
712 <th align=right>| . $locale->text('Bis') . qq|</th>
713 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
716 <th align=right>| . $locale->text('Method') . qq|</th>
717 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
718 . $locale->text('Accrual') . qq|
719 <input name=method class=radio type=radio value=cash $cash>|
720 . $locale->text('EUR') . qq|</td>
723 <th align=right>| . $locale->text('Include in Report') . qq|</th>
727 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
728 <td>| . $locale->text('ID') . qq|</td>
729 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
730 <td>| . $locale->text('Invoice') . qq|</td>
731 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
732 <td>| . $locale->text('Date') . qq|</td>
735 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
738 if ($form->{db} eq 'ar') {
739 print $locale->text('Customer');
741 if ($form->{db} eq 'ap') {
742 print $locale->text('Vendor');
746 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
747 <td>| . $locale->text('Amount') . qq|</td>
748 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
749 <td>| . $locale->text('Total') . qq|</td>
752 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
753 <td>| . $locale->text('Subtotal') . qq|</td>
762 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
763 if ($form->{report} eq 'ar_aging') {
764 $label = $locale->text('Customer');
765 $form->{vc} = 'customer';
767 $label = $locale->text('Vendor');
768 $form->{vc} = 'vendor';
771 $nextsub = "generate_$form->{report}";
774 $form->all_vc(\%myconfig, $form->{vc},
775 ($form->{vc} eq 'customer') ? "AR" : "AP");
777 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
778 @{ $form->{"all_$form->{vc}"} };
782 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
783 : qq|<input name=$form->{vc} size=35>|;
787 <th align=right>| . $locale->text($label) . qq|</th>
791 <td align=left colspan=4>| . $locale->text('From') . qq|
794 | . $locale->text('Bis') . qq|
799 <input type=hidden name=type value=statement>
800 <input type=hidden name=format value=html>
801 <input type=hidden name=media value=screen>
803 <input type=hidden name=nextsub value=$nextsub>
804 <input type=hidden name=action value=$nextsub>
810 # above action can be removed if there is more than one input field
812 if ($form->{report} =~ /(receipts|payments)$/) {
813 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
815 RP->paymentaccounts(\%myconfig, \%$form);
817 $selection = "<option>\n";
818 foreach $ref (@{ $form->{PR} }) {
819 $paymentaccounts .= "$ref->{accno} ";
820 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
823 chop $paymentaccounts;
826 <input type=hidden name=nextsub value=list_payments>
828 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
829 <td colspan=3><select name=account>$selection</select>
830 <input type=hidden name=paymentaccounts value="$paymentaccounts">
834 <th align=right>| . $locale->text('Reference') . qq|</th>
835 <td colspan=3><input name=reference></td>
838 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
839 <td colspan=3><input name=source></td>
842 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
843 <td colspan=3><input name=memo size=30></td>
846 <th align=right>| . $locale->text('From') . qq|</th>
851 <th align=right>| . $locale->text('Bis') . qq|</th>
858 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
859 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
864 <input type=hidden name=db value=$form->{db}>
865 <input type=hidden name=sort value=transdate>
876 <td><hr size=3 noshade></td>
881 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
889 $lxdebug->leave_sub();
892 sub continue { call_sub($form->{"nextsub"}); }
895 $lxdebug->enter_sub();
897 $auth->assert('report');
901 $form->{project_id} = $form->{project_id_1};
902 if ($form->{projectnumber} && !$form->{project_id}) {
903 $form->{rowcount} = 1;
905 # call this instead of update
906 $form->{update} = $nextsub;
907 $form->{projectnumber_1} = $form->{projectnumber};
909 delete $form->{sort};
912 # if there is one only, assign id
913 $form->{project_id} = $form->{project_id_1};
916 $lxdebug->leave_sub();
919 sub generate_income_statement {
920 $lxdebug->enter_sub();
922 $auth->assert('report');
924 $form->{padding} = " ";
925 $form->{bold} = "<b>";
926 $form->{endbold} = "</b>";
927 $form->{br} = "<br>";
929 if ($form->{reporttype} eq "custom") {
931 #forgotten the year --> thisyear
932 if ($form->{year} !~ m/^\d\d\d\d$/) {
933 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
939 if ($form->{duetyp} eq "13") {
940 $form->{fromdate} = "1.1.$form->{year}";
941 $form->{todate} = "31.12.$form->{year}";
945 if ($form->{duetyp} eq "A") {
946 $form->{fromdate} = "1.1.$form->{year}";
947 $form->{todate} = "31.3.$form->{year}";
949 if ($form->{duetyp} eq "B") {
950 $form->{fromdate} = "1.4.$form->{year}";
951 $form->{todate} = "30.6.$form->{year}";
953 if ($form->{duetyp} eq "C") {
954 $form->{fromdate} = "1.7.$form->{year}";
955 $form->{todate} = "30.9.$form->{year}";
957 if ($form->{duetyp} eq "D") {
958 $form->{fromdate} = "1.10.$form->{year}";
959 $form->{todate} = "31.12.$form->{year}";
964 $form->{duetyp} eq "1" && do {
965 $form->{fromdate} = "1.1.$form->{year}";
966 $form->{todate} = "31.1.$form->{year}";
969 $form->{duetyp} eq "2" && do {
970 $form->{fromdate} = "1.2.$form->{year}";
972 #this works from 1901 to 2099, 1900 and 2100 fail.
973 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
974 $form->{todate} = "$leap.2.$form->{year}";
977 $form->{duetyp} eq "3" && do {
978 $form->{fromdate} = "1.3.$form->{year}";
979 $form->{todate} = "31.3.$form->{year}";
982 $form->{duetyp} eq "4" && do {
983 $form->{fromdate} = "1.4.$form->{year}";
984 $form->{todate} = "30.4.$form->{year}";
987 $form->{duetyp} eq "5" && do {
988 $form->{fromdate} = "1.5.$form->{year}";
989 $form->{todate} = "31.5.$form->{year}";
992 $form->{duetyp} eq "6" && do {
993 $form->{fromdate} = "1.6.$form->{year}";
994 $form->{todate} = "30.6.$form->{year}";
997 $form->{duetyp} eq "7" && do {
998 $form->{fromdate} = "1.7.$form->{year}";
999 $form->{todate} = "31.7.$form->{year}";
1002 $form->{duetyp} eq "8" && do {
1003 $form->{fromdate} = "1.8.$form->{year}";
1004 $form->{todate} = "31.8.$form->{year}";
1007 $form->{duetyp} eq "9" && do {
1008 $form->{fromdate} = "1.9.$form->{year}";
1009 $form->{todate} = "30.9.$form->{year}";
1012 $form->{duetyp} eq "10" && do {
1013 $form->{fromdate} = "1.10.$form->{year}";
1014 $form->{todate} = "31.10.$form->{year}";
1017 $form->{duetyp} eq "11" && do {
1018 $form->{fromdate} = "1.11.$form->{year}";
1019 $form->{todate} = "30.11.$form->{year}";
1022 $form->{duetyp} eq "12" && do {
1023 $form->{fromdate} = "1.12.$form->{year}";
1024 $form->{todate} = "31.12.$form->{year}";
1030 RP->income_statement(\%myconfig, \%$form);
1032 ($form->{department}) = split /--/, $form->{department};
1035 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1036 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1038 # if there are any dates construct a where
1039 if ($form->{fromdate} || $form->{todate}) {
1041 unless ($form->{todate}) {
1042 $form->{todate} = $form->current_date(\%myconfig);
1045 $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1046 $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1048 $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1049 $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1051 $form->{this_period} = "$shortfromdate\n$shorttodate";
1053 $locale->text('for Period')
1054 . qq|\n$longfromdate |
1055 . $locale->text('Bis')
1059 if ($form->{comparefromdate} || $form->{comparetodate}) {
1060 $longcomparefromdate =
1061 $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1062 $shortcomparefromdate =
1063 $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1065 $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1066 $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1068 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1070 "\n$longcomparefromdate "
1071 . $locale->text('Bis')
1072 . qq| $longcomparetodate|;
1075 # setup variables for the form
1076 @a = qw(company address businessnumber);
1077 map { $form->{$_} = $myconfig{$_} } @a;
1079 $form->{templates} = $myconfig{templates};
1081 $form->{IN} = "income_statement.html";
1083 $form->parse_template;
1085 $lxdebug->leave_sub();
1088 sub generate_balance_sheet {
1089 $lxdebug->enter_sub();
1091 $auth->assert('report');
1093 RP->balance_sheet(\%myconfig, \%$form);
1095 $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1097 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1099 ($form->{department}) = split /--/, $form->{department};
1101 # define Current Earnings account
1102 $padding = ($form->{l_heading}) ? $form->{padding} : "";
1103 push(@{ $form->{equity_account} },
1104 $padding . $locale->text('Current Earnings'));
1106 $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1107 $form->{last_period} =
1108 $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1110 my $attachment_basename;
1112 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1114 my @hidden_variables = ();
1115 push @hidden_variables, qw(fromdate todate year cash );
1117 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1120 'accno' => { 'text' => $locale->text('Account Number'), },
1121 'description' => { 'text' => $locale->text('Description'), },
1122 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1123 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1124 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1125 'soll' => { 'text' => $locale->text('Debit'), },
1126 'haben' => { 'text' => $locale->text('Credit'), },
1127 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1128 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1129 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1130 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1133 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1135 map { $column_defs{$_}->{visible} = 1 } @columns;
1137 $report->set_columns(%column_defs);
1138 $report->set_column_order(@columns);
1140 $report->set_export_options('trial_balance', @hidden_variables);
1142 $report->set_sort_indicator($form->{sort}, 1);
1147 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1148 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1150 $report->set_options('output_format' => 'HTML',
1151 'title' => $form->{title},
1152 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1154 $report->set_options_from_form();
1155 # $form->parse_html_template('report_generator/html_report_bilanz', $variables));
1156 $form->{report_template} = 'report_generator/html_report_bilanz';
1157 # add sort and escape callback, this one we use for the add sub
1158 $form->{callback} = $href .= "&sort=$form->{sort}";
1160 # escape callback for href
1161 $callback = $form->escape($href);
1163 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1165 my %totals = map { $_ => 0 } @subtotal_columns;
1167 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1169 # foreach $accno (@{ $form->{TB} }) {
1171 # $accno->{soll} = $accno->{debit};
1172 # $accno->{haben} = $accno->{credit};
1173 # map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1175 # map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1177 # map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1181 # foreach my $column (@columns) {
1182 # $row->{$column} = {
1183 # 'data' => $accno->{$column},
1184 # 'align' => $column_alignment{$column},
1189 # $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1191 # my $row_set = [ $row ];
1194 # $report->add_data($row_set);
1199 # $report->add_separator();
1201 # $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1203 $report->generate_with_headers();
1206 $lxdebug->leave_sub();
1209 sub generate_projects {
1210 $lxdebug->enter_sub();
1212 $auth->assert('report');
1214 &get_project(generate_projects);
1215 $form->{projectnumber} = $form->{projectnumber_1};
1217 $form->{nextsub} = "generate_projects";
1218 $form->{title} = $locale->text('Project Transactions');
1219 RP->trial_balance(\%myconfig, \%$form);
1221 list_accounts('generate_projects');
1223 $lxdebug->leave_sub();
1229 # included links to display transactions for period entered
1230 # added headers and subtotals
1232 sub generate_trial_balance {
1233 $lxdebug->enter_sub();
1235 $auth->assert('report');
1237 if ($form->{reporttype} eq "custom") {
1239 #forgotten the year --> thisyear
1240 if ($form->{year} !~ m/^\d\d\d\d$/) {
1241 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1247 if ($form->{duetyp} eq "13") {
1248 $form->{fromdate} = "1.1.$form->{year}";
1249 $form->{todate} = "31.12.$form->{year}";
1253 if ($form->{duetyp} eq "A") {
1254 $form->{fromdate} = "1.1.$form->{year}";
1255 $form->{todate} = "31.3.$form->{year}";
1257 if ($form->{duetyp} eq "B") {
1258 $form->{fromdate} = "1.4.$form->{year}";
1259 $form->{todate} = "30.6.$form->{year}";
1261 if ($form->{duetyp} eq "C") {
1262 $form->{fromdate} = "1.7.$form->{year}";
1263 $form->{todate} = "30.9.$form->{year}";
1265 if ($form->{duetyp} eq "D") {
1266 $form->{fromdate} = "1.10.$form->{year}";
1267 $form->{todate} = "31.12.$form->{year}";
1272 $form->{duetyp} eq "1" && do {
1273 $form->{fromdate} = "1.1.$form->{year}";
1274 $form->{todate} = "31.1.$form->{year}";
1277 $form->{duetyp} eq "2" && do {
1278 $form->{fromdate} = "1.2.$form->{year}";
1280 #this works from 1901 to 2099, 1900 and 2100 fail.
1281 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1282 $form->{todate} = "$leap.2.$form->{year}";
1285 $form->{duetyp} eq "3" && do {
1286 $form->{fromdate} = "1.3.$form->{year}";
1287 $form->{todate} = "31.3.$form->{year}";
1290 $form->{duetyp} eq "4" && do {
1291 $form->{fromdate} = "1.4.$form->{year}";
1292 $form->{todate} = "30.4.$form->{year}";
1295 $form->{duetyp} eq "5" && do {
1296 $form->{fromdate} = "1.5.$form->{year}";
1297 $form->{todate} = "31.5.$form->{year}";
1300 $form->{duetyp} eq "6" && do {
1301 $form->{fromdate} = "1.6.$form->{year}";
1302 $form->{todate} = "30.6.$form->{year}";
1305 $form->{duetyp} eq "7" && do {
1306 $form->{fromdate} = "1.7.$form->{year}";
1307 $form->{todate} = "31.7.$form->{year}";
1310 $form->{duetyp} eq "8" && do {
1311 $form->{fromdate} = "1.8.$form->{year}";
1312 $form->{todate} = "31.8.$form->{year}";
1315 $form->{duetyp} eq "9" && do {
1316 $form->{fromdate} = "1.9.$form->{year}";
1317 $form->{todate} = "30.9.$form->{year}";
1320 $form->{duetyp} eq "10" && do {
1321 $form->{fromdate} = "1.10.$form->{year}";
1322 $form->{todate} = "31.10.$form->{year}";
1325 $form->{duetyp} eq "11" && do {
1326 $form->{fromdate} = "1.11.$form->{year}";
1327 $form->{todate} = "30.11.$form->{year}";
1330 $form->{duetyp} eq "12" && do {
1331 $form->{fromdate} = "1.12.$form->{year}";
1332 $form->{todate} = "31.12.$form->{year}";
1339 # get for each account initial balance, debits and credits
1340 RP->trial_balance(\%myconfig, \%$form);
1343 $form->{rowcount} = scalar @{ $form->{TB} };
1344 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1347 "accno", "description",
1348 "last_transaction", "soll_eb",
1351 "soll_kumuliert", "haben_kumuliert",
1352 "soll_saldo", "haben_saldo"
1356 my $attachment_basename;
1357 $attachment_basename = $locale->text('trial_balance');
1358 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1360 my @hidden_variables = ();
1361 push @hidden_variables, qw(fromdate todate year cash );
1363 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1366 'accno' => { 'text' => $locale->text('Account Number'), },
1367 'description' => { 'text' => $locale->text('Description'), },
1368 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1369 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1370 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1371 'soll' => { 'text' => $locale->text('Debit'), },
1372 'haben' => { 'text' => $locale->text('Credit'), },
1373 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1374 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1375 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1376 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1381 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1383 map { $column_defs{$_}->{visible} = 1 } @columns;
1385 $report->set_columns(%column_defs);
1386 $report->set_column_order(@columns);
1388 $report->set_export_options('generate_trial_balance', @hidden_variables);
1390 $report->set_sort_indicator($form->{sort}, 1);
1395 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1396 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1398 $report->set_options('output_format' => 'HTML',
1399 'title' => $form->{title},
1400 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1401 'html_template' => 'rp/html_report_susa',
1402 'pdf_template' => 'rp/html_report_susa',
1404 $report->set_options_from_form();
1406 # add sort and escape callback, this one we use for the add sub
1407 $form->{callback} = $href .= "&sort=$form->{sort}";
1409 # escape callback for href
1410 $callback = $form->escape($href);
1412 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1414 my %totals = map { $_ => 0 } @subtotal_columns;
1416 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1418 foreach $accno (@{ $form->{TB} }) {
1420 $accno->{soll} = $accno->{debit};
1421 $accno->{haben} = $accno->{credit};
1422 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1424 map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1426 map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1430 foreach my $column (@columns) {
1432 'data' => $accno->{$column},
1433 'align' => $column_alignment{$column},
1438 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1440 my $row_set = [ $row ];
1443 $report->add_data($row_set);
1448 $report->add_separator();
1450 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1452 $report->generate_with_headers();
1454 $lxdebug->leave_sub();
1458 sub create_subtotal_row {
1459 $lxdebug->enter_sub();
1461 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1463 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1465 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1467 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1469 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1471 $lxdebug->leave_sub();
1476 sub create_list_accounts_subtotal_row {
1477 $lxdebug->enter_sub();
1479 my ($subtotals, $columns, $fields, $class) = @_;
1481 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1483 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1485 $lxdebug->leave_sub();
1491 $lxdebug->enter_sub();
1496 if ($form->{department}) {
1497 my ($department) = split /--/, $form->{department};
1498 push @options, $locale->text('Department') . " : $department";
1500 if ($form->{projectnumber}) {
1501 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1504 # if there are any dates
1505 if ($form->{fromdate} || $form->{todate}) {
1506 my ($fromdate, $todate);
1508 if ($form->{fromdate}) {
1509 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1511 if ($form->{todate}) {
1512 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1515 push @options, "$fromdate - $todate";
1518 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1521 my @columns = qw(accno description begbalance debit credit endbalance);
1523 'accno' => { 'text' => $locale->text('Account'), },
1524 'description' => { 'text' => $locale->text('Description'), },
1525 'debit' => { 'text' => $locale->text('Debit'), },
1526 'credit' => { 'text' => $locale->text('Credit'), },
1527 'begbalance' => { 'text' => $locale->text('Balance'), },
1528 'endbalance' => { 'text' => $locale->text('Balance'), },
1530 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1532 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1534 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1536 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1538 $report->set_options('top_info_text' => join("\n", @options),
1539 'output_format' => 'HTML',
1540 'title' => $form->{title},
1541 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1542 'std_column_visibility' => 1,
1544 $report->set_options_from_form();
1546 $report->set_columns(%column_defs);
1547 $report->set_column_order(@columns);
1549 $report->set_export_options($action, @hidden_variables);
1551 $report->set_sort_indicator('accno', 1);
1553 my @totals_columns = qw(credit debit begbalance endbalance);
1554 my %subtotals = map { $_ => 0 } @totals_columns;
1555 my %totals = map { $_ => 0 } @totals_columns;
1556 my $found_heading = 0;
1557 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1559 # sort the whole thing by account numbers and display
1560 foreach my $idx (0 .. scalar(@tb) - 1) {
1561 my $ref = $tb[$idx];
1562 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1564 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1566 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1568 if ($ref->{charttype} eq 'H') {
1569 next unless ($form->{l_heading});
1571 %subtotals = map { $_ => 0 } @totals_columns;
1573 $row->{description}->{class} = 'listheading';
1574 $row->{description}->{data} = $ref->{description};
1576 $report->add_data($row);
1581 foreach (qw(debit credit)) {
1582 $subtotals{$_} += $ref->{$_};
1583 $totals{$_} += $ref->{$_};
1586 $subtotals{begbalance} += $ref->{balance} * $ml;
1587 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1589 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1590 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1592 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1593 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1595 $report->add_data($row);
1597 if ($form->{l_heading} && $found_heading &&
1598 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1599 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1603 $report->add_separator();
1605 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1607 $report->generate_with_headers();
1609 $lxdebug->leave_sub();
1612 sub generate_ar_aging {
1613 $lxdebug->enter_sub();
1615 $auth->assert('general_ledger');
1618 ($form->{customer}) = split(/--/, $form->{customer});
1620 $form->{ct} = "customer";
1621 $form->{arap} = "ar";
1623 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1625 RP->aging(\%myconfig, \%$form);
1628 $lxdebug->leave_sub();
1631 sub generate_ap_aging {
1632 $lxdebug->enter_sub();
1634 $auth->assert('general_ledger');
1637 ($form->{vendor}) = split(/--/, $form->{vendor});
1639 $form->{ct} = "vendor";
1640 $form->{arap} = "ap";
1642 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1644 RP->aging(\%myconfig, \%$form);
1647 $lxdebug->leave_sub();
1650 sub create_aging_subtotal_row {
1651 $lxdebug->enter_sub();
1653 my ($subtotals, $columns, $periods, $class) = @_;
1655 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1657 foreach (@{ $periods }) {
1658 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1659 $subtotals->{$_} = 0;
1662 $lxdebug->leave_sub();
1668 $lxdebug->enter_sub();
1670 $auth->assert('general_ledger');
1672 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1674 my @columns = qw(statement ct invnumber transdate duedate amount open);
1677 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1678 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1679 'invnumber' => { 'text' => $locale->text('Invoice'), },
1680 'transdate' => { 'text' => $locale->text('Date'), },
1681 'duedate' => { 'text' => $locale->text('Due'), },
1682 'amount' => { 'text' => $locale->text('Amount'), },
1683 'open' => { 'text' => $locale->text('Open'), },
1686 my %column_alignment = ('statement' => 'center',
1687 map { $_ => 'right' } qw(open amount));
1689 $report->set_options('std_column_visibility' => 1);
1690 $report->set_columns(%column_defs);
1691 $report->set_column_order(@columns);
1693 my @hidden_variables = qw(todate customer vendor arap title ct);
1694 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1697 my $attachment_basename;
1699 if ($form->{department}) {
1700 my ($department) = split /--/, $form->{department};
1701 push @options, $locale->text('Department') . " : $department";
1702 $form->{callback} .= "&department=" . E($department);
1705 if (($form->{arap} eq 'ar') && $form->{customer}) {
1706 push @options, $form->{customer};
1707 $attachment_basename = $locale->text('ar_aging_list');
1708 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1711 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1712 push @options, $form->{vendor};
1713 $attachment_basename = $locale->text('ap_aging_list');
1714 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1717 if ($form->{fromdate}) {
1718 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1720 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1723 my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1725 $report->set_options('top_info_text' => join("\n", @options),
1726 'output_format' => 'HTML',
1727 'title' => $form->{title},
1728 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1731 my $previous_ctid = 0;
1733 my @periods = qw(open amount);
1734 my %subtotals = map { $_ => 0 } @periods;
1735 my %totals = map { $_ => 0 } @periods;
1737 foreach $ref (@{ $form->{AG} }) {
1738 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1739 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1742 foreach my $key (@periods) {
1743 $subtotals{$key} += $ref->{"$key"};
1744 $totals{$key} += $ref->{"$key"};
1745 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1750 foreach my $column (@columns) {
1752 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1753 'align' => $column_alignment{$column},
1754 'valign' => $column eq 'statement' ? 'center' : '',
1758 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1760 if ($previous_ctid != $ref->{ctid}) {
1761 $row->{statement}->{raw_data} =
1762 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1763 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1764 $row->{ct}->{data} = $ref->{name};
1769 $previous_ctid = $ref->{ctid};
1771 $report->add_data($row);
1774 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1776 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1778 if ($form->{arap} eq 'ar') {
1779 $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1780 $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1781 'PRINT_OPTIONS' => print_options(inline => 1), });
1782 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1783 'raw_bottom_info_text' => $raw_bottom_info_text);
1786 $report->set_options_from_form();
1788 $report->generate_with_headers();
1790 $lxdebug->leave_sub();
1794 $lxdebug->enter_sub();
1796 RP->aging(\%myconfig, \%$form);
1798 map { $_->{checked} = "checked" } @{ $form->{AG} };
1802 $lxdebug->leave_sub();
1806 $lxdebug->enter_sub();
1808 $auth->assert('general_ledger');
1810 # get name and email addresses
1811 for $i (1 .. $form->{rowcount}) {
1812 if ($form->{"statement_$i"}) {
1813 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1814 RP->get_customer(\%myconfig, \%$form);
1820 $form->error($locale->text('Nothing selected!')) unless $selected;
1822 if ($myconfig{role} eq 'admin') {
1824 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1825 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1829 $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1831 $form->{media} = "email";
1838 <form method=post action=$form->{script}>
1844 <tr height="5"></tr>
1849 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1850 <td><input name=email size=30 value="$form->{email}"></td>
1851 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1852 <td><input name=cc size=30 value="$form->{cc}"></td>
1855 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1856 <td><input name=subject size=30 value="$form->{subject}"></td>
1866 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1869 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1880 map { delete $form->{$_} }
1881 qw(action email cc bcc subject message type sendmode format header);
1883 # save all other variables
1884 foreach $key (keys %$form) {
1885 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1886 $form->{$key} =~ s/\"/"/g;
1887 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1894 <td><hr size=3 noshade></td>
1898 <input type=hidden name=nextsub value=send_email>
1901 <input name=action class=submit type=submit value="|
1902 . $locale->text('Continue') . qq|">
1909 $lxdebug->leave_sub();
1913 $lxdebug->enter_sub();
1915 $auth->assert('general_ledger');
1917 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1918 unless $form->{subject};
1920 RP->aging(\%myconfig, \%$form);
1922 $form->{"statement_1"} = 1;
1924 $form->{media} = 'email';
1927 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1929 $lxdebug->leave_sub();
1933 $lxdebug->enter_sub();
1935 $auth->assert('general_ledger');
1937 if ($form->{media} eq 'printer') {
1938 $form->error($locale->text('Select postscript or PDF!'))
1939 if ($form->{format} !~ /(postscript|pdf)/);
1942 for $i (1 .. $form->{rowcount}) {
1943 if ($form->{"statement_$i"}) {
1944 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1950 $form->error($locale->text('Nothing selected!')) unless $selected;
1952 if ($form->{media} eq 'printer') {
1953 $form->{"$form->{ct}_id"} = "";
1955 $form->{"statement_1"} = 1;
1958 RP->aging(\%myconfig, \%$form);
1962 $form->redirect($locale->text('Statements sent to printer!'))
1963 if ($form->{media} eq 'printer');
1965 $lxdebug->leave_sub();
1969 $lxdebug->enter_sub();
1971 $auth->assert('general_ledger');
1973 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1975 $form->{templates} = "$myconfig{templates}";
1977 my $suffix = "html";
1978 my $attachment_suffix = "html";
1979 if ($form->{format} eq 'postscript') {
1980 $form->{postscript} = 1;
1982 $attachment_suffix = "ps";
1983 } elsif ($form->{format} eq 'pdf') {
1986 $attachment_suffix = "pdf";
1989 $form->{IN} = "$form->{type}.$suffix";
1990 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1992 # Save $form->{email} because it will be overwritten.
1993 $form->{EMAIL_RECIPIENT} = $form->{email};
1996 while (@{ $form->{AG} }) {
1998 $ref = shift @{ $form->{AG} };
2000 if ($ctid != $ref->{ctid}) {
2002 $ctid = $ref->{ctid};
2005 if ($form->{"statement_$i"}) {
2008 (name, street, zipcode, city, country, contact, email,
2009 "$form->{ct}phone", "$form->{ct}fax");
2010 map { $form->{$_} = $ref->{$_} } @a;
2012 $form->{ $form->{ct} } = $form->{name};
2013 $form->{"$form->{ct}_id"} = $ref->{ctid};
2015 map { $form->{$_} = () } qw(invnumber invdate duedate);
2017 foreach $item (qw(c0 c30 c60 c90)) {
2018 $form->{$item} = ();
2019 $form->{"${item}total"} = 0;
2022 &statement_details($ref);
2026 if (scalar(@{ $form->{AG} }) > 0) {
2028 # one or more left to go
2029 if ($ctid == $form->{AG}->[0]->{ctid}) {
2030 $ref = shift @{ $form->{AG} };
2031 &statement_details($ref);
2034 $ref = scalar(@{ $form->{AG} });
2040 # set initial ref to 0
2047 $form->{"${_}total"} =
2048 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2049 } (c0, c30, c60, c90, "");
2051 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2052 $form->{attachment_filename} =~ s/\s+/_/g;
2054 $form->parse_template(\%myconfig, $userspath);
2059 # saving the history
2060 if(!exists $form->{addition} && $form->{id} ne "") {
2061 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2062 $form->{addition} = "PRINTED";
2063 $form->{what_done} = $form->{type};
2064 $form->save_history($form->dbconnect(\%myconfig));
2066 # /saving the history
2067 $lxdebug->leave_sub();
2070 sub statement_details {
2071 $lxdebug->enter_sub();
2073 $auth->assert('general_ledger');
2077 push @{ $form->{invnumber} }, $ref->{invnumber};
2078 push @{ $form->{invdate} }, $ref->{transdate};
2079 push @{ $form->{duedate} }, $ref->{duedate};
2081 foreach $item (qw(c0 c30 c60 c90)) {
2082 if ($ref->{exchangerate} * 1) {
2084 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2086 $form->{"${item}total"} += $ref->{$item};
2087 $form->{total} += $ref->{$item};
2088 push @{ $form->{$item} },
2089 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2092 $lxdebug->leave_sub();
2095 sub generate_tax_report {
2096 $lxdebug->enter_sub();
2098 $auth->assert('report');
2100 RP->tax_report(\%myconfig, \%$form);
2102 $descvar = "$form->{accno}_description";
2103 $description = $form->escape($form->{$descvar});
2104 $ratevar = "$form->{accno}_rate";
2106 $department = $form->escape($form->{department});
2110 "$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}";
2112 # construct callback
2113 $description = $form->escape($form->{$descvar}, 1);
2114 $department = $form->escape($form->{department}, 1);
2116 "$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}";
2118 $title = $form->escape($form->{title});
2119 $href .= "&title=$title";
2120 $title = $form->escape($form->{title}, 1);
2121 $callback .= "&title=$title";
2123 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2126 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2128 foreach $item (@columns) {
2129 if ($form->{"l_$item"} eq "Y") {
2130 push @column_index, $item;
2132 # add column to href and callback
2133 $callback .= "&l_$item=Y";
2134 $href .= "&l_$item=Y";
2138 if ($form->{l_subtotal} eq 'Y') {
2139 $callback .= "&l_subtotal=Y";
2140 $href .= "&l_subtotal=Y";
2143 if ($form->{department}) {
2144 ($department) = split /--/, $form->{department};
2145 $option = $locale->text('Department') . " : $department";
2148 # if there are any dates
2149 if ($form->{fromdate} || $form->{todate}) {
2150 if ($form->{fromdate}) {
2151 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2153 if ($form->{todate}) {
2154 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2157 $form->{period} = "$fromdate - $todate";
2160 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2163 if ($form->{db} eq 'ar') {
2164 $name = $locale->text('Customer');
2168 if ($form->{db} eq 'ap') {
2169 $name = $locale->text('Vendor');
2174 $option .= "<br>" if $option;
2175 $option .= "$form->{period}";
2177 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2178 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2179 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2180 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2181 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2182 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2184 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2193 <th class=listtop colspan=$colspan>$form->{title}</th>
2195 <tr height="5"></tr>
2202 <tr class=listheading>
2205 map { print "$column_header{$_}\n" } @column_index;
2211 # add sort and escape callback
2212 $callback = $form->escape($callback . "&sort=$form->{sort}");
2214 if (@{ $form->{TR} }) {
2215 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2218 foreach $ref (@{ $form->{TR} }) {
2220 $module = ($ref->{invoice}) ? $invoice : $arap;
2222 if ($form->{l_subtotal} eq 'Y') {
2223 if ($sameitem ne $ref->{ $form->{sort} }) {
2225 $sameitem = $ref->{ $form->{sort} };
2229 $totalnetamount += $ref->{netamount};
2230 $totaltax += $ref->{tax};
2231 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2233 $subtotalnetamount += $ref->{netamount};
2234 $subtotaltax += $ref->{tax};
2237 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2238 } qw(netamount tax amount);
2240 $column_data{id} = qq|<td>$ref->{id}</td>|;
2241 $column_data{invnumber} =
2242 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2243 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2244 $column_data{name} = qq|<td>$ref->{name} </td>|;
2246 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2247 qw(netamount tax amount);
2252 <tr class=listrow$i>
2255 map { print "$column_data{$_}\n" } @column_index;
2263 if ($form->{l_subtotal} eq 'Y') {
2267 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2271 <tr class=listtotal>
2275 $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2277 $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2278 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2280 $column_data{netamount} =
2281 qq|<th class=listtotal align=right>$totalnetamount</th>|;
2282 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2283 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2285 map { print "$column_data{$_}\n" } @column_index;
2293 <td><hr size=3 noshade></td>
2301 $lxdebug->leave_sub();
2305 $lxdebug->enter_sub();
2307 map { $column_data{$_} = "<td> </td>" } @column_index;
2309 $subtotalnetamount =
2310 $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
2311 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
2313 $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2316 $column_data{netamount} =
2317 "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2318 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2319 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2321 $subtotalnetamount = 0;
2325 <tr class=listsubtotal>
2327 map { print "\n$column_data{$_}" } @column_index;
2333 $lxdebug->leave_sub();
2337 $lxdebug->enter_sub();
2339 $auth->assert('cash');
2341 if ($form->{account}) {
2342 ($form->{paymentaccounts}) = split /--/, $form->{account};
2344 if ($form->{department}) {
2345 ($department, $form->{department_id}) = split /--/, $form->{department};
2346 $option = $locale->text('Department') . " : $department";
2349 report_generator_set_default_sort('transdate', 1);
2351 RP->payments(\%myconfig, \%$form);
2353 my @hidden_variables = qw(account title department reference source memo fromdate todate
2354 fx_transaction db prepayment paymentaccounts sort);
2356 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2357 $form->{callback} = $href;
2359 my @columns = qw(transdate invnumber name paid source memo);
2361 'name' => { 'text' => $locale->text('Description'), },
2362 'invnumber' => { 'text' => $locale->text('Reference'), },
2363 'transdate' => { 'text' => $locale->text('Date'), },
2364 'paid' => { 'text' => $locale->text('Amount'), },
2365 'source' => { 'text' => $locale->text('Source'), },
2366 'memo' => { 'text' => $locale->text('Memo'), },
2368 my %column_alignment = ('paid' => 'right');
2370 foreach my $name (grep { $_ ne 'paid' } @columns) {
2371 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2372 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2376 if ($form->{fromdate}) {
2377 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2379 if ($form->{todate}) {
2380 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2383 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2385 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2387 $report->set_options('top_info_text' => join("\n", @options),
2388 'output_format' => 'HTML',
2389 'title' => $form->{title},
2390 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2391 'std_column_visibility' => 1,
2393 $report->set_options_from_form();
2395 $report->set_columns(%column_defs);
2396 $report->set_column_order(@columns);
2398 $report->set_export_options('list_payments', @hidden_variables);
2400 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2404 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2405 next unless @{ $form->{ $ref->{id} } };
2407 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2409 my $subtotal_paid = 0;
2411 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2412 my $module = $payment->{module};
2413 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2414 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2416 $subtotal_paid += $payment->{paid};
2417 $total_paid += $payment->{paid};
2419 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2423 foreach my $column (@columns) {
2425 'data' => $payment->{$column},
2426 'align' => $column_alignment{$column},
2430 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2432 $report->add_data($row);
2435 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2437 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2439 'class' => 'listsubtotal',
2442 $report->add_data($row);
2445 $report->add_separator();
2447 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2449 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2451 'class' => 'listtotal',
2454 $report->add_data($row);
2456 $report->generate_with_headers();
2458 $lxdebug->leave_sub();
2462 $lxdebug->enter_sub();
2464 my ($dont_print) = @_;
2466 $form->{sendmode} = "attachment";
2469 $form->{"format"} ? $form->{"format"} :
2470 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2474 $form->{"copies"} ? $form->{"copies"} :
2475 $myconfig{"copies"} ? $myconfig{"copies"} :
2478 $form->{PD}{ $form->{type} } = "selected";
2479 $form->{DF}{ $form->{format} } = "selected";
2480 $form->{OP}{ $form->{media} } = "selected";
2481 $form->{SM}{ $form->{sendmode} } = "selected";
2484 <option value=statement $form->{PD}{statement}>|
2485 . $locale->text('Statement');
2487 if ($form->{media} eq 'email') {
2489 <option value=attachment $form->{SM}{attachment}>|
2490 . $locale->text('Attachment') . qq|
2491 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2494 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2495 if ($myconfig{printer} && $latex_templates) {
2497 <option value=printer $form->{OP}{printer}>|
2498 . $locale->text('Printer');
2502 if ($latex_templates) {
2504 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2505 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2506 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2512 <td><select name=type>$type</select></td>
2513 <td><select name=format>$format</select></td>
2514 <td><select name=media>$media</select></td>
2517 if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2519 <td>| . $locale->text('Copies') . qq|
2520 <input name=copies size=2 value=$form->{copies}></td>
2529 print $output unless $dont_print;
2531 $lxdebug->leave_sub();
2537 $lxdebug->enter_sub();
2539 $auth->assert('report');
2541 $form->{padding} = " ";
2542 $form->{bold} = "<b>";
2543 $form->{endbold} = "</b>";
2544 $form->{br} = "<br>";
2546 if ($form->{reporttype} eq "custom") {
2548 #forgotten the year --> thisyear
2549 if ($form->{year} !~ m/^\d\d\d\d$/) {
2550 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2556 if ($form->{duetyp} eq "13") {
2557 $form->{fromdate} = "1.1.$form->{year}";
2558 $form->{todate} = "31.12.$form->{year}";
2559 $form->{comparefromdate} = "1.01.$form->{year}";
2560 $form->{comparetodate} = "31.12.$form->{year}";
2564 if ($form->{duetyp} eq "A") {
2565 $form->{fromdate} = "1.1.$form->{year}";
2566 $form->{todate} = "31.3.$form->{year}";
2567 $form->{comparefromdate} = "1.01.$form->{year}";
2568 $form->{comparetodate} = "31.03.$form->{year}";
2570 if ($form->{duetyp} eq "B") {
2571 $form->{fromdate} = "1.4.$form->{year}";
2572 $form->{todate} = "30.6.$form->{year}";
2573 $form->{comparefromdate} = "1.01.$form->{year}";
2574 $form->{comparetodate} = "30.06.$form->{year}";
2576 if ($form->{duetyp} eq "C") {
2577 $form->{fromdate} = "1.7.$form->{year}";
2578 $form->{todate} = "30.9.$form->{year}";
2579 $form->{comparefromdate} = "1.01.$form->{year}";
2580 $form->{comparetodate} = "30.09.$form->{year}";
2582 if ($form->{duetyp} eq "D") {
2583 $form->{fromdate} = "1.10.$form->{year}";
2584 $form->{todate} = "31.12.$form->{year}";
2585 $form->{comparefromdate} = "1.01.$form->{year}";
2586 $form->{comparetodate} = "31.12.$form->{year}";
2591 $form->{duetyp} eq "1" && do {
2592 $form->{fromdate} = "1.1.$form->{year}";
2593 $form->{todate} = "31.1.$form->{year}";
2594 $form->{comparefromdate} = "1.01.$form->{year}";
2595 $form->{comparetodate} = "31.01.$form->{year}";
2598 $form->{duetyp} eq "2" && do {
2599 $form->{fromdate} = "1.2.$form->{year}";
2601 #this works from 1901 to 2099, 1900 and 2100 fail.
2602 $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2603 $form->{todate} = "$leap.2.$form->{year}";
2604 $form->{comparefromdate} = "1.01.$form->{year}";
2605 $form->{comparetodate} = "$leap.02.$form->{year}";
2608 $form->{duetyp} eq "3" && do {
2609 $form->{fromdate} = "1.3.$form->{year}";
2610 $form->{todate} = "31.3.$form->{year}";
2611 $form->{comparefromdate} = "1.01.$form->{year}";
2612 $form->{comparetodate} = "31.03.$form->{year}";
2615 $form->{duetyp} eq "4" && do {
2616 $form->{fromdate} = "1.4.$form->{year}";
2617 $form->{todate} = "30.4.$form->{year}";
2618 $form->{comparefromdate} = "1.01.$form->{year}";
2619 $form->{comparetodate} = "30.04.$form->{year}";
2622 $form->{duetyp} eq "5" && do {
2623 $form->{fromdate} = "1.5.$form->{year}";
2624 $form->{todate} = "31.5.$form->{year}";
2625 $form->{comparefromdate} = "1.01.$form->{year}";
2626 $form->{comparetodate} = "31.05.$form->{year}";
2629 $form->{duetyp} eq "6" && do {
2630 $form->{fromdate} = "1.6.$form->{year}";
2631 $form->{todate} = "30.6.$form->{year}";
2632 $form->{comparefromdate} = "1.01.$form->{year}";
2633 $form->{comparetodate} = "30.06.$form->{year}";
2636 $form->{duetyp} eq "7" && do {
2637 $form->{fromdate} = "1.7.$form->{year}";
2638 $form->{todate} = "31.7.$form->{year}";
2639 $form->{comparefromdate} = "1.01.$form->{year}";
2640 $form->{comparetodate} = "31.07.$form->{year}";
2643 $form->{duetyp} eq "8" && do {
2644 $form->{fromdate} = "1.8.$form->{year}";
2645 $form->{todate} = "31.8.$form->{year}";
2646 $form->{comparefromdate} = "1.01.$form->{year}";
2647 $form->{comparetodate} = "31.08.$form->{year}";
2650 $form->{duetyp} eq "9" && do {
2651 $form->{fromdate} = "1.9.$form->{year}";
2652 $form->{todate} = "30.9.$form->{year}";
2653 $form->{comparefromdate} = "1.01.$form->{year}";
2654 $form->{comparetodate} = "30.09.$form->{year}";
2657 $form->{duetyp} eq "10" && do {
2658 $form->{fromdate} = "1.10.$form->{year}";
2659 $form->{todate} = "31.10.$form->{year}";
2660 $form->{comparefromdate} = "1.01.$form->{year}";
2661 $form->{comparetodate} = "31.10.$form->{year}";
2664 $form->{duetyp} eq "11" && do {
2665 $form->{fromdate} = "1.11.$form->{year}";
2666 $form->{todate} = "30.11.$form->{year}";
2667 $form->{comparefromdate} = "1.01.$form->{year}";
2668 $form->{comparetodate} = "30.11.$form->{year}";
2671 $form->{duetyp} eq "12" && do {
2672 $form->{fromdate} = "1.12.$form->{year}";
2673 $form->{todate} = "31.12.$form->{year}";
2674 $form->{comparefromdate} = "1.01.$form->{year}";
2675 $form->{comparetodate} = "31.12.$form->{year}";
2680 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2681 $form->{fromdate} = "${dd}.${mm}.${yy}";
2682 ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2683 $form->{todate} = "${dd}.${mm}.${yy}";
2684 $form->{comparefromdate} = "01.01.$yy";
2685 $form->{comparetodate} = $form->{todate};
2688 RP->bwa(\%myconfig, \%$form);
2690 ($form->{department}) = split /--/, $form->{department};
2693 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2694 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2696 # if there are any dates construct a where
2697 if ($form->{fromdate} || $form->{todate}) {
2699 unless ($form->{todate}) {
2700 $form->{todate} = $form->current_date(\%myconfig);
2703 my %germandate = ("dateformat" => "dd.mm.yyyy");
2705 $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2706 $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2708 $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2709 $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2711 $form->{this_period} = "$shortfromdate\n$shorttodate";
2713 $locale->text('for Period')
2714 . qq|\n$longfromdate |
2715 . $locale->text('bis')
2719 # setup variables for the form
2720 @a = qw(company address businessnumber);
2721 map { $form->{$_} = $myconfig{$_} } @a;
2722 $form->{templates} = $myconfig{templates};
2724 $form->{IN} = "bwa.html";
2726 $form->parse_template;
2728 $lxdebug->leave_sub();