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 = ($main::eur) ? "" : "checked";
150 my $cash = ($main::eur) ? "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} || [] };
163 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
164 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
166 | if $form->{selectdepartment};
168 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
171 my %project_labels = ();
172 my @project_values = ("");
173 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
174 push(@project_values, $item->{"id"});
175 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
179 NTI($main::cgi->popup_menu('-name' => "project_id",
180 '-values' => \@project_values,
181 '-labels' => \%project_labels));
183 # use JavaScript Calendar or not
184 $form->{jsscript} = 1;
186 my ( $name_1, $id_1, $value_1, $trigger_1, $name_2, $id_2, $value_2, $trigger_2, );
187 if ($form->{report} eq "balance_sheet") {
188 $name_1 = "asofdate";
190 $value_1 = "$form->{asofdate}";
191 $trigger_1 = "trigger1";
192 $name_2 = "compareasofdate";
193 $id_2 = "compareasofdate";
194 $value_2 = "$form->{compareasofdate}";
195 $trigger_2 = "trigger2";
196 } elsif ($form->{report} =~ /(receipts|payments)$/) {
197 $name_1 = "fromdate";
199 $value_1 = "$form->{fromdate}";
200 $trigger_1 = "trigger1";
204 $trigger_2 = "trigger2";
205 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
206 $name_1 = "fromdate";
208 $value_1 = "$form->{fromdate}";
209 $trigger_1 = "trigger1";
213 $trigger_2 = "trigger2";
216 $name_1 = "fromdate";
218 $value_1 = "$form->{fromdate}";
219 $trigger_1 = "trigger1";
223 $trigger_2 = "trigger2";
226 my ($button1, $button1_2, $button2, $button2_2);
229 # with JavaScript Calendar
230 if ($form->{jsscript}) {
232 $button1 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
233 $button1_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|>|;
236 $jsscript = Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
238 $button1 = qq| <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
239 $button1_2 = qq| <input type=button name=$name_1 id="$trigger_1" value=| . $locale->text('button') . qq|>|;
240 $button2 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
241 $button2_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|> |;
244 $jsscript = Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1", "$name_2", "BL", "$trigger_2");
248 # without JavaScript Calendar
250 $button1 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
252 $button1 = qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
253 $button2 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
256 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
258 my $onload = qq|focus()|;
259 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
260 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
262 <body onLoad="$onload">
264 <form method=post action=$form->{script}>
266 <input type=hidden name=title value="$form->{title}">
270 <th class=listtop>$form->{title}</th>
279 if ($form->{report} eq "projects") {
282 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
283 <td colspan=5><input name=projectnumber size=25</td>
285 <input type=hidden name=nextsub value=generate_projects>
287 <th align=right>| . $locale->text('From') . qq|</th>
290 <th align=right>| . $locale->text('Bis') . qq|</th>
301 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
302 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
303 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
310 if ($form->{report} eq "income_statement") {
313 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
314 <td colspan=3>$projectnumber</td>
316 <input type=hidden name=nextsub value=generate_income_statement>
320 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
323 <th colspan=1>| . $locale->text('Year') . qq|</th>
324 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
330 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
331 <th align=left>| . $locale->text('Quarterly') . qq|</th>
332 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
335 <td align=right> <input name=duetyp class=radio type=radio value="13" "checked"></td>
336 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
340 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
344 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
345 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
349 <td align= right> </td>
350 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
351 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
352 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
353 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
357 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
358 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
359 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
360 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
365 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
366 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
367 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
368 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
372 <td colspan=5><hr size=3 noshade></td>
375 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
376 <td align=left colspan=4>| . $locale->text('From') . qq|
379 | . $locale->text('Bis') . qq|
385 <td colspan=5><hr size=3 noshade></td>
388 <th align=leftt>| . $locale->text('Method') . qq|</th>
389 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
390 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
397 if ($form->{report} eq "bwa") {
400 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
401 <td colspan=3>$projectnumber</td>
403 <input type=hidden name=nextsub value=generate_bwa>
407 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
410 <th colspan=1>| . $locale->text('Year') . qq|</th>
411 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
417 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
418 <th align=left>| . $locale->text('Quarterly') . qq|</th>
419 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
422 <td align=right> <input name=duetyp class=radio type=radio value="13"
424 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
426 $checked = "checked";
428 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
432 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
433 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
437 <td align= right> </td>
438 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
439 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
440 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
441 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
445 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
446 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
447 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
448 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
453 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
454 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
455 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
456 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
460 <td colspan=5><hr size=3 noshade></td>
463 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
464 <td align=left colspan=4>| . $locale->text('From') . qq|
467 | . $locale->text('Bis') . qq|
473 <td colspan=5><hr size=3 noshade></td>
476 <th align=leftt>| . $locale->text('Method') . qq|</th>
477 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
478 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
481 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
482 <td><input name=decimalplaces size=3 value="2"></td>
489 if ($form->{report} eq "balance_sheet") {
491 <input type=hidden name=nextsub value=generate_balance_sheet>
493 <th align=right>| . $locale->text('as at') . qq|</th>
498 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
505 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
506 <td><input name=decimalplaces size=3 value="2"></td>
515 <th align=right>| . $locale->text('Method') . qq|</th>
516 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
517 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
521 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
522 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
523 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|
524 <input name=l_accno class=checkbox type=checkbox value=Y> | . $locale->text('Account Number') . qq|</td>
531 if ($form->{report} eq "trial_balance") {
534 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
535 <td colspan=3>$projectnumber</td>
537 <input type=hidden name=nextsub value=generate_trial_balance>
541 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
544 <th colspan=1>| . $locale->text('Year') . qq|</th>
545 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
551 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
552 <th align=left>| . $locale->text('Quarterly') . qq|</th>
553 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
556 <td align=right> <input name=duetyp class=radio type=radio value="13" $checked></td>
557 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
559 $checked = "checked";
561 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
565 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
566 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
570 <td align= right> </td>
571 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
572 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
573 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
574 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
578 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
579 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
580 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
581 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
586 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
587 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
588 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
589 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
593 <td colspan=5><hr size=3 noshade></td>
596 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
597 <td align=left colspan=4>| . $locale->text('From') . qq|
600 | . $locale->text('Bis') . qq|
606 <td colspan=5><hr size=3 noshade></td>
609 <th align=leftt>| . $locale->text('Method') . qq|</th>
610 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
611 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
614 <th align=right colspan=4>| . $locale->text('All Accounts') . qq|</th>
615 <td><input name=all_accounts type=checkbox value=1></td>
618 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
619 <td><input name=decimalplaces size=3 value="2"></td>
626 if ($form->{report} =~ /^tax_/) {
627 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
629 RP->get_taxaccounts(\%myconfig, \%$form);
632 <input type=hidden name=nextsub value=generate_tax_report>
634 <th align=right>| . $locale->text('From') . qq|</th>
635 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
636 <th align=right>| . $locale->text('Bis') . qq|</th>
637 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
640 <th align=right>| . $locale->text('Report for') . qq|</th>
644 $checked = "checked";
645 foreach my $ref (@{ $form->{taxaccounts} }) {
648 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
650 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
651 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
658 <input type=hidden name=db value=$form->{db}>
659 <input type=hidden name=sort value=transdate>
664 <th align=right>| . $locale->text('Method') . qq|</th>
665 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
666 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
675 <th align=right>| . $locale->text('Include in Report') . qq|</th>
679 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
680 <td>| . $locale->text('ID') . qq|</td>
681 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
682 <td>| . $locale->text('Invoice') . qq|</td>
683 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
684 <td>| . $locale->text('Date') . qq|</td>
687 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
690 if ($form->{db} eq 'ar') {
691 print $locale->text('Customer');
693 if ($form->{db} eq 'ap') {
694 print $locale->text('Vendor');
698 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
699 <td>| . $locale->text('Amount') . qq|</td>
700 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
701 <td>| . $locale->text('Tax') . qq|</td>
702 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
703 <td>| . $locale->text('Total') . qq|</td>
706 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
707 <td>| . $locale->text('Subtotal') . qq|</td>
716 if ($form->{report} =~ /^nontaxable_/) {
717 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
720 <input type=hidden name=nextsub value=generate_tax_report>
722 <input type=hidden name=db value=$form->{db}>
723 <input type=hidden name=sort value=transdate>
724 <input type=hidden name=report value=$form->{report}>
727 <th align=right>| . $locale->text('From') . qq|</th>
728 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
729 <th align=right>| . $locale->text('Bis') . qq|</th>
730 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
733 <th align=right>| . $locale->text('Method') . qq|</th>
734 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
735 . $locale->text('Accrual') . qq|
736 <input name=method class=radio type=radio value=cash $cash>|
737 . $locale->text('EUR') . qq|</td>
740 <th align=right>| . $locale->text('Include in Report') . qq|</th>
744 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
745 <td>| . $locale->text('ID') . qq|</td>
746 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
747 <td>| . $locale->text('Invoice') . qq|</td>
748 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
749 <td>| . $locale->text('Date') . qq|</td>
752 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
755 if ($form->{db} eq 'ar') {
756 print $locale->text('Customer');
758 if ($form->{db} eq 'ap') {
759 print $locale->text('Vendor');
763 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
764 <td>| . $locale->text('Amount') . qq|</td>
765 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
766 <td>| . $locale->text('Total') . qq|</td>
769 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
770 <td>| . $locale->text('Subtotal') . qq|</td>
779 my ($label, $nextsub, $vc);
780 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
781 if ($form->{report} eq 'ar_aging') {
782 $label = $locale->text('Customer');
783 $form->{vc} = 'customer';
785 $label = $locale->text('Vendor');
786 $form->{vc} = 'vendor';
789 $nextsub = "generate_$form->{report}";
792 $form->all_vc(\%myconfig, $form->{vc},
793 ($form->{vc} eq 'customer') ? "AR" : "AP");
795 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
796 @{ $form->{"all_$form->{vc}"} };
800 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
801 : qq|<input name=$form->{vc} size=35>|;
805 <th align=right>| . $locale->text($label) . qq|</th>
809 <td align=left colspan=4>| . $locale->text('From') . qq|
812 | . $locale->text('Bis') . qq|
817 <input type=hidden name=type value=statement>
818 <input type=hidden name=format value=html>
819 <input type=hidden name=media value=screen>
821 <input type=hidden name=nextsub value=$nextsub>
822 <input type=hidden name=action value=$nextsub>
828 # above action can be removed if there is more than one input field
830 my ($selection, $paymentaccounts);
831 if ($form->{report} =~ /(receipts|payments)$/) {
832 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
834 RP->paymentaccounts(\%myconfig, \%$form);
836 $selection = "<option>\n";
837 foreach my $ref (@{ $form->{PR} }) {
838 $paymentaccounts .= "$ref->{accno} ";
839 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
842 chop $paymentaccounts;
845 <input type=hidden name=nextsub value=list_payments>
847 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
848 <td colspan=3><select name=account>$selection</select>
849 <input type=hidden name=paymentaccounts value="$paymentaccounts">
853 <th align=right>| . $locale->text('Reference') . qq|</th>
854 <td colspan=3><input name=reference></td>
857 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
858 <td colspan=3><input name=source></td>
861 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
862 <td colspan=3><input name=memo size=30></td>
865 <th align=right>| . $locale->text('From') . qq|</th>
870 <th align=right>| . $locale->text('Bis') . qq|</th>
877 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
878 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
883 <input type=hidden name=db value=$form->{db}>
884 <input type=hidden name=sort value=transdate>
895 <td><hr size=3 noshade></td>
900 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
908 $main::lxdebug->leave_sub();
911 sub continue { call_sub($main::form->{"nextsub"}); }
914 $main::lxdebug->enter_sub();
916 $main::auth->assert('report');
918 my $form = $main::form;
919 my %myconfig = %main::myconfig;
920 my $locale = $main::locale;
924 $form->{project_id} = $form->{project_id_1};
925 if ($form->{projectnumber} && !$form->{project_id}) {
926 $form->{rowcount} = 1;
928 # call this instead of update
929 $form->{update} = $nextsub;
930 $form->{projectnumber_1} = $form->{projectnumber};
932 delete $form->{sort};
933 check_project('generate_projects');
935 # if there is one only, assign id
936 $form->{project_id} = $form->{project_id_1};
939 $main::lxdebug->leave_sub();
942 sub generate_income_statement {
943 $main::lxdebug->enter_sub();
945 $main::auth->assert('report');
947 my $form = $main::form;
948 my %myconfig = %main::myconfig;
949 my $locale = $main::locale;
951 $form->{padding} = " ";
952 $form->{bold} = "<b>";
953 $form->{endbold} = "</b>";
954 $form->{br} = "<br>";
956 if ($form->{reporttype} eq "custom") {
958 #forgotten the year --> thisyear
959 if ($form->{year} !~ m/^\d\d\d\d$/) {
960 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
966 if ($form->{duetyp} eq "13") {
967 $form->{fromdate} = "1.1.$form->{year}";
968 $form->{todate} = "31.12.$form->{year}";
972 if ($form->{duetyp} eq "A") {
973 $form->{fromdate} = "1.1.$form->{year}";
974 $form->{todate} = "31.3.$form->{year}";
976 if ($form->{duetyp} eq "B") {
977 $form->{fromdate} = "1.4.$form->{year}";
978 $form->{todate} = "30.6.$form->{year}";
980 if ($form->{duetyp} eq "C") {
981 $form->{fromdate} = "1.7.$form->{year}";
982 $form->{todate} = "30.9.$form->{year}";
984 if ($form->{duetyp} eq "D") {
985 $form->{fromdate} = "1.10.$form->{year}";
986 $form->{todate} = "31.12.$form->{year}";
991 $form->{duetyp} eq "1" && do {
992 $form->{fromdate} = "1.1.$form->{year}";
993 $form->{todate} = "31.1.$form->{year}";
996 $form->{duetyp} eq "2" && do {
997 $form->{fromdate} = "1.2.$form->{year}";
999 #this works from 1901 to 2099, 1900 and 2100 fail.
1000 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1001 $form->{todate} = "$leap.2.$form->{year}";
1004 $form->{duetyp} eq "3" && do {
1005 $form->{fromdate} = "1.3.$form->{year}";
1006 $form->{todate} = "31.3.$form->{year}";
1009 $form->{duetyp} eq "4" && do {
1010 $form->{fromdate} = "1.4.$form->{year}";
1011 $form->{todate} = "30.4.$form->{year}";
1014 $form->{duetyp} eq "5" && do {
1015 $form->{fromdate} = "1.5.$form->{year}";
1016 $form->{todate} = "31.5.$form->{year}";
1019 $form->{duetyp} eq "6" && do {
1020 $form->{fromdate} = "1.6.$form->{year}";
1021 $form->{todate} = "30.6.$form->{year}";
1024 $form->{duetyp} eq "7" && do {
1025 $form->{fromdate} = "1.7.$form->{year}";
1026 $form->{todate} = "31.7.$form->{year}";
1029 $form->{duetyp} eq "8" && do {
1030 $form->{fromdate} = "1.8.$form->{year}";
1031 $form->{todate} = "31.8.$form->{year}";
1034 $form->{duetyp} eq "9" && do {
1035 $form->{fromdate} = "1.9.$form->{year}";
1036 $form->{todate} = "30.9.$form->{year}";
1039 $form->{duetyp} eq "10" && do {
1040 $form->{fromdate} = "1.10.$form->{year}";
1041 $form->{todate} = "31.10.$form->{year}";
1044 $form->{duetyp} eq "11" && do {
1045 $form->{fromdate} = "1.11.$form->{year}";
1046 $form->{todate} = "30.11.$form->{year}";
1049 $form->{duetyp} eq "12" && do {
1050 $form->{fromdate} = "1.12.$form->{year}";
1051 $form->{todate} = "31.12.$form->{year}";
1057 RP->income_statement(\%myconfig, \%$form);
1059 ($form->{department}) = split /--/, $form->{department};
1062 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1063 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1065 # if there are any dates construct a where
1066 if ($form->{fromdate} || $form->{todate}) {
1068 unless ($form->{todate}) {
1069 $form->{todate} = $form->current_date(\%myconfig);
1072 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1073 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1075 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1076 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1078 $form->{this_period} = "$shortfromdate\n$shorttodate";
1080 $locale->text('for Period')
1081 . qq|\n$longfromdate |
1082 . $locale->text('Bis')
1086 if ($form->{comparefromdate} || $form->{comparetodate}) {
1087 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1088 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1090 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1091 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1093 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1095 "\n$longcomparefromdate "
1096 . $locale->text('Bis')
1097 . qq| $longcomparetodate|;
1100 # setup variables for the form
1101 my @a = qw(company address businessnumber);
1102 map { $form->{$_} = $myconfig{$_} } @a;
1104 $form->{templates} = $myconfig{templates};
1106 $form->{IN} = "income_statement.html";
1108 $form->parse_template;
1110 $main::lxdebug->leave_sub();
1113 sub generate_balance_sheet {
1114 $::lxdebug->enter_sub;
1115 $::auth->assert('report');
1117 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
1118 $::form->{padding} = " ";
1119 $::form->{bold} = "<b>";
1120 $::form->{endbold} = "</b>";
1121 $::form->{br} = "<br>";
1123 my $data = RP->balance_sheet(\%::myconfig, $::form);
1125 $::form->{asofdate} ||= $::form->current_date;
1126 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
1128 ($::form->{department}) = split /--/, $::form->{department};
1130 # define Current Earnings account
1131 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
1132 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
1134 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
1135 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
1137 # $::form->{IN} = "balance_sheet.html";
1139 # setup company variables for the form
1140 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
1142 $::form->{templates} = $::myconfig{templates};
1145 print $::form->parse_html_template('rp/balance_sheet', $data);
1147 $::lxdebug->leave_sub;
1150 sub generate_projects {
1151 $main::lxdebug->enter_sub();
1153 $main::auth->assert('report');
1155 my $form = $main::form;
1156 my %myconfig = %main::myconfig;
1157 my $locale = $main::locale;
1159 &get_project("generate_projects");
1160 $form->{projectnumber} = $form->{projectnumber_1};
1162 $form->{nextsub} = "generate_projects";
1163 $form->{title} = $locale->text('Project Transactions');
1164 RP->trial_balance(\%myconfig, \%$form);
1166 list_accounts('generate_projects');
1168 $main::lxdebug->leave_sub();
1174 # included links to display transactions for period entered
1175 # added headers and subtotals
1177 sub generate_trial_balance {
1178 $main::lxdebug->enter_sub();
1180 $main::auth->assert('report');
1182 my $form = $main::form;
1183 my %myconfig = %main::myconfig;
1184 my $locale = $main::locale;
1186 if ($form->{reporttype} eq "custom") {
1188 #forgotten the year --> thisyear
1189 if ($form->{year} !~ m/^\d\d\d\d$/) {
1190 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1196 if ($form->{duetyp} eq "13") {
1197 $form->{fromdate} = "1.1.$form->{year}";
1198 $form->{todate} = "31.12.$form->{year}";
1202 if ($form->{duetyp} eq "A") {
1203 $form->{fromdate} = "1.1.$form->{year}";
1204 $form->{todate} = "31.3.$form->{year}";
1206 if ($form->{duetyp} eq "B") {
1207 $form->{fromdate} = "1.4.$form->{year}";
1208 $form->{todate} = "30.6.$form->{year}";
1210 if ($form->{duetyp} eq "C") {
1211 $form->{fromdate} = "1.7.$form->{year}";
1212 $form->{todate} = "30.9.$form->{year}";
1214 if ($form->{duetyp} eq "D") {
1215 $form->{fromdate} = "1.10.$form->{year}";
1216 $form->{todate} = "31.12.$form->{year}";
1221 $form->{duetyp} eq "1" && do {
1222 $form->{fromdate} = "1.1.$form->{year}";
1223 $form->{todate} = "31.1.$form->{year}";
1226 $form->{duetyp} eq "2" && do {
1227 $form->{fromdate} = "1.2.$form->{year}";
1229 #this works from 1901 to 2099, 1900 and 2100 fail.
1230 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1231 $form->{todate} = "$leap.2.$form->{year}";
1234 $form->{duetyp} eq "3" && do {
1235 $form->{fromdate} = "1.3.$form->{year}";
1236 $form->{todate} = "31.3.$form->{year}";
1239 $form->{duetyp} eq "4" && do {
1240 $form->{fromdate} = "1.4.$form->{year}";
1241 $form->{todate} = "30.4.$form->{year}";
1244 $form->{duetyp} eq "5" && do {
1245 $form->{fromdate} = "1.5.$form->{year}";
1246 $form->{todate} = "31.5.$form->{year}";
1249 $form->{duetyp} eq "6" && do {
1250 $form->{fromdate} = "1.6.$form->{year}";
1251 $form->{todate} = "30.6.$form->{year}";
1254 $form->{duetyp} eq "7" && do {
1255 $form->{fromdate} = "1.7.$form->{year}";
1256 $form->{todate} = "31.7.$form->{year}";
1259 $form->{duetyp} eq "8" && do {
1260 $form->{fromdate} = "1.8.$form->{year}";
1261 $form->{todate} = "31.8.$form->{year}";
1264 $form->{duetyp} eq "9" && do {
1265 $form->{fromdate} = "1.9.$form->{year}";
1266 $form->{todate} = "30.9.$form->{year}";
1269 $form->{duetyp} eq "10" && do {
1270 $form->{fromdate} = "1.10.$form->{year}";
1271 $form->{todate} = "31.10.$form->{year}";
1274 $form->{duetyp} eq "11" && do {
1275 $form->{fromdate} = "1.11.$form->{year}";
1276 $form->{todate} = "30.11.$form->{year}";
1279 $form->{duetyp} eq "12" && do {
1280 $form->{fromdate} = "1.12.$form->{year}";
1281 $form->{todate} = "31.12.$form->{year}";
1288 # get for each account initial balance, debits and credits
1289 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
1292 $form->{rowcount} = scalar @{ $form->{TB} || [] };
1293 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1296 "accno", "description",
1297 "last_transaction", "soll_eb",
1300 "soll_kumuliert", "haben_kumuliert",
1301 "soll_saldo", "haben_saldo"
1305 my $attachment_basename = $locale->text('trial_balance');
1306 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1308 my @hidden_variables = qw(fromdate todate year cash);
1310 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1313 'accno' => { 'text' => $locale->text('Account'), },
1314 'description' => { 'text' => $locale->text('Description'), },
1315 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1316 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1317 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1318 'soll' => { 'text' => $locale->text('Debit'), },
1319 'haben' => { 'text' => $locale->text('Credit'), },
1320 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1321 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1322 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1323 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1328 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1330 map { $column_defs{$_}->{visible} = 1 } @columns;
1332 $report->set_columns(%column_defs);
1333 $report->set_column_order(@columns);
1335 $report->set_export_options('generate_trial_balance', @hidden_variables);
1340 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1342 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
1343 push (@options, $form->{print_date});
1345 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
1346 push (@options, $form->{company});
1349 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1351 $report->set_options('output_format' => 'HTML',
1352 'top_info_text' => join("\n", @options),
1353 'title' => $form->{title},
1354 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1355 'html_template' => 'rp/html_report_susa',
1356 'pdf_template' => 'rp/html_report_susa',
1358 $report->set_options_from_form();
1360 # add sort and escape callback, this one we use for the add sub
1361 $form->{callback} = $href .= "&sort=$form->{sort}";
1363 # escape callback for href
1364 my $callback = $form->escape($href);
1366 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1368 my %totals = map { $_ => 0 } @subtotal_columns;
1370 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1373 foreach my $accno (@{ $form->{TB} }) {
1375 $accno->{soll} = $accno->{debit};
1376 $accno->{haben} = $accno->{credit};
1377 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1379 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
1380 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1384 foreach my $column (@columns) {
1386 'data' => $accno->{$column},
1387 'align' => $column_alignment{$column},
1391 $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}));
1393 my $row_set = [ $row ];
1396 $report->add_data($row_set);
1401 $report->add_separator();
1403 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1405 $report->generate_with_headers();
1407 $main::lxdebug->leave_sub();
1411 sub create_subtotal_row {
1412 $main::lxdebug->enter_sub();
1414 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1416 my $form = $main::form;
1417 my %myconfig = %main::myconfig;
1418 my $locale = $main::locale;
1420 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1422 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1424 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1426 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1428 $main::lxdebug->leave_sub();
1433 sub create_list_accounts_subtotal_row {
1434 $main::lxdebug->enter_sub();
1436 my ($subtotals, $columns, $fields, $class) = @_;
1438 my $form = $main::form;
1439 my %myconfig = %main::myconfig;
1440 my $locale = $main::locale;
1442 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1444 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1446 $main::lxdebug->leave_sub();
1452 $main::lxdebug->enter_sub();
1456 my $form = $main::form;
1457 my %myconfig = %main::myconfig;
1458 my $locale = $main::locale;
1461 if ($form->{department}) {
1462 my ($department) = split /--/, $form->{department};
1463 push @options, $locale->text('Department') . " : $department";
1465 if ($form->{projectnumber}) {
1466 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1469 # if there are any dates
1470 if ($form->{fromdate} || $form->{todate}) {
1471 my ($fromdate, $todate);
1473 if ($form->{fromdate}) {
1474 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1476 if ($form->{todate}) {
1477 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1480 push @options, "$fromdate - $todate";
1483 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1486 my @columns = qw(accno description begbalance debit credit endbalance);
1488 'accno' => { 'text' => $locale->text('Account'), },
1489 'description' => { 'text' => $locale->text('Description'), },
1490 'debit' => { 'text' => $locale->text('Debit'), },
1491 'credit' => { 'text' => $locale->text('Credit'), },
1492 'begbalance' => { 'text' => $locale->text('Balance'), },
1493 'endbalance' => { 'text' => $locale->text('Balance'), },
1495 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1497 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1499 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1501 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1503 $report->set_options('top_info_text' => join("\n", @options),
1504 'output_format' => 'HTML',
1505 'title' => $form->{title},
1506 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1507 'std_column_visibility' => 1,
1509 $report->set_options_from_form();
1511 $report->set_columns(%column_defs);
1512 $report->set_column_order(@columns);
1514 $report->set_export_options($action, @hidden_variables);
1516 my @totals_columns = qw(credit debit begbalance endbalance);
1517 my %subtotals = map { $_ => 0 } @totals_columns;
1518 my %totals = map { $_ => 0 } @totals_columns;
1519 my $found_heading = 0;
1520 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1522 # sort the whole thing by account numbers and display
1523 foreach my $idx (0 .. scalar(@tb) - 1) {
1524 my $ref = $tb[$idx];
1525 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1527 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1529 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1531 if ($ref->{charttype} eq 'H') {
1532 next unless ($form->{l_heading});
1534 %subtotals = map { $_ => 0 } @totals_columns;
1536 $row->{description}->{class} = 'listheading';
1537 $row->{description}->{data} = $ref->{description};
1539 $report->add_data($row);
1544 foreach (qw(debit credit)) {
1545 $subtotals{$_} += $ref->{$_};
1546 $totals{$_} += $ref->{$_};
1549 $subtotals{begbalance} += $ref->{balance} * $ml;
1550 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1552 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1553 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1555 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1556 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1558 $report->add_data($row);
1560 if ($form->{l_heading} && $found_heading &&
1561 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1562 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1566 $report->add_separator();
1568 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1570 $report->generate_with_headers();
1572 $main::lxdebug->leave_sub();
1575 sub generate_ar_aging {
1576 $main::lxdebug->enter_sub();
1578 $main::auth->assert('general_ledger');
1580 my $form = $main::form;
1581 my %myconfig = %main::myconfig;
1582 my $locale = $main::locale;
1585 ($form->{customer}) = split(/--/, $form->{customer});
1587 $form->{ct} = "customer";
1588 $form->{arap} = "ar";
1590 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1592 RP->aging(\%myconfig, \%$form);
1595 $main::lxdebug->leave_sub();
1598 sub generate_ap_aging {
1599 $main::lxdebug->enter_sub();
1601 $main::auth->assert('general_ledger');
1603 my $form = $main::form;
1604 my %myconfig = %main::myconfig;
1605 my $locale = $main::locale;
1608 ($form->{vendor}) = split(/--/, $form->{vendor});
1610 $form->{ct} = "vendor";
1611 $form->{arap} = "ap";
1613 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1615 RP->aging(\%myconfig, \%$form);
1618 $main::lxdebug->leave_sub();
1621 sub create_aging_subtotal_row {
1622 $main::lxdebug->enter_sub();
1624 my ($subtotals, $columns, $periods, $class) = @_;
1626 my $form = $main::form;
1627 my %myconfig = %main::myconfig;
1628 my $locale = $main::locale;
1630 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1632 foreach (@{ $periods }) {
1633 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1634 $subtotals->{$_} = 0;
1637 $main::lxdebug->leave_sub();
1643 $main::lxdebug->enter_sub();
1645 $main::auth->assert('general_ledger');
1647 my $form = $main::form;
1648 my %myconfig = %main::myconfig;
1649 my $locale = $main::locale;
1650 my $cgi = $main::cgi;
1652 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1654 my @columns = qw(statement ct invnumber transdate duedate amount open);
1657 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1658 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1659 'invnumber' => { 'text' => $locale->text('Invoice'), },
1660 'transdate' => { 'text' => $locale->text('Date'), },
1661 'duedate' => { 'text' => $locale->text('Due'), },
1662 'amount' => { 'text' => $locale->text('Amount'), },
1663 'open' => { 'text' => $locale->text('Open'), },
1666 my %column_alignment = ('statement' => 'center',
1667 map { $_ => 'right' } qw(open amount));
1669 $report->set_options('std_column_visibility' => 1);
1670 $report->set_columns(%column_defs);
1671 $report->set_column_order(@columns);
1673 my @hidden_variables = qw(todate customer vendor arap title ct);
1674 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1677 my $attachment_basename;
1679 if ($form->{department}) {
1680 my ($department) = split /--/, $form->{department};
1681 push @options, $locale->text('Department') . " : $department";
1682 $form->{callback} .= "&department=" . E($department);
1685 if (($form->{arap} eq 'ar') && $form->{customer}) {
1686 push @options, $form->{customer};
1687 $attachment_basename = $locale->text('ar_aging_list');
1688 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1691 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1692 push @options, $form->{vendor};
1693 $attachment_basename = $locale->text('ap_aging_list');
1694 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1697 if ($form->{fromdate}) {
1698 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1700 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1703 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1705 $report->set_options('top_info_text' => join("\n", @options),
1706 'output_format' => 'HTML',
1707 'title' => $form->{title},
1708 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1711 my $previous_ctid = 0;
1713 my @periods = qw(open amount);
1714 my %subtotals = map { $_ => 0 } @periods;
1715 my %totals = map { $_ => 0 } @periods;
1717 foreach my $ref (@{ $form->{AG} }) {
1718 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1719 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1722 foreach my $key (@periods) {
1723 $subtotals{$key} += $ref->{"$key"};
1724 $totals{$key} += $ref->{"$key"};
1725 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1730 foreach my $column (@columns) {
1732 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1733 'align' => $column_alignment{$column},
1734 'valign' => $column eq 'statement' ? 'center' : '',
1738 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1740 if ($previous_ctid != $ref->{ctid}) {
1741 $row->{statement}->{raw_data} =
1742 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1743 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1744 $row->{ct}->{data} = $ref->{name};
1749 $previous_ctid = $ref->{ctid};
1751 $report->add_data($row);
1754 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1756 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1758 if ($form->{arap} eq 'ar') {
1759 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1760 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1761 'PRINT_OPTIONS' => print_options(inline => 1), });
1762 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1763 'raw_bottom_info_text' => $raw_bottom_info_text);
1766 $report->set_options_from_form();
1768 $report->generate_with_headers();
1770 $main::lxdebug->leave_sub();
1774 $main::lxdebug->enter_sub();
1776 my $form = $main::form;
1777 my %myconfig = %main::myconfig;
1778 my $locale = $main::locale;
1780 RP->aging(\%myconfig, \%$form);
1782 map { $_->{checked} = "checked" } @{ $form->{AG} };
1786 $main::lxdebug->leave_sub();
1790 $main::lxdebug->enter_sub();
1792 $main::auth->assert('general_ledger');
1794 my $form = $main::form;
1795 my %myconfig = %main::myconfig;
1796 my $locale = $main::locale;
1798 # get name and email addresses
1800 for my $i (1 .. $form->{rowcount}) {
1801 if ($form->{"statement_$i"}) {
1802 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1803 RP->get_customer(\%myconfig, \%$form);
1809 $form->error($locale->text('Nothing selected!')) unless $selected;
1812 if ($myconfig{role} eq 'admin') {
1814 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1815 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1819 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1821 $form->{media} = "email";
1828 <form method=post action=$form->{script}>
1834 <tr height="5"></tr>
1839 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1840 <td><input name=email size=30 value="$form->{email}"></td>
1841 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1842 <td><input name=cc size=30 value="$form->{cc}"></td>
1845 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1846 <td><input name=subject size=30 value="$form->{subject}"></td>
1856 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1859 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1870 map { delete $form->{$_} }
1871 qw(action email cc bcc subject message type sendmode format header);
1873 # save all other variables
1874 foreach my $key (keys %$form) {
1875 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1876 $form->{$key} =~ s/\"/"/g;
1877 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1884 <td><hr size=3 noshade></td>
1888 <input type=hidden name=nextsub value=send_email>
1891 <input name=action class=submit type=submit value="|
1892 . $locale->text('Continue') . qq|">
1899 $main::lxdebug->leave_sub();
1903 $main::lxdebug->enter_sub();
1905 $main::auth->assert('general_ledger');
1907 my $form = $main::form;
1908 my %myconfig = %main::myconfig;
1909 my $locale = $main::locale;
1911 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1912 unless $form->{subject};
1914 RP->aging(\%myconfig, \%$form);
1916 $form->{"statement_1"} = 1;
1918 $form->{media} = 'email';
1921 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1923 $main::lxdebug->leave_sub();
1927 $main::lxdebug->enter_sub();
1929 $main::auth->assert('general_ledger');
1931 my $form = $main::form;
1932 my %myconfig = %main::myconfig;
1933 my $locale = $main::locale;
1935 if ($form->{media} eq 'printer') {
1936 $form->error($locale->text('Select postscript or PDF!'))
1937 if ($form->{format} !~ /(postscript|pdf)/);
1941 for my $i (1 .. $form->{rowcount}) {
1942 if ($form->{"statement_$i"}) {
1943 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1949 $form->error($locale->text('Nothing selected!')) unless $selected;
1951 if ($form->{media} eq 'printer') {
1952 $form->{"$form->{ct}_id"} = "";
1954 $form->{"statement_1"} = 1;
1957 RP->aging(\%myconfig, \%$form);
1961 $form->redirect($locale->text('Statements sent to printer!'))
1962 if ($form->{media} eq 'printer');
1964 $main::lxdebug->leave_sub();
1968 $main::lxdebug->enter_sub();
1970 $main::auth->assert('general_ledger');
1972 my $form = $main::form;
1973 my %myconfig = %main::myconfig;
1974 my $locale = $main::locale;
1976 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1978 $form->{templates} = "$myconfig{templates}";
1980 my $suffix = "html";
1981 my $attachment_suffix = "html";
1982 if ($form->{format} eq 'postscript') {
1983 $form->{postscript} = 1;
1985 $attachment_suffix = "ps";
1986 } elsif ($form->{format} eq 'pdf') {
1989 $attachment_suffix = "pdf";
1992 $form->{IN} = "$form->{type}.$suffix";
1993 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1995 # Save $form->{email} because it will be overwritten.
1996 $form->{EMAIL_RECIPIENT} = $form->{email};
2000 while (@{ $form->{AG} }) {
2002 my $ref = shift @{ $form->{AG} };
2004 if ($ctid != $ref->{ctid}) {
2006 $ctid = $ref->{ctid};
2009 if ($form->{"statement_$i"}) {
2012 ("name", "street", "zipcode", "city", "country", "contact", "email",
2013 "$form->{ct}phone", "$form->{ct}fax");
2014 map { $form->{$_} = $ref->{$_} } @a;
2016 $form->{ $form->{ct} } = $form->{name};
2017 $form->{"$form->{ct}_id"} = $ref->{ctid};
2019 map { $form->{$_} = () } qw(invnumber invdate duedate);
2021 foreach my $item (qw(c0 c30 c60 c90)) {
2022 $form->{$item} = ();
2023 $form->{"${item}total"} = 0;
2026 &statement_details($ref);
2030 if (scalar(@{ $form->{AG} }) > 0) {
2032 # one or more left to go
2033 if ($ctid == $form->{AG}->[0]->{ctid}) {
2034 $ref = shift @{ $form->{AG} };
2035 &statement_details($ref);
2038 $ref = scalar(@{ $form->{AG} });
2044 # set initial ref to 0
2051 $form->{"${_}total"} =
2052 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2053 } ('c0', 'c30', 'c60', 'c90', "");
2055 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2056 $form->{attachment_filename} =~ s/\s+/_/g;
2058 $form->parse_template(\%myconfig, $main::userspath);
2063 # saving the history
2064 if(!exists $form->{addition} && $form->{id} ne "") {
2065 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2066 $form->{addition} = "PRINTED";
2067 $form->{what_done} = $form->{type};
2068 $form->save_history;
2070 # /saving the history
2071 $main::lxdebug->leave_sub();
2074 sub statement_details {
2075 $main::lxdebug->enter_sub();
2077 $main::auth->assert('general_ledger');
2079 my $form = $main::form;
2080 my %myconfig = %main::myconfig;
2081 my $locale = $main::locale;
2085 push @{ $form->{invnumber} }, $ref->{invnumber};
2086 push @{ $form->{invdate} }, $ref->{transdate};
2087 push @{ $form->{duedate} }, $ref->{duedate};
2089 foreach my $item (qw(c0 c30 c60 c90)) {
2090 if ($ref->{exchangerate} * 1) {
2092 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2094 $form->{"${item}total"} += $ref->{$item};
2095 $form->{total} += $ref->{$item};
2096 push @{ $form->{$item} },
2097 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2100 $main::lxdebug->leave_sub();
2103 sub generate_tax_report {
2104 $main::lxdebug->enter_sub();
2106 $main::auth->assert('report');
2108 my $form = $main::form;
2109 my %myconfig = %main::myconfig;
2110 my $locale = $main::locale;
2112 RP->tax_report(\%myconfig, \%$form);
2114 my $descvar = "$form->{accno}_description";
2115 my $description = $form->escape($form->{$descvar});
2116 my $ratevar = "$form->{accno}_rate";
2117 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
2119 my $department = $form->escape($form->{department});
2123 "$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}";
2125 # construct callback
2126 $description = $form->escape($form->{$descvar}, 1);
2127 $department = $form->escape($form->{department}, 1);
2129 "$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}";
2131 my $title = $form->escape($form->{title});
2132 $href .= "&title=$title";
2133 $title = $form->escape($form->{title}, 1);
2134 $callback .= "&title=$title";
2136 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2139 $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} }) {
2245 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
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);
2262 $column_data{id} = qq|<td>$ref->{id}</td>|;
2263 $column_data{invnumber} =
2264 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2265 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2266 $column_data{name} = qq|<td>$ref->{name} </td>|;
2268 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2269 qw(netamount tax amount);
2274 <tr class=listrow$i>
2277 map { print "$column_data{$_}\n" } @column_index;
2285 if ($form->{l_subtotal} eq 'Y') {
2286 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2290 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2294 <tr class=listtotal>
2297 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2298 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2299 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2301 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
2302 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2303 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2305 map { print "$column_data{$_}\n" } @column_index;
2313 <td><hr size=3 noshade></td>
2321 $main::lxdebug->leave_sub();
2325 $main::lxdebug->enter_sub();
2327 my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
2329 my $form = $main::form;
2330 my %myconfig = %main::myconfig;
2331 my $locale = $main::locale;
2334 map { $column_data{$_} = "<td> </td>" } @{ $column_index };
2336 $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " ");
2337 $$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " ");
2338 $$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " ");
2340 $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
2341 $column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>";
2342 $column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>";
2344 $$subtotalnetamount = 0;
2348 <tr class=listsubtotal>
2350 map { print "\n$column_data{$_}" } @{ $column_index };
2356 $main::lxdebug->leave_sub();
2360 $main::lxdebug->enter_sub();
2362 $main::auth->assert('cash');
2364 my $form = $main::form;
2365 my %myconfig = %main::myconfig;
2366 my $locale = $main::locale;
2368 if ($form->{account}) {
2369 ($form->{paymentaccounts}) = split /--/, $form->{account};
2373 if ($form->{department}) {
2374 (my $department, $form->{department_id}) = split /--/, $form->{department};
2375 $option = $locale->text('Department') . " : $department";
2378 report_generator_set_default_sort('transdate', 1);
2380 RP->payments(\%myconfig, \%$form);
2382 my @hidden_variables = qw(account title department reference source memo fromdate todate
2383 fx_transaction db prepayment paymentaccounts sort);
2385 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2386 $form->{callback} = $href;
2388 my @columns = qw(transdate invnumber name paid source memo);
2390 'name' => { 'text' => $locale->text('Description'), },
2391 'invnumber' => { 'text' => $locale->text('Reference'), },
2392 'transdate' => { 'text' => $locale->text('Date'), },
2393 'paid' => { 'text' => $locale->text('Amount'), },
2394 'source' => { 'text' => $locale->text('Source'), },
2395 'memo' => { 'text' => $locale->text('Memo'), },
2397 my %column_alignment = ('paid' => 'right');
2399 foreach my $name (grep { $_ ne 'paid' } @columns) {
2400 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2401 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2405 if ($form->{fromdate}) {
2406 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2408 if ($form->{todate}) {
2409 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2412 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2414 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2416 $report->set_options('top_info_text' => join("\n", @options),
2417 'output_format' => 'HTML',
2418 'title' => $form->{title},
2419 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2420 'std_column_visibility' => 1,
2422 $report->set_options_from_form();
2424 $report->set_columns(%column_defs);
2425 $report->set_column_order(@columns);
2427 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2429 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2433 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2434 next unless @{ $form->{ $ref->{id} } };
2436 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2438 my $subtotal_paid = 0;
2440 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2441 my $module = $payment->{module};
2442 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2443 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2445 $subtotal_paid += $payment->{paid};
2446 $total_paid += $payment->{paid};
2448 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2452 foreach my $column (@columns) {
2454 'data' => $payment->{$column},
2455 'align' => $column_alignment{$column},
2459 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2461 $report->add_data($row);
2464 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2466 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2468 'class' => 'listsubtotal',
2471 $report->add_data($row);
2474 $report->add_separator();
2476 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2478 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2480 'class' => 'listtotal',
2483 $report->add_data($row);
2485 $report->generate_with_headers();
2487 $main::lxdebug->leave_sub();
2491 $main::lxdebug->enter_sub();
2493 my ($dont_print) = @_;
2495 my $form = $main::form;
2496 my %myconfig = %main::myconfig;
2497 my $locale = $main::locale;
2499 $form->{sendmode} = "attachment";
2502 $form->{"format"} ? $form->{"format"} :
2503 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2507 $form->{"copies"} ? $form->{"copies"} :
2508 $myconfig{"copies"} ? $myconfig{"copies"} :
2511 $form->{PD}{ $form->{type} } = "selected";
2512 $form->{DF}{ $form->{format} } = "selected";
2513 $form->{OP}{ $form->{media} } = "selected";
2514 $form->{SM}{ $form->{sendmode} } = "selected";
2518 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
2520 if ($form->{media} eq 'email') {
2522 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
2523 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2526 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2527 if ($myconfig{printer} && $main::latex_templates) {
2529 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
2534 if ($main::latex_templates) {
2536 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2537 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2538 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2544 <td><select name=type>$type</select></td>
2545 <td><select name=format>$format</select></td>
2546 <td><select name=media>$media</select></td>
2549 if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
2551 <td>| . $locale->text('Copies') . qq|
2552 <input name=copies size=2 value=$form->{copies}></td>
2561 print $output unless $dont_print;
2563 $main::lxdebug->leave_sub();
2569 $main::lxdebug->enter_sub();
2571 $main::auth->assert('report');
2573 my $form = $main::form;
2574 my %myconfig = %main::myconfig;
2575 my $locale = $main::locale;
2577 $form->{padding} = " ";
2578 $form->{bold} = "<b>";
2579 $form->{endbold} = "</b>";
2580 $form->{br} = "<br>";
2582 if ($form->{reporttype} eq "custom") {
2584 #forgotten the year --> thisyear
2585 if ($form->{year} !~ m/^\d\d\d\d$/) {
2586 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2592 if ($form->{duetyp} eq "13") {
2593 $form->{fromdate} = "1.1.$form->{year}";
2594 $form->{todate} = "31.12.$form->{year}";
2595 $form->{comparefromdate} = "1.01.$form->{year}";
2596 $form->{comparetodate} = "31.12.$form->{year}";
2600 if ($form->{duetyp} eq "A") {
2601 $form->{fromdate} = "1.1.$form->{year}";
2602 $form->{todate} = "31.3.$form->{year}";
2603 $form->{comparefromdate} = "1.01.$form->{year}";
2604 $form->{comparetodate} = "31.03.$form->{year}";
2606 if ($form->{duetyp} eq "B") {
2607 $form->{fromdate} = "1.4.$form->{year}";
2608 $form->{todate} = "30.6.$form->{year}";
2609 $form->{comparefromdate} = "1.01.$form->{year}";
2610 $form->{comparetodate} = "30.06.$form->{year}";
2612 if ($form->{duetyp} eq "C") {
2613 $form->{fromdate} = "1.7.$form->{year}";
2614 $form->{todate} = "30.9.$form->{year}";
2615 $form->{comparefromdate} = "1.01.$form->{year}";
2616 $form->{comparetodate} = "30.09.$form->{year}";
2618 if ($form->{duetyp} eq "D") {
2619 $form->{fromdate} = "1.10.$form->{year}";
2620 $form->{todate} = "31.12.$form->{year}";
2621 $form->{comparefromdate} = "1.01.$form->{year}";
2622 $form->{comparetodate} = "31.12.$form->{year}";
2627 $form->{duetyp} eq "1" && do {
2628 $form->{fromdate} = "1.1.$form->{year}";
2629 $form->{todate} = "31.1.$form->{year}";
2630 $form->{comparefromdate} = "1.01.$form->{year}";
2631 $form->{comparetodate} = "31.01.$form->{year}";
2634 $form->{duetyp} eq "2" && do {
2635 $form->{fromdate} = "1.2.$form->{year}";
2637 #this works from 1901 to 2099, 1900 and 2100 fail.
2638 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2639 $form->{todate} = "$leap.2.$form->{year}";
2640 $form->{comparefromdate} = "1.01.$form->{year}";
2641 $form->{comparetodate} = "$leap.02.$form->{year}";
2644 $form->{duetyp} eq "3" && do {
2645 $form->{fromdate} = "1.3.$form->{year}";
2646 $form->{todate} = "31.3.$form->{year}";
2647 $form->{comparefromdate} = "1.01.$form->{year}";
2648 $form->{comparetodate} = "31.03.$form->{year}";
2651 $form->{duetyp} eq "4" && do {
2652 $form->{fromdate} = "1.4.$form->{year}";
2653 $form->{todate} = "30.4.$form->{year}";
2654 $form->{comparefromdate} = "1.01.$form->{year}";
2655 $form->{comparetodate} = "30.04.$form->{year}";
2658 $form->{duetyp} eq "5" && do {
2659 $form->{fromdate} = "1.5.$form->{year}";
2660 $form->{todate} = "31.5.$form->{year}";
2661 $form->{comparefromdate} = "1.01.$form->{year}";
2662 $form->{comparetodate} = "31.05.$form->{year}";
2665 $form->{duetyp} eq "6" && do {
2666 $form->{fromdate} = "1.6.$form->{year}";
2667 $form->{todate} = "30.6.$form->{year}";
2668 $form->{comparefromdate} = "1.01.$form->{year}";
2669 $form->{comparetodate} = "30.06.$form->{year}";
2672 $form->{duetyp} eq "7" && do {
2673 $form->{fromdate} = "1.7.$form->{year}";
2674 $form->{todate} = "31.7.$form->{year}";
2675 $form->{comparefromdate} = "1.01.$form->{year}";
2676 $form->{comparetodate} = "31.07.$form->{year}";
2679 $form->{duetyp} eq "8" && do {
2680 $form->{fromdate} = "1.8.$form->{year}";
2681 $form->{todate} = "31.8.$form->{year}";
2682 $form->{comparefromdate} = "1.01.$form->{year}";
2683 $form->{comparetodate} = "31.08.$form->{year}";
2686 $form->{duetyp} eq "9" && do {
2687 $form->{fromdate} = "1.9.$form->{year}";
2688 $form->{todate} = "30.9.$form->{year}";
2689 $form->{comparefromdate} = "1.01.$form->{year}";
2690 $form->{comparetodate} = "30.09.$form->{year}";
2693 $form->{duetyp} eq "10" && do {
2694 $form->{fromdate} = "1.10.$form->{year}";
2695 $form->{todate} = "31.10.$form->{year}";
2696 $form->{comparefromdate} = "1.01.$form->{year}";
2697 $form->{comparetodate} = "31.10.$form->{year}";
2700 $form->{duetyp} eq "11" && do {
2701 $form->{fromdate} = "1.11.$form->{year}";
2702 $form->{todate} = "30.11.$form->{year}";
2703 $form->{comparefromdate} = "1.01.$form->{year}";
2704 $form->{comparetodate} = "30.11.$form->{year}";
2707 $form->{duetyp} eq "12" && do {
2708 $form->{fromdate} = "1.12.$form->{year}";
2709 $form->{todate} = "31.12.$form->{year}";
2710 $form->{comparefromdate} = "1.01.$form->{year}";
2711 $form->{comparetodate} = "31.12.$form->{year}";
2716 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2717 # ansonsten ist die prüfung in RP.pm
2718 # if (defined ($form->{fromdate|todate}=='..'))
2720 if ($form->{fromdate}){
2721 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2722 $form->{fromdate} = "${dd}.${mm}.${yy}";
2723 $form->{comparefromdate} = "01.01.$yy";
2725 if ($form->{todate}){
2726 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2727 $form->{todate} = "${dd}.${mm}.${yy}";
2728 $form->{comparetodate} = $form->{todate};
2732 RP->bwa(\%myconfig, \%$form);
2734 ($form->{department}) = split /--/, $form->{department};
2737 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2738 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2740 # if there are any dates construct a where
2741 if ($form->{fromdate} || $form->{todate}) {
2743 unless ($form->{todate}) {
2744 $form->{todate} = $form->current_date(\%myconfig);
2747 my %germandate = ("dateformat" => "dd.mm.yyyy");
2749 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2750 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2752 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2753 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2755 $form->{this_period} = "$shortfromdate\n$shorttodate";
2757 $locale->text('for Period')
2758 . qq|\n$longfromdate |
2759 . $locale->text('bis')
2763 # setup variables for the form
2764 my @a = qw(company address businessnumber);
2765 map { $form->{$_} = $myconfig{$_} } @a;
2766 $form->{templates} = $myconfig{templates};
2768 $form->{IN} = "bwa.html";
2770 $form->parse_template;
2772 $main::lxdebug->leave_sub();