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