1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Antonio Gallardo <agssa@ibw.com.ni>
16 # Benjamin Lee <benjaminlee@consultant.com>
17 # Philip Reetz <p.reetz@linet-services.de>
20 # This program is free software; you can redistribute it and/or modify
21 # it under the terms of the GNU General Public License as published by
22 # the Free Software Foundation; either version 2 of the License, or
23 # (at your option) any later version.
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #======================================================================
34 # module for preparing Income Statement and Balance Sheet
36 #======================================================================
38 use POSIX qw(strftime);
43 use SL::ReportGenerator;
46 require "bin/mozilla/arap.pl";
47 require "bin/mozilla/common.pl";
48 require "bin/mozilla/reportgenerator.pl";
50 # note: this file was particularly hard to strictify.
51 # alot of the vars are passed carelessly between invocations
52 # should there be any missing vars, declare them globally
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
83 # $locale->text('Balance Sheet')
84 # $locale->text('Income Statement')
85 # $locale->text('Trial Balance')
86 # $locale->text('AR Aging')
87 # $locale->text('AP Aging')
88 # $locale->text('Search AR Aging')
89 # $locale->text('Search AP Aging')
90 # $locale->text('Tax collected')
91 # $locale->text('Tax paid')
92 # $locale->text('Receipts')
93 # $locale->text('Payments')
94 # $locale->text('Project Transactions')
95 # $locale->text('Non-taxable Sales')
96 # $locale->text('Non-taxable Purchases')
97 # $locale->text('Business evaluation')
99 # $form->parse_html_template('rp/html_report_susa')
101 my $rp_access_map = {
102 'projects' => 'report',
103 'ar_aging' => 'general_ledger',
104 'ap_aging' => 'general_ledger',
105 'receipts' => 'cash',
106 'payments' => 'cash',
107 'trial_balance' => 'report',
108 'income_statement' => 'report',
110 'balance_sheet' => 'report',
113 sub check_rp_access {
114 my $form = $main::form;
116 my $right = $rp_access_map->{$form->{report}};
117 $right ||= 'DOES_NOT_EXIST';
119 $main::auth->assert($right);
123 $::lxdebug->enter_sub;
128 balance_sheet => $::locale->text('Balance Sheet'),
129 income_statement => $::locale->text('Income Statement'),
130 trial_balance => $::locale->text('Trial Balance'),
131 ar_aging => $::locale->text('Search AR Aging'),
132 ap_aging => $::locale->text('Search AP Aging'),
133 tax_collected => $::locale->text('Tax collected'),
134 tax_paid => $::locale->text('Tax paid'),
135 nontaxable_sales => $::locale->text('Non-taxable Sales'),
136 nontaxable_purchases => $::locale->text('Non-taxable Purchases'),
137 receipts => $::locale->text('Receipts'),
138 payments => $::locale->text('Payments'),
139 projects => $::locale->text('Project Transactions'),
140 bwa => $::locale->text('Business evaluation'),
143 $::form->{title} = $title{$::form->{report}};
146 $::form->all_departments(\%::myconfig);
147 if (@{ $::form->{all_departments} || [] }) {
148 $::form->{selectdepartment} = "<option>\n";
149 map { $::form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $::form->{all_departments} || [] };
152 $::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
154 my $onload = qq|focus()|;
156 my $is_projects = $::form->{report} eq "projects";
157 my $is_income_statement = $::form->{report} eq "income_statement";
158 my $is_bwa = $::form->{report} eq "bwa";
159 my $is_balance_sheet = $::form->{report} eq "balance_sheet";
160 my $is_trial_balance = $::form->{report} eq "trial_balance";
161 my $is_taxreport = $::form->{report} =~ /^tax_/;
162 my $is_nontaxable = $::form->{report} =~ /^nontaxable_/;
163 my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
164 my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
166 # if (is_taxreport) {
167 # $::form->{db} = ($::form->{report} =~ /_collected/) ? "ar" : "ap";
168 # RP->get_taxaccounts(\%::myconfig, $::form);
171 # if ($is_nontaxable) {
172 # $::form->{db} = ($::form->{report} =~ /_sales/) ? "ar" : "ap";
175 my ($label, $nextsub, $vc);
177 my $is_sales = $::form->{report} eq 'ar_aging';
178 $label = $is_sales ? $::locale->text('Customer') : $::locale->text('Vendor');
179 $::form->{vc} = $is_sales ? 'customer' : 'vendor';
181 $nextsub = "generate_$::form->{report}";
184 $::form->all_vc(\%::myconfig, $::form->{vc}, $is_sales ? "AR" : "AP");
185 $vc .= "<option>$_->{name}--$_->{id}\n" for @{ $::form->{"all_$::form->{vc}"} };
187 ? qq|<select name=$::form->{vc}><option>\n$vc</select>|
188 : qq|<input name=$::form->{vc} size=35>|;
191 my ($selection, $paymentaccounts);
193 $::form->{db} = $::form->{report} =~ /payments$/ ? "ap" : "ar";
195 RP->paymentaccounts(\%::myconfig, $::form);
197 $selection = "<option>\n";
198 for my $ref (@{ $::form->{PR} }) {
199 $paymentaccounts .= "$ref->{accno} ";
200 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
205 print $::form->parse_html_template('rp/report', {
206 paymentaccounts => $paymentaccounts,
207 selection => $selection,
208 is_aging => $is_aging,
211 year => DateTime->today->year,
213 accrual => $::instance_conf->get_accounting_method ne 'cash',
214 cash => $::instance_conf->get_accounting_method eq 'cash',
215 is_payments => $is_payments,
216 is_trial_balance => $is_trial_balance,
217 is_balance_sheet => $is_balance_sheet,
219 is_income_statement => $is_income_statement,
220 is_projects => $is_projects,
223 $::lxdebug->leave_sub;
226 sub continue { call_sub($main::form->{"nextsub"}); }
229 $main::lxdebug->enter_sub();
231 $main::auth->assert('report');
233 my $form = $main::form;
234 my %myconfig = %main::myconfig;
235 my $locale = $main::locale;
239 $form->{project_id} = $form->{project_id_1};
240 if ($form->{projectnumber} && !$form->{project_id}) {
241 $form->{rowcount} = 1;
243 # call this instead of update
244 $form->{update} = $nextsub;
245 $form->{projectnumber_1} = $form->{projectnumber};
247 delete $form->{sort};
248 check_project('generate_projects');
250 # if there is one only, assign id
251 $form->{project_id} = $form->{project_id_1};
254 $main::lxdebug->leave_sub();
257 sub generate_income_statement {
258 $main::lxdebug->enter_sub();
260 $main::auth->assert('report');
262 my $form = $main::form;
263 my %myconfig = %main::myconfig;
264 my $locale = $main::locale;
266 $form->{padding} = " ";
267 $form->{bold} = "<b>";
268 $form->{endbold} = "</b>";
269 $form->{br} = "<br>";
271 if ($form->{reporttype} eq "custom") {
273 #forgotten the year --> thisyear
274 if ($form->{year} !~ m/^\d\d\d\d$/) {
275 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
281 if ($form->{duetyp} eq "13") {
282 $form->{fromdate} = "1.1.$form->{year}";
283 $form->{todate} = "31.12.$form->{year}";
287 if ($form->{duetyp} eq "A") {
288 $form->{fromdate} = "1.1.$form->{year}";
289 $form->{todate} = "31.3.$form->{year}";
291 if ($form->{duetyp} eq "B") {
292 $form->{fromdate} = "1.4.$form->{year}";
293 $form->{todate} = "30.6.$form->{year}";
295 if ($form->{duetyp} eq "C") {
296 $form->{fromdate} = "1.7.$form->{year}";
297 $form->{todate} = "30.9.$form->{year}";
299 if ($form->{duetyp} eq "D") {
300 $form->{fromdate} = "1.10.$form->{year}";
301 $form->{todate} = "31.12.$form->{year}";
306 $form->{duetyp} eq "1" && do {
307 $form->{fromdate} = "1.1.$form->{year}";
308 $form->{todate} = "31.1.$form->{year}";
311 $form->{duetyp} eq "2" && do {
312 $form->{fromdate} = "1.2.$form->{year}";
314 #this works from 1901 to 2099, 1900 and 2100 fail.
315 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
316 $form->{todate} = "$leap.2.$form->{year}";
319 $form->{duetyp} eq "3" && do {
320 $form->{fromdate} = "1.3.$form->{year}";
321 $form->{todate} = "31.3.$form->{year}";
324 $form->{duetyp} eq "4" && do {
325 $form->{fromdate} = "1.4.$form->{year}";
326 $form->{todate} = "30.4.$form->{year}";
329 $form->{duetyp} eq "5" && do {
330 $form->{fromdate} = "1.5.$form->{year}";
331 $form->{todate} = "31.5.$form->{year}";
334 $form->{duetyp} eq "6" && do {
335 $form->{fromdate} = "1.6.$form->{year}";
336 $form->{todate} = "30.6.$form->{year}";
339 $form->{duetyp} eq "7" && do {
340 $form->{fromdate} = "1.7.$form->{year}";
341 $form->{todate} = "31.7.$form->{year}";
344 $form->{duetyp} eq "8" && do {
345 $form->{fromdate} = "1.8.$form->{year}";
346 $form->{todate} = "31.8.$form->{year}";
349 $form->{duetyp} eq "9" && do {
350 $form->{fromdate} = "1.9.$form->{year}";
351 $form->{todate} = "30.9.$form->{year}";
354 $form->{duetyp} eq "10" && do {
355 $form->{fromdate} = "1.10.$form->{year}";
356 $form->{todate} = "31.10.$form->{year}";
359 $form->{duetyp} eq "11" && do {
360 $form->{fromdate} = "1.11.$form->{year}";
361 $form->{todate} = "30.11.$form->{year}";
364 $form->{duetyp} eq "12" && do {
365 $form->{fromdate} = "1.12.$form->{year}";
366 $form->{todate} = "31.12.$form->{year}";
370 hotfix_reformat_date();
371 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
373 RP->income_statement(\%myconfig, \%$form);
375 ($form->{department}) = split /--/, $form->{department};
378 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
379 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
381 # if there are any dates construct a where
382 if ($form->{fromdate} || $form->{todate}) {
384 unless ($form->{todate}) {
385 $form->{todate} = $form->current_date(\%myconfig);
388 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
389 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
391 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
392 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
394 $form->{this_period} = "$shortfromdate\n$shorttodate";
396 $locale->text('for Period')
397 . qq|\n$longfromdate |
398 . $locale->text('Bis')
402 if ($form->{comparefromdate} || $form->{comparetodate}) {
403 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
404 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
406 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
407 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
409 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
411 "\n$longcomparefromdate "
412 . $locale->text('Bis')
413 . qq| $longcomparetodate|;
416 # setup variables for the form
417 my @a = qw(company address businessnumber);
418 map { $form->{$_} = $myconfig{$_} } @a;
420 $form->{templates} = $myconfig{templates};
422 $form->{IN} = "income_statement.html";
424 $form->parse_template;
426 $main::lxdebug->leave_sub();
429 sub generate_balance_sheet {
430 $::lxdebug->enter_sub;
431 $::auth->assert('report');
433 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
434 $::form->{padding} = " ";
435 $::form->{bold} = "<b>";
436 $::form->{endbold} = "</b>";
437 $::form->{br} = "<br>";
439 my $data = RP->balance_sheet(\%::myconfig, $::form);
441 $::form->{asofdate} ||= $::form->current_date;
442 $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
444 ($::form->{department}) = split /--/, $::form->{department};
446 # define Current Earnings account
447 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
448 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
450 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
451 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
453 # $::form->{IN} = "balance_sheet.html";
455 # setup company variables for the form
456 map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
458 $::form->{templates} = $::myconfig{templates};
461 print $::form->parse_html_template('rp/balance_sheet', $data);
463 $::lxdebug->leave_sub;
466 sub generate_projects {
467 $main::lxdebug->enter_sub();
469 $main::auth->assert('report');
471 my $form = $main::form;
472 my %myconfig = %main::myconfig;
473 my $locale = $main::locale;
475 &get_project("generate_projects");
476 $form->{projectnumber} = $form->{projectnumber_1};
478 $form->{nextsub} = "generate_projects";
479 $form->{title} = $locale->text('Project Transactions');
480 RP->trial_balance(\%myconfig, \%$form);
482 list_accounts('generate_projects');
484 $main::lxdebug->leave_sub();
490 # included links to display transactions for period entered
491 # added headers and subtotals
493 sub generate_trial_balance {
494 $main::lxdebug->enter_sub();
496 $main::auth->assert('report');
498 my $form = $main::form;
499 my %myconfig = %main::myconfig;
500 my $locale = $main::locale;
502 if ($form->{reporttype} eq "custom") {
504 #forgotten the year --> thisyear
505 if ($form->{year} !~ m/^\d\d\d\d$/) {
506 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
512 if ($form->{duetyp} eq "13") {
513 $form->{fromdate} = "1.1.$form->{year}";
514 $form->{todate} = "31.12.$form->{year}";
518 if ($form->{duetyp} eq "A") {
519 $form->{fromdate} = "1.1.$form->{year}";
520 $form->{todate} = "31.3.$form->{year}";
522 if ($form->{duetyp} eq "B") {
523 $form->{fromdate} = "1.4.$form->{year}";
524 $form->{todate} = "30.6.$form->{year}";
526 if ($form->{duetyp} eq "C") {
527 $form->{fromdate} = "1.7.$form->{year}";
528 $form->{todate} = "30.9.$form->{year}";
530 if ($form->{duetyp} eq "D") {
531 $form->{fromdate} = "1.10.$form->{year}";
532 $form->{todate} = "31.12.$form->{year}";
537 $form->{duetyp} eq "1" && do {
538 $form->{fromdate} = "1.1.$form->{year}";
539 $form->{todate} = "31.1.$form->{year}";
542 $form->{duetyp} eq "2" && do {
543 $form->{fromdate} = "1.2.$form->{year}";
545 #this works from 1901 to 2099, 1900 and 2100 fail.
546 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
547 $form->{todate} = "$leap.2.$form->{year}";
550 $form->{duetyp} eq "3" && do {
551 $form->{fromdate} = "1.3.$form->{year}";
552 $form->{todate} = "31.3.$form->{year}";
555 $form->{duetyp} eq "4" && do {
556 $form->{fromdate} = "1.4.$form->{year}";
557 $form->{todate} = "30.4.$form->{year}";
560 $form->{duetyp} eq "5" && do {
561 $form->{fromdate} = "1.5.$form->{year}";
562 $form->{todate} = "31.5.$form->{year}";
565 $form->{duetyp} eq "6" && do {
566 $form->{fromdate} = "1.6.$form->{year}";
567 $form->{todate} = "30.6.$form->{year}";
570 $form->{duetyp} eq "7" && do {
571 $form->{fromdate} = "1.7.$form->{year}";
572 $form->{todate} = "31.7.$form->{year}";
575 $form->{duetyp} eq "8" && do {
576 $form->{fromdate} = "1.8.$form->{year}";
577 $form->{todate} = "31.8.$form->{year}";
580 $form->{duetyp} eq "9" && do {
581 $form->{fromdate} = "1.9.$form->{year}";
582 $form->{todate} = "30.9.$form->{year}";
585 $form->{duetyp} eq "10" && do {
586 $form->{fromdate} = "1.10.$form->{year}";
587 $form->{todate} = "31.10.$form->{year}";
590 $form->{duetyp} eq "11" && do {
591 $form->{fromdate} = "1.11.$form->{year}";
592 $form->{todate} = "30.11.$form->{year}";
595 $form->{duetyp} eq "12" && do {
596 $form->{fromdate} = "1.12.$form->{year}";
597 $form->{todate} = "31.12.$form->{year}";
601 hotfix_reformat_date();
605 # get for each account initial balance, debits and credits
606 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
609 $form->{rowcount} = scalar @{ $form->{TB} || [] };
610 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
613 "accno", "description",
614 "last_transaction", "soll_eb",
617 "soll_kumuliert", "haben_kumuliert",
618 "soll_saldo", "haben_saldo"
622 my $attachment_basename = $locale->text('trial_balance');
623 my $report = SL::ReportGenerator->new(\%myconfig, $form);
625 my @hidden_variables = qw(fromdate todate year cash);
627 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
630 'accno' => { 'text' => $locale->text('Account'), },
631 'description' => { 'text' => $locale->text('Description'), },
632 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
633 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
634 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
635 'soll' => { 'text' => $locale->text('Debit'), },
636 'haben' => { 'text' => $locale->text('Credit'), },
637 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
638 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
639 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
640 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
645 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
647 map { $column_defs{$_}->{visible} = 1 } @columns;
649 $report->set_columns(%column_defs);
650 $report->set_column_order(@columns);
652 $report->set_export_options('generate_trial_balance', @hidden_variables);
657 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
659 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
660 push (@options, $form->{print_date});
662 $form->{company} = $locale->text('Company') . " " . $myconfig{company};
663 push (@options, $form->{company});
666 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
668 $report->set_options('output_format' => 'HTML',
669 'top_info_text' => join("\n", @options),
670 'title' => $form->{title},
671 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
672 'html_template' => 'rp/html_report_susa',
673 'pdf_template' => 'rp/html_report_susa',
675 $report->set_options_from_form();
676 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
678 # add sort and escape callback, this one we use for the add sub
679 $form->{callback} = $href .= "&sort=$form->{sort}";
681 # escape callback for href
682 my $callback = $form->escape($href);
684 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
686 my %totals = map { $_ => 0 } @subtotal_columns;
688 my $edit_url = build_std_url('action=edit', 'type', 'vc');
691 foreach my $accno (@{ $form->{TB} || [] }) {
693 $accno->{soll} = $accno->{debit};
694 $accno->{haben} = $accno->{credit};
695 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
697 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
698 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
702 foreach my $column (@columns) {
704 'data' => $accno->{$column},
705 'align' => $column_alignment{$column},
709 $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}));
711 my $row_set = [ $row ];
714 $report->add_data($row_set);
719 $report->add_separator();
721 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
723 $report->generate_with_headers();
725 $main::lxdebug->leave_sub();
729 sub create_subtotal_row {
730 $main::lxdebug->enter_sub();
732 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
734 my $form = $main::form;
735 my %myconfig = %main::myconfig;
736 my $locale = $main::locale;
738 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
740 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
742 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
744 map { $totals->{$_} = 0 } @{ $subtotal_columns };
746 $main::lxdebug->leave_sub();
751 sub create_list_accounts_subtotal_row {
752 $main::lxdebug->enter_sub();
754 my ($subtotals, $columns, $fields, $class) = @_;
756 my $form = $main::form;
757 my %myconfig = %main::myconfig;
758 my $locale = $main::locale;
760 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
762 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
764 $main::lxdebug->leave_sub();
770 $main::lxdebug->enter_sub();
774 my $form = $main::form;
775 my %myconfig = %main::myconfig;
776 my $locale = $main::locale;
779 if ($form->{department}) {
780 my ($department) = split /--/, $form->{department};
781 push @options, $locale->text('Department') . " : $department";
783 if ($form->{projectnumber}) {
784 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
787 # if there are any dates
788 if ($form->{fromdate} || $form->{todate}) {
789 my ($fromdate, $todate);
791 if ($form->{fromdate}) {
792 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
794 if ($form->{todate}) {
795 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
798 push @options, "$fromdate - $todate";
801 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
804 my @columns = qw(accno description begbalance debit credit endbalance);
806 'accno' => { 'text' => $locale->text('Account'), },
807 'description' => { 'text' => $locale->text('Description'), },
808 'debit' => { 'text' => $locale->text('Debit'), },
809 'credit' => { 'text' => $locale->text('Credit'), },
810 'begbalance' => { 'text' => $locale->text('Balance'), },
811 'endbalance' => { 'text' => $locale->text('Balance'), },
813 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
815 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
817 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
819 my $report = SL::ReportGenerator->new(\%myconfig, $form);
821 $report->set_options('top_info_text' => join("\n", @options),
822 'output_format' => 'HTML',
823 'title' => $form->{title},
824 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
825 'std_column_visibility' => 1,
827 $report->set_options_from_form();
828 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
830 $report->set_columns(%column_defs);
831 $report->set_column_order(@columns);
833 $report->set_export_options($action, @hidden_variables);
835 my @totals_columns = qw(credit debit begbalance endbalance);
836 my %subtotals = map { $_ => 0 } @totals_columns;
837 my %totals = map { $_ => 0 } @totals_columns;
838 my $found_heading = 0;
839 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
841 # sort the whole thing by account numbers and display
842 foreach my $idx (0 .. scalar(@tb) - 1) {
844 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
846 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
848 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
850 if ($ref->{charttype} eq 'H') {
851 next unless ($form->{l_heading});
853 %subtotals = map { $_ => 0 } @totals_columns;
855 $row->{description}->{class} = 'listheading';
856 $row->{description}->{data} = $ref->{description};
858 $report->add_data($row);
863 foreach (qw(debit credit)) {
864 $subtotals{$_} += $ref->{$_};
865 $totals{$_} += $ref->{$_};
868 $subtotals{begbalance} += $ref->{balance} * $ml;
869 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
871 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
872 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
874 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
875 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
877 $report->add_data($row);
879 if ($form->{l_heading} && $found_heading &&
880 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
881 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
885 $report->add_separator();
887 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
889 $report->generate_with_headers();
891 $main::lxdebug->leave_sub();
894 sub generate_ar_aging {
895 $main::lxdebug->enter_sub();
897 $main::auth->assert('general_ledger');
899 my $form = $main::form;
900 my %myconfig = %main::myconfig;
901 my $locale = $main::locale;
904 ($form->{customer}) = split(/--/, $form->{customer});
906 $form->{ct} = "customer";
907 $form->{arap} = "ar";
909 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
911 RP->aging(\%myconfig, \%$form);
914 $main::lxdebug->leave_sub();
917 sub generate_ap_aging {
918 $main::lxdebug->enter_sub();
920 $main::auth->assert('general_ledger');
922 my $form = $main::form;
923 my %myconfig = %main::myconfig;
924 my $locale = $main::locale;
927 ($form->{vendor}) = split(/--/, $form->{vendor});
929 $form->{ct} = "vendor";
930 $form->{arap} = "ap";
932 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
934 RP->aging(\%myconfig, \%$form);
937 $main::lxdebug->leave_sub();
940 sub create_aging_subtotal_row {
941 $main::lxdebug->enter_sub();
943 my ($subtotals, $columns, $periods, $class) = @_;
945 my $form = $main::form;
946 my %myconfig = %main::myconfig;
947 my $locale = $main::locale;
949 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
951 foreach (@{ $periods }) {
952 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
953 $subtotals->{$_} = 0;
956 $main::lxdebug->leave_sub();
962 $main::lxdebug->enter_sub();
964 $main::auth->assert('general_ledger');
966 my $form = $main::form;
967 my %myconfig = %main::myconfig;
968 my $locale = $main::locale;
969 my $cgi = $::request->{cgi};
971 my $report = SL::ReportGenerator->new(\%myconfig, $form);
973 my @columns = qw(statement ct invnumber transdate duedate amount open);
976 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
977 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
978 'invnumber' => { 'text' => $locale->text('Invoice'), },
979 'transdate' => { 'text' => $locale->text('Date'), },
980 'duedate' => { 'text' => $locale->text('Due'), },
981 'amount' => { 'text' => $locale->text('Amount'), },
982 'open' => { 'text' => $locale->text('Open'), },
985 my %column_alignment = ('statement' => 'center',
986 map { $_ => 'right' } qw(open amount));
988 $report->set_options('std_column_visibility' => 1);
989 $report->set_columns(%column_defs);
990 $report->set_column_order(@columns);
992 my @hidden_variables = qw(todate customer vendor arap title ct);
993 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
996 my $attachment_basename;
998 if ($form->{department}) {
999 my ($department) = split /--/, $form->{department};
1000 push @options, $locale->text('Department') . " : $department";
1001 $form->{callback} .= "&department=" . E($department);
1004 if (($form->{arap} eq 'ar') && $form->{customer}) {
1005 push @options, $form->{customer};
1006 $attachment_basename = $locale->text('ar_aging_list');
1007 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1010 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1011 push @options, $form->{vendor};
1012 $attachment_basename = $locale->text('ap_aging_list');
1013 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1016 if ($form->{fromdate}) {
1017 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1019 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1022 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1024 $report->set_options('top_info_text' => join("\n", @options),
1025 'output_format' => 'HTML',
1026 'title' => $form->{title},
1027 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1029 $report->set_options_from_form();
1030 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1032 my $previous_ctid = 0;
1034 my @periods = qw(open amount);
1035 my %subtotals = map { $_ => 0 } @periods;
1036 my %totals = map { $_ => 0 } @periods;
1038 foreach my $ref (@{ $form->{AG} }) {
1039 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1040 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1043 foreach my $key (@periods) {
1044 $subtotals{$key} += $ref->{"$key"};
1045 $totals{$key} += $ref->{"$key"};
1046 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1051 foreach my $column (@columns) {
1053 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1054 'align' => $column_alignment{$column},
1055 'valign' => $column eq 'statement' ? 'center' : '',
1059 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1061 if ($previous_ctid != $ref->{ctid}) {
1062 $row->{statement}->{raw_data} =
1063 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1064 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1065 $row->{ct}->{data} = $ref->{name};
1070 $previous_ctid = $ref->{ctid};
1072 $report->add_data($row);
1075 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1077 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1079 if ($form->{arap} eq 'ar') {
1080 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1081 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1082 'PRINT_OPTIONS' => print_options(inline => 1), });
1083 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1084 'raw_bottom_info_text' => $raw_bottom_info_text);
1087 $report->generate_with_headers();
1089 $main::lxdebug->leave_sub();
1093 $main::lxdebug->enter_sub();
1095 my $form = $main::form;
1096 my %myconfig = %main::myconfig;
1097 my $locale = $main::locale;
1099 RP->aging(\%myconfig, \%$form);
1101 map { $_->{checked} = "checked" } @{ $form->{AG} };
1105 $main::lxdebug->leave_sub();
1109 $main::lxdebug->enter_sub();
1111 $main::auth->assert('general_ledger');
1113 my $form = $main::form;
1114 my %myconfig = %main::myconfig;
1115 my $locale = $main::locale;
1117 # get name and email addresses
1119 for my $i (1 .. $form->{rowcount}) {
1120 if ($form->{"statement_$i"}) {
1121 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1122 RP->get_customer(\%myconfig, \%$form);
1128 $form->error($locale->text('Nothing selected!')) unless $selected;
1131 if ($myconfig{role} eq 'admin') {
1133 <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1134 <td><input name=bcc size=30 value="$form->{bcc}"></td>
1138 my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1140 $form->{media} = "email";
1147 <form method=post action=$form->{script}>
1153 <tr height="5"></tr>
1158 <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1159 <td><input name=email size=30 value="$form->{email}"></td>
1160 <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1161 <td><input name=cc size=30 value="$form->{cc}"></td>
1164 <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1165 <td><input name=subject size=30 value="$form->{subject}"></td>
1175 <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1178 <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1189 map { delete $form->{$_} }
1190 qw(action email cc bcc subject message type sendmode format header);
1192 # save all other variables
1193 foreach my $key (keys %$form) {
1194 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1195 $form->{$key} =~ s/\"/"/g;
1196 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1203 <td><hr size=3 noshade></td>
1207 <input type=hidden name=nextsub value=send_email>
1210 <input name=action class=submit type=submit value="|
1211 . $locale->text('Continue') . qq|">
1218 $main::lxdebug->leave_sub();
1222 $main::lxdebug->enter_sub();
1224 $main::auth->assert('general_ledger');
1226 my $form = $main::form;
1227 my %myconfig = %main::myconfig;
1228 my $locale = $main::locale;
1230 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1231 unless $form->{subject};
1233 RP->aging(\%myconfig, \%$form);
1235 $form->{"statement_1"} = 1;
1237 $form->{media} = 'email';
1240 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1242 $main::lxdebug->leave_sub();
1246 $main::lxdebug->enter_sub();
1248 $main::auth->assert('general_ledger');
1250 my $form = $main::form;
1251 my %myconfig = %main::myconfig;
1252 my $locale = $main::locale;
1254 if ($form->{media} eq 'printer') {
1255 $form->error($locale->text('Select postscript or PDF!'))
1256 if ($form->{format} !~ /(postscript|pdf)/);
1260 for my $i (1 .. $form->{rowcount}) {
1261 if ($form->{"statement_$i"}) {
1262 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1268 $form->error($locale->text('Nothing selected!')) unless $selected;
1270 if ($form->{media} eq 'printer') {
1271 $form->{"$form->{ct}_id"} = "";
1273 $form->{"statement_1"} = 1;
1276 RP->aging(\%myconfig, \%$form);
1280 $form->redirect($locale->text('Statements sent to printer!'))
1281 if ($form->{media} eq 'printer');
1283 $main::lxdebug->leave_sub();
1287 $main::lxdebug->enter_sub();
1289 $main::auth->assert('general_ledger');
1291 my $form = $main::form;
1292 my %myconfig = %main::myconfig;
1293 my $locale = $main::locale;
1295 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1297 $form->{templates} = "$myconfig{templates}";
1299 my $suffix = "html";
1300 my $attachment_suffix = "html";
1301 if ($form->{format} eq 'postscript') {
1302 $form->{postscript} = 1;
1304 $attachment_suffix = "ps";
1305 } elsif ($form->{format} eq 'pdf') {
1308 $attachment_suffix = "pdf";
1311 $form->{IN} = "$form->{type}.$suffix";
1312 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1314 # Save $form->{email} because it will be overwritten.
1315 $form->{EMAIL_RECIPIENT} = $form->{email};
1319 while (@{ $form->{AG} }) {
1321 my $ref = shift @{ $form->{AG} };
1323 if ($ctid != $ref->{ctid}) {
1325 $ctid = $ref->{ctid};
1328 if ($form->{"statement_$i"}) {
1331 ("name", "street", "zipcode", "city", "country", "contact", "email",
1332 "$form->{ct}phone", "$form->{ct}fax");
1333 map { $form->{$_} = $ref->{$_} } @a;
1335 $form->{ $form->{ct} } = $form->{name};
1336 $form->{"$form->{ct}_id"} = $ref->{ctid};
1338 map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
1340 foreach my $item (qw(c0 c30 c60 c90)) {
1341 $form->{$item} = ();
1342 $form->{"${item}total"} = 0;
1345 &statement_details($ref);
1349 if (scalar(@{ $form->{AG} }) > 0) {
1351 # one or more left to go
1352 if ($ctid == $form->{AG}->[0]->{ctid}) {
1353 $ref = shift @{ $form->{AG} };
1354 &statement_details($ref);
1357 $ref = scalar(@{ $form->{AG} });
1363 # set initial ref to 0
1370 $form->{"${_}total"} =
1371 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1372 } ('c0', 'c30', 'c60', 'c90', "");
1374 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1375 $form->{attachment_filename} =~ s/\s+/_/g;
1377 $form->parse_template(\%myconfig);
1382 # saving the history
1383 if(!exists $form->{addition} && $form->{id} ne "") {
1384 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1385 $form->{addition} = "PRINTED";
1386 $form->{what_done} = $form->{type};
1387 $form->save_history;
1389 # /saving the history
1390 $main::lxdebug->leave_sub();
1393 sub statement_details {
1394 $main::lxdebug->enter_sub();
1396 $main::auth->assert('general_ledger');
1398 my $form = $main::form;
1399 my %myconfig = %main::myconfig;
1400 my $locale = $main::locale;
1404 push @{ $form->{invnumber} }, $ref->{invnumber};
1405 push @{ $form->{invdate} }, $ref->{transdate};
1406 push @{ $form->{duedate} }, $ref->{duedate};
1407 push @{ $form->{amount} }, $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
1408 push @{ $form->{open} }, $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
1410 foreach my $item (qw(c0 c30 c60 c90)) {
1411 if ($ref->{exchangerate} * 1) {
1412 # add only the open amount of the invoice to the aging, not the total amount
1413 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
1414 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
1415 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
1416 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
1418 $form->{"${item}total"} += $ref->{$item};
1419 $form->{total} += $ref->{$item};
1420 push @{ $form->{$item} },
1421 $form->format_amount(\%myconfig, $ref->{$item}, 2);
1424 $main::lxdebug->leave_sub();
1427 sub generate_tax_report {
1428 $main::lxdebug->enter_sub();
1430 $main::auth->assert('report');
1432 my $form = $main::form;
1433 my %myconfig = %main::myconfig;
1434 my $locale = $main::locale;
1436 RP->tax_report(\%myconfig, \%$form);
1438 my $descvar = "$form->{accno}_description";
1439 my $description = $form->escape($form->{$descvar});
1440 my $ratevar = "$form->{accno}_rate";
1441 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
1443 my $department = $form->escape($form->{department});
1447 "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}";
1449 # construct callback
1450 $description = $form->escape($form->{$descvar}, 1);
1451 $department = $form->escape($form->{department}, 1);
1453 "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}";
1455 my $title = $form->escape($form->{title});
1456 $href .= "&title=$title";
1457 $title = $form->escape($form->{title}, 1);
1458 $callback .= "&title=$title";
1460 $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
1463 $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1466 foreach my $item (@columns) {
1467 if ($form->{"l_$item"} eq "Y") {
1468 push @column_index, $item;
1470 # add column to href and callback
1471 $callback .= "&l_$item=Y";
1472 $href .= "&l_$item=Y";
1476 if ($form->{l_subtotal} eq 'Y') {
1477 $callback .= "&l_subtotal=Y";
1478 $href .= "&l_subtotal=Y";
1482 if ($form->{department}) {
1483 ($department) = split /--/, $form->{department};
1484 $option = $locale->text('Department') . " : $department";
1487 my ($fromdate, $todate);
1488 # if there are any dates
1489 if ($form->{fromdate} || $form->{todate}) {
1490 if ($form->{fromdate}) {
1491 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1493 if ($form->{todate}) {
1494 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1497 $form->{period} = "$fromdate - $todate";
1500 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1503 my ($name, $invoice, $arap);
1504 if ($form->{db} eq 'ar') {
1505 $name = $locale->text('Customer');
1509 if ($form->{db} eq 'ap') {
1510 $name = $locale->text('Vendor');
1515 $option .= "<br>" if $option;
1516 $option .= "$form->{period}";
1519 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
1520 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
1521 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
1522 $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1523 $column_header{tax} = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1524 $column_header{amount} = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1526 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
1535 <th class=listtop>$form->{title}</th>
1537 <tr height="5"></tr>
1544 <tr class=listheading>
1547 map { print "$column_header{$_}\n" } @column_index;
1553 # add sort and escape callback
1554 $callback = $form->escape($callback . "&sort=$form->{sort}");
1557 if (@{ $form->{TR} }) {
1558 $sameitem = $form->{TR}->[0]->{ $form->{sort} };
1561 my ($totalnetamount, $totaltax);
1563 foreach my $ref (@{ $form->{TR} }) {
1565 my $module = ($ref->{invoice}) ? $invoice : $arap;
1567 if ($form->{l_subtotal} eq 'Y') {
1568 if ($sameitem ne $ref->{ $form->{sort} }) {
1569 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
1570 $sameitem = $ref->{ $form->{sort} };
1574 $totalnetamount += $ref->{netamount};
1575 $totaltax += $ref->{tax};
1576 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1578 $subtotalnetamount += $ref->{netamount};
1579 $subtotaltax += $ref->{tax};
1582 $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
1583 } qw(netamount tax amount);
1586 $column_data{id} = qq|<td>$ref->{id}</td>|;
1587 $column_data{invnumber} =
1588 qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
1589 $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
1590 $column_data{name} = qq|<td>$ref->{name} </td>|;
1592 map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
1593 qw(netamount tax amount);
1598 <tr class=listrow$i>
1601 map { print "$column_data{$_}\n" } @column_index;
1609 if ($form->{l_subtotal} eq 'Y') {
1610 tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
1614 map { $column_data{$_} = qq|<th> </th>| } @column_index;
1618 <tr class=listtotal>
1621 my $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
1622 $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
1623 $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
1625 $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
1626 $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
1627 $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
1629 map { print "$column_data{$_}\n" } @column_index;
1637 <td><hr size=3 noshade></td>
1645 $main::lxdebug->leave_sub();
1649 $main::lxdebug->enter_sub();
1651 my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
1653 my $form = $main::form;
1654 my %myconfig = %main::myconfig;
1655 my $locale = $main::locale;
1658 map { $column_data{$_} = "<td> </td>" } @{ $column_index };
1660 $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, " ");
1661 $$subtotaltax = $form->format_amount(\%myconfig, $$subtotaltax, 2, " ");
1662 $$subtotal = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, " ");
1664 $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
1665 $column_data{tax} = "<th class=listsubtotal align=right>$$subtotaltax</th>";
1666 $column_data{amount} = "<th class=listsubtotal align=right>$$subtotal</th>";
1668 $$subtotalnetamount = 0;
1672 <tr class=listsubtotal>
1674 map { print "\n$column_data{$_}" } @{ $column_index };
1680 $main::lxdebug->leave_sub();
1684 $main::lxdebug->enter_sub();
1686 $main::auth->assert('cash');
1688 my $form = $main::form;
1689 my %myconfig = %main::myconfig;
1690 my $locale = $main::locale;
1692 if ($form->{account}) {
1693 ($form->{paymentaccounts}) = split /--/, $form->{account};
1697 if ($form->{department}) {
1698 (my $department, $form->{department_id}) = split /--/, $form->{department};
1699 $option = $locale->text('Department') . " : $department";
1702 report_generator_set_default_sort('transdate', 1);
1704 RP->payments(\%myconfig, \%$form);
1706 my @hidden_variables = qw(account title department reference source memo fromdate todate
1707 fx_transaction db prepayment paymentaccounts sort);
1709 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
1710 $form->{callback} = $href;
1712 my @columns = qw(transdate invnumber name paid source memo);
1714 'name' => { 'text' => $locale->text('Description'), },
1715 'invnumber' => { 'text' => $locale->text('Reference'), },
1716 'transdate' => { 'text' => $locale->text('Date'), },
1717 'paid' => { 'text' => $locale->text('Amount'), },
1718 'source' => { 'text' => $locale->text('Source'), },
1719 'memo' => { 'text' => $locale->text('Memo'), },
1721 my %column_alignment = ('paid' => 'right');
1723 foreach my $name (grep { $_ ne 'paid' } @columns) {
1724 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1725 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
1729 if ($form->{fromdate}) {
1730 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
1732 if ($form->{todate}) {
1733 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1736 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1738 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
1740 $report->set_options('top_info_text' => join("\n", @options),
1741 'output_format' => 'HTML',
1742 'title' => $form->{title},
1743 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1744 'std_column_visibility' => 1,
1746 $report->set_options_from_form();
1748 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1750 $report->set_columns(%column_defs);
1751 $report->set_column_order(@columns);
1753 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
1755 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1759 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1760 next unless @{ $form->{ $ref->{id} } };
1762 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
1764 my $subtotal_paid = 0;
1766 foreach my $payment (@{ $form->{ $ref->{id} } }) {
1767 my $module = $payment->{module};
1768 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1769 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1771 $subtotal_paid += $payment->{paid};
1772 $total_paid += $payment->{paid};
1774 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
1778 foreach my $column (@columns) {
1780 'data' => $payment->{$column},
1781 'align' => $column_alignment{$column},
1785 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
1787 $report->add_data($row);
1790 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
1792 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
1794 'class' => 'listsubtotal',
1797 $report->add_data($row);
1800 $report->add_separator();
1802 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
1804 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
1806 'class' => 'listtotal',
1809 $report->add_data($row);
1811 $report->generate_with_headers();
1813 $main::lxdebug->leave_sub();
1817 $main::lxdebug->enter_sub();
1819 my ($dont_print) = @_;
1821 my $form = $main::form;
1822 my %myconfig = %main::myconfig;
1823 my $locale = $main::locale;
1825 $form->{sendmode} = "attachment";
1828 $form->{"format"} ? $form->{"format"} :
1829 $myconfig{"template_format"} ? $myconfig{"template_format"} :
1833 $form->{"copies"} ? $form->{"copies"} :
1834 $myconfig{"copies"} ? $myconfig{"copies"} :
1837 $form->{PD}{ $form->{type} } = "selected";
1838 $form->{DF}{ $form->{format} } = "selected";
1839 $form->{OP}{ $form->{media} } = "selected";
1840 $form->{SM}{ $form->{sendmode} } = "selected";
1844 <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
1846 if ($form->{media} eq 'email') {
1848 <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
1849 <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1852 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1853 if ($myconfig{printer} && $::lx_office_conf{print_templates}->{latex}) {
1855 <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
1860 if ($::lx_office_conf{print_templates}->{latex}) {
1862 <option value=html $form->{DF}{html}>| . $locale->text('HTML')
1863 . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
1864 . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
1870 <td><select name=type>$type</select></td>
1871 <td><select name=format>$format</select></td>
1872 <td><select name=media>$media</select></td>
1875 if ($myconfig{printer} && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email') {
1877 <td>| . $locale->text('Copies') . qq|
1878 <input name=copies size=2 value=$form->{copies}></td>
1887 print $output unless $dont_print;
1889 $main::lxdebug->leave_sub();
1895 $main::lxdebug->enter_sub();
1897 $main::auth->assert('report');
1899 my $form = $main::form;
1900 my %myconfig = %main::myconfig;
1901 my $locale = $main::locale;
1903 $form->{padding} = " ";
1904 $form->{bold} = "<b>";
1905 $form->{endbold} = "</b>";
1906 $form->{br} = "<br>";
1908 if ($form->{reporttype} eq "custom") {
1910 #forgotten the year --> thisyear
1911 if ($form->{year} !~ m/^\d\d\d\d$/) {
1912 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1918 if ($form->{duetyp} eq "13") {
1919 $form->{fromdate} = "1.1.$form->{year}";
1920 $form->{todate} = "31.12.$form->{year}";
1921 $form->{comparefromdate} = "1.01.$form->{year}";
1922 $form->{comparetodate} = "31.12.$form->{year}";
1926 if ($form->{duetyp} eq "A") {
1927 $form->{fromdate} = "1.1.$form->{year}";
1928 $form->{todate} = "31.3.$form->{year}";
1929 $form->{comparefromdate} = "1.01.$form->{year}";
1930 $form->{comparetodate} = "31.03.$form->{year}";
1932 if ($form->{duetyp} eq "B") {
1933 $form->{fromdate} = "1.4.$form->{year}";
1934 $form->{todate} = "30.6.$form->{year}";
1935 $form->{comparefromdate} = "1.01.$form->{year}";
1936 $form->{comparetodate} = "30.06.$form->{year}";
1938 if ($form->{duetyp} eq "C") {
1939 $form->{fromdate} = "1.7.$form->{year}";
1940 $form->{todate} = "30.9.$form->{year}";
1941 $form->{comparefromdate} = "1.01.$form->{year}";
1942 $form->{comparetodate} = "30.09.$form->{year}";
1944 if ($form->{duetyp} eq "D") {
1945 $form->{fromdate} = "1.10.$form->{year}";
1946 $form->{todate} = "31.12.$form->{year}";
1947 $form->{comparefromdate} = "1.01.$form->{year}";
1948 $form->{comparetodate} = "31.12.$form->{year}";
1953 $form->{duetyp} eq "1" && do {
1954 $form->{fromdate} = "1.1.$form->{year}";
1955 $form->{todate} = "31.1.$form->{year}";
1956 $form->{comparefromdate} = "1.01.$form->{year}";
1957 $form->{comparetodate} = "31.01.$form->{year}";
1960 $form->{duetyp} eq "2" && do {
1961 $form->{fromdate} = "1.2.$form->{year}";
1963 #this works from 1901 to 2099, 1900 and 2100 fail.
1964 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1965 $form->{todate} = "$leap.2.$form->{year}";
1966 $form->{comparefromdate} = "1.01.$form->{year}";
1967 $form->{comparetodate} = "$leap.02.$form->{year}";
1970 $form->{duetyp} eq "3" && do {
1971 $form->{fromdate} = "1.3.$form->{year}";
1972 $form->{todate} = "31.3.$form->{year}";
1973 $form->{comparefromdate} = "1.01.$form->{year}";
1974 $form->{comparetodate} = "31.03.$form->{year}";
1977 $form->{duetyp} eq "4" && do {
1978 $form->{fromdate} = "1.4.$form->{year}";
1979 $form->{todate} = "30.4.$form->{year}";
1980 $form->{comparefromdate} = "1.01.$form->{year}";
1981 $form->{comparetodate} = "30.04.$form->{year}";
1984 $form->{duetyp} eq "5" && do {
1985 $form->{fromdate} = "1.5.$form->{year}";
1986 $form->{todate} = "31.5.$form->{year}";
1987 $form->{comparefromdate} = "1.01.$form->{year}";
1988 $form->{comparetodate} = "31.05.$form->{year}";
1991 $form->{duetyp} eq "6" && do {
1992 $form->{fromdate} = "1.6.$form->{year}";
1993 $form->{todate} = "30.6.$form->{year}";
1994 $form->{comparefromdate} = "1.01.$form->{year}";
1995 $form->{comparetodate} = "30.06.$form->{year}";
1998 $form->{duetyp} eq "7" && do {
1999 $form->{fromdate} = "1.7.$form->{year}";
2000 $form->{todate} = "31.7.$form->{year}";
2001 $form->{comparefromdate} = "1.01.$form->{year}";
2002 $form->{comparetodate} = "31.07.$form->{year}";
2005 $form->{duetyp} eq "8" && do {
2006 $form->{fromdate} = "1.8.$form->{year}";
2007 $form->{todate} = "31.8.$form->{year}";
2008 $form->{comparefromdate} = "1.01.$form->{year}";
2009 $form->{comparetodate} = "31.08.$form->{year}";
2012 $form->{duetyp} eq "9" && do {
2013 $form->{fromdate} = "1.9.$form->{year}";
2014 $form->{todate} = "30.9.$form->{year}";
2015 $form->{comparefromdate} = "1.01.$form->{year}";
2016 $form->{comparetodate} = "30.09.$form->{year}";
2019 $form->{duetyp} eq "10" && do {
2020 $form->{fromdate} = "1.10.$form->{year}";
2021 $form->{todate} = "31.10.$form->{year}";
2022 $form->{comparefromdate} = "1.01.$form->{year}";
2023 $form->{comparetodate} = "31.10.$form->{year}";
2026 $form->{duetyp} eq "11" && do {
2027 $form->{fromdate} = "1.11.$form->{year}";
2028 $form->{todate} = "30.11.$form->{year}";
2029 $form->{comparefromdate} = "1.01.$form->{year}";
2030 $form->{comparetodate} = "30.11.$form->{year}";
2033 $form->{duetyp} eq "12" && do {
2034 $form->{fromdate} = "1.12.$form->{year}";
2035 $form->{todate} = "31.12.$form->{year}";
2036 $form->{comparefromdate} = "1.01.$form->{year}";
2037 $form->{comparetodate} = "31.12.$form->{year}";
2041 hotfix_reformat_date();
2043 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
2044 # ansonsten ist die prüfung in RP.pm
2045 # if (defined ($form->{fromdate|todate}=='..'))
2047 if ($form->{fromdate}){
2048 my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2049 my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
2050 $datetime->set( month => 1,
2052 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
2054 if ($form->{todate}){
2055 $form->{comparetodate} = $form->{todate};
2059 RP->bwa(\%myconfig, \%$form);
2061 ($form->{department}) = split /--/, $form->{department};
2064 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2065 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2067 # if there are any dates construct a where
2068 if ($form->{fromdate} || $form->{todate}) {
2070 unless ($form->{todate}) {
2071 $form->{todate} = $form->current_date(\%myconfig);
2074 my %germandate = ("dateformat" => "dd.mm.yyyy");
2076 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2077 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2079 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2080 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2082 $form->{this_period} = "$shortfromdate\n$shorttodate";
2084 $locale->text('for Period')
2085 . qq|\n$longfromdate |
2086 . $locale->text('bis')
2090 # setup variables for the form
2091 my @a = qw(company address businessnumber);
2092 map { $form->{$_} = $myconfig{$_} } @a;
2093 $form->{templates} = $myconfig{templates};
2095 $form->{IN} = "bwa.html";
2097 $form->parse_template;
2099 $main::lxdebug->leave_sub();
2102 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
2103 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
2104 sub hotfix_reformat_date {
2106 $main::lxdebug->enter_sub();
2108 my $form = $main::form;
2109 my %myconfig = %main::myconfig;
2110 my $locale = $main::locale;
2112 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
2113 my $current_dateformat = $myconfig{dateformat};
2114 $myconfig{dateformat} = 'dd.mm.yyyy';
2115 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
2116 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
2117 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
2118 unless (!defined ($form->{comparefromdate}));
2119 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
2120 unless (!defined ($form->{comparetodate}));
2122 # Und wieder zurücksetzen
2123 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
2124 } # Ende Hotifx Bug 1388
2126 $main::lxdebug->leave_sub();