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}">
268 <table width=100% border="0">
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>| . $locale->text('Review of Aging list') . qq|</td>
810 <td><select name="review_of_aging_list">
812 <option>0-30</option>
813 <option>30-60</option>
814 <option>60-90</option>
815 <option>90-120</option>
816 <option>> 120</option>
821 <td align=left colspan=4>| . $locale->text('From') . qq|
824 | . $locale->text('Bis') . qq|
829 <input type=hidden name=type value=statement>
830 <input type=hidden name=format value=html>
831 <input type=hidden name=media value=screen>
833 <input type=hidden name=nextsub value=$nextsub>
834 <input type=hidden name=action value=$nextsub>
840 # above action can be removed if there is more than one input field
842 my ($selection, $paymentaccounts);
843 if ($form->{report} =~ /(receipts|payments)$/) {
844 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
846 RP->paymentaccounts(\%myconfig, \%$form);
848 $selection = "<option>\n";
849 foreach my $ref (@{ $form->{PR} }) {
850 $paymentaccounts .= "$ref->{accno} ";
851 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
854 chop $paymentaccounts;
857 <input type=hidden name=nextsub value=list_payments>
859 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
860 <td colspan=3><select name=account>$selection</select>
861 <input type=hidden name=paymentaccounts value="$paymentaccounts">
865 <th align=right>| . $locale->text('Reference') . qq|</th>
866 <td colspan=3><input name=reference></td>
869 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
870 <td colspan=3><input name=source></td>
873 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
874 <td colspan=3><input name=memo size=30></td>
877 <th align=right>| . $locale->text('From') . qq|</th>
882 <th align=right>| . $locale->text('Bis') . qq|</th>
889 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
890 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
895 <input type=hidden name=db value=$form->{db}>
896 <input type=hidden name=sort value=transdate>
907 <td><hr size=3 noshade></td>
912 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
920 $main::lxdebug->leave_sub();
923 sub continue { call_sub($main::form->{"nextsub"}); }
926 $main::lxdebug->enter_sub();
928 $main::auth->assert('report');
930 my $form = $main::form;
931 my %myconfig = %main::myconfig;
932 my $locale = $main::locale;
936 $form->{project_id} = $form->{project_id_1};
937 if ($form->{projectnumber} && !$form->{project_id}) {
938 $form->{rowcount} = 1;
940 # call this instead of update
941 $form->{update} = $nextsub;
942 $form->{projectnumber_1} = $form->{projectnumber};
944 delete $form->{sort};
945 check_project('generate_projects');
947 # if there is one only, assign id
948 $form->{project_id} = $form->{project_id_1};
951 $main::lxdebug->leave_sub();
954 sub generate_income_statement {
955 $main::lxdebug->enter_sub();
957 $main::auth->assert('report');
959 my $form = $main::form;
960 my %myconfig = %main::myconfig;
961 my $locale = $main::locale;
963 $form->{padding} = " ";
964 $form->{bold} = "<b>";
965 $form->{endbold} = "</b>";
966 $form->{br} = "<br>";
968 if ($form->{reporttype} eq "custom") {
970 #forgotten the year --> thisyear
971 if ($form->{year} !~ m/^\d\d\d\d$/) {
972 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
978 if ($form->{duetyp} eq "13") {
979 $form->{fromdate} = "1.1.$form->{year}";
980 $form->{todate} = "31.12.$form->{year}";
984 if ($form->{duetyp} eq "A") {
985 $form->{fromdate} = "1.1.$form->{year}";
986 $form->{todate} = "31.3.$form->{year}";
988 if ($form->{duetyp} eq "B") {
989 $form->{fromdate} = "1.4.$form->{year}";
990 $form->{todate} = "30.6.$form->{year}";
992 if ($form->{duetyp} eq "C") {
993 $form->{fromdate} = "1.7.$form->{year}";
994 $form->{todate} = "30.9.$form->{year}";
996 if ($form->{duetyp} eq "D") {
997 $form->{fromdate} = "1.10.$form->{year}";
998 $form->{todate} = "31.12.$form->{year}";
1003 $form->{duetyp} eq "1" && do {
1004 $form->{fromdate} = "1.1.$form->{year}";
1005 $form->{todate} = "31.1.$form->{year}";
1008 $form->{duetyp} eq "2" && do {
1009 $form->{fromdate} = "1.2.$form->{year}";
1011 #this works from 1901 to 2099, 1900 and 2100 fail.
1012 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1013 $form->{todate} = "$leap.2.$form->{year}";
1016 $form->{duetyp} eq "3" && do {
1017 $form->{fromdate} = "1.3.$form->{year}";
1018 $form->{todate} = "31.3.$form->{year}";
1021 $form->{duetyp} eq "4" && do {
1022 $form->{fromdate} = "1.4.$form->{year}";
1023 $form->{todate} = "30.4.$form->{year}";
1026 $form->{duetyp} eq "5" && do {
1027 $form->{fromdate} = "1.5.$form->{year}";
1028 $form->{todate} = "31.5.$form->{year}";
1031 $form->{duetyp} eq "6" && do {
1032 $form->{fromdate} = "1.6.$form->{year}";
1033 $form->{todate} = "30.6.$form->{year}";
1036 $form->{duetyp} eq "7" && do {
1037 $form->{fromdate} = "1.7.$form->{year}";
1038 $form->{todate} = "31.7.$form->{year}";
1041 $form->{duetyp} eq "8" && do {
1042 $form->{fromdate} = "1.8.$form->{year}";
1043 $form->{todate} = "31.8.$form->{year}";
1046 $form->{duetyp} eq "9" && do {
1047 $form->{fromdate} = "1.9.$form->{year}";
1048 $form->{todate} = "30.9.$form->{year}";
1051 $form->{duetyp} eq "10" && do {
1052 $form->{fromdate} = "1.10.$form->{year}";
1053 $form->{todate} = "31.10.$form->{year}";
1056 $form->{duetyp} eq "11" && do {
1057 $form->{fromdate} = "1.11.$form->{year}";
1058 $form->{todate} = "30.11.$form->{year}";
1061 $form->{duetyp} eq "12" && do {
1062 $form->{fromdate} = "1.12.$form->{year}";
1063 $form->{todate} = "31.12.$form->{year}";
1067 hotfix_reformat_date();
1068 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
1070 RP->income_statement(\%myconfig, \%$form);
1072 ($form->{department}) = split /--/, $form->{department};
1075 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1076 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1078 # if there are any dates construct a where
1079 if ($form->{fromdate} || $form->{todate}) {
1081 unless ($form->{todate}) {
1082 $form->{todate} = $form->current_date(\%myconfig);
1085 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1086 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1088 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1089 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1091 $form->{this_period} = "$shortfromdate\n$shorttodate";
1093 $locale->text('for Period')
1094 . qq|\n$longfromdate |
1095 . $locale->text('Bis')
1099 if ($form->{comparefromdate} || $form->{comparetodate}) {
1100 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1101 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1103 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1104 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1106 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1108 "\n$longcomparefromdate "
1109 . $locale->text('Bis')
1110 . qq| $longcomparetodate|;
1113 # setup variables for the form
1114 my @a = qw(company address businessnumber);
1115 map { $form->{$_} = $myconfig{$_} } @a;
1117 $form->{templates} = $myconfig{templates};
1119 $form->{IN} = "income_statement.html";
1121 $form->parse_template;
1123 $main::lxdebug->leave_sub();
1126 sub generate_balance_sheet {
1127 $::lxdebug->enter_sub;
1128 $::auth->assert('report');
1130 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
1131 $::form->{padding} = " ";
1132 $::form->{bold} = "<b>";
1133 $::form->{endbold} = "</b>";
1134 $::form->{br} = "<br>";
1136 my $data = RP->balance_sheet(\%::myconfig, $::form);
1138 $::form->{asofdate} ||= $::form->current_date;
1139 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
1141 ($::form->{department}) = split /--/, $::form->{department};
1143 # define Current Earnings account
1144 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
1145 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
1147 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
1148 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
1150 # $::form->{IN} = "balance_sheet.html";
1152 # setup company variables for the form
1153 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
1155 $::form->{templates} = $::myconfig{templates};
1158 print $::form->parse_html_template('rp/balance_sheet', $data);
1160 $::lxdebug->leave_sub;
1163 sub generate_projects {
1164 $main::lxdebug->enter_sub();
1166 $main::auth->assert('report');
1168 my $form = $main::form;
1169 my %myconfig = %main::myconfig;
1170 my $locale = $main::locale;
1172 &get_project("generate_projects");
1173 $form->{projectnumber} = $form->{projectnumber_1};
1175 $form->{nextsub} = "generate_projects";
1176 $form->{title} = $locale->text('Project Transactions');
1177 RP->trial_balance(\%myconfig, \%$form);
1179 list_accounts('generate_projects');
1181 $main::lxdebug->leave_sub();
1187 # included links to display transactions for period entered
1188 # added headers and subtotals
1190 sub generate_trial_balance {
1191 $main::lxdebug->enter_sub();
1193 $main::auth->assert('report');
1195 my $form = $main::form;
1196 my %myconfig = %main::myconfig;
1197 my $locale = $main::locale;
1199 if ($form->{reporttype} eq "custom") {
1201 #forgotten the year --> thisyear
1202 if ($form->{year} !~ m/^\d\d\d\d$/) {
1203 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1209 if ($form->{duetyp} eq "13") {
1210 $form->{fromdate} = "1.1.$form->{year}";
1211 $form->{todate} = "31.12.$form->{year}";
1215 if ($form->{duetyp} eq "A") {
1216 $form->{fromdate} = "1.1.$form->{year}";
1217 $form->{todate} = "31.3.$form->{year}";
1219 if ($form->{duetyp} eq "B") {
1220 $form->{fromdate} = "1.4.$form->{year}";
1221 $form->{todate} = "30.6.$form->{year}";
1223 if ($form->{duetyp} eq "C") {
1224 $form->{fromdate} = "1.7.$form->{year}";
1225 $form->{todate} = "30.9.$form->{year}";
1227 if ($form->{duetyp} eq "D") {
1228 $form->{fromdate} = "1.10.$form->{year}";
1229 $form->{todate} = "31.12.$form->{year}";
1234 $form->{duetyp} eq "1" && do {
1235 $form->{fromdate} = "1.1.$form->{year}";
1236 $form->{todate} = "31.1.$form->{year}";
1239 $form->{duetyp} eq "2" && do {
1240 $form->{fromdate} = "1.2.$form->{year}";
1242 #this works from 1901 to 2099, 1900 and 2100 fail.
1243 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1244 $form->{todate} = "$leap.2.$form->{year}";
1247 $form->{duetyp} eq "3" && do {
1248 $form->{fromdate} = "1.3.$form->{year}";
1249 $form->{todate} = "31.3.$form->{year}";
1252 $form->{duetyp} eq "4" && do {
1253 $form->{fromdate} = "1.4.$form->{year}";
1254 $form->{todate} = "30.4.$form->{year}";
1257 $form->{duetyp} eq "5" && do {
1258 $form->{fromdate} = "1.5.$form->{year}";
1259 $form->{todate} = "31.5.$form->{year}";
1262 $form->{duetyp} eq "6" && do {
1263 $form->{fromdate} = "1.6.$form->{year}";
1264 $form->{todate} = "30.6.$form->{year}";
1267 $form->{duetyp} eq "7" && do {
1268 $form->{fromdate} = "1.7.$form->{year}";
1269 $form->{todate} = "31.7.$form->{year}";
1272 $form->{duetyp} eq "8" && do {
1273 $form->{fromdate} = "1.8.$form->{year}";
1274 $form->{todate} = "31.8.$form->{year}";
1277 $form->{duetyp} eq "9" && do {
1278 $form->{fromdate} = "1.9.$form->{year}";
1279 $form->{todate} = "30.9.$form->{year}";
1282 $form->{duetyp} eq "10" && do {
1283 $form->{fromdate} = "1.10.$form->{year}";
1284 $form->{todate} = "31.10.$form->{year}";
1287 $form->{duetyp} eq "11" && do {
1288 $form->{fromdate} = "1.11.$form->{year}";
1289 $form->{todate} = "30.11.$form->{year}";
1292 $form->{duetyp} eq "12" && do {
1293 $form->{fromdate} = "1.12.$form->{year}";
1294 $form->{todate} = "31.12.$form->{year}";
1298 hotfix_reformat_date();
1302 # get for each account initial balance, debits and credits
1303 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
1306 $form->{rowcount} = scalar @{ $form->{TB} || [] };
1307 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1310 "accno", "description",
1311 "last_transaction", "soll_eb",
1314 "soll_kumuliert", "haben_kumuliert",
1315 "soll_saldo", "haben_saldo"
1319 my $attachment_basename = $locale->text('trial_balance');
1320 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1322 my @hidden_variables = qw(fromdate todate year cash);
1324 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1327 'accno' => { 'text' => $locale->text('Account'), },
1328 'description' => { 'text' => $locale->text('Description'), },
1329 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1330 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1331 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1332 'soll' => { 'text' => $locale->text('Debit'), },
1333 'haben' => { 'text' => $locale->text('Credit'), },
1334 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1335 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1336 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1337 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1342 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1344 map { $column_defs{$_}->{visible} = 1 } @columns;
1346 $report->set_columns(%column_defs);
1347 $report->set_column_order(@columns);
1349 $report->set_export_options('generate_trial_balance', @hidden_variables);
1354 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1356 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
1357 push (@options, $form->{print_date});
1359 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
1360 push (@options, $form->{company});
1363 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1365 $report->set_options('output_format' => 'HTML',
1366 'top_info_text' => join("\n", @options),
1367 'title' => $form->{title},
1368 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1369 'html_template' => 'rp/html_report_susa',
1370 'pdf_template' => 'rp/html_report_susa',
1372 $report->set_options_from_form();
1373 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1375 # add sort and escape callback, this one we use for the add sub
1376 $form->{callback} = $href .= "&sort=$form->{sort}";
1378 # escape callback for href
1379 my $callback = $form->escape($href);
1381 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1383 my %totals = map { $_ => 0 } @subtotal_columns;
1385 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1388 foreach my $accno (@{ $form->{TB} || [] }) {
1390 $accno->{soll} = $accno->{debit};
1391 $accno->{haben} = $accno->{credit};
1392 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1394 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
1395 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1399 foreach my $column (@columns) {
1401 'data' => $accno->{$column},
1402 'align' => $column_alignment{$column},
1406 $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}));
1408 my $row_set = [ $row ];
1411 $report->add_data($row_set);
1416 $report->add_separator();
1418 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1420 $report->generate_with_headers();
1422 $main::lxdebug->leave_sub();
1426 sub create_subtotal_row {
1427 $main::lxdebug->enter_sub();
1429 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1431 my $form = $main::form;
1432 my %myconfig = %main::myconfig;
1433 my $locale = $main::locale;
1435 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1437 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1439 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1441 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1443 $main::lxdebug->leave_sub();
1448 sub create_list_accounts_subtotal_row {
1449 $main::lxdebug->enter_sub();
1451 my ($subtotals, $columns, $fields, $class) = @_;
1453 my $form = $main::form;
1454 my %myconfig = %main::myconfig;
1455 my $locale = $main::locale;
1457 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1459 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1461 $main::lxdebug->leave_sub();
1467 $main::lxdebug->enter_sub();
1471 my $form = $main::form;
1472 my %myconfig = %main::myconfig;
1473 my $locale = $main::locale;
1476 if ($form->{department}) {
1477 my ($department) = split /--/, $form->{department};
1478 push @options, $locale->text('Department') . " : $department";
1480 if ($form->{projectnumber}) {
1481 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1484 # if there are any dates
1485 if ($form->{fromdate} || $form->{todate}) {
1486 my ($fromdate, $todate);
1488 if ($form->{fromdate}) {
1489 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1491 if ($form->{todate}) {
1492 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1495 push @options, "$fromdate - $todate";
1498 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1501 my @columns = qw(accno description begbalance debit credit endbalance);
1503 'accno' => { 'text' => $locale->text('Account'), },
1504 'description' => { 'text' => $locale->text('Description'), },
1505 'debit' => { 'text' => $locale->text('Debit'), },
1506 'credit' => { 'text' => $locale->text('Credit'), },
1507 'begbalance' => { 'text' => $locale->text('Balance'), },
1508 'endbalance' => { 'text' => $locale->text('Balance'), },
1510 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1512 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1514 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1516 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1518 $report->set_options('top_info_text' => join("\n", @options),
1519 'output_format' => 'HTML',
1520 'title' => $form->{title},
1521 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1522 'std_column_visibility' => 1,
1524 $report->set_options_from_form();
1525 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1527 $report->set_columns(%column_defs);
1528 $report->set_column_order(@columns);
1530 $report->set_export_options($action, @hidden_variables);
1532 my @totals_columns = qw(credit debit begbalance endbalance);
1533 my %subtotals = map { $_ => 0 } @totals_columns;
1534 my %totals = map { $_ => 0 } @totals_columns;
1535 my $found_heading = 0;
1536 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
1538 # sort the whole thing by account numbers and display
1539 foreach my $idx (0 .. scalar(@tb) - 1) {
1540 my $ref = $tb[$idx];
1541 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1543 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1545 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1547 if ($ref->{charttype} eq 'H') {
1548 next unless ($form->{l_heading});
1550 %subtotals = map { $_ => 0 } @totals_columns;
1552 $row->{description}->{class} = 'listheading';
1553 $row->{description}->{data} = $ref->{description};
1555 $report->add_data($row);
1560 foreach (qw(debit credit)) {
1561 $subtotals{$_} += $ref->{$_};
1562 $totals{$_} += $ref->{$_};
1565 $subtotals{begbalance} += $ref->{balance} * $ml;
1566 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1568 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1569 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1571 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1572 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1574 $report->add_data($row);
1576 if ($form->{l_heading} && $found_heading &&
1577 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1578 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1582 $report->add_separator();
1584 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1586 $report->generate_with_headers();
1588 $main::lxdebug->leave_sub();
1591 sub generate_ar_aging {
1592 $main::lxdebug->enter_sub();
1594 $main::auth->assert('general_ledger');
1596 my $form = $main::form;
1597 my %myconfig = %main::myconfig;
1598 my $locale = $main::locale;
1601 ($form->{customer}) = split(/--/, $form->{customer});
1603 $form->{ct} = "customer";
1604 $form->{arap} = "ar";
1606 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1608 RP->aging(\%myconfig, \%$form);
1611 $main::lxdebug->leave_sub();
1614 sub generate_ap_aging {
1615 $main::lxdebug->enter_sub();
1617 $main::auth->assert('general_ledger');
1619 my $form = $main::form;
1620 my %myconfig = %main::myconfig;
1621 my $locale = $main::locale;
1624 ($form->{vendor}) = split(/--/, $form->{vendor});
1626 $form->{ct} = "vendor";
1627 $form->{arap} = "ap";
1629 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1631 RP->aging(\%myconfig, \%$form);
1634 $main::lxdebug->leave_sub();
1637 sub create_aging_subtotal_row {
1638 $main::lxdebug->enter_sub();
1640 my ($subtotals, $columns, $periods, $class) = @_;
1642 my $form = $main::form;
1643 my %myconfig = %main::myconfig;
1644 my $locale = $main::locale;
1646 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1648 foreach (@{ $periods }) {
1649 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1650 $subtotals->{$_} = 0;
1653 $main::lxdebug->leave_sub();
1659 $main::lxdebug->enter_sub();
1661 $main::auth->assert('general_ledger');
1663 my $form = $main::form;
1664 my %myconfig = %main::myconfig;
1665 my $locale = $main::locale;
1666 my $cgi = $main::cgi;
1668 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1670 my @columns = qw(statement ct invnumber transdate duedate amount open);
1673 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1674 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1675 'invnumber' => { 'text' => $locale->text('Invoice'), },
1676 'transdate' => { 'text' => $locale->text('Date'), },
1677 'duedate' => { 'text' => $locale->text('Due'), },
1678 'amount' => { 'text' => $locale->text('Amount'), },
1679 'open' => { 'text' => $locale->text('Open'), },
1682 my %column_alignment = ('statement' => 'center',
1683 map { $_ => 'right' } qw(open amount));
1685 $report->set_options('std_column_visibility' => 1);
1686 $report->set_columns(%column_defs);
1687 $report->set_column_order(@columns);
1689 my @hidden_variables = qw(todate customer vendor arap title ct);
1690 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1693 my $attachment_basename;
1695 if ($form->{department}) {
1696 my ($department) = split /--/, $form->{department};
1697 push @options, $locale->text('Department') . " : $department";
1698 $form->{callback} .= "&department=" . E($department);
1701 if (($form->{arap} eq 'ar') && $form->{customer}) {
1702 push @options, $form->{customer};
1703 $attachment_basename = $locale->text('ar_aging_list');
1704 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1707 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1708 push @options, $form->{vendor};
1709 $attachment_basename = $locale->text('ap_aging_list');
1710 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1713 if ($form->{fromdate}) {
1714 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1716 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1719 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1721 $report->set_options('top_info_text' => join("\n", @options),
1722 'output_format' => 'HTML',
1723 'title' => $form->{title},
1724 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1726 $report->set_options_from_form();
1727 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1729 my $previous_ctid = 0;
1731 my @periods = qw(open amount);
1732 my %subtotals = map { $_ => 0 } @periods;
1733 my %totals = map { $_ => 0 } @periods;
1735 foreach my $ref (@{ $form->{AG} }) {
1736 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1737 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1740 foreach my $key (@periods) {
1741 $subtotals{$key} += $ref->{"$key"};
1742 $totals{$key} += $ref->{"$key"};
1743 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1748 foreach my $column (@columns) {
1750 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1751 'align' => $column_alignment{$column},
1752 'valign' => $column eq 'statement' ? 'center' : '',
1756 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1758 if ($previous_ctid != $ref->{ctid}) {
1759 $row->{statement}->{raw_data} =
1760 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1761 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1762 $row->{ct}->{data} = $ref->{name};
1767 $previous_ctid = $ref->{ctid};
1769 $report->add_data($row);
1772 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1774 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1776 if ($form->{arap} eq 'ar') {
1777 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1778 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1779 'PRINT_OPTIONS' => print_options(inline => 1), });
1780 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1781 'raw_bottom_info_text' => $raw_bottom_info_text);
1784 $report->generate_with_headers();
1786 $main::lxdebug->leave_sub();
1790 $main::lxdebug->enter_sub();
1792 my $form = $main::form;
1793 my %myconfig = %main::myconfig;
1794 my $locale = $main::locale;
1796 RP->aging(\%myconfig, \%$form);
1798 map { $_->{checked} = "checked" } @{ $form->{AG} };
1802 $main::lxdebug->leave_sub();
1806 $main::lxdebug->enter_sub();
1808 $main::auth->assert('general_ledger');
1810 my $form = $main::form;
1811 my %myconfig = %main::myconfig;
1812 my $locale = $main::locale;
1814 # get name and email addresses
1816 for my $i (1 .. $form->{rowcount}) {
1817 if ($form->{"statement_$i"}) {
1818 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1819 RP->get_customer(\%myconfig, \%$form);
1825 $form->error($locale->text('Nothing selected!')) unless $selected;
1828 if ($myconfig{role} eq 'admin') {
1830 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1831 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1835 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1837 $form->{media} = "email";
1844 <form method=post action=$form->{script}>
1850 <tr height="5"></tr>
1855 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1856 <td><input name=email size=30 value="$form->{email}"></td>
1857 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1858 <td><input name=cc size=30 value="$form->{cc}"></td>
1861 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1862 <td><input name=subject size=30 value="$form->{subject}"></td>
1872 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1875 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1886 map { delete $form->{$_} }
1887 qw(action email cc bcc subject message type sendmode format header);
1889 # save all other variables
1890 foreach my $key (keys %$form) {
1891 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1892 $form->{$key} =~ s/\"/"/g;
1893 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1900 <td><hr size=3 noshade></td>
1904 <input type=hidden name=nextsub value=send_email>
1907 <input name=action class=submit type=submit value="|
1908 . $locale->text('Continue') . qq|">
1915 $main::lxdebug->leave_sub();
1919 $main::lxdebug->enter_sub();
1921 $main::auth->assert('general_ledger');
1923 my $form = $main::form;
1924 my %myconfig = %main::myconfig;
1925 my $locale = $main::locale;
1927 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1928 unless $form->{subject};
1930 RP->aging(\%myconfig, \%$form);
1932 $form->{"statement_1"} = 1;
1934 $form->{media} = 'email';
1937 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1939 $main::lxdebug->leave_sub();
1943 $main::lxdebug->enter_sub();
1945 $main::auth->assert('general_ledger');
1947 my $form = $main::form;
1948 my %myconfig = %main::myconfig;
1949 my $locale = $main::locale;
1951 if ($form->{media} eq 'printer') {
1952 $form->error($locale->text('Select postscript or PDF!'))
1953 if ($form->{format} !~ /(postscript|pdf)/);
1957 for my $i (1 .. $form->{rowcount}) {
1958 if ($form->{"statement_$i"}) {
1959 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1965 $form->error($locale->text('Nothing selected!')) unless $selected;
1967 if ($form->{media} eq 'printer') {
1968 $form->{"$form->{ct}_id"} = "";
1970 $form->{"statement_1"} = 1;
1973 RP->aging(\%myconfig, \%$form);
1977 $form->redirect($locale->text('Statements sent to printer!'))
1978 if ($form->{media} eq 'printer');
1980 $main::lxdebug->leave_sub();
1984 $main::lxdebug->enter_sub();
1986 $main::auth->assert('general_ledger');
1988 my $form = $main::form;
1989 my %myconfig = %main::myconfig;
1990 my $locale = $main::locale;
1992 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1994 $form->{templates} = "$myconfig{templates}";
1996 my $suffix = "html";
1997 my $attachment_suffix = "html";
1998 if ($form->{format} eq 'postscript') {
1999 $form->{postscript} = 1;
2001 $attachment_suffix = "ps";
2002 } elsif ($form->{format} eq 'pdf') {
2005 $attachment_suffix = "pdf";
2008 $form->{IN} = "$form->{type}.$suffix";
2009 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
2011 # Save $form->{email} because it will be overwritten.
2012 $form->{EMAIL_RECIPIENT} = $form->{email};
2016 while (@{ $form->{AG} }) {
2018 my $ref = shift @{ $form->{AG} };
2020 if ($ctid != $ref->{ctid}) {
2022 $ctid = $ref->{ctid};
2025 if ($form->{"statement_$i"}) {
2028 ("name", "street", "zipcode", "city", "country", "contact", "email",
2029 "$form->{ct}phone", "$form->{ct}fax");
2030 map { $form->{$_} = $ref->{$_} } @a;
2032 $form->{ $form->{ct} } = $form->{name};
2033 $form->{"$form->{ct}_id"} = $ref->{ctid};
2035 map { $form->{$_} = () } qw(invnumber invdate duedate);
2037 foreach my $item (qw(c0 c30 c60 c90)) {
2038 $form->{$item} = ();
2039 $form->{"${item}total"} = 0;
2042 &statement_details($ref);
2046 if (scalar(@{ $form->{AG} }) > 0) {
2048 # one or more left to go
2049 if ($ctid == $form->{AG}->[0]->{ctid}) {
2050 $ref = shift @{ $form->{AG} };
2051 &statement_details($ref);
2054 $ref = scalar(@{ $form->{AG} });
2060 # set initial ref to 0
2067 $form->{"${_}total"} =
2068 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2069 } ('c0', 'c30', 'c60', 'c90', "");
2071 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2072 $form->{attachment_filename} =~ s/\s+/_/g;
2074 $form->parse_template(\%myconfig, $main::userspath);
2079 # saving the history
2080 if(!exists $form->{addition} && $form->{id} ne "") {
2081 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2082 $form->{addition} = "PRINTED";
2083 $form->{what_done} = $form->{type};
2084 $form->save_history;
2086 # /saving the history
2087 $main::lxdebug->leave_sub();
2090 sub statement_details {
2091 $main::lxdebug->enter_sub();
2093 $main::auth->assert('general_ledger');
2095 my $form = $main::form;
2096 my %myconfig = %main::myconfig;
2097 my $locale = $main::locale;
2101 push @{ $form->{invnumber} }, $ref->{invnumber};
2102 push @{ $form->{invdate} }, $ref->{transdate};
2103 push @{ $form->{duedate} }, $ref->{duedate};
2105 foreach my $item (qw(c0 c30 c60 c90)) {
2106 if ($ref->{exchangerate} * 1) {
2108 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2110 $form->{"${item}total"} += $ref->{$item};
2111 $form->{total} += $ref->{$item};
2112 push @{ $form->{$item} },
2113 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2116 $main::lxdebug->leave_sub();
2119 sub generate_tax_report {
2120 $main::lxdebug->enter_sub();
2122 $main::auth->assert('report');
2124 my $form = $main::form;
2125 my %myconfig = %main::myconfig;
2126 my $locale = $main::locale;
2128 RP->tax_report(\%myconfig, \%$form);
2130 my $descvar = "$form->{accno}_description";
2131 my $description = $form->escape($form->{$descvar});
2132 my $ratevar = "$form->{accno}_rate";
2133 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
2135 my $department = $form->escape($form->{department});
2139 "$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}";
2141 # construct callback
2142 $description = $form->escape($form->{$descvar}, 1);
2143 $department = $form->escape($form->{department}, 1);
2145 "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}";
2147 my $title = $form->escape($form->{title});
2148 $href .= "&title=$title";
2149 $title = $form->escape($form->{title}, 1);
2150 $callback .= "&title=$title";
2152 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2155 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2158 foreach my $item (@columns) {
2159 if ($form->{"l_$item"} eq "Y") {
2160 push @column_index, $item;
2162 # add column to href and callback
2163 $callback .= "&l_$item=Y";
2164 $href .= "&l_$item=Y";
2168 if ($form->{l_subtotal} eq 'Y') {
2169 $callback .= "&l_subtotal=Y";
2170 $href .= "&l_subtotal=Y";
2174 if ($form->{department}) {
2175 ($department) = split /--/, $form->{department};
2176 $option = $locale->text('Department') . " : $department";
2179 my ($fromdate, $todate);
2180 # if there are any dates
2181 if ($form->{fromdate} || $form->{todate}) {
2182 if ($form->{fromdate}) {
2183 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2185 if ($form->{todate}) {
2186 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2189 $form->{period} = "$fromdate - $todate";
2192 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2195 my ($name, $invoice, $arap);
2196 if ($form->{db} eq 'ar') {
2197 $name = $locale->text('Customer');
2201 if ($form->{db} eq 'ap') {
2202 $name = $locale->text('Vendor');
2207 $option .= "<br>" if $option;
2208 $option .= "$form->{period}";
2211 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2212 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2213 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2214 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2215 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2216 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2218 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2227 <th class=listtop>$form->{title}</th>
2229 <tr height="5"></tr>
2236 <tr class=listheading>
2239 map { print "$column_header{$_}\n" } @column_index;
2245 # add sort and escape callback
2246 $callback = $form->escape($callback . "&sort=$form->{sort}");
2249 if (@{ $form->{TR} }) {
2250 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2253 my ($totalnetamount, $totaltax);
2255 foreach my $ref (@{ $form->{TR} }) {
2257 my $module = ($ref->{invoice}) ? $invoice : $arap;
2259 if ($form->{l_subtotal} eq 'Y') {
2260 if ($sameitem ne $ref->{ $form->{sort} }) {
2261 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2262 $sameitem = $ref->{ $form->{sort} };
2266 $totalnetamount += $ref->{netamount};
2267 $totaltax += $ref->{tax};
2268 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2270 $subtotalnetamount += $ref->{netamount};
2271 $subtotaltax += $ref->{tax};
2274 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2275 } qw(netamount tax amount);
2278 $column_data{id} = qq|<td>$ref->{id}</td>|;
2279 $column_data{invnumber} =
2280 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2281 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2282 $column_data{name} = qq|<td>$ref->{name} </td>|;
2284 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2285 qw(netamount tax amount);
2290 <tr class=listrow$i>
2293 map { print "$column_data{$_}\n" } @column_index;
2301 if ($form->{l_subtotal} eq 'Y') {
2302 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2306 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2310 <tr class=listtotal>
2313 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2314 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2315 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2317 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
2318 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2319 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2321 map { print "$column_data{$_}\n" } @column_index;
2329 <td><hr size=3 noshade></td>
2337 $main::lxdebug->leave_sub();
2341 $main::lxdebug->enter_sub();
2343 my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
2345 my $form = $main::form;
2346 my %myconfig = %main::myconfig;
2347 my $locale = $main::locale;
2350 map { $column_data{$_} = "<td> </td>" } @{ $column_index };
2352 $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " ");
2353 $$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " ");
2354 $$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " ");
2356 $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
2357 $column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>";
2358 $column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>";
2360 $$subtotalnetamount = 0;
2364 <tr class=listsubtotal>
2366 map { print "\n$column_data{$_}" } @{ $column_index };
2372 $main::lxdebug->leave_sub();
2376 $main::lxdebug->enter_sub();
2378 $main::auth->assert('cash');
2380 my $form = $main::form;
2381 my %myconfig = %main::myconfig;
2382 my $locale = $main::locale;
2384 if ($form->{account}) {
2385 ($form->{paymentaccounts}) = split /--/, $form->{account};
2389 if ($form->{department}) {
2390 (my $department, $form->{department_id}) = split /--/, $form->{department};
2391 $option = $locale->text('Department') . " : $department";
2394 report_generator_set_default_sort('transdate', 1);
2396 RP->payments(\%myconfig, \%$form);
2398 my @hidden_variables = qw(account title department reference source memo fromdate todate
2399 fx_transaction db prepayment paymentaccounts sort);
2401 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2402 $form->{callback} = $href;
2404 my @columns = qw(transdate invnumber name paid source memo);
2406 'name' => { 'text' => $locale->text('Description'), },
2407 'invnumber' => { 'text' => $locale->text('Reference'), },
2408 'transdate' => { 'text' => $locale->text('Date'), },
2409 'paid' => { 'text' => $locale->text('Amount'), },
2410 'source' => { 'text' => $locale->text('Source'), },
2411 'memo' => { 'text' => $locale->text('Memo'), },
2413 my %column_alignment = ('paid' => 'right');
2415 foreach my $name (grep { $_ ne 'paid' } @columns) {
2416 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2417 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2421 if ($form->{fromdate}) {
2422 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2424 if ($form->{todate}) {
2425 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2428 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2430 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2432 $report->set_options('top_info_text' => join("\n", @options),
2433 'output_format' => 'HTML',
2434 'title' => $form->{title},
2435 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2436 'std_column_visibility' => 1,
2438 $report->set_options_from_form();
2440 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
2442 $report->set_columns(%column_defs);
2443 $report->set_column_order(@columns);
2445 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2447 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2451 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2452 next unless @{ $form->{ $ref->{id} } };
2454 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2456 my $subtotal_paid = 0;
2458 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2459 my $module = $payment->{module};
2460 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2461 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2463 $subtotal_paid += $payment->{paid};
2464 $total_paid += $payment->{paid};
2466 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2470 foreach my $column (@columns) {
2472 'data' => $payment->{$column},
2473 'align' => $column_alignment{$column},
2477 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2479 $report->add_data($row);
2482 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2484 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2486 'class' => 'listsubtotal',
2489 $report->add_data($row);
2492 $report->add_separator();
2494 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2496 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2498 'class' => 'listtotal',
2501 $report->add_data($row);
2503 $report->generate_with_headers();
2505 $main::lxdebug->leave_sub();
2509 $main::lxdebug->enter_sub();
2511 my ($dont_print) = @_;
2513 my $form = $main::form;
2514 my %myconfig = %main::myconfig;
2515 my $locale = $main::locale;
2517 $form->{sendmode} = "attachment";
2520 $form->{"format"} ? $form->{"format"} :
2521 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2525 $form->{"copies"} ? $form->{"copies"} :
2526 $myconfig{"copies"} ? $myconfig{"copies"} :
2529 $form->{PD}{ $form->{type} } = "selected";
2530 $form->{DF}{ $form->{format} } = "selected";
2531 $form->{OP}{ $form->{media} } = "selected";
2532 $form->{SM}{ $form->{sendmode} } = "selected";
2536 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
2538 if ($form->{media} eq 'email') {
2540 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
2541 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2544 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2545 if ($myconfig{printer} && $main::latex_templates) {
2547 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
2552 if ($main::latex_templates) {
2554 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2555 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2556 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2562 <td><select name=type>$type</select></td>
2563 <td><select name=format>$format</select></td>
2564 <td><select name=media>$media</select></td>
2567 if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
2569 <td>| . $locale->text('Copies') . qq|
2570 <input name=copies size=2 value=$form->{copies}></td>
2579 print $output unless $dont_print;
2581 $main::lxdebug->leave_sub();
2587 $main::lxdebug->enter_sub();
2589 $main::auth->assert('report');
2591 my $form = $main::form;
2592 my %myconfig = %main::myconfig;
2593 my $locale = $main::locale;
2595 $form->{padding} = " ";
2596 $form->{bold} = "<b>";
2597 $form->{endbold} = "</b>";
2598 $form->{br} = "<br>";
2600 if ($form->{reporttype} eq "custom") {
2602 #forgotten the year --> thisyear
2603 if ($form->{year} !~ m/^\d\d\d\d$/) {
2604 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2610 if ($form->{duetyp} eq "13") {
2611 $form->{fromdate} = "1.1.$form->{year}";
2612 $form->{todate} = "31.12.$form->{year}";
2613 $form->{comparefromdate} = "1.01.$form->{year}";
2614 $form->{comparetodate} = "31.12.$form->{year}";
2618 if ($form->{duetyp} eq "A") {
2619 $form->{fromdate} = "1.1.$form->{year}";
2620 $form->{todate} = "31.3.$form->{year}";
2621 $form->{comparefromdate} = "1.01.$form->{year}";
2622 $form->{comparetodate} = "31.03.$form->{year}";
2624 if ($form->{duetyp} eq "B") {
2625 $form->{fromdate} = "1.4.$form->{year}";
2626 $form->{todate} = "30.6.$form->{year}";
2627 $form->{comparefromdate} = "1.01.$form->{year}";
2628 $form->{comparetodate} = "30.06.$form->{year}";
2630 if ($form->{duetyp} eq "C") {
2631 $form->{fromdate} = "1.7.$form->{year}";
2632 $form->{todate} = "30.9.$form->{year}";
2633 $form->{comparefromdate} = "1.01.$form->{year}";
2634 $form->{comparetodate} = "30.09.$form->{year}";
2636 if ($form->{duetyp} eq "D") {
2637 $form->{fromdate} = "1.10.$form->{year}";
2638 $form->{todate} = "31.12.$form->{year}";
2639 $form->{comparefromdate} = "1.01.$form->{year}";
2640 $form->{comparetodate} = "31.12.$form->{year}";
2645 $form->{duetyp} eq "1" && do {
2646 $form->{fromdate} = "1.1.$form->{year}";
2647 $form->{todate} = "31.1.$form->{year}";
2648 $form->{comparefromdate} = "1.01.$form->{year}";
2649 $form->{comparetodate} = "31.01.$form->{year}";
2652 $form->{duetyp} eq "2" && do {
2653 $form->{fromdate} = "1.2.$form->{year}";
2655 #this works from 1901 to 2099, 1900 and 2100 fail.
2656 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2657 $form->{todate} = "$leap.2.$form->{year}";
2658 $form->{comparefromdate} = "1.01.$form->{year}";
2659 $form->{comparetodate} = "$leap.02.$form->{year}";
2662 $form->{duetyp} eq "3" && do {
2663 $form->{fromdate} = "1.3.$form->{year}";
2664 $form->{todate} = "31.3.$form->{year}";
2665 $form->{comparefromdate} = "1.01.$form->{year}";
2666 $form->{comparetodate} = "31.03.$form->{year}";
2669 $form->{duetyp} eq "4" && do {
2670 $form->{fromdate} = "1.4.$form->{year}";
2671 $form->{todate} = "30.4.$form->{year}";
2672 $form->{comparefromdate} = "1.01.$form->{year}";
2673 $form->{comparetodate} = "30.04.$form->{year}";
2676 $form->{duetyp} eq "5" && do {
2677 $form->{fromdate} = "1.5.$form->{year}";
2678 $form->{todate} = "31.5.$form->{year}";
2679 $form->{comparefromdate} = "1.01.$form->{year}";
2680 $form->{comparetodate} = "31.05.$form->{year}";
2683 $form->{duetyp} eq "6" && do {
2684 $form->{fromdate} = "1.6.$form->{year}";
2685 $form->{todate} = "30.6.$form->{year}";
2686 $form->{comparefromdate} = "1.01.$form->{year}";
2687 $form->{comparetodate} = "30.06.$form->{year}";
2690 $form->{duetyp} eq "7" && do {
2691 $form->{fromdate} = "1.7.$form->{year}";
2692 $form->{todate} = "31.7.$form->{year}";
2693 $form->{comparefromdate} = "1.01.$form->{year}";
2694 $form->{comparetodate} = "31.07.$form->{year}";
2697 $form->{duetyp} eq "8" && do {
2698 $form->{fromdate} = "1.8.$form->{year}";
2699 $form->{todate} = "31.8.$form->{year}";
2700 $form->{comparefromdate} = "1.01.$form->{year}";
2701 $form->{comparetodate} = "31.08.$form->{year}";
2704 $form->{duetyp} eq "9" && do {
2705 $form->{fromdate} = "1.9.$form->{year}";
2706 $form->{todate} = "30.9.$form->{year}";
2707 $form->{comparefromdate} = "1.01.$form->{year}";
2708 $form->{comparetodate} = "30.09.$form->{year}";
2711 $form->{duetyp} eq "10" && do {
2712 $form->{fromdate} = "1.10.$form->{year}";
2713 $form->{todate} = "31.10.$form->{year}";
2714 $form->{comparefromdate} = "1.01.$form->{year}";
2715 $form->{comparetodate} = "31.10.$form->{year}";
2718 $form->{duetyp} eq "11" && do {
2719 $form->{fromdate} = "1.11.$form->{year}";
2720 $form->{todate} = "30.11.$form->{year}";
2721 $form->{comparefromdate} = "1.01.$form->{year}";
2722 $form->{comparetodate} = "30.11.$form->{year}";
2725 $form->{duetyp} eq "12" && do {
2726 $form->{fromdate} = "1.12.$form->{year}";
2727 $form->{todate} = "31.12.$form->{year}";
2728 $form->{comparefromdate} = "1.01.$form->{year}";
2729 $form->{comparetodate} = "31.12.$form->{year}";
2733 hotfix_reformat_date();
2735 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2736 # ansonsten ist die prüfung in RP.pm
2737 # if (defined ($form->{fromdate|todate}=='..'))
2739 if ($form->{fromdate}){
2740 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2741 my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
2742 $datetime->set( month => 1,
2744 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
2746 if ($form->{todate}){
2747 $form->{comparetodate} = $form->{todate};
2751 RP->bwa(\%myconfig, \%$form);
2753 ($form->{department}) = split /--/, $form->{department};
2756 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2757 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2759 # if there are any dates construct a where
2760 if ($form->{fromdate} || $form->{todate}) {
2762 unless ($form->{todate}) {
2763 $form->{todate} = $form->current_date(\%myconfig);
2766 my %germandate = ("dateformat" => "dd.mm.yyyy");
2768 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2769 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2771 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2772 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2774 $form->{this_period} = "$shortfromdate\n$shorttodate";
2776 $locale->text('for Period')
2777 . qq|\n$longfromdate |
2778 . $locale->text('bis')
2782 # setup variables for the form
2783 my @a = qw(company address businessnumber);
2784 map { $form->{$_} = $myconfig{$_} } @a;
2785 $form->{templates} = $myconfig{templates};
2787 $form->{IN} = "bwa.html";
2789 $form->parse_template;
2791 $main::lxdebug->leave_sub();
2794 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
2795 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
2796 sub hotfix_reformat_date {
2798 $main::lxdebug->enter_sub();
2800 my $form = $main::form;
2801 my %myconfig = %main::myconfig;
2802 my $locale = $main::locale;
2804 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
2805 my $current_dateformat = $myconfig{dateformat};
2806 $myconfig{dateformat} = 'dd.mm.yyyy';
2807 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
2808 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
2809 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
2810 unless (!defined ($form->{comparefromdate}));
2811 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
2812 unless (!defined ($form->{comparetodate}));
2814 # Und wieder zurücksetzen
2815 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
2816 } # Ende Hotifx Bug 1388
2818 $main::lxdebug->leave_sub();