Formatierungen in der Kontenliste, Summensaldenliste und AR und AP Aging geaendert...
[kivitendo-erp.git] / bin / mozilla / ca.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) 2001
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # module for Chart of Accounts, Income Statement and Balance Sheet
31 # search and edit transactions posted by the GL, AR and AP
32 #
33 #======================================================================
34
35 use SL::CA;
36
37 1;
38
39 # end of main
40
41 # this is for our long dates
42 # $locale->text('January')
43 # $locale->text('February')
44 # $locale->text('March')
45 # $locale->text('April')
46 # $locale->text('May ')
47 # $locale->text('June')
48 # $locale->text('July')
49 # $locale->text('August')
50 # $locale->text('September')
51 # $locale->text('October')
52 # $locale->text('November')
53 # $locale->text('December')
54
55 # this is for our short month
56 # $locale->text('Jan')
57 # $locale->text('Feb')
58 # $locale->text('Mar')
59 # $locale->text('Apr')
60 # $locale->text('May')
61 # $locale->text('Jun')
62 # $locale->text('Jul')
63 # $locale->text('Aug')
64 # $locale->text('Sep')
65 # $locale->text('Oct')
66 # $locale->text('Nov')
67 # $locale->text('Dec')
68
69 sub chart_of_accounts {
70   $lxdebug->enter_sub();
71
72   CA->all_accounts(\%myconfig, \%$form);
73
74   @column_index = qw(accno gifi_accno description debit credit);
75
76   $column_header{accno} =
77     qq|<th class=listheading>| . $locale->text('Account') . qq|</th>\n|;
78   $column_header{gifi_accno} =
79     qq|<th class=listheading>| . $locale->text('GIFI') . qq|</th>\n|;
80   $column_header{description} =
81     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>\n|;
82   $column_header{debit} =
83     qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>\n|;
84   $column_header{credit} =
85     qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>\n|;
86
87   $form->{title} = $locale->text('Chart of Accounts');
88
89   $colspan = $#column_index + 1;
90
91   $form->header;
92
93   print qq|
94 <body>
95
96 <table border=0 width=100%>
97   <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
98   <tr height="5"></tr>
99   <tr class=listheading>|;
100
101   map { print $column_header{$_} } @column_index;
102
103   print qq|
104   </tr>
105 |;
106
107   foreach $ca (@{ $form->{CA} }) {
108
109     $description      = $form->escape($ca->{description});
110     $gifi_description = $form->escape($ca->{gifi_description});
111
112     $href =
113       qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&password=$form->{password}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
114
115     if ($ca->{charttype} eq "H") {
116       print qq|<tr class=listheading>|;
117       map { $column_data{$_} = "<th>$ca->{$_}</th>"; } qw(accno description);
118       $column_data{gifi_accno} = "<th>$ca->{gifi_accno}&nbsp;</th>";
119     } else {
120       $i++;
121       $i %= 2;
122       print qq|<tr class=listrow$i>|;
123       $column_data{accno}      = "<td><a href=$href>$ca->{accno}</a></td>";
124       $column_data{gifi_accno} =
125         "<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a>&nbsp;</td>";
126       $column_data{description} = "<td>$ca->{description}</td>";
127     }
128     my $debit = "";
129     my $credit = "";
130     if ($ca->{debit}) {
131       $debit = $form->format_amount(\%myconfig, $ca->{debit}, 2, "&nbsp;");
132     }
133     if ($ca->{credit}) {
134       $credit = $form->format_amount(\%myconfig, $ca->{credit}, 2, "&nbsp;");
135     }
136     $column_data{debit} =
137         "<td align=right>"
138       . $debit
139       . "</td>\n";
140     $column_data{credit} =
141         "<td align=right>"
142       . $credit
143       . "</td>\n";
144
145     $totaldebit  += $ca->{debit};
146     $totalcredit += $ca->{credit};
147
148     map { print $column_data{$_} } @column_index;
149
150     print qq|
151 </tr>
152 |;
153   }
154
155   map { $column_data{$_} = "<td>&nbsp;</td>"; }
156     qw(accno gifi_accno description);
157
158   $column_data{debit} =
159     "<th align=right class=listtotal>"
160     . $form->format_amount(\%myconfig, $totaldebit, 2, 0) . "</th>";
161   $column_data{credit} =
162     "<th align=right class=listtotal>"
163     . $form->format_amount(\%myconfig, $totalcredit, 2, 0) . "</th>";
164
165   print "<tr class=listtotal>";
166
167   map { print $column_data{$_} } @column_index;
168
169   print qq|
170 </tr>
171 <tr>
172   <td colspan=$colspan><hr size=3 noshade></td>
173 </tr>
174 </table>
175
176 </body>
177 </html>
178 |;
179
180   $lxdebug->leave_sub();
181 }
182
183 sub list {
184   $lxdebug->enter_sub();
185
186   $form->{title} = $locale->text('List Transactions');
187   if ($form->{accounttype} eq 'gifi') {
188     $form->{title} .= " - " . $locale->text('GIFI') . " $form->{gifi_accno}";
189   } else {
190     $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}";
191   }
192
193   # get departments
194   $form->all_departments(\%myconfig);
195   if (@{ $form->{all_departments} }) {
196     $form->{selectdepartment} = "<option>\n";
197
198     map {
199       $form->{selectdepartment} .=
200         "<option>$_->{description}--$_->{id}\n"
201     } (@{ $form->{all_departments} });
202   }
203
204   $department = qq|
205         <tr>
206           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
207           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
208         </tr>
209 | if $form->{selectdepartment};
210
211   $form->header;
212
213   map { $form->{$_} =~ s/\"/&quot;/g; } qw(description gifi_description);
214
215   print qq|
216 <body>
217
218 <form method=post action=$form->{script}>
219
220 <input type=hidden name=accno value=$form->{accno}>
221 <input type=hidden name=description value="$form->{description}">
222 <input type=hidden name=sort value=transdate>
223 <input type=hidden name=eur value=$eur>
224 <input type=hidden name=accounttype value=$form->{accounttype}>
225 <input type=hidden name=gifi_accno value=$form->{gifi_accno}>
226 <input type=hidden name=gifi_description value="$form->{gifi_description}">
227
228 <table border=0 width=100%>
229   <tr><th class=listtop>$form->{title}</th></tr>
230   <tr height="5"></tr
231   <tr valign=top>
232     <td>
233       <table>
234         $department
235         <tr>
236           <th align=right>| . $locale->text('From') . qq|</th>
237           <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
238           <th align=right>| . $locale->text('To') . qq|</th>
239           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
240         </tr>
241         <tr>
242           <th align=right>| . $locale->text('Include in Report') . qq|</th>
243           <td colspan=3>
244           <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
245     . $locale->text('Subtotal') . qq|</td>
246         </tr>
247       </table>
248     </td>
249   </tr>
250   <tr><td><hr size=3 noshade></td></tr>
251 </table>
252
253 <input type=hidden name=login value=$form->{login}>
254 <input type=hidden name=path value=$form->{path}>
255 <input type=hidden name=password value=$form->{password}>
256
257 <br><input class=submit type=submit name=action value="|
258     . $locale->text('List Transactions') . qq|">
259 </form>
260
261 </body>
262 </html>
263 |;
264
265   $lxdebug->leave_sub();
266 }
267
268 sub list_transactions {
269   $lxdebug->enter_sub();
270
271   CA->all_transactions(\%myconfig, \%$form);
272
273   $description      = $form->escape($form->{description});
274   $gifi_description = $form->escape($form->{gifi_description});
275   $department       = $form->escape($form->{department});
276   $projectnumber    = $form->escape($form->{projectnumber});
277   $title            = $form->escape($form->{title});
278
279   # construct href
280   $href =
281     "$form->{script}?path=$form->{path}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title";
282
283   $description      = $form->escape($form->{description},      1);
284   $gifi_description = $form->escape($form->{gifi_description}, 1);
285   $department       = $form->escape($form->{department},       1);
286   $projectnumber    = $form->escape($form->{projectnumber},    1);
287   $title            = $form->escape($form->{title},            1);
288
289   # construct callback
290   $callback =
291     "$form->{script}?path=$form->{path}&action=list_transactions&accno=$form->{accno}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&description=$description&accounttype=$form->{accounttype}&gifi_accno=$form->{gifi_accno}&gifi_description=$gifi_description&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title";
292
293   # figure out which column comes first
294   $column_header{transdate} =
295       qq|<th><a class=listheading href=$href&sort=transdate>|
296     . $locale->text('Date')
297     . qq|</a></th>|;
298   $column_header{reference} =
299       qq|<th><a class=listheading href=$href&sort=reference>|
300     . $locale->text('Reference')
301     . qq|</a></th>|;
302   $column_header{description} =
303       qq|<th><a class=listheading href=$href&sort=description>|
304     . $locale->text('Description')
305     . qq|</a></th>|;
306   $column_header{debit}   = qq|<th>| . $locale->text('Debit') . qq|</th>|;
307   $column_header{credit}  = qq|<th>| . $locale->text('Credit') . qq|</th>|;
308   $column_header{balance} = qq|<th>| . $locale->text('Balance') . qq|</th>|;
309
310   @column_index =
311     $form->sort_columns(qw(transdate reference description debit credit));
312
313   if ($form->{accounttype} eq 'gifi') {
314     map { $form->{$_} = $form->{"gifi_$_"} } qw(accno description);
315   }
316   if ($form->{accno}) {
317     push @column_index, "balance";
318   }
319
320   $form->{title} =
321     ($form->{accounttype} eq 'gifi')
322     ? $locale->text('GIFI')
323     : $locale->text('Account');
324
325   $form->{title} .= " $form->{accno} - $form->{description}";
326
327   if ($form->{department}) {
328     ($department) = split /--/, $form->{department};
329     $options = $locale->text('Department') . " : $department<br>";
330   }
331   if ($form->{projectnumber}) {
332     $options .= $locale->text('Project Number');
333     $options .= " : $form->{projectnumber}<br>";
334   }
335
336   if ($form->{fromdate} || $form->{todate}) {
337     if ($form->{fromdate}) {
338       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
339     }
340     if ($form->{todate}) {
341       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
342     }
343
344     $form->{period} = "$fromdate - $todate";
345   } else {
346     $form->{period} =
347       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
348   }
349
350   $options .= $form->{period};
351
352   $form->header;
353
354   print qq|
355 <body>
356
357 <table width=100%>
358   <tr>
359     <th class=listtop>$form->{title}</th>
360   </tr>
361   <tr height="5"></tr>
362   <tr>
363     <td>$options</td>
364   </tr>
365   <tr>
366     <td>
367       <table width=100%>
368        <tr class=listheading>
369 |;
370
371   map { print "$column_header{$_}\n" } @column_index;
372
373   print qq|
374        </tr>
375 |;
376
377   # add sort to callback
378   $callback = $form->escape($callback . "&sort=$form->{sort}");
379
380   if (@{ $form->{CA} }) {
381     $sameitem = $form->{CA}->[0]->{ $form->{sort} };
382   }
383
384   $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
385   if ($form->{accno} && $form->{balance}) {
386
387     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
388
389     $column_data{balance} =
390         "<td align=right>"
391       . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
392       . "</td>";
393
394     $i++;
395     $i %= 2;
396     print qq|
397         <tr class=listrow$i>
398 |;
399     map { print $column_data{$_} } @column_index;
400     print qq|
401        </tr>
402 |;
403   }
404
405   foreach $ca (@{ $form->{CA} }) {
406
407     if ($form->{l_subtotal} eq 'Y') {
408       if ($sameitem ne $ca->{ $form->{sort} }) {
409         &ca_subtotal;
410       }
411     }
412
413     # construct link to source
414     $href =
415       "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{reference}</a>";
416     my $debit = ($ca->{debit} != 0) ? $form->format_amount(\%myconfig, $ca->{debit}, 2, "&nbsp;") : "&nbsp;";
417     $column_data{debit} =
418       "<td align=right>$debit</td>";
419     my $credit = ($ca->{credit} != 0) ? $form->format_amount(\%myconfig, $ca->{credit}, 2, "&nbsp;") : "&nbsp;";
420     $column_data{credit} =
421       "<td align=right>$credit</td>";
422
423     $form->{balance} += $ca->{amount};
424     $column_data{balance} =
425         "<td align=right>"
426       . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
427       . "</td>";
428
429     $subtotaldebit  += $ca->{debit};
430     $subtotalcredit += $ca->{credit};
431
432     $totaldebit  += $ca->{debit};
433     $totalcredit += $ca->{credit};
434
435     $column_data{transdate}   = qq|<td>$ca->{transdate}</td>|;
436     $column_data{reference}   = qq|<td>$href</td>|;
437     $column_data{description} = qq|<td>$ca->{description}</td>|;
438
439     $i++;
440     $i %= 2;
441     print qq|
442         <tr class=listrow$i>
443 |;
444
445     map { print $column_data{$_} } @column_index;
446
447     print qq|
448         </tr>
449 |;
450
451   }
452
453   if ($form->{l_subtotal} eq 'Y') {
454     &ca_subtotal;
455   }
456
457   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
458
459   $column_data{debit} =
460     "<th align=right>"
461     . $form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;") . "</th>";
462   $column_data{credit} =
463     "<th align=right>"
464     . $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;") . "</th>";
465   $column_data{balance} =
466     "<th align=right>"
467     . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0) . "</th>";
468
469   print qq|
470         <tr class=listtotal>
471 |;
472
473   map { print $column_data{$_} } @column_index;
474
475   print qq|
476         </tr>
477       </table>
478     </td>
479   </tr>
480   <tr>
481     <td><hr size=3 noshade></td>
482   </tr>
483 </table>
484
485 </body>
486 </html>
487 |;
488
489   $lxdebug->leave_sub();
490 }
491
492 sub ca_subtotal {
493   $lxdebug->enter_sub();
494
495   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
496
497   $column_data{debit} =
498     "<th align=right>"
499     . $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;") . "</th>";
500   $column_data{credit} =
501     "<th align=right>"
502     . $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;") . "</th>";
503
504   $subtotaldebit  = 0;
505   $subtotalcredit = 0;
506
507   $sameitem = $ca->{ $form->{sort} };
508
509   print qq|
510       <tr class=listsubtotal>
511 |;
512
513   map { print "$column_data{$_}\n" } @column_index;
514
515   print qq|
516       </tr>
517 |;
518
519   $lxdebug->leave_sub();
520 }