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