Historie eingefügt
[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     $gifi = "";
707
708     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
709
710     RP->get_taxaccounts(\%myconfig, \%$form);
711
712     print qq|
713         <input type=hidden name=nextsub value=generate_tax_report>
714         <tr>
715           <th align=right>| . $locale->text('From') . qq|</th>
716           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
717           <th align=right>| . $locale->text('Bis') . qq|</th>
718           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
719         </tr>
720         <tr>
721           <th align=right>| . $locale->text('Report for') . qq|</th>
722           <td colspan=3>
723 |;
724
725     $checked = "checked";
726     foreach $ref (@{ $form->{taxaccounts} }) {
727
728       print
729         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
730
731     <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
732     <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
733
734       $checked = "";
735
736     }
737
738     print qq|
739   <input type=hidden name=db value=$form->{db}>
740   <input type=hidden name=sort value=transdate>
741
742           </td>
743         </tr>
744 |;
745
746     if (@{ $form->{gifi_taxaccounts} }) {
747       print qq|
748         <tr>
749           <th align=right>| . $locale->text('GIFI') . qq|</th>
750           <td colspan=3>
751 |;
752
753       foreach $ref (@{ $form->{gifi_taxaccounts} }) {
754
755         print
756           qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
757
758       <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
759       <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
760
761       }
762
763       print qq|
764           </td>
765         </tr>
766 |;
767     }
768
769     print qq|
770         <tr>
771           <th align=right>| . $locale->text('Method') . qq|</th>
772           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
773       . $locale->text('Accrual') . qq|
774           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
775       . $locale->text('EUR') . qq|</td>
776         </tr>
777       </table>
778     </td>
779   </tr>
780   <tr>
781     <td>
782       <table>
783         <tr>
784           <th align=right>| . $locale->text('Include in Report') . qq|</th>
785           <td>
786             <table>
787               <tr>
788                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
789                 <td>| . $locale->text('ID') . qq|</td>
790                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
791                 <td>| . $locale->text('Invoice') . qq|</td>
792                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
793                 <td>| . $locale->text('Date') . qq|</td>
794               </tr>
795               <tr>
796                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
797                 <td>|;
798
799     if ($form->{db} eq 'ar') {
800       print $locale->text('Customer');
801     }
802     if ($form->{db} eq 'ap') {
803       print $locale->text('Vendor');
804     }
805
806     print qq|</td>
807                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
808                 <td>| . $locale->text('Amount') . qq|</td>
809                 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
810                 <td>| . $locale->text('Tax') . qq|</td>
811                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
812                 <td>| . $locale->text('Total') . qq|</td>
813               </tr>
814               <tr>
815                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
816                 <td>| . $locale->text('Subtotal') . qq|</td>
817               </tr>
818             </table>
819           </td>
820         </tr>
821 |;
822
823   }
824
825   if ($form->{report} =~ /^nontaxable_/) {
826     $gifi = "";
827
828     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
829
830     print qq|
831         <input type=hidden name=nextsub value=generate_tax_report>
832
833         <input type=hidden name=db value=$form->{db}>
834         <input type=hidden name=sort value=transdate>
835         <input type=hidden name=report value=$form->{report}>
836
837         <tr>
838           <th align=right>| . $locale->text('From') . qq|</th>
839           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
840           <th align=right>| . $locale->text('Bis') . qq|</th>
841           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
842         </tr>
843         <tr>
844           <th align=right>| . $locale->text('Method') . qq|</th>
845           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
846       . $locale->text('Accrual') . qq|
847           &nbsp;<input name=method class=radio type=radio value=cash $cash>|
848       . $locale->text('EUR') . qq|</td>
849         </tr>
850         <tr>
851           <th align=right>| . $locale->text('Include in Report') . qq|</th>
852           <td colspan=3>
853             <table>
854               <tr>
855                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
856                 <td>| . $locale->text('ID') . qq|</td>
857                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
858                 <td>| . $locale->text('Invoice') . qq|</td>
859                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
860                 <td>| . $locale->text('Date') . qq|</td>
861               </tr>
862               <tr>
863                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
864                 <td>|;
865
866     if ($form->{db} eq 'ar') {
867       print $locale->text('Customer');
868     }
869     if ($form->{db} eq 'ap') {
870       print $locale->text('Vendor');
871     }
872
873     print qq|</td>
874                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
875                 <td>| . $locale->text('Amount') . qq|</td>
876                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
877                 <td>| . $locale->text('Total') . qq|</td>
878               </tr>
879               <tr>
880                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
881                 <td>| . $locale->text('Subtotal') . qq|</td>
882               </tr>
883             </table>
884           </td>
885         </tr>
886 |;
887
888   }
889
890   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
891     $gifi = "";
892
893     if ($form->{report} eq 'ar_aging') {
894       $label = $locale->text('Customer');
895       $form->{vc} = 'customer';
896     } else {
897       $label = $locale->text('Vendor');
898       $form->{vc} = 'vendor';
899     }
900
901     $nextsub = "generate_$form->{report}";
902
903     # setup vc selection
904     $form->all_vc(\%myconfig, $form->{vc},
905                   ($form->{vc} eq 'customer') ? "AR" : "AP");
906
907     map { $vc .= "<option>$_->{name}--$_->{id}\n" }
908       @{ $form->{"all_$form->{vc}"} };
909
910     $vc =
911       ($vc)
912       ? qq|<select name=$form->{vc}><option>\n$vc</select>|
913       : qq|<input name=$form->{vc} size=35>|;
914
915     print qq|
916         <tr>
917           <th align=right>| . $locale->text($label) . qq|</th>
918           <td>$vc</td>
919         </tr>
920         <tr>
921           <th align=right>| . $locale->text('Bis') . qq|</th>
922           <td>
923             $button1
924             $button1_2
925           </td>
926         </tr>
927         <input type=hidden name=type value=statement>
928         <input type=hidden name=format value=html>
929         <input type=hidden name=media value=screen>
930
931         <input type=hidden name=nextsub value=$nextsub>
932         <input type=hidden name=action value=$nextsub>
933
934 $jsscript
935 |;
936   }
937
938   # above action can be removed if there is more than one input field
939
940   if ($form->{report} =~ /(receipts|payments)$/) {
941     $gifi = "";
942
943     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
944
945     RP->paymentaccounts(\%myconfig, \%$form);
946
947     $selection = "<option>\n";
948     foreach $ref (@{ $form->{PR} }) {
949       $paymentaccounts .= "$ref->{accno} ";
950       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
951     }
952
953     chop $paymentaccounts;
954
955     print qq|
956         <input type=hidden name=nextsub value=list_payments>
957         <tr>
958           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
959           <td colspan=3><select name=account>$selection</select>
960             <input type=hidden name=paymentaccounts value="$paymentaccounts">
961           </td>
962         </tr>
963         <tr>
964           <th align=right>| . $locale->text('Reference') . qq|</th>
965           <td colspan=3><input name=reference></td>
966         </tr>
967         <tr>
968           <th align=right nowrap>| . $locale->text('Source') . qq|</th>
969           <td colspan=3><input name=source></td>
970         </tr>
971         <tr>
972           <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
973           <td colspan=3><input name=memo size=30></td>
974         </tr>
975         <tr>
976           <th align=right>| . $locale->text('From') . qq|</th>
977           <td>
978             $button1
979             $button1_2
980           </td>
981           <th align=right>| . $locale->text('Bis') . qq|</th>
982           <td>
983             $button2
984             $button2_2
985           </td>
986         </tr>
987         <tr>
988           <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
989           <th align=left colspan=3>|
990       . $locale->text('Include Exchangerate Difference') . qq|</td>
991         </tr>
992
993 $jsscript
994
995           <input type=hidden name=db value=$form->{db}>
996           <input type=hidden name=sort value=transdate>
997 |;
998
999   }
1000
1001   print qq|
1002
1003       </table>
1004     </td>
1005   </tr>
1006   <tr>
1007     <td><hr size=3 noshade></td>
1008   </tr>
1009 </table>
1010
1011 <br>
1012 <input type=hidden name=path value=$form->{path}>
1013 <input type=hidden name=login value=$form->{login}>
1014 <input type=hidden name=password value=$form->{password}>
1015
1016 <input type=submit class=submit name=action value="|
1017     . $locale->text('Continue') . qq|">
1018 |;
1019
1020   # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
1021   # Einlesen der Finanzamtdaten
1022   get_config($userspath, 'finanzamt.ini');
1023
1024   $disabled = qq|disabled="disabled"|;
1025   $disabled = '' if ($form->{elster} eq '1');
1026   if ($form->{report} eq 'ustva') {
1027     print qq|
1028   <input type=submit class=submit name=action value="|
1029       . $locale->text('debug') . qq|">
1030   <input type=submit class=submit name=action $disabled
1031    value="| . $locale->text('winston_export') . qq|">
1032   |;
1033     print qq|
1034    <input type=submit class=submit name=action value="|
1035       . $locale->text('config') . qq|">
1036   |;
1037   }
1038
1039   print qq|
1040 </form>
1041
1042 </body>
1043 </html>
1044 |;
1045
1046   $lxdebug->leave_sub();
1047 }
1048
1049 sub continue { &{ $form->{nextsub} } }
1050
1051 sub get_project {
1052   $lxdebug->enter_sub();
1053   my $nextsub = shift;
1054
1055   $form->{project_id} = $form->{project_id_1};
1056   if ($form->{projectnumber} && !$form->{project_id}) {
1057     $form->{rowcount} = 1;
1058
1059     # call this instead of update
1060     $form->{update}          = $nextsub;
1061     $form->{projectnumber_1} = $form->{projectnumber};
1062
1063     delete $form->{sort};
1064     &check_project;
1065
1066     # if there is one only, assign id
1067     $form->{project_id} = $form->{project_id_1};
1068   }
1069
1070   $lxdebug->leave_sub();
1071 }
1072
1073 sub generate_income_statement {
1074   $lxdebug->enter_sub();
1075
1076   $form->{padding} = "&nbsp;&nbsp;";
1077   $form->{bold}    = "<b>";
1078   $form->{endbold} = "</b>";
1079   $form->{br}      = "<br>";
1080
1081   if ($form->{reporttype} eq "custom") {
1082
1083     #forgotten the year --> thisyear
1084     if ($form->{year} !~ m/^\d\d\d\d$/) {
1085       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
1086         /(\d\d\d\d)/;
1087       $form->{year} = $1;
1088     }
1089
1090     #yearly report
1091     if ($form->{duetyp} eq "13") {
1092       $form->{fromdate} = "1.1.$form->{year}";
1093       $form->{todate}   = "31.12.$form->{year}";
1094     }
1095
1096     #Quater reports
1097     if ($form->{duetyp} eq "A") {
1098       $form->{fromdate} = "1.1.$form->{year}";
1099       $form->{todate}   = "31.3.$form->{year}";
1100     }
1101     if ($form->{duetyp} eq "B") {
1102       $form->{fromdate} = "1.4.$form->{year}";
1103       $form->{todate}   = "30.6.$form->{year}";
1104     }
1105     if ($form->{duetyp} eq "C") {
1106       $form->{fromdate} = "1.7.$form->{year}";
1107       $form->{todate}   = "30.9.$form->{year}";
1108     }
1109     if ($form->{duetyp} eq "D") {
1110       $form->{fromdate} = "1.10.$form->{year}";
1111       $form->{todate}   = "31.12.$form->{year}";
1112     }
1113
1114     #Monthly reports
1115   SWITCH: {
1116       $form->{duetyp} eq "1" && do {
1117         $form->{fromdate} = "1.1.$form->{year}";
1118         $form->{todate}   = "31.1.$form->{year}";
1119         last SWITCH;
1120       };
1121       $form->{duetyp} eq "2" && do {
1122         $form->{fromdate} = "1.2.$form->{year}";
1123
1124         #this works from 1901 to 2099, 1900 and 2100 fail.
1125         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1126         $form->{todate} = "$leap.2.$form->{year}";
1127         last SWITCH;
1128       };
1129       $form->{duetyp} eq "3" && do {
1130         $form->{fromdate} = "1.3.$form->{year}";
1131         $form->{todate}   = "31.3.$form->{year}";
1132         last SWITCH;
1133       };
1134       $form->{duetyp} eq "4" && do {
1135         $form->{fromdate} = "1.4.$form->{year}";
1136         $form->{todate}   = "30.4.$form->{year}";
1137         last SWITCH;
1138       };
1139       $form->{duetyp} eq "5" && do {
1140         $form->{fromdate} = "1.5.$form->{year}";
1141         $form->{todate}   = "31.5.$form->{year}";
1142         last SWITCH;
1143       };
1144       $form->{duetyp} eq "6" && do {
1145         $form->{fromdate} = "1.6.$form->{year}";
1146         $form->{todate}   = "30.6.$form->{year}";
1147         last SWITCH;
1148       };
1149       $form->{duetyp} eq "7" && do {
1150         $form->{fromdate} = "1.7.$form->{year}";
1151         $form->{todate}   = "31.7.$form->{year}";
1152         last SWITCH;
1153       };
1154       $form->{duetyp} eq "8" && do {
1155         $form->{fromdate} = "1.8.$form->{year}";
1156         $form->{todate}   = "31.8.$form->{year}";
1157         last SWITCH;
1158       };
1159       $form->{duetyp} eq "9" && do {
1160         $form->{fromdate} = "1.9.$form->{year}";
1161         $form->{todate}   = "30.9.$form->{year}";
1162         last SWITCH;
1163       };
1164       $form->{duetyp} eq "10" && do {
1165         $form->{fromdate} = "1.10.$form->{year}";
1166         $form->{todate}   = "31.10.$form->{year}";
1167         last SWITCH;
1168       };
1169       $form->{duetyp} eq "11" && do {
1170         $form->{fromdate} = "1.11.$form->{year}";
1171         $form->{todate}   = "30.11.$form->{year}";
1172         last SWITCH;
1173       };
1174       $form->{duetyp} eq "12" && do {
1175         $form->{fromdate} = "1.12.$form->{year}";
1176         $form->{todate}   = "31.12.$form->{year}";
1177         last SWITCH;
1178       };
1179     }
1180   }
1181
1182   RP->income_statement(\%myconfig, \%$form);
1183
1184   ($form->{department}) = split /--/, $form->{department};
1185
1186   $form->{period} =
1187     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1188   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
1189
1190   # if there are any dates construct a where
1191   if ($form->{fromdate} || $form->{todate}) {
1192
1193     unless ($form->{todate}) {
1194       $form->{todate} = $form->current_date(\%myconfig);
1195     }
1196
1197     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
1198     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
1199
1200     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
1201     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
1202
1203     $form->{this_period} = "$shortfromdate\n$shorttodate";
1204     $form->{period}      =
1205         $locale->text('for Period')
1206       . qq|\n$longfromdate |
1207       . $locale->text('Bis')
1208       . qq| $longtodate|;
1209   }
1210
1211   if ($form->{comparefromdate} || $form->{comparetodate}) {
1212     $longcomparefromdate =
1213       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
1214     $shortcomparefromdate =
1215       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
1216
1217     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
1218     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
1219
1220     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
1221     $form->{period} .=
1222         "\n$longcomparefromdate "
1223       . $locale->text('Bis')
1224       . qq| $longcomparetodate|;
1225   }
1226
1227   # setup variables for the form
1228   @a = qw(company address businessnumber);
1229   map { $form->{$_} = $myconfig{$_} } @a;
1230
1231   $form->{templates} = $myconfig{templates};
1232
1233   $form->{IN} = "income_statement.html";
1234
1235   $form->parse_template;
1236
1237   $lxdebug->leave_sub();
1238 }
1239
1240 sub generate_balance_sheet {
1241   $lxdebug->enter_sub();
1242
1243   $form->{padding} = "&nbsp;&nbsp;";
1244   $form->{bold}    = "<b>";
1245   $form->{endbold} = "</b>";
1246   $form->{br}      = "<br>";
1247
1248   RP->balance_sheet(\%myconfig, \%$form);
1249
1250   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1251   $form->{period} =
1252     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1253
1254   ($form->{department}) = split /--/, $form->{department};
1255
1256   # define Current Earnings account
1257   $padding = ($form->{l_heading}) ? $form->{padding} : "";
1258   push(@{ $form->{equity_account} },
1259        $padding . $locale->text('Current Earnings'));
1260
1261   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1262   $form->{last_period} =
1263     $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1264
1265   $form->{IN} = "balance_sheet.html";
1266
1267   # setup company variables for the form
1268   map { $form->{$_} = $myconfig{$_};
1269         $form->{$_} =~ s/\\n/\n/g; }
1270     (qw(company address businessnumber nativecurr));
1271
1272   $form->{templates} = $myconfig{templates};
1273
1274   $form->parse_template;
1275
1276   $lxdebug->leave_sub();
1277 }
1278
1279 sub generate_projects {
1280   $lxdebug->enter_sub();
1281
1282   &get_project(generate_projects);
1283   $form->{projectnumber} = $form->{projectnumber_1};
1284
1285   $form->{nextsub} = "generate_projects";
1286   $form->{title}   = $locale->text('Project Transactions');
1287   RP->trial_balance(\%myconfig, \%$form);
1288
1289   &list_accounts;
1290
1291   $lxdebug->leave_sub();
1292 }
1293
1294 # Antonio Gallardo
1295 #
1296 # D.S. Feb 16, 2001
1297 # included links to display transactions for period entered
1298 # added headers and subtotals
1299 #
1300 sub generate_trial_balance {
1301   $lxdebug->enter_sub();
1302
1303   # get for each account initial balance, debits and credits
1304   RP->trial_balance(\%myconfig, \%$form);
1305
1306   $form->{nextsub} = "generate_trial_balance";
1307   $form->{title}   = $locale->text('Trial Balance');
1308   &list_accounts;
1309
1310   $lxdebug->leave_sub();
1311 }
1312
1313 sub list_accounts {
1314   $lxdebug->enter_sub();
1315
1316   $title = $form->escape($form->{title});
1317
1318   if ($form->{department}) {
1319     ($department) = split /--/, $form->{department};
1320     $options    = $locale->text('Department') . " : $department<br>";
1321     $department = $form->escape($form->{department});
1322   }
1323   if ($form->{projectnumber}) {
1324     $options .=
1325       $locale->text('Project Number') . " : $form->{projectnumber}<br>";
1326     $projectnumber = $form->escape($form->{projectnumber});
1327   }
1328
1329   # if there are any dates
1330   if ($form->{fromdate} || $form->{todate}) {
1331     if ($form->{fromdate}) {
1332       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1333     }
1334     if ($form->{todate}) {
1335       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1336     }
1337
1338     $form->{period} = "$fromdate - $todate";
1339   } else {
1340     $form->{period} =
1341       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1342
1343   }
1344   $options .= $form->{period};
1345
1346   @column_index = qw(accno description begbalance debit credit endbalance);
1347
1348   $column_header{accno} =
1349     qq|<th class=listheading>| . $locale->text('Account') . qq|</th>|;
1350   $column_header{description} =
1351     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1352   $column_header{debit} =
1353     qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>|;
1354   $column_header{credit} =
1355     qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>|;
1356   $column_header{begbalance} =
1357     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
1358   $column_header{endbalance} =
1359     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
1360
1361   if ($form->{accounttype} eq 'gifi') {
1362     $column_header{accno} =
1363       qq|<th class=listheading>| . $locale->text('GIFI') . qq|</th>|;
1364   }
1365
1366   $form->header;
1367
1368   print qq|
1369 <body>
1370
1371 <table width=100%>
1372   <tr>
1373     <th class=listtop>$form->{title}</th>
1374   </tr>
1375   <tr height="5"></tr>
1376   <tr>
1377     <td>$options</td>
1378   </tr>
1379   <tr>
1380     <td>
1381       <table width=100%>
1382         <tr>|;
1383
1384   map { print "$column_header{$_}\n" } @column_index;
1385
1386   print qq|
1387         </tr>
1388 |;
1389
1390   # sort the whole thing by account numbers and display
1391   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
1392
1393     $description = $form->escape($ref->{description});
1394
1395     $href =
1396       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}|;
1397
1398     if ($form->{accounttype} eq 'gifi') {
1399       $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
1400       $na = $locale->text('N/A');
1401       map { $ref->{$_} = $na } qw(accno description) unless $ref->{accno};
1402     } else {
1403       $href .= "&accno=$ref->{accno}&description=$description";
1404     }
1405
1406     $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1407
1408     $debit  = ($ref->{debit} != 0) ? $form->format_amount(\%myconfig, $ref->{debit},  2, "&nbsp;") : "&nbsp;";
1409     $credit = ($ref->{credit} != 0) ? $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;") : "&nbsp;";
1410     $begbalance =
1411       $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
1412     $endbalance =
1413       $form->format_amount(\%myconfig,
1414                            ($ref->{balance} + $ref->{amount}) * $ml,
1415                            2, "&nbsp;");
1416
1417     #    next if ($ref->{debit} == 0 && $ref->{credit} == 0);
1418
1419     if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
1420       map { $column_data{$_} = "<th>&nbsp;</th>" }
1421         qw(accno begbalance endbalance);
1422
1423       $subtotalbegbalance =
1424         $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
1425       $subtotalendbalance =
1426         $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
1427       $subtotaldebit =
1428         $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
1429       $subtotalcredit =
1430         $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
1431
1432       $column_data{description} = "<th>$subtotaldescription</th>";
1433       $column_data{begbalance}  = "<th align=right>$subtotalbegbalance</th>";
1434       $column_data{endbalance}  = "<th align=right>$subtotalendbalance</th>";
1435       $column_data{debit}       = "<th align=right>$subtotaldebit</th>";
1436       $column_data{credit}      = "<th align=right>$subtotalcredit</th>";
1437
1438       print qq|
1439         <tr class=listsubtotal>
1440 |;
1441       map { print "$column_data{$_}\n" } @column_index;
1442
1443       print qq|
1444         </tr>
1445 |;
1446     }
1447
1448     if ($ref->{charttype} eq "H") {
1449       $subtotal            = 1;
1450       $subtotaldescription = $ref->{description};
1451       $subtotaldebit       = $ref->{debit};
1452       $subtotalcredit      = $ref->{credit};
1453       $subtotalbegbalance  = 0;
1454       $subtotalendbalance  = 0;
1455
1456       next unless $form->{l_heading};
1457
1458       map { $column_data{$_} = "<th>&nbsp;</th>" }
1459         qw(accno debit credit begbalance endbalance);
1460       $column_data{description} =
1461         "<th class=listheading>$ref->{description}</th>";
1462     }
1463
1464     if ($ref->{charttype} eq "A") {
1465       $column_data{accno}       = "<td><a href=$href>$ref->{accno}</a></td>";
1466       $column_data{description} = "<td>$ref->{description}</td>";
1467       $column_data{debit}       = "<td align=right>$debit</td>";
1468       $column_data{credit}      = "<td align=right>$credit</td>";
1469       $column_data{begbalance}  = "<td align=right>$begbalance</td>";
1470       $column_data{endbalance}  = "<td align=right>$endbalance</td>";
1471
1472       $totaldebit  += $ref->{debit};
1473       $totalcredit += $ref->{credit};
1474
1475       $subtotalbegbalance += $ref->{balance} * $ml;
1476       $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml;
1477
1478     }
1479
1480     if ($ref->{charttype} eq "H") {
1481       print qq|
1482       <tr class=listheading>
1483 |;
1484     }
1485     if ($ref->{charttype} eq "A") {
1486       $i++;
1487       $i %= 2;
1488       print qq|
1489       <tr class=listrow$i>
1490 |;
1491     }
1492
1493     map { print "$column_data{$_}\n" } @column_index;
1494
1495     print qq|
1496       </tr>
1497 |;
1498   }
1499
1500   # print last subtotal
1501   if ($subtotal && $form->{l_subtotal}) {
1502     map { $column_data{$_} = "<th>&nbsp;</th>" }
1503       qw(accno begbalance endbalance);
1504     $subtotalbegbalance =
1505       $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
1506     $subtotalendbalance =
1507       $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
1508     $subtotaldebit =
1509       $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
1510     $subtotalcredit =
1511       $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
1512     $column_data{description} = "<th>$subdescription</th>";
1513     $column_data{begbalance}  = "<th align=right>$subtotalbegbalance</th>";
1514     $column_data{endbalance}  = "<th align=right>$subtotalendbalance</th>";
1515     $column_data{debit}       = "<th align=right>$subtotaldebit</th>";
1516     $column_data{credit}      = "<th align=right>$subtotalcredit</th>";
1517
1518     print qq|
1519       <tr class=listsubtotal>
1520 |;
1521     map { print "$column_data{$_}\n" } @column_index;
1522
1523     print qq|
1524       </tr>
1525 |;
1526   }
1527
1528   $totaldebit  = $form->format_amount(\%myconfig, $totaldebit,  2, "&nbsp;");
1529   $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;");
1530
1531   map { $column_data{$_} = "<th>&nbsp;</th>" }
1532     qw(accno description begbalance endbalance);
1533
1534   $column_data{debit}  = qq|<th align=right class=listtotal>$totaldebit</th>|;
1535   $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
1536
1537   print qq|
1538         <tr class=listtotal>
1539 |;
1540
1541   map { print "$column_data{$_}\n" } @column_index;
1542
1543   print qq|
1544         </tr>
1545       </table>
1546     </td>
1547   </tr>
1548   <tr>
1549     <td><hr size=3 noshade></td>
1550   </tr>
1551 </table>
1552
1553 </body>
1554 </html>
1555 |;
1556
1557   $lxdebug->leave_sub();
1558 }
1559
1560 sub generate_ar_aging {
1561   $lxdebug->enter_sub();
1562
1563   # split customer
1564   ($form->{customer}) = split(/--/, $form->{customer});
1565   $customer = $form->escape($form->{customer}, 1);
1566   $title    = $form->escape($form->{title},    1);
1567
1568   $form->{ct}   = "customer";
1569   $form->{arap} = "ar";
1570
1571   $form->{callback} =
1572     qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&customer=$customer&title=$title|;
1573
1574   RP->aging(\%myconfig, \%$form);
1575   &aging;
1576
1577   $lxdebug->leave_sub();
1578 }
1579
1580 sub generate_ap_aging {
1581   $lxdebug->enter_sub();
1582
1583   # split vendor
1584   ($form->{vendor}) = split(/--/, $form->{vendor});
1585   $vendor = $form->escape($form->{vendor}, 1);
1586   $title  = $form->escape($form->{title},  1);
1587
1588   $form->{ct}   = "vendor";
1589   $form->{arap} = "ap";
1590
1591   $form->{callback} =
1592     qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&vendor=$vendor&title=$title|;
1593
1594   RP->aging(\%myconfig, \%$form);
1595   &aging;
1596
1597   $lxdebug->leave_sub();
1598 }
1599
1600 sub aging {
1601   $lxdebug->enter_sub();
1602
1603   $form->header;
1604
1605   $column_header{statement} = qq|<th>&nbsp;</th>|;
1606   $column_header{ct}        =
1607       qq|<th class=listheading>|
1608     . $locale->text(ucfirst $form->{ct})
1609     . qq|</th>|;
1610   $column_header{invnumber} =
1611     qq|<th class=listheading>| . $locale->text('Invoice') . qq|</th>|;
1612   $column_header{transdate} =
1613     qq|<th class=listheading>| . $locale->text('Date') . qq|</th>|;
1614   $column_header{duedate} =
1615     qq|<th class=listheading>| . $locale->text('Due') . qq|</th>|;
1616   $column_header{c0} =
1617     qq|<th class=listheading>| . $locale->text('Current') . qq|</th>|;
1618   $column_header{c30} = qq|<th class=listheading>30</th>|;
1619   $column_header{c60} = qq|<th class=listheading>60</th>|;
1620   $column_header{c90} = qq|<th class=listheading>90</th>|;
1621
1622   @column_index =
1623     (qw(statement ct invnumber transdate duedate c0 c30 c60 c90));
1624
1625   if ($form->{department}) {
1626     $option .= "\n<br>" if $option;
1627     ($department) = split /--/, $form->{department};
1628     $option .= $locale->text('Department') . " : $department";
1629     $department = $form->escape($form->{department}, 1);
1630     $form->{callback} .= "&department=$department";
1631   }
1632
1633   if ($form->{arap} eq 'ar') {
1634     if ($form->{customer}) {
1635       $option .= "\n<br>" if $option;
1636       $option .= $form->{customer};
1637     }
1638   }
1639   if ($form->{arap} eq 'ap') {
1640     shift @column_index;
1641     if ($form->{vendor}) {
1642       $option .= "\n<br>" if $option;
1643       $option .= $form->{vendor};
1644     }
1645   }
1646
1647   $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1648   $option .= "\n<br>" if $option;
1649   $option .=
1650     $locale->text('for Period') . " " . $locale->text('Bis') . " $todate";
1651
1652   print qq|
1653 <body>
1654
1655 <form method=post action=$form->{script}>
1656
1657 <table width=100%>
1658   <tr>
1659     <th class=listtop>$form->{title}</th>
1660   </tr>
1661   <tr height="5"></tr>
1662   <tr>
1663     <td>$option</td>
1664   </tr>
1665   <tr>
1666     <td>
1667       <table width=100%>
1668         <tr class=listheading>
1669 |;
1670
1671   map { print "$column_header{$_}\n" } @column_index;
1672
1673   print qq|
1674         </tr>
1675 |;
1676
1677   $ctid     = 0;
1678   $subtotal = 0;
1679   $i        = 0;
1680
1681   foreach $ref (@{ $form->{AG} }) {
1682
1683     if ($ctid != $ref->{ctid}) {
1684
1685       $i++;
1686
1687       if ($subtotal) {
1688         $c0subtotal = ($c0subtotal != 0) ? 
1689           $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp") : "";
1690         $c30subtotal = ($c30subtotal != 0) ?
1691           $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp") : "";
1692         $c60subtotal = ($c60subtotal != 0) ?
1693           $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp") : "";
1694         $c90subtotal = ($c90subtotal != 0) ?
1695           $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp") : "";
1696       }
1697
1698       $column_data{ct}        = qq|<th>&nbsp;</th>|;
1699       $column_data{invnumber} = qq|<th>&nbsp;</th>|;
1700       $column_data{transdate} = qq|<th>&nbsp;</th>|;
1701       $column_data{duedate}   = qq|<th>&nbsp;</th>|;
1702       $column_data{c0}        =
1703         qq|<th align=right class=listsubtotal>$c0subtotal</th>|;
1704       $column_data{c30} =
1705         qq|<th align=right class=listsubtotal>$c30subtotal</th>|;
1706       $column_data{c60} =
1707         qq|<th align=right class=listsubtotal>$c60subtotal</th>|;
1708       $column_data{c90} =
1709         qq|<th align=right class=listsubtotal>$c90subtotal</th>|;
1710
1711       if ($subtotal) {
1712
1713         # print subtotals
1714         print qq|
1715         <tr class=listsubtotal>
1716 |;
1717
1718         map { print "$column_data{$_}\n" } @column_index;
1719
1720         $column_data{statement} = qq|<td>&nbsp;</td>|;
1721
1722         print qq|
1723         </tr>
1724 |;
1725       }
1726
1727       $subtotal = 1;
1728
1729       $c0subtotal  = 0;
1730       $c30subtotal = 0;
1731       $c60subtotal = 0;
1732       $c90subtotal = 0;
1733
1734       $column_data{ct}        = qq|<td>$ref->{name}</td>|;
1735       $column_data{statement} =
1736         qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
1737       <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
1738       </td>|;
1739     }
1740
1741     $c0subtotal  += $ref->{c0};
1742     $c30subtotal += $ref->{c30};
1743     $c60subtotal += $ref->{c60};
1744     $c90subtotal += $ref->{c90};
1745
1746     $c0total  += $ref->{c0};
1747     $c30total += $ref->{c30};
1748     $c60total += $ref->{c60};
1749     $c90total += $ref->{c90};
1750
1751     $ref->{c0}  = ($ref->{c0} != 0) ? $form->format_amount(\%myconfig, $ref->{c0},  2, "&nbsp;") : "";
1752     $ref->{c30} = ($ref->{c30} != 0) ? $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;") : "";
1753     $ref->{c60} = ($ref->{c60} != 0) ?  $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;") : "";
1754     $ref->{c90} = ($ref->{c90} != 0) ?  $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;") : "";
1755
1756     $href =
1757       qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|
1758       . $form->escape($form->{callback});
1759
1760     $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
1761     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
1762     $column_data{duedate}   = qq|<td>$ref->{duedate}&nbsp;</td>|;
1763     $column_data{c0}        = qq|<td align=right>$ref->{c0}</td>|;
1764     $column_data{c30}       = qq|<td align=right>$ref->{c30}</td>|;
1765     $column_data{c60}       = qq|<td align=right>$ref->{c60}</td>|;
1766     $column_data{c90}       = qq|<td align=right>$ref->{c90}</td>|;
1767
1768     $j++;
1769     $j %= 2;
1770     print qq|
1771         <tr class=listrow$j>
1772 |;
1773
1774     map { print "$column_data{$_}\n" } @column_index;
1775
1776     print qq|
1777         </tr>
1778 |;
1779
1780     $column_data{ct}        = qq|<td>&nbsp;</td>|;
1781     $column_data{statement} = qq|<td>&nbsp;</td>|;
1782
1783     $ctid = $ref->{ctid};
1784
1785   }
1786
1787   # print subtotals
1788   $c0subtotal  = $form->format_amount(\%myconfig, $c0subtotal,  2, "&nbsp;");
1789   $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp;");
1790   $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp;");
1791   $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp;");
1792
1793   print qq|
1794         <tr class=listsubtotal>
1795 |;
1796
1797   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
1798
1799   $column_data{c0}  = qq|<th align=right class=listsubtotal>$c0subtotal</th>|;
1800   $column_data{c30} = qq|<th align=right class=listsubtotal>$c30subtotal</th>|;
1801   $column_data{c60} = qq|<th align=right class=listsubtotal>$c60subtotal</th>|;
1802   $column_data{c90} = qq|<th align=right class=listsubtotal>$c90subtotal</th>|;
1803
1804   map { print "$column_data{$_}\n" } @column_index;
1805
1806   print qq|
1807         </tr>
1808         <tr class=listtotal>
1809 |;
1810
1811   $c0total  = $form->format_amount(\%myconfig, $c0total,  2, "&nbsp;");
1812   $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp;");
1813   $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp;");
1814   $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp;");
1815
1816   $column_data{c0}  = qq|<th align=right class=listtotal>$c0total</th>|;
1817   $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
1818   $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
1819   $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
1820
1821   map { print "$column_data{$_}\n" } @column_index;
1822
1823   print qq|
1824           <input type=hidden name=rowcount value=$i>
1825         </tr>
1826       </table>
1827     </td>
1828   </tr>
1829   <tr>
1830     <td>
1831 |;
1832
1833   &print_options if ($form->{arap} eq 'ar');
1834
1835   print qq|
1836     </td>
1837   </tr>
1838   <tr>
1839     <td><hr size=3 noshade></td>
1840   </tr>
1841 </table>
1842 |;
1843
1844   if ($form->{arap} eq 'ar') {
1845     print qq|
1846 <input type=hidden name=todate value=$form->{todate}>
1847
1848 <input type=hidden name=title value="$form->{title}">
1849
1850 <input type=hidden name=arap value=$form->{arap}>
1851 <input type=hidden name=ct value=$form->{ct}>
1852 <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
1853
1854 <input type=hidden name=department value="$form->{department}">
1855
1856 <input type=hidden name=path value=$form->{path}>
1857 <input type=hidden name=login value=$form->{login}>
1858 <input type=hidden name=password value=$form->{password}>
1859
1860 <br>
1861 <input class=submit type=submit name=action value="|
1862       . $locale->text('Select all') . qq|">
1863 <input class=submit type=submit name=action value="|
1864       . $locale->text('Print') . qq|">
1865 <input class=submit type=submit name=action value="|
1866       . $locale->text('E-mail') . qq|">|;
1867 }
1868
1869 print qq|
1870 </form>
1871
1872 </body>
1873 </html>
1874 |;
1875
1876   $lxdebug->leave_sub();
1877 }
1878
1879 sub select_all {
1880   $lxdebug->enter_sub();
1881
1882   RP->aging(\%myconfig, \%$form);
1883
1884   map { $_->{checked} = "checked" } @{ $form->{AG} };
1885
1886   &aging;
1887
1888   $lxdebug->leave_sub();
1889 }
1890
1891 sub e_mail {
1892   $lxdebug->enter_sub();
1893
1894   # get name and email addresses
1895   for $i (1 .. $form->{rowcount}) {
1896     if ($form->{"statement_$i"}) {
1897       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1898       RP->get_customer(\%myconfig, \%$form);
1899       $selected = 1;
1900       last;
1901     }
1902   }
1903
1904   $form->error($locale->text('Nothing selected!')) unless $selected;
1905
1906   if ($myconfig{role} eq 'admin') {
1907     $bcc = qq|
1908           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1909           <td><input name=bcc size=30 value="$form->{bcc}"></td>
1910 |;
1911   }
1912
1913   $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1914
1915   $form->{media} = "email";
1916
1917   $form->header;
1918
1919   print qq|
1920 <body>
1921
1922 <form method=post action=$form->{script}>
1923
1924 <table width=100%>
1925   <tr class=listtop>
1926     <th>$title</th>
1927   </tr>
1928   <tr height="5"></tr>
1929   <tr>
1930     <td>
1931       <table width=100%>
1932         <tr>
1933           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1934           <td><input name=email size=30 value="$form->{email}"></td>
1935           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1936           <td><input name=cc size=30 value="$form->{cc}"></td>
1937         </tr>
1938         <tr>
1939           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1940           <td><input name=subject size=30 value="$form->{subject}"></td>
1941           $bcc
1942         </tr>
1943       </table>
1944     </td>
1945   </tr>
1946   <tr>
1947     <td>
1948       <table width=100%>
1949         <tr>
1950           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
1951         </tr>
1952         <tr>
1953           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
1954         </tr>
1955       </table>
1956     </td>
1957   </tr>
1958   <tr>
1959     <td>
1960 |;
1961
1962   &print_options;
1963
1964   map { delete $form->{$_} }
1965     qw(action email cc bcc subject message type sendmode format header);
1966
1967   # save all other variables
1968   foreach $key (keys %$form) {
1969     $form->{$key} =~ s/\"/&quot;/g;
1970     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1971   }
1972
1973   print qq|
1974     </td>
1975   </tr>
1976   <tr>
1977     <td><hr size=3 noshade></td>
1978   </tr>
1979 </table>
1980
1981 <input type=hidden name=nextsub value=send_email>
1982
1983 <br>
1984 <input name=action class=submit type=submit value="|
1985     . $locale->text('Continue') . qq|">
1986 </form>
1987
1988 </body>
1989 </html>
1990 |;
1991
1992   $lxdebug->leave_sub();
1993 }
1994
1995 sub send_email {
1996   $lxdebug->enter_sub();
1997
1998   $form->{OUT} = "$sendmail";
1999
2000   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
2001     unless $form->{subject};
2002
2003   RP->aging(\%myconfig, \%$form);
2004
2005   $form->{"statement_1"} = 1;
2006
2007   &print_form;
2008
2009   $form->redirect(
2010                  $locale->text('Statement sent to') . " $form->{$form->{ct}}");
2011
2012   $lxdebug->leave_sub();
2013 }
2014
2015 sub print {
2016   $lxdebug->enter_sub();
2017
2018   if ($form->{media} eq 'printer') {
2019     $form->error($locale->text('Select postscript or PDF!'))
2020       if ($form->{format} !~ /(postscript|pdf)/);
2021   }
2022
2023   for $i (1 .. $form->{rowcount}) {
2024     if ($form->{"statement_$i"}) {
2025       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
2026       $selected = 1;
2027       last;
2028     }
2029   }
2030
2031   $form->error($locale->text('Nothing selected!')) unless $selected;
2032
2033   if ($form->{media} eq 'printer') {
2034     $form->{OUT} = "| $myconfig{printer}";
2035     $form->{"$form->{ct}_id"} = "";
2036   } else {
2037     $form->{"statement_1"} = 1;
2038   }
2039
2040   RP->aging(\%myconfig, \%$form);
2041
2042   &print_form;
2043
2044   $form->redirect($locale->text('Statements sent to printer!'))
2045     if ($form->{media} eq 'printer');
2046
2047   $lxdebug->leave_sub();
2048 }
2049
2050 sub print_form {
2051   $lxdebug->enter_sub();
2052
2053   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
2054
2055   $form->{templates} = "$myconfig{templates}";
2056
2057   $form->{IN} = "$form->{type}.html";
2058
2059   if ($form->{format} eq 'postscript') {
2060     $form->{postscript} = 1;
2061     $form->{IN} =~ s/html$/tex/;
2062   }
2063   if ($form->{format} eq 'pdf') {
2064     $form->{pdf} = 1;
2065     $form->{IN} =~ s/html$/tex/;
2066   }
2067
2068   $i = 0;
2069   while (@{ $form->{AG} }) {
2070
2071     $ref = shift @{ $form->{AG} };
2072
2073     if ($ctid != $ref->{ctid}) {
2074
2075       $ctid = $ref->{ctid};
2076       $i++;
2077
2078       if ($form->{"statement_$i"}) {
2079
2080         @a =
2081           (name, street, zipcode, city, country, contact, email,
2082            "$form->{ct}phone", "$form->{ct}fax");
2083         map { $form->{$_} = $ref->{$_} } @a;
2084
2085         $form->{ $form->{ct} } = $form->{name};
2086         $form->{"$form->{ct}_id"} = $ref->{ctid};
2087
2088         map { $form->{$_} = () } qw(invnumber invdate duedate);
2089         $form->{total} = 0;
2090         foreach $item (qw(c0 c30 c60 c90)) {
2091           $form->{$item} = ();
2092           $form->{"${item}total"} = 0;
2093         }
2094
2095         &statement_details($ref);
2096
2097         while ($ref) {
2098
2099           if (scalar(@{ $form->{AG} }) > 0) {
2100
2101             # one or more left to go
2102             if ($ctid == $form->{AG}->[0]->{ctid}) {
2103               $ref = shift @{ $form->{AG} };
2104               &statement_details($ref);
2105
2106               # any more?
2107               $ref = scalar(@{ $form->{AG} });
2108             } else {
2109               $ref = 0;
2110             }
2111           } else {
2112
2113             # set initial ref to 0
2114             $ref = 0;
2115           }
2116
2117         }
2118
2119         map {
2120           $form->{"${_}total"} =
2121             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2122         } (c0, c30, c60, c90, "");
2123
2124         $form->parse_template(\%myconfig, $userspath);
2125
2126       }
2127     }
2128   }
2129   # saving the history
2130   if(!exists $form->{addition} && $form->{id} ne "") {
2131         $form->{addition} = "PRINTED";
2132         $form->{what_done} = $form->{type};
2133         $form->save_history($form->dbconnect(\%myconfig));
2134   }
2135   # /saving the history 
2136   $lxdebug->leave_sub();
2137 }
2138
2139 sub statement_details {
2140   $lxdebug->enter_sub();
2141   my ($ref) = @_;
2142
2143   push @{ $form->{invnumber} }, $ref->{invnumber};
2144   push @{ $form->{invdate} },   $ref->{transdate};
2145   push @{ $form->{duedate} },   $ref->{duedate};
2146
2147   foreach $item (qw(c0 c30 c60 c90)) {
2148     if ($ref->{exchangerate} * 1) {
2149       $ref->{$item} =
2150         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2151     }
2152     $form->{"${item}total"} += $ref->{$item};
2153     $form->{total}          += $ref->{$item};
2154     push @{ $form->{$item} },
2155       $form->format_amount(\%myconfig, $ref->{$item}, 2);
2156   }
2157
2158   $lxdebug->leave_sub();
2159 }
2160
2161 sub generate_tax_report {
2162   $lxdebug->enter_sub();
2163
2164   RP->tax_report(\%myconfig, \%$form);
2165
2166   $descvar     = "$form->{accno}_description";
2167   $description = $form->escape($form->{$descvar});
2168   $ratevar     = "$form->{accno}_rate";
2169
2170   if ($form->{accno} =~ /^gifi_/) {
2171     $descvar     = "gifi_$form->{accno}_description";
2172     $description = $form->escape($form->{$descvar});
2173     $ratevar     = "gifi_$form->{accno}_rate";
2174   }
2175
2176   $department = $form->escape($form->{department});
2177
2178   # construct href
2179   $href =
2180     "$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}";
2181
2182   # construct callback
2183   $description = $form->escape($form->{$descvar},   1);
2184   $department  = $form->escape($form->{department}, 1);
2185   $callback    =
2186     "$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}";
2187
2188   $form->{title} = $locale->text('GIFI') . " - "
2189     if ($form->{accno} =~ /^gifi_/);
2190
2191   $title = $form->escape($form->{title});
2192   $href .= "&title=$title";
2193   $title = $form->escape($form->{title}, 1);
2194   $callback .= "&title=$title";
2195
2196   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2197
2198   @columns =
2199     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2200
2201   foreach $item (@columns) {
2202     if ($form->{"l_$item"} eq "Y") {
2203       push @column_index, $item;
2204
2205       # add column to href and callback
2206       $callback .= "&l_$item=Y";
2207       $href     .= "&l_$item=Y";
2208     }
2209   }
2210
2211   if ($form->{l_subtotal} eq 'Y') {
2212     $callback .= "&l_subtotal=Y";
2213     $href     .= "&l_subtotal=Y";
2214   }
2215
2216   if ($form->{department}) {
2217     ($department) = split /--/, $form->{department};
2218     $option = $locale->text('Department') . " : $department";
2219   }
2220
2221   # if there are any dates
2222   if ($form->{fromdate} || $form->{todate}) {
2223     if ($form->{fromdate}) {
2224       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2225     }
2226     if ($form->{todate}) {
2227       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2228     }
2229
2230     $form->{period} = "$fromdate - $todate";
2231   } else {
2232     $form->{period} =
2233       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2234   }
2235
2236   if ($form->{db} eq 'ar') {
2237     $name    = $locale->text('Customer');
2238     $invoice = 'is.pl';
2239     $arap    = 'ar.pl';
2240   }
2241   if ($form->{db} eq 'ap') {
2242     $name    = $locale->text('Vendor');
2243     $invoice = 'ir.pl';
2244     $arap    = 'ap.pl';
2245   }
2246
2247   $option .= "<br>" if $option;
2248   $option .= "$form->{period}";
2249
2250   $column_header{id} =
2251       qq|<th><a class=listheading href=$href&sort=id>|
2252     . $locale->text('ID')
2253     . qq|</th>|;
2254   $column_header{invnumber} =
2255       qq|<th><a class=listheading href=$href&sort=invnumber>|
2256     . $locale->text('Invoice')
2257     . qq|</th>|;
2258   $column_header{transdate} =
2259       qq|<th><a class=listheading href=$href&sort=transdate>|
2260     . $locale->text('Date')
2261     . qq|</th>|;
2262   $column_header{netamount} =
2263     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2264   $column_header{tax} =
2265     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2266   $column_header{amount} =
2267     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2268
2269   $column_header{name} =
2270     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2271
2272   $form->header;
2273
2274   print qq|
2275 <body>
2276
2277 <table width=100%>
2278   <tr>
2279     <th class=listtop colspan=$colspan>$form->{title}</th>
2280   </tr>
2281   <tr height="5"></tr>
2282   <tr>
2283     <td>$option</td>
2284   </tr>
2285   <tr>
2286     <td>
2287       <table width=100%>
2288         <tr class=listheading>
2289 |;
2290
2291   map { print "$column_header{$_}\n" } @column_index;
2292
2293   print qq|
2294         </tr>
2295 |;
2296
2297   # add sort and escape callback
2298   $callback = $form->escape($callback . "&sort=$form->{sort}");
2299
2300   if (@{ $form->{TR} }) {
2301     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2302   }
2303
2304   foreach $ref (@{ $form->{TR} }) {
2305
2306     $module = ($ref->{invoice}) ? $invoice : $arap;
2307
2308     if ($form->{l_subtotal} eq 'Y') {
2309       if ($sameitem ne $ref->{ $form->{sort} }) {
2310         &tax_subtotal;
2311         $sameitem = $ref->{ $form->{sort} };
2312       }
2313     }
2314
2315     $totalnetamount += $ref->{netamount};
2316     $totaltax       += $ref->{tax};
2317     $ref->{amount} = $ref->{netamount} + $ref->{tax};
2318
2319     $subtotalnetamount += $ref->{netamount};
2320     $subtotaltax       += $ref->{tax};
2321
2322     map {
2323       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;");
2324     } qw(netamount tax amount);
2325
2326     $column_data{id}        = qq|<td>$ref->{id}</td>|;
2327     $column_data{invnumber} =
2328       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>|;
2329     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2330     $column_data{name}      = qq|<td>$ref->{name}&nbsp;</td>|;
2331
2332     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2333       qw(netamount tax amount);
2334
2335     $i++;
2336     $i %= 2;
2337     print qq|
2338         <tr class=listrow$i>
2339 |;
2340
2341     map { print "$column_data{$_}\n" } @column_index;
2342
2343     print qq|
2344         </tr>
2345 |;
2346
2347   }
2348
2349   if ($form->{l_subtotal} eq 'Y') {
2350     &tax_subtotal;
2351   }
2352
2353   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
2354
2355   print qq|
2356         </tr>
2357         <tr class=listtotal>
2358 |;
2359
2360   $total =
2361     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
2362   $totalnetamount =
2363     $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
2364   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
2365
2366   $column_data{netamount} =
2367     qq|<th class=listtotal align=right>$totalnetamount</th>|;
2368   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
2369   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2370
2371   map { print "$column_data{$_}\n" } @column_index;
2372
2373   print qq|
2374         </tr>
2375       </table>
2376     </td>
2377   </tr>
2378   <tr>
2379     <td><hr size=3 noshade></td>
2380   </tr>
2381 </table>
2382
2383 </body>
2384 </html>
2385 |;
2386
2387   $lxdebug->leave_sub();
2388 }
2389
2390 sub tax_subtotal {
2391   $lxdebug->enter_sub();
2392
2393   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2394
2395   $subtotalnetamount =
2396     $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
2397   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
2398   $subtotal =
2399     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2400                          2, "&nbsp;");
2401
2402   $column_data{netamount} =
2403     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2404   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2405   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2406
2407   $subtotalnetamount = 0;
2408   $subtotaltax       = 0;
2409
2410   print qq|
2411         <tr class=listsubtotal>
2412 |;
2413   map { print "\n$column_data{$_}" } @column_index;
2414
2415   print qq|
2416         </tr>
2417 |;
2418
2419   $lxdebug->leave_sub();
2420 }
2421
2422 sub list_payments {
2423   $lxdebug->enter_sub();
2424
2425   if ($form->{account}) {
2426     ($form->{paymentaccounts}) = split /--/, $form->{account};
2427   }
2428   if ($form->{department}) {
2429     ($department, $form->{department_id}) = split /--/, $form->{department};
2430     $option = $locale->text('Department') . " : $department";
2431   }
2432
2433   RP->payments(\%myconfig, \%$form);
2434
2435   @columns =
2436     $form->sort_columns(qw(transdate reference name paid source memo));
2437
2438   # construct href
2439   $account    = $form->escape($form->{account});
2440   $title      = $form->escape($form->{title});
2441   $department = $form->escape($form->{department});
2442   $form->{paymentaccounts} =~ s/ /%20/g;
2443   $reference = $form->escape($form->{reference});
2444   $source    = $form->escape($form->{source});
2445   $memo      = $form->escape($form->{memo});
2446
2447   $href =
2448     "$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";
2449
2450   # construct callback
2451   $account    = $form->escape($form->{account},    1);
2452   $title      = $form->escape($form->{title},      1);
2453   $department = $form->escape($form->{department}, 1);
2454   $reference  = $form->escape($form->{reference},  1);
2455   $source     = $form->escape($form->{source},     1);
2456   $memo       = $form->escape($form->{memo},       1);
2457
2458   $form->{callback} =
2459     "$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}";
2460   $callback = $form->escape($form->{callback});
2461
2462   $column_header{name} =
2463       "<th><a class=listheading href=$href&sort=name>"
2464     . $locale->text('Description')
2465     . "</a></th>";
2466   $column_header{reference} =
2467       "<th><a class=listheading href=$href&sort=invnumber>"
2468     . $locale->text('Reference')
2469     . "</a></th>";
2470   $column_header{transdate} =
2471       "<th><a class=listheading href=$href&sort=transdate>"
2472     . $locale->text('Date')
2473     . "</a></th>";
2474   $column_header{paid} =
2475     "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
2476   $column_header{source} =
2477       "<th><a class=listheading href=$href&sort=source>"
2478     . $locale->text('Source')
2479     . "</a></th>";
2480   $column_header{memo} =
2481       "<th><a class=listheading href=$href&sort=memo>"
2482     . $locale->text('Memo')
2483     . "</a></th>";
2484
2485   if ($form->{fromdate}) {
2486     $option .= "\n<br>" if ($option);
2487     $option .=
2488         $locale->text('From') . "&nbsp;"
2489       . $locale->date(\%myconfig, $form->{fromdate}, 1);
2490   }
2491   if ($form->{todate}) {
2492     $option .= "\n<br>" if ($option);
2493     $option .=
2494         $locale->text('bis') . "&nbsp;"
2495       . $locale->date(\%myconfig, $form->{todate}, 1);
2496   }
2497
2498   @column_index = @columns;
2499   $colspan      = $#column_index + 1;
2500
2501   $form->header;
2502
2503   print qq|
2504 <body>
2505
2506 <table width=100%>
2507   <tr>
2508     <th class=listtop>$form->{title}</th>
2509   </tr>
2510   <tr height="5"></tr>
2511   <tr>
2512     <td>$option</td>
2513   </tr>
2514   <tr>
2515     <td>
2516       <table width=100%>
2517         <tr class=listheading>
2518 |;
2519
2520   map { print "\n$column_header{$_}" } @column_index;
2521
2522   print qq|
2523         </tr>
2524 |;
2525
2526   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2527
2528     next unless @{ $form->{ $ref->{id} } };
2529
2530     print qq|
2531         <tr>
2532           <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
2533         </tr>
2534 |;
2535
2536     foreach $payment (@{ $form->{ $ref->{id} } }) {
2537
2538       $module = $payment->{module};
2539       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2540       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2541
2542       $href =
2543         qq|${module}.pl?path=$form->{path}&action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|;
2544
2545       $column_data{name}      = "<td>$payment->{name}&nbsp;</td>";
2546       $column_data{reference} =
2547         qq|<td><a href=$href>$payment->{invnumber}</a></td>|;
2548       $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
2549       $column_data{paid}      =
2550           "<td align=right>"
2551         . $form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")
2552         . "</td>";
2553       $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
2554       $column_data{memo}   = "<td>$payment->{memo}&nbsp;</td>";
2555
2556       $subtotalpaid += $payment->{paid};
2557       $totalpaid    += $payment->{paid};
2558
2559       $i++;
2560       $i %= 2;
2561       print qq|
2562         <tr class=listrow$i>
2563 |;
2564
2565       map { print "\n$column_data{$_}" } @column_index;
2566
2567       print qq|
2568         </tr>
2569 |;
2570
2571     }
2572
2573     # print subtotals
2574     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2575
2576     $column_data{paid} =
2577       "<th class=listsubtotal align=right>"
2578       . $form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;") . "</th>";
2579
2580     print qq|
2581         <tr class=listsubtotal>
2582 |;
2583
2584     map { print "\n$column_data{$_}" } @column_index;
2585
2586     print qq|
2587         </tr>
2588 |;
2589
2590     $subtotalpaid = 0;
2591
2592   }
2593
2594   # print total
2595   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2596
2597   $column_data{paid} =
2598     "<th class=listtotal align=right>"
2599     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;") . "</th>";
2600
2601   print qq|
2602         <tr class=listtotal>
2603 |;
2604
2605   map { print "\n$column_data{$_}" } @column_index;
2606
2607   print qq|
2608         </tr>
2609
2610       </table>
2611     </td>
2612   </tr>
2613   <tr>
2614     <td><hr size=3 noshade></td>
2615   </tr>
2616 </table>
2617
2618 </body>
2619 </html>
2620 |;
2621
2622   $lxdebug->leave_sub();
2623 }
2624
2625 sub config {
2626   $lxdebug->enter_sub();
2627   edit();
2628
2629   #$form->header;
2630   #print qq|Hallo|;
2631   $lxdebug->leave_sub();
2632 }
2633
2634 sub debug {
2635
2636   $form->debug();
2637
2638 }
2639
2640 sub winston_export {
2641   $lxdebug->enter_sub();
2642
2643   #create_winston();
2644   $form->{winston} = 1;
2645   &generate_ustva();
2646   $lxdebug->leave_sub();
2647 }
2648
2649 sub print_options {
2650   $lxdebug->enter_sub();
2651
2652   $form->{sendmode} = "attachment";
2653
2654   $form->{"format"} =
2655     $form->{"format"} ? $form->{"format"} :
2656     $myconfig{"template_format"} ? $myconfig{"template_format"} :
2657     "pdf";
2658
2659   $form->{"copies"} =
2660     $form->{"copies"} ? $form->{"copies"} :
2661     $myconfig{"copies"} ? $myconfig{"copies"} :
2662     2;
2663
2664   $form->{PD}{ $form->{type} }     = "selected";
2665   $form->{DF}{ $form->{format} }   = "selected";
2666   $form->{OP}{ $form->{media} }    = "selected";
2667   $form->{SM}{ $form->{sendmode} } = "selected";
2668
2669   if ($form->{report} eq 'ustva') {
2670     $type = qq|
2671             <option value=ustva $form->{PD}{ustva}>| . $locale->text('ustva');
2672   } else {
2673     $type = qq|
2674             <option value=statement $form->{PD}{statement}>|
2675       . $locale->text('Statement');
2676   }
2677
2678   if ($form->{media} eq 'email') {
2679     $media = qq|
2680             <option value=attachment $form->{SM}{attachment}>|
2681       . $locale->text('Attachment') . qq|
2682             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2683   } else {
2684     $media = qq|
2685             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2686     if ($myconfig{printer} && $latex_templates) {
2687       $media .= qq|
2688             <option value=printer $form->{OP}{printer}>|
2689         . $locale->text('Printer');
2690     }
2691   }
2692
2693   if ($latex_templates) {
2694     $format .= qq|
2695             <option value=html $form->{DF}{html}>|
2696       . $locale->text('HTML') . qq|
2697             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
2698     if ($form->{report} ne 'ustva') {
2699       $format . qq|
2700             <option value=postscript $form->{DF}{postscript}>|
2701         . $locale->text('Postscript');
2702     }
2703   }
2704
2705   print qq|
2706 <table>
2707   <tr>
2708     <td><select name=type>$type</select></td>
2709     <td><select name=format>$format</select></td>
2710     <td><select name=media>$media</select></td>
2711 |;
2712
2713   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2714     print qq|
2715       <td>| . $locale->text('Copies') . qq|
2716       <input name=copies size=2 value=$form->{copies}></td>
2717 |;
2718   }
2719
2720   print qq|
2721   </tr>
2722 </table>
2723 |;
2724
2725   $lxdebug->leave_sub();
2726 }
2727
2728 sub generate_bwa {
2729   $lxdebug->enter_sub();
2730   $form->{padding} = "&nbsp;&nbsp;";
2731   $form->{bold}    = "<b>";
2732   $form->{endbold} = "</b>";
2733   $form->{br}      = "<br>";
2734
2735   if ($form->{reporttype} eq "custom") {
2736
2737     #forgotten the year --> thisyear
2738     if ($form->{year} !~ m/^\d\d\d\d$/) {
2739       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2740         /(\d\d\d\d)/;
2741       $form->{year} = $1;
2742     }
2743
2744     #yearly report
2745     if ($form->{duetyp} eq "13") {
2746       $form->{fromdate}        = "1.1.$form->{year}";
2747       $form->{todate}          = "31.12.$form->{year}";
2748       $form->{comparefromdate} = "1.01.$form->{year}";
2749       $form->{comparetodate}   = "31.12.$form->{year}";
2750     }
2751
2752     #Quater reports
2753     if ($form->{duetyp} eq "A") {
2754       $form->{fromdate}        = "1.1.$form->{year}";
2755       $form->{todate}          = "31.3.$form->{year}";
2756       $form->{comparefromdate} = "1.01.$form->{year}";
2757       $form->{comparetodate}   = "31.03.$form->{year}";
2758     }
2759     if ($form->{duetyp} eq "B") {
2760       $form->{fromdate}        = "1.4.$form->{year}";
2761       $form->{todate}          = "30.6.$form->{year}";
2762       $form->{comparefromdate} = "1.01.$form->{year}";
2763       $form->{comparetodate}   = "30.06.$form->{year}";
2764     }
2765     if ($form->{duetyp} eq "C") {
2766       $form->{fromdate}        = "1.7.$form->{year}";
2767       $form->{todate}          = "30.9.$form->{year}";
2768       $form->{comparefromdate} = "1.01.$form->{year}";
2769       $form->{comparetodate}   = "30.09.$form->{year}";
2770     }
2771     if ($form->{duetyp} eq "D") {
2772       $form->{fromdate}        = "1.10.$form->{year}";
2773       $form->{todate}          = "31.12.$form->{year}";
2774       $form->{comparefromdate} = "1.01.$form->{year}";
2775       $form->{comparetodate}   = "31.12.$form->{year}";
2776     }
2777
2778     #Monthly reports
2779   SWITCH: {
2780       $form->{duetyp} eq "1" && do {
2781         $form->{fromdate}        = "1.1.$form->{year}";
2782         $form->{todate}          = "31.1.$form->{year}";
2783         $form->{comparefromdate} = "1.01.$form->{year}";
2784         $form->{comparetodate}   = "31.01.$form->{year}";
2785         last SWITCH;
2786       };
2787       $form->{duetyp} eq "2" && do {
2788         $form->{fromdate} = "1.2.$form->{year}";
2789
2790         #this works from 1901 to 2099, 1900 and 2100 fail.
2791         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2792         $form->{todate}          = "$leap.2.$form->{year}";
2793         $form->{comparefromdate} = "1.01.$form->{year}";
2794         $form->{comparetodate}   = "$leap.02.$form->{year}";
2795         last SWITCH;
2796       };
2797       $form->{duetyp} eq "3" && do {
2798         $form->{fromdate}        = "1.3.$form->{year}";
2799         $form->{todate}          = "31.3.$form->{year}";
2800         $form->{comparefromdate} = "1.01.$form->{year}";
2801         $form->{comparetodate}   = "31.03.$form->{year}";
2802         last SWITCH;
2803       };
2804       $form->{duetyp} eq "4" && do {
2805         $form->{fromdate}        = "1.4.$form->{year}";
2806         $form->{todate}          = "30.4.$form->{year}";
2807         $form->{comparefromdate} = "1.01.$form->{year}";
2808         $form->{comparetodate}   = "30.04.$form->{year}";
2809         last SWITCH;
2810       };
2811       $form->{duetyp} eq "5" && do {
2812         $form->{fromdate}        = "1.5.$form->{year}";
2813         $form->{todate}          = "31.5.$form->{year}";
2814         $form->{comparefromdate} = "1.01.$form->{year}";
2815         $form->{comparetodate}   = "31.05.$form->{year}";
2816         last SWITCH;
2817       };
2818       $form->{duetyp} eq "6" && do {
2819         $form->{fromdate}        = "1.6.$form->{year}";
2820         $form->{todate}          = "30.6.$form->{year}";
2821         $form->{comparefromdate} = "1.01.$form->{year}";
2822         $form->{comparetodate}   = "30.06.$form->{year}";
2823         last SWITCH;
2824       };
2825       $form->{duetyp} eq "7" && do {
2826         $form->{fromdate}        = "1.7.$form->{year}";
2827         $form->{todate}          = "31.7.$form->{year}";
2828         $form->{comparefromdate} = "1.01.$form->{year}";
2829         $form->{comparetodate}   = "31.07.$form->{year}";
2830         last SWITCH;
2831       };
2832       $form->{duetyp} eq "8" && do {
2833         $form->{fromdate}        = "1.8.$form->{year}";
2834         $form->{todate}          = "31.8.$form->{year}";
2835         $form->{comparefromdate} = "1.01.$form->{year}";
2836         $form->{comparetodate}   = "31.08.$form->{year}";
2837         last SWITCH;
2838       };
2839       $form->{duetyp} eq "9" && do {
2840         $form->{fromdate}        = "1.9.$form->{year}";
2841         $form->{todate}          = "30.9.$form->{year}";
2842         $form->{comparefromdate} = "1.01.$form->{year}";
2843         $form->{comparetodate}   = "30.09.$form->{year}";
2844         last SWITCH;
2845       };
2846       $form->{duetyp} eq "10" && do {
2847         $form->{fromdate}        = "1.10.$form->{year}";
2848         $form->{todate}          = "31.10.$form->{year}";
2849         $form->{comparefromdate} = "1.01.$form->{year}";
2850         $form->{comparetodate}   = "31.10.$form->{year}";
2851         last SWITCH;
2852       };
2853       $form->{duetyp} eq "11" && do {
2854         $form->{fromdate}        = "1.11.$form->{year}";
2855         $form->{todate}          = "30.11.$form->{year}";
2856         $form->{comparefromdate} = "1.01.$form->{year}";
2857         $form->{comparetodate}   = "30.11.$form->{year}";
2858         last SWITCH;
2859       };
2860       $form->{duetyp} eq "12" && do {
2861         $form->{fromdate}        = "1.12.$form->{year}";
2862         $form->{todate}          = "31.12.$form->{year}";
2863         $form->{comparefromdate} = "1.01.$form->{year}";
2864         $form->{comparetodate}   = "31.12.$form->{year}";
2865         last SWITCH;
2866       };
2867     }
2868   } else {
2869     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2870     $form->{fromdate} = "${dd}.${mm}.${yy}";
2871     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2872     $form->{todate}          = "${dd}.${mm}.${yy}";
2873     $form->{comparefromdate} = "01.01.$yy";
2874     $form->{comparetodate}   = $form->{todate};
2875   }
2876
2877   RP->bwa(\%myconfig, \%$form);
2878
2879   ($form->{department}) = split /--/, $form->{department};
2880
2881   $form->{period} =
2882     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2883   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2884
2885   # if there are any dates construct a where
2886   if ($form->{fromdate} || $form->{todate}) {
2887
2888     unless ($form->{todate}) {
2889       $form->{todate} = $form->current_date(\%myconfig);
2890     }
2891
2892     my %germandate = ("dateformat" => "dd.mm.yyyy");
2893
2894     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
2895     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2896
2897     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
2898     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2899
2900     $form->{this_period} = "$shortfromdate\n$shorttodate";
2901     $form->{period}      =
2902         $locale->text('for Period')
2903       . qq|\n$longfromdate |
2904       . $locale->text('bis')
2905       . qq| $longtodate|;
2906   }
2907
2908   # setup variables for the form
2909   @a = qw(company address businessnumber);
2910   map { $form->{$_} = $myconfig{$_} } @a;
2911   $form->{templates} = $myconfig{templates};
2912
2913   $form->{IN} = "bwa.html";
2914
2915   $form->parse_template;
2916
2917   $lxdebug->leave_sub();
2918 }
2919
2920 sub generate_ustva {
2921   $lxdebug->enter_sub();
2922
2923   # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
2924   # Einlesen der Finanzamtdaten
2925   get_config($userspath, 'finanzamt.ini');
2926
2927   #  &get_project(generate_bwa);
2928   @anmeldungszeitraum =
2929     qw(0401, 0402, 0403, 0404, 0405, 0405, 0406, 0407, 0408, 0409, 0410, 0411, 0412, 0441, 0442, 0443, 0444);
2930
2931   foreach $item (@anmeldungszeitraum) {
2932     $form->{$item} = "";
2933   }
2934   if ($form->{reporttype} eq "custom") {
2935
2936     #forgotten the year --> thisyear
2937     if ($form->{year} !~ m/^\d\d\d\d$/) {
2938       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2939         /(\d\d\d\d)/;
2940       $form->{year} = $1;
2941     }
2942
2943     #yearly report
2944     if ($form->{duetyp} eq "13") {
2945       $form->{fromdate} = "1.1.$form->{year}";
2946       $form->{todate}   = "31.12.$form->{year}";
2947     }
2948
2949     #Quater reports
2950     if ($form->{duetyp} eq "A") {
2951       $form->{fromdate} = "1.1.$form->{year}";
2952       $form->{todate}   = "31.3.$form->{year}";
2953       $form->{"0441"}   = "X";
2954     }
2955     if ($form->{duetyp} eq "B") {
2956       $form->{fromdate} = "1.4.$form->{year}";
2957       $form->{todate}   = "30.6.$form->{year}";
2958       $form->{"0442"}   = "X";
2959     }
2960     if ($form->{duetyp} eq "C") {
2961       $form->{fromdate} = "1.7.$form->{year}";
2962       $form->{todate}   = "30.9.$form->{year}";
2963       $form->{"0443"}   = "X";
2964     }
2965     if ($form->{duetyp} eq "D") {
2966       $form->{fromdate} = "1.10.$form->{year}";
2967       $form->{todate}   = "31.12.$form->{year}";
2968       $form->{"0444"}   = "X";
2969     }
2970
2971     #Monthly reports
2972   SWITCH: {
2973       $form->{duetyp} eq "1" && do {
2974         $form->{fromdate} = "1.1.$form->{year}";
2975         $form->{todate}   = "31.1.$form->{year}";
2976         $form->{"0401"}   = "X";
2977         last SWITCH;
2978       };
2979       $form->{duetyp} eq "2" && do {
2980         $form->{fromdate} = "1.2.$form->{year}";
2981
2982         #this works from 1901 to 2099, 1900 and 2100 fail.
2983         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2984         $form->{todate} = "$leap.2.$form->{year}";
2985         $form->{"0402"} = "X";
2986         last SWITCH;
2987       };
2988       $form->{duetyp} eq "3" && do {
2989         $form->{fromdate} = "1.3.$form->{year}";
2990         $form->{todate}   = "31.3.$form->{year}";
2991         $form->{"0403"}   = "X";
2992         last SWITCH;
2993       };
2994       $form->{duetyp} eq "4" && do {
2995         $form->{fromdate} = "1.4.$form->{year}";
2996         $form->{todate}   = "30.4.$form->{year}";
2997         $form->{"0404"}   = "X";
2998         last SWITCH;
2999       };
3000       $form->{duetyp} eq "5" && do {
3001         $form->{fromdate} = "1.5.$form->{year}";
3002         $form->{todate}   = "31.5.$form->{year}";
3003         $form->{"0405"}   = "X";
3004         last SWITCH;
3005       };
3006       $form->{duetyp} eq "6" && do {
3007         $form->{fromdate} = "1.6.$form->{year}";
3008         $form->{todate}   = "30.6.$form->{year}";
3009         $form->{"0406"}   = "X";
3010         last SWITCH;
3011       };
3012       $form->{duetyp} eq "7" && do {
3013         $form->{fromdate} = "1.7.$form->{year}";
3014         $form->{todate}   = "31.7.$form->{year}";
3015         $form->{"0407"}   = "X";
3016         last SWITCH;
3017       };
3018       $form->{duetyp} eq "8" && do {
3019         $form->{fromdate} = "1.8.$form->{year}";
3020         $form->{todate}   = "31.8.$form->{year}";
3021         $form->{"0408"}   = "X";
3022         last SWITCH;
3023       };
3024       $form->{duetyp} eq "9" && do {
3025         $form->{fromdate} = "1.9.$form->{year}";
3026         $form->{todate}   = "30.9.$form->{year}";
3027         $form->{"0409"}   = "X";
3028         last SWITCH;
3029       };
3030       $form->{duetyp} eq "10" && do {
3031         $form->{fromdate} = "1.10.$form->{year}";
3032         $form->{todate}   = "31.10.$form->{year}";
3033         $form->{"0410"}   = "X";
3034         last SWITCH;
3035       };
3036       $form->{duetyp} eq "11" && do {
3037         $form->{fromdate} = "1.11.$form->{year}";
3038         $form->{todate}   = "30.11.$form->{year}";
3039         $form->{"0411"}   = "X";
3040         last SWITCH;
3041       };
3042       $form->{duetyp} eq "12" && do {
3043         $form->{fromdate} = "1.12.$form->{year}";
3044         $form->{todate}   = "31.12.$form->{year}";
3045         $form->{"0412"}   = "X";
3046         last SWITCH;
3047       };
3048     }
3049   }
3050
3051   #    $locale->date(\%myconfig, $form->current_date(\%myconfig), 0)=~ /(\d\d\d\d)/;
3052   #    $form->{year}= $1;
3053   #    $form->{fromdate}="1.1.$form->{year}";
3054   #    $form->{todate}="31.3.$form->{year}";
3055   #    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3056   #  }
3057
3058   RP->ustva(\%myconfig, \%$form);
3059
3060   ($form->{department}) = split /--/, $form->{department};
3061
3062   $form->{period} =
3063     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3064   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
3065
3066   # if there are any dates construct a where
3067   if ($form->{fromdate} || $form->{todate}) {
3068
3069     unless ($form->{todate}) {
3070       $form->{todate} = $form->current_date(\%myconfig);
3071     }
3072
3073     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
3074     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
3075
3076     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
3077     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
3078
3079     $form->{this_period} = "$shortfromdate\n$shorttodate";
3080     $form->{period}      =
3081         $locale->text('for Period')
3082       . qq|<br>\n$longfromdate |
3083       . $locale->text('bis')
3084       . qq| $longtodate|;
3085   }
3086
3087   if ($form->{comparefromdate} || $form->{comparetodate}) {
3088     $longcomparefromdate =
3089       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
3090     $shortcomparefromdate =
3091       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
3092
3093     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
3094     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
3095
3096     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
3097     $form->{period} .=
3098         "\n$longcomparefromdate "
3099       . $locale->text('bis')
3100       . qq| $longcomparetodate|;
3101   }
3102
3103   $form->{Datum_heute} =
3104     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
3105
3106   if (   $form->{format} eq 'pdf'
3107       or $form->{format} eq 'postscript') {
3108     $form->{padding} = "~~";
3109     $form->{bold}    = "\textbf{";
3110     $form->{endbold} = "}";
3111     $form->{br}      = '\\\\';
3112
3113     @numbers = qw(51r 86r 97r 93r 96 43 45
3114       66 62 67);
3115     foreach $number (@numbers) {
3116       $form->{$number} =~ s/,/~~/g;
3117     }
3118
3119       } elsif ($form->{format} eq 'html') {
3120     $form->{padding} = "&nbsp;&nbsp;";
3121     $form->{bold}    = "<b>";
3122     $form->{endbold} = "</b>";
3123     $form->{br}      = "<br>"
3124
3125   }
3126
3127   # setup variables for the form
3128   @a = qw(company address businessnumber);
3129   map { $form->{$_} = $myconfig{$_} } @a;
3130
3131   $form->{address} =~ s/\\n/$form->{br}/g;
3132
3133   if ($form->{winston} eq '1') {
3134     create_winston();
3135
3136   } else {
3137     $form->{templates} = $myconfig{templates};
3138     $form->{IN}        = "$form->{type}";
3139     $form->{IN} .= '.tex'
3140       if (   $form->{format} eq 'pdf'
3141           or $form->{format} eq 'postscript');
3142     $form->{IN} .= '.html' if ($form->{format} eq 'html');
3143
3144     $form->parse_template(\%myconfig, $userspath);
3145
3146     # $form->parse_template;
3147   }
3148   $lxdebug->leave_sub();
3149 }