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 #======================================================================
 
  38 require "$form->{path}/arap.pl";
 
  44 # this is for our long dates
 
  45 # $locale->text('January')
 
  46 # $locale->text('February')
 
  47 # $locale->text('March')
 
  48 # $locale->text('April')
 
  49 # $locale->text('May ')
 
  50 # $locale->text('June')
 
  51 # $locale->text('July')
 
  52 # $locale->text('August')
 
  53 # $locale->text('September')
 
  54 # $locale->text('October')
 
  55 # $locale->text('November')
 
  56 # $locale->text('December')
 
  58 # this is for our short month
 
  59 # $locale->text('Jan')
 
  60 # $locale->text('Feb')
 
  61 # $locale->text('Mar')
 
  62 # $locale->text('Apr')
 
  63 # $locale->text('May')
 
  64 # $locale->text('Jun')
 
  65 # $locale->text('Jul')
 
  66 # $locale->text('Aug')
 
  67 # $locale->text('Sep')
 
  68 # $locale->text('Oct')
 
  69 # $locale->text('Nov')
 
  70 # $locale->text('Dec')
 
  73   $lxdebug->enter_sub();
 
  75   $form->{title} = "Add";
 
  78     "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
 
  79     unless $form->{callback};
 
  82   AP->get_transdate(\%myconfig, $form);
 
  85   $lxdebug->leave_sub();
 
  89   $lxdebug->enter_sub();
 
  91   $form->{title} = "Edit";
 
  96   $lxdebug->leave_sub();
 
 100   $lxdebug->enter_sub();
 
 105   $lxdebug->leave_sub();
 
 109   $lxdebug->enter_sub();
 
 111   $form->create_links("AP", \%myconfig, "vendor");
 
 112   $taxincluded = $form->{taxincluded};
 
 113   $duedate     = $form->{duedate};
 
 115   IR->get_vendor(\%myconfig, \%$form);
 
 116   $form->{taxincluded} = $taxincluded;
 
 117   $form->{duedate}   = $duedate if $duedate;
 
 118   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
 
 119   $form->{rowcount}  = 1;
 
 121   # build the popup menus
 
 122   $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
 
 126       qq|<option value=\"$_->{id}--$_->{rate}\">$_->{taxdescription}  |
 
 127       . ($_->{rate} * 100) . qq| %|
 
 129   $form->{taxchart}       = $tax;
 
 130   $form->{selecttaxchart} = $tax;
 
 133   @curr = split(/:/, $form->{currencies});
 
 135   $form->{defaultcurrency} = $curr[0];
 
 137   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 140   if (@{ $form->{all_vendor} }) {
 
 141     $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
 
 142     map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
 
 143       (@{ $form->{all_vendor} });
 
 147   if (@{ $form->{all_departments} }) {
 
 148     $form->{selectdepartment} = "<option>\n";
 
 149     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 152       $form->{selectdepartment} .=
 
 153         "<option>$_->{description}--$_->{id}\n"
 
 154     } (@{ $form->{all_departments} });
 
 157   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 160   $form->{forex} = $form->{exchangerate};
 
 161   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 163   foreach $key (keys %{ $form->{AP_links} }) {
 
 164     foreach $ref (@{ $form->{AP_links}{$key} }) {
 
 165       if ($key eq "AP_paid") {
 
 166         $form->{"select$key"} .=
 
 167           "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
 
 169         $form->{"select$key"} .=
 
 170           "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
 
 174     $form->{$key} = $form->{"select$key"};
 
 176     # if there is a value we have an old entry
 
 180     for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 182       if ($key eq "AP_paid") {
 
 184         $form->{"AP_paid_$j"} =
 
 185           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 186         $form->{"paid_$j"}     = $form->{acc_trans}{$key}->[$i - 1]->{amount};
 
 187         $form->{"datepaid_$j"} =
 
 188           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 189         $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 190         $form->{"memo_$j"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 192         $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
 
 193           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 194         $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
 
 195         $form->{paidaccounts}++;
 
 201         if (($key eq "AP_tax") || ($key eq "AR_tax")) {
 
 202           $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
 
 203             "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 204           $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
 
 206                   $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
 
 209           if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
 
 211               $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
 
 213               $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
 
 216               $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
 
 218               $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
 
 220           $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
 
 221           $form->{"tax_$index"} =
 
 222             $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
 
 223           $totaltax += $form->{"tax_$index"};
 
 227           $form->{"${akey}_$k"} =
 
 229                   $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
 
 231           if ($akey eq 'amount') {
 
 233             $form->{"${akey}_$i"} *= -1;
 
 234             $totalamount += $form->{"${akey}_$i"};
 
 235             $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
 
 236             $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
 
 237               "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
 
 238             $form->{"project_id_$k"} =
 
 239               "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
 
 241           $form->{"${key}_$k"} =
 
 242             "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 243           my $q_description = quotemeta($form->{acc_trans}{$key}->[$i-1]->{description});
 
 244           $form->{"select${key}"} =~
 
 245             /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--${q_description}<\/option>\n/;
 
 246           $form->{"${key}_$k"} = $1;
 
 247           if ($akey eq 'amount') {
 
 248             $form->{"taxchart_$k"} = $form->{taxchart};
 
 249             $form->{"taxchart_$k"} =~
 
 250               /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{id}--[^\"]*)/;
 
 251             $form->{"taxchart_$k"} = $1;
 
 258   $form->{taxincluded}  = $taxincluded if ($form->{id});
 
 259   $form->{paidaccounts} = 1            if not defined $form->{paidaccounts};
 
 261   if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
 
 263     # add tax to amounts and invtotal
 
 264     for $i (1 .. $form->{rowcount}) {
 
 266         ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
 
 267       $tax = $form->round_amount($taxamount, 2);
 
 268       $diff                += ($taxamount - $tax);
 
 269       $form->{"amount_$i"} += $form->{"tax_$i"};
 
 271     $form->{amount_1} += $form->round_amount($diff, 2);
 
 274   $taxamount = $form->round_amount($taxamount, 2);
 
 276   $form->{invtotal} = $totalamount + $totaltax;
 
 279     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 280      $form->datetonum($form->{closedto}, \%myconfig));
 
 282   $form->{"APselected"} = $form->{"AP_1"};
 
 284   $lxdebug->leave_sub();
 
 288   $lxdebug->enter_sub();
 
 290   $title = $form->{title};
 
 291   $form->{title} = $locale->text("$title Accounts Payables Transaction");
 
 293   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 295   # type=submit $locale->text('Add Accounts Payables Transaction')
 
 296   # type=submit $locale->text('Edit Accounts Payables Transaction')
 
 298   $form->{javascript} = qq|<script type="text/javascript">
 
 300   function setTaxkey(accno, row) {
 
 301     var taxkey = accno.options[accno.selectedIndex].value;
 
 302     var reg = /--([0-9]*)/;
 
 303     var found = reg.exec(taxkey);
 
 304     var index = found[1];
 
 305     index = parseInt(index);
 
 306     var tax = 'taxchart_' + row;
 
 307     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
 308       var reg2 = new RegExp("^"+ index, "");
 
 309       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
 310         document.getElementById(tax).options[i].selected = true;
 
 318   # set option selected
 
 319   foreach $item (qw(vendor currency department)) {
 
 320     $form->{"select$item"} =~ s/ selected//;
 
 321     $form->{"select$item"} =~
 
 322       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 324   $readonly = ($form->{id}) ? "readonly" : "";
 
 326   my $APselected_quoted = quotemeta($form->{"APselected"});
 
 327   $form->{selectAP} = $form->{AP};
 
 329     s/value=\"${APselected_quoted}\"/value=\"$form->{APselected}\" selected/;
 
 332     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 333   $readonly                 = ($form->{radier}) ? "" : $readonly;
 
 334   $selectAP_amount_unquoted = $form->{selectAP_amount};
 
 335   $taxchart                 = $form->{taxchart};
 
 336   map { $form->{$_} =~ s/\"/"/g }
 
 337     qw(AP_amount selectAP_amount AP taxchart);
 
 340   $form->{exchangerate} =
 
 341     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 343   $form->{creditlimit} =
 
 344     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 345   $form->{creditremaining} =
 
 346     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 349 <input type=hidden name=forex value=$form->{forex}>
 
 351   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 352     if ($form->{forex}) {
 
 355               <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 356               <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
 
 361              <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 362              <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
 
 371               <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
 
 372               <th align=left nowrap>|
 
 373     . $locale->text('Tax Included') . qq|</th>
 
 377   if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
 
 381     qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
 
 385                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 386                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 387                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 390 | if $form->{selectdepartment};
 
 392   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 395     ($form->{selectvendor})
 
 396     ? qq|<select name=vendor>$form->{selectvendor}</select>|
 
 397     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
 399   # use JavaScript Calendar or not
 
 400   $form->{jsscript} = $jscalendar;
 
 402   if ($form->{jsscript}) {
 
 404     # with JavaScript Calendar
 
 406        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>
 
 407        <td><input type=button name=transdate id="trigger1" value=|
 
 408       . $locale->text('button') . qq|></td>
 
 411        <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>
 
 412        <td><input type=button name=duedate id="trigger2" value=|
 
 413       . $locale->text('button') . qq|></td></td>
 
 418       Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
 
 419                           "duedate", "BL", "trigger2");
 
 422     # without JavaScript Calendar
 
 424       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>|;
 
 426       qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>|;
 
 434 <form method=post action=$form->{script}>
 
 436 <input type=hidden name=id value=$form->{id}>
 
 437 <input type=hidden name=sort value=$form->{sort}>
 
 438 <input type=hidden name=closedto value=$form->{closedto}>
 
 439 <input type=hidden name=locked value=$form->{locked}>
 
 440 <input type=hidden name=title value="$title">
 
 444     <th class=listtop>$form->{title}</th>
 
 454                 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
 
 455                 <td colspan=3>$vendor</td>
 
 456                 <input type=hidden name=selectvendor value="$form->{selectvendor}">
 
 457                 <input type=hidden name=oldvendor value="$form->{oldvendor}">
 
 458                 <input type=hidden name=vendor_id value="$form->{vendor_id}">
 
 459                 <input type=hidden name=terms value=$form->{terms}>
 
 466                       <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 467                       <td>$form->{creditlimit}</td>
 
 468                       <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
 
 469                       <td class="plus$n">$form->{creditremaining}</td>
 
 470                       <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 471                       <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 476                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 477                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 478                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 479                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 480                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 481                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 491                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 492                 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
 
 495                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 496                 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
 
 499                 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
 
 503                 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
 
 516   <input type=hidden name=selectAP_amount value="$form->{selectAP_amount}">
 
 517   <input type=hidden name=AP_amount value="$form->{AP_amount}">
 
 518   <input type=hidden name=taxchart value="$form->{taxchart}">
 
 519   <input type=hidden name=rowcount value=$form->{rowcount}>
 
 523            <tr class=listheading>
 
 524           <th class=listheading style="width:15%">|
 
 525     . $locale->text('Account') . qq|</th>
 
 526           <th class=listheading style="width:10%">|
 
 527     . $locale->text('Amount') . qq|</th>
 
 528           <th class=listheading style="width:10%">|
 
 529     . $locale->text('Tax') . qq|</th>
 
 530           <th class=listheading style="width:5%">|
 
 531     . $locale->text('Korrektur') . qq|</th>
 
 532           <th class=listheading style="width:10%">|
 
 533     . $locale->text('Taxkey') . qq|</th>
 
 534           <th class=listheading style="width:10%">|
 
 535     . $locale->text('Project') . qq|</th>
 
 539   $amount  = $locale->text('Amount');
 
 540   $project = $locale->text('Project');
 
 542   for $i (1 .. $form->{rowcount}) {
 
 545     $form->{"amount_$i"} =
 
 546       $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
 
 547     $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
 
 548     $selectAP_amount = $selectAP_amount_unquoted;
 
 549     $re_amount = quotemeta($form->{"AP_amount_$i"});
 
 551       s/option value=\"${re_amount}\"/option value=\"$form->{"AP_amount_$i"}\" selected/;
 
 553     $tax_selected = $form->{"taxchart_$i"};
 
 554     $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
 
 556       qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px">$tax</select></td>|;
 
 558     my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
 
 562           <td width=50%><select name="AP_amount_$i" onChange="setTaxkey(this, $i)" style="width:100%">$selectAP_amount</select></td>
 
 563           <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
 
 564           <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
 
 565           <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
 
 567           <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
 
 568               <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
 
 569               <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
 
 577     ($form->{taxincluded})
 
 578     ? $locale->text('Tax Included')
 
 579     : $locale->text('Tax');
 
 581   $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
 
 590           <td><select name=APselected>$form->{selectAP}</select></td>
 
 591           <input type=hidden name=AP value="$form->{AP}">
 
 592           <th align=left>$form->{invtotal}</th>
 
 594           <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 595           <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
 
 597           <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 610           <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
 
 611           <td align=left>$notes</td>
 
 619         <tr class=listheading>
 
 620           <th class=listheading colspan=6>| . $locale->text('Payments') . qq|</th>
 
 624   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 625     @column_index = qw(datepaid source memo paid AP_paid);
 
 627     @column_index = qw(datepaid source memo paid exchangerate AP_paid);
 
 630   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 631   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 632   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 633   $column_data{AP_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 634   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 635   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 640   map { print "$column_data{$_}\n" } @column_index;
 
 646   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 647   for $i (1 .. $form->{paidaccounts}) {
 
 652     $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
 
 653     $form->{"selectAP_paid_$i"} =~
 
 654       s/option value=\"$form->{"AP_paid_$i"}\">/option value=\"$form->{"AP_paid_$i"}\" selected>/;
 
 657     if ($form->{"paid_$i"}) {
 
 659       $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 661     $form->{"exchangerate_$i"} =
 
 662       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 664     $exchangerate = qq| |;
 
 665     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 666       if ($form->{"forex_$i"}) {
 
 668           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 671           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 676 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 679     $column_data{"paid_$i"} =
 
 680       qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
 
 681     $column_data{"AP_paid_$i"} =
 
 682       qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
 
 683     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
 684     $column_data{"datepaid_$i"}     =
 
 685       qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}>
 
 686          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
 687     $column_data{"source_$i"} =
 
 688       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
 689     $column_data{"memo_$i"} =
 
 690       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
 692     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
 697     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
 699   map { $form->{$_} =~ s/\"/"/g } qw(selectAP_paid);
 
 700   print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
 702     <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 703     <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
 
 709     <td><hr size=3 noshade></td>
 
 714   $lxdebug->leave_sub();
 
 718   $lxdebug->enter_sub();
 
 722 <input name=callback type=hidden value="$form->{callback}">
 
 724 <input type=hidden name=path value=$form->{path}>
 
 725 <input type=hidden name=login value=$form->{login}>
 
 726 <input type=hidden name=password value=$form->{password}>
 
 731   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
 732   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
 736     #     print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
 
 738   if ($form->{radier}) {
 
 740         <input class=submit type=submit name=action value="|
 
 741           . $locale->text('Post') . qq|">
 
 742         <input class=submit type=submit name=action value="|
 
 743           . $locale->text('Delete') . qq|">
 
 748 <input class=submit type=submit name=action value="|
 
 749         . $locale->text('Use As Template') . qq|">
 
 752 <input class=submit type=submit name=action value="|
 
 753         . $locale->text('Post Payment') . qq|">
 
 756     if (($transdate > $closedto) && !$form->{id}) {
 
 757       print qq|<input class=submit type=submit name=action value="|
 
 758         . $locale->text('Update') . qq|">
 
 759       <input class=submit type=submit name=action value="|
 
 760         . $locale->text('Post') . qq|">|;
 
 771   $lxdebug->leave_sub();
 
 775   $lxdebug->enter_sub();
 
 783   $form->{invtotal} = 0;
 
 785   #   $form->{selectAP_amount} = $form->{AP_amount};
 
 786   #   $form->{selectAP_amount} =~
 
 787   #     s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
 
 789   ($AP_amountaccno, $AP_amounttaxkey) =
 
 790     split(/--/, $form->{AP_amountselected});
 
 791   $form->{selecttaxchart} = $form->{taxchart};
 
 792   $form->{selecttaxchart} =~
 
 793     s/value=\"$AP_amounttaxkey--([^\"]*)\"/value=\"$AP_amounttaxkey--$1\" selected/;
 
 797   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 798     qw(exchangerate creditlimit creditremaining);
 
 800   @flds  = qw(amount AP_amount projectnumber oldprojectnumber project_id);
 
 802   for $i (1 .. $form->{rowcount}) {
 
 803     $form->{"amount_$i"} =
 
 804       $form->parse_amount(\%myconfig, $form->{"amount_$i"});
 
 805     $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
 
 806     if ($form->{"amount_$i"}) {
 
 809       if (!$form->{"korrektur_$i"}) {
 
 810         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
 812           if ($form->{taxincluded}) {
 
 813             $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
 
 815             $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
 
 818           $form->{"tax_$i"} = 0;
 
 821       $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
 
 823       $totaltax += $form->{"tax_$i"};
 
 824       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 828   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
 830   map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
 
 832   $form->{exchangerate} = $exchangerate
 
 836                       $form->check_exchangerate(
 
 837                       \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
 
 840   $form->{invdate} = $form->{transdate};
 
 841   $save_AP = $form->{AP};
 
 843   $form->{AP} = $save_AP;
 
 846   $form->{rowcount} = $count + 1;
 
 849     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
 
 851   for $i (1 .. $form->{paidaccounts}) {
 
 852     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 855           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 856       } qw(paid exchangerate);
 
 858       $totalpaid += $form->{"paid_$i"};
 
 860       $form->{"exchangerate_$i"} = $exchangerate
 
 862             $form->{"forex_$i"} = (
 
 864                   $form->check_exchangerate(
 
 865                   \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
 
 870   $form->{creditremaining} -=
 
 871     ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
 
 872      $form->{oldinvtotal});
 
 873   $form->{oldinvtotal}  = $form->{invtotal};
 
 874   $form->{oldtotalpaid} = $totalpaid;
 
 878   $lxdebug->leave_sub();
 
 883   $lxdebug->enter_sub();
 
 884   for $i (1 .. $form->{paidaccounts}) {
 
 885     if ($form->{"paid_$i"}) {
 
 886       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 888       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 890       $form->error($locale->text('Cannot post payment for a closed period!'))
 
 891         if ($datepaid <= $closedto);
 
 893       if ($form->{currency} ne $form->{defaultcurrency}) {
 
 894         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
 895           if ($invdate == $datepaid);
 
 896         $form->isblank("exchangerate_$i",
 
 897                        $locale->text('Exchangerate for payment missing!'));
 
 902   ($form->{AP})      = split /--/, $form->{AP};
 
 903   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
 
 904   $form->redirect($locale->text(' Payment posted!'))
 
 905       if (AP->post_payment(\%myconfig, \%$form));
 
 906     $form->error($locale->text('Cannot post payment!'));
 
 909   $lxdebug->leave_sub();
 
 914   $lxdebug->enter_sub();
 
 916   # check if there is a vendor, invoice and due date
 
 917   $form->isblank("transdate", $locale->text("Invoice Date missing!"));
 
 918   $form->isblank("duedate",   $locale->text("Due Date missing!"));
 
 919   $form->isblank("vendor",    $locale->text('Vendor missing!'));
 
 921   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
 922   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
 924   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
 925     if ($transdate <= $closedto);
 
 927   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
 928     if ($form->{currency} ne $form->{defaultcurrency});
 
 931   for $i (1 .. $form->{paidaccounts}) {
 
 932     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 933       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 935       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 937       $form->error($locale->text('Cannot post payment for a closed period!'))
 
 938         if ($datepaid <= $closedto);
 
 940       if ($form->{currency} ne $form->{defaultcurrency}) {
 
 941         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
 942           if ($transdate == $datepaid);
 
 943         $form->isblank("exchangerate_$i",
 
 944                        $locale->text('Exchangerate for payment missing!'));
 
 950   # if old vendor ne vendor redo form
 
 951   ($vendor) = split /--/, $form->{vendor};
 
 952   if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
 
 956   ($debitaccno,    $debittaxkey)    = split /--/, $form->{AP_amountselected};
 
 957   ($taxkey,        $NULL)           = split /--/, $form->{taxchartselected};
 
 958   ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
 
 959   $form->{AP}{amount_1} = $debitaccno;
 
 960   $form->{AP}{payables} = $payablesaccno;
 
 961   $form->{taxkey}       = $taxkey;
 
 963   $form->{id} = 0 if $form->{postasnew};
 
 965   $form->redirect($locale->text('Transaction posted!'))
 
 966     if (AP->post_transaction(\%myconfig, \%$form));
 
 967   $form->error($locale->text('Cannot post transaction!'));
 
 969   $lxdebug->leave_sub();
 
 973   $lxdebug->enter_sub();
 
 975   $form->{postasnew} = 1;
 
 978   $lxdebug->leave_sub();
 
 981 sub use_as_template {
 
 982   $lxdebug->enter_sub();
 
 984   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);
 
 985   $form->{paidaccounts} = 1;
 
 987   $form->{invdate} = $form->current_date(\%myconfig);
 
 990   $lxdebug->leave_sub();
 
 994   $lxdebug->enter_sub();
 
 996   $form->{title} = $locale->text('Confirm!');
 
1000   delete $form->{header};
 
1005 <form method=post action=$form->{script}>
 
1008   foreach $key (keys %$form) {
 
1009     $form->{$key} =~ s/\"/"/g;
 
1010     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1014 <h2 class=confirm>$form->{title}</h2>
 
1017     . $locale->text('Are you sure you want to delete Transaction')
 
1018     . qq| $form->{invnumber}</h4>
 
1020 <input name=action class=submit type=submit value="|
 
1021     . $locale->text('Yes') . qq|">
 
1028   $lxdebug->leave_sub();
 
1032   $lxdebug->enter_sub();
 
1034   $form->redirect($locale->text('Transaction deleted!'))
 
1035     if (AP->delete_transaction(\%myconfig, \%$form, $spool));
 
1036   $form->error($locale->text('Cannot delete transaction!'));
 
1038   $lxdebug->leave_sub();
 
1042   $lxdebug->enter_sub();
 
1044   # setup vendor selection
 
1045   $form->all_vc(\%myconfig, "vendor", "AP");
 
1047   if (@{ $form->{all_vendor} }) {
 
1048     map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
 
1049       @{ $form->{all_vendor} };
 
1050     $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
 
1052     $vendor = qq|<input name=vendor size=35>|;
 
1056   if (@{ $form->{all_departments} }) {
 
1057     $form->{selectdepartment} = "<option>\n";
 
1060       $form->{selectdepartment} .=
 
1061         "<option>$_->{description}--$_->{id}\n"
 
1062     } (@{ $form->{all_departments} });
 
1067           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1068           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1070 | if $form->{selectdepartment};
 
1072   $form->{title} = $locale->text('AP Transactions');
 
1074   # use JavaScript Calendar or not
 
1075   $form->{jsscript} = $jscalendar;
 
1077   if ($form->{jsscript}) {
 
1079     # with JavaScript Calendar
 
1081        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
 
1082        <input type=button name=transdatefrom id="trigger1" value=|
 
1083       . $locale->text('button') . qq|></td>
 
1086        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
 
1087        <input type=button name=transdateto name=transdateto id="trigger2" value=|
 
1088       . $locale->text('button') . qq|></td>
 
1093       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
 
1094                           "transdateto", "BL", "trigger2");
 
1097     # without JavaScript Calendar
 
1099                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
 
1101                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
 
1109 <form method=post action=$form->{script}>
 
1113     <th class=listtop>$form->{title}</th>
 
1115   <tr height="5"></tr>
 
1120           <th align=right>| . $locale->text('Vendor') . qq|</th>
 
1121           <td colspan=3>$vendor</td>
 
1125           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
1126           <td colspan=3><input name=invnumber size=20></td>
 
1129           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
1130           <td colspan=3><input name=ordnumber size=20></td>
 
1133           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
 
1134           <td colspan=3><input name=notes size=40></td>
 
1137           <th align=right nowrap>| . $locale->text('From') . qq|</th>
 
1139           <th align=right>| . $locale->text('Bis') . qq|</th>
 
1142         <input type=hidden name=sort value=transdate>
 
1150           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
1154                 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
 
1155                 <td nowrap>| . $locale->text('Open') . qq|</td>
 
1156                 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
 
1157                 <td nowrap>| . $locale->text('Closed') . qq|</td>
 
1160                 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
1161                 <td nowrap>| . $locale->text('ID') . qq|</td>
 
1162                 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
1163                 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
 
1164                 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
 
1165                 <td nowrap>| . $locale->text('Order Number') . qq|</td>
 
1168                 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
1169                 <td nowrap>| . $locale->text('Vendor') . qq|</td>
 
1170                 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
1171                 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
 
1172                 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
 
1173                 <td nowrap>| . $locale->text('Amount') . qq|</td>
 
1176                 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
 
1177                 <td nowrap>| . $locale->text('Tax') . qq|</td>
 
1178                 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
 
1179                 <td nowrap>| . $locale->text('Total') . qq|</td>
 
1180                 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
 
1181                 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
 
1184                 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
 
1185                 <td nowrap>| . $locale->text('Paid') . qq|</td>
 
1186                 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
 
1187                 <td nowrap>| . $locale->text('Due Date') . qq|</td>
 
1188                 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
 
1189                 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
 
1192                 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
1193                 <td nowrap>| . $locale->text('Notes') . qq|</td>
 
1194                 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
 
1195                 <td nowrap>| . $locale->text('Employee') . qq|</td>
 
1198                 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
1199                 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
 
1208     <td><hr size=3 noshade></td>
 
1215 <input type=hidden name=nextsub value=$form->{nextsub}>
 
1216 <input type=hidden name=path value=$form->{path}>
 
1217 <input type=hidden name=login value=$form->{login}>
 
1218 <input type=hidden name=password value=$form->{password}>
 
1220 <input class=submit type=submit name=action value="|
 
1221     . $locale->text('Continue') . qq|">
 
1228   $lxdebug->leave_sub();
 
1231 sub ap_transactions {
 
1232   $lxdebug->enter_sub();
 
1234   $form->{vendor} = $form->unescape($form->{vendor});
 
1235   ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
 
1237   AP->ap_transactions(\%myconfig, \%$form);
 
1240     "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
 
1243   if ($form->{vendor}) {
 
1244     $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
 
1245     $href .= "&vendor=" . $form->escape($form->{vendor});
 
1246     $option .= $locale->text('Vendor') . " : $form->{vendor}";
 
1248   if ($form->{department}) {
 
1249     $callback .= "&department=" . $form->escape($form->{department}, 1);
 
1250     $href .= "&department=" . $form->escape($form->{department});
 
1251     ($department) = split /--/, $form->{department};
 
1252     $option .= "\n<br>" if ($option);
 
1253     $option .= $locale->text('Department') . " : $department";
 
1255   if ($form->{invnumber}) {
 
1256     $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
 
1257     $href .= "&invnumber=" . $form->escape($form->{invnumber});
 
1258     $option .= "\n<br>" if ($option);
 
1259     $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
 
1261   if ($form->{ordnumber}) {
 
1262     $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
 
1263     $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
 
1264     $option .= "\n<br>" if ($option);
 
1265     $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
 
1267   if ($form->{notes}) {
 
1268     $callback .= "¬es=" . $form->escape($form->{notes}, 1);
 
1269     $href .= "¬es=" . $form->escape($form->{notes});
 
1270     $option .= "\n<br>" if $option;
 
1271     $option .= $locale->text('Notes') . " : $form->{notes}";
 
1274   if ($form->{transdatefrom}) {
 
1275     $callback .= "&transdatefrom=$form->{transdatefrom}";
 
1276     $href     .= "&transdatefrom=$form->{transdatefrom}";
 
1277     $option   .= "\n<br>" if ($option);
 
1279         $locale->text('From') . " "
 
1280       . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
 
1282   if ($form->{transdateto}) {
 
1283     $callback .= "&transdateto=$form->{transdateto}";
 
1284     $href     .= "&transdateto=$form->{transdateto}";
 
1285     $option   .= "\n<br>" if ($option);
 
1287         $locale->text('Bis') . " "
 
1288       . $locale->date(\%myconfig, $form->{transdateto}, 1);
 
1290   if ($form->{open}) {
 
1291     $callback .= "&open=$form->{open}";
 
1292     $href     .= "&open=$form->{open}";
 
1293     $option   .= "\n<br>" if ($option);
 
1294     $option   .= $locale->text('Open');
 
1296   if ($form->{closed}) {
 
1297     $callback .= "&closed=$form->{closed}";
 
1298     $href     .= "&closed=$form->{closed}";
 
1299     $option   .= "\n<br>" if ($option);
 
1300     $option   .= $locale->text('Closed');
 
1303   @columns = $form->sort_columns(
 
1304     qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee)
 
1307   foreach $item (@columns) {
 
1308     if ($form->{"l_$item"} eq "Y") {
 
1309       push @column_index, $item;
 
1311       # add column to href and callback
 
1312       $callback .= "&l_$item=Y";
 
1313       $href     .= "&l_$item=Y";
 
1317   if ($form->{l_subtotal} eq 'Y') {
 
1318     $callback .= "&l_subtotal=Y";
 
1319     $href     .= "&l_subtotal=Y";
 
1322   $column_header{id} =
 
1323       qq|<th><a class=listheading href=$href&sort=id>|
 
1324     . $locale->text('ID')
 
1326   $column_header{transdate} =
 
1327       qq|<th><a class=listheading href=$href&sort=transdate>|
 
1328     . $locale->text('Date')
 
1330   $column_header{duedate} =
 
1331       qq|<th><a class=listheading href=$href&sort=duedate>|
 
1332     . $locale->text('Due Date')
 
1334   $column_header{due} =
 
1335     qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
 
1336   $column_header{invnumber} =
 
1337       qq|<th><a class=listheading href=$href&sort=invnumber>|
 
1338     . $locale->text('Invoice')
 
1340   $column_header{ordnumber} =
 
1341       qq|<th><a class=listheading href=$href&sort=ordnumber>|
 
1342     . $locale->text('Order')
 
1344   $column_header{name} =
 
1345       qq|<th><a class=listheading href=$href&sort=name>|
 
1346     . $locale->text('Vendor')
 
1348   $column_header{netamount} =
 
1349     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
 
1350   $column_header{tax} =
 
1351     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
 
1352   $column_header{amount} =
 
1353     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
 
1354   $column_header{paid} =
 
1355     qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
 
1356   $column_header{datepaid} =
 
1357       qq|<th><a class=listheading href=$href&sort=datepaid>|
 
1358     . $locale->text('Date Paid')
 
1360   $column_header{notes} =
 
1361     qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
 
1362   $column_header{employee} =
 
1363     "<th><a class=listheading href=$href&sort=employee>"
 
1364     . $locale->text('Employee') . "</th>";
 
1366   $form->{title} = $locale->text('AP Transactions');
 
1375     <th class=listtop>$form->{title}</th>
 
1377   <tr height="5"></tr>
 
1384         <tr class=listheading>
 
1387   map { print "\n$column_header{$_}" } @column_index;
 
1393   # add sort and escape callback
 
1394   $form->{callback} = "$callback&sort=$form->{sort}";
 
1395   $callback = $form->escape($form->{callback});
 
1397   if (@{ $form->{AP} }) {
 
1398     $sameitem = $form->{AP}->[0]->{ $form->{sort} };
 
1401   # sums and tax on reports by Antonio Gallardo
 
1403   foreach $ap (@{ $form->{AP} }) {
 
1405     if ($form->{l_subtotal} eq 'Y') {
 
1406       if ($sameitem ne $ap->{ $form->{sort} }) {
 
1408         $sameitem = $ap->{ $form->{sort} };
 
1412     $column_data{netamount} =
 
1414       . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
 
1416     $column_data{tax} = "<td align=right>"
 
1417       . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
 
1420     $column_data{amount} =
 
1422       . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
 
1423     $column_data{paid} =
 
1425       . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
 
1426     $column_data{due} = "<td align=right>"
 
1427       . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
 
1431     $totalnetamount += $ap->{netamount};
 
1432     $totalamount    += $ap->{amount};
 
1433     $totalpaid      += $ap->{paid};
 
1434     $totaldue       += ($ap->{amount} - $ap->{paid});
 
1436     $subtotalnetamount += $ap->{netamount};
 
1437     $subtotalamount    += $ap->{amount};
 
1438     $subtotalpaid      += $ap->{paid};
 
1439     $subtotaldue       += ($ap->{amount} - $ap->{paid});
 
1441     $column_data{transdate} = "<td>$ap->{transdate} </td>";
 
1442     $column_data{duedate}   = "<td>$ap->{duedate} </td>";
 
1443     $column_data{datepaid}  = "<td>$ap->{datepaid} </td>";
 
1445     $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
 
1447     $column_data{invnumber} =
 
1448       qq|<td><a href="$module?action=edit&path=$form->{path}&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|;
 
1449     $column_data{id}        = "<td>$ap->{id}</td>";
 
1450     $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
 
1451     $column_data{name}      = "<td>$ap->{name}</td>";
 
1452     $ap->{notes} =~ s/\r\n/<br>/g;
 
1453     $column_data{notes}    = "<td>$ap->{notes} </td>";
 
1454     $column_data{employee} = "<td>$ap->{employee} </td>";
 
1459         <tr class=listrow$i >
 
1462     map { print "\n$column_data{$_}" } @column_index;
 
1470   if ($form->{l_subtotal} eq 'Y') {
 
1476         <tr class=listtotal>
 
1479   map { $column_data{$_} = "<td> </td>" } @column_index;
 
1481   $column_data{netamount} =
 
1482     "<th class=listtotal align=right>"
 
1483     . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
 
1484   $column_data{tax} = "<th class=listtotal align=right>"
 
1485     . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
 
1488   $column_data{amount} =
 
1489     "<th class=listtotal align=right>"
 
1490     . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
 
1491   $column_data{paid} =
 
1492     "<th class=listtotal align=right>"
 
1493     . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
 
1495     "<th class=listtotal align=right>"
 
1496     . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
 
1498   map { print "$column_data{$_}\n" } @column_index;
 
1506     <td><hr size=3 noshade></td>
 
1511 <form method=post action=$form->{script}>
 
1513 <input name=callback type=hidden value="$form->{callback}">
 
1515 <input type=hidden name=path value=$form->{path}>
 
1516 <input type=hidden name=login value=$form->{login}>
 
1517 <input type=hidden name=password value=$form->{password}>
 
1519 <input class=submit type=submit name=action value="|
 
1520     . $locale->text('AP Transaction') . qq|">
 
1522 <input class=submit type=submit name=action value="|
 
1523     . $locale->text('Vendor Invoice') . qq|">
 
1531   $lxdebug->leave_sub();
 
1535   $lxdebug->enter_sub();
 
1537   map { $column_data{$_} = "<td> </td>" } @column_index;
 
1539   $column_data{netamount} =
 
1540       "<th class=listsubtotal align=right>"
 
1541     . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
 
1543   $column_data{tax} = "<th class=listsubtotal align=right>"
 
1544     . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
 
1547   $column_data{amount} =
 
1548     "<th class=listsubtotal align=right>"
 
1549     . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
 
1550   $column_data{paid} =
 
1551     "<th class=listsubtotal align=right>"
 
1552     . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
 
1554     "<th class=listsubtotal align=right>"
 
1555     . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
 
1557   $subtotalnetamount = 0;
 
1558   $subtotalamount    = 0;
 
1562   print "<tr class=listsubtotal>";
 
1564   map { print "\n$column_data{$_}" } @column_index;
 
1570   $lxdebug->leave_sub();