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