Dialogbuchen um WebDAV-Funktion erweitert
[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., 51 Franklin Street, Fifth Floor, Boston,
28 # MA 02110-1335, USA.
29 #======================================================================
30 #
31 # Genereal Ledger
32 #
33 #======================================================================
34
35 use utf8;
36 use strict;
37
38 use POSIX qw(strftime);
39 use List::Util qw(sum);
40
41 use SL::FU;
42 use SL::GL;
43 use SL::IS;
44 use SL::ReportGenerator;
45 use SL::DBUtils qw(selectrow_query selectall_hashref_query);
46 use SL::Webdav;
47 use SL::Locale::String qw(t8);
48
49 require "bin/mozilla/common.pl";
50 require "bin/mozilla/reportgenerator.pl";
51
52 # this is for our long dates
53 # $locale->text('January')
54 # $locale->text('February')
55 # $locale->text('March')
56 # $locale->text('April')
57 # $locale->text('May ')
58 # $locale->text('June')
59 # $locale->text('July')
60 # $locale->text('August')
61 # $locale->text('September')
62 # $locale->text('October')
63 # $locale->text('November')
64 # $locale->text('December')
65
66 # this is for our short month
67 # $locale->text('Jan')
68 # $locale->text('Feb')
69 # $locale->text('Mar')
70 # $locale->text('Apr')
71 # $locale->text('May')
72 # $locale->text('Jun')
73 # $locale->text('Jul')
74 # $locale->text('Aug')
75 # $locale->text('Sep')
76 # $locale->text('Oct')
77 # $locale->text('Nov')
78 # $locale->text('Dec')
79
80 sub add {
81   $main::lxdebug->enter_sub();
82
83   $main::auth->assert('gl_transactions');
84
85   my $form     = $main::form;
86   my %myconfig = %main::myconfig;
87
88   $form->{title} = "Add";
89
90   $form->{callback} = "gl.pl?action=add" unless $form->{callback};
91
92   # we use this only to set a default date
93   # yep. aber er holt hier auch schon ALL_CHARTS. Aufwand / Nutzen? jb
94   GL->transaction(\%myconfig, \%$form);
95
96   $form->{rowcount}  = 2;
97
98   $form->{debit}  = 0;
99   $form->{credit} = 0;
100   $form->{tax}    = 0;
101
102   # departments
103   $form->all_departments(\%myconfig);
104   if (@{ $form->{all_departments} || [] }) {
105     $form->{selectdepartment} = "<option>\n";
106
107     map {
108       $form->{selectdepartment} .=
109         "<option>$_->{description}--$_->{id}\n"
110     } (@{ $form->{all_departments} || [] });
111   }
112
113   $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
114
115   &display_form(1);
116   $main::lxdebug->leave_sub();
117
118 }
119
120 sub prepare_transaction {
121   $main::lxdebug->enter_sub();
122
123   $main::auth->assert('gl_transactions');
124
125   my $form     = $main::form;
126   my %myconfig = %main::myconfig;
127
128   GL->transaction(\%myconfig, \%$form);
129
130   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
131
132   # departments
133   $form->all_departments(\%myconfig);
134   if (@{ $form->{all_departments} || [] }) {
135     $form->{selectdepartment} = "<option>\n";
136
137     map {
138       $form->{selectdepartment} .=
139         "<option>$_->{description}--$_->{id}\n"
140     } (@{ $form->{all_departments} || [] });
141   }
142
143   my $i        = 1;
144   my $tax      = 0;
145   my $taxaccno = "";
146   foreach my $ref (@{ $form->{GL} }) {
147     my $j = $i - 1;
148     if ($tax && ($ref->{accno} eq $taxaccno)) {
149       $form->{"tax_$j"}      = abs($ref->{amount});
150       $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
151       if ($form->{taxincluded}) {
152         if ($ref->{amount} < 0) {
153           $form->{"debit_$j"} += $form->{"tax_$j"};
154         } else {
155           $form->{"credit_$j"} += $form->{"tax_$j"};
156         }
157       }
158       $form->{"project_id_$j"} = $ref->{project_id};
159
160     } else {
161       $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
162       for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
163       if ($ref->{amount} < 0) {
164         $form->{totaldebit} -= $ref->{amount};
165         $form->{"debit_$i"} = $ref->{amount} * -1;
166       } else {
167         $form->{totalcredit} += $ref->{amount};
168         $form->{"credit_$i"} = $ref->{amount};
169       }
170       $form->{"taxchart_$i"} = $ref->{id}."--0.00000";
171       $form->{"project_id_$i"} = $ref->{project_id};
172       $i++;
173     }
174     if ($ref->{taxaccno} && !$tax) {
175       $taxaccno = $ref->{taxaccno};
176       $tax      = 1;
177     } else {
178       $taxaccno = "";
179       $tax      = 0;
180     }
181   }
182
183   $form->{rowcount} = $i;
184   $form->{locked}   =
185     ($form->datetonum($form->{transdate}, \%myconfig) <=
186      $form->datetonum($form->{closedto}, \%myconfig));
187
188   $main::lxdebug->leave_sub();
189 }
190
191 sub edit {
192   $main::lxdebug->enter_sub();
193
194   $main::auth->assert('gl_transactions');
195
196   my $form     = $main::form;
197   my %myconfig = %main::myconfig;
198
199   prepare_transaction();
200
201   $form->{title} = "Edit";
202
203   $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
204
205   if ($form->{reference} && $::instance_conf->get_webdav) {
206     my $webdav = SL::Webdav->new(
207       type     => 'general_ledger',
208       number   => $form->{reference},
209     );
210     my $webdav_path = $webdav->webdav_path;
211     my @all_objects = $webdav->get_all_objects;
212     @{ $form->{WEBDAV} } = map { { name => $_->filename,
213                                    type => t8('File'),
214                                    link => File::Spec->catdir($webdav_path, $_->filename),
215                                } } @all_objects;
216   }
217   form_header();
218   display_rows();
219   form_footer();
220
221   $main::lxdebug->leave_sub();
222 }
223
224
225 sub search {
226   $::lxdebug->enter_sub;
227   $::auth->assert('general_ledger | gl_transactions');
228
229   $::form->all_departments(\%::myconfig);
230   $::form->get_lists(
231     projects  => { key => "ALL_PROJECTS", all => 1 },
232   );
233   $::form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
234
235   $::form->header;
236   print $::form->parse_html_template('gl/search', {
237     department_label => sub { ("$_[0]{description}--$_[0]{id}")x2 },
238     employee_label => sub { "$_[0]{id}--$_[0]{name}" },
239   });
240
241   $::lxdebug->leave_sub;
242 }
243
244 sub create_subtotal_row {
245   $main::lxdebug->enter_sub();
246
247   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
248
249   my $form     = $main::form;
250   my %myconfig = %main::myconfig;
251
252   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
253
254   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
255
256   map { $totals->{$_} = 0 } @{ $subtotal_columns };
257
258   $main::lxdebug->leave_sub();
259
260   return $row;
261 }
262
263 sub generate_report {
264   $main::lxdebug->enter_sub();
265
266   $main::auth->assert('general_ledger | gl_transactions');
267
268   my $form     = $main::form;
269   my %myconfig = %main::myconfig;
270   my $locale   = $main::locale;
271
272   # generate_report wird beim ersten Aufruf per Weiter-Knopf und POST mit der hidden Variablen sort mit Wert "datesort" (früher "transdate" als Defaultsortiervariable) Ã¼bertragen
273
274   # <form method=post action=gl.pl>
275   # <input type=hidden name=sort value=datesort>    # form->{sort} setzen
276   # <input type=hidden name=nextsub value=generate_report>
277
278   # anhand von neuer Variable datesort wird jetzt $form->{sort} auf transdate oder gldate gesetzt
279   # damit ist die Hidden Variable "sort" wahrscheinlich sogar Ã¼berflüssig
280
281   # Ã¤ndert man die Sortierreihenfolge per Klick auf eine der Ãœberschriften wird die Variable "sort" per GET Ã¼bergeben, z.B. id,transdate, gldate, ...
282   # gl.pl?action=generate_report&employee=18383--Jan%20B%c3%bcren&datesort=transdate&category=X&l_transdate=Y&l_gldate=Y&l_id=Y&l_reference=Y&l_description=Y&l_source=Y&l_debit=Y&l_credit=Y&sort=gldate&sortdir=0
283
284   if ( $form->{sort} eq 'datesort' ) {   # sollte bei einem Post (Aufruf aus Suchmaske) immer wahr sein
285       # je nachdem ob in Suchmaske "transdate" oder "gldate" ausgesucht wurde erstes Suchergebnis entsprechend sortieren
286       $form->{sort} = $form->{datesort};
287   };
288
289   # was passiert hier?
290   report_generator_set_default_sort("$form->{datesort}", 1);
291 #  report_generator_set_default_sort('transdate', 1);
292
293   GL->all_transactions(\%myconfig, \%$form);
294
295   my %acctype = ('A' => $locale->text('Asset'),
296                  'C' => $locale->text('Contra'),
297                  'L' => $locale->text('Liability'),
298                  'Q' => $locale->text('Equity'),
299                  'I' => $locale->text('Revenue'),
300                  'E' => $locale->text('Expense'),);
301
302   $form->{title} = $locale->text('Journal');
303   if ($form->{category} ne 'X') {
304     $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
305   }
306
307   $form->{landscape} = 1;
308
309   my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
310
311   my @columns = qw(
312     gldate         transdate        id             reference      description
313     notes          source           debit          debit_accno
314     credit         credit_accno     debit_tax      debit_tax_accno
315     credit_tax     credit_tax_accno projectnumbers balance employee
316   );
317
318   # add employee here, so that variable is still known and passed in url when choosing a different sort order in resulting table
319   my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto employee_id datesort category l_subtotal);
320   push @hidden_variables, map { "l_${_}" } @columns;
321
322   my $employee = $form->{employee_id} ? SL::DB::Employee->new(id => $form->{employee_id})->load->name : '';
323
324   my (@options, @date_options);
325   push @options,      $locale->text('Account')     . " : $form->{accno} $form->{account_description}" if ($form->{accno});
326   push @options,      $locale->text('Source')      . " : $form->{source}"                             if ($form->{source});
327   push @options,      $locale->text('Reference')   . " : $form->{reference}"                          if ($form->{reference});
328   push @options,      $locale->text('Description') . " : $form->{description}"                        if ($form->{description});
329   push @options,      $locale->text('Notes')       . " : $form->{notes}"                              if ($form->{notes});
330   push @options,      $locale->text('Employee')    . " : $employee"                                   if $employee;
331   my $datesorttext = $form->{datesort} eq 'transdate' ? $locale->text('Invoice Date') :  $locale->text('Booking Date');
332   push @date_options,      "$datesorttext"                              if ($form->{datesort} and ($form->{datefrom} or $form->{dateto}));
333   push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1)          if ($form->{datefrom});
334   push @date_options, $locale->text('Bis'),  $locale->date(\%myconfig, $form->{dateto},   1)          if ($form->{dateto});
335   push @options,      join(' ', @date_options)                                                        if (scalar @date_options);
336
337   if ($form->{department}) {
338     my ($department) = split /--/, $form->{department};
339     push @options, $locale->text('Department') . " : $department";
340   }
341
342
343   my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
344
345   $form->{l_credit_accno}     = 'Y';
346   $form->{l_debit_accno}      = 'Y';
347   $form->{l_credit_tax}       = 'Y';
348   $form->{l_debit_tax}        = 'Y';
349 #  $form->{l_gldate}           = 'Y';  # Spalte mit gldate immer anzeigen
350   $form->{l_credit_tax_accno} = 'Y';
351   $form->{l_datesort} = 'Y';
352   $form->{l_debit_tax_accno}  = 'Y';
353   $form->{l_balance}          = $form->{accno} ? 'Y' : '';
354
355   my %column_defs = (
356     'id'               => { 'text' => $locale->text('ID'), },
357     'transdate'        => { 'text' => $locale->text('Invoice Date'), },
358     'gldate'           => { 'text' => $locale->text('Booking Date'), },
359     'reference'        => { 'text' => $locale->text('Reference'), },
360     'source'           => { 'text' => $locale->text('Source'), },
361     'description'      => { 'text' => $locale->text('Description'), },
362     'notes'            => { 'text' => $locale->text('Notes'), },
363     'debit'            => { 'text' => $locale->text('Debit'), },
364     'debit_accno'      => { 'text' => $locale->text('Debit Account'), },
365     'credit'           => { 'text' => $locale->text('Credit'), },
366     'credit_accno'     => { 'text' => $locale->text('Credit Account'), },
367     'debit_tax'        => { 'text' => $locale->text('Debit Tax'), },
368     'debit_tax_accno'  => { 'text' => $locale->text('Debit Tax Account'), },
369     'credit_tax'       => { 'text' => $locale->text('Credit Tax'), },
370     'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
371     'balance'          => { 'text' => $locale->text('Balance'), },
372     'projectnumbers'   => { 'text' => $locale->text('Project Numbers'), },
373     'employee'         => { 'text' => $locale->text('Employee'), },
374   );
375
376   foreach my $name (qw(id transdate gldate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
377     my $sortname                = $name =~ m/accno/ ? 'accno' : $name;
378     my $sortdir                 = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
379     $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
380   }
381
382   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
383   map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
384
385   my %column_alignment;
386   map { $column_alignment{$_}     = 'right'  } qw(balance id debit credit debit_tax credit_tax balance);
387   map { $column_alignment{$_}     = 'center' } qw(transdate gldate reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
388   map { $column_alignment{$_}     = 'left' } qw(description source notes);
389   map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
390
391   my $report = SL::ReportGenerator->new(\%myconfig, $form);
392
393   $report->set_columns(%column_defs);
394   $report->set_column_order(@columns);
395
396   $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
397
398   $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
399
400   $report->set_options('top_info_text'        => join("\n", @options),
401                        'output_format'        => 'HTML',
402                        'title'                => $form->{title},
403                        'attachment_basename'  => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
404     );
405   $report->set_options_from_form();
406   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
407
408   # add sort to callback
409   $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
410
411
412   my @totals_columns = qw(debit credit debit_tax credit_tax);
413   my %subtotals      = map { $_ => 0 } @totals_columns;
414   my %totals         = map { $_ => 0 } @totals_columns;
415   my $idx            = 0;
416
417   foreach my $ref (@{ $form->{GL} }) {
418
419     my %rows;
420
421     foreach my $key (qw(debit credit debit_tax credit_tax)) {
422       $rows{$key} = [];
423       foreach my $idx (sort keys(%{ $ref->{$key} })) {
424         my $value         = $ref->{$key}->{$idx};
425         $subtotals{$key} += $value;
426         $totals{$key}    += $value;
427         if ($key =~ /debit.*/) {
428           $ml = -1;
429         } else {
430           $ml = 1;
431         }
432         $form->{balance}  = $form->{balance} + $value * $ml;
433         push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
434       }
435     }
436
437     foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
438       my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
439       $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
440     }
441
442     my $row = { };
443     map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
444
445     my $sh = "";
446     if ($form->{balance} < 0) {
447       $sh = " S";
448       $ml = -1;
449     } elsif ($form->{balance} > 0) {
450       $sh = " H";
451       $ml = 1;
452     }
453     my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
454     $data .= $sh;
455
456     $row->{balance}->{data}        = $data;
457     $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
458
459     map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes gldate employee);
460
461     map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
462
463     foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
464       $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
465     }
466
467     map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
468
469     $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
470
471     my $row_set = [ $row ];
472
473     if ( ($form->{l_subtotal} eq 'Y' && !$form->{report_generator_csv_options_for_import} )
474         && (($idx == (scalar @{ $form->{GL} } - 1))
475             || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
476       push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
477     }
478
479     $report->add_data($row_set);
480
481     $idx++;
482   }
483
484   # = 0 for balanced ledger
485   my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
486
487   my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
488
489   my $sh = "";
490   if ($form->{balance} < 0) {
491     $sh = " S";
492     $ml = -1;
493   } elsif ($form->{balance} > 0) {
494     $sh = " H";
495     $ml = 1;
496   }
497   my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
498   $data .= $sh;
499
500   $row->{balance}->{data}        = $data;
501
502   if ( !$form->{report_generator_csv_options_for_import} ) {
503     $report->add_separator();
504     $report->add_data($row);
505   }
506
507   my $raw_bottom_info_text;
508
509   if (!$form->{accno} && (abs($balanced_ledger) >  0.001)) {
510     $raw_bottom_info_text .=
511         '<p><span class="unbalanced_ledger">'
512       . $locale->text('Unbalanced Ledger')
513       . ': '
514       . $form->format_amount(\%myconfig, $balanced_ledger, 3)
515       . '</span></p> ';
516   }
517
518   $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
519
520   $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
521
522   $report->generate_with_headers();
523
524   $main::lxdebug->leave_sub();
525 }
526
527 sub show_draft {
528   $::form->{transdate} = DateTime->today_local->to_kivitendo if !$::form->{transdate};
529   $::form->{gldate}    = $::form->{transdate} if !$::form->{gldate};
530   update();
531 }
532
533 sub update {
534   $main::lxdebug->enter_sub();
535
536   $main::auth->assert('gl_transactions');
537
538   my $form     = $main::form;
539   my %myconfig = %main::myconfig;
540
541   $form->{oldtransdate} = $form->{transdate};
542
543   my @a           = ();
544   my $count       = 0;
545   my $debittax    = 0;
546   my $credittax   = 0;
547   my $debitcount  = 0;
548   my $creditcount = 0;
549   my ($debitcredit, $amount);
550
551   my $dbh = SL::DB->client->dbh;
552   my ($notax_id) = selectrow_query($form, $dbh, "SELECT id FROM tax WHERE taxkey = 0 LIMIT 1", );
553   my $zerotaxes  = selectall_hashref_query($form, $dbh, "SELECT id FROM tax WHERE rate = 0", );
554
555   my @flds =
556     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
557
558   for my $i (1 .. $form->{rowcount}) {
559
560     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
561       for (qw(debit credit tax)) {
562         $form->{"${_}_$i"} =
563           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
564       }
565
566       push @a, {};
567       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
568       if ($debitcredit) {
569         $debitcount++;
570       } else {
571         $creditcount++;
572       }
573
574       if (($debitcount >= 2) && ($creditcount == 2)) {
575         $form->{"credit_$i"} = 0;
576         $form->{"tax_$i"}    = 0;
577         $creditcount--;
578         $form->{creditlock} = 1;
579       }
580       if (($creditcount >= 2) && ($debitcount == 2)) {
581         $form->{"debit_$i"} = 0;
582         $form->{"tax_$i"}   = 0;
583         $debitcount--;
584         $form->{debitlock} = 1;
585       }
586       if (($creditcount == 1) && ($debitcount == 2)) {
587         $form->{creditlock} = 1;
588       }
589       if (($creditcount == 2) && ($debitcount == 1)) {
590         $form->{debitlock} = 1;
591       }
592       if ($debitcredit && $credittax) {
593         $form->{"taxchart_$i"} = "$notax_id--0.00";
594       }
595       if (!$debitcredit && $debittax) {
596         $form->{"taxchart_$i"} = "$notax_id--0.00";
597       }
598       $amount =
599         ($form->{"debit_$i"} == 0)
600         ? $form->{"credit_$i"}
601         : $form->{"debit_$i"};
602       my $j = $#a;
603       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
604         $form->{"taxchart_$i"} = "$notax_id--0.00";
605         $form->{"tax_$i"}      = 0;
606       }
607       my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
608       my $iswithouttax = grep { $_->{id} == $taxkey } @{ $zerotaxes };
609       if (!$iswithouttax) {
610         if ($debitcredit) {
611           $debittax = 1;
612         } else {
613           $credittax = 1;
614         }
615       };
616       my ($tmpnetamount,$tmpdiff);
617       ($tmpnetamount,$form->{"tax_$i"},$tmpdiff) = $form->calculate_tax($amount,$rate,$form->{taxincluded} *= 1,2);
618
619       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
620       $count++;
621     }
622   }
623
624   for my $i (1 .. $count) {
625     my $j = $i - 1;
626     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
627   }
628
629   for my $i ($count + 1 .. $form->{rowcount}) {
630     for (@flds) { delete $form->{"${_}_$i"} }
631   }
632
633   $form->{rowcount} = $count + 1;
634
635   &display_form;
636   $main::lxdebug->leave_sub();
637
638 }
639
640 sub display_form {
641   my ($init) = @_;
642   $main::lxdebug->enter_sub();
643
644   $main::auth->assert('gl_transactions');
645
646   my $form     = $main::form;
647   my %myconfig = %main::myconfig;
648
649   &form_header($init);
650
651   #   for $i (1 .. $form->{rowcount}) {
652   #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
653   #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
654   #
655   #     &form_row($i);
656   #   }
657   &display_rows($init);
658   &form_footer;
659   $main::lxdebug->leave_sub();
660
661 }
662
663 sub display_rows {
664   my ($init) = @_;
665   $main::lxdebug->enter_sub();
666
667   $main::auth->assert('gl_transactions');
668
669   my $form     = $main::form;
670   my %myconfig = %main::myconfig;
671   my $cgi      = $::request->{cgi};
672
673   $form->{debit_1}     = 0 if !$form->{"debit_1"};
674   $form->{totaldebit}  = 0;
675   $form->{totalcredit} = 0;
676
677   my %project_labels = ();
678   my @project_values = ("");
679   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
680     push(@project_values, $item->{"id"});
681     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
682   }
683
684   my %chart_labels = ();
685   my @chart_values = ();
686   my %charts = ();
687   my $taxchart_init;
688   foreach my $item (@{ $form->{ALL_CHARTS} }) {
689     if ($item->{charttype} eq 'H'){ #falls ÃƒÅ’berschrift
690       next;                         #ÃŒberspringen (Bug 1150)
691     }
692     my $key = $item->{accno} . "--" . $item->{tax_id};
693     $taxchart_init = $item->{tax_id} unless (@chart_values);
694     push(@chart_values, $key);
695     $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
696     $charts{$item->{accno}} = $item;
697   }
698
699   my ($source, $memo, $source_hidden, $memo_hidden);
700   for my $i (1 .. $form->{rowcount}) {
701     if ($form->{show_details}) {
702       $source = qq|
703       <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
704       $memo = qq|
705       <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
706     } else {
707       $source_hidden = qq|
708       <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
709       $memo_hidden = qq|
710       <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
711     }
712
713     my $selected_accno_full;
714     my ($accno_row) = split(/--/, $form->{"accno_$i"});
715     my $item = $charts{$accno_row};
716     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
717
718     my $selected_taxchart = $form->{"taxchart_$i"};
719     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
720     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
721
722     my %taxchart_labels = ();
723     my @taxchart_values = ();
724     my %taxcharts = ();
725     my $filter_accno;
726     $filter_accno = $::form->{ALL_CHARTS}[0]->{accno};
727     $filter_accno = $selected_accno if (!$init and $i < $form->{rowcount});
728     foreach my $item ( GL->get_tax_dropdown($filter_accno) ) {
729       my $key = $item->{id} . "--" . $item->{rate};
730       $taxchart_init = $key if ($taxchart_init == $item->{id});
731       push(@taxchart_values, $key);
732       $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
733       $taxcharts{$item->{id}} = $item;
734     }
735
736     if ($previous_accno &&
737         ($previous_accno eq $selected_accno) &&
738         ($previous_tax_id ne $selected_tax_id)) {
739       my $item = $taxcharts{$selected_tax_id};
740       $selected_taxchart = "$item->{id}--$item->{rate}";
741     }
742
743     $selected_accno      = '' if ($init);
744     $selected_taxchart ||= $taxchart_init;
745
746     my $accno = qq|<td>| .
747       NTI($cgi->popup_menu('-name' => "accno_$i",
748                            '-id' => "accno_$i",
749                            '-onChange' => "updateTaxes($i);",
750                            '-style' => 'width:200px',
751                            '-values' => \@chart_values,
752                            '-labels' => \%chart_labels,
753                            '-default' => $selected_accno_full))
754       . $cgi->hidden('-name' => "previous_accno_$i",
755                      '-default' => $selected_accno_full)
756       . qq|</td>|;
757     my $tax_ddbox = qq|<td>| .
758       NTI($cgi->popup_menu('-name' => "taxchart_$i",
759             '-id' => "taxchart_$i",
760             '-style' => 'width:200px',
761             '-values' => \@taxchart_values,
762             '-labels' => \%taxchart_labels,
763             '-default' => $selected_taxchart))
764       . qq|</td>|;
765
766     my ($fx_transaction, $checked);
767     if ($init) {
768       if ($form->{transfer}) {
769         $fx_transaction = qq|
770         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
771     |;
772       }
773
774     } else {
775       if ($form->{"debit_$i"} != 0) {
776         $form->{totaldebit} += $form->{"debit_$i"};
777         if (!$form->{taxincluded}) {
778           $form->{totaldebit} += $form->{"tax_$i"};
779         }
780       } else {
781         $form->{totalcredit} += $form->{"credit_$i"};
782         if (!$form->{taxincluded}) {
783           $form->{totalcredit} += $form->{"tax_$i"};
784         }
785       }
786
787       for (qw(debit credit tax)) {
788         $form->{"${_}_$i"} =
789           ($form->{"${_}_$i"})
790           ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
791           : "";
792       }
793
794       if ($i < $form->{rowcount}) {
795         if ($form->{transfer}) {
796           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
797           my $x = ($checked) ? "x" : "";
798           $fx_transaction = qq|
799       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
800     |;
801         }
802         $form->hide_form("accno_$i");
803
804       } else {
805         if ($form->{transfer}) {
806           $fx_transaction = qq|
807       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
808     |;
809         }
810       }
811     }
812     my $debitreadonly  = "";
813     my $creditreadonly = "";
814     if ($i == $form->{rowcount}) {
815       if ($form->{debitlock}) {
816         $debitreadonly = "readonly";
817       } elsif ($form->{creditlock}) {
818         $creditreadonly = "readonly";
819       }
820     }
821
822     my $projectnumber =
823       NTI($cgi->popup_menu('-name' => "project_id_$i",
824                            '-values' => \@project_values,
825                            '-labels' => \%project_labels,
826                            '-default' => $form->{"project_id_$i"} ));
827     my $projectnumber_hidden = qq|
828     <input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|;
829
830     my $copy2credit = $i == 1 ? 'onkeyup="copy_debit_to_credit()"' : '';
831
832     print qq|<tr valign=top>
833     $accno
834     <td id="chart_balance_$i" align="right">&nbsp;</td>
835     $fx_transaction
836     <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
837     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
838     <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
839     $tax_ddbox|;
840
841     if ($form->{show_details}) {
842       print qq|
843     $source
844     $memo
845     <td>$projectnumber</td>
846 |;
847     } else {
848     print qq|
849     $source_hidden
850     $memo_hidden
851     $projectnumber_hidden
852     |;
853     }
854     print qq|
855   </tr>
856 |;
857   }
858
859   $form->hide_form(qw(rowcount selectaccno));
860
861   $main::lxdebug->leave_sub();
862
863 }
864
865 sub _get_radieren {
866   return ($::instance_conf->get_gl_changeable == 2) ? ($::form->current_date(\%::myconfig) eq $::form->{gldate}) : ($::instance_conf->get_gl_changeable == 1);
867 }
868
869 sub form_header {
870   $::lxdebug->enter_sub;
871   $::auth->assert('gl_transactions');
872
873   my ($init) = @_;
874
875   my @old_project_ids = grep { $_ } map{ $::form->{"project_id_$_"} } 1..$::form->{rowcount};
876
877   $::form->get_lists("projects"  => { "key"       => "ALL_PROJECTS",
878                                     "all"       => 0,
879                                     "old_id"    => \@old_project_ids },
880                    "charts"    => { "key"       => "ALL_CHARTS",
881                                     "transdate" => $::form->{transdate} });
882
883   GL->get_chart_balances('charts' => $::form->{ALL_CHARTS});
884
885   my $title      = $::form->{title};
886   $::form->{title} = $::locale->text("$title General Ledger Transaction");
887   # $locale->text('Add General Ledger Transaction')
888   # $locale->text('Edit General Ledger Transaction')
889
890   map { $::form->{$_} =~ s/\"/&quot;/g }
891     qw(chart taxchart);
892
893   $::form->{selectdepartment} =~ s/ selected//;
894   $::form->{selectdepartment} =~
895     s/option>\Q$::form->{department}\E/option selected>$::form->{department}/;
896
897   if ($init) {
898     $::request->{layout}->focus("#reference");
899     $::form->{taxincluded} = "1";
900   } else {
901     $::request->{layout}->focus("#accno_$::form->{rowcount}");
902   }
903
904   $::form->{previous_id}     ||= "--";
905   $::form->{previous_gldate} ||= "--";
906
907   $::form->header;
908   print $::form->parse_html_template('gl/form_header', {
909     hide_title => $title,
910     readonly   => $::form->{id} && ($::form->{locked} || !_get_radieren()),
911   });
912
913   $::lxdebug->leave_sub;
914
915 }
916
917 sub form_footer {
918   $::lxdebug->enter_sub;
919   $::auth->assert('gl_transactions');
920
921   my ($follow_ups, $follow_ups_due);
922
923   if ($::form->{id}) {
924     $follow_ups     = FU->follow_ups('trans_id' => $::form->{id}, 'not_done' => 1);
925     $follow_ups_due = sum map { $_->{due} * 1 } @{ $follow_ups || [] };
926   }
927
928   print $::form->parse_html_template('gl/form_footer', {
929     radieren       => _get_radieren(),
930     follow_ups     => $follow_ups,
931     follow_ups_due => $follow_ups_due,
932   });
933
934   $::lxdebug->leave_sub;
935 }
936
937 sub delete {
938   $main::lxdebug->enter_sub();
939
940   my $form     = $main::form;
941   my $locale   = $main::locale;
942
943   $form->header;
944
945   print qq|
946 <form method=post action=gl.pl>
947 |;
948
949   map { $form->{$_} =~ s/\"/&quot;/g } qw(reference description);
950
951   delete $form->{header};
952
953   foreach my $key (keys %$form) {
954     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
955     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
956   }
957
958   print qq|
959 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
960
961 <h4>|
962     . $locale->text('Are you sure you want to delete Transaction')
963     . qq| $form->{reference}</h4>
964
965 <input name=action class=submit type=submit value="|
966     . $locale->text('Yes') . qq|">
967 </form>
968 |;
969   $main::lxdebug->leave_sub();
970
971 }
972
973 sub yes {
974   $main::lxdebug->enter_sub();
975
976   my $form     = $main::form;
977   my %myconfig = %main::myconfig;
978   my $locale   = $main::locale;
979
980   if (GL->delete_transaction(\%myconfig, \%$form)){
981     # saving the history
982       if(!exists $form->{addition} && $form->{id} ne "") {
983         $form->{snumbers} = qq|gltransaction_| . $form->{id};
984         $form->{addition} = "DELETED";
985         $form->{what_done} = "gl_transaction";
986         $form->save_history;
987       }
988     # /saving the history
989     $form->redirect($locale->text('Transaction deleted!'))
990   }
991   $form->error($locale->text('Cannot delete transaction!'));
992   $main::lxdebug->leave_sub();
993
994 }
995
996 sub post_transaction {
997   $main::lxdebug->enter_sub();
998
999   my $form     = $main::form;
1000   my %myconfig = %main::myconfig;
1001   my $locale   = $main::locale;
1002
1003   # check if there is something in reference and date
1004   $form->isblank("reference",   $locale->text('Reference missing!'));
1005   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
1006   $form->isblank("description", $locale->text('Description missing!'));
1007
1008   my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1009   my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
1010
1011   my @a           = ();
1012   my $count       = 0;
1013   my $debittax    = 0;
1014   my $credittax   = 0;
1015   my $debitcount  = 0;
1016   my $creditcount = 0;
1017   my $debitcredit;
1018   my %split_safety = ();
1019
1020   my $dbh = SL::DB->client->dbh;
1021   my ($notax_id) = selectrow_query($form, $dbh, "SELECT id FROM tax WHERE taxkey = 0 LIMIT 1", );
1022   my $zerotaxes  = selectall_hashref_query($form, $dbh, "SELECT id FROM tax WHERE rate = 0", );
1023
1024   my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1025
1026   for my $i (1 .. $form->{rowcount}) {
1027     next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1028
1029     for (qw(debit credit tax)) {
1030       $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1031     }
1032
1033     push @a, {};
1034     $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1035
1036     $split_safety{   $form->{"debit_$i"}  <=> 0 }++;
1037     $split_safety{ - $form->{"credit_$i"} <=> 0 }++;
1038
1039     if ($debitcredit) {
1040       $debitcount++;
1041     } else {
1042       $creditcount++;
1043     }
1044
1045     if (($debitcount >= 2) && ($creditcount == 2)) {
1046       $form->{"credit_$i"} = 0;
1047       $form->{"tax_$i"}    = 0;
1048       $creditcount--;
1049       $form->{creditlock} = 1;
1050     }
1051     if (($creditcount >= 2) && ($debitcount == 2)) {
1052       $form->{"debit_$i"} = 0;
1053       $form->{"tax_$i"}   = 0;
1054       $debitcount--;
1055       $form->{debitlock} = 1;
1056     }
1057     if (($creditcount == 1) && ($debitcount == 2)) {
1058       $form->{creditlock} = 1;
1059     }
1060     if (($creditcount == 2) && ($debitcount == 1)) {
1061       $form->{debitlock} = 1;
1062     }
1063     if ($debitcredit && $credittax) {
1064       $form->{"taxchart_$i"} = "$notax_id--0.00";
1065     }
1066     if (!$debitcredit && $debittax) {
1067       $form->{"taxchart_$i"} = "$notax_id--0.00";
1068     }
1069     my $amount = ($form->{"debit_$i"} == 0)
1070             ? $form->{"credit_$i"}
1071             : $form->{"debit_$i"};
1072     my $j = $#a;
1073     if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1074       $form->{"taxchart_$i"} = "$notax_id--0.00";
1075       $form->{"tax_$i"}      = 0;
1076     }
1077     my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1078     my $iswithouttax = grep { $_->{id} == $taxkey } @{ $zerotaxes };
1079     if (!$iswithouttax) {
1080       if ($debitcredit) {
1081         $debittax = 1;
1082       } else {
1083         $credittax = 1;
1084       }
1085
1086       my ($tmpnetamount,$tmpdiff);
1087       ($tmpnetamount,$form->{"tax_$i"},$tmpdiff) = $form->calculate_tax($amount,$rate,$form->{taxincluded} *= 1,2);
1088       if ($debitcredit) {
1089         $form->{"debit_$i"} = $tmpnetamount;
1090       } else {
1091         $form->{"credit_$i"} = $tmpnetamount;
1092       }
1093
1094     } else {
1095       $form->{"tax_$i"} = 0;
1096     }
1097
1098     for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1099     $count++;
1100   }
1101
1102   if ($split_safety{-1} > 1 && $split_safety{1} > 1) {
1103     $::form->error($::locale->text("Split entry detected. The values you have entered will result in an entry with more than one position on both debit and credit. " .
1104                                    "Due to known problems involving accounting software kivitendo does not allow these."));
1105   }
1106
1107   for my $i (1 .. $count) {
1108     my $j = $i - 1;
1109     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1110   }
1111
1112   for my $i ($count + 1 .. $form->{rowcount}) {
1113     for (@flds) { delete $form->{"${_}_$i"} }
1114   }
1115
1116   my ($debit, $credit, $taxtotal);
1117   for my $i (1 .. $form->{rowcount}) {
1118     my $dr  = $form->{"debit_$i"};
1119     my $cr  = $form->{"credit_$i"};
1120     my $tax = $form->{"tax_$i"};
1121     if ($dr && $cr) {
1122       $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1123     }
1124     $debit    += $dr + $tax if $dr;
1125     $credit   += $cr + $tax if $cr;
1126     $taxtotal += $tax if $form->{taxincluded}
1127   }
1128
1129   $form->{taxincluded} = 0 if !$taxtotal;
1130
1131   # this is just for the wise guys
1132
1133   $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
1134     if ($form->date_max_future($form->{"transdate"}, \%myconfig));
1135   $form->error($locale->text('Cannot post transaction for a closed period!'))
1136     if ($form->date_closed($form->{"transdate"}, \%myconfig));
1137   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1138     $form->error($locale->text('Out of balance transaction!'));
1139   }
1140
1141   if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1142     $form->error($locale->text('Empty transaction!'));
1143   }
1144
1145   if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1146     $errno *= -1;
1147     my @err;
1148     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1149     $err[2] = $locale->text('Debit and credit out of balance!');
1150     $err[3] = $locale->text('Cannot post a transaction without a value!');
1151
1152     $form->error($err[$errno]);
1153   }
1154   undef($form->{callback});
1155   # saving the history
1156   if(!exists $form->{addition} && $form->{id} ne "") {
1157     $form->{snumbers} = qq|gltransaction_| . $form->{id};
1158     $form->{addition} = "POSTED";
1159     $form->{what_done} = "gl transaction";
1160     $form->save_history;
1161   }
1162   # /saving the history
1163
1164   $main::lxdebug->leave_sub();
1165 }
1166
1167 sub post {
1168   $main::lxdebug->enter_sub();
1169
1170   $main::auth->assert('gl_transactions');
1171
1172   my $form     = $main::form;
1173   my $locale   = $main::locale;
1174
1175   if ($::myconfig{mandatory_departments} && !$form->{department}) {
1176     $form->{saved_message} = $::locale->text('You have to specify a department.');
1177     update();
1178     exit;
1179   }
1180
1181   $form->{title}  = $locale->text("$form->{title} General Ledger Transaction");
1182   $form->{storno} = 0;
1183
1184   post_transaction();
1185   if ($::instance_conf->get_webdav) {
1186     SL::Webdav->new(type     => 'general_ledger',
1187                     number   => $form->{reference},
1188                    )->webdav_path;
1189   }
1190
1191   $form->{callback} = build_std_url("action=add", "show_details");
1192   $form->redirect($form->{callback});
1193
1194   $main::lxdebug->leave_sub();
1195 }
1196
1197 sub post_as_new {
1198   $main::lxdebug->enter_sub();
1199
1200   $main::auth->assert('gl_transactions');
1201
1202   my $form     = $main::form;
1203
1204   $form->{id} = 0;
1205   &add;
1206   $main::lxdebug->leave_sub();
1207
1208 }
1209
1210 sub storno {
1211   $main::lxdebug->enter_sub();
1212
1213   $main::auth->assert('gl_transactions');
1214
1215   my $form     = $main::form;
1216   my %myconfig = %main::myconfig;
1217   my $locale   = $main::locale;
1218
1219   # don't cancel cancelled transactions
1220   if (IS->has_storno(\%myconfig, $form, 'gl')) {
1221     $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1222     $form->error($locale->text("Transaction has already been cancelled!"));
1223   }
1224
1225   GL->storno($form, \%myconfig, $form->{id});
1226
1227   # saving the history
1228   if(!exists $form->{addition} && $form->{id} ne "") {
1229     $form->{snumbers} = qq|gltransaction_| . $form->{id};
1230     $form->{addition} = "STORNO";
1231     $form->{what_done} = "gl_transaction";
1232     $form->save_history;
1233   }
1234   # /saving the history
1235
1236   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1237
1238   $main::lxdebug->leave_sub();
1239 }
1240
1241 sub continue {
1242   call_sub($main::form->{nextsub});
1243 }
1244
1245 sub get_tax_dropdown {
1246   $main::lxdebug->enter_sub();
1247
1248   my $form = $main::form;
1249   my @tax_accounts = GL->get_tax_dropdown($form->{accno});
1250
1251   foreach my $item (@tax_accounts) {
1252     $item->{taxdescription} = $::locale->{iconv_utf8}->convert($item->{taxdescription});
1253     $item->{taxdescription} .= ' ' . $form->round_amount($item->{rate} * 100);
1254   }
1255
1256   $form->{TAX_ACCOUNTS} = [ @tax_accounts ];
1257
1258   print $form->ajax_response_header, $form->parse_html_template("gl/update_tax_accounts");
1259
1260   $main::lxdebug->leave_sub();
1261
1262 }
1263
1264 1;