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