1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger, Accounting
 
   9 # Copyright (c) 1998-2002
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #======================================================================
 
  30 # Inventory received module
 
  32 #======================================================================
 
  37 require "$form->{path}/io.pl";
 
  38 require "$form->{path}/arap.pl";
 
  45   $lxdebug->enter_sub();
 
  47   $form->{title} = $locale->text('Add Vendor Invoice');
 
  53   $lxdebug->leave_sub();
 
  57   $lxdebug->enter_sub();
 
  59   $form->{title} = $locale->text('Edit Vendor Invoice');
 
  65   $lxdebug->leave_sub();
 
  69   $lxdebug->enter_sub();
 
  72   $form->{webdav} = $webdav;
 
  75   $form->{jscalendar} = $jscalendar;
 
  77   $form->create_links("AP", \%myconfig, "vendor");
 
  79   if ($form->{all_vendor}) {
 
  80     unless ($form->{vendor_id}) {
 
  81       $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
 
  85   $cp_id = $form->{cp_id};
 
  86   IR->get_vendor(\%myconfig, \%$form);
 
  87   IR->retrieve_invoice(\%myconfig, \%$form);
 
  88   $form->{cp_id} = $cp_id;
 
  91   @curr = split /:/, $form->{currencies};
 
  93   $form->{defaultcurrency} = $curr[0];
 
  95   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
  97   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
 
 100   if ($form->{all_vendor}) {
 
 101     $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
 
 102     map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
 
 103       (@{ $form->{all_vendor} });
 
 107   if ($form->{all_departments}) {
 
 108     $form->{selectdepartment} = "<option>\n";
 
 109     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 112       $form->{selectdepartment} .=
 
 113         "<option>$_->{description}--$_->{id}\n"
 
 114     } (@{ $form->{all_departments} });
 
 118   $form->{forex} = $form->{exchangerate};
 
 119   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 121   foreach $key (keys %{ $form->{AP_links} }) {
 
 123     foreach $ref (@{ $form->{AP_links}{$key} }) {
 
 124       $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
 
 127     if ($key eq "AP_paid") {
 
 128       for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 129         $form->{"AP_paid_$i"} =
 
 130           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 133         $form->{"paid_$i"}     = $form->{acc_trans}{$key}->[$i - 1]->{amount};
 
 134         $form->{"datepaid_$i"} =
 
 135           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 136         $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
 
 137           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 138         $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 139         $form->{"memo_$i"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 141         $form->{paidaccounts} = $i;
 
 145         "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
 
 150   $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
 
 152   $form->{AP} = $form->{AP_1} unless $form->{id};
 
 155     ($form->datetonum($form->{invdate}, \%myconfig) <=
 
 156      $form->datetonum($form->{closedto}, \%myconfig));
 
 158   $lxdebug->leave_sub();
 
 161 sub prepare_invoice {
 
 162   $lxdebug->enter_sub();
 
 166     map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
 
 168     foreach $ref (@{ $form->{invoice_details} }) {
 
 170       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
 172       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 174       $decimalplaces = ($dec > 2) ? $dec : 2;
 
 176       $form->{"sellprice_$i"} =
 
 177         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 180       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 181       $dec_qty = length $dec_qty;
 
 184         $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
 
 186       $form->{rowcount} = $i;
 
 190   $lxdebug->leave_sub();
 
 194   $lxdebug->enter_sub();
 
 196   # set option selected
 
 197   foreach $item (qw(AP vendor currency department contact)) {
 
 198     $form->{"select$item"} =~ s/ selected//;
 
 199     $form->{"select$item"} =~
 
 200       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 203   $form->{exchangerate} =
 
 204     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 206   $form->{creditlimit} =
 
 207     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 208   $form->{creditremaining} =
 
 209     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 212   if ($form->{all_contacts}) {
 
 214     $form->{selectcontact} = "";
 
 215     foreach $item (@{ $form->{all_contacts} }) {
 
 216       if ($form->{cp_id} == $item->{cp_id}) {
 
 217         $form->{selectcontact} .=
 
 218           "<option selected>$item->{cp_name}--$item->{cp_id}";
 
 220         $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
 
 226   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 227     if ($form->{forex}) {
 
 229                 <th align=right nowrap>|
 
 230         . $locale->text('Exchangerate') . qq|</th>
 
 231                 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
 
 235                 <th align=right nowrap>|
 
 236         . $locale->text('Exchangerate') . qq|</th>
 
 237                 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
 
 242 <input type=hidden name=forex value=$form->{forex}>
 
 246     ($form->{selectvendor})
 
 247     ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
 
 248     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
 251     ($form->{selectcontact})
 
 252     ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
 
 253     : qq|<input name=contact value="$form->{contact}" size=35>|;
 
 257               <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 258               <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 259               <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 262 | if $form->{selectdepartment};
 
 264   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 266   # use JavaScript Calendar or not
 
 267   $form->{jsscript} = $form->{jscalendar};
 
 269   if ($form->{jsscript}) {
 
 271     # with JavaScript Calendar
 
 273        <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
 
 274        <td><input type=button name=invdate id="trigger1" value=|
 
 275       . $locale->text('button') . qq|></td>
 
 278        <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
 
 279        <td width="4"><input type=button name=duedate id="trigger2" value=|
 
 280       . $locale->text('button') . qq|></td></td>
 
 285       Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
 
 286                           "duedate", "BL", "trigger2");
 
 289     # without JavaScript Calendar
 
 291       qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
 
 293       qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
 
 301 <form method=post action=$form->{script}>
 
 303 <input type=hidden name=id value=$form->{id}>
 
 304 <input type=hidden name=title value="$form->{title}">
 
 305 <input type=hidden name=vc value="vendor">
 
 306 <input type=hidden name=type value=$form->{type}>
 
 307 <input type=hidden name=level value=$form->{level}>
 
 309 <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 310 <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 312 <input type=hidden name=closedto value=$form->{closedto}>
 
 313 <input type=hidden name=locked value=$form->{locked}>
 
 315 <input type=hidden name=shipped value=$form->{shipped}>
 
 320     <th class=listtop>$form->{title}</th>
 
 330                 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
 
 331                 <td colspan=3>$vendor</td>
 
 333                 <th align=richt nowrap>|
 
 334     . $locale->text('Contact Person') . qq|</th>
 
 335                 <td colspan=3>$contact</td>
 
 337                 <input type=hidden name=vendor_id value=$form->{vendor_id}>
 
 338                 <input type=hidden name=oldvendor value="$form->{oldvendor}">
 
 346                       <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 347                       <td>$form->{creditlimit}</td>
 
 349                       <th nowrap>| . $locale->text('Remaining') . qq|</th>
 
 350                       <td class="plus$n">$form->{creditremaining}</td>
 
 355                 <th align=right>| . $locale->text('Record in') . qq|</th>
 
 356                 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
 
 357                 <input type=hidden name=selectAP value="$form->{selectAP}">
 
 361                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 362                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 370                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 371                 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
 
 374                 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
 
 378                 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
 
 382                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 383                 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
 
 384 <input type=hidden name=quonumber value="$form->{quonumber}">
 
 395 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 396 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 397 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 398 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 399 <input type=hidden name=webdav value=$webdav>
 
 401 <input type=hidden name=taxpart value="$form->{taxpart}">
 
 402 <input type=hidden name=taxservice value="$form->{taxservice}">
 
 404 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 407   foreach $item (split / /, $form->{taxaccounts}) {
 
 409 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
 
 410 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
 
 414   $lxdebug->leave_sub();
 
 418   $lxdebug->enter_sub();
 
 420   $form->{invtotal} = $form->{invsubtotal};
 
 422   if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
 
 425   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
 
 428   $rows = ($rows > $introws) ? $rows : $introws;
 
 430     qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
 
 432     qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
 
 434   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 437   if ($form->{taxaccounts}) {
 
 439                 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
 
 440       . $locale->text('Tax Included') . qq|</b>
 
 444   if (!$form->{taxincluded}) {
 
 446     foreach $item (split / /, $form->{taxaccounts}) {
 
 447       if ($form->{"${item}_base"}) {
 
 448         $form->{invtotal} += $form->{"${item}_total"} =
 
 450                              $form->{"${item}_base"} * $form->{"${item}_rate"},
 
 452         $form->{"${item}_total"} =
 
 453           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 457                   <th align=right>$form->{"${item}_description"}</th>
 
 458                   <td align=right>$form->{"${item}_total"}</td>
 
 464     $form->{invsubtotal} =
 
 465       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
 
 469                 <th align=right>| . $locale->text('Subtotal') . qq|</th>
 
 470                 <td align=right>$form->{invsubtotal}</td>
 
 476   if ($form->{taxincluded}) {
 
 477     foreach $item (split / /, $form->{taxaccounts}) {
 
 478       if ($form->{"${item}_base"}) {
 
 479         $form->{"${item}_total"} =
 
 481                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
 
 482                               (1 + $form->{"${item}_rate"})
 
 485         $form->{"${item}_base"} =
 
 486           $form->round_amount($form->{"${item}_base"}, 2);
 
 487         $form->{"${item}_netto"} =
 
 489                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
 
 491         $form->{"${item}_netto"} =
 
 492           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
 
 493         $form->{"${item}_total"} =
 
 494           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 498                 <th align=right>Enthaltene $form->{"${item}_description"}</th>
 
 499                 <td align=right>$form->{"${item}_total"}</td>
 
 502                 <th align=right>Nettobetrag</th>
 
 503                 <td align=right>$form->{"${item}_netto"}</td>
 
 511   $form->{oldinvtotal} = $form->{invtotal};
 
 513     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
 
 517     <td colspan=$colspan>
 
 518       <table cellspacing="0">
 
 523                 <th align=left>| . $locale->text('Notes') . qq|</th>
 
 524                 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
 
 532           <td colspan=2 align=right width=100%>
 
 539                 <th align=right>| . $locale->text('Total') . qq|</th>
 
 540                 <td align=right>$form->{invtotal}</td>
 
 552     <td><hr size=3 noshade></td>
 
 555     <th class=listtop align=left>Dokumente im Webdav-Repository</th>
 
 558       <td align=left width=30%><b>Dateiname</b></td>
 
 559       <td align=left width=70%><b>Webdavlink</b></td>
 
 561     foreach $file (keys %{ $form->{WEBDAV} }) {
 
 564         <td align=left>$file</td>
 
 565         <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
 
 577 <input type=hidden name=jscalendar value=$form->{jscalendar}>
 
 581     <td colspan=$colspan>
 
 584           <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
 
 588   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 589     @column_index = qw(datepaid source memo paid AP_paid);
 
 591     @column_index = qw(datepaid source memo paid exchangerate AP_paid);
 
 594   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 595   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 596   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 597   $column_data{AP_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 598   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 599   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 604   map { print "$column_data{$_}\n" } @column_index;
 
 609   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 610   for $i (1 .. $form->{paidaccounts}) {
 
 616     $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
 
 617     $form->{"selectAP_paid_$i"} =~
 
 618       s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
 
 622       $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 623     $form->{"exchangerate_$i"} =
 
 624       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 626     $exchangerate = qq| |;
 
 627     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 628       if ($form->{"forex_$i"}) {
 
 630           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 633           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 637 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 640     $column_data{"paid_$i"} =
 
 641       qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
 
 642     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
 643     $column_data{"AP_paid_$i"}      =
 
 644       qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
 
 645     $column_data{"datepaid_$i"} =
 
 646       qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
 
 647     $column_data{"source_$i"} =
 
 648       qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
 
 649     $column_data{"memo_$i"} =
 
 650       qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
 
 652     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
 660             <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 661             <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 662             <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
 
 667     <td><hr size=3 noshade></td>
 
 673   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
 674   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
 677     print qq|<input class=submit type=submit name=action value="|
 
 678       . $locale->text('Update') . qq|">
 
 681     if (!$form->{revtrans}) {
 
 682       if (!$form->{locked}) {
 
 684         <input class=submit type=submit name=action value="|
 
 685           . $locale->text('Post') . qq|">
 
 686         <input class=submit type=submit name=action value="|
 
 687           . $locale->text('Delete') . qq|">
 
 692     if ($invdate > $closedto) {
 
 694       <input class=submit type=submit name=action value="|
 
 695         . $locale->text('Post as new') . qq|">
 
 696       <input class=submit type=submit name=action value="|
 
 697         . $locale->text('Order') . qq|">
 
 702     if ($invdate > $closedto) {
 
 703       print qq|<input class=submit type=submit name=action value="|
 
 704         . $locale->text('Update') . qq|">
 
 705       <input class=submit type=submit name=action value="|
 
 706         . $locale->text('Post') . qq|">|;
 
 710   if ($form->{menubar}) {
 
 711     require "$form->{path}/menu.pl";
 
 717 <input type=hidden name=rowcount value=$form->{rowcount}>
 
 719 <input name=callback type=hidden value="$form->{callback}">
 
 721 <input type=hidden name=path value=$form->{path}>
 
 722 <input type=hidden name=login value=$form->{login}>
 
 723 <input type=hidden name=password value=$form->{password}>
 
 731   $lxdebug->leave_sub();
 
 735   $lxdebug->enter_sub();
 
 737   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 738     qw(exchangerate creditlimit creditremaining);
 
 744   $form->{exchangerate} = $exchangerate
 
 748                         $form->check_exchangerate(
 
 749                         \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
 
 752   for $i (1 .. $form->{paidaccounts}) {
 
 753     if ($form->{"paid_$i"}) {
 
 756           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 757       } qw(paid exchangerate);
 
 759       $form->{"exchangerate_$i"} = $exchangerate
 
 761             $form->{"forex_$i"} = (
 
 763                   $form->check_exchangerate(
 
 764                   \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
 
 769   $i            = $form->{rowcount};
 
 770   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 772   if (   ($form->{"partnumber_$i"} eq "")
 
 773       && ($form->{"description_$i"} eq "")
 
 774       && ($form->{"partsgroup_$i"} eq "")) {
 
 775     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
 780     IR->retrieve_item(\%myconfig, \%$form);
 
 782     my $rows = scalar @{ $form->{item_list} };
 
 785       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
 
 794         # override sellprice if there is one entered
 
 795         $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
 797         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
 
 798           qw(partnumber description unit);
 
 800         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
 
 801           keys %{ $form->{item_list}[0] };
 
 803         $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
 
 805         ($dec) = ($s =~ /\.(\d+)/);
 
 807         $decimalplaces = ($dec > 2) ? $dec : 2;
 
 810           $form->{"sellprice_$i"} = $sellprice;
 
 813           # if there is an exchange rate adjust sellprice
 
 814           $form->{"sellprice_$i"} /= $exchangerate;
 
 818           $form->{"sellprice_$i"} * $form->{"qty_$i"} *
 
 819           (1 - $form->{"discount_$i"} / 100);
 
 820         $form->{creditremaining} -= $amount;
 
 821         $form->{"sellprice_$i"} =
 
 822           $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 825           $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
 
 832       # ok, so this is a new part
 
 833       # ask if it is a part or service item
 
 835       if (   $form->{"partsgroup_$i"}
 
 836           && ($form->{"partsnumber_$i"} eq "")
 
 837           && ($form->{"description_$i"} eq "")) {
 
 839         $form->{"discount_$i"} = "";
 
 843         $form->{"id_$i"}   = 0;
 
 844         $form->{"unit_$i"} = $locale->text('ea');
 
 851   $lxdebug->leave_sub();
 
 855   $lxdebug->enter_sub();
 
 857   $form->isblank("invdate", $locale->text('Invoice Date missing!'));
 
 858   $form->isblank("vendor",  $locale->text('Vendor missing!'));
 
 860   # if the vendor changed get new values
 
 861   if (&check_name(vendor)) {
 
 868   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
 869   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
 871   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
 872     if ($invdate <= $closedto);
 
 874   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
 875     if ($form->{currency} ne $form->{defaultcurrency});
 
 877   for $i (1 .. $form->{paidaccounts}) {
 
 878     if ($form->{"paid_$i"}) {
 
 879       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 881       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 883       $form->error($locale->text('Cannot post payment for a closed period!'))
 
 884         if ($datepaid <= $closedto);
 
 886       if ($form->{currency} ne $form->{defaultcurrency}) {
 
 887         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
 888           if ($invdate == $datepaid);
 
 889         $form->isblank("exchangerate_$i",
 
 890                        $locale->text('Exchangerate for payment missing!'));
 
 895   ($form->{AP})      = split /--/, $form->{AP};
 
 896   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
 
 898   $form->{id} = 0 if $form->{postasnew};
 
 900   $form->redirect(  $locale->text('Invoice')
 
 901                   . " $form->{invnumber} "
 
 902                   . $locale->text('posted!'))
 
 903     if (IR->post_invoice(\%myconfig, \%$form));
 
 904   $form->error($locale->text('Cannot post invoice!'));
 
 906   $lxdebug->leave_sub();
 
 910   $lxdebug->enter_sub();
 
 917 <form method=post action=$form->{script}>
 
 920   # delete action variable
 
 921   map { delete $form->{$_} } qw(action header);
 
 923   foreach $key (keys %$form) {
 
 924     $form->{$key} =~ s/\"/"/g;
 
 925     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
 929 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
 932     . $locale->text('Are you sure you want to delete Invoice Number')
 
 933     . qq| $form->{invnumber}</h4>
 
 935 <input name=action class=submit type=submit value="|
 
 936     . $locale->text('Yes') . qq|">
 
 940   $lxdebug->leave_sub();
 
 944   $lxdebug->enter_sub();
 
 946   $form->redirect($locale->text('Invoice deleted!'))
 
 947     if (IR->delete_invoice(\%myconfig, \%$form));
 
 948   $form->error($locale->text('Cannot delete invoice!'));
 
 950   $lxdebug->leave_sub();