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       "<option value=\"$_->{accno}--$_->{tax_id}\">$_->{accno}--$_->{description}</option>"
 
  87   } @{ $form->{chart} };
 
  90       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
  91       . ($_->{rate} * 100) . qq| %|
 
  94   $form->{chart}     = $chart;
 
  95   $form->{chartinit} = $chart;
 
  96   $form->{rowcount}  = 2;
 
  98   $form->{debitchart}  = $chart;
 
  99   $form->{creditchart} = $chart;
 
 100   $form->{taxchart}    = $tax;
 
 107   $form->all_departments(\%myconfig);
 
 108   if (@{ $form->{all_departments} }) {
 
 109     $form->{selectdepartment} = "<option>\n";
 
 112       $form->{selectdepartment} .=
 
 113         "<option>$_->{description}--$_->{id}\n"
 
 114     } (@{ $form->{all_departments} });
 
 118   $lxdebug->leave_sub();
 
 123   $lxdebug->enter_sub();
 
 125   GL->transaction(\%myconfig, \%$form);
 
 128       "<option value=\"$_->{accno}--$_->{tax_id}\">$_->{accno}--$_->{description}</option>"
 
 129   } @{ $form->{chart} };
 
 133       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
 134       . ($_->{rate} * 100) . qq| %|
 
 137   $form->{chart} = $chart;
 
 139   $form->{taxchart} = $tax;
 
 141   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
 
 144   $form->all_departments(\%myconfig);
 
 145   if (@{ $form->{all_departments} }) {
 
 146     $form->{selectdepartment} = "<option>\n";
 
 149       $form->{selectdepartment} .=
 
 150         "<option>$_->{description}--$_->{id}\n"
 
 151     } (@{ $form->{all_departments} });
 
 157   foreach $ref (@{ $form->{GL} }) {
 
 159     if ($tax && ($ref->{accno} eq $taxaccno)) {
 
 160       $form->{"tax_$j"}      = abs($ref->{amount});
 
 161       $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
 
 162       if ($form->{taxincluded}) {
 
 163         if ($ref->{amount} < 0) {
 
 164           $form->{"debit_$j"} += $form->{"tax_$j"};
 
 166           $form->{"credit_$j"} += $form->{"tax_$j"};
 
 170       $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
 
 171       for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
 
 172       if ($ref->{amount} < 0) {
 
 173         $form->{totaldebit} -= $ref->{amount};
 
 174         $form->{"debit_$i"} = $ref->{amount} * -1;
 
 176         $form->{totalcredit} += $ref->{amount};
 
 177         $form->{"credit_$i"} = $ref->{amount};
 
 179       $form->{"taxchart_$i"} = "0--0.00";
 
 182     if ($ref->{taxaccno} && !$tax) {
 
 183       $taxaccno = $ref->{taxaccno};
 
 192   $form->{rowcount} = $i;
 
 194     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 195      $form->datetonum($form->{closedto}, \%myconfig));
 
 197   $form->{title} = "Edit";
 
 202   $lxdebug->leave_sub();
 
 207   $lxdebug->enter_sub();
 
 209   $form->{title} = $locale->text('Buchungsjournal');
 
 211   $form->all_departments(\%myconfig);
 
 214   if (@{ $form->{all_departments} }) {
 
 215     $form->{selectdepartment} = "<option>\n";
 
 218       $form->{selectdepartment} .=
 
 219         "<option>$_->{description}--$_->{id}\n"
 
 220     } (@{ $form->{all_departments} });
 
 225           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 226           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 228 | if $form->{selectdepartment};
 
 230   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 233   my %project_labels = ();
 
 234   my @project_values = ("");
 
 235   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 236     push(@project_values, $item->{"id"});
 
 237     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 241     NTI($cgi->popup_menu('-name' => "project_id",
 
 242                          '-values' => \@project_values,
 
 243                          '-labels' => \%project_labels));
 
 245   # use JavaScript Calendar or not
 
 246   $form->{jsscript} = $jscalendar;
 
 248   if ($form->{jsscript}) {
 
 250     # with JavaScript Calendar
 
 252        <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}">
 
 253        <input type=button name=datefrom id="trigger1" value=|
 
 254       . $locale->text('button') . qq|></td>  
 
 257        <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}">
 
 258        <input type=button name=dateto id="trigger2" value=|
 
 259       . $locale->text('button') . qq|></td>
 
 264       Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
 
 265                           "dateto", "BL", "trigger2");
 
 268     # without JavaScript Calendar
 
 270       qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}"></td>|;
 
 272       qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}"></td>|;
 
 280 <form method=post action=$form->{script}>
 
 282 <input type=hidden name=sort value=transdate>
 
 286     <th class=listtop>$form->{title}</th>
 
 293           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 294           <td><input name=reference size=20></td>
 
 295           <th align=right>| . $locale->text('Source') . qq|</th>
 
 296           <td><input name=source size=20></td>
 
 300           <th align=right>| . $locale->text('Description') . qq|</th>
 
 301           <td colspan=3><input name=description size=40></td>
 
 304           <th align=right>| . $locale->text('Notes') . qq|</th>
 
 305           <td colspan=3><input name=notes size=40></td>
 
 308           <th align=right>| . $locale->text('Project Number') . qq|</th>
 
 309           <td colspan=3>$projectnumber</td>
 
 312           <th align=right>| . $locale->text('From') . qq|</th>
 
 314           <th align=right>| . $locale->text('To (time)') . qq|</th>
 
 318           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 323                   <input name="category" class=radio type=radio value=X checked> |
 
 324     . $locale->text('All') . qq|
 
 325                   <input name="category" class=radio type=radio value=A> |
 
 326     . $locale->text('Asset') . qq|
 
 327                   <input name="category" class=radio type=radio value=L> |
 
 328     . $locale->text('Liability') . qq|
 
 329                   <input name="category" class=radio type=radio value=I> |
 
 330     . $locale->text('Revenue') . qq|
 
 331                   <input name="category" class=radio type=radio value=E> |
 
 332     . $locale->text('Expense') . qq|
 
 338                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 339                     <td>| . $locale->text('ID') . qq|</td>
 
 340                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 341                     <td>| . $locale->text('Date') . qq|</td>
 
 342                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
 
 343                     <td>| . $locale->text('Reference') . qq|</td>
 
 344                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
 
 345                     <td>| . $locale->text('Description') . qq|</td>
 
 346                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
 347                     <td>| . $locale->text('Notes') . qq|</td>
 
 350                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
 
 351                     <td>| . $locale->text('Debit') . qq|</td>
 
 352                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
 
 353                     <td>| . $locale->text('Credit') . qq|</td>
 
 354                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
 
 355                     <td>| . $locale->text('Source') . qq|</td>
 
 356                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
 
 357                     <td>| . $locale->text('Account') . qq|</td>
 
 358                     <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
 
 359                     <td>| . $locale->text('GIFI') . qq|</td>
 
 362                     <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 363                     <td>| . $locale->text('Subtotal') . qq|</td>
 
 364                     <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
 
 365                     <td>| . $locale->text('Project Number') . qq|</td>
 
 375     <td><hr size=3 noshade></td>
 
 381 <input type=hidden name=nextsub value=generate_report>
 
 383 <input type=hidden name=path value=$form->{path}>
 
 384 <input type=hidden name=login value=$form->{login}>
 
 385 <input type=hidden name=password value=$form->{password}>
 
 388 <input class=submit type=submit name=action value="|
 
 389     . $locale->text('Continue') . qq|">
 
 395   $lxdebug->leave_sub();
 
 398 sub generate_report {
 
 399   $lxdebug->enter_sub();
 
 401   $form->{sort} = "transdate" unless $form->{sort};
 
 403   GL->all_transactions(\%myconfig, \%$form);
 
 406     "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
 
 410   %acctype = ('A' => $locale->text('Asset'),
 
 411               'C' => $locale->text('Contra'),
 
 412               'L' => $locale->text('Liability'),
 
 413               'Q' => $locale->text('Equity'),
 
 414               'I' => $locale->text('Revenue'),
 
 415               'E' => $locale->text('Expense'),);
 
 417   $form->{title} = $locale->text('General Ledger');
 
 419   $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
 
 421   unless ($form->{category} eq 'X') {
 
 422     $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
 
 424   if ($form->{accno}) {
 
 425     $href .= "&accno=" . $form->escape($form->{accno});
 
 426     $callback .= "&accno=" . $form->escape($form->{accno}, 1);
 
 428       $locale->text('Account')
 
 429       . " : $form->{accno} $form->{account_description}";
 
 431   if ($form->{gifi_accno}) {
 
 432     $href     .= "&gifi_accno=" . $form->escape($form->{gifi_accno});
 
 433     $callback .= "&gifi_accno=" . $form->escape($form->{gifi_accno}, 1);
 
 434     $option   .= "\n<br>" if $option;
 
 436       $locale->text('GIFI')
 
 437       . " : $form->{gifi_accno} $form->{gifi_account_description}";
 
 439   if ($form->{source}) {
 
 440     $href     .= "&source=" . $form->escape($form->{source});
 
 441     $callback .= "&source=" . $form->escape($form->{source}, 1);
 
 442     $option   .= "\n<br>" if $option;
 
 443     $option   .= $locale->text('Source') . " : $form->{source}";
 
 445   if ($form->{reference}) {
 
 446     $href     .= "&reference=" . $form->escape($form->{reference});
 
 447     $callback .= "&reference=" . $form->escape($form->{reference}, 1);
 
 448     $option   .= "\n<br>" if $option;
 
 449     $option   .= $locale->text('Reference') . " : $form->{reference}";
 
 451   if ($form->{department}) {
 
 452     $href .= "&department=" . $form->escape($form->{department});
 
 453     $callback .= "&department=" . $form->escape($form->{department}, 1);
 
 454     ($department) = split /--/, $form->{department};
 
 455     $option .= "\n<br>" if $option;
 
 456     $option .= $locale->text('Department') . " : $department";
 
 459   if ($form->{description}) {
 
 460     $href     .= "&description=" . $form->escape($form->{description});
 
 461     $callback .= "&description=" . $form->escape($form->{description}, 1);
 
 462     $option   .= "\n<br>" if $option;
 
 463     $option   .= $locale->text('Description') . " : $form->{description}";
 
 465   if ($form->{notes}) {
 
 466     $href     .= "¬es=" . $form->escape($form->{notes});
 
 467     $callback .= "¬es=" . $form->escape($form->{notes}, 1);
 
 468     $option   .= "\n<br>" if $option;
 
 469     $option   .= $locale->text('Notes') . " : $form->{notes}";
 
 471  if ($form->{project_id}) {
 
 472     $href     .= "&project_id=" . $form->escape($form->{project_id});
 
 473     $callback .= "&project_id=" . $form->escape($form->{project_id});
 
 476   if ($form->{datefrom}) {
 
 477     $href     .= "&datefrom=$form->{datefrom}";
 
 478     $callback .= "&datefrom=$form->{datefrom}";
 
 479     $option   .= "\n<br>" if $option;
 
 481         $locale->text('From') . " "
 
 482       . $locale->date(\%myconfig, $form->{datefrom}, 1);
 
 484   if ($form->{dateto}) {
 
 485     $href     .= "&dateto=$form->{dateto}";
 
 486     $callback .= "&dateto=$form->{dateto}";
 
 487     if ($form->{datefrom}) {
 
 490       $option .= "\n<br>" if $option;
 
 493         $locale->text('Bis') . " "
 
 494       . $locale->date(\%myconfig, $form->{dateto}, 1);
 
 497   @columns = $form->sort_columns( qw(
 
 498        transdate       id                reference         description  
 
 499        notes           source            debit             debit_accno  
 
 500        credit          credit_accno      debit_tax         debit_tax_accno
 
 501        credit_tax      credit_tax_accno  accno             gifi_accno
 
 506   if ($form->{accno} || $form->{gifi_accno}) {
 
 507     @columns = grep !/(accno|gifi_accno)/, @columns;
 
 508     push @columns, "balance";
 
 509     $form->{l_balance} = "Y";
 
 513   $form->{l_credit_accno}     = "Y";
 
 514   $form->{l_debit_accno}      = "Y";
 
 515   $form->{l_credit_tax}       = "Y";
 
 516   $form->{l_debit_tax}        = "Y";
 
 517   $form->{l_credit_tax_accno} = "Y";
 
 518   $form->{l_debit_tax_accno}  = "Y";
 
 519   $form->{l_accno}            = "N";
 
 520   foreach $item (@columns) {
 
 521     if ($form->{"l_$item"} eq "Y") {
 
 522       push @column_index, $item;
 
 524       # add column to href and callback
 
 525       $callback .= "&l_$item=Y";
 
 526       $href     .= "&l_$item=Y";
 
 530   if ($form->{l_subtotal} eq 'Y') {
 
 531     $callback .= "&l_subtotal=Y";
 
 532     $href     .= "&l_subtotal=Y";
 
 535   $callback .= "&category=$form->{category}";
 
 536   $href     .= "&category=$form->{category}";
 
 539       "<th><a class=listheading href=$href&sort=id>"
 
 540     . $locale->text('ID')
 
 542   $column_header{transdate} =
 
 543       "<th><a class=listheading href=$href&sort=transdate>"
 
 544     . $locale->text('Date')
 
 546   $column_header{reference} =
 
 547       "<th><a class=listheading href=$href&sort=reference>"
 
 548     . $locale->text('Reference')
 
 550   $column_header{source} =
 
 551       "<th><a class=listheading href=$href&sort=source>"
 
 552     . $locale->text('Source')
 
 554   $column_header{description} =
 
 555       "<th><a class=listheading href=$href&sort=description>"
 
 556     . $locale->text('Description')
 
 558   $column_header{notes} =
 
 559     "<th class=listheading>" . $locale->text('Notes') . "</th>";
 
 560   $column_header{debit} =
 
 561     "<th class=listheading>" . $locale->text('Debit') . "</th>";
 
 562   $column_header{debit_accno} =
 
 563       "<th><a class=listheading href=$href&sort=accno>"
 
 564     . $locale->text('Debit Account')
 
 566   $column_header{credit} =
 
 567     "<th class=listheading>" . $locale->text('Credit') . "</th>";
 
 568   $column_header{credit_accno} =
 
 569       "<th><a class=listheading href=$href&sort=accno>"
 
 570     . $locale->text('Credit Account')
 
 572   $column_header{debit_tax} =
 
 573       "<th><a class=listheading href=$href&sort=accno>"
 
 574     . $locale->text('Debit Tax')
 
 576   $column_header{debit_tax_accno} =
 
 577       "<th><a class=listheading href=$href&sort=accno>"
 
 578     . $locale->text('Debit Tax Account')
 
 580   $column_header{credit_tax} =
 
 581       "<th><a class=listheading href=$href&sort=accno>"
 
 582     . $locale->text('Credit Tax')
 
 584   $column_header{credit_tax_accno} =
 
 585       "<th><a class=listheading href=$href&sort=accno>"
 
 586     . $locale->text('Credit Tax Account')
 
 588   $column_header{gifi_accno} =
 
 589       "<th><a class=listheading href=$href&sort=gifi_accno>"
 
 590     . $locale->text('GIFI')
 
 592   $column_header{balance} = "<th>" . $locale->text('Balance') . "</th>";
 
 593   $column_header{projectnumbers} =
 
 594       "<th class=listheading>"  . $locale->text('Project Numbers') . "</th>";
 
 596   $form->{landscape} = 1;
 
 605     <th class=listtop>$form->{title}</th>
 
 615         <tr class=listheading>
 
 618   map { print "$column_header{$_}\n" } @column_index;
 
 627   # add sort to callback
 
 628   $form->{callback} = "$callback&sort=$form->{sort}";
 
 629   $callback = $form->escape($form->{callback});
 
 631   # initial item for subtotals
 
 632   if (@{ $form->{GL} }) {
 
 633     $sameitem = $form->{GL}->[0]->{ $form->{sort} };
 
 636   if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
 
 638     map { $column_data{$_} = "<td> </td>" } @column_index;
 
 639     $column_data{balance} =
 
 641       . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
 
 649     map { print "$column_data{$_}\n" } @column_index;
 
 655   $form->{balance} *= $ml;
 
 656   foreach $ref (@{ $form->{GL} }) {
 
 657     $form->{balance} *= $ml;
 
 659     # if item ne sort print subtotal
 
 660     if ($form->{l_subtotal} eq 'Y') {
 
 661       if ($sameitem ne $ref->{ $form->{sort} }) {
 
 666     #foreach $key (sort keys(%{ $ref->{amount} })) {
 
 667     #  $form->{balance} += $ref->{amount}{$key};
 
 671     foreach $key (sort keys(%{ $ref->{debit} })) {
 
 672       $subtotaldebit += $ref->{debit}{$key};
 
 673       $totaldebit    += $ref->{debit}{$key};
 
 675         $debit = $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 678           "<br>" . $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 680       $form->{balance} = abs($form->{balance}) - abs($ref->{debit}{$key});
 
 684     foreach $key (sort keys(%{ $ref->{credit} })) {
 
 685       $subtotalcredit += $ref->{credit}{$key};
 
 686       $totalcredit    += $ref->{credit}{$key};
 
 688         $credit = $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 691           . $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 693       $form->{balance} = abs($form->{balance}) - abs($ref->{credit}{$key});
 
 697     foreach $key (sort keys(%{ $ref->{debit_tax} })) {
 
 698       $subtotaldebittax += $ref->{debit_tax}{$key};
 
 699       $totaldebittax    += $ref->{debit_tax}{$key};
 
 702           $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 705           . $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 707       $form->{balance} = abs($form->{balance}) - abs($ref->{debit_tax}{$key});
 
 711     foreach $key (sort keys(%{ $ref->{credit_tax} })) {
 
 712       $subtotalcredittax += $ref->{credit_tax}{$key};
 
 713       $totalcredittax    += $ref->{credit_tax}{$key};
 
 716           $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 719           . $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 721       $form->{balance} = abs($form->{balance}) - abs($ref->{credit_tax}{$key});
 
 727     foreach $key (sort keys(%{ $ref->{debit_accno} })) {
 
 730           "<a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 733           "<br><a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 736       #       if ($ref->{debit_taxkey}{$key} eq $debittaxkey) {
 
 737       #         $ref->{debit_tax_accno}{$key} = $taxaccno;
 
 739       $taxaccno    = $ref->{debit_tax_accno}{$key};
 
 740       $debittaxkey = $ref->{debit_taxkey}{$key};
 
 746     foreach $key (sort keys(%{ $ref->{credit_accno} })) {
 
 749           "<a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 752           "<br><a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 755       #       if ($ref->{credit_taxkey}{$key} eq $credittaxkey) {
 
 756       #         $ref->{credit_tax_accno}{$key} = $taxaccno;
 
 758       $taxaccno     = $ref->{credit_tax_accno}{$key};
 
 759       $credittaxkey = $ref->{credit_taxkey}{$key};
 
 763     foreach $key (sort keys(%{ $ref->{debit_tax_accno} })) {
 
 766           "<a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 769           "<br><a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 773     $credittaxaccno = "";
 
 774     foreach $key (sort keys(%{ $ref->{credit_tax_accno} })) {
 
 777           "<a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 780           "<br><a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 785     foreach $key (sort keys(%{ $ref->{transdate} })) {
 
 787         $transdate = "$ref->{transdate}{$key}";
 
 789         $transdate .= "<br>$ref->{transdate}{$key}";
 
 793     #    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
 
 794     #    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
 
 796     $column_data{id}        = "<td align=right> $ref->{id} </td>";
 
 797     $column_data{transdate}    = "<td align=center>$transdate</td>";
 
 798     $column_data{reference} =
 
 799       "<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>";
 
 800     $column_data{description}  = "<td align=center>$ref->{description} </td>";
 
 801     $column_data{source}       = "<td align=center>$ref->{source} </td>";
 
 802     $column_data{notes}        = "<td align=center>$ref->{notes} </td>";
 
 803     $column_data{debit}        = "<td align=right>$debit</td>";
 
 804     $column_data{debit_accno}  = "<td align=center>$debitaccno</td>";
 
 805     $column_data{credit}       = "<td align=right>$credit</td>";
 
 806     $column_data{credit_accno} = "<td align=center>$creditaccno</td>";
 
 807     $column_data{debit_tax}    =
 
 808       ($ref->{debit_tax_accno} ne "")
 
 809       ? "<td align=right>$debittax</td>"
 
 811     $column_data{debit_tax_accno} = "<td align=center>$debittaxaccno</td>";
 
 812     $column_data{gifi_accno}      =
 
 813       "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";
 
 814     $column_data{credit_tax} =
 
 815       ($ref->{credit_tax_accno} ne "")
 
 816       ? "<td align=right>$credittax</td>"
 
 818     $column_data{credit_tax_accno} = "<td align=center>$credittaxaccno</td>";
 
 819     $column_data{gifi_accno}       =
 
 820       "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";
 
 821     $column_data{balance} =
 
 823       . $form->format_amount(\%myconfig, $form->{balance}, 2, 0) . "</td>";
 
 824     $column_data{projectnumbers} =
 
 825       "<td>" . join(", ", sort({ lc($a) cmp lc($b) } keys(%{ $ref->{projectnumbers} }))) . "</td>";
 
 830         <tr class=listrow$i>";
 
 831     map { print "$column_data{$_}\n" } @column_index;
 
 836   &gl_subtotal if ($form->{l_subtotal} eq 'Y');
 
 838   map { $column_data{$_} = "<td> </td>" } @column_index;
 
 840   my $balanced_ledger = $totaldebit 
 
 844                     # = 0 for balanced ledger
 
 846   $column_data{debit} =
 
 847     "<th align=right class=listtotal>"
 
 848     . $form->format_amount(\%myconfig, $totaldebit, 2, " ") . "</th>";
 
 849   $column_data{credit} =
 
 850     "<th align=right class=listtotal>"
 
 851     . $form->format_amount(\%myconfig, $totalcredit, 2, " ") . "</th>";
 
 852   $column_data{debit_tax} =
 
 853     "<th align=right class=listtotal>"
 
 854     . $form->format_amount(\%myconfig, $totaldebittax, 2, " ") . "</th>";
 
 855   $column_data{credit_tax} =
 
 856     "<th align=right class=listtotal>"
 
 857     . $form->format_amount(\%myconfig, $totalcredittax, 2, " ") . "</th>";
 
 858   $column_data{balance} =
 
 859     "<th align=right class=listtotal>"
 
 860     . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0) . "</th>";
 
 866   map { print "$column_data{$_}\n" } @column_index;
 
 873   if ( abs($balanced_ledger) >  0.001 ) {
 
 875     print qq|<td colspan="4" style="background-color:#FFA0A0" >|
 
 876         . $locale->text('Unbalanced Ledger') 
 
 878         . $form->format_amount(\%myconfig, $balanced_ledger, 3, " ")
 
 880   } elsif ( abs($balanced_ledger) <= 0.001 ) {
 
 882     print qq|<td colspan="3">|
 
 883           . $locale->text('Balanced Ledger') 
 
 896     <td><hr size=3 noshade></td>
 
 902 <form method=post action=$form->{script}>
 
 904 <input name=callback type=hidden value="$form->{callback}">
 
 906 <input type=hidden name=path value=$form->{path}>
 
 907 <input type=hidden name=login value=$form->{login}>
 
 908 <input type=hidden name=password value=$form->{password}>
 
 910 <input class=submit type=submit name=action value="|
 
 911     . $locale->text('GL Transaction') . qq|">
 
 912 <input class=submit type=submit name=action value="|
 
 913     . $locale->text('AR Transaction') . qq|">
 
 914 <input class=submit type=submit name=action value="|
 
 915     . $locale->text('AP Transaction') . qq|">
 
 916 <input class=submit type=submit name=action value="|
 
 917     . $locale->text('Sales Invoice') . qq|">
 
 918 <input class=submit type=submit name=action value="|
 
 919     . $locale->text('Vendor Invoice') . qq|">
 
 926   $lxdebug->leave_sub();
 
 931   $lxdebug->enter_sub();
 
 934     $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
 
 936     $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
 
 938   map { $column_data{$_} = "<td> </td>" }
 
 939     qw(transdate id reference source description accno);
 
 940   $column_data{debit}  = "<th align=right>$subtotaldebit</td>";
 
 941   $column_data{credit} = "<th align=right>$subtotalcredit</td>";
 
 943   print "<tr class=listsubtotal>";
 
 944   map { print "$column_data{$_}\n" } @column_index;
 
 950   $sameitem = $ref->{ $form->{sort} };
 
 951   $lxdebug->leave_sub();
 
 956   $lxdebug->enter_sub();
 
 958   $form->{oldtransdate} = $form->{transdate};
 
 970     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
 972   for my $i (1 .. $form->{rowcount}) {
 
 974     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
 975       for (qw(debit credit tax)) {
 
 977           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
 981       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
 988       if (($debitcount >= 2) && ($creditcount == 2)) {
 
 989         $form->{"credit_$i"} = 0;
 
 990         $form->{"tax_$i"}    = 0;
 
 994       if (($creditcount >= 2) && ($debitcount == 2)) {
 
 995         $form->{"debit_$i"} = 0;
 
 996         $form->{"tax_$i"}   = 0;
 
1000       if (($creditcount == 1) && ($debitcount == 2)) {
 
1003       if (($creditcount == 2) && ($debitcount == 1)) {
 
1006       if ($debitcredit && $credittax) {
 
1007         $form->{"taxchart_$i"} = "0--0.00";
 
1009       if (!$debitcredit && $debittax) {
 
1010         $form->{"taxchart_$i"} = "0--0.00";
 
1013         ($form->{"debit_$i"} == 0)
 
1014         ? $form->{"credit_$i"}
 
1015         : $form->{"debit_$i"};
 
1017       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1018         $form->{"taxchart_$i"} = "0--0.00";
 
1019         $form->{"tax_$i"}      = 0;
 
1021       if (!$form->{"korrektur_$i"}) {
 
1022         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1029           if ($form->{taxincluded}) {
 
1030             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1032             $form->{"tax_$i"} = $amount * $rate;
 
1035           $form->{"tax_$i"} = 0;
 
1039       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1044   for $i (1 .. $count) {
 
1046     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1049   for $i ($count + 1 .. $form->{rowcount}) {
 
1050     for (@flds) { delete $form->{"${_}_$i"} }
 
1053   $form->{rowcount} = $count + 1;
 
1056   $lxdebug->leave_sub();
 
1062   $lxdebug->enter_sub();
 
1064   &form_header($init);
 
1066   #   for $i (1 .. $form->{rowcount}) {
 
1067   #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
 
1068   #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
 
1072   &display_rows($init);
 
1074   $lxdebug->leave_sub();
 
1080   $lxdebug->enter_sub();
 
1082   $form->{totaldebit}  = 0;
 
1083   $form->{totalcredit} = 0;
 
1084   my $chart = $form->{chart};
 
1085   $chart            = $form->unquote($chart);
 
1086   $form->{taxchart} = $form->unquote($form->{taxchart});
 
1087   $taxchart         = $form->{taxchart};
 
1089   my @old_project_ids = ();
 
1090   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
1091           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
1093   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1095                                    "old_id" => \@old_project_ids });
 
1097   my %project_labels = ();
 
1098   my @project_values = ("");
 
1099   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1100     push(@project_values, $item->{"id"});
 
1101     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
1104   for $i (1 .. $form->{rowcount}) {
 
1107     <td><input name="source_$i" value="$form->{"source_$i"}" size="16" tabindex=|
 
1108       . ($i + 11 + (($i - 1) * 8)) . qq|></td>|;
 
1110     <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16" tabindex=|
 
1111       . ($i + 12 + (($i - 1) * 8)) . qq|></td>|;
 
1115       <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:200px" tabindex=|
 
1116         . ($i + 5 + (($i - 1) * 8)) . qq|>$form->{chartinit}</select></td>|;
 
1118         qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px" tabindex=|
 
1119         . ($i + 10 + (($i - 1) * 8))
 
1120         . qq|>$form->{taxchart}</select></td>|;
 
1123         qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
 
1124         . ($i + 9 + (($i - 1) * 8))
 
1126       if ($form->{transfer}) {
 
1127         $fx_transaction = qq|
 
1128         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1133       if ($form->{"debit_$i"} != 0) {
 
1134         $form->{totaldebit} += $form->{"debit_$i"};
 
1135         if (!$form->{taxincluded}) {
 
1136           $form->{totaldebit} += $form->{"tax_$i"};
 
1139         $form->{totalcredit} += $form->{"credit_$i"};
 
1140         if (!$form->{taxincluded}) {
 
1141           $form->{totalcredit} += $form->{"tax_$i"};
 
1145       for (qw(debit credit tax)) {
 
1146         $form->{"${_}_$i"} =
 
1147           ($form->{"${_}_$i"})
 
1148           ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
 
1152       if ($i < $form->{rowcount}) {
 
1155         $chart_selected = $form->{"accno_$i"};
 
1157           s/value=\"$chart_selected\"/value=\"$chart_selected\" selected/;
 
1159           qq|<td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:200px" tabindex=|
 
1160           . ($i + 5 + (($i - 1) * 8))
 
1161           . qq|>$accno</select></td>|;
 
1163         $tax_selected = $form->{"taxchart_$i"};
 
1164         $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
 
1166             qq|<td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
 
1167           . ($i + 10 + (($i - 1) * 8))
 
1168           . qq|>$tax</select></td>|;
 
1170         if ($form->{transfer}) {
 
1171           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
 
1172           $x = ($checked) ? "x" : "";
 
1173           $fx_transaction = qq|
 
1174       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
 
1177         $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
 
1179           qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked tabindex=|
 
1180           . ($i + 9 + (($i - 1) * 8))
 
1182         $form->hide_form("accno_$i");
 
1187       <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:300px" tabindex=|
 
1188           . ($i + 5 + (($i - 1) * 8)) . qq|>$chart</select></td>|;
 
1190       <td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
 
1191           . ($i + 10 + (($i - 1) * 8)) . qq|>$taxchart</select></td>|;
 
1194           qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
 
1195           . ($i + 9 + (($i - 1) * 8))
 
1197         if ($form->{transfer}) {
 
1198           $fx_transaction = qq|
 
1199       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1204     my $debitreadonly  = "";
 
1205     my $creditreadonly = "";
 
1206     if ($i == $form->{rowcount}) {
 
1208         $debitreadonly = "readonly";
 
1209       } elsif ($creditlock) {
 
1210         $creditreadonly = "readonly";
 
1215       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
1216                            '-values' => \@project_values,
 
1217                            '-labels' => \%project_labels,
 
1218                            '-default' => $form->{"project_id_$i"} ));
 
1220     print qq|<tr valign=top>
 
1223     <td><input name="debit_$i" size=8 value="$form->{"debit_$i"}" accesskey=$i tabindex=|
 
1224       . ($i + 6 + (($i - 1) * 8)) . qq| $debitreadonly></td>
 
1225     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" tabindex=|
 
1226       . ($i + 7 + (($i - 1) * 8)) . qq| $creditreadonly></td>
 
1227     <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}" tabindex=|
 
1228       . ($i + 8 + (($i - 1) * 8)) . qq|></td>
 
1233     <td>$projectnumber</td>
 
1239   $form->hide_form(qw(rowcount selectaccno));
 
1241   $lxdebug->leave_sub();
 
1247   $lxdebug->enter_sub();
 
1248   $title         = $form->{title};
 
1249   $form->{title} = $locale->text("$title General Ledger Transaction");
 
1250   $readonly      = ($form->{id}) ? "readonly" : "";
 
1252   # $locale->text('Add General Ledger Transaction')
 
1253   # $locale->text('Edit General Ledger Transaction')
 
1255   map { $form->{$_} =~ s/\"/"/g }
 
1256     qw(reference description chart taxchart);
 
1257   $form->{javascript} = qq|<script type="text/javascript">
 
1259   function setTaxkey(accno, row) {
 
1260     var taxkey = accno.options[accno.selectedIndex].value;
 
1261     var reg = /--([0-9]*)/;
 
1262     var found = reg.exec(taxkey);
 
1263     var index = found[1];
 
1264     index = parseInt(index);
 
1265     var tax = 'taxchart_' + row;
 
1266     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
1267       var reg2 = new RegExp("^"+ index, "");
 
1268       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
1269         document.getElementById(tax).options[i].selected = true;
 
1277   $form->{selectdepartment} =~ s/ selected//;
 
1278   $form->{selectdepartment} =~
 
1279     s/option>\Q$form->{department}\E/option selected>$form->{department}/;
 
1281   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
 
1283       qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
 
1286       qq|<input name=description size=50 value="$form->{description}" tabindex="3" $readonly>|;
 
1289   $taxincluded = ($form->{taxincluded}) ? "checked" : "";
 
1292     $taxincluded = "checked";
 
1297           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1298           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1299           <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
1301 | if $form->{selectdepartment};
 
1303     $form->{fokus} = "gl.reference";
 
1305     $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
 
1308   # use JavaScript Calendar or not
 
1309   $form->{jsscript} = $jscalendar;
 
1311   if ($form->{jsscript}) {
 
1313     # with JavaScript Calendar
 
1315        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" tabindex="2" $readonly>
 
1316        <input type=button name=transdate id="trigger1" value=|
 
1317       . $locale->text('button') . qq|></td>  
 
1322       Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
 
1325     # without JavaScript Calendar
 
1327       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" tabindex="2" $readonly></td>|;
 
1333 <body onLoad="fokus()">
 
1335 <form method=post name="gl" action=$form->{script}>
 
1337 <input name=id type=hidden value=$form->{id}>
 
1339 <input type=hidden name=closedto value=$form->{closedto}>
 
1340 <input type=hidden name=locked value=$form->{locked}>
 
1341 <input type=hidden name=title value="$title">
 
1342 <input type=hidden name=taxchart value="$form->{taxchart}">
 
1343 <input type=hidden name=chart value="$form->{chart}">
 
1348     <th class=listtop>$form->{title}</th>
 
1350   <tr height="5"></tr>
 
1355           <th align=left>| . $locale->text('Reference') . qq|</th>
 
1356           <td><input name=reference size=20 value="$form->{reference}" tabindex="1" $readonly></td>
 
1360                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
 
1369           <th align=right>| . $locale->text('Belegnummer') . qq|</th>
 
1370           <td><input name=id size=20 value="$form->{id}" $readonly></td>
 
1374                 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
 
1375                 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly></td>
 
1386           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1387           <td width=1%>$description</td>
 
1391                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1392                 <td><input type=checkbox name=taxincluded value=1 tabindex="5" $taxincluded></td>
 
1399                 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
 
1400                 <td align=left><input name=employee size=11  value=$form->{employee} $readonly></td>
 
1408           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1409           <td width=1%>$description</td>
 
1413                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1414                 <td><input type=checkbox name=taxincluded value=1 tabindex="5" $taxincluded></td>
 
1424            <tr class=listheading>
 
1425           <th class=listheading style="width:15%">|
 
1426     . $locale->text('Account') . qq|</th>
 
1427           <th class=listheading style="width:10%">|
 
1428     . $locale->text('Debit') . qq|</th>
 
1429           <th class=listheading style="width:10%">|
 
1430     . $locale->text('Credit') . qq|</th>
 
1431           <th class=listheading style="width:10%">|
 
1432     . $locale->text('Tax') . qq|</th>
 
1433           <th class=listheading style="width:5%">|
 
1434     . $locale->text('Korrektur') . qq|</th>
 
1435           <th class=listheading style="width:10%">|
 
1436     . $locale->text('Taxkey') . qq|</th>
 
1437           <th class=listheading style="width:20%">|
 
1438     . $locale->text('Source') . qq|</th>
 
1439           <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
 
1440           <th class=listheading style="width:20%">|
 
1441     . $locale->text('Project Number') . qq|</th>
 
1446   $lxdebug->leave_sub();
 
1451   $lxdebug->enter_sub();
 
1452   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
 
1454   $decimalplaces = ($dec > 2) ? $dec : 2;
 
1455   $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
1459       $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
 
1460   } qw(totaldebit totalcredit);
 
1463     <tr class=listtotal>
 
1465     <th align=right class=listtotal> $form->{totaldebit}</th>
 
1466     <th align=right class=listtotal> $form->{totalcredit}</th> 
 
1474 <input type=hidden name=path value=$form->{path}>
 
1475 <input type=hidden name=login value=$form->{login}>
 
1476 <input type=hidden name=password value=$form->{password}>
 
1478 <input name=callback type=hidden value="$form->{callback}">
 
1483   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1484   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1488     print qq|<input class=submit type=submit name=action value="|
 
1489       . $locale->text('Storno') . qq|">|;
 
1491     # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
 
1493     if (!$form->{locked} && $radieren) {
 
1495                 <input class=submit type=submit name=action value="|
 
1496         . $locale->text('Post') . qq|" accesskey="b">
 
1497                 <input class=submit type=submit name=action value="|
 
1498         . $locale->text('Delete') . qq|">|;
 
1501     #   if ($transdate > $closedto) {
 
1503     #           <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">|;
 
1506     if ($transdate > $closedto) {
 
1507       print qq|<input class=submit type=submit name=action value="|
 
1508         . $locale->text('Update') . qq|">
 
1509                  <input class=submit type=submit name=action value="|
 
1510         . $locale->text('Post') . qq|">|;
 
1520   $lxdebug->leave_sub();
 
1525   $lxdebug->enter_sub();
 
1532 <form method=post action=$form->{script}>
 
1535   map { $form->{$_} =~ s/\"/"/g } qw(reference description chart taxchart);
 
1537   delete $form->{header};
 
1539   foreach $key (keys %$form) {
 
1540     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1544 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1547     . $locale->text('Are you sure you want to delete Transaction')
 
1548     . qq| $form->{reference}</h4>
 
1550 <input name=action class=submit type=submit value="|
 
1551     . $locale->text('Yes') . qq|">
 
1554   $lxdebug->leave_sub();
 
1559   $lxdebug->enter_sub();
 
1560   if (GL->delete_transaction(\%myconfig, \%$form)){
 
1561     # saving the history
 
1562       if(!exists $form->{addition} && $form->{id} ne "") {
 
1563             $form->{addition} = "DELETED";
 
1564             $form->save_history($form->dbconnect(\%myconfig));
 
1566     # /saving the history 
 
1567     $form->redirect($locale->text('Transaction deleted!'))
 
1569   $form->error($locale->text('Cannot delete transaction!'));
 
1570   $lxdebug->leave_sub();
 
1575   $lxdebug->enter_sub();
 
1577   # check if there is something in reference and date
 
1578   $form->isblank("reference",   $locale->text('Reference missing!'));
 
1579   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
 
1580   $form->isblank("description", $locale->text('Description missing!'));
 
1582   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1583   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1590   my $creditcount = 0;
 
1595     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
1596   if ($form->{storno}) {
 
1597     for my $i (1 .. $form->{rowcount}) {
 
1598       unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1599         if ($form->{"debit_$i"} ne "") {
 
1600           $form->{"credit_$i"} = $form->{"debit_$i"};
 
1601           $form->{"debit_$i"}  = "";
 
1602         } elsif ($form->{"credit_$i"} ne "") {
 
1603           $form->{"debit_$i"}  = $form->{"credit_$i"};
 
1604           $form->{"credit_$i"} = "";
 
1610   for my $i (1 .. $form->{rowcount}) {
 
1612     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1613       for (qw(debit credit tax)) {
 
1614         $form->{"${_}_$i"} =
 
1615           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
1619       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
1627       if (($debitcount >= 2) && ($creditcount == 2)) {
 
1628         $form->{"credit_$i"} = 0;
 
1629         $form->{"tax_$i"}    = 0;
 
1633       if (($creditcount >= 2) && ($debitcount == 2)) {
 
1634         $form->{"debit_$i"} = 0;
 
1635         $form->{"tax_$i"}   = 0;
 
1639       if (($creditcount == 1) && ($debitcount == 2)) {
 
1642       if (($creditcount == 2) && ($debitcount == 1)) {
 
1645       if ($debitcredit && $credittax) {
 
1646         $form->{"taxchart_$i"} = "0--0.00";
 
1648       if (!$debitcredit && $debittax) {
 
1649         $form->{"taxchart_$i"} = "0--0.00";
 
1652         ($form->{"debit_$i"} == 0)
 
1653         ? $form->{"credit_$i"}
 
1654         : $form->{"debit_$i"};
 
1656       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1657         $form->{"taxchart_$i"} = "0--0.00";
 
1658         $form->{"tax_$i"}      = 0;
 
1660       if (!$form->{"korrektur_$i"}) {
 
1661         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1668           if ($form->{taxincluded}) {
 
1669             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1671               $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1673               $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1676             $form->{"tax_$i"} = $amount * $rate;
 
1679           $form->{"tax_$i"} = 0;
 
1681       } elsif ($form->{taxincluded}) {
 
1683           $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1685           $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1689       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1694   for $i (1 .. $count) {
 
1696     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1699   for $i ($count + 1 .. $form->{rowcount}) {
 
1700     for (@flds) { delete $form->{"${_}_$i"} }
 
1703   for $i (1 .. $form->{rowcount}) {
 
1704     $dr  = $form->{"debit_$i"};
 
1705     $cr  = $form->{"credit_$i"};
 
1706     $tax = $form->{"tax_$i"};
 
1710           'Cannot post transaction with a debit and credit entry for the same account!'
 
1713     if ($form->{taxincluded}) {
 
1715         $debit += $dr + $tax;
 
1718         $credit += $cr + $tax;
 
1723         $debit += $dr + $tax;
 
1726         $credit += $cr + $tax;
 
1731     $form->{taxincluded} = 0;
 
1734   # this is just for the wise guys
 
1735   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
1736     if ($transdate <= $closedto);
 
1737   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
 
1738     $form->error($locale->text('Out of balance transaction!'));
 
1741   if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
 
1742     $form->error($locale->text('Empty transaction!'));
 
1745   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
 
1747     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
 
1748     $err[2] = $locale->text('Debit and credit out of balance!');
 
1749     $err[3] = $locale->text('Cannot post a transaction without a value!');
 
1751     $form->error($err[$errno]);
 
1753   undef($form->{callback});
 
1754   # saving the history
 
1755   if(!exists $form->{addition} && $form->{id} ne "") {
 
1756         $form->{addition} = "SAVED";
 
1757         $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; 
 
1758         $form->save_history($form->dbconnect(\%myconfig));
 
1760   # /saving the history 
 
1761   $form->redirect("Buchung gespeichert. Buchungsnummer = " . $form->{id});
 
1762   $lxdebug->leave_sub();
 
1767   $lxdebug->enter_sub();
 
1771   $lxdebug->leave_sub();
 
1776   $lxdebug->enter_sub();
 
1779   $form->{storno} = 1;
 
1780   # saving the history
 
1781   if(!exists $form->{addition} && $form->{id} ne "") {
 
1782         $form->{addition} = "STORNO";
 
1783         $form->save_history($form->dbconnect(\%myconfig));
 
1785   # /saving the history 
 
1787   $lxdebug->leave_sub();