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");
 
  62   $form->{format} ="pdf";
 
  66   $lxdebug->leave_sub();
 
  70   $lxdebug->enter_sub();
 
  72   $form->{title} = $locale->text('Edit Sales Invoice');
 
  74   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  76     $form->error("Access Denied");
 
  78   if ($form->{print_and_post}) {
 
  79     $form->{action}     = "print";
 
  80     $form->{resubmit} = 1;
 
  86   $lxdebug->leave_sub();
 
  90   $lxdebug->enter_sub();
 
  92   $form->{vc} = 'customer';
 
  95   $form->{webdav}   = $webdav;
 
  96   $form->{lizenzen} = $lizenzen;
 
  98   $form->create_links("AR", \%myconfig, "customer");
 
 100   if ($form->{all_customer}) {
 
 101     unless ($form->{customer_id}) {
 
 102       $form->{customer_id} = $form->{all_customer}->[0]->{id};
 
 105   $cp_id = $form->{cp_id};
 
 106   IS->get_customer(\%myconfig, \%$form);
 
 108   IS->retrieve_invoice(\%myconfig, \%$form);
 
 109   $form->{cp_id} = $cp_id;
 
 112   @curr = split /:/, $form->{currencies};
 
 114   $form->{defaultcurrency} = $curr[0];
 
 116   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 118   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
 120   if ($form->{all_customer}) {
 
 121     $form->{customer} = "$form->{customer}--$form->{customer_id}";
 
 122     map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
 
 123       (@{ $form->{all_customer} });
 
 127   if ($form->{all_departments}) {
 
 128     $form->{selectdepartment} = "<option>\n";
 
 129     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 132       $form->{selectdepartment} .=
 
 133         "<option>$_->{description}--$_->{id}\n"
 
 134     } (@{ $form->{all_departments} });
 
 137   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 140   if ($form->{all_employees}) {
 
 141     $form->{selectemployee} = "";
 
 142     map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
 
 143       (@{ $form->{all_employees} });
 
 147   $form->{forex} = $form->{exchangerate};
 
 148   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 150   foreach $key (keys %{ $form->{AR_links} }) {
 
 151     foreach $ref (@{ $form->{AR_links}{$key} }) {
 
 152       $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
 
 155     if ($key eq "AR_paid") {
 
 156       for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 157         $form->{"AR_paid_$i"} =
 
 158           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 161         $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
 
 162         $form->{"datepaid_$i"} =
 
 163           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 164         $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
 
 165           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 166         $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 167         $form->{"memo_$i"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 169         $form->{paidaccounts} = $i;
 
 173         "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
 
 178   $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
 
 180   $form->{AR} = $form->{AR_1} unless $form->{id};
 
 183     ($form->datetonum($form->{invdate}, \%myconfig) <=
 
 184      $form->datetonum($form->{closedto}, \%myconfig));
 
 186   $lxdebug->leave_sub();
 
 189 sub prepare_invoice {
 
 190   $lxdebug->enter_sub();
 
 192   $form->{type}     = "invoice";
 
 193   $form->{formname} = "invoice";
 
 194   $form->{media}    = "screen";
 
 198     map { $form->{$_} =~ s/\"/"/g }
 
 199       qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
 
 201     #     # get pricegroups for parts
 
 202     #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 204     foreach $ref (@{ $form->{invoice_details} }) {
 
 206       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
 207       $form->{"discount_$i"} =
 
 208         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
 
 209       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 211       $decimalplaces = ($dec > 2) ? $dec : 2;
 
 213       $form->{"sellprice_$i"} =
 
 214         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 217       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 218       $dec_qty = length $dec_qty;
 
 221         $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
 
 223       map { $form->{"${_}_$i"} =~ s/\"/"/g }
 
 224         qw(partnumber description unit partnotes);
 
 225       $form->{rowcount} = $i;
 
 229   $lxdebug->leave_sub();
 
 233   $lxdebug->enter_sub();
 
 235   # set option selected
 
 236   foreach $item (qw(AR customer currency department employee contact)) {
 
 237     $form->{"select$item"} =~ s/ selected//;
 
 238     $form->{"select$item"} =~
 
 239       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 243   if ($form->{all_contacts}) {
 
 245     $form->{selectcontact} = "";
 
 246     foreach $item (@{ $form->{all_contacts} }) {
 
 247       if ($form->{cp_id} == $item->{cp_id}) {
 
 248         $form->{selectcontact} .=
 
 249           "<option selected>$item->{cp_name}--$item->{cp_id}";
 
 251         $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
 
 256   #else {$form->{all_contacts} = 0;}
 
 258   $form->{exchangerate} =
 
 259     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 261   $form->{creditlimit} =
 
 262     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 263   $form->{creditremaining} =
 
 264     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 267   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 268     if ($form->{forex}) {
 
 271         . $locale->text('Exchangerate')
 
 272         . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
 
 276         . $locale->text('Exchangerate')
 
 277         . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
 
 281 <input type=hidden name=forex value=$form->{forex}>
 
 285     ($form->{selectcustomer})
 
 286     ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
 
 287     : qq|<input name=customer value="$form->{customer}" size=35>|;
 
 291     ($form->{selectcontact})
 
 292     ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
 
 293     : qq|<input name=contact value="$form->{contact}" size=35>|;
 
 297                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 298                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 299                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 302 | if $form->{selectdepartment};
 
 304   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 306   if ($form->{business}) {
 
 309                 <th align=right>| . $locale->text('Business') . qq|</th>
 
 310                 <td>$form->{business}</td>
 
 311                 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
 
 313       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
 
 319   $form->{fokus} = "invoice.customer";
 
 321   # use JavaScript Calendar or not
 
 322   $form->{jsscript} = $jscalendar;
 
 324   if ($form->{jsscript}) {
 
 326     # with JavaScript Calendar
 
 328        <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
 
 329        <td><input type=button name=invdate id="trigger1" value=|
 
 330       . $locale->text('button') . qq|></td>
 
 333        <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
 
 334        <td width="4"><input type=button name=duedate id="trigger2" value=|
 
 335       . $locale->text('button') . qq|></td></td>
 
 340       Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
 
 341                           "duedate", "BL", "trigger2");
 
 344     # without JavaScript Calendar
 
 346       qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
 
 348       qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
 
 350   if ($form->{resubmit} && ($form->{format} eq "html")) {
 
 351     $onload = qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
 
 352   } elsif($form->{resubmit}) {
 
 353     $onload = qq|document.invoice.submit()|;
 
 360 <body onLoad="$onload">
 
 362 <form method=post name="invoice" action=$form->{script}>
 
 365 <input type=hidden name=id value=$form->{id}>
 
 366 <input type=hidden name=action value=$form->{action}>
 
 368 <input type=hidden name=type value=$form->{type}>
 
 369 <input type=hidden name=media value=$form->{media}>
 
 370 <input type=hidden name=format value=$form->{format}>
 
 372 <input type=hidden name=queued value="$form->{queued}">
 
 373 <input type=hidden name=printed value="$form->{printed}">
 
 374 <input type=hidden name=emailed value="$form->{emailed}">
 
 376 <input type=hidden name=title value="$form->{title}">
 
 377 <input type=hidden name=vc value=$form->{vc}>
 
 379 <input type=hidden name=discount value=$form->{discount}>
 
 380 <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 381 <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 383 <input type=hidden name=tradediscount value=$form->{tradediscount}>
 
 384 <input type=hidden name=business value=$form->{business}>
 
 386 <input type=hidden name=closedto value=$form->{closedto}>
 
 387 <input type=hidden name=locked value=$form->{locked}>
 
 389 <input type=hidden name=shipped value=$form->{shipped}>
 
 390 <input type=hidden name=lizenzen value=$lizenzen>
 
 394     <th class=listtop>$form->{title}</th>
 
 404                 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
 
 405                 <td colspan=3>$customer</td>
 
 406     <input type=hidden name=customer_klass value=$form->{customer_klass}>
 
 407                 <input type=hidden name=customer_id value=$form->{customer_id}>
 
 408                 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
 
 409                 <th align=richt nowrap>|
 
 410     . $locale->text('Contact Person') . qq|</th>
 
 411                 <td colspan=3>$contact</td>
 
 418                       <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 419                       <td>$form->{creditlimit}</td>
 
 421                       <th nowrap>| . $locale->text('Remaining') . qq|</th>
 
 422                       <td class="plus$n">$form->{creditremaining}</td>
 
 429                 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
 
 430                 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
 
 431                 <input type=hidden name=selectAR value="$form->{selectAR}">
 
 435                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 436                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 437                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 438                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 439                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 440                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 444                 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
 
 445                 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
 
 448                 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
 
 449                 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
 
 456                 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
 
 457                 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
 
 458                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
 
 462                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 463                 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
 
 466                 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
 
 470                 <th align=right>| . $locale->text('Due Date') . qq|</th>
 
 474                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 475                 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
 
 478                 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
 
 479                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
 
 482                 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
 
 483                 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
 
 498 <!-- shipto are in hidden variables -->
 
 500 <input type=hidden name=shiptoname value="$form->{shiptoname}">
 
 501 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
 
 502 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
 
 503 <input type=hidden name=shiptocity value="$form->{shiptocity}">
 
 504 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
 
 505 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
 
 506 <input type=hidden name=shiptophone value="$form->{shiptophone}">
 
 507 <input type=hidden name=shiptofax value="$form->{shiptofax}">
 
 508 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
 
 510 <!-- email variables -->
 
 511 <input type=hidden name=message value="$form->{message}">
 
 512 <input type=hidden name=email value="$form->{email}">
 
 513 <input type=hidden name=subject value="$form->{subject}">
 
 514 <input type=hidden name=cc value="$form->{cc}">
 
 515 <input type=hidden name=bcc value="$form->{bcc}">
 
 516 <input type=hidden name=webdav value=$webdav>
 
 517 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 520   foreach $item (split / /, $form->{taxaccounts}) {
 
 522 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
 
 523 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
 
 524 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
 
 527   $lxdebug->leave_sub();
 
 531   $lxdebug->enter_sub();
 
 533   $form->{invtotal} = $form->{invsubtotal};
 
 535   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
 
 538   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
 
 541   $rows = ($rows > $introws) ? $rows : $introws;
 
 543     qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
 
 545     qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
 
 547   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 550   if ($form->{taxaccounts}) {
 
 552                 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
 
 553       . $locale->text('Tax Included') . qq|</b><br><br>|;
 
 556   if (!$form->{taxincluded}) {
 
 558     foreach $item (split / /, $form->{taxaccounts}) {
 
 559       if ($form->{"${item}_base"}) {
 
 560         $form->{"${item}_total"} =
 
 562                              $form->{"${item}_base"} * $form->{"${item}_rate"},
 
 564         $form->{invtotal} += $form->{"${item}_total"};
 
 565         $form->{"${item}_total"} =
 
 566           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 570                 <th align=right>$form->{"${item}_description"}</th>
 
 571                 <td align=right>$form->{"${item}_total"}</td>
 
 577     $form->{invsubtotal} =
 
 578       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
 
 582                 <th align=right>| . $locale->text('Subtotal') . qq|</th>
 
 583                 <td align=right>$form->{invsubtotal}</td>
 
 589   if ($form->{taxincluded}) {
 
 590     foreach $item (split / /, $form->{taxaccounts}) {
 
 591       if ($form->{"${item}_base"}) {
 
 592         $form->{"${item}_total"} =
 
 594                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
 
 595                               (1 + $form->{"${item}_rate"})
 
 598         $form->{"${item}_netto"} =
 
 600                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
 
 602         $form->{"${item}_total"} =
 
 603           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 604         $form->{"${item}_netto"} =
 
 605           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
 
 609                 <th align=right>Enthaltene $form->{"${item}_description"}</th>
 
 610                 <td align=right>$form->{"${item}_total"}</td>
 
 613                 <th align=right>Nettobetrag</th>
 
 614                 <td align=right>$form->{"${item}_netto"}</td>
 
 622   $form->{oldinvtotal} = $form->{invtotal};
 
 624     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
 
 634                 <th align=left>| . $locale->text('Notes') . qq|</th>
 
 635                 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
 
 643           <td align=right width=100%>
 
 649                 <th align=right>| . $locale->text('Total') . qq|</th>
 
 650                 <td align=right>$form->{invtotal}</td>
 
 662     <td><hr size=3 noshade></td>
 
 665     <th class=listtop align=left>Dokumente im Webdav-Repository</th>
 
 668       <td align=left width=30%><b>Dateiname</b></td>
 
 669       <td align=left width=70%><b>Webdavlink</b></td>
 
 671     foreach $file (keys %{ $form->{WEBDAV} }) {
 
 674         <td align=left>$file</td>
 
 675         <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
 
 690         <tr class=listheading>
 
 691           <th colspan=6 class=listheading>|
 
 692     . $locale->text('Incoming Payments') . qq|</th>
 
 696   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 697     @column_index = qw(datepaid source memo paid AR_paid);
 
 699     @column_index = qw(datepaid source memo paid exchangerate AR_paid);
 
 702   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 703   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 704   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 705   $column_data{AR_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 706   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 707   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 712   map { print "$column_data{$_}\n" } @column_index;
 
 717   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 718   for $i (1 .. $form->{paidaccounts}) {
 
 723     $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
 
 724     $form->{"selectAR_paid_$i"} =~
 
 725       s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
 
 728     $totalpaid += $form->{"paid_$i"};
 
 730       $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 731     $form->{"exchangerate_$i"} =
 
 732       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 734     $exchangerate = qq| |;
 
 735     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 736       if ($form->{"forex_$i"}) {
 
 738           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 741           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 746 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 749     $column_data{"paid_$i"} =
 
 750       qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
 
 751     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
 752     $column_data{"AR_paid_$i"}      =
 
 753       qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
 
 754     $column_data{"datepaid_$i"} =
 
 755       qq|<td align=center><input name="datepaid_$i"  size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
 
 756     $column_data{"source_$i"} =
 
 757       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
 758     $column_data{"memo_$i"} =
 
 759       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
 761     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
 767 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 768 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
 
 769 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 770 <input type=hidden name=oldtotalpaid value=$totalpaid>
 
 775     <td><hr size=3 noshade></td>
 
 789   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
 790   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
 794     <input class=submit type=submit name=action value="|
 
 795       . $locale->text('Update') . qq|">
 
 796     <input class=submit type=submit name=action value="|
 
 797       . $locale->text('Ship to') . qq|">
 
 798     <input class=submit type=submit name=action value="|
 
 799       . $locale->text('Print') . qq|">
 
 800     <input class=submit type=submit name=action value="|
 
 801       . $locale->text('E-mail') . qq|">
 
 804     if (!$form->{revtrans}) {
 
 805       if (!$form->{locked}) {
 
 807         <input class=submit type=submit name=action value="|
 
 808           . $locale->text('Post') . qq|">
 
 809         <input class=submit type=submit name=action value="|
 
 810           . $locale->text('Delete') . qq|">
 
 815     if ($invdate > $closedto) {
 
 817       <input class=submit type=submit name=action value="|
 
 818         . $locale->text('Post as new') . qq|">
 
 819       <input class=submit type=submit name=action value="|
 
 820         . $locale->text('Order') . qq|">
 
 825     if ($invdate > $closedto) {
 
 826       print qq|<input class=submit type=submit name=action value="|
 
 827         . $locale->text('Update') . qq|">
 
 828       <input class=submit type=submit name=action value="|
 
 829         . $locale->text('Ship to') . qq|">
 
 830       <input class=submit type=submit name=action value="|
 
 831         . $locale->text('Preview') . qq|">
 
 832       <input class=submit type=submit name=action value="|
 
 833         . $locale->text('E-mail') . qq|">
 
 834       <input class=submit type=submit name=action value="|
 
 835         . $locale->text('Print and Post') . qq|">
 
 836       <input class=submit type=submit name=action value="|
 
 837         . $locale->text('Post') . qq|">|;
 
 841   if ($form->{menubar}) {
 
 842     require "$form->{path}/menu.pl";
 
 848 <input type=hidden name=rowcount value=$form->{rowcount}>
 
 850 <input name=callback type=hidden value="$form->{callback}">
 
 852 <input type=hidden name=path value=$form->{path}>
 
 853 <input type=hidden name=login value=$form->{login}>
 
 854 <input type=hidden name=password value=$form->{password}>
 
 863   $lxdebug->leave_sub();
 
 867   $lxdebug->enter_sub();
 
 869   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 870     qw(exchangerate creditlimit creditremaining);
 
 871   if ($form->{second_run}) {
 
 872     $form->{print_and_post} = 0;
 
 874   &check_name(customer);
 
 878   $form->{exchangerate} = $exchangerate
 
 882                          $form->check_exchangerate(
 
 883                          \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
 
 886   for $i (1 .. $form->{paidaccounts}) {
 
 887     if ($form->{"paid_$i"}) {
 
 890           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 891       } qw(paid exchangerate);
 
 893       $form->{"exchangerate_$i"} = $exchangerate
 
 895             $form->{"forex_$i"} = (
 
 897                    $form->check_exchangerate(
 
 898                    \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
 
 903   $i            = $form->{rowcount};
 
 904   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 906   # if last row empty, check the form otherwise retrieve new item
 
 907   if (   ($form->{"partnumber_$i"} eq "")
 
 908       && ($form->{"description_$i"} eq "")
 
 909       && ($form->{"partsgroup_$i"}  eq "")) {
 
 911     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
 916     IS->retrieve_item(\%myconfig, \%$form);
 
 918     $rows = scalar @{ $form->{item_list} };
 
 920     $form->{"discount_$i"} =
 
 921       $form->format_amount(\%myconfig, $form->{discount} * 100);
 
 924       $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
 
 933         $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
 
 935         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
 
 936           qw(partnumber description unit);
 
 937         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
 
 938           keys %{ $form->{item_list}[0] };
 
 940         $form->{"discount_$i"} = $form->{discount} * 100;
 
 942         $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
 
 943         ($dec) = ($s =~ /\.(\d+)/);
 
 945         $decimalplaces = ($dec > 2) ? $dec : 2;
 
 948           $form->{"sellprice_$i"} = $sellprice;
 
 951           # if there is an exchange rate adjust sellprice
 
 952           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
 
 953           $form->{"sellprice_$i"} /= $exchangerate;
 
 956         $form->{"listprice_$i"} /= $exchangerate;
 
 959           $form->{"sellprice_$i"} * $form->{"qty_$i"} *
 
 960           (1 - $form->{"discount_$i"} / 100);
 
 961         map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
 
 962         map { $form->{"${_}_base"} += $amount }
 
 963           (split / /, $form->{"taxaccounts_$i"});
 
 964         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
 965           split / /, $form->{"taxaccounts_$i"}
 
 966           if !$form->{taxincluded};
 
 968         $form->{creditremaining} -= $amount;
 
 972             $form->format_amount(\%myconfig, $form->{"${_}_$i"},
 
 974         } qw(sellprice listprice);
 
 977           $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
 980           if ($form->{"inventory_accno_$i"} ne "") {
 
 981             $form->{"lizenzen_$i"} = qq|<option></option>|;
 
 982             foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
 
 983               $form->{"lizenzen_$i"} .=
 
 984                 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
 
 986             $form->{"lizenzen_$i"} .=
 
 987               qq|<option value=-1>Neue Lizenz</option>|;
 
 991         # get pricegroups for parts
 
 992         IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 994         # build up html code for prices_$i
 
1002       # ok, so this is a new part
 
1003       # ask if it is a part or service item
 
1005       if (   $form->{"partsgroup_$i"}
 
1006           && ($form->{"partsnumber_$i"} eq "")
 
1007           && ($form->{"description_$i"} eq "")) {
 
1008         $form->{rowcount}--;
 
1009         $form->{"discount_$i"} = "";
 
1013         $form->{"id_$i"}   = 0;
 
1014         $form->{"unit_$i"} = $locale->text('ea');
 
1021   $lxdebug->leave_sub();
 
1025   $lxdebug->enter_sub();
 
1026   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
 
1027   $form->isblank("customer", $locale->text('Customer missing!'));
 
1029   # if oldcustomer ne customer redo form
 
1030   if (&check_name(customer)) {
 
1034   if ($form->{second_run}) {
 
1035     $form->{print_and_post} = 0;
 
1040   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1041   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1043   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
1044     if ($invdate <= $closedto);
 
1046   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1047     if ($form->{currency} ne $form->{defaultcurrency});
 
1049   for $i (1 .. $form->{paidaccounts}) {
 
1050     if ($form->{"paid_$i"}) {
 
1051       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1053       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1055       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1056         if ($datepaid <= $closedto);
 
1058       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1059         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1060           if ($invdate == $datepaid);
 
1061         $form->isblank("exchangerate_$i",
 
1062                        $locale->text('Exchangerate for payment missing!'));
 
1067   ($form->{AR})      = split /--/, $form->{AR};
 
1068   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
1070   $form->{label} = $locale->text('Invoice');
 
1072   $form->{id} = 0 if $form->{postasnew};
 
1074   # get new invnumber in sequence if no invnumber is given or if posasnew was requested
 
1075   if (!$form->{invnumber} || $form->{postasnew}) {
 
1076     $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
 
1079     if (!(IS->post_invoice(\%myconfig, \%$form))) {
 
1080       $form->error($locale->text('Cannot post invoice!'));
 
1084             $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
 
1085       if (IS->post_invoice(\%myconfig, \%$form));
 
1086     $form->error($locale->text('Cannot post invoice!'));
 
1089   $lxdebug->leave_sub();
 
1092 sub print_and_post {
 
1093   $lxdebug->enter_sub();
 
1095   $old_form               = new Form;
 
1097   $form->{print_and_post} = 1;
 
1101   $lxdebug->leave_sub();
 
1106   $lxdebug->enter_sub();
 
1108   $form->{preview} = 1;
 
1109   $old_form = new Form;
 
1110   for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
1111   $old_form->{rowcount}++;
 
1113   &print_form($old_form);
 
1114   $lxdebug->leave_sub();
 
1119   $lxdebug->enter_sub();
 
1120   if ($form->{second_run}) {
 
1121     $form->{print_and_post} = 0;
 
1128 <form method=post action=$form->{script}>
 
1131   # delete action variable
 
1132   map { delete $form->{$_} } qw(action header);
 
1134   foreach $key (keys %$form) {
 
1135     $form->{$key} =~ s/\"/"/g;
 
1136     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1140 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1143     . $locale->text('Are you sure you want to delete Invoice Number')
 
1144     . qq| $form->{invnumber}
 
1148 <input name=action class=submit type=submit value="|
 
1149     . $locale->text('Yes') . qq|">
 
1153   $lxdebug->leave_sub();
 
1157   $lxdebug->enter_sub();
 
1159   $form->redirect($locale->text('Invoice deleted!'))
 
1160     if (IS->delete_invoice(\%myconfig, \%$form, $spool));
 
1161   $form->error($locale->text('Cannot delete invoice!'));
 
1163   $lxdebug->leave_sub();