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 #======================================================================
 
  37 require "$form->{path}/arap.pl";
 
  38 require "bin/mozilla/common.pl";
 
  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')
 
  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')
 
  73   $lxdebug->enter_sub();
 
  75   $form->{title} = "Add";
 
  78     "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
 
  79     unless $form->{callback};
 
  81   # we use this only to set a default date
 
  82   GL->transaction(\%myconfig, \%$form);
 
  86       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
  87       . ($_->{rate} * 100) . qq| %|
 
  90   $form->{rowcount}  = 2;
 
  97   $form->all_departments(\%myconfig);
 
  98   if (@{ $form->{all_departments} }) {
 
  99     $form->{selectdepartment} = "<option>\n";
 
 102       $form->{selectdepartment} .=
 
 103         "<option>$_->{description}--$_->{id}\n"
 
 104     } (@{ $form->{all_departments} });
 
 108   $lxdebug->leave_sub();
 
 113   $lxdebug->enter_sub();
 
 115   GL->transaction(\%myconfig, \%$form);
 
 119       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
 120       . ($_->{rate} * 100) . qq| %|
 
 123   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
 
 126   $form->all_departments(\%myconfig);
 
 127   if (@{ $form->{all_departments} }) {
 
 128     $form->{selectdepartment} = "<option>\n";
 
 131       $form->{selectdepartment} .=
 
 132         "<option>$_->{description}--$_->{id}\n"
 
 133     } (@{ $form->{all_departments} });
 
 139   foreach $ref (@{ $form->{GL} }) {
 
 141     if ($tax && ($ref->{accno} eq $taxaccno)) {
 
 142       $form->{"tax_$j"}      = abs($ref->{amount});
 
 143       $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
 
 144       if ($form->{taxincluded}) {
 
 145         if ($ref->{amount} < 0) {
 
 146           $form->{"debit_$j"} += $form->{"tax_$j"};
 
 148           $form->{"credit_$j"} += $form->{"tax_$j"};
 
 152       $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
 
 153       for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
 
 154       if ($ref->{amount} < 0) {
 
 155         $form->{totaldebit} -= $ref->{amount};
 
 156         $form->{"debit_$i"} = $ref->{amount} * -1;
 
 158         $form->{totalcredit} += $ref->{amount};
 
 159         $form->{"credit_$i"} = $ref->{amount};
 
 161       $form->{"taxchart_$i"} = "0--0.00";
 
 164     if ($ref->{taxaccno} && !$tax) {
 
 165       $taxaccno = $ref->{taxaccno};
 
 174   $form->{rowcount} = $i;
 
 176     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 177      $form->datetonum($form->{closedto}, \%myconfig));
 
 179   $form->{title} = "Edit";
 
 184   $lxdebug->leave_sub();
 
 189   $lxdebug->enter_sub();
 
 191   $form->{title} = $locale->text('Buchungsjournal');
 
 193   $form->all_departments(\%myconfig);
 
 196   if (@{ $form->{all_departments} }) {
 
 197     $form->{selectdepartment} = "<option>\n";
 
 200       $form->{selectdepartment} .=
 
 201         "<option>$_->{description}--$_->{id}\n"
 
 202     } (@{ $form->{all_departments} });
 
 207           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 208           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 210 | if $form->{selectdepartment};
 
 212   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 215   my %project_labels = ();
 
 216   my @project_values = ("");
 
 217   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 218     push(@project_values, $item->{"id"});
 
 219     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 223     NTI($cgi->popup_menu('-name' => "project_id",
 
 224                          '-values' => \@project_values,
 
 225                          '-labels' => \%project_labels));
 
 227   # use JavaScript Calendar or not
 
 228   $form->{jsscript} = $jscalendar;
 
 230   if ($form->{jsscript}) {
 
 232     # with JavaScript Calendar
 
 234        <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}">
 
 235        <input type=button name=datefrom id="trigger1" value=|
 
 236       . $locale->text('button') . qq|></td>  
 
 239        <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}">
 
 240        <input type=button name=dateto id="trigger2" value=|
 
 241       . $locale->text('button') . qq|></td>
 
 246       Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
 
 247                           "dateto", "BL", "trigger2");
 
 250     # without JavaScript Calendar
 
 252       qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}"></td>|;
 
 254       qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}"></td>|;
 
 262 <form method=post action=$form->{script}>
 
 264 <input type=hidden name=sort value=transdate>
 
 268     <th class=listtop>$form->{title}</th>
 
 275           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 276           <td><input name=reference size=20></td>
 
 277           <th align=right>| . $locale->text('Source') . qq|</th>
 
 278           <td><input name=source size=20></td>
 
 282           <th align=right>| . $locale->text('Description') . qq|</th>
 
 283           <td colspan=3><input name=description size=40></td>
 
 286           <th align=right>| . $locale->text('Notes') . qq|</th>
 
 287           <td colspan=3><input name=notes size=40></td>
 
 290           <th align=right>| . $locale->text('Project Number') . qq|</th>
 
 291           <td colspan=3>$projectnumber</td>
 
 294           <th align=right>| . $locale->text('From') . qq|</th>
 
 296           <th align=right>| . $locale->text('To (time)') . qq|</th>
 
 300           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 305                   <input name="category" class=radio type=radio value=X checked> |
 
 306     . $locale->text('All') . qq|
 
 307                   <input name="category" class=radio type=radio value=A> |
 
 308     . $locale->text('Asset') . qq|
 
 309                   <input name="category" class=radio type=radio value=L> |
 
 310     . $locale->text('Liability') . qq|
 
 311                   <input name="category" class=radio type=radio value=I> |
 
 312     . $locale->text('Revenue') . qq|
 
 313                   <input name="category" class=radio type=radio value=E> |
 
 314     . $locale->text('Expense') . qq|
 
 320                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 321                     <td>| . $locale->text('ID') . qq|</td>
 
 322                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 323                     <td>| . $locale->text('Date') . qq|</td>
 
 324                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
 
 325                     <td>| . $locale->text('Reference') . qq|</td>
 
 326                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
 
 327                     <td>| . $locale->text('Description') . qq|</td>
 
 328                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
 329                     <td>| . $locale->text('Notes') . qq|</td>
 
 332                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
 
 333                     <td>| . $locale->text('Debit') . qq|</td>
 
 334                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
 
 335                     <td>| . $locale->text('Credit') . qq|</td>
 
 336                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
 
 337                     <td>| . $locale->text('Source') . qq|</td>
 
 338                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
 
 339                     <td>| . $locale->text('Account') . qq|</td>
 
 340                     <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
 
 341                     <td>| . $locale->text('GIFI') . qq|</td>
 
 344                     <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 345                     <td>| . $locale->text('Subtotal') . qq|</td>
 
 346                     <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
 
 347                     <td>| . $locale->text('Project Number') . qq|</td>
 
 357     <td><hr size=3 noshade></td>
 
 363 <input type=hidden name=nextsub value=generate_report>
 
 365 <input type=hidden name=path value=$form->{path}>
 
 366 <input type=hidden name=login value=$form->{login}>
 
 367 <input type=hidden name=password value=$form->{password}>
 
 370 <input class=submit type=submit name=action value="|
 
 371     . $locale->text('Continue') . qq|">
 
 377   $lxdebug->leave_sub();
 
 380 sub generate_report {
 
 381   $lxdebug->enter_sub();
 
 383   $form->{sort} = "transdate" unless $form->{sort};
 
 385   GL->all_transactions(\%myconfig, \%$form);
 
 388     "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
 
 392   %acctype = ('A' => $locale->text('Asset'),
 
 393               'C' => $locale->text('Contra'),
 
 394               'L' => $locale->text('Liability'),
 
 395               'Q' => $locale->text('Equity'),
 
 396               'I' => $locale->text('Revenue'),
 
 397               'E' => $locale->text('Expense'),);
 
 399   $form->{title} = $locale->text('General Ledger');
 
 401   $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
 
 403   unless ($form->{category} eq 'X') {
 
 404     $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
 
 406   if ($form->{accno}) {
 
 407     $href .= "&accno=" . $form->escape($form->{accno});
 
 408     $callback .= "&accno=" . $form->escape($form->{accno}, 1);
 
 410       $locale->text('Account')
 
 411       . " : $form->{accno} $form->{account_description}";
 
 413   if ($form->{gifi_accno}) {
 
 414     $href     .= "&gifi_accno=" . $form->escape($form->{gifi_accno});
 
 415     $callback .= "&gifi_accno=" . $form->escape($form->{gifi_accno}, 1);
 
 416     $option   .= "\n<br>" if $option;
 
 418       $locale->text('GIFI')
 
 419       . " : $form->{gifi_accno} $form->{gifi_account_description}";
 
 421   if ($form->{source}) {
 
 422     $href     .= "&source=" . $form->escape($form->{source});
 
 423     $callback .= "&source=" . $form->escape($form->{source}, 1);
 
 424     $option   .= "\n<br>" if $option;
 
 425     $option   .= $locale->text('Source') . " : $form->{source}";
 
 427   if ($form->{reference}) {
 
 428     $href     .= "&reference=" . $form->escape($form->{reference});
 
 429     $callback .= "&reference=" . $form->escape($form->{reference}, 1);
 
 430     $option   .= "\n<br>" if $option;
 
 431     $option   .= $locale->text('Reference') . " : $form->{reference}";
 
 433   if ($form->{department}) {
 
 434     $href .= "&department=" . $form->escape($form->{department});
 
 435     $callback .= "&department=" . $form->escape($form->{department}, 1);
 
 436     ($department) = split /--/, $form->{department};
 
 437     $option .= "\n<br>" if $option;
 
 438     $option .= $locale->text('Department') . " : $department";
 
 441   if ($form->{description}) {
 
 442     $href     .= "&description=" . $form->escape($form->{description});
 
 443     $callback .= "&description=" . $form->escape($form->{description}, 1);
 
 444     $option   .= "\n<br>" if $option;
 
 445     $option   .= $locale->text('Description') . " : $form->{description}";
 
 447   if ($form->{notes}) {
 
 448     $href     .= "¬es=" . $form->escape($form->{notes});
 
 449     $callback .= "¬es=" . $form->escape($form->{notes}, 1);
 
 450     $option   .= "\n<br>" if $option;
 
 451     $option   .= $locale->text('Notes') . " : $form->{notes}";
 
 453  if ($form->{project_id}) {
 
 454     $href     .= "&project_id=" . $form->escape($form->{project_id});
 
 455     $callback .= "&project_id=" . $form->escape($form->{project_id});
 
 458   if ($form->{datefrom}) {
 
 459     $href     .= "&datefrom=$form->{datefrom}";
 
 460     $callback .= "&datefrom=$form->{datefrom}";
 
 461     $option   .= "\n<br>" if $option;
 
 463         $locale->text('From') . " "
 
 464       . $locale->date(\%myconfig, $form->{datefrom}, 1);
 
 466   if ($form->{dateto}) {
 
 467     $href     .= "&dateto=$form->{dateto}";
 
 468     $callback .= "&dateto=$form->{dateto}";
 
 469     if ($form->{datefrom}) {
 
 472       $option .= "\n<br>" if $option;
 
 475         $locale->text('Bis') . " "
 
 476       . $locale->date(\%myconfig, $form->{dateto}, 1);
 
 479   @columns = $form->sort_columns( qw(
 
 480        transdate       id                reference         description  
 
 481        notes           source            debit             debit_accno  
 
 482        credit          credit_accno      debit_tax         debit_tax_accno
 
 483        credit_tax      credit_tax_accno  accno             gifi_accno
 
 488   if ($form->{accno} || $form->{gifi_accno}) {
 
 489     @columns = grep !/(accno|gifi_accno)/, @columns;
 
 490     push @columns, "balance";
 
 491     $form->{l_balance} = "Y";
 
 495   $form->{l_credit_accno}     = "Y";
 
 496   $form->{l_debit_accno}      = "Y";
 
 497   $form->{l_credit_tax}       = "Y";
 
 498   $form->{l_debit_tax}        = "Y";
 
 499   $form->{l_credit_tax_accno} = "Y";
 
 500   $form->{l_debit_tax_accno}  = "Y";
 
 501   $form->{l_accno}            = "N";
 
 502   foreach $item (@columns) {
 
 503     if ($form->{"l_$item"} eq "Y") {
 
 504       push @column_index, $item;
 
 506       # add column to href and callback
 
 507       $callback .= "&l_$item=Y";
 
 508       $href     .= "&l_$item=Y";
 
 512   if ($form->{l_subtotal} eq 'Y') {
 
 513     $callback .= "&l_subtotal=Y";
 
 514     $href     .= "&l_subtotal=Y";
 
 517   $callback .= "&category=$form->{category}";
 
 518   $href     .= "&category=$form->{category}";
 
 521       "<th><a class=listheading href=$href&sort=id>"
 
 522     . $locale->text('ID')
 
 524   $column_header{transdate} =
 
 525       "<th><a class=listheading href=$href&sort=transdate>"
 
 526     . $locale->text('Date')
 
 528   $column_header{reference} =
 
 529       "<th><a class=listheading href=$href&sort=reference>"
 
 530     . $locale->text('Reference')
 
 532   $column_header{source} =
 
 533       "<th><a class=listheading href=$href&sort=source>"
 
 534     . $locale->text('Source')
 
 536   $column_header{description} =
 
 537       "<th><a class=listheading href=$href&sort=description>"
 
 538     . $locale->text('Description')
 
 540   $column_header{notes} =
 
 541     "<th class=listheading>" . $locale->text('Notes') . "</th>";
 
 542   $column_header{debit} =
 
 543     "<th class=listheading>" . $locale->text('Debit') . "</th>";
 
 544   $column_header{debit_accno} =
 
 545       "<th><a class=listheading href=$href&sort=accno>"
 
 546     . $locale->text('Debit Account')
 
 548   $column_header{credit} =
 
 549     "<th class=listheading>" . $locale->text('Credit') . "</th>";
 
 550   $column_header{credit_accno} =
 
 551       "<th><a class=listheading href=$href&sort=accno>"
 
 552     . $locale->text('Credit Account')
 
 554   $column_header{debit_tax} =
 
 555       "<th><a class=listheading href=$href&sort=accno>"
 
 556     . $locale->text('Debit Tax')
 
 558   $column_header{debit_tax_accno} =
 
 559       "<th><a class=listheading href=$href&sort=accno>"
 
 560     . $locale->text('Debit Tax Account')
 
 562   $column_header{credit_tax} =
 
 563       "<th><a class=listheading href=$href&sort=accno>"
 
 564     . $locale->text('Credit Tax')
 
 566   $column_header{credit_tax_accno} =
 
 567       "<th><a class=listheading href=$href&sort=accno>"
 
 568     . $locale->text('Credit Tax Account')
 
 570   $column_header{gifi_accno} =
 
 571       "<th><a class=listheading href=$href&sort=gifi_accno>"
 
 572     . $locale->text('GIFI')
 
 574   $column_header{balance} = "<th>" . $locale->text('Balance') . "</th>";
 
 575   $column_header{projectnumbers} =
 
 576       "<th class=listheading>"  . $locale->text('Project Numbers') . "</th>";
 
 578   $form->{landscape} = 1;
 
 587     <th class=listtop>$form->{title}</th>
 
 597         <tr class=listheading>
 
 600   map { print "$column_header{$_}\n" } @column_index;
 
 609   # add sort to callback
 
 610   $form->{callback} = "$callback&sort=$form->{sort}";
 
 611   $callback = $form->escape($form->{callback});
 
 613   # initial item for subtotals
 
 614   if (@{ $form->{GL} }) {
 
 615     $sameitem = $form->{GL}->[0]->{ $form->{sort} };
 
 618   if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
 
 620     map { $column_data{$_} = "<td> </td>" } @column_index;
 
 621     $column_data{balance} =
 
 623       . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
 
 631     map { print "$column_data{$_}\n" } @column_index;
 
 637   $form->{balance} *= $ml;
 
 638   foreach $ref (@{ $form->{GL} }) {
 
 639     $form->{balance} *= $ml;
 
 641     # if item ne sort print subtotal
 
 642     if ($form->{l_subtotal} eq 'Y') {
 
 643       if ($sameitem ne $ref->{ $form->{sort} }) {
 
 648     #foreach $key (sort keys(%{ $ref->{amount} })) {
 
 649     #  $form->{balance} += $ref->{amount}{$key};
 
 653     foreach $key (sort keys(%{ $ref->{debit} })) {
 
 654       $subtotaldebit += $ref->{debit}{$key};
 
 655       $totaldebit    += $ref->{debit}{$key};
 
 657         $debit = $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 660           "<br>" . $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 662       $form->{balance} = abs($form->{balance}) - abs($ref->{debit}{$key});
 
 666     foreach $key (sort keys(%{ $ref->{credit} })) {
 
 667       $subtotalcredit += $ref->{credit}{$key};
 
 668       $totalcredit    += $ref->{credit}{$key};
 
 670         $credit = $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 673           . $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 675       $form->{balance} = abs($form->{balance}) - abs($ref->{credit}{$key});
 
 679     foreach $key (sort keys(%{ $ref->{debit_tax} })) {
 
 680       $subtotaldebittax += $ref->{debit_tax}{$key};
 
 681       $totaldebittax    += $ref->{debit_tax}{$key};
 
 684           $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 687           . $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 689       $form->{balance} = abs($form->{balance}) - abs($ref->{debit_tax}{$key});
 
 693     foreach $key (sort keys(%{ $ref->{credit_tax} })) {
 
 694       $subtotalcredittax += $ref->{credit_tax}{$key};
 
 695       $totalcredittax    += $ref->{credit_tax}{$key};
 
 698           $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 701           . $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 703       $form->{balance} = abs($form->{balance}) - abs($ref->{credit_tax}{$key});
 
 709     foreach $key (sort keys(%{ $ref->{debit_accno} })) {
 
 712           "<a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 715           "<br><a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 718       #       if ($ref->{debit_taxkey}{$key} eq $debittaxkey) {
 
 719       #         $ref->{debit_tax_accno}{$key} = $taxaccno;
 
 721       $taxaccno    = $ref->{debit_tax_accno}{$key};
 
 722       $debittaxkey = $ref->{debit_taxkey}{$key};
 
 728     foreach $key (sort keys(%{ $ref->{credit_accno} })) {
 
 731           "<a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 734           "<br><a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 737       #       if ($ref->{credit_taxkey}{$key} eq $credittaxkey) {
 
 738       #         $ref->{credit_tax_accno}{$key} = $taxaccno;
 
 740       $taxaccno     = $ref->{credit_tax_accno}{$key};
 
 741       $credittaxkey = $ref->{credit_taxkey}{$key};
 
 745     foreach $key (sort keys(%{ $ref->{debit_tax_accno} })) {
 
 748           "<a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 751           "<br><a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 755     $credittaxaccno = "";
 
 756     foreach $key (sort keys(%{ $ref->{credit_tax_accno} })) {
 
 759           "<a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 762           "<br><a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 767     foreach $key (sort keys(%{ $ref->{transdate} })) {
 
 769         $transdate = "$ref->{transdate}{$key}";
 
 771         $transdate .= "<br>$ref->{transdate}{$key}";
 
 775     #    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
 
 776     #    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
 
 778     $column_data{id}        = "<td align=right> $ref->{id} </td>";
 
 779     $column_data{transdate}    = "<td align=center>$transdate</td>";
 
 780     $column_data{reference} =
 
 781       "<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>";
 
 782     $column_data{description}  = "<td align=center>$ref->{description} </td>";
 
 783     $column_data{source}       = "<td align=center>$ref->{source} </td>";
 
 784     $column_data{notes}        = "<td align=center>$ref->{notes} </td>";
 
 785     $column_data{debit}        = "<td align=right>$debit</td>";
 
 786     $column_data{debit_accno}  = "<td align=center>$debitaccno</td>";
 
 787     $column_data{credit}       = "<td align=right>$credit</td>";
 
 788     $column_data{credit_accno} = "<td align=center>$creditaccno</td>";
 
 789     $column_data{debit_tax}    =
 
 790       ($ref->{debit_tax_accno} ne "")
 
 791       ? "<td align=right>$debittax</td>"
 
 793     $column_data{debit_tax_accno} = "<td align=center>$debittaxaccno</td>";
 
 794     $column_data{gifi_accno}      =
 
 795       "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";
 
 796     $column_data{credit_tax} =
 
 797       ($ref->{credit_tax_accno} ne "")
 
 798       ? "<td align=right>$credittax</td>"
 
 800     $column_data{credit_tax_accno} = "<td align=center>$credittaxaccno</td>";
 
 801     $column_data{gifi_accno}       =
 
 802       "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";
 
 803     $column_data{balance} =
 
 805       . $form->format_amount(\%myconfig, $form->{balance}, 2, 0) . "</td>";
 
 806     $column_data{projectnumbers} =
 
 807       "<td>" . join(", ", sort({ lc($a) cmp lc($b) } keys(%{ $ref->{projectnumbers} }))) . "</td>";
 
 812         <tr class=listrow$i>";
 
 813     map { print "$column_data{$_}\n" } @column_index;
 
 818   &gl_subtotal if ($form->{l_subtotal} eq 'Y');
 
 820   map { $column_data{$_} = "<td> </td>" } @column_index;
 
 822   my $balanced_ledger = $totaldebit 
 
 826                     # = 0 for balanced ledger
 
 828   $column_data{debit} =
 
 829     "<th align=right class=listtotal>"
 
 830     . $form->format_amount(\%myconfig, $totaldebit, 2, " ") . "</th>";
 
 831   $column_data{credit} =
 
 832     "<th align=right class=listtotal>"
 
 833     . $form->format_amount(\%myconfig, $totalcredit, 2, " ") . "</th>";
 
 834   $column_data{debit_tax} =
 
 835     "<th align=right class=listtotal>"
 
 836     . $form->format_amount(\%myconfig, $totaldebittax, 2, " ") . "</th>";
 
 837   $column_data{credit_tax} =
 
 838     "<th align=right class=listtotal>"
 
 839     . $form->format_amount(\%myconfig, $totalcredittax, 2, " ") . "</th>";
 
 840   $column_data{balance} =
 
 841     "<th align=right class=listtotal>"
 
 842     . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0) . "</th>";
 
 848   map { print "$column_data{$_}\n" } @column_index;
 
 855   if ( abs($balanced_ledger) >  0.001 ) {
 
 857     print qq|<td colspan="4" style="background-color:#FFA0A0" >|
 
 858         . $locale->text('Unbalanced Ledger') 
 
 860         . $form->format_amount(\%myconfig, $balanced_ledger, 3, " ")
 
 862   } elsif ( abs($balanced_ledger) <= 0.001 ) {
 
 864     print qq|<td colspan="3">|
 
 865           . $locale->text('Balanced Ledger') 
 
 878     <td><hr size=3 noshade></td>
 
 884 <form method=post action=$form->{script}>
 
 886 <input name=callback type=hidden value="$form->{callback}">
 
 888 <input type=hidden name=path value=$form->{path}>
 
 889 <input type=hidden name=login value=$form->{login}>
 
 890 <input type=hidden name=password value=$form->{password}>
 
 892 <input class=submit type=submit name=action value="|
 
 893     . $locale->text('GL Transaction') . qq|">
 
 894 <input class=submit type=submit name=action value="|
 
 895     . $locale->text('AR Transaction') . qq|">
 
 896 <input class=submit type=submit name=action value="|
 
 897     . $locale->text('AP Transaction') . qq|">
 
 898 <input class=submit type=submit name=action value="|
 
 899     . $locale->text('Sales Invoice') . qq|">
 
 900 <input class=submit type=submit name=action value="|
 
 901     . $locale->text('Vendor Invoice') . qq|">
 
 908   $lxdebug->leave_sub();
 
 913   $lxdebug->enter_sub();
 
 916     $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
 
 918     $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
 
 920   map { $column_data{$_} = "<td> </td>" }
 
 921     qw(transdate id reference source description accno);
 
 922   $column_data{debit}  = "<th align=right>$subtotaldebit</td>";
 
 923   $column_data{credit} = "<th align=right>$subtotalcredit</td>";
 
 925   print "<tr class=listsubtotal>";
 
 926   map { print "$column_data{$_}\n" } @column_index;
 
 932   $sameitem = $ref->{ $form->{sort} };
 
 933   $lxdebug->leave_sub();
 
 938   $lxdebug->enter_sub();
 
 940   $form->{oldtransdate} = $form->{transdate};
 
 952     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
 954   for my $i (1 .. $form->{rowcount}) {
 
 956     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
 957       for (qw(debit credit tax)) {
 
 959           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
 963       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
 970       if (($debitcount >= 2) && ($creditcount == 2)) {
 
 971         $form->{"credit_$i"} = 0;
 
 972         $form->{"tax_$i"}    = 0;
 
 976       if (($creditcount >= 2) && ($debitcount == 2)) {
 
 977         $form->{"debit_$i"} = 0;
 
 978         $form->{"tax_$i"}   = 0;
 
 982       if (($creditcount == 1) && ($debitcount == 2)) {
 
 985       if (($creditcount == 2) && ($debitcount == 1)) {
 
 988       if ($debitcredit && $credittax) {
 
 989         $form->{"taxchart_$i"} = "0--0.00";
 
 991       if (!$debitcredit && $debittax) {
 
 992         $form->{"taxchart_$i"} = "0--0.00";
 
 995         ($form->{"debit_$i"} == 0)
 
 996         ? $form->{"credit_$i"}
 
 997         : $form->{"debit_$i"};
 
 999       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1000         $form->{"taxchart_$i"} = "0--0.00";
 
1001         $form->{"tax_$i"}      = 0;
 
1003       if (!$form->{"korrektur_$i"}) {
 
1004         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1011           if ($form->{taxincluded}) {
 
1012             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1014             $form->{"tax_$i"} = $amount * $rate;
 
1017           $form->{"tax_$i"} = 0;
 
1021       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1026   for $i (1 .. $count) {
 
1028     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1031   for $i ($count + 1 .. $form->{rowcount}) {
 
1032     for (@flds) { delete $form->{"${_}_$i"} }
 
1035   $form->{rowcount} = $count + 1;
 
1038   $lxdebug->leave_sub();
 
1044   $lxdebug->enter_sub();
 
1046   &form_header($init);
 
1048   #   for $i (1 .. $form->{rowcount}) {
 
1049   #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
 
1050   #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
 
1054   &display_rows($init);
 
1056   $lxdebug->leave_sub();
 
1062   $lxdebug->enter_sub();
 
1064   $form->{totaldebit}  = 0;
 
1065   $form->{totalcredit} = 0;
 
1067   my @old_project_ids = ();
 
1068   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
1069           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
1071   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1073                                    "old_id" => \@old_project_ids },
 
1074                    "charts" => { "key" => "ALL_CHARTS",
 
1075                                  "transdate" => $form->{transdate} },
 
1076                    "taxcharts" => "ALL_TAXCHARTS");
 
1078   my %project_labels = ();
 
1079   my @project_values = ("");
 
1080   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1081     push(@project_values, $item->{"id"});
 
1082     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
1085   my %chart_labels = ();
 
1086   my @chart_values = ();
 
1088   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
1089     my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
 
1090     $taxchart_init = $item->{taxkey_id} unless (@chart_values);
 
1091     push(@chart_values, $key);
 
1092     $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
 
1095   my %taxchart_labels = ();
 
1096   my @taxchart_values = ();
 
1097   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
1098     my $key = Q($item->{id}) . "--" . Q($item->{rate});
 
1099     $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
 
1100     push(@taxchart_values, $key);
 
1101     $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
 
1102       H($item->{rate} * 100) . ' %';
 
1105   for $i (1 .. $form->{rowcount}) {
 
1108     <td><input name="source_$i" value="$form->{"source_$i"}" size="16" tabindex=|
 
1109       . ($i + 11 + (($i - 1) * 8)) . qq|></td>|;
 
1111     <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16" tabindex=|
 
1112       . ($i + 12 + (($i - 1) * 8)) . qq|></td>|;
 
1115       $cgi->popup_menu('-name' => "accno_$i",
 
1116                        '-onChange' => "setTaxkey(this, $i)",
 
1117                        '-style' => 'width:200px',
 
1118                        '-tabindex' => ($i + 5 + (($i - 1) * 8)),
 
1119                        '-values' => \@chart_values,
 
1120                        '-labels' => \%chart_labels,
 
1121                        '-default' => $init ? '' : $form->{"accno_$i"})
 
1124       $cgi->popup_menu('-name' => "taxchart_$i",
 
1125                        '-style' => 'width:200px',
 
1126                        '-tabindex' => ($i + 10 + (($i - 1) * 8)),
 
1127                        '-values' => \@taxchart_values,
 
1128                        '-labels' => \%taxchart_labels,
 
1129                        '-default' => $init ? $taxchart_init : $form->{"taxchart_$i"})
 
1134         qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
 
1135         . ($i + 9 + (($i - 1) * 8))
 
1137       if ($form->{transfer}) {
 
1138         $fx_transaction = qq|
 
1139         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1144       if ($form->{"debit_$i"} != 0) {
 
1145         $form->{totaldebit} += $form->{"debit_$i"};
 
1146         if (!$form->{taxincluded}) {
 
1147           $form->{totaldebit} += $form->{"tax_$i"};
 
1150         $form->{totalcredit} += $form->{"credit_$i"};
 
1151         if (!$form->{taxincluded}) {
 
1152           $form->{totalcredit} += $form->{"tax_$i"};
 
1156       for (qw(debit credit tax)) {
 
1157         $form->{"${_}_$i"} =
 
1158           ($form->{"${_}_$i"})
 
1159           ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
 
1163       if ($i < $form->{rowcount}) {
 
1164         if ($form->{transfer}) {
 
1165           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
 
1166           $x = ($checked) ? "x" : "";
 
1167           $fx_transaction = qq|
 
1168       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
 
1171         $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
 
1173           qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked tabindex=|
 
1174           . ($i + 9 + (($i - 1) * 8))
 
1176         $form->hide_form("accno_$i");
 
1180           qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
 
1181           . ($i + 9 + (($i - 1) * 8))
 
1183         if ($form->{transfer}) {
 
1184           $fx_transaction = qq|
 
1185       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1190     my $debitreadonly  = "";
 
1191     my $creditreadonly = "";
 
1192     if ($i == $form->{rowcount}) {
 
1194         $debitreadonly = "readonly";
 
1195       } elsif ($creditlock) {
 
1196         $creditreadonly = "readonly";
 
1201       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
1202                            '-values' => \@project_values,
 
1203                            '-labels' => \%project_labels,
 
1204                            '-default' => $form->{"project_id_$i"} ));
 
1206     print qq|<tr valign=top>
 
1209     <td><input name="debit_$i" size=8 value="$form->{"debit_$i"}" accesskey=$i tabindex=|
 
1210       . ($i + 6 + (($i - 1) * 8)) . qq| $debitreadonly></td>
 
1211     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" tabindex=|
 
1212       . ($i + 7 + (($i - 1) * 8)) . qq| $creditreadonly></td>
 
1213     <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}" tabindex=|
 
1214       . ($i + 8 + (($i - 1) * 8)) . qq|></td>
 
1219     <td>$projectnumber</td>
 
1225   $form->hide_form(qw(rowcount selectaccno));
 
1227   $lxdebug->leave_sub();
 
1233   $lxdebug->enter_sub();
 
1234   $title         = $form->{title};
 
1235   $form->{title} = $locale->text("$title General Ledger Transaction");
 
1236   $readonly      = ($form->{id}) ? "readonly" : "";
 
1238   # $locale->text('Add General Ledger Transaction')
 
1239   # $locale->text('Edit General Ledger Transaction')
 
1241   map { $form->{$_} =~ s/\"/"/g }
 
1242     qw(reference description chart taxchart);
 
1243   $form->{javascript} = qq|<script type="text/javascript">
 
1245   function setTaxkey(accno, row) {
 
1246     var taxkey = accno.options[accno.selectedIndex].value;
 
1247     var reg = /--([0-9]*)/;
 
1248     var found = reg.exec(taxkey);
 
1249     var index = found[1];
 
1250     index = parseInt(index);
 
1251     var tax = 'taxchart_' + row;
 
1252     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
1253       var reg2 = new RegExp("^"+ index, "");
 
1254       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
1255         document.getElementById(tax).options[i].selected = true;
 
1263   $form->{selectdepartment} =~ s/ selected//;
 
1264   $form->{selectdepartment} =~
 
1265     s/option>\Q$form->{department}\E/option selected>$form->{department}/;
 
1267   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
 
1269       qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
 
1272       qq|<input name=description size=50 value="$form->{description}" tabindex="3" $readonly>|;
 
1275   $taxincluded = ($form->{taxincluded}) ? "checked" : "";
 
1278     $taxincluded = "checked";
 
1283           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1284           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1285           <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
1287 | if $form->{selectdepartment};
 
1289     $form->{fokus} = "gl.reference";
 
1291     $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
 
1294   # use JavaScript Calendar or not
 
1295   $form->{jsscript} = $jscalendar;
 
1297   if ($form->{jsscript}) {
 
1299     # with JavaScript Calendar
 
1301        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" tabindex="2" $readonly>
 
1302        <input type=button name=transdate id="trigger1" value=|
 
1303       . $locale->text('button') . qq|></td>  
 
1308       Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
 
1311     # without JavaScript Calendar
 
1313       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" tabindex="2" $readonly></td>|;
 
1319 <body onLoad="fokus()">
 
1321 <form method=post name="gl" action=$form->{script}>
 
1323 <input name=id type=hidden value=$form->{id}>
 
1325 <input type=hidden name=closedto value=$form->{closedto}>
 
1326 <input type=hidden name=locked value=$form->{locked}>
 
1327 <input type=hidden name=title value="$title">
 
1332     <th class=listtop>$form->{title}</th>
 
1334   <tr height="5"></tr>
 
1339           <th align=left>| . $locale->text('Reference') . qq|</th>
 
1340           <td><input name=reference size=20 value="$form->{reference}" tabindex="1" $readonly></td>
 
1344                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
 
1353           <th align=right>| . $locale->text('Belegnummer') . qq|</th>
 
1354           <td><input name=id size=20 value="$form->{id}" $readonly></td>
 
1358                 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
 
1359                 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly></td>
 
1370           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1371           <td width=1%>$description</td>
 
1375                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1376                 <td><input type=checkbox name=taxincluded value=1 tabindex="5" $taxincluded></td>
 
1383                 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
 
1384                 <td align=left><input name=employee size=11  value=$form->{employee} $readonly></td>
 
1392           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1393           <td width=1%>$description</td>
 
1397                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1398                 <td><input type=checkbox name=taxincluded value=1 tabindex="5" $taxincluded></td>
 
1408            <tr class=listheading>
 
1409           <th class=listheading style="width:15%">|
 
1410     . $locale->text('Account') . qq|</th>
 
1411           <th class=listheading style="width:10%">|
 
1412     . $locale->text('Debit') . qq|</th>
 
1413           <th class=listheading style="width:10%">|
 
1414     . $locale->text('Credit') . qq|</th>
 
1415           <th class=listheading style="width:10%">|
 
1416     . $locale->text('Tax') . qq|</th>
 
1417           <th class=listheading style="width:5%">|
 
1418     . $locale->text('Korrektur') . qq|</th>
 
1419           <th class=listheading style="width:10%">|
 
1420     . $locale->text('Taxkey') . qq|</th>
 
1421           <th class=listheading style="width:20%">|
 
1422     . $locale->text('Source') . qq|</th>
 
1423           <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
 
1424           <th class=listheading style="width:20%">|
 
1425     . $locale->text('Project Number') . qq|</th>
 
1430   $lxdebug->leave_sub();
 
1435   $lxdebug->enter_sub();
 
1436   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
 
1438   $decimalplaces = ($dec > 2) ? $dec : 2;
 
1439   $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
1443       $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
 
1444   } qw(totaldebit totalcredit);
 
1447     <tr class=listtotal>
 
1449     <th align=right class=listtotal> $form->{totaldebit}</th>
 
1450     <th align=right class=listtotal> $form->{totalcredit}</th> 
 
1458 <input type=hidden name=path value=$form->{path}>
 
1459 <input type=hidden name=login value=$form->{login}>
 
1460 <input type=hidden name=password value=$form->{password}>
 
1462 <input name=callback type=hidden value="$form->{callback}">
 
1467   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1468   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1472     print qq|<input class=submit type=submit name=action value="|
 
1473       . $locale->text('Storno') . qq|">|;
 
1475     # Löschen und Ã„ndern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
 
1477     if (!$form->{locked} && $radieren) {
 
1479                 <input class=submit type=submit name=action value="|
 
1480         . $locale->text('Post') . qq|" accesskey="b">
 
1481                 <input class=submit type=submit name=action value="|
 
1482         . $locale->text('Delete') . qq|">|;
 
1485     #   if ($transdate > $closedto) {
 
1487     #           <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">|;
 
1490     if ($transdate > $closedto) {
 
1491       print qq|<input class=submit type=submit name=action value="|
 
1492         . $locale->text('Update') . qq|">
 
1493                  <input class=submit type=submit name=action value="|
 
1494         . $locale->text('Post') . qq|">|;
 
1504   $lxdebug->leave_sub();
 
1509   $lxdebug->enter_sub();
 
1516 <form method=post action=$form->{script}>
 
1519   map { $form->{$_} =~ s/\"/"/g } qw(reference description);
 
1521   delete $form->{header};
 
1523   foreach $key (keys %$form) {
 
1524     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1528 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1531     . $locale->text('Are you sure you want to delete Transaction')
 
1532     . qq| $form->{reference}</h4>
 
1534 <input name=action class=submit type=submit value="|
 
1535     . $locale->text('Yes') . qq|">
 
1538   $lxdebug->leave_sub();
 
1543   $lxdebug->enter_sub();
 
1544   if (GL->delete_transaction(\%myconfig, \%$form)){
 
1545     # saving the history
 
1546       if(!exists $form->{addition} && $form->{id} ne "") {
 
1547             $form->{addition} = "DELETED";
 
1548             $form->save_history($form->dbconnect(\%myconfig));
 
1550     # /saving the history 
 
1551     $form->redirect($locale->text('Transaction deleted!'))
 
1553   $form->error($locale->text('Cannot delete transaction!'));
 
1554   $lxdebug->leave_sub();
 
1559   $lxdebug->enter_sub();
 
1561   # check if there is something in reference and date
 
1562   $form->isblank("reference",   $locale->text('Reference missing!'));
 
1563   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
 
1564   $form->isblank("description", $locale->text('Description missing!'));
 
1566   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1567   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1574   my $creditcount = 0;
 
1579     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
1580   if ($form->{storno}) {
 
1581     for my $i (1 .. $form->{rowcount}) {
 
1582       unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1583         if ($form->{"debit_$i"} ne "") {
 
1584           $form->{"credit_$i"} = $form->{"debit_$i"};
 
1585           $form->{"debit_$i"}  = "";
 
1586         } elsif ($form->{"credit_$i"} ne "") {
 
1587           $form->{"debit_$i"}  = $form->{"credit_$i"};
 
1588           $form->{"credit_$i"} = "";
 
1594   for my $i (1 .. $form->{rowcount}) {
 
1596     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1597       for (qw(debit credit tax)) {
 
1598         $form->{"${_}_$i"} =
 
1599           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
1603       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
1611       if (($debitcount >= 2) && ($creditcount == 2)) {
 
1612         $form->{"credit_$i"} = 0;
 
1613         $form->{"tax_$i"}    = 0;
 
1617       if (($creditcount >= 2) && ($debitcount == 2)) {
 
1618         $form->{"debit_$i"} = 0;
 
1619         $form->{"tax_$i"}   = 0;
 
1623       if (($creditcount == 1) && ($debitcount == 2)) {
 
1626       if (($creditcount == 2) && ($debitcount == 1)) {
 
1629       if ($debitcredit && $credittax) {
 
1630         $form->{"taxchart_$i"} = "0--0.00";
 
1632       if (!$debitcredit && $debittax) {
 
1633         $form->{"taxchart_$i"} = "0--0.00";
 
1636         ($form->{"debit_$i"} == 0)
 
1637         ? $form->{"credit_$i"}
 
1638         : $form->{"debit_$i"};
 
1640       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1641         $form->{"taxchart_$i"} = "0--0.00";
 
1642         $form->{"tax_$i"}      = 0;
 
1644       if (!$form->{"korrektur_$i"}) {
 
1645         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1652           if ($form->{taxincluded}) {
 
1653             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1655               $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1657               $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1660             $form->{"tax_$i"} = $amount * $rate;
 
1663           $form->{"tax_$i"} = 0;
 
1665       } elsif ($form->{taxincluded}) {
 
1667           $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1669           $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1673       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1678   for $i (1 .. $count) {
 
1680     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1683   for $i ($count + 1 .. $form->{rowcount}) {
 
1684     for (@flds) { delete $form->{"${_}_$i"} }
 
1687   for $i (1 .. $form->{rowcount}) {
 
1688     $dr  = $form->{"debit_$i"};
 
1689     $cr  = $form->{"credit_$i"};
 
1690     $tax = $form->{"tax_$i"};
 
1694           'Cannot post transaction with a debit and credit entry for the same account!'
 
1697     if ($form->{taxincluded}) {
 
1699         $debit += $dr + $tax;
 
1702         $credit += $cr + $tax;
 
1707         $debit += $dr + $tax;
 
1710         $credit += $cr + $tax;
 
1715     $form->{taxincluded} = 0;
 
1718   # this is just for the wise guys
 
1719   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
1720     if ($transdate <= $closedto);
 
1721   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
 
1722     $form->error($locale->text('Out of balance transaction!'));
 
1725   if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
 
1726     $form->error($locale->text('Empty transaction!'));
 
1729   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
 
1731     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
 
1732     $err[2] = $locale->text('Debit and credit out of balance!');
 
1733     $err[3] = $locale->text('Cannot post a transaction without a value!');
 
1735     $form->error($err[$errno]);
 
1737   undef($form->{callback});
 
1738   # saving the history
 
1739   if(!exists $form->{addition} && $form->{id} ne "") {
 
1740         $form->{addition} = "SAVED";
 
1741         $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; 
 
1742         $form->save_history($form->dbconnect(\%myconfig));
 
1744   # /saving the history 
 
1745   $form->redirect("Buchung gespeichert. Buchungsnummer = " . $form->{id});
 
1746   $lxdebug->leave_sub();
 
1751   $lxdebug->enter_sub();
 
1755   $lxdebug->leave_sub();
 
1760   $lxdebug->enter_sub();
 
1763   $form->{storno} = 1;
 
1764   # saving the history
 
1765   if(!exists $form->{addition} && $form->{id} ne "") {
 
1766         $form->{addition} = "STORNO";
 
1767         $form->save_history($form->dbconnect(\%myconfig));
 
1769   # /saving the history 
 
1771   $lxdebug->leave_sub();