1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
16 # Benjamin Lee <benjaminlee@consultant.com>
17 # Philip Reetz <p.reetz@linet-services.de>
20 # This program is free software; you can redistribute it and/or modify
21 # it under the terms of the GNU General Public License as published by
22 # the Free Software Foundation; either version 2 of the License, or
23 # (at your option) any later version.
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #======================================================================
34 # module for preparing Income Statement and Balance Sheet
36 #======================================================================
38 use POSIX qw(strftime);
43 use SL::ReportGenerator;
46 require "bin/mozilla/arap.pl";
47 require "bin/mozilla/common.pl";
48 require "bin/mozilla/reportgenerator.pl";
50 # note: this file was particularly hard to strictify.
51 # alot of the vars are passed carelessly between invocations
52 # should there be any missing vars, declare them globally
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
83 # $locale->text('Balance Sheet')
84 # $locale->text('Income Statement')
85 # $locale->text('Trial Balance')
86 # $locale->text('AR Aging')
87 # $locale->text('AP Aging')
88 # $locale->text('Tax collected')
89 # $locale->text('Tax paid')
90 # $locale->text('Receipts')
91 # $locale->text('Payments')
92 # $locale->text('Project Transactions')
93 # $locale->text('Non-taxable Sales')
94 # $locale->text('Non-taxable Purchases')
96 # $form->parse_html_template('rp/html_report_susa')
99 'projects' => 'report',
100 'ar_aging' => 'general_ledger',
101 'ap_aging' => 'general_ledger',
102 'receipts' => 'cash',
103 'payments' => 'cash',
104 'trial_balance' => 'report',
105 'income_statement' => 'report',
107 'balance_sheet' => 'report',
110 sub check_rp_access {
111 my $form = $main::form;
113 my $right = $rp_access_map->{$form->{report}};
114 $right ||= 'DOES_NOT_EXIST';
116 $main::auth->assert($right);
120 $main::lxdebug->enter_sub();
124 my $form = $main::form;
125 my %myconfig = %main::myconfig;
126 my $locale = $main::locale;
129 'balance_sheet' => 'Balance Sheet',
130 'income_statement' => 'Income Statement',
131 'trial_balance' => 'Trial Balance',
132 'ar_aging' => 'AR Aging',
133 'ap_aging' => 'Offene Verbindlichkeiten',
134 'tax_collected' => 'Tax collected',
135 'tax_paid' => 'Tax paid',
136 'nontaxable_sales' => 'Non-taxable Sales',
137 'nontaxable_purchases' => 'Non-taxable Purchases',
138 'receipts' => 'Receipts',
139 'payments' => 'Payments',
140 'projects' => 'Project Transactions',
141 'bwa' => 'Betriebswirtschaftliche Auswertung',
144 $form->{title} = $locale->text($title{ $form->{report} });
146 my $accrual = ($main::eur) ? "" : "checked";
147 my $cash = ($main::eur) ? "checked" : "";
149 my $year = (localtime)[5] + 1900;
152 $form->all_departments(\%myconfig);
153 if (@{ $form->{all_departments} || [] }) {
154 $form->{selectdepartment} = "<option>\n";
155 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} || [] };
160 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
161 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
163 | if $form->{selectdepartment};
165 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
168 my %project_labels = ();
169 my @project_values = ("");
170 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
171 push(@project_values, $item->{"id"});
172 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
176 NTI($main::cgi->popup_menu('-name' => "project_id",
177 '-values' => \@project_values,
178 '-labels' => \%project_labels));
180 # use JavaScript Calendar or not
181 $form->{jsscript} = 1;
183 my ( $name_1, $id_1, $value_1, $trigger_1, $name_2, $id_2, $value_2, $trigger_2, );
184 if ($form->{report} eq "balance_sheet") {
185 $name_1 = "asofdate";
187 $value_1 = "$form->{asofdate}";
188 $trigger_1 = "trigger1";
189 $name_2 = "compareasofdate";
190 $id_2 = "compareasofdate";
191 $value_2 = "$form->{compareasofdate}";
192 $trigger_2 = "trigger2";
193 } elsif ($form->{report} =~ /(receipts|payments)$/) {
194 $name_1 = "fromdate";
196 $value_1 = "$form->{fromdate}";
197 $trigger_1 = "trigger1";
201 $trigger_2 = "trigger2";
202 } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
203 $name_1 = "fromdate";
205 $value_1 = "$form->{fromdate}";
206 $trigger_1 = "trigger1";
210 $trigger_2 = "trigger2";
213 $name_1 = "fromdate";
215 $value_1 = "$form->{fromdate}";
216 $trigger_1 = "trigger1";
220 $trigger_2 = "trigger2";
223 my ($button1, $button1_2, $button2, $button2_2);
226 # with JavaScript Calendar
227 if ($form->{jsscript}) {
229 $button1 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
230 $button1_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|>|;
233 $jsscript = Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
235 $button1 = qq| <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
236 $button1_2 = qq| <input type=button name=$name_1 id="$trigger_1" value=| . $locale->text('button') . qq|>|;
237 $button2 = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
238 $button2_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|> |;
241 $jsscript = Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1", "$name_2", "BL", "$trigger_2");
245 # without JavaScript Calendar
247 $button1 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
249 $button1 = qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
250 $button2 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
253 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
255 my $onload = qq|focus()|;
256 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
257 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
259 <body onLoad="$onload">
261 <form method=post action=$form->{script}>
263 <input type=hidden name=title value="$form->{title}">
267 <th class=listtop>$form->{title}</th>
276 if ($form->{report} eq "projects") {
279 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
280 <td colspan=5><input name=projectnumber size=25</td>
282 <input type=hidden name=nextsub value=generate_projects>
284 <th align=right>| . $locale->text('From') . qq|</th>
287 <th align=right>| . $locale->text('Bis') . qq|</th>
298 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
299 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
300 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
307 if ($form->{report} eq "income_statement") {
310 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
311 <td colspan=3>$projectnumber</td>
313 <input type=hidden name=nextsub value=generate_income_statement>
317 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
320 <th colspan=1>| . $locale->text('Year') . qq|</th>
321 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
327 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
328 <th align=left>| . $locale->text('Quarterly') . qq|</th>
329 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
332 <td align=right> <input name=duetyp class=radio type=radio value="13" "checked"></td>
333 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
337 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
341 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
342 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
346 <td align= right> </td>
347 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
348 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
349 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
350 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
354 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
355 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
356 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
357 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
362 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
363 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
364 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
365 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
369 <td colspan=5><hr size=3 noshade></td>
372 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
373 <td align=left colspan=4>| . $locale->text('From') . qq|
376 | . $locale->text('Bis') . qq|
382 <td colspan=5><hr size=3 noshade></td>
385 <th align=leftt>| . $locale->text('Method') . qq|</th>
386 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
387 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
394 if ($form->{report} eq "bwa") {
397 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
398 <td colspan=3>$projectnumber</td>
400 <input type=hidden name=nextsub value=generate_bwa>
404 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
407 <th colspan=1>| . $locale->text('Year') . qq|</th>
408 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
414 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
415 <th align=left>| . $locale->text('Quarterly') . qq|</th>
416 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
419 <td align=right> <input name=duetyp class=radio type=radio value="13"
421 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
423 $checked = "checked";
425 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
429 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
430 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
434 <td align= right> </td>
435 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
436 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
437 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
438 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
442 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
443 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
444 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
445 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
450 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
451 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
452 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
453 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
457 <td colspan=5><hr size=3 noshade></td>
460 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
461 <td align=left colspan=4>| . $locale->text('From') . qq|
464 | . $locale->text('Bis') . qq|
470 <td colspan=5><hr size=3 noshade></td>
473 <th align=leftt>| . $locale->text('Method') . qq|</th>
474 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
475 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
478 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
479 <td><input name=decimalplaces size=3 value="2"></td>
486 if ($form->{report} eq "balance_sheet") {
488 <input type=hidden name=nextsub value=generate_balance_sheet>
490 <th align=right>| . $locale->text('as at') . qq|</th>
495 <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
502 <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
503 <td><input name=decimalplaces size=3 value="2"></td>
512 <th align=right>| . $locale->text('Method') . qq|</th>
513 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
514 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
518 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
519 <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
520 <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|
521 <input name=l_accno class=checkbox type=checkbox value=Y> | . $locale->text('Account Number') . qq|</td>
528 if ($form->{report} eq "trial_balance") {
531 <th align=right nowrap>| . $locale->text('Project') . qq|</th>
532 <td colspan=3>$projectnumber</td>
534 <input type=hidden name=nextsub value=generate_trial_balance>
538 <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
541 <th colspan=1>| . $locale->text('Year') . qq|</th>
542 <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
548 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
549 <th align=left>| . $locale->text('Quarterly') . qq|</th>
550 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
553 <td align=right> <input name=duetyp class=radio type=radio value="13" $checked></td>
554 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
556 $checked = "checked";
558 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
562 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
563 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
567 <td align= right> </td>
568 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
569 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
570 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
571 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
575 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
576 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
577 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
578 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
583 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
584 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
585 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
586 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
590 <td colspan=5><hr size=3 noshade></td>
593 <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
594 <td align=left colspan=4>| . $locale->text('From') . qq|
597 | . $locale->text('Bis') . qq|
603 <td colspan=5><hr size=3 noshade></td>
606 <th align=leftt>| . $locale->text('Method') . qq|</th>
607 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
608 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
611 <th align=right colspan=4>| . $locale->text('All Accounts') . qq|</th>
612 <td><input name=all_accounts type=checkbox value=1></td>
615 <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
616 <td><input name=decimalplaces size=3 value="2"></td>
623 if ($form->{report} =~ /^tax_/) {
624 $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
626 RP->get_taxaccounts(\%myconfig, \%$form);
629 <input type=hidden name=nextsub value=generate_tax_report>
631 <th align=right>| . $locale->text('From') . qq|</th>
632 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
633 <th align=right>| . $locale->text('Bis') . qq|</th>
634 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
637 <th align=right>| . $locale->text('Report for') . qq|</th>
641 $checked = "checked";
642 foreach my $ref (@{ $form->{taxaccounts} }) {
645 qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
647 <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
648 <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
655 <input type=hidden name=db value=$form->{db}>
656 <input type=hidden name=sort value=transdate>
661 <th align=right>| . $locale->text('Method') . qq|</th>
662 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
663 <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
672 <th align=right>| . $locale->text('Include in Report') . qq|</th>
676 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
677 <td>| . $locale->text('ID') . qq|</td>
678 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
679 <td>| . $locale->text('Invoice') . qq|</td>
680 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
681 <td>| . $locale->text('Date') . qq|</td>
684 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
687 if ($form->{db} eq 'ar') {
688 print $locale->text('Customer');
690 if ($form->{db} eq 'ap') {
691 print $locale->text('Vendor');
695 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
696 <td>| . $locale->text('Amount') . qq|</td>
697 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
698 <td>| . $locale->text('Tax') . qq|</td>
699 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
700 <td>| . $locale->text('Total') . qq|</td>
703 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
704 <td>| . $locale->text('Subtotal') . qq|</td>
713 if ($form->{report} =~ /^nontaxable_/) {
714 $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
717 <input type=hidden name=nextsub value=generate_tax_report>
719 <input type=hidden name=db value=$form->{db}>
720 <input type=hidden name=sort value=transdate>
721 <input type=hidden name=report value=$form->{report}>
724 <th align=right>| . $locale->text('From') . qq|</th>
725 <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
726 <th align=right>| . $locale->text('Bis') . qq|</th>
727 <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
730 <th align=right>| . $locale->text('Method') . qq|</th>
731 <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
732 . $locale->text('Accrual') . qq|
733 <input name=method class=radio type=radio value=cash $cash>|
734 . $locale->text('EUR') . qq|</td>
737 <th align=right>| . $locale->text('Include in Report') . qq|</th>
741 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
742 <td>| . $locale->text('ID') . qq|</td>
743 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
744 <td>| . $locale->text('Invoice') . qq|</td>
745 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
746 <td>| . $locale->text('Date') . qq|</td>
749 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
752 if ($form->{db} eq 'ar') {
753 print $locale->text('Customer');
755 if ($form->{db} eq 'ap') {
756 print $locale->text('Vendor');
760 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
761 <td>| . $locale->text('Amount') . qq|</td>
762 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
763 <td>| . $locale->text('Total') . qq|</td>
766 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
767 <td>| . $locale->text('Subtotal') . qq|</td>
776 my ($label, $nextsub, $vc);
777 if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
778 if ($form->{report} eq 'ar_aging') {
779 $label = $locale->text('Customer');
780 $form->{vc} = 'customer';
782 $label = $locale->text('Vendor');
783 $form->{vc} = 'vendor';
786 $nextsub = "generate_$form->{report}";
789 $form->all_vc(\%myconfig, $form->{vc},
790 ($form->{vc} eq 'customer') ? "AR" : "AP");
792 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
793 @{ $form->{"all_$form->{vc}"} };
797 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
798 : qq|<input name=$form->{vc} size=35>|;
802 <th align=right>| . $locale->text($label) . qq|</th>
806 <td align=left colspan=4>| . $locale->text('From') . qq|
809 | . $locale->text('Bis') . qq|
814 <input type=hidden name=type value=statement>
815 <input type=hidden name=format value=html>
816 <input type=hidden name=media value=screen>
818 <input type=hidden name=nextsub value=$nextsub>
819 <input type=hidden name=action value=$nextsub>
825 # above action can be removed if there is more than one input field
827 my ($selection, $paymentaccounts);
828 if ($form->{report} =~ /(receipts|payments)$/) {
829 $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
831 RP->paymentaccounts(\%myconfig, \%$form);
833 $selection = "<option>\n";
834 foreach my $ref (@{ $form->{PR} }) {
835 $paymentaccounts .= "$ref->{accno} ";
836 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
839 chop $paymentaccounts;
842 <input type=hidden name=nextsub value=list_payments>
844 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
845 <td colspan=3><select name=account>$selection</select>
846 <input type=hidden name=paymentaccounts value="$paymentaccounts">
850 <th align=right>| . $locale->text('Reference') . qq|</th>
851 <td colspan=3><input name=reference></td>
854 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
855 <td colspan=3><input name=source></td>
858 <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
859 <td colspan=3><input name=memo size=30></td>
862 <th align=right>| . $locale->text('From') . qq|</th>
867 <th align=right>| . $locale->text('Bis') . qq|</th>
874 <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
875 <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
880 <input type=hidden name=db value=$form->{db}>
881 <input type=hidden name=sort value=transdate>
892 <td><hr size=3 noshade></td>
897 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
905 $main::lxdebug->leave_sub();
908 sub continue { call_sub($main::form->{"nextsub"}); }
911 $main::lxdebug->enter_sub();
913 $main::auth->assert('report');
915 my $form = $main::form;
916 my %myconfig = %main::myconfig;
917 my $locale = $main::locale;
921 $form->{project_id} = $form->{project_id_1};
922 if ($form->{projectnumber} && !$form->{project_id}) {
923 $form->{rowcount} = 1;
925 # call this instead of update
926 $form->{update} = $nextsub;
927 $form->{projectnumber_1} = $form->{projectnumber};
929 delete $form->{sort};
930 check_project('generate_projects');
932 # if there is one only, assign id
933 $form->{project_id} = $form->{project_id_1};
936 $main::lxdebug->leave_sub();
939 sub generate_income_statement {
940 $main::lxdebug->enter_sub();
942 $main::auth->assert('report');
944 my $form = $main::form;
945 my %myconfig = %main::myconfig;
946 my $locale = $main::locale;
948 $form->{padding} = " ";
949 $form->{bold} = "<b>";
950 $form->{endbold} = "</b>";
951 $form->{br} = "<br>";
953 if ($form->{reporttype} eq "custom") {
955 #forgotten the year --> thisyear
956 if ($form->{year} !~ m/^\d\d\d\d$/) {
957 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
963 if ($form->{duetyp} eq "13") {
964 $form->{fromdate} = "1.1.$form->{year}";
965 $form->{todate} = "31.12.$form->{year}";
969 if ($form->{duetyp} eq "A") {
970 $form->{fromdate} = "1.1.$form->{year}";
971 $form->{todate} = "31.3.$form->{year}";
973 if ($form->{duetyp} eq "B") {
974 $form->{fromdate} = "1.4.$form->{year}";
975 $form->{todate} = "30.6.$form->{year}";
977 if ($form->{duetyp} eq "C") {
978 $form->{fromdate} = "1.7.$form->{year}";
979 $form->{todate} = "30.9.$form->{year}";
981 if ($form->{duetyp} eq "D") {
982 $form->{fromdate} = "1.10.$form->{year}";
983 $form->{todate} = "31.12.$form->{year}";
988 $form->{duetyp} eq "1" && do {
989 $form->{fromdate} = "1.1.$form->{year}";
990 $form->{todate} = "31.1.$form->{year}";
993 $form->{duetyp} eq "2" && do {
994 $form->{fromdate} = "1.2.$form->{year}";
996 #this works from 1901 to 2099, 1900 and 2100 fail.
997 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
998 $form->{todate} = "$leap.2.$form->{year}";
1001 $form->{duetyp} eq "3" && do {
1002 $form->{fromdate} = "1.3.$form->{year}";
1003 $form->{todate} = "31.3.$form->{year}";
1006 $form->{duetyp} eq "4" && do {
1007 $form->{fromdate} = "1.4.$form->{year}";
1008 $form->{todate} = "30.4.$form->{year}";
1011 $form->{duetyp} eq "5" && do {
1012 $form->{fromdate} = "1.5.$form->{year}";
1013 $form->{todate} = "31.5.$form->{year}";
1016 $form->{duetyp} eq "6" && do {
1017 $form->{fromdate} = "1.6.$form->{year}";
1018 $form->{todate} = "30.6.$form->{year}";
1021 $form->{duetyp} eq "7" && do {
1022 $form->{fromdate} = "1.7.$form->{year}";
1023 $form->{todate} = "31.7.$form->{year}";
1026 $form->{duetyp} eq "8" && do {
1027 $form->{fromdate} = "1.8.$form->{year}";
1028 $form->{todate} = "31.8.$form->{year}";
1031 $form->{duetyp} eq "9" && do {
1032 $form->{fromdate} = "1.9.$form->{year}";
1033 $form->{todate} = "30.9.$form->{year}";
1036 $form->{duetyp} eq "10" && do {
1037 $form->{fromdate} = "1.10.$form->{year}";
1038 $form->{todate} = "31.10.$form->{year}";
1041 $form->{duetyp} eq "11" && do {
1042 $form->{fromdate} = "1.11.$form->{year}";
1043 $form->{todate} = "30.11.$form->{year}";
1046 $form->{duetyp} eq "12" && do {
1047 $form->{fromdate} = "1.12.$form->{year}";
1048 $form->{todate} = "31.12.$form->{year}";
1054 RP->income_statement(\%myconfig, \%$form);
1056 ($form->{department}) = split /--/, $form->{department};
1059 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1060 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1062 # if there are any dates construct a where
1063 if ($form->{fromdate} || $form->{todate}) {
1065 unless ($form->{todate}) {
1066 $form->{todate} = $form->current_date(\%myconfig);
1069 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
1070 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1072 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1073 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1075 $form->{this_period} = "$shortfromdate\n$shorttodate";
1077 $locale->text('for Period')
1078 . qq|\n$longfromdate |
1079 . $locale->text('Bis')
1083 if ($form->{comparefromdate} || $form->{comparetodate}) {
1084 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1085 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1087 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1088 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1090 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1092 "\n$longcomparefromdate "
1093 . $locale->text('Bis')
1094 . qq| $longcomparetodate|;
1097 # setup variables for the form
1098 my @a = qw(company address businessnumber);
1099 map { $form->{$_} = $myconfig{$_} } @a;
1101 $form->{templates} = $myconfig{templates};
1103 $form->{IN} = "income_statement.html";
1105 $form->parse_template;
1107 $main::lxdebug->leave_sub();
1110 sub generate_balance_sheet {
1111 $::lxdebug->enter_sub;
1112 $::auth->assert('report');
1114 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
1115 $::form->{padding} = " ";
1116 $::form->{bold} = "<b>";
1117 $::form->{endbold} = "</b>";
1118 $::form->{br} = "<br>";
1120 my $data = RP->balance_sheet(\%::myconfig, $::form);
1122 $::form->{asofdate} ||= $::form->current_date;
1123 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
1125 ($::form->{department}) = split /--/, $::form->{department};
1127 # define Current Earnings account
1128 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
1129 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
1131 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
1132 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
1134 # $::form->{IN} = "balance_sheet.html";
1136 # setup company variables for the form
1137 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
1139 $::form->{templates} = $::myconfig{templates};
1142 print $::form->parse_html_template('rp/balance_sheet', $data);
1144 $::lxdebug->leave_sub;
1147 sub generate_projects {
1148 $main::lxdebug->enter_sub();
1150 $main::auth->assert('report');
1152 my $form = $main::form;
1153 my %myconfig = %main::myconfig;
1154 my $locale = $main::locale;
1156 &get_project("generate_projects");
1157 $form->{projectnumber} = $form->{projectnumber_1};
1159 $form->{nextsub} = "generate_projects";
1160 $form->{title} = $locale->text('Project Transactions');
1161 RP->trial_balance(\%myconfig, \%$form);
1163 list_accounts('generate_projects');
1165 $main::lxdebug->leave_sub();
1171 # included links to display transactions for period entered
1172 # added headers and subtotals
1174 sub generate_trial_balance {
1175 $main::lxdebug->enter_sub();
1177 $main::auth->assert('report');
1179 my $form = $main::form;
1180 my %myconfig = %main::myconfig;
1181 my $locale = $main::locale;
1183 if ($form->{reporttype} eq "custom") {
1185 #forgotten the year --> thisyear
1186 if ($form->{year} !~ m/^\d\d\d\d$/) {
1187 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1193 if ($form->{duetyp} eq "13") {
1194 $form->{fromdate} = "1.1.$form->{year}";
1195 $form->{todate} = "31.12.$form->{year}";
1199 if ($form->{duetyp} eq "A") {
1200 $form->{fromdate} = "1.1.$form->{year}";
1201 $form->{todate} = "31.3.$form->{year}";
1203 if ($form->{duetyp} eq "B") {
1204 $form->{fromdate} = "1.4.$form->{year}";
1205 $form->{todate} = "30.6.$form->{year}";
1207 if ($form->{duetyp} eq "C") {
1208 $form->{fromdate} = "1.7.$form->{year}";
1209 $form->{todate} = "30.9.$form->{year}";
1211 if ($form->{duetyp} eq "D") {
1212 $form->{fromdate} = "1.10.$form->{year}";
1213 $form->{todate} = "31.12.$form->{year}";
1218 $form->{duetyp} eq "1" && do {
1219 $form->{fromdate} = "1.1.$form->{year}";
1220 $form->{todate} = "31.1.$form->{year}";
1223 $form->{duetyp} eq "2" && do {
1224 $form->{fromdate} = "1.2.$form->{year}";
1226 #this works from 1901 to 2099, 1900 and 2100 fail.
1227 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1228 $form->{todate} = "$leap.2.$form->{year}";
1231 $form->{duetyp} eq "3" && do {
1232 $form->{fromdate} = "1.3.$form->{year}";
1233 $form->{todate} = "31.3.$form->{year}";
1236 $form->{duetyp} eq "4" && do {
1237 $form->{fromdate} = "1.4.$form->{year}";
1238 $form->{todate} = "30.4.$form->{year}";
1241 $form->{duetyp} eq "5" && do {
1242 $form->{fromdate} = "1.5.$form->{year}";
1243 $form->{todate} = "31.5.$form->{year}";
1246 $form->{duetyp} eq "6" && do {
1247 $form->{fromdate} = "1.6.$form->{year}";
1248 $form->{todate} = "30.6.$form->{year}";
1251 $form->{duetyp} eq "7" && do {
1252 $form->{fromdate} = "1.7.$form->{year}";
1253 $form->{todate} = "31.7.$form->{year}";
1256 $form->{duetyp} eq "8" && do {
1257 $form->{fromdate} = "1.8.$form->{year}";
1258 $form->{todate} = "31.8.$form->{year}";
1261 $form->{duetyp} eq "9" && do {
1262 $form->{fromdate} = "1.9.$form->{year}";
1263 $form->{todate} = "30.9.$form->{year}";
1266 $form->{duetyp} eq "10" && do {
1267 $form->{fromdate} = "1.10.$form->{year}";
1268 $form->{todate} = "31.10.$form->{year}";
1271 $form->{duetyp} eq "11" && do {
1272 $form->{fromdate} = "1.11.$form->{year}";
1273 $form->{todate} = "30.11.$form->{year}";
1276 $form->{duetyp} eq "12" && do {
1277 $form->{fromdate} = "1.12.$form->{year}";
1278 $form->{todate} = "31.12.$form->{year}";
1285 # get for each account initial balance, debits and credits
1286 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
1289 $form->{rowcount} = scalar @{ $form->{TB} || [] };
1290 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
1293 "accno", "description",
1294 "last_transaction", "soll_eb",
1297 "soll_kumuliert", "haben_kumuliert",
1298 "soll_saldo", "haben_saldo"
1302 my $attachment_basename = $locale->text('trial_balance');
1303 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1305 my @hidden_variables = qw(fromdate todate year cash);
1307 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
1310 'accno' => { 'text' => $locale->text('Account'), },
1311 'description' => { 'text' => $locale->text('Description'), },
1312 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
1313 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
1314 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
1315 'soll' => { 'text' => $locale->text('Debit'), },
1316 'haben' => { 'text' => $locale->text('Credit'), },
1317 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
1318 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
1319 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
1320 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
1325 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1327 map { $column_defs{$_}->{visible} = 1 } @columns;
1329 $report->set_columns(%column_defs);
1330 $report->set_column_order(@columns);
1332 $report->set_export_options('generate_trial_balance', @hidden_variables);
1337 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
1339 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
1340 push (@options, $form->{print_date});
1342 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
1343 push (@options, $form->{company});
1346 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
1348 $report->set_options('output_format' => 'HTML',
1349 'top_info_text' => join("\n", @options),
1350 'title' => $form->{title},
1351 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1352 'html_template' => 'rp/html_report_susa',
1353 'pdf_template' => 'rp/html_report_susa',
1355 $report->set_options_from_form();
1357 # add sort and escape callback, this one we use for the add sub
1358 $form->{callback} = $href .= "&sort=$form->{sort}";
1360 # escape callback for href
1361 my $callback = $form->escape($href);
1363 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1365 my %totals = map { $_ => 0 } @subtotal_columns;
1367 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1370 foreach my $accno (@{ $form->{TB} }) {
1372 $accno->{soll} = $accno->{debit};
1373 $accno->{haben} = $accno->{credit};
1374 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
1376 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
1377 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
1381 foreach my $column (@columns) {
1383 'data' => $accno->{$column},
1384 'align' => $column_alignment{$column},
1388 $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}));
1390 my $row_set = [ $row ];
1393 $report->add_data($row_set);
1398 $report->add_separator();
1400 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1402 $report->generate_with_headers();
1404 $main::lxdebug->leave_sub();
1408 sub create_subtotal_row {
1409 $main::lxdebug->enter_sub();
1411 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1413 my $form = $main::form;
1414 my %myconfig = %main::myconfig;
1415 my $locale = $main::locale;
1417 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1419 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1421 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1423 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1425 $main::lxdebug->leave_sub();
1430 sub create_list_accounts_subtotal_row {
1431 $main::lxdebug->enter_sub();
1433 my ($subtotals, $columns, $fields, $class) = @_;
1435 my $form = $main::form;
1436 my %myconfig = %main::myconfig;
1437 my $locale = $main::locale;
1439 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1441 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1443 $main::lxdebug->leave_sub();
1449 $main::lxdebug->enter_sub();
1453 my $form = $main::form;
1454 my %myconfig = %main::myconfig;
1455 my $locale = $main::locale;
1458 if ($form->{department}) {
1459 my ($department) = split /--/, $form->{department};
1460 push @options, $locale->text('Department') . " : $department";
1462 if ($form->{projectnumber}) {
1463 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1466 # if there are any dates
1467 if ($form->{fromdate} || $form->{todate}) {
1468 my ($fromdate, $todate);
1470 if ($form->{fromdate}) {
1471 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1473 if ($form->{todate}) {
1474 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1477 push @options, "$fromdate - $todate";
1480 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1483 my @columns = qw(accno description begbalance debit credit endbalance);
1485 'accno' => { 'text' => $locale->text('Account'), },
1486 'description' => { 'text' => $locale->text('Description'), },
1487 'debit' => { 'text' => $locale->text('Debit'), },
1488 'credit' => { 'text' => $locale->text('Credit'), },
1489 'begbalance' => { 'text' => $locale->text('Balance'), },
1490 'endbalance' => { 'text' => $locale->text('Balance'), },
1492 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1494 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1496 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1498 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1500 $report->set_options('top_info_text' => join("\n", @options),
1501 'output_format' => 'HTML',
1502 'title' => $form->{title},
1503 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1504 'std_column_visibility' => 1,
1506 $report->set_options_from_form();
1508 $report->set_columns(%column_defs);
1509 $report->set_column_order(@columns);
1511 $report->set_export_options($action, @hidden_variables);
1513 my @totals_columns = qw(credit debit begbalance endbalance);
1514 my %subtotals = map { $_ => 0 } @totals_columns;
1515 my %totals = map { $_ => 0 } @totals_columns;
1516 my $found_heading = 0;
1517 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1519 # sort the whole thing by account numbers and display
1520 foreach my $idx (0 .. scalar(@tb) - 1) {
1521 my $ref = $tb[$idx];
1522 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1524 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1526 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1528 if ($ref->{charttype} eq 'H') {
1529 next unless ($form->{l_heading});
1531 %subtotals = map { $_ => 0 } @totals_columns;
1533 $row->{description}->{class} = 'listheading';
1534 $row->{description}->{data} = $ref->{description};
1536 $report->add_data($row);
1541 foreach (qw(debit credit)) {
1542 $subtotals{$_} += $ref->{$_};
1543 $totals{$_} += $ref->{$_};
1546 $subtotals{begbalance} += $ref->{balance} * $ml;
1547 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1549 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1550 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1552 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1553 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1555 $report->add_data($row);
1557 if ($form->{l_heading} && $found_heading &&
1558 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1559 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1563 $report->add_separator();
1565 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1567 $report->generate_with_headers();
1569 $main::lxdebug->leave_sub();
1572 sub generate_ar_aging {
1573 $main::lxdebug->enter_sub();
1575 $main::auth->assert('general_ledger');
1577 my $form = $main::form;
1578 my %myconfig = %main::myconfig;
1579 my $locale = $main::locale;
1582 ($form->{customer}) = split(/--/, $form->{customer});
1584 $form->{ct} = "customer";
1585 $form->{arap} = "ar";
1587 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1589 RP->aging(\%myconfig, \%$form);
1592 $main::lxdebug->leave_sub();
1595 sub generate_ap_aging {
1596 $main::lxdebug->enter_sub();
1598 $main::auth->assert('general_ledger');
1600 my $form = $main::form;
1601 my %myconfig = %main::myconfig;
1602 my $locale = $main::locale;
1605 ($form->{vendor}) = split(/--/, $form->{vendor});
1607 $form->{ct} = "vendor";
1608 $form->{arap} = "ap";
1610 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1612 RP->aging(\%myconfig, \%$form);
1615 $main::lxdebug->leave_sub();
1618 sub create_aging_subtotal_row {
1619 $main::lxdebug->enter_sub();
1621 my ($subtotals, $columns, $periods, $class) = @_;
1623 my $form = $main::form;
1624 my %myconfig = %main::myconfig;
1625 my $locale = $main::locale;
1627 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1629 foreach (@{ $periods }) {
1630 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1631 $subtotals->{$_} = 0;
1634 $main::lxdebug->leave_sub();
1640 $main::lxdebug->enter_sub();
1642 $main::auth->assert('general_ledger');
1644 my $form = $main::form;
1645 my %myconfig = %main::myconfig;
1646 my $locale = $main::locale;
1647 my $cgi = $main::cgi;
1649 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1651 my @columns = qw(statement ct invnumber transdate duedate amount open);
1654 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1655 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1656 'invnumber' => { 'text' => $locale->text('Invoice'), },
1657 'transdate' => { 'text' => $locale->text('Date'), },
1658 'duedate' => { 'text' => $locale->text('Due'), },
1659 'amount' => { 'text' => $locale->text('Amount'), },
1660 'open' => { 'text' => $locale->text('Open'), },
1663 my %column_alignment = ('statement' => 'center',
1664 map { $_ => 'right' } qw(open amount));
1666 $report->set_options('std_column_visibility' => 1);
1667 $report->set_columns(%column_defs);
1668 $report->set_column_order(@columns);
1670 my @hidden_variables = qw(todate customer vendor arap title ct);
1671 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1674 my $attachment_basename;
1676 if ($form->{department}) {
1677 my ($department) = split /--/, $form->{department};
1678 push @options, $locale->text('Department') . " : $department";
1679 $form->{callback} .= "&department=" . E($department);
1682 if (($form->{arap} eq 'ar') && $form->{customer}) {
1683 push @options, $form->{customer};
1684 $attachment_basename = $locale->text('ar_aging_list');
1685 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1688 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1689 push @options, $form->{vendor};
1690 $attachment_basename = $locale->text('ap_aging_list');
1691 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1694 if ($form->{fromdate}) {
1695 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1697 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1700 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1702 $report->set_options('top_info_text' => join("\n", @options),
1703 'output_format' => 'HTML',
1704 'title' => $form->{title},
1705 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1708 my $previous_ctid = 0;
1710 my @periods = qw(open amount);
1711 my %subtotals = map { $_ => 0 } @periods;
1712 my %totals = map { $_ => 0 } @periods;
1714 foreach my $ref (@{ $form->{AG} }) {
1715 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1716 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1719 foreach my $key (@periods) {
1720 $subtotals{$key} += $ref->{"$key"};
1721 $totals{$key} += $ref->{"$key"};
1722 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1727 foreach my $column (@columns) {
1729 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1730 'align' => $column_alignment{$column},
1731 'valign' => $column eq 'statement' ? 'center' : '',
1735 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1737 if ($previous_ctid != $ref->{ctid}) {
1738 $row->{statement}->{raw_data} =
1739 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1740 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1741 $row->{ct}->{data} = $ref->{name};
1746 $previous_ctid = $ref->{ctid};
1748 $report->add_data($row);
1751 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1753 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1755 if ($form->{arap} eq 'ar') {
1756 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1757 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1758 'PRINT_OPTIONS' => print_options(inline => 1), });
1759 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1760 'raw_bottom_info_text' => $raw_bottom_info_text);
1763 $report->set_options_from_form();
1765 $report->generate_with_headers();
1767 $main::lxdebug->leave_sub();
1771 $main::lxdebug->enter_sub();
1773 my $form = $main::form;
1774 my %myconfig = %main::myconfig;
1775 my $locale = $main::locale;
1777 RP->aging(\%myconfig, \%$form);
1779 map { $_->{checked} = "checked" } @{ $form->{AG} };
1783 $main::lxdebug->leave_sub();
1787 $main::lxdebug->enter_sub();
1789 $main::auth->assert('general_ledger');
1791 my $form = $main::form;
1792 my %myconfig = %main::myconfig;
1793 my $locale = $main::locale;
1795 # get name and email addresses
1797 for my $i (1 .. $form->{rowcount}) {
1798 if ($form->{"statement_$i"}) {
1799 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1800 RP->get_customer(\%myconfig, \%$form);
1806 $form->error($locale->text('Nothing selected!')) unless $selected;
1809 if ($myconfig{role} eq 'admin') {
1811 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1812 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1816 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1818 $form->{media} = "email";
1825 <form method=post action=$form->{script}>
1831 <tr height="5"></tr>
1836 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1837 <td><input name=email size=30 value="$form->{email}"></td>
1838 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1839 <td><input name=cc size=30 value="$form->{cc}"></td>
1842 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1843 <td><input name=subject size=30 value="$form->{subject}"></td>
1853 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1856 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1867 map { delete $form->{$_} }
1868 qw(action email cc bcc subject message type sendmode format header);
1870 # save all other variables
1871 foreach my $key (keys %$form) {
1872 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1873 $form->{$key} =~ s/\"/"/g;
1874 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1881 <td><hr size=3 noshade></td>
1885 <input type=hidden name=nextsub value=send_email>
1888 <input name=action class=submit type=submit value="|
1889 . $locale->text('Continue') . qq|">
1896 $main::lxdebug->leave_sub();
1900 $main::lxdebug->enter_sub();
1902 $main::auth->assert('general_ledger');
1904 my $form = $main::form;
1905 my %myconfig = %main::myconfig;
1906 my $locale = $main::locale;
1908 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1909 unless $form->{subject};
1911 RP->aging(\%myconfig, \%$form);
1913 $form->{"statement_1"} = 1;
1915 $form->{media} = 'email';
1918 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1920 $main::lxdebug->leave_sub();
1924 $main::lxdebug->enter_sub();
1926 $main::auth->assert('general_ledger');
1928 my $form = $main::form;
1929 my %myconfig = %main::myconfig;
1930 my $locale = $main::locale;
1932 if ($form->{media} eq 'printer') {
1933 $form->error($locale->text('Select postscript or PDF!'))
1934 if ($form->{format} !~ /(postscript|pdf)/);
1938 for my $i (1 .. $form->{rowcount}) {
1939 if ($form->{"statement_$i"}) {
1940 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1946 $form->error($locale->text('Nothing selected!')) unless $selected;
1948 if ($form->{media} eq 'printer') {
1949 $form->{"$form->{ct}_id"} = "";
1951 $form->{"statement_1"} = 1;
1954 RP->aging(\%myconfig, \%$form);
1958 $form->redirect($locale->text('Statements sent to printer!'))
1959 if ($form->{media} eq 'printer');
1961 $main::lxdebug->leave_sub();
1965 $main::lxdebug->enter_sub();
1967 $main::auth->assert('general_ledger');
1969 my $form = $main::form;
1970 my %myconfig = %main::myconfig;
1971 my $locale = $main::locale;
1973 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1975 $form->{templates} = "$myconfig{templates}";
1977 my $suffix = "html";
1978 my $attachment_suffix = "html";
1979 if ($form->{format} eq 'postscript') {
1980 $form->{postscript} = 1;
1982 $attachment_suffix = "ps";
1983 } elsif ($form->{format} eq 'pdf') {
1986 $attachment_suffix = "pdf";
1989 $form->{IN} = "$form->{type}.$suffix";
1990 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1992 # Save $form->{email} because it will be overwritten.
1993 $form->{EMAIL_RECIPIENT} = $form->{email};
1997 while (@{ $form->{AG} }) {
1999 my $ref = shift @{ $form->{AG} };
2001 if ($ctid != $ref->{ctid}) {
2003 $ctid = $ref->{ctid};
2006 if ($form->{"statement_$i"}) {
2009 ("name", "street", "zipcode", "city", "country", "contact", "email",
2010 "$form->{ct}phone", "$form->{ct}fax");
2011 map { $form->{$_} = $ref->{$_} } @a;
2013 $form->{ $form->{ct} } = $form->{name};
2014 $form->{"$form->{ct}_id"} = $ref->{ctid};
2016 map { $form->{$_} = () } qw(invnumber invdate duedate);
2018 foreach my $item (qw(c0 c30 c60 c90)) {
2019 $form->{$item} = ();
2020 $form->{"${item}total"} = 0;
2023 &statement_details($ref);
2027 if (scalar(@{ $form->{AG} }) > 0) {
2029 # one or more left to go
2030 if ($ctid == $form->{AG}->[0]->{ctid}) {
2031 $ref = shift @{ $form->{AG} };
2032 &statement_details($ref);
2035 $ref = scalar(@{ $form->{AG} });
2041 # set initial ref to 0
2048 $form->{"${_}total"} =
2049 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2050 } ('c0', 'c30', 'c60', 'c90', "");
2052 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
2053 $form->{attachment_filename} =~ s/\s+/_/g;
2055 $form->parse_template(\%myconfig, $main::userspath);
2060 # saving the history
2061 if(!exists $form->{addition} && $form->{id} ne "") {
2062 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2063 $form->{addition} = "PRINTED";
2064 $form->{what_done} = $form->{type};
2065 $form->save_history;
2067 # /saving the history
2068 $main::lxdebug->leave_sub();
2071 sub statement_details {
2072 $main::lxdebug->enter_sub();
2074 $main::auth->assert('general_ledger');
2076 my $form = $main::form;
2077 my %myconfig = %main::myconfig;
2078 my $locale = $main::locale;
2082 push @{ $form->{invnumber} }, $ref->{invnumber};
2083 push @{ $form->{invdate} }, $ref->{transdate};
2084 push @{ $form->{duedate} }, $ref->{duedate};
2086 foreach my $item (qw(c0 c30 c60 c90)) {
2087 if ($ref->{exchangerate} * 1) {
2089 $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2091 $form->{"${item}total"} += $ref->{$item};
2092 $form->{total} += $ref->{$item};
2093 push @{ $form->{$item} },
2094 $form->format_amount(\%myconfig, $ref->{$item}, 2);
2097 $main::lxdebug->leave_sub();
2100 sub generate_tax_report {
2101 $main::lxdebug->enter_sub();
2103 $main::auth->assert('report');
2105 my $form = $main::form;
2106 my %myconfig = %main::myconfig;
2107 my $locale = $main::locale;
2109 RP->tax_report(\%myconfig, \%$form);
2111 my $descvar = "$form->{accno}_description";
2112 my $description = $form->escape($form->{$descvar});
2113 my $ratevar = "$form->{accno}_rate";
2114 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
2116 my $department = $form->escape($form->{department});
2120 "$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}";
2122 # construct callback
2123 $description = $form->escape($form->{$descvar}, 1);
2124 $department = $form->escape($form->{department}, 1);
2126 "$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}";
2128 my $title = $form->escape($form->{title});
2129 $href .= "&title=$title";
2130 $title = $form->escape($form->{title}, 1);
2131 $callback .= "&title=$title";
2133 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2136 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2139 foreach my $item (@columns) {
2140 if ($form->{"l_$item"} eq "Y") {
2141 push @column_index, $item;
2143 # add column to href and callback
2144 $callback .= "&l_$item=Y";
2145 $href .= "&l_$item=Y";
2149 if ($form->{l_subtotal} eq 'Y') {
2150 $callback .= "&l_subtotal=Y";
2151 $href .= "&l_subtotal=Y";
2155 if ($form->{department}) {
2156 ($department) = split /--/, $form->{department};
2157 $option = $locale->text('Department') . " : $department";
2160 my ($fromdate, $todate);
2161 # if there are any dates
2162 if ($form->{fromdate} || $form->{todate}) {
2163 if ($form->{fromdate}) {
2164 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2166 if ($form->{todate}) {
2167 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2170 $form->{period} = "$fromdate - $todate";
2173 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2176 my ($name, $invoice, $arap);
2177 if ($form->{db} eq 'ar') {
2178 $name = $locale->text('Customer');
2182 if ($form->{db} eq 'ap') {
2183 $name = $locale->text('Vendor');
2188 $option .= "<br>" if $option;
2189 $option .= "$form->{period}";
2192 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
2193 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
2194 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
2195 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2196 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2197 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2199 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2208 <th class=listtop>$form->{title}</th>
2210 <tr height="5"></tr>
2217 <tr class=listheading>
2220 map { print "$column_header{$_}\n" } @column_index;
2226 # add sort and escape callback
2227 $callback = $form->escape($callback . "&sort=$form->{sort}");
2230 if (@{ $form->{TR} }) {
2231 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2234 my ($totalnetamount, $totaltax);
2236 foreach my $ref (@{ $form->{TR} }) {
2238 my $module = ($ref->{invoice}) ? $invoice : $arap;
2240 if ($form->{l_subtotal} eq 'Y') {
2241 if ($sameitem ne $ref->{ $form->{sort} }) {
2242 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2243 $sameitem = $ref->{ $form->{sort} };
2247 $totalnetamount += $ref->{netamount};
2248 $totaltax += $ref->{tax};
2249 $ref->{amount} = $ref->{netamount} + $ref->{tax};
2251 $subtotalnetamount += $ref->{netamount};
2252 $subtotaltax += $ref->{tax};
2255 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
2256 } qw(netamount tax amount);
2259 $column_data{id} = qq|<td>$ref->{id}</td>|;
2260 $column_data{invnumber} =
2261 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
2262 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2263 $column_data{name} = qq|<td>$ref->{name} </td>|;
2265 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2266 qw(netamount tax amount);
2271 <tr class=listrow$i>
2274 map { print "$column_data{$_}\n" } @column_index;
2282 if ($form->{l_subtotal} eq 'Y') {
2283 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
2287 map { $column_data{$_} = qq|<th> </th>| } @column_index;
2291 <tr class=listtotal>
2294 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
2295 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
2296 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
2298 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
2299 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
2300 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2302 map { print "$column_data{$_}\n" } @column_index;
2310 <td><hr size=3 noshade></td>
2318 $main::lxdebug->leave_sub();
2322 $main::lxdebug->enter_sub();
2324 my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
2326 my $form = $main::form;
2327 my %myconfig = %main::myconfig;
2328 my $locale = $main::locale;
2331 map { $column_data{$_} = "<td> </td>" } @{ $column_index };
2333 $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " ");
2334 $$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " ");
2335 $$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " ");
2337 $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
2338 $column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>";
2339 $column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>";
2341 $$subtotalnetamount = 0;
2345 <tr class=listsubtotal>
2347 map { print "\n$column_data{$_}" } @{ $column_index };
2353 $main::lxdebug->leave_sub();
2357 $main::lxdebug->enter_sub();
2359 $main::auth->assert('cash');
2361 my $form = $main::form;
2362 my %myconfig = %main::myconfig;
2363 my $locale = $main::locale;
2365 if ($form->{account}) {
2366 ($form->{paymentaccounts}) = split /--/, $form->{account};
2370 if ($form->{department}) {
2371 (my $department, $form->{department_id}) = split /--/, $form->{department};
2372 $option = $locale->text('Department') . " : $department";
2375 report_generator_set_default_sort('transdate', 1);
2377 RP->payments(\%myconfig, \%$form);
2379 my @hidden_variables = qw(account title department reference source memo fromdate todate
2380 fx_transaction db prepayment paymentaccounts sort);
2382 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2383 $form->{callback} = $href;
2385 my @columns = qw(transdate invnumber name paid source memo);
2387 'name' => { 'text' => $locale->text('Description'), },
2388 'invnumber' => { 'text' => $locale->text('Reference'), },
2389 'transdate' => { 'text' => $locale->text('Date'), },
2390 'paid' => { 'text' => $locale->text('Amount'), },
2391 'source' => { 'text' => $locale->text('Source'), },
2392 'memo' => { 'text' => $locale->text('Memo'), },
2394 my %column_alignment = ('paid' => 'right');
2396 foreach my $name (grep { $_ ne 'paid' } @columns) {
2397 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
2398 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
2402 if ($form->{fromdate}) {
2403 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
2405 if ($form->{todate}) {
2406 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
2409 my $report = SL::ReportGenerator->new(\%myconfig, $form);
2411 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2413 $report->set_options('top_info_text' => join("\n", @options),
2414 'output_format' => 'HTML',
2415 'title' => $form->{title},
2416 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
2417 'std_column_visibility' => 1,
2419 $report->set_options_from_form();
2421 $report->set_columns(%column_defs);
2422 $report->set_column_order(@columns);
2424 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
2426 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
2430 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2431 next unless @{ $form->{ $ref->{id} } };
2433 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2435 my $subtotal_paid = 0;
2437 foreach my $payment (@{ $form->{ $ref->{id} } }) {
2438 my $module = $payment->{module};
2439 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2440 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2442 $subtotal_paid += $payment->{paid};
2443 $total_paid += $payment->{paid};
2445 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2449 foreach my $column (@columns) {
2451 'data' => $payment->{$column},
2452 'align' => $column_alignment{$column},
2456 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2458 $report->add_data($row);
2461 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2463 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2465 'class' => 'listsubtotal',
2468 $report->add_data($row);
2471 $report->add_separator();
2473 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2475 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
2477 'class' => 'listtotal',
2480 $report->add_data($row);
2482 $report->generate_with_headers();
2484 $main::lxdebug->leave_sub();
2488 $main::lxdebug->enter_sub();
2490 my ($dont_print) = @_;
2492 my $form = $main::form;
2493 my %myconfig = %main::myconfig;
2494 my $locale = $main::locale;
2496 $form->{sendmode} = "attachment";
2499 $form->{"format"} ? $form->{"format"} :
2500 $myconfig{"template_format"} ? $myconfig{"template_format"} :
2504 $form->{"copies"} ? $form->{"copies"} :
2505 $myconfig{"copies"} ? $myconfig{"copies"} :
2508 $form->{PD}{ $form->{type} } = "selected";
2509 $form->{DF}{ $form->{format} } = "selected";
2510 $form->{OP}{ $form->{media} } = "selected";
2511 $form->{SM}{ $form->{sendmode} } = "selected";
2515 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
2517 if ($form->{media} eq 'email') {
2519 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
2520 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2523 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2524 if ($myconfig{printer} && $main::latex_templates) {
2526 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
2531 if ($main::latex_templates) {
2533 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
2534 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
2535 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
2541 <td><select name=type>$type</select></td>
2542 <td><select name=format>$format</select></td>
2543 <td><select name=media>$media</select></td>
2546 if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
2548 <td>| . $locale->text('Copies') . qq|
2549 <input name=copies size=2 value=$form->{copies}></td>
2558 print $output unless $dont_print;
2560 $main::lxdebug->leave_sub();
2566 $main::lxdebug->enter_sub();
2568 $main::auth->assert('report');
2570 my $form = $main::form;
2571 my %myconfig = %main::myconfig;
2572 my $locale = $main::locale;
2574 $form->{padding} = " ";
2575 $form->{bold} = "<b>";
2576 $form->{endbold} = "</b>";
2577 $form->{br} = "<br>";
2579 if ($form->{reporttype} eq "custom") {
2581 #forgotten the year --> thisyear
2582 if ($form->{year} !~ m/^\d\d\d\d$/) {
2583 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2589 if ($form->{duetyp} eq "13") {
2590 $form->{fromdate} = "1.1.$form->{year}";
2591 $form->{todate} = "31.12.$form->{year}";
2592 $form->{comparefromdate} = "1.01.$form->{year}";
2593 $form->{comparetodate} = "31.12.$form->{year}";
2597 if ($form->{duetyp} eq "A") {
2598 $form->{fromdate} = "1.1.$form->{year}";
2599 $form->{todate} = "31.3.$form->{year}";
2600 $form->{comparefromdate} = "1.01.$form->{year}";
2601 $form->{comparetodate} = "31.03.$form->{year}";
2603 if ($form->{duetyp} eq "B") {
2604 $form->{fromdate} = "1.4.$form->{year}";
2605 $form->{todate} = "30.6.$form->{year}";
2606 $form->{comparefromdate} = "1.01.$form->{year}";
2607 $form->{comparetodate} = "30.06.$form->{year}";
2609 if ($form->{duetyp} eq "C") {
2610 $form->{fromdate} = "1.7.$form->{year}";
2611 $form->{todate} = "30.9.$form->{year}";
2612 $form->{comparefromdate} = "1.01.$form->{year}";
2613 $form->{comparetodate} = "30.09.$form->{year}";
2615 if ($form->{duetyp} eq "D") {
2616 $form->{fromdate} = "1.10.$form->{year}";
2617 $form->{todate} = "31.12.$form->{year}";
2618 $form->{comparefromdate} = "1.01.$form->{year}";
2619 $form->{comparetodate} = "31.12.$form->{year}";
2624 $form->{duetyp} eq "1" && do {
2625 $form->{fromdate} = "1.1.$form->{year}";
2626 $form->{todate} = "31.1.$form->{year}";
2627 $form->{comparefromdate} = "1.01.$form->{year}";
2628 $form->{comparetodate} = "31.01.$form->{year}";
2631 $form->{duetyp} eq "2" && do {
2632 $form->{fromdate} = "1.2.$form->{year}";
2634 #this works from 1901 to 2099, 1900 and 2100 fail.
2635 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2636 $form->{todate} = "$leap.2.$form->{year}";
2637 $form->{comparefromdate} = "1.01.$form->{year}";
2638 $form->{comparetodate} = "$leap.02.$form->{year}";
2641 $form->{duetyp} eq "3" && do {
2642 $form->{fromdate} = "1.3.$form->{year}";
2643 $form->{todate} = "31.3.$form->{year}";
2644 $form->{comparefromdate} = "1.01.$form->{year}";
2645 $form->{comparetodate} = "31.03.$form->{year}";
2648 $form->{duetyp} eq "4" && do {
2649 $form->{fromdate} = "1.4.$form->{year}";
2650 $form->{todate} = "30.4.$form->{year}";
2651 $form->{comparefromdate} = "1.01.$form->{year}";
2652 $form->{comparetodate} = "30.04.$form->{year}";
2655 $form->{duetyp} eq "5" && do {
2656 $form->{fromdate} = "1.5.$form->{year}";
2657 $form->{todate} = "31.5.$form->{year}";
2658 $form->{comparefromdate} = "1.01.$form->{year}";
2659 $form->{comparetodate} = "31.05.$form->{year}";
2662 $form->{duetyp} eq "6" && do {
2663 $form->{fromdate} = "1.6.$form->{year}";
2664 $form->{todate} = "30.6.$form->{year}";
2665 $form->{comparefromdate} = "1.01.$form->{year}";
2666 $form->{comparetodate} = "30.06.$form->{year}";
2669 $form->{duetyp} eq "7" && do {
2670 $form->{fromdate} = "1.7.$form->{year}";
2671 $form->{todate} = "31.7.$form->{year}";
2672 $form->{comparefromdate} = "1.01.$form->{year}";
2673 $form->{comparetodate} = "31.07.$form->{year}";
2676 $form->{duetyp} eq "8" && do {
2677 $form->{fromdate} = "1.8.$form->{year}";
2678 $form->{todate} = "31.8.$form->{year}";
2679 $form->{comparefromdate} = "1.01.$form->{year}";
2680 $form->{comparetodate} = "31.08.$form->{year}";
2683 $form->{duetyp} eq "9" && do {
2684 $form->{fromdate} = "1.9.$form->{year}";
2685 $form->{todate} = "30.9.$form->{year}";
2686 $form->{comparefromdate} = "1.01.$form->{year}";
2687 $form->{comparetodate} = "30.09.$form->{year}";
2690 $form->{duetyp} eq "10" && do {
2691 $form->{fromdate} = "1.10.$form->{year}";
2692 $form->{todate} = "31.10.$form->{year}";
2693 $form->{comparefromdate} = "1.01.$form->{year}";
2694 $form->{comparetodate} = "31.10.$form->{year}";
2697 $form->{duetyp} eq "11" && do {
2698 $form->{fromdate} = "1.11.$form->{year}";
2699 $form->{todate} = "30.11.$form->{year}";
2700 $form->{comparefromdate} = "1.01.$form->{year}";
2701 $form->{comparetodate} = "30.11.$form->{year}";
2704 $form->{duetyp} eq "12" && do {
2705 $form->{fromdate} = "1.12.$form->{year}";
2706 $form->{todate} = "31.12.$form->{year}";
2707 $form->{comparefromdate} = "1.01.$form->{year}";
2708 $form->{comparetodate} = "31.12.$form->{year}";
2713 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2714 # ansonsten ist die prüfung in RP.pm
2715 # if (defined ($form->{fromdate|todate}=='..'))
2717 if ($form->{fromdate}){
2718 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2719 $form->{fromdate} = "${dd}.${mm}.${yy}";
2720 $form->{comparefromdate} = "01.01.$yy";
2722 if ($form->{todate}){
2723 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2724 $form->{todate} = "${dd}.${mm}.${yy}";
2725 $form->{comparetodate} = $form->{todate};
2729 RP->bwa(\%myconfig, \%$form);
2731 ($form->{department}) = split /--/, $form->{department};
2734 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2735 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2737 # if there are any dates construct a where
2738 if ($form->{fromdate} || $form->{todate}) {
2740 unless ($form->{todate}) {
2741 $form->{todate} = $form->current_date(\%myconfig);
2744 my %germandate = ("dateformat" => "dd.mm.yyyy");
2746 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2747 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2749 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2750 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2752 $form->{this_period} = "$shortfromdate\n$shorttodate";
2754 $locale->text('for Period')
2755 . qq|\n$longfromdate |
2756 . $locale->text('bis')
2760 # setup variables for the form
2761 my @a = qw(company address businessnumber);
2762 map { $form->{$_} = $myconfig{$_} } @a;
2763 $form->{templates} = $myconfig{templates};
2765 $form->{IN} = "bwa.html";
2767 $form->parse_template;
2769 $main::lxdebug->leave_sub();