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);
45 use SL::ReportGenerator;
47 use List::MoreUtils qw(any);
49 require "bin/mozilla/arap.pl";
50 require "bin/mozilla/common.pl";
51 require "bin/mozilla/reportgenerator.pl";
53 # note: this file was particularly hard to strictify.
54 # alot of the vars are passed carelessly between invocations
55 # should there be any missing vars, declare them globally
58 # this is for our long dates
59 # $locale->text('January')
60 # $locale->text('February')
61 # $locale->text('March')
62 # $locale->text('April')
63 # $locale->text('May ')
64 # $locale->text('June')
65 # $locale->text('July')
66 # $locale->text('August')
67 # $locale->text('September')
68 # $locale->text('October')
69 # $locale->text('November')
70 # $locale->text('December')
72 # this is for our short month
73 # $locale->text('Jan')
74 # $locale->text('Feb')
75 # $locale->text('Mar')
76 # $locale->text('Apr')
77 # $locale->text('May')
78 # $locale->text('Jun')
79 # $locale->text('Jul')
80 # $locale->text('Aug')
81 # $locale->text('Sep')
82 # $locale->text('Oct')
83 # $locale->text('Nov')
84 # $locale->text('Dec')
86 # $locale->text('Balance Sheet')
87 # $locale->text('Income Statement')
88 # $locale->text('Trial Balance')
89 # $locale->text('AR Aging')
90 # $locale->text('AP Aging')
91 # $locale->text('Search AR Aging')
92 # $locale->text('Search AP Aging')
93 # $locale->text('Tax collected')
94 # $locale->text('Tax paid')
95 # $locale->text('Receipts')
96 # $locale->text('Payments')
97 # $locale->text('Project Transactions')
98 # $locale->text('Business evaluation')
100 # $form->parse_html_template('rp/html_report_susa')
102 my $rp_access_map = {
103 'projects' => 'report',
104 'ar_aging' => 'general_ledger',
105 'ap_aging' => 'general_ledger',
106 'receipts' => 'cash',
107 'payments' => 'cash',
108 'trial_balance' => 'report',
109 'income_statement' => 'report',
111 'balance_sheet' => 'report',
114 sub check_rp_access {
115 my $form = $main::form;
117 my $right = $rp_access_map->{$form->{report}};
118 $right ||= 'DOES_NOT_EXIST';
120 $main::auth->assert($right);
124 $::lxdebug->enter_sub;
129 balance_sheet => $::locale->text('Balance Sheet'),
130 income_statement => $::locale->text('Income Statement'),
131 trial_balance => $::locale->text('Trial Balance'),
132 ar_aging => $::locale->text('Search AR Aging'),
133 ap_aging => $::locale->text('Search AP Aging'),
134 tax_collected => $::locale->text('Tax collected'),
135 tax_paid => $::locale->text('Tax paid'),
136 receipts => $::locale->text('Receipts'),
137 payments => $::locale->text('Payments'),
138 projects => $::locale->text('Project Transactions'),
139 bwa => $::locale->text('Business evaluation'),
142 $::form->{title} = $title{$::form->{report}};
145 $::form->all_departments(\%::myconfig);
146 if (@{ $::form->{all_departments} || [] }) {
147 $::form->{selectdepartment} = "<option>\n";
148 map { $::form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $::form->{all_departments} || [] };
151 $::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
153 my $is_projects = $::form->{report} eq "projects";
154 my $is_income_statement = $::form->{report} eq "income_statement";
155 my $is_bwa = $::form->{report} eq "bwa";
156 my $is_balance_sheet = $::form->{report} eq "balance_sheet";
157 my $is_trial_balance = $::form->{report} eq "trial_balance";
158 my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
159 my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
161 my ($label, $nextsub, $vc);
163 my $is_sales = $::form->{report} eq 'ar_aging';
164 $label = $is_sales ? $::locale->text('Customer') : $::locale->text('Vendor');
165 $::form->{vc} = $is_sales ? 'customer' : 'vendor';
167 $nextsub = "generate_$::form->{report}";
170 $::form->all_vc(\%::myconfig, $::form->{vc}, $is_sales ? "AR" : "AP");
171 $vc .= "<option>$_->{name}--$_->{id}\n" for @{ $::form->{"all_$::form->{vc}"} };
173 ? qq|<select name=$::form->{vc} class="initial_focus"><option>\n$vc</select>|
174 : qq|<input name=$::form->{vc} size=35 class="initial_focus">|;
177 my ($selection, $paymentaccounts);
179 $::form->{db} = $::form->{report} =~ /payments$/ ? "ap" : "ar";
181 RP->paymentaccounts(\%::myconfig, $::form);
183 $selection = "<option>\n";
184 for my $ref (@{ $::form->{PR} }) {
185 $paymentaccounts .= "$ref->{accno} ";
186 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
191 print $::form->parse_html_template('rp/report', {
192 paymentaccounts => $paymentaccounts,
193 selection => $selection,
194 is_aging => $is_aging,
197 year => DateTime->today->year,
198 today => DateTime->today,
200 accrual => $::instance_conf->get_accounting_method ne 'cash',
201 cash => $::instance_conf->get_accounting_method eq 'cash',
202 is_payments => $is_payments,
203 is_trial_balance => $is_trial_balance,
204 is_balance_sheet => $is_balance_sheet,
206 is_income_statement => $is_income_statement,
207 is_projects => $is_projects,
210 $::lxdebug->leave_sub;
213 sub continue { call_sub($main::form->{"nextsub"}); }
215 sub generate_income_statement {
216 $main::lxdebug->enter_sub();
218 $main::auth->assert('report');
220 my $form = $main::form;
221 my %myconfig = %main::myconfig;
222 my $locale = $main::locale;
224 my $defaults = SL::DB::Default->get;
225 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
226 $form->{templates} = $defaults->templates;
228 $form->{padding} = " ";
229 $form->{bold} = "<b>";
230 $form->{endbold} = "</b>";
231 $form->{br} = "<br>";
233 if ($form->{reporttype} eq "custom") {
235 #forgotten the year --> thisyear
236 if ($form->{year} !~ m/^\d\d\d\d$/) {
237 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
243 if ($form->{duetyp} eq "13") {
244 $form->{fromdate} = "1.1.$form->{year}";
245 $form->{todate} = "31.12.$form->{year}";
249 if ($form->{duetyp} eq "A") {
250 $form->{fromdate} = "1.1.$form->{year}";
251 $form->{todate} = "31.3.$form->{year}";
253 if ($form->{duetyp} eq "B") {
254 $form->{fromdate} = "1.4.$form->{year}";
255 $form->{todate} = "30.6.$form->{year}";
257 if ($form->{duetyp} eq "C") {
258 $form->{fromdate} = "1.7.$form->{year}";
259 $form->{todate} = "30.9.$form->{year}";
261 if ($form->{duetyp} eq "D") {
262 $form->{fromdate} = "1.10.$form->{year}";
263 $form->{todate} = "31.12.$form->{year}";
268 $form->{duetyp} eq "1" && do {
269 $form->{fromdate} = "1.1.$form->{year}";
270 $form->{todate} = "31.1.$form->{year}";
273 $form->{duetyp} eq "2" && do {
274 $form->{fromdate} = "1.2.$form->{year}";
276 #this works from 1901 to 2099, 1900 and 2100 fail.
277 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
278 $form->{todate} = "$leap.2.$form->{year}";
281 $form->{duetyp} eq "3" && do {
282 $form->{fromdate} = "1.3.$form->{year}";
283 $form->{todate} = "31.3.$form->{year}";
286 $form->{duetyp} eq "4" && do {
287 $form->{fromdate} = "1.4.$form->{year}";
288 $form->{todate} = "30.4.$form->{year}";
291 $form->{duetyp} eq "5" && do {
292 $form->{fromdate} = "1.5.$form->{year}";
293 $form->{todate} = "31.5.$form->{year}";
296 $form->{duetyp} eq "6" && do {
297 $form->{fromdate} = "1.6.$form->{year}";
298 $form->{todate} = "30.6.$form->{year}";
301 $form->{duetyp} eq "7" && do {
302 $form->{fromdate} = "1.7.$form->{year}";
303 $form->{todate} = "31.7.$form->{year}";
306 $form->{duetyp} eq "8" && do {
307 $form->{fromdate} = "1.8.$form->{year}";
308 $form->{todate} = "31.8.$form->{year}";
311 $form->{duetyp} eq "9" && do {
312 $form->{fromdate} = "1.9.$form->{year}";
313 $form->{todate} = "30.9.$form->{year}";
316 $form->{duetyp} eq "10" && do {
317 $form->{fromdate} = "1.10.$form->{year}";
318 $form->{todate} = "31.10.$form->{year}";
321 $form->{duetyp} eq "11" && do {
322 $form->{fromdate} = "1.11.$form->{year}";
323 $form->{todate} = "30.11.$form->{year}";
326 $form->{duetyp} eq "12" && do {
327 $form->{fromdate} = "1.12.$form->{year}";
328 $form->{todate} = "31.12.$form->{year}";
332 hotfix_reformat_date();
333 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
335 RP->income_statement(\%myconfig, \%$form);
337 ($form->{department}) = split /--/, $form->{department};
340 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
341 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
343 # if there are any dates construct a where
344 if ($form->{fromdate} || $form->{todate}) {
346 unless ($form->{todate}) {
347 $form->{todate} = $form->current_date(\%myconfig);
350 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
351 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
353 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
354 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
356 $form->{this_period} = "$shortfromdate\n$shorttodate";
358 $locale->text('for Period')
359 . qq|\n$longfromdate |
360 . $locale->text('Bis')
364 if ($form->{comparefromdate} || $form->{comparetodate}) {
365 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
366 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
368 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
369 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
371 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
373 "\n$longcomparefromdate "
374 . $locale->text('Bis')
375 . qq| $longcomparetodate|;
378 if ( $::instance_conf->get_profit_determination eq 'balance' ) {
379 $form->{title} = $locale->text('Income Statement');
380 } elsif ( $::instance_conf->get_profit_determination eq 'income' ) {
381 $form->{title} = $locale->text('Net Income Statement');
386 if ( $form->{method} eq 'cash' ) {
387 $form->{accounting_method} = $locale->text('Cash accounting');
388 } elsif ( $form->{method} eq 'accrual' ) {
389 $form->{accounting_method} = $locale->text('Accrual accounting');
391 $form->{accounting_method} = "";
394 $form->{report_date} = $locale->text('Report date') . ": " . $form->current_date;
397 print $form->parse_html_template('rp/income_statement');
399 $main::lxdebug->leave_sub();
402 sub generate_balance_sheet {
403 $::lxdebug->enter_sub;
404 $::auth->assert('report');
406 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
407 $::form->{padding} = " ";
408 $::form->{bold} = "<b>";
409 $::form->{endbold} = "</b>";
410 $::form->{br} = "<br>";
412 my $data = RP->balance_sheet(\%::myconfig, $::form);
414 $::form->{asofdate} ||= $::form->current_date;
415 $::form->{report_title} = $::locale->text('Balance Sheet');
416 $::form->{report_date} ||= $::form->current_date;
418 ($::form->{department}) = split /--/, $::form->{department};
420 # define Current Earnings account
421 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
422 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
424 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
425 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
427 # balance sheet isn't read from print templates anymore,
428 # instead use template in rp
429 # $::form->{IN} = "balance_sheet.html";
432 print $::form->parse_html_template('rp/balance_sheet', $data);
434 $::lxdebug->leave_sub;
437 sub generate_projects {
438 $main::lxdebug->enter_sub();
440 $main::auth->assert('report');
442 my $form = $main::form;
443 my %myconfig = %main::myconfig;
444 my $locale = $main::locale;
446 my $project = $form->{project_id} ? SL::DB::Project->new(id => $form->{project_id})->load : undef;
447 $form->{projectnumber} = $project ? $project->projectnumber : '';
449 $form->{nextsub} = "generate_projects";
450 $form->{title} = $locale->text('Project Transactions');
451 RP->trial_balance(\%myconfig, \%$form);
453 list_accounts('generate_projects');
455 $main::lxdebug->leave_sub();
461 # included links to display transactions for period entered
462 # added headers and subtotals
464 sub generate_trial_balance {
465 $main::lxdebug->enter_sub();
467 $main::auth->assert('report');
469 my $form = $main::form;
470 my %myconfig = %main::myconfig;
471 my $locale = $main::locale;
472 my $defaults = SL::DB::Default->get;
474 if ($form->{reporttype} eq "custom") {
476 #forgotten the year --> thisyear
477 if ($form->{year} !~ m/^\d\d\d\d$/) {
478 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
484 if ($form->{duetyp} eq "13") {
485 $form->{fromdate} = "1.1.$form->{year}";
486 $form->{todate} = "31.12.$form->{year}";
490 if ($form->{duetyp} eq "A") {
491 $form->{fromdate} = "1.1.$form->{year}";
492 $form->{todate} = "31.3.$form->{year}";
494 if ($form->{duetyp} eq "B") {
495 $form->{fromdate} = "1.4.$form->{year}";
496 $form->{todate} = "30.6.$form->{year}";
498 if ($form->{duetyp} eq "C") {
499 $form->{fromdate} = "1.7.$form->{year}";
500 $form->{todate} = "30.9.$form->{year}";
502 if ($form->{duetyp} eq "D") {
503 $form->{fromdate} = "1.10.$form->{year}";
504 $form->{todate} = "31.12.$form->{year}";
509 $form->{duetyp} eq "1" && do {
510 $form->{fromdate} = "1.1.$form->{year}";
511 $form->{todate} = "31.1.$form->{year}";
514 $form->{duetyp} eq "2" && do {
515 $form->{fromdate} = "1.2.$form->{year}";
517 #this works from 1901 to 2099, 1900 and 2100 fail.
518 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
519 $form->{todate} = "$leap.2.$form->{year}";
522 $form->{duetyp} eq "3" && do {
523 $form->{fromdate} = "1.3.$form->{year}";
524 $form->{todate} = "31.3.$form->{year}";
527 $form->{duetyp} eq "4" && do {
528 $form->{fromdate} = "1.4.$form->{year}";
529 $form->{todate} = "30.4.$form->{year}";
532 $form->{duetyp} eq "5" && do {
533 $form->{fromdate} = "1.5.$form->{year}";
534 $form->{todate} = "31.5.$form->{year}";
537 $form->{duetyp} eq "6" && do {
538 $form->{fromdate} = "1.6.$form->{year}";
539 $form->{todate} = "30.6.$form->{year}";
542 $form->{duetyp} eq "7" && do {
543 $form->{fromdate} = "1.7.$form->{year}";
544 $form->{todate} = "31.7.$form->{year}";
547 $form->{duetyp} eq "8" && do {
548 $form->{fromdate} = "1.8.$form->{year}";
549 $form->{todate} = "31.8.$form->{year}";
552 $form->{duetyp} eq "9" && do {
553 $form->{fromdate} = "1.9.$form->{year}";
554 $form->{todate} = "30.9.$form->{year}";
557 $form->{duetyp} eq "10" && do {
558 $form->{fromdate} = "1.10.$form->{year}";
559 $form->{todate} = "31.10.$form->{year}";
562 $form->{duetyp} eq "11" && do {
563 $form->{fromdate} = "1.11.$form->{year}";
564 $form->{todate} = "30.11.$form->{year}";
567 $form->{duetyp} eq "12" && do {
568 $form->{fromdate} = "1.12.$form->{year}";
569 $form->{todate} = "31.12.$form->{year}";
573 hotfix_reformat_date();
577 # get for each account initial balance, debits and credits
578 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
581 $form->{rowcount} = scalar @{ $form->{TB} || [] };
582 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
585 "accno", "description",
586 "last_transaction", "soll_eb",
589 "soll_kumuliert", "haben_kumuliert",
590 "soll_saldo", "haben_saldo"
594 my $attachment_basename = $locale->text('trial_balance');
595 my $report = SL::ReportGenerator->new(\%myconfig, $form);
597 my @hidden_variables = qw(fromdate todate year method);
599 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
602 'accno' => { 'text' => $locale->text('Account'), },
603 'description' => { 'text' => $locale->text('Description'), },
604 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
605 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
606 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
607 'soll' => { 'text' => $locale->text('Debit'), },
608 'haben' => { 'text' => $locale->text('Credit'), },
609 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
610 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
611 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
612 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
617 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
619 map { $column_defs{$_}->{visible} = 1 } @columns;
621 $report->set_columns(%column_defs);
622 $report->set_column_order(@columns);
624 $report->set_export_options('generate_trial_balance', @hidden_variables);
629 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
631 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
632 push (@options, $form->{print_date});
634 $form->{company} = $locale->text('Company') . " " . $defaults->company;
635 push (@options, $form->{company});
638 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
640 my @custom_headers = ([
641 { text => $::locale->text('Account'), rowspan => 2, },
642 { text => $::locale->text('Description'), rowspan => 2, },
643 { text => $::locale->text('Last Transaction'), rowspan => 2, },
644 { text => $::locale->text('Starting Balance'), colspan => 2, },
645 { text => $::locale->text('Sum for') . " $form->{template_fromto}", colspan => 2, },
646 { text => $::locale->text('Sum per') . " $form->{template_to}", colspan => 2, },
647 { text => $::locale->text('Saldo per') . " $form->{template_to}", colspan => 2, },
652 { text => $::locale->text('Assets'), },
653 { text => $::locale->text('Equity'), },
654 { text => $::locale->text('Debit'), },
655 { text => $::locale->text('Credit'), },
656 { text => $::locale->text('Debit'), },
657 { text => $::locale->text('Credit'), },
658 { text => $::locale->text('Debit'), },
659 { text => $::locale->text('Credit'), },
662 $report->set_options('output_format' => 'HTML',
663 'top_info_text' => join("\n", @options),
664 'title' => $form->{title},
665 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
666 'html_template' => 'rp/html_report_susa',
667 'pdf_template' => 'rp/html_report_susa',
669 $report->set_custom_headers(@custom_headers);
670 $report->set_options_from_form();
671 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
673 # add sort and escape callback, this one we use for the add sub
674 $form->{callback} = $href .= "&sort=$form->{sort}";
676 # escape callback for href
677 my $callback = $form->escape($href);
679 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
681 my %totals = map { $_ => 0 } @subtotal_columns;
683 my $edit_url = build_std_url('action=edit', 'type', 'vc');
686 foreach my $accno (@{ $form->{TB} || [] }) {
688 $accno->{soll} = $accno->{debit};
689 $accno->{haben} = $accno->{credit};
690 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
692 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
693 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
697 foreach my $column (@columns) {
699 'data' => $accno->{$column},
700 'align' => $column_alignment{$column},
704 $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}));
706 my $row_set = [ $row ];
709 $report->add_data($row_set);
714 $report->add_separator();
716 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
718 $report->generate_with_headers();
720 $main::lxdebug->leave_sub();
724 sub create_subtotal_row {
725 $main::lxdebug->enter_sub();
727 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
729 my $form = $main::form;
730 my %myconfig = %main::myconfig;
731 my $locale = $main::locale;
733 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
735 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
737 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
739 map { $totals->{$_} = 0 } @{ $subtotal_columns };
741 $main::lxdebug->leave_sub();
746 sub create_list_accounts_subtotal_row {
747 $main::lxdebug->enter_sub();
749 my ($subtotals, $columns, $fields, $class) = @_;
751 my $form = $main::form;
752 my %myconfig = %main::myconfig;
753 my $locale = $main::locale;
755 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
757 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
759 $main::lxdebug->leave_sub();
765 $main::lxdebug->enter_sub();
769 my $form = $main::form;
770 my %myconfig = %main::myconfig;
771 my $locale = $main::locale;
774 if ($form->{department}) {
775 my ($department) = split /--/, $form->{department};
776 push @options, $locale->text('Department') . " : $department";
778 if ($form->{projectnumber}) {
779 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
782 # if there are any dates
783 if ($form->{fromdate} || $form->{todate}) {
784 my ($fromdate, $todate);
786 if ($form->{fromdate}) {
787 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
789 if ($form->{todate}) {
790 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
793 push @options, "$fromdate - $todate";
796 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
799 my @columns = qw(accno description begbalance debit credit endbalance);
801 'accno' => { 'text' => $locale->text('Account'), },
802 'description' => { 'text' => $locale->text('Description'), },
803 'debit' => { 'text' => $locale->text('Debit'), },
804 'credit' => { 'text' => $locale->text('Credit'), },
805 'begbalance' => { 'text' => $locale->text('Balance'), },
806 'endbalance' => { 'text' => $locale->text('Balance'), },
808 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
810 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
812 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
814 my $report = SL::ReportGenerator->new(\%myconfig, $form);
816 $report->set_options('top_info_text' => join("\n", @options),
817 'output_format' => 'HTML',
818 'title' => $form->{title},
819 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
820 'std_column_visibility' => 1,
822 $report->set_options_from_form();
823 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
825 $report->set_columns(%column_defs);
826 $report->set_column_order(@columns);
828 $report->set_export_options($action, @hidden_variables);
830 my @totals_columns = qw(credit debit begbalance endbalance);
831 my %subtotals = map { $_ => 0 } @totals_columns;
832 my %totals = map { $_ => 0 } @totals_columns;
833 my $found_heading = 0;
834 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
836 # sort the whole thing by account numbers and display
837 foreach my $idx (0 .. scalar(@tb) - 1) {
839 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
841 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
843 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
845 if ($ref->{charttype} eq 'H') {
846 next unless ($form->{l_heading});
848 %subtotals = map { $_ => 0 } @totals_columns;
850 $row->{description}->{class} = 'listheading';
851 $row->{description}->{data} = $ref->{description};
853 $report->add_data($row);
858 foreach (qw(debit credit)) {
859 $subtotals{$_} += $ref->{$_};
860 $totals{$_} += $ref->{$_};
863 $subtotals{begbalance} += $ref->{balance} * $ml;
864 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
866 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
867 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
869 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
870 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
872 $report->add_data($row);
874 if ($form->{l_heading} && $found_heading &&
875 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
876 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
880 $report->add_separator();
882 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
884 $report->generate_with_headers();
886 $main::lxdebug->leave_sub();
889 sub generate_ar_aging {
890 $main::lxdebug->enter_sub();
892 $main::auth->assert('general_ledger');
894 my $form = $main::form;
895 my %myconfig = %main::myconfig;
896 my $locale = $main::locale;
899 ($form->{customer}) = split(/--/, $form->{customer});
901 $form->{ct} = "customer";
902 $form->{arap} = "ar";
904 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
906 RP->aging(\%myconfig, \%$form);
909 $main::lxdebug->leave_sub();
912 sub generate_ap_aging {
913 $main::lxdebug->enter_sub();
915 $main::auth->assert('general_ledger');
917 my $form = $main::form;
918 my %myconfig = %main::myconfig;
919 my $locale = $main::locale;
922 ($form->{vendor}) = split(/--/, $form->{vendor});
924 $form->{ct} = "vendor";
925 $form->{arap} = "ap";
927 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
929 RP->aging(\%myconfig, \%$form);
932 $main::lxdebug->leave_sub();
935 sub create_aging_subtotal_row {
936 $main::lxdebug->enter_sub();
938 my ($subtotals, $columns, $periods, $class) = @_;
940 my $form = $main::form;
941 my %myconfig = %main::myconfig;
942 my $locale = $main::locale;
944 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
946 foreach (@{ $periods }) {
947 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
948 $subtotals->{$_} = 0;
951 $main::lxdebug->leave_sub();
957 $main::lxdebug->enter_sub();
959 $main::auth->assert('general_ledger');
961 my $form = $main::form;
962 my %myconfig = %main::myconfig;
963 my $locale = $main::locale;
964 my $cgi = $::request->{cgi};
966 my $report = SL::ReportGenerator->new(\%myconfig, $form);
968 my @columns = qw(statement ct invnumber transdate duedate amount open);
971 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
972 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
973 'invnumber' => { 'text' => $locale->text('Invoice'), },
974 'transdate' => { 'text' => $locale->text('Date'), },
975 'duedate' => { 'text' => $locale->text('Due'), },
976 'amount' => { 'text' => $locale->text('Amount'), },
977 'open' => { 'text' => $locale->text('Open'), },
980 my %column_alignment = ('statement' => 'center',
981 map { $_ => 'right' } qw(open amount));
983 $report->set_options('std_column_visibility' => 1);
984 $report->set_columns(%column_defs);
985 $report->set_column_order(@columns);
987 my @hidden_variables = qw(todate customer vendor arap title ct fordate reporttype);
988 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
991 my $attachment_basename;
993 if ($form->{department}) {
994 my ($department) = split /--/, $form->{department};
995 push @options, $locale->text('Department') . " : $department";
996 $form->{callback} .= "&department=" . E($department);
999 if (($form->{arap} eq 'ar') && $form->{customer}) {
1000 push @options, $form->{customer};
1001 $attachment_basename = $locale->text('ar_aging_list');
1002 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1005 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1006 push @options, $form->{vendor};
1007 $attachment_basename = $locale->text('ap_aging_list');
1008 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1011 if ($form->{fromdate}) {
1012 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1014 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1017 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1019 $report->set_options('top_info_text' => join("\n", @options),
1020 'output_format' => 'HTML',
1021 'title' => $form->{title},
1022 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1024 $report->set_options_from_form();
1025 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1027 my $previous_ctid = 0;
1029 my @periods = qw(open amount);
1030 my %subtotals = map { $_ => 0 } @periods;
1031 my %totals = map { $_ => 0 } @periods;
1033 foreach my $ref (@{ $form->{AG} }) {
1034 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1035 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1038 foreach my $key (@periods) {
1039 $subtotals{$key} += $ref->{"$key"};
1040 $totals{$key} += $ref->{"$key"};
1041 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1046 foreach my $column (@columns) {
1048 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1049 'align' => $column_alignment{$column},
1050 'valign' => $column eq 'statement' ? 'center' : '',
1054 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1056 if ($previous_ctid != $ref->{ctid}) {
1057 $row->{statement}->{raw_data} =
1058 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1059 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1060 $row->{ct}->{data} = $ref->{name};
1065 $previous_ctid = $ref->{ctid};
1067 $report->add_data($row);
1070 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1072 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1074 if ($form->{arap} eq 'ar') {
1075 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1076 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1077 'PRINT_OPTIONS' => print_options(inline => 1), });
1078 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1079 'raw_bottom_info_text' => $raw_bottom_info_text);
1082 $report->generate_with_headers();
1084 $main::lxdebug->leave_sub();
1088 $main::lxdebug->enter_sub();
1090 my $form = $main::form;
1091 my %myconfig = %main::myconfig;
1092 my $locale = $main::locale;
1094 RP->aging(\%myconfig, \%$form);
1096 map { $_->{checked} = "checked" } @{ $form->{AG} };
1100 $main::lxdebug->leave_sub();
1104 $::lxdebug->enter_sub;
1105 $::auth->assert('general_ledger');
1107 # get name and email addresses
1109 for my $i (1 .. $::form->{rowcount}) {
1110 next unless $::form->{"statement_$i"};
1111 $::form->{"$::form->{ct}_id"} = $::form->{"$::form->{ct}_id_$i"};
1112 RP->get_customer(\%::myconfig, $::form);
1117 $::form->error($::locale->text('Nothing selected!')) unless $selected;
1119 $::form->{media} = "email";
1121 # save all other variables
1123 for my $key (keys %$::form) {
1124 next if any { $key eq $_ } qw(login password action email cc bcc subject message type sendmode format header);
1125 next unless '' eq ref $::form->{$key};
1126 push @hidden_values, $key;
1130 print $::form->parse_html_template('rp/e_mail', {
1131 show_bcc => $::auth->assert('email_bcc', 'may fail'),
1132 print_options => print_options(inline => 1),
1133 hidden_values => \@hidden_values,
1136 $::lxdebug->leave_sub;
1140 $main::lxdebug->enter_sub();
1142 $main::auth->assert('general_ledger');
1144 my $form = $main::form;
1145 my %myconfig = %main::myconfig;
1146 my $locale = $main::locale;
1148 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1149 unless $form->{subject};
1151 RP->aging(\%myconfig, \%$form);
1153 $form->{"statement_1"} = 1;
1155 $form->{media} = 'email';
1158 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1160 $main::lxdebug->leave_sub();
1164 $main::lxdebug->enter_sub();
1166 $main::auth->assert('general_ledger');
1168 my $form = $main::form;
1169 my %myconfig = %main::myconfig;
1170 my $locale = $main::locale;
1172 if ($form->{media} eq 'printer') {
1173 $form->error($locale->text('Select postscript or PDF!'))
1174 if ($form->{format} !~ /(postscript|pdf)/);
1178 for my $i (1 .. $form->{rowcount}) {
1179 if ($form->{"statement_$i"}) {
1180 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1186 $form->error($locale->text('Nothing selected!')) unless $selected;
1188 if ($form->{media} eq 'printer') {
1189 $form->{"$form->{ct}_id"} = "";
1191 $form->{"statement_1"} = 1;
1194 RP->aging(\%myconfig, \%$form);
1198 $form->redirect($locale->text('Statements sent to printer!'))
1199 if ($form->{media} eq 'printer');
1201 $main::lxdebug->leave_sub();
1205 $main::lxdebug->enter_sub();
1207 $main::auth->assert('general_ledger');
1209 my $form = $main::form;
1210 my %myconfig = %main::myconfig;
1211 my $locale = $main::locale;
1213 my $defaults = SL::DB::Default->get;
1214 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
1215 $form->{templates} = $defaults->templates;
1217 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1219 my $suffix = "html";
1220 my $attachment_suffix = "html";
1221 if ($form->{format} eq 'postscript') {
1222 $form->{postscript} = 1;
1224 $attachment_suffix = "ps";
1225 } elsif ($form->{format} eq 'pdf') {
1228 $attachment_suffix = "pdf";
1231 $form->{IN} = "$form->{type}.$suffix";
1232 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1234 # Save $form->{email} because it will be overwritten.
1235 $form->{EMAIL_RECIPIENT} = $form->{email};
1239 while (@{ $form->{AG} }) {
1241 my $ref = shift @{ $form->{AG} };
1243 if ($ctid != $ref->{ctid}) {
1245 $ctid = $ref->{ctid};
1248 if ($form->{"statement_$i"}) {
1251 ("name", "street", "zipcode", "city", "country", "contact", "email",
1252 "$form->{ct}phone", "$form->{ct}fax");
1253 map { $form->{$_} = $ref->{$_} } @a;
1255 $form->{ $form->{ct} } = $form->{name};
1256 $form->{"$form->{ct}_id"} = $ref->{ctid};
1258 map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
1260 foreach my $item (qw(c0 c30 c60 c90)) {
1261 $form->{$item} = ();
1262 $form->{"${item}total"} = 0;
1265 &statement_details($ref);
1269 if (scalar(@{ $form->{AG} }) > 0) {
1271 # one or more left to go
1272 if ($ctid == $form->{AG}->[0]->{ctid}) {
1273 $ref = shift @{ $form->{AG} };
1274 &statement_details($ref);
1277 $ref = scalar(@{ $form->{AG} });
1283 # set initial ref to 0
1290 $form->{"${_}total"} =
1291 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1292 } ('c0', 'c30', 'c60', 'c90', "");
1294 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1295 $form->{attachment_filename} =~ s/\s+/_/g;
1297 $form->parse_template(\%myconfig);
1302 # saving the history
1303 if(!exists $form->{addition} && $form->{id} ne "") {
1304 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1305 $form->{addition} = "PRINTED";
1306 $form->{what_done} = $form->{type};
1307 $form->save_history;
1309 # /saving the history
1310 $main::lxdebug->leave_sub();
1313 sub statement_details {
1314 $main::lxdebug->enter_sub();
1316 $main::auth->assert('general_ledger');
1318 my $form = $main::form;
1319 my %myconfig = %main::myconfig;
1320 my $locale = $main::locale;
1324 push @{ $form->{invnumber} }, $ref->{invnumber};
1325 push @{ $form->{invdate} }, $ref->{transdate};
1326 push @{ $form->{duedate} }, $ref->{duedate};
1327 push @{ $form->{amount} }, $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
1328 push @{ $form->{open} }, $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
1330 foreach my $item (qw(c0 c30 c60 c90)) {
1331 if ($ref->{exchangerate} * 1) {
1332 # add only the open amount of the invoice to the aging, not the total amount
1333 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
1334 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
1335 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
1336 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
1338 $form->{"${item}total"} += $ref->{$item};
1339 $form->{total} += $ref->{$item};
1340 push @{ $form->{$item} },
1341 $form->format_amount(\%myconfig, $ref->{$item}, 2);
1344 $main::lxdebug->leave_sub();
1347 sub generate_tax_report {
1348 $::lxdebug->enter_sub;
1349 $::auth->assert('report');
1351 RP->tax_report(\%::myconfig, $::form);
1353 my $descvar = "$::form->{accno}_description";
1354 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
1358 my $callback = build_std_url('action=generate_tax_report', $descvar,
1359 qw(fromdate todate db method accno department report title));
1361 my @columns = $::form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1364 for my $item (@columns, 'subtotal') {
1365 if ($::form->{"l_$item"} eq "Y") {
1366 $callback .= "&l_$item=Y";
1367 $href .= "&l_$item=Y";
1371 for my $item (@columns) {
1372 if ($::form->{"l_$item"} eq "Y") {
1373 push @column_index, $item;
1378 if ($::form->{department}) {
1379 my ($department) = split /--/, $::form->{department};
1380 push @options, $::locale->text('Department') . " : $department";
1383 # if there are any dates
1384 if ($::form->{fromdate} || $::form->{todate}) {
1385 my $fromdate = $::form->{fromdate} ? $::locale->date(\%::myconfig, $::form->{fromdate}, 1) : '';
1386 my $todate = $::form->{todate} ? $::locale->date(\%::myconfig, $::form->{todate}, 1) : '';
1387 push @options, "$fromdate - $todate";
1389 push @options, $::locale->date(\%::myconfig, $::form->current_date, 1);
1392 my ($name, $invoice, $arap);
1393 if ($::form->{db} eq 'ar') {
1394 $name = $::locale->text('Customer');
1398 if ($::form->{db} eq 'ap') {
1399 $name = $::locale->text('Vendor');
1404 my %column_header = (
1405 id => $::locale->text('ID'),
1406 invnumber => $::locale->text('Invoice'),
1407 transdate => $::locale->text('Date'),
1408 netamount => $::locale->text('Amount'),
1409 tax => $::locale->text('Tax'),
1410 amount => $::locale->text('Total'),
1414 my %column_sorted = map { $_ => 1 } qw(id invnumber transdate);
1416 $callback .= "&sort=$::form->{sort}";
1419 if (@{ $::form->{TR} }) {
1420 $sameitem = $::form->{TR}->[0]->{ $::form->{sort} };
1423 my ($totalnetamount, $totaltax, @data);
1424 for my $ref (@{ $::form->{TR} }) {
1426 my $module = ($ref->{invoice}) ? $invoice : $arap;
1428 if ($::form->{l_subtotal} eq 'Y') {
1429 if ($sameitem ne $ref->{ $::form->{sort} }) {
1432 netamount => $subtotalnetamount,
1433 tax => $subtotaltax,
1434 amount => $subtotal,
1436 $subtotalnetamount = 0;
1438 $sameitem = $ref->{ $::form->{sort} };
1442 $subtotalnetamount += $ref->{netamount};
1443 $subtotaltax += $ref->{tax};
1444 $totalnetamount += $ref->{netamount};
1445 $totaltax += $ref->{tax};
1446 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1448 push @data, { map { $_ => { data => $ref->{$_} } } keys %$ref };
1449 $data[-1]{invnumber}{link} = "$module?action=edit&id=$ref->{id}&callback=$callback";
1450 $data[-1]{$_}{numeric} = 1 for qw(netamount tax amount);
1453 if ($::form->{l_subtotal} eq 'Y') {
1456 netamount => $subtotalnetamount,
1457 tax => $subtotaltax,
1458 amount => $subtotal,
1464 netamount => $totalnetamount,
1466 amount => $totalnetamount + $totaltax,
1470 print $::form->parse_html_template('rp/tax_report', {
1471 column_index => \@column_index,
1472 column_header => \%column_header,
1473 column_sorted => \%column_sorted,
1476 options => \@options,
1479 $::lxdebug->leave_sub;
1483 $main::lxdebug->enter_sub();
1485 $main::auth->assert('cash');
1487 my $form = $main::form;
1488 my %myconfig = %main::myconfig;
1489 my $locale = $main::locale;
1491 if ($form->{account}) {
1492 ($form->{paymentaccounts}) = split /--/, $form->{account};
1496 if ($form->{department}) {
1497 (my $department, $form->{department_id}) = split /--/, $form->{department};
1498 $option = $locale->text('Department') . " : $department";
1501 report_generator_set_default_sort('transdate', 1);
1503 RP->payments(\%myconfig, \%$form);
1505 my @hidden_variables = qw(account title department reference source memo fromdate todate
1506 fx_transaction db prepayment paymentaccounts sort);
1508 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
1509 $form->{callback} = $href;
1511 my @columns = qw(transdate invnumber name paid source memo);
1513 'name' => { 'text' => $locale->text('Description'), },
1514 'invnumber' => { 'text' => $locale->text('Reference'), },
1515 'transdate' => { 'text' => $locale->text('Date'), },
1516 'paid' => { 'text' => $locale->text('Amount'), },
1517 'source' => { 'text' => $locale->text('Source'), },
1518 'memo' => { 'text' => $locale->text('Memo'), },
1520 my %column_alignment = ('paid' => 'right');
1522 foreach my $name (grep { $_ ne 'paid' } @columns) {
1523 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1524 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
1528 if ($form->{fromdate}) {
1529 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
1531 if ($form->{todate}) {
1532 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1535 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1537 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
1539 $report->set_options('top_info_text' => join("\n", @options),
1540 'output_format' => 'HTML',
1541 'title' => $form->{title},
1542 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1543 'std_column_visibility' => 1,
1545 $report->set_options_from_form();
1547 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1549 $report->set_columns(%column_defs);
1550 $report->set_column_order(@columns);
1552 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
1554 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1558 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1559 next unless @{ $form->{ $ref->{id} } };
1561 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
1563 my $subtotal_paid = 0;
1565 foreach my $payment (@{ $form->{ $ref->{id} } }) {
1566 my $module = $payment->{module};
1567 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1568 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1570 $subtotal_paid += $payment->{paid};
1571 $total_paid += $payment->{paid};
1573 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
1577 foreach my $column (@columns) {
1579 'data' => $payment->{$column},
1580 'align' => $column_alignment{$column},
1584 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
1586 $report->add_data($row);
1589 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
1591 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
1593 'class' => 'listsubtotal',
1596 $report->add_data($row);
1599 $report->add_separator();
1601 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
1603 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
1605 'class' => 'listtotal',
1608 $report->add_data($row);
1610 $report->generate_with_headers();
1612 $main::lxdebug->leave_sub();
1616 $::lxdebug->enter_sub;
1618 my ($dont_print) = @_;
1620 $::form->{sendmode} = "attachment";
1621 $::form->{format} ||= $::myconfig{template_format} || "pdf";
1622 $::form->{copies} ||= $::myconfig{copies} || 2;
1624 $::form->{PD}{ $::form->{type} } = "selected";
1625 $::form->{DF}{ $::form->{format} } = "selected";
1626 $::form->{OP}{ $::form->{media} } = "selected";
1627 $::form->{SM}{ $::form->{sendmode} } = "selected";
1629 my $output = $::form->parse_html_template('rp/print_options', {
1630 got_printer => $::myconfig{printer},
1631 show_latex => $::lx_office_conf{print_templates}->{latex},
1632 is_email => $::form->{media} eq 'email',
1635 print $output unless $dont_print;
1637 $::lxdebug->leave_sub;
1643 $main::lxdebug->enter_sub();
1645 $main::auth->assert('report');
1647 my $form = $main::form;
1648 my %myconfig = %main::myconfig;
1649 my $locale = $main::locale;
1651 $form->{padding} = " ";
1652 $form->{bold} = "<b>";
1653 $form->{endbold} = "</b>";
1654 $form->{br} = "<br>";
1656 if ($form->{reporttype} eq "custom") {
1658 #forgotten the year --> thisyear
1659 if ($form->{year} !~ m/^\d\d\d\d$/) {
1660 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1666 if ($form->{duetyp} eq "13") {
1667 $form->{fromdate} = "1.1.$form->{year}";
1668 $form->{todate} = "31.12.$form->{year}";
1669 $form->{comparefromdate} = "1.01.$form->{year}";
1670 $form->{comparetodate} = "31.12.$form->{year}";
1674 if ($form->{duetyp} eq "A") {
1675 $form->{fromdate} = "1.1.$form->{year}";
1676 $form->{todate} = "31.3.$form->{year}";
1677 $form->{comparefromdate} = "1.01.$form->{year}";
1678 $form->{comparetodate} = "31.03.$form->{year}";
1680 if ($form->{duetyp} eq "B") {
1681 $form->{fromdate} = "1.4.$form->{year}";
1682 $form->{todate} = "30.6.$form->{year}";
1683 $form->{comparefromdate} = "1.01.$form->{year}";
1684 $form->{comparetodate} = "30.06.$form->{year}";
1686 if ($form->{duetyp} eq "C") {
1687 $form->{fromdate} = "1.7.$form->{year}";
1688 $form->{todate} = "30.9.$form->{year}";
1689 $form->{comparefromdate} = "1.01.$form->{year}";
1690 $form->{comparetodate} = "30.09.$form->{year}";
1692 if ($form->{duetyp} eq "D") {
1693 $form->{fromdate} = "1.10.$form->{year}";
1694 $form->{todate} = "31.12.$form->{year}";
1695 $form->{comparefromdate} = "1.01.$form->{year}";
1696 $form->{comparetodate} = "31.12.$form->{year}";
1701 $form->{duetyp} eq "1" && do {
1702 $form->{fromdate} = "1.1.$form->{year}";
1703 $form->{todate} = "31.1.$form->{year}";
1704 $form->{comparefromdate} = "1.01.$form->{year}";
1705 $form->{comparetodate} = "31.01.$form->{year}";
1708 $form->{duetyp} eq "2" && do {
1709 $form->{fromdate} = "1.2.$form->{year}";
1711 #this works from 1901 to 2099, 1900 and 2100 fail.
1712 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1713 $form->{todate} = "$leap.2.$form->{year}";
1714 $form->{comparefromdate} = "1.01.$form->{year}";
1715 $form->{comparetodate} = "$leap.02.$form->{year}";
1718 $form->{duetyp} eq "3" && do {
1719 $form->{fromdate} = "1.3.$form->{year}";
1720 $form->{todate} = "31.3.$form->{year}";
1721 $form->{comparefromdate} = "1.01.$form->{year}";
1722 $form->{comparetodate} = "31.03.$form->{year}";
1725 $form->{duetyp} eq "4" && do {
1726 $form->{fromdate} = "1.4.$form->{year}";
1727 $form->{todate} = "30.4.$form->{year}";
1728 $form->{comparefromdate} = "1.01.$form->{year}";
1729 $form->{comparetodate} = "30.04.$form->{year}";
1732 $form->{duetyp} eq "5" && do {
1733 $form->{fromdate} = "1.5.$form->{year}";
1734 $form->{todate} = "31.5.$form->{year}";
1735 $form->{comparefromdate} = "1.01.$form->{year}";
1736 $form->{comparetodate} = "31.05.$form->{year}";
1739 $form->{duetyp} eq "6" && do {
1740 $form->{fromdate} = "1.6.$form->{year}";
1741 $form->{todate} = "30.6.$form->{year}";
1742 $form->{comparefromdate} = "1.01.$form->{year}";
1743 $form->{comparetodate} = "30.06.$form->{year}";
1746 $form->{duetyp} eq "7" && do {
1747 $form->{fromdate} = "1.7.$form->{year}";
1748 $form->{todate} = "31.7.$form->{year}";
1749 $form->{comparefromdate} = "1.01.$form->{year}";
1750 $form->{comparetodate} = "31.07.$form->{year}";
1753 $form->{duetyp} eq "8" && do {
1754 $form->{fromdate} = "1.8.$form->{year}";
1755 $form->{todate} = "31.8.$form->{year}";
1756 $form->{comparefromdate} = "1.01.$form->{year}";
1757 $form->{comparetodate} = "31.08.$form->{year}";
1760 $form->{duetyp} eq "9" && do {
1761 $form->{fromdate} = "1.9.$form->{year}";
1762 $form->{todate} = "30.9.$form->{year}";
1763 $form->{comparefromdate} = "1.01.$form->{year}";
1764 $form->{comparetodate} = "30.09.$form->{year}";
1767 $form->{duetyp} eq "10" && do {
1768 $form->{fromdate} = "1.10.$form->{year}";
1769 $form->{todate} = "31.10.$form->{year}";
1770 $form->{comparefromdate} = "1.01.$form->{year}";
1771 $form->{comparetodate} = "31.10.$form->{year}";
1774 $form->{duetyp} eq "11" && do {
1775 $form->{fromdate} = "1.11.$form->{year}";
1776 $form->{todate} = "30.11.$form->{year}";
1777 $form->{comparefromdate} = "1.01.$form->{year}";
1778 $form->{comparetodate} = "30.11.$form->{year}";
1781 $form->{duetyp} eq "12" && do {
1782 $form->{fromdate} = "1.12.$form->{year}";
1783 $form->{todate} = "31.12.$form->{year}";
1784 $form->{comparefromdate} = "1.01.$form->{year}";
1785 $form->{comparetodate} = "31.12.$form->{year}";
1789 hotfix_reformat_date();
1791 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
1792 # ansonsten ist die prüfung in RP.pm
1793 # if (defined ($form->{fromdate|todate}=='..'))
1795 if ($form->{fromdate}){
1796 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
1797 my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
1798 $datetime->set( month => 1,
1800 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
1802 if ($form->{todate}){
1803 $form->{comparetodate} = $form->{todate};
1807 RP->bwa(\%myconfig, \%$form);
1809 ($form->{department}) = split /--/, $form->{department};
1812 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1813 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1815 # if there are any dates construct a where
1816 if ($form->{fromdate} || $form->{todate}) {
1818 unless ($form->{todate}) {
1819 $form->{todate} = $form->current_date(\%myconfig);
1822 my %germandate = ("dateformat" => "dd.mm.yyyy");
1824 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
1825 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
1827 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
1828 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
1830 $form->{this_period} = "$shortfromdate\n$shorttodate";
1832 $locale->text('for Period')
1833 . qq|\n$longfromdate |
1834 . $locale->text('bis')
1838 $form->{report_date} = $locale->text('Report date') . ": " . $form->current_date;
1840 if ( $form->{method} eq 'cash' ) {
1841 $form->{accounting_method} = $locale->text('Cash accounting');
1842 } elsif ( $form->{method} eq 'accrual' ) {
1843 $form->{accounting_method} = $locale->text('Accrual accounting');
1845 $form->{accounting_method} = "";
1848 $form->{title} = $locale->text('BWA');
1851 print $form->parse_html_template('rp/bwa');
1853 $main::lxdebug->leave_sub();
1856 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
1857 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
1858 sub hotfix_reformat_date {
1860 $main::lxdebug->enter_sub();
1862 my $form = $main::form;
1863 my %myconfig = %main::myconfig;
1864 my $locale = $main::locale;
1866 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
1867 my $current_dateformat = $myconfig{dateformat};
1868 $myconfig{dateformat} = 'dd.mm.yyyy';
1869 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
1870 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
1871 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
1872 unless (!defined ($form->{comparefromdate}));
1873 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
1874 unless (!defined ($form->{comparetodate}));
1876 # Und wieder zurücksetzen
1877 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
1878 } # Ende Hotifx Bug 1388
1880 $main::lxdebug->leave_sub();