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('Tax collected')
89 # $locale->text('Tax paid')
90 # $locale->text('Receipts')
91 # $locale->text('Payments')
92 # $locale->text('Project Transactions')
93 # $locale->text('Non-taxable Sales')
94 # $locale->text('Non-taxable Purchases')
96 # $form->parse_html_template('rp/html_report_susa')
99 'projects' => 'report',
100 'ar_aging' => 'general_ledger',
101 'ap_aging' => 'general_ledger',
102 'receipts' => 'cash',
103 'payments' => 'cash',
104 'trial_balance' => 'report',
105 'income_statement' => 'report',
107 'balance_sheet' => 'report',
110 # subs use these pretty freely, so declare them here
111 our (%column_data, @column_index);
112 our ($subtotalnetamount, $subtotaltax, $subtotal);
114 sub check_rp_access {
115 my $form = $main::form;
117 my $right = $rp_access_map->{$form->{report}};
118 $right ||= 'DOES_NOT_EXIST';
120 $main::auth->assert($right);
124 $main::lxdebug->enter_sub();
128 my $form = $main::form;
129 my %myconfig = %main::myconfig;
130 my $locale = $main::locale;
133 'balance_sheet' => 'Balance Sheet',
134 'income_statement' => 'Income Statement',
135 'trial_balance' => 'Trial Balance',
136 'ar_aging' => 'AR Aging',
137 'ap_aging' => 'Offene Verbindlichkeiten',
138 'tax_collected' => 'Tax collected',
139 'tax_paid' => 'Tax paid',
140 'nontaxable_sales' => 'Non-taxable Sales',
141 'nontaxable_purchases' => 'Non-taxable Purchases',
142 'receipts' => 'Receipts',
143 'payments' => 'Payments',
144 'projects' => 'Project Transactions',
145 'bwa' => 'Betriebswirtschaftliche Auswertung',
148 $form->{title} = $locale->text($title{ $form->{report} });
150 my $accrual = ($main::eur) ? "" : "checked";
151 my $cash = ($main::eur) ? "checked" : "";
153 my $year = (localtime)[5] + 1900;
156 $form->all_departments(\%myconfig);
157 if (@{ $form->{all_departments} || [] }) {
158 $form->{selectdepartment} = "<option>\n";
159 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($main::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}">
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 align=left colspan=4>| . $locale->text('From') . qq|
813 | . $locale->text('Bis') . qq|
818 <input type=hidden name=type value=statement>
819 <input type=hidden name=format value=html>
820 <input type=hidden name=media value=screen>
822 <input type=hidden name=nextsub value=$nextsub>
823 <input type=hidden name=action value=$nextsub>
829 # above action can be removed if there is more than one input field
831 my ($selection, $paymentaccounts);
832 if ($form->{report} =~ /(receipts|payments)$/) {
833 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
835 RP->paymentaccounts(\%myconfig, \%$form);
837 $selection = "<option>\n";
838 foreach my $ref (@{ $form->{PR} }) {
839 $paymentaccounts .= "$ref->{accno} ";
840 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
843 chop $paymentaccounts;
846 <input type=hidden name=nextsub value=list_payments>
848 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
849 <td colspan=3><select name=account>$selection</select>
850 <input type=hidden name=paymentaccounts value="$paymentaccounts">
854 <th align=right>| . $locale->text('Reference') . qq|</th>
855 <td colspan=3><input name=reference></td>
858 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
859 <td colspan=3><input name=source></td>
862 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
863 <td colspan=3><input name=memo size=30></td>
866 <th align=right>| . $locale->text('From') . qq|</th>
871 <th align=right>| . $locale->text('Bis') . qq|</th>
878 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
879 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
884 <input type=hidden name=db value=$form->{db}>
885 <input type=hidden name=sort value=transdate>
896 <td><hr size=3 noshade></td>
901 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
909 $main::lxdebug->leave_sub();
912 sub continue { call_sub($main::form->{"nextsub"}); }
915 $main::lxdebug->enter_sub();
917 $main::auth->assert('report');
919 my $form = $main::form;
920 my %myconfig = %main::myconfig;
921 my $locale = $main::locale;
925 $form->{project_id} = $form->{project_id_1};
926 if ($form->{projectnumber} && !$form->{project_id}) {
927 $form->{rowcount} = 1;
929 # call this instead of update
930 $form->{update} = $nextsub;
931 $form->{projectnumber_1} = $form->{projectnumber};
933 delete $form->{sort};
934 check_project('generate_projects');
936 # if there is one only, assign id
937 $form->{project_id} = $form->{project_id_1};
940 $main::lxdebug->leave_sub();
943 sub generate_income_statement {
944 $main::lxdebug->enter_sub();
946 $main::auth->assert('report');
948 my $form = $main::form;
949 my %myconfig = %main::myconfig;
950 my $locale = $main::locale;
952 $form->{padding} = " ";
953 $form->{bold} = "<b>";
954 $form->{endbold} = "</b>";
955 $form->{br} = "<br>";
957 if ($form->{reporttype} eq "custom") {
959 #forgotten the year --> thisyear
960 if ($form->{year} !~ m/^\d\d\d\d$/) {
961 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
967 if ($form->{duetyp} eq "13") {
968 $form->{fromdate} = "1.1.$form->{year}";
969 $form->{todate} = "31.12.$form->{year}";
973 if ($form->{duetyp} eq "A") {
974 $form->{fromdate} = "1.1.$form->{year}";
975 $form->{todate} = "31.3.$form->{year}";
977 if ($form->{duetyp} eq "B") {
978 $form->{fromdate} = "1.4.$form->{year}";
979 $form->{todate} = "30.6.$form->{year}";
981 if ($form->{duetyp} eq "C") {
982 $form->{fromdate} = "1.7.$form->{year}";
983 $form->{todate} = "30.9.$form->{year}";
985 if ($form->{duetyp} eq "D") {
986 $form->{fromdate} = "1.10.$form->{year}";
987 $form->{todate} = "31.12.$form->{year}";
992 $form->{duetyp} eq "1" && do {
993 $form->{fromdate} = "1.1.$form->{year}";
994 $form->{todate} = "31.1.$form->{year}";
997 $form->{duetyp} eq "2" && do {
998 $form->{fromdate} = "1.2.$form->{year}";
1000 #this works from 1901 to 2099, 1900 and 2100 fail.
1001 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1002 $form->{todate} = "$leap.2.$form->{year}";
1005 $form->{duetyp} eq "3" && do {
1006 $form->{fromdate} = "1.3.$form->{year}";
1007 $form->{todate} = "31.3.$form->{year}";
1010 $form->{duetyp} eq "4" && do {
1011 $form->{fromdate} = "1.4.$form->{year}";
1012 $form->{todate} = "30.4.$form->{year}";
1015 $form->{duetyp} eq "5" && do {
1016 $form->{fromdate} = "1.5.$form->{year}";
1017 $form->{todate} = "31.5.$form->{year}";
1020 $form->{duetyp} eq "6" && do {
1021 $form->{fromdate} = "1.6.$form->{year}";
1022 $form->{todate} = "30.6.$form->{year}";
1025 $form->{duetyp} eq "7" && do {
1026 $form->{fromdate} = "1.7.$form->{year}";
1027 $form->{todate} = "31.7.$form->{year}";
1030 $form->{duetyp} eq "8" && do {
1031 $form->{fromdate} = "1.8.$form->{year}";
1032 $form->{todate} = "31.8.$form->{year}";
1035 $form->{duetyp} eq "9" && do {
1036 $form->{fromdate} = "1.9.$form->{year}";
1037 $form->{todate} = "30.9.$form->{year}";
1040 $form->{duetyp} eq "10" && do {
1041 $form->{fromdate} = "1.10.$form->{year}";
1042 $form->{todate} = "31.10.$form->{year}";
1045 $form->{duetyp} eq "11" && do {
1046 $form->{fromdate} = "1.11.$form->{year}";
1047 $form->{todate} = "30.11.$form->{year}";
1050 $form->{duetyp} eq "12" && do {
1051 $form->{fromdate} = "1.12.$form->{year}";
1052 $form->{todate} = "31.12.$form->{year}";
1058 RP->income_statement(\%myconfig, \%$form);
1060 ($form->{department}) = split /--/, $form->{department};
1063 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1064 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1066 # if there are any dates construct a where
1067 if ($form->{fromdate} || $form->{todate}) {
1069 unless ($form->{todate}) {
1070 $form->{todate} = $form->current_date(\%myconfig);
1073 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1074 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1076 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1077 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1079 $form->{this_period} = "$shortfromdate\n$shorttodate";
1081 $locale->text('for Period')
1082 . qq|\n$longfromdate |
1083 . $locale->text('Bis')
1087 if ($form->{comparefromdate} || $form->{comparetodate}) {
1088 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1089 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1091 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1092 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1094 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1096 "\n$longcomparefromdate "
1097 . $locale->text('Bis')
1098 . qq| $longcomparetodate|;
1101 # setup variables for the form
1102 my @a = qw(company address businessnumber);
1103 map { $form->{$_} = $myconfig{$_} } @a;
1105 $form->{templates} = $myconfig{templates};
1107 $form->{IN} = "income_statement.html";
1109 $form->parse_template;
1111 $main::lxdebug->leave_sub();
1114 sub generate_balance_sheet {
1115 $::lxdebug->enter_sub;
1116 $::auth->assert('report');
1118 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
1119 $::form->{padding} = " ";
1120 $::form->{bold} = "<b>";
1121 $::form->{endbold} = "</b>";
1122 $::form->{br} = "<br>";
1124 my $data = RP->balance_sheet(\%::myconfig, $::form);
1126 $::form->{asofdate} ||= $::form->current_date;
1127 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
1129 ($::form->{department}) = split /--/, $::form->{department};
1131 # define Current Earnings account
1132 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
1133 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
1135 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
1136 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
1138 # $::form->{IN} = "balance_sheet.html";
1140 # setup company variables for the form
1141 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
1143 $::form->{templates} = $::myconfig{templates};
1146 print $::form->parse_html_template('rp/balance_sheet', $data);
1148 $::lxdebug->leave_sub;
1151 sub generate_projects {
1152 $main::lxdebug->enter_sub();
1154 $main::auth->assert('report');
1156 my $form = $main::form;
1157 my %myconfig = %main::myconfig;
1158 my $locale = $main::locale;
1160 &get_project("generate_projects");
1161 $form->{projectnumber} = $form->{projectnumber_1};
1163 $form->{nextsub} = "generate_projects";
1164 $form->{title} = $locale->text('Project Transactions');
1165 RP->trial_balance(\%myconfig, \%$form);
1167 list_accounts('generate_projects');
1169 $main::lxdebug->leave_sub();
1175 # included links to display transactions for period entered
1176 # added headers and subtotals
1178 sub generate_trial_balance {
1179 $main::lxdebug->enter_sub();
1181 $main::auth->assert('report');
1183 my $form = $main::form;
1184 my %myconfig = %main::myconfig;
1185 my $locale = $main::locale;
1187 if ($form->{reporttype} eq "custom") {
1189 #forgotten the year --> thisyear
1190 if ($form->{year} !~ m/^\d\d\d\d$/) {
1191 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1197 if ($form->{duetyp} eq "13") {
1198 $form->{fromdate} = "1.1.$form->{year}";
1199 $form->{todate} = "31.12.$form->{year}";
1203 if ($form->{duetyp} eq "A") {
1204 $form->{fromdate} = "1.1.$form->{year}";
1205 $form->{todate} = "31.3.$form->{year}";
1207 if ($form->{duetyp} eq "B") {
1208 $form->{fromdate} = "1.4.$form->{year}";
1209 $form->{todate} = "30.6.$form->{year}";
1211 if ($form->{duetyp} eq "C") {
1212 $form->{fromdate} = "1.7.$form->{year}";
1213 $form->{todate} = "30.9.$form->{year}";
1215 if ($form->{duetyp} eq "D") {
1216 $form->{fromdate} = "1.10.$form->{year}";
1217 $form->{todate} = "31.12.$form->{year}";
1222 $form->{duetyp} eq "1" && do {
1223 $form->{fromdate} = "1.1.$form->{year}";
1224 $form->{todate} = "31.1.$form->{year}";
1227 $form->{duetyp} eq "2" && do {
1228 $form->{fromdate} = "1.2.$form->{year}";
1230 #this works from 1901 to 2099, 1900 and 2100 fail.
1231 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1232 $form->{todate} = "$leap.2.$form->{year}";
1235 $form->{duetyp} eq "3" && do {
1236 $form->{fromdate} = "1.3.$form->{year}";
1237 $form->{todate} = "31.3.$form->{year}";
1240 $form->{duetyp} eq "4" && do {
1241 $form->{fromdate} = "1.4.$form->{year}";
1242 $form->{todate} = "30.4.$form->{year}";
1245 $form->{duetyp} eq "5" && do {
1246 $form->{fromdate} = "1.5.$form->{year}";
1247 $form->{todate} = "31.5.$form->{year}";
1250 $form->{duetyp} eq "6" && do {
1251 $form->{fromdate} = "1.6.$form->{year}";
1252 $form->{todate} = "30.6.$form->{year}";
1255 $form->{duetyp} eq "7" && do {
1256 $form->{fromdate} = "1.7.$form->{year}";
1257 $form->{todate} = "31.7.$form->{year}";
1260 $form->{duetyp} eq "8" && do {
1261 $form->{fromdate} = "1.8.$form->{year}";
1262 $form->{todate} = "31.8.$form->{year}";
1265 $form->{duetyp} eq "9" && do {
1266 $form->{fromdate} = "1.9.$form->{year}";
1267 $form->{todate} = "30.9.$form->{year}";
1270 $form->{duetyp} eq "10" && do {
1271 $form->{fromdate} = "1.10.$form->{year}";
1272 $form->{todate} = "31.10.$form->{year}";
1275 $form->{duetyp} eq "11" && do {
1276 $form->{fromdate} = "1.11.$form->{year}";
1277 $form->{todate} = "30.11.$form->{year}";
1280 $form->{duetyp} eq "12" && do {
1281 $form->{fromdate} = "1.12.$form->{year}";
1282 $form->{todate} = "31.12.$form->{year}";
1289 # get for each account initial balance, debits and credits
1290 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
1293 $form->{rowcount} = scalar @{ $form->{TB} || [] };
1294 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1297 "accno", "description",
1298 "last_transaction", "soll_eb",
1301 "soll_kumuliert", "haben_kumuliert",
1302 "soll_saldo", "haben_saldo"
1306 my $attachment_basename = $locale->text('trial_balance');
1307 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1309 my @hidden_variables = qw(fromdate todate year cash);
1311 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1314 'accno' => { 'text' => $locale->text('Account'), },
1315 'description' => { 'text' => $locale->text('Description'), },
1316 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1317 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1318 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1319 'soll' => { 'text' => $locale->text('Debit'), },
1320 'haben' => { 'text' => $locale->text('Credit'), },
1321 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1322 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1323 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1324 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1329 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1331 map { $column_defs{$_}->{visible} = 1 } @columns;
1333 $report->set_columns(%column_defs);
1334 $report->set_column_order(@columns);
1336 $report->set_export_options('generate_trial_balance', @hidden_variables);
1341 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1343 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
1344 push (@options, $form->{print_date});
1346 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
1347 push (@options, $form->{company});
1350 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1352 $report->set_options('output_format' => 'HTML',
1353 'top_info_text' => join("\n", @options),
1354 'title' => $form->{title},
1355 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1356 'html_template' => 'rp/html_report_susa',
1357 'pdf_template' => 'rp/html_report_susa',
1359 $report->set_options_from_form();
1361 # add sort and escape callback, this one we use for the add sub
1362 $form->{callback} = $href .= "&sort=$form->{sort}";
1364 # escape callback for href
1365 my $callback = $form->escape($href);
1367 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1369 my %totals = map { $_ => 0 } @subtotal_columns;
1371 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1374 foreach my $accno (@{ $form->{TB} }) {
1376 $accno->{soll} = $accno->{debit};
1377 $accno->{haben} = $accno->{credit};
1378 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1380 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
1381 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1385 foreach my $column (@columns) {
1387 'data' => $accno->{$column},
1388 'align' => $column_alignment{$column},
1392 $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}));
1394 my $row_set = [ $row ];
1397 $report->add_data($row_set);
1402 $report->add_separator();
1404 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1406 $report->generate_with_headers();
1408 $main::lxdebug->leave_sub();
1412 sub create_subtotal_row {
1413 $main::lxdebug->enter_sub();
1415 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1417 my $form = $main::form;
1418 my %myconfig = %main::myconfig;
1419 my $locale = $main::locale;
1421 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1423 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1425 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1427 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1429 $main::lxdebug->leave_sub();
1434 sub create_list_accounts_subtotal_row {
1435 $main::lxdebug->enter_sub();
1437 my ($subtotals, $columns, $fields, $class) = @_;
1439 my $form = $main::form;
1440 my %myconfig = %main::myconfig;
1441 my $locale = $main::locale;
1443 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1445 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1447 $main::lxdebug->leave_sub();
1453 $main::lxdebug->enter_sub();
1457 my $form = $main::form;
1458 my %myconfig = %main::myconfig;
1459 my $locale = $main::locale;
1462 if ($form->{department}) {
1463 my ($department) = split /--/, $form->{department};
1464 push @options, $locale->text('Department') . " : $department";
1466 if ($form->{projectnumber}) {
1467 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1470 # if there are any dates
1471 if ($form->{fromdate} || $form->{todate}) {
1472 my ($fromdate, $todate);
1474 if ($form->{fromdate}) {
1475 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1477 if ($form->{todate}) {
1478 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1481 push @options, "$fromdate - $todate";
1484 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1487 my @columns = qw(accno description begbalance debit credit endbalance);
1489 'accno' => { 'text' => $locale->text('Account'), },
1490 'description' => { 'text' => $locale->text('Description'), },
1491 'debit' => { 'text' => $locale->text('Debit'), },
1492 'credit' => { 'text' => $locale->text('Credit'), },
1493 'begbalance' => { 'text' => $locale->text('Balance'), },
1494 'endbalance' => { 'text' => $locale->text('Balance'), },
1496 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1498 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1500 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1502 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1504 $report->set_options('top_info_text' => join("\n", @options),
1505 'output_format' => 'HTML',
1506 'title' => $form->{title},
1507 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1508 'std_column_visibility' => 1,
1510 $report->set_options_from_form();
1512 $report->set_columns(%column_defs);
1513 $report->set_column_order(@columns);
1515 $report->set_export_options($action, @hidden_variables);
1517 my @totals_columns = qw(credit debit begbalance endbalance);
1518 my %subtotals = map { $_ => 0 } @totals_columns;
1519 my %totals = map { $_ => 0 } @totals_columns;
1520 my $found_heading = 0;
1521 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1523 # sort the whole thing by account numbers and display
1524 foreach my $idx (0 .. scalar(@tb) - 1) {
1525 my $ref = $tb[$idx];
1526 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1528 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1530 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1532 if ($ref->{charttype} eq 'H') {
1533 next unless ($form->{l_heading});
1535 %subtotals = map { $_ => 0 } @totals_columns;
1537 $row->{description}->{class} = 'listheading';
1538 $row->{description}->{data} = $ref->{description};
1540 $report->add_data($row);
1545 foreach (qw(debit credit)) {
1546 $subtotals{$_} += $ref->{$_};
1547 $totals{$_} += $ref->{$_};
1550 $subtotals{begbalance} += $ref->{balance} * $ml;
1551 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1553 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1554 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1556 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1557 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1559 $report->add_data($row);
1561 if ($form->{l_heading} && $found_heading &&
1562 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1563 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1567 $report->add_separator();
1569 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1571 $report->generate_with_headers();
1573 $main::lxdebug->leave_sub();
1576 sub generate_ar_aging {
1577 $main::lxdebug->enter_sub();
1579 $main::auth->assert('general_ledger');
1581 my $form = $main::form;
1582 my %myconfig = %main::myconfig;
1583 my $locale = $main::locale;
1586 ($form->{customer}) = split(/--/, $form->{customer});
1588 $form->{ct} = "customer";
1589 $form->{arap} = "ar";
1591 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1593 RP->aging(\%myconfig, \%$form);
1596 $main::lxdebug->leave_sub();
1599 sub generate_ap_aging {
1600 $main::lxdebug->enter_sub();
1602 $main::auth->assert('general_ledger');
1604 my $form = $main::form;
1605 my %myconfig = %main::myconfig;
1606 my $locale = $main::locale;
1609 ($form->{vendor}) = split(/--/, $form->{vendor});
1611 $form->{ct} = "vendor";
1612 $form->{arap} = "ap";
1614 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1616 RP->aging(\%myconfig, \%$form);
1619 $main::lxdebug->leave_sub();
1622 sub create_aging_subtotal_row {
1623 $main::lxdebug->enter_sub();
1625 my ($subtotals, $columns, $periods, $class) = @_;
1627 my $form = $main::form;
1628 my %myconfig = %main::myconfig;
1629 my $locale = $main::locale;
1631 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1633 foreach (@{ $periods }) {
1634 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1635 $subtotals->{$_} = 0;
1638 $main::lxdebug->leave_sub();
1644 $main::lxdebug->enter_sub();
1646 $main::auth->assert('general_ledger');
1648 my $form = $main::form;
1649 my %myconfig = %main::myconfig;
1650 my $locale = $main::locale;
1651 my $cgi = $main::cgi;
1653 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1655 my @columns = qw(statement ct invnumber transdate duedate amount open);
1658 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1659 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1660 'invnumber' => { 'text' => $locale->text('Invoice'), },
1661 'transdate' => { 'text' => $locale->text('Date'), },
1662 'duedate' => { 'text' => $locale->text('Due'), },
1663 'amount' => { 'text' => $locale->text('Amount'), },
1664 'open' => { 'text' => $locale->text('Open'), },
1667 my %column_alignment = ('statement' => 'center',
1668 map { $_ => 'right' } qw(open amount));
1670 $report->set_options('std_column_visibility' => 1);
1671 $report->set_columns(%column_defs);
1672 $report->set_column_order(@columns);
1674 my @hidden_variables = qw(todate customer vendor arap title ct);
1675 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1678 my $attachment_basename;
1680 if ($form->{department}) {
1681 my ($department) = split /--/, $form->{department};
1682 push @options, $locale->text('Department') . " : $department";
1683 $form->{callback} .= "&department=" . E($department);
1686 if (($form->{arap} eq 'ar') && $form->{customer}) {
1687 push @options, $form->{customer};
1688 $attachment_basename = $locale->text('ar_aging_list');
1689 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1692 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1693 push @options, $form->{vendor};
1694 $attachment_basename = $locale->text('ap_aging_list');
1695 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1698 if ($form->{fromdate}) {
1699 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1701 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1704 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1706 $report->set_options('top_info_text' => join("\n", @options),
1707 'output_format' => 'HTML',
1708 'title' => $form->{title},
1709 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1712 my $previous_ctid = 0;
1714 my @periods = qw(open amount);
1715 my %subtotals = map { $_ => 0 } @periods;
1716 my %totals = map { $_ => 0 } @periods;
1718 foreach my $ref (@{ $form->{AG} }) {
1719 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1720 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1723 foreach my $key (@periods) {
1724 $subtotals{$key} += $ref->{"$key"};
1725 $totals{$key} += $ref->{"$key"};
1726 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1731 foreach my $column (@columns) {
1733 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1734 'align' => $column_alignment{$column},
1735 'valign' => $column eq 'statement' ? 'center' : '',
1739 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1741 if ($previous_ctid != $ref->{ctid}) {
1742 $row->{statement}->{raw_data} =
1743 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1744 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1745 $row->{ct}->{data} = $ref->{name};
1750 $previous_ctid = $ref->{ctid};
1752 $report->add_data($row);
1755 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1757 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1759 if ($form->{arap} eq 'ar') {
1760 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1761 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1762 'PRINT_OPTIONS' => print_options(inline => 1), });
1763 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1764 'raw_bottom_info_text' => $raw_bottom_info_text);
1767 $report->set_options_from_form();
1769 $report->generate_with_headers();
1771 $main::lxdebug->leave_sub();
1775 $main::lxdebug->enter_sub();
1777 my $form = $main::form;
1778 my %myconfig = %main::myconfig;
1779 my $locale = $main::locale;
1781 RP->aging(\%myconfig, \%$form);
1783 map { $_->{checked} = "checked" } @{ $form->{AG} };
1787 $main::lxdebug->leave_sub();
1791 $main::lxdebug->enter_sub();
1793 $main::auth->assert('general_ledger');
1795 my $form = $main::form;
1796 my %myconfig = %main::myconfig;
1797 my $locale = $main::locale;
1799 # get name and email addresses
1801 for my $i (1 .. $form->{rowcount}) {
1802 if ($form->{"statement_$i"}) {
1803 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1804 RP->get_customer(\%myconfig, \%$form);
1810 $form->error($locale->text('Nothing selected!')) unless $selected;
1813 if ($myconfig{role} eq 'admin') {
1815 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1816 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1820 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1822 $form->{media} = "email";
1829 <form method=post action=$form->{script}>
1835 <tr height="5"></tr>
1840 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1841 <td><input name=email size=30 value="$form->{email}"></td>
1842 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1843 <td><input name=cc size=30 value="$form->{cc}"></td>
1846 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1847 <td><input name=subject size=30 value="$form->{subject}"></td>
1857 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1860 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1871 map { delete $form->{$_} }
1872 qw(action email cc bcc subject message type sendmode format header);
1874 # save all other variables
1875 foreach my $key (keys %$form) {
1876 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1877 $form->{$key} =~ s/\"/"/g;
1878 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1885 <td><hr size=3 noshade></td>
1889 <input type=hidden name=nextsub value=send_email>
1892 <input name=action class=submit type=submit value="|
1893 . $locale->text('Continue') . qq|">
1900 $main::lxdebug->leave_sub();
1904 $main::lxdebug->enter_sub();
1906 $main::auth->assert('general_ledger');
1908 my $form = $main::form;
1909 my %myconfig = %main::myconfig;
1910 my $locale = $main::locale;
1912 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1913 unless $form->{subject};
1915 RP->aging(\%myconfig, \%$form);
1917 $form->{"statement_1"} = 1;
1919 $form->{media} = 'email';
1922 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1924 $main::lxdebug->leave_sub();
1928 $main::lxdebug->enter_sub();
1930 $main::auth->assert('general_ledger');
1932 my $form = $main::form;
1933 my %myconfig = %main::myconfig;
1934 my $locale = $main::locale;
1936 if ($form->{media} eq 'printer') {
1937 $form->error($locale->text('Select postscript or PDF!'))
1938 if ($form->{format} !~ /(postscript|pdf)/);
1942 for my $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 $main::lxdebug->leave_sub();
1969 $main::lxdebug->enter_sub();
1971 $main::auth->assert('general_ledger');
1973 my $form = $main::form;
1974 my %myconfig = %main::myconfig;
1975 my $locale = $main::locale;
1977 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1979 $form->{templates} = "$myconfig{templates}";
1981 my $suffix = "html";
1982 my $attachment_suffix = "html";
1983 if ($form->{format} eq 'postscript') {
1984 $form->{postscript} = 1;
1986 $attachment_suffix = "ps";
1987 } elsif ($form->{format} eq 'pdf') {
1990 $attachment_suffix = "pdf";
1993 $form->{IN} = "$form->{type}.$suffix";
1994 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1996 # Save $form->{email} because it will be overwritten.
1997 $form->{EMAIL_RECIPIENT} = $form->{email};
2001 while (@{ $form->{AG} }) {
2003 my $ref = shift @{ $form->{AG} };
2005 if ($ctid != $ref->{ctid}) {
2007 $ctid = $ref->{ctid};
2010 if ($form->{"statement_$i"}) {
2013 ("name", "street", "zipcode", "city", "country", "contact", "email",
2014 "$form->{ct}phone", "$form->{ct}fax");
2015 map { $form->{$_} = $ref->{$_} } @a;
2017 $form->{ $form->{ct} } = $form->{name};
2018 $form->{"$form->{ct}_id"} = $ref->{ctid};
2020 map { $form->{$_} = () } qw(invnumber invdate duedate);
2022 foreach my $item (qw(c0 c30 c60 c90)) {
2023 $form->{$item} = ();
2024 $form->{"${item}total"} = 0;
2027 &statement_details($ref);
2031 if (scalar(@{ $form->{AG} }) > 0) {
2033 # one or more left to go
2034 if ($ctid == $form->{AG}->[0]->{ctid}) {
2035 $ref = shift @{ $form->{AG} };
2036 &statement_details($ref);
2039 $ref = scalar(@{ $form->{AG} });
2045 # set initial ref to 0
2052 $form->{"${_}total"} =
2053 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2054 } ('c0', 'c30', 'c60', 'c90', "");
2056 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2057 $form->{attachment_filename} =~ s/\s+/_/g;
2059 $form->parse_template(\%myconfig, $main::userspath);
2064 # saving the history
2065 if(!exists $form->{addition} && $form->{id} ne "") {
2066 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2067 $form->{addition} = "PRINTED";
2068 $form->{what_done} = $form->{type};
2069 $form->save_history($form->dbconnect(\%myconfig));
2071 # /saving the history
2072 $main::lxdebug->leave_sub();
2075 sub statement_details {
2076 $main::lxdebug->enter_sub();
2078 $main::auth->assert('general_ledger');
2080 my $form = $main::form;
2081 my %myconfig = %main::myconfig;
2082 my $locale = $main::locale;
2086 push @{ $form->{invnumber} }, $ref->{invnumber};
2087 push @{ $form->{invdate} }, $ref->{transdate};
2088 push @{ $form->{duedate} }, $ref->{duedate};
2090 foreach my $item (qw(c0 c30 c60 c90)) {
2091 if ($ref->{exchangerate} * 1) {
2093 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2095 $form->{"${item}total"} += $ref->{$item};
2096 $form->{total} += $ref->{$item};
2097 push @{ $form->{$item} },
2098 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2101 $main::lxdebug->leave_sub();
2104 sub generate_tax_report {
2105 $main::lxdebug->enter_sub();
2107 $main::auth->assert('report');
2109 my $form = $main::form;
2110 my %myconfig = %main::myconfig;
2111 my $locale = $main::locale;
2113 RP->tax_report(\%myconfig, \%$form);
2115 my $descvar = "$form->{accno}_description";
2116 my $description = $form->escape($form->{$descvar});
2117 my $ratevar = "$form->{accno}_rate";
2118 our $taxrate; # most likely error
2120 my $department = $form->escape($form->{department});
2124 "$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}";
2126 # construct callback
2127 $description = $form->escape($form->{$descvar}, 1);
2128 $department = $form->escape($form->{department}, 1);
2130 "$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}";
2132 my $title = $form->escape($form->{title});
2133 $href .= "&title=$title";
2134 $title = $form->escape($form->{title}, 1);
2135 $callback .= "&title=$title";
2137 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2140 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2142 foreach my $item (@columns) {
2143 if ($form->{"l_$item"} eq "Y") {
2144 push @column_index, $item;
2146 # add column to href and callback
2147 $callback .= "&l_$item=Y";
2148 $href .= "&l_$item=Y";
2152 if ($form->{l_subtotal} eq 'Y') {
2153 $callback .= "&l_subtotal=Y";
2154 $href .= "&l_subtotal=Y";
2158 if ($form->{department}) {
2159 ($department) = split /--/, $form->{department};
2160 $option = $locale->text('Department') . " : $department";
2163 my ($fromdate, $todate);
2164 # if there are any dates
2165 if ($form->{fromdate} || $form->{todate}) {
2166 if ($form->{fromdate}) {
2167 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2169 if ($form->{todate}) {
2170 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2173 $form->{period} = "$fromdate - $todate";
2176 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2179 my ($name, $invoice, $arap);
2180 if ($form->{db} eq 'ar') {
2181 $name = $locale->text('Customer');
2185 if ($form->{db} eq 'ap') {
2186 $name = $locale->text('Vendor');
2191 $option .= "<br>" if $option;
2192 $option .= "$form->{period}";
2195 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2196 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2197 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2198 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2199 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2200 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2202 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2211 <th class=listtop>$form->{title}</th>
2213 <tr height="5"></tr>
2220 <tr class=listheading>
2223 map { print "$column_header{$_}\n" } @column_index;
2229 # add sort and escape callback
2230 $callback = $form->escape($callback . "&sort=$form->{sort}");
2233 if (@{ $form->{TR} }) {
2234 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2237 my ($totalnetamount, $totaltax);
2239 foreach my $ref (@{ $form->{TR} }) {
2241 my $module = ($ref->{invoice}) ? $invoice : $arap;
2243 if ($form->{l_subtotal} eq 'Y') {
2244 if ($sameitem ne $ref->{ $form->{sort} }) {
2246 $sameitem = $ref->{ $form->{sort} };
2250 $totalnetamount += $ref->{netamount};
2251 $totaltax += $ref->{tax};
2252 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2254 $subtotalnetamount += $ref->{netamount};
2255 $subtotaltax += $ref->{tax};
2258 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2259 } qw(netamount tax amount);
2261 $column_data{id} = qq|<td>$ref->{id}</td>|;
2262 $column_data{invnumber} =
2263 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2264 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2265 $column_data{name} = qq|<td>$ref->{name} </td>|;
2267 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2268 qw(netamount tax amount);
2273 <tr class=listrow$i>
2276 map { print "$column_data{$_}\n" } @column_index;
2284 if ($form->{l_subtotal} eq 'Y') {
2288 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2292 <tr class=listtotal>
2295 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2296 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2297 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2299 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
2300 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2301 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2303 map { print "$column_data{$_}\n" } @column_index;
2311 <td><hr size=3 noshade></td>
2319 $main::lxdebug->leave_sub();
2323 $main::lxdebug->enter_sub();
2325 my $form = $main::form;
2326 my %myconfig = %main::myconfig;
2327 my $locale = $main::locale;
2329 map { $column_data{$_} = "<td> </td>" } @column_index;
2331 $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
2332 $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
2333 $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, " ");
2335 $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2336 $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2337 $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2339 $subtotalnetamount = 0;
2343 <tr class=listsubtotal>
2345 map { print "\n$column_data{$_}" } @column_index;
2351 $main::lxdebug->leave_sub();
2355 $main::lxdebug->enter_sub();
2357 $main::auth->assert('cash');
2359 my $form = $main::form;
2360 my %myconfig = %main::myconfig;
2361 my $locale = $main::locale;
2363 if ($form->{account}) {
2364 ($form->{paymentaccounts}) = split /--/, $form->{account};
2368 if ($form->{department}) {
2369 (my $department, $form->{department_id}) = split /--/, $form->{department};
2370 $option = $locale->text('Department') . " : $department";
2373 report_generator_set_default_sort('transdate', 1);
2375 RP->payments(\%myconfig, \%$form);
2377 my @hidden_variables = qw(account title department reference source memo fromdate todate
2378 fx_transaction db prepayment paymentaccounts sort);
2380 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2381 $form->{callback} = $href;
2383 my @columns = qw(transdate invnumber name paid source memo);
2385 'name' => { 'text' => $locale->text('Description'), },
2386 'invnumber' => { 'text' => $locale->text('Reference'), },
2387 'transdate' => { 'text' => $locale->text('Date'), },
2388 'paid' => { 'text' => $locale->text('Amount'), },
2389 'source' => { 'text' => $locale->text('Source'), },
2390 'memo' => { 'text' => $locale->text('Memo'), },
2392 my %column_alignment = ('paid' => 'right');
2394 foreach my $name (grep { $_ ne 'paid' } @columns) {
2395 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2396 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2400 if ($form->{fromdate}) {
2401 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2403 if ($form->{todate}) {
2404 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2407 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2409 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2411 $report->set_options('top_info_text' => join("\n", @options),
2412 'output_format' => 'HTML',
2413 'title' => $form->{title},
2414 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2415 'std_column_visibility' => 1,
2417 $report->set_options_from_form();
2419 $report->set_columns(%column_defs);
2420 $report->set_column_order(@columns);
2422 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2424 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2428 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2429 next unless @{ $form->{ $ref->{id} } };
2431 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2433 my $subtotal_paid = 0;
2435 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2436 my $module = $payment->{module};
2437 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2438 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2440 $subtotal_paid += $payment->{paid};
2441 $total_paid += $payment->{paid};
2443 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2447 foreach my $column (@columns) {
2449 'data' => $payment->{$column},
2450 'align' => $column_alignment{$column},
2454 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2456 $report->add_data($row);
2459 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2461 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2463 'class' => 'listsubtotal',
2466 $report->add_data($row);
2469 $report->add_separator();
2471 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2473 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2475 'class' => 'listtotal',
2478 $report->add_data($row);
2480 $report->generate_with_headers();
2482 $main::lxdebug->leave_sub();
2486 $main::lxdebug->enter_sub();
2488 my ($dont_print) = @_;
2490 my $form = $main::form;
2491 my %myconfig = %main::myconfig;
2492 my $locale = $main::locale;
2494 $form->{sendmode} = "attachment";
2497 $form->{"format"} ? $form->{"format"} :
2498 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2502 $form->{"copies"} ? $form->{"copies"} :
2503 $myconfig{"copies"} ? $myconfig{"copies"} :
2506 $form->{PD}{ $form->{type} } = "selected";
2507 $form->{DF}{ $form->{format} } = "selected";
2508 $form->{OP}{ $form->{media} } = "selected";
2509 $form->{SM}{ $form->{sendmode} } = "selected";
2513 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
2515 if ($form->{media} eq 'email') {
2517 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
2518 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2521 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2522 if ($myconfig{printer} && $main::latex_templates) {
2524 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
2529 if ($main::latex_templates) {
2531 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2532 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2533 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2539 <td><select name=type>$type</select></td>
2540 <td><select name=format>$format</select></td>
2541 <td><select name=media>$media</select></td>
2544 if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
2546 <td>| . $locale->text('Copies') . qq|
2547 <input name=copies size=2 value=$form->{copies}></td>
2556 print $output unless $dont_print;
2558 $main::lxdebug->leave_sub();
2564 $main::lxdebug->enter_sub();
2566 $main::auth->assert('report');
2568 my $form = $main::form;
2569 my %myconfig = %main::myconfig;
2570 my $locale = $main::locale;
2572 $form->{padding} = " ";
2573 $form->{bold} = "<b>";
2574 $form->{endbold} = "</b>";
2575 $form->{br} = "<br>";
2577 if ($form->{reporttype} eq "custom") {
2579 #forgotten the year --> thisyear
2580 if ($form->{year} !~ m/^\d\d\d\d$/) {
2581 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2587 if ($form->{duetyp} eq "13") {
2588 $form->{fromdate} = "1.1.$form->{year}";
2589 $form->{todate} = "31.12.$form->{year}";
2590 $form->{comparefromdate} = "1.01.$form->{year}";
2591 $form->{comparetodate} = "31.12.$form->{year}";
2595 if ($form->{duetyp} eq "A") {
2596 $form->{fromdate} = "1.1.$form->{year}";
2597 $form->{todate} = "31.3.$form->{year}";
2598 $form->{comparefromdate} = "1.01.$form->{year}";
2599 $form->{comparetodate} = "31.03.$form->{year}";
2601 if ($form->{duetyp} eq "B") {
2602 $form->{fromdate} = "1.4.$form->{year}";
2603 $form->{todate} = "30.6.$form->{year}";
2604 $form->{comparefromdate} = "1.01.$form->{year}";
2605 $form->{comparetodate} = "30.06.$form->{year}";
2607 if ($form->{duetyp} eq "C") {
2608 $form->{fromdate} = "1.7.$form->{year}";
2609 $form->{todate} = "30.9.$form->{year}";
2610 $form->{comparefromdate} = "1.01.$form->{year}";
2611 $form->{comparetodate} = "30.09.$form->{year}";
2613 if ($form->{duetyp} eq "D") {
2614 $form->{fromdate} = "1.10.$form->{year}";
2615 $form->{todate} = "31.12.$form->{year}";
2616 $form->{comparefromdate} = "1.01.$form->{year}";
2617 $form->{comparetodate} = "31.12.$form->{year}";
2622 $form->{duetyp} eq "1" && do {
2623 $form->{fromdate} = "1.1.$form->{year}";
2624 $form->{todate} = "31.1.$form->{year}";
2625 $form->{comparefromdate} = "1.01.$form->{year}";
2626 $form->{comparetodate} = "31.01.$form->{year}";
2629 $form->{duetyp} eq "2" && do {
2630 $form->{fromdate} = "1.2.$form->{year}";
2632 #this works from 1901 to 2099, 1900 and 2100 fail.
2633 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2634 $form->{todate} = "$leap.2.$form->{year}";
2635 $form->{comparefromdate} = "1.01.$form->{year}";
2636 $form->{comparetodate} = "$leap.02.$form->{year}";
2639 $form->{duetyp} eq "3" && do {
2640 $form->{fromdate} = "1.3.$form->{year}";
2641 $form->{todate} = "31.3.$form->{year}";
2642 $form->{comparefromdate} = "1.01.$form->{year}";
2643 $form->{comparetodate} = "31.03.$form->{year}";
2646 $form->{duetyp} eq "4" && do {
2647 $form->{fromdate} = "1.4.$form->{year}";
2648 $form->{todate} = "30.4.$form->{year}";
2649 $form->{comparefromdate} = "1.01.$form->{year}";
2650 $form->{comparetodate} = "30.04.$form->{year}";
2653 $form->{duetyp} eq "5" && do {
2654 $form->{fromdate} = "1.5.$form->{year}";
2655 $form->{todate} = "31.5.$form->{year}";
2656 $form->{comparefromdate} = "1.01.$form->{year}";
2657 $form->{comparetodate} = "31.05.$form->{year}";
2660 $form->{duetyp} eq "6" && do {
2661 $form->{fromdate} = "1.6.$form->{year}";
2662 $form->{todate} = "30.6.$form->{year}";
2663 $form->{comparefromdate} = "1.01.$form->{year}";
2664 $form->{comparetodate} = "30.06.$form->{year}";
2667 $form->{duetyp} eq "7" && do {
2668 $form->{fromdate} = "1.7.$form->{year}";
2669 $form->{todate} = "31.7.$form->{year}";
2670 $form->{comparefromdate} = "1.01.$form->{year}";
2671 $form->{comparetodate} = "31.07.$form->{year}";
2674 $form->{duetyp} eq "8" && do {
2675 $form->{fromdate} = "1.8.$form->{year}";
2676 $form->{todate} = "31.8.$form->{year}";
2677 $form->{comparefromdate} = "1.01.$form->{year}";
2678 $form->{comparetodate} = "31.08.$form->{year}";
2681 $form->{duetyp} eq "9" && do {
2682 $form->{fromdate} = "1.9.$form->{year}";
2683 $form->{todate} = "30.9.$form->{year}";
2684 $form->{comparefromdate} = "1.01.$form->{year}";
2685 $form->{comparetodate} = "30.09.$form->{year}";
2688 $form->{duetyp} eq "10" && do {
2689 $form->{fromdate} = "1.10.$form->{year}";
2690 $form->{todate} = "31.10.$form->{year}";
2691 $form->{comparefromdate} = "1.01.$form->{year}";
2692 $form->{comparetodate} = "31.10.$form->{year}";
2695 $form->{duetyp} eq "11" && do {
2696 $form->{fromdate} = "1.11.$form->{year}";
2697 $form->{todate} = "30.11.$form->{year}";
2698 $form->{comparefromdate} = "1.01.$form->{year}";
2699 $form->{comparetodate} = "30.11.$form->{year}";
2702 $form->{duetyp} eq "12" && do {
2703 $form->{fromdate} = "1.12.$form->{year}";
2704 $form->{todate} = "31.12.$form->{year}";
2705 $form->{comparefromdate} = "1.01.$form->{year}";
2706 $form->{comparetodate} = "31.12.$form->{year}";
2711 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2712 # ansonsten ist die prüfung in RP.pm
2713 # if (defined ($form->{fromdate|todate}=='..'))
2715 if ($form->{fromdate}){
2716 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2717 $form->{fromdate} = "${dd}.${mm}.${yy}";
2718 $form->{comparefromdate} = "01.01.$yy";
2720 if ($form->{todate}){
2721 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2722 $form->{todate} = "${dd}.${mm}.${yy}";
2723 $form->{comparetodate} = $form->{todate};
2727 RP->bwa(\%myconfig, \%$form);
2729 ($form->{department}) = split /--/, $form->{department};
2732 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2733 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2735 # if there are any dates construct a where
2736 if ($form->{fromdate} || $form->{todate}) {
2738 unless ($form->{todate}) {
2739 $form->{todate} = $form->current_date(\%myconfig);
2742 my %germandate = ("dateformat" => "dd.mm.yyyy");
2744 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2745 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2747 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2748 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2750 $form->{this_period} = "$shortfromdate\n$shorttodate";
2752 $locale->text('for Period')
2753 . qq|\n$longfromdate |
2754 . $locale->text('bis')
2758 # setup variables for the form
2759 my @a = qw(company address businessnumber);
2760 map { $form->{$_} = $myconfig{$_} } @a;
2761 $form->{templates} = $myconfig{templates};
2763 $form->{IN} = "bwa.html";
2765 $form->parse_template;
2767 $main::lxdebug->leave_sub();