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 #======================================================================
 
  37 use List::Util qw(max);
 
  39 require "bin/mozilla/io.pl";
 
  40 require "bin/mozilla/arap.pl";
 
  41 require "bin/mozilla/drafts.pl";
 
  48   $lxdebug->enter_sub();
 
  50   return $lxdebug->leave_sub() if (load_draft_maybe());
 
  52   if ($form->{type} eq "credit_note") {
 
  53     $form->{title} = $locale->text('Add Credit Note');
 
  55     if ($form->{storno}) {
 
  56       $form->{title} = $locale->text('Add Storno Credit Note');
 
  59     $form->{title} = $locale->text('Add Sales Invoice');
 
  65     "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&password=$form->{password}"
 
  66     unless $form->{callback};
 
  68   $form{jsscript} = "date";
 
  70   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  72     $form->error("Access Denied");
 
  78   $lxdebug->leave_sub();
 
  82   $lxdebug->enter_sub();
 
  85   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
  86   #/show hhistory button
 
  88   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
 
  90     $form->error("Access Denied");
 
  93   if ($form->{print_and_post}) {
 
  94     $form->{action}   = "print";
 
  95     $form->{resubmit} = 1;
 
  96     $language_id = $form->{language_id};
 
  97     $printer_id = $form->{printer_id};
 
 101   if ($form->{print_and_post}) {
 
 102     $form->{language_id} = $language_id;
 
 103     $form->{printer_id} = $printer_id;
 
 108   $lxdebug->leave_sub();
 
 112   $lxdebug->enter_sub();
 
 114   $form->{vc} = 'customer';
 
 117   $form->{webdav}   = $webdav;
 
 118   $form->{lizenzen} = $lizenzen;
 
 120   $form->create_links("AR", \%myconfig, "customer");
 
 122   if ($form->{all_customer}) {
 
 123     unless ($form->{customer_id}) {
 
 124       $form->{customer_id} = $form->{all_customer}->[0]->{id};
 
 125       $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
 
 129   if ($form->{payment_id}) {
 
 130     $payment_id = $form->{payment_id};
 
 132   if ($form->{language_id}) {
 
 133     $language_id = $form->{language_id};
 
 135   if ($form->{taxzone_id}) {
 
 136     $taxzone_id = $form->{taxzone_id};
 
 141   if ($form->{shipto_id}) {
 
 142     $shipto_id = $form->{shipto_id};
 
 145   $cp_id = $form->{cp_id};
 
 146   IS->get_customer(\%myconfig, \%$form);
 
 148   #quote all_customer Bug 133
 
 149   foreach $ref (@{ $form->{all_customer} }) {
 
 150     $ref->{name} = $form->quote($ref->{name});
 
 155   IS->retrieve_invoice(\%myconfig, \%$form);
 
 156   $form->{cp_id} = $cp_id;
 
 159     $form->{payment_id} = $payment_id;
 
 162     $form->{language_id} = $language_id;
 
 165     $form->{taxzone_id} = $taxzone_id;
 
 168     $form->{shipto_id} = $shipto_id;
 
 171   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
 174   if ($form->{all_departments}) {
 
 175     $form->{selectdepartment} = "<option>\n";
 
 176     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 179       $form->{selectdepartment} .=
 
 180         "<option>$_->{description}--$_->{id}</option>\n"
 
 181     } (@{ $form->{all_departments} });
 
 184   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 187   $form->{forex} = $form->{exchangerate};
 
 188   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 190   foreach $key (keys %{ $form->{AR_links} }) {
 
 191     foreach $ref (@{ $form->{AR_links}{$key} }) {
 
 192       $form->{"select$key"} .=
 
 193 "<option>$ref->{accno}--$ref->{description}</option>\n";
 
 196     if ($key eq "AR_paid") {
 
 197       for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 198         $form->{"AR_paid_$i"} =
 
 199           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 202         $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
 
 203         $form->{"datepaid_$i"} =
 
 204           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 205         $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
 
 206           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 207         $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 208         $form->{"memo_$i"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 210         $form->{paidaccounts} = $i;
 
 214         "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
 
 219   $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
 
 221   $form->{AR} = $form->{AR_1} unless $form->{id};
 
 224     ($form->datetonum($form->{invdate}, \%myconfig) <=
 
 225      $form->datetonum($form->{closedto}, \%myconfig));
 
 227   $lxdebug->leave_sub();
 
 230 sub prepare_invoice {
 
 231   $lxdebug->enter_sub();
 
 233   if ($form->{type} eq "credit_note") {
 
 234     $form->{type}     = "credit_note";
 
 235     $form->{formname} = "credit_note";
 
 237     $form->{type}     = "invoice";
 
 238     $form->{formname} = "invoice";
 
 243     map { $form->{$_} =~ s/\"/"/g }
 
 244       qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
 
 246     #     # get pricegroups for parts
 
 247     #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 251     foreach $ref (@{ $form->{invoice_details} }) {
 
 254       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
 255       $form->{"discount_$i"} =
 
 256         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
 
 257       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 259       $decimalplaces = ($dec > 2) ? $dec : 2;
 
 261       $form->{"sellprice_$i"} =
 
 262         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 265       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 266       $dec_qty = length $dec_qty;
 
 269         $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
 
 271       map { $form->{"${_}_$i"} =~ s/\"/"/g }
 
 272         qw(partnumber description unit partnotes);
 
 273       $form->{rowcount} = $i;
 
 277   $lxdebug->leave_sub();
 
 281   $lxdebug->enter_sub();
 
 283   $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
 
 284   $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
 
 287     if ($form->{type} eq "credit_note") {
 
 288       $form->{title} = $locale->text('Edit Credit Note');
 
 289       $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
 
 291       $form->{title} = $locale->text('Edit Sales Invoice');
 
 292       $form->{title} = $locale->text('Edit Storno Invoice')     if $form->{storno};
 
 295   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
 296   $form->{radier}          = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 298   $payment = qq|<option value=""></option>|;
 
 299   foreach $item (@{ $form->{payment_terms} }) {
 
 300     if ($form->{payment_id} eq $item->{id}) {
 
 301       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
 
 303       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
 
 307   my $set_duedate_url = "$form->{script}?login=$form->{login}&password=$form->{password}&action=set_duedate";
 
 309   my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
 
 310   push(@ { $form->{AJAX} }, $pjx);
 
 312   my @old_project_ids = ($form->{"globalproject_id"});
 
 313   map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
 
 315   $form->get_lists("contacts"   => "ALL_CONTACTS",
 
 316                    "shipto"     => "ALL_SHIPTO",
 
 317                    "projects"   => { "key"    => "ALL_PROJECTS",
 
 319                                      "old_id" => \@old_project_ids },
 
 320                    "employees"  => "ALL_SALESMEN",
 
 321                    "taxzones"   => "ALL_TAXZONES",
 
 322                    "currencies" => "ALL_CURRENCIES",
 
 323                    "customers"  => "ALL_CUSTOMERS");
 
 326   my @values = (undef);
 
 327   foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
 
 328     push(@values, $item->{"cp_id"});
 
 329     $labels{$item->{"cp_id"}} = $item->{"cp_name"} .  ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
 
 332   if (scalar @values > 1) {
 
 335       <th align="right">| . $locale->text('Contact Person') . qq|</th>
 
 336       <td>| .  NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
 
 337                                     '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
 
 344   foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
 
 345     push(@values, $item->{"id"});
 
 346     $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
 
 351       <th align="right">| . $locale->text('Employee') . qq|</th>
 
 352       <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
 
 353                                    '-values' => \@values, '-labels' => \%labels)) . qq|
 
 360   foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
 
 361     push(@values, $item->{name}.qq|--|.$item->{"id"});
 
 362     $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
 
 365   $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
 
 368       <th align="right">| . $locale->text('Customer') . qq|</th>
 
 370         (($myconfig{vclimit} <=  scalar(@values))
 
 371               ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
 
 372               : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
 
 373                              '-onChange' => 'document.getElementById(\'update_button\').click();',
 
 374                              '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
 
 375         <input type="button" value="?" onclick="show_vc_details('customer')">
 
 380   foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
 
 381     push(@values, $item->{"shipto_id"});
 
 382     $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
 
 386   if (scalar @values > 1) {
 
 389       <th align="right">| . $locale->text('Shipping Address') . qq|</th>
 
 390       <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
 
 391                                    '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
 
 397   foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
 
 398     push(@values, $item);
 
 399     $labels{$item} = $item;
 
 402   $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
 
 404   if (scalar @values) {
 
 407       <th align="right">| . $locale->text('Currency') . qq|</th>
 
 408       <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
 
 409                                    '-values' => \@values, '-labels' => \%labels)) . qq|
 
 416   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 417     push(@values, $item->{"id"});
 
 418     $labels{$item->{"id"}} = $item->{"projectnumber"};
 
 420   my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
 
 421                                                  '-labels' => \%labels,
 
 422                                                  '-default' => $form->{"globalproject_id"}));
 
 426   foreach my $item (@{ $form->{ALL_SALESMEN} }) {
 
 427     push(@values, $item->{id});
 
 428     $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
 
 432     qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
 
 433          <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
 
 434                                       '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
 
 440   foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
 
 441     push(@values, $item->{"id"});
 
 442     $labels{$item->{"id"}} = $item->{"description"};
 
 445   if (!$form->{"id"}) {
 
 448       <th align="right">| . $locale->text('Steuersatz') . qq|</th>
 
 449       <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
 
 450                                    '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
 
 457       <th align="right">| . $locale->text('Steuersatz') . qq|</th>
 
 459         <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
 
 460         | . H($labels{$form->{"taxzone_id"}}) . qq|
 
 465   # set option selected
 
 466   foreach $item (qw(AR customer currency department employee)) {
 
 467     $form->{"select$item"} =~ s/ selected//;
 
 468     $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 471   $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
 
 473   $form->{exchangerate}    = $form->format_amount(\%myconfig, $form->{exchangerate});
 
 474   $form->{creditlimit}     = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 475   $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 478   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 479     if ($form->{forex}) {
 
 480       $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
 
 481                           <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
 
 483       $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
 
 484                           <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
 
 487   $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
 
 491                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 492                 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
 
 493                   <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
 
 496 | if $form->{selectdepartment};
 
 498   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 500   if ($form->{business}) {
 
 503           <th align="right">| . $locale->text('Customer type') . qq|</th>
 
 504           <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
 
 505       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
 
 511   if ($form->{max_dunning_level}) {
 
 514         <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
 
 516           <b>$form->{max_dunning_level}</b>;
 
 517           | . $locale->text('Dunning Amount') . qq|: <b>|
 
 518         . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
 
 525   $form->{fokus} = "invoice.customer";
 
 527   # use JavaScript Calendar or not
 
 528   $form->{jsscript} = 1;
 
 530   if ($form->{type} eq "credit_note") {
 
 532       <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
 
 533        <input type="button" name="invdate" id="trigger1" value="|
 
 534       . $locale->text('button') . qq|"></td>|;
 
 538       Form->write_trigger(\%myconfig,     "1",
 
 543       <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
 
 544        <input type="button" name="invdate" id="trigger1" value="|
 
 545       . $locale->text('button') . qq|"></td>
 
 548       <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
 
 549        <input type="button" name="duedate" id="trigger2" value="|
 
 550       . $locale->text('button') . qq|"></td></td>
 
 553       <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
 
 554        <input type="button" name="deliverydate" id="trigger3" value="|
 
 555       . $locale->text('button') . qq|"></td></td>
 
 560       Form->write_trigger(\%myconfig,     "3",
 
 561                           "invdate",      "BL", "trigger1", 
 
 562                           "duedate",      "BL", "trigger2",
 
 563                           "deliverydate", "BL", "trigger3");
 
 566   $credittext = $locale->text('Credit Limit exceeded!!!');
 
 567   $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
 
 568           : ($form->{resubmit})                                ? qq|document.invoice.submit()|
 
 569           : ($creditwarning)                                   ? qq|alert('$credittext')|
 
 571   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 572   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 574   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
 
 575   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
 
 578     $form->write_trigger(\%myconfig, 2,
 
 579                          "orddate", "BL", "trigger_orddate",
 
 580                          "quodate", "BL", "trigger_quodate");
 
 581   # show history button js
 
 582   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 583   #/show history button js
 
 587 <body onLoad="$onload">
 
 588 <script type="text/javascript" src="js/common.js"></script>
 
 589 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
 
 590 <script type="text/javascript" src="js/vendor_selection.js"></script>
 
 591 <script type="text/javascript" src="js/calculate_qty.js"></script>
 
 593 <form method="post" name="invoice" action="$form->{script}">
 
 596   $form->hide_form(qw(id action type media format queued printed emailed title vc discount
 
 597                       creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
 
 598                       max_dunning_level dunning_amount
 
 599                       shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax 
 
 600                       shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts),
 
 601                       map { $_.'_rate', $_,'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
 
 603   print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
 
 607 <input type="hidden" name="lizenzen" value="$lizenzen">
 
 609 <div class="listtop" width="100%">$form->{title}</div>
 
 617           <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
 
 618           <input type="hidden" name="customer_id" value="$form->{customer_id}">
 
 619           <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
 
 620           <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
 
 625           <td align="right">| . $locale->text('Credit Limit') . qq|</td>
 
 626           <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
 
 631                 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
 
 632                 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
 
 633                 <input type="hidden" name="selectAR" value="$form->{selectAR}">
 
 639                 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
 
 640                 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
 
 644                 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
 
 646                 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
 
 649                 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
 
 650                 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
 
 653                 <th align="right">| . $locale->text('Transaction description') . qq|</th>
 
 654                 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
 
 661 #                         <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
 
 663 #                       <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
 
 664 #                       <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
 
 668 #                         <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
 
 670 #                       <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
 
 671 #                       <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
 
 678           <td align="right" valign="top">
 
 683 if ($form->{type} eq "credit_note") {
 
 685                 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
 
 686                 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
 
 689                 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
 
 694                 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 695                 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
 
 698                 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
 
 702                 <th align="right">| . $locale->text('Due Date') . qq|</th>
 
 706                 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
 
 711                 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
 
 712                 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
 
 715           <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
 
 716           <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
 
 717            <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
 
 720                 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
 
 721                 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
 
 724           <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
 
 725           <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
 
 726            <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
 
 729                 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
 
 730                 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
 
 733           <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
 
 734           <td>$globalprojectnumber</td>
 
 748   print qq|<input type="hidden" name="webdav" value="$webdav">|;
 
 750   $lxdebug->leave_sub();
 
 754   $lxdebug->enter_sub();
 
 756   $form->{invtotal} = $form->{invsubtotal};
 
 758   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
 
 761   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
 
 764   $rows = ($rows > $introws) ? $rows : $introws;
 
 766     qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
 
 768     qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
 
 770   $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
 
 773   if ($form->{taxaccounts}) {
 
 775                 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
 
 776       . $locale->text('Tax Included') . qq|</b><br><br>|;
 
 779   if (!$form->{taxincluded}) {
 
 781     foreach $item (split / /, $form->{taxaccounts}) {
 
 782       if ($form->{"${item}_base"}) {
 
 783         $form->{"${item}_total"} =
 
 785                              $form->{"${item}_base"} * $form->{"${item}_rate"},
 
 787         $form->{invtotal} += $form->{"${item}_total"};
 
 788         $form->{"${item}_total"} =
 
 789           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 793                 <th align="right">$form->{"${item}_description"} |
 
 794                                     . $form->{"${item}_rate"} * 100 .qq|%</th>
 
 795                 <td align="right">$form->{"${item}_total"}</td>
 
 801     $form->{invsubtotal} =
 
 802       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
 
 806                 <th align="right">| . $locale->text('Subtotal') . qq|</th>
 
 807                 <td align="right">$form->{invsubtotal}</td>
 
 813   if ($form->{taxincluded}) {
 
 814     foreach $item (split / /, $form->{taxaccounts}) {
 
 815       if ($form->{"${item}_base"}) {
 
 816         $form->{"${item}_total"} =
 
 818                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
 
 819                               (1 + $form->{"${item}_rate"})
 
 822         $form->{"${item}_netto"} =
 
 824                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
 
 826         $form->{"${item}_total"} =
 
 827           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 828         $form->{"${item}_netto"} =
 
 829           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
 
 833                 <th align="right">Enthaltene $form->{"${item}_description"} |
 
 834                                     . $form->{"${item}_rate"} * 100 .qq|%</th>
 
 835                 <td align="right">$form->{"${item}_total"}</td>
 
 838                 <th align="right">Nettobetrag</th>
 
 839                 <td align="right">$form->{"${item}_netto"}</td>
 
 847   $form->{oldinvtotal} = $form->{invtotal};
 
 849     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
 
 859                 <th align="left">| . $locale->text('Notes') . qq|</th>
 
 860                 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
 
 861                 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
 
 866                 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
 
 874               <th  align=left>| . $locale->text('Ertrag') . qq|</th>
 
 875               <td>| .  $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
 
 878               <th  align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
 
 879               <td>| .  $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
 
 881             <input type=hidden name="marge_total" value="$form->{"marge_total"}">
 
 882             <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
 
 891                 <th align="right">| . $locale->text('Total') . qq|</th>
 
 892                 <td align="right">$form->{invtotal}</td>
 
 904     <td><hr size="3" noshade></td>
 
 907     <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
 
 910       <td align="left" width="30%"><b>Dateiname</b></td>
 
 911       <td align="left" width="70%"><b>Webdavlink</b></td>
 
 913     foreach $file (@{ $form->{WEBDAV} }) {
 
 916         <td align="left">$file->{name}</td>
 
 917         <td align="left"><a href="$file->{link}">$file->{type}</a></td>
 
 928 if ($form->{type} eq "credit_note") {
 
 933         <tr class="listheading">
 
 934           <th colspan="6" class="listheading">|
 
 935     . $locale->text('Payments') . qq|</th>
 
 943         <tr class="listheading">
 
 944           <th colspan="6" class="listheading">|
 
 945     . $locale->text('Incoming Payments') . qq|</th>
 
 950   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 951     @column_index = qw(datepaid source memo paid AR_paid);
 
 953     @column_index = qw(datepaid source memo paid exchangerate AR_paid);
 
 956   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 957   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 958   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 959   $column_data{AR_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 960   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 961   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
 966   map { print "$column_data{$_}\n" } @column_index;
 
 974   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 975   for $i (1 .. $form->{paidaccounts}) {
 
 980     $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
 
 981     $form->{"selectAR_paid_$i"} =~
 
 982       s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
 
 985     $totalpaid += $form->{"paid_$i"};
 
 986     if ($form->{"paid_$i"}) {
 
 988         $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 990     $form->{"exchangerate_$i"} =
 
 991       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 993     if ($form->{"exchangerate_$i"} == 0) {
 
 994       $form->{"exchangerate_$i"} = "";
 
 996     $exchangerate = qq| |;
 
 997     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 998       if ($form->{"forex_$i"}) {
 
 999         $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
 
1001         $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
 
1005     $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
 
1007     $column_data{"paid_$i"} =
 
1008       qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
 
1009     $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
 
1010     $column_data{"AR_paid_$i"}      =
 
1011       qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
 
1012     $column_data{"datepaid_$i"} =
 
1013       qq|<td align="center"><input id="datepaid_$i" name="datepaid_$i"  size="11" title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
 
1014          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
1015     $column_data{"source_$i"} =
 
1016       qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
 
1017     $column_data{"memo_$i"} =
 
1018       qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
 
1020     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
1023     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
1026   my $paid_missing = $form->{oldinvtotal} - $totalpaid;
 
1032       <td align="center">| . $locale->text('Total') . qq|</td>
 
1033       <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
 
1038       <td align="center">| . $locale->text('Missing amount') . qq|</td>
 
1039       <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
 
1043   map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
 
1044   print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
 
1049     <td><hr size="3" noshade></td>
 
1063   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1064   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1067     my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
 
1070     <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
 
1071       . $locale->text('Update') . qq|">
 
1072     <input class="submit" type="submit" name="action" value="|
 
1073       . $locale->text('Ship to') . qq|">
 
1074     <input class="submit" type="submit" name="action" value="|
 
1075       . $locale->text('Print') . qq|">
 
1076     <input class="submit" type="submit" name="action" value="|
 
1077       . $locale->text('E-mail') . qq|"> |;
 
1078     print qq|<input class="submit" type="submit" name="action" value="|
 
1079       . $locale->text('Storno') . qq|"> | if ($show_storno);
 
1080     print qq|<input class="submit" type="submit" name="action" value="|
 
1081       . $locale->text('Post Payment') . qq|">
 
1083     print qq|<input class="submit" type="submit" name="action" value="|
 
1084       . $locale->text('Use As Template') . qq|">
 
1086   if ($form->{id} && !($form->{type} eq "credit_note")) {
 
1088     <input class="submit" type="submit" name="action" value="|
 
1089       . $locale->text('Credit Note') . qq|">
 
1092     if ($form->{radier}) {
 
1094     <input class="submit" type="submit" name="action" value="|
 
1095       . $locale->text('Delete') . qq|">
 
1100     if ($invdate > $closedto) {
 
1102       <input class="submit" type="submit" name="action" value="|
 
1103         . $locale->text('Order') . qq|">
 
1108     if ($invdate > $closedto) {
 
1109       print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
 
1110         . $locale->text('Update') . qq|">
 
1111       <input class="submit" type="submit" name="action" value="|
 
1112         . $locale->text('Ship to') . qq|">
 
1113       <input class="submit" type="submit" name="action" value="|
 
1114         . $locale->text('Preview') . qq|">
 
1115       <input class="submit" type="submit" name="action" value="|
 
1116         . $locale->text('E-mail') . qq|">
 
1117       <input class="submit" type="submit" name="action" value="|
 
1118         . $locale->text('Print and Post') . qq|">
 
1119       <input class="submit" type="submit" name="action" value="|
 
1120         . $locale->text('Post') . qq|"> | .
 
1121         NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
 
1122                          '-class' => 'submit'));
 
1126   # button for saving history
 
1127   if($form->{id} ne "") {
 
1129           <input type="button" class="submit" onclick="set_history_window(|
 
1131           . qq|);" name="history" id="history" value="|
 
1132           . $locale->text('history')
 
1135   # /button for saving history
 
1137   # mark_as_paid button 
 
1138   if($form->{id} ne "") {  
 
1139     print qq|<input type="submit" class="submit" name="action" value="| 
 
1140           . $locale->text('mark as paid') . qq|">|;
 
1142   # /mark_as_paid button
 
1143   print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
1146 <input type="hidden" name="rowcount" value="$form->{rowcount}">
 
1148 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
 
1149 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 
1150 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
 
1151 map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(login password));
 
1160   $lxdebug->leave_sub();
 
1164   $lxdebug->enter_sub();
 
1165   &mark_as_paid_common(\%myconfig,"ar");  
 
1166   $lxdebug->leave_sub();
 
1170   $lxdebug->enter_sub();
 
1172   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
 
1174   $form->{print_and_post} = 0         if $form->{second_run};
 
1175   $taxincluded            = "checked" if $form->{taxincluded};
 
1176   $form->{update} = 1;
 
1178   &check_name(customer);
 
1180   $form->{taxincluded} ||= $taxincluded;
 
1182   $form->{exchangerate} = $exchangerate if
 
1183     $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
 
1185   for $i (1 .. $form->{paidaccounts}) {
 
1186     next unless $form->{"paid_$i"};
 
1187     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
 
1188     $form->{"exchangerate_$i"} = $exchangerate if
 
1189       $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
 
1192   $i            = $form->{rowcount};
 
1193   $exchangerate = $form->{exchangerate} || 1;
 
1195   # if last row empty, check the form otherwise retrieve new item
 
1196   if (   ($form->{"partnumber_$i"} eq "")
 
1197       && ($form->{"description_$i"} eq "")
 
1198       && ($form->{"partsgroup_$i"}  eq "")) {
 
1200     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
1205     IS->retrieve_item(\%myconfig, \%$form);
 
1207     $rows = scalar @{ $form->{item_list} };
 
1209     $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1212       $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
 
1221         $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
1223         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
 
1224         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
 
1226         $form->{payment_id}    = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
 
1227         $form->{"discount_$i"} = 0                             if $form->{"not_discountable_$i"};
 
1229         ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
 
1230         $decimalplaces = max 2, length $1;
 
1233           $form->{"sellprice_$i"} = $sellprice;
 
1235           # if there is an exchange rate adjust sellprice
 
1236           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
 
1237           $form->{"sellprice_$i"} /= $exchangerate;
 
1240         $form->{"listprice_$i"} /= $exchangerate;
 
1242         $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
 
1243         map { $form->{"${_}_base"} = 0 }                                 split / /, $form->{taxaccounts};
 
1244         map { $form->{"${_}_base"} += $amount }                          split / /, $form->{"taxaccounts_$i"};
 
1245         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
 
1247         $form->{creditremaining} -= $amount;
 
1249         map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
 
1251         $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
1254           if ($form->{"inventory_accno_$i"} ne "") {
 
1255             $form->{"lizenzen_$i"} = qq|<option></option>|;
 
1256             foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
 
1257               $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
 
1259             $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
 
1263         # get pricegroups for parts
 
1264         IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1266         # build up html code for prices_$i
 
1267         &set_pricegroup($i);
 
1274       # ok, so this is a new part
 
1275       # ask if it is a part or service item
 
1277       if (   $form->{"partsgroup_$i"}
 
1278           && ($form->{"partsnumber_$i"} eq "")
 
1279           && ($form->{"description_$i"} eq "")) {
 
1280         $form->{rowcount}--;
 
1281         $form->{"discount_$i"} = "";
 
1285         $form->{"id_$i"}   = 0;
 
1290   $lxdebug->leave_sub();
 
1294   $lxdebug->enter_sub();
 
1296   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
1297   for $i (1 .. $form->{paidaccounts}) {
 
1298     if ($form->{"paid_$i"}) {
 
1299       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1301       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1303       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1304         if ($datepaid <= $closedto);
 
1306       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1307         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1308           if ($invdate == $datepaid);
 
1309         $form->isblank("exchangerate_$i",
 
1310                        $locale->text('Exchangerate for payment missing!'));
 
1315   ($form->{AR})      = split /--/, $form->{AR};
 
1316   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
1318   $form->redirect($locale->text('Payment posted!'))
 
1319       if (IS->post_payment(\%myconfig, \%$form));
 
1320     $form->error($locale->text('Cannot post payment!'));
 
1323   $lxdebug->leave_sub();
 
1327   $lxdebug->enter_sub();
 
1329   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
1330   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
 
1331   $form->isblank("customer", $locale->text('Customer missing!'));
 
1333   $form->{invnumber} =~ s/^\s*//g;
 
1334   $form->{invnumber} =~ s/\s*$//g;
 
1336   # if oldcustomer ne customer redo form
 
1337   if (&check_name(customer)) {
 
1341   if ($form->{second_run}) {
 
1342     $form->{print_and_post} = 0;
 
1347   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1348   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1350   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
1351     if ($invdate <= $closedto);
 
1353   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1354     if ($form->{currency} ne $form->{defaultcurrency});
 
1356   for $i (1 .. $form->{paidaccounts}) {
 
1357     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
1358       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1360       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1362       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1363         if ($datepaid <= $closedto);
 
1365       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1366         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1367           if ($invdate == $datepaid);
 
1368         $form->isblank("exchangerate_$i",
 
1369                        $locale->text('Exchangerate for payment missing!'));
 
1374   ($form->{AR})        = split /--/, $form->{AR};
 
1375   ($form->{AR_paid})   = split /--/, $form->{AR_paid};
 
1376   $form->{storno}    ||= 0;
 
1378   $form->{label} = $locale->text('Invoice');
 
1380   $form->{id} = 0 if $form->{postasnew};
 
1382   # get new invnumber in sequence if no invnumber is given or if posasnew was requested
 
1383   if ($form->{postasnew}) {
 
1384     if ($form->{type} eq "credit_note") {
 
1385       undef($form->{cnnumber});
 
1387       undef($form->{invnumber});
 
1392   $form->error($locale->text('Cannot post invoice!'))
 
1393     unless IS->post_invoice(\%myconfig, \%$form);
 
1394   remove_draft() if $form->{remove_draft};
 
1396   if(!exists $form->{addition}) {
 
1397     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1398     $form->{addition} = $print_post     ? "PRINTED AND POSTED" :
 
1399                         $form->{storno} ? "STORNO"             :
 
1401     $form->save_history($form->dbconnect(\%myconfig));
 
1404   $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
 
1407   $lxdebug->leave_sub();
 
1410 sub print_and_post {
 
1411   $lxdebug->enter_sub();
 
1413   $old_form               = new Form;
 
1415   $form->{print_and_post} = 1;
 
1419   $lxdebug->leave_sub();
 
1423 sub use_as_template {
 
1424   $lxdebug->enter_sub();
 
1426   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);
 
1427   $form->{paidaccounts} = 1;
 
1428   $form->{rowcount}--;
 
1429   $form->{invdate} = $form->current_date(\%myconfig);
 
1432   $lxdebug->leave_sub();
 
1436   $lxdebug->enter_sub();
 
1438   if ($form->{storno}) {
 
1439     $form->error($locale->text('Cannot storno storno invoice!'));
 
1442   if (IS->has_storno(\%myconfig, $form, "ar")) {
 
1443     $form->error($locale->text("Invoice has already been storno'd!"));
 
1446   map({ my $key = $_; delete($form->{$key})
 
1447           unless (grep({ $key eq $_ } qw(login password id stylesheet type))); }
 
1454   # Payments must not be recorded for the new storno invoice.
 
1455   $form->{paidaccounts} = 0;
 
1456   map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
 
1458   $form->{storno_id} = $form->{id};
 
1459   $form->{storno} = 1;
 
1461   $form->{invnumber} = "Storno zu " . $form->{invnumber};
 
1462   $form->{rowcount}++;
 
1465   $lxdebug->leave_sub();
 
1469   $lxdebug->enter_sub();
 
1471   $form->{preview} = 1;
 
1472   $old_form = new Form;
 
1473   for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
1475   &print_form($old_form);
 
1476   $lxdebug->leave_sub();
 
1481   $lxdebug->enter_sub();
 
1482   if ($form->{second_run}) {
 
1483     $form->{print_and_post} = 0;
 
1490 <form method="post" action="$form->{script}">
 
1493   # delete action variable
 
1494   map { delete $form->{$_} } qw(action header);
 
1496   foreach $key (keys %$form) {
 
1497     $form->{$key} =~ s/\"/"/g;
 
1498     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1502 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
 
1505     . $locale->text('Are you sure you want to delete Invoice Number')
 
1506     . qq| $form->{invnumber}
 
1510 <input name="action" class="submit" type="submit" value="|
 
1511     . $locale->text('Yes') . qq|">
 
1515   $lxdebug->leave_sub();
 
1519   $lxdebug->enter_sub();
 
1521   $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
 
1523     $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
 
1526   $form->{rowcount}--;
 
1527   $form->{shipto} = 1;
 
1530   $form->{title}  = $locale->text('Add Credit Note');
 
1531   $form->{script} = 'is.pl';
 
1536   # bo creates the id, reset it
 
1537   map { delete $form->{$_} }
 
1538     qw(id invnumber subject message cc bcc printed emailed queued);
 
1539   $form->{ $form->{vc} } =~ s/--.*//g;
 
1540   $form->{type} = "credit_note";
 
1543   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1545   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1546     qw(creditlimit creditremaining);
 
1548   $currency = $form->{currency};
 
1551   $form->{currency}     = $currency;
 
1552   $form->{exchangerate} = "";
 
1553   $form->{forex}        = "";
 
1554   $form->{exchangerate} = $exchangerate
 
1558                       $form->check_exchangerate(
 
1559                       \%myconfig, $form->{currency}, $form->{invdate}, $buysell
 
1562   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
1569   $lxdebug->leave_sub();
 
1573   $lxdebug->enter_sub();
 
1574   if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
 
1575     # saving the history
 
1576         if(!exists $form->{addition}) {
 
1577     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1578           $form->{addition} = "DELETED";
 
1579           $form->save_history($form->dbconnect(\%myconfig));
 
1581     # /saving the history
 
1582     $form->redirect($locale->text('Invoice deleted!'));
 
1584   $form->error($locale->text('Cannot delete invoice!'));
 
1586   $lxdebug->leave_sub();
 
1590   $lxdebug->enter_sub();
 
1595     my $saved_form = save_form();
 
1600     map({ $saved_vars{$_} = $form->{$_}; } qw(id invnumber));
 
1601     restore_form($saved_form);
 
1602     map({ $form->{$_} = $saved_vars{$_}; } qw(id invnumber));
 
1607   $lxdebug->leave_sub();