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