X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FInventory.pm;h=f20f6aee8d5de286f2d7faf777ae763f1464700b;hb=44ed4e99507c6de660029eabad6b3ccdc7ab5fd6;hp=792aa2c9b9385e1693b7dea395a1e8d132c29dd5;hpb=51072516787d639c5f8df4d487155b4a66b16d6f;p=kivitendo-erp.git diff --git a/SL/Controller/Inventory.pm b/SL/Controller/Inventory.pm index 792aa2c9b..f20f6aee8 100644 --- a/SL/Controller/Inventory.pm +++ b/SL/Controller/Inventory.pm @@ -30,13 +30,13 @@ use Rose::Object::MakeMethods::Generic ( __PACKAGE__->run_before('_check_auth'); __PACKAGE__->run_before('_check_warehouses'); -__PACKAGE__->run_before('load_part_from_form', only => [ qw(stock_in part_changed mini_stock stock stocktaking_part_changed save_stocktaking) ]); -__PACKAGE__->run_before('load_unit_from_form', only => [ qw(stock_in part_changed mini_stock stock stocktaking_part_changed save_stocktaking) ]); -__PACKAGE__->run_before('load_wh_from_form', only => [ qw(stock_in warehouse_changed stock stocktaking save_stocktaking) ]); -__PACKAGE__->run_before('load_bin_from_form', only => [ qw(stock_in stock stocktaking save_stocktaking) ]); +__PACKAGE__->run_before('load_part_from_form', only => [ qw(stock_in part_changed mini_stock stock stocktaking_part_changed stocktaking_get_warn_qty_threshold save_stocktaking) ]); +__PACKAGE__->run_before('load_unit_from_form', only => [ qw(stock_in part_changed mini_stock stock stocktaking_part_changed stocktaking_get_warn_qty_threshold save_stocktaking) ]); +__PACKAGE__->run_before('load_wh_from_form', only => [ qw(stock_in warehouse_changed stock stocktaking stocktaking_get_warn_qty_threshold save_stocktaking) ]); +__PACKAGE__->run_before('load_bin_from_form', only => [ qw(stock_in stock stocktaking stocktaking_get_warn_qty_threshold save_stocktaking) ]); __PACKAGE__->run_before('set_target_from_part', only => [ qw(part_changed) ]); __PACKAGE__->run_before('mini_stock', only => [ qw(stock_in mini_stock) ]); -__PACKAGE__->run_before('sanitize_target', only => [ qw(stock_usage stock_in warehouse_changed part_changed stocktaking stocktaking_part_changed save_stocktaking) ]); +__PACKAGE__->run_before('sanitize_target', only => [ qw(stock_usage stock_in warehouse_changed part_changed stocktaking stocktaking_part_changed stocktaking_get_warn_qty_threshold save_stocktaking) ]); __PACKAGE__->run_before('set_layout'); sub action_stock_in { @@ -58,7 +58,6 @@ sub action_stock_usage { $::form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS', }); - $::request->layout->use_javascript("${_}.js") for qw(kivi.PartsWarehouse); $self->setup_stock_usage_action_bar; $self->render('inventory/warehouse_usage', @@ -411,13 +410,13 @@ sub action_stock { qty => $qty, unit => $self->unit, transfer_type => 'stock', + transfer_type_id => $::form->{transfer_type_id}, chargenumber => $::form->{chargenumber}, bestbefore => $::form->{bestbefore}, - ean => $::form->{ean}, comment => $::form->{comment}, }); 1; - } or do { $transfer_error = $EVAL_ERROR->getMessage; } + } or do { $transfer_error = $EVAL_ERROR->error; } }); if (!$transfer_error) { @@ -498,6 +497,9 @@ sub action_stocktaking { sub action_save_stocktaking { my ($self) = @_; + return $self->js->flash('error', t8('Please choose a part.'))->render() + if !$::form->{part_id}; + return $self->js->flash('error', t8('A target quantitiy has to be given'))->render() if $::form->{target_qty} eq ''; @@ -565,7 +567,7 @@ sub action_save_stocktaking { stocktaking_cutoff_date => $::form->{cutoff_date_as_date}, }); 1; - } or do { $transfer_error = $EVAL_ERROR->getMessage; } + } or do { $transfer_error = $EVAL_ERROR->error; } }); return $self->js->flash('error', $transfer_error)->render() @@ -603,6 +605,35 @@ sub action_stocktaking_journal { $self->prepare_stocktaking_report(full => 1); $self->report_generator_list_objects(report => $self->{report}, objects => $self->stocktaking_models->get); } + +sub action_stocktaking_get_warn_qty_threshold { + my ($self) = @_; + + return $_[0]->render(\ !!0, { type => 'text' }) if !$::form->{part_id}; + return $_[0]->render(\ !!0, { type => 'text' }) if $::form->{target_qty} eq ''; + return $_[0]->render(\ !!0, { type => 'text' }) if 0 == $::instance_conf->get_stocktaking_qty_threshold; + + my $target_qty = $::form->parse_amount(\%::myconfig, $::form->{target_qty}); + my $stocked_qty = _get_stocked_qty($self->part, + warehouse_id => $self->warehouse->id, + bin_id => $self->bin->id, + chargenumber => $::form->{chargenumber}, + bestbefore => $::form->{bestbefore},); + my $stocked_qty_in_form_units = $self->part->unit_obj->convert_to($stocked_qty, $self->unit); + my $qty = $target_qty - $stocked_qty_in_form_units; + $qty = abs($qty); + + my $warn; + if ($qty > $::instance_conf->get_stocktaking_qty_threshold) { + $warn = t8('The target quantity of #1 differs more than the threshold quantity of #2.', + $::form->{target_qty} . " " . $self->unit->name, + $::form->format_amount(\%::myconfig, $::instance_conf->get_stocktaking_qty_threshold, 2)); + $warn .= "\n"; + $warn .= t8('Choose "continue" if you want to use this value. Choose "cancel" otherwise.'); + } + return $_[0]->render(\ $warn, { type => 'text' }); +} + #================================================================ sub _check_auth { @@ -696,7 +727,7 @@ sub sanitize_target { } sub load_part_from_form { - $_[0]->part(SL::DB::Manager::Part->find_by_or_create(id => $::form->{part_id})); + $_[0]->part(SL::DB::Manager::Part->find_by_or_create(id => $::form->{part_id}||undef)); } sub load_unit_from_form { @@ -930,6 +961,7 @@ sub setup_stock_stocktaking_action_bar { $bar->add( action => [ t8('Save'), + checks => [ 'kivi.Inventory.check_stocktaking_qty_threshold' ], call => [ 'kivi.Inventory.save_stocktaking' ], accesskey => 'enter', ], @@ -1016,9 +1048,16 @@ and the current employee. The history is displayed via javascript. This action is called after the user selected or changed the part. +=item C + +This action checks if a warning should be shown and returns the warning text via +ajax. The warning will be shown if the given target value is greater than the +threshold given in the client configuration. + =item C This is a method to check if actions are called from stocktaking form. +This actions should contain "stocktaking" in their name. =back