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