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