Neuanfang in unstable mit Release 2.2.0: Kopie des Releasestandes.
[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></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></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<br>\n$shorttodate";
1192     $form->{period}      =
1193         $locale->text('for Period')
1194       . qq|<br>\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<br>\n$shortcomparetodate";
1209     $form->{period} .=
1210         "<br>\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   $form->{address} =~ s/\\n/<br>/g;
1219
1220   $form->{templates} = $myconfig{templates};
1221
1222   $form->{IN} = "income_statement.html";
1223
1224   $form->parse_template;
1225
1226   $lxdebug->leave_sub();
1227 }
1228
1229 sub generate_balance_sheet {
1230   $lxdebug->enter_sub();
1231
1232   $form->{padding} = "&nbsp;&nbsp;";
1233   $form->{bold}    = "<b>";
1234   $form->{endbold} = "</b>";
1235   $form->{br}      = "<br>";
1236
1237   RP->balance_sheet(\%myconfig, \%$form);
1238
1239   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
1240   $form->{period} =
1241     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1242
1243   ($form->{department}) = split /--/, $form->{department};
1244
1245   # define Current Earnings account
1246   $padding = ($form->{l_heading}) ? $form->{padding} : "";
1247   push(@{ $form->{equity_account} },
1248        $padding . $locale->text('Current Earnings'));
1249
1250   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
1251   $form->{last_period} =
1252     $locale->date(\%myconfig, $form->{compareasofdate}, 0);
1253
1254   $form->{IN} = "balance_sheet.html";
1255
1256   # setup company variables for the form
1257   map { $form->{$_} = $myconfig{$_} }
1258     (qw(company address businessnumber nativecurr));
1259   $form->{address} =~ s/\\n/<br>/g;
1260
1261   $form->{templates} = $myconfig{templates};
1262
1263   $form->parse_template;
1264
1265   $lxdebug->leave_sub();
1266 }
1267
1268 sub generate_projects {
1269   $lxdebug->enter_sub();
1270
1271   &get_project(generate_projects);
1272   $form->{projectnumber} = $form->{projectnumber_1};
1273
1274   $form->{nextsub} = "generate_projects";
1275   $form->{title}   = $locale->text('Project Transactions');
1276   RP->trial_balance(\%myconfig, \%$form);
1277
1278   &list_accounts;
1279
1280   $lxdebug->leave_sub();
1281 }
1282
1283 # Antonio Gallardo
1284 #
1285 # D.S. Feb 16, 2001
1286 # included links to display transactions for period entered
1287 # added headers and subtotals
1288 #
1289 sub generate_trial_balance {
1290   $lxdebug->enter_sub();
1291
1292   # get for each account initial balance, debits and credits
1293   RP->trial_balance(\%myconfig, \%$form);
1294
1295   $form->{nextsub} = "generate_trial_balance";
1296   $form->{title}   = $locale->text('Trial Balance');
1297   &list_accounts;
1298
1299   $lxdebug->leave_sub();
1300 }
1301
1302 sub list_accounts {
1303   $lxdebug->enter_sub();
1304
1305   $title = $form->escape($form->{title});
1306
1307   if ($form->{department}) {
1308     ($department) = split /--/, $form->{department};
1309     $options    = $locale->text('Department') . " : $department<br>";
1310     $department = $form->escape($form->{department});
1311   }
1312   if ($form->{projectnumber}) {
1313     $options .=
1314       $locale->text('Project Number') . " : $form->{projectnumber}<br>";
1315     $projectnumber = $form->escape($form->{projectnumber});
1316   }
1317
1318   # if there are any dates
1319   if ($form->{fromdate} || $form->{todate}) {
1320     if ($form->{fromdate}) {
1321       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
1322     }
1323     if ($form->{todate}) {
1324       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1325     }
1326
1327     $form->{period} = "$fromdate - $todate";
1328   } else {
1329     $form->{period} =
1330       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
1331
1332   }
1333   $options .= $form->{period};
1334
1335   @column_index = qw(accno description begbalance debit credit endbalance);
1336
1337   $column_header{accno} =
1338     qq|<th class=listheading>| . $locale->text('Account') . qq|</th>|;
1339   $column_header{description} =
1340     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1341   $column_header{debit} =
1342     qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>|;
1343   $column_header{credit} =
1344     qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>|;
1345   $column_header{begbalance} =
1346     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
1347   $column_header{endbalance} =
1348     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
1349
1350   if ($form->{accounttype} eq 'gifi') {
1351     $column_header{accno} =
1352       qq|<th class=listheading>| . $locale->text('GIFI') . qq|</th>|;
1353   }
1354
1355   $form->header;
1356
1357   print qq|
1358 <body>
1359
1360 <table width=100%>
1361   <tr>
1362     <th class=listtop>$form->{title}</th>
1363   </tr>
1364   <tr height="5"></tr>
1365   <tr>
1366     <td>$options</td>
1367   </tr>
1368   <tr>
1369     <td>
1370       <table width=100%>
1371         <tr>|;
1372
1373   map { print "$column_header{$_}\n" } @column_index;
1374
1375   print qq|
1376         </tr>
1377 |;
1378
1379   # sort the whole thing by account numbers and display
1380   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
1381
1382     $description = $form->escape($ref->{description});
1383
1384     $href =
1385       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}|;
1386
1387     if ($form->{accounttype} eq 'gifi') {
1388       $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
1389       $na = $locale->text('N/A');
1390       map { $ref->{$_} = $na } qw(accno description) unless $ref->{accno};
1391     } else {
1392       $href .= "&accno=$ref->{accno}&description=$description";
1393     }
1394
1395     $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
1396
1397     $debit  = $form->format_amount(\%myconfig, $ref->{debit},  2, "&nbsp;");
1398     $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
1399     $begbalance =
1400       $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
1401     $endbalance =
1402       $form->format_amount(\%myconfig,
1403                            ($ref->{balance} + $ref->{amount}) * $ml,
1404                            2, "&nbsp;");
1405
1406     #    next if ($ref->{debit} == 0 && $ref->{credit} == 0);
1407
1408     if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
1409       map { $column_data{$_} = "<th>&nbsp;</th>" }
1410         qw(accno begbalance endbalance);
1411
1412       $subtotalbegbalance =
1413         $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
1414       $subtotalendbalance =
1415         $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
1416       $subtotaldebit =
1417         $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
1418       $subtotalcredit =
1419         $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
1420
1421       $column_data{description} = "<th>$subtotaldescription</th>";
1422       $column_data{begbalance}  = "<th align=right>$subtotalbegbalance</th>";
1423       $column_data{endbalance}  = "<th align=right>$subtotalendbalance</th>";
1424       $column_data{debit}       = "<th align=right>$subtotaldebit</th>";
1425       $column_data{credit}      = "<th align=right>$subtotalcredit</th>";
1426
1427       print qq|
1428         <tr class=listsubtotal>
1429 |;
1430       map { print "$column_data{$_}\n" } @column_index;
1431
1432       print qq|
1433         </tr>
1434 |;
1435     }
1436
1437     if ($ref->{charttype} eq "H") {
1438       $subtotal            = 1;
1439       $subtotaldescription = $ref->{description};
1440       $subtotaldebit       = $ref->{debit};
1441       $subtotalcredit      = $ref->{credit};
1442       $subtotalbegbalance  = 0;
1443       $subtotalendbalance  = 0;
1444
1445       next unless $form->{l_heading};
1446
1447       map { $column_data{$_} = "<th>&nbsp;</th>" }
1448         qw(accno debit credit begbalance endbalance);
1449       $column_data{description} =
1450         "<th class=listheading>$ref->{description}</th>";
1451     }
1452
1453     if ($ref->{charttype} eq "A") {
1454       $column_data{accno}       = "<td><a href=$href>$ref->{accno}</a></td>";
1455       $column_data{description} = "<td>$ref->{description}</td>";
1456       $column_data{debit}       = "<td align=right>$debit</td>";
1457       $column_data{credit}      = "<td align=right>$credit</td>";
1458       $column_data{begbalance}  = "<td align=right>$begbalance</td>";
1459       $column_data{endbalance}  = "<td align=right>$endbalance</td>";
1460
1461       $totaldebit  += $ref->{debit};
1462       $totalcredit += $ref->{credit};
1463
1464       $subtotalbegbalance += $ref->{balance} * $ml;
1465       $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml;
1466
1467     }
1468
1469     if ($ref->{charttype} eq "H") {
1470       print qq|
1471       <tr class=listheading>
1472 |;
1473     }
1474     if ($ref->{charttype} eq "A") {
1475       $i++;
1476       $i %= 2;
1477       print qq|
1478       <tr class=listrow$i>
1479 |;
1480     }
1481
1482     map { print "$column_data{$_}\n" } @column_index;
1483
1484     print qq|
1485       </tr>
1486 |;
1487   }
1488
1489   # print last subtotal
1490   if ($subtotal && $form->{l_subtotal}) {
1491     map { $column_data{$_} = "<th>&nbsp;</th>" }
1492       qw(accno begbalance endbalance);
1493     $subtotalbegbalance =
1494       $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
1495     $subtotalendbalance =
1496       $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
1497     $subtotaldebit =
1498       $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
1499     $subtotalcredit =
1500       $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
1501     $column_data{description} = "<th>$subdescription</th>";
1502     $column_data{begbalance}  = "<th align=right>$subtotalbegbalance</th>";
1503     $column_data{endbalance}  = "<th align=right>$subtotalendbalance</th>";
1504     $column_data{debit}       = "<th align=right>$subtotaldebit</th>";
1505     $column_data{credit}      = "<th align=right>$subtotalcredit</th>";
1506
1507     print qq|
1508       <tr class=listsubtotal>
1509 |;
1510     map { print "$column_data{$_}\n" } @column_index;
1511
1512     print qq|
1513       </tr>
1514 |;
1515   }
1516
1517   $totaldebit  = $form->format_amount(\%myconfig, $totaldebit,  2, "&nbsp;");
1518   $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;");
1519
1520   map { $column_data{$_} = "<th>&nbsp;</th>" }
1521     qw(accno description begbalance endbalance);
1522
1523   $column_data{debit}  = qq|<th align=right class=listtotal>$totaldebit</th>|;
1524   $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
1525
1526   print qq|
1527         <tr class=listtotal>
1528 |;
1529
1530   map { print "$column_data{$_}\n" } @column_index;
1531
1532   print qq|
1533         </tr>
1534       </table>
1535     </td>
1536   </tr>
1537   <tr>
1538     <td><hr size=3 noshade></td>
1539   </tr>
1540 </table>
1541
1542 </body>
1543 </html>
1544 |;
1545
1546   $lxdebug->leave_sub();
1547 }
1548
1549 sub generate_ar_aging {
1550   $lxdebug->enter_sub();
1551
1552   # split customer
1553   ($form->{customer}) = split(/--/, $form->{customer});
1554   $customer = $form->escape($form->{customer}, 1);
1555   $title    = $form->escape($form->{title},    1);
1556
1557   $form->{ct}   = "customer";
1558   $form->{arap} = "ar";
1559
1560   $form->{callback} =
1561     qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&customer=$customer&title=$title|;
1562
1563   RP->aging(\%myconfig, \%$form);
1564   &aging;
1565
1566   $lxdebug->leave_sub();
1567 }
1568
1569 sub generate_ap_aging {
1570   $lxdebug->enter_sub();
1571
1572   # split vendor
1573   ($form->{vendor}) = split(/--/, $form->{vendor});
1574   $vendor = $form->escape($form->{vendor}, 1);
1575   $title  = $form->escape($form->{title},  1);
1576
1577   $form->{ct}   = "vendor";
1578   $form->{arap} = "ap";
1579
1580   $form->{callback} =
1581     qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&password=$form->{password}&todate=$form->{todate}&vendor=$vendor&title=$title|;
1582
1583   RP->aging(\%myconfig, \%$form);
1584   &aging;
1585
1586   $lxdebug->leave_sub();
1587 }
1588
1589 sub aging {
1590   $lxdebug->enter_sub();
1591
1592   $form->header;
1593
1594   $column_header{statement} = qq|<th>&nbsp;</th>|;
1595   $column_header{ct}        =
1596       qq|<th class=listheading>|
1597     . $locale->text(ucfirst $form->{ct})
1598     . qq|</th>|;
1599   $column_header{invnumber} =
1600     qq|<th class=listheading>| . $locale->text('Invoice') . qq|</th>|;
1601   $column_header{transdate} =
1602     qq|<th class=listheading>| . $locale->text('Date') . qq|</th>|;
1603   $column_header{duedate} =
1604     qq|<th class=listheading>| . $locale->text('Due') . qq|</th>|;
1605   $column_header{c0} =
1606     qq|<th class=listheading>| . $locale->text('Current') . qq|</th>|;
1607   $column_header{c30} = qq|<th class=listheading>30</th>|;
1608   $column_header{c60} = qq|<th class=listheading>60</th>|;
1609   $column_header{c90} = qq|<th class=listheading>90</th>|;
1610
1611   @column_index =
1612     (qw(statement ct invnumber transdate duedate c0 c30 c60 c90));
1613
1614   if ($form->{department}) {
1615     $option .= "\n<br>" if $option;
1616     ($department) = split /--/, $form->{department};
1617     $option .= $locale->text('Department') . " : $department";
1618     $department = $form->escape($form->{department}, 1);
1619     $form->{callback} .= "&department=$department";
1620   }
1621
1622   if ($form->{arap} eq 'ar') {
1623     if ($form->{customer}) {
1624       $option .= "\n<br>" if $option;
1625       $option .= $form->{customer};
1626     }
1627   }
1628   if ($form->{arap} eq 'ap') {
1629     shift @column_index;
1630     if ($form->{vendor}) {
1631       $option .= "\n<br>" if $option;
1632       $option .= $form->{vendor};
1633     }
1634   }
1635
1636   $todate = $locale->date(\%myconfig, $form->{todate}, 1);
1637   $option .= "\n<br>" if $option;
1638   $option .=
1639     $locale->text('for Period') . " " . $locale->text('Bis') . " $todate";
1640
1641   print qq|
1642 <body>
1643
1644 <form method=post action=$form->{script}>
1645
1646 <table width=100%>
1647   <tr>
1648     <th class=listtop>$form->{title}</th>
1649   </tr>
1650   <tr height="5"></tr>
1651   <tr>
1652     <td>$option</td>
1653   </tr>
1654   <tr>
1655     <td>
1656       <table width=100%>
1657         <tr class=listheading>
1658 |;
1659
1660   map { print "$column_header{$_}\n" } @column_index;
1661
1662   print qq|
1663         </tr>
1664 |;
1665
1666   $ctid     = 0;
1667   $subtotal = 0;
1668   $i        = 0;
1669
1670   foreach $ref (@{ $form->{AG} }) {
1671
1672     if ($ctid != $ref->{ctid}) {
1673
1674       $i++;
1675
1676       if ($subtotal) {
1677         $c0subtotal =
1678           $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp");
1679         $c30subtotal =
1680           $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp");
1681         $c60subtotal =
1682           $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp");
1683         $c90subtotal =
1684           $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp");
1685       }
1686
1687       $column_data{ct}        = qq|<th>&nbsp;</th>|;
1688       $column_data{invnumber} = qq|<th>&nbsp;</th>|;
1689       $column_data{transdate} = qq|<th>&nbsp;</th>|;
1690       $column_data{duedate}   = qq|<th>&nbsp;</th>|;
1691       $column_data{c0}        =
1692         qq|<th align=right class=listsubtotal>$c0subtotal</th>|;
1693       $column_data{c30} =
1694         qq|<th align=right class=listsubtotal>$c30subtotal</th>|;
1695       $column_data{c60} =
1696         qq|<th align=right class=listsubtotal>$c60subtotal</th>|;
1697       $column_data{c90} =
1698         qq|<th align=right class=listsubtotal>$c90subtotal</th>|;
1699
1700       if ($subtotal) {
1701
1702         # print subtotals
1703         print qq|
1704         <tr class=listsubtotal>
1705 |;
1706
1707         map { print "$column_data{$_}\n" } @column_index;
1708
1709         $column_data{statement} = qq|<td>&nbsp;</td>|;
1710
1711         print qq|
1712         </tr>
1713 |;
1714       }
1715
1716       $subtotal = 1;
1717
1718       $c0subtotal  = 0;
1719       $c30subtotal = 0;
1720       $c60subtotal = 0;
1721       $c90subtotal = 0;
1722
1723       $column_data{ct}        = qq|<td>$ref->{name}</td>|;
1724       $column_data{statement} =
1725         qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
1726       <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
1727       </td>|;
1728     }
1729
1730     $c0subtotal  += $ref->{c0};
1731     $c30subtotal += $ref->{c30};
1732     $c60subtotal += $ref->{c60};
1733     $c90subtotal += $ref->{c90};
1734
1735     $c0total  += $ref->{c0};
1736     $c30total += $ref->{c30};
1737     $c60total += $ref->{c60};
1738     $c90total += $ref->{c90};
1739
1740     $ref->{c0}  = $form->format_amount(\%myconfig, $ref->{c0},  2, "&nbsp;");
1741     $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;");
1742     $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;");
1743     $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;");
1744
1745     $href =
1746       qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|
1747       . $form->escape($form->{callback});
1748
1749     $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
1750     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
1751     $column_data{duedate}   = qq|<td>$ref->{duedate}&nbsp;</td>|;
1752     $column_data{c0}        = qq|<td align=right>$ref->{c0}</td>|;
1753     $column_data{c30}       = qq|<td align=right>$ref->{c30}</td>|;
1754     $column_data{c60}       = qq|<td align=right>$ref->{c60}</td>|;
1755     $column_data{c90}       = qq|<td align=right>$ref->{c90}</td>|;
1756
1757     $j++;
1758     $j %= 2;
1759     print qq|
1760         <tr class=listrow$j>
1761 |;
1762
1763     map { print "$column_data{$_}\n" } @column_index;
1764
1765     print qq|
1766         </tr>
1767 |;
1768
1769     $column_data{ct}        = qq|<td>&nbsp;</td>|;
1770     $column_data{statement} = qq|<td>&nbsp;</td>|;
1771
1772     $ctid = $ref->{ctid};
1773
1774   }
1775
1776   # print subtotals
1777   $c0subtotal  = $form->format_amount(\%myconfig, $c0subtotal,  2, "&nbsp;");
1778   $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp;");
1779   $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp;");
1780   $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp;");
1781
1782   print qq|
1783         <tr class=listsubtotal>
1784 |;
1785
1786   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
1787
1788   $column_data{c0}  = qq|<th align=right class=listsubtotal>$c0subtotal</th>|;
1789   $column_data{c30} = qq|<th align=right class=listsubtotal>$c30subtotal</th>|;
1790   $column_data{c60} = qq|<th align=right class=listsubtotal>$c60subtotal</th>|;
1791   $column_data{c90} = qq|<th align=right class=listsubtotal>$c90subtotal</th>|;
1792
1793   map { print "$column_data{$_}\n" } @column_index;
1794
1795   print qq|
1796         </tr>
1797         <tr class=listtotal>
1798 |;
1799
1800   $c0total  = $form->format_amount(\%myconfig, $c0total,  2, "&nbsp;");
1801   $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp;");
1802   $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp;");
1803   $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp;");
1804
1805   $column_data{c0}  = qq|<th align=right class=listtotal>$c0total</th>|;
1806   $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
1807   $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
1808   $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
1809
1810   map { print "$column_data{$_}\n" } @column_index;
1811
1812   print qq|
1813           <input type=hidden name=rowcount value=$i>
1814         </tr>
1815       </table>
1816     </td>
1817   </tr>
1818   <tr>
1819     <td>
1820 |;
1821
1822   &print_options if ($form->{arap} eq 'ar');
1823
1824   print qq|
1825     </td>
1826   </tr>
1827   <tr>
1828     <td><hr size=3 noshade></td>
1829   </tr>
1830 </table>
1831 |;
1832
1833   if ($form->{arap} eq 'ar') {
1834     print qq|
1835 <input type=hidden name=todate value=$form->{todate}>
1836
1837 <input type=hidden name=title value="$form->{title}">
1838
1839 <input type=hidden name=arap value=$form->{arap}>
1840 <input type=hidden name=ct value=$form->{ct}>
1841 <input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
1842
1843 <input type=hidden name=department value="$form->{department}">
1844
1845 <input type=hidden name=path value=$form->{path}>
1846 <input type=hidden name=login value=$form->{login}>
1847 <input type=hidden name=password value=$form->{password}>
1848
1849 <br>
1850 <input class=submit type=submit name=action value="|
1851       . $locale->text('Select all') . qq|">
1852 <input class=submit type=submit name=action value="|
1853       . $locale->text('Print') . qq|">
1854 <input class=submit type=submit name=action value="|
1855       . $locale->text('E-mail') . qq|">
1856 |;
1857   }
1858
1859   if ($form->{menubar}) {
1860     require "$form->{path}/menu.pl";
1861     &menubar;
1862   }
1863
1864   print qq|
1865 </form>
1866
1867 </body>
1868 </html>
1869 |;
1870
1871   $lxdebug->leave_sub();
1872 }
1873
1874 sub select_all {
1875   $lxdebug->enter_sub();
1876
1877   RP->aging(\%myconfig, \%$form);
1878
1879   map { $_->{checked} = "checked" } @{ $form->{AG} };
1880
1881   &aging;
1882
1883   $lxdebug->leave_sub();
1884 }
1885
1886 sub print_options {
1887   $lxdebug->enter_sub();
1888
1889   $form->{sendmode} = "attachment";
1890   $form->{copies}   = 2 unless $form->{copies};
1891
1892   $form->{PD}{ $form->{type} }     = "selected";
1893   $form->{DF}{ $form->{format} }   = "selected";
1894   $form->{OP}{ $form->{media} }    = "selected";
1895   $form->{SM}{ $form->{sendmode} } = "selected";
1896
1897   $type = qq|
1898             <option value=statement $form->{PD}{statement}>|
1899     . $locale->text('Statement');
1900
1901   if ($form->{media} eq 'email') {
1902     $media = qq|
1903             <option value=attachment $form->{SM}{attachment}>|
1904       . $locale->text('Attachment') . qq|
1905             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1906   } else {
1907     $media = qq|
1908             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1909     if ($myconfig{printer} && $latex) {
1910       $media .= qq|
1911             <option value=printer $form->{OP}{printer}>|
1912         . $locale->text('Printer');
1913     }
1914   }
1915
1916   if ($latex) {
1917     $format .= qq|
1918             <option value=postscript $form->{DF}{postscript}>|
1919       . $locale->text('Postscript') . qq|
1920             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
1921   }
1922
1923   print qq|
1924 <table>
1925   <tr>
1926     <td><select name=type>$type</select></td>
1927     <td><select name=format>$format</select></td>
1928     <td><select name=media>$media</select></td>
1929 |;
1930
1931   if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
1932     print qq|
1933       <td>| . $locale->text('Copies') . qq|
1934       <input name=copies size=2 value=$form->{copies}></td>
1935 |;
1936   }
1937
1938   print qq|
1939   </tr>
1940 </table>
1941 |;
1942
1943   $lxdebug->leave_sub();
1944 }
1945
1946 sub e_mail {
1947   $lxdebug->enter_sub();
1948
1949   # get name and email addresses
1950   for $i (1 .. $form->{rowcount}) {
1951     if ($form->{"statement_$i"}) {
1952       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
1953       RP->get_customer(\%myconfig, \%$form);
1954       $selected = 1;
1955       last;
1956     }
1957   }
1958
1959   $form->error($locale->text('Nothing selected!')) unless $selected;
1960
1961   if ($myconfig{role} eq 'admin') {
1962     $bcc = qq|
1963           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
1964           <td><input name=bcc size=30 value="$form->{bcc}"></td>
1965 |;
1966   }
1967
1968   $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
1969
1970   $form->{media} = "email";
1971
1972   $form->header;
1973
1974   print qq|
1975 <body>
1976
1977 <form method=post action=$form->{script}>
1978
1979 <table width=100%>
1980   <tr class=listtop>
1981     <th>$title</th>
1982   </tr>
1983   <tr height="5"></tr>
1984   <tr>
1985     <td>
1986       <table width=100%>
1987         <tr>
1988           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
1989           <td><input name=email size=30 value="$form->{email}"></td>
1990           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
1991           <td><input name=cc size=30 value="$form->{cc}"></td>
1992         </tr>
1993         <tr>
1994           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
1995           <td><input name=subject size=30 value="$form->{subject}"></td>
1996           $bcc
1997         </tr>
1998       </table>
1999     </td>
2000   </tr>
2001   <tr>
2002     <td>
2003       <table width=100%>
2004         <tr>
2005           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
2006         </tr>
2007         <tr>
2008           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
2009         </tr>
2010       </table>
2011     </td>
2012   </tr>
2013   <tr>
2014     <td>
2015 |;
2016
2017   &print_options;
2018
2019   map { delete $form->{$_} }
2020     qw(action email cc bcc subject message type sendmode format header);
2021
2022   # save all other variables
2023   foreach $key (keys %$form) {
2024     $form->{$key} =~ s/\"/&quot;/g;
2025     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2026   }
2027
2028   print qq|
2029     </td>
2030   </tr>
2031   <tr>
2032     <td><hr size=3 noshade></td>
2033   </tr>
2034 </table>
2035
2036 <input type=hidden name=nextsub value=send_email>
2037
2038 <br>
2039 <input name=action class=submit type=submit value="|
2040     . $locale->text('Continue') . qq|">
2041 </form>
2042
2043 </body>
2044 </html>
2045 |;
2046
2047   $lxdebug->leave_sub();
2048 }
2049
2050 sub send_email {
2051   $lxdebug->enter_sub();
2052
2053   $form->{OUT} = "$sendmail";
2054
2055   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
2056     unless $form->{subject};
2057
2058   RP->aging(\%myconfig, \%$form);
2059
2060   $form->{"statement_1"} = 1;
2061
2062   &print_form;
2063
2064   $form->redirect(
2065                  $locale->text('Statement sent to') . " $form->{$form->{ct}}");
2066
2067   $lxdebug->leave_sub();
2068 }
2069
2070 sub print {
2071   $lxdebug->enter_sub();
2072
2073   if ($form->{media} eq 'printer') {
2074     $form->error($locale->text('Select postscript or PDF!'))
2075       if ($form->{format} !~ /(postscript|pdf)/);
2076   }
2077
2078   for $i (1 .. $form->{rowcount}) {
2079     if ($form->{"statement_$i"}) {
2080       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
2081       $selected = 1;
2082       last;
2083     }
2084   }
2085
2086   $form->error($locale->text('Nothing selected!')) unless $selected;
2087
2088   if ($form->{media} eq 'printer') {
2089     $form->{OUT} = "| $myconfig{printer}";
2090     $form->{"$form->{ct}_id"} = "";
2091   } else {
2092     $form->{"statement_1"} = 1;
2093   }
2094
2095   RP->aging(\%myconfig, \%$form);
2096
2097   &print_form;
2098
2099   $form->redirect($locale->text('Statements sent to printer!'))
2100     if ($form->{media} eq 'printer');
2101
2102   $lxdebug->leave_sub();
2103 }
2104
2105 sub print_form {
2106   $lxdebug->enter_sub();
2107
2108   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
2109
2110   $form->{templates} = "$myconfig{templates}";
2111
2112   # setup variables for the form
2113   @a = qw(company address businessnumber tel fax);
2114   map { $form->{$_} = $myconfig{$_} } @a;
2115   $form->format_string(@a);
2116
2117   $form->{IN} = "$form->{type}.html";
2118
2119   if ($form->{format} eq 'postscript') {
2120     $form->{postscript} = 1;
2121     $form->{IN} =~ s/html$/tex/;
2122   }
2123   if ($form->{format} eq 'pdf') {
2124     $form->{pdf} = 1;
2125     $form->{IN} =~ s/html$/tex/;
2126   }
2127
2128   $i = 0;
2129   while (@{ $form->{AG} }) {
2130
2131     $ref = shift @{ $form->{AG} };
2132
2133     if ($ctid != $ref->{ctid}) {
2134
2135       $ctid = $ref->{ctid};
2136       $i++;
2137
2138       if ($form->{"statement_$i"}) {
2139
2140         @a =
2141           (name, street, zipcode, city, country, contact, email,
2142            "$form->{ct}phone", "$form->{ct}fax");
2143         map { $form->{$_} = $ref->{$_} } @a;
2144         $form->format_string(@a);
2145
2146         $form->{ $form->{ct} } = $form->{name};
2147         $form->{"$form->{ct}_id"} = $ref->{ctid};
2148
2149         map { $form->{$_} = () } qw(invnumber invdate duedate);
2150         $form->{total} = 0;
2151         foreach $item (qw(c0 c30 c60 c90)) {
2152           $form->{$item} = ();
2153           $form->{"${item}total"} = 0;
2154         }
2155
2156         &statement_details($ref);
2157
2158         while ($ref) {
2159
2160           if (scalar(@{ $form->{AG} }) > 0) {
2161
2162             # one or more left to go
2163             if ($ctid == $form->{AG}->[0]->{ctid}) {
2164               $ref = shift @{ $form->{AG} };
2165               &statement_details($ref);
2166
2167               # any more?
2168               $ref = scalar(@{ $form->{AG} });
2169             } else {
2170               $ref = 0;
2171             }
2172           } else {
2173
2174             # set initial ref to 0
2175             $ref = 0;
2176           }
2177
2178         }
2179
2180         map {
2181           $form->{"${_}total"} =
2182             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
2183         } (c0, c30, c60, c90, "");
2184
2185         $form->parse_template(\%myconfig, $userspath);
2186
2187       }
2188     }
2189   }
2190
2191   $lxdebug->leave_sub();
2192 }
2193
2194 sub statement_details {
2195   $lxdebug->enter_sub();
2196   my ($ref) = @_;
2197
2198   push @{ $form->{invnumber} }, $ref->{invnumber};
2199   push @{ $form->{invdate} },   $ref->{transdate};
2200   push @{ $form->{duedate} },   $ref->{duedate};
2201
2202   foreach $item (qw(c0 c30 c60 c90)) {
2203     eval {
2204       $ref->{$item} =
2205         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
2206     };
2207     $form->{"${item}total"} += $ref->{$item};
2208     $form->{total}          += $ref->{$item};
2209     push @{ $form->{$item} },
2210       $form->format_amount(\%myconfig, $ref->{$item}, 2);
2211   }
2212
2213   $lxdebug->leave_sub();
2214 }
2215
2216 sub generate_tax_report {
2217   $lxdebug->enter_sub();
2218
2219   RP->tax_report(\%myconfig, \%$form);
2220
2221   $descvar     = "$form->{accno}_description";
2222   $description = $form->escape($form->{$descvar});
2223   $ratevar     = "$form->{accno}_rate";
2224
2225   if ($form->{accno} =~ /^gifi_/) {
2226     $descvar     = "gifi_$form->{accno}_description";
2227     $description = $form->escape($form->{$descvar});
2228     $ratevar     = "gifi_$form->{accno}_rate";
2229   }
2230
2231   $department = $form->escape($form->{department});
2232
2233   # construct href
2234   $href =
2235     "$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}";
2236
2237   # construct callback
2238   $description = $form->escape($form->{$descvar},   1);
2239   $department  = $form->escape($form->{department}, 1);
2240   $callback    =
2241     "$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}";
2242
2243   $form->{title} = $locale->text('GIFI') . " - "
2244     if ($form->{accno} =~ /^gifi_/);
2245
2246   $title = $form->escape($form->{title});
2247   $href .= "&title=$title";
2248   $title = $form->escape($form->{title}, 1);
2249   $callback .= "&title=$title";
2250
2251   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
2252
2253   @columns =
2254     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
2255
2256   foreach $item (@columns) {
2257     if ($form->{"l_$item"} eq "Y") {
2258       push @column_index, $item;
2259
2260       # add column to href and callback
2261       $callback .= "&l_$item=Y";
2262       $href     .= "&l_$item=Y";
2263     }
2264   }
2265
2266   if ($form->{l_subtotal} eq 'Y') {
2267     $callback .= "&l_subtotal=Y";
2268     $href     .= "&l_subtotal=Y";
2269   }
2270
2271   if ($form->{department}) {
2272     ($department) = split /--/, $form->{department};
2273     $option = $locale->text('Department') . " : $department";
2274   }
2275
2276   # if there are any dates
2277   if ($form->{fromdate} || $form->{todate}) {
2278     if ($form->{fromdate}) {
2279       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
2280     }
2281     if ($form->{todate}) {
2282       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
2283     }
2284
2285     $form->{period} = "$fromdate - $todate";
2286   } else {
2287     $form->{period} =
2288       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2289   }
2290
2291   if ($form->{db} eq 'ar') {
2292     $name    = $locale->text('Customer');
2293     $invoice = 'is.pl';
2294     $arap    = 'ar.pl';
2295   }
2296   if ($form->{db} eq 'ap') {
2297     $name    = $locale->text('Vendor');
2298     $invoice = 'ir.pl';
2299     $arap    = 'ap.pl';
2300   }
2301
2302   $option .= "<br>" if $option;
2303   $option .= "$form->{period}";
2304
2305   $column_header{id} =
2306       qq|<th><a class=listheading href=$href&sort=id>|
2307     . $locale->text('ID')
2308     . qq|</th>|;
2309   $column_header{invnumber} =
2310       qq|<th><a class=listheading href=$href&sort=invnumber>|
2311     . $locale->text('Invoice')
2312     . qq|</th>|;
2313   $column_header{transdate} =
2314       qq|<th><a class=listheading href=$href&sort=transdate>|
2315     . $locale->text('Date')
2316     . qq|</th>|;
2317   $column_header{netamount} =
2318     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
2319   $column_header{tax} =
2320     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
2321   $column_header{amount} =
2322     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
2323
2324   $column_header{name} =
2325     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
2326
2327   $form->header;
2328
2329   print qq|
2330 <body>
2331
2332 <table width=100%>
2333   <tr>
2334     <th class=listtop colspan=$colspan>$form->{title}</th>
2335   </tr>
2336   <tr height="5"></tr>
2337   <tr>
2338     <td>$option</td>
2339   </tr>
2340   <tr>
2341     <td>
2342       <table width=100%>
2343         <tr class=listheading>
2344 |;
2345
2346   map { print "$column_header{$_}\n" } @column_index;
2347
2348   print qq|
2349         </tr>
2350 |;
2351
2352   # add sort and escape callback
2353   $callback = $form->escape($callback . "&sort=$form->{sort}");
2354
2355   if (@{ $form->{TR} }) {
2356     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
2357   }
2358
2359   foreach $ref (@{ $form->{TR} }) {
2360
2361     $module = ($ref->{invoice}) ? $invoice : $arap;
2362
2363     if ($form->{l_subtotal} eq 'Y') {
2364       if ($sameitem ne $ref->{ $form->{sort} }) {
2365         &tax_subtotal;
2366         $sameitem = $ref->{ $form->{sort} };
2367       }
2368     }
2369
2370     $totalnetamount += $ref->{netamount};
2371     $totaltax       += $ref->{tax};
2372     $ref->{amount} = $ref->{netamount} + $ref->{tax};
2373
2374     $subtotalnetamount += $ref->{netamount};
2375     $subtotaltax       += $ref->{tax};
2376
2377     map {
2378       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;");
2379     } qw(netamount tax amount);
2380
2381     $column_data{id}        = qq|<td>$ref->{id}</td>|;
2382     $column_data{invnumber} =
2383       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>|;
2384     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
2385     $column_data{name}      = qq|<td>$ref->{name}&nbsp;</td>|;
2386
2387     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
2388       qw(netamount tax amount);
2389
2390     $i++;
2391     $i %= 2;
2392     print qq|
2393         <tr class=listrow$i>
2394 |;
2395
2396     map { print "$column_data{$_}\n" } @column_index;
2397
2398     print qq|
2399         </tr>
2400 |;
2401
2402   }
2403
2404   if ($form->{l_subtotal} eq 'Y') {
2405     &tax_subtotal;
2406   }
2407
2408   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
2409
2410   print qq|
2411         </tr>
2412         <tr class=listtotal>
2413 |;
2414
2415   $total =
2416     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
2417   $totalnetamount =
2418     $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
2419   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
2420
2421   $column_data{netamount} =
2422     qq|<th class=listtotal align=right>$totalnetamount</th>|;
2423   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
2424   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
2425
2426   map { print "$column_data{$_}\n" } @column_index;
2427
2428   print qq|
2429         </tr>
2430       </table>
2431     </td>
2432   </tr>
2433   <tr>
2434     <td><hr size=3 noshade></td>
2435   </tr>
2436 </table>
2437
2438 </body>
2439 </html>
2440 |;
2441
2442   $lxdebug->leave_sub();
2443 }
2444
2445 sub tax_subtotal {
2446   $lxdebug->enter_sub();
2447
2448   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2449
2450   $subtotalnetamount =
2451     $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
2452   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
2453   $subtotal =
2454     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
2455                          2, "&nbsp;");
2456
2457   $column_data{netamount} =
2458     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
2459   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
2460   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
2461
2462   $subtotalnetamount = 0;
2463   $subtotaltax       = 0;
2464
2465   print qq|
2466         <tr class=listsubtotal>
2467 |;
2468   map { print "\n$column_data{$_}" } @column_index;
2469
2470   print qq|
2471         </tr>
2472 |;
2473
2474   $lxdebug->leave_sub();
2475 }
2476
2477 sub list_payments {
2478   $lxdebug->enter_sub();
2479
2480   if ($form->{account}) {
2481     ($form->{paymentaccounts}) = split /--/, $form->{account};
2482   }
2483   if ($form->{department}) {
2484     ($department, $form->{department_id}) = split /--/, $form->{department};
2485     $option = $locale->text('Department') . " : $department";
2486   }
2487
2488   RP->payments(\%myconfig, \%$form);
2489
2490   @columns =
2491     $form->sort_columns(qw(transdate reference name paid source memo));
2492
2493   # construct href
2494   $account    = $form->escape($form->{account});
2495   $title      = $form->escape($form->{title});
2496   $department = $form->escape($form->{department});
2497   $form->{paymentaccounts} =~ s/ /%20/g;
2498   $reference = $form->escape($form->{reference});
2499   $source    = $form->escape($form->{source});
2500   $memo      = $form->escape($form->{memo});
2501
2502   $href =
2503     "$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";
2504
2505   # construct callback
2506   $account    = $form->escape($form->{account},    1);
2507   $title      = $form->escape($form->{title},      1);
2508   $department = $form->escape($form->{department}, 1);
2509   $reference  = $form->escape($form->{reference},  1);
2510   $source     = $form->escape($form->{source},     1);
2511   $memo       = $form->escape($form->{memo},       1);
2512
2513   $form->{callback} =
2514     "$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}";
2515   $callback = $form->escape($form->{callback});
2516
2517   $column_header{name} =
2518       "<th><a class=listheading href=$href&sort=name>"
2519     . $locale->text('Description')
2520     . "</a></th>";
2521   $column_header{reference} =
2522       "<th><a class=listheading href=$href&sort=invnumber>"
2523     . $locale->text('Reference')
2524     . "</a></th>";
2525   $column_header{transdate} =
2526       "<th><a class=listheading href=$href&sort=transdate>"
2527     . $locale->text('Date')
2528     . "</a></th>";
2529   $column_header{paid} =
2530     "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
2531   $column_header{source} =
2532       "<th><a class=listheading href=$href&sort=source>"
2533     . $locale->text('Source')
2534     . "</a></th>";
2535   $column_header{memo} =
2536       "<th><a class=listheading href=$href&sort=memo>"
2537     . $locale->text('Memo')
2538     . "</a></th>";
2539
2540   if ($form->{fromdate}) {
2541     $option .= "\n<br>" if ($option);
2542     $option .=
2543         $locale->text('From') . "&nbsp;"
2544       . $locale->date(\%myconfig, $form->{fromdate}, 1);
2545   }
2546   if ($form->{todate}) {
2547     $option .= "\n<br>" if ($option);
2548     $option .=
2549         $locale->text('bis') . "&nbsp;"
2550       . $locale->date(\%myconfig, $form->{todate}, 1);
2551   }
2552
2553   @column_index = @columns;
2554   $colspan      = $#column_index + 1;
2555
2556   $form->header;
2557
2558   print qq|
2559 <body>
2560
2561 <table width=100%>
2562   <tr>
2563     <th class=listtop>$form->{title}</th>
2564   </tr>
2565   <tr height="5"></tr>
2566   <tr>
2567     <td>$option</td>
2568   </tr>
2569   <tr>
2570     <td>
2571       <table width=100%>
2572         <tr class=listheading>
2573 |;
2574
2575   map { print "\n$column_header{$_}" } @column_index;
2576
2577   print qq|
2578         </tr>
2579 |;
2580
2581   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
2582
2583     next unless @{ $form->{ $ref->{id} } };
2584
2585     print qq|
2586         <tr>
2587           <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
2588         </tr>
2589 |;
2590
2591     foreach $payment (@{ $form->{ $ref->{id} } }) {
2592
2593       $module = $payment->{module};
2594       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
2595       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
2596
2597       $href =
2598         qq|${module}.pl?path=$form->{path}&action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|;
2599
2600       $column_data{name}      = "<td>$payment->{name}&nbsp;</td>";
2601       $column_data{reference} =
2602         qq|<td><a href=$href>$payment->{invnumber}</a></td>|;
2603       $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
2604       $column_data{paid}      =
2605           "<td align=right>"
2606         . $form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")
2607         . "</td>";
2608       $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
2609       $column_data{memo}   = "<td>$payment->{memo}&nbsp;</td>";
2610
2611       $subtotalpaid += $payment->{paid};
2612       $totalpaid    += $payment->{paid};
2613
2614       $i++;
2615       $i %= 2;
2616       print qq|
2617         <tr class=listrow$i>
2618 |;
2619
2620       map { print "\n$column_data{$_}" } @column_index;
2621
2622       print qq|
2623         </tr>
2624 |;
2625
2626     }
2627
2628     # print subtotals
2629     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2630
2631     $column_data{paid} =
2632       "<th class=listsubtotal align=right>"
2633       . $form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;") . "</th>";
2634
2635     print qq|
2636         <tr class=listsubtotal>
2637 |;
2638
2639     map { print "\n$column_data{$_}" } @column_index;
2640
2641     print qq|
2642         </tr>
2643 |;
2644
2645     $subtotalpaid = 0;
2646
2647   }
2648
2649   # print total
2650   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2651
2652   $column_data{paid} =
2653     "<th class=listtotal align=right>"
2654     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;") . "</th>";
2655
2656   print qq|
2657         <tr class=listtotal>
2658 |;
2659
2660   map { print "\n$column_data{$_}" } @column_index;
2661
2662   print qq|
2663         </tr>
2664
2665       </table>
2666     </td>
2667   </tr>
2668   <tr>
2669     <td><hr size=3 noshade></td>
2670   </tr>
2671 </table>
2672
2673 </body>
2674 </html>
2675 |;
2676
2677   $lxdebug->leave_sub();
2678 }
2679
2680 sub config {
2681   $lxdebug->enter_sub();
2682   edit();
2683
2684   #$form->header;
2685   #print qq|Hallo|;
2686   $lxdebug->leave_sub();
2687 }
2688
2689 sub debug {
2690
2691   $form->debug();
2692
2693 }
2694
2695 sub winston_export {
2696   $lxdebug->enter_sub();
2697
2698   #create_winston();
2699   $form->{winston} = 1;
2700   &generate_ustva();
2701   $lxdebug->leave_sub();
2702 }
2703
2704 sub print_options {
2705   $lxdebug->enter_sub();
2706
2707   $form->{sendmode} = "attachment";
2708   $form->{copies}   = 2 unless $form->{copies};
2709
2710   $form->{PD}{ $form->{type} }     = "selected";
2711   $form->{DF}{ $form->{format} }   = "selected";
2712   $form->{OP}{ $form->{media} }    = "selected";
2713   $form->{SM}{ $form->{sendmode} } = "selected";
2714
2715   if ($form->{report} eq 'ustva') {
2716     $type = qq|
2717             <option value=ustva $form->{PD}{ustva}>| . $locale->text('ustva');
2718   } else {
2719     $type = qq|
2720             <option value=statement $form->{PD}{statement}>|
2721       . $locale->text('Statement');
2722   }
2723
2724   if ($form->{media} eq 'email') {
2725     $media = qq|
2726             <option value=attachment $form->{SM}{attachment}>|
2727       . $locale->text('Attachment') . qq|
2728             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
2729   } else {
2730     $media = qq|
2731             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
2732     if ($myconfig{printer} && $latex) {
2733       $media .= qq|
2734             <option value=printer $form->{OP}{printer}>|
2735         . $locale->text('Printer');
2736     }
2737   }
2738
2739   if ($latex) {
2740     $format .= qq|
2741             <option value=html $form->{DF}{html}>|
2742       . $locale->text('HTML') . qq|
2743             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
2744     if ($form->{report} ne 'ustva') {
2745       $format . qq|
2746             <option value=postscript $form->{DF}{postscript}>|
2747         . $locale->text('Postscript');
2748     }
2749   }
2750
2751   print qq|
2752 <table>
2753   <tr>
2754     <td><select name=type>$type</select></td>
2755     <td><select name=format>$format</select></td>
2756     <td><select name=media>$media</select></td>
2757 |;
2758
2759   if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
2760     print qq|
2761       <td>| . $locale->text('Copies') . qq|
2762       <input name=copies size=2 value=$form->{copies}></td>
2763 |;
2764   }
2765
2766   print qq|
2767   </tr>
2768 </table>
2769 |;
2770
2771   $lxdebug->leave_sub();
2772 }
2773
2774 sub generate_bwa {
2775   $lxdebug->enter_sub();
2776   $form->{padding} = "&nbsp;&nbsp;";
2777   $form->{bold}    = "<b>";
2778   $form->{endbold} = "</b>";
2779   $form->{br}      = "<br>";
2780
2781   #  &get_project(generate_bwa);
2782
2783   if ($form->{reporttype} eq "custom") {
2784
2785     #forgotten the year --> thisyear
2786     if ($form->{year} !~ m/^\d\d\d\d$/) {
2787       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2788         /(\d\d\d\d)/;
2789       $form->{year} = $1;
2790     }
2791
2792     #yearly report
2793     if ($form->{duetyp} eq "13") {
2794       $form->{fromdate}        = "1.1.$form->{year}";
2795       $form->{todate}          = "31.12.$form->{year}";
2796       $form->{comparefromdate} = "1.01.$form->{year}";
2797       $form->{comparetodate}   = "31.12.$form->{year}";
2798     }
2799
2800     #Quater reports
2801     if ($form->{duetyp} eq "A") {
2802       $form->{fromdate}        = "1.1.$form->{year}";
2803       $form->{todate}          = "31.3.$form->{year}";
2804       $form->{comparefromdate} = "1.01.$form->{year}";
2805       $form->{comparetodate}   = "31.03.$form->{year}";
2806     }
2807     if ($form->{duetyp} eq "B") {
2808       $form->{fromdate}        = "1.4.$form->{year}";
2809       $form->{todate}          = "30.6.$form->{year}";
2810       $form->{comparefromdate} = "1.01.$form->{year}";
2811       $form->{comparetodate}   = "30.06.$form->{year}";
2812     }
2813     if ($form->{duetyp} eq "C") {
2814       $form->{fromdate}        = "1.7.$form->{year}";
2815       $form->{todate}          = "30.9.$form->{year}";
2816       $form->{comparefromdate} = "1.01.$form->{year}";
2817       $form->{comparetodate}   = "30.09.$form->{year}";
2818     }
2819     if ($form->{duetyp} eq "D") {
2820       $form->{fromdate}        = "1.10.$form->{year}";
2821       $form->{todate}          = "31.12.$form->{year}";
2822       $form->{comparefromdate} = "1.01.$form->{year}";
2823       $form->{comparetodate}   = "31.12.$form->{year}";
2824     }
2825
2826     #Monthly reports
2827   SWITCH: {
2828       $form->{duetyp} eq "1" && do {
2829         $form->{fromdate}        = "1.1.$form->{year}";
2830         $form->{todate}          = "31.1.$form->{year}";
2831         $form->{comparefromdate} = "1.01.$form->{year}";
2832         $form->{comparetodate}   = "31.01.$form->{year}";
2833         last SWITCH;
2834       };
2835       $form->{duetyp} eq "2" && do {
2836         $form->{fromdate} = "1.2.$form->{year}";
2837
2838         #this works from 1901 to 2099, 1900 and 2100 fail.
2839         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
2840         $form->{todate}          = "$leap.2.$form->{year}";
2841         $form->{comparefromdate} = "1.01.$form->{year}";
2842         $form->{comparetodate}   = "$leap.02.$form->{year}";
2843         last SWITCH;
2844       };
2845       $form->{duetyp} eq "3" && do {
2846         $form->{fromdate}        = "1.3.$form->{year}";
2847         $form->{todate}          = "31.3.$form->{year}";
2848         $form->{comparefromdate} = "1.01.$form->{year}";
2849         $form->{comparetodate}   = "31.03.$form->{year}";
2850         last SWITCH;
2851       };
2852       $form->{duetyp} eq "4" && do {
2853         $form->{fromdate}        = "1.4.$form->{year}";
2854         $form->{todate}          = "30.4.$form->{year}";
2855         $form->{comparefromdate} = "1.01.$form->{year}";
2856         $form->{comparetodate}   = "30.04.$form->{year}";
2857         last SWITCH;
2858       };
2859       $form->{duetyp} eq "5" && do {
2860         $form->{fromdate}        = "1.5.$form->{year}";
2861         $form->{todate}          = "31.5.$form->{year}";
2862         $form->{comparefromdate} = "1.01.$form->{year}";
2863         $form->{comparetodate}   = "31.05.$form->{year}";
2864         last SWITCH;
2865       };
2866       $form->{duetyp} eq "6" && do {
2867         $form->{fromdate}        = "1.6.$form->{year}";
2868         $form->{todate}          = "30.6.$form->{year}";
2869         $form->{comparefromdate} = "1.01.$form->{year}";
2870         $form->{comparetodate}   = "30.06.$form->{year}";
2871         last SWITCH;
2872       };
2873       $form->{duetyp} eq "7" && do {
2874         $form->{fromdate}        = "1.7.$form->{year}";
2875         $form->{todate}          = "31.7.$form->{year}";
2876         $form->{comparefromdate} = "1.01.$form->{year}";
2877         $form->{comparetodate}   = "31.07.$form->{year}";
2878         last SWITCH;
2879       };
2880       $form->{duetyp} eq "8" && do {
2881         $form->{fromdate}        = "1.8.$form->{year}";
2882         $form->{todate}          = "31.8.$form->{year}";
2883         $form->{comparefromdate} = "1.01.$form->{year}";
2884         $form->{comparetodate}   = "31.08.$form->{year}";
2885         last SWITCH;
2886       };
2887       $form->{duetyp} eq "9" && do {
2888         $form->{fromdate}        = "1.9.$form->{year}";
2889         $form->{todate}          = "30.9.$form->{year}";
2890         $form->{comparefromdate} = "1.01.$form->{year}";
2891         $form->{comparetodate}   = "30.09.$form->{year}";
2892         last SWITCH;
2893       };
2894       $form->{duetyp} eq "10" && do {
2895         $form->{fromdate}        = "1.10.$form->{year}";
2896         $form->{todate}          = "31.10.$form->{year}";
2897         $form->{comparefromdate} = "1.01.$form->{year}";
2898         $form->{comparetodate}   = "31.10.$form->{year}";
2899         last SWITCH;
2900       };
2901       $form->{duetyp} eq "11" && do {
2902         $form->{fromdate}        = "1.11.$form->{year}";
2903         $form->{todate}          = "30.11.$form->{year}";
2904         $form->{comparefromdate} = "1.01.$form->{year}";
2905         $form->{comparetodate}   = "30.11.$form->{year}";
2906         last SWITCH;
2907       };
2908       $form->{duetyp} eq "12" && do {
2909         $form->{fromdate}        = "1.12.$form->{year}";
2910         $form->{todate}          = "31.12.$form->{year}";
2911         $form->{comparefromdate} = "1.01.$form->{year}";
2912         $form->{comparetodate}   = "31.12.$form->{year}";
2913         last SWITCH;
2914       };
2915     }
2916   } else {
2917     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
2918     $form->{fromdate} = "${dd}.${mm}.${yy}";
2919     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
2920     $form->{todate}          = "${dd}.${mm}.${yy}";
2921     $form->{comparefromdate} = "01.01.$yy";
2922     $form->{comparetodate}   = $form->{todate};
2923   }
2924
2925   RP->bwa(\%myconfig, \%$form);
2926
2927   ($form->{department}) = split /--/, $form->{department};
2928
2929   $form->{period} =
2930     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
2931   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
2932
2933   # if there are any dates construct a where
2934   if ($form->{fromdate} || $form->{todate}) {
2935
2936     unless ($form->{todate}) {
2937       $form->{todate} = $form->current_date(\%myconfig);
2938     }
2939
2940     my %germandate = ("dateformat" => "dd.mm.yyyy");
2941
2942     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
2943     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
2944
2945     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
2946     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
2947
2948     $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
2949     $form->{period}      =
2950         $locale->text('for Period')
2951       . qq|<br>\n$longfromdate |
2952       . $locale->text('bis')
2953       . qq| $longtodate|;
2954   }
2955
2956   # setup variables for the form
2957   @a = qw(company address businessnumber);
2958   map { $form->{$_} = $myconfig{$_} } @a;
2959   $form->{address} =~ s/\\n/<br>/g;
2960   $form->{templates} = $myconfig{templates};
2961
2962   $form->{IN} = "bwa.html";
2963
2964   $form->parse_template;
2965
2966   $lxdebug->leave_sub();
2967 }
2968
2969 sub generate_ustva {
2970   $lxdebug->enter_sub();
2971
2972   # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
2973   # Einlesen der Finanzamtdaten
2974   get_config($userspath, 'finanzamt.ini');
2975
2976   #  &get_project(generate_bwa);
2977   @anmeldungszeitraum =
2978     qw(0401, 0402, 0403, 0404, 0405, 0405, 0406, 0407, 0408, 0409, 0410, 0411, 0412, 0441, 0442, 0443, 0444);
2979
2980   foreach $item (@anmeldungszeitraum) {
2981     $form->{$item} = "";
2982   }
2983   if ($form->{reporttype} eq "custom") {
2984
2985     #forgotten the year --> thisyear
2986     if ($form->{year} !~ m/^\d\d\d\d$/) {
2987       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
2988         /(\d\d\d\d)/;
2989       $form->{year} = $1;
2990     }
2991
2992     #yearly report
2993     if ($form->{duetyp} eq "13") {
2994       $form->{fromdate} = "1.1.$form->{year}";
2995       $form->{todate}   = "31.12.$form->{year}";
2996     }
2997
2998     #Quater reports
2999     if ($form->{duetyp} eq "A") {
3000       $form->{fromdate} = "1.1.$form->{year}";
3001       $form->{todate}   = "31.3.$form->{year}";
3002       $form->{"0441"}   = "X";
3003     }
3004     if ($form->{duetyp} eq "B") {
3005       $form->{fromdate} = "1.4.$form->{year}";
3006       $form->{todate}   = "30.6.$form->{year}";
3007       $form->{"0442"}   = "X";
3008     }
3009     if ($form->{duetyp} eq "C") {
3010       $form->{fromdate} = "1.7.$form->{year}";
3011       $form->{todate}   = "30.9.$form->{year}";
3012       $form->{"0443"}   = "X";
3013     }
3014     if ($form->{duetyp} eq "D") {
3015       $form->{fromdate} = "1.10.$form->{year}";
3016       $form->{todate}   = "31.12.$form->{year}";
3017       $form->{"0444"}   = "X";
3018     }
3019
3020     #Monthly reports
3021   SWITCH: {
3022       $form->{duetyp} eq "1" && do {
3023         $form->{fromdate} = "1.1.$form->{year}";
3024         $form->{todate}   = "31.1.$form->{year}";
3025         $form->{"0401"}   = "X";
3026         last SWITCH;
3027       };
3028       $form->{duetyp} eq "2" && do {
3029         $form->{fromdate} = "1.2.$form->{year}";
3030
3031         #this works from 1901 to 2099, 1900 and 2100 fail.
3032         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
3033         $form->{todate} = "$leap.2.$form->{year}";
3034         $form->{"0402"} = "X";
3035         last SWITCH;
3036       };
3037       $form->{duetyp} eq "3" && do {
3038         $form->{fromdate} = "1.3.$form->{year}";
3039         $form->{todate}   = "31.3.$form->{year}";
3040         $form->{"0403"}   = "X";
3041         last SWITCH;
3042       };
3043       $form->{duetyp} eq "4" && do {
3044         $form->{fromdate} = "1.4.$form->{year}";
3045         $form->{todate}   = "30.4.$form->{year}";
3046         $form->{"0404"}   = "X";
3047         last SWITCH;
3048       };
3049       $form->{duetyp} eq "5" && do {
3050         $form->{fromdate} = "1.5.$form->{year}";
3051         $form->{todate}   = "31.5.$form->{year}";
3052         $form->{"0405"}   = "X";
3053         last SWITCH;
3054       };
3055       $form->{duetyp} eq "6" && do {
3056         $form->{fromdate} = "1.6.$form->{year}";
3057         $form->{todate}   = "30.6.$form->{year}";
3058         $form->{"0406"}   = "X";
3059         last SWITCH;
3060       };
3061       $form->{duetyp} eq "7" && do {
3062         $form->{fromdate} = "1.7.$form->{year}";
3063         $form->{todate}   = "31.7.$form->{year}";
3064         $form->{"0407"}   = "X";
3065         last SWITCH;
3066       };
3067       $form->{duetyp} eq "8" && do {
3068         $form->{fromdate} = "1.8.$form->{year}";
3069         $form->{todate}   = "31.8.$form->{year}";
3070         $form->{"0408"}   = "X";
3071         last SWITCH;
3072       };
3073       $form->{duetyp} eq "9" && do {
3074         $form->{fromdate} = "1.9.$form->{year}";
3075         $form->{todate}   = "30.9.$form->{year}";
3076         $form->{"0409"}   = "X";
3077         last SWITCH;
3078       };
3079       $form->{duetyp} eq "10" && do {
3080         $form->{fromdate} = "1.10.$form->{year}";
3081         $form->{todate}   = "31.10.$form->{year}";
3082         $form->{"0410"}   = "X";
3083         last SWITCH;
3084       };
3085       $form->{duetyp} eq "11" && do {
3086         $form->{fromdate} = "1.11.$form->{year}";
3087         $form->{todate}   = "30.11.$form->{year}";
3088         $form->{"0411"}   = "X";
3089         last SWITCH;
3090       };
3091       $form->{duetyp} eq "12" && do {
3092         $form->{fromdate} = "1.12.$form->{year}";
3093         $form->{todate}   = "31.12.$form->{year}";
3094         $form->{"0412"}   = "X";
3095         last SWITCH;
3096       };
3097     }
3098   }
3099
3100   #    $locale->date(\%myconfig, $form->current_date(\%myconfig), 0)=~ /(\d\d\d\d)/;
3101   #    $form->{year}= $1;
3102   #    $form->{fromdate}="1.1.$form->{year}";
3103   #    $form->{todate}="31.3.$form->{year}";
3104   #    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3105   #  }
3106
3107   RP->ustva(\%myconfig, \%$form);
3108
3109   ($form->{department}) = split /--/, $form->{department};
3110
3111   $form->{period} =
3112     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
3113   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
3114
3115   # if there are any dates construct a where
3116   if ($form->{fromdate} || $form->{todate}) {
3117
3118     unless ($form->{todate}) {
3119       $form->{todate} = $form->current_date(\%myconfig);
3120     }
3121
3122     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
3123     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
3124
3125     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
3126     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
3127
3128     $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
3129     $form->{period}      =
3130         $locale->text('for Period')
3131       . qq|<br>\n$longfromdate |
3132       . $locale->text('bis')
3133       . qq| $longtodate|;
3134   }
3135
3136   if ($form->{comparefromdate} || $form->{comparetodate}) {
3137     $longcomparefromdate =
3138       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
3139     $shortcomparefromdate =
3140       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
3141
3142     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
3143     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
3144
3145     $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
3146     $form->{period} .=
3147         "<br>\n$longcomparefromdate "
3148       . $locale->text('bis')
3149       . qq| $longcomparetodate|;
3150   }
3151
3152   $form->{Datum_heute} =
3153     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
3154
3155   if (   $form->{format} eq 'pdf'
3156       or $form->{format} eq 'postscript') {
3157     $form->{padding} = "~~";
3158     $form->{bold}    = "\textbf{";
3159     $form->{endbold} = "}";
3160     $form->{br}      = '\\\\';
3161
3162     @numbers = qw(51r 86r 97r 93r 96 43 45
3163       66 62 67);
3164     foreach $number (@numbers) {
3165       $form->{$number} =~ s/,/~~/g;
3166     }
3167
3168       } elsif ($form->{format} eq 'html') {
3169     $form->{padding} = "&nbsp;&nbsp;";
3170     $form->{bold}    = "<b>";
3171     $form->{endbold} = "</b>";
3172     $form->{br}      = "<br>"
3173
3174   }
3175
3176   # setup variables for the form
3177   @a = qw(company address businessnumber);
3178   map { $form->{$_} = $myconfig{$_} } @a;
3179
3180   $form->{address} =~ s/\\n/$form->{br}/g;
3181
3182   if ($form->{winston} eq '1') {
3183     create_winston();
3184
3185   } else {
3186     $form->{templates} = $myconfig{templates};
3187     $form->{IN}        = "$form->{type}";
3188     $form->{IN} .= '.tex'
3189       if (   $form->{format} eq 'pdf'
3190           or $form->{format} eq 'postscript');
3191     $form->{IN} .= '.html' if ($form->{format} eq 'html');
3192
3193     $form->parse_template(\%myconfig, $userspath);
3194
3195     # $form->parse_template;
3196   }
3197   $lxdebug->leave_sub();
3198 }