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