1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
   9 # Copyright (c) 1998-2002
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  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.
 
  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 #======================================================================
 
  32 #======================================================================
 
  34 use POSIX qw(strftime);
 
  39 use SL::ReportGenerator;
 
  41 require "bin/mozilla/arap.pl";
 
  42 require "bin/mozilla/common.pl";
 
  43 require "bin/mozilla/reportgenerator.pl";
 
  49 # this is for our long dates
 
  50 # $locale->text('January')
 
  51 # $locale->text('February')
 
  52 # $locale->text('March')
 
  53 # $locale->text('April')
 
  54 # $locale->text('May ')
 
  55 # $locale->text('June')
 
  56 # $locale->text('July')
 
  57 # $locale->text('August')
 
  58 # $locale->text('September')
 
  59 # $locale->text('October')
 
  60 # $locale->text('November')
 
  61 # $locale->text('December')
 
  63 # this is for our short month
 
  64 # $locale->text('Jan')
 
  65 # $locale->text('Feb')
 
  66 # $locale->text('Mar')
 
  67 # $locale->text('Apr')
 
  68 # $locale->text('May')
 
  69 # $locale->text('Jun')
 
  70 # $locale->text('Jul')
 
  71 # $locale->text('Aug')
 
  72 # $locale->text('Sep')
 
  73 # $locale->text('Oct')
 
  74 # $locale->text('Nov')
 
  75 # $locale->text('Dec')
 
  78   $lxdebug->enter_sub();
 
  80   $form->{title} = "Add";
 
  83     "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
 
  84     unless $form->{callback};
 
  86   # we use this only to set a default date
 
  87   GL->transaction(\%myconfig, \%$form);
 
  91       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
  92       . ($_->{rate} * 100) . qq| %|
 
  95   $form->{rowcount}  = 2;
 
 102   $form->all_departments(\%myconfig);
 
 103   if (@{ $form->{all_departments} }) {
 
 104     $form->{selectdepartment} = "<option>\n";
 
 107       $form->{selectdepartment} .=
 
 108         "<option>$_->{description}--$_->{id}\n"
 
 109     } (@{ $form->{all_departments} });
 
 112   $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
 
 115   $lxdebug->leave_sub();
 
 119 sub prepare_transaction {
 
 120   $lxdebug->enter_sub();
 
 122   GL->transaction(\%myconfig, \%$form);
 
 126       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
 127       . ($_->{rate} * 100) . qq| %|
 
 130   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
 
 133   $form->all_departments(\%myconfig);
 
 134   if (@{ $form->{all_departments} }) {
 
 135     $form->{selectdepartment} = "<option>\n";
 
 138       $form->{selectdepartment} .=
 
 139         "<option>$_->{description}--$_->{id}\n"
 
 140     } (@{ $form->{all_departments} });
 
 146   foreach $ref (@{ $form->{GL} }) {
 
 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"};
 
 155           $form->{"credit_$j"} += $form->{"tax_$j"};
 
 158       $form->{"project_id_$j"} = $ref->{project_id};
 
 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;
 
 167         $form->{totalcredit} += $ref->{amount};
 
 168         $form->{"credit_$i"} = $ref->{amount};
 
 170       $form->{"taxchart_$i"} = "0--0.00";
 
 171       $form->{"project_id_$i"} = $ref->{project_id};
 
 174     if ($ref->{taxaccno} && !$tax) {
 
 175       $taxaccno = $ref->{taxaccno};
 
 183   $form->{rowcount} = $i;
 
 185     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 186      $form->datetonum($form->{closedto}, \%myconfig));
 
 188   $lxdebug->leave_sub();
 
 192   $lxdebug->enter_sub();
 
 194   prepare_transaction();
 
 196   $form->{title} = "Edit";
 
 198   $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
 
 204   $lxdebug->leave_sub();
 
 209   $lxdebug->enter_sub();
 
 211   $form->{title} = $locale->text('Journal');
 
 213   $form->all_departments(\%myconfig);
 
 216   if (@{ $form->{all_departments} }) {
 
 217     $form->{selectdepartment} = "<option>\n";
 
 220       $form->{selectdepartment} .=
 
 221         "<option>$_->{description}--$_->{id}\n"
 
 222     } (@{ $form->{all_departments} });
 
 227           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 228           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 230 | if $form->{selectdepartment};
 
 232   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 235   my %project_labels = ();
 
 236   my @project_values = ("");
 
 237   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 238     push(@project_values, $item->{"id"});
 
 239     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 243     NTI($cgi->popup_menu('-name' => "project_id",
 
 244                          '-values' => \@project_values,
 
 245                          '-labels' => \%project_labels));
 
 247   # use JavaScript Calendar or not
 
 248   $form->{jsscript} = 1;
 
 250   if ($form->{jsscript}) {
 
 252     # with JavaScript Calendar
 
 254        <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
 255        <input type=button name=datefrom id="trigger1" value=|
 
 256       . $locale->text('button') . qq|></td>  
 
 259        <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
 260        <input type=button name=dateto id="trigger2" value=|
 
 261       . $locale->text('button') . qq|></td>
 
 266       Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
 
 267                           "dateto", "BL", "trigger2");
 
 270     # without JavaScript Calendar
 
 272       qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 274       qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 276   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 278   $onload = qq|focus()|;
 
 279   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 280   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 282 <body onLoad="$onload">
 
 284 <form method=post action=$form->{script}>
 
 286 <input type=hidden name=sort value=transdate>
 
 290     <th class=listtop>$form->{title}</th>
 
 297           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 298           <td><input name=reference size=20></td>
 
 299           <th align=right>| . $locale->text('Source') . qq|</th>
 
 300           <td><input name=source size=20></td>
 
 304           <th align=right>| . $locale->text('Description') . qq|</th>
 
 305           <td colspan=3><input name=description size=40></td>
 
 308           <th align=right>| . $locale->text('Notes') . qq|</th>
 
 309           <td colspan=3><input name=notes size=40></td>
 
 312           <th align=right>| . $locale->text('Project Number') . qq|</th>
 
 313           <td colspan=3>$projectnumber</td>
 
 316           <th align=right>| . $locale->text('From') . qq|</th>
 
 318           <th align=right>| . $locale->text('To (time)') . qq|</th>
 
 322           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 327                   <input name="category" class=radio type=radio value=X checked> |
 
 328     . $locale->text('All') . qq|
 
 329                   <input name="category" class=radio type=radio value=A> |
 
 330     . $locale->text('Asset') . qq|
 
 331                   <input name="category" class=radio type=radio value=L> |
 
 332     . $locale->text('Liability') . qq|
 
 333                   <input name="category" class=radio type=radio value=I> |
 
 334     . $locale->text('Revenue') . qq|
 
 335                   <input name="category" class=radio type=radio value=E> |
 
 336     . $locale->text('Expense') . qq|
 
 342                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 343                     <td>| . $locale->text('ID') . qq|</td>
 
 344                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 345                     <td>| . $locale->text('Date') . qq|</td>
 
 346                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
 
 347                     <td>| . $locale->text('Reference') . qq|</td>
 
 348                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
 
 349                     <td>| . $locale->text('Description') . qq|</td>
 
 350                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
 351                     <td>| . $locale->text('Notes') . qq|</td>
 
 354                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
 
 355                     <td>| . $locale->text('Debit') . qq|</td>
 
 356                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
 
 357                     <td>| . $locale->text('Credit') . qq|</td>
 
 358                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
 
 359                     <td>| . $locale->text('Source') . qq|</td>
 
 360                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
 
 361                     <td>| . $locale->text('Account') . qq|</td>
 
 364                     <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 365                     <td>| . $locale->text('Subtotal') . qq|</td>
 
 366                     <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
 
 367                     <td>| . $locale->text('Project Number') . qq|</td>
 
 377     <td><hr size=3 noshade></td>
 
 383 <input type=hidden name=nextsub value=generate_report>
 
 385 <input type=hidden name=login value=$form->{login}>
 
 386 <input type=hidden name=password value=$form->{password}>
 
 389 <input class=submit type=submit name=action value="|
 
 390     . $locale->text('Continue') . qq|">
 
 396   $lxdebug->leave_sub();
 
 399 sub create_subtotal_row {
 
 400   $lxdebug->enter_sub();
 
 402   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
 404   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
 406   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
 
 408   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
 410   $lxdebug->leave_sub();
 
 415 sub generate_report {
 
 416   $lxdebug->enter_sub();
 
 418   $form->{sort} ||= "transdate";
 
 420   GL->all_transactions(\%myconfig, \%$form);
 
 422   my %acctype = ('A' => $locale->text('Asset'),
 
 423                  'C' => $locale->text('Contra'),
 
 424                  'L' => $locale->text('Liability'),
 
 425                  'Q' => $locale->text('Equity'),
 
 426                  'I' => $locale->text('Revenue'),
 
 427                  'E' => $locale->text('Expense'),);
 
 429   $form->{title} = $locale->text('Journal');
 
 430   if ($form->{category} ne 'X') {
 
 431     $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
 
 434   $form->{landscape} = 1;
 
 436   my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
 
 439     transdate      id               reference      description
 
 440     notes          source           debit          debit_accno
 
 441     credit         credit_accno     debit_tax      debit_tax_accno
 
 442     credit_tax     credit_tax_accno projectnumbers balance
 
 445   my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
 
 446   push @hidden_variables, map { "l_${_}" } @columns;
 
 448   my (@options, $date_option);
 
 449   if ($form->{accno}) {
 
 450     push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}";
 
 452   if ($form->{source}) {
 
 453     push @options, $locale->text('Source') . " : $form->{source}";
 
 455   if ($form->{reference}) {
 
 456     push @options, $locale->text('Reference') . " : $form->{reference}";
 
 458   if ($form->{department}) {
 
 459     my ($department) = split /--/, $form->{department};
 
 460     push @options, $locale->text('Department') . " : $department";
 
 462   if ($form->{description}) {
 
 463     push @options, $locale->text('Description') . " : $form->{description}";
 
 465   if ($form->{notes}) {
 
 466     push @options, $locale->text('Notes') . " : $form->{notes}";
 
 468   if ($form->{datefrom}) {
 
 469     $date_option = $locale->text('From') . " " . $locale->date(\%myconfig, $form->{datefrom}, 1);
 
 471   if ($form->{dateto}) {
 
 472     if ($form->{datefrom}) {
 
 475     $date_option .= $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{dateto}, 1);
 
 477   push @options, $date_option if $date_option;
 
 479   my $callback = build_std_url('action=generate_report', @hidden_variables);
 
 481   $form->{l_credit_accno}     = 'Y';
 
 482   $form->{l_debit_accno}      = 'Y';
 
 483   $form->{l_credit_tax}       = 'Y';
 
 484   $form->{l_debit_tax}        = 'Y';
 
 485   $form->{l_credit_tax_accno} = 'Y';
 
 486   $form->{l_debit_tax_accno}  = 'Y';
 
 487   $form->{l_balance}          = $form->{accno} ? 'Y' : '';
 
 490     'id'               => { 'text' => $locale->text('ID'), },
 
 491     'transdate'        => { 'text' => $locale->text('Date'), },
 
 492     'reference'        => { 'text' => $locale->text('Reference'), },
 
 493     'source'           => { 'text' => $locale->text('Source'), },
 
 494     'description'      => { 'text' => $locale->text('Description'), },
 
 495     'notes'            => { 'text' => $locale->text('Notes'), },
 
 496     'debit'            => { 'text' => $locale->text('Debit'), },
 
 497     'debit_accno'      => { 'text' => $locale->text('Debit Account'), },
 
 498     'credit'           => { 'text' => $locale->text('Credit'), },
 
 499     'credit_accno'     => { 'text' => $locale->text('Credit Account'), },
 
 500     'debit_tax'        => { 'text' => $locale->text('Debit Tax'), },
 
 501     'debit_tax_accno'  => { 'text' => $locale->text('Debit Tax Account'), },
 
 502     'credit_tax'       => { 'text' => $locale->text('Credit Tax'), },
 
 503     'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
 
 504     'balance'          => { 'text' => $locale->text('Balance'), },
 
 505     'projectnumbers'   => { 'text' => $locale->text('Project Numbers'), },
 
 508   map { $column_defs{$_}->{link}    = $callback . "&sort=${_}" }  qw(id transdate reference source description);
 
 509   map { $column_defs{$_}->{link}    = $callback . "&sort=accno" } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno debit_tax credit_tax);
 
 510   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
 
 511   map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
 
 513   my %column_alignment;
 
 514   map { $column_alignment{$_} = 'right' }  qw(balance id debit credit debit_tax credit_tax);
 
 515   map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno);
 
 517   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
 519   $report->set_columns(%column_defs);
 
 520   $report->set_column_order(@columns);
 
 522   $report->set_export_options('generate_report', @hidden_variables);
 
 524   $report->set_sort_indicator($form->{sort}, 1);
 
 526   $report->set_options('top_info_text'        => join("\n", @options),
 
 527                        'output_format'        => 'HTML',
 
 528                        'title'                => $form->{title},
 
 529                        'attachment_basename'  => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
 
 531   $report->set_options_from_form();
 
 533   # add sort to callback
 
 534   $form->{callback} = "$callback&sort=" . E($form->{sort});
 
 536   $form->{balance} *= $ml;
 
 538   if ($form->{accno} && $form->{balance}) {
 
 541         'data'  => $form->format_amount(\%myconfig, $form->{balance}, 2),
 
 546     $report->add_data($row);
 
 549   my @totals_columns = qw(debit credit debit_tax credit_tax);
 
 550   my %subtotals      = map { $_ => 0 } @totals_columns;
 
 551   my %totals         = map { $_ => 0 } @totals_columns;
 
 554   foreach $ref (@{ $form->{GL} }) {
 
 555     $form->{balance} *= $ml;
 
 559     foreach my $key (qw(debit credit debit_tax credit_tax)) {
 
 561       foreach my $idx (sort keys(%{ $ref->{$key} })) {
 
 562         my $value         = $ref->{$key}->{$idx};
 
 563         $subtotals{$key} += $value;
 
 564         $totals{$key}    += $value;
 
 565         $form->{balance}  = abs($form->{balance}) - abs($value);
 
 566         push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
 
 570     foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate)) {
 
 571       my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
 
 572       $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
 
 576     map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
 
 578     $row->{balance}->{data}        = $form->format_amount(\%myconfig, $form->{balance}, 2);
 
 579     $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
 
 581     map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes);
 
 583     map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno);
 
 585     foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
 
 586       $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
 
 589     map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
 
 591     $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
 
 593     my $row_set = [ $row ];
 
 595     if (($form->{l_subtotal} eq 'Y')
 
 596         && (($idx == (scalar @{ $form->{GL} } - 1))
 
 597             || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
 
 598       push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
 
 601     $report->add_data($row_set);
 
 606   $report->add_separator();
 
 608   # = 0 for balanced ledger
 
 609   my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
 
 611   my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
 
 613     'data'  => $form->format_amount(\%myconfig, $form->{balance} * $ml, 2),
 
 615     'class' => 'listtotal',
 
 617   $report->add_data($row);
 
 619   my $raw_bottom_info_text;
 
 621   if (!$form->{accno} && (abs($balanced_ledger) >  0.001)) {
 
 622     $raw_bottom_info_text .=
 
 623         '<p><span class="unbalanced_ledger">'
 
 624       . $locale->text('Unbalanced Ledger')
 
 626       . $form->format_amount(\%myconfig, $balanced_ledger, 3)
 
 630   $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
 
 632   $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
 
 634   $report->generate_with_headers();
 
 636   $lxdebug->leave_sub();
 
 640   $lxdebug->enter_sub();
 
 642   $form->{oldtransdate} = $form->{transdate};
 
 654     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
 656   for my $i (1 .. $form->{rowcount}) {
 
 658     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
 659       for (qw(debit credit tax)) {
 
 661           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
 665       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
 672       if (($debitcount >= 2) && ($creditcount == 2)) {
 
 673         $form->{"credit_$i"} = 0;
 
 674         $form->{"tax_$i"}    = 0;
 
 678       if (($creditcount >= 2) && ($debitcount == 2)) {
 
 679         $form->{"debit_$i"} = 0;
 
 680         $form->{"tax_$i"}   = 0;
 
 684       if (($creditcount == 1) && ($debitcount == 2)) {
 
 687       if (($creditcount == 2) && ($debitcount == 1)) {
 
 690       if ($debitcredit && $credittax) {
 
 691         $form->{"taxchart_$i"} = "0--0.00";
 
 693       if (!$debitcredit && $debittax) {
 
 694         $form->{"taxchart_$i"} = "0--0.00";
 
 697         ($form->{"debit_$i"} == 0)
 
 698         ? $form->{"credit_$i"}
 
 699         : $form->{"debit_$i"};
 
 701       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
 702         $form->{"taxchart_$i"} = "0--0.00";
 
 703         $form->{"tax_$i"}      = 0;
 
 705       if (!$form->{"korrektur_$i"}) {
 
 706         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
 713           if ($form->{taxincluded}) {
 
 714             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
 716             $form->{"tax_$i"} = $amount * $rate;
 
 719           $form->{"tax_$i"} = 0;
 
 723       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
 728   for $i (1 .. $count) {
 
 730     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
 733   for $i ($count + 1 .. $form->{rowcount}) {
 
 734     for (@flds) { delete $form->{"${_}_$i"} }
 
 737   $form->{rowcount} = $count + 1;
 
 740   $lxdebug->leave_sub();
 
 746   $lxdebug->enter_sub();
 
 750   #   for $i (1 .. $form->{rowcount}) {
 
 751   #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
 
 752   #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
 
 756   &display_rows($init);
 
 758   $lxdebug->leave_sub();
 
 764   $lxdebug->enter_sub();
 
 766   $form->{debit_1}     = 0 if !$form->{"debit_1"};
 
 767   $form->{totaldebit}  = 0;
 
 768   $form->{totalcredit} = 0;
 
 770   my @old_project_ids = ();
 
 771   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
 772           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
 774   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 776                                    "old_id" => \@old_project_ids },
 
 777                    "charts" => { "key" => "ALL_CHARTS",
 
 778                                  "transdate" => $form->{transdate} },
 
 779                    "taxcharts" => "ALL_TAXCHARTS");
 
 781   my %project_labels = ();
 
 782   my @project_values = ("");
 
 783   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 784     push(@project_values, $item->{"id"});
 
 785     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 788   my %chart_labels = ();
 
 789   my @chart_values = ();
 
 792   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
 793     my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
 
 794     $taxchart_init = $item->{taxkey_id} unless (@chart_values);
 
 795     push(@chart_values, $key);
 
 796     $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
 
 797     $charts{$item->{accno}} = $item;
 
 800   my %taxchart_labels = ();
 
 801   my @taxchart_values = ();
 
 803   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
 804     my $key = Q($item->{id}) . "--" . Q($item->{rate});
 
 805     $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
 
 806     push(@taxchart_values, $key);
 
 807     $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
 
 808       H($item->{rate} * 100) . ' %';
 
 809     $taxcharts{$item->{id}} = $item;
 
 812   for $i (1 .. $form->{rowcount}) {
 
 815     <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
 
 817     <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
 
 819     my $selected_accno_full;
 
 820     my ($accno_row) = split(/--/, $form->{"accno_$i"});
 
 821     my $item = $charts{$accno_row};
 
 822     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
 
 824     my $selected_taxchart = $form->{"taxchart_$i"};
 
 825     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
 
 826     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
 
 828     if ($previous_accno &&
 
 829         ($previous_accno eq $selected_accno) &&
 
 830         ($previous_tax_id ne $selected_tax_id)) {
 
 831       my $item = $taxcharts{$selected_tax_id};
 
 832       $selected_taxchart = "$item->{id}--$item->{rate}";
 
 835     $selected_accno = '' if ($init);
 
 836     $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
 
 839       NTI($cgi->popup_menu('-name' => "accno_$i",
 
 841                            '-onChange' => "setTaxkey(this, $i)",
 
 842                            '-style' => 'width:200px',
 
 843                            '-values' => \@chart_values,
 
 844                            '-labels' => \%chart_labels,
 
 845                            '-default' => $selected_accno_full))
 
 846       . $cgi->hidden('-name' => "previous_accno_$i",
 
 847                      '-default' => $selected_accno_full)
 
 850       NTI($cgi->popup_menu('-name' => "taxchart_$i",
 
 851                            '-id' => "taxchart_$i",
 
 852                            '-style' => 'width:200px',
 
 853                            '-values' => \@taxchart_values,
 
 854                            '-labels' => \%taxchart_labels,
 
 855                            '-default' => $selected_taxchart))
 
 860         qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
 
 861       if ($form->{transfer}) {
 
 862         $fx_transaction = qq|
 
 863         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
 868       if ($form->{"debit_$i"} != 0) {
 
 869         $form->{totaldebit} += $form->{"debit_$i"};
 
 870         if (!$form->{taxincluded}) {
 
 871           $form->{totaldebit} += $form->{"tax_$i"};
 
 874         $form->{totalcredit} += $form->{"credit_$i"};
 
 875         if (!$form->{taxincluded}) {
 
 876           $form->{totalcredit} += $form->{"tax_$i"};
 
 880       for (qw(debit credit tax)) {
 
 883           ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
 
 887       if ($i < $form->{rowcount}) {
 
 888         if ($form->{transfer}) {
 
 889           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
 
 890           $x = ($checked) ? "x" : "";
 
 891           $fx_transaction = qq|
 
 892       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
 
 895         $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
 
 897           qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked></td>|;
 
 898         $form->hide_form("accno_$i");
 
 902           qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
 
 903         if ($form->{transfer}) {
 
 904           $fx_transaction = qq|
 
 905       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
 910     my $debitreadonly  = "";
 
 911     my $creditreadonly = "";
 
 912     if ($i == $form->{rowcount}) {
 
 914         $debitreadonly = "readonly";
 
 915       } elsif ($creditlock) {
 
 916         $creditreadonly = "readonly";
 
 921       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
 922                            '-values' => \@project_values,
 
 923                            '-labels' => \%project_labels,
 
 924                            '-default' => $form->{"project_id_$i"} ));
 
 926     my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
 
 928     print qq|<tr valign=top>
 
 931     <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
 
 932     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
 
 933     <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
 
 937     if ($form->{show_details}) {
 
 941     <td>$projectnumber</td>
 
 949   $form->hide_form(qw(rowcount selectaccno));
 
 951   $lxdebug->leave_sub();
 
 957   $lxdebug->enter_sub();
 
 958   $title         = $form->{title};
 
 959   $form->{title} = $locale->text("$title General Ledger Transaction");
 
 960   $readonly      = ($form->{id}) ? "readonly" : "";
 
 962   $show_details_checked = "checked" if $form->{show_details};
 
 964   # $locale->text('Add General Ledger Transaction')
 
 965   # $locale->text('Edit General Ledger Transaction')
 
 967   map { $form->{$_} =~ s/\"/"/g }
 
 968     qw(reference description chart taxchart);
 
 970   $form->{javascript} = qq|<script type="text/javascript">
 
 972   function setTaxkey(accno, row) {
 
 973     var taxkey = accno.options[accno.selectedIndex].value;
 
 974     var reg = /--([0-9]*)/;
 
 975     var found = reg.exec(taxkey);
 
 976     var index = found[1];
 
 977     index = parseInt(index);
 
 978     var tax = 'taxchart_' + row;
 
 979     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
 980       var reg2 = new RegExp("^"+ index, "");
 
 981       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
 982         document.getElementById(tax).options[i].selected = true;
 
 988   function copy_debit_to_credit() {
 
 989     var txt = document.getElementsByName('debit_1')[0].value;
 
 990     document.getElementsByName('credit_2')[0].value = txt;
 
 995   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
 
 997   $form->{selectdepartment} =~ s/ selected//;
 
 998   $form->{selectdepartment} =~
 
 999     s/option>\Q$form->{department}\E/option selected>$form->{department}/;
 
1001   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
 
1003       qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
 
1006       qq|<input name=description size=50 value="$form->{description}" $readonly>|;
 
1009   $taxincluded = ($form->{taxincluded}) ? "checked" : "";
 
1012     $taxincluded = "checked";
 
1017           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1018           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1019           <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
1021 | if $form->{selectdepartment};
 
1023     $form->{fokus} = "gl.reference";
 
1025     $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
 
1028   # use JavaScript Calendar or not
 
1029   $form->{jsscript} = 1;
 
1031   if ($form->{jsscript}) {
 
1033     # with JavaScript Calendar
 
1035        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
 
1036        <input type=button name=transdate id="trigger1" value=|
 
1037       . $locale->text('button') . qq|></td>  
 
1042       Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
 
1045     # without JavaScript Calendar
 
1047       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
 
1050   $form->{previous_id}     ||= "--";
 
1051   $form->{previous_gldate} ||= "--";
 
1056 <body onLoad="fokus()">
 
1058 <form method=post name="gl" action=$form->{script}>
 
1061   $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
 
1064 <input type=hidden name=title value="$title">
 
1069     <th class=listtop>$form->{title}</th>
 
1071   <tr height="5"></tr>
 
1076           <td colspan="6" align="left">|
 
1077     . $locale->text("Previous transnumber text")
 
1078     . " $form->{previous_id} "
 
1079     . $locale->text("Previous transdate text")
 
1080     . " $form->{previous_gldate}"
 
1084           <th align=right>| . $locale->text('Reference') . qq|</th>
 
1085           <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
 
1089                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
 
1098           <th align=right>| . $locale->text('Belegnummer') . qq|</th>
 
1099           <td><input name=id size=20 value="$form->{id}" $readonly></td>
 
1103                 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
 
1104                 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
 
1115           <th align=right width=1%>| . $locale->text('Description') . qq|</th>
 
1116           <td width=1%>$description</td>
 
1120                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1121                 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
 
1128                 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
 
1129                 <td align=left><input name=employee size=20  value="| . H($form->{employee}) . qq|" readonly></td>
 
1137           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1138           <td width=1%>$description</td>
 
1142                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1143                 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
 
1151        <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
 
1152        <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
 
1159            <tr class=listheading>
 
1160           <th class=listheading style="width:15%">|
 
1161     . $locale->text('Account') . qq|</th>
 
1162           <th class=listheading style="width:10%">|
 
1163     . $locale->text('Debit') . qq|</th>
 
1164           <th class=listheading style="width:10%">|
 
1165     . $locale->text('Credit') . qq|</th>
 
1166           <th class=listheading style="width:10%">|
 
1167     . $locale->text('Tax') . qq|</th>
 
1168           <th class=listheading style="width:5%">|
 
1169     . $locale->text('Korrektur') . qq|</th>
 
1170           <th class=listheading style="width:10%">|
 
1171     . $locale->text('Taxkey') . qq|</th>|;
 
1173   if ($form->{show_details}) {
 
1175           <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
 
1176           <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
 
1177           <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
 
1186   $lxdebug->leave_sub();
 
1191   $lxdebug->enter_sub();
 
1192   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
 
1194   $decimalplaces = ($dec > 2) ? $dec : 2;
 
1195   $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
1198     $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
 
1199   } qw(totaldebit totalcredit);
 
1202     <tr class=listtotal>
 
1204     <th align=right class=listtotal> $form->{totaldebit}</th>
 
1205     <th align=right class=listtotal> $form->{totalcredit}</th> 
 
1213 <input type=hidden name=login value=$form->{login}>
 
1214 <input type=hidden name=password value=$form->{password}>
 
1216 <input name=callback type=hidden value="$form->{callback}">
 
1221   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1222   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1226     if (!$form->{storno}) {
 
1227       print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
 
1230     # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
 
1231     if (!$form->{locked} && $radieren) {
 
1233         <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
 
1234         <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
 
1238     if ($transdate > $closedto) {
 
1240         <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
 
1241         <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">|;
 
1251   $lxdebug->leave_sub();
 
1256   $lxdebug->enter_sub();
 
1263 <form method=post action=$form->{script}>
 
1266   map { $form->{$_} =~ s/\"/"/g } qw(reference description);
 
1268   delete $form->{header};
 
1270   foreach $key (keys %$form) {
 
1271     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1275 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1278     . $locale->text('Are you sure you want to delete Transaction')
 
1279     . qq| $form->{reference}</h4>
 
1281 <input name=action class=submit type=submit value="|
 
1282     . $locale->text('Yes') . qq|">
 
1285   $lxdebug->leave_sub();
 
1290   $lxdebug->enter_sub();
 
1291   if (GL->delete_transaction(\%myconfig, \%$form)){
 
1292     # saving the history
 
1293       if(!exists $form->{addition} && $form->{id} ne "") {
 
1294         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1295             $form->{addition} = "DELETED";
 
1296             $form->save_history($form->dbconnect(\%myconfig));
 
1298     # /saving the history 
 
1299     $form->redirect($locale->text('Transaction deleted!'))
 
1301   $form->error($locale->text('Cannot delete transaction!'));
 
1302   $lxdebug->leave_sub();
 
1306 sub post_transaction {
 
1307   $lxdebug->enter_sub();
 
1309   # check if there is something in reference and date
 
1310   $form->isblank("reference",   $locale->text('Reference missing!'));
 
1311   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
 
1312   $form->isblank("description", $locale->text('Description missing!'));
 
1314   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1315   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1322   my $creditcount = 0;
 
1326   my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
1328   for my $i (1 .. $form->{rowcount}) {
 
1329     next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
 
1331     for (qw(debit credit tax)) {
 
1332       $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
1336     $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
1344     if (($debitcount >= 2) && ($creditcount == 2)) {
 
1345       $form->{"credit_$i"} = 0;
 
1346       $form->{"tax_$i"}    = 0;
 
1350     if (($creditcount >= 2) && ($debitcount == 2)) {
 
1351       $form->{"debit_$i"} = 0;
 
1352       $form->{"tax_$i"}   = 0;
 
1356     if (($creditcount == 1) && ($debitcount == 2)) {
 
1359     if (($creditcount == 2) && ($debitcount == 1)) {
 
1362     if ($debitcredit && $credittax) {
 
1363       $form->{"taxchart_$i"} = "0--0.00";
 
1365     if (!$debitcredit && $debittax) {
 
1366       $form->{"taxchart_$i"} = "0--0.00";
 
1368     $amount = ($form->{"debit_$i"} == 0)
 
1369             ? $form->{"credit_$i"}
 
1370             : $form->{"debit_$i"};
 
1372     if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1373       $form->{"taxchart_$i"} = "0--0.00";
 
1374       $form->{"tax_$i"}      = 0;
 
1376     if (!$form->{"korrektur_$i"}) {
 
1377       ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1384         if ($form->{taxincluded}) {
 
1385           $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1387             $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1389             $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1392           $form->{"tax_$i"} = $amount * $rate;
 
1395         $form->{"tax_$i"} = 0;
 
1397     } elsif ($form->{taxincluded}) {
 
1399         $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1401         $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1405     for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1409   for $i (1 .. $count) {
 
1411     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1414   for $i ($count + 1 .. $form->{rowcount}) {
 
1415     for (@flds) { delete $form->{"${_}_$i"} }
 
1418   for $i (1 .. $form->{rowcount}) {
 
1419     $dr  = $form->{"debit_$i"};
 
1420     $cr  = $form->{"credit_$i"};
 
1421     $tax = $form->{"tax_$i"};
 
1423       $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
 
1425     $debit    += $dr + $tax if $dr;
 
1426     $credit   += $cr + $tax if $cr;
 
1427     $taxtotal += $tax if $form->{taxincluded}
 
1430   $form->{taxincluded} = 0 if !$taxtotal;
 
1432   # this is just for the wise guys
 
1433   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
1434     if ($transdate <= $closedto);
 
1435   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
 
1436     $form->error($locale->text('Out of balance transaction!'));
 
1439   if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
 
1440     $form->error($locale->text('Empty transaction!'));
 
1443   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
 
1445     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
 
1446     $err[2] = $locale->text('Debit and credit out of balance!');
 
1447     $err[3] = $locale->text('Cannot post a transaction without a value!');
 
1449     $form->error($err[$errno]);
 
1451   undef($form->{callback});
 
1452   # saving the history
 
1453   if(!exists $form->{addition} && $form->{id} ne "") {
 
1454     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1455     $form->{addition} = "SAVED";
 
1456     $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; 
 
1457     $form->save_history($form->dbconnect(\%myconfig));
 
1459   # /saving the history 
 
1461   $lxdebug->leave_sub();
 
1465   $lxdebug->enter_sub();
 
1467   $form->{title}  = $locale->text("$form->{title} General Ledger Transaction");
 
1468   $form->{storno} = 0;
 
1472   $form->{callback} = build_std_url("action=add", "show_details");
 
1473   $form->redirect($form->{callback});
 
1475   $lxdebug->leave_sub();
 
1479   $lxdebug->enter_sub();
 
1483   $lxdebug->leave_sub();
 
1488   $lxdebug->enter_sub();
 
1490   # don't cancel cancelled transactions
 
1491   if (IS->has_storno(\%myconfig, $form, 'gl')) {
 
1492     $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
 
1493     $form->error($locale->text("Transaction has already been cancelled!"));
 
1496   GL->storno($form, \%myconfig, $form->{id});
 
1498   # saving the history
 
1499   if(!exists $form->{addition} && $form->{id} ne "") {
 
1500     $form->{snumbers} = "ordnumber_$form->{ordnumber}";
 
1501     $form->{addition} = "STORNO";
 
1502     $form->save_history($form->dbconnect(\%myconfig));
 
1504   # /saving the history 
 
1506   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); 
 
1508   $lxdebug->leave_sub();