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