]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/CsvImport/Inventory.pm
Rechnungen: Zahlungsein-/-ausgänge nach Datum sortieren
[mfinanz.git] / SL / Controller / CsvImport / Inventory.pm
index 16debc0933dca151db368c076c5263f68c490684..e35aac65b18b6ed4071887fb66d519de5b974232 100644 (file)
@@ -28,6 +28,9 @@ sub init_class {
   $self->class('SL::DB::Inventory');
 }
 
+sub set_profile_defaults {
+};
+
 sub init_profile {
   my ($self) = @_;
 
@@ -145,7 +148,7 @@ sub check_warehouse {
     $object->warehouse_id($wh->id);
   }
 
-  # Check wether or not warehouse ID is valid.
+  # Check whether or not warehouse ID is valid.
   if ($object->warehouse_id && !$self->warehouses_by->{id}->{ $object->warehouse_id }) {
     push @{ $entry->{errors} }, $::locale->text('Error: Invalid warehouse');
     return 0;
@@ -203,12 +206,12 @@ sub check_bin {
     $object->bin_id($bin->id);
   }
 
-  # Check wether or not bin ID is valid.
+  # Check whether or not bin ID is valid.
   if ($object->bin_id && !$self->bins_by->{_wh_id_and_id_ident()}->{ _wh_id_and_id_maker($object->warehouse_id, $object->bin_id) }) {
     push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin');
     return 0;
   }
-  
+
   # Map description to ID if given.
   if (!$object->bin_id && $entry->{raw_data}->{bin}) {
     my $bin = $self->bins_by->{_wh_id_and_description_ident()}->{ _wh_id_and_description_maker($object->warehouse_id, $entry->{raw_data}->{bin}) };
@@ -235,7 +238,7 @@ sub check_part {
 
   my $object = $entry->{object};
 
-  # Check wether or non part ID is valid.
+  # Check whether or not part ID is valid.
   if ($object->parts_id && !$self->parts_by->{id}->{ $object->parts_id }) {
     push @{ $entry->{errors} }, $::locale->text('Error: Invalid part');
     return 0;
@@ -286,15 +289,17 @@ sub check_qty{
   }
 
   # Actual quantity is read from stock or is the result of transfers for the
-  # same part, warehouse and bin done before.
-  my $key = join '+', $object->parts_id, $object->warehouse_id, $object->bin_id;
+  # same part, warehouse, bin and chargenumber done before.
+  my $key = join '+', $object->parts_id, $object->warehouse_id, $object->bin_id, $object->chargenumber;
   if (!exists $self->{resulting_quantities}->{$key}) {
-    my $stock = $object->part->get_simple_stock;
-    my @stocked = grep { $_->{warehouse_id} == $object->warehouse_id && $_->{bin_id} == $object->bin_id } @$stock;
-    my $stocked_qty = 0;
-    foreach (@stocked) {
-      $stocked_qty += $stocked[0]->{sum} * 1;
-    }
+    my $query = <<SQL;
+      SELECT sum(qty) FROM inventory
+        WHERE parts_id = ? AND warehouse_id = ? AND bin_id = ? AND chargenumber = ?
+        GROUP BY warehouse_id, bin_id, chargenumber
+SQL
+
+    my ($stocked_qty) = selectrow_query($::form, $::form->get_standard_dbh, $query,
+                                        $object->parts_id, $object->warehouse_id, $object->bin_id, $object->chargenumber);
     $self->{resulting_quantities}->{$key} = $stocked_qty;
   }
   my $actual_qty = $self->{resulting_quantities}->{$key};