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