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}";
1069 RP->income_statement(\%myconfig, \%$form);
1071 ($form->{department}) = split /--/, $form->{department};
1074 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1075 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1077 # if there are any dates construct a where
1078 if ($form->{fromdate} || $form->{todate}) {
1080 unless ($form->{todate}) {
1081 $form->{todate} = $form->current_date(\%myconfig);
1084 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1085 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1087 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1088 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1090 $form->{this_period} = "$shortfromdate\n$shorttodate";
1092 $locale->text('for Period')
1093 . qq|\n$longfromdate |
1094 . $locale->text('Bis')
1098 if ($form->{comparefromdate} || $form->{comparetodate}) {
1099 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1100 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1102 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1103 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1105 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1107 "\n$longcomparefromdate "
1108 . $locale->text('Bis')
1109 . qq| $longcomparetodate|;
1112 # setup variables for the form
1113 my @a = qw(company address businessnumber);
1114 map { $form->{$_} = $myconfig{$_} } @a;
1116 $form->{templates} = $myconfig{templates};
1118 $form->{IN} = "income_statement.html";
1120 $form->parse_template;
1122 $main::lxdebug->leave_sub();
1125 sub generate_balance_sheet {
1126 $::lxdebug->enter_sub;
1127 $::auth->assert('report');
1129 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
1130 $::form->{padding} = " ";
1131 $::form->{bold} = "<b>";
1132 $::form->{endbold} = "</b>";
1133 $::form->{br} = "<br>";
1135 my $data = RP->balance_sheet(\%::myconfig, $::form);
1137 $::form->{asofdate} ||= $::form->current_date;
1138 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
1140 ($::form->{department}) = split /--/, $::form->{department};
1142 # define Current Earnings account
1143 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
1144 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
1146 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
1147 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
1149 # $::form->{IN} = "balance_sheet.html";
1151 # setup company variables for the form
1152 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
1154 $::form->{templates} = $::myconfig{templates};
1157 print $::form->parse_html_template('rp/balance_sheet', $data);
1159 $::lxdebug->leave_sub;
1162 sub generate_projects {
1163 $main::lxdebug->enter_sub();
1165 $main::auth->assert('report');
1167 my $form = $main::form;
1168 my %myconfig = %main::myconfig;
1169 my $locale = $main::locale;
1171 &get_project("generate_projects");
1172 $form->{projectnumber} = $form->{projectnumber_1};
1174 $form->{nextsub} = "generate_projects";
1175 $form->{title} = $locale->text('Project Transactions');
1176 RP->trial_balance(\%myconfig, \%$form);
1178 list_accounts('generate_projects');
1180 $main::lxdebug->leave_sub();
1186 # included links to display transactions for period entered
1187 # added headers and subtotals
1189 sub generate_trial_balance {
1190 $main::lxdebug->enter_sub();
1192 $main::auth->assert('report');
1194 my $form = $main::form;
1195 my %myconfig = %main::myconfig;
1196 my $locale = $main::locale;
1198 if ($form->{reporttype} eq "custom") {
1200 #forgotten the year --> thisyear
1201 if ($form->{year} !~ m/^\d\d\d\d$/) {
1202 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1208 if ($form->{duetyp} eq "13") {
1209 $form->{fromdate} = "1.1.$form->{year}";
1210 $form->{todate} = "31.12.$form->{year}";
1214 if ($form->{duetyp} eq "A") {
1215 $form->{fromdate} = "1.1.$form->{year}";
1216 $form->{todate} = "31.3.$form->{year}";
1218 if ($form->{duetyp} eq "B") {
1219 $form->{fromdate} = "1.4.$form->{year}";
1220 $form->{todate} = "30.6.$form->{year}";
1222 if ($form->{duetyp} eq "C") {
1223 $form->{fromdate} = "1.7.$form->{year}";
1224 $form->{todate} = "30.9.$form->{year}";
1226 if ($form->{duetyp} eq "D") {
1227 $form->{fromdate} = "1.10.$form->{year}";
1228 $form->{todate} = "31.12.$form->{year}";
1233 $form->{duetyp} eq "1" && do {
1234 $form->{fromdate} = "1.1.$form->{year}";
1235 $form->{todate} = "31.1.$form->{year}";
1238 $form->{duetyp} eq "2" && do {
1239 $form->{fromdate} = "1.2.$form->{year}";
1241 #this works from 1901 to 2099, 1900 and 2100 fail.
1242 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1243 $form->{todate} = "$leap.2.$form->{year}";
1246 $form->{duetyp} eq "3" && do {
1247 $form->{fromdate} = "1.3.$form->{year}";
1248 $form->{todate} = "31.3.$form->{year}";
1251 $form->{duetyp} eq "4" && do {
1252 $form->{fromdate} = "1.4.$form->{year}";
1253 $form->{todate} = "30.4.$form->{year}";
1256 $form->{duetyp} eq "5" && do {
1257 $form->{fromdate} = "1.5.$form->{year}";
1258 $form->{todate} = "31.5.$form->{year}";
1261 $form->{duetyp} eq "6" && do {
1262 $form->{fromdate} = "1.6.$form->{year}";
1263 $form->{todate} = "30.6.$form->{year}";
1266 $form->{duetyp} eq "7" && do {
1267 $form->{fromdate} = "1.7.$form->{year}";
1268 $form->{todate} = "31.7.$form->{year}";
1271 $form->{duetyp} eq "8" && do {
1272 $form->{fromdate} = "1.8.$form->{year}";
1273 $form->{todate} = "31.8.$form->{year}";
1276 $form->{duetyp} eq "9" && do {
1277 $form->{fromdate} = "1.9.$form->{year}";
1278 $form->{todate} = "30.9.$form->{year}";
1281 $form->{duetyp} eq "10" && do {
1282 $form->{fromdate} = "1.10.$form->{year}";
1283 $form->{todate} = "31.10.$form->{year}";
1286 $form->{duetyp} eq "11" && do {
1287 $form->{fromdate} = "1.11.$form->{year}";
1288 $form->{todate} = "30.11.$form->{year}";
1291 $form->{duetyp} eq "12" && do {
1292 $form->{fromdate} = "1.12.$form->{year}";
1293 $form->{todate} = "31.12.$form->{year}";
1300 # get for each account initial balance, debits and credits
1301 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
1304 $form->{rowcount} = scalar @{ $form->{TB} || [] };
1305 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1308 "accno", "description",
1309 "last_transaction", "soll_eb",
1312 "soll_kumuliert", "haben_kumuliert",
1313 "soll_saldo", "haben_saldo"
1317 my $attachment_basename = $locale->text('trial_balance');
1318 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1320 my @hidden_variables = qw(fromdate todate year cash);
1322 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1325 'accno' => { 'text' => $locale->text('Account'), },
1326 'description' => { 'text' => $locale->text('Description'), },
1327 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1328 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1329 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1330 'soll' => { 'text' => $locale->text('Debit'), },
1331 'haben' => { 'text' => $locale->text('Credit'), },
1332 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1333 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1334 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1335 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1340 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1342 map { $column_defs{$_}->{visible} = 1 } @columns;
1344 $report->set_columns(%column_defs);
1345 $report->set_column_order(@columns);
1347 $report->set_export_options('generate_trial_balance', @hidden_variables);
1352 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1354 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
1355 push (@options, $form->{print_date});
1357 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
1358 push (@options, $form->{company});
1361 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1363 $report->set_options('output_format' => 'HTML',
1364 'top_info_text' => join("\n", @options),
1365 'title' => $form->{title},
1366 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1367 'html_template' => 'rp/html_report_susa',
1368 'pdf_template' => 'rp/html_report_susa',
1370 $report->set_options_from_form();
1372 # add sort and escape callback, this one we use for the add sub
1373 $form->{callback} = $href .= "&sort=$form->{sort}";
1375 # escape callback for href
1376 my $callback = $form->escape($href);
1378 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1380 my %totals = map { $_ => 0 } @subtotal_columns;
1382 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1385 foreach my $accno (@{ $form->{TB} }) {
1387 $accno->{soll} = $accno->{debit};
1388 $accno->{haben} = $accno->{credit};
1389 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1391 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
1392 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1396 foreach my $column (@columns) {
1398 'data' => $accno->{$column},
1399 'align' => $column_alignment{$column},
1403 $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}));
1405 my $row_set = [ $row ];
1408 $report->add_data($row_set);
1413 $report->add_separator();
1415 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1417 $report->generate_with_headers();
1419 $main::lxdebug->leave_sub();
1423 sub create_subtotal_row {
1424 $main::lxdebug->enter_sub();
1426 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1428 my $form = $main::form;
1429 my %myconfig = %main::myconfig;
1430 my $locale = $main::locale;
1432 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1434 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1436 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1438 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1440 $main::lxdebug->leave_sub();
1445 sub create_list_accounts_subtotal_row {
1446 $main::lxdebug->enter_sub();
1448 my ($subtotals, $columns, $fields, $class) = @_;
1450 my $form = $main::form;
1451 my %myconfig = %main::myconfig;
1452 my $locale = $main::locale;
1454 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1456 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1458 $main::lxdebug->leave_sub();
1464 $main::lxdebug->enter_sub();
1468 my $form = $main::form;
1469 my %myconfig = %main::myconfig;
1470 my $locale = $main::locale;
1473 if ($form->{department}) {
1474 my ($department) = split /--/, $form->{department};
1475 push @options, $locale->text('Department') . " : $department";
1477 if ($form->{projectnumber}) {
1478 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1481 # if there are any dates
1482 if ($form->{fromdate} || $form->{todate}) {
1483 my ($fromdate, $todate);
1485 if ($form->{fromdate}) {
1486 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1488 if ($form->{todate}) {
1489 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1492 push @options, "$fromdate - $todate";
1495 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1498 my @columns = qw(accno description begbalance debit credit endbalance);
1500 'accno' => { 'text' => $locale->text('Account'), },
1501 'description' => { 'text' => $locale->text('Description'), },
1502 'debit' => { 'text' => $locale->text('Debit'), },
1503 'credit' => { 'text' => $locale->text('Credit'), },
1504 'begbalance' => { 'text' => $locale->text('Balance'), },
1505 'endbalance' => { 'text' => $locale->text('Balance'), },
1507 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1509 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1511 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1513 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1515 $report->set_options('top_info_text' => join("\n", @options),
1516 'output_format' => 'HTML',
1517 'title' => $form->{title},
1518 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1519 'std_column_visibility' => 1,
1521 $report->set_options_from_form();
1523 $report->set_columns(%column_defs);
1524 $report->set_column_order(@columns);
1526 $report->set_export_options($action, @hidden_variables);
1528 my @totals_columns = qw(credit debit begbalance endbalance);
1529 my %subtotals = map { $_ => 0 } @totals_columns;
1530 my %totals = map { $_ => 0 } @totals_columns;
1531 my $found_heading = 0;
1532 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1534 # sort the whole thing by account numbers and display
1535 foreach my $idx (0 .. scalar(@tb) - 1) {
1536 my $ref = $tb[$idx];
1537 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1539 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1541 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1543 if ($ref->{charttype} eq 'H') {
1544 next unless ($form->{l_heading});
1546 %subtotals = map { $_ => 0 } @totals_columns;
1548 $row->{description}->{class} = 'listheading';
1549 $row->{description}->{data} = $ref->{description};
1551 $report->add_data($row);
1556 foreach (qw(debit credit)) {
1557 $subtotals{$_} += $ref->{$_};
1558 $totals{$_} += $ref->{$_};
1561 $subtotals{begbalance} += $ref->{balance} * $ml;
1562 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1564 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1565 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1567 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1568 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1570 $report->add_data($row);
1572 if ($form->{l_heading} && $found_heading &&
1573 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1574 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1578 $report->add_separator();
1580 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1582 $report->generate_with_headers();
1584 $main::lxdebug->leave_sub();
1587 sub generate_ar_aging {
1588 $main::lxdebug->enter_sub();
1590 $main::auth->assert('general_ledger');
1592 my $form = $main::form;
1593 my %myconfig = %main::myconfig;
1594 my $locale = $main::locale;
1597 ($form->{customer}) = split(/--/, $form->{customer});
1599 $form->{ct} = "customer";
1600 $form->{arap} = "ar";
1602 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1604 RP->aging(\%myconfig, \%$form);
1607 $main::lxdebug->leave_sub();
1610 sub generate_ap_aging {
1611 $main::lxdebug->enter_sub();
1613 $main::auth->assert('general_ledger');
1615 my $form = $main::form;
1616 my %myconfig = %main::myconfig;
1617 my $locale = $main::locale;
1620 ($form->{vendor}) = split(/--/, $form->{vendor});
1622 $form->{ct} = "vendor";
1623 $form->{arap} = "ap";
1625 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1627 RP->aging(\%myconfig, \%$form);
1630 $main::lxdebug->leave_sub();
1633 sub create_aging_subtotal_row {
1634 $main::lxdebug->enter_sub();
1636 my ($subtotals, $columns, $periods, $class) = @_;
1638 my $form = $main::form;
1639 my %myconfig = %main::myconfig;
1640 my $locale = $main::locale;
1642 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1644 foreach (@{ $periods }) {
1645 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1646 $subtotals->{$_} = 0;
1649 $main::lxdebug->leave_sub();
1655 $main::lxdebug->enter_sub();
1657 $main::auth->assert('general_ledger');
1659 my $form = $main::form;
1660 my %myconfig = %main::myconfig;
1661 my $locale = $main::locale;
1662 my $cgi = $main::cgi;
1664 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1666 my @columns = qw(statement ct invnumber transdate duedate amount open);
1669 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1670 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1671 'invnumber' => { 'text' => $locale->text('Invoice'), },
1672 'transdate' => { 'text' => $locale->text('Date'), },
1673 'duedate' => { 'text' => $locale->text('Due'), },
1674 'amount' => { 'text' => $locale->text('Amount'), },
1675 'open' => { 'text' => $locale->text('Open'), },
1678 my %column_alignment = ('statement' => 'center',
1679 map { $_ => 'right' } qw(open amount));
1681 $report->set_options('std_column_visibility' => 1);
1682 $report->set_columns(%column_defs);
1683 $report->set_column_order(@columns);
1685 my @hidden_variables = qw(todate customer vendor arap title ct);
1686 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1689 my $attachment_basename;
1691 if ($form->{department}) {
1692 my ($department) = split /--/, $form->{department};
1693 push @options, $locale->text('Department') . " : $department";
1694 $form->{callback} .= "&department=" . E($department);
1697 if (($form->{arap} eq 'ar') && $form->{customer}) {
1698 push @options, $form->{customer};
1699 $attachment_basename = $locale->text('ar_aging_list');
1700 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1703 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1704 push @options, $form->{vendor};
1705 $attachment_basename = $locale->text('ap_aging_list');
1706 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1709 if ($form->{fromdate}) {
1710 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1712 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1715 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1717 $report->set_options('top_info_text' => join("\n", @options),
1718 'output_format' => 'HTML',
1719 'title' => $form->{title},
1720 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1723 my $previous_ctid = 0;
1725 my @periods = qw(open amount);
1726 my %subtotals = map { $_ => 0 } @periods;
1727 my %totals = map { $_ => 0 } @periods;
1729 foreach my $ref (@{ $form->{AG} }) {
1730 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1731 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1734 foreach my $key (@periods) {
1735 $subtotals{$key} += $ref->{"$key"};
1736 $totals{$key} += $ref->{"$key"};
1737 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1742 foreach my $column (@columns) {
1744 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1745 'align' => $column_alignment{$column},
1746 'valign' => $column eq 'statement' ? 'center' : '',
1750 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1752 if ($previous_ctid != $ref->{ctid}) {
1753 $row->{statement}->{raw_data} =
1754 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1755 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1756 $row->{ct}->{data} = $ref->{name};
1761 $previous_ctid = $ref->{ctid};
1763 $report->add_data($row);
1766 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1768 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1770 if ($form->{arap} eq 'ar') {
1771 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1772 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1773 'PRINT_OPTIONS' => print_options(inline => 1), });
1774 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1775 'raw_bottom_info_text' => $raw_bottom_info_text);
1778 $report->set_options_from_form();
1780 $report->generate_with_headers();
1782 $main::lxdebug->leave_sub();
1786 $main::lxdebug->enter_sub();
1788 my $form = $main::form;
1789 my %myconfig = %main::myconfig;
1790 my $locale = $main::locale;
1792 RP->aging(\%myconfig, \%$form);
1794 map { $_->{checked} = "checked" } @{ $form->{AG} };
1798 $main::lxdebug->leave_sub();
1802 $main::lxdebug->enter_sub();
1804 $main::auth->assert('general_ledger');
1806 my $form = $main::form;
1807 my %myconfig = %main::myconfig;
1808 my $locale = $main::locale;
1810 # get name and email addresses
1812 for my $i (1 .. $form->{rowcount}) {
1813 if ($form->{"statement_$i"}) {
1814 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1815 RP->get_customer(\%myconfig, \%$form);
1821 $form->error($locale->text('Nothing selected!')) unless $selected;
1824 if ($myconfig{role} eq 'admin') {
1826 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1827 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1831 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1833 $form->{media} = "email";
1840 <form method=post action=$form->{script}>
1846 <tr height="5"></tr>
1851 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1852 <td><input name=email size=30 value="$form->{email}"></td>
1853 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1854 <td><input name=cc size=30 value="$form->{cc}"></td>
1857 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1858 <td><input name=subject size=30 value="$form->{subject}"></td>
1868 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1871 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1882 map { delete $form->{$_} }
1883 qw(action email cc bcc subject message type sendmode format header);
1885 # save all other variables
1886 foreach my $key (keys %$form) {
1887 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1888 $form->{$key} =~ s/\"/"/g;
1889 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1896 <td><hr size=3 noshade></td>
1900 <input type=hidden name=nextsub value=send_email>
1903 <input name=action class=submit type=submit value="|
1904 . $locale->text('Continue') . qq|">
1911 $main::lxdebug->leave_sub();
1915 $main::lxdebug->enter_sub();
1917 $main::auth->assert('general_ledger');
1919 my $form = $main::form;
1920 my %myconfig = %main::myconfig;
1921 my $locale = $main::locale;
1923 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1924 unless $form->{subject};
1926 RP->aging(\%myconfig, \%$form);
1928 $form->{"statement_1"} = 1;
1930 $form->{media} = 'email';
1933 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1935 $main::lxdebug->leave_sub();
1939 $main::lxdebug->enter_sub();
1941 $main::auth->assert('general_ledger');
1943 my $form = $main::form;
1944 my %myconfig = %main::myconfig;
1945 my $locale = $main::locale;
1947 if ($form->{media} eq 'printer') {
1948 $form->error($locale->text('Select postscript or PDF!'))
1949 if ($form->{format} !~ /(postscript|pdf)/);
1953 for my $i (1 .. $form->{rowcount}) {
1954 if ($form->{"statement_$i"}) {
1955 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1961 $form->error($locale->text('Nothing selected!')) unless $selected;
1963 if ($form->{media} eq 'printer') {
1964 $form->{"$form->{ct}_id"} = "";
1966 $form->{"statement_1"} = 1;
1969 RP->aging(\%myconfig, \%$form);
1973 $form->redirect($locale->text('Statements sent to printer!'))
1974 if ($form->{media} eq 'printer');
1976 $main::lxdebug->leave_sub();
1980 $main::lxdebug->enter_sub();
1982 $main::auth->assert('general_ledger');
1984 my $form = $main::form;
1985 my %myconfig = %main::myconfig;
1986 my $locale = $main::locale;
1988 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1990 $form->{templates} = "$myconfig{templates}";
1992 my $suffix = "html";
1993 my $attachment_suffix = "html";
1994 if ($form->{format} eq 'postscript') {
1995 $form->{postscript} = 1;
1997 $attachment_suffix = "ps";
1998 } elsif ($form->{format} eq 'pdf') {
2001 $attachment_suffix = "pdf";
2004 $form->{IN} = "$form->{type}.$suffix";
2005 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
2007 # Save $form->{email} because it will be overwritten.
2008 $form->{EMAIL_RECIPIENT} = $form->{email};
2012 while (@{ $form->{AG} }) {
2014 my $ref = shift @{ $form->{AG} };
2016 if ($ctid != $ref->{ctid}) {
2018 $ctid = $ref->{ctid};
2021 if ($form->{"statement_$i"}) {
2024 ("name", "street", "zipcode", "city", "country", "contact", "email",
2025 "$form->{ct}phone", "$form->{ct}fax");
2026 map { $form->{$_} = $ref->{$_} } @a;
2028 $form->{ $form->{ct} } = $form->{name};
2029 $form->{"$form->{ct}_id"} = $ref->{ctid};
2031 map { $form->{$_} = () } qw(invnumber invdate duedate);
2033 foreach my $item (qw(c0 c30 c60 c90)) {
2034 $form->{$item} = ();
2035 $form->{"${item}total"} = 0;
2038 &statement_details($ref);
2042 if (scalar(@{ $form->{AG} }) > 0) {
2044 # one or more left to go
2045 if ($ctid == $form->{AG}->[0]->{ctid}) {
2046 $ref = shift @{ $form->{AG} };
2047 &statement_details($ref);
2050 $ref = scalar(@{ $form->{AG} });
2056 # set initial ref to 0
2063 $form->{"${_}total"} =
2064 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2065 } ('c0', 'c30', 'c60', 'c90', "");
2067 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2068 $form->{attachment_filename} =~ s/\s+/_/g;
2070 $form->parse_template(\%myconfig, $main::userspath);
2075 # saving the history
2076 if(!exists $form->{addition} && $form->{id} ne "") {
2077 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2078 $form->{addition} = "PRINTED";
2079 $form->{what_done} = $form->{type};
2080 $form->save_history;
2082 # /saving the history
2083 $main::lxdebug->leave_sub();
2086 sub statement_details {
2087 $main::lxdebug->enter_sub();
2089 $main::auth->assert('general_ledger');
2091 my $form = $main::form;
2092 my %myconfig = %main::myconfig;
2093 my $locale = $main::locale;
2097 push @{ $form->{invnumber} }, $ref->{invnumber};
2098 push @{ $form->{invdate} }, $ref->{transdate};
2099 push @{ $form->{duedate} }, $ref->{duedate};
2101 foreach my $item (qw(c0 c30 c60 c90)) {
2102 if ($ref->{exchangerate} * 1) {
2104 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2106 $form->{"${item}total"} += $ref->{$item};
2107 $form->{total} += $ref->{$item};
2108 push @{ $form->{$item} },
2109 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2112 $main::lxdebug->leave_sub();
2115 sub generate_tax_report {
2116 $main::lxdebug->enter_sub();
2118 $main::auth->assert('report');
2120 my $form = $main::form;
2121 my %myconfig = %main::myconfig;
2122 my $locale = $main::locale;
2124 RP->tax_report(\%myconfig, \%$form);
2126 my $descvar = "$form->{accno}_description";
2127 my $description = $form->escape($form->{$descvar});
2128 my $ratevar = "$form->{accno}_rate";
2129 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
2131 my $department = $form->escape($form->{department});
2135 "$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}";
2137 # construct callback
2138 $description = $form->escape($form->{$descvar}, 1);
2139 $department = $form->escape($form->{department}, 1);
2141 "$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}";
2143 my $title = $form->escape($form->{title});
2144 $href .= "&title=$title";
2145 $title = $form->escape($form->{title}, 1);
2146 $callback .= "&title=$title";
2148 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2151 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2154 foreach my $item (@columns) {
2155 if ($form->{"l_$item"} eq "Y") {
2156 push @column_index, $item;
2158 # add column to href and callback
2159 $callback .= "&l_$item=Y";
2160 $href .= "&l_$item=Y";
2164 if ($form->{l_subtotal} eq 'Y') {
2165 $callback .= "&l_subtotal=Y";
2166 $href .= "&l_subtotal=Y";
2170 if ($form->{department}) {
2171 ($department) = split /--/, $form->{department};
2172 $option = $locale->text('Department') . " : $department";
2175 my ($fromdate, $todate);
2176 # if there are any dates
2177 if ($form->{fromdate} || $form->{todate}) {
2178 if ($form->{fromdate}) {
2179 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2181 if ($form->{todate}) {
2182 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2185 $form->{period} = "$fromdate - $todate";
2188 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2191 my ($name, $invoice, $arap);
2192 if ($form->{db} eq 'ar') {
2193 $name = $locale->text('Customer');
2197 if ($form->{db} eq 'ap') {
2198 $name = $locale->text('Vendor');
2203 $option .= "<br>" if $option;
2204 $option .= "$form->{period}";
2207 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2208 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2209 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2210 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2211 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2212 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2214 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2223 <th class=listtop>$form->{title}</th>
2225 <tr height="5"></tr>
2232 <tr class=listheading>
2235 map { print "$column_header{$_}\n" } @column_index;
2241 # add sort and escape callback
2242 $callback = $form->escape($callback . "&sort=$form->{sort}");
2245 if (@{ $form->{TR} }) {
2246 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2249 my ($totalnetamount, $totaltax);
2251 foreach my $ref (@{ $form->{TR} }) {
2253 my $module = ($ref->{invoice}) ? $invoice : $arap;
2255 if ($form->{l_subtotal} eq 'Y') {
2256 if ($sameitem ne $ref->{ $form->{sort} }) {
2257 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2258 $sameitem = $ref->{ $form->{sort} };
2262 $totalnetamount += $ref->{netamount};
2263 $totaltax += $ref->{tax};
2264 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2266 $subtotalnetamount += $ref->{netamount};
2267 $subtotaltax += $ref->{tax};
2270 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2271 } qw(netamount tax amount);
2274 $column_data{id} = qq|<td>$ref->{id}</td>|;
2275 $column_data{invnumber} =
2276 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2277 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2278 $column_data{name} = qq|<td>$ref->{name} </td>|;
2280 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2281 qw(netamount tax amount);
2286 <tr class=listrow$i>
2289 map { print "$column_data{$_}\n" } @column_index;
2297 if ($form->{l_subtotal} eq 'Y') {
2298 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2302 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2306 <tr class=listtotal>
2309 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2310 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2311 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2313 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
2314 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2315 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2317 map { print "$column_data{$_}\n" } @column_index;
2325 <td><hr size=3 noshade></td>
2333 $main::lxdebug->leave_sub();
2337 $main::lxdebug->enter_sub();
2339 my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
2341 my $form = $main::form;
2342 my %myconfig = %main::myconfig;
2343 my $locale = $main::locale;
2346 map { $column_data{$_} = "<td> </td>" } @{ $column_index };
2348 $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " ");
2349 $$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " ");
2350 $$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " ");
2352 $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
2353 $column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>";
2354 $column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>";
2356 $$subtotalnetamount = 0;
2360 <tr class=listsubtotal>
2362 map { print "\n$column_data{$_}" } @{ $column_index };
2368 $main::lxdebug->leave_sub();
2372 $main::lxdebug->enter_sub();
2374 $main::auth->assert('cash');
2376 my $form = $main::form;
2377 my %myconfig = %main::myconfig;
2378 my $locale = $main::locale;
2380 if ($form->{account}) {
2381 ($form->{paymentaccounts}) = split /--/, $form->{account};
2385 if ($form->{department}) {
2386 (my $department, $form->{department_id}) = split /--/, $form->{department};
2387 $option = $locale->text('Department') . " : $department";
2390 report_generator_set_default_sort('transdate', 1);
2392 RP->payments(\%myconfig, \%$form);
2394 my @hidden_variables = qw(account title department reference source memo fromdate todate
2395 fx_transaction db prepayment paymentaccounts sort);
2397 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2398 $form->{callback} = $href;
2400 my @columns = qw(transdate invnumber name paid source memo);
2402 'name' => { 'text' => $locale->text('Description'), },
2403 'invnumber' => { 'text' => $locale->text('Reference'), },
2404 'transdate' => { 'text' => $locale->text('Date'), },
2405 'paid' => { 'text' => $locale->text('Amount'), },
2406 'source' => { 'text' => $locale->text('Source'), },
2407 'memo' => { 'text' => $locale->text('Memo'), },
2409 my %column_alignment = ('paid' => 'right');
2411 foreach my $name (grep { $_ ne 'paid' } @columns) {
2412 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2413 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2417 if ($form->{fromdate}) {
2418 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2420 if ($form->{todate}) {
2421 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2424 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2426 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2428 $report->set_options('top_info_text' => join("\n", @options),
2429 'output_format' => 'HTML',
2430 'title' => $form->{title},
2431 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2432 'std_column_visibility' => 1,
2434 $report->set_options_from_form();
2436 $report->set_columns(%column_defs);
2437 $report->set_column_order(@columns);
2439 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2441 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2445 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2446 next unless @{ $form->{ $ref->{id} } };
2448 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2450 my $subtotal_paid = 0;
2452 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2453 my $module = $payment->{module};
2454 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2455 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2457 $subtotal_paid += $payment->{paid};
2458 $total_paid += $payment->{paid};
2460 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2464 foreach my $column (@columns) {
2466 'data' => $payment->{$column},
2467 'align' => $column_alignment{$column},
2471 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2473 $report->add_data($row);
2476 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2478 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2480 'class' => 'listsubtotal',
2483 $report->add_data($row);
2486 $report->add_separator();
2488 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2490 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2492 'class' => 'listtotal',
2495 $report->add_data($row);
2497 $report->generate_with_headers();
2499 $main::lxdebug->leave_sub();
2503 $main::lxdebug->enter_sub();
2505 my ($dont_print) = @_;
2507 my $form = $main::form;
2508 my %myconfig = %main::myconfig;
2509 my $locale = $main::locale;
2511 $form->{sendmode} = "attachment";
2514 $form->{"format"} ? $form->{"format"} :
2515 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2519 $form->{"copies"} ? $form->{"copies"} :
2520 $myconfig{"copies"} ? $myconfig{"copies"} :
2523 $form->{PD}{ $form->{type} } = "selected";
2524 $form->{DF}{ $form->{format} } = "selected";
2525 $form->{OP}{ $form->{media} } = "selected";
2526 $form->{SM}{ $form->{sendmode} } = "selected";
2530 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
2532 if ($form->{media} eq 'email') {
2534 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
2535 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2538 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2539 if ($myconfig{printer} && $main::latex_templates) {
2541 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
2546 if ($main::latex_templates) {
2548 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2549 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2550 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2556 <td><select name=type>$type</select></td>
2557 <td><select name=format>$format</select></td>
2558 <td><select name=media>$media</select></td>
2561 if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
2563 <td>| . $locale->text('Copies') . qq|
2564 <input name=copies size=2 value=$form->{copies}></td>
2573 print $output unless $dont_print;
2575 $main::lxdebug->leave_sub();
2581 $main::lxdebug->enter_sub();
2583 $main::auth->assert('report');
2585 my $form = $main::form;
2586 my %myconfig = %main::myconfig;
2587 my $locale = $main::locale;
2589 $form->{padding} = " ";
2590 $form->{bold} = "<b>";
2591 $form->{endbold} = "</b>";
2592 $form->{br} = "<br>";
2594 if ($form->{reporttype} eq "custom") {
2596 #forgotten the year --> thisyear
2597 if ($form->{year} !~ m/^\d\d\d\d$/) {
2598 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2604 if ($form->{duetyp} eq "13") {
2605 $form->{fromdate} = "1.1.$form->{year}";
2606 $form->{todate} = "31.12.$form->{year}";
2607 $form->{comparefromdate} = "1.01.$form->{year}";
2608 $form->{comparetodate} = "31.12.$form->{year}";
2612 if ($form->{duetyp} eq "A") {
2613 $form->{fromdate} = "1.1.$form->{year}";
2614 $form->{todate} = "31.3.$form->{year}";
2615 $form->{comparefromdate} = "1.01.$form->{year}";
2616 $form->{comparetodate} = "31.03.$form->{year}";
2618 if ($form->{duetyp} eq "B") {
2619 $form->{fromdate} = "1.4.$form->{year}";
2620 $form->{todate} = "30.6.$form->{year}";
2621 $form->{comparefromdate} = "1.01.$form->{year}";
2622 $form->{comparetodate} = "30.06.$form->{year}";
2624 if ($form->{duetyp} eq "C") {
2625 $form->{fromdate} = "1.7.$form->{year}";
2626 $form->{todate} = "30.9.$form->{year}";
2627 $form->{comparefromdate} = "1.01.$form->{year}";
2628 $form->{comparetodate} = "30.09.$form->{year}";
2630 if ($form->{duetyp} eq "D") {
2631 $form->{fromdate} = "1.10.$form->{year}";
2632 $form->{todate} = "31.12.$form->{year}";
2633 $form->{comparefromdate} = "1.01.$form->{year}";
2634 $form->{comparetodate} = "31.12.$form->{year}";
2639 $form->{duetyp} eq "1" && do {
2640 $form->{fromdate} = "1.1.$form->{year}";
2641 $form->{todate} = "31.1.$form->{year}";
2642 $form->{comparefromdate} = "1.01.$form->{year}";
2643 $form->{comparetodate} = "31.01.$form->{year}";
2646 $form->{duetyp} eq "2" && do {
2647 $form->{fromdate} = "1.2.$form->{year}";
2649 #this works from 1901 to 2099, 1900 and 2100 fail.
2650 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2651 $form->{todate} = "$leap.2.$form->{year}";
2652 $form->{comparefromdate} = "1.01.$form->{year}";
2653 $form->{comparetodate} = "$leap.02.$form->{year}";
2656 $form->{duetyp} eq "3" && do {
2657 $form->{fromdate} = "1.3.$form->{year}";
2658 $form->{todate} = "31.3.$form->{year}";
2659 $form->{comparefromdate} = "1.01.$form->{year}";
2660 $form->{comparetodate} = "31.03.$form->{year}";
2663 $form->{duetyp} eq "4" && do {
2664 $form->{fromdate} = "1.4.$form->{year}";
2665 $form->{todate} = "30.4.$form->{year}";
2666 $form->{comparefromdate} = "1.01.$form->{year}";
2667 $form->{comparetodate} = "30.04.$form->{year}";
2670 $form->{duetyp} eq "5" && do {
2671 $form->{fromdate} = "1.5.$form->{year}";
2672 $form->{todate} = "31.5.$form->{year}";
2673 $form->{comparefromdate} = "1.01.$form->{year}";
2674 $form->{comparetodate} = "31.05.$form->{year}";
2677 $form->{duetyp} eq "6" && do {
2678 $form->{fromdate} = "1.6.$form->{year}";
2679 $form->{todate} = "30.6.$form->{year}";
2680 $form->{comparefromdate} = "1.01.$form->{year}";
2681 $form->{comparetodate} = "30.06.$form->{year}";
2684 $form->{duetyp} eq "7" && do {
2685 $form->{fromdate} = "1.7.$form->{year}";
2686 $form->{todate} = "31.7.$form->{year}";
2687 $form->{comparefromdate} = "1.01.$form->{year}";
2688 $form->{comparetodate} = "31.07.$form->{year}";
2691 $form->{duetyp} eq "8" && do {
2692 $form->{fromdate} = "1.8.$form->{year}";
2693 $form->{todate} = "31.8.$form->{year}";
2694 $form->{comparefromdate} = "1.01.$form->{year}";
2695 $form->{comparetodate} = "31.08.$form->{year}";
2698 $form->{duetyp} eq "9" && do {
2699 $form->{fromdate} = "1.9.$form->{year}";
2700 $form->{todate} = "30.9.$form->{year}";
2701 $form->{comparefromdate} = "1.01.$form->{year}";
2702 $form->{comparetodate} = "30.09.$form->{year}";
2705 $form->{duetyp} eq "10" && do {
2706 $form->{fromdate} = "1.10.$form->{year}";
2707 $form->{todate} = "31.10.$form->{year}";
2708 $form->{comparefromdate} = "1.01.$form->{year}";
2709 $form->{comparetodate} = "31.10.$form->{year}";
2712 $form->{duetyp} eq "11" && do {
2713 $form->{fromdate} = "1.11.$form->{year}";
2714 $form->{todate} = "30.11.$form->{year}";
2715 $form->{comparefromdate} = "1.01.$form->{year}";
2716 $form->{comparetodate} = "30.11.$form->{year}";
2719 $form->{duetyp} eq "12" && do {
2720 $form->{fromdate} = "1.12.$form->{year}";
2721 $form->{todate} = "31.12.$form->{year}";
2722 $form->{comparefromdate} = "1.01.$form->{year}";
2723 $form->{comparetodate} = "31.12.$form->{year}";
2728 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2729 # ansonsten ist die prüfung in RP.pm
2730 # if (defined ($form->{fromdate|todate}=='..'))
2732 if ($form->{fromdate}){
2733 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2734 $form->{fromdate} = "${dd}.${mm}.${yy}";
2735 $form->{comparefromdate} = "01.01.$yy";
2737 if ($form->{todate}){
2738 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2739 $form->{todate} = "${dd}.${mm}.${yy}";
2740 $form->{comparetodate} = $form->{todate};
2744 RP->bwa(\%myconfig, \%$form);
2746 ($form->{department}) = split /--/, $form->{department};
2749 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2750 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2752 # if there are any dates construct a where
2753 if ($form->{fromdate} || $form->{todate}) {
2755 unless ($form->{todate}) {
2756 $form->{todate} = $form->current_date(\%myconfig);
2759 my %germandate = ("dateformat" => "dd.mm.yyyy");
2761 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2762 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2764 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2765 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2767 $form->{this_period} = "$shortfromdate\n$shorttodate";
2769 $locale->text('for Period')
2770 . qq|\n$longfromdate |
2771 . $locale->text('bis')
2775 # setup variables for the form
2776 my @a = qw(company address businessnumber);
2777 map { $form->{$_} = $myconfig{$_} } @a;
2778 $form->{templates} = $myconfig{templates};
2780 $form->{IN} = "bwa.html";
2782 $form->parse_template;
2784 $main::lxdebug->leave_sub();