Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a88f2c21

Von Bernd Bleßmann vor 4 Monaten hinzugefügt

  • ID a88f2c21ec0bea966d4c9e4c37fed6ff5438f4c3
  • Vorgänger 2373e0a8
  • Nachfolger 756f5042

Zwischeninventur-Abgleich: nur eine Zählung gleichzeitig abgleichen können

Unterschiede anzeigen:

SL/Controller/StockCountingReconciliation.pm
14 14
use SL::DB::StockCountingItem;
15 15
use SL::Helper::Flash qw(flash_later);
16 16
use SL::Helper::Number qw(_format_total);
17
use SL::JSON;
18 17
use SL::Locale::String qw(t8);
19
use SL::Presenter::Tag qw(checkbox_tag);
20 18
use SL::ReportGenerator;
21 19
use SL::WH;
22 20

  
......
84 82
sub action_reconcile {
85 83
  my ($self) = @_;
86 84

  
87
  my @transfer_errors;
88

  
89
  foreach my $selection (@{$::form->{ids}}) {
90
    my $ids               = SL::JSON::from_json($selection);
91
    my @counting_item_ids = split ',', $ids;
92
    my $counting_items    = SL::DB::Manager::StockCountingItem->get_all(query => [id => \@counting_item_ids]);
93

  
94
    my $counted_qty       = sum0 map { $_->qty } @$counting_items;
95
    my $stocked_qty       = $counting_items->[0]->part->get_stock(bin_id => $counting_items->[0]->bin_id);
96

  
97
    my $comment           = t8('correction from stock counting (counting "#1")', $counting_items->[0]->counting->name);
98

  
99
    my $transfer_qty      = $counted_qty - $stocked_qty;
100
    my $src_or_dst        = $transfer_qty < 0? 'src' : 'dst';
101
    $transfer_qty         = abs($transfer_qty);
102

  
103
    my $transfer_error;
104
    # do stock
105
    $::form->throw_on_error(sub {
106
      eval {
107
        WH->transfer({
108
          parts                   => $counting_items->[0]->part,
109
          $src_or_dst.'_bin'      => $counting_items->[0]->bin,
110
          $src_or_dst.'_wh'       => $counting_items->[0]->bin->warehouse,
111
          qty                     => $transfer_qty,
112
          unit                    => $counting_items->[0]->part->unit,
113
          transfer_type           => 'correction',
114
          comment                 => $comment,
115
        });
116
        1;
117
      } or do { $transfer_error = ref($EVAL_ERROR) eq 'SL::X::FormError' ? $EVAL_ERROR->error : $EVAL_ERROR; }
118
    });
119

  
120
    push @transfer_errors, $transfer_error if $transfer_error;
121
  }
122

  
123
  if (@transfer_errors) {
124
    flash_later('error', @transfer_errors);
85
  my $counting_id    = $::form->{filter}->{counting_id};
86
  my $counting_items = SL::DB::Manager::StockCountingItem->get_all(query => [counting_id => $counting_id]);
87

  
88
  my $counted_qty    = sum0 map { $_->qty } @$counting_items;
89
  my $stocked_qty    = $counting_items->[0]->part->get_stock(bin_id => $counting_items->[0]->bin_id);
90

  
91
  my $comment        = t8('correction from stock counting (counting "#1")', $counting_items->[0]->counting->name);
92

  
93
  my $transfer_qty   = $counted_qty - $stocked_qty;
94
  my $src_or_dst     = $transfer_qty < 0? 'src' : 'dst';
95
  $transfer_qty      = abs($transfer_qty);
96

  
97
  my $transfer_error;
98
  # do stock
99
  $::form->throw_on_error(sub {
100
    eval {
101
      WH->transfer({
102
        parts                   => $counting_items->[0]->part,
103
        $src_or_dst.'_bin'      => $counting_items->[0]->bin,
104
        $src_or_dst.'_wh'       => $counting_items->[0]->bin->warehouse,
105
        qty                     => $transfer_qty,
106
        unit                    => $counting_items->[0]->part->unit,
107
        transfer_type           => 'correction',
108
        comment                 => $comment,
109
      });
110
      1;
111
    } or do { $transfer_error = ref($EVAL_ERROR) eq 'SL::X::FormError' ? $EVAL_ERROR->error : $EVAL_ERROR; }
112
  });
113

  
114
  if ($transfer_error) {
115
    flash_later('error', $transfer_error);
125 116
  } else {
126 117
    flash_later('info', t8('successfully reconciled'));
127 118
  }
......
158 149
  my @columns = qw(ids counting part bin qty stocked);
159 150

  
160 151
  my %column_defs = (
161
    ids        => { raw_header_data => checkbox_tag("", id => "check_all", checkall  => "[data-checkall=1]"),
162
                    align    => 'center',
163
                    raw_data => sub { $_[0]->correction_inventory_id ? '' : checkbox_tag("ids[]", value => SL::JSON::to_json($_[0]->id), "data-checkall" => 1) }   },
164 152
    counting   => { text => t8('Stock Counting'), sub => sub { $_[0]->counting->name }, },
165 153
    counted_at => { text => t8('Counted At'),     sub => sub { $_[0]->counted_at_as_timestamp }, },
166 154
    qty        => { text => t8('Qty'),            sub => sub { $_[0]->qty_as_number }, align => 'right' },

Auch abrufbar als: Unified diff