]> wagnertech.de Git - mfinanz.git/blobdiff - SL/IS.pm
Auslagern in VK-Rechnung: Beim Buchen einer VK-Rechnung wird ausgelagert.
[mfinanz.git] / SL / IS.pm
index 7b1871e77600194a021251b5ec85ea0fe5bbcb3f..6a8ef46351ae3e6d2cf293c1dff23987185bc9f8 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -373,6 +373,12 @@ sub invoice_details {
         $sth->finish;
       }
 
+      CVar->get_non_editable_ic_cvars(form               => $form,
+                                      dbh                => $dbh,
+                                      row                => $i, 
+                                      sub_module         => 'invoice',
+                                      may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']);
+
       push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} },
         CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)
           for @{ $ic_cvar_configs };
@@ -749,6 +755,12 @@ sub post_invoice {
       $pricegroup_id *= 1;
       $pricegroup_id  = undef if !$pricegroup_id;
 
+      CVar->get_non_editable_ic_cvars(form               => $form,
+                                      dbh                => $dbh,
+                                      row                => $i, 
+                                      sub_module         => 'invoice',
+                                      may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']);
+
       if (!$form->{"invoice_id_$i"}) {
         # there is no persistent id, therefore create one with all necessary constraints
         my $q_invoice_id = qq|SELECT nextval('invoiceid')|;
@@ -800,7 +812,7 @@ SQL
     }
     # link previous items with invoice items
     foreach (qw(delivery_order_items orderitems invoice)) {
-      if ($form->{"converted_from_${_}_id_$i"}) {
+      if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
         RecordLinks->create_links('dbh'        => $dbh,
                                   'mode'       => 'ids',
                                   'from_table' => $_,
@@ -808,8 +820,8 @@ SQL
                                   'to_table'   => 'invoice',
                                   'to_id'      => $form->{"invoice_id_$i"},
         );
-        delete $form->{"converted_from_${_}_id_$i"};
       }
+      delete $form->{"converted_from_${_}_id_$i"};
     }
   }
 
@@ -1159,7 +1171,7 @@ SQL
              conv_date($form->{"invdate"}),  conv_date($form->{"orddate"}),    conv_date($form->{"quodate"}),    conv_i($form->{"customer_id"}),
                        $amount,                        $netamount,                       $form->{"paid"},
              conv_date($form->{"duedate"}),  conv_date($form->{"deliverydate"}),    '1',                                $form->{"shippingpoint"},
-                       $form->{"shipvia"},      conv_i($form->{"terms"}),                $form->{"notes"},              $form->{"intnotes"},
+                       $form->{"shipvia"},      conv_i($form->{"terms"}), $restricter->process($form->{"notes"}),       $form->{"intnotes"},
                        $form->{"currency"},     conv_i($form->{"department_id"}), conv_i($form->{"payment_id"}),        $form->{"taxincluded"} ? 't' : 'f',
                        $form->{"type"},         conv_i($form->{"language_id"}),   conv_i($form->{"taxzone_id"}), conv_i($form->{"shipto_id"}),
                 conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}),   conv_i($form->{storno_id}),           $form->{"storno"} ? 't' : 'f',
@@ -1279,6 +1291,63 @@ SQL
   return $rc;
 }
 
+sub transfer_out {
+  $::lxdebug->enter_sub;
+
+  my ($self, $form) = @_; 
+
+  my @transfers;
+
+  foreach my $i (1 .. $form->{rowcount}) {
+    next if !$form->{"id_$i"};
+    my ($wh_id, $bin_id) = _determine_wh_and_bin($::instance_conf, $form->{"id_$i"});
+
+    if ($wh_id && $bin_id) {
+      push @transfers, {
+        'parts_id'         => $form->{"id_$i"},
+        'qty'              => $form->{"qty_$i"},
+        'unit'             => $form->{"unit_$i"},
+        'transfer_type'    => 'shipped',
+        'src_warehouse_id' => $wh_id,
+        'src_bin_id'       => $bin_id,
+        'project_id'       => $form->{"project_id_$i"},
+        'invoice_id'       => $form->{"invoice_id_$i"},
+      };
+    }
+  }
+
+  require SL::WH;
+  WH->transfer(@transfers);
+
+  $::lxdebug->leave_sub;
+  return 1;
+}
+
+sub _determine_wh_and_bin {
+  $::lxdebug->enter_sub(2);
+
+  my ($conf, $part_id) = @_;
+
+  my $part = SL::DB::Part->new(id => $part_id)->load;
+
+  if ($part->is_service && !$conf->get_transfer_default_services) {
+    $::lxdebug->leave_sub(2);
+    return;
+  }
+    
+
+  my $wh_id  = $part->warehouse_id;
+  my $bin_id = $part->bin_id;
+
+  if (!$wh_id && !$bin_id && $conf->get_transfer_default_ignore_onhand) {
+    $wh_id  = $conf->get_warehouse_id_ignore_onhand;
+    $bin_id = $conf->get_bin_id_ignore_onhand;
+  }
+
+  $::lxdebug->leave_sub(2);
+  return ($wh_id, $bin_id);
+}
+
 sub _delete_payments {
   $main::lxdebug->enter_sub();