Überprüfen auf korrekte Eingaben eingepflegt. (common.js check_right_date_format...
[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->{addition} = "PRINTED";
2105         $form->{what_done} = $form->{type};
2106         $form->save_history($form->dbconnect(\%myconfig));
2107   }
2108   # /saving the history 
2109   $lxdebug->leave_sub();
2110 }
2111
2112 sub statement_details {
2113   $lxdebug->enter_sub();
2114   my ($ref) = @_;
2115
2116   push @{ $form->{invnumber} }, $ref->{invnumber};
2117   push @{ $form->{invdate} },   $ref->{transdate};
2118   push @{ $form->{duedate} },   $ref->{duedate};
2119
2120   foreach $item (qw(c0 c30 c60 c90)) {
2121     if ($ref->{exchangerate} * 1) {
2122       $ref->{$item} =
2123         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2124     }
2125     $form->{"${item}total"} += $ref->{$item};
2126     $form->{total}          += $ref->{$item};
2127     push @{ $form->{$item} },
2128       $form->format_amount(\%myconfig, $ref->{$item}, 2);
2129   }
2130
2131   $lxdebug->leave_sub();
2132 }
2133
2134 sub generate_tax_report {
2135   $lxdebug->enter_sub();
2136
2137   RP->tax_report(\%myconfig, \%$form);
2138
2139   $descvar     = "$form->{accno}_description";
2140   $description = $form->escape($form->{$descvar});
2141   $ratevar     = "$form->{accno}_rate";
2142
2143   $department = $form->escape($form->{department});
2144
2145   # construct href
2146   $href =
2147     "$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}";
2148
2149   # construct callback
2150   $description = $form->escape($form->{$descvar},   1);
2151   $department  = $form->escape($form->{department}, 1);
2152   $callback    =
2153     "$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}";
2154
2155   $title = $form->escape($form->{title});
2156   $href .= "&title=$title";
2157   $title = $form->escape($form->{title}, 1);
2158   $callback .= "&title=$title";
2159
2160   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2161
2162   @columns =
2163     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2164
2165   foreach $item (@columns) {
2166     if ($form->{"l_$item"} eq "Y") {
2167       push @column_index, $item;
2168
2169       # add column to href and callback
2170       $callback .= "&l_$item=Y";
2171       $href     .= "&l_$item=Y";
2172     }
2173   }
2174
2175   if ($form->{l_subtotal} eq 'Y') {
2176     $callback .= "&l_subtotal=Y";
2177     $href     .= "&l_subtotal=Y";
2178   }
2179
2180   if ($form->{department}) {
2181     ($department) = split /--/, $form->{department};
2182     $option = $locale->text('Department') . " : $department";
2183   }
2184
2185   # if there are any dates
2186   if ($form->{fromdate} || $form->{todate}) {
2187     if ($form->{fromdate}) {
2188       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2189     }
2190     if ($form->{todate}) {
2191       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2192     }
2193
2194     $form->{period} = "$fromdate - $todate";
2195   } else {
2196     $form->{period} =
2197       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2198   }
2199
2200   if ($form->{db} eq 'ar') {
2201     $name    = $locale->text('Customer');
2202     $invoice = 'is.pl';
2203     $arap    = 'ar.pl';
2204   }
2205   if ($form->{db} eq 'ap') {
2206     $name    = $locale->text('Vendor');
2207     $invoice = 'ir.pl';
2208     $arap    = 'ap.pl';
2209   }
2210
2211   $option .= "<br>" if $option;
2212   $option .= "$form->{period}";
2213
2214   $column_header{id} =
2215       qq|<th><a class=listheading href=$href&sort=id>|
2216     . $locale->text('ID')
2217     . qq|</th>|;
2218   $column_header{invnumber} =
2219       qq|<th><a class=listheading href=$href&sort=invnumber>|
2220     . $locale->text('Invoice')
2221     . qq|</th>|;
2222   $column_header{transdate} =
2223       qq|<th><a class=listheading href=$href&sort=transdate>|
2224     . $locale->text('Date')
2225     . qq|</th>|;
2226   $column_header{netamount} =
2227     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2228   $column_header{tax} =
2229     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2230   $column_header{amount} =
2231     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2232
2233   $column_header{name} =
2234     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2235
2236   $form->header;
2237
2238   print qq|
2239 <body>
2240
2241 <table width=100%>
2242   <tr>
2243     <th class=listtop colspan=$colspan>$form->{title}</th>
2244   </tr>
2245   <tr height="5"></tr>
2246   <tr>
2247     <td>$option</td>
2248   </tr>
2249   <tr>
2250     <td>
2251       <table width=100%>
2252         <tr class=listheading>
2253 |;
2254
2255   map { print "$column_header{$_}\n" } @column_index;
2256
2257   print qq|
2258         </tr>
2259 |;
2260
2261   # add sort and escape callback
2262   $callback = $form->escape($callback . "&sort=$form->{sort}");
2263
2264   if (@{ $form->{TR} }) {
2265     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2266   }
2267
2268   foreach $ref (@{ $form->{TR} }) {
2269
2270     $module = ($ref->{invoice}) ? $invoice : $arap;
2271
2272     if ($form->{l_subtotal} eq 'Y') {
2273       if ($sameitem ne $ref->{ $form->{sort} }) {
2274         &tax_subtotal;
2275         $sameitem = $ref->{ $form->{sort} };
2276       }
2277     }
2278
2279     $totalnetamount += $ref->{netamount};
2280     $totaltax       += $ref->{tax};
2281     $ref->{amount} = $ref->{netamount} + $ref->{tax};
2282
2283     $subtotalnetamount += $ref->{netamount};
2284     $subtotaltax       += $ref->{tax};
2285
2286     map {
2287       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;");
2288     } qw(netamount tax amount);
2289
2290     $column_data{id}        = qq|<td>$ref->{id}</td>|;
2291     $column_data{invnumber} =
2292       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>|;
2293     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2294     $column_data{name}      = qq|<td>$ref->{name}&nbsp;</td>|;
2295
2296     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2297       qw(netamount tax amount);
2298
2299     $i++;
2300     $i %= 2;
2301     print qq|
2302         <tr class=listrow$i>
2303 |;
2304
2305     map { print "$column_data{$_}\n" } @column_index;
2306
2307     print qq|
2308         </tr>
2309 |;
2310
2311   }
2312
2313   if ($form->{l_subtotal} eq 'Y') {
2314     &tax_subtotal;
2315   }
2316
2317   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
2318
2319   print qq|
2320         </tr>
2321         <tr class=listtotal>
2322 |;
2323
2324   $total =
2325     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
2326   $totalnetamount =
2327     $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
2328   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
2329
2330   $column_data{netamount} =
2331     qq|<th class=listtotal align=right>$totalnetamount</th>|;
2332   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
2333   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2334
2335   map { print "$column_data{$_}\n" } @column_index;
2336
2337   print qq|
2338         </tr>
2339       </table>
2340     </td>
2341   </tr>
2342   <tr>
2343     <td><hr size=3 noshade></td>
2344   </tr>
2345 </table>
2346
2347 </body>
2348 </html>
2349 |;
2350
2351   $lxdebug->leave_sub();
2352 }
2353
2354 sub tax_subtotal {
2355   $lxdebug->enter_sub();
2356
2357   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2358
2359   $subtotalnetamount =
2360     $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
2361   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
2362   $subtotal =
2363     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2364                          2, "&nbsp;");
2365
2366   $column_data{netamount} =
2367     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2368   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2369   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2370
2371   $subtotalnetamount = 0;
2372   $subtotaltax       = 0;
2373
2374   print qq|
2375         <tr class=listsubtotal>
2376 |;
2377   map { print "\n$column_data{$_}" } @column_index;
2378
2379   print qq|
2380         </tr>
2381 |;
2382
2383   $lxdebug->leave_sub();
2384 }
2385
2386 sub list_payments {
2387   $lxdebug->enter_sub();
2388
2389   if ($form->{account}) {
2390     ($form->{paymentaccounts}) = split /--/, $form->{account};
2391   }
2392   if ($form->{department}) {
2393     ($department, $form->{department_id}) = split /--/, $form->{department};
2394     $option = $locale->text('Department') . " : $department";
2395   }
2396
2397   RP->payments(\%myconfig, \%$form);
2398
2399   @columns =
2400     $form->sort_columns(qw(transdate reference name paid source memo));
2401
2402   # construct href
2403   $account    = $form->escape($form->{account});
2404   $title      = $form->escape($form->{title});
2405   $department = $form->escape($form->{department});
2406   $form->{paymentaccounts} =~ s/ /%20/g;
2407   $reference = $form->escape($form->{reference});
2408   $source    = $form->escape($form->{source});
2409   $memo      = $form->escape($form->{memo});
2410
2411   $href =
2412     "$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";
2413
2414   # construct callback
2415   $account    = $form->escape($form->{account},    1);
2416   $title      = $form->escape($form->{title},      1);
2417   $department = $form->escape($form->{department}, 1);
2418   $reference  = $form->escape($form->{reference},  1);
2419   $source     = $form->escape($form->{source},     1);
2420   $memo       = $form->escape($form->{memo},       1);
2421
2422   $form->{callback} =
2423     "$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}";
2424   $callback = $form->escape($form->{callback});
2425
2426   $column_header{name} =
2427       "<th><a class=listheading href=$href&sort=name>"
2428     . $locale->text('Description')
2429     . "</a></th>";
2430   $column_header{reference} =
2431       "<th><a class=listheading href=$href&sort=invnumber>"
2432     . $locale->text('Reference')
2433     . "</a></th>";
2434   $column_header{transdate} =
2435       "<th><a class=listheading href=$href&sort=transdate>"
2436     . $locale->text('Date')
2437     . "</a></th>";
2438   $column_header{paid} =
2439     "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
2440   $column_header{source} =
2441       "<th><a class=listheading href=$href&sort=source>"
2442     . $locale->text('Source')
2443     . "</a></th>";
2444   $column_header{memo} =
2445       "<th><a class=listheading href=$href&sort=memo>"
2446     . $locale->text('Memo')
2447     . "</a></th>";
2448
2449   if ($form->{fromdate}) {
2450     $option .= "\n<br>" if ($option);
2451     $option .=
2452         $locale->text('From') . "&nbsp;"
2453       . $locale->date(\%myconfig, $form->{fromdate}, 1);
2454   }
2455   if ($form->{todate}) {
2456     $option .= "\n<br>" if ($option);
2457     $option .=
2458         $locale->text('bis') . "&nbsp;"
2459       . $locale->date(\%myconfig, $form->{todate}, 1);
2460   }
2461
2462   @column_index = @columns;
2463   $colspan      = $#column_index + 1;
2464
2465   $form->header;
2466
2467   print qq|
2468 <body>
2469
2470 <table width=100%>
2471   <tr>
2472     <th class=listtop>$form->{title}</th>
2473   </tr>
2474   <tr height="5"></tr>
2475   <tr>
2476     <td>$option</td>
2477   </tr>
2478   <tr>
2479     <td>
2480       <table width=100%>
2481         <tr class=listheading>
2482 |;
2483
2484   map { print "\n$column_header{$_}" } @column_index;
2485
2486   print qq|
2487         </tr>
2488 |;
2489
2490   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2491
2492     next unless @{ $form->{ $ref->{id} } };
2493
2494     print qq|
2495         <tr>
2496           <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
2497         </tr>
2498 |;
2499
2500     foreach $payment (@{ $form->{ $ref->{id} } }) {
2501
2502       $module = $payment->{module};
2503       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2504       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2505
2506       $href =
2507         qq|${module}.pl?path=$form->{path}&action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|;
2508
2509       $column_data{name}      = "<td>$payment->{name}&nbsp;</td>";
2510       $column_data{reference} =
2511         qq|<td><a href=$href>$payment->{invnumber}</a></td>|;
2512       $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
2513       $column_data{paid}      =
2514           "<td align=right>"
2515         . $form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")
2516         . "</td>";
2517       $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
2518       $column_data{memo}   = "<td>$payment->{memo}&nbsp;</td>";
2519
2520       $subtotalpaid += $payment->{paid};
2521       $totalpaid    += $payment->{paid};
2522
2523       $i++;
2524       $i %= 2;
2525       print qq|
2526         <tr class=listrow$i>
2527 |;
2528
2529       map { print "\n$column_data{$_}" } @column_index;
2530
2531       print qq|
2532         </tr>
2533 |;
2534
2535     }
2536
2537     # print subtotals
2538     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2539
2540     $column_data{paid} =
2541       "<th class=listsubtotal align=right>"
2542       . $form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;") . "</th>";
2543
2544     print qq|
2545         <tr class=listsubtotal>
2546 |;
2547
2548     map { print "\n$column_data{$_}" } @column_index;
2549
2550     print qq|
2551         </tr>
2552 |;
2553
2554     $subtotalpaid = 0;
2555
2556   }
2557
2558   # print total
2559   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2560
2561   $column_data{paid} =
2562     "<th class=listtotal align=right>"
2563     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;") . "</th>";
2564
2565   print qq|
2566         <tr class=listtotal>
2567 |;
2568
2569   map { print "\n$column_data{$_}" } @column_index;
2570
2571   print qq|
2572         </tr>
2573
2574       </table>
2575     </td>
2576   </tr>
2577   <tr>
2578     <td><hr size=3 noshade></td>
2579   </tr>
2580 </table>
2581
2582 </body>
2583 </html>
2584 |;
2585
2586   $lxdebug->leave_sub();
2587 }
2588
2589 sub config {
2590   $lxdebug->enter_sub();
2591   edit();
2592
2593   #$form->header;
2594   #print qq|Hallo|;
2595   $lxdebug->leave_sub();
2596 }
2597
2598 sub debug {
2599
2600   $form->debug();
2601
2602 }
2603
2604 sub winston_export {
2605   $lxdebug->enter_sub();
2606
2607   #create_winston();
2608   $form->{winston} = 1;
2609   &generate_ustva();
2610   $lxdebug->leave_sub();
2611 }
2612
2613 sub print_options {
2614   $lxdebug->enter_sub();
2615
2616   $form->{sendmode} = "attachment";
2617
2618   $form->{"format"} =
2619     $form->{"format"} ? $form->{"format"} :
2620     $myconfig{"template_format"} ? $myconfig{"template_format"} :
2621     "pdf";
2622
2623   $form->{"copies"} =
2624     $form->{"copies"} ? $form->{"copies"} :
2625     $myconfig{"copies"} ? $myconfig{"copies"} :
2626     2;
2627
2628   $form->{PD}{ $form->{type} }     = "selected";
2629   $form->{DF}{ $form->{format} }   = "selected";
2630   $form->{OP}{ $form->{media} }    = "selected";
2631   $form->{SM}{ $form->{sendmode} } = "selected";
2632
2633   if ($form->{report} eq 'ustva') {
2634     $type = qq|
2635             <option value=ustva $form->{PD}{ustva}>| . $locale->text('ustva');
2636   } else {
2637     $type = qq|
2638             <option value=statement $form->{PD}{statement}>|
2639       . $locale->text('Statement');
2640   }
2641
2642   if ($form->{media} eq 'email') {
2643     $media = qq|
2644             <option value=attachment $form->{SM}{attachment}>|
2645       . $locale->text('Attachment') . qq|
2646             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2647   } else {
2648     $media = qq|
2649             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2650     if ($myconfig{printer} && $latex_templates) {
2651       $media .= qq|
2652             <option value=printer $form->{OP}{printer}>|
2653         . $locale->text('Printer');
2654     }
2655   }
2656
2657   if ($latex_templates) {
2658     $format .= qq|
2659             <option value=html $form->{DF}{html}>|
2660       . $locale->text('HTML') . qq|
2661             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
2662     if ($form->{report} ne 'ustva') {
2663       $format . qq|
2664             <option value=postscript $form->{DF}{postscript}>|
2665         . $locale->text('Postscript');
2666     }
2667   }
2668
2669   print qq|
2670 <table>
2671   <tr>
2672     <td><select name=type>$type</select></td>
2673     <td><select name=format>$format</select></td>
2674     <td><select name=media>$media</select></td>
2675 |;
2676
2677   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
2678     print qq|
2679       <td>| . $locale->text('Copies') . qq|
2680       <input name=copies size=2 value=$form->{copies}></td>
2681 |;
2682   }
2683
2684   print qq|
2685   </tr>
2686 </table>
2687 |;
2688
2689   $lxdebug->leave_sub();
2690 }
2691
2692 sub generate_bwa {
2693   $lxdebug->enter_sub();
2694   $form->{padding} = "&nbsp;&nbsp;";
2695   $form->{bold}    = "<b>";
2696   $form->{endbold} = "</b>";
2697   $form->{br}      = "<br>";
2698
2699   if ($form->{reporttype} eq "custom") {
2700
2701     #forgotten the year --> thisyear
2702     if ($form->{year} !~ m/^\d\d\d\d$/) {
2703       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2704         /(\d\d\d\d)/;
2705       $form->{year} = $1;
2706     }
2707
2708     #yearly report
2709     if ($form->{duetyp} eq "13") {
2710       $form->{fromdate}        = "1.1.$form->{year}";
2711       $form->{todate}          = "31.12.$form->{year}";
2712       $form->{comparefromdate} = "1.01.$form->{year}";
2713       $form->{comparetodate}   = "31.12.$form->{year}";
2714     }
2715
2716     #Quater reports
2717     if ($form->{duetyp} eq "A") {
2718       $form->{fromdate}        = "1.1.$form->{year}";
2719       $form->{todate}          = "31.3.$form->{year}";
2720       $form->{comparefromdate} = "1.01.$form->{year}";
2721       $form->{comparetodate}   = "31.03.$form->{year}";
2722     }
2723     if ($form->{duetyp} eq "B") {
2724       $form->{fromdate}        = "1.4.$form->{year}";
2725       $form->{todate}          = "30.6.$form->{year}";
2726       $form->{comparefromdate} = "1.01.$form->{year}";
2727       $form->{comparetodate}   = "30.06.$form->{year}";
2728     }
2729     if ($form->{duetyp} eq "C") {
2730       $form->{fromdate}        = "1.7.$form->{year}";
2731       $form->{todate}          = "30.9.$form->{year}";
2732       $form->{comparefromdate} = "1.01.$form->{year}";
2733       $form->{comparetodate}   = "30.09.$form->{year}";
2734     }
2735     if ($form->{duetyp} eq "D") {
2736       $form->{fromdate}        = "1.10.$form->{year}";
2737       $form->{todate}          = "31.12.$form->{year}";
2738       $form->{comparefromdate} = "1.01.$form->{year}";
2739       $form->{comparetodate}   = "31.12.$form->{year}";
2740     }
2741
2742     #Monthly reports
2743   SWITCH: {
2744       $form->{duetyp} eq "1" && do {
2745         $form->{fromdate}        = "1.1.$form->{year}";
2746         $form->{todate}          = "31.1.$form->{year}";
2747         $form->{comparefromdate} = "1.01.$form->{year}";
2748         $form->{comparetodate}   = "31.01.$form->{year}";
2749         last SWITCH;
2750       };
2751       $form->{duetyp} eq "2" && do {
2752         $form->{fromdate} = "1.2.$form->{year}";
2753
2754         #this works from 1901 to 2099, 1900 and 2100 fail.
2755         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2756         $form->{todate}          = "$leap.2.$form->{year}";
2757         $form->{comparefromdate} = "1.01.$form->{year}";
2758         $form->{comparetodate}   = "$leap.02.$form->{year}";
2759         last SWITCH;
2760       };
2761       $form->{duetyp} eq "3" && do {
2762         $form->{fromdate}        = "1.3.$form->{year}";
2763         $form->{todate}          = "31.3.$form->{year}";
2764         $form->{comparefromdate} = "1.01.$form->{year}";
2765         $form->{comparetodate}   = "31.03.$form->{year}";
2766         last SWITCH;
2767       };
2768       $form->{duetyp} eq "4" && do {
2769         $form->{fromdate}        = "1.4.$form->{year}";
2770         $form->{todate}          = "30.4.$form->{year}";
2771         $form->{comparefromdate} = "1.01.$form->{year}";
2772         $form->{comparetodate}   = "30.04.$form->{year}";
2773         last SWITCH;
2774       };
2775       $form->{duetyp} eq "5" && do {
2776         $form->{fromdate}        = "1.5.$form->{year}";
2777         $form->{todate}          = "31.5.$form->{year}";
2778         $form->{comparefromdate} = "1.01.$form->{year}";
2779         $form->{comparetodate}   = "31.05.$form->{year}";
2780         last SWITCH;
2781       };
2782       $form->{duetyp} eq "6" && do {
2783         $form->{fromdate}        = "1.6.$form->{year}";
2784         $form->{todate}          = "30.6.$form->{year}";
2785         $form->{comparefromdate} = "1.01.$form->{year}";
2786         $form->{comparetodate}   = "30.06.$form->{year}";
2787         last SWITCH;
2788       };
2789       $form->{duetyp} eq "7" && do {
2790         $form->{fromdate}        = "1.7.$form->{year}";
2791         $form->{todate}          = "31.7.$form->{year}";
2792         $form->{comparefromdate} = "1.01.$form->{year}";
2793         $form->{comparetodate}   = "31.07.$form->{year}";
2794         last SWITCH;
2795       };
2796       $form->{duetyp} eq "8" && do {
2797         $form->{fromdate}        = "1.8.$form->{year}";
2798         $form->{todate}          = "31.8.$form->{year}";
2799         $form->{comparefromdate} = "1.01.$form->{year}";
2800         $form->{comparetodate}   = "31.08.$form->{year}";
2801         last SWITCH;
2802       };
2803       $form->{duetyp} eq "9" && do {
2804         $form->{fromdate}        = "1.9.$form->{year}";
2805         $form->{todate}          = "30.9.$form->{year}";
2806         $form->{comparefromdate} = "1.01.$form->{year}";
2807         $form->{comparetodate}   = "30.09.$form->{year}";
2808         last SWITCH;
2809       };
2810       $form->{duetyp} eq "10" && do {
2811         $form->{fromdate}        = "1.10.$form->{year}";
2812         $form->{todate}          = "31.10.$form->{year}";
2813         $form->{comparefromdate} = "1.01.$form->{year}";
2814         $form->{comparetodate}   = "31.10.$form->{year}";
2815         last SWITCH;
2816       };
2817       $form->{duetyp} eq "11" && do {
2818         $form->{fromdate}        = "1.11.$form->{year}";
2819         $form->{todate}          = "30.11.$form->{year}";
2820         $form->{comparefromdate} = "1.01.$form->{year}";
2821         $form->{comparetodate}   = "30.11.$form->{year}";
2822         last SWITCH;
2823       };
2824       $form->{duetyp} eq "12" && do {
2825         $form->{fromdate}        = "1.12.$form->{year}";
2826         $form->{todate}          = "31.12.$form->{year}";
2827         $form->{comparefromdate} = "1.01.$form->{year}";
2828         $form->{comparetodate}   = "31.12.$form->{year}";
2829         last SWITCH;
2830       };
2831     }
2832   } else {
2833     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2834     $form->{fromdate} = "${dd}.${mm}.${yy}";
2835     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2836     $form->{todate}          = "${dd}.${mm}.${yy}";
2837     $form->{comparefromdate} = "01.01.$yy";
2838     $form->{comparetodate}   = $form->{todate};
2839   }
2840
2841   RP->bwa(\%myconfig, \%$form);
2842
2843   ($form->{department}) = split /--/, $form->{department};
2844
2845   $form->{period} =
2846     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2847   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2848
2849   # if there are any dates construct a where
2850   if ($form->{fromdate} || $form->{todate}) {
2851
2852     unless ($form->{todate}) {
2853       $form->{todate} = $form->current_date(\%myconfig);
2854     }
2855
2856     my %germandate = ("dateformat" => "dd.mm.yyyy");
2857
2858     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
2859     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2860
2861     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
2862     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2863
2864     $form->{this_period} = "$shortfromdate\n$shorttodate";
2865     $form->{period}      =
2866         $locale->text('for Period')
2867       . qq|\n$longfromdate |
2868       . $locale->text('bis')
2869       . qq| $longtodate|;
2870   }
2871
2872   # setup variables for the form
2873   @a = qw(company address businessnumber);
2874   map { $form->{$_} = $myconfig{$_} } @a;
2875   $form->{templates} = $myconfig{templates};
2876
2877   $form->{IN} = "bwa.html";
2878
2879   $form->parse_template;
2880
2881   $lxdebug->leave_sub();
2882 }
2883
2884 sub generate_ustva {
2885   $lxdebug->enter_sub();
2886
2887   # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
2888   USTVA->get_config($userspath, 'finanzamt.ini');
2889
2890   #  &get_project(generate_bwa);
2891   @anmeldungszeitraum =
2892     qw(0401, 0402, 0403, 0404, 0405, 0405, 0406, 0407, 0408, 0409, 0410, 0411, 0412, 0441, 0442, 0443, 0444);
2893
2894   foreach $item (@anmeldungszeitraum) {
2895     $form->{$item} = "";
2896   }
2897   if ($form->{reporttype} eq "custom") {
2898
2899     #forgotten the year --> thisyear
2900     if ($form->{year} !~ m/^\d\d\d\d$/) {
2901       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2902         /(\d\d\d\d)/;
2903       $form->{year} = $1;
2904     }
2905
2906     #yearly report
2907     if ($form->{duetyp} eq "13") {
2908       $form->{fromdate} = "1.1.$form->{year}";
2909       $form->{todate}   = "31.12.$form->{year}";
2910     }
2911
2912     #Quater reports
2913     if ($form->{duetyp} eq "A") {
2914       $form->{fromdate} = "1.1.$form->{year}";
2915       $form->{todate}   = "31.3.$form->{year}";
2916       $form->{"0441"}   = "X";
2917     }
2918     if ($form->{duetyp} eq "B") {
2919       $form->{fromdate} = "1.4.$form->{year}";
2920       $form->{todate}   = "30.6.$form->{year}";
2921       $form->{"0442"}   = "X";
2922     }
2923     if ($form->{duetyp} eq "C") {
2924       $form->{fromdate} = "1.7.$form->{year}";
2925       $form->{todate}   = "30.9.$form->{year}";
2926       $form->{"0443"}   = "X";
2927     }
2928     if ($form->{duetyp} eq "D") {
2929       $form->{fromdate} = "1.10.$form->{year}";
2930       $form->{todate}   = "31.12.$form->{year}";
2931       $form->{"0444"}   = "X";
2932     }
2933
2934     #Monthly reports
2935   SWITCH: {
2936       $form->{duetyp} eq "1" && do {
2937         $form->{fromdate} = "1.1.$form->{year}";
2938         $form->{todate}   = "31.1.$form->{year}";
2939         $form->{"0401"}   = "X";
2940         last SWITCH;
2941       };
2942       $form->{duetyp} eq "2" && do {
2943         $form->{fromdate} = "1.2.$form->{year}";
2944
2945         #this works from 1901 to 2099, 1900 and 2100 fail.
2946         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2947         $form->{todate} = "$leap.2.$form->{year}";
2948         $form->{"0402"} = "X";
2949         last SWITCH;
2950       };
2951       $form->{duetyp} eq "3" && do {
2952         $form->{fromdate} = "1.3.$form->{year}";
2953         $form->{todate}   = "31.3.$form->{year}";
2954         $form->{"0403"}   = "X";
2955         last SWITCH;
2956       };
2957       $form->{duetyp} eq "4" && do {
2958         $form->{fromdate} = "1.4.$form->{year}";
2959         $form->{todate}   = "30.4.$form->{year}";
2960         $form->{"0404"}   = "X";
2961         last SWITCH;
2962       };
2963       $form->{duetyp} eq "5" && do {
2964         $form->{fromdate} = "1.5.$form->{year}";
2965         $form->{todate}   = "31.5.$form->{year}";
2966         $form->{"0405"}   = "X";
2967         last SWITCH;
2968       };
2969       $form->{duetyp} eq "6" && do {
2970         $form->{fromdate} = "1.6.$form->{year}";
2971         $form->{todate}   = "30.6.$form->{year}";
2972         $form->{"0406"}   = "X";
2973         last SWITCH;
2974       };
2975       $form->{duetyp} eq "7" && do {
2976         $form->{fromdate} = "1.7.$form->{year}";
2977         $form->{todate}   = "31.7.$form->{year}";
2978         $form->{"0407"}   = "X";
2979         last SWITCH;
2980       };
2981       $form->{duetyp} eq "8" && do {
2982         $form->{fromdate} = "1.8.$form->{year}";
2983         $form->{todate}   = "31.8.$form->{year}";
2984         $form->{"0408"}   = "X";
2985         last SWITCH;
2986       };
2987       $form->{duetyp} eq "9" && do {
2988         $form->{fromdate} = "1.9.$form->{year}";
2989         $form->{todate}   = "30.9.$form->{year}";
2990         $form->{"0409"}   = "X";
2991         last SWITCH;
2992       };
2993       $form->{duetyp} eq "10" && do {
2994         $form->{fromdate} = "1.10.$form->{year}";
2995         $form->{todate}   = "31.10.$form->{year}";
2996         $form->{"0410"}   = "X";
2997         last SWITCH;
2998       };
2999       $form->{duetyp} eq "11" && do {
3000         $form->{fromdate} = "1.11.$form->{year}";
3001         $form->{todate}   = "30.11.$form->{year}";
3002         $form->{"0411"}   = "X";
3003         last SWITCH;
3004       };
3005       $form->{duetyp} eq "12" && do {
3006         $form->{fromdate} = "1.12.$form->{year}";
3007         $form->{todate}   = "31.12.$form->{year}";
3008         $form->{"0412"}   = "X";
3009         last SWITCH;
3010       };
3011     }
3012   }
3013
3014   #    $locale->date(\%myconfig, $form->current_date(\%myconfig), 0)=~ /(\d\d\d\d)/;
3015   #    $form->{year}= $1;
3016   #    $form->{fromdate}="1.1.$form->{year}";
3017   #    $form->{todate}="31.3.$form->{year}";
3018   #    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3019   #  }
3020
3021   RP->ustva(\%myconfig, \%$form);
3022
3023   ($form->{department}) = split /--/, $form->{department};
3024
3025   $form->{period} =
3026     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3027   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
3028
3029   # if there are any dates construct a where
3030   if ($form->{fromdate} || $form->{todate}) {
3031
3032     unless ($form->{todate}) {
3033       $form->{todate} = $form->current_date(\%myconfig);
3034     }
3035
3036     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
3037     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
3038
3039     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
3040     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
3041
3042     $form->{this_period} = "$shortfromdate\n$shorttodate";
3043     $form->{period}      =
3044         $locale->text('for Period')
3045       . qq|<br>\n$longfromdate |
3046       . $locale->text('bis')
3047       . qq| $longtodate|;
3048   }
3049
3050   if ($form->{comparefromdate} || $form->{comparetodate}) {
3051     $longcomparefromdate =
3052       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
3053     $shortcomparefromdate =
3054       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
3055
3056     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
3057     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
3058
3059     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
3060     $form->{period} .=
3061         "\n$longcomparefromdate "
3062       . $locale->text('bis')
3063       . qq| $longcomparetodate|;
3064   }
3065
3066   $form->{Datum_heute} =
3067     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
3068
3069   if (   $form->{format} eq 'pdf'
3070       or $form->{format} eq 'postscript') {
3071     $form->{padding} = "~~";
3072     $form->{bold}    = "\textbf{";
3073     $form->{endbold} = "}";
3074     $form->{br}      = '\\\\';
3075
3076     @numbers = qw(51r 86r 97r 93r 96 43 45
3077       66 62 67);
3078     foreach $number (@numbers) {
3079       $form->{$number} =~ s/,/~~/g;
3080     }
3081
3082       } elsif ($form->{format} eq 'html') {
3083     $form->{padding} = "&nbsp;&nbsp;";
3084     $form->{bold}    = "<b>";
3085     $form->{endbold} = "</b>";
3086     $form->{br}      = "<br>"
3087
3088   }
3089
3090   # setup variables for the form
3091   @a = qw(company address businessnumber);
3092   map { $form->{$_} = $myconfig{$_} } @a;
3093
3094   $form->{address} =~ s/\\n/$form->{br}/g;
3095
3096   if ($form->{winston} eq '1') {
3097     create_winston();
3098
3099   } else {
3100     $form->{templates} = $myconfig{templates};
3101     $form->{IN}        = "$form->{type}";
3102     $form->{IN} .= '.tex'
3103       if (   $form->{format} eq 'pdf'
3104           or $form->{format} eq 'postscript');
3105     $form->{IN} .= '.html' if ($form->{format} eq 'html');
3106
3107     $form->parse_template(\%myconfig, $userspath);
3108
3109     # $form->parse_template;
3110   }
3111   $lxdebug->leave_sub();
3112 }