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);
46 use SL::ReportGenerator;
48 use List::MoreUtils qw(any);
50 require "bin/mozilla/arap.pl";
51 require "bin/mozilla/common.pl";
52 require "bin/mozilla/reportgenerator.pl";
54 # note: this file was particularly hard to strictify.
55 # alot of the vars are passed carelessly between invocations
56 # should there be any missing vars, declare them globally
59 # this is for our long dates
60 # $locale->text('January')
61 # $locale->text('February')
62 # $locale->text('March')
63 # $locale->text('April')
64 # $locale->text('May ')
65 # $locale->text('June')
66 # $locale->text('July')
67 # $locale->text('August')
68 # $locale->text('September')
69 # $locale->text('October')
70 # $locale->text('November')
71 # $locale->text('December')
73 # this is for our short month
74 # $locale->text('Jan')
75 # $locale->text('Feb')
76 # $locale->text('Mar')
77 # $locale->text('Apr')
78 # $locale->text('May')
79 # $locale->text('Jun')
80 # $locale->text('Jul')
81 # $locale->text('Aug')
82 # $locale->text('Sep')
83 # $locale->text('Oct')
84 # $locale->text('Nov')
85 # $locale->text('Dec')
87 # $locale->text('Balance Sheet')
88 # $locale->text('Income Statement')
89 # $locale->text('Trial Balance')
90 # $locale->text('AR Aging')
91 # $locale->text('AP Aging')
92 # $locale->text('Search AR Aging')
93 # $locale->text('Search AP Aging')
94 # $locale->text('Tax collected')
95 # $locale->text('Tax paid')
96 # $locale->text('Receipts')
97 # $locale->text('Payments')
98 # $locale->text('Project Transactions')
99 # $locale->text('Business evaluation')
101 # $form->parse_html_template('rp/html_report_susa')
103 my $rp_access_map = {
104 'projects' => 'report',
105 'ar_aging' => 'general_ledger',
106 'ap_aging' => 'general_ledger',
107 'receipts' => 'cash',
108 'payments' => 'cash',
109 'trial_balance' => 'report',
110 'income_statement' => 'report',
111 'income_statement_ch'=> 'report',
113 'balance_sheet' => 'report',
116 sub check_rp_access {
117 my $form = $main::form;
119 my $right = $rp_access_map->{$form->{report}};
120 $right ||= 'DOES_NOT_EXIST';
122 $main::auth->assert($right);
126 $::lxdebug->enter_sub;
131 balance_sheet => $::locale->text('Balance Sheet'),
132 income_statement => $::locale->text('Income Statement'),
133 income_statement_ch => ('Erfolgsrechnung'),
134 trial_balance => $::locale->text('Trial Balance'),
135 ar_aging => $::locale->text('Search AR Aging'),
136 ap_aging => $::locale->text('Search AP Aging'),
137 tax_collected => $::locale->text('Tax collected'),
138 tax_paid => $::locale->text('Tax paid'),
139 receipts => $::locale->text('Receipts'),
140 payments => $::locale->text('Payments'),
141 projects => $::locale->text('Project Transactions'),
142 bwa => $::locale->text('Business evaluation'),
145 $::form->{title} = $title{$::form->{report}};
146 $::request->{layout}->add_javascripts('autocomplete_customer.js');
149 $::form->all_departments(\%::myconfig);
150 if (@{ $::form->{all_departments} || [] }) {
151 $::form->{selectdepartment} = "<option>\n";
152 map { $::form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $::form->{all_departments} || [] };
155 $::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
157 my $is_projects = $::form->{report} eq "projects";
158 my $is_income_statement = $::form->{report} eq "income_statement";
159 my $is_income_statement_ch = $::form->{report} eq "income_statement_ch";
160 my $is_bwa = $::form->{report} eq "bwa";
161 my $is_balance_sheet = $::form->{report} eq "balance_sheet";
162 my $is_trial_balance = $::form->{report} eq "trial_balance";
163 my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
164 my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
166 my ($label, $nextsub, $vc);
168 my $is_sales = $::form->{report} eq 'ar_aging';
169 $label = $is_sales ? $::locale->text('Customer') : $::locale->text('Vendor');
170 $::form->{vc} = $is_sales ? 'customer' : 'vendor';
172 $nextsub = "generate_$::form->{report}";
175 $::form->all_vc(\%::myconfig, $::form->{vc}, $is_sales ? "AR" : "AP");
176 $vc .= "<option>$_->{name}--$_->{id}\n" for @{ $::form->{"all_$::form->{vc}"} };
178 ? qq|<select name=$::form->{vc} class="initial_focus"><option>\n$vc</select>|
179 : qq|<input name=$::form->{vc} size=35 class="initial_focus">|;
182 my ($selection, $paymentaccounts);
184 $::form->{db} = $::form->{report} =~ /payments$/ ? "ap" : "ar";
186 RP->paymentaccounts(\%::myconfig, $::form);
188 $selection = "<option>\n";
189 for my $ref (@{ $::form->{PR} }) {
190 $paymentaccounts .= "$ref->{accno} ";
191 $selection .= "<option>$ref->{accno}--$ref->{description}\n";
196 print $::form->parse_html_template('rp/report', {
197 paymentaccounts => $paymentaccounts,
198 selection => $selection,
199 is_aging => $is_aging,
202 year => DateTime->today->year,
203 today => DateTime->today,
205 accrual => $::instance_conf->get_accounting_method ne 'cash',
206 cash => $::instance_conf->get_accounting_method eq 'cash',
207 is_payments => $is_payments,
208 is_trial_balance => $is_trial_balance,
209 is_balance_sheet => $is_balance_sheet,
211 is_income_statement => $is_income_statement,
212 is_income_statement_ch => $is_income_statement_ch,
213 is_projects => $is_projects,
216 $::lxdebug->leave_sub;
219 sub continue { call_sub($main::form->{"nextsub"}); }
221 sub generate_income_statement {
222 $main::lxdebug->enter_sub();
224 $main::auth->assert('report');
226 my $form = $main::form;
227 my %myconfig = %main::myconfig;
228 my $locale = $main::locale;
230 $form->{padding} = " ";
231 $form->{bold} = "<b>";
232 $form->{endbold} = "</b>";
233 $form->{br} = "<br>";
235 if ($form->{reporttype} eq "custom") {
237 #forgotten the year --> thisyear
238 if ($form->{year} !~ m/^\d\d\d\d$/) {
239 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
245 if ($form->{duetyp} eq "13") {
246 $form->{fromdate} = "1.1.$form->{year}";
247 $form->{todate} = "31.12.$form->{year}";
251 if ($form->{duetyp} eq "A") {
252 $form->{fromdate} = "1.1.$form->{year}";
253 $form->{todate} = "31.3.$form->{year}";
255 if ($form->{duetyp} eq "B") {
256 $form->{fromdate} = "1.4.$form->{year}";
257 $form->{todate} = "30.6.$form->{year}";
259 if ($form->{duetyp} eq "C") {
260 $form->{fromdate} = "1.7.$form->{year}";
261 $form->{todate} = "30.9.$form->{year}";
263 if ($form->{duetyp} eq "D") {
264 $form->{fromdate} = "1.10.$form->{year}";
265 $form->{todate} = "31.12.$form->{year}";
270 $form->{duetyp} eq "1" && do {
271 $form->{fromdate} = "1.1.$form->{year}";
272 $form->{todate} = "31.1.$form->{year}";
275 $form->{duetyp} eq "2" && do {
276 $form->{fromdate} = "1.2.$form->{year}";
278 #this works from 1901 to 2099, 1900 and 2100 fail.
279 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
280 $form->{todate} = "$leap.2.$form->{year}";
283 $form->{duetyp} eq "3" && do {
284 $form->{fromdate} = "1.3.$form->{year}";
285 $form->{todate} = "31.3.$form->{year}";
288 $form->{duetyp} eq "4" && do {
289 $form->{fromdate} = "1.4.$form->{year}";
290 $form->{todate} = "30.4.$form->{year}";
293 $form->{duetyp} eq "5" && do {
294 $form->{fromdate} = "1.5.$form->{year}";
295 $form->{todate} = "31.5.$form->{year}";
298 $form->{duetyp} eq "6" && do {
299 $form->{fromdate} = "1.6.$form->{year}";
300 $form->{todate} = "30.6.$form->{year}";
303 $form->{duetyp} eq "7" && do {
304 $form->{fromdate} = "1.7.$form->{year}";
305 $form->{todate} = "31.7.$form->{year}";
308 $form->{duetyp} eq "8" && do {
309 $form->{fromdate} = "1.8.$form->{year}";
310 $form->{todate} = "31.8.$form->{year}";
313 $form->{duetyp} eq "9" && do {
314 $form->{fromdate} = "1.9.$form->{year}";
315 $form->{todate} = "30.9.$form->{year}";
318 $form->{duetyp} eq "10" && do {
319 $form->{fromdate} = "1.10.$form->{year}";
320 $form->{todate} = "31.10.$form->{year}";
323 $form->{duetyp} eq "11" && do {
324 $form->{fromdate} = "1.11.$form->{year}";
325 $form->{todate} = "30.11.$form->{year}";
328 $form->{duetyp} eq "12" && do {
329 $form->{fromdate} = "1.12.$form->{year}";
330 $form->{todate} = "31.12.$form->{year}";
334 hotfix_reformat_date();
335 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
337 RP->income_statement(\%myconfig, \%$form);
339 ($form->{department}) = split /--/, $form->{department};
342 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
343 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
345 # if there are any dates construct a where
346 if ($form->{fromdate} || $form->{todate}) {
348 unless ($form->{todate}) {
349 $form->{todate} = $form->current_date(\%myconfig);
352 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
353 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
355 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
356 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
358 $form->{this_period} = "$shortfromdate\n$shorttodate";
360 $locale->text('for Period')
361 . qq|\n$longfromdate |
362 . $locale->text('Bis')
366 if ($form->{comparefromdate} || $form->{comparetodate}) {
367 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
368 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
370 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
371 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
373 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
375 "\n$longcomparefromdate "
376 . $locale->text('Bis')
377 . qq| $longcomparetodate|;
380 if ( $::instance_conf->get_profit_determination eq 'balance' ) {
381 $form->{title} = $locale->text('Income Statement');
382 } elsif ( $::instance_conf->get_profit_determination eq 'income' ) {
383 $form->{title} = $locale->text('Net Income Statement');
388 if ( $form->{method} eq 'cash' ) {
389 $form->{accounting_method} = $locale->text('Cash accounting');
390 } elsif ( $form->{method} eq 'accrual' ) {
391 $form->{accounting_method} = $locale->text('Accrual accounting');
393 $form->{accounting_method} = "";
396 $form->{report_date} = $locale->text('Report date') . ": " . $form->current_date;
399 print $form->parse_html_template('rp/income_statement');
401 $main::lxdebug->leave_sub();
404 sub generate_income_statement_ch {
405 $main::lxdebug->enter_sub();
407 $main::auth->assert('report');
409 my $form = $main::form;
410 my %myconfig = %main::myconfig;
411 my $locale = $main::locale;
413 my $defaults = SL::DB::Default->get;
414 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
415 $form->{templates} = $defaults->templates;
417 $form->{padding} = " ";
418 $form->{bold} = "<b>";
419 $form->{endbold} = "</b>";
420 $form->{br} = "<br>";
422 if ($form->{reporttype} eq "custom") {
424 #forgotten the year --> thisyear
425 if ($form->{year} !~ m/^\d\d\d\d$/) {
426 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
432 if ($form->{duetyp} eq "13") {
433 $form->{fromdate} = "1.1.$form->{year}";
434 $form->{todate} = "31.12.$form->{year}";
437 if ($form->{duetyp} eq "A") {
438 $form->{fromdate} = "1.1.$form->{year}";
439 $form->{todate} = "31.3.$form->{year}";
441 if ($form->{duetyp} eq "B") {
442 $form->{fromdate} = "1.4.$form->{year}";
443 $form->{todate} = "30.6.$form->{year}";
445 if ($form->{duetyp} eq "C") {
446 $form->{fromdate} = "1.7.$form->{year}";
447 $form->{todate} = "30.9.$form->{year}";
449 if ($form->{duetyp} eq "D") {
450 $form->{fromdate} = "1.10.$form->{year}";
451 $form->{todate} = "31.12.$form->{year}";
455 $form->{duetyp} eq "1" && do {
456 $form->{fromdate} = "1.1.$form->{year}";
457 $form->{todate} = "31.1.$form->{year}";
460 $form->{duetyp} eq "2" && do {
461 $form->{fromdate} = "1.2.$form->{year}";
463 #this works from 1901 to 2099, 1900 and 2100 fail.
464 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
465 $form->{todate} = "$leap.2.$form->{year}";
468 $form->{duetyp} eq "3" && do {
469 $form->{fromdate} = "1.3.$form->{year}";
470 $form->{todate} = "31.3.$form->{year}";
473 $form->{duetyp} eq "4" && do {
474 $form->{fromdate} = "1.4.$form->{year}";
475 $form->{todate} = "30.4.$form->{year}";
478 $form->{duetyp} eq "5" && do {
479 $form->{fromdate} = "1.5.$form->{year}";
480 $form->{todate} = "31.5.$form->{year}";
483 $form->{duetyp} eq "6" && do {
484 $form->{fromdate} = "1.6.$form->{year}";
485 $form->{todate} = "30.6.$form->{year}";
488 $form->{duetyp} eq "7" && do {
489 $form->{fromdate} = "1.7.$form->{year}";
490 $form->{todate} = "31.7.$form->{year}";
493 $form->{duetyp} eq "8" && do {
494 $form->{fromdate} = "1.8.$form->{year}";
495 $form->{todate} = "31.8.$form->{year}";
498 $form->{duetyp} eq "9" && do {
499 $form->{fromdate} = "1.9.$form->{year}";
500 $form->{todate} = "30.9.$form->{year}";
503 $form->{duetyp} eq "10" && do {
504 $form->{fromdate} = "1.10.$form->{year}";
505 $form->{todate} = "31.10.$form->{year}";
508 $form->{duetyp} eq "11" && do {
509 $form->{fromdate} = "1.11.$form->{year}";
510 $form->{todate} = "30.11.$form->{year}";
513 $form->{duetyp} eq "12" && do {
514 $form->{fromdate} = "1.12.$form->{year}";
515 $form->{todate} = "31.12.$form->{year}";
519 hotfix_reformat_date();
520 } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
522 RP->income_statement_ch(\%myconfig, \%$form);
524 ($form->{department}) = split /--/, $form->{department};
527 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
528 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
530 # if there are any dates construct a where
531 if ($form->{fromdate} || $form->{todate}) {
533 unless ($form->{todate}) {
534 $form->{todate} = $form->current_date(\%myconfig);
537 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
538 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
540 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
541 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
543 $form->{this_period} = "$shortfromdate\n$shorttodate";
545 $locale->text('for Period')
546 . qq|\n$longfromdate |
547 . $locale->text('Bis')
551 if ($form->{comparefromdate} || $form->{comparetodate}) {
552 my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
553 my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
555 my $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
556 my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
558 $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
560 "\n$longcomparefromdate "
561 . $locale->text('Bis')
562 . qq| $longcomparetodate|;
565 $form->{IN} = "erfolgsrechnung.html";
567 $form->parse_template;
569 $main::lxdebug->leave_sub();
573 sub generate_balance_sheet {
574 $::lxdebug->enter_sub;
575 $::auth->assert('report');
577 $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
578 $::form->{padding} = " ";
579 $::form->{bold} = "<b>";
580 $::form->{endbold} = "</b>";
581 $::form->{br} = "<br>";
583 my $data = RP->balance_sheet(\%::myconfig, $::form);
585 $::form->{asofdate} ||= $::form->current_date;
586 $::form->{report_title} = $::locale->text('Balance Sheet');
587 $::form->{report_date} ||= $::form->current_date;
589 ($::form->{department}) = split /--/, $::form->{department};
591 # define Current Earnings account
592 my $padding = $::form->{l_heading} ? $::form->{padding} : "";
593 push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
595 $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
596 $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
598 # balance sheet isn't read from print templates anymore,
599 # instead use template in rp
600 # $::form->{IN} = "balance_sheet.html";
603 print $::form->parse_html_template('rp/balance_sheet', $data);
605 $::lxdebug->leave_sub;
608 sub generate_projects {
609 $main::lxdebug->enter_sub();
611 $main::auth->assert('report');
613 my $form = $main::form;
614 my %myconfig = %main::myconfig;
615 my $locale = $main::locale;
617 my $project = $form->{project_id} ? SL::DB::Project->new(id => $form->{project_id})->load : undef;
618 $form->{projectnumber} = $project ? $project->projectnumber : '';
620 $form->{nextsub} = "generate_projects";
621 $form->{title} = $locale->text('Project Transactions');
622 RP->trial_balance(\%myconfig, \%$form);
624 list_accounts('generate_projects');
626 $main::lxdebug->leave_sub();
632 # included links to display transactions for period entered
633 # added headers and subtotals
635 sub generate_trial_balance {
636 $main::lxdebug->enter_sub();
638 $main::auth->assert('report');
640 my $form = $main::form;
641 my %myconfig = %main::myconfig;
642 my $locale = $main::locale;
643 my $defaults = SL::DB::Default->get;
645 if ($form->{reporttype} eq "custom") {
647 #forgotten the year --> thisyear
648 if ($form->{year} !~ m/^\d\d\d\d$/) {
649 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
655 if ($form->{duetyp} eq "13") {
656 $form->{fromdate} = "1.1.$form->{year}";
657 $form->{todate} = "31.12.$form->{year}";
661 if ($form->{duetyp} eq "A") {
662 $form->{fromdate} = "1.1.$form->{year}";
663 $form->{todate} = "31.3.$form->{year}";
665 if ($form->{duetyp} eq "B") {
666 $form->{fromdate} = "1.4.$form->{year}";
667 $form->{todate} = "30.6.$form->{year}";
669 if ($form->{duetyp} eq "C") {
670 $form->{fromdate} = "1.7.$form->{year}";
671 $form->{todate} = "30.9.$form->{year}";
673 if ($form->{duetyp} eq "D") {
674 $form->{fromdate} = "1.10.$form->{year}";
675 $form->{todate} = "31.12.$form->{year}";
680 $form->{duetyp} eq "1" && do {
681 $form->{fromdate} = "1.1.$form->{year}";
682 $form->{todate} = "31.1.$form->{year}";
685 $form->{duetyp} eq "2" && do {
686 $form->{fromdate} = "1.2.$form->{year}";
688 #this works from 1901 to 2099, 1900 and 2100 fail.
689 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
690 $form->{todate} = "$leap.2.$form->{year}";
693 $form->{duetyp} eq "3" && do {
694 $form->{fromdate} = "1.3.$form->{year}";
695 $form->{todate} = "31.3.$form->{year}";
698 $form->{duetyp} eq "4" && do {
699 $form->{fromdate} = "1.4.$form->{year}";
700 $form->{todate} = "30.4.$form->{year}";
703 $form->{duetyp} eq "5" && do {
704 $form->{fromdate} = "1.5.$form->{year}";
705 $form->{todate} = "31.5.$form->{year}";
708 $form->{duetyp} eq "6" && do {
709 $form->{fromdate} = "1.6.$form->{year}";
710 $form->{todate} = "30.6.$form->{year}";
713 $form->{duetyp} eq "7" && do {
714 $form->{fromdate} = "1.7.$form->{year}";
715 $form->{todate} = "31.7.$form->{year}";
718 $form->{duetyp} eq "8" && do {
719 $form->{fromdate} = "1.8.$form->{year}";
720 $form->{todate} = "31.8.$form->{year}";
723 $form->{duetyp} eq "9" && do {
724 $form->{fromdate} = "1.9.$form->{year}";
725 $form->{todate} = "30.9.$form->{year}";
728 $form->{duetyp} eq "10" && do {
729 $form->{fromdate} = "1.10.$form->{year}";
730 $form->{todate} = "31.10.$form->{year}";
733 $form->{duetyp} eq "11" && do {
734 $form->{fromdate} = "1.11.$form->{year}";
735 $form->{todate} = "30.11.$form->{year}";
738 $form->{duetyp} eq "12" && do {
739 $form->{fromdate} = "1.12.$form->{year}";
740 $form->{todate} = "31.12.$form->{year}";
744 hotfix_reformat_date();
748 # get for each account initial balance, debits and credits
749 RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
752 $form->{rowcount} = scalar @{ $form->{TB} || [] };
753 $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
756 "accno", "description",
757 "last_transaction", "soll_eb",
760 "soll_kumuliert", "haben_kumuliert",
761 "soll_saldo", "haben_saldo"
765 my $attachment_basename = $locale->text('trial_balance');
766 my $report = SL::ReportGenerator->new(\%myconfig, $form);
768 my @hidden_variables = qw(fromdate todate year method);
770 my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
773 'accno' => { 'text' => $locale->text('Account'), },
774 'description' => { 'text' => $locale->text('Description'), },
775 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
776 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
777 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
778 'soll' => { 'text' => $locale->text('Debit'), },
779 'haben' => { 'text' => $locale->text('Credit'), },
780 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
781 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
782 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
783 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
788 my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
790 map { $column_defs{$_}->{visible} = 1 } @columns;
792 $report->set_columns(%column_defs);
793 $report->set_column_order(@columns);
795 $report->set_export_options('generate_trial_balance', @hidden_variables);
800 $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
802 $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
803 push (@options, $form->{print_date});
805 $form->{company} = $locale->text('Company') . " " . $defaults->company;
806 push (@options, $form->{company});
808 if ($::form->{customer_id}) {
809 my $customer = SL::DB::Manager::Customer->find_by(id => $::form->{customer_id});
810 push @options, $::locale->text('Customer') . ' ' . $customer->displayable_name;
814 $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
816 my @custom_headers = ([
817 { text => $::locale->text('Account'), rowspan => 2, },
818 { text => $::locale->text('Description'), rowspan => 2, },
819 { text => $::locale->text('Last Transaction'), rowspan => 2, },
820 { text => $::locale->text('Starting Balance'), colspan => 2, },
821 { text => $::locale->text('Sum for') . " $form->{template_fromto}", colspan => 2, },
822 { text => $::locale->text('Sum per') . " $form->{template_to}", colspan => 2, },
823 { text => $::locale->text('Saldo per') . " $form->{template_to}", colspan => 2, },
828 { text => $::locale->text('Assets'), },
829 { text => $::locale->text('Equity'), },
830 { text => $::locale->text('Debit'), },
831 { text => $::locale->text('Credit'), },
832 { text => $::locale->text('Debit'), },
833 { text => $::locale->text('Credit'), },
834 { text => $::locale->text('Debit'), },
835 { text => $::locale->text('Credit'), },
838 $report->set_options('output_format' => 'HTML',
839 'top_info_text' => join("\n", @options),
840 'title' => $form->{title},
841 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
842 'html_template' => 'rp/html_report_susa',
843 'pdf_template' => 'rp/html_report_susa',
845 $report->set_custom_headers(@custom_headers);
846 $report->set_options_from_form();
847 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
849 # add sort and escape callback, this one we use for the add sub
850 $form->{callback} = $href .= "&sort=$form->{sort}";
852 # escape callback for href
853 my $callback = $form->escape($href);
855 my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
857 my %totals = map { $_ => 0 } @subtotal_columns;
859 my $edit_url = build_std_url('action=edit', 'type', 'vc');
862 foreach my $accno (@{ $form->{TB} || [] }) {
864 $accno->{soll} = $accno->{debit};
865 $accno->{haben} = $accno->{credit};
866 map { $totals{$_} += $accno->{$_} } @subtotal_columns;
868 map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
869 qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
873 foreach my $column (@columns) {
875 'data' => $accno->{$column},
876 'align' => $column_alignment{$column},
880 $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}));
882 my $row_set = [ $row ];
885 $report->add_data($row_set);
890 $report->add_separator();
892 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
894 $report->generate_with_headers();
896 $main::lxdebug->leave_sub();
900 sub create_subtotal_row {
901 $main::lxdebug->enter_sub();
903 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
905 my $form = $main::form;
906 my %myconfig = %main::myconfig;
907 my $locale = $main::locale;
909 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
911 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
913 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
915 map { $totals->{$_} = 0 } @{ $subtotal_columns };
917 $main::lxdebug->leave_sub();
922 sub create_list_accounts_subtotal_row {
923 $main::lxdebug->enter_sub();
925 my ($subtotals, $columns, $fields, $class) = @_;
927 my $form = $main::form;
928 my %myconfig = %main::myconfig;
929 my $locale = $main::locale;
931 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
933 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
935 $main::lxdebug->leave_sub();
941 $main::lxdebug->enter_sub();
945 my $form = $main::form;
946 my %myconfig = %main::myconfig;
947 my $locale = $main::locale;
950 if ($form->{department}) {
951 my ($department) = split /--/, $form->{department};
952 push @options, $locale->text('Department') . " : $department";
954 if ($form->{projectnumber}) {
955 push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
958 # if there are any dates
959 if ($form->{fromdate} || $form->{todate}) {
960 my ($fromdate, $todate);
962 if ($form->{fromdate}) {
963 $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
965 if ($form->{todate}) {
966 $todate = $locale->date(\%myconfig, $form->{todate}, 1);
969 push @options, "$fromdate - $todate";
972 push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
975 my @columns = qw(accno description begbalance debit credit endbalance);
977 'accno' => { 'text' => $locale->text('Account'), },
978 'description' => { 'text' => $locale->text('Description'), },
979 'debit' => { 'text' => $locale->text('Debit'), },
980 'credit' => { 'text' => $locale->text('Credit'), },
981 'begbalance' => { 'text' => $locale->text('Balance'), },
982 'endbalance' => { 'text' => $locale->text('Balance'), },
984 my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
986 my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
988 $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
990 my $report = SL::ReportGenerator->new(\%myconfig, $form);
992 $report->set_options('top_info_text' => join("\n", @options),
993 'output_format' => 'HTML',
994 'title' => $form->{title},
995 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
996 'std_column_visibility' => 1,
998 $report->set_options_from_form();
999 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1001 $report->set_columns(%column_defs);
1002 $report->set_column_order(@columns);
1004 $report->set_export_options($action, @hidden_variables);
1006 my @totals_columns = qw(credit debit begbalance endbalance);
1007 my %subtotals = map { $_ => 0 } @totals_columns;
1008 my %totals = map { $_ => 0 } @totals_columns;
1009 my $found_heading = 0;
1010 my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
1012 # sort the whole thing by account numbers and display
1013 foreach my $idx (0 .. scalar(@tb) - 1) {
1014 my $ref = $tb[$idx];
1015 my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1017 my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1019 my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1021 if ($ref->{charttype} eq 'H') {
1022 next unless ($form->{l_heading});
1024 %subtotals = map { $_ => 0 } @totals_columns;
1026 $row->{description}->{class} = 'listheading';
1027 $row->{description}->{data} = $ref->{description};
1029 $report->add_data($row);
1034 foreach (qw(debit credit)) {
1035 $subtotals{$_} += $ref->{$_};
1036 $totals{$_} += $ref->{$_};
1039 $subtotals{begbalance} += $ref->{balance} * $ml;
1040 $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1042 map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1043 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1045 $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1046 $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1048 $report->add_data($row);
1050 if ($form->{l_heading} && $found_heading &&
1051 (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1052 $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1056 $report->add_separator();
1058 $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1060 $report->generate_with_headers();
1062 $main::lxdebug->leave_sub();
1065 sub generate_ar_aging {
1066 $main::lxdebug->enter_sub();
1068 $main::auth->assert('general_ledger');
1070 my $form = $main::form;
1071 my %myconfig = %main::myconfig;
1072 my $locale = $main::locale;
1075 ($form->{customer}) = split(/--/, $form->{customer});
1077 $form->{ct} = "customer";
1078 $form->{arap} = "ar";
1080 $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1082 RP->aging(\%myconfig, \%$form);
1085 $main::lxdebug->leave_sub();
1088 sub generate_ap_aging {
1089 $main::lxdebug->enter_sub();
1091 $main::auth->assert('general_ledger');
1093 my $form = $main::form;
1094 my %myconfig = %main::myconfig;
1095 my $locale = $main::locale;
1098 ($form->{vendor}) = split(/--/, $form->{vendor});
1100 $form->{ct} = "vendor";
1101 $form->{arap} = "ap";
1103 $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1105 RP->aging(\%myconfig, \%$form);
1108 $main::lxdebug->leave_sub();
1111 sub create_aging_subtotal_row {
1112 $main::lxdebug->enter_sub();
1114 my ($subtotals, $columns, $periods, $class) = @_;
1116 my $form = $main::form;
1117 my %myconfig = %main::myconfig;
1118 my $locale = $main::locale;
1120 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1122 foreach (@{ $periods }) {
1123 $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1124 $subtotals->{$_} = 0;
1127 $main::lxdebug->leave_sub();
1133 $main::lxdebug->enter_sub();
1135 $main::auth->assert('general_ledger');
1137 my $form = $main::form;
1138 my %myconfig = %main::myconfig;
1139 my $locale = $main::locale;
1140 my $cgi = $::request->{cgi};
1142 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1144 my @columns = qw(statement ct invnumber transdate duedate amount open);
1147 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1148 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1149 'invnumber' => { 'text' => $locale->text('Invoice'), },
1150 'transdate' => { 'text' => $locale->text('Date'), },
1151 'duedate' => { 'text' => $locale->text('Due'), },
1152 'amount' => { 'text' => $locale->text('Amount'), },
1153 'open' => { 'text' => $locale->text('Open'), },
1156 my %column_alignment = ('statement' => 'center',
1157 map { $_ => 'right' } qw(open amount));
1159 $report->set_options('std_column_visibility' => 1);
1160 $report->set_columns(%column_defs);
1161 $report->set_column_order(@columns);
1163 my @hidden_variables = qw(todate customer vendor arap title ct fordate reporttype);
1164 $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1167 my $attachment_basename;
1169 if ($form->{department}) {
1170 my ($department) = split /--/, $form->{department};
1171 push @options, $locale->text('Department') . " : $department";
1172 $form->{callback} .= "&department=" . E($department);
1175 if (($form->{arap} eq 'ar') && $form->{customer}) {
1176 push @options, $form->{customer};
1177 $attachment_basename = $locale->text('ar_aging_list');
1178 $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1181 if (($form->{arap} eq 'ap') && $form->{vendor}) {
1182 push @options, $form->{vendor};
1183 $attachment_basename = $locale->text('ap_aging_list');
1184 $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1187 if ($form->{fromdate}) {
1188 push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1190 push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1193 $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1195 $report->set_options('top_info_text' => join("\n", @options),
1196 'output_format' => 'HTML',
1197 'title' => $form->{title},
1198 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1200 $report->set_options_from_form();
1201 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1203 my $previous_ctid = 0;
1205 my @periods = qw(open amount);
1206 my %subtotals = map { $_ => 0 } @periods;
1207 my %totals = map { $_ => 0 } @periods;
1209 foreach my $ref (@{ $form->{AG} }) {
1210 if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1211 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1214 foreach my $key (@periods) {
1215 $subtotals{$key} += $ref->{"$key"};
1216 $totals{$key} += $ref->{"$key"};
1217 $ref->{"$key"} = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1222 foreach my $column (@columns) {
1224 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1225 'align' => $column_alignment{$column},
1226 'valign' => $column eq 'statement' ? 'center' : '',
1230 $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1232 if ($previous_ctid != $ref->{ctid}) {
1233 $row->{statement}->{raw_data} =
1234 $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1235 . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1236 $row->{ct}->{data} = $ref->{name};
1241 $previous_ctid = $ref->{ctid};
1243 $report->add_data($row);
1246 $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1248 $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1250 if ($form->{arap} eq 'ar') {
1251 my $raw_top_info_text = $form->parse_html_template('rp/aging_ar_top');
1252 my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1253 'PRINT_OPTIONS' => print_options(inline => 1), });
1254 $report->set_options('raw_top_info_text' => $raw_top_info_text,
1255 'raw_bottom_info_text' => $raw_bottom_info_text);
1258 $report->generate_with_headers();
1260 $main::lxdebug->leave_sub();
1264 $main::lxdebug->enter_sub();
1266 my $form = $main::form;
1267 my %myconfig = %main::myconfig;
1268 my $locale = $main::locale;
1270 RP->aging(\%myconfig, \%$form);
1272 map { $_->{checked} = "checked" } @{ $form->{AG} };
1276 $main::lxdebug->leave_sub();
1280 $::lxdebug->enter_sub;
1281 $::auth->assert('general_ledger');
1283 # get name and email addresses
1285 for my $i (1 .. $::form->{rowcount}) {
1286 next unless $::form->{"statement_$i"};
1287 $::form->{"$::form->{ct}_id"} = $::form->{"$::form->{ct}_id_$i"};
1288 RP->get_customer(\%::myconfig, $::form);
1293 $::form->error($::locale->text('Nothing selected!')) unless $selected;
1295 $::form->{media} = "email";
1297 # save all other variables
1299 for my $key (keys %$::form) {
1300 next if any { $key eq $_ } qw(login password action email cc bcc subject message type sendmode format header);
1301 next unless '' eq ref $::form->{$key};
1302 push @hidden_values, $key;
1306 print $::form->parse_html_template('rp/e_mail', {
1307 show_bcc => $::auth->assert('email_bcc', 'may fail'),
1308 print_options => print_options(inline => 1),
1309 hidden_values => \@hidden_values,
1312 $::lxdebug->leave_sub;
1316 $main::lxdebug->enter_sub();
1318 $main::auth->assert('general_ledger');
1320 my $form = $main::form;
1321 my %myconfig = %main::myconfig;
1322 my $locale = $main::locale;
1324 $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1325 unless $form->{subject};
1327 RP->aging(\%myconfig, \%$form);
1329 $form->{"statement_1"} = 1;
1331 $form->{media} = 'email';
1334 $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1336 $main::lxdebug->leave_sub();
1340 $main::lxdebug->enter_sub();
1342 $main::auth->assert('general_ledger');
1344 my $form = $main::form;
1345 my %myconfig = %main::myconfig;
1346 my $locale = $main::locale;
1348 if ($form->{media} eq 'printer') {
1349 $form->error($locale->text('Select postscript or PDF!'))
1350 if ($form->{format} !~ /(postscript|pdf)/);
1354 for my $i (1 .. $form->{rowcount}) {
1355 if ($form->{"statement_$i"}) {
1356 $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1362 $form->error($locale->text('Nothing selected!')) unless $selected;
1364 if ($form->{media} eq 'printer') {
1365 $form->{"$form->{ct}_id"} = "";
1367 $form->{"statement_1"} = 1;
1370 RP->aging(\%myconfig, \%$form);
1374 $form->redirect($locale->text('Statements sent to printer!'))
1375 if ($form->{media} eq 'printer');
1377 $main::lxdebug->leave_sub();
1381 $main::lxdebug->enter_sub();
1383 $main::auth->assert('general_ledger');
1385 my $form = $main::form;
1386 my %myconfig = %main::myconfig;
1387 my $locale = $main::locale;
1389 my $defaults = SL::DB::Default->get;
1390 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
1391 $form->{templates} = $defaults->templates;
1393 $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1395 my $suffix = "html";
1396 my $attachment_suffix = "html";
1397 if ($form->{format} eq 'postscript') {
1398 $form->{postscript} = 1;
1400 $attachment_suffix = "ps";
1401 } elsif ($form->{format} eq 'pdf') {
1404 $attachment_suffix = "pdf";
1407 $form->{IN} = "$form->{type}.$suffix";
1408 $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1410 # Save $form->{email} because it will be overwritten.
1411 $form->{EMAIL_RECIPIENT} = $form->{email};
1415 while (@{ $form->{AG} }) {
1417 my $ref = shift @{ $form->{AG} };
1419 if ($ctid != $ref->{ctid}) {
1421 $ctid = $ref->{ctid};
1424 if ($form->{"statement_$i"}) {
1427 ("name", "street", "zipcode", "city", "country", "contact", "email",
1428 "$form->{ct}phone", "$form->{ct}fax");
1429 map { $form->{$_} = $ref->{$_} } @a;
1431 $form->{ $form->{ct} } = $form->{name};
1432 $form->{"$form->{ct}_id"} = $ref->{ctid};
1434 map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
1436 foreach my $item (qw(c0 c30 c60 c90)) {
1437 $form->{$item} = ();
1438 $form->{"${item}total"} = 0;
1441 &statement_details($ref);
1445 if (scalar(@{ $form->{AG} }) > 0) {
1447 # one or more left to go
1448 if ($ctid == $form->{AG}->[0]->{ctid}) {
1449 $ref = shift @{ $form->{AG} };
1450 &statement_details($ref);
1453 $ref = scalar(@{ $form->{AG} });
1459 # set initial ref to 0
1466 $form->{"${_}total"} =
1467 $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1468 } ('c0', 'c30', 'c60', 'c90', "");
1470 $form->{attachment_filename} = $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1471 $form->{attachment_filename} =~ s/\s+/_/g;
1473 $form->parse_template(\%myconfig);
1478 # saving the history
1479 if(!exists $form->{addition} && $form->{id} ne "") {
1480 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1481 $form->{addition} = "PRINTED";
1482 $form->{what_done} = $form->{type};
1483 $form->save_history;
1485 # /saving the history
1486 $main::lxdebug->leave_sub();
1489 sub statement_details {
1490 $main::lxdebug->enter_sub();
1492 $main::auth->assert('general_ledger');
1494 my $form = $main::form;
1495 my %myconfig = %main::myconfig;
1496 my $locale = $main::locale;
1500 push @{ $form->{invnumber} }, $ref->{invnumber};
1501 push @{ $form->{invdate} }, $ref->{transdate};
1502 push @{ $form->{duedate} }, $ref->{duedate};
1503 push @{ $form->{amount} }, $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
1504 push @{ $form->{open} }, $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
1506 foreach my $item (qw(c0 c30 c60 c90)) {
1507 if ($ref->{exchangerate} * 1) {
1508 # add only the open amount of the invoice to the aging, not the total amount
1509 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
1510 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
1511 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
1512 $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
1514 $form->{"${item}total"} += $ref->{$item};
1515 $form->{total} += $ref->{$item};
1516 push @{ $form->{$item} },
1517 $form->format_amount(\%myconfig, $ref->{$item}, 2);
1520 $main::lxdebug->leave_sub();
1523 sub generate_tax_report {
1524 $::lxdebug->enter_sub;
1525 $::auth->assert('report');
1527 RP->tax_report(\%::myconfig, $::form);
1529 my $descvar = "$::form->{accno}_description";
1530 my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
1534 my $callback = build_std_url('action=generate_tax_report', $descvar,
1535 qw(fromdate todate db method accno department report title));
1537 my @columns = $::form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1540 for my $item (@columns, 'subtotal') {
1541 if ($::form->{"l_$item"} eq "Y") {
1542 $callback .= "&l_$item=Y";
1543 $href .= "&l_$item=Y";
1547 for my $item (@columns) {
1548 if ($::form->{"l_$item"} eq "Y") {
1549 push @column_index, $item;
1554 if ($::form->{department}) {
1555 my ($department) = split /--/, $::form->{department};
1556 push @options, $::locale->text('Department') . " : $department";
1559 # if there are any dates
1560 if ($::form->{fromdate} || $::form->{todate}) {
1561 my $fromdate = $::form->{fromdate} ? $::locale->date(\%::myconfig, $::form->{fromdate}, 1) : '';
1562 my $todate = $::form->{todate} ? $::locale->date(\%::myconfig, $::form->{todate}, 1) : '';
1563 push @options, "$fromdate - $todate";
1565 push @options, $::locale->date(\%::myconfig, $::form->current_date, 1);
1568 my ($name, $invoice, $arap);
1569 if ($::form->{db} eq 'ar') {
1570 $name = $::locale->text('Customer');
1574 if ($::form->{db} eq 'ap') {
1575 $name = $::locale->text('Vendor');
1580 my %column_header = (
1581 id => $::locale->text('ID'),
1582 invnumber => $::locale->text('Invoice'),
1583 transdate => $::locale->text('Date'),
1584 netamount => $::locale->text('Amount'),
1585 tax => $::locale->text('Tax'),
1586 amount => $::locale->text('Total'),
1590 my %column_sorted = map { $_ => 1 } qw(id invnumber transdate);
1592 $callback .= "&sort=$::form->{sort}";
1595 if (@{ $::form->{TR} }) {
1596 $sameitem = $::form->{TR}->[0]->{ $::form->{sort} };
1599 my ($totalnetamount, $totaltax, @data);
1600 for my $ref (@{ $::form->{TR} }) {
1602 my $module = ($ref->{invoice}) ? $invoice : $arap;
1604 if ($::form->{l_subtotal} eq 'Y') {
1605 if ($sameitem ne $ref->{ $::form->{sort} }) {
1608 netamount => $subtotalnetamount,
1609 tax => $subtotaltax,
1610 amount => $subtotal,
1612 $subtotalnetamount = 0;
1614 $sameitem = $ref->{ $::form->{sort} };
1618 $subtotalnetamount += $ref->{netamount};
1619 $subtotaltax += $ref->{tax};
1620 $totalnetamount += $ref->{netamount};
1621 $totaltax += $ref->{tax};
1622 $ref->{amount} = $ref->{netamount} + $ref->{tax};
1624 push @data, { map { $_ => { data => $ref->{$_} } } keys %$ref };
1625 $data[-1]{invnumber}{link} = "$module?action=edit&id=$ref->{id}&callback=$callback";
1626 $data[-1]{$_}{numeric} = 1 for qw(netamount tax amount);
1629 if ($::form->{l_subtotal} eq 'Y') {
1632 netamount => $subtotalnetamount,
1633 tax => $subtotaltax,
1634 amount => $subtotal,
1640 netamount => $totalnetamount,
1642 amount => $totalnetamount + $totaltax,
1646 print $::form->parse_html_template('rp/tax_report', {
1647 column_index => \@column_index,
1648 column_header => \%column_header,
1649 column_sorted => \%column_sorted,
1652 options => \@options,
1655 $::lxdebug->leave_sub;
1659 $main::lxdebug->enter_sub();
1661 $main::auth->assert('cash');
1663 my $form = $main::form;
1664 my %myconfig = %main::myconfig;
1665 my $locale = $main::locale;
1667 if ($form->{account}) {
1668 ($form->{paymentaccounts}) = split /--/, $form->{account};
1672 if ($form->{department}) {
1673 (my $department, $form->{department_id}) = split /--/, $form->{department};
1674 $option = $locale->text('Department') . " : $department";
1677 report_generator_set_default_sort('transdate', 1);
1679 RP->payments(\%myconfig, \%$form);
1681 my @hidden_variables = qw(account title department reference source memo fromdate todate
1682 fx_transaction db prepayment paymentaccounts sort);
1684 my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
1685 $form->{callback} = $href;
1687 my @columns = qw(transdate invnumber name paid source memo);
1689 'name' => { 'text' => $locale->text('Description'), },
1690 'invnumber' => { 'text' => $locale->text('Reference'), },
1691 'transdate' => { 'text' => $locale->text('Date'), },
1692 'paid' => { 'text' => $locale->text('Amount'), },
1693 'source' => { 'text' => $locale->text('Source'), },
1694 'memo' => { 'text' => $locale->text('Memo'), },
1696 my %column_alignment = ('paid' => 'right');
1698 foreach my $name (grep { $_ ne 'paid' } @columns) {
1699 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1700 $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
1704 if ($form->{fromdate}) {
1705 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
1707 if ($form->{todate}) {
1708 push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1711 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1713 my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
1715 $report->set_options('top_info_text' => join("\n", @options),
1716 'output_format' => 'HTML',
1717 'title' => $form->{title},
1718 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1719 'std_column_visibility' => 1,
1721 $report->set_options_from_form();
1723 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1725 $report->set_columns(%column_defs);
1726 $report->set_column_order(@columns);
1728 $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
1730 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1734 foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1735 next unless @{ $form->{ $ref->{id} } };
1737 $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
1739 my $subtotal_paid = 0;
1741 foreach my $payment (@{ $form->{ $ref->{id} } }) {
1742 my $module = $payment->{module};
1743 $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1744 $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1746 $subtotal_paid += $payment->{paid};
1747 $total_paid += $payment->{paid};
1749 $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
1753 foreach my $column (@columns) {
1755 'data' => $payment->{$column},
1756 'align' => $column_alignment{$column},
1760 $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
1762 $report->add_data($row);
1765 my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
1767 'data' => $form->format_amount(\%myconfig, $subtotal_paid, 2),
1769 'class' => 'listsubtotal',
1772 $report->add_data($row);
1775 $report->add_separator();
1777 my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
1779 'data' => $form->format_amount(\%myconfig, $total_paid, 2),
1781 'class' => 'listtotal',
1784 $report->add_data($row);
1786 $report->generate_with_headers();
1788 $main::lxdebug->leave_sub();
1792 $::lxdebug->enter_sub;
1794 my ($dont_print) = @_;
1796 $::form->{sendmode} = "attachment";
1797 $::form->{format} ||= $::myconfig{template_format} || "pdf";
1798 $::form->{copies} ||= $::myconfig{copies} || 2;
1800 $::form->{PD}{ $::form->{type} } = "selected";
1801 $::form->{DF}{ $::form->{format} } = "selected";
1802 $::form->{OP}{ $::form->{media} } = "selected";
1803 $::form->{SM}{ $::form->{sendmode} } = "selected";
1805 my $output = $::form->parse_html_template('rp/print_options', {
1806 got_printer => $::myconfig{printer},
1807 show_latex => $::lx_office_conf{print_templates}->{latex},
1808 is_email => $::form->{media} eq 'email',
1811 print $output unless $dont_print;
1813 $::lxdebug->leave_sub;
1819 $main::lxdebug->enter_sub();
1821 $main::auth->assert('report');
1823 my $form = $main::form;
1824 my %myconfig = %main::myconfig;
1825 my $locale = $main::locale;
1827 $form->{padding} = " ";
1828 $form->{bold} = "<b>";
1829 $form->{endbold} = "</b>";
1830 $form->{br} = "<br>";
1832 if ($form->{reporttype} eq "custom") {
1834 #forgotten the year --> thisyear
1835 if ($form->{year} !~ m/^\d\d\d\d$/) {
1836 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1842 if ($form->{duetyp} eq "13") {
1843 $form->{fromdate} = "1.1.$form->{year}";
1844 $form->{todate} = "31.12.$form->{year}";
1845 $form->{comparefromdate} = "1.01.$form->{year}";
1846 $form->{comparetodate} = "31.12.$form->{year}";
1850 if ($form->{duetyp} eq "A") {
1851 $form->{fromdate} = "1.1.$form->{year}";
1852 $form->{todate} = "31.3.$form->{year}";
1853 $form->{comparefromdate} = "1.01.$form->{year}";
1854 $form->{comparetodate} = "31.03.$form->{year}";
1856 if ($form->{duetyp} eq "B") {
1857 $form->{fromdate} = "1.4.$form->{year}";
1858 $form->{todate} = "30.6.$form->{year}";
1859 $form->{comparefromdate} = "1.01.$form->{year}";
1860 $form->{comparetodate} = "30.06.$form->{year}";
1862 if ($form->{duetyp} eq "C") {
1863 $form->{fromdate} = "1.7.$form->{year}";
1864 $form->{todate} = "30.9.$form->{year}";
1865 $form->{comparefromdate} = "1.01.$form->{year}";
1866 $form->{comparetodate} = "30.09.$form->{year}";
1868 if ($form->{duetyp} eq "D") {
1869 $form->{fromdate} = "1.10.$form->{year}";
1870 $form->{todate} = "31.12.$form->{year}";
1871 $form->{comparefromdate} = "1.01.$form->{year}";
1872 $form->{comparetodate} = "31.12.$form->{year}";
1877 $form->{duetyp} eq "1" && do {
1878 $form->{fromdate} = "1.1.$form->{year}";
1879 $form->{todate} = "31.1.$form->{year}";
1880 $form->{comparefromdate} = "1.01.$form->{year}";
1881 $form->{comparetodate} = "31.01.$form->{year}";
1884 $form->{duetyp} eq "2" && do {
1885 $form->{fromdate} = "1.2.$form->{year}";
1887 #this works from 1901 to 2099, 1900 and 2100 fail.
1888 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1889 $form->{todate} = "$leap.2.$form->{year}";
1890 $form->{comparefromdate} = "1.01.$form->{year}";
1891 $form->{comparetodate} = "$leap.02.$form->{year}";
1894 $form->{duetyp} eq "3" && do {
1895 $form->{fromdate} = "1.3.$form->{year}";
1896 $form->{todate} = "31.3.$form->{year}";
1897 $form->{comparefromdate} = "1.01.$form->{year}";
1898 $form->{comparetodate} = "31.03.$form->{year}";
1901 $form->{duetyp} eq "4" && do {
1902 $form->{fromdate} = "1.4.$form->{year}";
1903 $form->{todate} = "30.4.$form->{year}";
1904 $form->{comparefromdate} = "1.01.$form->{year}";
1905 $form->{comparetodate} = "30.04.$form->{year}";
1908 $form->{duetyp} eq "5" && do {
1909 $form->{fromdate} = "1.5.$form->{year}";
1910 $form->{todate} = "31.5.$form->{year}";
1911 $form->{comparefromdate} = "1.01.$form->{year}";
1912 $form->{comparetodate} = "31.05.$form->{year}";
1915 $form->{duetyp} eq "6" && do {
1916 $form->{fromdate} = "1.6.$form->{year}";
1917 $form->{todate} = "30.6.$form->{year}";
1918 $form->{comparefromdate} = "1.01.$form->{year}";
1919 $form->{comparetodate} = "30.06.$form->{year}";
1922 $form->{duetyp} eq "7" && do {
1923 $form->{fromdate} = "1.7.$form->{year}";
1924 $form->{todate} = "31.7.$form->{year}";
1925 $form->{comparefromdate} = "1.01.$form->{year}";
1926 $form->{comparetodate} = "31.07.$form->{year}";
1929 $form->{duetyp} eq "8" && do {
1930 $form->{fromdate} = "1.8.$form->{year}";
1931 $form->{todate} = "31.8.$form->{year}";
1932 $form->{comparefromdate} = "1.01.$form->{year}";
1933 $form->{comparetodate} = "31.08.$form->{year}";
1936 $form->{duetyp} eq "9" && do {
1937 $form->{fromdate} = "1.9.$form->{year}";
1938 $form->{todate} = "30.9.$form->{year}";
1939 $form->{comparefromdate} = "1.01.$form->{year}";
1940 $form->{comparetodate} = "30.09.$form->{year}";
1943 $form->{duetyp} eq "10" && do {
1944 $form->{fromdate} = "1.10.$form->{year}";
1945 $form->{todate} = "31.10.$form->{year}";
1946 $form->{comparefromdate} = "1.01.$form->{year}";
1947 $form->{comparetodate} = "31.10.$form->{year}";
1950 $form->{duetyp} eq "11" && do {
1951 $form->{fromdate} = "1.11.$form->{year}";
1952 $form->{todate} = "30.11.$form->{year}";
1953 $form->{comparefromdate} = "1.01.$form->{year}";
1954 $form->{comparetodate} = "30.11.$form->{year}";
1957 $form->{duetyp} eq "12" && do {
1958 $form->{fromdate} = "1.12.$form->{year}";
1959 $form->{todate} = "31.12.$form->{year}";
1960 $form->{comparefromdate} = "1.01.$form->{year}";
1961 $form->{comparetodate} = "31.12.$form->{year}";
1965 hotfix_reformat_date();
1967 # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
1968 # ansonsten ist die prüfung in RP.pm
1969 # if (defined ($form->{fromdate|todate}=='..'))
1971 if ($form->{fromdate}){
1972 my $datetime = $locale->parse_date_to_object($form->{fromdate});
1973 $datetime->set( month => 1,
1975 $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
1977 if ($form->{todate}){
1978 $form->{comparetodate} = $form->{todate};
1982 RP->bwa(\%myconfig, \%$form);
1984 ($form->{department}) = split /--/, $form->{department};
1987 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1988 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1990 # if there are any dates construct a where
1991 if ($form->{fromdate} || $form->{todate}) {
1993 unless ($form->{todate}) {
1994 $form->{todate} = $form->current_date(\%myconfig);
1997 my %germandate = ("dateformat" => "dd.mm.yyyy");
1999 my $longtodate = $locale->date(\%germandate, $form->{todate}, 1);
2000 my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2002 my $longfromdate = $locale->date(\%germandate, $form->{fromdate}, 1);
2003 my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2005 $form->{this_period} = "$shortfromdate\n$shorttodate";
2007 $locale->text('for Period')
2008 . qq|\n$longfromdate |
2009 . $locale->text('bis')
2013 $form->{report_date} = $locale->text('Report date') . ": " . $form->current_date;
2015 if ( $form->{method} eq 'cash' ) {
2016 $form->{accounting_method} = $locale->text('Cash accounting');
2017 } elsif ( $form->{method} eq 'accrual' ) {
2018 $form->{accounting_method} = $locale->text('Accrual accounting');
2020 $form->{accounting_method} = "";
2023 $form->{title} = $locale->text('BWA');
2025 $::request->layout->add_stylesheets('bwa.css');
2027 print $form->parse_html_template('rp/bwa');
2029 $main::lxdebug->leave_sub();
2032 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
2033 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
2034 sub hotfix_reformat_date {
2036 $main::lxdebug->enter_sub();
2038 my $form = $main::form;
2039 my %myconfig = %main::myconfig;
2040 my $locale = $main::locale;
2042 if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
2043 my $current_dateformat = $myconfig{dateformat};
2044 $myconfig{dateformat} = 'dd.mm.yyyy';
2045 $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
2046 $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
2047 $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
2048 unless (!defined ($form->{comparefromdate}));
2049 $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
2050 unless (!defined ($form->{comparetodate}));
2052 # Und wieder zurücksetzen
2053 $myconfig{dateformat} = $current_dateformat; #'dd.mm.yyyy';
2054 } # Ende Hotifx Bug 1388
2056 $main::lxdebug->leave_sub();