EK-Preis editierbar gemacht und marge_total repariert
[kivitendo-erp.git] / bin / mozilla / is.pl
index 4b8b817..a47b7e8 100644 (file)
@@ -34,6 +34,7 @@
 use SL::FU;
 use SL::IS;
 use SL::PE;
+use SL::OE;
 use Data::Dumper;
 use List::Util qw(max sum);
 
@@ -155,6 +156,14 @@ sub invoice_links {
     $ref->{name} = $form->quote($ref->{name});
   }
 
+  # Load data for a specific order and update form fields
+  my $order_data = OE->get_order_data_by_ordnumber(%$form) if $form->{ordnumber};
+
+  # Copy the fields we need to %form
+  for my $key (qw(payment_id salesman_id orddate taxzone_id quonumber)) {
+    $form->{$key} = $order_data->{$key};
+  }
+
   $form->restore_vars(qw(id));
 
   IS->retrieve_invoice(\%myconfig, \%$form);
@@ -162,6 +171,7 @@ sub invoice_links {
   $form->restore_vars(qw(taxincluded)) if $form->{id};
   $form->restore_vars(qw(salesman_id)) if $main::editing;
 
+
   # build vendor/customer drop down comatibility... don't ask
   if (@{ $form->{"all_customer"} }) {
     $form->{"selectcustomer"} = 1;
@@ -253,6 +263,8 @@ sub prepare_invoice {
       (my $dec_qty)            = ($form->{"qty_$i"} =~ /\.(\d+)/);
       $dec_qty                 = length $dec_qty;
 
+      $form->{"lastcost_$i"}  = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
+
       $form->{"qty_$i"}        = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
 
       $form->{rowcount}        = $i;
@@ -283,7 +295,6 @@ sub form_header {
   $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
-  $form->{radier}          = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
   my $set_duedate_url = "$form->{script}?action=set_duedate";
 
@@ -302,6 +313,7 @@ sub form_header {
                    "taxzones"      => "ALL_TAXZONES",
                    "currencies"    => "ALL_CURRENCIES",
                    "customers"     => "ALL_CUSTOMERS",
+                   "departments"   => "all_departments",
                    "price_factors" => "ALL_PRICE_FACTORS");
 
   $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
@@ -534,7 +546,7 @@ sub update {
 
         $form->{creditremaining} -= $amount;
 
-        map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
+        map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice lastcost);
 
         $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
@@ -646,6 +658,7 @@ sub post {
     $form->{print_and_post} = 0;
   }
 
+  remove_emptied_rows();
   &validate_items;
 
   my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
@@ -888,6 +901,16 @@ sub credit_note {
 
   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
+  # bei Gutschriften werden Zahlungseingänge aus Rechnung nicht übernommen
+  for my $i (1 .. $form->{paidaccounts}) {
+    delete $form->{"paid_$i"};
+    delete $form->{"source_$i"};
+    delete $form->{"memo_$i"};
+    delete $form->{"datepaid_$i"};
+    delete $form->{"AR_paid_$i"};
+  };
+  $form->{paidaccounts} = 1;
+
   &prepare_invoice;
 
 
@@ -907,10 +930,10 @@ sub yes {
 
   if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
     # saving the history
-       if(!exists $form->{addition}) {
+    if(!exists $form->{addition}) {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
-         $form->{addition} = "DELETED";
-         $form->save_history($form->dbconnect(\%myconfig));
+      $form->{addition} = "DELETED";
+      $form->save_history($form->dbconnect(\%myconfig));
     }
     # /saving the history
     $form->redirect($locale->text('Invoice deleted!'));