Buchungsjournal um Anzeige von Splitbuchungen erweitert, Splitbuchungen beim Dialogbu...
[kivitendo-erp.git] / bin / mozilla / gl.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 #
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 # Genereal Ledger
31 #
32 #======================================================================
33
34
35 use SL::GL;
36 use SL::PE;
37
38 require "$form->{path}/arap.pl";
39
40 1;
41 # end of main
42
43
44 # this is for our long dates
45 # $locale->text('January')
46 # $locale->text('February')
47 # $locale->text('March')
48 # $locale->text('April')
49 # $locale->text('May ')
50 # $locale->text('June')
51 # $locale->text('July')
52 # $locale->text('August')
53 # $locale->text('September')
54 # $locale->text('October')
55 # $locale->text('November')
56 # $locale->text('December')
57
58 # this is for our short month
59 # $locale->text('Jan')
60 # $locale->text('Feb')
61 # $locale->text('Mar')
62 # $locale->text('Apr')
63 # $locale->text('May')
64 # $locale->text('Jun')
65 # $locale->text('Jul')
66 # $locale->text('Aug')
67 # $locale->text('Sep')
68 # $locale->text('Oct')
69 # $locale->text('Nov')
70 # $locale->text('Dec')
71
72
73 sub add {
74
75   $form->{title} = "Add";
76   
77   $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
78
79   # we use this only to set a default date
80   GL->transaction(\%myconfig, \%$form);
81
82   map { $chart .= "<option value=\"$_->{accno}--$_->{taxkey_id}\">$_->{accno}--$_->{description}</option>" } @{ $form->{chart} };
83   map { $tax .= qq|<option value="$_->{taxkey}--$_->{rate}">$_->{taxdescription}  |.($_->{rate} * 100).qq| %|} @{ $form->{TAX} };
84   
85   $form->{chart} = $chart;
86   $form->{chartinit} = $chart;
87   $form->{rowcount} = 2;
88
89   $form->{debitchart} = $chart;
90   $form->{creditchart} = $chart;
91   $form->{taxchart} = $tax;
92   
93   $form->{debit} = 0;
94   $form->{credit} = 0;
95   $form->{tax} = 0;
96   
97
98   # departments
99   $form->all_departments(\%myconfig);
100   if (@{ $form->{all_departments} }) {
101     $form->{selectdepartment} = "<option>\n";
102
103     map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
104   }
105  
106   &display_form(1);
107   
108 }
109
110
111 sub edit {
112
113   GL->transaction(\%myconfig, \%$form);
114
115   map { if ($form->{debitaccno} eq $_->{accno}) {$form->{debitchart} .= "<option value=\"$_->{accno}--$_->{taxkey_id}\">$_->{accno}--$_->{description}"} } @{ $form->{chart} };
116   map { if ($form->{creditaccno} eq $_->{accno}) {$form->{creditchart} .= "<option value=\"$_->{accno}--$_->{taxkey_id}\">$_->{accno}--$_->{description}"} } @{ $form->{chart} };
117   map { $tax .= qq|<option value="$_->{taxkey}--$_->{rate}">$_->{taxdescription}  |.($_->{rate} * 100).qq| %|} @{ $form->{TAX} };
118   
119   $form->{chart} = $chart;
120
121   $form->{taxchart} = $tax;
122   
123   if ($form->{tax} < 0) {
124     $form->{tax} = $form->{tax} * (-1);
125   }
126   
127   $form->{amount}=$form->format_amount(\%myconfig, $form->{amount}, 2);
128   
129   # departments
130   $form->all_departments(\%myconfig);
131   if (@{ $form->{all_departments} }) {
132     $form->{selectdepartment} = "<option>\n";
133
134     map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
135   }
136
137    $i = 1;
138   foreach $ref (@{ $form->{GL} }) {
139     $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
140
141     $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}";
142     for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
143     
144     if ($ref->{amount} < 0) {
145       $form->{totaldebit} -= $ref->{amount};
146       $form->{"debit_$i"} = $ref->{amount} * -1;
147     } else {
148       $form->{totalcredit} += $ref->{amount};
149       $form->{"credit_$i"} = $ref->{amount};
150     }
151
152     $i++;
153   }
154
155   $form->{rowcount} = $i;
156   $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
157
158   $form->{title} = "Edit";
159   
160   &form_header;
161   &display_rows;
162   &form_footer;
163   
164 }
165
166
167
168 sub search {
169
170   $form->{title} = $locale->text('Buchungsjournal');
171   
172   $form->all_departments(\%myconfig);
173   # departments
174   if (@{ $form->{all_departments} }) {
175     $form->{selectdepartment} = "<option>\n";
176
177     map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
178   }
179  
180   $department = qq|
181         <tr>
182           <th align=right nowrap>|.$locale->text('Department').qq|</th>
183           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
184         </tr>
185 | if $form->{selectdepartment};
186   
187   # use JavaScript Calendar or not
188   $form->{jsscript} = $jscalendar;
189   $jsscript = "";
190   if ($form->{jsscript}) 
191   {
192     # with JavaScript Calendar
193     $button1 = qq|
194        <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}">
195        <input type=button name=datefrom id="trigger1" value=|.$locale->text('button').qq|></td>  
196        |;
197      $button2 = qq|
198        <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}">
199        <input type=button name=dateto id="trigger2" value=|.$locale->text('button').qq|></td>
200      |;
201      #write Trigger
202      $jsscript = Form->write_trigger(\%myconfig,"2","datefrom","BR","trigger1","dateto","BL","trigger2");
203    }
204    else
205    {
206       # without JavaScript Calendar
207       $button1 = qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}"></td>|;
208       $button2 = qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}"></td>|;
209     }
210
211   $form->header;
212
213   print qq|
214 <body>
215
216 <form method=post action=$form->{script}>
217
218 <input type=hidden name=sort value=transdate>
219
220 <table width=100%>
221   <tr>
222     <th class=listtop>$form->{title}</th>
223   </tr>
224   <tr height="5"></tr>
225   <tr>
226     <td>
227       <table>
228         <tr>
229           <th align=right>|.$locale->text('Reference').qq|</th>
230           <td><input name=reference size=20></td>
231           <th align=right>|.$locale->text('Source').qq|</th>
232           <td><input name=source size=20></td>
233         </tr>
234         $department
235         <tr>
236           <th align=right>|.$locale->text('Description').qq|</th>
237           <td colspan=3><input name=description size=40></td>
238         </tr>
239         <tr>
240           <th align=right>|.$locale->text('Notes').qq|</th>
241           <td colspan=3><input name=notes size=40></td>
242         </tr>
243         <tr>
244           <th align=right>|.$locale->text('From').qq|</th>
245           $button1
246           $button2
247         </tr>
248         <tr>
249           <th align=right>|.$locale->text('Include in Report').qq|</th>
250           <td colspan=3>
251             <table>
252               <tr>
253                 <td>
254                   <input name="category" class=radio type=radio value=X checked>&nbsp;|.$locale->text('All').qq|
255                   <input name="category" class=radio type=radio value=A>&nbsp;|.$locale->text('Asset').qq|
256                   <input name="category" class=radio type=radio value=C>&nbsp;|.$locale->text('Contra').qq|
257                   <input name="category" class=radio type=radio value=L>&nbsp;|.$locale->text('Liability').qq|
258                   <input name="category" class=radio type=radio value=Q>&nbsp;|.$locale->text('Equity').qq|
259                   <input name="category" class=radio type=radio value=I>&nbsp;|.$locale->text('Revenue').qq|
260                   <input name="category" class=radio type=radio value=E>&nbsp;|.$locale->text('Expense').qq|
261                 </td>
262               </tr>
263               <tr>
264                 <table>
265                   <tr>
266                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
267                     <td>|.$locale->text('ID').qq|</td>
268                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
269                     <td>|.$locale->text('Date').qq|</td>
270                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
271                     <td>|.$locale->text('Reference').qq|</td>
272                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
273                     <td>|.$locale->text('Description').qq|</td>
274                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
275                     <td>|.$locale->text('Notes').qq|</td>
276                   </tr>
277                   <tr>
278                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
279                     <td>|.$locale->text('Debit').qq|</td>
280                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
281                     <td>|.$locale->text('Credit').qq|</td>
282                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
283                     <td>|.$locale->text('Source').qq|</td>
284                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
285                     <td>|.$locale->text('Account').qq|</td>
286                     <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
287                     <td>|.$locale->text('GIFI').qq|</td>
288                   </tr>
289                   <tr>
290                     <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
291                     <td>|.$locale->text('Subtotal').qq|</td>
292                   </tr>
293                 </table>
294               </tr>
295             </table>
296         </tr>
297       </table>
298     </td>
299   </tr>
300   <tr>
301     <td><hr size=3 noshade></td>
302   </tr>
303 </table>
304
305 $jsscript
306
307 <input type=hidden name=nextsub value=generate_report>
308
309 <input type=hidden name=path value=$form->{path}>
310 <input type=hidden name=login value=$form->{login}>
311 <input type=hidden name=password value=$form->{password}>
312
313 <br>
314 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
315 </form>
316
317 </body>
318 </html>
319 |;
320 }
321
322
323 sub generate_report {
324
325   $form->{sort} = "transdate" unless $form->{sort};
326
327   GL->all_transactions(\%myconfig, \%$form);
328   
329   $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
330
331   $href = $callback;
332   
333   %acctype = ( 'A' => $locale->text('Asset'),
334                'C' => $locale->text('Contra'),
335                'L' => $locale->text('Liability'),
336                'Q' => $locale->text('Equity'),
337                'I' => $locale->text('Revenue'),
338                'E' => $locale->text('Expense'),
339              );
340   
341   $form->{title} = $locale->text('General Ledger');
342   
343   $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
344
345   unless ($form->{category} eq 'X') {
346     $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
347   }
348   if ($form->{accno}) {
349     $href .= "&accno=".$form->escape($form->{accno});
350     $callback .= "&accno=".$form->escape($form->{accno},1);
351     $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
352   }
353   if ($form->{gifi_accno}) {
354     $href .= "&gifi_accno=".$form->escape($form->{gifi_accno});
355     $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);
356     $option .= "\n<br>" if $option;
357     $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
358   }
359   if ($form->{source}) {
360     $href .= "&source=".$form->escape($form->{source});
361     $callback .= "&source=".$form->escape($form->{source},1);
362     $option .= "\n<br>" if $option;
363     $option .= $locale->text('Source')." : $form->{source}";
364   }
365   if ($form->{reference}) {
366     $href .= "&reference=".$form->escape($form->{reference});
367     $callback .= "&reference=".$form->escape($form->{reference},1);
368     $option .= "\n<br>" if $option;
369     $option .= $locale->text('Reference')." : $form->{reference}";
370   }
371   if ($form->{department}) {
372     $href .= "&department=".$form->escape($form->{department});
373     $callback .= "&department=".$form->escape($form->{department},1);
374     ($department) = split /--/, $form->{department};
375     $option .= "\n<br>" if $option;
376     $option .= $locale->text('Department')." : $department";
377   }
378
379   if ($form->{description}) {
380     $href .= "&description=".$form->escape($form->{description});
381     $callback .= "&description=".$form->escape($form->{description},1);
382     $option .= "\n<br>" if $option;
383     $option .= $locale->text('Description')." : $form->{description}";
384   }
385   if ($form->{notes}) {
386     $href .= "&notes=".$form->escape($form->{notes});
387     $callback .= "&notes=".$form->escape($form->{notes},1);
388     $option .= "\n<br>" if $option;
389     $option .= $locale->text('Notes')." : $form->{notes}";
390   }
391    
392   if ($form->{datefrom}) {
393     $href .= "&datefrom=$form->{datefrom}";
394     $callback .= "&datefrom=$form->{datefrom}";
395     $option .= "\n<br>" if $option;
396     $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
397   }
398   if ($form->{dateto}) {
399     $href .= "&dateto=$form->{dateto}";
400     $callback .= "&dateto=$form->{dateto}";
401     if ($form->{datefrom}) {
402       $option .= " ";
403     } else {
404       $option .= "\n<br>" if $option;
405     }
406     $option .= $locale->text('Bis')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
407   }
408
409
410   @columns = $form->sort_columns(qw(transdate id reference description notes source debit debit_accno credit credit_accno debit_tax debit_tax_accno credit_tax credit_tax_accno accno gifi_accno));
411
412   if ($form->{accno} || $form->{gifi_accno}) {
413     @columns = grep !/(accno|gifi_accno)/, @columns;
414     push @columns, "balance";
415     $form->{l_balance} = "Y";
416  
417  }
418   
419   $form->{l_credit_accno} = "Y";
420   $form->{l_debit_accno} = "Y";
421   $form->{l_credit_tax} = "Y";
422   $form->{l_debit_tax} = "Y";
423   $form->{l_credit_tax_accno} = "Y";
424   $form->{l_debit_tax_accno} = "Y";
425   $form->{l_accno} = "N";
426   foreach $item (@columns) {
427     if ($form->{"l_$item"} eq "Y") {
428       push @column_index, $item;
429
430       # add column to href and callback
431       $callback .= "&l_$item=Y";
432       $href .= "&l_$item=Y";
433     }
434   }
435
436   if ($form->{l_subtotal} eq 'Y') {
437     $callback .= "&l_subtotal=Y";
438     $href .= "&l_subtotal=Y";
439   }
440
441   $callback .= "&category=$form->{category}";
442   $href .= "&category=$form->{category}";
443
444   $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
445   $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
446   $column_header{reference} = "<th><a class=listheading href=$href&sort=reference>".$locale->text('Reference')."</a></th>";
447   $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
448   $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";
449   $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
450   $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
451   $column_header{debit_accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Debit Account')."</a></th>";
452   $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
453   $column_header{credit_accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Credit Account')."</a></th>";
454   $column_header{debit_tax} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Debit Tax')."</a></th>";
455   $column_header{debit_tax_accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Debit Tax Account')."</a></th>";
456   $column_header{credit_tax} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Credit Tax')."</a></th>";
457   $column_header{credit_tax_accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Credit Tax Account')."</a></th>";
458   $column_header{gifi_accno} = "<th><a class=listheading href=$href&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
459   $column_header{balance} = "<th>".$locale->text('Balance')."</th>";
460   
461   $form->{landscape} = 1;
462   
463   $form->header;
464
465   print qq|
466 <body>
467
468 <table width=100%>
469   <tr>
470     <th class=listtop>$form->{title}</th>
471   </tr>
472   <tr height="5"></tr>
473   <tr>
474     <td>$option</td>
475   </tr>
476   <tr>
477     <td>
478       <table width=100%>
479        <thead>
480         <tr class=listheading>
481 |;
482
483 map { print "$column_header{$_}\n" } @column_index;
484
485 print "
486         </tr>
487         </thead>
488         </tfoot>
489         <tbody>
490 ";
491   
492   # add sort to callback
493   $form->{callback} = "$callback&sort=$form->{sort}";
494   $callback = $form->escape($form->{callback});
495   
496   # initial item for subtotals
497   if (@{ $form->{GL} }) {
498     $sameitem = $form->{GL}->[0]->{$form->{sort}};
499   }
500   
501   if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
502
503     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
504     $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
505     
506     $i++; $i %= 2;
507     print qq|
508         <tr class=listrow$i>
509 |;
510     map { print "$column_data{$_}\n" } @column_index;
511     
512     print qq|
513         </tr>
514 |;
515   }
516     
517   foreach $ref (@{ $form->{GL} }) {
518
519     # if item ne sort print subtotal
520     if ($form->{l_subtotal} eq 'Y') {
521       if ($sameitem ne $ref->{$form->{sort}}) {
522         &gl_subtotal;
523       }
524     }
525     foreach $key (sort keys (%{$ref->{amount}})) {
526       $form->{balance} += $ref->{amount}{$key};
527     }
528     
529     $debit = "";
530     foreach $key (sort keys (%{$ref->{debit}})) {
531       $subtotaldebit += $ref->{debit}{$key};
532       $totaldebit += $ref->{debit}{$key};
533       if ($key == 0) {
534         $debit = $form->format_amount(\%myconfig, $ref->{debit}{$key} , 2, 0);
535       } else {
536         $debit .= "<br>".$form->format_amount(\%myconfig, $ref->{debit}{$key} , 2, 0);
537       }
538     }
539     
540     $credit = "";
541     foreach $key (sort keys (%{$ref->{credit}})) {
542       $subtotalcredit += $ref->{credit}{$key};
543       $totalcredit += $ref->{credit}{$key};
544       if ($key == 0) {
545         $credit = $form->format_amount(\%myconfig, $ref->{credit}{$key} , 2, 0);
546       } else {
547         $credit .= "<br>".$form->format_amount(\%myconfig, $ref->{credit}{$key} , 2, 0);
548       }      
549     }
550     
551     $debittax = "";
552     foreach $key (sort keys (%{$ref->{debit_tax}})) {
553       $subtotaldebittax += $ref->{debit_tax}{$key};
554       $totaldebittax += $ref->{debit_tax}{$key};
555       if ($key == 0) {
556         $debittax = $form->format_amount(\%myconfig, $ref->{debit_tax}{$key} , 2, 0);
557       } else {
558         $debittax .= "<br>".$form->format_amount(\%myconfig, $ref->{debit_tax}{$key} , 2, 0);
559       }
560     }
561     
562     $credittax = "";
563     foreach $key (sort keys (%{$ref->{credit_tax}})) {
564       $subtotalcredittax += $ref->{credit_tax}{$key};
565       $totalcredittax += $ref->{credit_tax}{$key};
566       if ($key == 0) {
567         $credittax = $form->format_amount(\%myconfig, $ref->{credit_tax}{$key} , 2, 0);
568       } else {
569         $credittax .= "<br>".$form->format_amount(\%myconfig, $ref->{credit_tax}{$key} , 2, 0);
570       }
571     }
572     
573     $debitaccno = "";
574     $debittaxkey = "";
575     $taxaccno = "";
576     foreach $key (sort keys (%{$ref->{debit_accno}})) {
577       if ($key == 0) {
578         $debitaccno = "<a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{debit_accno}{$key}</a>";
579       } else {
580         $debitaccno .= "<br><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{debit_accno}{$key}</a>";
581       }
582       if ($ref->{debit_taxkey}{$key} eq $debittaxkey) {
583         $ref->{debit_tax_accno}{$key} = $taxaccno;
584       }      
585       $taxaccno = $ref->{debit_tax_accno}{$key};
586       $debittaxkey = $ref->{debit_taxkey}{$key};
587     }
588     
589     $creditaccno = "";
590     $credittaxkey = "";
591     $taxaccno = "";
592     foreach $key (sort keys (%{$ref->{credit_accno}})) {
593       if ($key == 0) {
594         $creditaccno = "<a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{credit_accno}{$key}</a>";
595       } else {
596         $creditaccno .= "<br><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{credit_accno}{$key}</a>";
597       }
598       if ($ref->{credit_taxkey}{$key} eq $credittaxkey) {
599         $ref->{credit_tax_accno}{$key} = $taxaccno;
600       }
601       $taxaccno = $ref->{credit_tax_accno}{$key};
602       $credittaxkey = $ref->{credit_taxkey}{$key};
603     }    
604     
605     $debittaxaccno = "";
606     foreach $key (sort keys (%{$ref->{debit_tax_accno}})) {
607       if ($key == 0) {
608         $debittaxaccno = "<a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
609       } else {
610         $debittaxaccno .= "<br><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
611       }
612     }
613     
614     $credittaxaccno = "";
615     foreach $key (sort keys (%{$ref->{credit_tax_accno}})) {
616       if ($key == 0) {
617         $credittaxaccno = "<a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
618       } else {
619         $credittaxaccno .= "<br><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
620       }
621     }    
622 #    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
623 #    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
624     
625     $column_data{id} = "<td align=right>&nbsp;$ref->{id}&nbsp;</td>";
626     $column_data{transdate} = "<td align=center>&nbsp;$ref->{transdate}&nbsp;</td>";
627     $column_data{reference} = "<td align=center><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
628     $column_data{description} = "<td align=center>$ref->{description}&nbsp;</td>";
629     $column_data{source} = "<td align=center>$ref->{source}&nbsp;</td>";
630     $column_data{notes} = "<td align=center>$ref->{notes}&nbsp;</td>";
631     $column_data{debit} = "<td align=right>$debit</td>";
632     $column_data{debit_accno} = "<td align=center>$debitaccno</td>";
633     $column_data{credit} = "<td align=right>$credit</td>";
634     $column_data{credit_accno} = "<td align=center>$creditaccno</td>";
635     $column_data{debit_tax} = ($ref->{debit_tax_accno} ne "") ? "<td align=right>$debittax</td>" : "<td></td>";
636     $column_data{debit_tax_accno} = "<td align=center>$debittaxaccno</td>";
637     $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
638     $column_data{credit_tax} = ($ref->{credit_tax_accno} ne "") ? "<td align=right>$credittax</td>" : "<td></td>";
639     $column_data{credit_tax_accno} = "<td align=center>$credittaxaccno</td>";
640     $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
641     $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
642
643     $i++; $i %= 2;
644     print "
645         <tr class=listrow$i>";
646     map { print "$column_data{$_}\n" } @column_index;
647     print "</tr>";
648     
649   }
650
651
652   &gl_subtotal if ($form->{l_subtotal} eq 'Y');
653
654
655   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
656   
657   $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
658   $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
659   $column_data{debit_tax} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebittax, 2, "&nbsp;")."</th>";
660   $column_data{credit_tax} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredittax, 2, "&nbsp;")."</th>";
661   $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
662   
663   print qq|
664         <tr class=listtotal>
665 |;
666
667   map { print "$column_data{$_}\n" } @column_index;
668
669   print qq|
670         </tr>
671         </tbody>
672       </table>
673     </td>
674   </tr>
675   <tr>
676     <td><hr size=3 noshade></td>
677   </tr>
678 </table>
679
680 <br>
681
682 <form method=post action=$form->{script}>
683
684 <input name=callback type=hidden value="$form->{callback}">
685
686 <input type=hidden name=path value=$form->{path}>
687 <input type=hidden name=login value=$form->{login}>
688 <input type=hidden name=password value=$form->{password}>
689
690 <input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|">
691 <input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|">
692 <input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|">
693 <input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|">
694 <input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|">|;
695
696
697   if ($form->{menubar}) {
698     require "$form->{path}/menu.pl";
699     &menubar;
700   }
701
702   print qq|
703
704 </form>
705
706 </body>
707 </html>
708 |;
709
710 }
711
712
713 sub gl_subtotal {
714       
715   $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
716   $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
717   
718   map { $column_data{$_} = "<td>&nbsp;</td>" } qw(transdate id reference source description accno);
719   $column_data{debit} = "<th align=right>$subtotaldebit</td>";
720   $column_data{credit} = "<th align=right>$subtotalcredit</td>";
721
722   
723   print "<tr class=listsubtotal>";
724   map { print "$column_data{$_}\n" } @column_index;
725   print "</tr>";
726
727   $subtotaldebit = 0;
728   $subtotalcredit = 0;
729
730   $sameitem = $ref->{$form->{sort}};
731
732 }
733
734
735 sub update {
736
737   if ($form->{transdate} ne $form->{oldtransdate}) {
738     if ($form->{selectprojectnumber}) {
739       $form->all_projects(\%myconfig, undef, $form->{transdate});
740       if (@{ $form->{all_project} }) {
741         $form->{selectprojectnumber} = "<option>\n";
742         for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
743         $form->{selectprojectnumber} = $form->escape($form->{selectprojectnumber},1);
744       }
745     }
746     $form->{oldtransdate} = $form->{transdate};
747   }
748   
749   my @a = ();
750   my $count = 0;
751   my $debittax = 0;
752   my $credittax = 0;
753   my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
754
755   for my $i (1 .. $form->{rowcount}) {
756
757     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
758       for (qw(debit credit tax)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
759       
760       push @a, {};
761       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
762       $amount = ($form->{"debit_$i"} == 0) ? $form->{"credit_$i"} : $form->{"debit_$i"};
763       $j = $#a;
764       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
765         $form->{"taxchart_$i"} = "0--";
766         $form->{"tax_$i"} = 0;
767       }
768       if (!$form->{"korrektur_$i"}) {
769         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
770         if ($taxkey > 1) {
771           if ($debitcredit) {
772             $debittax = 1;
773           } else {
774             $credittax = 1;
775           }
776           if ($form->{taxincluded}) {
777             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
778           } else {
779             $form->{"tax_$i"} = $amount * $rate;
780           }
781         } else {
782           $form->{"tax_$i"} = 0;
783         }
784       }
785       
786       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
787       $count++;
788     }
789   }
790
791
792   for $i (1 .. $count) {
793     $j = $i - 1;
794     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
795   }
796
797   for $i ($count + 1 .. $form->{rowcount}) {
798     for (@flds) { delete $form->{"${_}_$i"} }
799   }
800
801   $form->{rowcount} = $count + 1;
802
803   &display_form;
804   
805 }
806
807
808 sub display_form {
809   my ($init) = @_;
810
811   &form_header($init);
812 #   for $i (1 .. $form->{rowcount}) {
813 #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
814 #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
815 #  
816 #     &form_row($i);
817 #   }
818   &display_rows($init);
819   &form_footer;
820
821 }
822
823
824 sub display_rows {
825   my ($init) = @_;
826
827   $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}) if $form->{selectprojectnumber};
828   
829   $form->{totaldebit} = 0;
830   $form->{totalcredit} = 0;
831   my $chart= $form->{chart};
832   $chart = $form->unquote($chart);
833   $form->{taxchart} = $form->unquote($form->{taxchart});
834   $taxchart = $form->{taxchart};
835   for $i (1 .. $form->{rowcount}) {
836
837     $source = qq|
838     <td><input name="source_$i" value="$form->{"source_$i"}" tabindex=|.($i+11+(($i-1)*8)).qq|></td>|;
839     $memo = qq|
840     <td><input name="memo_$i" value="$form->{"memo_$i"}" tabindex=|.($i+12+(($i-1)*8)).qq|></td>|;
841
842     if ($init) {
843       $accno = qq|
844       <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:300px" tabindex=|.($i+5+(($i-1)*8)).qq|>$form->{chartinit}</select></td>|;
845       $tax = qq|<td><select id="taxchart_$i" name="taxchart_$i" tabindex=|.($i+10+(($i-1)*8)).qq|>$form->{taxchart}</select></td>|;
846       if ($form->{selectprojectnumber}) {
847         $project = qq|
848     <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
849       }
850       $korrektur = qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|.($i+9+(($i-1)*8)).qq|></td>|;
851       if ($form->{transfer}) {
852         $fx_transaction = qq|
853         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
854     |;
855         }
856
857     } else {
858    
859       $form->{totaldebit} += $form->{"debit_$i"};
860       $form->{totalcredit} += $form->{"credit_$i"};
861
862       for (qw(debit credit tax)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) : "" }
863
864       if ($i < $form->{rowcount}) {
865         
866         $accno = $chart;
867         $chart_selected = $form->{"accno_$i"};
868         $accno  =~ s/value=\"$chart_selected\"/value=\"$chart_selected\" selected/;
869         $accno = qq|<td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:300px" tabindex=|.($i+5+(($i-1)*8)).qq|>$accno</select></td>|;
870         $tax = $taxchart;
871         $tax_selected = $form->{"taxchart_$i"};
872         $tax  =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
873         $tax = qq|<td><select id="taxchart_$i" name="taxchart_$i" tabindex=|.($i+10+(($i-1)*8)).qq|>$tax</select></td>|;
874         if ($form->{selectprojectnumber}) {
875           $form->{"projectnumber_$i"} = "" if $form->{selectprojectnumber} !~ /$form->{"projectnumber_$i"}/;
876           
877           $project = $form->{"projectnumber_$i"};
878           $project =~ s/--.*//;
879           $project = qq|<td>$project</td>|;
880         }
881       
882         if ($form->{transfer}) {
883           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
884           $x = ($checked) ? "x" : "";
885           $fx_transaction = qq|
886       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
887     |;
888         }
889         $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
890         $korrektur = qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked tabindex=|.($i+9+(($i-1)*8)).qq|></td>|;
891         $form->hide_form("accno_$i", "projectnumber_$i");
892         
893       } else {
894         
895         $accno = qq|
896       <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:300px" tabindex=|.($i+5+(($i-1)*8)).qq|>$chart</select></td>|;
897         $tax = qq|
898       <td><select id="taxchart_$i" name="taxchart_$i" tabindex=|.($i+10+(($i-1)*8)).qq|>$taxchart</select></td>|;
899         if ($form->{selectprojectnumber}) {
900           $project = qq|
901       <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
902         }
903         $korrektur = qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|.($i+9+(($i-1)*8)).qq|></td>|;
904         if ($form->{transfer}) {
905           $fx_transaction = qq|
906       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
907     |;
908         }
909       }
910     }
911     
912     print qq|<tr valign=top>
913     $accno
914     $fx_transaction
915     <td><input name="debit_$i" size=10 value="$form->{"debit_$i"}" accesskey=$i tabindex=|.($i+6+(($i-1)*8)).qq|></td>
916     <td><input name="credit_$i" size=10 value="$form->{"credit_$i"}" tabindex=|.($i+7+(($i-1)*8)).qq|></td>
917     <td><input name="tax_$i" size=8 value="$form->{"tax_$i"}" tabindex=|.($i+8+(($i-1)*8)).qq|></td>
918     $korrektur
919     $tax
920     $source
921     $memo
922     $project
923   </tr>
924
925   |;
926   }
927
928   $form->hide_form(qw(rowcount selectaccno));
929   print qq|
930 <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">|;
931
932 }
933
934 sub form_header {
935   my ($init) = @_;
936   $title = $form->{title};
937   $form->{title} = $locale->text("$title General Ledger Transaction");
938   $readonly = ($form->{id}) ? "readonly" : "";
939   
940  
941 # $locale->text('Add General Ledger Transaction')
942 # $locale->text('Edit General Ledger Transaction')
943
944   map { $form->{$_} =~ s/\"/&quot;/g } qw(reference description chart taxchart);
945   $form->{javascript} = qq|<script type="text/javascript">
946   <!--
947   function setTaxkey(accno, row) {
948     var taxkey = accno.options[accno.selectedIndex].value;
949     var reg = /--([0-9])*/;
950     var found = reg.exec(taxkey);
951     var index = found[1];
952     index = parseInt(index);
953     var tax = 'taxchart_' + row;
954     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
955       var reg2 = new RegExp("^"+ index, "");
956       if (reg2.exec(document.getElementById(tax).options[i].value)) {
957         document.getElementById(tax).options[i].selected = true;
958         break;
959       }
960     }
961   };
962   //-->
963   </script>|;
964
965   $form->{selectdepartment} =~ s/ selected//;
966   $form->{selectdepartment} =~ s/option>\Q$form->{department}\E/option selected>$form->{department}/;
967
968   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
969     $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
970   } else {
971     $description = qq|<input name=description size=50 value="$form->{description}" tabindex="3" $readonly>|;
972   }
973   
974   $taxincluded = ($form->{taxincluded}) ? "checked" : "";
975   
976   if ($init) {
977         $taxincluded = "checked";
978   }
979   
980   $amount = qq|<input name=amount size=20 value="$form->{amount}" tabindex="4" $readonly>|;
981   
982   
983   $department = qq|
984         <tr>
985           <th align=right nowrap>|.$locale->text('Department').qq|</th>
986           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
987           <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
988         </tr>
989 | if $form->{selectdepartment};
990   if ($init) {
991     $form->{fokus} = "gl.reference";
992   } else {
993     $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
994   }
995   
996   # use JavaScript Calendar or not
997   $form->{jsscript} = $jscalendar;
998   $jsscript = "";
999   if ($form->{jsscript}) 
1000   {
1001     # with JavaScript Calendar
1002     $button1 = qq|
1003        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate} tabindex="2" $readonly>
1004        <input type=button name=transdate id="trigger1" value=|.$locale->text('button').qq|></td>  
1005        |;
1006    #write Trigger
1007    $jsscript = Form->write_trigger(\%myconfig,"1","transdate","BL","trigger1","","","");
1008    }
1009    else
1010    {
1011       # without JavaScript Calendar
1012       $button1 = qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate} tabindex="2" $readonly></td>|;
1013     }
1014     
1015   $form->header;
1016
1017   
1018   print qq|
1019 <body onLoad="fokus()">
1020
1021 <form method=post name="gl" action=$form->{script}>
1022
1023 <input name=id type=hidden value=$form->{id}>
1024
1025 <input type=hidden name=closedto value=$form->{closedto}>
1026 <input type=hidden name=locked value=$form->{locked}>
1027 <input type=hidden name=title value="$title">
1028 <input type=hidden name=taxchart value="$form->{taxchart}">
1029 <input type=hidden name=chart value="$form->{chart}">
1030
1031
1032 <table width=100%>
1033   <tr>
1034     <th class=listtop>$form->{title}</th>
1035   </tr>
1036   <tr height="5"></tr>
1037   <tr>
1038     <td>
1039       <table width=100%>
1040         <tr>
1041           <th align=right>|.$locale->text('Reference').qq|</th>
1042           <td><input name=reference size=20 value="$form->{reference}" tabindex="1" $readonly></td>
1043           <td align=left>
1044             <table width=100%>
1045               <tr>
1046                 <th align=right nowrap>|.$locale->text('Date').qq|</th>
1047                 $button1
1048               </tr>
1049             </table>
1050           </td>
1051         </tr>|;
1052 if ($form->{id}) {
1053         print qq|
1054         <tr>
1055           <th align=right>|.$locale->text('Belegnummer').qq|</th>
1056           <td><input name=id size=20 value="$form->{id}" $readonly></td>
1057           <td align=left>
1058           <table width=100%>
1059               <tr>
1060                 <th align=right width=50%>|.$locale->text('Buchungsdatum').qq|</th>
1061                 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly></td>
1062               </tr>
1063             </table>
1064           </td>
1065         </tr>|;
1066         }
1067         print qq|       
1068         $department|;
1069 if ($form->{id}) {
1070         print qq|
1071         <tr>
1072           <th align=right>|.$locale->text('Description').qq|</th>
1073           <td>$description</td>
1074           <td align=left>
1075             <table width=100%>
1076               <tr>
1077                 <th align=right width=50%>|.$locale->text('Mitarbeiter').qq|</th>
1078                 <td align=left><input name=employee size=11  value=$form->{employee} $readonly></td>
1079               </tr>
1080             </table>
1081           </td>
1082         </tr>|; 
1083         } else {
1084         print qq|
1085         <tr>
1086           <th align=right>|.$locale->text('Description').qq|</th>
1087           <td colspan=2>$description</td>
1088         </tr>|;
1089         }
1090         print qq|
1091         <tr>
1092           <th align=right>|.$locale->text('Betrag').qq|</th>
1093           <td>$amount</td>
1094           <td align=left>
1095             <table>
1096               <tr>
1097                 <th align=left>|.$locale->text('MwSt. inkl.').qq|</th>
1098                 <td><input type=checkbox name=taxincluded value=1 tabindex="5" $taxincluded></td>
1099               </tr>
1100             </table>
1101          </td>
1102       </tr>
1103       <tr>
1104           <table width=100%>
1105            <tr class=listheading>
1106           <th class=listheading style="width:15%">|.$locale->text('Account').qq|</th>
1107           <th class=listheading style="width:10%">|.$locale->text('Debit').qq|</th>
1108           <th class=listheading style="width:10%">|.$locale->text('Credit').qq|</th>
1109           <th class=listheading style="width:10%">|.$locale->text('Tax').qq|</th>
1110           <th class=listheading style="width:5%">|.$locale->text('Korrektur').qq|</th>
1111           <th class=listheading style="width:10%">|.$locale->text('Taxkey').qq|</th>
1112           <th class=listheading style="width:20%">|.$locale->text('Source').qq|</th>
1113           <th class=listheading style="width:20%">|.$locale->text('Memo').qq|</th>
1114           $project
1115         </tr>
1116
1117 $jsscript
1118 |;
1119
1120 }
1121
1122
1123 sub form_footer {
1124   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1125   $dec = length $dec;
1126   $decimalplaces = ($dec > 2) ? $dec : 2;
1127   $radieren = ($form->current_date(\%myconfig) eq $form->{gldate})? 1 : 0;
1128
1129   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, "&nbsp;") } qw(totaldebit totalcredit);
1130   
1131   print qq|
1132   </table>
1133 </table>
1134
1135 <input type=hidden name=path value=$form->{path}>
1136 <input type=hidden name=login value=$form->{login}>
1137 <input type=hidden name=password value=$form->{password}>
1138
1139 <input name=callback type=hidden value="$form->{callback}">
1140
1141 <br>
1142 |;
1143
1144   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1145   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1146
1147   if ($form->{id}) {
1148   
1149   print qq|<input class=submit type=submit name=action value="|.$locale->text('Storno').qq|">|;
1150
1151 # Löschen und ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1152
1153  
1154
1155         if (!$form->{locked} && $radieren) {
1156                 print qq|
1157                 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|" accesskey="b">
1158                 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|;
1159         }
1160
1161         
1162 #       if ($transdate > $closedto) {
1163 #               print qq|
1164 #               <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">|;
1165 #       }
1166    }  else {
1167         if ($transdate > $closedto) {
1168                 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
1169                  <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
1170         }
1171    }
1172
1173   if ($form->{menubar}) {
1174     require "$form->{path}/menu.pl";
1175     &menubar;
1176   }
1177   
1178   print "
1179   </form>
1180
1181 </body>
1182 </html>
1183 ";
1184   
1185 }
1186
1187
1188 sub delete {
1189
1190   $form->header;
1191
1192   print qq|
1193 <body>
1194
1195 <form method=post action=$form->{script}>
1196 |;
1197
1198   map { $form->{$_} =~ s/\"/&quot;/g } qw(reference description chart);
1199
1200   delete $form->{header};
1201
1202   foreach $key (keys %$form) {
1203     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1204   }
1205
1206   print qq|
1207 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
1208
1209 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
1210
1211 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
1212 </form>
1213 |;
1214
1215 }
1216
1217
1218 sub yes {
1219
1220   $form->redirect($locale->text('Transaction deleted!')) if (GL->delete_transaction(\%myconfig, \%$form));
1221   $form->error($locale->text('Cannot delete transaction!'));
1222   
1223 }
1224
1225
1226 sub post {
1227   # check if there is something in reference and date
1228   $form->isblank("reference", $locale->text('Reference missing!'));
1229   $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1230   $form->isblank("description", $locale->text('Description missing!'));
1231   
1232   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1233   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1234
1235
1236   # check project
1237   &check_project;
1238
1239   my @a = ();
1240   my $count = 0;
1241   my $debittax = 0;
1242   my $credittax = 0;
1243   my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1244
1245   for my $i (1 .. $form->{rowcount}) {
1246
1247     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
1248       for (qw(debit credit tax)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
1249       
1250       push @a, {};
1251       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1252       $amount = ($form->{"debit_$i"} == 0) ? $form->{"credit_$i"} : $form->{"debit_$i"};
1253       $j = $#a;
1254       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1255         $form->{"taxchart_$i"} = "0--";
1256         $form->{"tax_$i"} = 0;
1257       }
1258       if (!$form->{"korrektur_$i"}) {
1259         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1260         if ($taxkey > 1) {
1261           if ($debitcredit) {
1262             $debittax = 1;
1263           } else {
1264             $credittax = 1;
1265           }
1266           if ($form->{taxincluded}) {
1267             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1268           } else {
1269             $form->{"tax_$i"} = $amount * $rate;
1270           }
1271         } else {
1272           $form->{"tax_$i"} = 0;
1273         }
1274       }
1275       
1276       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1277       $count++;
1278     }
1279   }
1280
1281
1282   for $i (1 .. $count) {
1283     $j = $i - 1;
1284     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1285   }
1286
1287   for $i ($count + 1 .. $form->{rowcount}) {
1288     for (@flds) { delete $form->{"${_}_$i"} }
1289   }
1290
1291   for $i (1 .. $form->{rowcount}) {
1292     $dr = $form->{"debit_$i"};
1293     $cr = $form->{"credit_$i"};
1294     $tax = $form->{"tax_$i"};
1295     if ($dr && $cr) {
1296       $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1297     }
1298     if ($form->{taxincluded}) {
1299       $debit += $dr;
1300       $credit += $cr;
1301       $taxtotal += $tax;
1302     } else {
1303       if ($dr) {
1304         $debit += $dr + $tax;
1305       }
1306       if ($cr) {
1307         $credit += $cr + $tax;
1308       }
1309   }
1310   }
1311   if (!$taxtotal) {
1312       $form->{taxincluded} = 0;
1313   }
1314
1315   # this is just for the wise guys
1316   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
1317   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1318     $form->error($locale->text('Out of balance transaction!'));
1319   }
1320   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1321     $errno *= -1;
1322     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1323     $err[2] = $locale->text('Debit and credit out of balance!');
1324     $err[3] = $locale->text('Cannot post a transaction without a value!');
1325     
1326     $form->error($err[$errno]);
1327   }
1328   undef($form->{callback});
1329   $form->redirect("Buchung gespeichert. Buchungsnummer = ".$form->{id});
1330   
1331 }
1332
1333
1334 sub post_as_new {
1335
1336   $form->{id} = 0;
1337   &add;
1338
1339 }
1340
1341 sub storno {
1342
1343   $form->{id} = 0;
1344   $form->{storno} =1;
1345   &post;
1346
1347 }
1348
1349