Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 227cd5b4

Von Tamino Steinert vor 9 Tagen hinzugefügt

  • ID 227cd5b4bfa41789b57371783f5cda554a04d72b
  • Vorgänger 8c002d8d
  • Nachfolger 0511a34b

FIX: S:C:DeliverOrder: Überprüfen der Lagerbewegungen auf Bestand

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
48 48
use SL::Helper::CreatePDF qw(:all);
49 49
use SL::Helper::PrintOptions;
50 50
use SL::Helper::ShippedQty;
51
use SL::Helper::Inventory;
52
use SL::Helper::DateTime;
51 53
use SL::Helper::UserPreferences::DisplayPreferences;
52 54
use SL::Helper::UserPreferences::PositionsScrollbar;
53 55
use SL::Helper::UserPreferences::UpdatePositions;
......
1140 1142
  }
1141 1143

  
1142 1144
  SL::DB->client->with_transaction(sub {
1145
    if ($inout eq 'out') { # check stock for enough qty
1146
      # part_id -> bin_id -> chargenumber -> bestbefore -> qty;
1147
      my $grouped_qtys;
1148
      foreach my $request (@transfer_requests) {
1149
        $grouped_qtys
1150
          ->{$request->parts_id}
1151
          ->{$request->bin_id}
1152
          ->{$request->chargenumber}
1153
          ->{$request->bestbefore} += -$request->qty # qty is negative
1154
      }
1155

  
1156
      my @missing_qtys;
1157
      foreach my $p_id (keys %{$grouped_qtys}) {
1158
        foreach my $b_id (keys %{$grouped_qtys->{$p_id}}) {
1159
          next if $default_transfer
1160
               && $::instance_conf->get_transfer_default_ignore_onhand
1161
               && $::instance_conf->get_bin_id_ignore_onhand eq $b_id;
1162
          foreach my $cn (keys %{$grouped_qtys->{$p_id}->{$b_id}}) {
1163
            foreach my $bb (keys %{$grouped_qtys->{$p_id}->{$b_id}->{$cn}}) {
1164
              my $stock = SL::Helper::Inventory::get_stock(
1165
                part         => $p_id,
1166
                bin          => $b_id,
1167
                chargenumber => $cn,
1168
                bestbefore   => DateTime->from_ymdhms($bb) || undef,
1169
              );
1170
              if ($stock < $grouped_qtys->{$p_id}->{$b_id}->{$cn}->{$bb}) {
1171
                my $part = SL::DB::Manager::Part->find_by(id => $p_id);
1172
                my $bin  = SL::DB::Manager::Bin->find_by(id => $b_id);
1173
                push @missing_qtys, {
1174
                  missing_qty  => $grouped_qtys->{$p_id}->{$b_id}->{$cn}->{$bb} - $stock,
1175
                  part         => $part,
1176
                  bin          => $bin,
1177
                  chargenumber => $cn,
1178
                  bestbefore   => $bb
1179
                }
1180
              }
1181
            }
1182
          }
1183
        }
1184
      }
1185
      if (scalar @missing_qtys) {
1186
        die t8('The stock is to low: #1.',
1187
          join(". ", map {
1188
              t8(
1189
                "For #1, #2 #3 are missing",
1190
                $_->{part}->displayable_name,
1191
                $::form->format_amount(\%::myconfig, $_->{missing_qty}),
1192
                $_->{part}->unit,
1193
              ) . (
1194
                $_->{chargenumber} ?
1195
                  " " . t8("of batch with chargenumber #1", $_->{chargenumber})
1196
                : ''
1197
              ) . (
1198
                $_->{chargenumber} && $_->{bestbefore} ?
1199
                  " " . t8("and")
1200
                : ''
1201
              ) . (
1202
                $_->{bestbefore} ?
1203
                " " . t8(
1204
                        "with a bestbefore date of #1",
1205
                        DateTime->from_ymdhms($_->{bestbefore})->to_kivitendo
1206
                      )
1207
                : ''
1208
              ) . " " . t8(
1209
                "in bin #1", $_->{bin}->full_description
1210
              )
1211
            } @missing_qtys
1212
          )
1213
        );
1214
      }
1215
    }
1216

  
1143 1217
    $_->save for @transfer_requests;
1144 1218
    $self->order->update_attributes(delivered => 1);
1145 1219
  });

Auch abrufbar als: Unified diff