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 use List::Util qw(max sum);
 
  40 require "bin/mozilla/io.pl";
 
  41 require "bin/mozilla/invoice_io.pl";
 
  42 require "bin/mozilla/arap.pl";
 
  43 require "bin/mozilla/drafts.pl";
 
  50   $lxdebug->enter_sub();
 
  52   $auth->assert('invoice_edit');
 
  54   return $lxdebug->leave_sub() if (load_draft_maybe());
 
  56   if ($form->{type} eq "credit_note") {
 
  57     $form->{title} = $locale->text('Add Credit Note');
 
  59     if ($form->{storno}) {
 
  60       $form->{title} = $locale->text('Add Storno Credit Note');
 
  63     $form->{title} = $locale->text('Add Sales Invoice');
 
  68   $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
 
  70   $form{jsscript} = "date";
 
  76   $lxdebug->leave_sub();
 
  80   $lxdebug->enter_sub();
 
  82   $auth->assert('invoice_edit');
 
  85   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
  86   #/show hhistory button
 
  89   if ($form->{print_and_post}) {
 
  90     $form->{action}   = "print";
 
  91     $form->{resubmit} = 1;
 
  92     $language_id = $form->{language_id};
 
  93     $printer_id = $form->{printer_id};
 
  97   if ($form->{print_and_post}) {
 
  98     $form->{language_id} = $language_id;
 
  99     $form->{printer_id} = $printer_id;
 
 104   $lxdebug->leave_sub();
 
 108   $lxdebug->enter_sub();
 
 110   $auth->assert('invoice_edit');
 
 112   $form->{vc} = 'customer';
 
 115   $form->{webdav}   = $webdav;
 
 116   $form->{lizenzen} = $lizenzen;
 
 118   $form->create_links("AR", \%myconfig, "customer");
 
 120   if ($form->{all_customer}) {
 
 121     unless ($form->{customer_id}) {
 
 122       $form->{customer_id} = $form->{all_customer}->[0]->{id};
 
 123       $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_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;
 
 169   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
 172   if ($form->{all_departments}) {
 
 173     $form->{selectdepartment} = "<option>\n";
 
 174     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 177       $form->{selectdepartment} .=
 
 178         "<option>$_->{description}--$_->{id}</option>\n"
 
 179     } (@{ $form->{all_departments} });
 
 182   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 185   $form->{forex} = $form->{exchangerate};
 
 186   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
 188   foreach $key (keys %{ $form->{AR_links} }) {
 
 189     foreach $ref (@{ $form->{AR_links}{$key} }) {
 
 190       $form->{"select$key"} .=
 
 191 "<option>$ref->{accno}--$ref->{description}</option>\n";
 
 194     if ($key eq "AR_paid") {
 
 195       for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
 196         $form->{"AR_paid_$i"} =
 
 197           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
 200         $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
 
 201         $form->{"datepaid_$i"} =
 
 202           $form->{acc_trans}{$key}->[$i - 1]->{transdate};
 
 203         $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
 
 204           $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
 
 205         $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
 
 206         $form->{"memo_$i"}   = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
 208         $form->{paidaccounts} = $i;
 
 212         "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
 
 217   $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
 
 219   $form->{AR} = $form->{AR_1} unless $form->{id};
 
 222     ($form->datetonum($form->{invdate}, \%myconfig) <=
 
 223      $form->datetonum($form->{closedto}, \%myconfig));
 
 225   $lxdebug->leave_sub();
 
 228 sub prepare_invoice {
 
 229   $lxdebug->enter_sub();
 
 231   $auth->assert('invoice_edit');
 
 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";
 
 244     #     # get pricegroups for parts
 
 245     #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
 249     foreach $ref (@{ $form->{invoice_details} }) {
 
 252       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
 253       $form->{"discount_$i"} =
 
 254         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
 
 255       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
 
 257       $decimalplaces = ($dec > 2) ? $dec : 2;
 
 259       $form->{"sellprice_$i"} =
 
 260         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
 
 263       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
 
 264       $dec_qty = length $dec_qty;
 
 267         $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
 
 269       $form->{rowcount} = $i;
 
 273   $lxdebug->leave_sub();
 
 277   $lxdebug->enter_sub();
 
 279   $auth->assert('invoice_edit');
 
 281   $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
 
 282   $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
 
 285     if ($form->{type} eq "credit_note") {
 
 286       $form->{title} = $locale->text('Edit Credit Note');
 
 287       $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
 
 289       $form->{title} = $locale->text('Edit Sales Invoice');
 
 290       $form->{title} = $locale->text('Edit Storno Invoice')     if $form->{storno};
 
 293   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
 294   $form->{radier}          = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 296   $payment = qq|<option value=""></option>|;
 
 297   foreach $item (@{ $form->{payment_terms} }) {
 
 298     if ($form->{payment_id} eq $item->{id}) {
 
 299       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
 
 301       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
 
 305   my $set_duedate_url = "$form->{script}?action=set_duedate";
 
 307   my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
 
 308   push(@ { $form->{AJAX} }, $pjx);
 
 310   my @old_project_ids = ($form->{"globalproject_id"});
 
 311   map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
 
 313   $form->get_lists("contacts"      => "ALL_CONTACTS",
 
 314                    "shipto"        => "ALL_SHIPTO",
 
 315                    "projects"      => { "key"    => "ALL_PROJECTS",
 
 317                                         "old_id" => \@old_project_ids },
 
 318                    "employees"     => "ALL_SALESMEN",
 
 319                    "taxzones"      => "ALL_TAXZONES",
 
 320                    "currencies"    => "ALL_CURRENCIES",
 
 321                    "customers"     => "ALL_CUSTOMERS",
 
 322                    "price_factors" => "ALL_PRICE_FACTORS");
 
 325   my @values = (undef);
 
 326   foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
 
 327     push(@values, $item->{"cp_id"});
 
 328     $labels{$item->{"cp_id"}} = join(',', $item->{"cp_name"}, $item->{"cp_givenname"}) .  ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
 
 331   if (scalar @values > 1) {
 
 334       <th align="right">| . $locale->text('Contact Person') . qq|</th>
 
 335       <td>| .  NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
 
 336                                     '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
 
 343   foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
 
 344     push(@values, $item->{"id"});
 
 345     $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
 
 350       <th align="right">| . $locale->text('Employee') . qq|</th>
 
 351       <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
 
 352                                    '-values' => \@values, '-labels' => \%labels)) . qq|
 
 359   foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
 
 360     push(@values, $item->{name}.qq|--|.$item->{"id"});
 
 361     $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
 
 364   $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
 
 367       <th align="right">| . $locale->text('Customer') . qq|</th>
 
 369         (($myconfig{vclimit} <=  scalar(@values))
 
 370               ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
 
 371               : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
 
 372                              '-onChange' => 'document.getElementById(\'update_button\').click();',
 
 373                              '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
 
 374         <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')">
 
 379   foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
 
 380     push(@values, $item->{"shipto_id"});
 
 381     $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
 
 385   if (scalar @values > 1) {
 
 388       <th align="right">| . $locale->text('Shipping Address') . qq|</th>
 
 389       <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
 
 390                                    '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
 
 396   foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
 
 397     push(@values, $item);
 
 398     $labels{$item} = $item;
 
 401   $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
 
 403   if (scalar @values) {
 
 406       <th align="right">| . $locale->text('Currency') . qq|</th>
 
 407       <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
 
 408                                    '-values' => \@values, '-labels' => \%labels)) . qq|
 
 415   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 416     push(@values, $item->{"id"});
 
 417     $labels{$item->{"id"}} = $item->{"projectnumber"};
 
 419   my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
 
 420                                                  '-labels' => \%labels,
 
 421                                                  '-default' => $form->{"globalproject_id"}));
 
 425   foreach my $item (@{ $form->{ALL_SALESMEN} }) {
 
 426     push(@values, $item->{id});
 
 427     $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
 
 431     qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
 
 432          <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
 
 433                                       '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
 
 439   foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
 
 440     push(@values, $item->{"id"});
 
 441     $labels{$item->{"id"}} = $item->{"description"};
 
 444   if (!$form->{"id"}) {
 
 447       <th align="right">| . $locale->text('Steuersatz') . qq|</th>
 
 448       <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
 
 449                                    '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
 
 456       <th align="right">| . $locale->text('Steuersatz') . qq|</th>
 
 458         <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
 
 459         | . H($labels{$form->{"taxzone_id"}}) . qq|
 
 464   # set option selected
 
 465   foreach $item (qw(AR customer currency department employee)) {
 
 466     $form->{"select$item"} =~ s/ selected//;
 
 467     $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 470   $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
 
 472   $form->{exchangerate}    = $form->format_amount(\%myconfig, $form->{exchangerate});
 
 473   $form->{creditlimit}     = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 474   $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 477   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 478     if ($form->{forex}) {
 
 479       $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
 
 480                           <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
 
 482       $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
 
 483                           <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
 
 486   $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
 
 490                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 491                 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
 
 492                   <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
 
 495 | if $form->{selectdepartment};
 
 497   $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 499   if ($form->{business}) {
 
 502           <th align="right">| . $locale->text('Customer type') . qq|</th>
 
 503           <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
 
 504       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
 
 510   if ($form->{max_dunning_level}) {
 
 513         <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
 
 515           <b>$form->{max_dunning_level}</b>;
 
 516           | . $locale->text('Dunning Amount') . qq|: <b>|
 
 517         . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
 
 524   $form->{fokus} = "invoice.customer";
 
 526   # use JavaScript Calendar or not
 
 527   $form->{jsscript} = 1;
 
 529   if ($form->{type} eq "credit_note") {
 
 531       <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
 
 532        <input type="button" name="invdate_button" id="trigger1" value="|
 
 533       . $locale->text('button') . qq|"></td>|;
 
 537       Form->write_trigger(\%myconfig,     "1",
 
 542       <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
 
 543        <input type="button" name="invdate_button" id="trigger1" value="|
 
 544       . $locale->text('button') . qq|"></td>
 
 547       <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
 
 548        <input type="button" name="duedate_button" id="trigger2" value="|
 
 549       . $locale->text('button') . qq|"></td>
 
 552       <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
 
 553        <input type="button" name="deliverydate_button" id="trigger3" value="|
 
 554       . $locale->text('button') . qq|"></td>
 
 559       Form->write_trigger(\%myconfig,     "3",
 
 560                           "invdate",      "BL", "trigger1", 
 
 561                           "duedate",      "BL", "trigger2",
 
 562                           "deliverydate", "BL", "trigger3");
 
 565   $credittext = $locale->text('Credit Limit exceeded!!!');
 
 567   my $follow_up_vc         =  $form->{customer};
 
 568   $follow_up_vc            =~ s/--.*?//;
 
 569   my $follow_up_trans_info =  "$form->{invnumber} ($follow_up_vc)";
 
 571   $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
 
 572           : ($form->{resubmit})                                ? qq|document.invoice.submit()|
 
 573           : ($creditwarning)                                   ? qq|alert('$credittext')|
 
 575   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 576   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 578   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
 
 579   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
 
 582     $form->write_trigger(\%myconfig, 2,
 
 583                          "orddate", "BL", "trigger_orddate",
 
 584                          "quodate", "BL", "trigger_quodate");
 
 585   # show history button js
 
 586   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 587   #/show history button js
 
 591 <body onLoad="$onload">
 
 592 <script type="text/javascript" src="js/common.js"></script>
 
 593 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
 
 594 <script type="text/javascript" src="js/vendor_selection.js"></script>
 
 595 <script type="text/javascript" src="js/calculate_qty.js"></script>
 
 596 <script type="text/javascript" src="js/follow_up.js"></script>
 
 598 <form method="post" name="invoice" action="$form->{script}">
 
 601   $form->hide_form(qw(id action type media format queued printed emailed title vc discount
 
 602                       creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
 
 603                       max_dunning_level dunning_amount
 
 604                       shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax 
 
 605                       shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
 
 606                       convert_from_do_ids convert_from_oe_ids),
 
 607                       map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
 
 609   print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
 
 613 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
 
 614 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
 
 615 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
 
 616 <input type="hidden" name="follow_up_rowcount" value="1">
 
 618 <input type="hidden" name="lizenzen" value="$lizenzen">
 
 620 <div class="listtop" width="100%">$form->{title}</div>
 
 628           <input type="hidden" name="customer_klass" value="| . H($form->{customer_klass}) . qq|">
 
 629           <input type="hidden" name="customer_id" value="| . H($form->{customer_id}) . qq|">
 
 630           <input type="hidden" name="oldcustomer" value="| . H($form->{oldcustomer}) . qq|">
 
 631           <input type="hidden" name="selectcustomer" value="| . H($form->{selectcustomer}) . qq|">
 
 636           <td align="right">| . $locale->text('Credit Limit') . qq|</td>
 
 637           <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
 
 642                 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
 
 643                 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
 
 644                 <input type="hidden" name="selectAR" value="$form->{selectAR}">
 
 650                 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
 
 651                 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
 
 655                 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
 
 657                 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
 
 661                 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
 
 663                 $cgi->textfield("-name" => "shipvia", "-size" => 35, "-value" => $form->{shipvia}) .
 
 667                 <th align="right">| . $locale->text('Transaction description') . qq|</th>
 
 668                 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
 
 675 #                         <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
 
 677 #                       <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
 
 678 #                       <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
 
 682 #                         <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
 
 684 #                       <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
 
 685 #                       <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
 
 692           <td align="right" valign="top">
 
 698 #ergänzung in der maske um das feld Lieferscheinnummer (Delivery Order Number), meiner meinung nach sinnvoll ueber dem feld lieferscheindatum 12.02.2009 jb
 
 699 if ($form->{type} eq "credit_note") {
 
 701                 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
 
 703                 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .        
 
 707                 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
 
 712                 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 714                 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .        
 
 718                 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
 
 722                 <th align="right">| . $locale->text('Due Date') . qq|</th>
 
 726                 <th align="right" nowrap>| . $locale->text('Delivery Order Number') . qq|</th>
 
 728                 $cgi->textfield("-name" => "donumber", "-size" => 11, "-value" => $form->{donumber}) .  
 
 732                 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
 
 737                 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
 
 739                 $cgi->textfield("-name" => "ordnumber", "-size" => 11, "-value" => $form->{ordnumber}) .        
 
 743           <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
 
 744           <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
 
 745            <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
 
 748                 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
 
 750                 $cgi->textfield("-name" => "quonumber", "-size" => 11, "-value" => $form->{quonumber}) .        
 
 754           <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
 
 755           <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
 
 756            <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
 
 759                 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
 
 761                 $cgi->textfield("-name" => "cusordnumber", "-size" => 11, "-value" => $form->{cusordnumber}) .  
 
 765           <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
 
 766           <td>$globalprojectnumber</td>
 
 780   print qq|<input type="hidden" name="webdav" value="$webdav">|;
 
 782   $lxdebug->leave_sub();
 
 786   $lxdebug->enter_sub();
 
 788   $auth->assert('invoice_edit');
 
 790   $form->{invtotal} = $form->{invsubtotal};
 
 792   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
 
 795   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
 
 798   $rows = ($rows > $introws) ? $rows : $introws;
 
 800     qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
 
 802     qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
 
 804   $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
 
 807   if ($form->{taxaccounts}) {
 
 809                 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
 
 810       . $locale->text('Tax Included') . qq|</b><br><br>|;
 
 813   if (!$form->{taxincluded}) {
 
 815     foreach $item (split / /, $form->{taxaccounts}) {
 
 816       if ($form->{"${item}_base"}) {
 
 817         $form->{"${item}_total"} =
 
 819                              $form->{"${item}_base"} * $form->{"${item}_rate"},
 
 821         $form->{invtotal} += $form->{"${item}_total"};
 
 822         $form->{"${item}_total"} =
 
 823           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 827                 <th align="right">$form->{"${item}_description"} |
 
 828                                     . $form->{"${item}_rate"} * 100 .qq|%</th>
 
 829                 <td align="right">$form->{"${item}_total"}</td>
 
 835     $form->{invsubtotal} =
 
 836       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
 
 840                 <th align="right">| . $locale->text('Subtotal') . qq|</th>
 
 841                 <td align="right">$form->{invsubtotal}</td>
 
 847   if ($form->{taxincluded}) {
 
 848     foreach $item (split / /, $form->{taxaccounts}) {
 
 849       if ($form->{"${item}_base"}) {
 
 850         $form->{"${item}_total"} =
 
 852                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
 
 853                               (1 + $form->{"${item}_rate"})
 
 856         $form->{"${item}_netto"} =
 
 858                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
 
 860         $form->{"${item}_total"} =
 
 861           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
 
 862         $form->{"${item}_netto"} =
 
 863           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
 
 867                 <th align="right">Enthaltene $form->{"${item}_description"} |
 
 868                                     . $form->{"${item}_rate"} * 100 .qq|%</th>
 
 869                 <td align="right">$form->{"${item}_total"}</td>
 
 872                 <th align="right">Nettobetrag</th>
 
 873                 <td align="right">$form->{"${item}_netto"}</td>
 
 881   $form->{oldinvtotal} = $form->{invtotal};
 
 883     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
 
 885   my $follow_ups_block;
 
 887     my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
 
 889     if (@{ $follow_ups} ) {
 
 890       my $num_due       = sum map { $_->{due} * 1 } @{ $follow_ups };
 
 891       $follow_ups_block = qq|
 
 893         <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
 
 907                 <th align="left">| . $locale->text('Notes') . qq|</th>
 
 908                 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
 
 909                 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
 
 914                 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value, 'invdate__' + invdate.value],['duedate'])">$payment
 
 923               <th  align=left>| . $locale->text('Ertrag') . qq|</th>
 
 924               <td>| .  $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
 
 927               <th  align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
 
 928               <td>| .  $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
 
 930             <input type=hidden name="marge_total" value="$form->{"marge_total"}">
 
 931             <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
 
 940                 <th align="right">| . $locale->text('Total') . qq|</th>
 
 941                 <td align="right">$form->{invtotal}</td>
 
 953     <td><hr size="3" noshade></td>
 
 956     <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
 
 959       <td align="left" width="30%"><b>Dateiname</b></td>
 
 960       <td align="left" width="70%"><b>Webdavlink</b></td>
 
 962     foreach $file (@{ $form->{WEBDAV} }) {
 
 965         <td align="left">$file->{name}</td>
 
 966         <td align="left"><a href="$file->{link}">$file->{type}</a></td>
 
 977 if ($form->{type} eq "credit_note") {
 
 982         <tr class="listheading">
 
 983           <th colspan="6" class="listheading">|
 
 984     . $locale->text('Payments') . qq|</th>
 
 992         <tr class="listheading">
 
 993           <th colspan="6" class="listheading">|
 
 994     . $locale->text('Incoming Payments') . qq|</th>
 
 999   if ($form->{currency} eq $form->{defaultcurrency}) {
 
1000     @column_index = qw(datepaid source memo paid AR_paid);
 
1002     @column_index = qw(datepaid source memo paid exchangerate AR_paid);
 
1005   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
1006   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
1007   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
1008   $column_data{AR_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
1009   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
1010   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>";
 
1015   map { print "$column_data{$_}\n" } @column_index;
 
1023   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
1024   for $i (1 .. $form->{paidaccounts}) {
 
1029     $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
 
1030     $form->{"selectAR_paid_$i"} =~
 
1031       s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
 
1034     $totalpaid += $form->{"paid_$i"};
 
1035     if ($form->{"paid_$i"}) {
 
1036       $form->{"paid_$i"} =
 
1037         $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
1039     $form->{"exchangerate_$i"} =
 
1040       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
1042     if ($form->{"exchangerate_$i"} == 0) {
 
1043       $form->{"exchangerate_$i"} = "";
 
1045     $exchangerate = qq| |;
 
1046     if ($form->{currency} ne $form->{defaultcurrency}) {
 
1047       if ($form->{"forex_$i"}) {
 
1048         $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
 
1050         $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
 
1054     $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
 
1056     $column_data{"paid_$i"} =
 
1057       qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
 
1058     $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
 
1059     $column_data{"AR_paid_$i"}      =
 
1060       qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
 
1061     $column_data{"datepaid_$i"} =
 
1062       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)\">
 
1063          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
1064     $column_data{"source_$i"} =
 
1065       qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
 
1066     $column_data{"memo_$i"} =
 
1067       qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
 
1069     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
1072     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
1075   my $paid_missing = $form->{oldinvtotal} - $totalpaid;
 
1081       <td align="center">| . $locale->text('Total') . qq|</td>
 
1082       <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
 
1087       <td align="center">| . $locale->text('Missing amount') . qq|</td>
 
1088       <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
 
1092   map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
 
1093   print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
 
1098     <td><hr size="3" noshade></td>
 
1112   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1113   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1116     my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && (($totalpaid == 0) || ($totalpaid eq ""));
 
1119     <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
 
1120       . $locale->text('Update') . qq|">
 
1121     <input class="submit" type="submit" name="action" value="|
 
1122       . $locale->text('Ship to') . qq|">
 
1123     <input class="submit" type="submit" name="action" value="|
 
1124       . $locale->text('Print') . qq|">
 
1125     <input class="submit" type="submit" name="action" value="|
 
1126       . $locale->text('E-mail') . qq|"> |;
 
1127     print qq|<input class="submit" type="submit" name="action" value="|
 
1128       . $locale->text('Storno') . qq|"> | if ($show_storno);
 
1129     print qq|<input class="submit" type="submit" name="action" value="|
 
1130       . $locale->text('Post Payment') . qq|">
 
1132     print qq|<input class="submit" type="submit" name="action" value="|
 
1133       . $locale->text('Use As Template') . qq|">
 
1135     if ($form->{id} && !($form->{type} eq "credit_note")) {
 
1137     <input class="submit" type="submit" name="action" value="|
 
1138       . $locale->text('Credit Note') . qq|">
 
1141     if ($form->{radier}) {
 
1143     <input class="submit" type="submit" name="action" value="|
 
1144       . $locale->text('Delete') . qq|">
 
1149     if ($invdate > $closedto) {
 
1151       <input class="submit" type="submit" name="action" value="|
 
1152         . $locale->text('Order') . qq|">
 
1157       <input type="button" class="submit" onclick="follow_up_window()" value="|
 
1158       . $locale->text('Follow-Up')
 
1162     if ($invdate > $closedto) {
 
1163       print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
 
1164         . $locale->text('Update') . qq|">
 
1165       <input class="submit" type="submit" name="action" value="|
 
1166         . $locale->text('Ship to') . qq|">
 
1167       <input class="submit" type="submit" name="action" value="|
 
1168         . $locale->text('Preview') . qq|">
 
1169       <input class="submit" type="submit" name="action" value="|
 
1170         . $locale->text('E-mail') . qq|">
 
1171       <input class="submit" type="submit" name="action" value="|
 
1172         . $locale->text('Print and Post') . qq|">
 
1173       <input class="submit" type="submit" name="action" value="|
 
1174         . $locale->text('Post') . qq|"> | .
 
1175         NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
 
1176                          '-class' => 'submit'));
 
1180   # button for saving history
 
1181   if($form->{id} ne "") {
 
1183           <input type="button" class="submit" onclick="set_history_window(|
 
1185           . qq|);" name="history" id="history" value="|
 
1186           . $locale->text('history')
 
1189   # /button for saving history
 
1191   # mark_as_paid button 
 
1192   if($form->{id} ne "") {  
 
1193     print qq|<input type="submit" class="submit" name="action" value="| 
 
1194           . $locale->text('mark as paid') . qq|">|;
 
1196   # /mark_as_paid button
 
1197   print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
1200 <input type="hidden" name="rowcount" value="$form->{rowcount}">
 
1202 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
 
1203 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 
1204 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
 
1205 . $cgi->hidden('-name' => 'customer_discount', '-value' => [$form->{customer_discount}])
 
1214   $lxdebug->leave_sub();
 
1218   $lxdebug->enter_sub();
 
1220   $auth->assert('invoice_edit');
 
1222   &mark_as_paid_common(\%myconfig,"ar");  
 
1224   $lxdebug->leave_sub();
 
1228   $lxdebug->enter_sub();
 
1230   $auth->assert('invoice_edit');
 
1232   my ($recursive_call) = shift;
 
1234   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
 
1236   $form->{print_and_post} = 0         if $form->{second_run};
 
1237   $taxincluded            = "checked" if $form->{taxincluded};
 
1238   $form->{update} = 1;
 
1240   &check_name(customer);
 
1242   $form->{taxincluded} ||= $taxincluded;
 
1244   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
 
1245   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
1247   for $i (1 .. $form->{paidaccounts}) {
 
1248     next unless $form->{"paid_$i"};
 
1249     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
 
1250     $form->{"forex_$i"}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
 
1251     $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
 
1254   $i            = $form->{rowcount};
 
1255   $exchangerate = $form->{exchangerate} || 1;
 
1257   # if last row empty, check the form otherwise retrieve new item
 
1258   if (   ($form->{"partnumber_$i"} eq "")
 
1259       && ($form->{"description_$i"} eq "")
 
1260       && ($form->{"partsgroup_$i"}  eq "")) {
 
1262     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
 
1267     IS->retrieve_item(\%myconfig, \%$form);
 
1269     $rows = scalar @{ $form->{item_list} };
 
1271     $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
 
1274       $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
 
1283         $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
1285         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
 
1286         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
 
1288         $form->{payment_id}    = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
 
1289         $form->{"discount_$i"} = 0                             if $form->{"not_discountable_$i"};
 
1291         $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
 
1293         ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
 
1294         $decimalplaces = max 2, length $1;
 
1297           $form->{"sellprice_$i"} = $sellprice;
 
1299           # if there is an exchange rate adjust sellprice
 
1300           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
 
1301           $form->{"sellprice_$i"} /= $exchangerate;
 
1304         $form->{"listprice_$i"} /= $exchangerate;
 
1306         $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
 
1307         map { $form->{"${_}_base"} = 0 }                                 split / /, $form->{taxaccounts};
 
1308         map { $form->{"${_}_base"} += $amount }                          split / /, $form->{"taxaccounts_$i"};
 
1309         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
 
1311         $form->{creditremaining} -= $amount;
 
1313         map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
 
1315         $form->{"qty_$i"} = $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"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
 
1323             $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
 
1327         # get pricegroups for parts
 
1328         IS->get_pricegroups_for_parts(\%myconfig, \%$form);
 
1330         # build up html code for prices_$i
 
1331         &set_pricegroup($i);
 
1338       # ok, so this is a new part
 
1339       # ask if it is a part or service item
 
1341       if (   $form->{"partsgroup_$i"}
 
1342           && ($form->{"partsnumber_$i"} eq "")
 
1343           && ($form->{"description_$i"} eq "")) {
 
1344         $form->{rowcount}--;
 
1345         $form->{"discount_$i"} = "";
 
1349         $form->{"id_$i"}   = 0;
 
1354   $lxdebug->leave_sub();
 
1358   $lxdebug->enter_sub();
 
1360   $auth->assert('invoice_edit');
 
1362   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
1363   for $i (1 .. $form->{paidaccounts}) {
 
1364     if ($form->{"paid_$i"}) {
 
1365       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1367       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1369       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1370         if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
 
1372       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1373         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1374           if ($invdate == $datepaid);
 
1375         $form->isblank("exchangerate_$i",
 
1376                        $locale->text('Exchangerate for payment missing!'));
 
1381   ($form->{AR})      = split /--/, $form->{AR};
 
1382   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
1384   $form->redirect($locale->text('Payment posted!'))
 
1385       if (IS->post_payment(\%myconfig, \%$form));
 
1386     $form->error($locale->text('Cannot post payment!'));
 
1389   $lxdebug->leave_sub();
 
1393   $lxdebug->enter_sub();
 
1395   $auth->assert('invoice_edit');
 
1397   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
1398   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
 
1399   $form->isblank("customer", $locale->text('Customer missing!'));
 
1400   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
1401         if ($form->date_closed($form->{"invdate"}, \%myconfig));
 
1403   $form->{invnumber} =~ s/^\s*//g;
 
1404   $form->{invnumber} =~ s/\s*$//g;
 
1406   # if oldcustomer ne customer redo form
 
1407   if (&check_name(customer)) {
 
1411   if ($form->{second_run}) {
 
1412     $form->{print_and_post} = 0;
 
1417   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
1418   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
1420   $form->error($locale->text('Cannot post invoice for a closed period!'))
 
1421     if ($invdate <= $closedto);
 
1423   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1424     if ($form->{currency} ne $form->{defaultcurrency});
 
1426   for $i (1 .. $form->{paidaccounts}) {
 
1427     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
1428       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1430       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1432       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1433         if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
 
1435       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1436         $form->{"exchangerate_$i"} = $form->{exchangerate}
 
1437           if ($invdate == $datepaid);
 
1438         $form->isblank("exchangerate_$i",
 
1439                        $locale->text('Exchangerate for payment missing!'));
 
1444   ($form->{AR})        = split /--/, $form->{AR};
 
1445   ($form->{AR_paid})   = split /--/, $form->{AR_paid};
 
1446   $form->{storno}    ||= 0;
 
1448   $form->{label} = $locale->text('Invoice');
 
1450   $form->{id} = 0 if $form->{postasnew};
 
1452   # get new invnumber in sequence if no invnumber is given or if posasnew was requested
 
1453   if ($form->{postasnew}) {
 
1454     if ($form->{type} eq "credit_note") {
 
1455       undef($form->{cnnumber});
 
1457       undef($form->{invnumber});
 
1462   $form->error($locale->text('Cannot post invoice!'))
 
1463     unless IS->post_invoice(\%myconfig, \%$form);
 
1464   remove_draft() if $form->{remove_draft};
 
1466   if(!exists $form->{addition}) {
 
1467     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1468     $form->{addition} = $print_post     ? "PRINTED AND POSTED" :
 
1469                         $form->{storno} ? "STORNO"             :
 
1471     $form->save_history($form->dbconnect(\%myconfig));
 
1474   $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
 
1477   $lxdebug->leave_sub();
 
1480 sub print_and_post {
 
1481   $lxdebug->enter_sub();
 
1483   $auth->assert('invoice_edit');
 
1485   $old_form               = new Form;
 
1487   $form->{print_and_post} = 1;
 
1491   $lxdebug->leave_sub();
 
1495 sub use_as_template {
 
1496   $lxdebug->enter_sub();
 
1498   $auth->assert('invoice_edit');
 
1500   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);
 
1501   $form->{paidaccounts} = 1;
 
1502   $form->{rowcount}--;
 
1503   $form->{invdate} = $form->current_date(\%myconfig);
 
1506   $lxdebug->leave_sub();
 
1510   $lxdebug->enter_sub();
 
1512   $auth->assert('invoice_edit');
 
1514   if ($form->{storno}) {
 
1515     $form->error($locale->text('Cannot storno storno invoice!'));
 
1518   if (IS->has_storno(\%myconfig, $form, "ar")) {
 
1519     $form->error($locale->text("Invoice has already been storno'd!"));
 
1522   map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
 
1528   # Payments must not be recorded for the new storno invoice.
 
1529   $form->{paidaccounts} = 0;
 
1530   map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
 
1532   $form->{storno_id} = $form->{id};
 
1533   $form->{storno} = 1;
 
1535   $form->{invnumber} = "Storno zu " . $form->{invnumber};
 
1536   $form->{rowcount}++;
 
1539   $lxdebug->leave_sub();
 
1543   $lxdebug->enter_sub();
 
1545   $auth->assert('invoice_edit');
 
1547   $form->{preview} = 1;
 
1548   $old_form = new Form;
 
1549   for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
1551   &print_form($old_form);
 
1552   $lxdebug->leave_sub();
 
1557   $lxdebug->enter_sub();
 
1559   $auth->assert('invoice_edit');
 
1561   if ($form->{second_run}) {
 
1562     $form->{print_and_post} = 0;
 
1569 <form method="post" action="$form->{script}">
 
1572   # delete action variable
 
1573   map { delete $form->{$_} } qw(action header);
 
1575   foreach $key (keys %$form) {
 
1576     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
1577     $form->{$key} =~ s/\"/"/g;
 
1578     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
 
1582 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
 
1585     . $locale->text('Are you sure you want to delete Invoice Number')
 
1586     . qq| $form->{invnumber}
 
1590 <input name="action" class="submit" type="submit" value="|
 
1591     . $locale->text('Yes') . qq|">
 
1595   $lxdebug->leave_sub();
 
1599   $lxdebug->enter_sub();
 
1601   $auth->assert('invoice_edit');
 
1603   $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
 
1605     $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
 
1608   $form->{rowcount}--;
 
1609   $form->{shipto} = 1;
 
1612   $form->{title}  = $locale->text('Add Credit Note');
 
1613   $form->{script} = 'is.pl';
 
1618   # bo creates the id, reset it
 
1619   map { delete $form->{$_} }
 
1620     qw(id invnumber subject message cc bcc printed emailed queued);
 
1621   $form->{ $form->{vc} } =~ s/--.*//g;
 
1622   $form->{type} = "credit_note";
 
1625   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
1627   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
1628     qw(creditlimit creditremaining);
 
1630   $currency = $form->{currency};
 
1633   $form->{currency}     = $currency;
 
1634   $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
 
1635   $form->{exchangerate} = $form->{forex} || '';
 
1637   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
1644   $lxdebug->leave_sub();
 
1648   $lxdebug->enter_sub();
 
1650   $auth->assert('invoice_edit');
 
1652   if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
 
1653     # saving the history
 
1654         if(!exists $form->{addition}) {
 
1655     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1656           $form->{addition} = "DELETED";
 
1657           $form->save_history($form->dbconnect(\%myconfig));
 
1659     # /saving the history
 
1660     $form->redirect($locale->text('Invoice deleted!'));
 
1662   $form->error($locale->text('Cannot delete invoice!'));
 
1664   $lxdebug->leave_sub();
 
1668   $lxdebug->enter_sub();
 
1670   $auth->assert('invoice_edit');
 
1675     my $saved_form = save_form();
 
1679     restore_form($saved_form, 0, qw(id invnumber));
 
1684   $lxdebug->leave_sub();