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 #======================================================================
 
  38 require "bin/mozilla/arap.pl";
 
  39 require "bin/mozilla/common.pl";
 
  45 # this is for our long dates
 
  46 # $locale->text('January')
 
  47 # $locale->text('February')
 
  48 # $locale->text('March')
 
  49 # $locale->text('April')
 
  50 # $locale->text('May ')
 
  51 # $locale->text('June')
 
  52 # $locale->text('July')
 
  53 # $locale->text('August')
 
  54 # $locale->text('September')
 
  55 # $locale->text('October')
 
  56 # $locale->text('November')
 
  57 # $locale->text('December')
 
  59 # this is for our short month
 
  60 # $locale->text('Jan')
 
  61 # $locale->text('Feb')
 
  62 # $locale->text('Mar')
 
  63 # $locale->text('Apr')
 
  64 # $locale->text('May')
 
  65 # $locale->text('Jun')
 
  66 # $locale->text('Jul')
 
  67 # $locale->text('Aug')
 
  68 # $locale->text('Sep')
 
  69 # $locale->text('Oct')
 
  70 # $locale->text('Nov')
 
  71 # $locale->text('Dec')
 
  74   $lxdebug->enter_sub();
 
  76   $form->{title} = "Add";
 
  79     "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
 
  80     unless $form->{callback};
 
  82   # we use this only to set a default date
 
  83   GL->transaction(\%myconfig, \%$form);
 
  87       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
  88       . ($_->{rate} * 100) . qq| %|
 
  91   $form->{rowcount}  = 2;
 
  98   $form->all_departments(\%myconfig);
 
  99   if (@{ $form->{all_departments} }) {
 
 100     $form->{selectdepartment} = "<option>\n";
 
 103       $form->{selectdepartment} .=
 
 104         "<option>$_->{description}--$_->{id}\n"
 
 105     } (@{ $form->{all_departments} });
 
 109   $lxdebug->leave_sub();
 
 113 sub prepare_transaction {
 
 114   $lxdebug->enter_sub();
 
 116   GL->transaction(\%myconfig, \%$form);
 
 120       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
 
 121       . ($_->{rate} * 100) . qq| %|
 
 124   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
 
 127   $form->all_departments(\%myconfig);
 
 128   if (@{ $form->{all_departments} }) {
 
 129     $form->{selectdepartment} = "<option>\n";
 
 132       $form->{selectdepartment} .=
 
 133         "<option>$_->{description}--$_->{id}\n"
 
 134     } (@{ $form->{all_departments} });
 
 140   foreach $ref (@{ $form->{GL} }) {
 
 142     if ($tax && ($ref->{accno} eq $taxaccno)) {
 
 143       $form->{"tax_$j"}      = abs($ref->{amount});
 
 144       $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
 
 145       if ($form->{taxincluded}) {
 
 146         if ($ref->{amount} < 0) {
 
 147           $form->{"debit_$j"} += $form->{"tax_$j"};
 
 149           $form->{"credit_$j"} += $form->{"tax_$j"};
 
 152       $form->{"project_id_$j"} = $ref->{project_id};
 
 155       $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
 
 156       for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
 
 157       if ($ref->{amount} < 0) {
 
 158         $form->{totaldebit} -= $ref->{amount};
 
 159         $form->{"debit_$i"} = $ref->{amount} * -1;
 
 161         $form->{totalcredit} += $ref->{amount};
 
 162         $form->{"credit_$i"} = $ref->{amount};
 
 164       $form->{"taxchart_$i"} = "0--0.00";
 
 165       $form->{"project_id_$i"} = $ref->{project_id};
 
 168     if ($ref->{taxaccno} && !$tax) {
 
 169       $taxaccno = $ref->{taxaccno};
 
 177   $form->{rowcount} = $i;
 
 179     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 180      $form->datetonum($form->{closedto}, \%myconfig));
 
 182   $lxdebug->leave_sub();
 
 186   $lxdebug->enter_sub();
 
 188   prepare_transaction();
 
 190   $form->{title} = "Edit";
 
 196   $lxdebug->leave_sub();
 
 201   $lxdebug->enter_sub();
 
 203   $form->{title} = $locale->text('Buchungsjournal');
 
 205   $form->all_departments(\%myconfig);
 
 208   if (@{ $form->{all_departments} }) {
 
 209     $form->{selectdepartment} = "<option>\n";
 
 212       $form->{selectdepartment} .=
 
 213         "<option>$_->{description}--$_->{id}\n"
 
 214     } (@{ $form->{all_departments} });
 
 219           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 220           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 222 | if $form->{selectdepartment};
 
 224   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 227   my %project_labels = ();
 
 228   my @project_values = ("");
 
 229   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 230     push(@project_values, $item->{"id"});
 
 231     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 235     NTI($cgi->popup_menu('-name' => "project_id",
 
 236                          '-values' => \@project_values,
 
 237                          '-labels' => \%project_labels));
 
 239   # use JavaScript Calendar or not
 
 240   $form->{jsscript} = $jscalendar;
 
 242   if ($form->{jsscript}) {
 
 244     # with JavaScript Calendar
 
 246        <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
 247        <input type=button name=datefrom id="trigger1" value=|
 
 248       . $locale->text('button') . qq|></td>  
 
 251        <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
 252        <input type=button name=dateto id="trigger2" value=|
 
 253       . $locale->text('button') . qq|></td>
 
 258       Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
 
 259                           "dateto", "BL", "trigger2");
 
 262     # without JavaScript Calendar
 
 264       qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 266       qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 268   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 270   $onload = qq|focus()|;
 
 271   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 272   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 274 <body onLoad="$onload">
 
 276 <form method=post action=$form->{script}>
 
 278 <input type=hidden name=sort value=transdate>
 
 282     <th class=listtop>$form->{title}</th>
 
 289           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 290           <td><input name=reference size=20></td>
 
 291           <th align=right>| . $locale->text('Source') . qq|</th>
 
 292           <td><input name=source size=20></td>
 
 296           <th align=right>| . $locale->text('Description') . qq|</th>
 
 297           <td colspan=3><input name=description size=40></td>
 
 300           <th align=right>| . $locale->text('Notes') . qq|</th>
 
 301           <td colspan=3><input name=notes size=40></td>
 
 304           <th align=right>| . $locale->text('Project Number') . qq|</th>
 
 305           <td colspan=3>$projectnumber</td>
 
 308           <th align=right>| . $locale->text('From') . qq|</th>
 
 310           <th align=right>| . $locale->text('To (time)') . qq|</th>
 
 314           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 319                   <input name="category" class=radio type=radio value=X checked> |
 
 320     . $locale->text('All') . qq|
 
 321                   <input name="category" class=radio type=radio value=A> |
 
 322     . $locale->text('Asset') . qq|
 
 323                   <input name="category" class=radio type=radio value=L> |
 
 324     . $locale->text('Liability') . qq|
 
 325                   <input name="category" class=radio type=radio value=I> |
 
 326     . $locale->text('Revenue') . qq|
 
 327                   <input name="category" class=radio type=radio value=E> |
 
 328     . $locale->text('Expense') . qq|
 
 334                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 335                     <td>| . $locale->text('ID') . qq|</td>
 
 336                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 337                     <td>| . $locale->text('Date') . qq|</td>
 
 338                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
 
 339                     <td>| . $locale->text('Reference') . qq|</td>
 
 340                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
 
 341                     <td>| . $locale->text('Description') . qq|</td>
 
 342                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
 343                     <td>| . $locale->text('Notes') . qq|</td>
 
 346                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
 
 347                     <td>| . $locale->text('Debit') . qq|</td>
 
 348                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
 
 349                     <td>| . $locale->text('Credit') . qq|</td>
 
 350                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
 
 351                     <td>| . $locale->text('Source') . qq|</td>
 
 352                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
 
 353                     <td>| . $locale->text('Account') . qq|</td>
 
 356                     <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 357                     <td>| . $locale->text('Subtotal') . qq|</td>
 
 358                     <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
 
 359                     <td>| . $locale->text('Project Number') . qq|</td>
 
 369     <td><hr size=3 noshade></td>
 
 375 <input type=hidden name=nextsub value=generate_report>
 
 377 <input type=hidden name=login value=$form->{login}>
 
 378 <input type=hidden name=password value=$form->{password}>
 
 381 <input class=submit type=submit name=action value="|
 
 382     . $locale->text('Continue') . qq|">
 
 388   $lxdebug->leave_sub();
 
 391 sub generate_report {
 
 392   $lxdebug->enter_sub();
 
 394   $form->{sort} = "transdate" unless $form->{sort};
 
 396   GL->all_transactions(\%myconfig, \%$form);
 
 399     "$form->{script}?action=generate_report&login=$form->{login}&password=$form->{password}";
 
 403   %acctype = ('A' => $locale->text('Asset'),
 
 404               'C' => $locale->text('Contra'),
 
 405               'L' => $locale->text('Liability'),
 
 406               'Q' => $locale->text('Equity'),
 
 407               'I' => $locale->text('Revenue'),
 
 408               'E' => $locale->text('Expense'),);
 
 410   $form->{title} = $locale->text('General Ledger');
 
 412   $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
 
 414   unless ($form->{category} eq 'X') {
 
 415     $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
 
 417   if ($form->{accno}) {
 
 418     $href .= "&accno=" . $form->escape($form->{accno});
 
 419     $callback .= "&accno=" . $form->escape($form->{accno}, 1);
 
 421       $locale->text('Account')
 
 422       . " : $form->{accno} $form->{account_description}";
 
 424   if ($form->{source}) {
 
 425     $href     .= "&source=" . $form->escape($form->{source});
 
 426     $callback .= "&source=" . $form->escape($form->{source}, 1);
 
 427     $option   .= "\n<br>" if $option;
 
 428     $option   .= $locale->text('Source') . " : $form->{source}";
 
 430   if ($form->{reference}) {
 
 431     $href     .= "&reference=" . $form->escape($form->{reference});
 
 432     $callback .= "&reference=" . $form->escape($form->{reference}, 1);
 
 433     $option   .= "\n<br>" if $option;
 
 434     $option   .= $locale->text('Reference') . " : $form->{reference}";
 
 436   if ($form->{department}) {
 
 437     $href .= "&department=" . $form->escape($form->{department});
 
 438     $callback .= "&department=" . $form->escape($form->{department}, 1);
 
 439     ($department) = split /--/, $form->{department};
 
 440     $option .= "\n<br>" if $option;
 
 441     $option .= $locale->text('Department') . " : $department";
 
 444   if ($form->{description}) {
 
 445     $href     .= "&description=" . $form->escape($form->{description});
 
 446     $callback .= "&description=" . $form->escape($form->{description}, 1);
 
 447     $option   .= "\n<br>" if $option;
 
 448     $option   .= $locale->text('Description') . " : $form->{description}";
 
 450   if ($form->{notes}) {
 
 451     $href     .= "¬es=" . $form->escape($form->{notes});
 
 452     $callback .= "¬es=" . $form->escape($form->{notes}, 1);
 
 453     $option   .= "\n<br>" if $option;
 
 454     $option   .= $locale->text('Notes') . " : $form->{notes}";
 
 456  if ($form->{project_id}) {
 
 457     $href     .= "&project_id=" . $form->escape($form->{project_id});
 
 458     $callback .= "&project_id=" . $form->escape($form->{project_id});
 
 461   if ($form->{datefrom}) {
 
 462     $href     .= "&datefrom=$form->{datefrom}";
 
 463     $callback .= "&datefrom=$form->{datefrom}";
 
 464     $option   .= "\n<br>" if $option;
 
 466         $locale->text('From') . " "
 
 467       . $locale->date(\%myconfig, $form->{datefrom}, 1);
 
 469   if ($form->{dateto}) {
 
 470     $href     .= "&dateto=$form->{dateto}";
 
 471     $callback .= "&dateto=$form->{dateto}";
 
 472     if ($form->{datefrom}) {
 
 475       $option .= "\n<br>" if $option;
 
 478         $locale->text('Bis') . " "
 
 479       . $locale->date(\%myconfig, $form->{dateto}, 1);
 
 482   @columns = $form->sort_columns( qw(
 
 483        transdate       id                reference         description  
 
 484        notes           source            debit             debit_accno  
 
 485        credit          credit_accno      debit_tax         debit_tax_accno
 
 486        credit_tax      credit_tax_accno  accno
 
 491   if ($form->{accno}) {
 
 492     @columns = grep !/accno/, @columns;
 
 493     push @columns, "balance";
 
 494     $form->{l_balance} = "Y";
 
 498   $form->{l_credit_accno}     = "Y";
 
 499   $form->{l_debit_accno}      = "Y";
 
 500   $form->{l_credit_tax}       = "Y";
 
 501   $form->{l_debit_tax}        = "Y";
 
 502   $form->{l_credit_tax_accno} = "Y";
 
 503   $form->{l_debit_tax_accno}  = "Y";
 
 504   $form->{l_accno}            = "N";
 
 505   foreach $item (@columns) {
 
 506     if ($form->{"l_$item"} eq "Y") {
 
 507       push @column_index, $item;
 
 509       # add column to href and callback
 
 510       $callback .= "&l_$item=Y";
 
 511       $href     .= "&l_$item=Y";
 
 515   if ($form->{l_subtotal} eq 'Y') {
 
 516     $callback .= "&l_subtotal=Y";
 
 517     $href     .= "&l_subtotal=Y";
 
 520   $callback .= "&category=$form->{category}";
 
 521   $href     .= "&category=$form->{category}";
 
 524       "<th><a class=listheading href=$href&sort=id>"
 
 525     . $locale->text('ID')
 
 527   $column_header{transdate} =
 
 528       "<th><a class=listheading href=$href&sort=transdate>"
 
 529     . $locale->text('Date')
 
 531   $column_header{reference} =
 
 532       "<th><a class=listheading href=$href&sort=reference>"
 
 533     . $locale->text('Reference')
 
 535   $column_header{source} =
 
 536       "<th><a class=listheading href=$href&sort=source>"
 
 537     . $locale->text('Source')
 
 539   $column_header{description} =
 
 540       "<th><a class=listheading href=$href&sort=description>"
 
 541     . $locale->text('Description')
 
 543   $column_header{notes} =
 
 544     "<th class=listheading>" . $locale->text('Notes') . "</th>";
 
 545   $column_header{debit} =
 
 546     "<th class=listheading>" . $locale->text('Debit') . "</th>";
 
 547   $column_header{debit_accno} =
 
 548       "<th><a class=listheading href=$href&sort=accno>"
 
 549     . $locale->text('Debit Account')
 
 551   $column_header{credit} =
 
 552     "<th class=listheading>" . $locale->text('Credit') . "</th>";
 
 553   $column_header{credit_accno} =
 
 554       "<th><a class=listheading href=$href&sort=accno>"
 
 555     . $locale->text('Credit Account')
 
 557   $column_header{debit_tax} =
 
 558       "<th><a class=listheading href=$href&sort=accno>"
 
 559     . $locale->text('Debit Tax')
 
 561   $column_header{debit_tax_accno} =
 
 562       "<th><a class=listheading href=$href&sort=accno>"
 
 563     . $locale->text('Debit Tax Account')
 
 565   $column_header{credit_tax} =
 
 566       "<th><a class=listheading href=$href&sort=accno>"
 
 567     . $locale->text('Credit Tax')
 
 569   $column_header{credit_tax_accno} =
 
 570       "<th><a class=listheading href=$href&sort=accno>"
 
 571     . $locale->text('Credit Tax Account')
 
 573   $column_header{balance} = "<th>" . $locale->text('Balance') . "</th>";
 
 574   $column_header{projectnumbers} =
 
 575       "<th class=listheading>"  . $locale->text('Project Numbers') . "</th>";
 
 577   $form->{landscape} = 1;
 
 586     <th class=listtop>$form->{title}</th>
 
 596         <tr class=listheading>
 
 599   map { print "$column_header{$_}\n" } @column_index;
 
 608   # add sort to callback
 
 609   $form->{callback} = "$callback&sort=$form->{sort}";
 
 610   $callback = $form->escape($form->{callback});
 
 612   # initial item for subtotals
 
 613   if (@{ $form->{GL} }) {
 
 614     $sameitem = $form->{GL}->[0]->{ $form->{sort} };
 
 617   if ($form->{accno} && $form->{balance}) {
 
 619     map { $column_data{$_} = "<td> </td>" } @column_index;
 
 620     $column_data{balance} =
 
 622       . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
 
 630     map { print "$column_data{$_}\n" } @column_index;
 
 636   $form->{balance} *= $ml;
 
 637   foreach $ref (@{ $form->{GL} }) {
 
 638     $form->{balance} *= $ml;
 
 640     # if item ne sort print subtotal
 
 641     if ($form->{l_subtotal} eq 'Y') {
 
 642       if ($sameitem ne $ref->{ $form->{sort} }) {
 
 647     #foreach $key (sort keys(%{ $ref->{amount} })) {
 
 648     #  $form->{balance} += $ref->{amount}{$key};
 
 652     foreach $key (sort keys(%{ $ref->{debit} })) {
 
 653       $subtotaldebit += $ref->{debit}{$key};
 
 654       $totaldebit    += $ref->{debit}{$key};
 
 656         $debit = $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 659           "<br>" . $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
 
 661       $form->{balance} = abs($form->{balance}) - abs($ref->{debit}{$key});
 
 665     foreach $key (sort keys(%{ $ref->{credit} })) {
 
 666       $subtotalcredit += $ref->{credit}{$key};
 
 667       $totalcredit    += $ref->{credit}{$key};
 
 669         $credit = $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 672           . $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
 
 674       $form->{balance} = abs($form->{balance}) - abs($ref->{credit}{$key});
 
 678     foreach $key (sort keys(%{ $ref->{debit_tax} })) {
 
 679       $subtotaldebittax += $ref->{debit_tax}{$key};
 
 680       $totaldebittax    += $ref->{debit_tax}{$key};
 
 683           $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 686           . $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
 
 688       $form->{balance} = abs($form->{balance}) - abs($ref->{debit_tax}{$key});
 
 692     foreach $key (sort keys(%{ $ref->{credit_tax} })) {
 
 693       $subtotalcredittax += $ref->{credit_tax}{$key};
 
 694       $totalcredittax    += $ref->{credit_tax}{$key};
 
 697           $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 700           . $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
 
 702       $form->{balance} = abs($form->{balance}) - abs($ref->{credit_tax}{$key});
 
 708     foreach $key (sort keys(%{ $ref->{debit_accno} })) {
 
 711           "<a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 714           "<br><a href=$href&accno=$ref->{debit_accno}{$key}&callback=$callback>$ref->{debit_accno}{$key}</a>";
 
 717       #       if ($ref->{debit_taxkey}{$key} eq $debittaxkey) {
 
 718       #         $ref->{debit_tax_accno}{$key} = $taxaccno;
 
 720       $taxaccno    = $ref->{debit_tax_accno}{$key};
 
 721       $debittaxkey = $ref->{debit_taxkey}{$key};
 
 727     foreach $key (sort keys(%{ $ref->{credit_accno} })) {
 
 730           "<a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 733           "<br><a href=$href&accno=$ref->{credit_accno}{$key}&callback=$callback>$ref->{credit_accno}{$key}</a>";
 
 736       #       if ($ref->{credit_taxkey}{$key} eq $credittaxkey) {
 
 737       #         $ref->{credit_tax_accno}{$key} = $taxaccno;
 
 739       $taxaccno     = $ref->{credit_tax_accno}{$key};
 
 740       $credittaxkey = $ref->{credit_taxkey}{$key};
 
 744     foreach $key (sort keys(%{ $ref->{debit_tax_accno} })) {
 
 747           "<a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 750           "<br><a href=$href&accno=$ref->{debit_tax_accno}{$key}&callback=$callback>$ref->{debit_tax_accno}{$key}</a>";
 
 754     $credittaxaccno = "";
 
 755     foreach $key (sort keys(%{ $ref->{credit_tax_accno} })) {
 
 758           "<a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 761           "<br><a href=$href&accno=$ref->{credit_tax_accno}{$key}&callback=$callback>$ref->{credit_tax_accno}{$key}</a>";
 
 766     foreach $key (sort keys(%{ $ref->{ac_transdate} })) {
 
 768         $transdate = "$ref->{ac_transdate}{$key}";
 
 770         $transdate .= "<br>$ref->{ac_transdate}{$key}";
 
 774     #    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
 
 775     #    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
 
 777     $column_data{id}        = "<td align=right> $ref->{id} </td>";
 
 778     $column_data{transdate}    = "<td align=center>$transdate</td>";
 
 779     $column_data{reference} =
 
 780       "<td align=center><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
 
 781     $column_data{description}  = "<td align=center>$ref->{description} </td>";
 
 782     $column_data{source}       = "<td align=center>$ref->{source} </td>";
 
 783     $column_data{notes}        = "<td align=center>$ref->{notes} </td>";
 
 784     $column_data{debit}        = "<td align=right>$debit</td>";
 
 785     $column_data{debit_accno}  = "<td align=center>$debitaccno</td>";
 
 786     $column_data{credit}       = "<td align=right>$credit</td>";
 
 787     $column_data{credit_accno} = "<td align=center>$creditaccno</td>";
 
 788     $column_data{debit_tax}    =
 
 789       ($ref->{debit_tax_accno} ne "")
 
 790       ? "<td align=right>$debittax</td>"
 
 792     $column_data{debit_tax_accno} = "<td align=center>$debittaxaccno</td>";
 
 793     $column_data{credit_tax} =
 
 794       ($ref->{credit_tax_accno} ne "")
 
 795       ? "<td align=right>$credittax</td>"
 
 797     $column_data{credit_tax_accno} = "<td align=center>$credittaxaccno</td>";
 
 798     $column_data{balance} =
 
 800       . $form->format_amount(\%myconfig, $form->{balance}, 2, 0) . "</td>";
 
 801     $column_data{projectnumbers} =
 
 802       "<td>" . join(", ", sort({ lc($a) cmp lc($b) } keys(%{ $ref->{projectnumbers} }))) . "</td>";
 
 807         <tr class=listrow$i>";
 
 808     map { print "$column_data{$_}\n" } @column_index;
 
 813   &gl_subtotal if ($form->{l_subtotal} eq 'Y');
 
 815   map { $column_data{$_} = "<td> </td>" } @column_index;
 
 817   my $balanced_ledger = $totaldebit 
 
 821                     # = 0 for balanced ledger
 
 823   $column_data{debit} =
 
 824     "<th align=right class=listtotal>"
 
 825     . $form->format_amount(\%myconfig, $totaldebit, 2, " ") . "</th>";
 
 826   $column_data{credit} =
 
 827     "<th align=right class=listtotal>"
 
 828     . $form->format_amount(\%myconfig, $totalcredit, 2, " ") . "</th>";
 
 829   $column_data{debit_tax} =
 
 830     "<th align=right class=listtotal>"
 
 831     . $form->format_amount(\%myconfig, $totaldebittax, 2, " ") . "</th>";
 
 832   $column_data{credit_tax} =
 
 833     "<th align=right class=listtotal>"
 
 834     . $form->format_amount(\%myconfig, $totalcredittax, 2, " ") . "</th>";
 
 835   $column_data{balance} =
 
 836     "<th align=right class=listtotal>"
 
 837     . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0) . "</th>";
 
 843   map { print "$column_data{$_}\n" } @column_index;
 
 850   if ( abs($balanced_ledger) >  0.001 ) {
 
 852     print qq|<td colspan="4" style="background-color:#FFA0A0" >|
 
 853         . $locale->text('Unbalanced Ledger') 
 
 855         . $form->format_amount(\%myconfig, $balanced_ledger, 3, " ")
 
 857   } elsif ( abs($balanced_ledger) <= 0.001 ) {
 
 859     print qq|<td colspan="3">|
 
 860           . $locale->text('Balanced Ledger') 
 
 873     <td><hr size=3 noshade></td>
 
 879 <form method=post action=$form->{script}>
 
 881 <input name=callback type=hidden value="$form->{callback}">
 
 883 <input type=hidden name=login value=$form->{login}>
 
 884 <input type=hidden name=password value=$form->{password}>
 
 886 <input class=submit type=submit name=action value="|
 
 887     . $locale->text('GL Transaction') . qq|">
 
 888 <input class=submit type=submit name=action value="|
 
 889     . $locale->text('AR Transaction') . qq|">
 
 890 <input class=submit type=submit name=action value="|
 
 891     . $locale->text('AP Transaction') . qq|">
 
 892 <input class=submit type=submit name=action value="|
 
 893     . $locale->text('Sales Invoice') . qq|">
 
 894 <input class=submit type=submit name=action value="|
 
 895     . $locale->text('Vendor Invoice') . qq|">
 
 902   $lxdebug->leave_sub();
 
 907   $lxdebug->enter_sub();
 
 910     $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
 
 912     $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
 
 914   map { $column_data{$_} = "<td> </td>" }
 
 915     qw(transdate id reference source description accno);
 
 916   $column_data{debit}  = "<th align=right>$subtotaldebit</td>";
 
 917   $column_data{credit} = "<th align=right>$subtotalcredit</td>";
 
 919   print "<tr class=listsubtotal>";
 
 920   map { print "$column_data{$_}\n" } @column_index;
 
 926   $sameitem = $ref->{ $form->{sort} };
 
 927   $lxdebug->leave_sub();
 
 932   $lxdebug->enter_sub();
 
 934   $form->{oldtransdate} = $form->{transdate};
 
 946     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
 948   for my $i (1 .. $form->{rowcount}) {
 
 950     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
 951       for (qw(debit credit tax)) {
 
 953           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
 957       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
 964       if (($debitcount >= 2) && ($creditcount == 2)) {
 
 965         $form->{"credit_$i"} = 0;
 
 966         $form->{"tax_$i"}    = 0;
 
 970       if (($creditcount >= 2) && ($debitcount == 2)) {
 
 971         $form->{"debit_$i"} = 0;
 
 972         $form->{"tax_$i"}   = 0;
 
 976       if (($creditcount == 1) && ($debitcount == 2)) {
 
 979       if (($creditcount == 2) && ($debitcount == 1)) {
 
 982       if ($debitcredit && $credittax) {
 
 983         $form->{"taxchart_$i"} = "0--0.00";
 
 985       if (!$debitcredit && $debittax) {
 
 986         $form->{"taxchart_$i"} = "0--0.00";
 
 989         ($form->{"debit_$i"} == 0)
 
 990         ? $form->{"credit_$i"}
 
 991         : $form->{"debit_$i"};
 
 993       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
 994         $form->{"taxchart_$i"} = "0--0.00";
 
 995         $form->{"tax_$i"}      = 0;
 
 997       if (!$form->{"korrektur_$i"}) {
 
 998         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1005           if ($form->{taxincluded}) {
 
1006             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1008             $form->{"tax_$i"} = $amount * $rate;
 
1011           $form->{"tax_$i"} = 0;
 
1015       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1020   for $i (1 .. $count) {
 
1022     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1025   for $i ($count + 1 .. $form->{rowcount}) {
 
1026     for (@flds) { delete $form->{"${_}_$i"} }
 
1029   $form->{rowcount} = $count + 1;
 
1032   $lxdebug->leave_sub();
 
1038   $lxdebug->enter_sub();
 
1040   &form_header($init);
 
1042   #   for $i (1 .. $form->{rowcount}) {
 
1043   #     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
 
1044   #     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
 
1048   &display_rows($init);
 
1050   $lxdebug->leave_sub();
 
1056   $lxdebug->enter_sub();
 
1058   $form->{totaldebit}  = 0;
 
1059   $form->{totalcredit} = 0;
 
1061   my @old_project_ids = ();
 
1062   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
1063           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
1065   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1067                                    "old_id" => \@old_project_ids },
 
1068                    "charts" => { "key" => "ALL_CHARTS",
 
1069                                  "transdate" => $form->{transdate} },
 
1070                    "taxcharts" => "ALL_TAXCHARTS");
 
1072   my %project_labels = ();
 
1073   my @project_values = ("");
 
1074   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1075     push(@project_values, $item->{"id"});
 
1076     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
1079   my %chart_labels = ();
 
1080   my @chart_values = ();
 
1083   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
1084     my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
 
1085     $taxchart_init = $item->{taxkey_id} unless (@chart_values);
 
1086     push(@chart_values, $key);
 
1087     $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
 
1088     $charts{$item->{accno}} = $item;
 
1091   my %taxchart_labels = ();
 
1092   my @taxchart_values = ();
 
1094   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
1095     my $key = Q($item->{id}) . "--" . Q($item->{rate});
 
1096     $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
 
1097     push(@taxchart_values, $key);
 
1098     $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
 
1099       H($item->{rate} * 100) . ' %';
 
1100     $taxcharts{$item->{id}} = $item;
 
1103   for $i (1 .. $form->{rowcount}) {
 
1106     <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
 
1108     <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
 
1110     my $selected_accno_full;
 
1111     my ($accno_row) = split(/--/, $form->{"accno_$i"});
 
1112     my $item = $charts{$accno_row};
 
1113     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
 
1115     my $selected_taxchart = $form->{"taxchart_$i"};
 
1116     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
 
1117     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
 
1119     if ($previous_accno &&
 
1120         ($previous_accno eq $selected_accno) &&
 
1121         ($previous_tax_id ne $selected_tax_id)) {
 
1122       my $item = $taxcharts{$selected_tax_id};
 
1123       $selected_taxchart = "$item->{id}--$item->{rate}";
 
1126     $selected_accno = '' if ($init);
 
1127     $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
 
1130       NTI($cgi->popup_menu('-name' => "accno_$i",
 
1131                            '-id' => "accno_$i",
 
1132                            '-onChange' => "setTaxkey(this, $i)",
 
1133                            '-style' => 'width:200px',
 
1134                            '-values' => \@chart_values,
 
1135                            '-labels' => \%chart_labels,
 
1136                            '-default' => $selected_accno_full))
 
1137       . $cgi->hidden('-name' => "previous_accno_$i",
 
1138                      '-default' => $selected_accno_full)
 
1141       NTI($cgi->popup_menu('-name' => "taxchart_$i",
 
1142                            '-id' => "taxchart_$i",
 
1143                            '-style' => 'width:200px',
 
1144                            '-values' => \@taxchart_values,
 
1145                            '-labels' => \%taxchart_labels,
 
1146                            '-default' => $selected_taxchart))
 
1151         qq|<td><input type="checkbox" name="korrektur_$i" value="1"</td>|;
 
1152       if ($form->{transfer}) {
 
1153         $fx_transaction = qq|
 
1154         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1159       if ($form->{"debit_$i"} != 0) {
 
1160         $form->{totaldebit} += $form->{"debit_$i"};
 
1161         if (!$form->{taxincluded}) {
 
1162           $form->{totaldebit} += $form->{"tax_$i"};
 
1165         $form->{totalcredit} += $form->{"credit_$i"};
 
1166         if (!$form->{taxincluded}) {
 
1167           $form->{totalcredit} += $form->{"tax_$i"};
 
1171       for (qw(debit credit tax)) {
 
1172         $form->{"${_}_$i"} =
 
1173           ($form->{"${_}_$i"})
 
1174           ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
 
1178       if ($i < $form->{rowcount}) {
 
1179         if ($form->{transfer}) {
 
1180           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
 
1181           $x = ($checked) ? "x" : "";
 
1182           $fx_transaction = qq|
 
1183       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
 
1186         $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
 
1188           qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked></td>|;
 
1189         $form->hide_form("accno_$i");
 
1193           qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
 
1194         if ($form->{transfer}) {
 
1195           $fx_transaction = qq|
 
1196       <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
 
1201     my $debitreadonly  = "";
 
1202     my $creditreadonly = "";
 
1203     if ($i == $form->{rowcount}) {
 
1205         $debitreadonly = "readonly";
 
1206       } elsif ($creditlock) {
 
1207         $creditreadonly = "readonly";
 
1212       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
1213                            '-values' => \@project_values,
 
1214                            '-labels' => \%project_labels,
 
1215                            '-default' => $form->{"project_id_$i"} ));
 
1217     print qq|<tr valign=top>
 
1220     <td><input name="debit_$i" size=8 value="$form->{"debit_$i"}" accesskey=$i $debitreadonly></td>
 
1221     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
 
1222     <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
 
1227     <td>$projectnumber</td>
 
1233   $form->hide_form(qw(rowcount selectaccno));
 
1235   $lxdebug->leave_sub();
 
1241   $lxdebug->enter_sub();
 
1242   $title         = $form->{title};
 
1243   $form->{title} = $locale->text("$title General Ledger Transaction");
 
1244   $readonly      = ($form->{id}) ? "readonly" : "";
 
1246   # $locale->text('Add General Ledger Transaction')
 
1247   # $locale->text('Edit General Ledger Transaction')
 
1249   map { $form->{$_} =~ s/\"/"/g }
 
1250     qw(reference description chart taxchart);
 
1251   $form->{javascript} = qq|<script type="text/javascript">
 
1253   function setTaxkey(accno, row) {
 
1254     var taxkey = accno.options[accno.selectedIndex].value;
 
1255     var reg = /--([0-9]*)/;
 
1256     var found = reg.exec(taxkey);
 
1257     var index = found[1];
 
1258     index = parseInt(index);
 
1259     var tax = 'taxchart_' + row;
 
1260     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
1261       var reg2 = new RegExp("^"+ index, "");
 
1262       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
1263         document.getElementById(tax).options[i].selected = true;
 
1271   $form->{selectdepartment} =~ s/ selected//;
 
1272   $form->{selectdepartment} =~
 
1273     s/option>\Q$form->{department}\E/option selected>$form->{department}/;
 
1275   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
 
1277       qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
 
1280       qq|<input name=description size=50 value="$form->{description}" $readonly>|;
 
1283   $taxincluded = ($form->{taxincluded}) ? "checked" : "";
 
1286     $taxincluded = "checked";
 
1291           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1292           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1293           <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
1295 | if $form->{selectdepartment};
 
1297     $form->{fokus} = "gl.reference";
 
1299     $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
 
1302   # use JavaScript Calendar or not
 
1303   $form->{jsscript} = $jscalendar;
 
1305   if ($form->{jsscript}) {
 
1307     # with JavaScript Calendar
 
1309        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
 
1310        <input type=button name=transdate id="trigger1" value=|
 
1311       . $locale->text('button') . qq|></td>  
 
1316       Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
 
1319     # without JavaScript Calendar
 
1321       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
 
1327 <body onLoad="fokus()">
 
1329 <form method=post name="gl" action=$form->{script}>
 
1332   $form->hide_form(qw(id closedto locked storno storno_id));
 
1335 <input type=hidden name=title value="$title">
 
1340     <th class=listtop>$form->{title}</th>
 
1342   <tr height="5"></tr>
 
1347           <th align=right>| . $locale->text('Reference') . qq|</th>
 
1348           <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
 
1352                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
 
1361           <th align=right>| . $locale->text('Belegnummer') . qq|</th>
 
1362           <td><input name=id size=20 value="$form->{id}" $readonly></td>
 
1366                 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
 
1367                 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
 
1378           <th align=right width=1%>| . $locale->text('Description') . qq|</th>
 
1379           <td width=1%>$description</td>
 
1383                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1384                 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
 
1391                 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
 
1392                 <td align=left><input name=employee size=20  value="| . H($form->{employee}) . qq|" readonly></td>
 
1400           <th align=left width=1%>| . $locale->text('Description') . qq|</th>
 
1401           <td width=1%>$description</td>
 
1405                 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
 
1406                 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
 
1416            <tr class=listheading>
 
1417           <th class=listheading style="width:15%">|
 
1418     . $locale->text('Account') . qq|</th>
 
1419           <th class=listheading style="width:10%">|
 
1420     . $locale->text('Debit') . qq|</th>
 
1421           <th class=listheading style="width:10%">|
 
1422     . $locale->text('Credit') . qq|</th>
 
1423           <th class=listheading style="width:10%">|
 
1424     . $locale->text('Tax') . qq|</th>
 
1425           <th class=listheading style="width:5%">|
 
1426     . $locale->text('Korrektur') . qq|</th>
 
1427           <th class=listheading style="width:10%">|
 
1428     . $locale->text('Taxkey') . qq|</th>
 
1429           <th class=listheading style="width:20%">|
 
1430     . $locale->text('Source') . qq|</th>
 
1431           <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
 
1432           <th class=listheading style="width:20%">|
 
1433     . $locale->text('Project Number') . qq|</th>
 
1438   $lxdebug->leave_sub();
 
1443   $lxdebug->enter_sub();
 
1444   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
 
1446   $decimalplaces = ($dec > 2) ? $dec : 2;
 
1447   $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
1451       $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
 
1452   } qw(totaldebit totalcredit);
 
1455     <tr class=listtotal>
 
1457     <th align=right class=listtotal> $form->{totaldebit}</th>
 
1458     <th align=right class=listtotal> $form->{totalcredit}</th> 
 
1466 <input type=hidden name=login value=$form->{login}>
 
1467 <input type=hidden name=password value=$form->{password}>
 
1469 <input name=callback type=hidden value="$form->{callback}">
 
1474   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1475   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1479     if (!$form->{storno}) {
 
1480       print qq|<input class=submit type=submit name=action value="|
 
1481         . $locale->text('Storno') . qq|">|;
 
1484     # Löschen und Ã„ndern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
 
1486     if (!$form->{locked} && $radieren) {
 
1488                 <input class=submit type=submit name=action value="|
 
1489         . $locale->text('Post') . qq|" accesskey="b">
 
1490                 <input class=submit type=submit name=action value="|
 
1491         . $locale->text('Delete') . qq|">|;
 
1494     #   if ($transdate > $closedto) {
 
1496     #           <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">|;
 
1499     if ($transdate > $closedto) {
 
1500       print qq|<input class=submit type=submit name=action value="|
 
1501         . $locale->text('Update') . qq|">
 
1502                  <input class=submit type=submit name=action value="|
 
1503         . $locale->text('Post') . qq|">|;
 
1513   $lxdebug->leave_sub();
 
1518   $lxdebug->enter_sub();
 
1525 <form method=post action=$form->{script}>
 
1528   map { $form->{$_} =~ s/\"/"/g } qw(reference description);
 
1530   delete $form->{header};
 
1532   foreach $key (keys %$form) {
 
1533     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1537 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1540     . $locale->text('Are you sure you want to delete Transaction')
 
1541     . qq| $form->{reference}</h4>
 
1543 <input name=action class=submit type=submit value="|
 
1544     . $locale->text('Yes') . qq|">
 
1547   $lxdebug->leave_sub();
 
1552   $lxdebug->enter_sub();
 
1553   if (GL->delete_transaction(\%myconfig, \%$form)){
 
1554     # saving the history
 
1555       if(!exists $form->{addition} && $form->{id} ne "") {
 
1556         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1557             $form->{addition} = "DELETED";
 
1558             $form->save_history($form->dbconnect(\%myconfig));
 
1560     # /saving the history 
 
1561     $form->redirect($locale->text('Transaction deleted!'))
 
1563   $form->error($locale->text('Cannot delete transaction!'));
 
1564   $lxdebug->leave_sub();
 
1569   $lxdebug->enter_sub();
 
1571   # check if there is something in reference and date
 
1572   $form->isblank("reference",   $locale->text('Reference missing!'));
 
1573   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
 
1574   $form->isblank("description", $locale->text('Description missing!'));
 
1576   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1577   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1584   my $creditcount = 0;
 
1589     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
1591   for my $i (1 .. $form->{rowcount}) {
 
1593     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
 
1594       for (qw(debit credit tax)) {
 
1595         $form->{"${_}_$i"} =
 
1596           $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
 
1600       $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
 
1608       if (($debitcount >= 2) && ($creditcount == 2)) {
 
1609         $form->{"credit_$i"} = 0;
 
1610         $form->{"tax_$i"}    = 0;
 
1614       if (($creditcount >= 2) && ($debitcount == 2)) {
 
1615         $form->{"debit_$i"} = 0;
 
1616         $form->{"tax_$i"}   = 0;
 
1620       if (($creditcount == 1) && ($debitcount == 2)) {
 
1623       if (($creditcount == 2) && ($debitcount == 1)) {
 
1626       if ($debitcredit && $credittax) {
 
1627         $form->{"taxchart_$i"} = "0--0.00";
 
1629       if (!$debitcredit && $debittax) {
 
1630         $form->{"taxchart_$i"} = "0--0.00";
 
1633         ($form->{"debit_$i"} == 0)
 
1634         ? $form->{"credit_$i"}
 
1635         : $form->{"debit_$i"};
 
1637       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
 
1638         $form->{"taxchart_$i"} = "0--0.00";
 
1639         $form->{"tax_$i"}      = 0;
 
1641       if (!$form->{"korrektur_$i"}) {
 
1642         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
1649           if ($form->{taxincluded}) {
 
1650             $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
 
1652               $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1654               $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1657             $form->{"tax_$i"} = $amount * $rate;
 
1660           $form->{"tax_$i"} = 0;
 
1662       } elsif ($form->{taxincluded}) {
 
1664           $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
 
1666           $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
 
1670       for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
 
1675   for $i (1 .. $count) {
 
1677     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
 
1680   for $i ($count + 1 .. $form->{rowcount}) {
 
1681     for (@flds) { delete $form->{"${_}_$i"} }
 
1684   for $i (1 .. $form->{rowcount}) {
 
1685     $dr  = $form->{"debit_$i"};
 
1686     $cr  = $form->{"credit_$i"};
 
1687     $tax = $form->{"tax_$i"};
 
1691           'Cannot post transaction with a debit and credit entry for the same account!'
 
1694     if ($form->{taxincluded}) {
 
1696         $debit += $dr + $tax;
 
1699         $credit += $cr + $tax;
 
1704         $debit += $dr + $tax;
 
1707         $credit += $cr + $tax;
 
1712     $form->{taxincluded} = 0;
 
1715   # this is just for the wise guys
 
1716   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
1717     if ($transdate <= $closedto);
 
1718   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
 
1719     $form->error($locale->text('Out of balance transaction!'));
 
1722   if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
 
1723     $form->error($locale->text('Empty transaction!'));
 
1726   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
 
1728     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
 
1729     $err[2] = $locale->text('Debit and credit out of balance!');
 
1730     $err[3] = $locale->text('Cannot post a transaction without a value!');
 
1732     $form->error($err[$errno]);
 
1734   undef($form->{callback});
 
1735   # saving the history
 
1736   if(!exists $form->{addition} && $form->{id} ne "") {
 
1737     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
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();
 
1760   if (IS->has_storno(\%myconfig, $form, 'gl')) {
 
1761     $form->{title} = $locale->text("Cancel General Ledger Transaction");
 
1762     $form->error($locale->text("Transaction has already been cancelled!"));
 
1765   my %keep_keys = map { $_, 1 } qw(login password id stylesheet);
 
1766   map { delete $form->{$_} unless $keep_keys{$_} } keys %{ $form };
 
1768   prepare_transaction();
 
1770   for my $i (1 .. $form->{rowcount}) {
 
1771     for (qw(debit credit tax)) {
 
1772       $form->{"${_}_$i"} =
 
1773         ($form->{"${_}_$i"})
 
1774         ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
 
1779   $form->{storno}      = 1;
 
1780   $form->{storno_id}   = $form->{id};
 
1783   $form->{reference}   = "Storno-" . $form->{reference};
 
1784   $form->{description} = "Storno-" . $form->{description};
 
1786   for my $i (1 .. $form->{rowcount}) {
 
1787     next if (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq ""));
 
1789     if ($form->{"debit_$i"} ne "") {
 
1790       $form->{"credit_$i"} = $form->{"debit_$i"};
 
1791       $form->{"debit_$i"}  = "";
 
1794       $form->{"debit_$i"}  = $form->{"credit_$i"};
 
1795       $form->{"credit_$i"} = "";
 
1801   # saving the history
 
1802   if(!exists $form->{addition} && $form->{id} ne "") {
 
1803     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1804         $form->{addition} = "STORNO";
 
1805         $form->save_history($form->dbconnect(\%myconfig));
 
1807   # /saving the history 
 
1809   $lxdebug->leave_sub();