Einige Browser (Opera) mögen es nicht, wenn "checked" bei Checkboxen in Anführungszei...
[kivitendo-erp.git] / bin / mozilla / rp.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors: Antonio Gallardo <agssa@ibw.com.ni>
16 #                Benjamin Lee <benjaminlee@consultant.com>
17 #                Philip Reetz <p.reetz@linet-services.de>
18 #                Udo Spallek
19 #
20 # This program is free software; you can redistribute it and/or modify
21 # it under the terms of the GNU General Public License as published by
22 # the Free Software Foundation; either version 2 of the License, or
23 # (at your option) any later version.
24 #
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #======================================================================
33 #
34 # module for preparing Income Statement and Balance Sheet
35 #
36 #======================================================================
37
38 use POSIX qw(strftime);
39
40 use SL::PE;
41 use SL::RP;
42 use SL::USTVA;
43 use SL::Iconv;
44 use SL::ReportGenerator;
45
46 require "bin/mozilla/arap.pl";
47 require "bin/mozilla/common.pl";
48 require "bin/mozilla/reportgenerator.pl";
49
50 1;
51
52 # end of main
53
54 # this is for our long dates
55 # $locale->text('January')
56 # $locale->text('February')
57 # $locale->text('March')
58 # $locale->text('April')
59 # $locale->text('May ')
60 # $locale->text('June')
61 # $locale->text('July')
62 # $locale->text('August')
63 # $locale->text('September')
64 # $locale->text('October')
65 # $locale->text('November')
66 # $locale->text('December')
67
68 # this is for our short month
69 # $locale->text('Jan')
70 # $locale->text('Feb')
71 # $locale->text('Mar')
72 # $locale->text('Apr')
73 # $locale->text('May')
74 # $locale->text('Jun')
75 # $locale->text('Jul')
76 # $locale->text('Aug')
77 # $locale->text('Sep')
78 # $locale->text('Oct')
79 # $locale->text('Nov')
80 # $locale->text('Dec')
81
82 # $locale->text('Balance Sheet')
83 # $locale->text('Income Statement')
84 # $locale->text('Trial Balance')
85 # $locale->text('AR Aging')
86 # $locale->text('AP Aging')
87 # $locale->text('Tax collected')
88 # $locale->text('Tax paid')
89 # $locale->text('Receipts')
90 # $locale->text('Payments')
91 # $locale->text('Project Transactions')
92 # $locale->text('Non-taxable Sales')
93 # $locale->text('Non-taxable Purchases')
94
95 sub report {
96   $lxdebug->enter_sub();
97
98   %title = ('balance_sheet'        => 'Balance Sheet',
99             'income_statement'     => 'Income Statement',
100             'trial_balance'        => 'Trial Balance',
101             'ar_aging'             => 'AR Aging',
102             'ap_aging'             => 'Offene Verbindlichkeiten',
103             'tax_collected'        => 'Tax collected',
104             'tax_paid'             => 'Tax paid',
105             'nontaxable_sales'     => 'Non-taxable Sales',
106             'nontaxable_purchases' => 'Non-taxable Purchases',
107             'receipts'             => 'Receipts',
108             'payments'             => 'Payments',
109             'projects'             => 'Project Transactions',
110             'bwa'                  => 'Betriebswirtschaftliche Auswertung',
111             'ustva'                => 'Umsatzsteuervoranmeldung',);
112
113   $form->{title} = $locale->text($title{ $form->{report} });
114
115   $accrual = ($eur) ? ""        : "checked";
116   $cash    = ($eur) ? "checked" : "";
117
118   $year = (localtime)[5] + 1900;
119
120   # get departments
121   $form->all_departments(\%myconfig);
122   if (@{ $form->{all_departments} }) {
123     $form->{selectdepartment} = "<option>\n";
124
125     map {
126       $form->{selectdepartment} .=
127         "<option>$_->{description}--$_->{id}\n"
128     } (@{ $form->{all_departments} });
129   }
130
131   $department = qq|
132         <tr>
133           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
134           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
135         </tr>
136 | if $form->{selectdepartment};
137
138   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
139                                    "all" => 1 });
140
141   my %project_labels = ();
142   my @project_values = ("");
143   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
144     push(@project_values, $item->{"id"});
145     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
146   }
147
148   my $projectnumber =
149     NTI($cgi->popup_menu('-name' => "project_id",
150                          '-values' => \@project_values,
151                          '-labels' => \%project_labels));
152
153   # use JavaScript Calendar or not
154   $form->{jsscript} = 1;
155   $jsscript = "";
156   if ($form->{report} eq "ustva") {
157     $department = "";
158   } else {
159     if ($form->{report} eq "balance_sheet") {
160       $name_1    = "asofdate";
161       $id_1      = "asofdate";
162       $value_1   = "$form->{asofdate}";
163       $trigger_1 = "trigger1";
164       $name_2    = "compareasofdate";
165       $id_2      = "compareasofdate";
166       $value_2   = "$form->{compareasofdate}";
167       $trigger_2 = "trigger2";
168     } elsif ($form->{report} =~ /(receipts|payments)$/) {
169       $name_1    = "fromdate";
170       $id_1      = "fromdate";
171       $value_1   = "$form->{fromdate}";
172       $trigger_1 = "trigger1";
173       $name_2    = "todate";
174       $id_2      = "todate";
175       $value_2   = "";
176       $trigger_2 = "trigger2";
177     } else {
178       if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
179         $name_1    = "";
180         $id_1      = "";
181         $value_1   = "";
182         $trigger_1 = "";
183         $name_2    = "todate";
184         $id_2      = "todate";
185         $value_2   = "";
186         $trigger_2 = "trigger2";
187
188       } else {
189         $name_1    = "fromdate";
190         $id_1      = "fromdate";
191         $value_1   = "$form->{fromdate}";
192         $trigger_1 = "trigger1";
193         $name_2    = "todate";
194         $id_2      = "todate";
195         $value_2   = "";
196         $trigger_2 = "trigger2";
197       }
198     }
199   }
200
201   # with JavaScript Calendar
202   if ($form->{jsscript}) {
203     if ($name_1 eq "") {
204
205       $button1 = qq|
206          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
207       $button1_2 = qq|
208         <input type=button name=$name_2 id="$trigger_2" value=|
209         . $locale->text('button') . qq|>|;
210
211       #write Trigger
212       $jsscript =
213         Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
214     } else {
215       $button1 = qq|
216          <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
217       $button1_2 = qq|
218         <input type=button name=$name_1 id="$trigger_1" value=|
219         . $locale->text('button') . qq|>|;
220       $button2 = qq|
221          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
222       $button2_2 = qq|
223          <input type=button name=$name_2 id="$trigger_2" value=|
224         . $locale->text('button') . qq|>
225        |;
226
227       #write Trigger
228       $jsscript =
229         Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
230                             "$name_2", "BL", "$trigger_2");
231     }
232   } else {
233
234     # without JavaScript Calendar
235     if ($name_1 eq "") {
236       $button1 =
237         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
238     } else {
239       $button1 =
240         qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
241       $button2 =
242         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
243     }
244   }
245   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
246   $form->header;
247   $onload = qq|focus()|;
248   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
249   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
250   print qq|
251 <body onLoad="$onload">
252
253 <form method=post action=$form->{script}>
254
255 <input type=hidden name=title value="$form->{title}">
256
257 <table width=100%>
258   <tr>
259     <th class=listtop>$form->{title}</th>
260   </tr>
261   <tr height="5"></tr>
262   <tr>
263     <td>
264       <table>
265       $department
266 |;
267
268   if ($form->{report} eq "projects") {
269     print qq|
270         <tr>
271           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
272           <td colspan=5><input name=projectnumber size=25</td>
273         </tr>
274         <input type=hidden name=nextsub value=generate_projects>
275         <tr>
276           <th align=right>| . $locale->text('From') . qq|</th>
277           <td>$button1</td>
278           <td>$button1_2</td>
279           <th align=right>| . $locale->text('Bis') . qq|</th>
280           <td>$button2</td>
281           <td>$button2_2</td>
282         </tr>
283       </table>
284     </td>
285   </tr>
286   <tr>
287     <td>
288       <table>
289         <tr>
290           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
291           <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
292       . $locale->text('Heading') . qq|
293           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
294       . $locale->text('Subtotal') . qq|</td>
295         </tr>
296
297 $jsscript
298 |;
299   }
300
301   if ($form->{report} eq "income_statement") {
302     print qq|
303         <tr>
304           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
305           <td colspan=3>$projectnumber</td>
306         </tr>
307         <input type=hidden name=nextsub value=generate_income_statement>
308 </table>
309 <table>
310         <tr>
311           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
312       . $locale->text('Customized Report') . qq|</th>
313         </tr>
314         <tr>
315           <th colspan=1>| . $locale->text('Year') . qq|</th>
316           <td><input name=year size=11 title="|
317       . $locale->text('YYYY') . qq|" value="$year"></td>
318         </tr>
319 |;
320
321     print qq|
322         <tr>
323                 <td align=right>
324 <b> | . $locale->text('Yearly') . qq|</b> </td>
325                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
326                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
327         </tr>
328         <tr>
329                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
330 "checked"></td>
331                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
332       . $locale->text('Quarter') . qq|</td>
333 |;
334     $checked = "";
335     print qq|
336                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
337       . $locale->text('January') . qq|</td>
338 |;
339     $checked = "";
340     print qq|
341                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
342       . $locale->text('May') . qq|</td>
343                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
344       . $locale->text('September') . qq|</td>
345
346         </tr>
347         <tr>
348                 <td align= right>&nbsp;</td>
349                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
350       . $locale->text('Quarter') . qq|</td>
351                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
352       . $locale->text('February') . qq|</td>
353                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
354       . $locale->text('June') . qq|</td>
355                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
356       . $locale->text('October') . qq|</td>
357         </tr>
358         <tr>
359                 <td> &nbsp;</td>
360                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
361       . $locale->text('Quarter') . qq|</td>
362                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
363       . $locale->text('March') . qq|</td>
364                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
365       . $locale->text('July') . qq|</td>
366                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
367       . $locale->text('November') . qq|</td>
368
369         </tr>
370         <tr>
371                 <td> &nbsp;</td>
372                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
373       . $locale->text('Quarter') . qq|&nbsp;</td>
374                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
375       . $locale->text('April') . qq|</td>
376                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
377       . $locale->text('August') . qq|</td>
378                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
379       . $locale->text('December') . qq|</td>
380
381         </tr>
382         <tr>
383                 <td colspan=5><hr size=3 noshade></td>
384         </tr>
385         <tr>
386           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
387       . $locale->text('Free report period') . qq|</th>
388           <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
389               $button1
390               $button1_2&nbsp;
391               | . $locale->text('Bis') . qq|
392               $button2
393               $button2_2&nbsp;
394           </td>
395         </tr>
396         <tr>
397                 <td colspan=5><hr size=3 noshade></td>
398         </tr>
399         <tr>
400           <th align=leftt>| . $locale->text('Method') . qq|</th>
401           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
402       . $locale->text('Accrual') . qq|
403           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
404       . $locale->text('EUR') . qq|</td>
405         </tr>
406
407 $jsscript
408 |;
409   }
410
411   if ($form->{report} eq "bwa") {
412     print qq|
413         <tr>
414           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
415           <td colspan=3>$projectnumber</td>
416         </tr>
417         <input type=hidden name=nextsub value=generate_bwa>
418 </table>
419 <table>
420         <tr>
421           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
422       . $locale->text('Customized Report') . qq|</th>
423         </tr>
424         <tr>
425           <th colspan=1>| . $locale->text('Year') . qq|</th>
426           <td><input name=year size=11 title="|
427       . $locale->text('YYYY') . qq|" value="$year"></td>
428         </tr>
429 |;
430
431     print qq|
432         <tr>
433                 <td align=right>
434 <b> | . $locale->text('Yearly') . qq|</b> </td>
435                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
436                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
437         </tr>
438         <tr>
439                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
440 $checked></td>
441                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
442       . $locale->text('Quarter') . qq|</td>
443 |;
444     $checked = "checked";
445     print qq|
446                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
447       . $locale->text('January') . qq|</td>
448 |;
449     $checked = "";
450     print qq|
451                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
452       . $locale->text('May') . qq|</td>
453                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
454       . $locale->text('September') . qq|</td>
455
456         </tr>
457         <tr>
458                 <td align= right>&nbsp;</td>
459                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
460       . $locale->text('Quarter') . qq|</td>
461                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
462       . $locale->text('February') . qq|</td>
463                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
464       . $locale->text('June') . qq|</td>
465                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
466       . $locale->text('October') . qq|</td>
467         </tr>
468         <tr>
469                 <td> &nbsp;</td>
470                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
471       . $locale->text('Quarter') . qq|</td>
472                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
473       . $locale->text('March') . qq|</td>
474                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
475       . $locale->text('July') . qq|</td>
476                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
477       . $locale->text('November') . qq|</td>
478
479         </tr>
480         <tr>
481                 <td> &nbsp;</td>
482                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
483       . $locale->text('Quarter') . qq|&nbsp;</td>
484                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
485       . $locale->text('April') . qq|</td>
486                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
487       . $locale->text('August') . qq|</td>
488                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
489       . $locale->text('December') . qq|</td>
490
491         </tr>
492         <tr>
493                 <td colspan=5><hr size=3 noshade></td>
494         </tr>
495         <tr>
496           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
497       . $locale->text('Free report period') . qq|</th>
498           <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
499               $button1
500               $button1_2&nbsp;
501               | . $locale->text('Bis') . qq|&nbsp;
502               $button2
503               $button2_2
504           </td>
505         </tr>
506         <tr>
507                 <td colspan=5><hr size=3 noshade></td>
508         </tr>
509         <tr>
510           <th align=leftt>| . $locale->text('Method') . qq|</th>
511           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
512       . $locale->text('Accrual') . qq|
513           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
514       . $locale->text('EUR') . qq|</td>
515         </tr>
516         <tr>
517          <th align=right colspan=4>|
518       . $locale->text('Decimalplaces')
519       . qq|</th>
520              <td><input name=decimalplaces size=3 value="2"></td>
521          </tr>
522                                     
523 $jsscript
524 |;
525   }
526
527   if ($form->{report} eq "ustva") {
528
529     print qq|
530
531         <br>
532         <input type=hidden name=nextsub value=generate_ustva>
533 </table>
534 <table>
535         <tr>
536           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
537       . $locale->text('Zeitraum') . qq|</th>
538         </tr>
539         <tr>
540           <th colspan=1>| . $locale->text('Year') . qq|</th>
541           <td><input name=year size=11 title="|
542       . $locale->text('YYYY') . qq|" value="$year"></td>
543         </tr>
544 |;
545
546     print qq|
547         <tr>
548                 <td align=right>
549 <b> | . $locale->text('Yearly') . qq|</b> </td>
550                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
551                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
552         </tr>
553         <tr>
554                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
555 $checked></td>
556                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
557       . $locale->text('Quarter') . qq|</td>
558 |;
559     $checked = "checked";
560     print qq|
561                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
562       . $locale->text('January') . qq|</td>
563 |;
564     $checked = "";
565     print qq|
566                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
567       . $locale->text('May') . qq|</td>
568                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
569       . $locale->text('September') . qq|</td>
570
571         </tr>
572         <tr>
573                 <td align= right>&nbsp;</td>
574                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
575       . $locale->text('Quarter') . qq|</td>
576                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
577       . $locale->text('February') . qq|</td>
578                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
579       . $locale->text('June') . qq|</td>
580                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
581       . $locale->text('October') . qq|</td>
582         </tr>
583         <tr>
584                 <td> &nbsp;</td>
585                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
586       . $locale->text('Quarter') . qq|</td>
587                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
588       . $locale->text('March') . qq|</td>
589                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
590       . $locale->text('July') . qq|</td>
591                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
592       . $locale->text('November') . qq|</td>
593
594         </tr>
595         <tr>
596                 <td> &nbsp;</td>
597                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
598       . $locale->text('Quarter') . qq|&nbsp;</td>
599                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
600       . $locale->text('April') . qq|</td>
601                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
602       . $locale->text('August') . qq|</td>
603                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
604       . $locale->text('December') . qq|</td>
605
606         </tr>
607         <tr>
608                 <td colspan=5><hr size=3 noshade></td>
609         </tr>
610         <tr>
611           <th align=left>| . $locale->text('Method') . qq|</th>
612           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
613       . $locale->text('Accrual') . qq|
614           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
615       . $locale->text('EUR') . qq|</td>
616         </tr>
617         <tr>
618           <th colspan=4>|;
619 ##########
620
621     &print_options();
622     print qq|
623           </th>
624         </tr>
625 |;
626   }
627
628   if ($form->{report} eq "balance_sheet") {
629     print qq|
630         <input type=hidden name=nextsub value=generate_balance_sheet>
631         <tr>
632           <th align=right>| . $locale->text('as at') . qq|</th>
633           <td>
634             $button1
635             $button1_2
636           </td>
637           <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
638           <td>
639           $button2
640           $button2_2
641           </td>
642         </tr>
643         <tr>
644           <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
645           <td><input name=decimalplaces size=3 value="2"></td>
646         </tr>
647       </table>
648     </td>
649   </tr>
650   <tr>
651     <td>
652       <table>
653         <tr>
654           <th align=right>| . $locale->text('Method') . qq|</th>
655           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
656       . $locale->text('Accrual') . qq|
657           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
658       . $locale->text('EUR') . qq|</td>
659         </tr>
660
661         <tr>
662           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
663           <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
664       . $locale->text('Heading') . qq|
665           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
666       . $locale->text('Subtotal') . qq|
667           <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|
668       . $locale->text('Account Number') . qq|</td>
669         </tr>
670
671 $jsscript
672 |;
673   }
674
675   if ($form->{report} eq "trial_balance") {
676     print qq|
677         <input type=hidden name=nextsub value=generate_trial_balance>
678         <input type=hidden name=eur value=$eur>
679        <tr>
680           <th align=right>| . $locale->text('From') . qq|</th>
681           <td>
682             $button1
683             $button1_2
684           </td>
685           <th align=right>| . $locale->text('Bis') . qq|</th>
686           <td>
687             $button2
688             $button2_2
689           </td>
690         </tr>
691       </table>
692     </td>
693   </tr>
694   <tr>
695     <td>
696       <table>
697         <tr>
698           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
699           <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
700       . $locale->text('Heading') . qq|
701           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
702       . $locale->text('Subtotal') . qq|
703           <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|
704       . $locale->text('All Accounts') . qq|</td>
705         </tr>
706
707 $jsscript
708 |;
709   }
710
711   if ($form->{report} =~ /^tax_/) {
712     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
713
714     RP->get_taxaccounts(\%myconfig, \%$form);
715
716     print qq|
717         <input type=hidden name=nextsub value=generate_tax_report>
718         <tr>
719           <th align=right>| . $locale->text('From') . qq|</th>
720           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
721           <th align=right>| . $locale->text('Bis') . qq|</th>
722           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
723         </tr>
724         <tr>
725           <th align=right>| . $locale->text('Report for') . qq|</th>
726           <td colspan=3>
727 |;
728
729     $checked = "checked";
730     foreach $ref (@{ $form->{taxaccounts} }) {
731
732       print
733         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
734
735     <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
736     <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
737
738       $checked = "";
739
740     }
741
742     print qq|
743   <input type=hidden name=db value=$form->{db}>
744   <input type=hidden name=sort value=transdate>
745
746           </td>
747         </tr>
748         <tr>
749           <th align=right>| . $locale->text('Method') . qq|</th>
750           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
751       . $locale->text('Accrual') . qq|
752           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
753       . $locale->text('EUR') . qq|</td>
754         </tr>
755       </table>
756     </td>
757   </tr>
758   <tr>
759     <td>
760       <table>
761         <tr>
762           <th align=right>| . $locale->text('Include in Report') . qq|</th>
763           <td>
764             <table>
765               <tr>
766                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
767                 <td>| . $locale->text('ID') . qq|</td>
768                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
769                 <td>| . $locale->text('Invoice') . qq|</td>
770                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
771                 <td>| . $locale->text('Date') . qq|</td>
772               </tr>
773               <tr>
774                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
775                 <td>|;
776
777     if ($form->{db} eq 'ar') {
778       print $locale->text('Customer');
779     }
780     if ($form->{db} eq 'ap') {
781       print $locale->text('Vendor');
782     }
783
784     print qq|</td>
785                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
786                 <td>| . $locale->text('Amount') . qq|</td>
787                 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
788                 <td>| . $locale->text('Tax') . qq|</td>
789                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
790                 <td>| . $locale->text('Total') . qq|</td>
791               </tr>
792               <tr>
793                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
794                 <td>| . $locale->text('Subtotal') . qq|</td>
795               </tr>
796             </table>
797           </td>
798         </tr>
799 |;
800
801   }
802
803   if ($form->{report} =~ /^nontaxable_/) {
804     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
805
806     print qq|
807         <input type=hidden name=nextsub value=generate_tax_report>
808
809         <input type=hidden name=db value=$form->{db}>
810         <input type=hidden name=sort value=transdate>
811         <input type=hidden name=report value=$form->{report}>
812
813         <tr>
814           <th align=right>| . $locale->text('From') . qq|</th>
815           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
816           <th align=right>| . $locale->text('Bis') . qq|</th>
817           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
818         </tr>
819         <tr>
820           <th align=right>| . $locale->text('Method') . qq|</th>
821           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
822       . $locale->text('Accrual') . qq|
823           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
824       . $locale->text('EUR') . qq|</td>
825         </tr>
826         <tr>
827           <th align=right>| . $locale->text('Include in Report') . qq|</th>
828           <td colspan=3>
829             <table>
830               <tr>
831                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
832                 <td>| . $locale->text('ID') . qq|</td>
833                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
834                 <td>| . $locale->text('Invoice') . qq|</td>
835                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
836                 <td>| . $locale->text('Date') . qq|</td>
837               </tr>
838               <tr>
839                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
840                 <td>|;
841
842     if ($form->{db} eq 'ar') {
843       print $locale->text('Customer');
844     }
845     if ($form->{db} eq 'ap') {
846       print $locale->text('Vendor');
847     }
848
849     print qq|</td>
850                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
851                 <td>| . $locale->text('Amount') . qq|</td>
852                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
853                 <td>| . $locale->text('Total') . qq|</td>
854               </tr>
855               <tr>
856                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
857                 <td>| . $locale->text('Subtotal') . qq|</td>
858               </tr>
859             </table>
860           </td>
861         </tr>
862 |;
863
864   }
865
866   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
867     if ($form->{report} eq 'ar_aging') {
868       $label = $locale->text('Customer');
869       $form->{vc} = 'customer';
870     } else {
871       $label = $locale->text('Vendor');
872       $form->{vc} = 'vendor';
873     }
874
875     $nextsub = "generate_$form->{report}";
876
877     # setup vc selection
878     $form->all_vc(\%myconfig, $form->{vc},
879                   ($form->{vc} eq 'customer') ? "AR" : "AP");
880
881     map { $vc .= "<option>$_->{name}--$_->{id}\n" }
882       @{ $form->{"all_$form->{vc}"} };
883
884     $vc =
885       ($vc)
886       ? qq|<select name=$form->{vc}><option>\n$vc</select>|
887       : qq|<input name=$form->{vc} size=35>|;
888
889     print qq|
890         <tr>
891           <th align=right>| . $locale->text($label) . qq|</th>
892           <td>$vc</td>
893         </tr>
894         <tr>
895           <th align=right>| . $locale->text('Bis') . qq|</th>
896           <td>
897             $button1
898             $button1_2
899           </td>
900         </tr>
901         <input type=hidden name=type value=statement>
902         <input type=hidden name=format value=html>
903         <input type=hidden name=media value=screen>
904
905         <input type=hidden name=nextsub value=$nextsub>
906         <input type=hidden name=action value=$nextsub>
907
908 $jsscript
909 |;
910   }
911
912   # above action can be removed if there is more than one input field
913
914   if ($form->{report} =~ /(receipts|payments)$/) {
915     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
916
917     RP->paymentaccounts(\%myconfig, \%$form);
918
919     $selection = "<option>\n";
920     foreach $ref (@{ $form->{PR} }) {
921       $paymentaccounts .= "$ref->{accno} ";
922       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
923     }
924
925     chop $paymentaccounts;
926
927     print qq|
928         <input type=hidden name=nextsub value=list_payments>
929         <tr>
930           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
931           <td colspan=3><select name=account>$selection</select>
932             <input type=hidden name=paymentaccounts value="$paymentaccounts">
933           </td>
934         </tr>
935         <tr>
936           <th align=right>| . $locale->text('Reference') . qq|</th>
937           <td colspan=3><input name=reference></td>
938         </tr>
939         <tr>
940           <th align=right nowrap>| . $locale->text('Source') . qq|</th>
941           <td colspan=3><input name=source></td>
942         </tr>
943         <tr>
944           <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
945           <td colspan=3><input name=memo size=30></td>
946         </tr>
947         <tr>
948           <th align=right>| . $locale->text('From') . qq|</th>
949           <td>
950             $button1
951             $button1_2
952           </td>
953           <th align=right>| . $locale->text('Bis') . qq|</th>
954           <td>
955             $button2
956             $button2_2
957           </td>
958         </tr>
959         <tr>
960           <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
961           <th align=left colspan=3>|
962       . $locale->text('Include Exchangerate Difference') . qq|</td>
963         </tr>
964
965 $jsscript
966
967           <input type=hidden name=db value=$form->{db}>
968           <input type=hidden name=sort value=transdate>
969 |;
970
971   }
972
973   print qq|
974
975       </table>
976     </td>
977   </tr>
978   <tr>
979     <td><hr size=3 noshade></td>
980   </tr>
981 </table>
982
983 <br>
984 <input type=hidden name=login value=$form->{login}>
985 <input type=hidden name=password value=$form->{password}>
986
987 <input type=submit class=submit name=action value="|
988     . $locale->text('Continue') . qq|">
989 |;
990
991   # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
992   USTVA->get_config($userspath, 'finanzamt.ini');
993
994   $disabled = qq|disabled="disabled"|;
995   $disabled = '' if ($form->{elster} eq '1');
996   if ($form->{report} eq 'ustva') {
997     print qq|
998   <input type=submit class=submit name=action value="|
999       . $locale->text('debug') . qq|">
1000   <input type=submit class=submit name=action $disabled
1001    value="| . $locale->text('winston_export') . qq|">
1002   |;
1003     print qq|
1004    <input type=submit class=submit name=action value="|
1005       . $locale->text('config') . qq|">
1006   |;
1007   }
1008
1009   print qq|
1010 </form>
1011
1012 </body>
1013 </html>
1014 |;
1015
1016   $lxdebug->leave_sub();
1017 }
1018
1019 sub continue { call_sub($form->{"nextsub"}); }
1020
1021 sub get_project {
1022   $lxdebug->enter_sub();
1023   my $nextsub = shift;
1024
1025   $form->{project_id} = $form->{project_id_1};
1026   if ($form->{projectnumber} && !$form->{project_id}) {
1027     $form->{rowcount} = 1;
1028
1029     # call this instead of update
1030     $form->{update}          = $nextsub;
1031     $form->{projectnumber_1} = $form->{projectnumber};
1032
1033     delete $form->{sort};
1034     &check_project;
1035
1036     # if there is one only, assign id
1037     $form->{project_id} = $form->{project_id_1};
1038   }
1039
1040   $lxdebug->leave_sub();
1041 }
1042
1043 sub generate_income_statement {
1044   $lxdebug->enter_sub();
1045
1046   $form->{padding} = "&nbsp;&nbsp;";
1047   $form->{bold}    = "<b>";
1048   $form->{endbold} = "</b>";
1049   $form->{br}      = "<br>";
1050
1051   if ($form->{reporttype} eq "custom") {
1052
1053     #forgotten the year --> thisyear
1054     if ($form->{year} !~ m/^\d\d\d\d$/) {
1055       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1056         /(\d\d\d\d)/;
1057       $form->{year} = $1;
1058     }
1059
1060     #yearly report
1061     if ($form->{duetyp} eq "13") {
1062       $form->{fromdate} = "1.1.$form->{year}";
1063       $form->{todate}   = "31.12.$form->{year}";
1064     }
1065
1066     #Quater reports
1067     if ($form->{duetyp} eq "A") {
1068       $form->{fromdate} = "1.1.$form->{year}";
1069       $form->{todate}   = "31.3.$form->{year}";
1070     }
1071     if ($form->{duetyp} eq "B") {
1072       $form->{fromdate} = "1.4.$form->{year}";
1073       $form->{todate}   = "30.6.$form->{year}";
1074     }
1075     if ($form->{duetyp} eq "C") {
1076       $form->{fromdate} = "1.7.$form->{year}";
1077       $form->{todate}   = "30.9.$form->{year}";
1078     }
1079     if ($form->{duetyp} eq "D") {
1080       $form->{fromdate} = "1.10.$form->{year}";
1081       $form->{todate}   = "31.12.$form->{year}";
1082     }
1083
1084     #Monthly reports
1085   SWITCH: {
1086       $form->{duetyp} eq "1" && do {
1087         $form->{fromdate} = "1.1.$form->{year}";
1088         $form->{todate}   = "31.1.$form->{year}";
1089         last SWITCH;
1090       };
1091       $form->{duetyp} eq "2" && do {
1092         $form->{fromdate} = "1.2.$form->{year}";
1093
1094         #this works from 1901 to 2099, 1900 and 2100 fail.
1095         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1096         $form->{todate} = "$leap.2.$form->{year}";
1097         last SWITCH;
1098       };
1099       $form->{duetyp} eq "3" && do {
1100         $form->{fromdate} = "1.3.$form->{year}";
1101         $form->{todate}   = "31.3.$form->{year}";
1102         last SWITCH;
1103       };
1104       $form->{duetyp} eq "4" && do {
1105         $form->{fromdate} = "1.4.$form->{year}";
1106         $form->{todate}   = "30.4.$form->{year}";
1107         last SWITCH;
1108       };
1109       $form->{duetyp} eq "5" && do {
1110         $form->{fromdate} = "1.5.$form->{year}";
1111         $form->{todate}   = "31.5.$form->{year}";
1112         last SWITCH;
1113       };
1114       $form->{duetyp} eq "6" && do {
1115         $form->{fromdate} = "1.6.$form->{year}";
1116         $form->{todate}   = "30.6.$form->{year}";
1117         last SWITCH;
1118       };
1119       $form->{duetyp} eq "7" && do {
1120         $form->{fromdate} = "1.7.$form->{year}";
1121         $form->{todate}   = "31.7.$form->{year}";
1122         last SWITCH;
1123       };
1124       $form->{duetyp} eq "8" && do {
1125         $form->{fromdate} = "1.8.$form->{year}";
1126         $form->{todate}   = "31.8.$form->{year}";
1127         last SWITCH;
1128       };
1129       $form->{duetyp} eq "9" && do {
1130         $form->{fromdate} = "1.9.$form->{year}";
1131         $form->{todate}   = "30.9.$form->{year}";
1132         last SWITCH;
1133       };
1134       $form->{duetyp} eq "10" && do {
1135         $form->{fromdate} = "1.10.$form->{year}";
1136         $form->{todate}   = "31.10.$form->{year}";
1137         last SWITCH;
1138       };
1139       $form->{duetyp} eq "11" && do {
1140         $form->{fromdate} = "1.11.$form->{year}";
1141         $form->{todate}   = "30.11.$form->{year}";
1142         last SWITCH;
1143       };
1144       $form->{duetyp} eq "12" && do {
1145         $form->{fromdate} = "1.12.$form->{year}";
1146         $form->{todate}   = "31.12.$form->{year}";
1147         last SWITCH;
1148       };
1149     }
1150   }
1151
1152   RP->income_statement(\%myconfig, \%$form);
1153
1154   ($form->{department}) = split /--/, $form->{department};
1155
1156   $form->{period} =
1157     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1158   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1159
1160   # if there are any dates construct a where
1161   if ($form->{fromdate} || $form->{todate}) {
1162
1163     unless ($form->{todate}) {
1164       $form->{todate} = $form->current_date(\%myconfig);
1165     }
1166
1167     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
1168     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1169
1170     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
1171     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1172
1173     $form->{this_period} = "$shortfromdate\n$shorttodate";
1174     $form->{period}      =
1175         $locale->text('for Period')
1176       . qq|\n$longfromdate |
1177       . $locale->text('Bis')
1178       . qq| $longtodate|;
1179   }
1180
1181   if ($form->{comparefromdate} || $form->{comparetodate}) {
1182     $longcomparefromdate =
1183       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1184     $shortcomparefromdate =
1185       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1186
1187     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1188     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1189
1190     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1191     $form->{period} .=
1192         "\n$longcomparefromdate "
1193       . $locale->text('Bis')
1194       . qq| $longcomparetodate|;
1195   }
1196
1197   # setup variables for the form
1198   @a = qw(company address businessnumber);
1199   map { $form->{$_} = $myconfig{$_} } @a;
1200
1201   $form->{templates} = $myconfig{templates};
1202
1203   $form->{IN} = "income_statement.html";
1204
1205   $form->parse_template;
1206
1207   $lxdebug->leave_sub();
1208 }
1209
1210 sub generate_balance_sheet {
1211   $lxdebug->enter_sub();
1212
1213   $form->{padding} = "&nbsp;&nbsp;";
1214   $form->{bold}    = "<b>";
1215   $form->{endbold} = "</b>";
1216   $form->{br}      = "<br>";
1217
1218   RP->balance_sheet(\%myconfig, \%$form);
1219
1220   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1221   $form->{period} =
1222     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1223
1224   ($form->{department}) = split /--/, $form->{department};
1225
1226   # define Current Earnings account
1227   $padding = ($form->{l_heading}) ? $form->{padding} : "";
1228   push(@{ $form->{equity_account} },
1229        $padding . $locale->text('Current Earnings'));
1230
1231   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1232   $form->{last_period} =
1233     $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1234
1235   $form->{IN} = "balance_sheet.html";
1236
1237   # setup company variables for the form
1238   map { $form->{$_} = $myconfig{$_};
1239         $form->{$_} =~ s/\\n/\n/g; }
1240     (qw(company address businessnumber nativecurr));
1241
1242   $form->{templates} = $myconfig{templates};
1243
1244   $form->parse_template;
1245
1246   $lxdebug->leave_sub();
1247 }
1248
1249 sub generate_projects {
1250   $lxdebug->enter_sub();
1251
1252   &get_project(generate_projects);
1253   $form->{projectnumber} = $form->{projectnumber_1};
1254
1255   $form->{nextsub} = "generate_projects";
1256   $form->{title}   = $locale->text('Project Transactions');
1257   RP->trial_balance(\%myconfig, \%$form);
1258
1259   list_accounts('generate_projects');
1260
1261   $lxdebug->leave_sub();
1262 }
1263
1264 # Antonio Gallardo
1265 #
1266 # D.S. Feb 16, 2001
1267 # included links to display transactions for period entered
1268 # added headers and subtotals
1269 #
1270 sub generate_trial_balance {
1271   $lxdebug->enter_sub();
1272
1273   # get for each account initial balance, debits and credits
1274   RP->trial_balance(\%myconfig, \%$form);
1275
1276   $form->{nextsub} = "generate_trial_balance";
1277   $form->{title}   = $locale->text('Trial Balance');
1278   list_accounts('generate_trial_balance');
1279
1280   $lxdebug->leave_sub();
1281 }
1282
1283 sub create_list_accounts_subtotal_row {
1284   $lxdebug->enter_sub();
1285
1286   my ($subtotals, $columns, $fields, $class) = @_;
1287
1288   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1289
1290   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
1291
1292   $lxdebug->leave_sub();
1293
1294   return $row;
1295 }
1296
1297 sub list_accounts {
1298   $lxdebug->enter_sub();
1299
1300   my ($action) = @_;
1301
1302   my @options;
1303   if ($form->{department}) {
1304     my ($department) = split /--/, $form->{department};
1305     push @options, $locale->text('Department') . " : $department";
1306   }
1307   if ($form->{projectnumber}) {
1308     push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
1309   }
1310
1311   # if there are any dates
1312   if ($form->{fromdate} || $form->{todate}) {
1313     my ($fromdate, $todate);
1314
1315     if ($form->{fromdate}) {
1316       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1317     }
1318     if ($form->{todate}) {
1319       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1320     }
1321
1322     push @options, "$fromdate - $todate";
1323
1324   } else {
1325     push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1326   }
1327
1328   my @columns     = qw(accno description begbalance debit credit endbalance);
1329   my %column_defs = (
1330     'accno'       => { 'text' => $locale->text('Account'), },
1331     'description' => { 'text' => $locale->text('Description'), },
1332     'debit'       => { 'text' => $locale->text('Debit'), },
1333     'credit'      => { 'text' => $locale->text('Credit'), },
1334     'begbalance'  => { 'text' => $locale->text('Balance'), },
1335     'endbalance'  => { 'text' => $locale->text('Balance'), },
1336   );
1337   my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
1338
1339   my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
1340
1341   $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
1342
1343   my $report = SL::ReportGenerator->new(\%myconfig, $form);
1344
1345   $report->set_options('top_info_text'         => join("\n", @options),
1346                        'output_format'         => 'HTML',
1347                        'title'                 => $form->{title},
1348                        'attachment_basename'   => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
1349                        'std_column_visibility' => 1,
1350     );
1351   $report->set_options_from_form();
1352
1353   $report->set_columns(%column_defs);
1354   $report->set_column_order(@columns);
1355
1356   $report->set_export_options($action, @hidden_variables);
1357
1358   $report->set_sort_indicator('accno', 1);
1359
1360   my @totals_columns = qw(credit debit begbalance endbalance);
1361   my %subtotals      = map { $_ => 0 } @totals_columns;
1362   my %totals         = map { $_ => 0 } @totals_columns;
1363   my $found_heading  = 0;
1364   my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
1365
1366   # sort the whole thing by account numbers and display
1367   foreach my $idx (0 .. scalar(@tb) - 1) {
1368     my $ref  = $tb[$idx];
1369     my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
1370
1371     my $ml   = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1372
1373     my $row  = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
1374
1375     if ($ref->{charttype} eq 'H') {
1376       next unless ($form->{l_heading});
1377
1378       %subtotals                   = map { $_ => 0 } @totals_columns;
1379       $found_heading               = 1;
1380       $row->{description}->{class} = 'listheading';
1381       $row->{description}->{data}  = $ref->{description};
1382
1383       $report->add_data($row);
1384
1385       next;
1386     }
1387
1388     foreach (qw(debit credit)) {
1389       $subtotals{$_} += $ref->{$_};
1390       $totals{$_}    += $ref->{$_};
1391     }
1392
1393     $subtotals{begbalance} += $ref->{balance} * $ml;
1394     $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
1395
1396     map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
1397     map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
1398
1399     $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
1400     $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
1401
1402     $report->add_data($row);
1403
1404     if ($form->{l_heading} && $found_heading &&
1405         (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
1406       $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
1407     }
1408   }
1409
1410   $report->add_separator();
1411
1412   $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
1413
1414   $report->generate_with_headers();
1415
1416   $lxdebug->leave_sub();
1417 }
1418
1419 sub generate_ar_aging {
1420   $lxdebug->enter_sub();
1421
1422   # split customer
1423   ($form->{customer}) = split(/--/, $form->{customer});
1424
1425   $form->{ct}   = "customer";
1426   $form->{arap} = "ar";
1427
1428   $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
1429
1430   RP->aging(\%myconfig, \%$form);
1431   aging();
1432
1433   $lxdebug->leave_sub();
1434 }
1435
1436 sub generate_ap_aging {
1437   $lxdebug->enter_sub();
1438
1439   # split vendor
1440   ($form->{vendor}) = split(/--/, $form->{vendor});
1441
1442   $form->{ct}   = "vendor";
1443   $form->{arap} = "ap";
1444
1445   $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
1446
1447   RP->aging(\%myconfig, \%$form);
1448   aging();
1449
1450   $lxdebug->leave_sub();
1451 }
1452
1453 sub create_aging_subtotal_row {
1454   $lxdebug->enter_sub();
1455
1456   my ($subtotals, $columns, $periods, $class) = @_;
1457
1458   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
1459
1460   foreach (@{ $periods }) {
1461     $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
1462     $subtotals->{$_}      = 0;
1463   }
1464
1465   $lxdebug->leave_sub();
1466
1467   return $row;
1468 }
1469
1470 sub aging {
1471   $lxdebug->enter_sub();
1472
1473   my $report = SL::ReportGenerator->new(\%myconfig, $form);
1474
1475   my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
1476
1477   my %column_defs = (
1478     'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
1479     'ct'        => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1480     'invnumber' => { 'text' => $locale->text('Invoice'), },
1481     'transdate' => { 'text' => $locale->text('Date'), },
1482     'duedate'   => { 'text' => $locale->text('Due'), },
1483     'c0'        => { 'text' => $locale->text('Current'), },
1484     'c30'       => { 'text' => '30', },
1485     'c60'       => { 'text' => '60', },
1486     'c90'       => { 'text' => '90', },
1487   );
1488
1489   my %column_alignment = ('statement' => 'center',
1490                           map { $_ => 'right' } qw(c0 c30 c60 c90));
1491
1492   $report->set_options('std_column_visibility' => 1);
1493   $report->set_columns(%column_defs);
1494   $report->set_column_order(@columns);
1495
1496   my @hidden_variables = qw(todate customer vendor arap title ct);
1497   $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
1498
1499   my @options;
1500
1501   if ($form->{department}) {
1502     my ($department) = split /--/, $form->{department};
1503     push @options, $locale->text('Department') . " : $department";
1504     $form->{callback} .= "&department=" . E($department);
1505   }
1506
1507   if (($form->{arap} eq 'ar') && $form->{customer}) {
1508     push @options, $form->{customer};
1509   }
1510
1511   if (($form->{arap} eq 'ap') && $form->{vendor}) {
1512     push @options, $form->{vendor};
1513   }
1514
1515   push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
1516
1517   my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
1518
1519   $report->set_options('top_info_text'        => join("\n", @options),
1520                        'output_format'        => 'HTML',
1521                        'title'                => $form->{title},
1522                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
1523     );
1524
1525   my $previous_ctid = 0;
1526   my $row_idx       = 0;
1527   my @periods       = qw(0 30 60 90);
1528   my %subtotals     = map { $_ => 0 } @periods;
1529   my %totals        = map { $_ => 0 } @periods;
1530
1531   foreach $ref (@{ $form->{AG} }) {
1532     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
1533       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
1534     }
1535
1536     foreach my $key (@periods) {
1537       $subtotals{$key}  += $ref->{"c${key}"};
1538       $totals{$key}     += $ref->{"c${key}"};
1539       $ref->{"c${key}"}  = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
1540     }
1541
1542     my $row = { };
1543
1544     foreach my $column (@columns) {
1545       $row->{$column} = {
1546         'data'   => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
1547         'align'  => $column_alignment{$column},
1548         'valign' => $column eq 'statement' ? 'center' : '',
1549       };
1550     }
1551
1552     $row->{invnumber}->{link} =  build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
1553
1554     if ($previous_ctid != $ref->{ctid}) {
1555       $row->{statement}->{raw_data} =
1556           $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
1557         . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
1558       $row->{ct}->{data} = $ref->{name};
1559
1560       $row_idx++;
1561     }
1562
1563     $previous_ctid = $ref->{ctid};
1564
1565     $report->add_data($row);
1566   }
1567
1568   $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
1569
1570   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
1571
1572   if ($form->{arap} eq 'ar') {
1573     $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
1574     $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
1575                                                                                'PRINT_OPTIONS' => print_options(1), });
1576     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
1577                          'raw_bottom_info_text' => $raw_bottom_info_text);
1578   }
1579
1580   $report->set_options_from_form();
1581
1582   $report->generate_with_headers();
1583
1584   $lxdebug->leave_sub();
1585 }
1586
1587 sub select_all {
1588   $lxdebug->enter_sub();
1589
1590   RP->aging(\%myconfig, \%$form);
1591
1592   map { $_->{checked} = "checked" } @{ $form->{AG} };
1593
1594   &aging;
1595
1596   $lxdebug->leave_sub();
1597 }
1598
1599 sub e_mail {
1600   $lxdebug->enter_sub();
1601
1602   # get name and email addresses
1603   for $i (1 .. $form->{rowcount}) {
1604     if ($form->{"statement_$i"}) {
1605       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1606       RP->get_customer(\%myconfig, \%$form);
1607       $selected = 1;
1608       last;
1609     }
1610   }
1611
1612   $form->error($locale->text('Nothing selected!')) unless $selected;
1613
1614   if ($myconfig{role} eq 'admin') {
1615     $bcc = qq|
1616           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1617           <td><input name=bcc size=30 value="$form->{bcc}"></td>
1618 |;
1619   }
1620
1621   $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1622
1623   $form->{media} = "email";
1624
1625   $form->header;
1626
1627   print qq|
1628 <body>
1629
1630 <form method=post action=$form->{script}>
1631
1632 <table width=100%>
1633   <tr class=listtop>
1634     <th>$title</th>
1635   </tr>
1636   <tr height="5"></tr>
1637   <tr>
1638     <td>
1639       <table width=100%>
1640         <tr>
1641           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1642           <td><input name=email size=30 value="$form->{email}"></td>
1643           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1644           <td><input name=cc size=30 value="$form->{cc}"></td>
1645         </tr>
1646         <tr>
1647           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1648           <td><input name=subject size=30 value="$form->{subject}"></td>
1649           $bcc
1650         </tr>
1651       </table>
1652     </td>
1653   </tr>
1654   <tr>
1655     <td>
1656       <table width=100%>
1657         <tr>
1658           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1659         </tr>
1660         <tr>
1661           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1662         </tr>
1663       </table>
1664     </td>
1665   </tr>
1666   <tr>
1667     <td>
1668 |;
1669
1670   &print_options;
1671
1672   map { delete $form->{$_} }
1673     qw(action email cc bcc subject message type sendmode format header);
1674
1675   # save all other variables
1676   foreach $key (keys %$form) {
1677     $form->{$key} =~ s/\"/&quot;/g;
1678     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1679   }
1680
1681   print qq|
1682     </td>
1683   </tr>
1684   <tr>
1685     <td><hr size=3 noshade></td>
1686   </tr>
1687 </table>
1688
1689 <input type=hidden name=nextsub value=send_email>
1690
1691 <br>
1692 <input name=action class=submit type=submit value="|
1693     . $locale->text('Continue') . qq|">
1694 </form>
1695
1696 </body>
1697 </html>
1698 |;
1699
1700   $lxdebug->leave_sub();
1701 }
1702
1703 sub send_email {
1704   $lxdebug->enter_sub();
1705
1706   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
1707     unless $form->{subject};
1708
1709   RP->aging(\%myconfig, \%$form);
1710
1711   $form->{"statement_1"} = 1;
1712
1713   $form->{media} = 'email';
1714   print_form();
1715
1716   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
1717
1718   $lxdebug->leave_sub();
1719 }
1720
1721 sub print {
1722   $lxdebug->enter_sub();
1723
1724   if ($form->{media} eq 'printer') {
1725     $form->error($locale->text('Select postscript or PDF!'))
1726       if ($form->{format} !~ /(postscript|pdf)/);
1727   }
1728
1729   for $i (1 .. $form->{rowcount}) {
1730     if ($form->{"statement_$i"}) {
1731       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1732       $selected = 1;
1733       last;
1734     }
1735   }
1736
1737   $form->error($locale->text('Nothing selected!')) unless $selected;
1738
1739   if ($form->{media} eq 'printer') {
1740     $form->{"$form->{ct}_id"} = "";
1741   } else {
1742     $form->{"statement_1"} = 1;
1743   }
1744
1745   RP->aging(\%myconfig, \%$form);
1746
1747   print_form();
1748
1749   $form->redirect($locale->text('Statements sent to printer!'))
1750     if ($form->{media} eq 'printer');
1751
1752   $lxdebug->leave_sub();
1753 }
1754
1755 sub print_form {
1756   $lxdebug->enter_sub();
1757
1758   my %replacements =
1759     (
1760      "ä" => "ae", "ö" => "oe", "ü" => "ue",
1761      "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
1762      "ß" => "ss",
1763      " " => "_"
1764     );
1765
1766   foreach my $key (keys %replacements) {
1767     my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
1768     $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
1769   }
1770
1771   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
1772
1773   $form->{templates} = "$myconfig{templates}";
1774
1775   my $suffix = "html";
1776   my $attachment_suffix = "html";
1777   if ($form->{format} eq 'postscript') {
1778     $form->{postscript} = 1;
1779     $suffix = "tex";
1780     $attachment_suffix = "ps";
1781   } elsif ($form->{format} eq 'pdf') {
1782     $form->{pdf} = 1;
1783     $suffix = "tex";
1784     $attachment_suffix = "pdf";
1785   }
1786
1787   $form->{IN}  = "$form->{type}.$suffix";
1788   $form->{OUT} =
1789     $form->{media} eq 'email'   ? $sendmail              :
1790     $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
1791
1792   # Save $form->{email} because it will be overwritten.
1793   $form->{EMAIL_RECIPIENT} = $form->{email};
1794
1795   $i = 0;
1796   while (@{ $form->{AG} }) {
1797
1798     $ref = shift @{ $form->{AG} };
1799
1800     if ($ctid != $ref->{ctid}) {
1801
1802       $ctid = $ref->{ctid};
1803       $i++;
1804
1805       if ($form->{"statement_$i"}) {
1806
1807         @a =
1808           (name, street, zipcode, city, country, contact, email,
1809            "$form->{ct}phone", "$form->{ct}fax");
1810         map { $form->{$_} = $ref->{$_} } @a;
1811
1812         $form->{ $form->{ct} } = $form->{name};
1813         $form->{"$form->{ct}_id"} = $ref->{ctid};
1814
1815         map { $form->{$_} = () } qw(invnumber invdate duedate);
1816         $form->{total} = 0;
1817         foreach $item (qw(c0 c30 c60 c90)) {
1818           $form->{$item} = ();
1819           $form->{"${item}total"} = 0;
1820         }
1821
1822         &statement_details($ref);
1823
1824         while ($ref) {
1825
1826           if (scalar(@{ $form->{AG} }) > 0) {
1827
1828             # one or more left to go
1829             if ($ctid == $form->{AG}->[0]->{ctid}) {
1830               $ref = shift @{ $form->{AG} };
1831               &statement_details($ref);
1832
1833               # any more?
1834               $ref = scalar(@{ $form->{AG} });
1835             } else {
1836               $ref = 0;
1837             }
1838           } else {
1839
1840             # set initial ref to 0
1841             $ref = 0;
1842           }
1843
1844         }
1845
1846         map {
1847           $form->{"${_}total"} =
1848             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
1849         } (c0, c30, c60, c90, "");
1850
1851         $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
1852         map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
1853
1854         $form->parse_template(\%myconfig, $userspath);
1855
1856       }
1857     }
1858   }
1859   # saving the history
1860   if(!exists $form->{addition} && $form->{id} ne "") {
1861     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1862         $form->{addition} = "PRINTED";
1863         $form->{what_done} = $form->{type};
1864         $form->save_history($form->dbconnect(\%myconfig));
1865   }
1866   # /saving the history 
1867   $lxdebug->leave_sub();
1868 }
1869
1870 sub statement_details {
1871   $lxdebug->enter_sub();
1872   my ($ref) = @_;
1873
1874   push @{ $form->{invnumber} }, $ref->{invnumber};
1875   push @{ $form->{invdate} },   $ref->{transdate};
1876   push @{ $form->{duedate} },   $ref->{duedate};
1877
1878   foreach $item (qw(c0 c30 c60 c90)) {
1879     if ($ref->{exchangerate} * 1) {
1880       $ref->{$item} =
1881         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
1882     }
1883     $form->{"${item}total"} += $ref->{$item};
1884     $form->{total}          += $ref->{$item};
1885     push @{ $form->{$item} },
1886       $form->format_amount(\%myconfig, $ref->{$item}, 2);
1887   }
1888
1889   $lxdebug->leave_sub();
1890 }
1891
1892 sub generate_tax_report {
1893   $lxdebug->enter_sub();
1894
1895   RP->tax_report(\%myconfig, \%$form);
1896
1897   $descvar     = "$form->{accno}_description";
1898   $description = $form->escape($form->{$descvar});
1899   $ratevar     = "$form->{accno}_rate";
1900
1901   $department = $form->escape($form->{department});
1902
1903   # construct href
1904   $href =
1905     "$form->{script}?&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
1906
1907   # construct callback
1908   $description = $form->escape($form->{$descvar},   1);
1909   $department  = $form->escape($form->{department}, 1);
1910   $callback    =
1911     "$form->{script}?&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
1912
1913   $title = $form->escape($form->{title});
1914   $href .= "&title=$title";
1915   $title = $form->escape($form->{title}, 1);
1916   $callback .= "&title=$title";
1917
1918   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
1919
1920   @columns =
1921     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
1922
1923   foreach $item (@columns) {
1924     if ($form->{"l_$item"} eq "Y") {
1925       push @column_index, $item;
1926
1927       # add column to href and callback
1928       $callback .= "&l_$item=Y";
1929       $href     .= "&l_$item=Y";
1930     }
1931   }
1932
1933   if ($form->{l_subtotal} eq 'Y') {
1934     $callback .= "&l_subtotal=Y";
1935     $href     .= "&l_subtotal=Y";
1936   }
1937
1938   if ($form->{department}) {
1939     ($department) = split /--/, $form->{department};
1940     $option = $locale->text('Department') . " : $department";
1941   }
1942
1943   # if there are any dates
1944   if ($form->{fromdate} || $form->{todate}) {
1945     if ($form->{fromdate}) {
1946       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1947     }
1948     if ($form->{todate}) {
1949       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1950     }
1951
1952     $form->{period} = "$fromdate - $todate";
1953   } else {
1954     $form->{period} =
1955       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1956   }
1957
1958   if ($form->{db} eq 'ar') {
1959     $name    = $locale->text('Customer');
1960     $invoice = 'is.pl';
1961     $arap    = 'ar.pl';
1962   }
1963   if ($form->{db} eq 'ap') {
1964     $name    = $locale->text('Vendor');
1965     $invoice = 'ir.pl';
1966     $arap    = 'ap.pl';
1967   }
1968
1969   $option .= "<br>" if $option;
1970   $option .= "$form->{period}";
1971
1972   $column_header{id} =
1973       qq|<th><a class=listheading href=$href&sort=id>|
1974     . $locale->text('ID')
1975     . qq|</th>|;
1976   $column_header{invnumber} =
1977       qq|<th><a class=listheading href=$href&sort=invnumber>|
1978     . $locale->text('Invoice')
1979     . qq|</th>|;
1980   $column_header{transdate} =
1981       qq|<th><a class=listheading href=$href&sort=transdate>|
1982     . $locale->text('Date')
1983     . qq|</th>|;
1984   $column_header{netamount} =
1985     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1986   $column_header{tax} =
1987     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1988   $column_header{amount} =
1989     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1990
1991   $column_header{name} =
1992     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
1993
1994   $form->header;
1995
1996   print qq|
1997 <body>
1998
1999 <table width=100%>
2000   <tr>
2001     <th class=listtop colspan=$colspan>$form->{title}</th>
2002   </tr>
2003   <tr height="5"></tr>
2004   <tr>
2005     <td>$option</td>
2006   </tr>
2007   <tr>
2008     <td>
2009       <table width=100%>
2010         <tr class=listheading>
2011 |;
2012
2013   map { print "$column_header{$_}\n" } @column_index;
2014
2015   print qq|
2016         </tr>
2017 |;
2018
2019   # add sort and escape callback
2020   $callback = $form->escape($callback . "&sort=$form->{sort}");
2021
2022   if (@{ $form->{TR} }) {
2023     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2024   }
2025
2026   foreach $ref (@{ $form->{TR} }) {
2027
2028     $module = ($ref->{invoice}) ? $invoice : $arap;
2029
2030     if ($form->{l_subtotal} eq 'Y') {
2031       if ($sameitem ne $ref->{ $form->{sort} }) {
2032         &tax_subtotal;
2033         $sameitem = $ref->{ $form->{sort} };
2034       }
2035     }
2036
2037     $totalnetamount += $ref->{netamount};
2038     $totaltax       += $ref->{tax};
2039     $ref->{amount} = $ref->{netamount} + $ref->{tax};
2040
2041     $subtotalnetamount += $ref->{netamount};
2042     $subtotaltax       += $ref->{tax};
2043
2044     map {
2045       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;");
2046     } qw(netamount tax amount);
2047
2048     $column_data{id}        = qq|<td>$ref->{id}</td>|;
2049     $column_data{invnumber} =
2050       qq|<td><a href=$module?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>|;
2051     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2052     $column_data{name}      = qq|<td>$ref->{name}&nbsp;</td>|;
2053
2054     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2055       qw(netamount tax amount);
2056
2057     $i++;
2058     $i %= 2;
2059     print qq|
2060         <tr class=listrow$i>
2061 |;
2062
2063     map { print "$column_data{$_}\n" } @column_index;
2064
2065     print qq|
2066         </tr>
2067 |;
2068
2069   }
2070
2071   if ($form->{l_subtotal} eq 'Y') {
2072     &tax_subtotal;
2073   }
2074
2075   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
2076
2077   print qq|
2078         </tr>
2079         <tr class=listtotal>
2080 |;
2081
2082   $total =
2083     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
2084   $totalnetamount =
2085     $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
2086   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
2087
2088   $column_data{netamount} =
2089     qq|<th class=listtotal align=right>$totalnetamount</th>|;
2090   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
2091   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2092
2093   map { print "$column_data{$_}\n" } @column_index;
2094
2095   print qq|
2096         </tr>
2097       </table>
2098     </td>
2099   </tr>
2100   <tr>
2101     <td><hr size=3 noshade></td>
2102   </tr>
2103 </table>
2104
2105 </body>
2106 </html>
2107 |;
2108
2109   $lxdebug->leave_sub();
2110 }
2111
2112 sub tax_subtotal {
2113   $lxdebug->enter_sub();
2114
2115   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2116
2117   $subtotalnetamount =
2118     $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
2119   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
2120   $subtotal =
2121     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2122                          2, "&nbsp;");
2123
2124   $column_data{netamount} =
2125     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2126   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2127   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2128
2129   $subtotalnetamount = 0;
2130   $subtotaltax       = 0;
2131
2132   print qq|
2133         <tr class=listsubtotal>
2134 |;
2135   map { print "\n$column_data{$_}" } @column_index;
2136
2137   print qq|
2138         </tr>
2139 |;
2140
2141   $lxdebug->leave_sub();
2142 }
2143
2144 sub list_payments {
2145   $lxdebug->enter_sub();
2146
2147   if ($form->{account}) {
2148     ($form->{paymentaccounts}) = split /--/, $form->{account};
2149   }
2150   if ($form->{department}) {
2151     ($department, $form->{department_id}) = split /--/, $form->{department};
2152     $option = $locale->text('Department') . " : $department";
2153   }
2154
2155   RP->payments(\%myconfig, \%$form);
2156
2157   my @hidden_variables = qw(account title department reference source memo fromdate todate
2158                             fx_transaction db prepayment paymentaccounts sort);
2159
2160   my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
2161   $form->{callback} = $href;
2162
2163   my @columns     = qw(transdate invnumber name paid source memo);
2164   my %column_defs = (
2165     'name'      => { 'text' => $locale->text('Description'), },
2166     'invnumber' => { 'text' => $locale->text('Reference'), },
2167     'transdate' => { 'text' => $locale->text('Date'), },
2168     'paid'      => { 'text' => $locale->text('Amount'), },
2169     'source'    => { 'text' => $locale->text('Source'), },
2170     'memo'      => { 'text' => $locale->text('Memo'), },
2171   );
2172   my %column_alignment = ('paid' => 'right');
2173
2174   map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns;
2175
2176   my @options;
2177   if ($form->{fromdate}) {
2178     push @options, $locale->text('From') . "&nbsp;" . $locale->date(\%myconfig, $form->{fromdate}, 1);
2179   }
2180   if ($form->{todate}) {
2181     push @options, $locale->text('bis') . "&nbsp;" . $locale->date(\%myconfig, $form->{todate}, 1);
2182   }
2183
2184   my $report = SL::ReportGenerator->new(\%myconfig, $form);
2185
2186   my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
2187
2188   $report->set_options('top_info_text'         => join("\n", @options),
2189                        'output_format'         => 'HTML',
2190                        'title'                 => $form->{title},
2191                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
2192                        'std_column_visibility' => 1,
2193     );
2194   $report->set_options_from_form();
2195
2196   $report->set_columns(%column_defs);
2197   $report->set_column_order(@columns);
2198
2199   $report->set_export_options('list_payments', @hidden_variables);
2200
2201   $report->set_sort_indicator($form->{sort}, 1);
2202
2203   my $total_paid    = 0;
2204
2205   foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2206     next unless @{ $form->{ $ref->{id} } };
2207
2208     $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
2209
2210     my $subtotal_paid = 0;
2211
2212     foreach my $payment (@{ $form->{ $ref->{id} } }) {
2213       my $module = $payment->{module};
2214       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2215       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2216
2217       $subtotal_paid += $payment->{paid};
2218       $total_paid    += $payment->{paid};
2219
2220       $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
2221
2222       my $row = { };
2223
2224       foreach my $column (@columns) {
2225         $row->{$column} = {
2226           'data'  => $payment->{$column},
2227           'align' => $column_alignment{$column},
2228         };
2229       }
2230
2231       $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
2232
2233       $report->add_data($row);
2234     }
2235
2236     my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
2237     $row->{paid} = {
2238       'data'  => $form->format_amount(\%myconfig, $subtotal_paid, 2),
2239       'align' => 'right',
2240       'class' => 'listsubtotal',
2241     };
2242
2243     $report->add_data($row);
2244   }
2245
2246   $report->add_separator();
2247
2248   my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
2249   $row->{paid} = {
2250     'data'  => $form->format_amount(\%myconfig, $total_paid, 2),
2251     'align' => 'right',
2252     'class' => 'listtotal',
2253   };
2254
2255   $report->add_data($row);
2256
2257   $report->generate_with_headers();
2258
2259   $lxdebug->leave_sub();
2260 }
2261
2262 sub config {
2263   $lxdebug->enter_sub();
2264   edit();
2265
2266   #$form->header;
2267   #print qq|Hallo|;
2268   $lxdebug->leave_sub();
2269 }
2270
2271 sub debug {
2272
2273   $form->debug();
2274
2275 }
2276
2277 sub winston_export {
2278   $lxdebug->enter_sub();
2279
2280   #create_winston();
2281   $form->{winston} = 1;
2282   &generate_ustva();
2283   $lxdebug->leave_sub();
2284 }
2285
2286 sub print_options {
2287   $lxdebug->enter_sub();
2288
2289   my ($dont_print) = @_;
2290
2291   $form->{sendmode} = "attachment";
2292
2293   $form->{"format"} =
2294     $form->{"format"} ? $form->{"format"} :
2295     $myconfig{"template_format"} ? $myconfig{"template_format"} :
2296     "pdf";
2297
2298   $form->{"copies"} =
2299     $form->{"copies"} ? $form->{"copies"} :
2300     $myconfig{"copies"} ? $myconfig{"copies"} :
2301     2;
2302
2303   $form->{PD}{ $form->{type} }     = "selected";
2304   $form->{DF}{ $form->{format} }   = "selected";
2305   $form->{OP}{ $form->{media} }    = "selected";
2306   $form->{SM}{ $form->{sendmode} } = "selected";
2307
2308   if ($form->{report} eq 'ustva') {
2309     $type = qq|
2310             <option value=ustva $form->{PD}{ustva}>| . $locale->text('ustva');
2311   } else {
2312     $type = qq|
2313             <option value=statement $form->{PD}{statement}>|
2314       . $locale->text('Statement');
2315   }
2316
2317   if ($form->{media} eq 'email') {
2318     $media = qq|
2319             <option value=attachment $form->{SM}{attachment}>|
2320       . $locale->text('Attachment') . qq|
2321             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2322   } else {
2323     $media = qq|
2324             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2325     if ($myconfig{printer} && $latex_templates) {
2326       $media .= qq|
2327             <option value=printer $form->{OP}{printer}>|
2328         . $locale->text('Printer');
2329     }
2330   }
2331
2332   if ($latex_templates) {
2333     $format .= qq|
2334             <option value=html $form->{DF}{html}>|
2335       . $locale->text('HTML') . qq|
2336             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
2337     if ($form->{report} ne 'ustva') {
2338       $format . qq|
2339             <option value=postscript $form->{DF}{postscript}>|
2340         . $locale->text('Postscript');
2341     }
2342   }
2343
2344   my $output = qq|
2345 <table>
2346   <tr>
2347     <td><select name=type>$type</select></td>
2348     <td><select name=format>$format</select></td>
2349     <td><select name=media>$media</select></td>
2350 |;
2351
2352   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2353     $output .= qq|
2354       <td>| . $locale->text('Copies') . qq|
2355       <input name=copies size=2 value=$form->{copies}></td>
2356 |;
2357   }
2358
2359   $output .= qq|
2360   </tr>
2361 </table>
2362 |;
2363
2364   print $output unless $dont_print;
2365
2366   $lxdebug->leave_sub();
2367
2368   return $output;
2369 }
2370
2371 sub generate_bwa {
2372   $lxdebug->enter_sub();
2373   $form->{padding} = "&nbsp;&nbsp;";
2374   $form->{bold}    = "<b>";
2375   $form->{endbold} = "</b>";
2376   $form->{br}      = "<br>";
2377
2378   if ($form->{reporttype} eq "custom") {
2379
2380     #forgotten the year --> thisyear
2381     if ($form->{year} !~ m/^\d\d\d\d$/) {
2382       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2383         /(\d\d\d\d)/;
2384       $form->{year} = $1;
2385     }
2386
2387     #yearly report
2388     if ($form->{duetyp} eq "13") {
2389       $form->{fromdate}        = "1.1.$form->{year}";
2390       $form->{todate}          = "31.12.$form->{year}";
2391       $form->{comparefromdate} = "1.01.$form->{year}";
2392       $form->{comparetodate}   = "31.12.$form->{year}";
2393     }
2394
2395     #Quater reports
2396     if ($form->{duetyp} eq "A") {
2397       $form->{fromdate}        = "1.1.$form->{year}";
2398       $form->{todate}          = "31.3.$form->{year}";
2399       $form->{comparefromdate} = "1.01.$form->{year}";
2400       $form->{comparetodate}   = "31.03.$form->{year}";
2401     }
2402     if ($form->{duetyp} eq "B") {
2403       $form->{fromdate}        = "1.4.$form->{year}";
2404       $form->{todate}          = "30.6.$form->{year}";
2405       $form->{comparefromdate} = "1.01.$form->{year}";
2406       $form->{comparetodate}   = "30.06.$form->{year}";
2407     }
2408     if ($form->{duetyp} eq "C") {
2409       $form->{fromdate}        = "1.7.$form->{year}";
2410       $form->{todate}          = "30.9.$form->{year}";
2411       $form->{comparefromdate} = "1.01.$form->{year}";
2412       $form->{comparetodate}   = "30.09.$form->{year}";
2413     }
2414     if ($form->{duetyp} eq "D") {
2415       $form->{fromdate}        = "1.10.$form->{year}";
2416       $form->{todate}          = "31.12.$form->{year}";
2417       $form->{comparefromdate} = "1.01.$form->{year}";
2418       $form->{comparetodate}   = "31.12.$form->{year}";
2419     }
2420
2421     #Monthly reports
2422   SWITCH: {
2423       $form->{duetyp} eq "1" && do {
2424         $form->{fromdate}        = "1.1.$form->{year}";
2425         $form->{todate}          = "31.1.$form->{year}";
2426         $form->{comparefromdate} = "1.01.$form->{year}";
2427         $form->{comparetodate}   = "31.01.$form->{year}";
2428         last SWITCH;
2429       };
2430       $form->{duetyp} eq "2" && do {
2431         $form->{fromdate} = "1.2.$form->{year}";
2432
2433         #this works from 1901 to 2099, 1900 and 2100 fail.
2434         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2435         $form->{todate}          = "$leap.2.$form->{year}";
2436         $form->{comparefromdate} = "1.01.$form->{year}";
2437         $form->{comparetodate}   = "$leap.02.$form->{year}";
2438         last SWITCH;
2439       };
2440       $form->{duetyp} eq "3" && do {
2441         $form->{fromdate}        = "1.3.$form->{year}";
2442         $form->{todate}          = "31.3.$form->{year}";
2443         $form->{comparefromdate} = "1.01.$form->{year}";
2444         $form->{comparetodate}   = "31.03.$form->{year}";
2445         last SWITCH;
2446       };
2447       $form->{duetyp} eq "4" && do {
2448         $form->{fromdate}        = "1.4.$form->{year}";
2449         $form->{todate}          = "30.4.$form->{year}";
2450         $form->{comparefromdate} = "1.01.$form->{year}";
2451         $form->{comparetodate}   = "30.04.$form->{year}";
2452         last SWITCH;
2453       };
2454       $form->{duetyp} eq "5" && do {
2455         $form->{fromdate}        = "1.5.$form->{year}";
2456         $form->{todate}          = "31.5.$form->{year}";
2457         $form->{comparefromdate} = "1.01.$form->{year}";
2458         $form->{comparetodate}   = "31.05.$form->{year}";
2459         last SWITCH;
2460       };
2461       $form->{duetyp} eq "6" && do {
2462         $form->{fromdate}        = "1.6.$form->{year}";
2463         $form->{todate}          = "30.6.$form->{year}";
2464         $form->{comparefromdate} = "1.01.$form->{year}";
2465         $form->{comparetodate}   = "30.06.$form->{year}";
2466         last SWITCH;
2467       };
2468       $form->{duetyp} eq "7" && do {
2469         $form->{fromdate}        = "1.7.$form->{year}";
2470         $form->{todate}          = "31.7.$form->{year}";
2471         $form->{comparefromdate} = "1.01.$form->{year}";
2472         $form->{comparetodate}   = "31.07.$form->{year}";
2473         last SWITCH;
2474       };
2475       $form->{duetyp} eq "8" && do {
2476         $form->{fromdate}        = "1.8.$form->{year}";
2477         $form->{todate}          = "31.8.$form->{year}";
2478         $form->{comparefromdate} = "1.01.$form->{year}";
2479         $form->{comparetodate}   = "31.08.$form->{year}";
2480         last SWITCH;
2481       };
2482       $form->{duetyp} eq "9" && do {
2483         $form->{fromdate}        = "1.9.$form->{year}";
2484         $form->{todate}          = "30.9.$form->{year}";
2485         $form->{comparefromdate} = "1.01.$form->{year}";
2486         $form->{comparetodate}   = "30.09.$form->{year}";
2487         last SWITCH;
2488       };
2489       $form->{duetyp} eq "10" && do {
2490         $form->{fromdate}        = "1.10.$form->{year}";
2491         $form->{todate}          = "31.10.$form->{year}";
2492         $form->{comparefromdate} = "1.01.$form->{year}";
2493         $form->{comparetodate}   = "31.10.$form->{year}";
2494         last SWITCH;
2495       };
2496       $form->{duetyp} eq "11" && do {
2497         $form->{fromdate}        = "1.11.$form->{year}";
2498         $form->{todate}          = "30.11.$form->{year}";
2499         $form->{comparefromdate} = "1.01.$form->{year}";
2500         $form->{comparetodate}   = "30.11.$form->{year}";
2501         last SWITCH;
2502       };
2503       $form->{duetyp} eq "12" && do {
2504         $form->{fromdate}        = "1.12.$form->{year}";
2505         $form->{todate}          = "31.12.$form->{year}";
2506         $form->{comparefromdate} = "1.01.$form->{year}";
2507         $form->{comparetodate}   = "31.12.$form->{year}";
2508         last SWITCH;
2509       };
2510     }
2511   } else {
2512     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2513     $form->{fromdate} = "${dd}.${mm}.${yy}";
2514     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2515     $form->{todate}          = "${dd}.${mm}.${yy}";
2516     $form->{comparefromdate} = "01.01.$yy";
2517     $form->{comparetodate}   = $form->{todate};
2518   }
2519
2520   RP->bwa(\%myconfig, \%$form);
2521
2522   ($form->{department}) = split /--/, $form->{department};
2523
2524   $form->{period} =
2525     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2526   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2527
2528   # if there are any dates construct a where
2529   if ($form->{fromdate} || $form->{todate}) {
2530
2531     unless ($form->{todate}) {
2532       $form->{todate} = $form->current_date(\%myconfig);
2533     }
2534
2535     my %germandate = ("dateformat" => "dd.mm.yyyy");
2536
2537     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
2538     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2539
2540     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
2541     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2542
2543     $form->{this_period} = "$shortfromdate\n$shorttodate";
2544     $form->{period}      =
2545         $locale->text('for Period')
2546       . qq|\n$longfromdate |
2547       . $locale->text('bis')
2548       . qq| $longtodate|;
2549   }
2550
2551   # setup variables for the form
2552   @a = qw(company address businessnumber);
2553   map { $form->{$_} = $myconfig{$_} } @a;
2554   $form->{templates} = $myconfig{templates};
2555
2556   $form->{IN} = "bwa.html";
2557
2558   $form->parse_template;
2559
2560   $lxdebug->leave_sub();
2561 }
2562
2563 sub generate_ustva {
2564   $lxdebug->enter_sub();
2565
2566   # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
2567   USTVA->get_config($userspath, 'finanzamt.ini');
2568
2569   #  &get_project(generate_bwa);
2570   @anmeldungszeitraum =
2571     qw(0401, 0402, 0403, 0404, 0405, 0405, 0406, 0407, 0408, 0409, 0410, 0411, 0412, 0441, 0442, 0443, 0444);
2572
2573   foreach $item (@anmeldungszeitraum) {
2574     $form->{$item} = "";
2575   }
2576   if ($form->{reporttype} eq "custom") {
2577
2578     #forgotten the year --> thisyear
2579     if ($form->{year} !~ m/^\d\d\d\d$/) {
2580       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2581         /(\d\d\d\d)/;
2582       $form->{year} = $1;
2583     }
2584
2585     #yearly report
2586     if ($form->{duetyp} eq "13") {
2587       $form->{fromdate} = "1.1.$form->{year}";
2588       $form->{todate}   = "31.12.$form->{year}";
2589     }
2590
2591     #Quater reports
2592     if ($form->{duetyp} eq "A") {
2593       $form->{fromdate} = "1.1.$form->{year}";
2594       $form->{todate}   = "31.3.$form->{year}";
2595       $form->{"0441"}   = "X";
2596     }
2597     if ($form->{duetyp} eq "B") {
2598       $form->{fromdate} = "1.4.$form->{year}";
2599       $form->{todate}   = "30.6.$form->{year}";
2600       $form->{"0442"}   = "X";
2601     }
2602     if ($form->{duetyp} eq "C") {
2603       $form->{fromdate} = "1.7.$form->{year}";
2604       $form->{todate}   = "30.9.$form->{year}";
2605       $form->{"0443"}   = "X";
2606     }
2607     if ($form->{duetyp} eq "D") {
2608       $form->{fromdate} = "1.10.$form->{year}";
2609       $form->{todate}   = "31.12.$form->{year}";
2610       $form->{"0444"}   = "X";
2611     }
2612
2613     #Monthly reports
2614   SWITCH: {
2615       $form->{duetyp} eq "1" && do {
2616         $form->{fromdate} = "1.1.$form->{year}";
2617         $form->{todate}   = "31.1.$form->{year}";
2618         $form->{"0401"}   = "X";
2619         last SWITCH;
2620       };
2621       $form->{duetyp} eq "2" && do {
2622         $form->{fromdate} = "1.2.$form->{year}";
2623
2624         #this works from 1901 to 2099, 1900 and 2100 fail.
2625         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2626         $form->{todate} = "$leap.2.$form->{year}";
2627         $form->{"0402"} = "X";
2628         last SWITCH;
2629       };
2630       $form->{duetyp} eq "3" && do {
2631         $form->{fromdate} = "1.3.$form->{year}";
2632         $form->{todate}   = "31.3.$form->{year}";
2633         $form->{"0403"}   = "X";
2634         last SWITCH;
2635       };
2636       $form->{duetyp} eq "4" && do {
2637         $form->{fromdate} = "1.4.$form->{year}";
2638         $form->{todate}   = "30.4.$form->{year}";
2639         $form->{"0404"}   = "X";
2640         last SWITCH;
2641       };
2642       $form->{duetyp} eq "5" && do {
2643         $form->{fromdate} = "1.5.$form->{year}";
2644         $form->{todate}   = "31.5.$form->{year}";
2645         $form->{"0405"}   = "X";
2646         last SWITCH;
2647       };
2648       $form->{duetyp} eq "6" && do {
2649         $form->{fromdate} = "1.6.$form->{year}";
2650         $form->{todate}   = "30.6.$form->{year}";
2651         $form->{"0406"}   = "X";
2652         last SWITCH;
2653       };
2654       $form->{duetyp} eq "7" && do {
2655         $form->{fromdate} = "1.7.$form->{year}";
2656         $form->{todate}   = "31.7.$form->{year}";
2657         $form->{"0407"}   = "X";
2658         last SWITCH;
2659       };
2660       $form->{duetyp} eq "8" && do {
2661         $form->{fromdate} = "1.8.$form->{year}";
2662         $form->{todate}   = "31.8.$form->{year}";
2663         $form->{"0408"}   = "X";
2664         last SWITCH;
2665       };
2666       $form->{duetyp} eq "9" && do {
2667         $form->{fromdate} = "1.9.$form->{year}";
2668         $form->{todate}   = "30.9.$form->{year}";
2669         $form->{"0409"}   = "X";
2670         last SWITCH;
2671       };
2672       $form->{duetyp} eq "10" && do {
2673         $form->{fromdate} = "1.10.$form->{year}";
2674         $form->{todate}   = "31.10.$form->{year}";
2675         $form->{"0410"}   = "X";
2676         last SWITCH;
2677       };
2678       $form->{duetyp} eq "11" && do {
2679         $form->{fromdate} = "1.11.$form->{year}";
2680         $form->{todate}   = "30.11.$form->{year}";
2681         $form->{"0411"}   = "X";
2682         last SWITCH;
2683       };
2684       $form->{duetyp} eq "12" && do {
2685         $form->{fromdate} = "1.12.$form->{year}";
2686         $form->{todate}   = "31.12.$form->{year}";
2687         $form->{"0412"}   = "X";
2688         last SWITCH;
2689       };
2690     }
2691   }
2692
2693   #    $locale->date(\%myconfig, $form->current_date(\%myconfig), 0)=~ /(\d\d\d\d)/;
2694   #    $form->{year}= $1;
2695   #    $form->{fromdate}="1.1.$form->{year}";
2696   #    $form->{todate}="31.3.$form->{year}";
2697   #    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2698   #  }
2699
2700   RP->ustva(\%myconfig, \%$form);
2701
2702   ($form->{department}) = split /--/, $form->{department};
2703
2704   $form->{period} =
2705     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2706   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2707
2708   # if there are any dates construct a where
2709   if ($form->{fromdate} || $form->{todate}) {
2710
2711     unless ($form->{todate}) {
2712       $form->{todate} = $form->current_date(\%myconfig);
2713     }
2714
2715     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
2716     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
2717
2718     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
2719     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
2720
2721     $form->{this_period} = "$shortfromdate\n$shorttodate";
2722     $form->{period}      =
2723         $locale->text('for Period')
2724       . qq|<br>\n$longfromdate |
2725       . $locale->text('bis')
2726       . qq| $longtodate|;
2727   }
2728
2729   if ($form->{comparefromdate} || $form->{comparetodate}) {
2730     $longcomparefromdate =
2731       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
2732     $shortcomparefromdate =
2733       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
2734
2735     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
2736     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
2737
2738     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
2739     $form->{period} .=
2740         "\n$longcomparefromdate "
2741       . $locale->text('bis')
2742       . qq| $longcomparetodate|;
2743   }
2744
2745   $form->{Datum_heute} =
2746     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
2747
2748   if (   $form->{format} eq 'pdf'
2749       or $form->{format} eq 'postscript') {
2750     $form->{padding} = "~~";
2751     $form->{bold}    = "\textbf{";
2752     $form->{endbold} = "}";
2753     $form->{br}      = '\\\\';
2754
2755     @numbers = qw(51r 86r 97r 93r 96 43 45
2756       66 62 67);
2757     foreach $number (@numbers) {
2758       $form->{$number} =~ s/,/~~/g;
2759     }
2760
2761       } elsif ($form->{format} eq 'html') {
2762     $form->{padding} = "&nbsp;&nbsp;";
2763     $form->{bold}    = "<b>";
2764     $form->{endbold} = "</b>";
2765     $form->{br}      = "<br>"
2766
2767   }
2768
2769   # setup variables for the form
2770   @a = qw(company address businessnumber);
2771   map { $form->{$_} = $myconfig{$_} } @a;
2772
2773   $form->{address} =~ s/\\n/$form->{br}/g;
2774
2775   if ($form->{winston} eq '1') {
2776     create_winston();
2777
2778   } else {
2779     $form->{templates} = $myconfig{templates};
2780     $form->{IN}        = "$form->{type}";
2781     $form->{IN} .= '.tex'
2782       if (   $form->{format} eq 'pdf'
2783           or $form->{format} eq 'postscript');
2784     $form->{IN} .= '.html' if ($form->{format} eq 'html');
2785
2786     $form->parse_template(\%myconfig, $userspath);
2787
2788     # $form->parse_template;
2789   }
2790   $lxdebug->leave_sub();
2791 }