Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f4431e33

Von Bernd Bleßmann vor etwa 9 Jahren hinzugefügt

  • ID f4431e33ab04ab24446d60bf2fad06642980fac1
  • Vorgänger 0560b39e
  • Nachfolger 39c2e07d

Auslagern in VK-Rechnung: Mandantenkonfiguration vollständig berücksichtigen …

und Fehlerbehandlung verbessert.

Unterschiede anzeigen:

SL/IS.pm
1298 1298
sub transfer_out {
1299 1299
  $::lxdebug->enter_sub;
1300 1300

  
1301
  my ($self, $form) = @_; 
1301
  my ($self, $form, $dbh) = @_; 
1302 1302

  
1303
  my @transfers;
1303
  my (@errors, @transfers);
1304

  
1305
  # do nothing, if transfer default is not requeseted at all
1306
  if (!$::instance_conf->get_transfer_default) {
1307
    $::lxdebug->leave_sub;
1308
    return \@errors;
1309
  }
1310

  
1311
  require SL::WH;
1304 1312

  
1305 1313
  foreach my $i (1 .. $form->{rowcount}) {
1306 1314
    next if !$form->{"id_$i"};
1307
    my ($wh_id, $bin_id) = _determine_wh_and_bin($::instance_conf, $form->{"id_$i"});
1315
    my ($err, $wh_id, $bin_id) = _determine_wh_and_bin($dbh, $::instance_conf,
1316
                                                       $form->{"id_$i"},
1317
                                                       $form->{"qty_$i"},
1318
                                                       $form->{"unit_$i"});
1308 1319

  
1309
    if ($wh_id && $bin_id) {
1320
    if (!@{ $err } && $wh_id && $bin_id) {
1310 1321
      push @transfers, {
1311 1322
        'parts_id'         => $form->{"id_$i"},
1312 1323
        'qty'              => $form->{"qty_$i"},
......
1318 1329
        'invoice_id'       => $form->{"invoice_id_$i"},
1319 1330
      };
1320 1331
    }
1332

  
1333
    push @errors, @{ $err };
1321 1334
  }
1322 1335

  
1323
  require SL::WH;
1324
  WH->transfer(@transfers);
1336
  if (!@errors) {
1337
    WH->transfer(@transfers);
1338
  }
1325 1339

  
1326 1340
  $::lxdebug->leave_sub;
1327
  return 1;
1341
  return \@errors;
1328 1342
}
1329 1343

  
1330 1344
sub _determine_wh_and_bin {
1331 1345
  $::lxdebug->enter_sub(2);
1332 1346

  
1333
  my ($conf, $part_id) = @_;
1347
  my ($dbh, $conf, $part_id, $qty, $unit) = @_;
1348
  my @errors;
1334 1349

  
1335 1350
  my $part = SL::DB::Part->new(id => $part_id)->load;
1336 1351

  
1352
  # ignore service if they are not configured to be transfered
1337 1353
  if ($part->is_service && !$conf->get_transfer_default_services) {
1338 1354
    $::lxdebug->leave_sub(2);
1339 1355
    return;
1340 1356
  }
1341
    
1342 1357

  
1343
  my $wh_id  = $part->warehouse_id;
1344
  my $bin_id = $part->bin_id;
1358
  # test negative qty
1359
  if ($qty < 0) {
1360
    push @errors, $::locale->text("Cannot transfer negative quantities.");
1361
    return (\@errors);
1362
  }
1363

  
1364
  # get/test default bin
1365
  my ($default_wh_id, $default_bin_id);
1366
  if ($conf->get_transfer_default_use_master_default_bin) {
1367
    $default_wh_id  = $conf->get_warehouse_id if $conf->get_warehouse_id;
1368
    $default_bin_id = $conf->get_bin_id       if $conf->get_bin_id;
1369
  }
1370
  my $wh_id  = $part->warehouse_id || $default_wh_id;
1371
  my $bin_id = $part->bin_id       || $default_bin_id;
1372

  
1373
  # check qty and bin
1374
  if ($bin_id) {
1375
    my ($max_qty, $error) = WH->get_max_qty_parts_bin(dbh      => $dbh,
1376
                                                      parts_id => $part->id,
1377
                                                      bin_id   => $bin_id);
1378
    if ($error == 1) {
1379
      push @errors, $::locale->text("Part \"#1\" has chargenumber or best before date set. So it cannot be transfered automaticaly.",
1380
                                    $part->description);
1381
    }
1382
    my $form_unit_obj = SL::DB::Unit->new(name => $unit)->load;
1383
    my $part_unit_qty = $form_unit_obj->convert_to($qty, $part->unit_obj);
1384
    my $diff_qty      = $max_qty - $part_unit_qty;
1385
    if (!@errors && $diff_qty < 0) {
1386
      push @errors, $::locale->text("For part \"#1\" there are missing #2 #3 in the default warehouse/bin \"#4/#5\"",
1387
                                    $part->description, 
1388
                                    $::form->format_amount(\%::myconfig, -1*$diff_qty),
1389
                                    $part->unit_obj->name,
1390
                                    SL::DB::Warehouse->new(id => $wh_id)->load->description,
1391
                                    SL::DB::Bin->new(      id => $bin_id)->load->description);
1392
    }
1393
  } else {
1394
    push @errors, $::locale->text("For part \"#1\" there is no default warehouse and bin defined.",
1395
                                  $part->description);
1396
  }
1345 1397

  
1346
  if (!$wh_id && !$bin_id && $conf->get_transfer_default_ignore_onhand) {
1398
  # transfer to special "ignore onhand" bin if requested and default bin does not work
1399
  if (@errors && $conf->get_transfer_default_ignore_onhand && $conf->get_bin_id_ignore_onhand) {
1347 1400
    $wh_id  = $conf->get_warehouse_id_ignore_onhand;
1348 1401
    $bin_id = $conf->get_bin_id_ignore_onhand;
1402
    if ($wh_id && $bin_id) {
1403
      @errors = ();
1404
    } else {
1405
      push @errors, $::locale->text("For part \"#1\" there is no default warehouse and bin for ignoring onhand defined.",
1406
                                    $part->description);
1407
    }
1349 1408
  }
1350 1409

  
1351 1410
  $::lxdebug->leave_sub(2);
1352
  return ($wh_id, $bin_id);
1411
  return (\@errors, $wh_id, $bin_id);
1353 1412
}
1354 1413

  
1355 1414
sub _delete_transfers {

Auch abrufbar als: Unified diff