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 $is_projects = $::form->{report} eq "projects";
155 my $is_income_statement = $::form->{report} eq "income_statement";
156 my $is_bwa = $::form->{report} eq "bwa";
157 my $is_balance_sheet = $::form->{report} eq "balance_sheet";
158 my $is_trial_balance = $::form->{report} eq "trial_balance";
159 my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
160 my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
162 my ($label, $nextsub, $vc);
164 my $is_sales = $::form->{report} eq 'ar_aging';
165 $label = $is_sales ? $::locale->text('Customer') : $::locale->text('Vendor');
166 $::form->{vc} = $is_sales ? 'customer' : 'vendor';
168 $nextsub = "generate_$::form->{report}";
171 $::form->all_vc(\%::myconfig, $::form->{vc}, $is_sales ? "AR" : "AP");
172 $vc .= "<option>$_->{name}--$_->{id}\n" for @{ $::form->{"all_$::form->{vc}"} };
174 ? qq|<select name=$::form->{vc}><option>\n$vc</select>|
175 : qq|<input name=$::form->{vc} size=35>|;
178 my ($selection, $paymentaccounts);
180 $::form->{db} = $::form->{report} =~ /payments$/ ? "ap" : "ar";
182 RP->paymentaccounts(\%::myconfig, $::form);
184 $selection = "<option>\n";
185 for my $ref (@{ $::form->{PR} }) {
186 $paymentaccounts .= "$ref->{accno} ";
187 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
192 print $::form->parse_html_template('rp/report', {
193 paymentaccounts => $paymentaccounts,
194 selection => $selection,
195 is_aging => $is_aging,
198 year => DateTime->today->year,
199 today => DateTime->today,
201 accrual => $::instance_conf->get_accounting_method ne 'cash',
202 cash => $::instance_conf->get_accounting_method eq 'cash',
203 is_payments => $is_payments,
204 is_trial_balance => $is_trial_balance,
205 is_balance_sheet => $is_balance_sheet,
207 is_income_statement => $is_income_statement,
208 is_projects => $is_projects,
211 $::lxdebug->leave_sub;
214 sub continue { call_sub($main::form->{"nextsub"}); }
217 $main::lxdebug->enter_sub();
219 $main::auth->assert('report');
221 my $form = $main::form;
222 my %myconfig = %main::myconfig;
223 my $locale = $main::locale;
227 $form->{project_id} = $form->{project_id_1};
228 if ($form->{projectnumber} && !$form->{project_id}) {
229 $form->{rowcount} = 1;
231 # call this instead of update
232 $form->{update} = $nextsub;
233 $form->{projectnumber_1} = $form->{projectnumber};
235 delete $form->{sort};
236 check_project('generate_projects');
238 # if there is one only, assign id
239 $form->{project_id} = $form->{project_id_1};
242 $main::lxdebug->leave_sub();
245 sub generate_income_statement {
246 $main::lxdebug->enter_sub();
248 $main::auth->assert('report');
250 my $form = $main::form;
251 my %myconfig = %main::myconfig;
252 my $locale = $main::locale;
254 $form->{padding} = " ";
255 $form->{bold} = "<b>";
256 $form->{endbold} = "</b>";
257 $form->{br} = "<br>";
259 if ($form->{reporttype} eq "custom") {
261 #forgotten the year --> thisyear
262 if ($form->{year} !~ m/^\d\d\d\d$/) {
263 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
269 if ($form->{duetyp} eq "13") {
270 $form->{fromdate} = "1.1.$form->{year}";
271 $form->{todate} = "31.12.$form->{year}";
275 if ($form->{duetyp} eq "A") {
276 $form->{fromdate} = "1.1.$form->{year}";
277 $form->{todate} = "31.3.$form->{year}";
279 if ($form->{duetyp} eq "B") {
280 $form->{fromdate} = "1.4.$form->{year}";
281 $form->{todate} = "30.6.$form->{year}";
283 if ($form->{duetyp} eq "C") {
284 $form->{fromdate} = "1.7.$form->{year}";
285 $form->{todate} = "30.9.$form->{year}";
287 if ($form->{duetyp} eq "D") {
288 $form->{fromdate} = "1.10.$form->{year}";
289 $form->{todate} = "31.12.$form->{year}";
294 $form->{duetyp} eq "1" && do {
295 $form->{fromdate} = "1.1.$form->{year}";
296 $form->{todate} = "31.1.$form->{year}";
299 $form->{duetyp} eq "2" && do {
300 $form->{fromdate} = "1.2.$form->{year}";
302 #this works from 1901 to 2099, 1900 and 2100 fail.
303 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
304 $form->{todate} = "$leap.2.$form->{year}";
307 $form->{duetyp} eq "3" && do {
308 $form->{fromdate} = "1.3.$form->{year}";
309 $form->{todate} = "31.3.$form->{year}";
312 $form->{duetyp} eq "4" && do {
313 $form->{fromdate} = "1.4.$form->{year}";
314 $form->{todate} = "30.4.$form->{year}";
317 $form->{duetyp} eq "5" && do {
318 $form->{fromdate} = "1.5.$form->{year}";
319 $form->{todate} = "31.5.$form->{year}";
322 $form->{duetyp} eq "6" && do {
323 $form->{fromdate} = "1.6.$form->{year}";
324 $form->{todate} = "30.6.$form->{year}";
327 $form->{duetyp} eq "7" && do {
328 $form->{fromdate} = "1.7.$form->{year}";
329 $form->{todate} = "31.7.$form->{year}";
332 $form->{duetyp} eq "8" && do {
333 $form->{fromdate} = "1.8.$form->{year}";
334 $form->{todate} = "31.8.$form->{year}";
337 $form->{duetyp} eq "9" && do {
338 $form->{fromdate} = "1.9.$form->{year}";
339 $form->{todate} = "30.9.$form->{year}";
342 $form->{duetyp} eq "10" && do {
343 $form->{fromdate} = "1.10.$form->{year}";
344 $form->{todate} = "31.10.$form->{year}";
347 $form->{duetyp} eq "11" && do {
348 $form->{fromdate} = "1.11.$form->{year}";
349 $form->{todate} = "30.11.$form->{year}";
352 $form->{duetyp} eq "12" && do {
353 $form->{fromdate} = "1.12.$form->{year}";
354 $form->{todate} = "31.12.$form->{year}";
358 hotfix_reformat_date();
359 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
361 RP->income_statement(\%myconfig, \%$form);
363 ($form->{department}) = split /--/, $form->{department};
366 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
367 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
369 # if there are any dates construct a where
370 if ($form->{fromdate} || $form->{todate}) {
372 unless ($form->{todate}) {
373 $form->{todate} = $form->current_date(\%myconfig);
376 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
377 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
379 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
380 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
382 $form->{this_period} = "$shortfromdate\n$shorttodate";
384 $locale->text('for Period')
385 . qq|\n$longfromdate |
386 . $locale->text('Bis')
390 if ($form->{comparefromdate} || $form->{comparetodate}) {
391 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
392 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
394 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
395 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
397 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
399 "\n$longcomparefromdate "
400 . $locale->text('Bis')
401 . qq| $longcomparetodate|;
404 # setup variables for the form
405 my @a = qw(company address businessnumber);
406 map { $form->{$_} = $myconfig{$_} } @a;
408 $form->{templates} = $myconfig{templates};
410 $form->{IN} = "income_statement.html";
412 $form->parse_template;
414 $main::lxdebug->leave_sub();
417 sub generate_balance_sheet {
418 $::lxdebug->enter_sub;
419 $::auth->assert('report');
421 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
422 $::form->{padding} = " ";
423 $::form->{bold} = "<b>";
424 $::form->{endbold} = "</b>";
425 $::form->{br} = "<br>";
427 my $data = RP->balance_sheet(\%::myconfig, $::form);
429 $::form->{asofdate} ||= $::form->current_date;
430 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
432 ($::form->{department}) = split /--/, $::form->{department};
434 # define Current Earnings account
435 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
436 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
438 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
439 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
441 # $::form->{IN} = "balance_sheet.html";
443 # setup company variables for the form
444 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
446 $::form->{templates} = $::myconfig{templates};
449 print $::form->parse_html_template('rp/balance_sheet', $data);
451 $::lxdebug->leave_sub;
454 sub generate_projects {
455 $main::lxdebug->enter_sub();
457 $main::auth->assert('report');
459 my $form = $main::form;
460 my %myconfig = %main::myconfig;
461 my $locale = $main::locale;
463 &get_project("generate_projects");
464 $form->{projectnumber} = $form->{projectnumber_1};
466 $form->{nextsub} = "generate_projects";
467 $form->{title} = $locale->text('Project Transactions');
468 RP->trial_balance(\%myconfig, \%$form);
470 list_accounts('generate_projects');
472 $main::lxdebug->leave_sub();
478 # included links to display transactions for period entered
479 # added headers and subtotals
481 sub generate_trial_balance {
482 $main::lxdebug->enter_sub();
484 $main::auth->assert('report');
486 my $form = $main::form;
487 my %myconfig = %main::myconfig;
488 my $locale = $main::locale;
490 if ($form->{reporttype} eq "custom") {
492 #forgotten the year --> thisyear
493 if ($form->{year} !~ m/^\d\d\d\d$/) {
494 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
500 if ($form->{duetyp} eq "13") {
501 $form->{fromdate} = "1.1.$form->{year}";
502 $form->{todate} = "31.12.$form->{year}";
506 if ($form->{duetyp} eq "A") {
507 $form->{fromdate} = "1.1.$form->{year}";
508 $form->{todate} = "31.3.$form->{year}";
510 if ($form->{duetyp} eq "B") {
511 $form->{fromdate} = "1.4.$form->{year}";
512 $form->{todate} = "30.6.$form->{year}";
514 if ($form->{duetyp} eq "C") {
515 $form->{fromdate} = "1.7.$form->{year}";
516 $form->{todate} = "30.9.$form->{year}";
518 if ($form->{duetyp} eq "D") {
519 $form->{fromdate} = "1.10.$form->{year}";
520 $form->{todate} = "31.12.$form->{year}";
525 $form->{duetyp} eq "1" && do {
526 $form->{fromdate} = "1.1.$form->{year}";
527 $form->{todate} = "31.1.$form->{year}";
530 $form->{duetyp} eq "2" && do {
531 $form->{fromdate} = "1.2.$form->{year}";
533 #this works from 1901 to 2099, 1900 and 2100 fail.
534 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
535 $form->{todate} = "$leap.2.$form->{year}";
538 $form->{duetyp} eq "3" && do {
539 $form->{fromdate} = "1.3.$form->{year}";
540 $form->{todate} = "31.3.$form->{year}";
543 $form->{duetyp} eq "4" && do {
544 $form->{fromdate} = "1.4.$form->{year}";
545 $form->{todate} = "30.4.$form->{year}";
548 $form->{duetyp} eq "5" && do {
549 $form->{fromdate} = "1.5.$form->{year}";
550 $form->{todate} = "31.5.$form->{year}";
553 $form->{duetyp} eq "6" && do {
554 $form->{fromdate} = "1.6.$form->{year}";
555 $form->{todate} = "30.6.$form->{year}";
558 $form->{duetyp} eq "7" && do {
559 $form->{fromdate} = "1.7.$form->{year}";
560 $form->{todate} = "31.7.$form->{year}";
563 $form->{duetyp} eq "8" && do {
564 $form->{fromdate} = "1.8.$form->{year}";
565 $form->{todate} = "31.8.$form->{year}";
568 $form->{duetyp} eq "9" && do {
569 $form->{fromdate} = "1.9.$form->{year}";
570 $form->{todate} = "30.9.$form->{year}";
573 $form->{duetyp} eq "10" && do {
574 $form->{fromdate} = "1.10.$form->{year}";
575 $form->{todate} = "31.10.$form->{year}";
578 $form->{duetyp} eq "11" && do {
579 $form->{fromdate} = "1.11.$form->{year}";
580 $form->{todate} = "30.11.$form->{year}";
583 $form->{duetyp} eq "12" && do {
584 $form->{fromdate} = "1.12.$form->{year}";
585 $form->{todate} = "31.12.$form->{year}";
589 hotfix_reformat_date();
593 # get for each account initial balance, debits and credits
594 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
597 $form->{rowcount} = scalar @{ $form->{TB} || [] };
598 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
601 "accno", "description",
602 "last_transaction", "soll_eb",
605 "soll_kumuliert", "haben_kumuliert",
606 "soll_saldo", "haben_saldo"
610 my $attachment_basename = $locale->text('trial_balance');
611 my $report = SL::ReportGenerator->new(\%myconfig, $form);
613 my @hidden_variables = qw(fromdate todate year cash);
615 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
618 'accno' => { 'text' => $locale->text('Account'), },
619 'description' => { 'text' => $locale->text('Description'), },
620 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
621 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
622 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
623 'soll' => { 'text' => $locale->text('Debit'), },
624 'haben' => { 'text' => $locale->text('Credit'), },
625 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
626 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
627 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
628 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
633 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
635 map { $column_defs{$_}->{visible} = 1 } @columns;
637 $report->set_columns(%column_defs);
638 $report->set_column_order(@columns);
640 $report->set_export_options('generate_trial_balance', @hidden_variables);
645 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
647 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
648 push (@options, $form->{print_date});
650 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
651 push (@options, $form->{company});
654 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
656 my @custom_headers = ([
657 { text => $::locale->text('Account'), rowspan => 2, },
658 { text => $::locale->text('Description'), rowspan => 2, },
659 { text => $::locale->text('Last Transaction'), rowspan => 2, },
660 { text => $::locale->text('Starting Balance'), colspan => 2, },
661 { text => $::locale->text('Sum for') . " $form->{template_fromto}", colspan => 2, },
662 { text => $::locale->text('Sum per') . " $form->{template_to}", colspan => 2, },
663 { text => $::locale->text('Saldo per') . " $form->{template_to}", colspan => 2, },
668 { text => $::locale->text('Assets'), },
669 { text => $::locale->text('Equity'), },
670 { text => $::locale->text('Debit'), },
671 { text => $::locale->text('Credit'), },
672 { text => $::locale->text('Debit'), },
673 { text => $::locale->text('Credit'), },
674 { text => $::locale->text('Debit'), },
675 { text => $::locale->text('Credit'), },
678 $report->set_options('output_format' => 'HTML',
679 'top_info_text' => join("\n", @options),
680 'title' => $form->{title},
681 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
682 'html_template' => 'rp/html_report_susa',
683 'pdf_template' => 'rp/html_report_susa',
685 $report->set_custom_headers(@custom_headers);
686 $report->set_options_from_form();
687 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
689 # add sort and escape callback, this one we use for the add sub
690 $form->{callback} = $href .= "&sort=$form->{sort}";
692 # escape callback for href
693 my $callback = $form->escape($href);
695 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
697 my %totals = map { $_ => 0 } @subtotal_columns;
699 my $edit_url = build_std_url('action=edit', 'type', 'vc');
702 foreach my $accno (@{ $form->{TB} || [] }) {
704 $accno->{soll} = $accno->{debit};
705 $accno->{haben} = $accno->{credit};
706 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
708 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
709 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
713 foreach my $column (@columns) {
715 'data' => $accno->{$column},
716 'align' => $column_alignment{$column},
720 $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}));
722 my $row_set = [ $row ];
725 $report->add_data($row_set);
730 $report->add_separator();
732 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
734 $report->generate_with_headers();
736 $main::lxdebug->leave_sub();
740 sub create_subtotal_row {
741 $main::lxdebug->enter_sub();
743 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
745 my $form = $main::form;
746 my %myconfig = %main::myconfig;
747 my $locale = $main::locale;
749 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
751 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
753 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
755 map { $totals->{$_} = 0 } @{ $subtotal_columns };
757 $main::lxdebug->leave_sub();
762 sub create_list_accounts_subtotal_row {
763 $main::lxdebug->enter_sub();
765 my ($subtotals, $columns, $fields, $class) = @_;
767 my $form = $main::form;
768 my %myconfig = %main::myconfig;
769 my $locale = $main::locale;
771 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
773 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
775 $main::lxdebug->leave_sub();
781 $main::lxdebug->enter_sub();
785 my $form = $main::form;
786 my %myconfig = %main::myconfig;
787 my $locale = $main::locale;
790 if ($form->{department}) {
791 my ($department) = split /--/, $form->{department};
792 push @options, $locale->text('Department') . " : $department";
794 if ($form->{projectnumber}) {
795 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
798 # if there are any dates
799 if ($form->{fromdate} || $form->{todate}) {
800 my ($fromdate, $todate);
802 if ($form->{fromdate}) {
803 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
805 if ($form->{todate}) {
806 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
809 push @options, "$fromdate - $todate";
812 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
815 my @columns = qw(accno description begbalance debit credit endbalance);
817 'accno' => { 'text' => $locale->text('Account'), },
818 'description' => { 'text' => $locale->text('Description'), },
819 'debit' => { 'text' => $locale->text('Debit'), },
820 'credit' => { 'text' => $locale->text('Credit'), },
821 'begbalance' => { 'text' => $locale->text('Balance'), },
822 'endbalance' => { 'text' => $locale->text('Balance'), },
824 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
826 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
828 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
830 my $report = SL::ReportGenerator->new(\%myconfig, $form);
832 $report->set_options('top_info_text' => join("\n", @options),
833 'output_format' => 'HTML',
834 'title' => $form->{title},
835 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
836 'std_column_visibility' => 1,
838 $report->set_options_from_form();
839 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
841 $report->set_columns(%column_defs);
842 $report->set_column_order(@columns);
844 $report->set_export_options($action, @hidden_variables);
846 my @totals_columns = qw(credit debit begbalance endbalance);
847 my %subtotals = map { $_ => 0 } @totals_columns;
848 my %totals = map { $_ => 0 } @totals_columns;
849 my $found_heading = 0;
850 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
852 # sort the whole thing by account numbers and display
853 foreach my $idx (0 .. scalar(@tb) - 1) {
855 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
857 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
859 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
861 if ($ref->{charttype} eq 'H') {
862 next unless ($form->{l_heading});
864 %subtotals = map { $_ => 0 } @totals_columns;
866 $row->{description}->{class} = 'listheading';
867 $row->{description}->{data} = $ref->{description};
869 $report->add_data($row);
874 foreach (qw(debit credit)) {
875 $subtotals{$_} += $ref->{$_};
876 $totals{$_} += $ref->{$_};
879 $subtotals{begbalance} += $ref->{balance} * $ml;
880 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
882 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
883 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
885 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
886 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
888 $report->add_data($row);
890 if ($form->{l_heading} && $found_heading &&
891 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
892 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
896 $report->add_separator();
898 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
900 $report->generate_with_headers();
902 $main::lxdebug->leave_sub();
905 sub generate_ar_aging {
906 $main::lxdebug->enter_sub();
908 $main::auth->assert('general_ledger');
910 my $form = $main::form;
911 my %myconfig = %main::myconfig;
912 my $locale = $main::locale;
915 ($form->{customer}) = split(/--/, $form->{customer});
917 $form->{ct} = "customer";
918 $form->{arap} = "ar";
920 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
922 RP->aging(\%myconfig, \%$form);
925 $main::lxdebug->leave_sub();
928 sub generate_ap_aging {
929 $main::lxdebug->enter_sub();
931 $main::auth->assert('general_ledger');
933 my $form = $main::form;
934 my %myconfig = %main::myconfig;
935 my $locale = $main::locale;
938 ($form->{vendor}) = split(/--/, $form->{vendor});
940 $form->{ct} = "vendor";
941 $form->{arap} = "ap";
943 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
945 RP->aging(\%myconfig, \%$form);
948 $main::lxdebug->leave_sub();
951 sub create_aging_subtotal_row {
952 $main::lxdebug->enter_sub();
954 my ($subtotals, $columns, $periods, $class) = @_;
956 my $form = $main::form;
957 my %myconfig = %main::myconfig;
958 my $locale = $main::locale;
960 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
962 foreach (@{ $periods }) {
963 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
964 $subtotals->{$_} = 0;
967 $main::lxdebug->leave_sub();
973 $main::lxdebug->enter_sub();
975 $main::auth->assert('general_ledger');
977 my $form = $main::form;
978 my %myconfig = %main::myconfig;
979 my $locale = $main::locale;
980 my $cgi = $::request->{cgi};
982 my $report = SL::ReportGenerator->new(\%myconfig, $form);
984 my @columns = qw(statement ct invnumber transdate duedate amount open);
987 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
988 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
989 'invnumber' => { 'text' => $locale->text('Invoice'), },
990 'transdate' => { 'text' => $locale->text('Date'), },
991 'duedate' => { 'text' => $locale->text('Due'), },
992 'amount' => { 'text' => $locale->text('Amount'), },
993 'open' => { 'text' => $locale->text('Open'), },
996 my %column_alignment = ('statement' => 'center',
997 map { $_ => 'right' } qw(open amount));
999 $report->set_options('std_column_visibility' => 1);
1000 $report->set_columns(%column_defs);
1001 $report->set_column_order(@columns);
1003 my @hidden_variables = qw(todate customer vendor arap title ct);
1004 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1007 my $attachment_basename;
1009 if ($form->{department}) {
1010 my ($department) = split /--/, $form->{department};
1011 push @options, $locale->text('Department') . " : $department";
1012 $form->{callback} .= "&department=" . E($department);
1015 if (($form->{arap} eq 'ar') && $form->{customer}) {
1016 push @options, $form->{customer};
1017 $attachment_basename = $locale->text('ar_aging_list');
1018 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1021 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1022 push @options, $form->{vendor};
1023 $attachment_basename = $locale->text('ap_aging_list');
1024 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1027 if ($form->{fromdate}) {
1028 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1030 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1033 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1035 $report->set_options('top_info_text' => join("\n", @options),
1036 'output_format' => 'HTML',
1037 'title' => $form->{title},
1038 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1040 $report->set_options_from_form();
1041 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1043 my $previous_ctid = 0;
1045 my @periods = qw(open amount);
1046 my %subtotals = map { $_ => 0 } @periods;
1047 my %totals = map { $_ => 0 } @periods;
1049 foreach my $ref (@{ $form->{AG} }) {
1050 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1051 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1054 foreach my $key (@periods) {
1055 $subtotals{$key} += $ref->{"$key"};
1056 $totals{$key} += $ref->{"$key"};
1057 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1062 foreach my $column (@columns) {
1064 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1065 'align' => $column_alignment{$column},
1066 'valign' => $column eq 'statement' ? 'center' : '',
1070 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1072 if ($previous_ctid != $ref->{ctid}) {
1073 $row->{statement}->{raw_data} =
1074 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1075 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1076 $row->{ct}->{data} = $ref->{name};
1081 $previous_ctid = $ref->{ctid};
1083 $report->add_data($row);
1086 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1088 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1090 if ($form->{arap} eq 'ar') {
1091 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1092 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1093 'PRINT_OPTIONS' => print_options(inline => 1), });
1094 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1095 'raw_bottom_info_text' => $raw_bottom_info_text);
1098 $report->generate_with_headers();
1100 $main::lxdebug->leave_sub();
1104 $main::lxdebug->enter_sub();
1106 my $form = $main::form;
1107 my %myconfig = %main::myconfig;
1108 my $locale = $main::locale;
1110 RP->aging(\%myconfig, \%$form);
1112 map { $_->{checked} = "checked" } @{ $form->{AG} };
1116 $main::lxdebug->leave_sub();
1120 $::lxdebug->enter_sub;
1121 $::auth->assert('general_ledger');
1123 # get name and email addresses
1125 for my $i (1 .. $::form->{rowcount}) {
1126 next unless $::form->{"statement_$i"};
1127 $::form->{"$::form->{ct}_id"} = $::form->{"$::form->{ct}_id_$i"};
1128 RP->get_customer(\%::myconfig, $::form);
1133 $::form->error($::locale->text('Nothing selected!')) unless $selected;
1135 $::form->{media} = "email";
1137 # save all other variables
1139 for my $key (keys %$::form) {
1140 next if any { $key eq $_ } qw(login password action email cc bcc subject message type sendmode format header);
1141 next unless '' eq ref $::form->{$key};
1142 push @hidden_values, $key;
1146 print $::form->parse_html_template('rp/e_mail', {
1147 show_bcc => $::auth->assert('email_bcc', 'may fail'),
1148 print_options => print_options(inline => 1),
1149 hidden_values => \@hidden_values,
1152 $::lxdebug->leave_sub;
1156 $main::lxdebug->enter_sub();
1158 $main::auth->assert('general_ledger');
1160 my $form = $main::form;
1161 my %myconfig = %main::myconfig;
1162 my $locale = $main::locale;
1164 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1165 unless $form->{subject};
1167 RP->aging(\%myconfig, \%$form);
1169 $form->{"statement_1"} = 1;
1171 $form->{media} = 'email';
1174 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1176 $main::lxdebug->leave_sub();
1180 $main::lxdebug->enter_sub();
1182 $main::auth->assert('general_ledger');
1184 my $form = $main::form;
1185 my %myconfig = %main::myconfig;
1186 my $locale = $main::locale;
1188 if ($form->{media} eq 'printer') {
1189 $form->error($locale->text('Select postscript or PDF!'))
1190 if ($form->{format} !~ /(postscript|pdf)/);
1194 for my $i (1 .. $form->{rowcount}) {
1195 if ($form->{"statement_$i"}) {
1196 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1202 $form->error($locale->text('Nothing selected!')) unless $selected;
1204 if ($form->{media} eq 'printer') {
1205 $form->{"$form->{ct}_id"} = "";
1207 $form->{"statement_1"} = 1;
1210 RP->aging(\%myconfig, \%$form);
1214 $form->redirect($locale->text('Statements sent to printer!'))
1215 if ($form->{media} eq 'printer');
1217 $main::lxdebug->leave_sub();
1221 $main::lxdebug->enter_sub();
1223 $main::auth->assert('general_ledger');
1225 my $form = $main::form;
1226 my %myconfig = %main::myconfig;
1227 my $locale = $main::locale;
1229 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1231 $form->{templates} = "$myconfig{templates}";
1233 my $suffix = "html";
1234 my $attachment_suffix = "html";
1235 if ($form->{format} eq 'postscript') {
1236 $form->{postscript} = 1;
1238 $attachment_suffix = "ps";
1239 } elsif ($form->{format} eq 'pdf') {
1242 $attachment_suffix = "pdf";
1245 $form->{IN} = "$form->{type}.$suffix";
1246 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1248 # Save $form->{email} because it will be overwritten.
1249 $form->{EMAIL_RECIPIENT} = $form->{email};
1253 while (@{ $form->{AG} }) {
1255 my $ref = shift @{ $form->{AG} };
1257 if ($ctid != $ref->{ctid}) {
1259 $ctid = $ref->{ctid};
1262 if ($form->{"statement_$i"}) {
1265 ("name", "street", "zipcode", "city", "country", "contact", "email",
1266 "$form->{ct}phone", "$form->{ct}fax");
1267 map { $form->{$_} = $ref->{$_} } @a;
1269 $form->{ $form->{ct} } = $form->{name};
1270 $form->{"$form->{ct}_id"} = $ref->{ctid};
1272 map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
1274 foreach my $item (qw(c0 c30 c60 c90)) {
1275 $form->{$item} = ();
1276 $form->{"${item}total"} = 0;
1279 &statement_details($ref);
1283 if (scalar(@{ $form->{AG} }) > 0) {
1285 # one or more left to go
1286 if ($ctid == $form->{AG}->[0]->{ctid}) {
1287 $ref = shift @{ $form->{AG} };
1288 &statement_details($ref);
1291 $ref = scalar(@{ $form->{AG} });
1297 # set initial ref to 0
1304 $form->{"${_}total"} =
1305 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1306 } ('c0', 'c30', 'c60', 'c90', "");
1308 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1309 $form->{attachment_filename} =~ s/\s+/_/g;
1311 $form->parse_template(\%myconfig);
1316 # saving the history
1317 if(!exists $form->{addition} && $form->{id} ne "") {
1318 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1319 $form->{addition} = "PRINTED";
1320 $form->{what_done} = $form->{type};
1321 $form->save_history;
1323 # /saving the history
1324 $main::lxdebug->leave_sub();
1327 sub statement_details {
1328 $main::lxdebug->enter_sub();
1330 $main::auth->assert('general_ledger');
1332 my $form = $main::form;
1333 my %myconfig = %main::myconfig;
1334 my $locale = $main::locale;
1338 push @{ $form->{invnumber} }, $ref->{invnumber};
1339 push @{ $form->{invdate} }, $ref->{transdate};
1340 push @{ $form->{duedate} }, $ref->{duedate};
1341 push @{ $form->{amount} }, $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
1342 push @{ $form->{open} }, $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
1344 foreach my $item (qw(c0 c30 c60 c90)) {
1345 if ($ref->{exchangerate} * 1) {
1346 # add only the open amount of the invoice to the aging, not the total amount
1347 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
1348 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
1349 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
1350 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
1352 $form->{"${item}total"} += $ref->{$item};
1353 $form->{total} += $ref->{$item};
1354 push @{ $form->{$item} },
1355 $form->format_amount(\%myconfig, $ref->{$item}, 2);
1358 $main::lxdebug->leave_sub();
1361 sub generate_tax_report {
1362 $::lxdebug->enter_sub;
1363 $::auth->assert('report');
1365 RP->tax_report(\%::myconfig, $::form);
1367 my $descvar = "$::form->{accno}_description";
1368 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
1372 my $callback = build_std_url('action=generate_tax_report', $descvar,
1373 qw(fromdate todate db method accno department report title));
1375 my @columns = $::form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1378 for my $item (@columns, 'subtotal') {
1379 if ($::form->{"l_$item"} eq "Y") {
1380 $callback .= "&l_$item=Y";
1381 $href .= "&l_$item=Y";
1385 for my $item (@columns) {
1386 if ($::form->{"l_$item"} eq "Y") {
1387 push @column_index, $item;
1392 if ($::form->{department}) {
1393 my ($department) = split /--/, $::form->{department};
1394 push @options, $::locale->text('Department') . " : $department";
1397 # if there are any dates
1398 if ($::form->{fromdate} || $::form->{todate}) {
1399 my $fromdate = $::form->{fromdate} ? $::locale->date(\%::myconfig, $::form->{fromdate}, 1) : '';
1400 my $todate = $::form->{todate} ? $::locale->date(\%::myconfig, $::form->{todate}, 1) : '';
1401 push @options, "$fromdate - $todate";
1403 push @options, $::locale->date(\%::myconfig, $::form->current_date, 1);
1406 my ($name, $invoice, $arap);
1407 if ($::form->{db} eq 'ar') {
1408 $name = $::locale->text('Customer');
1412 if ($::form->{db} eq 'ap') {
1413 $name = $::locale->text('Vendor');
1418 my %column_header = (
1419 id => $::locale->text('ID'),
1420 invnumber => $::locale->text('Invoice'),
1421 transdate => $::locale->text('Date'),
1422 netamount => $::locale->text('Amount'),
1423 tax => $::locale->text('Tax'),
1424 amount => $::locale->text('Total'),
1428 my %column_sorted = map { $_ => 1 } qw(id invnumber transdate);
1430 $callback .= "&sort=$::form->{sort}";
1433 if (@{ $::form->{TR} }) {
1434 $sameitem = $::form->{TR}->[0]->{ $::form->{sort} };
1437 my ($totalnetamount, $totaltax, @data);
1438 for my $ref (@{ $::form->{TR} }) {
1440 my $module = ($ref->{invoice}) ? $invoice : $arap;
1442 if ($::form->{l_subtotal} eq 'Y') {
1443 if ($sameitem ne $ref->{ $::form->{sort} }) {
1446 netamount => $subtotalnetamount,
1447 tax => $subtotaltax,
1448 amount => $subtotal,
1450 $subtotalnetamount = 0;
1452 $sameitem = $ref->{ $::form->{sort} };
1456 $subtotalnetamount += $ref->{netamount};
1457 $subtotaltax += $ref->{tax};
1458 $totalnetamount += $ref->{netamount};
1459 $totaltax += $ref->{tax};
1460 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1462 push @data, { map { $_ => { data => $ref->{$_} } } keys %$ref };
1463 $data[-1]{invnumber}{link} = "$module?action=edit&id=$ref->{id}&callback=$callback";
1464 $data[-1]{$_}{numeric} = 1 for qw(netamount tax amount);
1467 if ($::form->{l_subtotal} eq 'Y') {
1470 netamount => $subtotalnetamount,
1471 tax => $subtotaltax,
1472 amount => $subtotal,
1478 netamount => $totalnetamount,
1480 amount => $totalnetamount + $totaltax,
1484 print $::form->parse_html_template('rp/tax_report', {
1485 column_index => \@column_index,
1486 column_header => \%column_header,
1487 column_sorted => \%column_sorted,
1490 options => \@options,
1493 $::lxdebug->leave_sub;
1497 $main::lxdebug->enter_sub();
1499 $main::auth->assert('cash');
1501 my $form = $main::form;
1502 my %myconfig = %main::myconfig;
1503 my $locale = $main::locale;
1505 if ($form->{account}) {
1506 ($form->{paymentaccounts}) = split /--/, $form->{account};
1510 if ($form->{department}) {
1511 (my $department, $form->{department_id}) = split /--/, $form->{department};
1512 $option = $locale->text('Department') . " : $department";
1515 report_generator_set_default_sort('transdate', 1);
1517 RP->payments(\%myconfig, \%$form);
1519 my @hidden_variables = qw(account title department reference source memo fromdate todate
1520 fx_transaction db prepayment paymentaccounts sort);
1522 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
1523 $form->{callback} = $href;
1525 my @columns = qw(transdate invnumber name paid source memo);
1527 'name' => { 'text' => $locale->text('Description'), },
1528 'invnumber' => { 'text' => $locale->text('Reference'), },
1529 'transdate' => { 'text' => $locale->text('Date'), },
1530 'paid' => { 'text' => $locale->text('Amount'), },
1531 'source' => { 'text' => $locale->text('Source'), },
1532 'memo' => { 'text' => $locale->text('Memo'), },
1534 my %column_alignment = ('paid' => 'right');
1536 foreach my $name (grep { $_ ne 'paid' } @columns) {
1537 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1538 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
1542 if ($form->{fromdate}) {
1543 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
1545 if ($form->{todate}) {
1546 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1549 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1551 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
1553 $report->set_options('top_info_text' => join("\n", @options),
1554 'output_format' => 'HTML',
1555 'title' => $form->{title},
1556 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1557 'std_column_visibility' => 1,
1559 $report->set_options_from_form();
1561 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1563 $report->set_columns(%column_defs);
1564 $report->set_column_order(@columns);
1566 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
1568 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1572 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1573 next unless @{ $form->{ $ref->{id} } };
1575 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
1577 my $subtotal_paid = 0;
1579 foreach my $payment (@{ $form->{ $ref->{id} } }) {
1580 my $module = $payment->{module};
1581 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1582 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1584 $subtotal_paid += $payment->{paid};
1585 $total_paid += $payment->{paid};
1587 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
1591 foreach my $column (@columns) {
1593 'data' => $payment->{$column},
1594 'align' => $column_alignment{$column},
1598 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
1600 $report->add_data($row);
1603 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
1605 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
1607 'class' => 'listsubtotal',
1610 $report->add_data($row);
1613 $report->add_separator();
1615 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
1617 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
1619 'class' => 'listtotal',
1622 $report->add_data($row);
1624 $report->generate_with_headers();
1626 $main::lxdebug->leave_sub();
1630 $::lxdebug->enter_sub;
1632 my ($dont_print) = @_;
1634 $::form->{sendmode} = "attachment";
1635 $::form->{format} ||= $::myconfig{template_format} || "pdf";
1636 $::form->{copies} ||= $::myconfig{copies} || 2;
1638 $::form->{PD}{ $::form->{type} } = "selected";
1639 $::form->{DF}{ $::form->{format} } = "selected";
1640 $::form->{OP}{ $::form->{media} } = "selected";
1641 $::form->{SM}{ $::form->{sendmode} } = "selected";
1643 my $output = $::form->parse_html_template('rp/print_options', {
1644 got_printer => $::myconfig{printer},
1645 show_latex => $::lx_office_conf{print_templates}->{latex},
1646 is_email => $::form->{media} eq 'email',
1649 print $output unless $dont_print;
1651 $::lxdebug->leave_sub;
1657 $main::lxdebug->enter_sub();
1659 $main::auth->assert('report');
1661 my $form = $main::form;
1662 my %myconfig = %main::myconfig;
1663 my $locale = $main::locale;
1665 $form->{padding} = " ";
1666 $form->{bold} = "<b>";
1667 $form->{endbold} = "</b>";
1668 $form->{br} = "<br>";
1670 if ($form->{reporttype} eq "custom") {
1672 #forgotten the year --> thisyear
1673 if ($form->{year} !~ m/^\d\d\d\d$/) {
1674 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1680 if ($form->{duetyp} eq "13") {
1681 $form->{fromdate} = "1.1.$form->{year}";
1682 $form->{todate} = "31.12.$form->{year}";
1683 $form->{comparefromdate} = "1.01.$form->{year}";
1684 $form->{comparetodate} = "31.12.$form->{year}";
1688 if ($form->{duetyp} eq "A") {
1689 $form->{fromdate} = "1.1.$form->{year}";
1690 $form->{todate} = "31.3.$form->{year}";
1691 $form->{comparefromdate} = "1.01.$form->{year}";
1692 $form->{comparetodate} = "31.03.$form->{year}";
1694 if ($form->{duetyp} eq "B") {
1695 $form->{fromdate} = "1.4.$form->{year}";
1696 $form->{todate} = "30.6.$form->{year}";
1697 $form->{comparefromdate} = "1.01.$form->{year}";
1698 $form->{comparetodate} = "30.06.$form->{year}";
1700 if ($form->{duetyp} eq "C") {
1701 $form->{fromdate} = "1.7.$form->{year}";
1702 $form->{todate} = "30.9.$form->{year}";
1703 $form->{comparefromdate} = "1.01.$form->{year}";
1704 $form->{comparetodate} = "30.09.$form->{year}";
1706 if ($form->{duetyp} eq "D") {
1707 $form->{fromdate} = "1.10.$form->{year}";
1708 $form->{todate} = "31.12.$form->{year}";
1709 $form->{comparefromdate} = "1.01.$form->{year}";
1710 $form->{comparetodate} = "31.12.$form->{year}";
1715 $form->{duetyp} eq "1" && do {
1716 $form->{fromdate} = "1.1.$form->{year}";
1717 $form->{todate} = "31.1.$form->{year}";
1718 $form->{comparefromdate} = "1.01.$form->{year}";
1719 $form->{comparetodate} = "31.01.$form->{year}";
1722 $form->{duetyp} eq "2" && do {
1723 $form->{fromdate} = "1.2.$form->{year}";
1725 #this works from 1901 to 2099, 1900 and 2100 fail.
1726 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1727 $form->{todate} = "$leap.2.$form->{year}";
1728 $form->{comparefromdate} = "1.01.$form->{year}";
1729 $form->{comparetodate} = "$leap.02.$form->{year}";
1732 $form->{duetyp} eq "3" && do {
1733 $form->{fromdate} = "1.3.$form->{year}";
1734 $form->{todate} = "31.3.$form->{year}";
1735 $form->{comparefromdate} = "1.01.$form->{year}";
1736 $form->{comparetodate} = "31.03.$form->{year}";
1739 $form->{duetyp} eq "4" && do {
1740 $form->{fromdate} = "1.4.$form->{year}";
1741 $form->{todate} = "30.4.$form->{year}";
1742 $form->{comparefromdate} = "1.01.$form->{year}";
1743 $form->{comparetodate} = "30.04.$form->{year}";
1746 $form->{duetyp} eq "5" && do {
1747 $form->{fromdate} = "1.5.$form->{year}";
1748 $form->{todate} = "31.5.$form->{year}";
1749 $form->{comparefromdate} = "1.01.$form->{year}";
1750 $form->{comparetodate} = "31.05.$form->{year}";
1753 $form->{duetyp} eq "6" && do {
1754 $form->{fromdate} = "1.6.$form->{year}";
1755 $form->{todate} = "30.6.$form->{year}";
1756 $form->{comparefromdate} = "1.01.$form->{year}";
1757 $form->{comparetodate} = "30.06.$form->{year}";
1760 $form->{duetyp} eq "7" && do {
1761 $form->{fromdate} = "1.7.$form->{year}";
1762 $form->{todate} = "31.7.$form->{year}";
1763 $form->{comparefromdate} = "1.01.$form->{year}";
1764 $form->{comparetodate} = "31.07.$form->{year}";
1767 $form->{duetyp} eq "8" && do {
1768 $form->{fromdate} = "1.8.$form->{year}";
1769 $form->{todate} = "31.8.$form->{year}";
1770 $form->{comparefromdate} = "1.01.$form->{year}";
1771 $form->{comparetodate} = "31.08.$form->{year}";
1774 $form->{duetyp} eq "9" && do {
1775 $form->{fromdate} = "1.9.$form->{year}";
1776 $form->{todate} = "30.9.$form->{year}";
1777 $form->{comparefromdate} = "1.01.$form->{year}";
1778 $form->{comparetodate} = "30.09.$form->{year}";
1781 $form->{duetyp} eq "10" && do {
1782 $form->{fromdate} = "1.10.$form->{year}";
1783 $form->{todate} = "31.10.$form->{year}";
1784 $form->{comparefromdate} = "1.01.$form->{year}";
1785 $form->{comparetodate} = "31.10.$form->{year}";
1788 $form->{duetyp} eq "11" && do {
1789 $form->{fromdate} = "1.11.$form->{year}";
1790 $form->{todate} = "30.11.$form->{year}";
1791 $form->{comparefromdate} = "1.01.$form->{year}";
1792 $form->{comparetodate} = "30.11.$form->{year}";
1795 $form->{duetyp} eq "12" && do {
1796 $form->{fromdate} = "1.12.$form->{year}";
1797 $form->{todate} = "31.12.$form->{year}";
1798 $form->{comparefromdate} = "1.01.$form->{year}";
1799 $form->{comparetodate} = "31.12.$form->{year}";
1803 hotfix_reformat_date();
1805 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
1806 # ansonsten ist die prüfung in RP.pm
1807 # if (defined ($form->{fromdate|todate}=='..'))
1809 if ($form->{fromdate}){
1810 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
1811 my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
1812 $datetime->set( month => 1,
1814 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
1816 if ($form->{todate}){
1817 $form->{comparetodate} = $form->{todate};
1821 RP->bwa(\%myconfig, \%$form);
1823 ($form->{department}) = split /--/, $form->{department};
1826 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1827 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1829 # if there are any dates construct a where
1830 if ($form->{fromdate} || $form->{todate}) {
1832 unless ($form->{todate}) {
1833 $form->{todate} = $form->current_date(\%myconfig);
1836 my %germandate = ("dateformat" => "dd.mm.yyyy");
1838 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
1839 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
1841 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
1842 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
1844 $form->{this_period} = "$shortfromdate\n$shorttodate";
1846 $locale->text('for Period')
1847 . qq|\n$longfromdate |
1848 . $locale->text('bis')
1852 # setup variables for the form
1853 my @a = qw(company address businessnumber);
1854 map { $form->{$_} = $myconfig{$_} } @a;
1855 $form->{templates} = $myconfig{templates};
1857 $form->{IN} = "bwa.html";
1859 $form->parse_template;
1861 $main::lxdebug->leave_sub();
1864 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
1865 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
1866 sub hotfix_reformat_date {
1868 $main::lxdebug->enter_sub();
1870 my $form = $main::form;
1871 my %myconfig = %main::myconfig;
1872 my $locale = $main::locale;
1874 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
1875 my $current_dateformat = $myconfig{dateformat};
1876 $myconfig{dateformat} = 'dd.mm.yyyy';
1877 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
1878 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
1879 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
1880 unless (!defined ($form->{comparefromdate}));
1881 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
1882 unless (!defined ($form->{comparetodate}));
1884 # Und wieder zurücksetzen
1885 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
1886 } # Ende Hotifx Bug 1388
1888 $main::lxdebug->leave_sub();