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 "bin/mozilla/arap.pl";
 
  39 require "bin/mozilla/common.pl";
 
  40 require "bin/mozilla/drafts.pl";
 
  46 # this is for our long dates
 
  47 # $locale->text('January')
 
  48 # $locale->text('February')
 
  49 # $locale->text('March')
 
  50 # $locale->text('April')
 
  51 # $locale->text('May ')
 
  52 # $locale->text('June')
 
  53 # $locale->text('July')
 
  54 # $locale->text('August')
 
  55 # $locale->text('September')
 
  56 # $locale->text('October')
 
  57 # $locale->text('November')
 
  58 # $locale->text('December')
 
  60 # this is for our short month
 
  61 # $locale->text('Jan')
 
  62 # $locale->text('Feb')
 
  63 # $locale->text('Mar')
 
  64 # $locale->text('Apr')
 
  65 # $locale->text('May')
 
  66 # $locale->text('Jun')
 
  67 # $locale->text('Jul')
 
  68 # $locale->text('Aug')
 
  69 # $locale->text('Sep')
 
  70 # $locale->text('Oct')
 
  71 # $locale->text('Nov')
 
  72 # $locale->text('Dec')
 
  75   $lxdebug->enter_sub();
 
  77   return $lxdebug->leave_sub() if (load_draft_maybe());
 
  79   $form->{title} = "Add";
 
  82     "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
 
  83     unless $form->{callback};
 
  85   AP->get_transdate(\%myconfig, $form);
 
  86   $form->{initial_transdate} = $form->{transdate};
 
  88   $form->{transdate} = $form->{initial_transdate};
 
  91   $lxdebug->leave_sub();
 
  95   $lxdebug->enter_sub();
 
  97   $form->{title} = "Edit";
 
 102   $lxdebug->leave_sub();
 
 106   $lxdebug->enter_sub();
 
 111   $lxdebug->leave_sub();
 
 115   $lxdebug->enter_sub();
 
 117   $form->create_links("AP", \%myconfig, "vendor");
 
 118   $taxincluded = $form->{taxincluded};
 
 119   $duedate     = $form->{duedate};
 
 121   IR->get_vendor(\%myconfig, \%$form);
 
 122   $form->{taxincluded} = $taxincluded;
 
 123   $form->{duedate}   = $duedate if $duedate;
 
 124   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
 
 125   $form->{rowcount}  = 1;
 
 127   # build the popup menus
 
 128   $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
 
 131   $form->{notes} = $form->{intnotes} unless $form->{notes};
 
 134   @curr = split(/:/, $form->{currencies});
 
 136   $form->{defaultcurrency} = $curr[0];
 
 138   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 141   if (@{ $form->{all_vendor} }) {
 
 142     $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
 
 143     map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
 
 144       (@{ $form->{all_vendor} });
 
 148   if (@{ $form->{all_departments} }) {
 
 149     $form->{selectdepartment} = "<option>\n";
 
 150     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 153       $form->{selectdepartment} .=
 
 154         "<option>$_->{description}--$_->{id}\n"
 
 155     } (@{ $form->{all_departments} });
 
 158   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 161   $form->{forex} = $form->{exchangerate};
 
 162   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 164   foreach $key (keys %{ $form->{AP_links} }) {
 
 165     foreach $ref (@{ $form->{AP_links}{$key} }) {
 
 166       if ($key eq "AP_paid") {
 
 167         $form->{"select$key"} .=
 
 168           "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
 
 170         $form->{"select$key"} .=
 
 171           "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
 
 175     $form->{$key} = $form->{"select$key"};
 
 177     # if there is a value we have an old entry
 
 181     for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 183       if ($key eq "AP_paid") {
 
 185         $form->{"AP_paid_$j"} =
 
 186           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 187         $form->{"paid_$j"}     = $form->{acc_trans}{$key}->[$i - 1]->{amount};
 
 188         $form->{"datepaid_$j"} =
 
 189           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 190         $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 191         $form->{"memo_$j"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 193         $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
 
 194           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 195         $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
 
 196         $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id};
 
 197         $form->{paidaccounts}++;
 
 203         if (($key eq "AP_tax") || ($key eq "AR_tax")) {
 
 204           $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
 
 205             "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 206           $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
 
 208                   $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
 
 211           if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
 
 213               $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
 
 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;
 
 249             $form->{APselected} = $form->{acc_trans}{$key}->[$i-1]->{accno};
 
 251           } elsif ($akey eq 'amount') {
 
 252             $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} .
 
 253               "--" . $form->{acc_trans}{$key}->[$i-1]->{id};
 
 254             $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} .
 
 255               "--" . $form->{acc_trans}{$key}->[$i-1]->{rate};
 
 262   $form->{taxincluded}  = $taxincluded if ($form->{id});
 
 263   $form->{paidaccounts} = 1            if not defined $form->{paidaccounts};
 
 265   if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
 
 267     # add tax to amounts and invtotal
 
 268     for $i (1 .. $form->{rowcount}) {
 
 270         ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
 
 271       $tax = $form->round_amount($taxamount, 2);
 
 272       $diff                += ($taxamount - $tax);
 
 273       $form->{"amount_$i"} += $form->{"tax_$i"};
 
 275     $form->{amount_1} += $form->round_amount($diff, 2);
 
 278   $taxamount = $form->round_amount($taxamount, 2);
 
 280   $form->{invtotal} = $totalamount + $totaltax;
 
 283     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 284      $form->datetonum($form->{closedto}, \%myconfig));
 
 286   $lxdebug->leave_sub();
 
 290   $lxdebug->enter_sub();
 
 292   $title = $form->{title};
 
 293   $form->{title} = $locale->text("$title Accounts Payables Transaction");
 
 295   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 297   # type=submit $locale->text('Add Accounts Payables Transaction')
 
 298   # type=submit $locale->text('Edit Accounts Payables Transaction')
 
 300   $form->{javascript} = qq|<script type="text/javascript">
 
 302   function setTaxkey(accno, row) {
 
 303     var taxkey = accno.options[accno.selectedIndex].value;
 
 304     var reg = /--([0-9]*)/;
 
 305     var found = reg.exec(taxkey);
 
 306     var index = found[1];
 
 307     index = parseInt(index);
 
 308     var tax = 'taxchart_' + row;
 
 309     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
 310       var reg2 = new RegExp("^"+ index, "");
 
 311       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
 312         document.getElementById(tax).options[i].selected = true;
 
 319   # show history button
 
 320   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 321   #/show hhistory button
 
 323   # set option selected
 
 324   foreach $item (qw(vendor currency department)) {
 
 325     $form->{"select$item"} =~ s/ selected//;
 
 326     $form->{"select$item"} =~
 
 327       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 329   $readonly = ($form->{id}) ? "readonly" : "";
 
 332     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 333   $readonly                 = ($form->{radier}) ? "" : $readonly;
 
 336   $form->{exchangerate} =
 
 337     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 339   $form->{creditlimit} =
 
 340     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 341   $form->{creditremaining} =
 
 342     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 345 <input type=hidden name=forex value=$form->{forex}>
 
 347   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 348     if ($form->{forex}) {
 
 351               <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 352               <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
 
 357              <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 358              <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
 
 367               <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
 
 368               <th align=left nowrap>|
 
 369     . $locale->text('Tax Included') . qq|</th>
 
 373   if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
 
 377     qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
 
 381                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 382                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 383                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 386 | if $form->{selectdepartment};
 
 388   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 391     ($form->{selectvendor})
 
 392     ? qq|<select name="vendor"
 
 393 onchange="document.getElementById('update_button').click();">$form->{
 
 394 selectvendor } </select>|
 
 395     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
 397   my @old_project_ids = ();
 
 398   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
 399           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
 401   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 403                                    "old_id" => \@old_project_ids },
 
 404                    "charts" => { "key" => "ALL_CHARTS",
 
 405                                  "transdate" => $form->{transdate} },
 
 406                    "taxcharts" => "ALL_TAXCHARTS");
 
 408   map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
 
 409       @{ $form->{ALL_CHARTS} });
 
 411   my %project_labels = ();
 
 412   my @project_values = ("");
 
 413   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 414     push(@project_values, $item->{"id"});
 
 415     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 418   my (%AP_amount_labels, @AP_amount_values);
 
 419   my (%AP_labels, @AP_values);
 
 420   my (%AP_paid_labels, @AP_paid_values);
 
 424   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
 425     if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
 
 426       $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
 
 427       my $key = "$item->{accno}--$item->{tax_id}";
 
 428       push(@AP_amount_values, $key);
 
 429       $AP_amount_labels{$key} =
 
 430         "$item->{accno}--$item->{description}";
 
 432     } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
 
 433       push(@AP_values, $item->{accno});
 
 434       $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
 
 436     } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
 
 437       push(@AP_paid_values, $item->{accno});
 
 438       $AP_paid_labels{$item->{accno}} =
 
 439         "$item->{accno}--$item->{description}";
 
 442     $charts{$item->{accno}} = $item;
 
 445   my %taxchart_labels = ();
 
 446   my @taxchart_values = ();
 
 448   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
 449     my $key = "$item->{id}--$item->{rate}";
 
 450     $taxchart_init = $key if ($taxchart_init eq $item->{id});
 
 451     push(@taxchart_values, $key);
 
 452     $taxchart_labels{$key} =
 
 453       "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
 
 454     $taxcharts{$item->{id}} = $item;
 
 457   # use JavaScript Calendar or not
 
 458   $form->{jsscript} = $jscalendar;
 
 460   if ($form->{jsscript}) {
 
 462     # with JavaScript Calendar
 
 464        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
 
 465        <td><input type=button name=transdate id="trigger1" value=|
 
 466       . $locale->text('button') . qq|></td>
 
 469        <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
 
 470        <td><input type=button name=duedate id="trigger2" value=|
 
 471       . $locale->text('button') . qq|></td></td>
 
 476       Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
 
 477                           "duedate", "BL", "trigger2");
 
 480     # without JavaScript Calendar
 
 482       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
 
 484       qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
 
 486   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 488   $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 489   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 491 <body onLoad="$onload">
 
 493 <form method=post action=$form->{script}>
 
 495 <input type=hidden name=id value=$form->{id}>
 
 496 <input type=hidden name=sort value=$form->{sort}>
 
 497 <input type=hidden name=closedto value=$form->{closedto}>
 
 498 <input type=hidden name=locked value=$form->{locked}>
 
 499 <input type=hidden name=title value="$title">
 
 501 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
 
 505     <th class=listtop>$form->{title}</th>
 
 515                 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
 
 516                 <td colspan=3>$vendor</td>
 
 517                 <input type=hidden name=selectvendor value="$form->{selectvendor}">
 
 518                 <input type=hidden name=oldvendor value="$form->{oldvendor}">
 
 519                 <input type=hidden name=vendor_id value="$form->{vendor_id}">
 
 520                 <input type=hidden name=terms value=$form->{terms}>
 
 527                       <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 528                       <td>$form->{creditlimit}</td>
 
 529                       <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
 
 530                       <td class="plus$n">$form->{creditremaining}</td>
 
 531                       <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 532                       <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 537                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 538                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 539                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 540                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 541                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 542                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 552                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 553                 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
 
 556                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 557                 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
 
 560                 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
 
 564                 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
 
 577   <input type=hidden name=rowcount value=$form->{rowcount}>
 
 581            <tr class=listheading>
 
 582           <th class=listheading style="width:15%">|
 
 583     . $locale->text('Account') . qq|</th>
 
 584           <th class=listheading style="width:10%">|
 
 585     . $locale->text('Amount') . qq|</th>
 
 586           <th class=listheading style="width:10%">|
 
 587     . $locale->text('Tax') . qq|</th>
 
 588           <th class=listheading style="width:5%">|
 
 589     . $locale->text('Korrektur') . qq|</th>
 
 590           <th class=listheading style="width:10%">|
 
 591     . $locale->text('Taxkey') . qq|</th>
 
 592           <th class=listheading style="width:10%">|
 
 593     . $locale->text('Project') . qq|</th>
 
 597   $amount  = $locale->text('Amount');
 
 598   $project = $locale->text('Project');
 
 600   for $i (1 .. $form->{rowcount}) {
 
 603     $form->{"amount_$i"} =
 
 604       $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
 
 605     $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
 
 607     my $selected_accno_full;
 
 608     my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
 
 609     my $item = $charts{$accno_row};
 
 610     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
 
 612     my $selected_taxchart = $form->{"taxchart_$i"};
 
 613     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
 
 614     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
 
 616     if ($previous_accno &&
 
 617         ($previous_accno eq $selected_accno) &&
 
 618         ($previous_tax_id ne $selected_tax_id)) {
 
 619       my $item = $taxcharts{$selected_tax_id};
 
 620       $selected_taxchart = "$item->{id}--$item->{rate}";
 
 623     $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
 
 626       NTI($cgi->popup_menu('-name' => "AP_amount_$i",
 
 627                            '-id' => "AP_amount_$i",
 
 628                            '-style' => 'width:400px',
 
 629                            '-onChange' => "setTaxkey(this, $i)",
 
 630                            '-values' => \@AP_amount_values,
 
 631                            '-labels' => \%AP_amount_labels,
 
 632                            '-default' => $selected_accno_full))
 
 633       . $cgi->hidden('-name' => "previous_AP_amount_$i",
 
 634                      '-default' => $selected_accno_full);
 
 637       NTI($cgi->popup_menu('-name' => "taxchart_$i",
 
 638                            '-id' => "taxchart_$i",
 
 639                            '-style' => 'width:200px',
 
 640                            '-values' => \@taxchart_values,
 
 641                            '-labels' => \%taxchart_labels,
 
 642                            '-default' => $selected_taxchart))
 
 645     my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
 
 648       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
 649                            '-values' => \@project_values,
 
 650                            '-labels' => \%project_labels,
 
 651                            '-default' => $form->{"project_id_$i"} ));
 
 655           <td>$selectAP_amount</td>
 
 656           <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
 
 657           <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
 
 658           <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
 
 660           <td>$projectnumber</td>
 
 668     ($form->{taxincluded})
 
 669     ? $locale->text('Tax Included')
 
 670     : $locale->text('Tax');
 
 672   $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
 
 675     NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
 
 676                          '-style' => 'width:400px',
 
 677                          '-values' => \@AP_values, '-labels' => \%AP_labels,
 
 678                          '-default' => $form->{APselected}));
 
 686           <td>${APselected}</td>
 
 687           <th align=left>$form->{invtotal}</th>
 
 689           <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 690           <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
 
 692           <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 705           <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
 
 706           <td align=left>$notes</td>
 
 714         <tr class=listheading>
 
 715           <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
 
 719   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 720     @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
 
 722     @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
 
 725   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 726   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 727   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 728   $column_data{AP_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 729   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 730   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 731   $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>"; 
 
 736   map { print "$column_data{$_}\n" } @column_index;
 
 742   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 743   for $i (1 .. $form->{paidaccounts}) {
 
 749       NTI($cgi->popup_menu('-name' => "AP_paid_$i",
 
 750                            '-id' => "AP_paid_$i",
 
 751                            '-values' => \@AP_paid_values,
 
 752                            '-labels' => \%AP_paid_labels,
 
 753                            '-default' => $form->{"AP_paid_$i"}));
 
 756     if ($form->{"paid_$i"}) {
 
 758       $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 760     $form->{"exchangerate_$i"} =
 
 761       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 763     $exchangerate = qq| |;
 
 764     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 765       if ($form->{"forex_$i"}) {
 
 767           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 770           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 775 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 778     $column_data{"paid_$i"} =
 
 779       qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
 
 780     $column_data{"AP_paid_$i"} =
 
 781       qq|<td align=center>${selectAP_paid}</td>|;
 
 782     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
 783     $column_data{"datepaid_$i"}     =
 
 784       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)\">
 
 785          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
 786     $column_data{"source_$i"} =
 
 787       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
 788     $column_data{"memo_$i"} =
 
 789       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
 790     $column_data{"paid_project_id_$i"} =
 
 792       . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
 
 793                              '-values' => \@project_values,
 
 794                              '-labels' => \%project_labels,
 
 795                              '-default' => $form->{"paid_project_id_$i"} ))
 
 798     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
 803     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
 805   print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
 807     <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 813     <td><hr size=3 noshade></td>
 
 818   $lxdebug->leave_sub();
 
 822   $lxdebug->enter_sub();
 
 826 <input name=callback type=hidden value="$form->{callback}">
 
 827 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
 
 829 <input type=hidden name=login value=$form->{login}>
 
 830 <input type=hidden name=password value=$form->{password}>
 
 832 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 
 833 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
 
 839   if (!$form->{id} && $form->{draft_id}) {
 
 840     print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
 
 841                              '-value' => 1, '-checked' => $form->{remove_draft},
 
 843           qq| <label for="remove_draft">| .
 
 844           $locale->text("Remove draft when posting") .
 
 848   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
 849   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
 851   print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
 
 852     . $locale->text('Update') . qq|">|;
 
 856     #     print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
 
 858     if ($form->{radier}) {
 
 860         <input class=submit type=submit name=action value="|
 
 861           . $locale->text('Post') . qq|">
 
 862         <input class=submit type=submit name=action value="|
 
 863           . $locale->text('Delete') . qq|">
 
 868 <input class=submit type=submit name=action value="|
 
 869         . $locale->text('Use As Template') . qq|">
 
 870 <input class=submit type=submit name=action value="|
 
 871         . $locale->text('Post Payment') . qq|">
 
 873   } elsif (($transdate > $closedto) && !$form->{id}) {
 
 875       <input class=submit type=submit name=action value="|
 
 876       . $locale->text('Post') . qq|"> | .
 
 877       NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
 
 878                        '-class' => 'submit'));
 
 880   # button for saving history
 
 881   if($form->{id} ne "") {
 
 883           <input type="button" class="submit" onclick="set_history_window(|
 
 885           . qq|);" name="history" id="history" value="|
 
 886           . $locale->text('history') 
 
 889   # /button for saving history
 
 897   $lxdebug->leave_sub();
 
 901   $lxdebug->enter_sub();
 
 905   $form->{invtotal} = 0;
 
 907   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 908     qw(exchangerate creditlimit creditremaining);
 
 910   @flds  = qw(amount AP_amount projectnumber oldprojectnumber project_id);
 
 912   for $i (1 .. $form->{rowcount}) {
 
 913     $form->{"amount_$i"} =
 
 914       $form->parse_amount(\%myconfig, $form->{"amount_$i"});
 
 915     $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
 
 916     if ($form->{"amount_$i"}) {
 
 919       if (!$form->{"korrektur_$i"}) {
 
 920         ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
 922           if ($form->{taxincluded}) {
 
 923             $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
 
 925             $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
 
 928           $form->{"tax_$i"} = 0;
 
 931       $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
 
 933       $totaltax += $form->{"tax_$i"};
 
 934       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 938   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
 940   map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
 
 942   $form->{exchangerate} = $exchangerate
 
 946                       $form->check_exchangerate(
 
 947                       \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
 
 950   $form->{invdate} = $form->{transdate};
 
 951   $save_AP = $form->{AP};
 
 953   $form->{AP} = $save_AP;
 
 955   $form->{rowcount} = $count + 1;
 
 958     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
 
 960   for $i (1 .. $form->{paidaccounts}) {
 
 961     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 964           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 965       } qw(paid exchangerate);
 
 967       $totalpaid += $form->{"paid_$i"};
 
 969       $form->{"exchangerate_$i"} = $exchangerate
 
 971             $form->{"forex_$i"} = (
 
 973                   $form->check_exchangerate(
 
 974                   \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
 
 979   $form->{creditremaining} -=
 
 980     ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
 
 981      $form->{oldinvtotal});
 
 982   $form->{oldinvtotal}  = $form->{invtotal};
 
 983   $form->{oldtotalpaid} = $totalpaid;
 
 987   $lxdebug->leave_sub();
 
 992   $lxdebug->enter_sub();
 
 993   for $i (1 .. $form->{paidaccounts}) {
 
 994     if ($form->{"paid_$i"}) {
 
 995       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 997       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 999       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1000         if ($datepaid <= $closedto);
 
1002       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1003         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1004           if ($invdate == $datepaid);
 
1005         $form->isblank("exchangerate_$i",
 
1006                        $locale->text('Exchangerate for payment missing!'));
 
1011   ($form->{AP})      = split /--/, $form->{AP};
 
1012   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
 
1013   $form->redirect($locale->text(' Payment posted!'))
 
1014       if (AP->post_payment(\%myconfig, \%$form));
 
1015     $form->error($locale->text('Cannot post payment!'));
 
1018   $lxdebug->leave_sub();
 
1023   $lxdebug->enter_sub();
 
1025   # check if there is a vendor, invoice and due date
 
1026   $form->isblank("transdate", $locale->text("Invoice Date missing!"));
 
1027   $form->isblank("duedate",   $locale->text("Due Date missing!"));
 
1028   $form->isblank("vendor",    $locale->text('Vendor missing!'));
 
1030   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1031   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1033   $form->error($locale->text('Cannot post transaction for a closed period!'))
 
1034     if ($transdate <= $closedto);
 
1036   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1037     if ($form->{currency} ne $form->{defaultcurrency});
 
1038   delete($form->{AP});
 
1040   for $i (1 .. $form->{paidaccounts}) {
 
1041     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
1042       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1044       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1046       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1047         if ($datepaid <= $closedto);
 
1049       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1050         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1051           if ($transdate == $datepaid);
 
1052         $form->isblank("exchangerate_$i",
 
1053                        $locale->text('Exchangerate for payment missing!'));
 
1059   # if old vendor ne vendor redo form
 
1060   ($vendor) = split /--/, $form->{vendor};
 
1061   if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
 
1065   ($debitaccno,    $debittaxkey)    = split /--/, $form->{AP_amountselected};
 
1066   ($taxkey,        $NULL)           = split /--/, $form->{taxchartselected};
 
1067   ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
 
1068   $form->{AP}{amount_1} = $debitaccno;
 
1069   $form->{AP}{payables} = $payablesaccno;
 
1070   $form->{taxkey}       = $taxkey;
 
1072   $form->{id} = 0 if $form->{postasnew};
 
1074   if (AP->post_transaction(\%myconfig, \%$form)) {
 
1075     # saving the history
 
1076     if(!exists $form->{addition} && $form->{id} ne "") {
 
1077       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1078       $form->{addition} = "POSTED";
 
1079       $form->save_history($form->dbconnect(\%myconfig));
 
1081     # /saving the history 
 
1082     remove_draft() if $form->{remove_draft};
 
1083     $form->redirect($locale->text('Transaction posted!'));
 
1085   $form->error($locale->text('Cannot post transaction!'));
 
1087   $lxdebug->leave_sub();
 
1091   $lxdebug->enter_sub();
 
1093   $form->{postasnew} = 1;
 
1094   # saving the history
 
1095   if(!exists $form->{addition} && $form->{id} ne "") {
 
1096     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1097         $form->{addition} = "POSTED AS NEW";
 
1098         $form->save_history($form->dbconnect(\%myconfig));
 
1100   # /saving the history 
 
1103   $lxdebug->leave_sub();
 
1106 sub use_as_template {
 
1107   $lxdebug->enter_sub();
 
1109   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);
 
1110   $form->{paidaccounts} = 1;
 
1111   $form->{rowcount}--;
 
1112   $form->{invdate} = $form->current_date(\%myconfig);
 
1115   $lxdebug->leave_sub();
 
1119   $lxdebug->enter_sub();
 
1121   $form->{title} = $locale->text('Confirm!');
 
1125   delete $form->{header};
 
1130 <form method=post action=$form->{script}>
 
1133   foreach $key (keys %$form) {
 
1134     $form->{$key} =~ s/\"/"/g;
 
1135     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1139 <h2 class=confirm>$form->{title}</h2>
 
1142     . $locale->text('Are you sure you want to delete Transaction')
 
1143     . qq| $form->{invnumber}</h4>
 
1145 <input name=action class=submit type=submit value="|
 
1146     . $locale->text('Yes') . qq|">
 
1153   $lxdebug->leave_sub();
 
1157   $lxdebug->enter_sub();
 
1158   if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
 
1159     # saving the history
 
1160     if(!exists $form->{addition}) {
 
1161       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1162           $form->{addition} = "DELETED";
 
1163       $form->save_history($form->dbconnect(\%myconfig));
 
1165     # /saving the history 
 
1166     $form->redirect($locale->text('Transaction deleted!'));
 
1168   $form->error($locale->text('Cannot delete transaction!'));
 
1170   $lxdebug->leave_sub();
 
1174   $lxdebug->enter_sub();
 
1176   # setup vendor selection
 
1177   $form->all_vc(\%myconfig, "vendor", "AP");
 
1179   if (@{ $form->{all_vendor} }) {
 
1180     map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
 
1181       @{ $form->{all_vendor} };
 
1182     $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
 
1184     $vendor = qq|<input name=vendor size=35>|;
 
1188   if (@{ $form->{all_departments} }) {
 
1189     $form->{selectdepartment} = "<option>\n";
 
1192       $form->{selectdepartment} .=
 
1193         "<option>$_->{description}--$_->{id}\n"
 
1194     } (@{ $form->{all_departments} });
 
1199           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1200           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1202 | if $form->{selectdepartment};
 
1204   $form->{title} = $locale->text('AP Transactions');
 
1206   # use JavaScript Calendar or not
 
1207   $form->{jsscript} = $jscalendar;
 
1209   if ($form->{jsscript}) {
 
1211     # with JavaScript Calendar
 
1213        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
1214        <input type=button name=transdatefrom id="trigger1" value=|
 
1215       . $locale->text('button') . qq|></td>
 
1218        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
1219        <input type=button name=transdateto name=transdateto id="trigger2" value=|
 
1220       . $locale->text('button') . qq|></td>
 
1225       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
 
1226                           "transdateto", "BL", "trigger2");
 
1229     # without JavaScript Calendar
 
1231                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
1233                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
1236   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1241   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1242     push(@values, $item->{"id"});
 
1243     $labels{$item->{"id"}} = $item->{"projectnumber"};
 
1246     NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
 
1247                          '-labels' => \%labels));
 
1248   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
1250   $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
1251   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
1253 <body onLoad="$onload">
 
1255 <form method=post action=$form->{script}>
 
1259     <th class=listtop>$form->{title}</th>
 
1261   <tr height="5"></tr>
 
1266           <th align=right>| . $locale->text('Vendor') . qq|</th>
 
1267           <td colspan=3>$vendor</td>
 
1271           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
1272           <td colspan=3><input name=invnumber size=20></td>
 
1275           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
1276           <td colspan=3><input name=ordnumber size=20></td>
 
1279           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
 
1280           <td colspan=3><input name=notes size=40></td>
 
1283           <th align="right">| . $locale->text("Project Number") . qq|</th>
 
1284           <td colspan="3">$projectnumber</td>
 
1287           <th align=right nowrap>| . $locale->text('From') . qq|</th>
 
1289           <th align=right>| . $locale->text('Bis') . qq|</th>
 
1292         <input type=hidden name=sort value=transdate>
 
1300           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
1304                 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
 
1305                 <td nowrap>| . $locale->text('Open') . qq|</td>
 
1306                 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
 
1307                 <td nowrap>| . $locale->text('Closed') . qq|</td>
 
1310                 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
1311                 <td nowrap>| . $locale->text('ID') . qq|</td>
 
1312                 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
1313                 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
 
1314                 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
 
1315                 <td nowrap>| . $locale->text('Order Number') . qq|</td>
 
1318                 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
1319                 <td nowrap>| . $locale->text('Vendor') . qq|</td>
 
1320                 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
1321                 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
 
1322                 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
 
1323                 <td nowrap>| . $locale->text('Amount') . qq|</td>
 
1326                 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
 
1327                 <td nowrap>| . $locale->text('Tax') . qq|</td>
 
1328                 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
 
1329                 <td nowrap>| . $locale->text('Total') . qq|</td>
 
1330                 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
 
1331                 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
 
1334                 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
 
1335                 <td nowrap>| . $locale->text('Paid') . qq|</td>
 
1336                 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
 
1337                 <td nowrap>| . $locale->text('Due Date') . qq|</td>
 
1338                 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
 
1339                 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
 
1342                 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
1343                 <td nowrap>| . $locale->text('Notes') . qq|</td>
 
1344                 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
 
1345                 <td nowrap>| . $locale->text('Employee') . qq|</td>
 
1348                 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
1349                 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
 
1350                 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
 
1351                 <td nowrap>| . $locale->text('Project Number') . qq|</td>
 
1360     <td><hr size=3 noshade></td>
 
1367 <input type=hidden name=nextsub value=$form->{nextsub}>
 
1368 <input type=hidden name=login value=$form->{login}>
 
1369 <input type=hidden name=password value=$form->{password}>
 
1371 <input class=submit type=submit name=action value="|
 
1372     . $locale->text('Continue') . qq|">
 
1379   $lxdebug->leave_sub();
 
1382 sub ap_transactions {
 
1383   $lxdebug->enter_sub();
 
1385   $form->{vendor} = $form->unescape($form->{vendor});
 
1386   ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
 
1388   AP->ap_transactions(\%myconfig, \%$form);
 
1391     "$form->{script}?action=ap_transactions&login=$form->{login}&password=$form->{password}";
 
1394   if ($form->{vendor}) {
 
1395     $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
 
1396     $href .= "&vendor=" . $form->escape($form->{vendor});
 
1397     $option .= $locale->text('Vendor') . " : $form->{vendor}";
 
1399   if ($form->{department}) {
 
1400     $callback .= "&department=" . $form->escape($form->{department}, 1);
 
1401     $href .= "&department=" . $form->escape($form->{department});
 
1402     ($department) = split /--/, $form->{department};
 
1403     $option .= "\n<br>" if ($option);
 
1404     $option .= $locale->text('Department') . " : $department";
 
1406   if ($form->{invnumber}) {
 
1407     $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
 
1408     $href .= "&invnumber=" . $form->escape($form->{invnumber});
 
1409     $option .= "\n<br>" if ($option);
 
1410     $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
 
1412   if ($form->{ordnumber}) {
 
1413     $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
 
1414     $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
 
1415     $option .= "\n<br>" if ($option);
 
1416     $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
 
1418   if ($form->{notes}) {
 
1419     $callback .= "¬es=" . $form->escape($form->{notes}, 1);
 
1420     $href .= "¬es=" . $form->escape($form->{notes});
 
1421     $option .= "\n<br>" if $option;
 
1422     $option .= $locale->text('Notes') . " : $form->{notes}";
 
1425   if ($form->{transdatefrom}) {
 
1426     $callback .= "&transdatefrom=$form->{transdatefrom}";
 
1427     $href     .= "&transdatefrom=$form->{transdatefrom}";
 
1428     $option   .= "\n<br>" if ($option);
 
1430         $locale->text('From') . " "
 
1431       . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
 
1433   if ($form->{transdateto}) {
 
1434     $callback .= "&transdateto=$form->{transdateto}";
 
1435     $href     .= "&transdateto=$form->{transdateto}";
 
1436     $option   .= "\n<br>" if ($option);
 
1438         $locale->text('Bis') . " "
 
1439       . $locale->date(\%myconfig, $form->{transdateto}, 1);
 
1441   if ($form->{open}) {
 
1442     $callback .= "&open=$form->{open}";
 
1443     $href     .= "&open=$form->{open}";
 
1444     $option   .= "\n<br>" if ($option);
 
1445     $option   .= $locale->text('Open');
 
1447   if ($form->{closed}) {
 
1448     $callback .= "&closed=$form->{closed}";
 
1449     $href     .= "&closed=$form->{closed}";
 
1450     $option   .= "\n<br>" if ($option);
 
1451     $option   .= $locale->text('Closed');
 
1453   if ($form->{globalproject_id}) {
 
1454     $callback .= "&globalproject_id=" . E($form->{globalproject_id});
 
1455     $href     .= "&globalproject_id=" . E($form->{globalproject_id});
 
1459     qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
 
1460        due duedate notes employee globalprojectnumber);
 
1462   $form->{"l_type"} = "Y";
 
1464   foreach $item (@columns) {
 
1465     if ($form->{"l_$item"} eq "Y") {
 
1466       push @column_index, $item;
 
1468       # add column to href and callback
 
1469       $callback .= "&l_$item=Y";
 
1470       $href     .= "&l_$item=Y";
 
1474   if ($form->{l_subtotal} eq 'Y') {
 
1475     $callback .= "&l_subtotal=Y";
 
1476     $href     .= "&l_subtotal=Y";
 
1479   $column_header{id} =
 
1480       qq|<th><a class=listheading href=$href&sort=id>|
 
1481     . $locale->text('ID')
 
1483   $column_header{transdate} =
 
1484       qq|<th><a class=listheading href=$href&sort=transdate>|
 
1485     . $locale->text('Date')
 
1487   $column_header{type} =
 
1488       "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
 
1489   $column_header{duedate} =
 
1490       qq|<th><a class=listheading href=$href&sort=duedate>|
 
1491     . $locale->text('Due Date')
 
1493   $column_header{due} =
 
1494     qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
 
1495   $column_header{invnumber} =
 
1496       qq|<th><a class=listheading href=$href&sort=invnumber>|
 
1497     . $locale->text('Invoice')
 
1499   $column_header{ordnumber} =
 
1500       qq|<th><a class=listheading href=$href&sort=ordnumber>|
 
1501     . $locale->text('Order')
 
1503   $column_header{name} =
 
1504       qq|<th><a class=listheading href=$href&sort=name>|
 
1505     . $locale->text('Vendor')
 
1507   $column_header{netamount} =
 
1508     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
 
1509   $column_header{tax} =
 
1510     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
 
1511   $column_header{amount} =
 
1512     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
 
1513   $column_header{paid} =
 
1514     qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
 
1515   $column_header{datepaid} =
 
1516       qq|<th><a class=listheading href=$href&sort=datepaid>|
 
1517     . $locale->text('Date Paid')
 
1519   $column_header{notes} =
 
1520     qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
 
1521   $column_header{employee} =
 
1522     "<th><a class=listheading href=$href&sort=employee>"
 
1523     . $locale->text('Employee') . "</th>";
 
1524   $column_header{globalprojectnumber} =
 
1525     qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
 
1527   $form->{title} = $locale->text('AP Transactions');
 
1536     <th class=listtop>$form->{title}</th>
 
1538   <tr height="5"></tr>
 
1545         <tr class=listheading>
 
1548   map { print "\n$column_header{$_}" } @column_index;
 
1554   # add sort and escape callback
 
1555   $form->{callback} = "$callback&sort=$form->{sort}";
 
1556   $callback = $form->escape($form->{callback});
 
1558   if (@{ $form->{AP} }) {
 
1559     $sameitem = $form->{AP}->[0]->{ $form->{sort} };
 
1562   # sums and tax on reports by Antonio Gallardo
 
1564   foreach $ap (@{ $form->{AP} }) {
 
1566     if ($form->{l_subtotal} eq 'Y') {
 
1567       if ($sameitem ne $ap->{ $form->{sort} }) {
 
1569         $sameitem = $ap->{ $form->{sort} };
 
1573     $column_data{netamount} =
 
1575       . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
 
1577     $column_data{tax} = "<td align=right>"
 
1578       . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
 
1581     $column_data{amount} =
 
1583       . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
 
1584     $column_data{paid} =
 
1586       . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
 
1587     $column_data{due} = "<td align=right>"
 
1588       . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
 
1592     $totalnetamount += $ap->{netamount};
 
1593     $totalamount    += $ap->{amount};
 
1594     $totalpaid      += $ap->{paid};
 
1595     $totaldue       += ($ap->{amount} - $ap->{paid});
 
1597     $subtotalnetamount += $ap->{netamount};
 
1598     $subtotalamount    += $ap->{amount};
 
1599     $subtotalpaid      += $ap->{paid};
 
1600     $subtotaldue       += ($ap->{amount} - $ap->{paid});
 
1602     $column_data{transdate} = "<td>$ap->{transdate} </td>";
 
1603     $column_data{type} = "<td>" .
 
1604       ($ap->{invoice}    ? $locale->text("Invoice (one letter abbreviation)") :
 
1605                            $locale->text("AP Transaction (abbreviation)"))
 
1607     $column_data{duedate}   = "<td>$ap->{duedate} </td>";
 
1608     $column_data{datepaid}  = "<td>$ap->{datepaid} </td>";
 
1610     $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
 
1612     $column_data{invnumber} =
 
1613       qq|<td><a href="$module?action=edit&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|;
 
1614     $column_data{id}        = "<td>$ap->{id}</td>";
 
1615     $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
 
1616     $column_data{name}      = "<td>$ap->{name}</td>";
 
1617     $ap->{notes} =~ s/\r\n/<br>/g;
 
1618     $column_data{notes}    = "<td>$ap->{notes} </td>";
 
1619     $column_data{employee} = "<td>$ap->{employee} </td>";
 
1620     $column_data{globalprojectnumber}  =
 
1621       "<td>" . H($ap->{globalprojectnumber}) . "</td>";
 
1626         <tr class=listrow$i >
 
1629     map { print "\n$column_data{$_}" } @column_index;
 
1637   if ($form->{l_subtotal} eq 'Y') {
 
1643         <tr class=listtotal>
 
1646   map { $column_data{$_} = "<td> </td>" } @column_index;
 
1648   $column_data{netamount} =
 
1649     "<th class=listtotal align=right>"
 
1650     . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
 
1651   $column_data{tax} = "<th class=listtotal align=right>"
 
1652     . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
 
1655   $column_data{amount} =
 
1656     "<th class=listtotal align=right>"
 
1657     . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
 
1658   $column_data{paid} =
 
1659     "<th class=listtotal align=right>"
 
1660     . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
 
1662     "<th class=listtotal align=right>"
 
1663     . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
 
1665   map { print "$column_data{$_}\n" } @column_index;
 
1673     <td><hr size=3 noshade></td>
 
1678 <form method=post action=$form->{script}>
 
1680 <input name=callback type=hidden value="$form->{callback}">
 
1682 <input type=hidden name=login value=$form->{login}>
 
1683 <input type=hidden name=password value=$form->{password}>
 
1685 <input class=submit type=submit name=action value="|
 
1686     . $locale->text('AP Transaction') . qq|">
 
1688 <input class=submit type=submit name=action value="|
 
1689     . $locale->text('Vendor Invoice') . qq|">
 
1697   $lxdebug->leave_sub();
 
1701   $lxdebug->enter_sub();
 
1703   map { $column_data{$_} = "<td> </td>" } @column_index;
 
1705   $column_data{netamount} =
 
1706       "<th class=listsubtotal align=right>"
 
1707     . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
 
1709   $column_data{tax} = "<th class=listsubtotal align=right>"
 
1710     . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
 
1713   $column_data{amount} =
 
1714     "<th class=listsubtotal align=right>"
 
1715     . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
 
1716   $column_data{paid} =
 
1717     "<th class=listsubtotal align=right>"
 
1718     . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
 
1720     "<th class=listsubtotal align=right>"
 
1721     . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
 
1723   $subtotalnetamount = 0;
 
1724   $subtotalamount    = 0;
 
1728   print "<tr class=listsubtotal>";
 
1730   map { print "\n$column_data{$_}" } @column_index;
 
1736   $lxdebug->leave_sub();