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 invoicing module
 
  32 #======================================================================
 
  38 require "$form->{path}/io.pl";
 
  39 require "$form->{path}/arap.pl";
 
  46   $lxdebug->enter_sub();
 
  48   $form->{title} = $locale->text('Add Sales Invoice');
 
  51     "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
 
  52     unless $form->{callback};
 
  54   $form{jsscript} = "date";
 
  56   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  58     $form->error("Access Denied");
 
  65   $lxdebug->leave_sub();
 
  69   $lxdebug->enter_sub();
 
  70 print STDERR "is.pl-edit\n";
 
  71   $form->{title} = $locale->text('Edit Sales Invoice');
 
  73   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  75     $form->error("Access Denied");
 
  82   $lxdebug->leave_sub();
 
  86   $lxdebug->enter_sub();
 
  87 print STDERR "is.pl-invoice_links\n";
 
  88   $form->{vc} = 'customer';
 
  91   $form->{webdav}   = $webdav;
 
  92   $form->{lizenzen} = $lizenzen;
 
  94   $form->create_links("AR", \%myconfig, "customer");
 
  96   if ($form->{all_customer}) {
 
  97     unless ($form->{customer_id}) {
 
  98       $form->{customer_id} = $form->{all_customer}->[0]->{id};
 
 101   $cp_id = $form->{cp_id};
 
 102   IS->get_customer(\%myconfig, \%$form);
 
 104   IS->retrieve_invoice(\%myconfig, \%$form);
 
 105   $form->{cp_id} = $cp_id;
 
 108   @curr = split /:/, $form->{currencies};
 
 110   $form->{defaultcurrency} = $curr[0];
 
 112   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 114   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
 116   if ($form->{all_customer}) {
 
 117     $form->{customer} = "$form->{customer}--$form->{customer_id}";
 
 118     map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
 
 119       (@{ $form->{all_customer} });
 
 123   if ($form->{all_departments}) {
 
 124     $form->{selectdepartment} = "<option>\n";
 
 125     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 128       $form->{selectdepartment} .=
 
 129         "<option>$_->{description}--$_->{id}\n"
 
 130     } (@{ $form->{all_departments} });
 
 133   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 136   if ($form->{all_employees}) {
 
 137     $form->{selectemployee} = "";
 
 138     map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
 
 139       (@{ $form->{all_employees} });
 
 143   $form->{forex} = $form->{exchangerate};
 
 144   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 146   foreach $key (keys %{ $form->{AR_links} }) {
 
 147     foreach $ref (@{ $form->{AR_links}{$key} }) {
 
 148       $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
 
 151     if ($key eq "AR_paid") {
 
 152       for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 153         $form->{"AR_paid_$i"} =
 
 154           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 157         $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
 
 158         $form->{"datepaid_$i"} =
 
 159           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 160         $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
 
 161           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 162         $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 163         $form->{"memo_$i"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 165         $form->{paidaccounts} = $i;
 
 169         "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
 
 174   $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
 
 176   $form->{AR} = $form->{AR_1} unless $form->{id};
 
 179     ($form->datetonum($form->{invdate}, \%myconfig) <=
 
 180      $form->datetonum($form->{closedto}, \%myconfig));
 
 182   $lxdebug->leave_sub();
 
 185 sub prepare_invoice {
 
 186   $lxdebug->enter_sub();
 
 187 print STDERR "is.pl-prepare_invoice\n";
 
 188   $form->{type}     = "invoice";
 
 189   $form->{formname} = "invoice";
 
 190   $form->{format}   = "html";
 
 191   $form->{media}    = "screen";
 
 195     map { $form->{$_} =~ s/\"/"/g }
 
 196       qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
 
 198 #     # get pricegroups for parts
 
 199 #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 201     foreach $ref (@{ $form->{invoice_details} }) {
 
 203       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
 204       $form->{"discount_$i"} =
 
 205         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
 
 206       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 208       $decimalplaces = ($dec > 2) ? $dec : 2;
 
 210       $form->{"sellprice_$i"} =
 
 211         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 213       $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
 215       map { $form->{"${_}_$i"} =~ s/\"/"/g }
 
 216         qw(partnumber description unit partnotes);
 
 217       $form->{rowcount} = $i;
 
 221   $lxdebug->leave_sub();
 
 225   $lxdebug->enter_sub();
 
 226 print STDERR "is.pl-form_header\n";
 
 227   # set option selected
 
 228   foreach $item (qw(AR customer currency department employee contact)) {
 
 229     $form->{"select$item"} =~ s/ selected//;
 
 230     $form->{"select$item"} =~
 
 231       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 235   if ($form->{all_contacts}) {
 
 237     $form->{selectcontact} = "";
 
 238     foreach $item (@{ $form->{all_contacts} }) {
 
 239       if ($form->{cp_id} == $item->{cp_id}) {
 
 240         $form->{selectcontact} .=
 
 241           "<option selected>$item->{cp_name}--$item->{cp_id}";
 
 243         $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
 
 248   #else {$form->{all_contacts} = 0;}
 
 250   $form->{exchangerate} =
 
 251     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 253   $form->{creditlimit} =
 
 254     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 255   $form->{creditremaining} =
 
 256     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 259   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 260     if ($form->{forex}) {
 
 263         . $locale->text('Exchangerate')
 
 264         . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
 
 268         . $locale->text('Exchangerate')
 
 269         . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
 
 273 <input type=hidden name=forex value=$form->{forex}>
 
 277     ($form->{selectcustomer})
 
 278     ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
 
 279     : qq|<input name=customer value="$form->{customer}" size=35>|;
 
 283     ($form->{selectcontact})
 
 284     ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
 
 285     : qq|<input name=contact value="$form->{contact}" size=35>|;
 
 289                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 290                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 291                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 294 | if $form->{selectdepartment};
 
 296   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 298   if ($form->{business}) {
 
 301                 <th align=right>| . $locale->text('Business') . qq|</th>
 
 302                 <td>$form->{business}</td>
 
 303                 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
 
 305       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
 
 311   $form->{fokus} = "invoice.customer";
 
 313   # use JavaScript Calendar or not
 
 314   $form->{jsscript} = $jscalendar;
 
 316   if ($form->{jsscript}) {
 
 318     # with JavaScript Calendar
 
 320        <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
 
 321        <td><input type=button name=invdate id="trigger1" value=|
 
 322       . $locale->text('button') . qq|></td>
 
 325        <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
 
 326        <td width="4"><input type=button name=duedate id="trigger2" value=|
 
 327       . $locale->text('button') . qq|></td></td>
 
 332       Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
 
 333                           "duedate", "BL", "trigger2");
 
 336     # without JavaScript Calendar
 
 338       qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
 
 340       qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
 
 342   if ($form->{resubmit}) {
 
 343     $onload = "document.invoice.submit()";
 
 350 <body onLoad="$onload">
 
 352 <form method=post name="invoice" action=$form->{script}>
 
 355 <input type=hidden name=id value=$form->{id}>
 
 356 <input type=hidden name=action value=$form->{action}>
 
 358 <input type=hidden name=type value=$form->{type}>
 
 359 <input type=hidden name=media value=$form->{media}>
 
 360 <input type=hidden name=format value=$form->{format}>
 
 362 <input type=hidden name=queued value="$form->{queued}">
 
 363 <input type=hidden name=printed value="$form->{printed}">
 
 364 <input type=hidden name=emailed value="$form->{emailed}">
 
 366 <input type=hidden name=title value="$form->{title}">
 
 367 <input type=hidden name=vc value=$form->{vc}>
 
 369 <input type=hidden name=discount value=$form->{discount}>
 
 370 <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 371 <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 373 <input type=hidden name=tradediscount value=$form->{tradediscount}>
 
 374 <input type=hidden name=business value=$form->{business}>
 
 376 <input type=hidden name=closedto value=$form->{closedto}>
 
 377 <input type=hidden name=locked value=$form->{locked}>
 
 379 <input type=hidden name=shipped value=$form->{shipped}>
 
 380 <input type=hidden name=lizenzen value=$lizenzen>
 
 384     <th class=listtop>$form->{title}</th>
 
 394                 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
 
 395                 <td colspan=3>$customer</td>
 
 396     <input type=hidden name=customer_klass value=$form->{customer_klass}>
 
 397                 <input type=hidden name=customer_id value=$form->{customer_id}>
 
 398                 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
 
 399                 <th align=richt nowrap>|
 
 400     . $locale->text('Contact Person') . qq|</th>
 
 401                 <td colspan=3>$contact</td>
 
 408                       <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 409                       <td>$form->{creditlimit}</td>
 
 411                       <th nowrap>| . $locale->text('Remaining') . qq|</th>
 
 412                       <td class="plus$n">$form->{creditremaining}</td>
 
 419                 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
 
 420                 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
 
 421                 <input type=hidden name=selectAR value="$form->{selectAR}">
 
 425                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 426                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 427                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 428                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 429                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 430                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 434                 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
 
 435                 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
 
 438                 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
 
 439                 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
 
 446                 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
 
 447                 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
 
 448                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
 
 452                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 453                 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
 
 456                 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
 
 460                 <th align=right>| . $locale->text('Due Date') . qq|</th>
 
 464                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 465                 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
 
 468                 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
 
 469                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
 
 472                 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
 
 473                 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
 
 488 <!-- shipto are in hidden variables -->
 
 490 <input type=hidden name=shiptoname value="$form->{shiptoname}">
 
 491 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
 
 492 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
 
 493 <input type=hidden name=shiptocity value="$form->{shiptocity}">
 
 494 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
 
 495 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
 
 496 <input type=hidden name=shiptophone value="$form->{shiptophone}">
 
 497 <input type=hidden name=shiptofax value="$form->{shiptofax}">
 
 498 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
 
 500 <!-- email variables -->
 
 501 <input type=hidden name=message value="$form->{message}">
 
 502 <input type=hidden name=email value="$form->{email}">
 
 503 <input type=hidden name=subject value="$form->{subject}">
 
 504 <input type=hidden name=cc value="$form->{cc}">
 
 505 <input type=hidden name=bcc value="$form->{bcc}">
 
 506 <input type=hidden name=webdav value=$webdav>
 
 507 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 510   foreach $item (split / /, $form->{taxaccounts}) {
 
 512 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
 
 513 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
 
 514 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
 
 517   $lxdebug->leave_sub();
 
 521   $lxdebug->enter_sub();
 
 522 print STDERR "is.pl-form_footer\n";
 
 523   $form->{invtotal} = $form->{invsubtotal};
 
 525   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
 
 528   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
 
 531   $rows = ($rows > $introws) ? $rows : $introws;
 
 533     qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
 
 535     qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
 
 537   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 540   if ($form->{taxaccounts}) {
 
 542                 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
 
 543       . $locale->text('Tax Included') . qq|</b><br><br>|;
 
 546   if (!$form->{taxincluded}) {
 
 548     foreach $item (split / /, $form->{taxaccounts}) {
 
 549       if ($form->{"${item}_base"}) {
 
 550         $form->{"${item}_total"} =
 
 552                              $form->{"${item}_base"} * $form->{"${item}_rate"},
 
 554         $form->{invtotal} += $form->{"${item}_total"};
 
 555         $form->{"${item}_total"} =
 
 556           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 560                 <th align=right>$form->{"${item}_description"}</th>
 
 561                 <td align=right>$form->{"${item}_total"}</td>
 
 567     $form->{invsubtotal} =
 
 568       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
 
 572                 <th align=right>| . $locale->text('Subtotal') . qq|</th>
 
 573                 <td align=right>$form->{invsubtotal}</td>
 
 579   if ($form->{taxincluded}) {
 
 580     foreach $item (split / /, $form->{taxaccounts}) {
 
 581       if ($form->{"${item}_base"}) {
 
 582         $form->{"${item}_total"} =
 
 584                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
 
 585                               (1 + $form->{"${item}_rate"})
 
 588         $form->{"${item}_netto"} =
 
 590                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
 
 592         $form->{"${item}_total"} =
 
 593           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 594         $form->{"${item}_netto"} =
 
 595           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
 
 599                 <th align=right>Enthaltene $form->{"${item}_description"}</th>
 
 600                 <td align=right>$form->{"${item}_total"}</td>
 
 603                 <th align=right>Nettobetrag</th>
 
 604                 <td align=right>$form->{"${item}_netto"}</td>
 
 612   $form->{oldinvtotal} = $form->{invtotal};
 
 614     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
 
 624                 <th align=left>| . $locale->text('Notes') . qq|</th>
 
 625                 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
 
 633           <td align=right width=100%>
 
 639                 <th align=right>| . $locale->text('Total') . qq|</th>
 
 640                 <td align=right>$form->{invtotal}</td>
 
 652     <td><hr size=3 noshade></td>
 
 655     <th class=listtop align=left>Dokumente im Webdav-Repository</th>
 
 658       <td align=left width=30%><b>Dateiname</b></td>
 
 659       <td align=left width=70%><b>Webdavlink</b></td>
 
 661     foreach $file (keys %{ $form->{WEBDAV} }) {
 
 664         <td align=left>$file</td>
 
 665         <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
 
 680         <tr class=listheading>
 
 681           <th colspan=6 class=listheading>|
 
 682     . $locale->text('Incoming Payments') . qq|</th>
 
 686   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 687     @column_index = qw(datepaid source memo paid AR_paid);
 
 689     @column_index = qw(datepaid source memo paid exchangerate AR_paid);
 
 692   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 693   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 694   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 695   $column_data{AR_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 696   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 697   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 702   map { print "$column_data{$_}\n" } @column_index;
 
 707   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 708   for $i (1 .. $form->{paidaccounts}) {
 
 713     $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
 
 714     $form->{"selectAR_paid_$i"} =~
 
 715       s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
 
 718     $totalpaid += $form->{"paid_$i"};
 
 720       $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 721     $form->{"exchangerate_$i"} =
 
 722       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 724     $exchangerate = qq| |;
 
 725     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 726       if ($form->{"forex_$i"}) {
 
 728           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 731           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 736 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 739     $column_data{"paid_$i"} =
 
 740       qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
 
 741     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
 742     $column_data{"AR_paid_$i"}      =
 
 743       qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
 
 744     $column_data{"datepaid_$i"} =
 
 745       qq|<td align=center><input name="datepaid_$i"  size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
 
 746     $column_data{"source_$i"} =
 
 747       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
 748     $column_data{"memo_$i"} =
 
 749       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
 751     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
 757 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 758 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
 
 759 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 760 <input type=hidden name=oldtotalpaid value=$totalpaid>
 
 761 <input type=hidden name=print_and_post value=$form->{print_and_post}>
 
 762 <input type=hidden name=second_run value=$form->{second_run}>
 
 767     <td><hr size=3 noshade></td>
 
 781   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
 782   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
 786     <input class=submit type=submit name=action value="|
 
 787       . $locale->text('Update') . qq|">
 
 788     <input class=submit type=submit name=action value="|
 
 789       . $locale->text('Ship to') . qq|">
 
 790     <input class=submit type=submit name=action value="|
 
 791       . $locale->text('Print') . qq|">
 
 792     <input class=submit type=submit name=action value="|
 
 793       . $locale->text('E-mail') . qq|">
 
 796     if (!$form->{revtrans}) {
 
 797       if (!$form->{locked}) {
 
 799         <input class=submit type=submit name=action value="|
 
 800           . $locale->text('Post') . qq|">
 
 801         <input class=submit type=submit name=action value="|
 
 802           . $locale->text('Delete') . qq|">
 
 807     if ($invdate > $closedto) {
 
 809       <input class=submit type=submit name=action value="|
 
 810         . $locale->text('Post as new') . qq|">
 
 811       <input class=submit type=submit name=action value="|
 
 812         . $locale->text('Order') . qq|">
 
 817     if ($invdate > $closedto) {
 
 818       print qq|<input class=submit type=submit name=action value="|
 
 819         . $locale->text('Update') . qq|">
 
 820       <input class=submit type=submit name=action value="|
 
 821         . $locale->text('Ship to') . qq|">
 
 822       <input class=submit type=submit name=action value="|
 
 823         . $locale->text('Preview') . qq|">
 
 824       <input class=submit type=submit name=action value="|
 
 825         . $locale->text('E-mail') . qq|">
 
 826       <input class=submit type=submit name=action value="|
 
 827         . $locale->text('Print and Post') . qq|">
 
 828       <input class=submit type=submit name=action value="|
 
 829         . $locale->text('Post') . qq|">|;
 
 833   if ($form->{menubar}) {
 
 834     require "$form->{path}/menu.pl";
 
 840 <input type=hidden name=rowcount value=$form->{rowcount}>
 
 842 <input name=callback type=hidden value="$form->{callback}">
 
 844 <input type=hidden name=path value=$form->{path}>
 
 845 <input type=hidden name=login value=$form->{login}>
 
 846 <input type=hidden name=password value=$form->{password}>
 
 855   $lxdebug->leave_sub();
 
 859   $lxdebug->enter_sub();
 
 861   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 862     qw(exchangerate creditlimit creditremaining);
 
 863   if ($form->{second_run}) {
 
 864     $form->{print_and_post} = 0;
 
 866   &check_name(customer);
 
 870   $form->{exchangerate} = $exchangerate
 
 874                          $form->check_exchangerate(
 
 875                          \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
 
 878   for $i (1 .. $form->{paidaccounts}) {
 
 879     if ($form->{"paid_$i"}) {
 
 882           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 883       } qw(paid exchangerate);
 
 885       $form->{"exchangerate_$i"} = $exchangerate
 
 887             $form->{"forex_$i"} = (
 
 889                    $form->check_exchangerate(
 
 890                    \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
 
 895   $i            = $form->{rowcount};
 
 896   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 898   # if last row empty, check the form otherwise retrieve new item
 
 899   if (   ($form->{"partnumber_$i"} eq "")
 
 900       && ($form->{"description_$i"} eq "")
 
 901       && ($form->{"partsgroup_$i"}  eq "")) {
 
 903     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
 908     IS->retrieve_item(\%myconfig, \%$form);
 
 910     $rows = scalar @{ $form->{item_list} };
 
 912     $form->{"discount_$i"} =
 
 913       $form->format_amount(\%myconfig, $form->{discount} * 100);
 
 916       $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
 
 925         $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
 
 926 #print STDERR " SELLPRICE-111- $sellprice\n";
 
 927         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
 
 928           qw(partnumber description unit);
 
 929         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
 
 930           keys %{ $form->{item_list}[0] };
 
 932         $form->{"discount_$i"} = $form->{discount} * 100;
 
 934         $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
 
 935         ($dec) = ($s =~ /\.(\d+)/);
 
 937         $decimalplaces = ($dec > 2) ? $dec : 2;
 
 940           $form->{"sellprice_$i"} = $sellprice;
 
 943           # if there is an exchange rate adjust sellprice
 
 944           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
 
 945           $form->{"sellprice_$i"} /= $exchangerate;
 
 948         $form->{"listprice_$i"} /= $exchangerate;
 
 951           $form->{"sellprice_$i"} * $form->{"qty_$i"} *
 
 952           (1 - $form->{"discount_$i"} / 100);
 
 953         map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
 
 954         map { $form->{"${_}_base"} += $amount }
 
 955           (split / /, $form->{"taxaccounts_$i"});
 
 956         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
 957           split / /, $form->{"taxaccounts_$i"}
 
 958           if !$form->{taxincluded};
 
 960         $form->{creditremaining} -= $amount;
 
 964             $form->format_amount(\%myconfig, $form->{"${_}_$i"},
 
 966         } qw(sellprice listprice);
 
 969           $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
 972           if ($form->{"inventory_accno_$i"} ne "") {
 
 973             $form->{"lizenzen_$i"} = qq|<option></option>|;
 
 974             foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
 
 975               $form->{"lizenzen_$i"} .=
 
 976                 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
 
 978             $form->{"lizenzen_$i"} .=
 
 979               qq|<option value=-1>Neue Lizenz</option>|;
 
 983         # get pricegroups for parts
 
 984         IS->get_pricegroups_for_parts(\%myconfig, \%$form, "new");
 
 986         # build up html code for prices_$i
 
 994       # ok, so this is a new part
 
 995       # ask if it is a part or service item
 
 997       if (   $form->{"partsgroup_$i"}
 
 998           && ($form->{"partsnumber_$i"} eq "")
 
 999           && ($form->{"description_$i"} eq "")) {
 
1000         $form->{rowcount}--;
 
1001         $form->{"discount_$i"} = "";
 
1005         $form->{"id_$i"}   = 0;
 
1006         $form->{"unit_$i"} = $locale->text('ea');
 
1013   $lxdebug->leave_sub();
 
1017   $lxdebug->enter_sub();
 
1018   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
 
1019   $form->isblank("customer", $locale->text('Customer missing!'));
 
1021   # if oldcustomer ne customer redo form
 
1022   if (&check_name(customer)) {
 
1026   if ($form->{second_run}) {
 
1027     $form->{print_and_post} = 0;
 
1032   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1033   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1035   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
1036     if ($invdate <= $closedto);
 
1038   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1039     if ($form->{currency} ne $form->{defaultcurrency});
 
1041   for $i (1 .. $form->{paidaccounts}) {
 
1042     if ($form->{"paid_$i"}) {
 
1043       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1045       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1047       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1048         if ($datepaid <= $closedto);
 
1050       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1051         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1052           if ($invdate == $datepaid);
 
1053         $form->isblank("exchangerate_$i",
 
1054                        $locale->text('Exchangerate for payment missing!'));
 
1059   ($form->{AR})      = split /--/, $form->{AR};
 
1060   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
1062   $form->{label} = $locale->text('Invoice');
 
1064   $form->{id} = 0 if $form->{postasnew};
 
1066   $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
 
1067     unless $form->{invnumber};
 
1069     if (!(IS->post_invoice(\%myconfig, \%$form))) {
 
1070       $form->error($locale->text('Cannot post invoice!'));
 
1074             $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
 
1075       if (IS->post_invoice(\%myconfig, \%$form));
 
1076     $form->error($locale->text('Cannot post invoice!'));
 
1079   $lxdebug->leave_sub();
 
1082 sub print_and_post {
 
1083   $lxdebug->enter_sub();
 
1085   $old_form               = new Form;
 
1087   $form->{print_and_post} = 1;
 
1091   $lxdebug->leave_sub();
 
1096   $lxdebug->enter_sub();
 
1098   $form->{preview} = 1;
 
1099   $old_form = new Form;
 
1100   for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
1101   $old_form->{rowcount}++;
 
1103   &print_form($old_form);
 
1104   $lxdebug->leave_sub();
 
1109   $lxdebug->enter_sub();
 
1110   if ($form->{second_run}) {
 
1111     $form->{print_and_post} = 0;
 
1118 <form method=post action=$form->{script}>
 
1121   # delete action variable
 
1122   map { delete $form->{$_} } qw(action header);
 
1124   foreach $key (keys %$form) {
 
1125     $form->{$key} =~ s/\"/"/g;
 
1126     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1130 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1133     . $locale->text('Are you sure you want to delete Invoice Number')
 
1134     . qq| $form->{invnumber}
 
1138 <input name=action class=submit type=submit value="|
 
1139     . $locale->text('Yes') . qq|">
 
1143   $lxdebug->leave_sub();
 
1147   $lxdebug->enter_sub();
 
1149   $form->redirect($locale->text('Invoice deleted!'))
 
1150     if (IS->delete_invoice(\%myconfig, \%$form, $spool));
 
1151   $form->error($locale->text('Cannot delete invoice!'));
 
1153   $lxdebug->leave_sub();