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