]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/Controller/Inventory.pm
OrderController: reorder mit Sort::Naturally damit nach Preis ordentlich
[kivitendo-erp.git] / SL / Controller / Inventory.pm
index 792aa2c9b9385e1693b7dea395a1e8d132c29dd5..bd57d7849b383f286822e24cbc2d1f12d281ebc1 100644 (file)
@@ -30,13 +30,13 @@ use Rose::Object::MakeMethods::Generic (
 
 __PACKAGE__->run_before('_check_auth');
 __PACKAGE__->run_before('_check_warehouses');
 
 __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('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 {
 __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', });
 
   $::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',
 
   $self->setup_stock_usage_action_bar;
   $self->render('inventory/warehouse_usage',
@@ -411,9 +410,9 @@ sub action_stock {
           qty           => $qty,
           unit          => $self->unit,
           transfer_type => 'stock',
           qty           => $qty,
           unit          => $self->unit,
           transfer_type => 'stock',
+          transfer_type_id => $::form->{transfer_type_id},
           chargenumber  => $::form->{chargenumber},
           bestbefore    => $::form->{bestbefore},
           chargenumber  => $::form->{chargenumber},
           bestbefore    => $::form->{bestbefore},
-          ean           => $::form->{ean},
           comment       => $::form->{comment},
         });
         1;
           comment       => $::form->{comment},
         });
         1;
@@ -498,6 +497,9 @@ sub action_stocktaking {
 sub action_save_stocktaking {
   my ($self) = @_;
 
 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 '';
 
   return $self->js->flash('error', t8('A target quantitiy has to be given'))->render()
     if $::form->{target_qty} eq '';
 
@@ -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);
 }
   $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 {
 #================================================================
 
 sub _check_auth {
@@ -696,7 +727,7 @@ sub sanitize_target {
 }
 
 sub load_part_from_form {
 }
 
 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 {
 }
 
 sub load_unit_from_form {
@@ -930,6 +961,7 @@ sub setup_stock_stocktaking_action_bar {
     $bar->add(
       action => [
         t8('Save'),
     $bar->add(
       action => [
         t8('Save'),
+        checks    => [ 'kivi.Inventory.check_stocktaking_qty_threshold' ],
         call      => [ 'kivi.Inventory.save_stocktaking' ],
         accesskey => 'enter',
       ],
         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.
 
 
 This action is called after the user selected or changed the part.
 
+=item C<action_stocktaking_get_warn_qty_threshold>
+
+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<is_stocktaking>
 
 This is a method to check if actions are called from stocktaking form.
 =item C<is_stocktaking>
 
 This is a method to check if actions are called from stocktaking form.
+This actions should contain "stocktaking" in their name.
 
 =back
 
 
 =back