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