Revert "retrieve_items in IR.pm bzgl. notes überarbeitet"
[kivitendo-erp.git] / SL / IR.pm
index a1cbb4d..55987af 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -800,6 +800,8 @@ SQL
 
   # safety check datev export
   if ($::instance_conf->get_datev_check_on_purchase_invoice) {
+    # if we need department for kostenstelle in DATEV check
+    $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id};
     my $transdate = $::form->{invdate} ? DateTime->from_lxoffice($::form->{invdate}) : undef;
     $transdate  ||= DateTime->today;
 
@@ -873,17 +875,20 @@ sub reverse_invoice {
         #adjust allocated
         $form->update_balance($dbh, "invoice", "allocated", qq|id = $pthref->{id}|, $qty);
 
-        $form->update_balance($dbh, "acc_trans", "amount",
-                              qq|    (trans_id = $pthref->{trans_id})
-                                 AND (chart_id = $ref->{expense_accno_id})
-                                 AND (transdate = '$pthref->{transdate}')|,
-                              $amount);
+        if  ( $::instance_conf->get_inventory_system eq 'perpetual' ) {
 
-        $form->update_balance($dbh, "acc_trans", "amount",
-                              qq|    (trans_id = $pthref->{trans_id})
-                                 AND (chart_id = $ref->{inventory_accno_id})
-                                 AND (transdate = '$pthref->{transdate}')|,
-                              $amount * -1);
+          $form->update_balance($dbh, "acc_trans", "amount",
+                                qq|    (trans_id = $pthref->{trans_id})
+                                   AND (chart_id = $ref->{expense_accno_id})
+                                   AND (transdate = '$pthref->{transdate}')|,
+                                $amount);
+
+          $form->update_balance($dbh, "acc_trans", "amount",
+                                qq|    (trans_id = $pthref->{trans_id})
+                                   AND (chart_id = $ref->{inventory_accno_id})
+                                   AND (transdate = '$pthref->{transdate}')|,
+                                $amount * -1);
+        }
 
         last if (($ref->{allocated} -= $qty) <= 0);
       }
@@ -984,12 +989,15 @@ sub retrieve_invoice {
   $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate,
                 orddate, quodate, globalproject_id,
                 ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate,
+                mtime, itime,
                 intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit,
                 delivery_term_id
               FROM ap
               WHERE id = ?|;
   $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id}));
   map { $form->{$_} = $ref->{$_} } keys %$ref;
+  $form->{mtime} = $form->{itime} if !$form->{mtime};
+  $form->{lastmtime} = $form->{mtime};
 
   $form->{exchangerate}  = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell");