|
|
@@ -81,8 +81,9 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
|
|
|
$errors[] = "第“" . ($index + 2) . "”行未知订单商品";
|
|
|
continue;
|
|
|
}
|
|
|
- $sql = "select INV_LOT_LOC_ID.LOCATIONID,INV_LOT_LOC_ID.LOTNUM,BAS_LOCATION.PICKZONE,INV_LOT_LOC_ID.QTY from INV_LOT_ATT LEFT JOIN
|
|
|
+ $sql = "select BAS_ZONE.DESCR,INV_LOT_LOC_ID.LOCATIONID,INV_LOT_LOC_ID.LOTNUM,BAS_LOCATION.PICKZONE,(INV_LOT_LOC_ID.QTY-INV_LOT_LOC_ID.QTYALLOCATED) AS qty from INV_LOT_ATT LEFT JOIN
|
|
|
INV_LOT_LOC_ID ON INV_LOT_ATT.LOTNUM = INV_LOT_LOC_ID.LOTNUM LEFT JOIN BAS_LOCATION ON INV_LOT_LOC_ID.LOCATIONID = BAS_LOCATION.LOCATIONID
|
|
|
+ LEFT JOIN BAS_ZONE ON BAS_LOCATION.PICKZONE = BAS_ZONE.ZONE
|
|
|
where INV_LOT_ATT.LOTNUM in (select LOTNUM from INV_LOT_LOC_ID where CUSTOMERID = ? AND SKU = ? GROUP BY LOTNUM)";
|
|
|
$bindings = [$detail->customerid,$detail->sku];
|
|
|
if ($item["生产日期"]){
|
|
|
@@ -94,26 +95,29 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
|
|
|
$bindings[] = $item["失效日期"];
|
|
|
}else $sql .= " AND LOTATT02 IS NULL";
|
|
|
|
|
|
- $lot = DB::connection("oracle")->select(DB::raw($sql),$bindings);
|
|
|
- if (!$lot){
|
|
|
+ $lots = DB::connection("oracle")->select(DB::raw($sql),$bindings);
|
|
|
+ if (!$lots){
|
|
|
$errors[] = "第“" . ($index + 2) . "”行未找到库位";
|
|
|
continue;
|
|
|
}
|
|
|
$result = null;
|
|
|
- if (count($lot)>1){
|
|
|
- $min = null;
|
|
|
- $max = null;
|
|
|
- $map = [];
|
|
|
- foreach ($lot as $i => $l){
|
|
|
- $qty = (int)$l->qty;
|
|
|
- $map[$qty] = $i;
|
|
|
- if (($qty >= (int)$item["数量"] && $qty<=$max) || $max===null)$max = $qty;
|
|
|
- if (($qty < (int)$item["数量"] && $qty>=$min) || $min===null)$min = $qty;
|
|
|
+ if (count($lots) == 1)$result = $lots[0];
|
|
|
+ else {
|
|
|
+ $zone = ["拣货区","存储区","虚拟库区"];
|
|
|
+ $zones = [];
|
|
|
+ foreach ($lots as $lot){
|
|
|
+ foreach ($zone as $index=>$str){
|
|
|
+ if (mb_strpos($lot->descr,$str) !== false){
|
|
|
+ $zones[$index][] = $lot;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($zones as $zl){
|
|
|
+ $result = $this->matching($zl,$item["数量"]);
|
|
|
+ if ($result)break;
|
|
|
}
|
|
|
- if ($max !== null)$result = $lot[$map[$max]];
|
|
|
- else $result = $lot[$map[$min]];
|
|
|
}
|
|
|
- if (count($lot) == 1)$result = $lot[0];
|
|
|
if ($result){
|
|
|
try{
|
|
|
$sql = "UPDATE DOC_ORDER_DETAILS SET LOTNUM = ?,PICKZONE = ?,KITREFERENCENO = ?,D_EDI_09 = ?,D_EDI_10 = ? WHERE ORDERNO = ? AND ORDERLINENO = ?";
|
|
|
@@ -165,4 +169,21 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
|
|
|
}
|
|
|
Cache::put("commodityAssign",["success"=>true,"data"=>$models,"errors"=>$errors]);
|
|
|
}
|
|
|
+
|
|
|
+ private function matching($lots, $amount)
|
|
|
+ {
|
|
|
+ if (!$lots) return null;
|
|
|
+ $min = null;
|
|
|
+ $max = null;
|
|
|
+ $map = [];
|
|
|
+ foreach ($lots as $i => $l){
|
|
|
+ $qty = (int)$l->qty;
|
|
|
+ $map[$qty] = $i;
|
|
|
+ if (($qty >= $amount && $qty<=$max) || $max===null)$max = $qty;
|
|
|
+ if (($qty < $amount && $qty>=$min) || $min===null)$min = $qty;
|
|
|
+ }
|
|
|
+ if ($max !== null)return $lots[$map[$max]];
|
|
|
+ if ($min !== null)return $lots[$map[$min]];
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|