Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / bin / mozilla / rp.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors: Antonio Gallardo <agssa@ibw.com.ni>
16 #                Benjamin Lee <benjaminlee@consultant.com>
17 #                Philip Reetz <p.reetz@linet-services.de>
18 #                Udo Spallek
19 #
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.
24 #
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 #======================================================================
33 #
34 # module for preparing Income Statement and Balance Sheet
35 #
36 #======================================================================
37
38 use POSIX qw(strftime);
39
40 use SL::PE;
41 use SL::RP;
42 use SL::Iconv;
43 use SL::ReportGenerator;
44 use Data::Dumper;
45
46 require "bin/mozilla/arap.pl";
47 require "bin/mozilla/common.pl";
48 require "bin/mozilla/reportgenerator.pl";
49
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
53 use strict;
54
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')
68
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')
82
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')
98
99 # $form->parse_html_template('rp/html_report_susa')
100
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',
109   'bwa'              => 'report',
110   'balance_sheet'    => 'report',
111 };
112
113 sub check_rp_access {
114   my $form     = $main::form;
115
116   my $right   = $rp_access_map->{$form->{report}};
117   $right    ||= 'DOES_NOT_EXIST';
118
119   $main::auth->assert($right);
120 }
121
122 sub report {
123   $::lxdebug->enter_sub;
124
125   check_rp_access();
126
127   my %title = (
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'),
141   );
142
143   $::form->{title} = $title{$::form->{report}};
144
145   # get departments
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} || [] };
150   }
151
152   $::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
153
154   my $is_projects         = $::form->{report} eq "projects";
155   my $is_income_statement = $::form->{report} eq "income_statement";
156   my $is_bwa              = $::form->{report} eq "bwa";
157   my $is_balance_sheet    = $::form->{report} eq "balance_sheet";
158   my $is_trial_balance    = $::form->{report} eq "trial_balance";
159   my $is_aging            = $::form->{report} =~ /^a[rp]_aging$/;
160   my $is_payments         = $::form->{report} =~ /(receipts|payments)$/;
161
162   my ($label, $nextsub, $vc);
163   if ($is_aging) {
164     my $is_sales  = $::form->{report} eq 'ar_aging';
165     $label        = $is_sales ? $::locale->text('Customer') : $::locale->text('Vendor');
166     $::form->{vc} = $is_sales ? 'customer' : 'vendor';
167
168     $nextsub = "generate_$::form->{report}";
169
170     # setup vc selection
171     $::form->all_vc(\%::myconfig, $::form->{vc}, $is_sales ? "AR" : "AP");
172     $vc .= "<option>$_->{name}--$_->{id}\n" for @{ $::form->{"all_$::form->{vc}"} };
173     $vc = ($vc)
174         ? qq|<select name=$::form->{vc}><option>\n$vc</select>|
175         : qq|<input name=$::form->{vc} size=35>|;
176   }
177
178   my ($selection, $paymentaccounts);
179   if ($is_payments) {
180     $::form->{db} = $::form->{report} =~ /payments$/ ? "ap" : "ar";
181
182     RP->paymentaccounts(\%::myconfig, $::form);
183
184     $selection = "<option>\n";
185     for my $ref (@{ $::form->{PR} }) {
186       $paymentaccounts .= "$ref->{accno} ";
187       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
188     }
189   }
190
191   $::form->header;
192   print $::form->parse_html_template('rp/report', {
193     paymentaccounts     => $paymentaccounts,
194     selection           => $selection,
195     is_aging            => $is_aging,
196     vc                  => $vc,
197     label               => $label,
198     year                => DateTime->today->year,
199     nextsub             => $nextsub,
200     accrual             => $::instance_conf->get_accounting_method ne 'cash',
201     cash                => $::instance_conf->get_accounting_method eq 'cash',
202     is_payments         => $is_payments,
203     is_trial_balance    => $is_trial_balance,
204     is_balance_sheet    => $is_balance_sheet,
205     is_bwa              => $is_bwa,
206     is_income_statement => $is_income_statement,
207     is_projects         => $is_projects,
208   });
209
210   $::lxdebug->leave_sub;
211 }
212
213 sub continue { call_sub($main::form->{"nextsub"}); }
214
215 sub get_project {
216   $main::lxdebug->enter_sub();
217
218   $main::auth->assert('report');
219
220   my $form     = $main::form;
221   my %myconfig = %main::myconfig;
222   my $locale   = $main::locale;
223
224   my $nextsub = shift;
225
226   $form->{project_id} = $form->{project_id_1};
227   if ($form->{projectnumber} && !$form->{project_id}) {
228     $form->{rowcount} = 1;
229
230     # call this instead of update
231     $form->{update}          = $nextsub;
232     $form->{projectnumber_1} = $form->{projectnumber};
233
234     delete $form->{sort};
235     check_project('generate_projects');
236
237     # if there is one only, assign id
238     $form->{project_id} = $form->{project_id_1};
239   }
240
241   $main::lxdebug->leave_sub();
242 }
243
244 sub generate_income_statement {
245   $main::lxdebug->enter_sub();
246
247   $main::auth->assert('report');
248
249   my $form     = $main::form;
250   my %myconfig = %main::myconfig;
251   my $locale   = $main::locale;
252
253   $form->{padding} = "&nbsp;&nbsp;";
254   $form->{bold}    = "<b>";
255   $form->{endbold} = "</b>";
256   $form->{br}      = "<br>";
257
258   if ($form->{reporttype} eq "custom") {
259
260     #forgotten the year --> thisyear
261     if ($form->{year} !~ m/^\d\d\d\d$/) {
262       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
263         /(\d\d\d\d)/;
264       $form->{year} = $1;
265     }
266
267     #yearly report
268     if ($form->{duetyp} eq "13") {
269       $form->{fromdate} = "1.1.$form->{year}";
270       $form->{todate}   = "31.12.$form->{year}";
271     }
272
273     #Quater reports
274     if ($form->{duetyp} eq "A") {
275       $form->{fromdate} = "1.1.$form->{year}";
276       $form->{todate}   = "31.3.$form->{year}";
277     }
278     if ($form->{duetyp} eq "B") {
279       $form->{fromdate} = "1.4.$form->{year}";
280       $form->{todate}   = "30.6.$form->{year}";
281     }
282     if ($form->{duetyp} eq "C") {
283       $form->{fromdate} = "1.7.$form->{year}";
284       $form->{todate}   = "30.9.$form->{year}";
285     }
286     if ($form->{duetyp} eq "D") {
287       $form->{fromdate} = "1.10.$form->{year}";
288       $form->{todate}   = "31.12.$form->{year}";
289     }
290
291     #Monthly reports
292   SWITCH: {
293       $form->{duetyp} eq "1" && do {
294         $form->{fromdate} = "1.1.$form->{year}";
295         $form->{todate}   = "31.1.$form->{year}";
296         last SWITCH;
297       };
298       $form->{duetyp} eq "2" && do {
299         $form->{fromdate} = "1.2.$form->{year}";
300
301         #this works from 1901 to 2099, 1900 and 2100 fail.
302         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
303         $form->{todate} = "$leap.2.$form->{year}";
304         last SWITCH;
305       };
306       $form->{duetyp} eq "3" && do {
307         $form->{fromdate} = "1.3.$form->{year}";
308         $form->{todate}   = "31.3.$form->{year}";
309         last SWITCH;
310       };
311       $form->{duetyp} eq "4" && do {
312         $form->{fromdate} = "1.4.$form->{year}";
313         $form->{todate}   = "30.4.$form->{year}";
314         last SWITCH;
315       };
316       $form->{duetyp} eq "5" && do {
317         $form->{fromdate} = "1.5.$form->{year}";
318         $form->{todate}   = "31.5.$form->{year}";
319         last SWITCH;
320       };
321       $form->{duetyp} eq "6" && do {
322         $form->{fromdate} = "1.6.$form->{year}";
323         $form->{todate}   = "30.6.$form->{year}";
324         last SWITCH;
325       };
326       $form->{duetyp} eq "7" && do {
327         $form->{fromdate} = "1.7.$form->{year}";
328         $form->{todate}   = "31.7.$form->{year}";
329         last SWITCH;
330       };
331       $form->{duetyp} eq "8" && do {
332         $form->{fromdate} = "1.8.$form->{year}";
333         $form->{todate}   = "31.8.$form->{year}";
334         last SWITCH;
335       };
336       $form->{duetyp} eq "9" && do {
337         $form->{fromdate} = "1.9.$form->{year}";
338         $form->{todate}   = "30.9.$form->{year}";
339         last SWITCH;
340       };
341       $form->{duetyp} eq "10" && do {
342         $form->{fromdate} = "1.10.$form->{year}";
343         $form->{todate}   = "31.10.$form->{year}";
344         last SWITCH;
345       };
346       $form->{duetyp} eq "11" && do {
347         $form->{fromdate} = "1.11.$form->{year}";
348         $form->{todate}   = "30.11.$form->{year}";
349         last SWITCH;
350       };
351       $form->{duetyp} eq "12" && do {
352         $form->{fromdate} = "1.12.$form->{year}";
353         $form->{todate}   = "31.12.$form->{year}";
354         last SWITCH;
355       };
356     }
357     hotfix_reformat_date();
358   } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
359
360   RP->income_statement(\%myconfig, \%$form);
361
362   ($form->{department}) = split /--/, $form->{department};
363
364   $form->{period} =
365     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
366   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
367
368   # if there are any dates construct a where
369   if ($form->{fromdate} || $form->{todate}) {
370
371     unless ($form->{todate}) {
372       $form->{todate} = $form->current_date(\%myconfig);
373     }
374
375     my $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
376     my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
377
378     my $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
379     my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
380
381     $form->{this_period} = "$shortfromdate\n$shorttodate";
382     $form->{period}      =
383         $locale->text('for Period')
384       . qq|\n$longfromdate |
385       . $locale->text('Bis')
386       . qq| $longtodate|;
387   }
388
389   if ($form->{comparefromdate} || $form->{comparetodate}) {
390     my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
391     my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
392
393     my $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
394     my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
395
396     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
397     $form->{period} .=
398         "\n$longcomparefromdate "
399       . $locale->text('Bis')
400       . qq| $longcomparetodate|;
401   }
402
403   # setup variables for the form
404   my @a = qw(company address businessnumber);
405   map { $form->{$_} = $myconfig{$_} } @a;
406
407   $form->{templates} = $myconfig{templates};
408
409   $form->{IN} = "income_statement.html";
410
411   $form->parse_template;
412
413   $main::lxdebug->leave_sub();
414 }
415
416 sub generate_balance_sheet {
417   $::lxdebug->enter_sub;
418   $::auth->assert('report');
419
420   $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
421   $::form->{padding}       = "&nbsp;&nbsp;";
422   $::form->{bold}          = "<b>";
423   $::form->{endbold}       = "</b>";
424   $::form->{br}            = "<br>";
425
426   my $data = RP->balance_sheet(\%::myconfig, $::form);
427
428   $::form->{asofdate} ||= $::form->current_date;
429   $::form->{period}     = $::locale->date(\%::myconfig, $::form->current_date, 1);
430
431   ($::form->{department}) = split /--/, $::form->{department};
432
433   # define Current Earnings account
434   my $padding = $::form->{l_heading} ? $::form->{padding} : "";
435   push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
436
437   $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
438   $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
439
440 #  $::form->{IN} = "balance_sheet.html";
441
442   # setup company variables for the form
443   map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
444
445   $::form->{templates} = $::myconfig{templates};
446
447   $::form->header;
448   print $::form->parse_html_template('rp/balance_sheet', $data);
449
450   $::lxdebug->leave_sub;
451 }
452
453 sub generate_projects {
454   $main::lxdebug->enter_sub();
455
456   $main::auth->assert('report');
457
458   my $form     = $main::form;
459   my %myconfig = %main::myconfig;
460   my $locale   = $main::locale;
461
462   &get_project("generate_projects");
463   $form->{projectnumber} = $form->{projectnumber_1};
464
465   $form->{nextsub} = "generate_projects";
466   $form->{title}   = $locale->text('Project Transactions');
467   RP->trial_balance(\%myconfig, \%$form);
468
469   list_accounts('generate_projects');
470
471   $main::lxdebug->leave_sub();
472 }
473
474 # Antonio Gallardo
475 #
476 # D.S. Feb 16, 2001
477 # included links to display transactions for period entered
478 # added headers and subtotals
479 #
480 sub generate_trial_balance {
481   $main::lxdebug->enter_sub();
482
483   $main::auth->assert('report');
484
485   my $form     = $main::form;
486   my %myconfig = %main::myconfig;
487   my $locale   = $main::locale;
488
489   if ($form->{reporttype} eq "custom") {
490
491     #forgotten the year --> thisyear
492     if ($form->{year} !~ m/^\d\d\d\d$/) {
493       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
494         /(\d\d\d\d)/;
495       $form->{year} = $1;
496     }
497
498     #yearly report
499     if ($form->{duetyp} eq "13") {
500       $form->{fromdate} = "1.1.$form->{year}";
501       $form->{todate}   = "31.12.$form->{year}";
502     }
503
504     #Quater reports
505     if ($form->{duetyp} eq "A") {
506       $form->{fromdate} = "1.1.$form->{year}";
507       $form->{todate}   = "31.3.$form->{year}";
508     }
509     if ($form->{duetyp} eq "B") {
510       $form->{fromdate} = "1.4.$form->{year}";
511       $form->{todate}   = "30.6.$form->{year}";
512     }
513     if ($form->{duetyp} eq "C") {
514       $form->{fromdate} = "1.7.$form->{year}";
515       $form->{todate}   = "30.9.$form->{year}";
516     }
517     if ($form->{duetyp} eq "D") {
518       $form->{fromdate} = "1.10.$form->{year}";
519       $form->{todate}   = "31.12.$form->{year}";
520     }
521
522     #Monthly reports
523   SWITCH: {
524       $form->{duetyp} eq "1" && do {
525         $form->{fromdate} = "1.1.$form->{year}";
526         $form->{todate}   = "31.1.$form->{year}";
527         last SWITCH;
528       };
529       $form->{duetyp} eq "2" && do {
530         $form->{fromdate} = "1.2.$form->{year}";
531
532         #this works from 1901 to 2099, 1900 and 2100 fail.
533         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
534         $form->{todate} = "$leap.2.$form->{year}";
535         last SWITCH;
536       };
537       $form->{duetyp} eq "3" && do {
538         $form->{fromdate} = "1.3.$form->{year}";
539         $form->{todate}   = "31.3.$form->{year}";
540         last SWITCH;
541       };
542       $form->{duetyp} eq "4" && do {
543         $form->{fromdate} = "1.4.$form->{year}";
544         $form->{todate}   = "30.4.$form->{year}";
545         last SWITCH;
546       };
547       $form->{duetyp} eq "5" && do {
548         $form->{fromdate} = "1.5.$form->{year}";
549         $form->{todate}   = "31.5.$form->{year}";
550         last SWITCH;
551       };
552       $form->{duetyp} eq "6" && do {
553         $form->{fromdate} = "1.6.$form->{year}";
554         $form->{todate}   = "30.6.$form->{year}";
555         last SWITCH;
556       };
557       $form->{duetyp} eq "7" && do {
558         $form->{fromdate} = "1.7.$form->{year}";
559         $form->{todate}   = "31.7.$form->{year}";
560         last SWITCH;
561       };
562       $form->{duetyp} eq "8" && do {
563         $form->{fromdate} = "1.8.$form->{year}";
564         $form->{todate}   = "31.8.$form->{year}";
565         last SWITCH;
566       };
567       $form->{duetyp} eq "9" && do {
568         $form->{fromdate} = "1.9.$form->{year}";
569         $form->{todate}   = "30.9.$form->{year}";
570         last SWITCH;
571       };
572       $form->{duetyp} eq "10" && do {
573         $form->{fromdate} = "1.10.$form->{year}";
574         $form->{todate}   = "31.10.$form->{year}";
575         last SWITCH;
576       };
577       $form->{duetyp} eq "11" && do {
578         $form->{fromdate} = "1.11.$form->{year}";
579         $form->{todate}   = "30.11.$form->{year}";
580         last SWITCH;
581       };
582       $form->{duetyp} eq "12" && do {
583         $form->{fromdate} = "1.12.$form->{year}";
584         $form->{todate}   = "31.12.$form->{year}";
585         last SWITCH;
586       };
587     }
588     hotfix_reformat_date();
589   }
590
591
592   # get for each account initial balance, debits and credits
593   RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
594
595
596   $form->{rowcount} = scalar @{ $form->{TB} || [] };
597   $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
598
599   my @columns = (
600     "accno",               "description",
601     "last_transaction",    "soll_eb",
602     "haben_eb",
603     "soll",                "haben",
604     "soll_kumuliert",      "haben_kumuliert",
605     "soll_saldo",          "haben_saldo"
606   );
607
608
609   my $attachment_basename = $locale->text('trial_balance');
610   my $report              = SL::ReportGenerator->new(\%myconfig, $form);
611
612   my @hidden_variables    = qw(fromdate todate year cash);
613
614   my $href                = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
615
616   my %column_defs         = (
617     'accno'               => { 'text' => $locale->text('Account'), },
618     'description'         => { 'text' => $locale->text('Description'), },
619     'last_transaction'    => { 'text' => $locale->text('Last Transaction'), },
620     'soll_eb'             => { 'text' => $locale->text('Debit Starting Balance'), },
621     'haben_eb'            => { 'text' => $locale->text('Credit Starting Balance'), },
622     'soll'                => { 'text' => $locale->text('Debit'), },
623     'haben'               => { 'text' => $locale->text('Credit'), },
624     'soll_kumuliert'      => { 'text' => $locale->text('Sum Debit'), },
625     'haben_kumuliert'     => { 'text' => $locale->text('Sum Credit'), },
626     'soll_saldo'          => { 'text' => $locale->text('Saldo Debit'), },
627     'haben_saldo'         => { 'text' => $locale->text('Saldo Credit'), }
628   );
629
630
631
632   my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
633
634   map { $column_defs{$_}->{visible} =  1 } @columns;
635
636   $report->set_columns(%column_defs);
637   $report->set_column_order(@columns);
638
639   $report->set_export_options('generate_trial_balance', @hidden_variables);
640
641   my @options;
642
643
644   $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
645
646   $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
647   push (@options, $form->{print_date});
648
649   $form->{company} = $locale->text('Company') . " " . $myconfig{company};
650   push (@options, $form->{company});
651
652
653   $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
654
655   my @custom_headers = ([
656     { text => $::locale->text('Account'),          rowspan => 2, },
657     { text => $::locale->text('Description'),      rowspan => 2, },
658     { text => $::locale->text('Last Transaction'), rowspan => 2, },
659     { text => $::locale->text('Starting Balance'), colspan => 2, },
660     { text => $::locale->text('Sum for')   . " $form->{template_fromto}", colspan => 2, },
661     { text => $::locale->text('Sum per')   . " $form->{template_to}",     colspan => 2, },
662     { text => $::locale->text('Saldo per') . " $form->{template_to}",     colspan => 2, },
663   ], [
664     { text => '', },
665     { text => '', },
666     { text => '', },
667     { text => $::locale->text('Assets'), },
668     { text => $::locale->text('Equity'), },
669     { text => $::locale->text('Debit'),  },
670     { text => $::locale->text('Credit'), },
671     { text => $::locale->text('Debit'),  },
672     { text => $::locale->text('Credit'), },
673     { text => $::locale->text('Debit'),  },
674     { text => $::locale->text('Credit'), },
675   ]);
676
677   $report->set_options('output_format'        => 'HTML',
678                        'top_info_text'        => join("\n", @options),
679                        'title'                => $form->{title},
680                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
681                        'html_template'        => 'rp/html_report_susa',
682                        'pdf_template'         => 'rp/html_report_susa',
683     );
684   $report->set_custom_headers(@custom_headers);
685   $report->set_options_from_form();
686   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
687
688   # add sort and escape callback, this one we use for the add sub
689   $form->{callback} = $href .= "&sort=$form->{sort}";
690
691   # escape callback for href
692   my $callback = $form->escape($href);
693
694   my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
695
696   my %totals    = map { $_ => 0 } @subtotal_columns;
697
698   my $edit_url = build_std_url('action=edit', 'type', 'vc');
699
700   my $idx;
701   foreach my $accno (@{ $form->{TB} || [] }) {
702
703     $accno->{soll} = $accno->{debit};
704     $accno->{haben} = $accno->{credit};
705     map { $totals{$_}    += $accno->{$_} } @subtotal_columns;
706
707     map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
708       qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
709
710     my $row = { };
711
712     foreach my $column (@columns) {
713       $row->{$column} = {
714         'data'  => $accno->{$column},
715         'align' => $column_alignment{$column},
716       };
717     }
718
719     $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}));
720
721     my $row_set = [ $row ];
722
723
724     $report->add_data($row_set);
725
726     $idx++;
727   }
728
729   $report->add_separator();
730
731   $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
732
733   $report->generate_with_headers();
734
735   $main::lxdebug->leave_sub();
736
737 }
738
739 sub create_subtotal_row {
740   $main::lxdebug->enter_sub();
741
742   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
743
744   my $form     = $main::form;
745   my %myconfig = %main::myconfig;
746   my $locale   = $main::locale;
747
748   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
749
750   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
751
752   $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
753
754   map { $totals->{$_} = 0 } @{ $subtotal_columns };
755
756   $main::lxdebug->leave_sub();
757
758   return $row;
759 }
760
761 sub create_list_accounts_subtotal_row {
762   $main::lxdebug->enter_sub();
763
764   my ($subtotals, $columns, $fields, $class) = @_;
765
766   my $form     = $main::form;
767   my %myconfig = %main::myconfig;
768   my $locale   = $main::locale;
769
770   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
771
772   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
773
774   $main::lxdebug->leave_sub();
775
776   return $row;
777 }
778
779 sub list_accounts {
780   $main::lxdebug->enter_sub();
781
782   my ($action) = @_;
783
784   my $form     = $main::form;
785   my %myconfig = %main::myconfig;
786   my $locale   = $main::locale;
787
788   my @options;
789   if ($form->{department}) {
790     my ($department) = split /--/, $form->{department};
791     push @options, $locale->text('Department') . " : $department";
792   }
793   if ($form->{projectnumber}) {
794     push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
795   }
796
797   # if there are any dates
798   if ($form->{fromdate} || $form->{todate}) {
799     my ($fromdate, $todate);
800
801     if ($form->{fromdate}) {
802       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
803     }
804     if ($form->{todate}) {
805       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
806     }
807
808     push @options, "$fromdate - $todate";
809
810   } else {
811     push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
812   }
813
814   my @columns     = qw(accno description begbalance debit credit endbalance);
815   my %column_defs = (
816     'accno'       => { 'text' => $locale->text('Account'), },
817     'description' => { 'text' => $locale->text('Description'), },
818     'debit'       => { 'text' => $locale->text('Debit'), },
819     'credit'      => { 'text' => $locale->text('Credit'), },
820     'begbalance'  => { 'text' => $locale->text('Balance'), },
821     'endbalance'  => { 'text' => $locale->text('Balance'), },
822   );
823   my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
824
825   my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
826
827   $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
828
829   my $report = SL::ReportGenerator->new(\%myconfig, $form);
830
831   $report->set_options('top_info_text'         => join("\n", @options),
832                        'output_format'         => 'HTML',
833                        'title'                 => $form->{title},
834                        'attachment_basename'   => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
835                        'std_column_visibility' => 1,
836     );
837   $report->set_options_from_form();
838   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
839
840   $report->set_columns(%column_defs);
841   $report->set_column_order(@columns);
842
843   $report->set_export_options($action, @hidden_variables);
844
845   my @totals_columns = qw(credit debit begbalance endbalance);
846   my %subtotals      = map { $_ => 0 } @totals_columns;
847   my %totals         = map { $_ => 0 } @totals_columns;
848   my $found_heading  = 0;
849   my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
850
851   # sort the whole thing by account numbers and display
852   foreach my $idx (0 .. scalar(@tb) - 1) {
853     my $ref  = $tb[$idx];
854     my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
855
856     my $ml   = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
857
858     my $row  = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
859
860     if ($ref->{charttype} eq 'H') {
861       next unless ($form->{l_heading});
862
863       %subtotals                   = map { $_ => 0 } @totals_columns;
864       $found_heading               = 1;
865       $row->{description}->{class} = 'listheading';
866       $row->{description}->{data}  = $ref->{description};
867
868       $report->add_data($row);
869
870       next;
871     }
872
873     foreach (qw(debit credit)) {
874       $subtotals{$_} += $ref->{$_};
875       $totals{$_}    += $ref->{$_};
876     }
877
878     $subtotals{begbalance} += $ref->{balance} * $ml;
879     $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
880
881     map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
882     map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
883
884     $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
885     $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
886
887     $report->add_data($row);
888
889     if ($form->{l_heading} && $found_heading &&
890         (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
891       $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
892     }
893   }
894
895   $report->add_separator();
896
897   $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
898
899   $report->generate_with_headers();
900
901   $main::lxdebug->leave_sub();
902 }
903
904 sub generate_ar_aging {
905   $main::lxdebug->enter_sub();
906
907   $main::auth->assert('general_ledger');
908
909   my $form     = $main::form;
910   my %myconfig = %main::myconfig;
911   my $locale   = $main::locale;
912
913   # split customer
914   ($form->{customer}) = split(/--/, $form->{customer});
915
916   $form->{ct}   = "customer";
917   $form->{arap} = "ar";
918
919   $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
920
921   RP->aging(\%myconfig, \%$form);
922   aging();
923
924   $main::lxdebug->leave_sub();
925 }
926
927 sub generate_ap_aging {
928   $main::lxdebug->enter_sub();
929
930   $main::auth->assert('general_ledger');
931
932   my $form     = $main::form;
933   my %myconfig = %main::myconfig;
934   my $locale   = $main::locale;
935
936   # split vendor
937   ($form->{vendor}) = split(/--/, $form->{vendor});
938
939   $form->{ct}   = "vendor";
940   $form->{arap} = "ap";
941
942   $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
943
944   RP->aging(\%myconfig, \%$form);
945   aging();
946
947   $main::lxdebug->leave_sub();
948 }
949
950 sub create_aging_subtotal_row {
951   $main::lxdebug->enter_sub();
952
953   my ($subtotals, $columns, $periods, $class) = @_;
954
955   my $form     = $main::form;
956   my %myconfig = %main::myconfig;
957   my $locale   = $main::locale;
958
959   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
960
961   foreach (@{ $periods }) {
962     $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
963     $subtotals->{$_}      = 0;
964   }
965
966   $main::lxdebug->leave_sub();
967
968   return $row;
969 }
970
971 sub aging {
972   $main::lxdebug->enter_sub();
973
974   $main::auth->assert('general_ledger');
975
976   my $form     = $main::form;
977   my %myconfig = %main::myconfig;
978   my $locale   = $main::locale;
979   my $cgi      = $::request->{cgi};
980
981   my $report = SL::ReportGenerator->new(\%myconfig, $form);
982
983   my @columns = qw(statement ct invnumber transdate duedate amount open);
984
985   my %column_defs = (
986     'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
987     'ct'        => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
988     'invnumber' => { 'text' => $locale->text('Invoice'), },
989     'transdate' => { 'text' => $locale->text('Date'), },
990     'duedate'   => { 'text' => $locale->text('Due'), },
991     'amount'    => { 'text' => $locale->text('Amount'), },
992     'open'      => { 'text' => $locale->text('Open'), },
993   );
994
995   my %column_alignment = ('statement' => 'center',
996                           map { $_ => 'right' } qw(open amount));
997
998   $report->set_options('std_column_visibility' => 1);
999   $report->set_columns(%column_defs);
1000   $report->set_column_order(@columns);
1001
1002   my @hidden_variables = qw(todate customer vendor arap title ct);
1003   $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1004
1005   my @options;
1006   my $attachment_basename;
1007
1008   if ($form->{department}) {
1009     my ($department) = split /--/, $form->{department};
1010     push @options, $locale->text('Department') . " : $department";
1011     $form->{callback} .= "&department=" . E($department);
1012   }
1013
1014   if (($form->{arap} eq 'ar') && $form->{customer}) {
1015     push @options, $form->{customer};
1016     $attachment_basename = $locale->text('ar_aging_list');
1017     $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
1018   }
1019
1020   if (($form->{arap} eq 'ap') && $form->{vendor}) {
1021     push @options, $form->{vendor};
1022     $attachment_basename = $locale->text('ap_aging_list');
1023     $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
1024   }
1025
1026   if ($form->{fromdate}) {
1027     push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1028   } else {
1029     push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1030   }
1031
1032   $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1033
1034   $report->set_options('top_info_text'        => join("\n", @options),
1035                        'output_format'        => 'HTML',
1036                        'title'                => $form->{title},
1037                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
1038     );
1039   $report->set_options_from_form();
1040   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1041
1042   my $previous_ctid = 0;
1043   my $row_idx       = 0;
1044   my @periods       = qw(open amount);
1045   my %subtotals     = map { $_ => 0 } @periods;
1046   my %totals        = map { $_ => 0 } @periods;
1047
1048   foreach my $ref (@{ $form->{AG} }) {
1049     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1050       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1051     }
1052
1053     foreach my $key (@periods) {
1054       $subtotals{$key}  += $ref->{"$key"};
1055       $totals{$key}     += $ref->{"$key"};
1056       $ref->{"$key"}  = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
1057     }
1058
1059     my $row = { };
1060
1061     foreach my $column (@columns) {
1062       $row->{$column} = {
1063         'data'   => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1064         'align'  => $column_alignment{$column},
1065         'valign' => $column eq 'statement' ? 'center' : '',
1066       };
1067     }
1068
1069     $row->{invnumber}->{link} =  build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1070
1071     if ($previous_ctid != $ref->{ctid}) {
1072       $row->{statement}->{raw_data} =
1073           $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
1074         . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1075       $row->{ct}->{data} = $ref->{name};
1076
1077       $row_idx++;
1078     }
1079
1080     $previous_ctid = $ref->{ctid};
1081
1082     $report->add_data($row);
1083   }
1084
1085   $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1086
1087   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1088
1089   if ($form->{arap} eq 'ar') {
1090     my $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
1091     my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1092                                                                                'PRINT_OPTIONS' => print_options(inline => 1), });
1093     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
1094                          'raw_bottom_info_text' => $raw_bottom_info_text);
1095   }
1096
1097   $report->generate_with_headers();
1098
1099   $main::lxdebug->leave_sub();
1100 }
1101
1102 sub select_all {
1103   $main::lxdebug->enter_sub();
1104
1105   my $form     = $main::form;
1106   my %myconfig = %main::myconfig;
1107   my $locale   = $main::locale;
1108
1109   RP->aging(\%myconfig, \%$form);
1110
1111   map { $_->{checked} = "checked" } @{ $form->{AG} };
1112
1113   &aging;
1114
1115   $main::lxdebug->leave_sub();
1116 }
1117
1118 sub e_mail {
1119   $::lxdebug->enter_sub;
1120   $::auth->assert('general_ledger');
1121
1122   # get name and email addresses
1123   my $selected = 0;
1124   for my $i (1 .. $::form->{rowcount}) {
1125     next unless $::form->{"statement_$i"};
1126     $::form->{"$::form->{ct}_id"} = $::form->{"$::form->{ct}_id_$i"};
1127     RP->get_customer(\%::myconfig, $::form);
1128     $selected = 1;
1129     last;
1130   }
1131
1132   $::form->error($::locale->text('Nothing selected!')) unless $selected;
1133
1134   $::form->{media} = "email";
1135
1136   # save all other variables
1137   my @hidden_values;
1138   for my $key (keys %$::form) {
1139     next if any { $key eq $_ } qw(login password action email cc bcc subject message type sendmode format header);
1140     next unless '' eq ref $::form->{$key};
1141     push @hidden_values, $key;
1142   }
1143
1144   $::form->header;
1145   print $::form->parse_html_template('rp/e_mail', {
1146     show_bcc      => $::auth->assert('email_bcc', 'may fail'),
1147     print_options => print_options(inline => 1),
1148     hidden_values => \@hidden_values,
1149   });
1150
1151   $::lxdebug->leave_sub;
1152 }
1153
1154 sub send_email {
1155   $main::lxdebug->enter_sub();
1156
1157   $main::auth->assert('general_ledger');
1158
1159   my $form     = $main::form;
1160   my %myconfig = %main::myconfig;
1161   my $locale   = $main::locale;
1162
1163   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1164     unless $form->{subject};
1165
1166   RP->aging(\%myconfig, \%$form);
1167
1168   $form->{"statement_1"} = 1;
1169
1170   $form->{media} = 'email';
1171   print_form();
1172
1173   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1174
1175   $main::lxdebug->leave_sub();
1176 }
1177
1178 sub print {
1179   $main::lxdebug->enter_sub();
1180
1181   $main::auth->assert('general_ledger');
1182
1183   my $form     = $main::form;
1184   my %myconfig = %main::myconfig;
1185   my $locale   = $main::locale;
1186
1187   if ($form->{media} eq 'printer') {
1188     $form->error($locale->text('Select postscript or PDF!'))
1189       if ($form->{format} !~ /(postscript|pdf)/);
1190   }
1191
1192   my $selected = 0;
1193   for my $i (1 .. $form->{rowcount}) {
1194     if ($form->{"statement_$i"}) {
1195       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1196       $selected = 1;
1197       last;
1198     }
1199   }
1200
1201   $form->error($locale->text('Nothing selected!')) unless $selected;
1202
1203   if ($form->{media} eq 'printer') {
1204     $form->{"$form->{ct}_id"} = "";
1205   } else {
1206     $form->{"statement_1"} = 1;
1207   }
1208
1209   RP->aging(\%myconfig, \%$form);
1210
1211   print_form();
1212
1213   $form->redirect($locale->text('Statements sent to printer!'))
1214     if ($form->{media} eq 'printer');
1215
1216   $main::lxdebug->leave_sub();
1217 }
1218
1219 sub print_form {
1220   $main::lxdebug->enter_sub();
1221
1222   $main::auth->assert('general_ledger');
1223
1224   my $form     = $main::form;
1225   my %myconfig = %main::myconfig;
1226   my $locale   = $main::locale;
1227
1228   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1229
1230   $form->{templates} = "$myconfig{templates}";
1231
1232   my $suffix = "html";
1233   my $attachment_suffix = "html";
1234   if ($form->{format} eq 'postscript') {
1235     $form->{postscript} = 1;
1236     $suffix = "tex";
1237     $attachment_suffix = "ps";
1238   } elsif ($form->{format} eq 'pdf') {
1239     $form->{pdf} = 1;
1240     $suffix = "tex";
1241     $attachment_suffix = "pdf";
1242   }
1243
1244   $form->{IN}  = "$form->{type}.$suffix";
1245   $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1246
1247   # Save $form->{email} because it will be overwritten.
1248   $form->{EMAIL_RECIPIENT} = $form->{email};
1249
1250   my $i = 0;
1251   my $ctid;
1252   while (@{ $form->{AG} }) {
1253
1254     my $ref = shift @{ $form->{AG} };
1255
1256     if ($ctid != $ref->{ctid}) {
1257
1258       $ctid = $ref->{ctid};
1259       $i++;
1260
1261       if ($form->{"statement_$i"}) {
1262
1263         my @a =
1264           ("name", "street", "zipcode", "city", "country", "contact", "email",
1265            "$form->{ct}phone", "$form->{ct}fax");
1266         map { $form->{$_} = $ref->{$_} } @a;
1267
1268         $form->{ $form->{ct} } = $form->{name};
1269         $form->{"$form->{ct}_id"} = $ref->{ctid};
1270
1271         map { $form->{$_} = () } qw(invnumber invdate duedate amount open);
1272         $form->{total} = 0;
1273         foreach my $item (qw(c0 c30 c60 c90)) {
1274           $form->{$item} = ();
1275           $form->{"${item}total"} = 0;
1276         }
1277
1278         &statement_details($ref);
1279
1280         while ($ref) {
1281
1282           if (scalar(@{ $form->{AG} }) > 0) {
1283
1284             # one or more left to go
1285             if ($ctid == $form->{AG}->[0]->{ctid}) {
1286               $ref = shift @{ $form->{AG} };
1287               &statement_details($ref);
1288
1289               # any more?
1290               $ref = scalar(@{ $form->{AG} });
1291             } else {
1292               $ref = 0;
1293             }
1294           } else {
1295
1296             # set initial ref to 0
1297             $ref = 0;
1298           }
1299
1300         }
1301
1302         map {
1303           $form->{"${_}total"} =
1304             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1305         } ('c0', 'c30', 'c60', 'c90', "");
1306
1307         $form->{attachment_filename} =  $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
1308         $form->{attachment_filename} =~ s/\s+/_/g;
1309
1310         $form->parse_template(\%myconfig);
1311
1312       }
1313     }
1314   }
1315   # saving the history
1316   if(!exists $form->{addition} && $form->{id} ne "") {
1317     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1318     $form->{addition} = "PRINTED";
1319     $form->{what_done} = $form->{type};
1320     $form->save_history;
1321   }
1322   # /saving the history
1323   $main::lxdebug->leave_sub();
1324 }
1325
1326 sub statement_details {
1327   $main::lxdebug->enter_sub();
1328
1329   $main::auth->assert('general_ledger');
1330
1331   my $form     = $main::form;
1332   my %myconfig = %main::myconfig;
1333   my $locale   = $main::locale;
1334
1335   my ($ref) = @_;
1336
1337   push @{ $form->{invnumber} }, $ref->{invnumber};
1338   push @{ $form->{invdate} },   $ref->{transdate};
1339   push @{ $form->{duedate} },   $ref->{duedate};
1340   push @{ $form->{amount} },    $form->format_amount(\%myconfig, $ref->{amount} / $ref->{exchangerate}, 2);
1341   push @{ $form->{open} },      $form->format_amount(\%myconfig, $ref->{open} / $ref->{exchangerate}, 2);
1342
1343   foreach my $item (qw(c0 c30 c60 c90)) {
1344     if ($ref->{exchangerate} * 1) {
1345       # add only the open amount of the invoice to the aging, not the total amount
1346       $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} < 30 and $item eq 'c0';
1347       $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 30 and $ref->{overduedays} < 60 and $item eq 'c30';
1348       $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 60 and $ref->{overduedays} < 90 and $item eq 'c60';
1349       $ref->{"${item}"} = $form->round_amount($ref->{open} / $ref->{exchangerate}, 2) if $ref->{overduedays} >= 90 and $item eq 'c90';
1350     }
1351     $form->{"${item}total"} += $ref->{$item};
1352     $form->{total}          += $ref->{$item};
1353     push @{ $form->{$item} },
1354       $form->format_amount(\%myconfig, $ref->{$item}, 2);
1355   }
1356
1357   $main::lxdebug->leave_sub();
1358 }
1359
1360 sub generate_tax_report {
1361   $::lxdebug->enter_sub;
1362   $::auth->assert('report');
1363
1364   RP->tax_report(\%::myconfig, $::form);
1365
1366   my $descvar     = "$::form->{accno}_description";
1367   my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
1368
1369   # construct href
1370   my $href     =
1371   my $callback = build_std_url('action=generate_tax_report', $descvar,
1372     qw(fromdate todate db method accno department report title));
1373
1374   my @columns = $::form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1375   my @column_index;
1376
1377   for my $item (@columns, 'subtotal') {
1378     if ($::form->{"l_$item"} eq "Y") {
1379       $callback .= "&l_$item=Y";
1380       $href     .= "&l_$item=Y";
1381     }
1382   }
1383
1384   for my $item (@columns) {
1385     if ($::form->{"l_$item"} eq "Y") {
1386       push @column_index, $item;
1387     }
1388   }
1389
1390   my @options;
1391   if ($::form->{department}) {
1392     my ($department) = split /--/, $::form->{department};
1393     push @options, $::locale->text('Department') . " : $department";
1394   }
1395
1396   # if there are any dates
1397   if ($::form->{fromdate} || $::form->{todate}) {
1398     my $fromdate = $::form->{fromdate} ? $::locale->date(\%::myconfig, $::form->{fromdate}, 1) : '';
1399     my $todate   = $::form->{todate}   ? $::locale->date(\%::myconfig, $::form->{todate}, 1)   : '';
1400     push @options, "$fromdate - $todate";
1401   } else {
1402     push @options, $::locale->date(\%::myconfig, $::form->current_date, 1);
1403   }
1404
1405   my ($name, $invoice, $arap);
1406   if ($::form->{db} eq 'ar') {
1407     $name    = $::locale->text('Customer');
1408     $invoice = 'is.pl';
1409     $arap    = 'ar.pl';
1410   }
1411   if ($::form->{db} eq 'ap') {
1412     $name    = $::locale->text('Vendor');
1413     $invoice = 'ir.pl';
1414     $arap    = 'ap.pl';
1415   }
1416
1417   my %column_header = (
1418     id        => $::locale->text('ID'),
1419     invnumber => $::locale->text('Invoice'),
1420     transdate => $::locale->text('Date'),
1421     netamount => $::locale->text('Amount'),
1422     tax       => $::locale->text('Tax'),
1423     amount    => $::locale->text('Total'),
1424     name      => $name,
1425   );
1426
1427   my %column_sorted = map { $_ => 1 } qw(id invnumber transdate);
1428
1429   $callback .= "&sort=$::form->{sort}";
1430
1431   my $sameitem;
1432   if (@{ $::form->{TR} }) {
1433     $sameitem = $::form->{TR}->[0]->{ $::form->{sort} };
1434   }
1435
1436   my ($totalnetamount, $totaltax, @data);
1437   for my $ref (@{ $::form->{TR} }) {
1438
1439     my $module = ($ref->{invoice}) ? $invoice : $arap;
1440
1441     if ($::form->{l_subtotal} eq 'Y') {
1442       if ($sameitem ne $ref->{ $::form->{sort} }) {
1443         push @data, {
1444           subtotal  => 1,
1445           netamount => $subtotalnetamount,
1446           tax       => $subtotaltax,
1447           amount    => $subtotal,
1448         };
1449         $subtotalnetamount = 0;
1450         $subtotaltax       = 0;
1451         $sameitem          = $ref->{ $::form->{sort} };
1452       }
1453     }
1454
1455     $subtotalnetamount += $ref->{netamount};
1456     $subtotaltax       += $ref->{tax};
1457     $totalnetamount    += $ref->{netamount};
1458     $totaltax          += $ref->{tax};
1459     $ref->{amount}      = $ref->{netamount} + $ref->{tax};
1460
1461     push @data, { map { $_ => { data => $ref->{$_} } } keys %$ref };
1462     $data[-1]{invnumber}{link} = "$module?action=edit&id=$ref->{id}&callback=$callback";
1463     $data[-1]{$_}{numeric}     = 1 for qw(netamount tax amount);
1464   }
1465
1466   if ($::form->{l_subtotal} eq 'Y') {
1467     push @data, {
1468       subtotal  => 1,
1469       netamount => $subtotalnetamount,
1470       tax       => $subtotaltax,
1471       amount    => $subtotal,
1472     };
1473   }
1474
1475   push @data, {
1476     total     => 1,
1477     netamount => $totalnetamount,
1478     tax       => $totaltax,
1479     amount    => $totalnetamount + $totaltax,
1480   };
1481
1482   $::form->header;
1483   print $::form->parse_html_template('rp/tax_report', {
1484     column_index  => \@column_index,
1485     column_header => \%column_header,
1486     column_sorted => \%column_sorted,
1487     sort_base     => $href,
1488     DATA          => \@data,
1489     options       => \@options,
1490   });
1491
1492   $::lxdebug->leave_sub;
1493 }
1494
1495 sub list_payments {
1496   $main::lxdebug->enter_sub();
1497
1498   $main::auth->assert('cash');
1499
1500   my $form     = $main::form;
1501   my %myconfig = %main::myconfig;
1502   my $locale   = $main::locale;
1503
1504   if ($form->{account}) {
1505     ($form->{paymentaccounts}) = split /--/, $form->{account};
1506   }
1507
1508   my $option;
1509   if ($form->{department}) {
1510     (my $department, $form->{department_id}) = split /--/, $form->{department};
1511     $option = $locale->text('Department') . " : $department";
1512   }
1513
1514   report_generator_set_default_sort('transdate', 1);
1515
1516   RP->payments(\%myconfig, \%$form);
1517
1518   my @hidden_variables = qw(account title department reference source memo fromdate todate
1519                             fx_transaction db prepayment paymentaccounts sort);
1520
1521   my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
1522   $form->{callback} = $href;
1523
1524   my @columns     = qw(transdate invnumber name paid source memo);
1525   my %column_defs = (
1526     'name'      => { 'text' => $locale->text('Description'), },
1527     'invnumber' => { 'text' => $locale->text('Reference'), },
1528     'transdate' => { 'text' => $locale->text('Date'), },
1529     'paid'      => { 'text' => $locale->text('Amount'), },
1530     'source'    => { 'text' => $locale->text('Source'), },
1531     'memo'      => { 'text' => $locale->text('Memo'), },
1532   );
1533   my %column_alignment = ('paid' => 'right');
1534
1535   foreach my $name (grep { $_ ne 'paid' } @columns) {
1536     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1537     $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
1538   }
1539
1540   my @options;
1541   if ($form->{fromdate}) {
1542     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
1543   }
1544   if ($form->{todate}) {
1545     push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1546   }
1547
1548   my $report = SL::ReportGenerator->new(\%myconfig, $form);
1549
1550   my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
1551
1552   $report->set_options('top_info_text'         => join("\n", @options),
1553                        'output_format'         => 'HTML',
1554                        'title'                 => $form->{title},
1555                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
1556                        'std_column_visibility' => 1,
1557     );
1558   $report->set_options_from_form();
1559
1560   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1561
1562   $report->set_columns(%column_defs);
1563   $report->set_column_order(@columns);
1564
1565   $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
1566
1567   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1568
1569   my $total_paid    = 0;
1570
1571   foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
1572     next unless @{ $form->{ $ref->{id} } };
1573
1574     $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
1575
1576     my $subtotal_paid = 0;
1577
1578     foreach my $payment (@{ $form->{ $ref->{id} } }) {
1579       my $module = $payment->{module};
1580       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
1581       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
1582
1583       $subtotal_paid += $payment->{paid};
1584       $total_paid    += $payment->{paid};
1585
1586       $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
1587
1588       my $row = { };
1589
1590       foreach my $column (@columns) {
1591         $row->{$column} = {
1592           'data'  => $payment->{$column},
1593           'align' => $column_alignment{$column},
1594         };
1595       }
1596
1597       $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
1598
1599       $report->add_data($row);
1600     }
1601
1602     my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
1603     $row->{paid} = {
1604       'data'  => $form->format_amount(\%myconfig, $subtotal_paid, 2),
1605       'align' => 'right',
1606       'class' => 'listsubtotal',
1607     };
1608
1609     $report->add_data($row);
1610   }
1611
1612   $report->add_separator();
1613
1614   my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
1615   $row->{paid} = {
1616     'data'  => $form->format_amount(\%myconfig, $total_paid, 2),
1617     'align' => 'right',
1618     'class' => 'listtotal',
1619   };
1620
1621   $report->add_data($row);
1622
1623   $report->generate_with_headers();
1624
1625   $main::lxdebug->leave_sub();
1626 }
1627
1628 sub print_options {
1629   $::lxdebug->enter_sub;
1630
1631   my ($dont_print) = @_;
1632
1633   $::form->{sendmode} = "attachment";
1634   $::form->{format} ||= $::myconfig{template_format} || "pdf";
1635   $::form->{copies} ||= $::myconfig{copies}          || 2;
1636
1637   $::form->{PD}{ $::form->{type} }     = "selected";
1638   $::form->{DF}{ $::form->{format} }   = "selected";
1639   $::form->{OP}{ $::form->{media} }    = "selected";
1640   $::form->{SM}{ $::form->{sendmode} } = "selected";
1641
1642   my $output = $::form->parse_html_template('rp/print_options', {
1643     got_printer => $::myconfig{printer},
1644     show_latex  => $::lx_office_conf{print_templates}->{latex},
1645     is_email    => $::form->{media} eq 'email',
1646   });
1647
1648   print $output unless $dont_print;
1649
1650   $::lxdebug->leave_sub;
1651
1652   return $output;
1653 }
1654
1655 sub generate_bwa {
1656   $main::lxdebug->enter_sub();
1657
1658   $main::auth->assert('report');
1659
1660   my $form     = $main::form;
1661   my %myconfig = %main::myconfig;
1662   my $locale   = $main::locale;
1663
1664   $form->{padding} = "&nbsp;&nbsp;";
1665   $form->{bold}    = "<b>";
1666   $form->{endbold} = "</b>";
1667   $form->{br}      = "<br>";
1668
1669   if ($form->{reporttype} eq "custom") {
1670
1671     #forgotten the year --> thisyear
1672     if ($form->{year} !~ m/^\d\d\d\d$/) {
1673       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1674         /(\d\d\d\d)/;
1675       $form->{year} = $1;
1676     }
1677
1678     #yearly report
1679     if ($form->{duetyp} eq "13") {
1680       $form->{fromdate}        = "1.1.$form->{year}";
1681       $form->{todate}          = "31.12.$form->{year}";
1682       $form->{comparefromdate} = "1.01.$form->{year}";
1683       $form->{comparetodate}   = "31.12.$form->{year}";
1684     }
1685
1686     #Quater reports
1687     if ($form->{duetyp} eq "A") {
1688       $form->{fromdate}        = "1.1.$form->{year}";
1689       $form->{todate}          = "31.3.$form->{year}";
1690       $form->{comparefromdate} = "1.01.$form->{year}";
1691       $form->{comparetodate}   = "31.03.$form->{year}";
1692     }
1693     if ($form->{duetyp} eq "B") {
1694       $form->{fromdate}        = "1.4.$form->{year}";
1695       $form->{todate}          = "30.6.$form->{year}";
1696       $form->{comparefromdate} = "1.01.$form->{year}";
1697       $form->{comparetodate}   = "30.06.$form->{year}";
1698     }
1699     if ($form->{duetyp} eq "C") {
1700       $form->{fromdate}        = "1.7.$form->{year}";
1701       $form->{todate}          = "30.9.$form->{year}";
1702       $form->{comparefromdate} = "1.01.$form->{year}";
1703       $form->{comparetodate}   = "30.09.$form->{year}";
1704     }
1705     if ($form->{duetyp} eq "D") {
1706       $form->{fromdate}        = "1.10.$form->{year}";
1707       $form->{todate}          = "31.12.$form->{year}";
1708       $form->{comparefromdate} = "1.01.$form->{year}";
1709       $form->{comparetodate}   = "31.12.$form->{year}";
1710     }
1711
1712     #Monthly reports
1713   SWITCH: {
1714       $form->{duetyp} eq "1" && do {
1715         $form->{fromdate}        = "1.1.$form->{year}";
1716         $form->{todate}          = "31.1.$form->{year}";
1717         $form->{comparefromdate} = "1.01.$form->{year}";
1718         $form->{comparetodate}   = "31.01.$form->{year}";
1719         last SWITCH;
1720       };
1721       $form->{duetyp} eq "2" && do {
1722         $form->{fromdate} = "1.2.$form->{year}";
1723
1724         #this works from 1901 to 2099, 1900 and 2100 fail.
1725         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1726         $form->{todate}          = "$leap.2.$form->{year}";
1727         $form->{comparefromdate} = "1.01.$form->{year}";
1728         $form->{comparetodate}   = "$leap.02.$form->{year}";
1729         last SWITCH;
1730       };
1731       $form->{duetyp} eq "3" && do {
1732         $form->{fromdate}        = "1.3.$form->{year}";
1733         $form->{todate}          = "31.3.$form->{year}";
1734         $form->{comparefromdate} = "1.01.$form->{year}";
1735         $form->{comparetodate}   = "31.03.$form->{year}";
1736         last SWITCH;
1737       };
1738       $form->{duetyp} eq "4" && do {
1739         $form->{fromdate}        = "1.4.$form->{year}";
1740         $form->{todate}          = "30.4.$form->{year}";
1741         $form->{comparefromdate} = "1.01.$form->{year}";
1742         $form->{comparetodate}   = "30.04.$form->{year}";
1743         last SWITCH;
1744       };
1745       $form->{duetyp} eq "5" && do {
1746         $form->{fromdate}        = "1.5.$form->{year}";
1747         $form->{todate}          = "31.5.$form->{year}";
1748         $form->{comparefromdate} = "1.01.$form->{year}";
1749         $form->{comparetodate}   = "31.05.$form->{year}";
1750         last SWITCH;
1751       };
1752       $form->{duetyp} eq "6" && do {
1753         $form->{fromdate}        = "1.6.$form->{year}";
1754         $form->{todate}          = "30.6.$form->{year}";
1755         $form->{comparefromdate} = "1.01.$form->{year}";
1756         $form->{comparetodate}   = "30.06.$form->{year}";
1757         last SWITCH;
1758       };
1759       $form->{duetyp} eq "7" && do {
1760         $form->{fromdate}        = "1.7.$form->{year}";
1761         $form->{todate}          = "31.7.$form->{year}";
1762         $form->{comparefromdate} = "1.01.$form->{year}";
1763         $form->{comparetodate}   = "31.07.$form->{year}";
1764         last SWITCH;
1765       };
1766       $form->{duetyp} eq "8" && do {
1767         $form->{fromdate}        = "1.8.$form->{year}";
1768         $form->{todate}          = "31.8.$form->{year}";
1769         $form->{comparefromdate} = "1.01.$form->{year}";
1770         $form->{comparetodate}   = "31.08.$form->{year}";
1771         last SWITCH;
1772       };
1773       $form->{duetyp} eq "9" && do {
1774         $form->{fromdate}        = "1.9.$form->{year}";
1775         $form->{todate}          = "30.9.$form->{year}";
1776         $form->{comparefromdate} = "1.01.$form->{year}";
1777         $form->{comparetodate}   = "30.09.$form->{year}";
1778         last SWITCH;
1779       };
1780       $form->{duetyp} eq "10" && do {
1781         $form->{fromdate}        = "1.10.$form->{year}";
1782         $form->{todate}          = "31.10.$form->{year}";
1783         $form->{comparefromdate} = "1.01.$form->{year}";
1784         $form->{comparetodate}   = "31.10.$form->{year}";
1785         last SWITCH;
1786       };
1787       $form->{duetyp} eq "11" && do {
1788         $form->{fromdate}        = "1.11.$form->{year}";
1789         $form->{todate}          = "30.11.$form->{year}";
1790         $form->{comparefromdate} = "1.01.$form->{year}";
1791         $form->{comparetodate}   = "30.11.$form->{year}";
1792         last SWITCH;
1793       };
1794       $form->{duetyp} eq "12" && do {
1795         $form->{fromdate}        = "1.12.$form->{year}";
1796         $form->{todate}          = "31.12.$form->{year}";
1797         $form->{comparefromdate} = "1.01.$form->{year}";
1798         $form->{comparetodate}   = "31.12.$form->{year}";
1799         last SWITCH;
1800       };
1801     }
1802     hotfix_reformat_date();
1803   } else {
1804     # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
1805     # ansonsten ist die prüfung in RP.pm
1806     # if (defined ($form->{fromdate|todate}=='..'))
1807     # immer wahr
1808     if ($form->{fromdate}){
1809       my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
1810       my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
1811       $datetime->set( month      => 1,
1812                       day        => 1);
1813       $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
1814     }
1815     if ($form->{todate}){
1816       $form->{comparetodate}   = $form->{todate};
1817     }
1818   }
1819
1820   RP->bwa(\%myconfig, \%$form);
1821
1822   ($form->{department}) = split /--/, $form->{department};
1823
1824   $form->{period} =
1825     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1826   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1827
1828   # if there are any dates construct a where
1829   if ($form->{fromdate} || $form->{todate}) {
1830
1831     unless ($form->{todate}) {
1832       $form->{todate} = $form->current_date(\%myconfig);
1833     }
1834
1835     my %germandate = ("dateformat" => "dd.mm.yyyy");
1836
1837     my $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
1838     my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
1839
1840     my $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
1841     my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
1842
1843     $form->{this_period} = "$shortfromdate\n$shorttodate";
1844     $form->{period}      =
1845         $locale->text('for Period')
1846       . qq|\n$longfromdate |
1847       . $locale->text('bis')
1848       . qq| $longtodate|;
1849   }
1850
1851   # setup variables for the form
1852   my @a = qw(company address businessnumber);
1853   map { $form->{$_} = $myconfig{$_} } @a;
1854   $form->{templates} = $myconfig{templates};
1855
1856   $form->{IN} = "bwa.html";
1857
1858   $form->parse_template;
1859
1860   $main::lxdebug->leave_sub();
1861 }
1862 ###
1863 # Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
1864 # sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
1865 sub hotfix_reformat_date {
1866
1867   $main::lxdebug->enter_sub();
1868
1869   my $form     = $main::form;
1870   my %myconfig = %main::myconfig;
1871   my $locale   = $main::locale;
1872
1873   if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
1874     my $current_dateformat = $myconfig{dateformat};
1875     $myconfig{dateformat} = 'dd.mm.yyyy';
1876     $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
1877     $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
1878     $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
1879       unless (!defined ($form->{comparefromdate}));
1880     $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
1881       unless (!defined ($form->{comparetodate}));
1882
1883     # Und wieder zurücksetzen
1884     $myconfig{dateformat} =  $current_dateformat; #'dd.mm.yyyy';
1885   } # Ende Hotifx Bug 1388
1886
1887   $main::lxdebug->leave_sub();
1888
1889 }
1890 1;