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";
50 # note: this file was particularly hard to strictify.
51 # alot of the vars are passed carelessly between invocations
52 # should there be any missing vars, declare them globally
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
83 # $locale->text('Balance Sheet')
84 # $locale->text('Income Statement')
85 # $locale->text('Trial Balance')
86 # $locale->text('AR Aging')
87 # $locale->text('AP Aging')
88 # $locale->text('Search AR Aging')
89 # $locale->text('Search AP Aging')
90 # $locale->text('Tax collected')
91 # $locale->text('Tax paid')
92 # $locale->text('Receipts')
93 # $locale->text('Payments')
94 # $locale->text('Project Transactions')
95 # $locale->text('Non-taxable Sales')
96 # $locale->text('Non-taxable Purchases')
97 # $locale->text('Business evaluation')
99 # $form->parse_html_template('rp/html_report_susa')
101 my $rp_access_map = {
102 'projects' => 'report',
103 'ar_aging' => 'general_ledger',
104 'ap_aging' => 'general_ledger',
105 'receipts' => 'cash',
106 'payments' => 'cash',
107 'trial_balance' => 'report',
108 'income_statement' => 'report',
110 'balance_sheet' => 'report',
113 sub check_rp_access {
114 my $form = $main::form;
116 my $right = $rp_access_map->{$form->{report}};
117 $right ||= 'DOES_NOT_EXIST';
119 $main::auth->assert($right);
123 $main::lxdebug->enter_sub();
127 my $form = $main::form;
128 my %myconfig = %main::myconfig;
129 my $locale = $main::locale;
132 'balance_sheet' => 'Balance Sheet',
133 'income_statement' => 'Income Statement',
134 'trial_balance' => 'Trial Balance',
135 'ar_aging' => 'Search AR Aging',
136 'ap_aging' => 'Search AP Aging',
137 'tax_collected' => 'Tax collected',
138 'tax_paid' => 'Tax paid',
139 'nontaxable_sales' => 'Non-taxable Sales',
140 'nontaxable_purchases' => 'Non-taxable Purchases',
141 'receipts' => 'Receipts',
142 'payments' => 'Payments',
143 'projects' => 'Project Transactions',
144 'bwa' => 'Business evaluation',
147 $form->{title} = $locale->text($title{ $form->{report} });
149 my $accrual = $::instance_conf->get_accounting_method eq 'cash' ? "" : "checked";
150 my $cash = $::instance_conf->get_accounting_method eq 'cash' ? "checked" : "";
152 my $year = (localtime)[5] + 1900;
155 $form->all_departments(\%myconfig);
156 if (@{ $form->{all_departments} || [] }) {
157 $form->{selectdepartment} = "<option>\n";
158 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} || [] };
164 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
165 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
167 | if $form->{selectdepartment};
169 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
172 my %project_labels = ();
173 my @project_values = ("");
174 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
175 push(@project_values, $item->{"id"});
176 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
180 NTI($::request->{cgi}->popup_menu('-name' => "project_id",
181 '-values' => \@project_values,
182 '-labels' => \%project_labels));
184 # use JavaScript Calendar or not
185 $form->{jsscript} = 1;
187 my ( $name_1, $id_1, $value_1, $trigger_1, $name_2, $id_2, $value_2, $trigger_2, );
188 if ($form->{report} eq "balance_sheet") {
189 $name_1 = "asofdate";
191 $value_1 = "$form->{asofdate}";
192 $trigger_1 = "trigger1";
193 $name_2 = "compareasofdate";
194 $id_2 = "compareasofdate";
195 $value_2 = "$form->{compareasofdate}";
196 $trigger_2 = "trigger2";
197 } elsif ($form->{report} =~ /(receipts|payments)$/) {
198 $name_1 = "fromdate";
200 $value_1 = "$form->{fromdate}";
201 $trigger_1 = "trigger1";
205 $trigger_2 = "trigger2";
206 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
207 $name_1 = "fromdate";
209 $value_1 = "$form->{fromdate}";
210 $trigger_1 = "trigger1";
214 $trigger_2 = "trigger2";
217 $name_1 = "fromdate";
219 $value_1 = "$form->{fromdate}";
220 $trigger_1 = "trigger1";
224 $trigger_2 = "trigger2";
227 my ($button1, $button1_2, $button2, $button2_2);
230 # with JavaScript Calendar
231 if ($form->{jsscript}) {
233 $button1 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
234 $button1_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|>|;
237 $jsscript = Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
239 $button1 = qq| <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
240 $button1_2 = qq| <input type=button name=$name_1 id="$trigger_1" value=| . $locale->text('button') . qq|>|;
241 $button2 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
242 $button2_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|> |;
245 $jsscript = Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1", "$name_2", "BL", "$trigger_2");
249 # without JavaScript Calendar
251 $button1 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
253 $button1 = qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
254 $button2 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
257 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
259 my $onload = qq|focus()|;
260 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
261 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
263 <body onLoad="$onload">
265 <form method=post action=$form->{script}>
267 <input type=hidden name=title value="$form->{title}">
269 <table width=100% border="0">
271 <th class=listtop>$form->{title}</th>
280 if ($form->{report} eq "projects") {
283 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
284 <td colspan=5><input name=projectnumber size=25</td>
286 <input type=hidden name=nextsub value=generate_projects>
288 <th align=right>| . $locale->text('From') . qq|</th>
291 <th align=right>| . $locale->text('Bis') . qq|</th>
302 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
303 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
304 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
311 if ($form->{report} eq "income_statement") {
314 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
315 <td colspan=3>$projectnumber</td>
317 <input type=hidden name=nextsub value=generate_income_statement>
321 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
324 <th colspan=1>| . $locale->text('Year') . qq|</th>
325 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
331 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
332 <th align=left>| . $locale->text('Quarterly') . qq|</th>
333 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
336 <td align=right> <input name=duetyp class=radio type=radio value="13" "checked"></td>
337 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
341 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
345 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
346 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
350 <td align= right> </td>
351 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
352 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
353 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
354 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
358 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
359 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
360 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
361 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
366 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
367 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
368 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
369 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
373 <td colspan=5><hr size=3 noshade></td>
376 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
377 <td align=left colspan=4>| . $locale->text('From') . qq|
380 | . $locale->text('Bis') . qq|
386 <td colspan=5><hr size=3 noshade></td>
389 <th align=leftt>| . $locale->text('Method') . qq|</th>
390 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
391 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
398 if ($form->{report} eq "bwa") {
401 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
402 <td colspan=3>$projectnumber</td>
404 <input type=hidden name=nextsub value=generate_bwa>
408 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
411 <th colspan=1>| . $locale->text('Year') . qq|</th>
412 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
418 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
419 <th align=left>| . $locale->text('Quarterly') . qq|</th>
420 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
423 <td align=right> <input name=duetyp class=radio type=radio value="13"
425 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
427 $checked = "checked";
429 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
433 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
434 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
438 <td align= right> </td>
439 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
440 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
441 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
442 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
446 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
447 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
448 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
449 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
454 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
455 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
456 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
457 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
461 <td colspan=5><hr size=3 noshade></td>
464 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
465 <td align=left colspan=4>| . $locale->text('From') . qq|
468 | . $locale->text('Bis') . qq|
474 <td colspan=5><hr size=3 noshade></td>
477 <th align=leftt>| . $locale->text('Method') . qq|</th>
478 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
479 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
482 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
483 <td><input name=decimalplaces size=3 value="2"></td>
490 if ($form->{report} eq "balance_sheet") {
492 <input type=hidden name=nextsub value=generate_balance_sheet>
494 <th align=right>| . $locale->text('as at') . qq|</th>
499 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
506 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
507 <td><input name=decimalplaces size=3 value="2"></td>
516 <th align=right>| . $locale->text('Method') . qq|</th>
517 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
518 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
522 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
523 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
524 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|
525 <input name=l_accno class=checkbox type=checkbox value=Y> | . $locale->text('Account Number') . qq|</td>
532 if ($form->{report} eq "trial_balance") {
535 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
536 <td colspan=3>$projectnumber</td>
538 <input type=hidden name=nextsub value=generate_trial_balance>
542 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
545 <th colspan=1>| . $locale->text('Year') . qq|</th>
546 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
552 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
553 <th align=left>| . $locale->text('Quarterly') . qq|</th>
554 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
557 <td align=right> <input name=duetyp class=radio type=radio value="13" $checked></td>
558 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
560 $checked = "checked";
562 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
566 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
567 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
571 <td align= right> </td>
572 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
573 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
574 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
575 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
579 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
580 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
581 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
582 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
587 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
588 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
589 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
590 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
594 <td colspan=5><hr size=3 noshade></td>
597 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
598 <td align=left colspan=4>| . $locale->text('From') . qq|
601 | . $locale->text('Bis') . qq|
607 <td colspan=5><hr size=3 noshade></td>
610 <th align=leftt>| . $locale->text('Method') . qq|</th>
611 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
612 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
615 <th align=right colspan=4>| . $locale->text('All Accounts') . qq|</th>
616 <td><input name=all_accounts type=checkbox value=1></td>
619 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
620 <td><input name=decimalplaces size=3 value="2"></td>
627 if ($form->{report} =~ /^tax_/) {
628 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
630 RP->get_taxaccounts(\%myconfig, \%$form);
633 <input type=hidden name=nextsub value=generate_tax_report>
635 <th align=right>| . $locale->text('From') . qq|</th>
636 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
637 <th align=right>| . $locale->text('Bis') . qq|</th>
638 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
641 <th align=right>| . $locale->text('Report for') . qq|</th>
645 $checked = "checked";
646 foreach my $ref (@{ $form->{taxaccounts} }) {
649 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
651 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
652 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
659 <input type=hidden name=db value=$form->{db}>
660 <input type=hidden name=sort value=transdate>
665 <th align=right>| . $locale->text('Method') . qq|</th>
666 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
667 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
676 <th align=right>| . $locale->text('Include in Report') . qq|</th>
680 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
681 <td>| . $locale->text('ID') . qq|</td>
682 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
683 <td>| . $locale->text('Invoice') . qq|</td>
684 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
685 <td>| . $locale->text('Date') . qq|</td>
688 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
691 if ($form->{db} eq 'ar') {
692 print $locale->text('Customer');
694 if ($form->{db} eq 'ap') {
695 print $locale->text('Vendor');
699 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
700 <td>| . $locale->text('Amount') . qq|</td>
701 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
702 <td>| . $locale->text('Tax') . qq|</td>
703 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
704 <td>| . $locale->text('Total') . qq|</td>
707 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
708 <td>| . $locale->text('Subtotal') . qq|</td>
717 if ($form->{report} =~ /^nontaxable_/) {
718 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
721 <input type=hidden name=nextsub value=generate_tax_report>
723 <input type=hidden name=db value=$form->{db}>
724 <input type=hidden name=sort value=transdate>
725 <input type=hidden name=report value=$form->{report}>
728 <th align=right>| . $locale->text('From') . qq|</th>
729 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
730 <th align=right>| . $locale->text('Bis') . qq|</th>
731 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
734 <th align=right>| . $locale->text('Method') . qq|</th>
735 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
736 . $locale->text('Accrual') . qq|
737 <input name=method class=radio type=radio value=cash $cash>|
738 . $locale->text('EUR') . qq|</td>
741 <th align=right>| . $locale->text('Include in Report') . qq|</th>
745 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
746 <td>| . $locale->text('ID') . qq|</td>
747 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
748 <td>| . $locale->text('Invoice') . qq|</td>
749 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
750 <td>| . $locale->text('Date') . qq|</td>
753 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
756 if ($form->{db} eq 'ar') {
757 print $locale->text('Customer');
759 if ($form->{db} eq 'ap') {
760 print $locale->text('Vendor');
764 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
765 <td>| . $locale->text('Amount') . qq|</td>
766 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
767 <td>| . $locale->text('Total') . qq|</td>
770 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
771 <td>| . $locale->text('Subtotal') . qq|</td>
780 my ($label, $nextsub, $vc);
781 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
782 if ($form->{report} eq 'ar_aging') {
783 $label = $locale->text('Customer');
784 $form->{vc} = 'customer';
786 $label = $locale->text('Vendor');
787 $form->{vc} = 'vendor';
790 $nextsub = "generate_$form->{report}";
793 $form->all_vc(\%myconfig, $form->{vc},
794 ($form->{vc} eq 'customer') ? "AR" : "AP");
796 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
797 @{ $form->{"all_$form->{vc}"} };
801 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
802 : qq|<input name=$form->{vc} size=35>|;
806 <th align=right>| . $locale->text($label) . qq|</th>
810 <td>| . $locale->text('Review of Aging list') . qq|</td>
811 <td><select name="review_of_aging_list">
813 <option>0-30</option>
814 <option>30-60</option>
815 <option>60-90</option>
816 <option>90-120</option>
817 <option>> 120</option>
822 <td align=left colspan=4>| . $locale->text('From') . qq|
825 | . $locale->text('Bis') . qq|
830 <input type=hidden name=type value=statement>
831 <input type=hidden name=format value=html>
832 <input type=hidden name=media value=screen>
834 <input type=hidden name=nextsub value=$nextsub>
835 <input type=hidden name=action value=$nextsub>
841 # above action can be removed if there is more than one input field
843 my ($selection, $paymentaccounts);
844 if ($form->{report} =~ /(receipts|payments)$/) {
845 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
847 RP->paymentaccounts(\%myconfig, \%$form);
849 $selection = "<option>\n";
850 foreach my $ref (@{ $form->{PR} }) {
851 $paymentaccounts .= "$ref->{accno} ";
852 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
855 chop $paymentaccounts;
858 <input type=hidden name=nextsub value=list_payments>
860 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
861 <td colspan=3><select name=account>$selection</select>
862 <input type=hidden name=paymentaccounts value="$paymentaccounts">
866 <th align=right>| . $locale->text('Reference') . qq|</th>
867 <td colspan=3><input name=reference></td>
870 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
871 <td colspan=3><input name=source></td>
874 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
875 <td colspan=3><input name=memo size=30></td>
878 <th align=right>| . $locale->text('From') . qq|</th>
883 <th align=right>| . $locale->text('Bis') . qq|</th>
890 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
891 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
896 <input type=hidden name=db value=$form->{db}>
897 <input type=hidden name=sort value=transdate>
908 <td><hr size=3 noshade></td>
913 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
921 $main::lxdebug->leave_sub();
924 sub continue { call_sub($main::form->{"nextsub"}); }
927 $main::lxdebug->enter_sub();
929 $main::auth->assert('report');
931 my $form = $main::form;
932 my %myconfig = %main::myconfig;
933 my $locale = $main::locale;
937 $form->{project_id} = $form->{project_id_1};
938 if ($form->{projectnumber} && !$form->{project_id}) {
939 $form->{rowcount} = 1;
941 # call this instead of update
942 $form->{update} = $nextsub;
943 $form->{projectnumber_1} = $form->{projectnumber};
945 delete $form->{sort};
946 check_project('generate_projects');
948 # if there is one only, assign id
949 $form->{project_id} = $form->{project_id_1};
952 $main::lxdebug->leave_sub();
955 sub generate_income_statement {
956 $main::lxdebug->enter_sub();
958 $main::auth->assert('report');
960 my $form = $main::form;
961 my %myconfig = %main::myconfig;
962 my $locale = $main::locale;
964 $form->{padding} = " ";
965 $form->{bold} = "<b>";
966 $form->{endbold} = "</b>";
967 $form->{br} = "<br>";
969 if ($form->{reporttype} eq "custom") {
971 #forgotten the year --> thisyear
972 if ($form->{year} !~ m/^\d\d\d\d$/) {
973 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
979 if ($form->{duetyp} eq "13") {
980 $form->{fromdate} = "1.1.$form->{year}";
981 $form->{todate} = "31.12.$form->{year}";
985 if ($form->{duetyp} eq "A") {
986 $form->{fromdate} = "1.1.$form->{year}";
987 $form->{todate} = "31.3.$form->{year}";
989 if ($form->{duetyp} eq "B") {
990 $form->{fromdate} = "1.4.$form->{year}";
991 $form->{todate} = "30.6.$form->{year}";
993 if ($form->{duetyp} eq "C") {
994 $form->{fromdate} = "1.7.$form->{year}";
995 $form->{todate} = "30.9.$form->{year}";
997 if ($form->{duetyp} eq "D") {
998 $form->{fromdate} = "1.10.$form->{year}";
999 $form->{todate} = "31.12.$form->{year}";
1004 $form->{duetyp} eq "1" && do {
1005 $form->{fromdate} = "1.1.$form->{year}";
1006 $form->{todate} = "31.1.$form->{year}";
1009 $form->{duetyp} eq "2" && do {
1010 $form->{fromdate} = "1.2.$form->{year}";
1012 #this works from 1901 to 2099, 1900 and 2100 fail.
1013 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1014 $form->{todate} = "$leap.2.$form->{year}";
1017 $form->{duetyp} eq "3" && do {
1018 $form->{fromdate} = "1.3.$form->{year}";
1019 $form->{todate} = "31.3.$form->{year}";
1022 $form->{duetyp} eq "4" && do {
1023 $form->{fromdate} = "1.4.$form->{year}";
1024 $form->{todate} = "30.4.$form->{year}";
1027 $form->{duetyp} eq "5" && do {
1028 $form->{fromdate} = "1.5.$form->{year}";
1029 $form->{todate} = "31.5.$form->{year}";
1032 $form->{duetyp} eq "6" && do {
1033 $form->{fromdate} = "1.6.$form->{year}";
1034 $form->{todate} = "30.6.$form->{year}";
1037 $form->{duetyp} eq "7" && do {
1038 $form->{fromdate} = "1.7.$form->{year}";
1039 $form->{todate} = "31.7.$form->{year}";
1042 $form->{duetyp} eq "8" && do {
1043 $form->{fromdate} = "1.8.$form->{year}";
1044 $form->{todate} = "31.8.$form->{year}";
1047 $form->{duetyp} eq "9" && do {
1048 $form->{fromdate} = "1.9.$form->{year}";
1049 $form->{todate} = "30.9.$form->{year}";
1052 $form->{duetyp} eq "10" && do {
1053 $form->{fromdate} = "1.10.$form->{year}";
1054 $form->{todate} = "31.10.$form->{year}";
1057 $form->{duetyp} eq "11" && do {
1058 $form->{fromdate} = "1.11.$form->{year}";
1059 $form->{todate} = "30.11.$form->{year}";
1062 $form->{duetyp} eq "12" && do {
1063 $form->{fromdate} = "1.12.$form->{year}";
1064 $form->{todate} = "31.12.$form->{year}";
1068 hotfix_reformat_date();
1069 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
1071 RP->income_statement(\%myconfig, \%$form);
1073 ($form->{department}) = split /--/, $form->{department};
1076 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1077 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1079 # if there are any dates construct a where
1080 if ($form->{fromdate} || $form->{todate}) {
1082 unless ($form->{todate}) {
1083 $form->{todate} = $form->current_date(\%myconfig);
1086 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1087 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1089 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1090 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1092 $form->{this_period} = "$shortfromdate\n$shorttodate";
1094 $locale->text('for Period')
1095 . qq|\n$longfromdate |
1096 . $locale->text('Bis')
1100 if ($form->{comparefromdate} || $form->{comparetodate}) {
1101 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1102 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1104 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1105 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1107 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1109 "\n$longcomparefromdate "
1110 . $locale->text('Bis')
1111 . qq| $longcomparetodate|;
1114 # setup variables for the form
1115 my @a = qw(company address businessnumber);
1116 map { $form->{$_} = $myconfig{$_} } @a;
1118 $form->{templates} = $myconfig{templates};
1120 $form->{IN} = "income_statement.html";
1122 $form->parse_template;
1124 $main::lxdebug->leave_sub();
1127 sub generate_balance_sheet {
1128 $::lxdebug->enter_sub;
1129 $::auth->assert('report');
1131 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
1132 $::form->{padding} = " ";
1133 $::form->{bold} = "<b>";
1134 $::form->{endbold} = "</b>";
1135 $::form->{br} = "<br>";
1137 my $data = RP->balance_sheet(\%::myconfig, $::form);
1139 $::form->{asofdate} ||= $::form->current_date;
1140 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
1142 ($::form->{department}) = split /--/, $::form->{department};
1144 # define Current Earnings account
1145 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
1146 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
1148 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
1149 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
1151 # $::form->{IN} = "balance_sheet.html";
1153 # setup company variables for the form
1154 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
1156 $::form->{templates} = $::myconfig{templates};
1159 print $::form->parse_html_template('rp/balance_sheet', $data);
1161 $::lxdebug->leave_sub;
1164 sub generate_projects {
1165 $main::lxdebug->enter_sub();
1167 $main::auth->assert('report');
1169 my $form = $main::form;
1170 my %myconfig = %main::myconfig;
1171 my $locale = $main::locale;
1173 &get_project("generate_projects");
1174 $form->{projectnumber} = $form->{projectnumber_1};
1176 $form->{nextsub} = "generate_projects";
1177 $form->{title} = $locale->text('Project Transactions');
1178 RP->trial_balance(\%myconfig, \%$form);
1180 list_accounts('generate_projects');
1182 $main::lxdebug->leave_sub();
1188 # included links to display transactions for period entered
1189 # added headers and subtotals
1191 sub generate_trial_balance {
1192 $main::lxdebug->enter_sub();
1194 $main::auth->assert('report');
1196 my $form = $main::form;
1197 my %myconfig = %main::myconfig;
1198 my $locale = $main::locale;
1200 if ($form->{reporttype} eq "custom") {
1202 #forgotten the year --> thisyear
1203 if ($form->{year} !~ m/^\d\d\d\d$/) {
1204 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1210 if ($form->{duetyp} eq "13") {
1211 $form->{fromdate} = "1.1.$form->{year}";
1212 $form->{todate} = "31.12.$form->{year}";
1216 if ($form->{duetyp} eq "A") {
1217 $form->{fromdate} = "1.1.$form->{year}";
1218 $form->{todate} = "31.3.$form->{year}";
1220 if ($form->{duetyp} eq "B") {
1221 $form->{fromdate} = "1.4.$form->{year}";
1222 $form->{todate} = "30.6.$form->{year}";
1224 if ($form->{duetyp} eq "C") {
1225 $form->{fromdate} = "1.7.$form->{year}";
1226 $form->{todate} = "30.9.$form->{year}";
1228 if ($form->{duetyp} eq "D") {
1229 $form->{fromdate} = "1.10.$form->{year}";
1230 $form->{todate} = "31.12.$form->{year}";
1235 $form->{duetyp} eq "1" && do {
1236 $form->{fromdate} = "1.1.$form->{year}";
1237 $form->{todate} = "31.1.$form->{year}";
1240 $form->{duetyp} eq "2" && do {
1241 $form->{fromdate} = "1.2.$form->{year}";
1243 #this works from 1901 to 2099, 1900 and 2100 fail.
1244 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1245 $form->{todate} = "$leap.2.$form->{year}";
1248 $form->{duetyp} eq "3" && do {
1249 $form->{fromdate} = "1.3.$form->{year}";
1250 $form->{todate} = "31.3.$form->{year}";
1253 $form->{duetyp} eq "4" && do {
1254 $form->{fromdate} = "1.4.$form->{year}";
1255 $form->{todate} = "30.4.$form->{year}";
1258 $form->{duetyp} eq "5" && do {
1259 $form->{fromdate} = "1.5.$form->{year}";
1260 $form->{todate} = "31.5.$form->{year}";
1263 $form->{duetyp} eq "6" && do {
1264 $form->{fromdate} = "1.6.$form->{year}";
1265 $form->{todate} = "30.6.$form->{year}";
1268 $form->{duetyp} eq "7" && do {
1269 $form->{fromdate} = "1.7.$form->{year}";
1270 $form->{todate} = "31.7.$form->{year}";
1273 $form->{duetyp} eq "8" && do {
1274 $form->{fromdate} = "1.8.$form->{year}";
1275 $form->{todate} = "31.8.$form->{year}";
1278 $form->{duetyp} eq "9" && do {
1279 $form->{fromdate} = "1.9.$form->{year}";
1280 $form->{todate} = "30.9.$form->{year}";
1283 $form->{duetyp} eq "10" && do {
1284 $form->{fromdate} = "1.10.$form->{year}";
1285 $form->{todate} = "31.10.$form->{year}";
1288 $form->{duetyp} eq "11" && do {
1289 $form->{fromdate} = "1.11.$form->{year}";
1290 $form->{todate} = "30.11.$form->{year}";
1293 $form->{duetyp} eq "12" && do {
1294 $form->{fromdate} = "1.12.$form->{year}";
1295 $form->{todate} = "31.12.$form->{year}";
1299 hotfix_reformat_date();
1303 # get for each account initial balance, debits and credits
1304 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
1307 $form->{rowcount} = scalar @{ $form->{TB} || [] };
1308 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1311 "accno", "description",
1312 "last_transaction", "soll_eb",
1315 "soll_kumuliert", "haben_kumuliert",
1316 "soll_saldo", "haben_saldo"
1320 my $attachment_basename = $locale->text('trial_balance');
1321 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1323 my @hidden_variables = qw(fromdate todate year cash);
1325 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1328 'accno' => { 'text' => $locale->text('Account'), },
1329 'description' => { 'text' => $locale->text('Description'), },
1330 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1331 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1332 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1333 'soll' => { 'text' => $locale->text('Debit'), },
1334 'haben' => { 'text' => $locale->text('Credit'), },
1335 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1336 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1337 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1338 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1343 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1345 map { $column_defs{$_}->{visible} = 1 } @columns;
1347 $report->set_columns(%column_defs);
1348 $report->set_column_order(@columns);
1350 $report->set_export_options('generate_trial_balance', @hidden_variables);
1355 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1357 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
1358 push (@options, $form->{print_date});
1360 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
1361 push (@options, $form->{company});
1364 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1366 $report->set_options('output_format' => 'HTML',
1367 'top_info_text' => join("\n", @options),
1368 'title' => $form->{title},
1369 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1370 'html_template' => 'rp/html_report_susa',
1371 'pdf_template' => 'rp/html_report_susa',
1373 $report->set_options_from_form();
1374 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1376 # add sort and escape callback, this one we use for the add sub
1377 $form->{callback} = $href .= "&sort=$form->{sort}";
1379 # escape callback for href
1380 my $callback = $form->escape($href);
1382 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1384 my %totals = map { $_ => 0 } @subtotal_columns;
1386 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1389 foreach my $accno (@{ $form->{TB} || [] }) {
1391 $accno->{soll} = $accno->{debit};
1392 $accno->{haben} = $accno->{credit};
1393 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1395 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
1396 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1400 foreach my $column (@columns) {
1402 'data' => $accno->{$column},
1403 'align' => $column_alignment{$column},
1407 $row->{accno}->{link} = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($accno->{accno}), 'description=' . E($accno->{description}), 'fromdate=' . E($form->{fromdate}), 'todate=' . E($form->{todate}), 'method=' . E($form->{method}));
1409 my $row_set = [ $row ];
1412 $report->add_data($row_set);
1417 $report->add_separator();
1419 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1421 $report->generate_with_headers();
1423 $main::lxdebug->leave_sub();
1427 sub create_subtotal_row {
1428 $main::lxdebug->enter_sub();
1430 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1432 my $form = $main::form;
1433 my %myconfig = %main::myconfig;
1434 my $locale = $main::locale;
1436 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1438 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1440 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1442 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1444 $main::lxdebug->leave_sub();
1449 sub create_list_accounts_subtotal_row {
1450 $main::lxdebug->enter_sub();
1452 my ($subtotals, $columns, $fields, $class) = @_;
1454 my $form = $main::form;
1455 my %myconfig = %main::myconfig;
1456 my $locale = $main::locale;
1458 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1460 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1462 $main::lxdebug->leave_sub();
1468 $main::lxdebug->enter_sub();
1472 my $form = $main::form;
1473 my %myconfig = %main::myconfig;
1474 my $locale = $main::locale;
1477 if ($form->{department}) {
1478 my ($department) = split /--/, $form->{department};
1479 push @options, $locale->text('Department') . " : $department";
1481 if ($form->{projectnumber}) {
1482 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1485 # if there are any dates
1486 if ($form->{fromdate} || $form->{todate}) {
1487 my ($fromdate, $todate);
1489 if ($form->{fromdate}) {
1490 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1492 if ($form->{todate}) {
1493 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1496 push @options, "$fromdate - $todate";
1499 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1502 my @columns = qw(accno description begbalance debit credit endbalance);
1504 'accno' => { 'text' => $locale->text('Account'), },
1505 'description' => { 'text' => $locale->text('Description'), },
1506 'debit' => { 'text' => $locale->text('Debit'), },
1507 'credit' => { 'text' => $locale->text('Credit'), },
1508 'begbalance' => { 'text' => $locale->text('Balance'), },
1509 'endbalance' => { 'text' => $locale->text('Balance'), },
1511 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1513 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1515 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1517 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1519 $report->set_options('top_info_text' => join("\n", @options),
1520 'output_format' => 'HTML',
1521 'title' => $form->{title},
1522 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1523 'std_column_visibility' => 1,
1525 $report->set_options_from_form();
1526 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1528 $report->set_columns(%column_defs);
1529 $report->set_column_order(@columns);
1531 $report->set_export_options($action, @hidden_variables);
1533 my @totals_columns = qw(credit debit begbalance endbalance);
1534 my %subtotals = map { $_ => 0 } @totals_columns;
1535 my %totals = map { $_ => 0 } @totals_columns;
1536 my $found_heading = 0;
1537 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
1539 # sort the whole thing by account numbers and display
1540 foreach my $idx (0 .. scalar(@tb) - 1) {
1541 my $ref = $tb[$idx];
1542 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1544 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1546 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1548 if ($ref->{charttype} eq 'H') {
1549 next unless ($form->{l_heading});
1551 %subtotals = map { $_ => 0 } @totals_columns;
1553 $row->{description}->{class} = 'listheading';
1554 $row->{description}->{data} = $ref->{description};
1556 $report->add_data($row);
1561 foreach (qw(debit credit)) {
1562 $subtotals{$_} += $ref->{$_};
1563 $totals{$_} += $ref->{$_};
1566 $subtotals{begbalance} += $ref->{balance} * $ml;
1567 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1569 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1570 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1572 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1573 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1575 $report->add_data($row);
1577 if ($form->{l_heading} && $found_heading &&
1578 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1579 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1583 $report->add_separator();
1585 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1587 $report->generate_with_headers();
1589 $main::lxdebug->leave_sub();
1592 sub generate_ar_aging {
1593 $main::lxdebug->enter_sub();
1595 $main::auth->assert('general_ledger');
1597 my $form = $main::form;
1598 my %myconfig = %main::myconfig;
1599 my $locale = $main::locale;
1602 ($form->{customer}) = split(/--/, $form->{customer});
1604 $form->{ct} = "customer";
1605 $form->{arap} = "ar";
1607 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1609 RP->aging(\%myconfig, \%$form);
1612 $main::lxdebug->leave_sub();
1615 sub generate_ap_aging {
1616 $main::lxdebug->enter_sub();
1618 $main::auth->assert('general_ledger');
1620 my $form = $main::form;
1621 my %myconfig = %main::myconfig;
1622 my $locale = $main::locale;
1625 ($form->{vendor}) = split(/--/, $form->{vendor});
1627 $form->{ct} = "vendor";
1628 $form->{arap} = "ap";
1630 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1632 RP->aging(\%myconfig, \%$form);
1635 $main::lxdebug->leave_sub();
1638 sub create_aging_subtotal_row {
1639 $main::lxdebug->enter_sub();
1641 my ($subtotals, $columns, $periods, $class) = @_;
1643 my $form = $main::form;
1644 my %myconfig = %main::myconfig;
1645 my $locale = $main::locale;
1647 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1649 foreach (@{ $periods }) {
1650 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1651 $subtotals->{$_} = 0;
1654 $main::lxdebug->leave_sub();
1660 $main::lxdebug->enter_sub();
1662 $main::auth->assert('general_ledger');
1664 my $form = $main::form;
1665 my %myconfig = %main::myconfig;
1666 my $locale = $main::locale;
1667 my $cgi = $::request->{cgi};
1669 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1671 my @columns = qw(statement ct invnumber transdate duedate amount open);
1674 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1675 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1676 'invnumber' => { 'text' => $locale->text('Invoice'), },
1677 'transdate' => { 'text' => $locale->text('Date'), },
1678 'duedate' => { 'text' => $locale->text('Due'), },
1679 'amount' => { 'text' => $locale->text('Amount'), },
1680 'open' => { 'text' => $locale->text('Open'), },
1683 my %column_alignment = ('statement' => 'center',
1684 map { $_ => 'right' } qw(open amount));
1686 $report->set_options('std_column_visibility' => 1);
1687 $report->set_columns(%column_defs);
1688 $report->set_column_order(@columns);
1690 my @hidden_variables = qw(todate customer vendor arap title ct);
1691 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1694 my $attachment_basename;
1696 if ($form->{department}) {
1697 my ($department) = split /--/, $form->{department};
1698 push @options, $locale->text('Department') . " : $department";
1699 $form->{callback} .= "&department=" . E($department);
1702 if (($form->{arap} eq 'ar') && $form->{customer}) {
1703 push @options, $form->{customer};
1704 $attachment_basename = $locale->text('ar_aging_list');
1705 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1708 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1709 push @options, $form->{vendor};
1710 $attachment_basename = $locale->text('ap_aging_list');
1711 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1714 if ($form->{fromdate}) {
1715 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1717 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1720 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1722 $report->set_options('top_info_text' => join("\n", @options),
1723 'output_format' => 'HTML',
1724 'title' => $form->{title},
1725 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1727 $report->set_options_from_form();
1728 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1730 my $previous_ctid = 0;
1732 my @periods = qw(open amount);
1733 my %subtotals = map { $_ => 0 } @periods;
1734 my %totals = map { $_ => 0 } @periods;
1736 foreach my $ref (@{ $form->{AG} }) {
1737 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1738 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1741 foreach my $key (@periods) {
1742 $subtotals{$key} += $ref->{"$key"};
1743 $totals{$key} += $ref->{"$key"};
1744 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1749 foreach my $column (@columns) {
1751 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1752 'align' => $column_alignment{$column},
1753 'valign' => $column eq 'statement' ? 'center' : '',
1757 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1759 if ($previous_ctid != $ref->{ctid}) {
1760 $row->{statement}->{raw_data} =
1761 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1762 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1763 $row->{ct}->{data} = $ref->{name};
1768 $previous_ctid = $ref->{ctid};
1770 $report->add_data($row);
1773 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1775 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1777 if ($form->{arap} eq 'ar') {
1778 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1779 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1780 'PRINT_OPTIONS' => print_options(inline => 1), });
1781 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1782 'raw_bottom_info_text' => $raw_bottom_info_text);
1785 $report->generate_with_headers();
1787 $main::lxdebug->leave_sub();
1791 $main::lxdebug->enter_sub();
1793 my $form = $main::form;
1794 my %myconfig = %main::myconfig;
1795 my $locale = $main::locale;
1797 RP->aging(\%myconfig, \%$form);
1799 map { $_->{checked} = "checked" } @{ $form->{AG} };
1803 $main::lxdebug->leave_sub();
1807 $main::lxdebug->enter_sub();
1809 $main::auth->assert('general_ledger');
1811 my $form = $main::form;
1812 my %myconfig = %main::myconfig;
1813 my $locale = $main::locale;
1815 # get name and email addresses
1817 for my $i (1 .. $form->{rowcount}) {
1818 if ($form->{"statement_$i"}) {
1819 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1820 RP->get_customer(\%myconfig, \%$form);
1826 $form->error($locale->text('Nothing selected!')) unless $selected;
1829 if ($myconfig{role} eq 'admin') {
1831 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1832 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1836 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1838 $form->{media} = "email";
1845 <form method=post action=$form->{script}>
1851 <tr height="5"></tr>
1856 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1857 <td><input name=email size=30 value="$form->{email}"></td>
1858 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1859 <td><input name=cc size=30 value="$form->{cc}"></td>
1862 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1863 <td><input name=subject size=30 value="$form->{subject}"></td>
1873 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1876 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1887 map { delete $form->{$_} }
1888 qw(action email cc bcc subject message type sendmode format header);
1890 # save all other variables
1891 foreach my $key (keys %$form) {
1892 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1893 $form->{$key} =~ s/\"/"/g;
1894 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1901 <td><hr size=3 noshade></td>
1905 <input type=hidden name=nextsub value=send_email>
1908 <input name=action class=submit type=submit value="|
1909 . $locale->text('Continue') . qq|">
1916 $main::lxdebug->leave_sub();
1920 $main::lxdebug->enter_sub();
1922 $main::auth->assert('general_ledger');
1924 my $form = $main::form;
1925 my %myconfig = %main::myconfig;
1926 my $locale = $main::locale;
1928 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1929 unless $form->{subject};
1931 RP->aging(\%myconfig, \%$form);
1933 $form->{"statement_1"} = 1;
1935 $form->{media} = 'email';
1938 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1940 $main::lxdebug->leave_sub();
1944 $main::lxdebug->enter_sub();
1946 $main::auth->assert('general_ledger');
1948 my $form = $main::form;
1949 my %myconfig = %main::myconfig;
1950 my $locale = $main::locale;
1952 if ($form->{media} eq 'printer') {
1953 $form->error($locale->text('Select postscript or PDF!'))
1954 if ($form->{format} !~ /(postscript|pdf)/);
1958 for my $i (1 .. $form->{rowcount}) {
1959 if ($form->{"statement_$i"}) {
1960 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1966 $form->error($locale->text('Nothing selected!')) unless $selected;
1968 if ($form->{media} eq 'printer') {
1969 $form->{"$form->{ct}_id"} = "";
1971 $form->{"statement_1"} = 1;
1974 RP->aging(\%myconfig, \%$form);
1978 $form->redirect($locale->text('Statements sent to printer!'))
1979 if ($form->{media} eq 'printer');
1981 $main::lxdebug->leave_sub();
1985 $main::lxdebug->enter_sub();
1987 $main::auth->assert('general_ledger');
1989 my $form = $main::form;
1990 my %myconfig = %main::myconfig;
1991 my $locale = $main::locale;
1993 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1995 $form->{templates} = "$myconfig{templates}";
1997 my $suffix = "html";
1998 my $attachment_suffix = "html";
1999 if ($form->{format} eq 'postscript') {
2000 $form->{postscript} = 1;
2002 $attachment_suffix = "ps";
2003 } elsif ($form->{format} eq 'pdf') {
2006 $attachment_suffix = "pdf";
2009 $form->{IN} = "$form->{type}.$suffix";
2010 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
2012 # Save $form->{email} because it will be overwritten.
2013 $form->{EMAIL_RECIPIENT} = $form->{email};
2017 while (@{ $form->{AG} }) {
2019 my $ref = shift @{ $form->{AG} };
2021 if ($ctid != $ref->{ctid}) {
2023 $ctid = $ref->{ctid};
2026 if ($form->{"statement_$i"}) {
2029 ("name", "street", "zipcode", "city", "country", "contact", "email",
2030 "$form->{ct}phone", "$form->{ct}fax");
2031 map { $form->{$_} = $ref->{$_} } @a;
2033 $form->{ $form->{ct} } = $form->{name};
2034 $form->{"$form->{ct}_id"} = $ref->{ctid};
2036 map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
2038 foreach my $item (qw(c0 c30 c60 c90)) {
2039 $form->{$item} = ();
2040 $form->{"${item}total"} = 0;
2043 &statement_details($ref);
2047 if (scalar(@{ $form->{AG} }) > 0) {
2049 # one or more left to go
2050 if ($ctid == $form->{AG}->[0]->{ctid}) {
2051 $ref = shift @{ $form->{AG} };
2052 &statement_details($ref);
2055 $ref = scalar(@{ $form->{AG} });
2061 # set initial ref to 0
2068 $form->{"${_}total"} =
2069 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2070 } ('c0', 'c30', 'c60', 'c90', "");
2072 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2073 $form->{attachment_filename} =~ s/\s+/_/g;
2075 $form->parse_template(\%myconfig);
2080 # saving the history
2081 if(!exists $form->{addition} && $form->{id} ne "") {
2082 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2083 $form->{addition} = "PRINTED";
2084 $form->{what_done} = $form->{type};
2085 $form->save_history;
2087 # /saving the history
2088 $main::lxdebug->leave_sub();
2091 sub statement_details {
2092 $main::lxdebug->enter_sub();
2094 $main::auth->assert('general_ledger');
2096 my $form = $main::form;
2097 my %myconfig = %main::myconfig;
2098 my $locale = $main::locale;
2102 push @{ $form->{invnumber} }, $ref->{invnumber};
2103 push @{ $form->{invdate} }, $ref->{transdate};
2104 push @{ $form->{duedate} }, $ref->{duedate};
2105 push @{ $form->{amount} }, $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
2106 push @{ $form->{open} }, $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
2108 foreach my $item (qw(c0 c30 c60 c90)) {
2109 if ($ref->{exchangerate} * 1) {
2110 # add only the open amount of the invoice to the aging, not the total amount
2111 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
2112 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
2113 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
2114 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
2116 $form->{"${item}total"} += $ref->{$item};
2117 $form->{total} += $ref->{$item};
2118 push @{ $form->{$item} },
2119 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2122 $main::lxdebug->leave_sub();
2125 sub generate_tax_report {
2126 $main::lxdebug->enter_sub();
2128 $main::auth->assert('report');
2130 my $form = $main::form;
2131 my %myconfig = %main::myconfig;
2132 my $locale = $main::locale;
2134 RP->tax_report(\%myconfig, \%$form);
2136 my $descvar = "$form->{accno}_description";
2137 my $description = $form->escape($form->{$descvar});
2138 my $ratevar = "$form->{accno}_rate";
2139 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
2141 my $department = $form->escape($form->{department});
2145 "$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&report=$form->{report}";
2147 # construct callback
2148 $description = $form->escape($form->{$descvar}, 1);
2149 $department = $form->escape($form->{department}, 1);
2151 "$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&report=$form->{report}";
2153 my $title = $form->escape($form->{title});
2154 $href .= "&title=$title";
2155 $title = $form->escape($form->{title}, 1);
2156 $callback .= "&title=$title";
2158 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2161 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2164 foreach my $item (@columns) {
2165 if ($form->{"l_$item"} eq "Y") {
2166 push @column_index, $item;
2168 # add column to href and callback
2169 $callback .= "&l_$item=Y";
2170 $href .= "&l_$item=Y";
2174 if ($form->{l_subtotal} eq 'Y') {
2175 $callback .= "&l_subtotal=Y";
2176 $href .= "&l_subtotal=Y";
2180 if ($form->{department}) {
2181 ($department) = split /--/, $form->{department};
2182 $option = $locale->text('Department') . " : $department";
2185 my ($fromdate, $todate);
2186 # if there are any dates
2187 if ($form->{fromdate} || $form->{todate}) {
2188 if ($form->{fromdate}) {
2189 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2191 if ($form->{todate}) {
2192 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2195 $form->{period} = "$fromdate - $todate";
2198 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2201 my ($name, $invoice, $arap);
2202 if ($form->{db} eq 'ar') {
2203 $name = $locale->text('Customer');
2207 if ($form->{db} eq 'ap') {
2208 $name = $locale->text('Vendor');
2213 $option .= "<br>" if $option;
2214 $option .= "$form->{period}";
2217 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2218 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2219 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2220 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2221 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2222 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2224 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2233 <th class=listtop>$form->{title}</th>
2235 <tr height="5"></tr>
2242 <tr class=listheading>
2245 map { print "$column_header{$_}\n" } @column_index;
2251 # add sort and escape callback
2252 $callback = $form->escape($callback . "&sort=$form->{sort}");
2255 if (@{ $form->{TR} }) {
2256 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2259 my ($totalnetamount, $totaltax);
2261 foreach my $ref (@{ $form->{TR} }) {
2263 my $module = ($ref->{invoice}) ? $invoice : $arap;
2265 if ($form->{l_subtotal} eq 'Y') {
2266 if ($sameitem ne $ref->{ $form->{sort} }) {
2267 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2268 $sameitem = $ref->{ $form->{sort} };
2272 $totalnetamount += $ref->{netamount};
2273 $totaltax += $ref->{tax};
2274 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2276 $subtotalnetamount += $ref->{netamount};
2277 $subtotaltax += $ref->{tax};
2280 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2281 } qw(netamount tax amount);
2284 $column_data{id} = qq|<td>$ref->{id}</td>|;
2285 $column_data{invnumber} =
2286 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2287 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2288 $column_data{name} = qq|<td>$ref->{name} </td>|;
2290 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2291 qw(netamount tax amount);
2296 <tr class=listrow$i>
2299 map { print "$column_data{$_}\n" } @column_index;
2307 if ($form->{l_subtotal} eq 'Y') {
2308 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2312 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2316 <tr class=listtotal>
2319 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2320 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2321 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2323 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
2324 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2325 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2327 map { print "$column_data{$_}\n" } @column_index;
2335 <td><hr size=3 noshade></td>
2343 $main::lxdebug->leave_sub();
2347 $main::lxdebug->enter_sub();
2349 my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
2351 my $form = $main::form;
2352 my %myconfig = %main::myconfig;
2353 my $locale = $main::locale;
2356 map { $column_data{$_} = "<td> </td>" } @{ $column_index };
2358 $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " ");
2359 $$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " ");
2360 $$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " ");
2362 $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
2363 $column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>";
2364 $column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>";
2366 $$subtotalnetamount = 0;
2370 <tr class=listsubtotal>
2372 map { print "\n$column_data{$_}" } @{ $column_index };
2378 $main::lxdebug->leave_sub();
2382 $main::lxdebug->enter_sub();
2384 $main::auth->assert('cash');
2386 my $form = $main::form;
2387 my %myconfig = %main::myconfig;
2388 my $locale = $main::locale;
2390 if ($form->{account}) {
2391 ($form->{paymentaccounts}) = split /--/, $form->{account};
2395 if ($form->{department}) {
2396 (my $department, $form->{department_id}) = split /--/, $form->{department};
2397 $option = $locale->text('Department') . " : $department";
2400 report_generator_set_default_sort('transdate', 1);
2402 RP->payments(\%myconfig, \%$form);
2404 my @hidden_variables = qw(account title department reference source memo fromdate todate
2405 fx_transaction db prepayment paymentaccounts sort);
2407 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2408 $form->{callback} = $href;
2410 my @columns = qw(transdate invnumber name paid source memo);
2412 'name' => { 'text' => $locale->text('Description'), },
2413 'invnumber' => { 'text' => $locale->text('Reference'), },
2414 'transdate' => { 'text' => $locale->text('Date'), },
2415 'paid' => { 'text' => $locale->text('Amount'), },
2416 'source' => { 'text' => $locale->text('Source'), },
2417 'memo' => { 'text' => $locale->text('Memo'), },
2419 my %column_alignment = ('paid' => 'right');
2421 foreach my $name (grep { $_ ne 'paid' } @columns) {
2422 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2423 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2427 if ($form->{fromdate}) {
2428 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2430 if ($form->{todate}) {
2431 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2434 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2436 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2438 $report->set_options('top_info_text' => join("\n", @options),
2439 'output_format' => 'HTML',
2440 'title' => $form->{title},
2441 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2442 'std_column_visibility' => 1,
2444 $report->set_options_from_form();
2446 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
2448 $report->set_columns(%column_defs);
2449 $report->set_column_order(@columns);
2451 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2453 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2457 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2458 next unless @{ $form->{ $ref->{id} } };
2460 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2462 my $subtotal_paid = 0;
2464 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2465 my $module = $payment->{module};
2466 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2467 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2469 $subtotal_paid += $payment->{paid};
2470 $total_paid += $payment->{paid};
2472 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2476 foreach my $column (@columns) {
2478 'data' => $payment->{$column},
2479 'align' => $column_alignment{$column},
2483 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2485 $report->add_data($row);
2488 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2490 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2492 'class' => 'listsubtotal',
2495 $report->add_data($row);
2498 $report->add_separator();
2500 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2502 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2504 'class' => 'listtotal',
2507 $report->add_data($row);
2509 $report->generate_with_headers();
2511 $main::lxdebug->leave_sub();
2515 $main::lxdebug->enter_sub();
2517 my ($dont_print) = @_;
2519 my $form = $main::form;
2520 my %myconfig = %main::myconfig;
2521 my $locale = $main::locale;
2523 $form->{sendmode} = "attachment";
2526 $form->{"format"} ? $form->{"format"} :
2527 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2531 $form->{"copies"} ? $form->{"copies"} :
2532 $myconfig{"copies"} ? $myconfig{"copies"} :
2535 $form->{PD}{ $form->{type} } = "selected";
2536 $form->{DF}{ $form->{format} } = "selected";
2537 $form->{OP}{ $form->{media} } = "selected";
2538 $form->{SM}{ $form->{sendmode} } = "selected";
2542 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
2544 if ($form->{media} eq 'email') {
2546 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
2547 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2550 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2551 if ($myconfig{printer} && $::lx_office_conf{print_templates}->{latex}) {
2553 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
2558 if ($::lx_office_conf{print_templates}->{latex}) {
2560 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2561 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2562 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2568 <td><select name=type>$type</select></td>
2569 <td><select name=format>$format</select></td>
2570 <td><select name=media>$media</select></td>
2573 if ($myconfig{printer} && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email') {
2575 <td>| . $locale->text('Copies') . qq|
2576 <input name=copies size=2 value=$form->{copies}></td>
2585 print $output unless $dont_print;
2587 $main::lxdebug->leave_sub();
2593 $main::lxdebug->enter_sub();
2595 $main::auth->assert('report');
2597 my $form = $main::form;
2598 my %myconfig = %main::myconfig;
2599 my $locale = $main::locale;
2601 $form->{padding} = " ";
2602 $form->{bold} = "<b>";
2603 $form->{endbold} = "</b>";
2604 $form->{br} = "<br>";
2606 if ($form->{reporttype} eq "custom") {
2608 #forgotten the year --> thisyear
2609 if ($form->{year} !~ m/^\d\d\d\d$/) {
2610 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2616 if ($form->{duetyp} eq "13") {
2617 $form->{fromdate} = "1.1.$form->{year}";
2618 $form->{todate} = "31.12.$form->{year}";
2619 $form->{comparefromdate} = "1.01.$form->{year}";
2620 $form->{comparetodate} = "31.12.$form->{year}";
2624 if ($form->{duetyp} eq "A") {
2625 $form->{fromdate} = "1.1.$form->{year}";
2626 $form->{todate} = "31.3.$form->{year}";
2627 $form->{comparefromdate} = "1.01.$form->{year}";
2628 $form->{comparetodate} = "31.03.$form->{year}";
2630 if ($form->{duetyp} eq "B") {
2631 $form->{fromdate} = "1.4.$form->{year}";
2632 $form->{todate} = "30.6.$form->{year}";
2633 $form->{comparefromdate} = "1.01.$form->{year}";
2634 $form->{comparetodate} = "30.06.$form->{year}";
2636 if ($form->{duetyp} eq "C") {
2637 $form->{fromdate} = "1.7.$form->{year}";
2638 $form->{todate} = "30.9.$form->{year}";
2639 $form->{comparefromdate} = "1.01.$form->{year}";
2640 $form->{comparetodate} = "30.09.$form->{year}";
2642 if ($form->{duetyp} eq "D") {
2643 $form->{fromdate} = "1.10.$form->{year}";
2644 $form->{todate} = "31.12.$form->{year}";
2645 $form->{comparefromdate} = "1.01.$form->{year}";
2646 $form->{comparetodate} = "31.12.$form->{year}";
2651 $form->{duetyp} eq "1" && do {
2652 $form->{fromdate} = "1.1.$form->{year}";
2653 $form->{todate} = "31.1.$form->{year}";
2654 $form->{comparefromdate} = "1.01.$form->{year}";
2655 $form->{comparetodate} = "31.01.$form->{year}";
2658 $form->{duetyp} eq "2" && do {
2659 $form->{fromdate} = "1.2.$form->{year}";
2661 #this works from 1901 to 2099, 1900 and 2100 fail.
2662 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2663 $form->{todate} = "$leap.2.$form->{year}";
2664 $form->{comparefromdate} = "1.01.$form->{year}";
2665 $form->{comparetodate} = "$leap.02.$form->{year}";
2668 $form->{duetyp} eq "3" && do {
2669 $form->{fromdate} = "1.3.$form->{year}";
2670 $form->{todate} = "31.3.$form->{year}";
2671 $form->{comparefromdate} = "1.01.$form->{year}";
2672 $form->{comparetodate} = "31.03.$form->{year}";
2675 $form->{duetyp} eq "4" && do {
2676 $form->{fromdate} = "1.4.$form->{year}";
2677 $form->{todate} = "30.4.$form->{year}";
2678 $form->{comparefromdate} = "1.01.$form->{year}";
2679 $form->{comparetodate} = "30.04.$form->{year}";
2682 $form->{duetyp} eq "5" && do {
2683 $form->{fromdate} = "1.5.$form->{year}";
2684 $form->{todate} = "31.5.$form->{year}";
2685 $form->{comparefromdate} = "1.01.$form->{year}";
2686 $form->{comparetodate} = "31.05.$form->{year}";
2689 $form->{duetyp} eq "6" && do {
2690 $form->{fromdate} = "1.6.$form->{year}";
2691 $form->{todate} = "30.6.$form->{year}";
2692 $form->{comparefromdate} = "1.01.$form->{year}";
2693 $form->{comparetodate} = "30.06.$form->{year}";
2696 $form->{duetyp} eq "7" && do {
2697 $form->{fromdate} = "1.7.$form->{year}";
2698 $form->{todate} = "31.7.$form->{year}";
2699 $form->{comparefromdate} = "1.01.$form->{year}";
2700 $form->{comparetodate} = "31.07.$form->{year}";
2703 $form->{duetyp} eq "8" && do {
2704 $form->{fromdate} = "1.8.$form->{year}";
2705 $form->{todate} = "31.8.$form->{year}";
2706 $form->{comparefromdate} = "1.01.$form->{year}";
2707 $form->{comparetodate} = "31.08.$form->{year}";
2710 $form->{duetyp} eq "9" && do {
2711 $form->{fromdate} = "1.9.$form->{year}";
2712 $form->{todate} = "30.9.$form->{year}";
2713 $form->{comparefromdate} = "1.01.$form->{year}";
2714 $form->{comparetodate} = "30.09.$form->{year}";
2717 $form->{duetyp} eq "10" && do {
2718 $form->{fromdate} = "1.10.$form->{year}";
2719 $form->{todate} = "31.10.$form->{year}";
2720 $form->{comparefromdate} = "1.01.$form->{year}";
2721 $form->{comparetodate} = "31.10.$form->{year}";
2724 $form->{duetyp} eq "11" && do {
2725 $form->{fromdate} = "1.11.$form->{year}";
2726 $form->{todate} = "30.11.$form->{year}";
2727 $form->{comparefromdate} = "1.01.$form->{year}";
2728 $form->{comparetodate} = "30.11.$form->{year}";
2731 $form->{duetyp} eq "12" && do {
2732 $form->{fromdate} = "1.12.$form->{year}";
2733 $form->{todate} = "31.12.$form->{year}";
2734 $form->{comparefromdate} = "1.01.$form->{year}";
2735 $form->{comparetodate} = "31.12.$form->{year}";
2739 hotfix_reformat_date();
2741 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2742 # ansonsten ist die prüfung in RP.pm
2743 # if (defined ($form->{fromdate|todate}=='..'))
2745 if ($form->{fromdate}){
2746 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2747 my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
2748 $datetime->set( month => 1,
2750 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
2752 if ($form->{todate}){
2753 $form->{comparetodate} = $form->{todate};
2757 RP->bwa(\%myconfig, \%$form);
2759 ($form->{department}) = split /--/, $form->{department};
2762 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2763 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2765 # if there are any dates construct a where
2766 if ($form->{fromdate} || $form->{todate}) {
2768 unless ($form->{todate}) {
2769 $form->{todate} = $form->current_date(\%myconfig);
2772 my %germandate = ("dateformat" => "dd.mm.yyyy");
2774 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2775 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2777 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2778 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2780 $form->{this_period} = "$shortfromdate\n$shorttodate";
2782 $locale->text('for Period')
2783 . qq|\n$longfromdate |
2784 . $locale->text('bis')
2788 # setup variables for the form
2789 my @a = qw(company address businessnumber);
2790 map { $form->{$_} = $myconfig{$_} } @a;
2791 $form->{templates} = $myconfig{templates};
2793 $form->{IN} = "bwa.html";
2795 $form->parse_template;
2797 $main::lxdebug->leave_sub();
2800 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
2801 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
2802 sub hotfix_reformat_date {
2804 $main::lxdebug->enter_sub();
2806 my $form = $main::form;
2807 my %myconfig = %main::myconfig;
2808 my $locale = $main::locale;
2810 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
2811 my $current_dateformat = $myconfig{dateformat};
2812 $myconfig{dateformat} = 'dd.mm.yyyy';
2813 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
2814 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
2815 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
2816 unless (!defined ($form->{comparefromdate}));
2817 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
2818 unless (!defined ($form->{comparetodate}));
2820 # Und wieder zurücksetzen
2821 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
2822 } # Ende Hotifx Bug 1388
2824 $main::lxdebug->leave_sub();