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