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";
 
  40 require "bin/mozilla/drafts.pl";
 
  47   $lxdebug->enter_sub();
 
  49   return $lxdebug->leave_sub() if (load_draft_maybe());
 
  51   if ($form->{type} eq "credit_note") {
 
  52     $form->{title} = $locale->text('Add Credit Note');
 
  54     if ($form->{storno}) {
 
  55       $form->{title} = $locale->text('Add Storno Credit Note');
 
  58     $form->{title} = $locale->text('Add Sales Invoice');
 
  64     "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
 
  65     unless $form->{callback};
 
  67   $form{jsscript} = "date";
 
  69   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  71     $form->error("Access Denied");
 
  77   $lxdebug->leave_sub();
 
  81   $lxdebug->enter_sub();
 
  84   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
  85   #/show hhistory button
 
  87   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  89     $form->error("Access Denied");
 
  92   if ($form->{print_and_post}) {
 
  93     $form->{action}   = "print";
 
  94     $form->{resubmit} = 1;
 
  95     $language_id = $form->{language_id};
 
  96     $printer_id = $form->{printer_id};
 
 100   if ($form->{print_and_post}) {
 
 101     $form->{language_id} = $language_id;
 
 102     $form->{printer_id} = $printer_id;
 
 107   $lxdebug->leave_sub();
 
 111   $lxdebug->enter_sub();
 
 113   $form->{vc} = 'customer';
 
 116   $form->{webdav}   = $webdav;
 
 117   $form->{lizenzen} = $lizenzen;
 
 119   $form->create_links("AR", \%myconfig, "customer");
 
 121   if ($form->{all_customer}) {
 
 122     unless ($form->{customer_id}) {
 
 123       $form->{customer_id} = $form->{all_customer}->[0]->{id};
 
 127   if ($form->{payment_id}) {
 
 128     $payment_id = $form->{payment_id};
 
 130   if ($form->{language_id}) {
 
 131     $language_id = $form->{language_id};
 
 133   if ($form->{taxzone_id}) {
 
 134     $taxzone_id = $form->{taxzone_id};
 
 139   if ($form->{shipto_id}) {
 
 140     $shipto_id = $form->{shipto_id};
 
 143   $cp_id = $form->{cp_id};
 
 144   IS->get_customer(\%myconfig, \%$form);
 
 146   #quote all_customer Bug 133
 
 147   foreach $ref (@{ $form->{all_customer} }) {
 
 148     $ref->{name} = $form->quote($ref->{name});
 
 153   IS->retrieve_invoice(\%myconfig, \%$form);
 
 154   $form->{cp_id} = $cp_id;
 
 157     $form->{payment_id} = $payment_id;
 
 160     $form->{language_id} = $language_id;
 
 163     $form->{taxzone_id} = $taxzone_id;
 
 166     $form->{shipto_id} = $shipto_id;
 
 170   @curr = split(/:/, $form->{currencies});
 
 172   $form->{defaultcurrency} = $curr[0];
 
 174   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 176   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
 178   if (@{ $form->{all_customer} }) {
 
 179     $form->{customer} = "$form->{customer}--$form->{customer_id}";
 
 180     map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
 
 181       (@{ $form->{all_customer} });
 
 185   if ($form->{all_departments}) {
 
 186     $form->{selectdepartment} = "<option>\n";
 
 187     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 190       $form->{selectdepartment} .=
 
 191         "<option>$_->{description}--$_->{id}\n"
 
 192     } (@{ $form->{all_departments} });
 
 195   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 198   if ($form->{all_employees}) {
 
 199     $form->{selectemployee} = "";
 
 200     map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
 
 201       (@{ $form->{all_employees} });
 
 205   $form->{forex} = $form->{exchangerate};
 
 206   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 208   foreach $key (keys %{ $form->{AR_links} }) {
 
 209     foreach $ref (@{ $form->{AR_links}{$key} }) {
 
 210       $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
 
 213     if ($key eq "AR_paid") {
 
 214       for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 215         $form->{"AR_paid_$i"} =
 
 216           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 219         $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
 
 220         $form->{"datepaid_$i"} =
 
 221           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 222         $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
 
 223           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 224         $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 225         $form->{"memo_$i"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 227         $form->{paidaccounts} = $i;
 
 231         "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
 
 236   $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
 
 238   $form->{AR} = $form->{AR_1} unless $form->{id};
 
 241     ($form->datetonum($form->{invdate}, \%myconfig) <=
 
 242      $form->datetonum($form->{closedto}, \%myconfig));
 
 244   $lxdebug->leave_sub();
 
 247 sub prepare_invoice {
 
 248   $lxdebug->enter_sub();
 
 250   if ($form->{type} eq "credit_note") {
 
 251     $form->{type}     = "credit_note";
 
 252     $form->{formname} = "credit_note";
 
 254     $form->{type}     = "invoice";
 
 255     $form->{formname} = "invoice";
 
 260     map { $form->{$_} =~ s/\"/"/g }
 
 261       qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
 
 263     #     # get pricegroups for parts
 
 264     #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 268     foreach $ref (@{ $form->{invoice_details} }) {
 
 271       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
 272       $form->{"discount_$i"} =
 
 273         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
 
 274       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 276       $decimalplaces = ($dec > 2) ? $dec : 2;
 
 278       $form->{"sellprice_$i"} =
 
 279         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 282       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 283       $dec_qty = length $dec_qty;
 
 286         $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
 
 288       map { $form->{"${_}_$i"} =~ s/\"/"/g }
 
 289         qw(partnumber description unit partnotes);
 
 290       $form->{rowcount} = $i;
 
 294   $lxdebug->leave_sub();
 
 298   $lxdebug->enter_sub();
 
 302     if ($form->{type} eq "credit_note") {
 
 303       $form->{title} = $locale->text('Edit Credit Note');
 
 305       if ($form->{storno}) {
 
 306         $form->{title} = $locale->text('Edit Storno Credit Note');
 
 309       $form->{title} = $locale->text('Edit Sales Invoice');
 
 311       if ($form->{storno}) {
 
 312         $form->{title} = $locale->text('Edit Storno Invoice');
 
 318     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 320   $payment = qq|<option value=""></option>|;
 
 321   foreach $item (@{ $form->{payment_terms} }) {
 
 322     if ($form->{payment_id} eq $item->{id}) {
 
 323       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
 
 325       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
 
 329   my $set_duedate_url =
 
 330     "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
 
 332   my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
 
 333   push(@ { $form->{AJAX} }, $pjx);
 
 335   if (@{ $form->{TAXZONE} }) {
 
 336     $form->{selecttaxzone} = "";
 
 337     foreach $item (@{ $form->{TAXZONE} }) {
 
 338       if ($item->{id} == $form->{taxzone_id}) {
 
 339         $form->{selecttaxzone} .=
 
 340           "<option value=$item->{id} selected>" . H($item->{description}) .
 
 343         $form->{selecttaxzone} .=
 
 344           "<option value=$item->{id}>" . H($item->{description}) . "</option>";
 
 349     $form->{selecttaxzone} =~ s/ selected//g;
 
 350     if ($form->{taxzone_id} ne "") {
 
 351       $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
 
 357                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
 
 358                 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
 
 359                 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
 
 362   my @old_project_ids = ($form->{"globalproject_id"});
 
 363   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
 364           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
 366   $form->get_lists("contacts" => "ALL_CONTACTS",
 
 367                    "shipto" => "ALL_SHIPTO",
 
 368                    "projects" => { "key" => "ALL_PROJECTS",
 
 370                                    "old_id" => \@old_project_ids });
 
 372   my (%labels, @values);
 
 373   foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
 
 374     push(@values, $item->{"cp_id"});
 
 375     $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
 
 376       ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
 
 379     NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
 
 380                          '-labels' => \%labels, '-default' => $form->{"cp_id"}));
 
 384   foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
 
 385     push(@values, $item->{"shipto_id"});
 
 386     $labels{$item->{"shipto_id"}} =
 
 387       $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
 
 391                 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
 
 393     NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
 
 394                          '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
 
 399   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 400     push(@values, $item->{"id"});
 
 401     $labels{$item->{"id"}} = $item->{"projectnumber"};
 
 403   my $globalprojectnumber =
 
 404     NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
 
 405                          '-labels' => \%labels,
 
 406                          '-default' => $form->{"globalproject_id"}));
 
 408   # set option selected
 
 409   foreach $item (qw(AR customer currency department employee)) {
 
 410     $form->{"select$item"} =~ s/ selected//;
 
 411     $form->{"select$item"} =~
 
 412       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 415   #quote customer Bug 133
 
 416   $form->{selectcustomer} = $form->quote($form->{selectcustomer});
 
 418   if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
 
 424   $form->{exchangerate} =
 
 425     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 427   $form->{creditlimit} =
 
 428     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 429   $form->{creditremaining} =
 
 430     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 433   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 434     if ($form->{forex}) {
 
 437         . $locale->text('Exchangerate')
 
 438         . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
 
 442         . $locale->text('Exchangerate')
 
 443         . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
 
 447 <input type=hidden name=forex value=$form->{forex}>
 
 451     ($form->{selectcustomer})
 
 452     ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
 
 453     : qq|<input name=customer value="$form->{customer}" size=35>|;
 
 457                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 458                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 459                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 462 | if $form->{selectdepartment};
 
 464   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 466   if ($form->{business}) {
 
 469                 <th align=right>| . $locale->text('Business') . qq|</th>
 
 470                 <td>$form->{business}</td>
 
 471                 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
 
 473       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
 
 479   if ($form->{max_dunning_level}) {
 
 485                 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
 
 486                 <td><b>$form->{max_dunning_level}</b></td>
 
 487                 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
 
 489       . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
 
 498   $form->{fokus} = "invoice.customer";
 
 500   # use JavaScript Calendar or not
 
 501   $form->{jsscript} = $jscalendar;
 
 503   if ($form->{type} eq "credit_note") {
 
 504     if ($form->{jsscript}) {
 
 506       # with JavaScript Calendar
 
 508         <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
 
 509         <td><input type=button name=invdate id="trigger1" value=|
 
 510         . $locale->text('button') . qq|></td>
 
 515         Form->write_trigger(\%myconfig,     "1",
 
 520       # without JavaScript Calendar
 
 522         qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
 
 524         qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
 
 527     if ($form->{jsscript}) {
 
 529       # with JavaScript Calendar
 
 531         <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
 
 532         <td><input type=button name=invdate id="trigger1" value=|
 
 533         . $locale->text('button') . qq|></td>
 
 536         <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
 
 537         <td width="4"><input type=button name=duedate id="trigger2" value=|
 
 538         . $locale->text('button') . qq|></td></td>
 
 541         <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
 
 542         <td width="4"><input type=button name=deliverydate id="trigger3" value=|
 
 543         . $locale->text('button') . qq|></td></td>
 
 548         Form->write_trigger(\%myconfig,     "3",
 
 550                             "trigger1",     "duedate",
 
 552                             "deliverydate", "BL",
 
 556       # without JavaScript Calendar
 
 558         qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
 
 560         qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
 
 563   if ($form->{resubmit} && ($form->{format} eq "html")) {
 
 565       qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
 
 566   } elsif ($form->{resubmit}) {
 
 567     $onload = qq|document.invoice.submit()|;
 
 572   $credittext = $locale->text('Credit Limit exceeded!!!');
 
 573   if ($creditwarning) {
 
 574     $onload = qq|alert('$credittext')|;
 
 577   $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
 
 580     $form->write_trigger(\%myconfig, 2,
 
 581                          "orddate", "BL", "trigger_orddate",
 
 582                          "quodate", "BL", "trigger_quodate");
 
 583   # show history button js
 
 584   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 585   #/show history button js
 
 589 <body onLoad="$onload">
 
 590 <script type="text/javascript" src="js/common.js"></script>
 
 591 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
 
 592 <script type="text/javascript" src="js/vendor_selection.js"></script>
 
 593 <script type="text/javascript" src="js/calculate_qty.js"></script>
 
 595 <form method=post name="invoice" action=$form->{script}>
 
 598 <input type=hidden name=id value=$form->{id}>
 
 599 <input type=hidden name=action value=$form->{action}>
 
 601 <input type=hidden name=type value=$form->{type}>
 
 602 <input type=hidden name=media value=$form->{media}>
 
 603 <input type=hidden name=format value=$form->{format}>
 
 605 <input type=hidden name=queued value="$form->{queued}">
 
 606 <input type=hidden name=printed value="$form->{printed}">
 
 607 <input type=hidden name=emailed value="$form->{emailed}">
 
 609 <input type=hidden name=title value="$form->{title}">
 
 610 <input type=hidden name=vc value=$form->{vc}>
 
 612 <input type=hidden name=discount value=$form->{discount}>
 
 613 <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 614 <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 616 <input type=hidden name=tradediscount value=$form->{tradediscount}>
 
 617 <input type=hidden name=business value=$form->{business}>
 
 619 <input type=hidden name=closedto value=$form->{closedto}>
 
 620 <input type=hidden name=locked value=$form->{locked}>
 
 622 <input type=hidden name=shipped value=$form->{shipped}>
 
 623 <input type=hidden name=lizenzen value=$lizenzen>
 
 624 <input type=hidden name=storno value=$form->{storno}>
 
 625 <input type=hidden name=storno_id value=$form->{storno_id}>
 
 627 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
 
 631     <th class=listtop>$form->{title}</th>
 
 641                 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
 
 642                 <td colspan=3>$customer</td>
 
 643     <input type=hidden name=customer_klass value=$form->{customer_klass}>
 
 644                 <input type=hidden name=customer_id value=$form->{customer_id}>
 
 645                 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
 
 646                 <th align=richt nowrap>|
 
 647     . $locale->text('Contact Person') . qq|</th>
 
 648                 <td colspan=3>$contact</td>
 
 655                       <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 656                       <td>$form->{creditlimit}</td>
 
 658                       <th nowrap>| . $locale->text('Remaining') . qq|</th>
 
 659                       <td class="plus$n">$form->{creditremaining}</td>
 
 668                 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
 
 669                 <td colspan=3><select name=AR style="width:280px;">$form->{selectAR}</select></td>
 
 670                 <input type=hidden name=selectAR value="$form->{selectAR}">
 
 675                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
 
 676                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 677                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 678                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 679                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 680                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 684                 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
 
 685                 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
 
 688                 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
 
 689                 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
 
 696 #                         <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
 
 698 #                       <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
 
 699 #                       <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
 
 703 #                         <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
 
 705 #                       <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
 
 706 #                       <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
 
 716                 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
 
 717                 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
 
 718                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
 
 721 if ($form->{type} eq "credit_note") {
 
 723                 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
 
 724                 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
 
 727                 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
 
 732                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 733                 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
 
 736                 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
 
 740                 <th align=right>| . $locale->text('Due Date') . qq|</th>
 
 744                 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
 
 749                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 750                 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
 
 753           <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
 
 754           <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
 
 755           <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
 
 758                 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
 
 759                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
 
 762           <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
 
 763           <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
 
 764           <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
 
 767                 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
 
 768                 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
 
 771           <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
 
 772           <td>$globalprojectnumber</td>
 
 787 <!-- shipto are in hidden variables -->
 
 789 <input type=hidden name=shiptoname value="$form->{shiptoname}">
 
 790 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
 
 791 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
 
 792 <input type=hidden name=shiptocity value="$form->{shiptocity}">
 
 793 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
 
 794 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
 
 795 <input type=hidden name=shiptophone value="$form->{shiptophone}">
 
 796 <input type=hidden name=shiptofax value="$form->{shiptofax}">
 
 797 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
 
 799 <!-- email variables -->
 
 800 <input type=hidden name=message value="$form->{message}">
 
 801 <input type=hidden name=email value="$form->{email}">
 
 802 <input type=hidden name=subject value="$form->{subject}">
 
 803 <input type=hidden name=cc value="$form->{cc}">
 
 804 <input type=hidden name=bcc value="$form->{bcc}">
 
 805 <input type=hidden name=webdav value=$webdav>
 
 806 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 809   foreach $item (split / /, $form->{taxaccounts}) {
 
 811 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
 
 812 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
 
 813 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
 
 816   $lxdebug->leave_sub();
 
 820   $lxdebug->enter_sub();
 
 822   $form->{invtotal} = $form->{invsubtotal};
 
 824   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
 
 827   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
 
 830   $rows = ($rows > $introws) ? $rows : $introws;
 
 832     qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
 
 834     qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
 
 836   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 839   if ($form->{taxaccounts}) {
 
 841                 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
 
 842       . $locale->text('Tax Included') . qq|</b><br><br>|;
 
 845   if (!$form->{taxincluded}) {
 
 847     foreach $item (split / /, $form->{taxaccounts}) {
 
 848       if ($form->{"${item}_base"}) {
 
 849         $form->{"${item}_total"} =
 
 851                              $form->{"${item}_base"} * $form->{"${item}_rate"},
 
 853         $form->{invtotal} += $form->{"${item}_total"};
 
 854         $form->{"${item}_total"} =
 
 855           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 859                 <th align=right>$form->{"${item}_description"} |
 
 860                 . $form->{"${item}_rate"} * 100 .qq|%</th>
 
 861                 <td align=right>$form->{"${item}_total"}</td>
 
 867     $form->{invsubtotal} =
 
 868       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
 
 872                 <th align=right>| . $locale->text('Subtotal') . qq|</th>
 
 873                 <td align=right>$form->{invsubtotal}</td>
 
 879   if ($form->{taxincluded}) {
 
 880     foreach $item (split / /, $form->{taxaccounts}) {
 
 881       if ($form->{"${item}_base"}) {
 
 882         $form->{"${item}_total"} =
 
 884                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
 
 885                               (1 + $form->{"${item}_rate"})
 
 888         $form->{"${item}_netto"} =
 
 890                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
 
 892         $form->{"${item}_total"} =
 
 893           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 894         $form->{"${item}_netto"} =
 
 895           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
 
 899                 <th align=right>Enthaltene $form->{"${item}_description"} |
 
 900                   . $form->{"${item}_rate"} * 100 .qq|%</th>
 
 901                 <td align=right>$form->{"${item}_total"}</td>
 
 904                 <th align=right>Nettobetrag</th>
 
 905                 <td align=right>$form->{"${item}_netto"}</td>
 
 913   $form->{oldinvtotal} = $form->{invtotal};
 
 915     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
 
 925                 <th align=left>| . $locale->text('Notes') . qq|</th>
 
 926                 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
 
 927                 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
 
 932                 <td><select name=payment_id onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
 
 937           <td align=right width=100%>
 
 943                 <th align=right>| . $locale->text('Total') . qq|</th>
 
 944                 <td align=right>$form->{invtotal}</td>
 
 956     <td><hr size=3 noshade></td>
 
 959     <th class=listtop align=left>Dokumente im Webdav-Repository</th>
 
 962       <td align=left width=30%><b>Dateiname</b></td>
 
 963       <td align=left width=70%><b>Webdavlink</b></td>
 
 965     foreach $file (keys %{ $form->{WEBDAV} }) {
 
 968         <td align=left>$file</td>
 
 969         <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
 
 980 if ($form->{type} eq "credit_note") {
 
 985         <tr class=listheading>
 
 986           <th colspan=6 class=listheading>|
 
 987     . $locale->text('Payments') . qq|</th>
 
 995         <tr class=listheading>
 
 996           <th colspan=6 class=listheading>|
 
 997     . $locale->text('Incoming Payments') . qq|</th>
 
1002   if ($form->{currency} eq $form->{defaultcurrency}) {
 
1003     @column_index = qw(datepaid source memo paid AR_paid);
 
1005     @column_index = qw(datepaid source memo paid exchangerate AR_paid);
 
1008   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
1009   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
1010   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
1011   $column_data{AR_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
1012   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
1013   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
1018   map { print "$column_data{$_}\n" } @column_index;
 
1025   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
1026   for $i (1 .. $form->{paidaccounts}) {
 
1031     $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
 
1032     $form->{"selectAR_paid_$i"} =~
 
1033       s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
 
1036     $totalpaid += $form->{"paid_$i"};
 
1037     if ($form->{"paid_$i"}) {
 
1038       $form->{"paid_$i"} =
 
1039         $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
1041     $form->{"exchangerate_$i"} =
 
1042       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
1044     $exchangerate = qq| |;
 
1045     if ($form->{currency} ne $form->{defaultcurrency}) {
 
1046       if ($form->{"forex_$i"}) {
 
1048           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
1051           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
1055     $exchangerate .= qq|
 
1056 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
1059     $column_data{"paid_$i"} =
 
1060       qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
 
1061     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
 
1062     $column_data{"AR_paid_$i"}      =
 
1063       qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
 
1064     $column_data{"datepaid_$i"} =
 
1065       qq|<td align=center><input id="datepaid_$i" name="datepaid_$i"  size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
 
1066          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
1067     $column_data{"source_$i"} =
 
1068       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
1069     $column_data{"memo_$i"} =
 
1070       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
1072     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
1075     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
1079 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
1080 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
 
1081 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
1082 <input type=hidden name=oldtotalpaid value=$totalpaid>
 
1087     <td><hr size=3 noshade></td>
 
1101   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1102   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1106     <input class=submit type=submit accesskey="u" name=action id=update_button value="|
 
1107       . $locale->text('Update') . qq|">
 
1108     <input class=submit type=submit name=action value="|
 
1109       . $locale->text('Ship to') . qq|">
 
1110     <input class=submit type=submit name=action value="|
 
1111       . $locale->text('Print') . qq|">
 
1112     <input class=submit type=submit name=action value="|
 
1113       . $locale->text('E-mail') . qq|"> |;
 
1114     print qq|<input class=submit type=submit name=action value="|
 
1115       . $locale->text('Storno') . qq|"> | unless ($form->{storno});
 
1116     print qq|<input class=submit type=submit name=action value="|
 
1117       . $locale->text('Post Payment') . qq|">
 
1119     print qq|<input class=submit type=submit name=action value="|
 
1120       . $locale->text('Use As Template') . qq|">
 
1122   if ($form->{id} && !($form->{type} eq "credit_note")) {
 
1124     <input class=submit type=submit name=action value="|
 
1125       . $locale->text('Credit Note') . qq|">
 
1128     if ($form->{radier}) {
 
1130     <input class=submit type=submit name=action value="|
 
1131       . $locale->text('Delete') . qq|">
 
1136     if ($invdate > $closedto) {
 
1138       <input class=submit type=submit name=action value="|
 
1139         . $locale->text('Order') . qq|">
 
1144     if ($invdate > $closedto) {
 
1145       print qq|<input class=submit type=submit name=action id=update_button value="|
 
1146         . $locale->text('Update') . qq|">
 
1147       <input class=submit type=submit name=action value="|
 
1148         . $locale->text('Ship to') . qq|">
 
1149       <input class=submit type=submit name=action value="|
 
1150         . $locale->text('Preview') . qq|">
 
1151       <input class=submit type=submit name=action value="|
 
1152         . $locale->text('E-mail') . qq|">
 
1153       <input class=submit type=submit name=action value="|
 
1154         . $locale->text('Print and Post') . qq|">
 
1155       <input class=submit type=submit name=action value="|
 
1156         . $locale->text('Post') . qq|"> | .
 
1157         NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
 
1158                          '-class' => 'submit'));
 
1162   # button for saving history
 
1163   if($form->{id} ne "") {
 
1165           <input type="button" class="submit" onclick="set_history_window(|
 
1167           . qq|);" name="history" id="history" value="|
 
1168           . $locale->text('history')
 
1171   # /button for saving history
 
1174   print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
1177 <input type=hidden name=rowcount value=$form->{rowcount}>
 
1179 <input name=callback type=hidden value="$form->{callback}">
 
1181 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 
1182 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
 
1184 <input type=hidden name=path value=$form->{path}>
 
1185 <input type=hidden name=login value=$form->{login}>
 
1186 <input type=hidden name=password value=$form->{password}>
 
1195   $lxdebug->leave_sub();
 
1199   $lxdebug->enter_sub();
 
1201   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1202     qw(exchangerate creditlimit creditremaining);
 
1203   if ($form->{second_run}) {
 
1204     $form->{print_and_post} = 0;
 
1207   $form->{update} = 1;
 
1209   &check_name(customer);
 
1211   $form->{exchangerate} = $exchangerate
 
1215                          $form->check_exchangerate(
 
1216                          \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
 
1219   for $i (1 .. $form->{paidaccounts}) {
 
1220     if ($form->{"paid_$i"}) {
 
1222         $form->{"${_}_$i"} =
 
1223           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
1224       } qw(paid exchangerate);
 
1226       $form->{"exchangerate_$i"} = $exchangerate
 
1228             $form->{"forex_$i"} = (
 
1230                    $form->check_exchangerate(
 
1231                    \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
 
1236   $i            = $form->{rowcount};
 
1237   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
1239   # if last row empty, check the form otherwise retrieve new item
 
1240   if (   ($form->{"partnumber_$i"} eq "")
 
1241       && ($form->{"description_$i"} eq "")
 
1242       && ($form->{"partsgroup_$i"}  eq "")) {
 
1244     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
1249     IS->retrieve_item(\%myconfig, \%$form);
 
1251     $rows = scalar @{ $form->{item_list} };
 
1253     $form->{"discount_$i"} =
 
1254       $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1257       $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
 
1266         $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
1268         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
 
1269           qw(partnumber description unit);
 
1270         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
 
1271           keys %{ $form->{item_list}[0] };
 
1272         if ($form->{"part_payment_id_$i"} ne "") {
 
1273           $form->{payment_id} = $form->{"part_payment_id_$i"};
 
1276         if ($form->{"not_discountable_$i"}) {
 
1277           $form->{"discount_$i"} = 0;
 
1280         $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
 
1281         ($dec) = ($s =~ /\.(\d+)/);
 
1283         $decimalplaces = ($dec > 2) ? $dec : 2;
 
1286           $form->{"sellprice_$i"} = $sellprice;
 
1289           # if there is an exchange rate adjust sellprice
 
1290           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
 
1291           $form->{"sellprice_$i"} /= $exchangerate;
 
1294         $form->{"listprice_$i"} /= $exchangerate;
 
1297           $form->{"sellprice_$i"} * $form->{"qty_$i"} *
 
1298           (1 - $form->{"discount_$i"} / 100);
 
1299         map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
 
1300         map { $form->{"${_}_base"} += $amount }
 
1301           (split / /, $form->{"taxaccounts_$i"});
 
1302         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
 
1303           split / /, $form->{"taxaccounts_$i"}
 
1304           if !$form->{taxincluded};
 
1306         $form->{creditremaining} -= $amount;
 
1309           $form->{"${_}_$i"} =
 
1310             $form->format_amount(\%myconfig, $form->{"${_}_$i"},
 
1312         } qw(sellprice listprice);
 
1315           $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
1318           if ($form->{"inventory_accno_$i"} ne "") {
 
1319             $form->{"lizenzen_$i"} = qq|<option></option>|;
 
1320             foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
 
1321               $form->{"lizenzen_$i"} .=
 
1322                 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
 
1324             $form->{"lizenzen_$i"} .=
 
1325               qq|<option value=-1>Neue Lizenz</option>|;
 
1329         # get pricegroups for parts
 
1330         IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1332         # build up html code for prices_$i
 
1333         &set_pricegroup($i);
 
1340       # ok, so this is a new part
 
1341       # ask if it is a part or service item
 
1343       if (   $form->{"partsgroup_$i"}
 
1344           && ($form->{"partsnumber_$i"} eq "")
 
1345           && ($form->{"description_$i"} eq "")) {
 
1346         $form->{rowcount}--;
 
1347         $form->{"discount_$i"} = "";
 
1351         $form->{"id_$i"}   = 0;
 
1352         $form->{"unit_$i"} = $locale->text('ea');
 
1359   $lxdebug->leave_sub();
 
1363   $lxdebug->enter_sub();
 
1364   for $i (1 .. $form->{paidaccounts}) {
 
1365     if ($form->{"paid_$i"}) {
 
1366       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1368       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1370       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1371         if ($datepaid <= $closedto);
 
1373       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1374         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1375           if ($invdate == $datepaid);
 
1376         $form->isblank("exchangerate_$i",
 
1377                        $locale->text('Exchangerate for payment missing!'));
 
1382   ($form->{AR})      = split /--/, $form->{AR};
 
1383   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
1385   $form->redirect($locale->text(' Payment posted!'))
 
1386       if (IS->post_payment(\%myconfig, \%$form));
 
1387     $form->error($locale->text('Cannot post payment!'));
 
1390   $lxdebug->leave_sub();
 
1394   $lxdebug->enter_sub();
 
1395   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
 
1396   $form->isblank("customer", $locale->text('Customer missing!'));
 
1398   # if oldcustomer ne customer redo form
 
1399   if (&check_name(customer)) {
 
1403   if ($form->{second_run}) {
 
1404     $form->{print_and_post} = 0;
 
1409   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1410   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1412   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
1413     if ($invdate <= $closedto);
 
1415   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1416     if ($form->{currency} ne $form->{defaultcurrency});
 
1418   for $i (1 .. $form->{paidaccounts}) {
 
1419     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
1420       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1422       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1424       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1425         if ($datepaid <= $closedto);
 
1427       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1428         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1429           if ($invdate == $datepaid);
 
1430         $form->isblank("exchangerate_$i",
 
1431                        $locale->text('Exchangerate for payment missing!'));
 
1436   ($form->{AR})      = split /--/, $form->{AR};
 
1437   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
1439   $form->{label} = $locale->text('Invoice');
 
1441   $form->{id} = 0 if $form->{postasnew};
 
1443   # get new invnumber in sequence if no invnumber is given or if posasnew was requested
 
1444   if (!$form->{invnumber} || $form->{postasnew}) {
 
1445     if ($form->{type} eq "credit_note") {
 
1446       $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber");
 
1448       $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
 
1453     if (!(IS->post_invoice(\%myconfig, \%$form))) {
 
1454       $form->error($locale->text('Cannot post invoice!'));
 
1457     # saving the history
 
1458         if(!exists $form->{addition}) {
 
1459           $form->{addition} = "PRINTED AND POSTED";
 
1460           $form->save_history($form->dbconnect(\%myconfig));
 
1462     # /saving the history
 
1465     if (IS->post_invoice(\%myconfig, \%$form)){
 
1467         # saving the history
 
1468         if(!exists $form->{addition}) {
 
1469                         if($form->{storno}) {
 
1470                                 $form->{addition} = "STORNO";
 
1473                                 $form->{addition} = "POSTED";
 
1475                         $form->save_history($form->dbconnect(\%myconfig));
 
1477         # /saving the history
 
1480             $form->{label} . " $form->{invnumber} " . $locale->text('posted!'));
 
1482     $form->error($locale->text('Cannot post invoice!'));
 
1485   $lxdebug->leave_sub();
 
1488 sub print_and_post {
 
1489   $lxdebug->enter_sub();
 
1491   $old_form               = new Form;
 
1493   $form->{print_and_post} = 1;
 
1497   $lxdebug->leave_sub();
 
1501 sub use_as_template {
 
1502   $lxdebug->enter_sub();
 
1504   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
 
1505   $form->{paidaccounts} = 1;
 
1506   $form->{rowcount}--;
 
1507   $form->{invdate} = $form->current_date(\%myconfig);
 
1510   $lxdebug->leave_sub();
 
1514   $lxdebug->enter_sub();
 
1516   if ($form->{storno}) {
 
1517     $form->error($locale->text('Cannot storno storno invoice!'));
 
1520   $form->{storno_id} = $form->{id};
 
1521   $form->{storno} = 1;
 
1523   $form->{invnumber} = "Storno zu " . $form->{invnumber};
 
1526   $lxdebug->leave_sub();
 
1531   $lxdebug->enter_sub();
 
1533   $form->{preview} = 1;
 
1534   $old_form = new Form;
 
1535   for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
1536   $old_form->{rowcount}++;
 
1538   &print_form($old_form);
 
1539   $lxdebug->leave_sub();
 
1544   $lxdebug->enter_sub();
 
1545   if ($form->{second_run}) {
 
1546     $form->{print_and_post} = 0;
 
1553 <form method=post action=$form->{script}>
 
1556   # delete action variable
 
1557   map { delete $form->{$_} } qw(action header);
 
1559   foreach $key (keys %$form) {
 
1560     $form->{$key} =~ s/\"/"/g;
 
1561     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1565 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
 
1568     . $locale->text('Are you sure you want to delete Invoice Number')
 
1569     . qq| $form->{invnumber}
 
1573 <input name=action class=submit type=submit value="|
 
1574     . $locale->text('Yes') . qq|">
 
1578   $lxdebug->leave_sub();
 
1582   $lxdebug->enter_sub();
 
1584   $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
 
1586     $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
 
1589   $form->{rowcount}--;
 
1590   $form->{shipto} = 1;
 
1593   $form->{title}  = $locale->text('Add Credit Note');
 
1594   $form->{script} = 'is.pl';
 
1599   # bo creates the id, reset it
 
1600   map { delete $form->{$_} }
 
1601     qw(id invnumber subject message cc bcc printed emailed queued);
 
1602   $form->{ $form->{vc} } =~ s/--.*//g;
 
1603   $form->{type} = "credit_note";
 
1606   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1608   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1609     qw(creditlimit creditremaining);
 
1611   $currency = $form->{currency};
 
1614   $form->{currency}     = $currency;
 
1615   $form->{exchangerate} = "";
 
1616   $form->{forex}        = "";
 
1617   $form->{exchangerate} = $exchangerate
 
1621                       $form->check_exchangerate(
 
1622                       \%myconfig, $form->{currency}, $form->{invdate}, $buysell
 
1625   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
1632   $lxdebug->leave_sub();
 
1636   $lxdebug->enter_sub();
 
1637   if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
 
1638     # saving the history
 
1639         if(!exists $form->{addition}) {
 
1640           $form->{addition} = "DELETED";
 
1641           $form->save_history($form->dbconnect(\%myconfig));
 
1643     # /saving the history 
 
1644     $form->redirect($locale->text('Invoice deleted!')); 
 
1646   $form->error($locale->text('Cannot delete invoice!'));
 
1648   $lxdebug->leave_sub();