]> wagnertech.de Git - mfinanz.git/blobdiff - bin/mozilla/do.pl
Setzt dois_id für inventory beim Standard-Auslagern
[mfinanz.git] / bin / mozilla / do.pl
index cf210ce5199cf82652c381e8d0f372e6a79d2a94..55c37adef7af1f35b9577445363f21f2740fa0df 100644 (file)
@@ -30,6 +30,7 @@
 # Delivery orders
 #======================================================================
 
+use Carp;
 use List::MoreUtils qw(uniq);
 use List::Util qw(max sum);
 use POSIX qw(strftime);
@@ -841,6 +842,15 @@ sub invoice {
   my $currency = $form->{currency};
   invoice_links();
 
+  if ($form->{ordnumber}) {
+    require SL::DB::Order;
+    if (my $order = SL::DB::Manager::Order->find_by(ordnumber => $form->{ordnumber})) {
+      $order->load;
+      $form->{orddate} = $order->transdate_as_date;
+      $form->{$_}      = $order->$_ for qw(payment_id salesman_id taxzone_id quonumber);
+    }
+  }
+
   $form->{currency}     = $currency;
   $form->{exchangerate} = "";
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell);
@@ -1710,6 +1720,9 @@ sub transfer_in_out_default {
   # dieser array_ref ist für DO->save da:
   # einmal die all_requests in YAML verwandeln, damit delivery_order_items_stock
   # gefüllt werden kann.
+  # could be dumped to the form in the first loop,
+  # but maybe bin_id and warehouse_id has changed to the "korrekturlager" with
+  # allowed negative qty ($::instance_conf->get_warehouse_id_ignore_onhand) ...
   my $i = 0;
   foreach (@all_requests){
     $i++;
@@ -1719,6 +1732,15 @@ sub transfer_in_out_default {
 
   save(no_redirect => 1); # Wir können auslagern, deshalb beleg speichern
                           # und in delivery_order_items_stock speichern
+
+  # ... and fill back the persistent dois_id for inventory fk
+  undef (@all_requests);
+  foreach my $i (1 .. $form->{rowcount}) {
+    next unless ($form->{"id_$i"} && $form->{"stock_${prefix}_$i"});
+    foreach my $request (@{ DO->unpack_stock_information('packed' => $form->{"stock_${prefix}_$i"}) }) {
+      push @all_requests, $request;
+    }
+  }
   DO->transfer_in_out('direction' => $prefix,
                       'requests'  => \@all_requests);