Aufträge: Anzeige der gelieferten Menge mit der selben Einheit, die in der Zeile...
[kivitendo-erp.git] / bin / mozilla / ca.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) 2001
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # module for Chart of Accounts, Income Statement and Balance Sheet
31 # search and edit transactions posted by the GL, AR and AP
32 #
33 #======================================================================
34
35 use POSIX qw(strftime);
36
37 use SL::CA;
38 use SL::ReportGenerator;
39
40 require "bin/mozilla/reportgenerator.pl";
41
42 1;
43
44 # end of main
45
46 # this is for our long dates
47 # $locale->text('January')
48 # $locale->text('February')
49 # $locale->text('March')
50 # $locale->text('April')
51 # $locale->text('May ')
52 # $locale->text('June')
53 # $locale->text('July')
54 # $locale->text('August')
55 # $locale->text('September')
56 # $locale->text('October')
57 # $locale->text('November')
58 # $locale->text('December')
59
60 # this is for our short month
61 # $locale->text('Jan')
62 # $locale->text('Feb')
63 # $locale->text('Mar')
64 # $locale->text('Apr')
65 # $locale->text('May')
66 # $locale->text('Jun')
67 # $locale->text('Jul')
68 # $locale->text('Aug')
69 # $locale->text('Sep')
70 # $locale->text('Oct')
71 # $locale->text('Nov')
72 # $locale->text('Dec')
73
74 sub chart_of_accounts {
75   $lxdebug->enter_sub();
76
77   $auth->assert('report');
78
79   $form->{title} = $locale->text('Chart of Accounts');
80
81   CA->all_accounts(\%myconfig, \%$form);
82
83   my @columns     = qw(accno description debit credit);
84   my %column_defs = (
85     'accno'       => { 'text' => $locale->text('Account'), },
86     'description' => { 'text' => $locale->text('Description'), },
87     'debit'       => { 'text' => $locale->text('Debit'), },
88     'credit'      => { 'text' => $locale->text('Credit'), },
89   );
90
91   my $report = SL::ReportGenerator->new(\%myconfig, $form);
92
93   $report->set_options('output_format'         => 'HTML',
94                        'title'                 => $form->{title},
95                        'attachment_basename'   => $locale->text('chart_of_accounts') . strftime('_%Y%m%d', localtime time),
96                        'std_column_visibility' => 1,
97     );
98   $report->set_options_from_form();
99
100   $report->set_columns(%column_defs);
101   $report->set_column_order(@columns);
102
103   $report->set_export_options('chart_of_accounts');
104
105   $report->set_sort_indicator($form->{sort}, 1);
106
107   my %totals = ('debit' => 0, 'credit' => 0);
108
109   foreach my $ca (@{ $form->{CA} }) {
110     my $row = { };
111
112     foreach (qw(debit credit)) {
113       $totals{$_} += $ca->{$_} * 1;
114       $ca->{$_}    = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_});
115     }
116
117     map { $row->{$_} = { 'data' => $ca->{$_} } } @columns;
118
119     map { $row->{$_}->{align} = 'right'       } qw(debit credit);
120     map { $row->{$_}->{class} = 'listheading' } @columns if ($ca->{charttype} eq "H");
121
122     $row->{accno}->{link} = build_std_url('action=list', 'accno=' . E($ca->{accno}), 'description=' . E($ca->{description}));
123
124     $report->add_data($row);
125   }
126
127   my $row = { map { $_ => { 'class' => 'listtotal', 'align' => 'right' } } @columns };
128   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } qw(debit credit);
129
130   $report->add_separator();
131   $report->add_data($row);
132
133   $report->generate_with_headers();
134
135   $lxdebug->leave_sub();
136 }
137
138 sub list {
139   $lxdebug->enter_sub();
140
141   $auth->assert('report');
142
143   $form->{title} = $locale->text('List Transactions');
144   $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}";
145   $year = (localtime)[5] + 1900;
146
147   # get departments
148   $form->all_departments(\%myconfig);
149   if (@{ $form->{all_departments} }) {
150     $form->{selectdepartment} = "<option>\n";
151
152     map {
153       $form->{selectdepartment} .=
154         "<option>$_->{description}--$_->{id}\n"
155     } (@{ $form->{all_departments} });
156   }
157
158   $department = qq|
159         <tr>
160           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
161           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
162         </tr>
163 | if $form->{selectdepartment};
164   $accrual = ($eur) ? ""        : "checked";
165   $cash    = ($eur) ? "checked" : "";
166  
167   $name_1    = "fromdate";
168   $id_1      = "fromdate";
169   $value_1   = "$form->{fromdate}";
170   $trigger_1 = "trigger1";
171   $name_2    = "todate";
172   $id_2      = "todate";
173   $value_2   = "";
174   $trigger_2 = "trigger2";
175
176
177   # with JavaScript Calendar
178   if ($form->{jsscript}) {
179     if ($name_1 eq "") {
180
181       $button1 = qq|
182          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
183       $button1_2 = qq|
184         <input type=button name=$name_2 id="$trigger_2" value=|
185         . $locale->text('button') . qq|>|;
186
187       #write Trigger
188       $jsscript =
189         Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
190     } else {
191       $button1 = qq|
192          <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\" value="$value_1">|;
193       $button1_2 = qq|
194         <input type=button name=$name_1 id="$trigger_1" value=|
195         . $locale->text('button') . qq|>|;
196       $button2 = qq|
197          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
198       $button2_2 = qq|
199          <input type=button name=$name_2 id="$trigger_2" value=|
200         . $locale->text('button') . qq|>
201        |;
202
203       #write Trigger
204       $jsscript =
205         Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
206                             "$name_2", "BL", "$trigger_2");
207     }
208   } else {
209
210     # without JavaScript Calendar
211     if ($name_1 eq "") {
212       $button1 =
213         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
214     } else {
215       $button1 =
216         qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
217       $button2 =
218         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
219     }
220   }
221   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
222   $form->header;
223   $onload = qq|focus()|;
224   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
225   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
226
227
228   $form->header;
229
230   $form->{description} =~ s/\"/&quot;/g;
231
232   print qq|
233 <body onLoad="$onload">
234
235 <form method=post action=$form->{script}>
236
237 <input type=hidden name=accno value=$form->{accno}>
238 <input type=hidden name=description value="$form->{description}">
239 <input type=hidden name=sort value=transdate>
240 <input type=hidden name=eur value=$eur>
241 <input type=hidden name=accounttype value=$form->{accounttype}>
242
243 <table border=0 width=100%>
244   <tr>
245     <th class=listtop>$form->{title}</th>
246   </tr>
247
248 </table>
249 <table>
250         <tr>
251           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
252       . $locale->text('Customized Report') . qq|</th>
253         </tr>
254         <tr>
255           <th colspan=1>| . $locale->text('Year') . qq|</th>
256           <td><input name=year size=11 title="|
257       . $locale->text('YYYY') . qq|" value="$year"></td>
258         </tr>
259 |;
260
261     print qq|
262         <tr>
263                 <td align=right>
264 <b> | . $locale->text('Yearly') . qq|</b> </td>
265                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
266                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
267         </tr>
268         <tr>
269                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
270 $checked></td>
271                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
272       . $locale->text('Quarter') . qq|</td>
273 |;
274     $checked = "checked";
275     print qq|
276                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
277       . $locale->text('January') . qq|</td>
278 |;
279     $checked = "";
280     print qq|
281                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
282       . $locale->text('May') . qq|</td>
283                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
284       . $locale->text('September') . qq|</td>
285
286         </tr>
287         <tr>
288                 <td align= right>&nbsp;</td>
289                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
290       . $locale->text('Quarter') . qq|</td>
291                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
292       . $locale->text('February') . qq|</td>
293                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
294       . $locale->text('June') . qq|</td>
295                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
296       . $locale->text('October') . qq|</td>
297         </tr>
298         <tr>
299                 <td> &nbsp;</td>
300                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
301       . $locale->text('Quarter') . qq|</td>
302                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
303       . $locale->text('March') . qq|</td>
304                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
305       . $locale->text('July') . qq|</td>
306                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
307       . $locale->text('November') . qq|</td>
308
309         </tr>
310         <tr>
311                 <td> &nbsp;</td>
312                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
313       . $locale->text('Quarter') . qq|&nbsp;</td>
314                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
315       . $locale->text('April') . qq|</td>
316                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
317       . $locale->text('August') . qq|</td>
318                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
319       . $locale->text('December') . qq|</td>
320
321         </tr>
322         <tr>
323                 <td colspan=5><hr size=3 noshade></td>
324         </tr>
325         <tr>
326           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
327       . $locale->text('Free report period') . qq|</th>
328           <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
329               $button1
330               $button1_2&nbsp;
331               | . $locale->text('Bis') . qq|&nbsp;
332               $button2
333               $button2_2
334           </td>
335         </tr>
336         <tr>
337                 <td colspan=5><hr size=3 noshade></td>
338         </tr>
339         <tr>
340           <th align=leftt>| . $locale->text('Method') . qq|</th>
341           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
342       . $locale->text('Accrual') . qq|
343           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
344       . $locale->text('EUR') . qq|</td>
345         </tr>
346         <tr>
347          <th align=right colspan=4>|
348       . $locale->text('Decimalplaces')
349       . qq|</th>
350              <td><input name=decimalplaces size=3 value="2"></td>
351          </tr>
352          <tr>
353             <td><input name="subtotal" class=checkbox type=checkbox value=1> | . $locale->text('Subtotal') . qq|</td>
354          </tr>
355                                     
356 $jsscript
357   <tr><td colspan=5 ><hr size=3 noshade></td></tr>
358 </table>
359
360 <br><input class=submit type=submit name=action value="|
361     . $locale->text('List Transactions') . qq|">
362 </form>
363
364 </body>
365 </html>
366 |;
367
368   $lxdebug->leave_sub();
369 }
370
371 sub list_transactions {
372   $lxdebug->enter_sub();
373
374   $auth->assert('report');
375
376   $form->{title} = $locale->text('Account') . " $form->{accno} - $form->{description}";
377
378   if ($form->{reporttype} eq "custom") {
379
380     #forgotten the year --> thisyear
381     if ($form->{year} !~ m/^\d\d\d\d$/) {
382       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
383         /(\d\d\d\d)/;
384       $form->{year} = $1;
385     }
386
387     #yearly report
388     if ($form->{duetyp} eq "13") {
389       $form->{fromdate} = "1.1.$form->{year}";
390       $form->{todate}   = "31.12.$form->{year}";
391     }
392
393     #Quater reports
394     if ($form->{duetyp} eq "A") {
395       $form->{fromdate} = "1.1.$form->{year}";
396       $form->{todate}   = "31.3.$form->{year}";
397     }
398     if ($form->{duetyp} eq "B") {
399       $form->{fromdate} = "1.4.$form->{year}";
400       $form->{todate}   = "30.6.$form->{year}";
401     }
402     if ($form->{duetyp} eq "C") {
403       $form->{fromdate} = "1.7.$form->{year}";
404       $form->{todate}   = "30.9.$form->{year}";
405     }
406     if ($form->{duetyp} eq "D") {
407       $form->{fromdate} = "1.10.$form->{year}";
408       $form->{todate}   = "31.12.$form->{year}";
409     }
410
411     #Monthly reports
412   SWITCH: {
413       $form->{duetyp} eq "1" && do {
414         $form->{fromdate} = "1.1.$form->{year}";
415         $form->{todate}   = "31.1.$form->{year}";
416         last SWITCH;
417       };
418       $form->{duetyp} eq "2" && do {
419         $form->{fromdate} = "1.2.$form->{year}";
420
421         #this works from 1901 to 2099, 1900 and 2100 fail.
422         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
423         $form->{todate} = "$leap.2.$form->{year}";
424         last SWITCH;
425       };
426       $form->{duetyp} eq "3" && do {
427         $form->{fromdate} = "1.3.$form->{year}";
428         $form->{todate}   = "31.3.$form->{year}";
429         last SWITCH;
430       };
431       $form->{duetyp} eq "4" && do {
432         $form->{fromdate} = "1.4.$form->{year}";
433         $form->{todate}   = "30.4.$form->{year}";
434         last SWITCH;
435       };
436       $form->{duetyp} eq "5" && do {
437         $form->{fromdate} = "1.5.$form->{year}";
438         $form->{todate}   = "31.5.$form->{year}";
439         last SWITCH;
440       };
441       $form->{duetyp} eq "6" && do {
442         $form->{fromdate} = "1.6.$form->{year}";
443         $form->{todate}   = "30.6.$form->{year}";
444         last SWITCH;
445       };
446       $form->{duetyp} eq "7" && do {
447         $form->{fromdate} = "1.7.$form->{year}";
448         $form->{todate}   = "31.7.$form->{year}";
449         last SWITCH;
450       };
451       $form->{duetyp} eq "8" && do {
452         $form->{fromdate} = "1.8.$form->{year}";
453         $form->{todate}   = "31.8.$form->{year}";
454         last SWITCH;
455       };
456       $form->{duetyp} eq "9" && do {
457         $form->{fromdate} = "1.9.$form->{year}";
458         $form->{todate}   = "30.9.$form->{year}";
459         last SWITCH;
460       };
461       $form->{duetyp} eq "10" && do {
462         $form->{fromdate} = "1.10.$form->{year}";
463         $form->{todate}   = "31.10.$form->{year}";
464         last SWITCH;
465       };
466       $form->{duetyp} eq "11" && do {
467         $form->{fromdate} = "1.11.$form->{year}";
468         $form->{todate}   = "30.11.$form->{year}";
469         last SWITCH;
470       };
471       $form->{duetyp} eq "12" && do {
472         $form->{fromdate} = "1.12.$form->{year}";
473         $form->{todate}   = "31.12.$form->{year}";
474         last SWITCH;
475       };
476     }
477   }
478
479   CA->all_transactions(\%myconfig, \%$form);
480
481
482   my $saldo_old = ($form->{saldo_old} > 0) ? $form->format_amount(\%myconfig, $form->{saldo_old}, 2) . " H" : $form->format_amount(\%myconfig, abs($form->{saldo_old}) , 2) . " S";
483
484   my $eb_string = ($form->{beginning_balance} > 0) ? $form->format_amount(\%myconfig, $form->{beginning_balance}, 2) . " H" : $form->format_amount(\%myconfig, abs($form->{beginning_balance}), 2) . " S";
485
486   my @options;
487   if ($form->{department}) {
488     my ($department) = split /--/, $form->{department};
489     push @options, $locale->text('Department') . " : $department";
490   }
491   if ($form->{projectnumber}) {
492     push @options, $locale->text('Project Number') . " : $form->{projectnumber}<br>";
493   }
494
495   my $period;
496   if ($form->{fromdate} || $form->{todate}) {
497     my ($fromdate, $todate);
498
499     if ($form->{fromdate}) {
500       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
501     }
502     if ($form->{todate}) {
503       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
504     }
505
506     $period = "$fromdate - $todate";
507
508   } else {
509     $period = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
510   }
511
512   push @options, $period;
513
514   my @columns     = qw(transdate reference description gegenkonto debit credit ustkonto ustrate);
515   my %column_defs = (
516     'transdate'   => { 'text' => $locale->text('Date'), },
517     'reference'   => { 'text' => $locale->text('Reference'), },
518     'description' => { 'text' => $locale->text('Description'), },
519     'debit'       => { 'text' => $locale->text('Debit'), },
520     'credit'      => { 'text' => $locale->text('Credit'), },
521     'gegenkonto'     => { 'text' => $locale->text('Gegenkonto'), },
522     'ustkonto'     => { 'text' => $locale->text('USt-Konto'), },
523      'ustrate'     => { 'text' => $locale->text('Satz %'), },
524  );
525
526   my @hidden_variables = qw(accno fromdate todate description accounttype l_heading subtotal department projectnumber project_id sort);
527
528   my $link = build_std_url('action=list_transactions', grep { $form->{$_} } @hidden_variables);
529
530   $form->{callback} = $link . '&sort=' . E($form->{sort});
531
532   my %column_alignment = map { $_ => 'right' } qw(debit credit);
533
534   @custom_headers = ();
535  # Zeile 1:
536  push @custom_headers, [
537    { 'text' => 'Letzte Buchung', },
538    { 'text' => 'EB-Wert', },
539    { 'text' => 'Saldo alt', 'colspan' => 2, },
540    { 'text' => 'Jahresverkehrszahlen alt', 'colspan' => 2, },
541    { 'text' => '', 'colspan' => 2, },
542  ];
543  push @custom_headers, [
544    { 'text' => $form->{last_transaction}, },
545    { 'text' => $eb_string, },
546    { 'text' => $saldo_old, 'colspan' => 2, },
547    { 'text' => $form->format_amount(\%myconfig, abs($form->{old_balance_debit}), 2) . " S", },
548    { 'text' => $form->format_amount(\%myconfig, $form->{old_balance_credit}, 2) . " H", },
549    { 'text' => '', 'colspan' => 2, },
550  ];
551  # Zeile 2:
552  push @custom_headers, [
553    { 'text' => $locale->text('Date'), 'link' => $link . "&sort=transdate", },
554    { 'text' => $locale->text('Reference'), 'link' => $link . "&sort=reference",  },
555    { 'text' => $locale->text('Description'), 'link' => $link . "&sort=description",  },
556    { 'text' => $locale->text('Gegenkonto'), },
557    { 'text' => $locale->text('Debit'), },
558    { 'text' => $locale->text('Credit'), },
559    { 'text' => $locale->text('USt-Konto'), },
560    { 'text' => $locale->text('Satz %'), },
561  ];
562
563
564
565
566
567   my $report = SL::ReportGenerator->new(\%myconfig, $form);
568   $report->set_custom_headers(@custom_headers);
569
570   $report->set_options('top_info_text'         => join("\n", @options),
571                        'output_format'         => 'HTML',
572                        'title'                 => $form->{title},
573                        'attachment_basename'   => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
574                        'std_column_visibility' => 1,
575     );
576   $report->set_options_from_form();
577
578   $report->set_columns(%column_defs);
579   $report->set_column_order(@columns);
580
581   $report->set_export_options('list_transactions', @hidden_variables);
582
583   $report->set_sort_indicator($form->{sort}, 1);
584
585   $column_defs->{balance}->{visible} = $form->{accno} ? 1 : 0;
586
587   my $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
588
589
590   my $idx       = 0;
591   my %totals    = ( 'debit' => 0, 'credit' => 0 );
592   my %subtotals = ( 'debit' => 0, 'credit' => 0 );
593   my ($previous_index, $row_set);
594
595   foreach my $ca (@{ $form->{CA} }) {
596
597     foreach (qw(debit credit)) {
598       $subtotals{$_} += $ca->{$_};
599       $totals{$_}    += $ca->{$_};
600       $ca->{$_}       = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_} != 0);
601     }
602
603     my $do_subtotal = 0;
604     if (($form->{subtotal})
605         && (($idx == scalar @{ $form->{CA} } - 1)
606             || ($ca->{$form->{sort}} ne $form->{CA}->[$idx + 1]->{$form->{sort}}))) {
607       $do_subtotal = 1;
608     }
609
610     my $row = { };
611
612     $ca->{ustrate} = $form->format_amount(\%myconfig, $ca->{ustrate} * 100, 2) if ($ca->{ustrate} != 0);
613
614     if ($ca->{memo} ne "") {
615       $ca->{description} .= " \n " . $ca->{memo};
616     }
617
618     
619
620     foreach my $gegenkonto (@{ $ca->{GEGENKONTO} }) {
621       if ($ca->{gegenkonto} eq "") {
622         $ca->{gegenkonto} = $gegenkonto->{accno};
623       } else {
624         $ca->{gegenkonto} .= ", " . $gegenkonto->{accno};
625       }
626     }
627
628     foreach (@columns) {
629       $row->{$_} = {
630         'data'  => $ca->{$_},
631         'align' => $column_alignment{$_},
632       };
633     }
634
635     if ($ca->{index} ne $previous_index) {
636 #       $report->add_data($row_set) if ($row_set);
637
638 #       $row_set         = [ ];
639       $previous_index  = $ca->{index};
640
641       $row->{reference}->{link} = build_std_url("script=$ca->{module}.pl", 'action=edit', 'id=' . E($ca->{id}), 'callback');
642
643     } elsif ($ca->{index} eq $previous_index) {
644       map { $row->{$_}->{data} = '' } qw(reference description);
645       $row->{transdate}->{data} = '' if ($form->{sort} eq 'transdate');
646     }
647
648     my $row_set = [];
649
650     push @{ $row_set }, $row;
651
652     push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, 'listsubtotal') if ($do_subtotal);
653
654
655     $idx++;
656     $report->add_data($row_set);
657
658   }
659
660   $report->add_data($row_set) if ($row_set);
661
662   $report->add_separator();
663
664   my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, 'listtotal');
665   $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance} * $ml, 2);
666   $report->add_data($row);
667
668
669   $report->add_separator();
670   my $row = {
671      'transdate' => {
672        'data'    => "",
673        'class' => 'listtotal',
674      },
675      'reference' => {
676        'data'    => $locale->text('EB-Wert'),
677        'class' => 'listtotal',
678      },
679      'description'      => {
680        'data'    => $locale->text('Saldo neu'),
681        'colspan' => 2,
682        'class' => 'listtotal',
683      },
684      'debit'      => {
685        'data'    => $locale->text('Jahresverkehrszahlen neu'),
686        'colspan' => 2,
687        'align' => 'left',
688        'class' => 'listtotal',
689     },
690      'ustkonto'      => {
691        'data'    => '',
692        'colspan' => 2,
693        'align' => 'left',
694        'class' => 'listtotal',
695     },
696   };
697
698   $report->add_data($row);
699   my $saldo_new = ($form->{saldo_new} > 0) ? $form->format_amount(\%myconfig, $form->{saldo_new}, 2) . " H" : $form->format_amount(\%myconfig, abs($form->{saldo_new}) , 2) . " S";
700   my $row = {
701      'transdate' => {
702        'data'    => "",
703        'class' => 'listtotal',
704      },
705      'reference' => {
706        'data'    => $eb_string,
707        'class' => 'listtotal',
708      },
709      'description'      => {
710        'data'    => $saldo_new,
711        'colspan' => 2,
712        'class' => 'listtotal',
713      },
714      'debit'      => {
715        'data'    => $form->format_amount(\%myconfig, abs($form->{current_balance_debit}) , 2) . " S",
716        'class' => 'listtotal',
717      },
718       'credit'      => {
719        'data'    => $form->format_amount(\%myconfig, $form->{current_balance_credit}, 2) . " H",
720        'class' => 'listtotal',
721      },
722       'ustkonto'      => {
723        'data'    => "",
724        'colspan' => 2,
725        'class' => 'listtotal',
726      },
727   };
728
729   $report->add_data($row);
730
731   $report->generate_with_headers();
732
733   $lxdebug->leave_sub();
734 }
735
736 sub create_subtotal_row {
737   $lxdebug->enter_sub();
738
739   my ($totals, $columns, $column_alignment, $class) = @_;
740
741   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
742
743   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } qw(credit debit);
744
745   map { $totals->{$_} = 0 } qw(debit credit);
746
747   $lxdebug->leave_sub();
748
749   return $row;
750 }