Fehlerbehebung fuer Bug 736 - Der beim Lieferanten hinterlegte Rabatt wird in dem...
[kivitendo-erp.git] / SL / IR.pm
index f1c9197..4c57f85 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -35,6 +35,7 @@
 package IR;
 
 use SL::AM;
+use SL::ARAP;
 use SL::Common;
 use SL::DBUtils;
 use SL::DO;
@@ -343,7 +344,7 @@ sub post_invoice {
     $expensediff += $paiddiff;
 
     ######## this only applies to tax included
-    
+
     $form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $invoicediff if $lastinventoryaccno;
     $form->{amount}{ $form->{id} }{$lastexpenseaccno}   -= $expensediff if $lastexpenseaccno;
 
@@ -364,11 +365,11 @@ sub post_invoice {
 
   $form->{amount}{ $form->{id} }{ $form->{AP} } = $netamount + $tax;
 
-  
+
   $form->{paid} = $form->round_amount($form->{paid} * $form->{exchangerate} + $paiddiff, 2) if $form->{paid} != 0;
 
   # update exchangerate
-  
+
   $form->update_exchangerate($dbh, $form->{currency}, $form->{invdate}, 0, $form->{exchangerate})
     if ($form->{currency} ne $defaultcurrency) && !$exchangerate;
 
@@ -397,7 +398,7 @@ sub post_invoice {
   }
 
   # force AP entry if 0
-  
+
   $form->{amount}{ $form->{id} }{ $form->{AP} } = $form->{paid} if $form->{amount}{$form->{id}}{$form->{AP}} == 0;
 
   # record payments and offsetting AP
@@ -499,7 +500,7 @@ sub post_invoice {
                 netamount    = ?, paid        = ?, duedate       = ?, datepaid    = ?,
                 invoice      = ?, taxzone_id  = ?, notes         = ?, taxincluded = ?,
                 intnotes     = ?, curr        = ?, storno_id     = ?, storno      = ?,
-                cp_id        = ?, employee_id = ?, department_id = ?, 
+                cp_id        = ?, employee_id = ?, department_id = ?,
                 globalproject_id = ?
               WHERE id = ?|;
   @values = (
@@ -508,7 +509,7 @@ sub post_invoice {
                 $netamount,                  $form->{paid},      conv_date($form->{duedate}),       $form->{paid} ? conv_date($form->{datepaid}) : undef,
             '1',                             $taxzone_id,                  $form->{notes},          $form->{taxincluded} ? 't' : 'f',
                 $form->{intnotes},           $form->{currency},     conv_i($form->{storno_id}),     $form->{storno}      ? 't' : 'f',
-         conv_i($form->{cp_id}),      conv_i($form->{employee_id}), conv_i($form->{department_id}), 
+         conv_i($form->{cp_id}),      conv_i($form->{employee_id}), conv_i($form->{department_id}),
          conv_i($form->{globalproject_id}),
          conv_i($form->{id})
   );
@@ -522,7 +523,7 @@ sub post_invoice {
     do_query($form, $dbh, $query, conv_i($form->{storno_id}));
 
     $query = qq!UPDATE ap SET intnotes = ? || intnotes WHERE id = ?!;
-    do_query($form, $dbh, $query, 'Rechnung storniert am $form->{invdate} ', conv_i($form->{storno_id}));
+    do_query($form, $dbh, $query, "Rechnung storniert am $form->{invdate} ", conv_i($form->{storno_id}));
 
     $query = qq|UPDATE ap SET paid = amount WHERE id = ?|;
     do_query($form, $dbh, $query, conv_i($form->{id}));
@@ -562,6 +563,11 @@ sub post_invoice {
                               'to_id'      => $form->{id},
       );
   }
+  delete $form->{convert_from_do_ids};
+
+  ARAP->close_orders_if_billed('dbh'     => $dbh,
+                               'arap_id' => $form->{id},
+                               'table'   => 'ap',);
 
   my $rc = 1;
   if (!$provided_dbh) {
@@ -860,7 +866,8 @@ sub get_vendor {
   }
   my $query =
     qq|SELECT
-         v.name AS vendor, v.creditlimit, v.terms, v.notes AS intnotes,
+         v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount, 
+        v.creditlimit, v.terms, v.notes AS intnotes,
          v.email, v.cc, v.bcc, v.language_id, v.payment_id,
          v.street, v.zipcode, v.city, v.country, v.taxzone_id,
          $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
@@ -964,7 +971,12 @@ sub retrieve_item {
     $where .= " AND lower(${table_column}) LIKE lower(?)";
     push @values, '%' . $form->{"${field}_${i}"} . '%';
   }
-
+  #Es soll auch nach EAN gesucht werden, ohne Einschränkung durch Beschreibung
+  if ($form->{"partnumber_$i"} && !$form->{"description_$i"}) {
+      $where .= qq| OR (NOT p.obsolete = '1' AND p.ean = ? )|;
+      push @values, $form->{"partnumber_$i"};
+   }
   if ($form->{"description_$i"}) {
     $where .= " ORDER BY p.description";
   } else {