a496faa9114ee88ffcfc69aa5d0d565a7fb5edc9
[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
44 1;
45
46 # end of main
47
48 # this is for our long dates
49 # $locale->text('January')
50 # $locale->text('February')
51 # $locale->text('March')
52 # $locale->text('April')
53 # $locale->text('May ')
54 # $locale->text('June')
55 # $locale->text('July')
56 # $locale->text('August')
57 # $locale->text('September')
58 # $locale->text('October')
59 # $locale->text('November')
60 # $locale->text('December')
61
62 # this is for our short month
63 # $locale->text('Jan')
64 # $locale->text('Feb')
65 # $locale->text('Mar')
66 # $locale->text('Apr')
67 # $locale->text('May')
68 # $locale->text('Jun')
69 # $locale->text('Jul')
70 # $locale->text('Aug')
71 # $locale->text('Sep')
72 # $locale->text('Oct')
73 # $locale->text('Nov')
74 # $locale->text('Dec')
75
76 # $locale->text('Balance Sheet')
77 # $locale->text('Income Statement')
78 # $locale->text('Trial Balance')
79 # $locale->text('AR Aging')
80 # $locale->text('AP Aging')
81 # $locale->text('Tax collected')
82 # $locale->text('Tax paid')
83 # $locale->text('Receipts')
84 # $locale->text('Payments')
85 # $locale->text('Project Transactions')
86 # $locale->text('Non-taxable Sales')
87 # $locale->text('Non-taxable Purchases')
88
89 sub report {
90   $lxdebug->enter_sub();
91
92   %title = ('balance_sheet'        => 'Balance Sheet',
93             'income_statement'     => 'Income Statement',
94             'trial_balance'        => 'Trial Balance',
95             'ar_aging'             => 'AR Aging',
96             'ap_aging'             => 'Offene Verbindlichkeiten',
97             'tax_collected'        => 'Tax collected',
98             'tax_paid'             => 'Tax paid',
99             'nontaxable_sales'     => 'Non-taxable Sales',
100             'nontaxable_purchases' => 'Non-taxable Purchases',
101             'receipts'             => 'Receipts',
102             'payments'             => 'Payments',
103             'projects'             => 'Project Transactions',
104             'bwa'                  => 'Betriebswirtschaftliche Auswertung',
105             'ustva'                => 'Umsatzsteuervoranmeldung',);
106
107   $form->{title} = $locale->text($title{ $form->{report} });
108
109   $accrual = ($eur) ? ""        : "checked";
110   $cash    = ($eur) ? "checked" : "";
111
112   ($null, $null, $null, $null, $null, $year, $null, $null, $null) =
113     localtime();
114   $year += 1900;
115
116   # get departments
117   $form->all_departments(\%myconfig);
118   if (@{ $form->{all_departments} }) {
119     $form->{selectdepartment} = "<option>\n";
120
121     map {
122       $form->{selectdepartment} .=
123         "<option>$_->{description}--$_->{id}\n"
124     } (@{ $form->{all_departments} });
125   }
126
127   $department = qq|
128         <tr>
129           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
130           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
131         </tr>
132 | if $form->{selectdepartment};
133
134   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
135                                    "all" => 1 });
136
137   my %project_labels = ();
138   my @project_values = ("");
139   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
140     push(@project_values, $item->{"id"});
141     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
142   }
143
144   my $projectnumber =
145     NTI($cgi->popup_menu('-name' => "project_id",
146                          '-values' => \@project_values,
147                          '-labels' => \%project_labels));
148
149   # use JavaScript Calendar or not
150   $form->{jsscript} = $jscalendar;
151   $jsscript = "";
152   if ($form->{report} eq "ustva") {
153     $department = "";
154   } else {
155     if ($form->{report} eq "balance_sheet") {
156       $name_1    = "asofdate";
157       $id_1      = "asofdate";
158       $value_1   = "$form->{asofdate}";
159       $trigger_1 = "trigger1";
160       $name_2    = "compareasofdate";
161       $id_2      = "compareasofdate";
162       $value_2   = "$form->{compareasofdate}";
163       $trigger_2 = "trigger2";
164     } elsif ($form->{report} =~ /(receipts|payments)$/) {
165       $name_1    = "fromdate";
166       $id_1      = "fromdate";
167       $value_1   = "$form->{fromdate}";
168       $trigger_1 = "trigger1";
169       $name_2    = "todate";
170       $id_2      = "todate";
171       $value_2   = "";
172       $trigger_2 = "trigger2";
173     } else {
174       if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
175         $name_1    = "";
176         $id_1      = "";
177         $value_1   = "";
178         $trigger_1 = "";
179         $name_2    = "todate";
180         $id_2      = "todate";
181         $value_2   = "";
182         $trigger_2 = "trigger2";
183
184       } else {
185         $name_1    = "fromdate";
186         $id_1      = "fromdate";
187         $value_1   = "$form->{fromdate}";
188         $trigger_1 = "trigger1";
189         $name_2    = "todate";
190         $id_2      = "todate";
191         $value_2   = "";
192         $trigger_2 = "trigger2";
193       }
194     }
195   }
196
197   # with JavaScript Calendar
198   if ($form->{jsscript}) {
199     if ($name_1 eq "") {
200
201       $button1 = qq|
202          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}">|;
203       $button1_2 = qq|
204         <input type=button name=$name_2 id="$trigger_2" value=|
205         . $locale->text('button') . qq|>|;
206
207       #write Trigger
208       $jsscript =
209         Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
210     } else {
211       $button1 = qq|
212          <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1>|;
213       $button1_2 = qq|
214         <input type=button name=$name_1 id="$trigger_1" value=|
215         . $locale->text('button') . qq|>|;
216       $button2 = qq|
217          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}">|;
218       $button2_2 = qq|
219          <input type=button name=$name_2 id="$trigger_2" value=|
220         . $locale->text('button') . qq|>
221        |;
222
223       #write Trigger
224       $jsscript =
225         Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
226                             "$name_2", "BL", "$trigger_2");
227     }
228   } else {
229
230     # without JavaScript Calendar
231     if ($name_1 eq "") {
232       $button1 =
233         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}">|;
234     } else {
235       $button1 =
236         qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1>|;
237       $button2 =
238         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}">|;
239     }
240   }
241
242   $form->header;
243
244   print qq|
245 <body>
246
247 <form method=post action=$form->{script}>
248
249 <input type=hidden name=title value="$form->{title}">
250
251 <table width=100%>
252   <tr>
253     <th class=listtop>$form->{title}</th>
254   </tr>
255   <tr height="5"></tr>
256   <tr>
257     <td>
258       <table>
259       $department
260 |;
261
262   if ($form->{report} eq "projects") {
263     print qq|
264         <tr>
265           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
266           <td colspan=5><input name=projectnumber size=25</td>
267         </tr>
268         <input type=hidden name=nextsub value=generate_projects>
269         <tr>
270           <th align=right>| . $locale->text('From') . qq|</th>
271           <td>$button1</td>
272           <td>$button1_2</td>
273           <th align=right>| . $locale->text('Bis') . qq|</th>
274           <td>$button2</td>
275           <td>$button2_2</td>
276         </tr>
277       </table>
278     </td>
279   </tr>
280   <tr>
281     <td>
282       <table>
283         <tr>
284           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
285           <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
286       . $locale->text('Heading') . qq|
287           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
288       . $locale->text('Subtotal') . qq|</td>
289         </tr>
290
291 $jsscript
292 |;
293   }
294
295   if ($form->{report} eq "income_statement") {
296     print qq|
297         <tr>
298           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
299           <td colspan=3>$projectnumber</td>
300         </tr>
301         <input type=hidden name=nextsub value=generate_income_statement>
302 </table>
303 <table>
304         <tr>
305           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
306       . $locale->text('Customized Report') . qq|</th>
307         </tr>
308         <tr>
309           <th colspan=1>| . $locale->text('Year') . qq|</th>
310           <td><input name=year size=11 title="|
311       . $locale->text('YYYY') . qq|" value="$year"></td>
312         </tr>
313 |;
314
315     print qq|
316         <tr>
317                 <td align=right>
318 <b> | . $locale->text('Yearly') . qq|</b> </td>
319                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
320                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
321         </tr>
322         <tr>
323                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
324 "checked"></td>
325                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
326       . $locale->text('Quarter') . qq|</td>
327 |;
328     $checked = "";
329     print qq|
330                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
331       . $locale->text('January') . qq|</td>
332 |;
333     $checked = "";
334     print qq|
335                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
336       . $locale->text('May') . qq|</td>
337                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
338       . $locale->text('September') . qq|</td>
339
340         </tr>
341         <tr>
342                 <td align= right>&nbsp;</td>
343                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
344       . $locale->text('Quarter') . qq|</td>
345                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
346       . $locale->text('February') . qq|</td>
347                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
348       . $locale->text('June') . qq|</td>
349                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
350       . $locale->text('October') . qq|</td>
351         </tr>
352         <tr>
353                 <td> &nbsp;</td>
354                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
355       . $locale->text('Quarter') . qq|</td>
356                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
357       . $locale->text('March') . qq|</td>
358                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
359       . $locale->text('July') . qq|</td>
360                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
361       . $locale->text('November') . qq|</td>
362
363         </tr>
364         <tr>
365                 <td> &nbsp;</td>
366                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
367       . $locale->text('Quarter') . qq|&nbsp;</td>
368                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
369       . $locale->text('April') . qq|</td>
370                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
371       . $locale->text('August') . qq|</td>
372                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
373       . $locale->text('December') . qq|</td>
374
375         </tr>
376         <tr>
377                 <td colspan=5><hr size=3 noshade></td>
378         </tr>
379         <tr>
380           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
381       . $locale->text('Free report period') . qq|</th>
382           <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
383               $button1
384               $button1_2&nbsp;
385               | . $locale->text('Bis') . qq|
386               $button2
387               $button2_2&nbsp;
388           </td>
389         </tr>
390         <tr>
391                 <td colspan=5><hr size=3 noshade></td>
392         </tr>
393         <tr>
394           <th align=leftt>| . $locale->text('Method') . qq|</th>
395           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
396       . $locale->text('Accrual') . qq|
397           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
398       . $locale->text('EUR') . qq|</td>
399         </tr>
400
401 $jsscript
402 |;
403   }
404
405   if ($form->{report} eq "bwa") {
406     print qq|
407         <tr>
408           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
409           <td colspan=3>$projectnumber</td>
410         </tr>
411         <input type=hidden name=nextsub value=generate_bwa>
412 </table>
413 <table>
414         <tr>
415           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
416       . $locale->text('Customized Report') . qq|</th>
417         </tr>
418         <tr>
419           <th colspan=1>| . $locale->text('Year') . qq|</th>
420           <td><input name=year size=11 title="|
421       . $locale->text('YYYY') . qq|" value="$year"></td>
422         </tr>
423 |;
424
425     print qq|
426         <tr>
427                 <td align=right>
428 <b> | . $locale->text('Yearly') . qq|</b> </td>
429                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
430                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
431         </tr>
432         <tr>
433                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
434 $checked></td>
435                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
436       . $locale->text('Quarter') . qq|</td>
437 |;
438     $checked = "checked";
439     print qq|
440                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
441       . $locale->text('January') . qq|</td>
442 |;
443     $checked = "";
444     print qq|
445                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
446       . $locale->text('May') . qq|</td>
447                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
448       . $locale->text('September') . qq|</td>
449
450         </tr>
451         <tr>
452                 <td align= right>&nbsp;</td>
453                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
454       . $locale->text('Quarter') . qq|</td>
455                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
456       . $locale->text('February') . qq|</td>
457                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
458       . $locale->text('June') . qq|</td>
459                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
460       . $locale->text('October') . qq|</td>
461         </tr>
462         <tr>
463                 <td> &nbsp;</td>
464                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
465       . $locale->text('Quarter') . qq|</td>
466                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
467       . $locale->text('March') . qq|</td>
468                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
469       . $locale->text('July') . qq|</td>
470                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
471       . $locale->text('November') . qq|</td>
472
473         </tr>
474         <tr>
475                 <td> &nbsp;</td>
476                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
477       . $locale->text('Quarter') . qq|&nbsp;</td>
478                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
479       . $locale->text('April') . qq|</td>
480                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
481       . $locale->text('August') . qq|</td>
482                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
483       . $locale->text('December') . qq|</td>
484
485         </tr>
486         <tr>
487                 <td colspan=5><hr size=3 noshade></td>
488         </tr>
489         <tr>
490           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
491       . $locale->text('Free report period') . qq|</th>
492           <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
493               $button1
494               $button1_2&nbsp;
495               | . $locale->text('Bis') . qq|&nbsp;
496               $button2
497               $button2_2
498           </td>
499         </tr>
500         <tr>
501                 <td colspan=5><hr size=3 noshade></td>
502         </tr>
503         <tr>
504           <th align=leftt>| . $locale->text('Method') . qq|</th>
505           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
506       . $locale->text('Accrual') . qq|
507           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
508       . $locale->text('EUR') . qq|</td>
509         </tr>
510         <tr>
511          <th align=right colspan=4>|
512       . $locale->text('Decimalplaces')
513       . qq|</th>
514              <td><input name=decimalplaces size=3 value="2"></td>
515          </tr>
516                                     
517 $jsscript
518 |;
519   }
520
521   if ($form->{report} eq "ustva") {
522
523     print qq|
524
525         <br>
526         <input type=hidden name=nextsub value=generate_ustva>
527 </table>
528 <table>
529         <tr>
530           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
531       . $locale->text('Zeitraum') . qq|</th>
532         </tr>
533         <tr>
534           <th colspan=1>| . $locale->text('Year') . qq|</th>
535           <td><input name=year size=11 title="|
536       . $locale->text('YYYY') . qq|" value="$year"></td>
537         </tr>
538 |;
539
540     print qq|
541         <tr>
542                 <td align=right>
543 <b> | . $locale->text('Yearly') . qq|</b> </td>
544                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
545                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
546         </tr>
547         <tr>
548                 <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
549 $checked></td>
550                 <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
551       . $locale->text('Quarter') . qq|</td>
552 |;
553     $checked = "checked";
554     print qq|
555                 <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
556       . $locale->text('January') . qq|</td>
557 |;
558     $checked = "";
559     print qq|
560                 <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
561       . $locale->text('May') . qq|</td>
562                 <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
563       . $locale->text('September') . qq|</td>
564
565         </tr>
566         <tr>
567                 <td align= right>&nbsp;</td>
568                 <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
569       . $locale->text('Quarter') . qq|</td>
570                 <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
571       . $locale->text('February') . qq|</td>
572                 <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
573       . $locale->text('June') . qq|</td>
574                 <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
575       . $locale->text('October') . qq|</td>
576         </tr>
577         <tr>
578                 <td> &nbsp;</td>
579                 <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
580       . $locale->text('Quarter') . qq|</td>
581                 <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
582       . $locale->text('March') . qq|</td>
583                 <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
584       . $locale->text('July') . qq|</td>
585                 <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
586       . $locale->text('November') . qq|</td>
587
588         </tr>
589         <tr>
590                 <td> &nbsp;</td>
591                 <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
592       . $locale->text('Quarter') . qq|&nbsp;</td>
593                 <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
594       . $locale->text('April') . qq|</td>
595                 <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
596       . $locale->text('August') . qq|</td>
597                 <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
598       . $locale->text('December') . qq|</td>
599
600         </tr>
601         <tr>
602                 <td colspan=5><hr size=3 noshade></td>
603         </tr>
604         <tr>
605           <th align=left>| . $locale->text('Method') . qq|</th>
606           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
607       . $locale->text('Accrual') . qq|
608           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
609       . $locale->text('EUR') . qq|</td>
610         </tr>
611         <tr>
612           <th colspan=4>|;
613 ##########
614
615     &print_options();
616     print qq|
617           </th>
618         </tr>
619 |;
620   }
621
622   if ($form->{report} eq "balance_sheet") {
623     print qq|
624         <input type=hidden name=nextsub value=generate_balance_sheet>
625         <tr>
626           <th align=right>| . $locale->text('as at') . qq|</th>
627           <td>
628             $button1
629             $button1_2
630           </td>
631           <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
632           <td>
633           $button2
634           $button2_2
635           </td>
636         </tr>
637         <tr>
638           <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
639           <td><input name=decimalplaces size=3 value="2"></td>
640         </tr>
641       </table>
642     </td>
643   </tr>
644   <tr>
645     <td>
646       <table>
647         <tr>
648           <th align=right>| . $locale->text('Method') . qq|</th>
649           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
650       . $locale->text('Accrual') . qq|
651           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
652       . $locale->text('EUR') . qq|</td>
653         </tr>
654
655         <tr>
656           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
657           <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
658       . $locale->text('Heading') . qq|
659           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
660       . $locale->text('Subtotal') . qq|
661           <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|
662       . $locale->text('Account Number') . qq|</td>
663         </tr>
664
665 $jsscript
666 |;
667   }
668
669   if ($form->{report} eq "trial_balance") {
670     print qq|
671         <input type=hidden name=nextsub value=generate_trial_balance>
672         <input type=hidden name=eur value=$eur>
673        <tr>
674           <th align=right>| . $locale->text('From') . qq|</th>
675           <td>
676             $button1
677             $button1_2
678           </td>
679           <th align=right>| . $locale->text('Bis') . qq|</th>
680           <td>
681             $button2
682             $button2_2
683           </td>
684         </tr>
685       </table>
686     </td>
687   </tr>
688   <tr>
689     <td>
690       <table>
691         <tr>
692           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
693           <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
694       . $locale->text('Heading') . qq|
695           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
696       . $locale->text('Subtotal') . qq|
697           <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|
698       . $locale->text('All Accounts') . qq|</td>
699         </tr>
700
701 $jsscript
702 |;
703   }
704
705   if ($form->{report} =~ /^tax_/) {
706     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
707
708     RP->get_taxaccounts(\%myconfig, \%$form);
709
710     print qq|
711         <input type=hidden name=nextsub value=generate_tax_report>
712         <tr>
713           <th align=right>| . $locale->text('From') . qq|</th>
714           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
715           <th align=right>| . $locale->text('Bis') . qq|</th>
716           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
717         </tr>
718         <tr>
719           <th align=right>| . $locale->text('Report for') . qq|</th>
720           <td colspan=3>
721 |;
722
723     $checked = "checked";
724     foreach $ref (@{ $form->{taxaccounts} }) {
725
726       print
727         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
728
729     <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
730     <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
731
732       $checked = "";
733
734     }
735
736     print qq|
737   <input type=hidden name=db value=$form->{db}>
738   <input type=hidden name=sort value=transdate>
739
740           </td>
741         </tr>
742         <tr>
743           <th align=right>| . $locale->text('Method') . qq|</th>
744           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
745       . $locale->text('Accrual') . qq|
746           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
747       . $locale->text('EUR') . qq|</td>
748         </tr>
749       </table>
750     </td>
751   </tr>
752   <tr>
753     <td>
754       <table>
755         <tr>
756           <th align=right>| . $locale->text('Include in Report') . qq|</th>
757           <td>
758             <table>
759               <tr>
760                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
761                 <td>| . $locale->text('ID') . qq|</td>
762                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
763                 <td>| . $locale->text('Invoice') . qq|</td>
764                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
765                 <td>| . $locale->text('Date') . qq|</td>
766               </tr>
767               <tr>
768                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
769                 <td>|;
770
771     if ($form->{db} eq 'ar') {
772       print $locale->text('Customer');
773     }
774     if ($form->{db} eq 'ap') {
775       print $locale->text('Vendor');
776     }
777
778     print qq|</td>
779                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
780                 <td>| . $locale->text('Amount') . qq|</td>
781                 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
782                 <td>| . $locale->text('Tax') . qq|</td>
783                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
784                 <td>| . $locale->text('Total') . qq|</td>
785               </tr>
786               <tr>
787                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
788                 <td>| . $locale->text('Subtotal') . qq|</td>
789               </tr>
790             </table>
791           </td>
792         </tr>
793 |;
794
795   }
796
797   if ($form->{report} =~ /^nontaxable_/) {
798     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
799
800     print qq|
801         <input type=hidden name=nextsub value=generate_tax_report>
802
803         <input type=hidden name=db value=$form->{db}>
804         <input type=hidden name=sort value=transdate>
805         <input type=hidden name=report value=$form->{report}>
806
807         <tr>
808           <th align=right>| . $locale->text('From') . qq|</th>
809           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
810           <th align=right>| . $locale->text('Bis') . qq|</th>
811           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
812         </tr>
813         <tr>
814           <th align=right>| . $locale->text('Method') . qq|</th>
815           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
816       . $locale->text('Accrual') . qq|
817           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
818       . $locale->text('EUR') . qq|</td>
819         </tr>
820         <tr>
821           <th align=right>| . $locale->text('Include in Report') . qq|</th>
822           <td colspan=3>
823             <table>
824               <tr>
825                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
826                 <td>| . $locale->text('ID') . qq|</td>
827                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
828                 <td>| . $locale->text('Invoice') . qq|</td>
829                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
830                 <td>| . $locale->text('Date') . qq|</td>
831               </tr>
832               <tr>
833                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
834                 <td>|;
835
836     if ($form->{db} eq 'ar') {
837       print $locale->text('Customer');
838     }
839     if ($form->{db} eq 'ap') {
840       print $locale->text('Vendor');
841     }
842
843     print qq|</td>
844                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
845                 <td>| . $locale->text('Amount') . qq|</td>
846                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
847                 <td>| . $locale->text('Total') . qq|</td>
848               </tr>
849               <tr>
850                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
851                 <td>| . $locale->text('Subtotal') . qq|</td>
852               </tr>
853             </table>
854           </td>
855         </tr>
856 |;
857
858   }
859
860   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
861     if ($form->{report} eq 'ar_aging') {
862       $label = $locale->text('Customer');
863       $form->{vc} = 'customer';
864     } else {
865       $label = $locale->text('Vendor');
866       $form->{vc} = 'vendor';
867     }
868
869     $nextsub = "generate_$form->{report}";
870
871     # setup vc selection
872     $form->all_vc(\%myconfig, $form->{vc},
873                   ($form->{vc} eq 'customer') ? "AR" : "AP");
874
875     map { $vc .= "<option>$_->{name}--$_->{id}\n" }
876       @{ $form->{"all_$form->{vc}"} };
877
878     $vc =
879       ($vc)
880       ? qq|<select name=$form->{vc}><option>\n$vc</select>|
881       : qq|<input name=$form->{vc} size=35>|;
882
883     print qq|
884         <tr>
885           <th align=right>| . $locale->text($label) . qq|</th>
886           <td>$vc</td>
887         </tr>
888         <tr>
889           <th align=right>| . $locale->text('Bis') . qq|</th>
890           <td>
891             $button1
892             $button1_2
893           </td>
894         </tr>
895         <input type=hidden name=type value=statement>
896         <input type=hidden name=format value=html>
897         <input type=hidden name=media value=screen>
898
899         <input type=hidden name=nextsub value=$nextsub>
900         <input type=hidden name=action value=$nextsub>
901
902 $jsscript
903 |;
904   }
905
906   # above action can be removed if there is more than one input field
907
908   if ($form->{report} =~ /(receipts|payments)$/) {
909     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
910
911     RP->paymentaccounts(\%myconfig, \%$form);
912
913     $selection = "<option>\n";
914     foreach $ref (@{ $form->{PR} }) {
915       $paymentaccounts .= "$ref->{accno} ";
916       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
917     }
918
919     chop $paymentaccounts;
920
921     print qq|
922         <input type=hidden name=nextsub value=list_payments>
923         <tr>
924           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
925           <td colspan=3><select name=account>$selection</select>
926             <input type=hidden name=paymentaccounts value="$paymentaccounts">
927           </td>
928         </tr>
929         <tr>
930           <th align=right>| . $locale->text('Reference') . qq|</th>
931           <td colspan=3><input name=reference></td>
932         </tr>
933         <tr>
934           <th align=right nowrap>| . $locale->text('Source') . qq|</th>
935           <td colspan=3><input name=source></td>
936         </tr>
937         <tr>
938           <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
939           <td colspan=3><input name=memo size=30></td>
940         </tr>
941         <tr>
942           <th align=right>| . $locale->text('From') . qq|</th>
943           <td>
944             $button1
945             $button1_2
946           </td>
947           <th align=right>| . $locale->text('Bis') . qq|</th>
948           <td>
949             $button2
950             $button2_2
951           </td>
952         </tr>
953         <tr>
954           <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
955           <th align=left colspan=3>|
956       . $locale->text('Include Exchangerate Difference') . qq|</td>
957         </tr>
958
959 $jsscript
960
961           <input type=hidden name=db value=$form->{db}>
962           <input type=hidden name=sort value=transdate>
963 |;
964
965   }
966
967   print qq|
968
969       </table>
970     </td>
971   </tr>
972   <tr>
973     <td><hr size=3 noshade></td>
974   </tr>
975 </table>
976
977 <br>
978 <input type=hidden name=path value=$form->{path}>
979 <input type=hidden name=login value=$form->{login}>
980 <input type=hidden name=password value=$form->{password}>
981
982 <input type=submit class=submit name=action value="|
983     . $locale->text('Continue') . qq|">
984 |;
985
986   # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
987   # Einlesen der Finanzamtdaten
988   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 { &{ $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   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
2007
2008   $form->{templates} = "$myconfig{templates}";
2009
2010   $form->{IN} = "$form->{type}.html";
2011
2012   if ($form->{format} eq 'postscript') {
2013     $form->{postscript} = 1;
2014     $form->{IN} =~ s/html$/tex/;
2015   }
2016   if ($form->{format} eq 'pdf') {
2017     $form->{pdf} = 1;
2018     $form->{IN} =~ s/html$/tex/;
2019   }
2020
2021   $i = 0;
2022   while (@{ $form->{AG} }) {
2023
2024     $ref = shift @{ $form->{AG} };
2025
2026     if ($ctid != $ref->{ctid}) {
2027
2028       $ctid = $ref->{ctid};
2029       $i++;
2030
2031       if ($form->{"statement_$i"}) {
2032
2033         @a =
2034           (name, street, zipcode, city, country, contact, email,
2035            "$form->{ct}phone", "$form->{ct}fax");
2036         map { $form->{$_} = $ref->{$_} } @a;
2037
2038         $form->{ $form->{ct} } = $form->{name};
2039         $form->{"$form->{ct}_id"} = $ref->{ctid};
2040
2041         map { $form->{$_} = () } qw(invnumber invdate duedate);
2042         $form->{total} = 0;
2043         foreach $item (qw(c0 c30 c60 c90)) {
2044           $form->{$item} = ();
2045           $form->{"${item}total"} = 0;
2046         }
2047
2048         &statement_details($ref);
2049
2050         while ($ref) {
2051
2052           if (scalar(@{ $form->{AG} }) > 0) {
2053
2054             # one or more left to go
2055             if ($ctid == $form->{AG}->[0]->{ctid}) {
2056               $ref = shift @{ $form->{AG} };
2057               &statement_details($ref);
2058
2059               # any more?
2060               $ref = scalar(@{ $form->{AG} });
2061             } else {
2062               $ref = 0;
2063             }
2064           } else {
2065
2066             # set initial ref to 0
2067             $ref = 0;
2068           }
2069
2070         }
2071
2072         map {
2073           $form->{"${_}total"} =
2074             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2075         } (c0, c30, c60, c90, "");
2076
2077         $form->parse_template(\%myconfig, $userspath);
2078
2079       }
2080     }
2081   }
2082   # saving the history
2083   if(!exists $form->{addition} && $form->{id} ne "") {
2084         $form->{addition} = "PRINTED";
2085         $form->{what_done} = $form->{type};
2086         $form->save_history($form->dbconnect(\%myconfig));
2087   }
2088   # /saving the history 
2089   $lxdebug->leave_sub();
2090 }
2091
2092 sub statement_details {
2093   $lxdebug->enter_sub();
2094   my ($ref) = @_;
2095
2096   push @{ $form->{invnumber} }, $ref->{invnumber};
2097   push @{ $form->{invdate} },   $ref->{transdate};
2098   push @{ $form->{duedate} },   $ref->{duedate};
2099
2100   foreach $item (qw(c0 c30 c60 c90)) {
2101     if ($ref->{exchangerate} * 1) {
2102       $ref->{$item} =
2103         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2104     }
2105     $form->{"${item}total"} += $ref->{$item};
2106     $form->{total}          += $ref->{$item};
2107     push @{ $form->{$item} },
2108       $form->format_amount(\%myconfig, $ref->{$item}, 2);
2109   }
2110
2111   $lxdebug->leave_sub();
2112 }
2113
2114 sub generate_tax_report {
2115   $lxdebug->enter_sub();
2116
2117   RP->tax_report(\%myconfig, \%$form);
2118
2119   $descvar     = "$form->{accno}_description";
2120   $description = $form->escape($form->{$descvar});
2121   $ratevar     = "$form->{accno}_rate";
2122
2123   $department = $form->escape($form->{department});
2124
2125   # construct href
2126   $href =
2127     "$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}";
2128
2129   # construct callback
2130   $description = $form->escape($form->{$descvar},   1);
2131   $department  = $form->escape($form->{department}, 1);
2132   $callback    =
2133     "$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}";
2134
2135   $title = $form->escape($form->{title});
2136   $href .= "&title=$title";
2137   $title = $form->escape($form->{title}, 1);
2138   $callback .= "&title=$title";
2139
2140   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2141
2142   @columns =
2143     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2144
2145   foreach $item (@columns) {
2146     if ($form->{"l_$item"} eq "Y") {
2147       push @column_index, $item;
2148
2149       # add column to href and callback
2150       $callback .= "&l_$item=Y";
2151       $href     .= "&l_$item=Y";
2152     }
2153   }
2154
2155   if ($form->{l_subtotal} eq 'Y') {
2156     $callback .= "&l_subtotal=Y";
2157     $href     .= "&l_subtotal=Y";
2158   }
2159
2160   if ($form->{department}) {
2161     ($department) = split /--/, $form->{department};
2162     $option = $locale->text('Department') . " : $department";
2163   }
2164
2165   # if there are any dates
2166   if ($form->{fromdate} || $form->{todate}) {
2167     if ($form->{fromdate}) {
2168       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2169     }
2170     if ($form->{todate}) {
2171       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2172     }
2173
2174     $form->{period} = "$fromdate - $todate";
2175   } else {
2176     $form->{period} =
2177       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2178   }
2179
2180   if ($form->{db} eq 'ar') {
2181     $name    = $locale->text('Customer');
2182     $invoice = 'is.pl';
2183     $arap    = 'ar.pl';
2184   }
2185   if ($form->{db} eq 'ap') {
2186     $name    = $locale->text('Vendor');
2187     $invoice = 'ir.pl';
2188     $arap    = 'ap.pl';
2189   }
2190
2191   $option .= "<br>" if $option;
2192   $option .= "$form->{period}";
2193
2194   $column_header{id} =
2195       qq|<th><a class=listheading href=$href&sort=id>|
2196     . $locale->text('ID')
2197     . qq|</th>|;
2198   $column_header{invnumber} =
2199       qq|<th><a class=listheading href=$href&sort=invnumber>|
2200     . $locale->text('Invoice')
2201     . qq|</th>|;
2202   $column_header{transdate} =
2203       qq|<th><a class=listheading href=$href&sort=transdate>|
2204     . $locale->text('Date')
2205     . qq|</th>|;
2206   $column_header{netamount} =
2207     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2208   $column_header{tax} =
2209     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2210   $column_header{amount} =
2211     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2212
2213   $column_header{name} =
2214     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2215
2216   $form->header;
2217
2218   print qq|
2219 <body>
2220
2221 <table width=100%>
2222   <tr>
2223     <th class=listtop colspan=$colspan>$form->{title}</th>
2224   </tr>
2225   <tr height="5"></tr>
2226   <tr>
2227     <td>$option</td>
2228   </tr>
2229   <tr>
2230     <td>
2231       <table width=100%>
2232         <tr class=listheading>
2233 |;
2234
2235   map { print "$column_header{$_}\n" } @column_index;
2236
2237   print qq|
2238         </tr>
2239 |;
2240
2241   # add sort and escape callback
2242   $callback = $form->escape($callback . "&sort=$form->{sort}");
2243
2244   if (@{ $form->{TR} }) {
2245     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2246   }
2247
2248   foreach $ref (@{ $form->{TR} }) {
2249
2250     $module = ($ref->{invoice}) ? $invoice : $arap;
2251
2252     if ($form->{l_subtotal} eq 'Y') {
2253       if ($sameitem ne $ref->{ $form->{sort} }) {
2254         &tax_subtotal;
2255         $sameitem = $ref->{ $form->{sort} };
2256       }
2257     }
2258
2259     $totalnetamount += $ref->{netamount};
2260     $totaltax       += $ref->{tax};
2261     $ref->{amount} = $ref->{netamount} + $ref->{tax};
2262
2263     $subtotalnetamount += $ref->{netamount};
2264     $subtotaltax       += $ref->{tax};
2265
2266     map {
2267       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;");
2268     } qw(netamount tax amount);
2269
2270     $column_data{id}        = qq|<td>$ref->{id}</td>|;
2271     $column_data{invnumber} =
2272       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>|;
2273     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2274     $column_data{name}      = qq|<td>$ref->{name}&nbsp;</td>|;
2275
2276     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2277       qw(netamount tax amount);
2278
2279     $i++;
2280     $i %= 2;
2281     print qq|
2282         <tr class=listrow$i>
2283 |;
2284
2285     map { print "$column_data{$_}\n" } @column_index;
2286
2287     print qq|
2288         </tr>
2289 |;
2290
2291   }
2292
2293   if ($form->{l_subtotal} eq 'Y') {
2294     &tax_subtotal;
2295   }
2296
2297   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
2298
2299   print qq|
2300         </tr>
2301         <tr class=listtotal>
2302 |;
2303
2304   $total =
2305     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
2306   $totalnetamount =
2307     $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
2308   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
2309
2310   $column_data{netamount} =
2311     qq|<th class=listtotal align=right>$totalnetamount</th>|;
2312   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
2313   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2314
2315   map { print "$column_data{$_}\n" } @column_index;
2316
2317   print qq|
2318         </tr>
2319       </table>
2320     </td>
2321   </tr>
2322   <tr>
2323     <td><hr size=3 noshade></td>
2324   </tr>
2325 </table>
2326
2327 </body>
2328 </html>
2329 |;
2330
2331   $lxdebug->leave_sub();
2332 }
2333
2334 sub tax_subtotal {
2335   $lxdebug->enter_sub();
2336
2337   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2338
2339   $subtotalnetamount =
2340     $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
2341   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
2342   $subtotal =
2343     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2344                          2, "&nbsp;");
2345
2346   $column_data{netamount} =
2347     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2348   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2349   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2350
2351   $subtotalnetamount = 0;
2352   $subtotaltax       = 0;
2353
2354   print qq|
2355         <tr class=listsubtotal>
2356 |;
2357   map { print "\n$column_data{$_}" } @column_index;
2358
2359   print qq|
2360         </tr>
2361 |;
2362
2363   $lxdebug->leave_sub();
2364 }
2365
2366 sub list_payments {
2367   $lxdebug->enter_sub();
2368
2369   if ($form->{account}) {
2370     ($form->{paymentaccounts}) = split /--/, $form->{account};
2371   }
2372   if ($form->{department}) {
2373     ($department, $form->{department_id}) = split /--/, $form->{department};
2374     $option = $locale->text('Department') . " : $department";
2375   }
2376
2377   RP->payments(\%myconfig, \%$form);
2378
2379   @columns =
2380     $form->sort_columns(qw(transdate reference name paid source memo));
2381
2382   # construct href
2383   $account    = $form->escape($form->{account});
2384   $title      = $form->escape($form->{title});
2385   $department = $form->escape($form->{department});
2386   $form->{paymentaccounts} =~ s/ /%20/g;
2387   $reference = $form->escape($form->{reference});
2388   $source    = $form->escape($form->{source});
2389   $memo      = $form->escape($form->{memo});
2390
2391   $href =
2392     "$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";
2393
2394   # construct callback
2395   $account    = $form->escape($form->{account},    1);
2396   $title      = $form->escape($form->{title},      1);
2397   $department = $form->escape($form->{department}, 1);
2398   $reference  = $form->escape($form->{reference},  1);
2399   $source     = $form->escape($form->{source},     1);
2400   $memo       = $form->escape($form->{memo},       1);
2401
2402   $form->{callback} =
2403     "$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}";
2404   $callback = $form->escape($form->{callback});
2405
2406   $column_header{name} =
2407       "<th><a class=listheading href=$href&sort=name>"
2408     . $locale->text('Description')
2409     . "</a></th>";
2410   $column_header{reference} =
2411       "<th><a class=listheading href=$href&sort=invnumber>"
2412     . $locale->text('Reference')
2413     . "</a></th>";
2414   $column_header{transdate} =
2415       "<th><a class=listheading href=$href&sort=transdate>"
2416     . $locale->text('Date')
2417     . "</a></th>";
2418   $column_header{paid} =
2419     "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
2420   $column_header{source} =
2421       "<th><a class=listheading href=$href&sort=source>"
2422     . $locale->text('Source')
2423     . "</a></th>";
2424   $column_header{memo} =
2425       "<th><a class=listheading href=$href&sort=memo>"
2426     . $locale->text('Memo')
2427     . "</a></th>";
2428
2429   if ($form->{fromdate}) {
2430     $option .= "\n<br>" if ($option);
2431     $option .=
2432         $locale->text('From') . "&nbsp;"
2433       . $locale->date(\%myconfig, $form->{fromdate}, 1);
2434   }
2435   if ($form->{todate}) {
2436     $option .= "\n<br>" if ($option);
2437     $option .=
2438         $locale->text('bis') . "&nbsp;"
2439       . $locale->date(\%myconfig, $form->{todate}, 1);
2440   }
2441
2442   @column_index = @columns;
2443   $colspan      = $#column_index + 1;
2444
2445   $form->header;
2446
2447   print qq|
2448 <body>
2449
2450 <table width=100%>
2451   <tr>
2452     <th class=listtop>$form->{title}</th>
2453   </tr>
2454   <tr height="5"></tr>
2455   <tr>
2456     <td>$option</td>
2457   </tr>
2458   <tr>
2459     <td>
2460       <table width=100%>
2461         <tr class=listheading>
2462 |;
2463
2464   map { print "\n$column_header{$_}" } @column_index;
2465
2466   print qq|
2467         </tr>
2468 |;
2469
2470   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2471
2472     next unless @{ $form->{ $ref->{id} } };
2473
2474     print qq|
2475         <tr>
2476           <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
2477         </tr>
2478 |;
2479
2480     foreach $payment (@{ $form->{ $ref->{id} } }) {
2481
2482       $module = $payment->{module};
2483       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2484       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2485
2486       $href =
2487         qq|${module}.pl?path=$form->{path}&action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|;
2488
2489       $column_data{name}      = "<td>$payment->{name}&nbsp;</td>";
2490       $column_data{reference} =
2491         qq|<td><a href=$href>$payment->{invnumber}</a></td>|;
2492       $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
2493       $column_data{paid}      =
2494           "<td align=right>"
2495         . $form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")
2496         . "</td>";
2497       $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
2498       $column_data{memo}   = "<td>$payment->{memo}&nbsp;</td>";
2499
2500       $subtotalpaid += $payment->{paid};
2501       $totalpaid    += $payment->{paid};
2502
2503       $i++;
2504       $i %= 2;
2505       print qq|
2506         <tr class=listrow$i>
2507 |;
2508
2509       map { print "\n$column_data{$_}" } @column_index;
2510
2511       print qq|
2512         </tr>
2513 |;
2514
2515     }
2516
2517     # print subtotals
2518     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2519
2520     $column_data{paid} =
2521       "<th class=listsubtotal align=right>"
2522       . $form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;") . "</th>";
2523
2524     print qq|
2525         <tr class=listsubtotal>
2526 |;
2527
2528     map { print "\n$column_data{$_}" } @column_index;
2529
2530     print qq|
2531         </tr>
2532 |;
2533
2534     $subtotalpaid = 0;
2535
2536   }
2537
2538   # print total
2539   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2540
2541   $column_data{paid} =
2542     "<th class=listtotal align=right>"
2543     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;") . "</th>";
2544
2545   print qq|
2546         <tr class=listtotal>
2547 |;
2548
2549   map { print "\n$column_data{$_}" } @column_index;
2550
2551   print qq|
2552         </tr>
2553
2554       </table>
2555     </td>
2556   </tr>
2557   <tr>
2558     <td><hr size=3 noshade></td>
2559   </tr>
2560 </table>
2561
2562 </body>
2563 </html>
2564 |;
2565
2566   $lxdebug->leave_sub();
2567 }
2568
2569 sub config {
2570   $lxdebug->enter_sub();
2571   edit();
2572
2573   #$form->header;
2574   #print qq|Hallo|;
2575   $lxdebug->leave_sub();
2576 }
2577
2578 sub debug {
2579
2580   $form->debug();
2581
2582 }
2583
2584 sub winston_export {
2585   $lxdebug->enter_sub();
2586
2587   #create_winston();
2588   $form->{winston} = 1;
2589   &generate_ustva();
2590   $lxdebug->leave_sub();
2591 }
2592
2593 sub print_options {
2594   $lxdebug->enter_sub();
2595
2596   $form->{sendmode} = "attachment";
2597
2598   $form->{"format"} =
2599     $form->{"format"} ? $form->{"format"} :
2600     $myconfig{"template_format"} ? $myconfig{"template_format"} :
2601     "pdf";
2602
2603   $form->{"copies"} =
2604     $form->{"copies"} ? $form->{"copies"} :
2605     $myconfig{"copies"} ? $myconfig{"copies"} :
2606     2;
2607
2608   $form->{PD}{ $form->{type} }     = "selected";
2609   $form->{DF}{ $form->{format} }   = "selected";
2610   $form->{OP}{ $form->{media} }    = "selected";
2611   $form->{SM}{ $form->{sendmode} } = "selected";
2612
2613   if ($form->{report} eq 'ustva') {
2614     $type = qq|
2615             <option value=ustva $form->{PD}{ustva}>| . $locale->text('ustva');
2616   } else {
2617     $type = qq|
2618             <option value=statement $form->{PD}{statement}>|
2619       . $locale->text('Statement');
2620   }
2621
2622   if ($form->{media} eq 'email') {
2623     $media = qq|
2624             <option value=attachment $form->{SM}{attachment}>|
2625       . $locale->text('Attachment') . qq|
2626             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2627   } else {
2628     $media = qq|
2629             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2630     if ($myconfig{printer} && $latex_templates) {
2631       $media .= qq|
2632             <option value=printer $form->{OP}{printer}>|
2633         . $locale->text('Printer');
2634     }
2635   }
2636
2637   if ($latex_templates) {
2638     $format .= qq|
2639             <option value=html $form->{DF}{html}>|
2640       . $locale->text('HTML') . qq|
2641             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
2642     if ($form->{report} ne 'ustva') {
2643       $format . qq|
2644             <option value=postscript $form->{DF}{postscript}>|
2645         . $locale->text('Postscript');
2646     }
2647   }
2648
2649   print qq|
2650 <table>
2651   <tr>
2652     <td><select name=type>$type</select></td>
2653     <td><select name=format>$format</select></td>
2654     <td><select name=media>$media</select></td>
2655 |;
2656
2657   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2658     print qq|
2659       <td>| . $locale->text('Copies') . qq|
2660       <input name=copies size=2 value=$form->{copies}></td>
2661 |;
2662   }
2663
2664   print qq|
2665   </tr>
2666 </table>
2667 |;
2668
2669   $lxdebug->leave_sub();
2670 }
2671
2672 sub generate_bwa {
2673   $lxdebug->enter_sub();
2674   $form->{padding} = "&nbsp;&nbsp;";
2675   $form->{bold}    = "<b>";
2676   $form->{endbold} = "</b>";
2677   $form->{br}      = "<br>";
2678
2679   if ($form->{reporttype} eq "custom") {
2680
2681     #forgotten the year --> thisyear
2682     if ($form->{year} !~ m/^\d\d\d\d$/) {
2683       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2684         /(\d\d\d\d)/;
2685       $form->{year} = $1;
2686     }
2687
2688     #yearly report
2689     if ($form->{duetyp} eq "13") {
2690       $form->{fromdate}        = "1.1.$form->{year}";
2691       $form->{todate}          = "31.12.$form->{year}";
2692       $form->{comparefromdate} = "1.01.$form->{year}";
2693       $form->{comparetodate}   = "31.12.$form->{year}";
2694     }
2695
2696     #Quater reports
2697     if ($form->{duetyp} eq "A") {
2698       $form->{fromdate}        = "1.1.$form->{year}";
2699       $form->{todate}          = "31.3.$form->{year}";
2700       $form->{comparefromdate} = "1.01.$form->{year}";
2701       $form->{comparetodate}   = "31.03.$form->{year}";
2702     }
2703     if ($form->{duetyp} eq "B") {
2704       $form->{fromdate}        = "1.4.$form->{year}";
2705       $form->{todate}          = "30.6.$form->{year}";
2706       $form->{comparefromdate} = "1.01.$form->{year}";
2707       $form->{comparetodate}   = "30.06.$form->{year}";
2708     }
2709     if ($form->{duetyp} eq "C") {
2710       $form->{fromdate}        = "1.7.$form->{year}";
2711       $form->{todate}          = "30.9.$form->{year}";
2712       $form->{comparefromdate} = "1.01.$form->{year}";
2713       $form->{comparetodate}   = "30.09.$form->{year}";
2714     }
2715     if ($form->{duetyp} eq "D") {
2716       $form->{fromdate}        = "1.10.$form->{year}";
2717       $form->{todate}          = "31.12.$form->{year}";
2718       $form->{comparefromdate} = "1.01.$form->{year}";
2719       $form->{comparetodate}   = "31.12.$form->{year}";
2720     }
2721
2722     #Monthly reports
2723   SWITCH: {
2724       $form->{duetyp} eq "1" && do {
2725         $form->{fromdate}        = "1.1.$form->{year}";
2726         $form->{todate}          = "31.1.$form->{year}";
2727         $form->{comparefromdate} = "1.01.$form->{year}";
2728         $form->{comparetodate}   = "31.01.$form->{year}";
2729         last SWITCH;
2730       };
2731       $form->{duetyp} eq "2" && do {
2732         $form->{fromdate} = "1.2.$form->{year}";
2733
2734         #this works from 1901 to 2099, 1900 and 2100 fail.
2735         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2736         $form->{todate}          = "$leap.2.$form->{year}";
2737         $form->{comparefromdate} = "1.01.$form->{year}";
2738         $form->{comparetodate}   = "$leap.02.$form->{year}";
2739         last SWITCH;
2740       };
2741       $form->{duetyp} eq "3" && do {
2742         $form->{fromdate}        = "1.3.$form->{year}";
2743         $form->{todate}          = "31.3.$form->{year}";
2744         $form->{comparefromdate} = "1.01.$form->{year}";
2745         $form->{comparetodate}   = "31.03.$form->{year}";
2746         last SWITCH;
2747       };
2748       $form->{duetyp} eq "4" && do {
2749         $form->{fromdate}        = "1.4.$form->{year}";
2750         $form->{todate}          = "30.4.$form->{year}";
2751         $form->{comparefromdate} = "1.01.$form->{year}";
2752         $form->{comparetodate}   = "30.04.$form->{year}";
2753         last SWITCH;
2754       };
2755       $form->{duetyp} eq "5" && do {
2756         $form->{fromdate}        = "1.5.$form->{year}";
2757         $form->{todate}          = "31.5.$form->{year}";
2758         $form->{comparefromdate} = "1.01.$form->{year}";
2759         $form->{comparetodate}   = "31.05.$form->{year}";
2760         last SWITCH;
2761       };
2762       $form->{duetyp} eq "6" && do {
2763         $form->{fromdate}        = "1.6.$form->{year}";
2764         $form->{todate}          = "30.6.$form->{year}";
2765         $form->{comparefromdate} = "1.01.$form->{year}";
2766         $form->{comparetodate}   = "30.06.$form->{year}";
2767         last SWITCH;
2768       };
2769       $form->{duetyp} eq "7" && do {
2770         $form->{fromdate}        = "1.7.$form->{year}";
2771         $form->{todate}          = "31.7.$form->{year}";
2772         $form->{comparefromdate} = "1.01.$form->{year}";
2773         $form->{comparetodate}   = "31.07.$form->{year}";
2774         last SWITCH;
2775       };
2776       $form->{duetyp} eq "8" && do {
2777         $form->{fromdate}        = "1.8.$form->{year}";
2778         $form->{todate}          = "31.8.$form->{year}";
2779         $form->{comparefromdate} = "1.01.$form->{year}";
2780         $form->{comparetodate}   = "31.08.$form->{year}";
2781         last SWITCH;
2782       };
2783       $form->{duetyp} eq "9" && do {
2784         $form->{fromdate}        = "1.9.$form->{year}";
2785         $form->{todate}          = "30.9.$form->{year}";
2786         $form->{comparefromdate} = "1.01.$form->{year}";
2787         $form->{comparetodate}   = "30.09.$form->{year}";
2788         last SWITCH;
2789       };
2790       $form->{duetyp} eq "10" && do {
2791         $form->{fromdate}        = "1.10.$form->{year}";
2792         $form->{todate}          = "31.10.$form->{year}";
2793         $form->{comparefromdate} = "1.01.$form->{year}";
2794         $form->{comparetodate}   = "31.10.$form->{year}";
2795         last SWITCH;
2796       };
2797       $form->{duetyp} eq "11" && do {
2798         $form->{fromdate}        = "1.11.$form->{year}";
2799         $form->{todate}          = "30.11.$form->{year}";
2800         $form->{comparefromdate} = "1.01.$form->{year}";
2801         $form->{comparetodate}   = "30.11.$form->{year}";
2802         last SWITCH;
2803       };
2804       $form->{duetyp} eq "12" && do {
2805         $form->{fromdate}        = "1.12.$form->{year}";
2806         $form->{todate}          = "31.12.$form->{year}";
2807         $form->{comparefromdate} = "1.01.$form->{year}";
2808         $form->{comparetodate}   = "31.12.$form->{year}";
2809         last SWITCH;
2810       };
2811     }
2812   } else {
2813     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2814     $form->{fromdate} = "${dd}.${mm}.${yy}";
2815     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2816     $form->{todate}          = "${dd}.${mm}.${yy}";
2817     $form->{comparefromdate} = "01.01.$yy";
2818     $form->{comparetodate}   = $form->{todate};
2819   }
2820
2821   RP->bwa(\%myconfig, \%$form);
2822
2823   ($form->{department}) = split /--/, $form->{department};
2824
2825   $form->{period} =
2826     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2827   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2828
2829   # if there are any dates construct a where
2830   if ($form->{fromdate} || $form->{todate}) {
2831
2832     unless ($form->{todate}) {
2833       $form->{todate} = $form->current_date(\%myconfig);
2834     }
2835
2836     my %germandate = ("dateformat" => "dd.mm.yyyy");
2837
2838     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
2839     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2840
2841     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
2842     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2843
2844     $form->{this_period} = "$shortfromdate\n$shorttodate";
2845     $form->{period}      =
2846         $locale->text('for Period')
2847       . qq|\n$longfromdate |
2848       . $locale->text('bis')
2849       . qq| $longtodate|;
2850   }
2851
2852   # setup variables for the form
2853   @a = qw(company address businessnumber);
2854   map { $form->{$_} = $myconfig{$_} } @a;
2855   $form->{templates} = $myconfig{templates};
2856
2857   $form->{IN} = "bwa.html";
2858
2859   $form->parse_template;
2860
2861   $lxdebug->leave_sub();
2862 }
2863
2864 sub generate_ustva {
2865   $lxdebug->enter_sub();
2866
2867   # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
2868   # Einlesen der Finanzamtdaten
2869   get_config($userspath, 'finanzamt.ini');
2870
2871   #  &get_project(generate_bwa);
2872   @anmeldungszeitraum =
2873     qw(0401, 0402, 0403, 0404, 0405, 0405, 0406, 0407, 0408, 0409, 0410, 0411, 0412, 0441, 0442, 0443, 0444);
2874
2875   foreach $item (@anmeldungszeitraum) {
2876     $form->{$item} = "";
2877   }
2878   if ($form->{reporttype} eq "custom") {
2879
2880     #forgotten the year --> thisyear
2881     if ($form->{year} !~ m/^\d\d\d\d$/) {
2882       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2883         /(\d\d\d\d)/;
2884       $form->{year} = $1;
2885     }
2886
2887     #yearly report
2888     if ($form->{duetyp} eq "13") {
2889       $form->{fromdate} = "1.1.$form->{year}";
2890       $form->{todate}   = "31.12.$form->{year}";
2891     }
2892
2893     #Quater reports
2894     if ($form->{duetyp} eq "A") {
2895       $form->{fromdate} = "1.1.$form->{year}";
2896       $form->{todate}   = "31.3.$form->{year}";
2897       $form->{"0441"}   = "X";
2898     }
2899     if ($form->{duetyp} eq "B") {
2900       $form->{fromdate} = "1.4.$form->{year}";
2901       $form->{todate}   = "30.6.$form->{year}";
2902       $form->{"0442"}   = "X";
2903     }
2904     if ($form->{duetyp} eq "C") {
2905       $form->{fromdate} = "1.7.$form->{year}";
2906       $form->{todate}   = "30.9.$form->{year}";
2907       $form->{"0443"}   = "X";
2908     }
2909     if ($form->{duetyp} eq "D") {
2910       $form->{fromdate} = "1.10.$form->{year}";
2911       $form->{todate}   = "31.12.$form->{year}";
2912       $form->{"0444"}   = "X";
2913     }
2914
2915     #Monthly reports
2916   SWITCH: {
2917       $form->{duetyp} eq "1" && do {
2918         $form->{fromdate} = "1.1.$form->{year}";
2919         $form->{todate}   = "31.1.$form->{year}";
2920         $form->{"0401"}   = "X";
2921         last SWITCH;
2922       };
2923       $form->{duetyp} eq "2" && do {
2924         $form->{fromdate} = "1.2.$form->{year}";
2925
2926         #this works from 1901 to 2099, 1900 and 2100 fail.
2927         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2928         $form->{todate} = "$leap.2.$form->{year}";
2929         $form->{"0402"} = "X";
2930         last SWITCH;
2931       };
2932       $form->{duetyp} eq "3" && do {
2933         $form->{fromdate} = "1.3.$form->{year}";
2934         $form->{todate}   = "31.3.$form->{year}";
2935         $form->{"0403"}   = "X";
2936         last SWITCH;
2937       };
2938       $form->{duetyp} eq "4" && do {
2939         $form->{fromdate} = "1.4.$form->{year}";
2940         $form->{todate}   = "30.4.$form->{year}";
2941         $form->{"0404"}   = "X";
2942         last SWITCH;
2943       };
2944       $form->{duetyp} eq "5" && do {
2945         $form->{fromdate} = "1.5.$form->{year}";
2946         $form->{todate}   = "31.5.$form->{year}";
2947         $form->{"0405"}   = "X";
2948         last SWITCH;
2949       };
2950       $form->{duetyp} eq "6" && do {
2951         $form->{fromdate} = "1.6.$form->{year}";
2952         $form->{todate}   = "30.6.$form->{year}";
2953         $form->{"0406"}   = "X";
2954         last SWITCH;
2955       };
2956       $form->{duetyp} eq "7" && do {
2957         $form->{fromdate} = "1.7.$form->{year}";
2958         $form->{todate}   = "31.7.$form->{year}";
2959         $form->{"0407"}   = "X";
2960         last SWITCH;
2961       };
2962       $form->{duetyp} eq "8" && do {
2963         $form->{fromdate} = "1.8.$form->{year}";
2964         $form->{todate}   = "31.8.$form->{year}";
2965         $form->{"0408"}   = "X";
2966         last SWITCH;
2967       };
2968       $form->{duetyp} eq "9" && do {
2969         $form->{fromdate} = "1.9.$form->{year}";
2970         $form->{todate}   = "30.9.$form->{year}";
2971         $form->{"0409"}   = "X";
2972         last SWITCH;
2973       };
2974       $form->{duetyp} eq "10" && do {
2975         $form->{fromdate} = "1.10.$form->{year}";
2976         $form->{todate}   = "31.10.$form->{year}";
2977         $form->{"0410"}   = "X";
2978         last SWITCH;
2979       };
2980       $form->{duetyp} eq "11" && do {
2981         $form->{fromdate} = "1.11.$form->{year}";
2982         $form->{todate}   = "30.11.$form->{year}";
2983         $form->{"0411"}   = "X";
2984         last SWITCH;
2985       };
2986       $form->{duetyp} eq "12" && do {
2987         $form->{fromdate} = "1.12.$form->{year}";
2988         $form->{todate}   = "31.12.$form->{year}";
2989         $form->{"0412"}   = "X";
2990         last SWITCH;
2991       };
2992     }
2993   }
2994
2995   #    $locale->date(\%myconfig, $form->current_date(\%myconfig), 0)=~ /(\d\d\d\d)/;
2996   #    $form->{year}= $1;
2997   #    $form->{fromdate}="1.1.$form->{year}";
2998   #    $form->{todate}="31.3.$form->{year}";
2999   #    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3000   #  }
3001
3002   RP->ustva(\%myconfig, \%$form);
3003
3004   ($form->{department}) = split /--/, $form->{department};
3005
3006   $form->{period} =
3007     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3008   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
3009
3010   # if there are any dates construct a where
3011   if ($form->{fromdate} || $form->{todate}) {
3012
3013     unless ($form->{todate}) {
3014       $form->{todate} = $form->current_date(\%myconfig);
3015     }
3016
3017     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
3018     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
3019
3020     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
3021     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
3022
3023     $form->{this_period} = "$shortfromdate\n$shorttodate";
3024     $form->{period}      =
3025         $locale->text('for Period')
3026       . qq|<br>\n$longfromdate |
3027       . $locale->text('bis')
3028       . qq| $longtodate|;
3029   }
3030
3031   if ($form->{comparefromdate} || $form->{comparetodate}) {
3032     $longcomparefromdate =
3033       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
3034     $shortcomparefromdate =
3035       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
3036
3037     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
3038     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
3039
3040     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
3041     $form->{period} .=
3042         "\n$longcomparefromdate "
3043       . $locale->text('bis')
3044       . qq| $longcomparetodate|;
3045   }
3046
3047   $form->{Datum_heute} =
3048     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
3049
3050   if (   $form->{format} eq 'pdf'
3051       or $form->{format} eq 'postscript') {
3052     $form->{padding} = "~~";
3053     $form->{bold}    = "\textbf{";
3054     $form->{endbold} = "}";
3055     $form->{br}      = '\\\\';
3056
3057     @numbers = qw(51r 86r 97r 93r 96 43 45
3058       66 62 67);
3059     foreach $number (@numbers) {
3060       $form->{$number} =~ s/,/~~/g;
3061     }
3062
3063       } elsif ($form->{format} eq 'html') {
3064     $form->{padding} = "&nbsp;&nbsp;";
3065     $form->{bold}    = "<b>";
3066     $form->{endbold} = "</b>";
3067     $form->{br}      = "<br>"
3068
3069   }
3070
3071   # setup variables for the form
3072   @a = qw(company address businessnumber);
3073   map { $form->{$_} = $myconfig{$_} } @a;
3074
3075   $form->{address} =~ s/\\n/$form->{br}/g;
3076
3077   if ($form->{winston} eq '1') {
3078     create_winston();
3079
3080   } else {
3081     $form->{templates} = $myconfig{templates};
3082     $form->{IN}        = "$form->{type}";
3083     $form->{IN} .= '.tex'
3084       if (   $form->{format} eq 'pdf'
3085           or $form->{format} eq 'postscript');
3086     $form->{IN} .= '.html' if ($form->{format} eq 'html');
3087
3088     $form->parse_template(\%myconfig, $userspath);
3089
3090     # $form->parse_template;
3091   }
3092   $lxdebug->leave_sub();
3093 }