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 $::lxdebug->enter_sub;
128 balance_sheet => $::locale->text('Balance Sheet'),
129 income_statement => $::locale->text('Income Statement'),
130 trial_balance => $::locale->text('Trial Balance'),
131 ar_aging => $::locale->text('Search AR Aging'),
132 ap_aging => $::locale->text('Search AP Aging'),
133 tax_collected => $::locale->text('Tax collected'),
134 tax_paid => $::locale->text('Tax paid'),
135 nontaxable_sales => $::locale->text('Non-taxable Sales'),
136 nontaxable_purchases => $::locale->text('Non-taxable Purchases'),
137 receipts => $::locale->text('Receipts'),
138 payments => $::locale->text('Payments'),
139 projects => $::locale->text('Project Transactions'),
140 bwa => $::locale->text('Business evaluation'),
143 $::form->{title} = $title{$::form->{report}};
146 $::form->all_departments(\%::myconfig);
147 if (@{ $::form->{all_departments} || [] }) {
148 $::form->{selectdepartment} = "<option>\n";
149 map { $::form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $::form->{all_departments} || [] };
152 $::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
154 my $onload = qq|focus()|;
156 my $is_projects = $::form->{report} eq "projects";
157 my $is_income_statement = $::form->{report} eq "income_statement";
158 my $is_bwa = $::form->{report} eq "bwa";
159 my $is_balance_sheet = $::form->{report} eq "balance_sheet";
160 my $is_trial_balance = $::form->{report} eq "trial_balance";
161 my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
162 my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
164 my ($label, $nextsub, $vc);
166 my $is_sales = $::form->{report} eq 'ar_aging';
167 $label = $is_sales ? $::locale->text('Customer') : $::locale->text('Vendor');
168 $::form->{vc} = $is_sales ? 'customer' : 'vendor';
170 $nextsub = "generate_$::form->{report}";
173 $::form->all_vc(\%::myconfig, $::form->{vc}, $is_sales ? "AR" : "AP");
174 $vc .= "<option>$_->{name}--$_->{id}\n" for @{ $::form->{"all_$::form->{vc}"} };
176 ? qq|<select name=$::form->{vc}><option>\n$vc</select>|
177 : qq|<input name=$::form->{vc} size=35>|;
180 my ($selection, $paymentaccounts);
182 $::form->{db} = $::form->{report} =~ /payments$/ ? "ap" : "ar";
184 RP->paymentaccounts(\%::myconfig, $::form);
186 $selection = "<option>\n";
187 for my $ref (@{ $::form->{PR} }) {
188 $paymentaccounts .= "$ref->{accno} ";
189 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
194 print $::form->parse_html_template('rp/report', {
195 paymentaccounts => $paymentaccounts,
196 selection => $selection,
197 is_aging => $is_aging,
200 year => DateTime->today->year,
203 accrual => $::instance_conf->get_accounting_method ne 'cash',
204 cash => $::instance_conf->get_accounting_method eq 'cash',
205 is_payments => $is_payments,
206 is_trial_balance => $is_trial_balance,
207 is_balance_sheet => $is_balance_sheet,
209 is_income_statement => $is_income_statement,
210 is_projects => $is_projects,
213 $::lxdebug->leave_sub;
216 sub continue { call_sub($main::form->{"nextsub"}); }
219 $main::lxdebug->enter_sub();
221 $main::auth->assert('report');
223 my $form = $main::form;
224 my %myconfig = %main::myconfig;
225 my $locale = $main::locale;
229 $form->{project_id} = $form->{project_id_1};
230 if ($form->{projectnumber} && !$form->{project_id}) {
231 $form->{rowcount} = 1;
233 # call this instead of update
234 $form->{update} = $nextsub;
235 $form->{projectnumber_1} = $form->{projectnumber};
237 delete $form->{sort};
238 check_project('generate_projects');
240 # if there is one only, assign id
241 $form->{project_id} = $form->{project_id_1};
244 $main::lxdebug->leave_sub();
247 sub generate_income_statement {
248 $main::lxdebug->enter_sub();
250 $main::auth->assert('report');
252 my $form = $main::form;
253 my %myconfig = %main::myconfig;
254 my $locale = $main::locale;
256 $form->{padding} = " ";
257 $form->{bold} = "<b>";
258 $form->{endbold} = "</b>";
259 $form->{br} = "<br>";
261 if ($form->{reporttype} eq "custom") {
263 #forgotten the year --> thisyear
264 if ($form->{year} !~ m/^\d\d\d\d$/) {
265 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
271 if ($form->{duetyp} eq "13") {
272 $form->{fromdate} = "1.1.$form->{year}";
273 $form->{todate} = "31.12.$form->{year}";
277 if ($form->{duetyp} eq "A") {
278 $form->{fromdate} = "1.1.$form->{year}";
279 $form->{todate} = "31.3.$form->{year}";
281 if ($form->{duetyp} eq "B") {
282 $form->{fromdate} = "1.4.$form->{year}";
283 $form->{todate} = "30.6.$form->{year}";
285 if ($form->{duetyp} eq "C") {
286 $form->{fromdate} = "1.7.$form->{year}";
287 $form->{todate} = "30.9.$form->{year}";
289 if ($form->{duetyp} eq "D") {
290 $form->{fromdate} = "1.10.$form->{year}";
291 $form->{todate} = "31.12.$form->{year}";
296 $form->{duetyp} eq "1" && do {
297 $form->{fromdate} = "1.1.$form->{year}";
298 $form->{todate} = "31.1.$form->{year}";
301 $form->{duetyp} eq "2" && do {
302 $form->{fromdate} = "1.2.$form->{year}";
304 #this works from 1901 to 2099, 1900 and 2100 fail.
305 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
306 $form->{todate} = "$leap.2.$form->{year}";
309 $form->{duetyp} eq "3" && do {
310 $form->{fromdate} = "1.3.$form->{year}";
311 $form->{todate} = "31.3.$form->{year}";
314 $form->{duetyp} eq "4" && do {
315 $form->{fromdate} = "1.4.$form->{year}";
316 $form->{todate} = "30.4.$form->{year}";
319 $form->{duetyp} eq "5" && do {
320 $form->{fromdate} = "1.5.$form->{year}";
321 $form->{todate} = "31.5.$form->{year}";
324 $form->{duetyp} eq "6" && do {
325 $form->{fromdate} = "1.6.$form->{year}";
326 $form->{todate} = "30.6.$form->{year}";
329 $form->{duetyp} eq "7" && do {
330 $form->{fromdate} = "1.7.$form->{year}";
331 $form->{todate} = "31.7.$form->{year}";
334 $form->{duetyp} eq "8" && do {
335 $form->{fromdate} = "1.8.$form->{year}";
336 $form->{todate} = "31.8.$form->{year}";
339 $form->{duetyp} eq "9" && do {
340 $form->{fromdate} = "1.9.$form->{year}";
341 $form->{todate} = "30.9.$form->{year}";
344 $form->{duetyp} eq "10" && do {
345 $form->{fromdate} = "1.10.$form->{year}";
346 $form->{todate} = "31.10.$form->{year}";
349 $form->{duetyp} eq "11" && do {
350 $form->{fromdate} = "1.11.$form->{year}";
351 $form->{todate} = "30.11.$form->{year}";
354 $form->{duetyp} eq "12" && do {
355 $form->{fromdate} = "1.12.$form->{year}";
356 $form->{todate} = "31.12.$form->{year}";
360 hotfix_reformat_date();
361 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
363 RP->income_statement(\%myconfig, \%$form);
365 ($form->{department}) = split /--/, $form->{department};
368 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
369 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
371 # if there are any dates construct a where
372 if ($form->{fromdate} || $form->{todate}) {
374 unless ($form->{todate}) {
375 $form->{todate} = $form->current_date(\%myconfig);
378 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
379 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
381 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
382 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
384 $form->{this_period} = "$shortfromdate\n$shorttodate";
386 $locale->text('for Period')
387 . qq|\n$longfromdate |
388 . $locale->text('Bis')
392 if ($form->{comparefromdate} || $form->{comparetodate}) {
393 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
394 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
396 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
397 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
399 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
401 "\n$longcomparefromdate "
402 . $locale->text('Bis')
403 . qq| $longcomparetodate|;
406 # setup variables for the form
407 my @a = qw(company address businessnumber);
408 map { $form->{$_} = $myconfig{$_} } @a;
410 $form->{templates} = $myconfig{templates};
412 $form->{IN} = "income_statement.html";
414 $form->parse_template;
416 $main::lxdebug->leave_sub();
419 sub generate_balance_sheet {
420 $::lxdebug->enter_sub;
421 $::auth->assert('report');
423 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
424 $::form->{padding} = " ";
425 $::form->{bold} = "<b>";
426 $::form->{endbold} = "</b>";
427 $::form->{br} = "<br>";
429 my $data = RP->balance_sheet(\%::myconfig, $::form);
431 $::form->{asofdate} ||= $::form->current_date;
432 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
434 ($::form->{department}) = split /--/, $::form->{department};
436 # define Current Earnings account
437 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
438 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
440 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
441 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
443 # $::form->{IN} = "balance_sheet.html";
445 # setup company variables for the form
446 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
448 $::form->{templates} = $::myconfig{templates};
451 print $::form->parse_html_template('rp/balance_sheet', $data);
453 $::lxdebug->leave_sub;
456 sub generate_projects {
457 $main::lxdebug->enter_sub();
459 $main::auth->assert('report');
461 my $form = $main::form;
462 my %myconfig = %main::myconfig;
463 my $locale = $main::locale;
465 &get_project("generate_projects");
466 $form->{projectnumber} = $form->{projectnumber_1};
468 $form->{nextsub} = "generate_projects";
469 $form->{title} = $locale->text('Project Transactions');
470 RP->trial_balance(\%myconfig, \%$form);
472 list_accounts('generate_projects');
474 $main::lxdebug->leave_sub();
480 # included links to display transactions for period entered
481 # added headers and subtotals
483 sub generate_trial_balance {
484 $main::lxdebug->enter_sub();
486 $main::auth->assert('report');
488 my $form = $main::form;
489 my %myconfig = %main::myconfig;
490 my $locale = $main::locale;
492 if ($form->{reporttype} eq "custom") {
494 #forgotten the year --> thisyear
495 if ($form->{year} !~ m/^\d\d\d\d$/) {
496 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
502 if ($form->{duetyp} eq "13") {
503 $form->{fromdate} = "1.1.$form->{year}";
504 $form->{todate} = "31.12.$form->{year}";
508 if ($form->{duetyp} eq "A") {
509 $form->{fromdate} = "1.1.$form->{year}";
510 $form->{todate} = "31.3.$form->{year}";
512 if ($form->{duetyp} eq "B") {
513 $form->{fromdate} = "1.4.$form->{year}";
514 $form->{todate} = "30.6.$form->{year}";
516 if ($form->{duetyp} eq "C") {
517 $form->{fromdate} = "1.7.$form->{year}";
518 $form->{todate} = "30.9.$form->{year}";
520 if ($form->{duetyp} eq "D") {
521 $form->{fromdate} = "1.10.$form->{year}";
522 $form->{todate} = "31.12.$form->{year}";
527 $form->{duetyp} eq "1" && do {
528 $form->{fromdate} = "1.1.$form->{year}";
529 $form->{todate} = "31.1.$form->{year}";
532 $form->{duetyp} eq "2" && do {
533 $form->{fromdate} = "1.2.$form->{year}";
535 #this works from 1901 to 2099, 1900 and 2100 fail.
536 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
537 $form->{todate} = "$leap.2.$form->{year}";
540 $form->{duetyp} eq "3" && do {
541 $form->{fromdate} = "1.3.$form->{year}";
542 $form->{todate} = "31.3.$form->{year}";
545 $form->{duetyp} eq "4" && do {
546 $form->{fromdate} = "1.4.$form->{year}";
547 $form->{todate} = "30.4.$form->{year}";
550 $form->{duetyp} eq "5" && do {
551 $form->{fromdate} = "1.5.$form->{year}";
552 $form->{todate} = "31.5.$form->{year}";
555 $form->{duetyp} eq "6" && do {
556 $form->{fromdate} = "1.6.$form->{year}";
557 $form->{todate} = "30.6.$form->{year}";
560 $form->{duetyp} eq "7" && do {
561 $form->{fromdate} = "1.7.$form->{year}";
562 $form->{todate} = "31.7.$form->{year}";
565 $form->{duetyp} eq "8" && do {
566 $form->{fromdate} = "1.8.$form->{year}";
567 $form->{todate} = "31.8.$form->{year}";
570 $form->{duetyp} eq "9" && do {
571 $form->{fromdate} = "1.9.$form->{year}";
572 $form->{todate} = "30.9.$form->{year}";
575 $form->{duetyp} eq "10" && do {
576 $form->{fromdate} = "1.10.$form->{year}";
577 $form->{todate} = "31.10.$form->{year}";
580 $form->{duetyp} eq "11" && do {
581 $form->{fromdate} = "1.11.$form->{year}";
582 $form->{todate} = "30.11.$form->{year}";
585 $form->{duetyp} eq "12" && do {
586 $form->{fromdate} = "1.12.$form->{year}";
587 $form->{todate} = "31.12.$form->{year}";
591 hotfix_reformat_date();
595 # get for each account initial balance, debits and credits
596 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
599 $form->{rowcount} = scalar @{ $form->{TB} || [] };
600 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
603 "accno", "description",
604 "last_transaction", "soll_eb",
607 "soll_kumuliert", "haben_kumuliert",
608 "soll_saldo", "haben_saldo"
612 my $attachment_basename = $locale->text('trial_balance');
613 my $report = SL::ReportGenerator->new(\%myconfig, $form);
615 my @hidden_variables = qw(fromdate todate year cash);
617 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
620 'accno' => { 'text' => $locale->text('Account'), },
621 'description' => { 'text' => $locale->text('Description'), },
622 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
623 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
624 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
625 'soll' => { 'text' => $locale->text('Debit'), },
626 'haben' => { 'text' => $locale->text('Credit'), },
627 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
628 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
629 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
630 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
635 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
637 map { $column_defs{$_}->{visible} = 1 } @columns;
639 $report->set_columns(%column_defs);
640 $report->set_column_order(@columns);
642 $report->set_export_options('generate_trial_balance', @hidden_variables);
647 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
649 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
650 push (@options, $form->{print_date});
652 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
653 push (@options, $form->{company});
656 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
658 my @custom_headers = ([
659 { text => $::locale->text('Account'), rowspan => 2, },
660 { text => $::locale->text('Description'), rowspan => 2, },
661 { text => $::locale->text('Last Transaction'), rowspan => 2, },
662 { text => $::locale->text('Starting Balance'), colspan => 2, },
663 { text => $::locale->text('Sum for') . " $form->{template_fromto}", colspan => 2, },
664 { text => $::locale->text('Sum per') . " $form->{template_to}", colspan => 2, },
665 { text => $::locale->text('Saldo per') . " $form->{template_to}", colspan => 2, },
670 { text => $::locale->text('Assets'), },
671 { text => $::locale->text('Equity'), },
672 { text => $::locale->text('Debit'), },
673 { text => $::locale->text('Credit'), },
674 { text => $::locale->text('Debit'), },
675 { text => $::locale->text('Credit'), },
676 { text => $::locale->text('Debit'), },
677 { text => $::locale->text('Credit'), },
680 $report->set_options('output_format' => 'HTML',
681 'top_info_text' => join("\n", @options),
682 'title' => $form->{title},
683 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
684 'html_template' => 'rp/html_report_susa',
685 'pdf_template' => 'rp/html_report_susa',
687 $report->set_custom_headers(@custom_headers);
688 $report->set_options_from_form();
689 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
691 # add sort and escape callback, this one we use for the add sub
692 $form->{callback} = $href .= "&sort=$form->{sort}";
694 # escape callback for href
695 my $callback = $form->escape($href);
697 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
699 my %totals = map { $_ => 0 } @subtotal_columns;
701 my $edit_url = build_std_url('action=edit', 'type', 'vc');
704 foreach my $accno (@{ $form->{TB} || [] }) {
706 $accno->{soll} = $accno->{debit};
707 $accno->{haben} = $accno->{credit};
708 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
710 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
711 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
715 foreach my $column (@columns) {
717 'data' => $accno->{$column},
718 'align' => $column_alignment{$column},
722 $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}));
724 my $row_set = [ $row ];
727 $report->add_data($row_set);
732 $report->add_separator();
734 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
736 $report->generate_with_headers();
738 $main::lxdebug->leave_sub();
742 sub create_subtotal_row {
743 $main::lxdebug->enter_sub();
745 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
747 my $form = $main::form;
748 my %myconfig = %main::myconfig;
749 my $locale = $main::locale;
751 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
753 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
755 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
757 map { $totals->{$_} = 0 } @{ $subtotal_columns };
759 $main::lxdebug->leave_sub();
764 sub create_list_accounts_subtotal_row {
765 $main::lxdebug->enter_sub();
767 my ($subtotals, $columns, $fields, $class) = @_;
769 my $form = $main::form;
770 my %myconfig = %main::myconfig;
771 my $locale = $main::locale;
773 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
775 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
777 $main::lxdebug->leave_sub();
783 $main::lxdebug->enter_sub();
787 my $form = $main::form;
788 my %myconfig = %main::myconfig;
789 my $locale = $main::locale;
792 if ($form->{department}) {
793 my ($department) = split /--/, $form->{department};
794 push @options, $locale->text('Department') . " : $department";
796 if ($form->{projectnumber}) {
797 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
800 # if there are any dates
801 if ($form->{fromdate} || $form->{todate}) {
802 my ($fromdate, $todate);
804 if ($form->{fromdate}) {
805 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
807 if ($form->{todate}) {
808 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
811 push @options, "$fromdate - $todate";
814 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
817 my @columns = qw(accno description begbalance debit credit endbalance);
819 'accno' => { 'text' => $locale->text('Account'), },
820 'description' => { 'text' => $locale->text('Description'), },
821 'debit' => { 'text' => $locale->text('Debit'), },
822 'credit' => { 'text' => $locale->text('Credit'), },
823 'begbalance' => { 'text' => $locale->text('Balance'), },
824 'endbalance' => { 'text' => $locale->text('Balance'), },
826 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
828 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
830 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
832 my $report = SL::ReportGenerator->new(\%myconfig, $form);
834 $report->set_options('top_info_text' => join("\n", @options),
835 'output_format' => 'HTML',
836 'title' => $form->{title},
837 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
838 'std_column_visibility' => 1,
840 $report->set_options_from_form();
841 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
843 $report->set_columns(%column_defs);
844 $report->set_column_order(@columns);
846 $report->set_export_options($action, @hidden_variables);
848 my @totals_columns = qw(credit debit begbalance endbalance);
849 my %subtotals = map { $_ => 0 } @totals_columns;
850 my %totals = map { $_ => 0 } @totals_columns;
851 my $found_heading = 0;
852 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
854 # sort the whole thing by account numbers and display
855 foreach my $idx (0 .. scalar(@tb) - 1) {
857 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
859 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
861 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
863 if ($ref->{charttype} eq 'H') {
864 next unless ($form->{l_heading});
866 %subtotals = map { $_ => 0 } @totals_columns;
868 $row->{description}->{class} = 'listheading';
869 $row->{description}->{data} = $ref->{description};
871 $report->add_data($row);
876 foreach (qw(debit credit)) {
877 $subtotals{$_} += $ref->{$_};
878 $totals{$_} += $ref->{$_};
881 $subtotals{begbalance} += $ref->{balance} * $ml;
882 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
884 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
885 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
887 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
888 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
890 $report->add_data($row);
892 if ($form->{l_heading} && $found_heading &&
893 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
894 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
898 $report->add_separator();
900 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
902 $report->generate_with_headers();
904 $main::lxdebug->leave_sub();
907 sub generate_ar_aging {
908 $main::lxdebug->enter_sub();
910 $main::auth->assert('general_ledger');
912 my $form = $main::form;
913 my %myconfig = %main::myconfig;
914 my $locale = $main::locale;
917 ($form->{customer}) = split(/--/, $form->{customer});
919 $form->{ct} = "customer";
920 $form->{arap} = "ar";
922 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
924 RP->aging(\%myconfig, \%$form);
927 $main::lxdebug->leave_sub();
930 sub generate_ap_aging {
931 $main::lxdebug->enter_sub();
933 $main::auth->assert('general_ledger');
935 my $form = $main::form;
936 my %myconfig = %main::myconfig;
937 my $locale = $main::locale;
940 ($form->{vendor}) = split(/--/, $form->{vendor});
942 $form->{ct} = "vendor";
943 $form->{arap} = "ap";
945 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
947 RP->aging(\%myconfig, \%$form);
950 $main::lxdebug->leave_sub();
953 sub create_aging_subtotal_row {
954 $main::lxdebug->enter_sub();
956 my ($subtotals, $columns, $periods, $class) = @_;
958 my $form = $main::form;
959 my %myconfig = %main::myconfig;
960 my $locale = $main::locale;
962 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
964 foreach (@{ $periods }) {
965 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
966 $subtotals->{$_} = 0;
969 $main::lxdebug->leave_sub();
975 $main::lxdebug->enter_sub();
977 $main::auth->assert('general_ledger');
979 my $form = $main::form;
980 my %myconfig = %main::myconfig;
981 my $locale = $main::locale;
982 my $cgi = $::request->{cgi};
984 my $report = SL::ReportGenerator->new(\%myconfig, $form);
986 my @columns = qw(statement ct invnumber transdate duedate amount open);
989 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
990 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
991 'invnumber' => { 'text' => $locale->text('Invoice'), },
992 'transdate' => { 'text' => $locale->text('Date'), },
993 'duedate' => { 'text' => $locale->text('Due'), },
994 'amount' => { 'text' => $locale->text('Amount'), },
995 'open' => { 'text' => $locale->text('Open'), },
998 my %column_alignment = ('statement' => 'center',
999 map { $_ => 'right' } qw(open amount));
1001 $report->set_options('std_column_visibility' => 1);
1002 $report->set_columns(%column_defs);
1003 $report->set_column_order(@columns);
1005 my @hidden_variables = qw(todate customer vendor arap title ct);
1006 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1009 my $attachment_basename;
1011 if ($form->{department}) {
1012 my ($department) = split /--/, $form->{department};
1013 push @options, $locale->text('Department') . " : $department";
1014 $form->{callback} .= "&department=" . E($department);
1017 if (($form->{arap} eq 'ar') && $form->{customer}) {
1018 push @options, $form->{customer};
1019 $attachment_basename = $locale->text('ar_aging_list');
1020 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1023 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1024 push @options, $form->{vendor};
1025 $attachment_basename = $locale->text('ap_aging_list');
1026 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1029 if ($form->{fromdate}) {
1030 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1032 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1035 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1037 $report->set_options('top_info_text' => join("\n", @options),
1038 'output_format' => 'HTML',
1039 'title' => $form->{title},
1040 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1042 $report->set_options_from_form();
1043 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1045 my $previous_ctid = 0;
1047 my @periods = qw(open amount);
1048 my %subtotals = map { $_ => 0 } @periods;
1049 my %totals = map { $_ => 0 } @periods;
1051 foreach my $ref (@{ $form->{AG} }) {
1052 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1053 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1056 foreach my $key (@periods) {
1057 $subtotals{$key} += $ref->{"$key"};
1058 $totals{$key} += $ref->{"$key"};
1059 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1064 foreach my $column (@columns) {
1066 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1067 'align' => $column_alignment{$column},
1068 'valign' => $column eq 'statement' ? 'center' : '',
1072 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1074 if ($previous_ctid != $ref->{ctid}) {
1075 $row->{statement}->{raw_data} =
1076 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1077 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1078 $row->{ct}->{data} = $ref->{name};
1083 $previous_ctid = $ref->{ctid};
1085 $report->add_data($row);
1088 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1090 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1092 if ($form->{arap} eq 'ar') {
1093 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1094 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1095 'PRINT_OPTIONS' => print_options(inline => 1), });
1096 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1097 'raw_bottom_info_text' => $raw_bottom_info_text);
1100 $report->generate_with_headers();
1102 $main::lxdebug->leave_sub();
1106 $main::lxdebug->enter_sub();
1108 my $form = $main::form;
1109 my %myconfig = %main::myconfig;
1110 my $locale = $main::locale;
1112 RP->aging(\%myconfig, \%$form);
1114 map { $_->{checked} = "checked" } @{ $form->{AG} };
1118 $main::lxdebug->leave_sub();
1122 $::lxdebug->enter_sub;
1123 $::auth->assert('general_ledger');
1125 # get name and email addresses
1127 for my $i (1 .. $::form->{rowcount}) {
1128 next unless $::form->{"statement_$i"};
1129 $::form->{"$::form->{ct}_id"} = $::form->{"$::form->{ct}_id_$i"};
1130 RP->get_customer(\%::myconfig, $::form);
1135 $::form->error($::locale->text('Nothing selected!')) unless $selected;
1137 $::form->{media} = "email";
1139 # save all other variables
1141 for my $key (keys %$::form) {
1142 next if any { $key eq $_ } qw(login password action email cc bcc subject message type sendmode format header);
1143 next unless '' eq ref $::form->{$key};
1144 push @hidden_values, $key;
1148 print $::form->parse_html_template('rp/e_mail', {
1149 show_bcc => $::auth->assert('email_bcc', 'may fail'),
1150 print_options => print_options(inline => 1),
1151 hidden_values => \@hidden_values,
1154 $::lxdebug->leave_sub;
1158 $main::lxdebug->enter_sub();
1160 $main::auth->assert('general_ledger');
1162 my $form = $main::form;
1163 my %myconfig = %main::myconfig;
1164 my $locale = $main::locale;
1166 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1167 unless $form->{subject};
1169 RP->aging(\%myconfig, \%$form);
1171 $form->{"statement_1"} = 1;
1173 $form->{media} = 'email';
1176 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1178 $main::lxdebug->leave_sub();
1182 $main::lxdebug->enter_sub();
1184 $main::auth->assert('general_ledger');
1186 my $form = $main::form;
1187 my %myconfig = %main::myconfig;
1188 my $locale = $main::locale;
1190 if ($form->{media} eq 'printer') {
1191 $form->error($locale->text('Select postscript or PDF!'))
1192 if ($form->{format} !~ /(postscript|pdf)/);
1196 for my $i (1 .. $form->{rowcount}) {
1197 if ($form->{"statement_$i"}) {
1198 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1204 $form->error($locale->text('Nothing selected!')) unless $selected;
1206 if ($form->{media} eq 'printer') {
1207 $form->{"$form->{ct}_id"} = "";
1209 $form->{"statement_1"} = 1;
1212 RP->aging(\%myconfig, \%$form);
1216 $form->redirect($locale->text('Statements sent to printer!'))
1217 if ($form->{media} eq 'printer');
1219 $main::lxdebug->leave_sub();
1223 $main::lxdebug->enter_sub();
1225 $main::auth->assert('general_ledger');
1227 my $form = $main::form;
1228 my %myconfig = %main::myconfig;
1229 my $locale = $main::locale;
1231 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1233 $form->{templates} = "$myconfig{templates}";
1235 my $suffix = "html";
1236 my $attachment_suffix = "html";
1237 if ($form->{format} eq 'postscript') {
1238 $form->{postscript} = 1;
1240 $attachment_suffix = "ps";
1241 } elsif ($form->{format} eq 'pdf') {
1244 $attachment_suffix = "pdf";
1247 $form->{IN} = "$form->{type}.$suffix";
1248 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1250 # Save $form->{email} because it will be overwritten.
1251 $form->{EMAIL_RECIPIENT} = $form->{email};
1255 while (@{ $form->{AG} }) {
1257 my $ref = shift @{ $form->{AG} };
1259 if ($ctid != $ref->{ctid}) {
1261 $ctid = $ref->{ctid};
1264 if ($form->{"statement_$i"}) {
1267 ("name", "street", "zipcode", "city", "country", "contact", "email",
1268 "$form->{ct}phone", "$form->{ct}fax");
1269 map { $form->{$_} = $ref->{$_} } @a;
1271 $form->{ $form->{ct} } = $form->{name};
1272 $form->{"$form->{ct}_id"} = $ref->{ctid};
1274 map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
1276 foreach my $item (qw(c0 c30 c60 c90)) {
1277 $form->{$item} = ();
1278 $form->{"${item}total"} = 0;
1281 &statement_details($ref);
1285 if (scalar(@{ $form->{AG} }) > 0) {
1287 # one or more left to go
1288 if ($ctid == $form->{AG}->[0]->{ctid}) {
1289 $ref = shift @{ $form->{AG} };
1290 &statement_details($ref);
1293 $ref = scalar(@{ $form->{AG} });
1299 # set initial ref to 0
1306 $form->{"${_}total"} =
1307 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1308 } ('c0', 'c30', 'c60', 'c90', "");
1310 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1311 $form->{attachment_filename} =~ s/\s+/_/g;
1313 $form->parse_template(\%myconfig);
1318 # saving the history
1319 if(!exists $form->{addition} && $form->{id} ne "") {
1320 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1321 $form->{addition} = "PRINTED";
1322 $form->{what_done} = $form->{type};
1323 $form->save_history;
1325 # /saving the history
1326 $main::lxdebug->leave_sub();
1329 sub statement_details {
1330 $main::lxdebug->enter_sub();
1332 $main::auth->assert('general_ledger');
1334 my $form = $main::form;
1335 my %myconfig = %main::myconfig;
1336 my $locale = $main::locale;
1340 push @{ $form->{invnumber} }, $ref->{invnumber};
1341 push @{ $form->{invdate} }, $ref->{transdate};
1342 push @{ $form->{duedate} }, $ref->{duedate};
1343 push @{ $form->{amount} }, $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
1344 push @{ $form->{open} }, $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
1346 foreach my $item (qw(c0 c30 c60 c90)) {
1347 if ($ref->{exchangerate} * 1) {
1348 # add only the open amount of the invoice to the aging, not the total amount
1349 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
1350 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
1351 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
1352 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
1354 $form->{"${item}total"} += $ref->{$item};
1355 $form->{total} += $ref->{$item};
1356 push @{ $form->{$item} },
1357 $form->format_amount(\%myconfig, $ref->{$item}, 2);
1360 $main::lxdebug->leave_sub();
1363 sub generate_tax_report {
1364 $::lxdebug->enter_sub;
1365 $::auth->assert('report');
1367 RP->tax_report(\%::myconfig, $::form);
1369 my $descvar = "$::form->{accno}_description";
1370 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
1374 my $callback = build_std_url('action=generate_tax_report', $descvar,
1375 qw(fromdate todate db method accno department report title));
1377 my @columns = $::form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1380 for my $item (@columns, 'subtotal') {
1381 if ($::form->{"l_$item"} eq "Y") {
1382 $callback .= "&l_$item=Y";
1383 $href .= "&l_$item=Y";
1387 for my $item (@columns) {
1388 if ($::form->{"l_$item"} eq "Y") {
1389 push @column_index, $item;
1394 if ($::form->{department}) {
1395 my ($department) = split /--/, $::form->{department};
1396 push @options, $::locale->text('Department') . " : $department";
1399 # if there are any dates
1400 if ($::form->{fromdate} || $::form->{todate}) {
1401 my $fromdate = $::form->{fromdate} ? $::locale->date(\%::myconfig, $::form->{fromdate}, 1) : '';
1402 my $todate = $::form->{todate} ? $::locale->date(\%::myconfig, $::form->{todate}, 1) : '';
1403 push @options, "$fromdate - $todate";
1405 push @options, $::locale->date(\%::myconfig, $::form->current_date, 1);
1408 my ($name, $invoice, $arap);
1409 if ($::form->{db} eq 'ar') {
1410 $name = $::locale->text('Customer');
1414 if ($::form->{db} eq 'ap') {
1415 $name = $::locale->text('Vendor');
1420 my %column_header = (
1421 id => $::locale->text('ID'),
1422 invnumber => $::locale->text('Invoice'),
1423 transdate => $::locale->text('Date'),
1424 netamount => $::locale->text('Amount'),
1425 tax => $::locale->text('Tax'),
1426 amount => $::locale->text('Total'),
1430 my %column_sorted = map { $_ => 1 } qw(id invnumber transdate);
1432 $callback .= "&sort=$::form->{sort}";
1435 if (@{ $::form->{TR} }) {
1436 $sameitem = $::form->{TR}->[0]->{ $::form->{sort} };
1439 my ($totalnetamount, $totaltax, @data);
1440 for my $ref (@{ $::form->{TR} }) {
1442 my $module = ($ref->{invoice}) ? $invoice : $arap;
1444 if ($::form->{l_subtotal} eq 'Y') {
1445 if ($sameitem ne $ref->{ $::form->{sort} }) {
1448 netamount => $subtotalnetamount,
1449 tax => $subtotaltax,
1450 amount => $subtotal,
1452 $subtotalnetamount = 0;
1454 $sameitem = $ref->{ $::form->{sort} };
1458 $subtotalnetamount += $ref->{netamount};
1459 $subtotaltax += $ref->{tax};
1460 $totalnetamount += $ref->{netamount};
1461 $totaltax += $ref->{tax};
1462 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1464 push @data, { map { $_ => { data => $ref->{$_} } } keys %$ref };
1465 $data[-1]{invnumber}{link} = "$module?action=edit&id=$ref->{id}&callback=$callback";
1466 $data[-1]{$_}{numeric} = 1 for qw(netamount tax amount);
1469 if ($::form->{l_subtotal} eq 'Y') {
1472 netamount => $subtotalnetamount,
1473 tax => $subtotaltax,
1474 amount => $subtotal,
1480 netamount => $totalnetamount,
1482 amount => $totalnetamount + $totaltax,
1486 print $::form->parse_html_template('rp/tax_report', {
1487 column_index => \@column_index,
1488 column_header => \%column_header,
1489 column_sorted => \%column_sorted,
1492 options => \@options,
1495 $::lxdebug->leave_sub;
1499 $main::lxdebug->enter_sub();
1501 $main::auth->assert('cash');
1503 my $form = $main::form;
1504 my %myconfig = %main::myconfig;
1505 my $locale = $main::locale;
1507 if ($form->{account}) {
1508 ($form->{paymentaccounts}) = split /--/, $form->{account};
1512 if ($form->{department}) {
1513 (my $department, $form->{department_id}) = split /--/, $form->{department};
1514 $option = $locale->text('Department') . " : $department";
1517 report_generator_set_default_sort('transdate', 1);
1519 RP->payments(\%myconfig, \%$form);
1521 my @hidden_variables = qw(account title department reference source memo fromdate todate
1522 fx_transaction db prepayment paymentaccounts sort);
1524 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
1525 $form->{callback} = $href;
1527 my @columns = qw(transdate invnumber name paid source memo);
1529 'name' => { 'text' => $locale->text('Description'), },
1530 'invnumber' => { 'text' => $locale->text('Reference'), },
1531 'transdate' => { 'text' => $locale->text('Date'), },
1532 'paid' => { 'text' => $locale->text('Amount'), },
1533 'source' => { 'text' => $locale->text('Source'), },
1534 'memo' => { 'text' => $locale->text('Memo'), },
1536 my %column_alignment = ('paid' => 'right');
1538 foreach my $name (grep { $_ ne 'paid' } @columns) {
1539 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1540 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
1544 if ($form->{fromdate}) {
1545 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
1547 if ($form->{todate}) {
1548 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1551 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1553 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
1555 $report->set_options('top_info_text' => join("\n", @options),
1556 'output_format' => 'HTML',
1557 'title' => $form->{title},
1558 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1559 'std_column_visibility' => 1,
1561 $report->set_options_from_form();
1563 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1565 $report->set_columns(%column_defs);
1566 $report->set_column_order(@columns);
1568 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
1570 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1574 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1575 next unless @{ $form->{ $ref->{id} } };
1577 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
1579 my $subtotal_paid = 0;
1581 foreach my $payment (@{ $form->{ $ref->{id} } }) {
1582 my $module = $payment->{module};
1583 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1584 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1586 $subtotal_paid += $payment->{paid};
1587 $total_paid += $payment->{paid};
1589 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
1593 foreach my $column (@columns) {
1595 'data' => $payment->{$column},
1596 'align' => $column_alignment{$column},
1600 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
1602 $report->add_data($row);
1605 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
1607 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
1609 'class' => 'listsubtotal',
1612 $report->add_data($row);
1615 $report->add_separator();
1617 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
1619 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
1621 'class' => 'listtotal',
1624 $report->add_data($row);
1626 $report->generate_with_headers();
1628 $main::lxdebug->leave_sub();
1632 $::lxdebug->enter_sub;
1634 my ($dont_print) = @_;
1636 $::form->{sendmode} = "attachment";
1637 $::form->{format} ||= $::myconfig{template_format} || "pdf";
1638 $::form->{copies} ||= $::myconfig{copies} || 2;
1640 $::form->{PD}{ $::form->{type} } = "selected";
1641 $::form->{DF}{ $::form->{format} } = "selected";
1642 $::form->{OP}{ $::form->{media} } = "selected";
1643 $::form->{SM}{ $::form->{sendmode} } = "selected";
1645 my $output = $::form->parse_html_template('rp/print_options', {
1646 got_printer => $::myconfig{printer},
1647 show_latex => $::lx_office_conf{print_templates}->{latex},
1648 is_email => $::form->{media} eq 'email',
1651 print $output unless $dont_print;
1653 $::lxdebug->leave_sub;
1659 $main::lxdebug->enter_sub();
1661 $main::auth->assert('report');
1663 my $form = $main::form;
1664 my %myconfig = %main::myconfig;
1665 my $locale = $main::locale;
1667 $form->{padding} = " ";
1668 $form->{bold} = "<b>";
1669 $form->{endbold} = "</b>";
1670 $form->{br} = "<br>";
1672 if ($form->{reporttype} eq "custom") {
1674 #forgotten the year --> thisyear
1675 if ($form->{year} !~ m/^\d\d\d\d$/) {
1676 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1682 if ($form->{duetyp} eq "13") {
1683 $form->{fromdate} = "1.1.$form->{year}";
1684 $form->{todate} = "31.12.$form->{year}";
1685 $form->{comparefromdate} = "1.01.$form->{year}";
1686 $form->{comparetodate} = "31.12.$form->{year}";
1690 if ($form->{duetyp} eq "A") {
1691 $form->{fromdate} = "1.1.$form->{year}";
1692 $form->{todate} = "31.3.$form->{year}";
1693 $form->{comparefromdate} = "1.01.$form->{year}";
1694 $form->{comparetodate} = "31.03.$form->{year}";
1696 if ($form->{duetyp} eq "B") {
1697 $form->{fromdate} = "1.4.$form->{year}";
1698 $form->{todate} = "30.6.$form->{year}";
1699 $form->{comparefromdate} = "1.01.$form->{year}";
1700 $form->{comparetodate} = "30.06.$form->{year}";
1702 if ($form->{duetyp} eq "C") {
1703 $form->{fromdate} = "1.7.$form->{year}";
1704 $form->{todate} = "30.9.$form->{year}";
1705 $form->{comparefromdate} = "1.01.$form->{year}";
1706 $form->{comparetodate} = "30.09.$form->{year}";
1708 if ($form->{duetyp} eq "D") {
1709 $form->{fromdate} = "1.10.$form->{year}";
1710 $form->{todate} = "31.12.$form->{year}";
1711 $form->{comparefromdate} = "1.01.$form->{year}";
1712 $form->{comparetodate} = "31.12.$form->{year}";
1717 $form->{duetyp} eq "1" && do {
1718 $form->{fromdate} = "1.1.$form->{year}";
1719 $form->{todate} = "31.1.$form->{year}";
1720 $form->{comparefromdate} = "1.01.$form->{year}";
1721 $form->{comparetodate} = "31.01.$form->{year}";
1724 $form->{duetyp} eq "2" && do {
1725 $form->{fromdate} = "1.2.$form->{year}";
1727 #this works from 1901 to 2099, 1900 and 2100 fail.
1728 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1729 $form->{todate} = "$leap.2.$form->{year}";
1730 $form->{comparefromdate} = "1.01.$form->{year}";
1731 $form->{comparetodate} = "$leap.02.$form->{year}";
1734 $form->{duetyp} eq "3" && do {
1735 $form->{fromdate} = "1.3.$form->{year}";
1736 $form->{todate} = "31.3.$form->{year}";
1737 $form->{comparefromdate} = "1.01.$form->{year}";
1738 $form->{comparetodate} = "31.03.$form->{year}";
1741 $form->{duetyp} eq "4" && do {
1742 $form->{fromdate} = "1.4.$form->{year}";
1743 $form->{todate} = "30.4.$form->{year}";
1744 $form->{comparefromdate} = "1.01.$form->{year}";
1745 $form->{comparetodate} = "30.04.$form->{year}";
1748 $form->{duetyp} eq "5" && do {
1749 $form->{fromdate} = "1.5.$form->{year}";
1750 $form->{todate} = "31.5.$form->{year}";
1751 $form->{comparefromdate} = "1.01.$form->{year}";
1752 $form->{comparetodate} = "31.05.$form->{year}";
1755 $form->{duetyp} eq "6" && do {
1756 $form->{fromdate} = "1.6.$form->{year}";
1757 $form->{todate} = "30.6.$form->{year}";
1758 $form->{comparefromdate} = "1.01.$form->{year}";
1759 $form->{comparetodate} = "30.06.$form->{year}";
1762 $form->{duetyp} eq "7" && do {
1763 $form->{fromdate} = "1.7.$form->{year}";
1764 $form->{todate} = "31.7.$form->{year}";
1765 $form->{comparefromdate} = "1.01.$form->{year}";
1766 $form->{comparetodate} = "31.07.$form->{year}";
1769 $form->{duetyp} eq "8" && do {
1770 $form->{fromdate} = "1.8.$form->{year}";
1771 $form->{todate} = "31.8.$form->{year}";
1772 $form->{comparefromdate} = "1.01.$form->{year}";
1773 $form->{comparetodate} = "31.08.$form->{year}";
1776 $form->{duetyp} eq "9" && do {
1777 $form->{fromdate} = "1.9.$form->{year}";
1778 $form->{todate} = "30.9.$form->{year}";
1779 $form->{comparefromdate} = "1.01.$form->{year}";
1780 $form->{comparetodate} = "30.09.$form->{year}";
1783 $form->{duetyp} eq "10" && do {
1784 $form->{fromdate} = "1.10.$form->{year}";
1785 $form->{todate} = "31.10.$form->{year}";
1786 $form->{comparefromdate} = "1.01.$form->{year}";
1787 $form->{comparetodate} = "31.10.$form->{year}";
1790 $form->{duetyp} eq "11" && do {
1791 $form->{fromdate} = "1.11.$form->{year}";
1792 $form->{todate} = "30.11.$form->{year}";
1793 $form->{comparefromdate} = "1.01.$form->{year}";
1794 $form->{comparetodate} = "30.11.$form->{year}";
1797 $form->{duetyp} eq "12" && do {
1798 $form->{fromdate} = "1.12.$form->{year}";
1799 $form->{todate} = "31.12.$form->{year}";
1800 $form->{comparefromdate} = "1.01.$form->{year}";
1801 $form->{comparetodate} = "31.12.$form->{year}";
1805 hotfix_reformat_date();
1807 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
1808 # ansonsten ist die prüfung in RP.pm
1809 # if (defined ($form->{fromdate|todate}=='..'))
1811 if ($form->{fromdate}){
1812 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
1813 my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
1814 $datetime->set( month => 1,
1816 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
1818 if ($form->{todate}){
1819 $form->{comparetodate} = $form->{todate};
1823 RP->bwa(\%myconfig, \%$form);
1825 ($form->{department}) = split /--/, $form->{department};
1828 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1829 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1831 # if there are any dates construct a where
1832 if ($form->{fromdate} || $form->{todate}) {
1834 unless ($form->{todate}) {
1835 $form->{todate} = $form->current_date(\%myconfig);
1838 my %germandate = ("dateformat" => "dd.mm.yyyy");
1840 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
1841 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
1843 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
1844 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
1846 $form->{this_period} = "$shortfromdate\n$shorttodate";
1848 $locale->text('for Period')
1849 . qq|\n$longfromdate |
1850 . $locale->text('bis')
1854 # setup variables for the form
1855 my @a = qw(company address businessnumber);
1856 map { $form->{$_} = $myconfig{$_} } @a;
1857 $form->{templates} = $myconfig{templates};
1859 $form->{IN} = "bwa.html";
1861 $form->parse_template;
1863 $main::lxdebug->leave_sub();
1866 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
1867 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
1868 sub hotfix_reformat_date {
1870 $main::lxdebug->enter_sub();
1872 my $form = $main::form;
1873 my %myconfig = %main::myconfig;
1874 my $locale = $main::locale;
1876 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
1877 my $current_dateformat = $myconfig{dateformat};
1878 $myconfig{dateformat} = 'dd.mm.yyyy';
1879 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
1880 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
1881 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
1882 unless (!defined ($form->{comparefromdate}));
1883 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
1884 unless (!defined ($form->{comparetodate}));
1886 # Und wieder zurücksetzen
1887 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
1888 } # Ende Hotifx Bug 1388
1890 $main::lxdebug->leave_sub();