From: Bernd Bleßmann Date: Fri, 9 Oct 2015 11:58:31 +0000 (+0200) Subject: Lagerbewegungen/-bestände auch mit Mindesthaltbarkeitsdatum importieren können. X-Git-Tag: release-3.4.1~653 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=38b907c9866951e95c8741959b4ead1544e45011;p=kivitendo-erp.git Lagerbewegungen/-bestände auch mit Mindesthaltbarkeitsdatum importieren können. Auch hier kann es Probleme geben, wenn eine Installation zuerst das Mindeshaltbarkeitsdatum aktiviert hatte und es dann deaktiviert wird (siehe auch "System->Mandantenkonfiguration", Reiter "Lager" unter "Mindesthaltbarkeit anzeigen". --- diff --git a/SL/Controller/CsvImport/Inventory.pm b/SL/Controller/CsvImport/Inventory.pm index e35aac65b..42bfac3d0 100644 --- a/SL/Controller/CsvImport/Inventory.pm +++ b/SL/Controller/CsvImport/Inventory.pm @@ -35,7 +35,8 @@ sub init_profile { my ($self) = @_; my $profile = $self->SUPER::init_profile; - delete @{$profile}{qw(trans_id oe_id delivery_order_items_stock_id bestbefore trans_type_id project_id)}; + delete @{$profile}{qw(trans_id oe_id delivery_order_items_stock_id trans_type_id project_id)}; + delete @{$profile}{qw(bestbefore)} if !$::instance_conf->get_show_bestbefore; return $profile; } @@ -116,6 +117,9 @@ sub setup_displayable_columns { { name => 'warehouse', description => $::locale->text('Warehouse') }, { name => 'warehouse_id', description => $::locale->text('Warehouse (database ID)') }, ); + if ($::instance_conf->get_show_bestbefore) { + $self->add_displayable_columns({ name => 'bestbefore', description => $::locale->text('Best Before') }); + } } sub check_warehouse { @@ -289,18 +293,13 @@ sub check_qty{ } # Actual quantity is read from stock or is the result of transfers for the - # same part, warehouse, bin and chargenumber done before. + # same part, warehouse, bin, chargenumber and bestbefore date (if + # show_bestbefore is enabled) done before. my $key = join '+', $object->parts_id, $object->warehouse_id, $object->bin_id, $object->chargenumber; - if (!exists $self->{resulting_quantities}->{$key}) { - my $query = <bestbefore if $::instance_conf->get_show_bestbefore; - 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; + if (!exists $self->{resulting_quantities}->{$key}) { + $self->{resulting_quantities}->{$key} = _get_stocked_qty($object); } my $actual_qty = $self->{resulting_quantities}->{$key}; @@ -403,6 +402,33 @@ sub save_objects { $self->SUPER::save_objects(%params); } +sub _get_stocked_qty { + my ($object) = @_; + + my $bestbefore_filter = ''; + my $bestbefore_val_cnt = 0; + if ($::instance_conf->get_show_bestbefore) { + $bestbefore_filter = ($object->bestbefore) ? 'AND bestbefore = ?' : 'AND bestbefore IS NULL'; + $bestbefore_val_cnt = ($object->bestbefore) ? 1 : 0; + } + + my $query = <parts_id, + $object->warehouse_id, + $object->bin_id, + $object->chargenumber); + push @values, $object->bestbefore if $bestbefore_val_cnt; + + my ($stocked_qty) = selectrow_query($::form, $::form->get_standard_dbh, $query, @values); + + return $stocked_qty; +} + sub _wh_id_and_description_ident { return 'wh_id+description'; }