]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Inventory.pm
restart apache2 in postinst
[mfinanz.git] / SL / Controller / Inventory.pm
index 479c9ad22d6552af94418ba4313117ba503e9a96..6940b2eb5b7234db6abc8049a4abaf3cb6594de5 100644 (file)
@@ -45,6 +45,12 @@ sub action_stock_in {
 
   $::form->{title}   = t8('Stock');
 
+  # Sometimes we want to open stock_in with a part already selected, but only
+  # the parts_id is passed in the url (and not also warehouse, bin and unit).
+  # Setting select_default_bin in the form will make sure the default warehouse
+  # and bin of that part will already be preselected, as normally
+  # set_target_from_part is only called when a part is changed.
+  $self->set_target_from_part if $::form->{select_default_bin};
   $::request->layout->focus('#part_id_name');
   my $transfer_types = WH->retrieve_transfer_types('in');
   map { $_->{description} = $main::locale->text($_->{description}) } @{ $transfer_types };
@@ -388,7 +394,7 @@ sub make_row_result {
        $row->{outcorrection}->{data} - $row->{incorrection}->{data};
   $row->{averconsumed}->{data} = $row->{consumed}->{data}*30/$days ;
   map { $row->{$_}->{data} = $form->format_amount($myconfig,$row->{$_}->{data},2); } $self->getnumcolumns();
-  $row->{partnumber}->{link} = 'controller.pl?action=Part/edit&part.id' . $partid;
+  $row->{partnumber}->{link} = 'controller.pl?action=Part/edit&part.id=' . $partid;
 }
 
 sub action_stock {
@@ -568,7 +574,7 @@ sub action_save_stocktaking {
         stocktaking_cutoff_date => $::form->{cutoff_date_as_date},
       });
       1;
-    } or do { $transfer_error = $EVAL_ERROR->error; }
+    } or do { $transfer_error = ref($EVAL_ERROR) eq 'SL::X::FormError' ? $EVAL_ERROR->error : $EVAL_ERROR; }
   });
 
   return $self->js->flash('error', $transfer_error)->render()
@@ -698,7 +704,7 @@ sub init_stocktaking_cutoff_date {
   my $now    = DateTime->now_local;
   my $cutoff = DateTime->new(year => $now->year, month => 12, day => 31);
   if ($now->month < 1) {
-    $cutoff->substract(years => 1);
+    $cutoff->subtract(years => 1);
   }
   return $cutoff;
 }
@@ -716,7 +722,7 @@ sub sanitize_target {
   my ($self) = @_;
 
   $self->warehouse($self->warehouses->[0])       if !$self->warehouse || !$self->warehouse->id;
-  $self->bin      ($self->warehouse->bins->[0])  if !$self->bin       || !$self->bin->id;
+  $self->bin      ($self->warehouse->bins_sorted_naturally->[0])  if !$self->bin       || !$self->bin->id;
 #  foreach my $warehouse ( $self->warehouses ) {
 #      $warehouse->{BINS} = [];
 #      foreach my $bin ( $self->bins ) {
@@ -762,7 +768,7 @@ sub build_warehouse_select {
 }
 
 sub build_bin_select {
-  select_tag('bin_id', [ $_[0]->warehouse->bins ],
+  select_tag('bin_id', $_[0]->warehouse->bins_sorted_naturally,
     title_key => 'description',
     default   => $_[0]->bin->id,
   );
@@ -806,7 +812,7 @@ grouped_ids as (
      from last_inventories
  group by trans_id
  order by max(itime)
-     desc limit 10
+     desc limit 20
 )
 select unnest(ids)
   from grouped_ids
@@ -814,7 +820,7 @@ select unnest(ids)
 SQL
 
   my $objs  = SL::DB::Manager::Inventory->get_all(
-    query        => [ id => [ \"$query" ] ],
+    query        => [ id => [ \"$query" ] ],                           # " make emacs happy
     with_objects => [ 'parts', 'trans_type', 'bin', 'bin.warehouse' ], # prevent lazy loading in template
     sort_by      => 'itime DESC',
   );
@@ -861,8 +867,9 @@ sub prepare_stocktaking_report {
 
   my $callback    = $self->stocktaking_models->get_callback;
 
-  my $report      = SL::ReportGenerator->new(\%::myconfig, $::form);
-  $self->{report} = $report;
+  my $report       = SL::ReportGenerator->new(\%::myconfig, $::form);
+  $report->{title} = t8('Stocktaking Journal');
+  $self->{report}  = $report;
 
   my @columns     = qw(itime employee ean partnumber part qty unit bin chargenumber comment cutoff_date);
   my @sortable    = qw(itime employee ean partnumber part qty bin chargenumber comment cutoff_date);
@@ -947,7 +954,7 @@ sub _already_counted {
 
   my %bestbefore_filter;
   if ($::instance_conf->get_show_bestbefore) {
-    %bestbefore_filter = (bestbefore => $params{bestbefore});
+    %bestbefore_filter = (bestbefore => ($params{bestbefore} || undef));
   }
 
   SL::DB::Manager::Stocktaking->get_all(query => [and => [parts_id     => $part->id,