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"};
 
 151       $form->{"project_id_$j"} = $ref->{project_id};
 
 154       $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
 
 155       for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
 
 156       if ($ref->{amount} < 0) {
 
 157         $form->{totaldebit} -= $ref->{amount};
 
 158         $form->{"debit_$i"} = $ref->{amount} * -1;
 
 160         $form->{totalcredit} += $ref->{amount};
 
 161         $form->{"credit_$i"} = $ref->{amount};
 
 163       $form->{"taxchart_$i"} = "0--0.00";
 
 164       $form->{"project_id_$i"} = $ref->{project_id};
 
 167     if ($ref->{taxaccno} && !$tax) {
 
 168       $taxaccno = $ref->{taxaccno};
 
 176   $form->{rowcount} = $i;
 
 178     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 179      $form->datetonum($form->{closedto}, \%myconfig));
 
 181   $form->{title} = "Edit";
 
 186   $lxdebug->leave_sub();
 
 191   $lxdebug->enter_sub();
 
 193   $form->{title} = $locale->text('Buchungsjournal');
 
 195   $form->all_departments(\%myconfig);
 
 198   if (@{ $form->{all_departments} }) {
 
 199     $form->{selectdepartment} = "<option>\n";
 
 202       $form->{selectdepartment} .=
 
 203         "<option>$_->{description}--$_->{id}\n"
 
 204     } (@{ $form->{all_departments} });
 
 209           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 210           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 212 | if $form->{selectdepartment};
 
 214   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 217   my %project_labels = ();
 
 218   my @project_values = ("");
 
 219   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 220     push(@project_values, $item->{"id"});
 
 221     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 225     NTI($cgi->popup_menu('-name' => "project_id",
 
 226                          '-values' => \@project_values,
 
 227                          '-labels' => \%project_labels));
 
 229   # use JavaScript Calendar or not
 
 230   $form->{jsscript} = $jscalendar;
 
 232   if ($form->{jsscript}) {
 
 234     # with JavaScript Calendar
 
 236        <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}">
 
 237        <input type=button name=datefrom id="trigger1" value=|
 
 238       . $locale->text('button') . qq|></td>  
 
 241        <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}">
 
 242        <input type=button name=dateto id="trigger2" value=|
 
 243       . $locale->text('button') . qq|></td>
 
 248       Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
 
 249                           "dateto", "BL", "trigger2");
 
 252     # without JavaScript Calendar
 
 254       qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}"></td>|;
 
 256       qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}"></td>|;
 
 264 <form method=post action=$form->{script}>
 
 266 <input type=hidden name=sort value=transdate>
 
 270     <th class=listtop>$form->{title}</th>
 
 277           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 278           <td><input name=reference size=20></td>
 
 279           <th align=right>| . $locale->text('Source') . qq|</th>
 
 280           <td><input name=source size=20></td>
 
 284           <th align=right>| . $locale->text('Description') . qq|</th>
 
 285           <td colspan=3><input name=description size=40></td>
 
 288           <th align=right>| . $locale->text('Notes') . qq|</th>
 
 289           <td colspan=3><input name=notes size=40></td>
 
 292           <th align=right>| . $locale->text('Project Number') . qq|</th>
 
 293           <td colspan=3>$projectnumber</td>
 
 296           <th align=right>| . $locale->text('From') . qq|</th>
 
 298           <th align=right>| . $locale->text('To (time)') . qq|</th>
 
 302           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 307                   <input name="category" class=radio type=radio value=X checked> |
 
 308     . $locale->text('All') . qq|
 
 309                   <input name="category" class=radio type=radio value=A> |
 
 310     . $locale->text('Asset') . qq|
 
 311                   <input name="category" class=radio type=radio value=L> |
 
 312     . $locale->text('Liability') . qq|
 
 313                   <input name="category" class=radio type=radio value=I> |
 
 314     . $locale->text('Revenue') . qq|
 
 315                   <input name="category" class=radio type=radio value=E> |
 
 316     . $locale->text('Expense') . qq|
 
 322                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 323                     <td>| . $locale->text('ID') . qq|</td>
 
 324                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 325                     <td>| . $locale->text('Date') . qq|</td>
 
 326                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
 
 327                     <td>| . $locale->text('Reference') . qq|</td>
 
 328                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
 
 329                     <td>| . $locale->text('Description') . qq|</td>
 
 330                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
 331                     <td>| . $locale->text('Notes') . qq|</td>
 
 334                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
 
 335                     <td>| . $locale->text('Debit') . qq|</td>
 
 336                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
 
 337                     <td>| . $locale->text('Credit') . qq|</td>
 
 338                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
 
 339                     <td>| . $locale->text('Source') . qq|</td>
 
 340                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
 
 341                     <td>| . $locale->text('Account') . 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->{source}) {
 
 414     $href     .= "&source=" . $form->escape($form->{source});
 
 415     $callback .= "&source=" . $form->escape($form->{source}, 1);
 
 416     $option   .= "\n<br>" if $option;
 
 417     $option   .= $locale->text('Source') . " : $form->{source}";
 
 419   if ($form->{reference}) {
 
 420     $href     .= "&reference=" . $form->escape($form->{reference});
 
 421     $callback .= "&reference=" . $form->escape($form->{reference}, 1);
 
 422     $option   .= "\n<br>" if $option;
 
 423     $option   .= $locale->text('Reference') . " : $form->{reference}";
 
 425   if ($form->{department}) {
 
 426     $href .= "&department=" . $form->escape($form->{department});
 
 427     $callback .= "&department=" . $form->escape($form->{department}, 1);
 
 428     ($department) = split /--/, $form->{department};
 
 429     $option .= "\n<br>" if $option;
 
 430     $option .= $locale->text('Department') . " : $department";
 
 433   if ($form->{description}) {
 
 434     $href     .= "&description=" . $form->escape($form->{description});
 
 435     $callback .= "&description=" . $form->escape($form->{description}, 1);
 
 436     $option   .= "\n<br>" if $option;
 
 437     $option   .= $locale->text('Description') . " : $form->{description}";
 
 439   if ($form->{notes}) {
 
 440     $href     .= "¬es=" . $form->escape($form->{notes});
 
 441     $callback .= "¬es=" . $form->escape($form->{notes}, 1);
 
 442     $option   .= "\n<br>" if $option;
 
 443     $option   .= $locale->text('Notes') . " : $form->{notes}";
 
 445  if ($form->{project_id}) {
 
 446     $href     .= "&project_id=" . $form->escape($form->{project_id});
 
 447     $callback .= "&project_id=" . $form->escape($form->{project_id});
 
 450   if ($form->{datefrom}) {
 
 451     $href     .= "&datefrom=$form->{datefrom}";
 
 452     $callback .= "&datefrom=$form->{datefrom}";
 
 453     $option   .= "\n<br>" if $option;
 
 455         $locale->text('From') . " "
 
 456       . $locale->date(\%myconfig, $form->{datefrom}, 1);
 
 458   if ($form->{dateto}) {
 
 459     $href     .= "&dateto=$form->{dateto}";
 
 460     $callback .= "&dateto=$form->{dateto}";
 
 461     if ($form->{datefrom}) {
 
 464       $option .= "\n<br>" if $option;
 
 467         $locale->text('Bis') . " "
 
 468       . $locale->date(\%myconfig, $form->{dateto}, 1);
 
 471   @columns = $form->sort_columns( qw(
 
 472        transdate       id                reference         description  
 
 473        notes           source            debit             debit_accno  
 
 474        credit          credit_accno      debit_tax         debit_tax_accno
 
 475        credit_tax      credit_tax_accno  accno
 
 480   if ($form->{accno}) {
 
 481     @columns = grep !/accno/, @columns;
 
 482     push @columns, "balance";
 
 483     $form->{l_balance} = "Y";
 
 487   $form->{l_credit_accno}     = "Y";
 
 488   $form->{l_debit_accno}      = "Y";
 
 489   $form->{l_credit_tax}       = "Y";
 
 490   $form->{l_debit_tax}        = "Y";
 
 491   $form->{l_credit_tax_accno} = "Y";
 
 492   $form->{l_debit_tax_accno}  = "Y";
 
 493   $form->{l_accno}            = "N";
 
 494   foreach $item (@columns) {
 
 495     if ($form->{"l_$item"} eq "Y") {
 
 496       push @column_index, $item;
 
 498       # add column to href and callback
 
 499       $callback .= "&l_$item=Y";
 
 500       $href     .= "&l_$item=Y";
 
 504   if ($form->{l_subtotal} eq 'Y') {
 
 505     $callback .= "&l_subtotal=Y";
 
 506     $href     .= "&l_subtotal=Y";
 
 509   $callback .= "&category=$form->{category}";
 
 510   $href     .= "&category=$form->{category}";
 
 513       "<th><a class=listheading href=$href&sort=id>"
 
 514     . $locale->text('ID')
 
 516   $column_header{transdate} =
 
 517       "<th><a class=listheading href=$href&sort=transdate>"
 
 518     . $locale->text('Date')
 
 520   $column_header{reference} =
 
 521       "<th><a class=listheading href=$href&sort=reference>"
 
 522     . $locale->text('Reference')
 
 524   $column_header{source} =
 
 525       "<th><a class=listheading href=$href&sort=source>"
 
 526     . $locale->text('Source')
 
 528   $column_header{description} =
 
 529       "<th><a class=listheading href=$href&sort=description>"
 
 530     . $locale->text('Description')
 
 532   $column_header{notes} =
 
 533     "<th class=listheading>" . $locale->text('Notes') . "</th>";
 
 534   $column_header{debit} =
 
 535     "<th class=listheading>" . $locale->text('Debit') . "</th>";
 
 536   $column_header{debit_accno} =
 
 537       "<th><a class=listheading href=$href&sort=accno>"
 
 538     . $locale->text('Debit Account')
 
 540   $column_header{credit} =
 
 541     "<th class=listheading>" . $locale->text('Credit') . "</th>";
 
 542   $column_header{credit_accno} =
 
 543       "<th><a class=listheading href=$href&sort=accno>"
 
 544     . $locale->text('Credit Account')
 
 546   $column_header{debit_tax} =
 
 547       "<th><a class=listheading href=$href&sort=accno>"
 
 548     . $locale->text('Debit Tax')
 
 550   $column_header{debit_tax_accno} =
 
 551       "<th><a class=listheading href=$href&sort=accno>"
 
 552     . $locale->text('Debit Tax Account')
 
 554   $column_header{credit_tax} =
 
 555       "<th><a class=listheading href=$href&sort=accno>"
 
 556     . $locale->text('Credit Tax')
 
 558   $column_header{credit_tax_accno} =
 
 559       "<th><a class=listheading href=$href&sort=accno>"
 
 560     . $locale->text('Credit Tax Account')
 
 562   $column_header{balance} = "<th>" . $locale->text('Balance') . "</th>";
 
 563   $column_header{projectnumbers} =
 
 564       "<th class=listheading>"  . $locale->text('Project Numbers') . "</th>";
 
 566   $form->{landscape} = 1;
 
 575     <th class=listtop>$form->{title}</th>
 
 585         <tr class=listheading>
 
 588   map { print "$column_header{$_}\n" } @column_index;
 
 597   # add sort to callback
 
 598   $form->{callback} = "$callback&sort=$form->{sort}";
 
 599   $callback = $form->escape($form->{callback});
 
 601   # initial item for subtotals
 
 602   if (@{ $form->{GL} }) {
 
 603     $sameitem = $form->{GL}->[0]->{ $form->{sort} };
 
 606   if ($form->{accno} && $form->{balance}) {
 
 608     map { $column_data{$_} = "<td> </td>" } @column_index;
 
 609     $column_data{balance} =
 
 611       . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
 
 619     map { print "$column_data{$_}\n" } @column_index;
 
 625   $form->{balance} *= $ml;
 
 626   foreach $ref (@{ $form->{GL} }) {
 
 627     $form->{balance} *= $ml;
 
 629     # if item ne sort print subtotal
 
 630     if ($form->{l_subtotal} eq 'Y') {
 
 631       if ($sameitem ne $ref->{ $form->{sort} }) {
 
 636     #foreach $key (sort keys(%{ $ref->{amount} })) {
 
 637     #  $form->{balance} += $ref->{amount}{$key};
 
 641     foreach $key (sort keys(%{ $ref->{debit} })) {
 
 642       $subtotaldebit += $ref->{debit}{$key};
 
 643       $totaldebit    += $ref->{debit}{$key};
 
 645         $debit = $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 648           "<br>" . $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 650       $form->{balance} = abs($form->{balance}) - abs($ref->{debit}{$key});
 
 654     foreach $key (sort keys(%{ $ref->{credit} })) {
 
 655       $subtotalcredit += $ref->{credit}{$key};
 
 656       $totalcredit    += $ref->{credit}{$key};
 
 658         $credit = $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 661           . $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 663       $form->{balance} = abs($form->{balance}) - abs($ref->{credit}{$key});
 
 667     foreach $key (sort keys(%{ $ref->{debit_tax} })) {
 
 668       $subtotaldebittax += $ref->{debit_tax}{$key};
 
 669       $totaldebittax    += $ref->{debit_tax}{$key};
 
 672           $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 675           . $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 677       $form->{balance} = abs($form->{balance}) - abs($ref->{debit_tax}{$key});
 
 681     foreach $key (sort keys(%{ $ref->{credit_tax} })) {
 
 682       $subtotalcredittax += $ref->{credit_tax}{$key};
 
 683       $totalcredittax    += $ref->{credit_tax}{$key};
 
 686           $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 689           . $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 691       $form->{balance} = abs($form->{balance}) - abs($ref->{credit_tax}{$key});
 
 697     foreach $key (sort keys(%{ $ref->{debit_accno} })) {
 
 700           "<a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 703           "<br><a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 706       #       if ($ref->{debit_taxkey}{$key} eq $debittaxkey) {
 
 707       #         $ref->{debit_tax_accno}{$key} = $taxaccno;
 
 709       $taxaccno    = $ref->{debit_tax_accno}{$key};
 
 710       $debittaxkey = $ref->{debit_taxkey}{$key};
 
 716     foreach $key (sort keys(%{ $ref->{credit_accno} })) {
 
 719           "<a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 722           "<br><a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 725       #       if ($ref->{credit_taxkey}{$key} eq $credittaxkey) {
 
 726       #         $ref->{credit_tax_accno}{$key} = $taxaccno;
 
 728       $taxaccno     = $ref->{credit_tax_accno}{$key};
 
 729       $credittaxkey = $ref->{credit_taxkey}{$key};
 
 733     foreach $key (sort keys(%{ $ref->{debit_tax_accno} })) {
 
 736           "<a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 739           "<br><a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 743     $credittaxaccno = "";
 
 744     foreach $key (sort keys(%{ $ref->{credit_tax_accno} })) {
 
 747           "<a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 750           "<br><a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 755     foreach $key (sort keys(%{ $ref->{ac_transdate} })) {
 
 757         $transdate = "$ref->{ac_transdate}{$key}";
 
 759         $transdate .= "<br>$ref->{ac_transdate}{$key}";
 
 763     #    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
 
 764     #    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
 
 766     $column_data{id}        = "<td align=right> $ref->{id} </td>";
 
 767     $column_data{transdate}    = "<td align=center>$transdate</td>";
 
 768     $column_data{reference} =
 
 769       "<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>";
 
 770     $column_data{description}  = "<td align=center>$ref->{description} </td>";
 
 771     $column_data{source}       = "<td align=center>$ref->{source} </td>";
 
 772     $column_data{notes}        = "<td align=center>$ref->{notes} </td>";
 
 773     $column_data{debit}        = "<td align=right>$debit</td>";
 
 774     $column_data{debit_accno}  = "<td align=center>$debitaccno</td>";
 
 775     $column_data{credit}       = "<td align=right>$credit</td>";
 
 776     $column_data{credit_accno} = "<td align=center>$creditaccno</td>";
 
 777     $column_data{debit_tax}    =
 
 778       ($ref->{debit_tax_accno} ne "")
 
 779       ? "<td align=right>$debittax</td>"
 
 781     $column_data{debit_tax_accno} = "<td align=center>$debittaxaccno</td>";
 
 782     $column_data{credit_tax} =
 
 783       ($ref->{credit_tax_accno} ne "")
 
 784       ? "<td align=right>$credittax</td>"
 
 786     $column_data{credit_tax_accno} = "<td align=center>$credittaxaccno</td>";
 
 787     $column_data{balance} =
 
 789       . $form->format_amount(\%myconfig, $form->{balance}, 2, 0) . "</td>";
 
 790     $column_data{projectnumbers} =
 
 791       "<td>" . join(", ", sort({ lc($a) cmp lc($b) } keys(%{ $ref->{projectnumbers} }))) . "</td>";
 
 796         <tr class=listrow$i>";
 
 797     map { print "$column_data{$_}\n" } @column_index;
 
 802   &gl_subtotal if ($form->{l_subtotal} eq 'Y');
 
 804   map { $column_data{$_} = "<td> </td>" } @column_index;
 
 806   my $balanced_ledger = $totaldebit 
 
 810                     # = 0 for balanced ledger
 
 812   $column_data{debit} =
 
 813     "<th align=right class=listtotal>"
 
 814     . $form->format_amount(\%myconfig, $totaldebit, 2, " ") . "</th>";
 
 815   $column_data{credit} =
 
 816     "<th align=right class=listtotal>"
 
 817     . $form->format_amount(\%myconfig, $totalcredit, 2, " ") . "</th>";
 
 818   $column_data{debit_tax} =
 
 819     "<th align=right class=listtotal>"
 
 820     . $form->format_amount(\%myconfig, $totaldebittax, 2, " ") . "</th>";
 
 821   $column_data{credit_tax} =
 
 822     "<th align=right class=listtotal>"
 
 823     . $form->format_amount(\%myconfig, $totalcredittax, 2, " ") . "</th>";
 
 824   $column_data{balance} =
 
 825     "<th align=right class=listtotal>"
 
 826     . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0) . "</th>";
 
 832   map { print "$column_data{$_}\n" } @column_index;
 
 839   if ( abs($balanced_ledger) >  0.001 ) {
 
 841     print qq|<td colspan="4" style="background-color:#FFA0A0" >|
 
 842         . $locale->text('Unbalanced Ledger') 
 
 844         . $form->format_amount(\%myconfig, $balanced_ledger, 3, " ")
 
 846   } elsif ( abs($balanced_ledger) <= 0.001 ) {
 
 848     print qq|<td colspan="3">|
 
 849           . $locale->text('Balanced Ledger') 
 
 862     <td><hr size=3 noshade></td>
 
 868 <form method=post action=$form->{script}>
 
 870 <input name=callback type=hidden value="$form->{callback}">
 
 872 <input type=hidden name=path value=$form->{path}>
 
 873 <input type=hidden name=login value=$form->{login}>
 
 874 <input type=hidden name=password value=$form->{password}>
 
 876 <input class=submit type=submit name=action value="|
 
 877     . $locale->text('GL Transaction') . qq|">
 
 878 <input class=submit type=submit name=action value="|
 
 879     . $locale->text('AR Transaction') . qq|">
 
 880 <input class=submit type=submit name=action value="|
 
 881     . $locale->text('AP Transaction') . qq|">
 
 882 <input class=submit type=submit name=action value="|
 
 883     . $locale->text('Sales Invoice') . qq|">
 
 884 <input class=submit type=submit name=action value="|
 
 885     . $locale->text('Vendor Invoice') . qq|">
 
 892   $lxdebug->leave_sub();
 
 897   $lxdebug->enter_sub();
 
 900     $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
 
 902     $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
 
 904   map { $column_data{$_} = "<td> </td>" }
 
 905     qw(transdate id reference source description accno);
 
 906   $column_data{debit}  = "<th align=right>$subtotaldebit</td>";
 
 907   $column_data{credit} = "<th align=right>$subtotalcredit</td>";
 
 909   print "<tr class=listsubtotal>";
 
 910   map { print "$column_data{$_}\n" } @column_index;
 
 916   $sameitem = $ref->{ $form->{sort} };
 
 917   $lxdebug->leave_sub();
 
 922   $lxdebug->enter_sub();
 
 924   $form->{oldtransdate} = $form->{transdate};
 
 936     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
 938   for my $i (1 .. $form->{rowcount}) {
 
 940     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
 941       for (qw(debit credit tax)) {
 
 943           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
 947       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
 954       if (($debitcount >= 2) && ($creditcount == 2)) {
 
 955         $form->{"credit_$i"} = 0;
 
 956         $form->{"tax_$i"}    = 0;
 
 960       if (($creditcount >= 2) && ($debitcount == 2)) {
 
 961         $form->{"debit_$i"} = 0;
 
 962         $form->{"tax_$i"}   = 0;
 
 966       if (($creditcount == 1) && ($debitcount == 2)) {
 
 969       if (($creditcount == 2) && ($debitcount == 1)) {
 
 972       if ($debitcredit && $credittax) {
 
 973         $form->{"taxchart_$i"} = "0--0.00";
 
 975       if (!$debitcredit && $debittax) {
 
 976         $form->{"taxchart_$i"} = "0--0.00";
 
 979         ($form->{"debit_$i"} == 0)
 
 980         ? $form->{"credit_$i"}
 
 981         : $form->{"debit_$i"};
 
 983       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
 984         $form->{"taxchart_$i"} = "0--0.00";
 
 985         $form->{"tax_$i"}      = 0;
 
 987       if (!$form->{"korrektur_$i"}) {
 
 988         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
 995           if ($form->{taxincluded}) {
 
 996             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
 998             $form->{"tax_$i"} = $amount * $rate;
 
1001           $form->{"tax_$i"} = 0;
 
1005       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1010   for $i (1 .. $count) {
 
1012     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1015   for $i ($count + 1 .. $form->{rowcount}) {
 
1016     for (@flds) { delete $form->{"${_}_$i"} }
 
1019   $form->{rowcount} = $count + 1;
 
1022   $lxdebug->leave_sub();
 
1028   $lxdebug->enter_sub();
 
1030   &form_header($init);
 
1032   #   for $i (1 .. $form->{rowcount}) {
 
1033   #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
 
1034   #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
 
1038   &display_rows($init);
 
1040   $lxdebug->leave_sub();
 
1046   $lxdebug->enter_sub();
 
1048   $form->{totaldebit}  = 0;
 
1049   $form->{totalcredit} = 0;
 
1051   my @old_project_ids = ();
 
1052   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
1053           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
1055   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1057                                    "old_id" => \@old_project_ids },
 
1058                    "charts" => { "key" => "ALL_CHARTS",
 
1059                                  "transdate" => $form->{transdate} },
 
1060                    "taxcharts" => "ALL_TAXCHARTS");
 
1062   my %project_labels = ();
 
1063   my @project_values = ("");
 
1064   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1065     push(@project_values, $item->{"id"});
 
1066     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
1069   my %chart_labels = ();
 
1070   my @chart_values = ();
 
1073   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
1074     my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
 
1075     $taxchart_init = $item->{taxkey_id} unless (@chart_values);
 
1076     push(@chart_values, $key);
 
1077     $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
 
1078     $charts{$item->{accno}} = $item;
 
1081   my %taxchart_labels = ();
 
1082   my @taxchart_values = ();
 
1084   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
1085     my $key = Q($item->{id}) . "--" . Q($item->{rate});
 
1086     $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
 
1087     push(@taxchart_values, $key);
 
1088     $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
 
1089       H($item->{rate} * 100) . ' %';
 
1090     $taxcharts{$item->{id}} = $item;
 
1093   for $i (1 .. $form->{rowcount}) {
 
1096     <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
 
1098     <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
 
1100     my $selected_accno_full;
 
1101     my ($accno_row) = split(/--/, $form->{"accno_$i"});
 
1102     my $item = $charts{$accno_row};
 
1103     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
 
1105     my $selected_taxchart = $form->{"taxchart_$i"};
 
1106     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
 
1107     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
 
1109     if ($previous_accno &&
 
1110         ($previous_accno eq $selected_accno) &&
 
1111         ($previous_tax_id ne $selected_tax_id)) {
 
1112       my $item = $taxcharts{$selected_tax_id};
 
1113       $selected_taxchart = "$item->{id}--$item->{rate}";
 
1116     $selected_accno = '' if ($init);
 
1117     $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
 
1120       NTI($cgi->popup_menu('-name' => "accno_$i",
 
1121                            '-id' => "accno_$i",
 
1122                            '-onChange' => "setTaxkey(this, $i)",
 
1123                            '-style' => 'width:200px',
 
1124                            '-values' => \@chart_values,
 
1125                            '-labels' => \%chart_labels,
 
1126                            '-default' => $selected_accno_full))
 
1127       . $cgi->hidden('-name' => "previous_accno_$i",
 
1128                      '-default' => $selected_accno_full)
 
1131       NTI($cgi->popup_menu('-name' => "taxchart_$i",
 
1132                            '-id' => "taxchart_$i",
 
1133                            '-style' => 'width:200px',
 
1134                            '-values' => \@taxchart_values,
 
1135                            '-labels' => \%taxchart_labels,
 
1136                            '-default' => $selected_taxchart))
 
1141         qq|<td><input type="checkbox" name="korrektur_$i" value="1"</td>|;
 
1142       if ($form->{transfer}) {
 
1143         $fx_transaction = qq|
 
1144         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1149       if ($form->{"debit_$i"} != 0) {
 
1150         $form->{totaldebit} += $form->{"debit_$i"};
 
1151         if (!$form->{taxincluded}) {
 
1152           $form->{totaldebit} += $form->{"tax_$i"};
 
1155         $form->{totalcredit} += $form->{"credit_$i"};
 
1156         if (!$form->{taxincluded}) {
 
1157           $form->{totalcredit} += $form->{"tax_$i"};
 
1161       for (qw(debit credit tax)) {
 
1162         $form->{"${_}_$i"} =
 
1163           ($form->{"${_}_$i"})
 
1164           ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
 
1168       if ($i < $form->{rowcount}) {
 
1169         if ($form->{transfer}) {
 
1170           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
 
1171           $x = ($checked) ? "x" : "";
 
1172           $fx_transaction = qq|
 
1173       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
 
1176         $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
 
1178           qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked></td>|;
 
1179         $form->hide_form("accno_$i");
 
1183           qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
 
1184         if ($form->{transfer}) {
 
1185           $fx_transaction = qq|
 
1186       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1191     my $debitreadonly  = "";
 
1192     my $creditreadonly = "";
 
1193     if ($i == $form->{rowcount}) {
 
1195         $debitreadonly = "readonly";
 
1196       } elsif ($creditlock) {
 
1197         $creditreadonly = "readonly";
 
1202       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
1203                            '-values' => \@project_values,
 
1204                            '-labels' => \%project_labels,
 
1205                            '-default' => $form->{"project_id_$i"} ));
 
1207     print qq|<tr valign=top>
 
1210     <td><input name="debit_$i" size=8 value="$form->{"debit_$i"}" accesskey=$i $debitreadonly></td>
 
1211     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
 
1212     <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
 
1217     <td>$projectnumber</td>
 
1223   $form->hide_form(qw(rowcount selectaccno));
 
1225   $lxdebug->leave_sub();
 
1231   $lxdebug->enter_sub();
 
1232   $title         = $form->{title};
 
1233   $form->{title} = $locale->text("$title General Ledger Transaction");
 
1234   $readonly      = ($form->{id}) ? "readonly" : "";
 
1236   # $locale->text('Add General Ledger Transaction')
 
1237   # $locale->text('Edit General Ledger Transaction')
 
1239   map { $form->{$_} =~ s/\"/"/g }
 
1240     qw(reference description chart taxchart);
 
1241   $form->{javascript} = qq|<script type="text/javascript">
 
1243   function setTaxkey(accno, row) {
 
1244     var taxkey = accno.options[accno.selectedIndex].value;
 
1245     var reg = /--([0-9]*)/;
 
1246     var found = reg.exec(taxkey);
 
1247     var index = found[1];
 
1248     index = parseInt(index);
 
1249     var tax = 'taxchart_' + row;
 
1250     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
1251       var reg2 = new RegExp("^"+ index, "");
 
1252       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
1253         document.getElementById(tax).options[i].selected = true;
 
1261   $form->{selectdepartment} =~ s/ selected//;
 
1262   $form->{selectdepartment} =~
 
1263     s/option>\Q$form->{department}\E/option selected>$form->{department}/;
 
1265   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
 
1267       qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
 
1270       qq|<input name=description size=50 value="$form->{description}" $readonly>|;
 
1273   $taxincluded = ($form->{taxincluded}) ? "checked" : "";
 
1276     $taxincluded = "checked";
 
1281           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1282           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1283           <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
1285 | if $form->{selectdepartment};
 
1287     $form->{fokus} = "gl.reference";
 
1289     $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
 
1292   # use JavaScript Calendar or not
 
1293   $form->{jsscript} = $jscalendar;
 
1295   if ($form->{jsscript}) {
 
1297     # with JavaScript Calendar
 
1299        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly>
 
1300        <input type=button name=transdate id="trigger1" value=|
 
1301       . $locale->text('button') . qq|></td>  
 
1306       Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
 
1309     # without JavaScript Calendar
 
1311       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly></td>|;
 
1317 <body onLoad="fokus()">
 
1319 <form method=post name="gl" action=$form->{script}>
 
1321 <input name=id type=hidden value=$form->{id}>
 
1323 <input type=hidden name=closedto value=$form->{closedto}>
 
1324 <input type=hidden name=locked value=$form->{locked}>
 
1325 <input type=hidden name=title value="$title">
 
1330     <th class=listtop>$form->{title}</th>
 
1332   <tr height="5"></tr>
 
1337           <th align=left>| . $locale->text('Reference') . qq|</th>
 
1338           <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
 
1342                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
 
1351           <th align=right>| . $locale->text('Belegnummer') . qq|</th>
 
1352           <td><input name=id size=20 value="$form->{id}" $readonly></td>
 
1356                 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
 
1357                 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly></td>
 
1368           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1369           <td width=1%>$description</td>
 
1373                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1374                 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
 
1381                 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
 
1382                 <td align=left><input name=employee size=11  value=$form->{employee} $readonly></td>
 
1390           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1391           <td width=1%>$description</td>
 
1395                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1396                 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
 
1406            <tr class=listheading>
 
1407           <th class=listheading style="width:15%">|
 
1408     . $locale->text('Account') . qq|</th>
 
1409           <th class=listheading style="width:10%">|
 
1410     . $locale->text('Debit') . qq|</th>
 
1411           <th class=listheading style="width:10%">|
 
1412     . $locale->text('Credit') . qq|</th>
 
1413           <th class=listheading style="width:10%">|
 
1414     . $locale->text('Tax') . qq|</th>
 
1415           <th class=listheading style="width:5%">|
 
1416     . $locale->text('Korrektur') . qq|</th>
 
1417           <th class=listheading style="width:10%">|
 
1418     . $locale->text('Taxkey') . qq|</th>
 
1419           <th class=listheading style="width:20%">|
 
1420     . $locale->text('Source') . qq|</th>
 
1421           <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
 
1422           <th class=listheading style="width:20%">|
 
1423     . $locale->text('Project Number') . qq|</th>
 
1428   $lxdebug->leave_sub();
 
1433   $lxdebug->enter_sub();
 
1434   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
 
1436   $decimalplaces = ($dec > 2) ? $dec : 2;
 
1437   $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
1441       $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
 
1442   } qw(totaldebit totalcredit);
 
1445     <tr class=listtotal>
 
1447     <th align=right class=listtotal> $form->{totaldebit}</th>
 
1448     <th align=right class=listtotal> $form->{totalcredit}</th> 
 
1456 <input type=hidden name=path value=$form->{path}>
 
1457 <input type=hidden name=login value=$form->{login}>
 
1458 <input type=hidden name=password value=$form->{password}>
 
1460 <input name=callback type=hidden value="$form->{callback}">
 
1465   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1466   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1470     print qq|<input class=submit type=submit name=action value="|
 
1471       . $locale->text('Storno') . qq|">|;
 
1473     # Löschen und Ã„ndern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
 
1475     if (!$form->{locked} && $radieren) {
 
1477                 <input class=submit type=submit name=action value="|
 
1478         . $locale->text('Post') . qq|" accesskey="b">
 
1479                 <input class=submit type=submit name=action value="|
 
1480         . $locale->text('Delete') . qq|">|;
 
1483     #   if ($transdate > $closedto) {
 
1485     #           <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">|;
 
1488     if ($transdate > $closedto) {
 
1489       print qq|<input class=submit type=submit name=action value="|
 
1490         . $locale->text('Update') . qq|">
 
1491                  <input class=submit type=submit name=action value="|
 
1492         . $locale->text('Post') . qq|">|;
 
1502   $lxdebug->leave_sub();
 
1507   $lxdebug->enter_sub();
 
1514 <form method=post action=$form->{script}>
 
1517   map { $form->{$_} =~ s/\"/"/g } qw(reference description);
 
1519   delete $form->{header};
 
1521   foreach $key (keys %$form) {
 
1522     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1526 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1529     . $locale->text('Are you sure you want to delete Transaction')
 
1530     . qq| $form->{reference}</h4>
 
1532 <input name=action class=submit type=submit value="|
 
1533     . $locale->text('Yes') . qq|">
 
1536   $lxdebug->leave_sub();
 
1541   $lxdebug->enter_sub();
 
1542   if (GL->delete_transaction(\%myconfig, \%$form)){
 
1543     # saving the history
 
1544       if(!exists $form->{addition} && $form->{id} ne "") {
 
1545             $form->{addition} = "DELETED";
 
1546             $form->save_history($form->dbconnect(\%myconfig));
 
1548     # /saving the history 
 
1549     $form->redirect($locale->text('Transaction deleted!'))
 
1551   $form->error($locale->text('Cannot delete transaction!'));
 
1552   $lxdebug->leave_sub();
 
1557   $lxdebug->enter_sub();
 
1559   # check if there is something in reference and date
 
1560   $form->isblank("reference",   $locale->text('Reference missing!'));
 
1561   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
 
1562   $form->isblank("description", $locale->text('Description missing!'));
 
1564   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1565   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1572   my $creditcount = 0;
 
1577     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
1578   if ($form->{storno}) {
 
1579     for my $i (1 .. $form->{rowcount}) {
 
1580       unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1581         if ($form->{"debit_$i"} ne "") {
 
1582           $form->{"credit_$i"} = $form->{"debit_$i"};
 
1583           $form->{"debit_$i"}  = "";
 
1584         } elsif ($form->{"credit_$i"} ne "") {
 
1585           $form->{"debit_$i"}  = $form->{"credit_$i"};
 
1586           $form->{"credit_$i"} = "";
 
1592   for my $i (1 .. $form->{rowcount}) {
 
1594     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1595       for (qw(debit credit tax)) {
 
1596         $form->{"${_}_$i"} =
 
1597           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
1601       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
1609       if (($debitcount >= 2) && ($creditcount == 2)) {
 
1610         $form->{"credit_$i"} = 0;
 
1611         $form->{"tax_$i"}    = 0;
 
1615       if (($creditcount >= 2) && ($debitcount == 2)) {
 
1616         $form->{"debit_$i"} = 0;
 
1617         $form->{"tax_$i"}   = 0;
 
1621       if (($creditcount == 1) && ($debitcount == 2)) {
 
1624       if (($creditcount == 2) && ($debitcount == 1)) {
 
1627       if ($debitcredit && $credittax) {
 
1628         $form->{"taxchart_$i"} = "0--0.00";
 
1630       if (!$debitcredit && $debittax) {
 
1631         $form->{"taxchart_$i"} = "0--0.00";
 
1634         ($form->{"debit_$i"} == 0)
 
1635         ? $form->{"credit_$i"}
 
1636         : $form->{"debit_$i"};
 
1638       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1639         $form->{"taxchart_$i"} = "0--0.00";
 
1640         $form->{"tax_$i"}      = 0;
 
1642       if (!$form->{"korrektur_$i"}) {
 
1643         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1650           if ($form->{taxincluded}) {
 
1651             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1653               $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1655               $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1658             $form->{"tax_$i"} = $amount * $rate;
 
1661           $form->{"tax_$i"} = 0;
 
1663       } elsif ($form->{taxincluded}) {
 
1665           $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1667           $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1671       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1676   for $i (1 .. $count) {
 
1678     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1681   for $i ($count + 1 .. $form->{rowcount}) {
 
1682     for (@flds) { delete $form->{"${_}_$i"} }
 
1685   for $i (1 .. $form->{rowcount}) {
 
1686     $dr  = $form->{"debit_$i"};
 
1687     $cr  = $form->{"credit_$i"};
 
1688     $tax = $form->{"tax_$i"};
 
1692           'Cannot post transaction with a debit and credit entry for the same account!'
 
1695     if ($form->{taxincluded}) {
 
1697         $debit += $dr + $tax;
 
1700         $credit += $cr + $tax;
 
1705         $debit += $dr + $tax;
 
1708         $credit += $cr + $tax;
 
1713     $form->{taxincluded} = 0;
 
1716   # this is just for the wise guys
 
1717   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
1718     if ($transdate <= $closedto);
 
1719   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
 
1720     $form->error($locale->text('Out of balance transaction!'));
 
1723   if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
 
1724     $form->error($locale->text('Empty transaction!'));
 
1727   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
 
1729     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
 
1730     $err[2] = $locale->text('Debit and credit out of balance!');
 
1731     $err[3] = $locale->text('Cannot post a transaction without a value!');
 
1733     $form->error($err[$errno]);
 
1735   undef($form->{callback});
 
1736   # saving the history
 
1737   if(!exists $form->{addition} && $form->{id} ne "") {
 
1738         $form->{addition} = "SAVED";
 
1739         $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; 
 
1740         $form->save_history($form->dbconnect(\%myconfig));
 
1742   # /saving the history 
 
1743   $form->redirect("Buchung gespeichert. Buchungsnummer = " . $form->{id});
 
1744   $lxdebug->leave_sub();
 
1749   $lxdebug->enter_sub();
 
1753   $lxdebug->leave_sub();
 
1758   $lxdebug->enter_sub();
 
1761   $form->{storno} = 1;
 
1762   # saving the history
 
1763   if(!exists $form->{addition} && $form->{id} ne "") {
 
1764         $form->{addition} = "STORNO";
 
1765         $form->save_history($form->dbconnect(\%myconfig));
 
1767   # /saving the history 
 
1769   $lxdebug->leave_sub();