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