1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #======================================================================
 
  32 #======================================================================
 
  34 use POSIX qw(strftime);
 
  40 use SL::ReportGenerator;
 
  42 require "bin/mozilla/arap.pl";
 
  43 require "bin/mozilla/common.pl";
 
  44 require "bin/mozilla/drafts.pl";
 
  45 require "bin/mozilla/reportgenerator.pl";
 
  51 # this is for our long dates
 
  52 # $locale->text('January')
 
  53 # $locale->text('February')
 
  54 # $locale->text('March')
 
  55 # $locale->text('April')
 
  56 # $locale->text('May ')
 
  57 # $locale->text('June')
 
  58 # $locale->text('July')
 
  59 # $locale->text('August')
 
  60 # $locale->text('September')
 
  61 # $locale->text('October')
 
  62 # $locale->text('November')
 
  63 # $locale->text('December')
 
  65 # this is for our short month
 
  66 # $locale->text('Jan')
 
  67 # $locale->text('Feb')
 
  68 # $locale->text('Mar')
 
  69 # $locale->text('Apr')
 
  70 # $locale->text('May')
 
  71 # $locale->text('Jun')
 
  72 # $locale->text('Jul')
 
  73 # $locale->text('Aug')
 
  74 # $locale->text('Sep')
 
  75 # $locale->text('Oct')
 
  76 # $locale->text('Nov')
 
  77 # $locale->text('Dec')
 
  80   $lxdebug->enter_sub();
 
  82   return $lxdebug->leave_sub() if (load_draft_maybe());
 
  84   $form->{title} = "Add";
 
  87     "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
 
  88     unless $form->{callback};
 
  90   AP->get_transdate(\%myconfig, $form);
 
  91   $form->{initial_transdate} = $form->{transdate};
 
  93   $form->{transdate} = $form->{initial_transdate};
 
  96   $lxdebug->leave_sub();
 
 100   $lxdebug->enter_sub();
 
 102   $form->{title} = "Edit";
 
 107   $lxdebug->leave_sub();
 
 111   $lxdebug->enter_sub();
 
 116   $lxdebug->leave_sub();
 
 120   $lxdebug->enter_sub();
 
 122   $form->create_links("AP", \%myconfig, "vendor");
 
 123   $taxincluded = $form->{taxincluded};
 
 124   $duedate     = $form->{duedate};
 
 126   IR->get_vendor(\%myconfig, \%$form);
 
 127   $form->{taxincluded} = $taxincluded;
 
 128   $form->{duedate}   = $duedate if $duedate;
 
 129   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
 
 130   $form->{rowcount}  = 1;
 
 132   # build the popup menus
 
 133   $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
 
 136   $form->{notes} = $form->{intnotes} unless $form->{notes};
 
 139   @curr = split(/:/, $form->{currencies});
 
 141   $form->{defaultcurrency} = $curr[0];
 
 143   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 146   if (@{ $form->{all_vendor} }) {
 
 147     $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
 
 148     map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
 
 149       (@{ $form->{all_vendor} });
 
 153   if (@{ $form->{all_departments} }) {
 
 154     $form->{selectdepartment} = "<option>\n";
 
 155     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 158       $form->{selectdepartment} .=
 
 159         "<option>$_->{description}--$_->{id}\n"
 
 160     } (@{ $form->{all_departments} });
 
 163   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 165   AP->setup_form($form);
 
 168     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 169      $form->datetonum($form->{closedto}, \%myconfig));
 
 171   $lxdebug->leave_sub();
 
 175   $lxdebug->enter_sub();
 
 177   $title = $form->{title};
 
 178   $form->{title} = $locale->text("$title Accounts Payables Transaction");
 
 180   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 182   # type=submit $locale->text('Add Accounts Payables Transaction')
 
 183   # type=submit $locale->text('Edit Accounts Payables Transaction')
 
 185   $form->{javascript} = qq|<script type="text/javascript">
 
 187   function setTaxkey(accno, row) {
 
 188     var taxkey = accno.options[accno.selectedIndex].value;
 
 189     var reg = /--([0-9]*)/;
 
 190     var found = reg.exec(taxkey);
 
 191     var index = found[1];
 
 192     index = parseInt(index);
 
 193     var tax = 'taxchart_' + row;
 
 194     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
 195       var reg2 = new RegExp("^"+ index, "");
 
 196       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
 197         document.getElementById(tax).options[i].selected = true;
 
 204   # show history button
 
 205   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 206   #/show hhistory button
 
 208   # set option selected
 
 209   foreach $item (qw(vendor currency department)) {
 
 210     $form->{"select$item"} =~ s/ selected//;
 
 211     $form->{"select$item"} =~
 
 212       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 214   $readonly = ($form->{id}) ? "readonly" : "";
 
 217     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 218   $readonly                 = ($form->{radier}) ? "" : $readonly;
 
 220   $form->{exchangerate} = $exchangerate
 
 224                        $form->check_exchangerate(
 
 225                        \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
 
 230   $form->{exchangerate} =
 
 231     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 232   if ($form->{exchangerate} == 0) {
 
 233     $form->{exchangerate} = "";
 
 235   $form->{creditlimit} =
 
 236     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 237   $form->{creditremaining} =
 
 238     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 241 <input type=hidden name=forex value=$form->{forex}>
 
 243   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 244     if ($form->{forex}) {
 
 247               <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 248               <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
 
 253              <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 254              <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
 
 263               <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
 
 264               <th align=left nowrap>|
 
 265     . $locale->text('Tax Included') . qq|</th>
 
 269   if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
 
 273     qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
 
 277                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 278                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 279                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 282 | if $form->{selectdepartment};
 
 284   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 287     ($form->{selectvendor})
 
 288     ? qq|<select name="vendor"
 
 289 onchange="document.getElementById('update_button').click();">$form->{
 
 290 selectvendor } </select>|
 
 291     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
 293   my @old_project_ids = ();
 
 294   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
 295           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
 297   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 299                                    "old_id" => \@old_project_ids },
 
 300                    "charts" => { "key" => "ALL_CHARTS",
 
 301                                  "transdate" => $form->{transdate} },
 
 302                    "taxcharts" => "ALL_TAXCHARTS");
 
 304   map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
 
 305       @{ $form->{ALL_CHARTS} });
 
 307   my %project_labels = ();
 
 308   my @project_values = ("");
 
 309   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 310     push(@project_values, $item->{"id"});
 
 311     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 314   my (%AP_amount_labels, @AP_amount_values);
 
 315   my (%AP_labels, @AP_values);
 
 316   my (%AP_paid_labels, @AP_paid_values);
 
 320   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
 321     if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
 
 322       $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
 
 323       my $key = "$item->{accno}--$item->{tax_id}";
 
 324       push(@AP_amount_values, $key);
 
 325       $AP_amount_labels{$key} =
 
 326         "$item->{accno}--$item->{description}";
 
 328     } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
 
 329       push(@AP_values, $item->{accno});
 
 330       $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
 
 332     } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
 
 333       push(@AP_paid_values, $item->{accno});
 
 334       $AP_paid_labels{$item->{accno}} =
 
 335         "$item->{accno}--$item->{description}";
 
 338     $charts{$item->{accno}} = $item;
 
 341   my %taxchart_labels = ();
 
 342   my @taxchart_values = ();
 
 344   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
 345     my $key = "$item->{id}--$item->{rate}";
 
 346     $taxchart_init = $key if ($taxchart_init eq $item->{id});
 
 347     push(@taxchart_values, $key);
 
 348     $taxchart_labels{$key} =
 
 349       "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
 
 350     $taxcharts{$item->{id}} = $item;
 
 353   # use JavaScript Calendar or not
 
 354   $form->{jsscript} = 1;
 
 356   if ($form->{jsscript}) {
 
 358     # with JavaScript Calendar
 
 360        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
 
 361        <td><input type=button name=transdate id="trigger1" value=|
 
 362       . $locale->text('button') . qq|></td>
 
 365        <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
 
 366        <td><input type=button name=duedate id="trigger2" value=|
 
 367       . $locale->text('button') . qq|></td></td>
 
 372       Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
 
 373                           "duedate", "BL", "trigger2");
 
 376     # without JavaScript Calendar
 
 378       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
 
 380       qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
 
 382   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 383   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
 
 386   $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 387   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 389 <body onLoad="$onload">
 
 391 <form method=post action=$form->{script}>
 
 393 <input type=hidden name=id value=$form->{id}>
 
 394 <input type=hidden name=sort value=$form->{sort}>
 
 395 <input type=hidden name=closedto value=$form->{closedto}>
 
 396 <input type=hidden name=locked value=$form->{locked}>
 
 397 <input type=hidden name=title value="$title">
 
 399 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
 
 403     <th class=listtop>$form->{title}</th>
 
 413                 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
 
 414                 <td colspan=3>$vendor <input type="button" value="?" onclick="show_vc_details('vendor')"></td>
 
 415                 <input type=hidden name=selectvendor value="$form->{selectvendor}">
 
 416                 <input type=hidden name=oldvendor value="$form->{oldvendor}">
 
 417                 <input type=hidden name=vendor_id value="$form->{vendor_id}">
 
 418                 <input type=hidden name=terms value=$form->{terms}>
 
 425                       <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 426                       <td>$form->{creditlimit}</td>
 
 427                       <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
 
 428                       <td class="plus$n">$form->{creditremaining}</td>
 
 429                       <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 430                       <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 435                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 436                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 437                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 438                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 439                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 440                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 450                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 451                 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
 
 454                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 455                 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
 
 458                 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
 
 462                 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
 
 475   <input type=hidden name=rowcount value=$form->{rowcount}>
 
 479            <tr class=listheading>
 
 480           <th class=listheading style="width:15%">|
 
 481     . $locale->text('Account') . qq|</th>
 
 482           <th class=listheading style="width:10%">|
 
 483     . $locale->text('Amount') . qq|</th>
 
 484           <th class=listheading style="width:10%">|
 
 485     . $locale->text('Tax') . qq|</th>
 
 486           <th class=listheading style="width:5%">|
 
 487     . $locale->text('Korrektur') . qq|</th>
 
 488           <th class=listheading style="width:10%">|
 
 489     . $locale->text('Taxkey') . qq|</th>
 
 490           <th class=listheading style="width:10%">|
 
 491     . $locale->text('Project') . qq|</th>
 
 495   $amount  = $locale->text('Amount');
 
 496   $project = $locale->text('Project');
 
 498   for $i (1 .. $form->{rowcount}) {
 
 501     $form->{"amount_$i"} =
 
 502       $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
 
 503     $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
 
 505     my $selected_accno_full;
 
 506     my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
 
 507     my $item = $charts{$accno_row};
 
 508     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
 
 510     my $selected_taxchart = $form->{"taxchart_$i"};
 
 511     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
 
 512     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
 
 514     if ($previous_accno &&
 
 515         ($previous_accno eq $selected_accno) &&
 
 516         ($previous_tax_id ne $selected_tax_id)) {
 
 517       my $item = $taxcharts{$selected_tax_id};
 
 518       $selected_taxchart = "$item->{id}--$item->{rate}";
 
 521     $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
 
 524       NTI($cgi->popup_menu('-name' => "AP_amount_$i",
 
 525                            '-id' => "AP_amount_$i",
 
 526                            '-style' => 'width:400px',
 
 527                            '-onChange' => "setTaxkey(this, $i)",
 
 528                            '-values' => \@AP_amount_values,
 
 529                            '-labels' => \%AP_amount_labels,
 
 530                            '-default' => $selected_accno_full))
 
 531       . $cgi->hidden('-name' => "previous_AP_amount_$i",
 
 532                      '-default' => $selected_accno_full);
 
 535       NTI($cgi->popup_menu('-name' => "taxchart_$i",
 
 536                            '-id' => "taxchart_$i",
 
 537                            '-style' => 'width:200px',
 
 538                            '-values' => \@taxchart_values,
 
 539                            '-labels' => \%taxchart_labels,
 
 540                            '-default' => $selected_taxchart))
 
 543     my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
 
 546       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
 547                            '-values' => \@project_values,
 
 548                            '-labels' => \%project_labels,
 
 549                            '-default' => $form->{"project_id_$i"} ));
 
 553           <td>$selectAP_amount</td>
 
 554           <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
 
 555           <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
 
 556           <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
 
 558           <td>$projectnumber</td>
 
 566     ($form->{taxincluded})
 
 567     ? $locale->text('Tax Included')
 
 568     : $locale->text('Tax');
 
 570   $form->{invtotal_unformatted} = $form->{invtotal};
 
 571   $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
 
 574     NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
 
 575                          '-style' => 'width:400px',
 
 576                          '-values' => \@AP_values, '-labels' => \%AP_labels,
 
 577                          '-default' => $form->{APselected}));
 
 585           <td>${APselected}</td>
 
 586           <th align=left>$form->{invtotal}</th>
 
 588           <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 589           <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
 
 591           <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 604           <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
 
 605           <td align=left>$notes</td>
 
 613         <tr class=listheading>
 
 614           <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
 
 618   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 619     @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
 
 621     @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
 
 624   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 625   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 626   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 627   $column_data{AP_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 628   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 629   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 630   $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>"; 
 
 635   map { print "$column_data{$_}\n" } @column_index;
 
 643   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 644   for $i (1 .. $form->{paidaccounts}) {
 
 650       NTI($cgi->popup_menu('-name' => "AP_paid_$i",
 
 651                            '-id' => "AP_paid_$i",
 
 652                            '-values' => \@AP_paid_values,
 
 653                            '-labels' => \%AP_paid_labels,
 
 654                            '-default' => $form->{"AP_paid_$i"}));
 
 656     $totalpaid += $form->{"paid_$i"};
 
 659     if ($form->{"paid_$i"}) {
 
 661       $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 663     $form->{"exchangerate_$i"} =
 
 664       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 665     if ($form->{"exchangerate_$i"} == 0) {
 
 666       $form->{"exchangerate_$i"} = "";
 
 669     $exchangerate = qq| |;
 
 670     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 671       if ($form->{"forex_$i"}) {
 
 673           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 676           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 681 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 684     $column_data{"paid_$i"} =
 
 685       qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
 
 686     $column_data{"AP_paid_$i"} =
 
 687       qq|<td align=center>${selectAP_paid}</td>|;
 
 688     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
 689     $column_data{"datepaid_$i"}     =
 
 690       qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
 
 691          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
 692     $column_data{"source_$i"} =
 
 693       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
 694     $column_data{"memo_$i"} =
 
 695       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
 696     $column_data{"paid_project_id_$i"} =
 
 698       . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
 
 699                              '-values' => \@project_values,
 
 700                              '-labels' => \%project_labels,
 
 701                              '-default' => $form->{"paid_project_id_$i"} ))
 
 704     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
 709     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
 712   my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
 
 718           <td align="center">| . $locale->text('Total') . qq|</td>
 
 719           <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
 
 724           <td align="center">| . $locale->text('Missing amount') . qq|</td>
 
 725           <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
 
 727 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
 729     <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 735     <td><hr size=3 noshade></td>
 
 740   $lxdebug->leave_sub();
 
 744   $lxdebug->enter_sub();
 
 748 <input name=callback type=hidden value="$form->{callback}">
 
 749 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
 
 751 <input type=hidden name=login value=$form->{login}>
 
 752 <input type=hidden name=password value=$form->{password}>
 
 754 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 
 755 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
 
 761   if (!$form->{id} && $form->{draft_id}) {
 
 762     print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
 
 763                              '-value' => 1, '-checked' => $form->{remove_draft},
 
 765           qq| <label for="remove_draft">| .
 
 766           $locale->text("Remove draft when posting") .
 
 770   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
 771   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
 773   print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
 
 776     if ($form->{radier}) {
 
 777       print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
 
 778                 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
 
 782     # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
 
 783     print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
 
 784       if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}));
 
 786     print qq| <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
 
 787               <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
 
 789   } elsif (($transdate > $closedto) && !$form->{id}) {
 
 791       <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
 
 792       NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
 
 794   # button for saving history
 
 795   if($form->{id} ne "") {
 
 796     print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|"> |;
 
 798   # /button for saving history
 
 799   # mark_as_paid button 
 
 800   if($form->{id} ne "") {  
 
 801     print qq| <input type="submit" class="submit" name="action" value="| . $locale->text('mark as paid') . qq|"> |;
 
 803   # /mark_as_paid button
 
 811   $lxdebug->leave_sub();
 
 815   $lxdebug->enter_sub();
 
 816   &mark_as_paid_common(\%myconfig,"ap");  
 
 817   $lxdebug->leave_sub();
 
 821   $lxdebug->enter_sub();
 
 825   $form->{invtotal} = 0;
 
 827   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 828     qw(exchangerate creditlimit creditremaining);
 
 830   @flds  = qw(amount AP_amount projectnumber oldprojectnumber project_id);
 
 832   for $i (1 .. $form->{rowcount}) {
 
 833     $form->{"amount_$i"} =
 
 834       $form->parse_amount(\%myconfig, $form->{"amount_$i"});
 
 835     $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
 
 836     if ($form->{"amount_$i"}) {
 
 839       if (!$form->{"korrektur_$i"}) {
 
 840         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
 842           if ($form->{taxincluded}) {
 
 843             $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
 
 845             $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
 
 848           $form->{"tax_$i"} = 0;
 
 851       $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
 
 853       $totaltax += $form->{"tax_$i"};
 
 854       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 858   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
 860   map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
 
 862   $form->{exchangerate} = $exchangerate
 
 866                       $form->check_exchangerate(
 
 867                       \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
 
 870   $form->{invdate} = $form->{transdate};
 
 871   $save_AP = $form->{AP};
 
 873   $form->{AP} = $save_AP;
 
 875   $form->{rowcount} = $count + 1;
 
 878     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
 
 880   for $i (1 .. $form->{paidaccounts}) {
 
 881     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 884           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 885       } qw(paid exchangerate);
 
 887       $totalpaid += $form->{"paid_$i"};
 
 889       $form->{"exchangerate_$i"} = $exchangerate
 
 891             $form->{"forex_$i"} = (
 
 893                   $form->check_exchangerate(
 
 894                   \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
 
 899   $form->{creditremaining} -=
 
 900     ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
 
 901      $form->{oldinvtotal});
 
 902   $form->{oldinvtotal}  = $form->{invtotal};
 
 903   $form->{oldtotalpaid} = $totalpaid;
 
 907   $lxdebug->leave_sub();
 
 912   $lxdebug->enter_sub();
 
 914   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
 916   for $i (1 .. $form->{paidaccounts}) {
 
 917     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 918       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 920       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 922       $form->error($locale->text('Cannot post payment for a closed period!'))
 
 923         if ($datepaid <= $closedto);
 
 925       if ($form->{currency} ne $form->{defaultcurrency}) {
 
 926         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
 927           if ($invdate == $datepaid);
 
 928         $form->isblank("exchangerate_$i",
 
 929                        $locale->text('Exchangerate for payment missing!'));
 
 934   ($form->{AP})      = split /--/, $form->{AP};
 
 935   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
 
 936   $form->redirect($locale->text('Payment posted!'))
 
 937       if (AP->post_payment(\%myconfig, \%$form));
 
 938     $form->error($locale->text('Cannot post payment!'));
 
 941   $lxdebug->leave_sub();
 
 946   $lxdebug->enter_sub();
 
 948   # check if there is a vendor, invoice and due date
 
 949   $form->isblank("transdate", $locale->text("Invoice Date missing!"));
 
 950   $form->isblank("duedate",   $locale->text("Due Date missing!"));
 
 951   $form->isblank("vendor",    $locale->text('Vendor missing!'));
 
 953   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
 954   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
 955   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
 
 957   my $zero_amount_posting = 1;
 
 958   for $i (1 .. $form->{rowcount}) {
 
 959     if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
 
 960       $zero_amount_posting = 0;
 
 965   $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
 
 967   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
 968     if ($form->{currency} ne $form->{defaultcurrency});
 
 971   for $i (1 .. $form->{paidaccounts}) {
 
 972     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 973       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 975       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 977       $form->error($locale->text('Cannot post payment for a closed period!'))
 
 978         if ($datepaid <= $closedto);
 
 980       if ($form->{currency} ne $form->{defaultcurrency}) {
 
 981         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
 982           if ($transdate == $datepaid);
 
 983         $form->isblank("exchangerate_$i",
 
 984                        $locale->text('Exchangerate for payment missing!'));
 
 990   # if old vendor ne vendor redo form
 
 991   ($vendor) = split /--/, $form->{vendor};
 
 992   if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
 
 996   ($debitaccno,    $debittaxkey)    = split /--/, $form->{AP_amountselected};
 
 997   ($taxkey,        $NULL)           = split /--/, $form->{taxchartselected};
 
 998   ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
 
 999   $form->{AP}{amount_1} = $debitaccno;
 
1000   $form->{AP}{payables} = $payablesaccno;
 
1001   $form->{taxkey}       = $taxkey;
 
1002   $form->{storno}       = 0;
 
1004   $form->{id} = 0 if $form->{postasnew};
 
1006   if (AP->post_transaction(\%myconfig, \%$form)) {
 
1007     # saving the history
 
1008     if(!exists $form->{addition} && $form->{id} ne "") {
 
1009       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1010       $form->{addition} = "POSTED";
 
1011       $form->save_history($form->dbconnect(\%myconfig));
 
1013     # /saving the history 
 
1014     remove_draft() if $form->{remove_draft};
 
1015     $form->redirect($locale->text('Transaction posted!'));
 
1017   $form->error($locale->text('Cannot post transaction!'));
 
1019   $lxdebug->leave_sub();
 
1023   $lxdebug->enter_sub();
 
1025   $form->{postasnew} = 1;
 
1026   # saving the history
 
1027   if(!exists $form->{addition} && $form->{id} ne "") {
 
1028     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1029         $form->{addition} = "POSTED AS NEW";
 
1030         $form->save_history($form->dbconnect(\%myconfig));
 
1032   # /saving the history 
 
1035   $lxdebug->leave_sub();
 
1038 sub use_as_template {
 
1039   $lxdebug->enter_sub();
 
1041   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
 
1042   $form->{paidaccounts} = 1;
 
1043   $form->{rowcount}--;
 
1044   $form->{invdate} = $form->current_date(\%myconfig);
 
1047   $lxdebug->leave_sub();
 
1051   $lxdebug->enter_sub();
 
1053   $form->{title} = $locale->text('Confirm!');
 
1057   delete $form->{header};
 
1062 <form method=post action=$form->{script}>
 
1065   foreach $key (keys %$form) {
 
1066     $form->{$key} =~ s/\"/"/g;
 
1067     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1071 <h2 class=confirm>$form->{title}</h2>
 
1074     . $locale->text('Are you sure you want to delete Transaction')
 
1075     . qq| $form->{invnumber}</h4>
 
1077 <input name=action class=submit type=submit value="|
 
1078     . $locale->text('Yes') . qq|">
 
1085   $lxdebug->leave_sub();
 
1089   $lxdebug->enter_sub();
 
1090   if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
 
1091     # saving the history
 
1092     if(!exists $form->{addition}) {
 
1093       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1094           $form->{addition} = "DELETED";
 
1095       $form->save_history($form->dbconnect(\%myconfig));
 
1097     # /saving the history 
 
1098     $form->redirect($locale->text('Transaction deleted!'));
 
1100   $form->error($locale->text('Cannot delete transaction!'));
 
1102   $lxdebug->leave_sub();
 
1106   $lxdebug->enter_sub();
 
1108   # setup vendor selection
 
1109   $form->all_vc(\%myconfig, "vendor", "AP");
 
1111   if (@{ $form->{all_vendor} }) {
 
1112     map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
 
1113       @{ $form->{all_vendor} };
 
1114     $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
 
1116     $vendor = qq|<input name=vendor size=35>|;
 
1120   if (@{ $form->{all_departments} }) {
 
1121     $form->{selectdepartment} = "<option>\n";
 
1124       $form->{selectdepartment} .=
 
1125         "<option>$_->{description}--$_->{id}\n"
 
1126     } (@{ $form->{all_departments} });
 
1131           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1132           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1134 | if $form->{selectdepartment};
 
1136   $form->{title} = $locale->text('AP Transactions');
 
1138   # use JavaScript Calendar or not
 
1139   $form->{jsscript} = 1;
 
1141   if ($form->{jsscript}) {
 
1143     # with JavaScript Calendar
 
1145        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
1146        <input type=button name=transdatefrom id="trigger1" value=|
 
1147       . $locale->text('button') . qq|></td>
 
1150        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
1151        <input type=button name=transdateto name=transdateto id="trigger2" value=|
 
1152       . $locale->text('button') . qq|></td>
 
1157       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
 
1158                           "transdateto", "BL", "trigger2");
 
1161     # without JavaScript Calendar
 
1163                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
1165                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
1168   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1173   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1174     push(@values, $item->{"id"});
 
1175     $labels{$item->{"id"}} = $item->{"projectnumber"};
 
1178     NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
 
1179                          '-labels' => \%labels));
 
1180   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
1182   $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
1183   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
1185 <body onLoad="$onload">
 
1187 <form method=post action=$form->{script}>
 
1191     <th class=listtop>$form->{title}</th>
 
1193   <tr height="5"></tr>
 
1198           <th align=right>| . $locale->text('Vendor') . qq|</th>
 
1199           <td colspan=3>$vendor</td>
 
1203           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
1204           <td colspan=3><input name=invnumber size=20></td>
 
1207           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
1208           <td colspan=3><input name=ordnumber size=20></td>
 
1211           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
 
1212           <td colspan=3><input name=notes size=40></td>
 
1215           <th align="right">| . $locale->text("Project Number") . qq|</th>
 
1216           <td colspan="3">$projectnumber</td>
 
1219           <th align=right nowrap>| . $locale->text('From') . qq|</th>
 
1221           <th align=right>| . $locale->text('Bis') . qq|</th>
 
1224         <input type=hidden name=sort value=transdate>
 
1232           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
1236                 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
 
1237                 <td nowrap>| . $locale->text('Open') . qq|</td>
 
1238                 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
 
1239                 <td nowrap>| . $locale->text('Closed') . qq|</td>
 
1242                 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
1243                 <td nowrap>| . $locale->text('ID') . qq|</td>
 
1244                 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
1245                 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
 
1246                 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
 
1247                 <td nowrap>| . $locale->text('Order Number') . qq|</td>
 
1250                 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
1251                 <td nowrap>| . $locale->text('Vendor') . qq|</td>
 
1252                 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
1253                 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
 
1254                 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
 
1255                 <td nowrap>| . $locale->text('Amount') . qq|</td>
 
1258                 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
 
1259                 <td nowrap>| . $locale->text('Tax') . qq|</td>
 
1260                 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
 
1261                 <td nowrap>| . $locale->text('Total') . qq|</td>
 
1262                 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
 
1263                 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
 
1266                 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
 
1267                 <td nowrap>| . $locale->text('Paid') . qq|</td>
 
1268                 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
 
1269                 <td nowrap>| . $locale->text('Due Date') . qq|</td>
 
1270                 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
 
1271                 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
 
1274                 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
1275                 <td nowrap>| . $locale->text('Notes') . qq|</td>
 
1276                 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
 
1277                 <td nowrap>| . $locale->text('Employee') . qq|</td>
 
1280                 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
1281                 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
 
1282                 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
 
1283                 <td nowrap>| . $locale->text('Project Number') . qq|</td>
 
1292     <td><hr size=3 noshade></td>
 
1299 <input type=hidden name=nextsub value=$form->{nextsub}>
 
1300 <input type=hidden name=login value=$form->{login}>
 
1301 <input type=hidden name=password value=$form->{password}>
 
1303 <input class=submit type=submit name=action value="|
 
1304     . $locale->text('Continue') . qq|">
 
1311   $lxdebug->leave_sub();
 
1314 sub create_subtotal_row {
 
1315   $lxdebug->enter_sub();
 
1317   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
1319   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
1321   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
 
1323   $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
 
1325   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
1327   $lxdebug->leave_sub();
 
1332 sub ap_transactions {
 
1333   $lxdebug->enter_sub();
 
1335   ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
 
1337   $form->{sort} ||= 'transdate';
 
1339   AP->ap_transactions(\%myconfig, \%$form);
 
1341   $form->{title} = $locale->text('AP Transactions');
 
1343   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1346     qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
 
1347        due duedate transaction_description notes employee globalprojectnumber);
 
1349   my @hidden_variables = map { "l_${_}" } @columns;
 
1350   push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
 
1352   my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
 
1355     'transdate'               => { 'text' => $locale->text('Date'), },
 
1356     'id'                      => { 'text' => $locale->text('ID'), },
 
1357     'type'                    => { 'text' => $locale->text('Type'), },
 
1358     'invnumber'               => { 'text' => $locale->text('Invoice'), },
 
1359     'ordnumber'               => { 'text' => $locale->text('Order'), },
 
1360     'name'                    => { 'text' => $locale->text('Vendor'), },
 
1361     'netamount'               => { 'text' => $locale->text('Amount'), },
 
1362     'tax'                     => { 'text' => $locale->text('Tax'), },
 
1363     'amount'                  => { 'text' => $locale->text('Total'), },
 
1364     'paid'                    => { 'text' => $locale->text('Paid'), },
 
1365     'datepaid'                => { 'text' => $locale->text('Date Paid'), },
 
1366     'due'                     => { 'text' => $locale->text('Amount Due'), },
 
1367     'duedate'                 => { 'text' => $locale->text('Due Date'), },
 
1368     'transaction_description' => { 'text' => $locale->text('Transaction description'), },
 
1369     'notes'                   => { 'text' => $locale->text('Notes'), },
 
1370     'employee'                => { 'text' => $locale->text('Salesperson'), },
 
1371     'globalprojectnumber'     => { 'text' => $locale->text('Project Number'), },
 
1374   foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
 
1375                        employee shippingpoint shipvia)) {
 
1376     $column_defs{$name}->{link} = $href . "&sort=$name";
 
1379   my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
 
1381   $form->{"l_type"} = "Y";
 
1382   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
 
1384   $report->set_columns(%column_defs);
 
1385   $report->set_column_order(@columns);
 
1387   $report->set_export_options('ap_transactions', @hidden_variables);
 
1389   $report->set_sort_indicator($form->{sort}, 1);
 
1392   if ($form->{vendor}) {
 
1393     push @options, $locale->text('Vendor') . " : $form->{vendor}";
 
1395   if ($form->{department}) {
 
1396     ($department) = split /--/, $form->{department};
 
1397     push @options, $locale->text('Department') . " : $department";
 
1399   if ($form->{invnumber}) {
 
1400     push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
 
1402   if ($form->{ordnumber}) {
 
1403     push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
 
1405   if ($form->{notes}) {
 
1406     push @options, $locale->text('Notes') . " : $form->{notes}";
 
1408   if ($form->{transaction_description}) {
 
1409     push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
 
1411   if ($form->{transdatefrom}) {
 
1412     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
 
1414   if ($form->{transdateto}) {
 
1415     push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
 
1417   if ($form->{open}) {
 
1418     push @options, $locale->text('Open');
 
1420   if ($form->{closed}) {
 
1421     push @options, $locale->text('Closed');
 
1424   $report->set_options('top_info_text'        => join("\n", @options),
 
1425                        'raw_bottom_info_text' => $form->parse_html_template('ap/ap_transactions_bottom'),
 
1426                        'output_format'        => 'HTML',
 
1427                        'title'                => $form->{title},
 
1428                        'attachment_basename'  => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
 
1430   $report->set_options_from_form();
 
1432   # add sort and escape callback, this one we use for the add sub
 
1433   $form->{callback} = $href .= "&sort=$form->{sort}";
 
1435   # escape callback for href
 
1436   $callback = $form->escape($href);
 
1438   my @subtotal_columns = qw(netamount amount paid due);
 
1440   my %totals    = map { $_ => 0 } @subtotal_columns;
 
1441   my %subtotals = map { $_ => 0 } @subtotal_columns;
 
1445   foreach $ap (@{ $form->{AP} }) {
 
1446     $ap->{tax} = $ap->{amount} - $ap->{netamount};
 
1447     $ap->{due} = $ap->{amount} - $ap->{paid};
 
1449     map { $subtotals{$_} += $ap->{$_};
 
1450           $totals{$_}    += $ap->{$_} } @subtotal_columns;
 
1452     map { $ap->{$_} = $form->format_amount(\%myconfig, $ap->{$_}, 2) } qw(netamount tax amount paid due);
 
1455       $ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
 
1456                        $locale->text("AP Transaction (abbreviation)");
 
1460     foreach my $column (@columns) {
 
1462         'data'  => $ap->{$column},
 
1463         'align' => $column_alignment{$column},
 
1467     $row->{invnumber}->{link} = build_std_url("script=" . ($ap->{invoice} ? 'ir.pl' : 'ap.pl'), 'action=edit')
 
1468       . "&id=" . E($ap->{id}) . "&callback=${callback}";
 
1470     my $row_set = [ $row ];
 
1472     if (($form->{l_subtotal} eq 'Y')
 
1473         && (($idx == (scalar @{ $form->{AP} } - 1))
 
1474             || ($ap->{ $form->{sort} } ne $form->{AP}->[$idx + 1]->{ $form->{sort} }))) {
 
1475       push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
 
1478     $report->add_data($row_set);
 
1483   $report->add_separator();
 
1484   $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
 
1486   $report->generate_with_headers();
 
1488   $lxdebug->leave_sub();
 
1492   $lxdebug->enter_sub();
 
1494   if (IS->has_storno(\%myconfig, $form, 'ap')) {
 
1495     $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
 
1496     $form->error($locale->text("Transaction has already been cancelled!"));
 
1499   AP->storno($form, \%myconfig, $form->{id});
 
1501   # saving the history
 
1502   if(!exists $form->{addition} && $form->{id} ne "") {
 
1503     $form->{snumbers} = "ordnumber_$form->{ordnumber}";
 
1504     $form->{addition} = "STORNO";
 
1505     $form->save_history($form->dbconnect(\%myconfig));
 
1507   # /saving the history 
 
1509   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); 
 
1511   $lxdebug->leave_sub();