|
|
@@ -5,6 +5,7 @@ namespace App\Services;
|
|
|
|
|
|
|
|
|
use App\MaterialBox;
|
|
|
+use App\MaterialBoxModel;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
use App\Storage;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
@@ -21,12 +22,12 @@ class MaterialBoxService
|
|
|
/**
|
|
|
* 获取一个空料箱
|
|
|
*
|
|
|
+ * @param MaterialBoxModel|\stdClass $model
|
|
|
* @param array $blacklist
|
|
|
- * @param integer|null $modelId
|
|
|
*
|
|
|
* @return MaterialBox|null
|
|
|
*/
|
|
|
- public function getAnEmptyBox(array $blacklist = [], $modelId = null)
|
|
|
+ public function getAnEmptyBox(MaterialBoxModel $model,array $blacklist = []):?MaterialBox
|
|
|
{
|
|
|
$id = 0;
|
|
|
while (true){
|
|
|
@@ -36,8 +37,8 @@ class MaterialBoxService
|
|
|
->where("id",">",$id)->where("code","like","IDE%")
|
|
|
->where("status",4)->limit(50)->orderBy("id")
|
|
|
->whereNotIn("id",StationTaskMaterialBox::query()->select("material_box_id")
|
|
|
- ->where("status","!=","完成")->groupBy("material_box_id"));
|
|
|
- if ($modelId)$boxes->where("material_box_model_id",$modelId);
|
|
|
+ ->whereNotIn("status",["完成","取消"])
|
|
|
+ ->where("material_box_model_id",$model->id)->groupBy("material_box_id"));
|
|
|
$boxes = $boxes->get();
|
|
|
if ($boxes->count()==0)break;
|
|
|
$id = $boxes[count($boxes)-1]->id;
|
|
|
@@ -53,7 +54,7 @@ class MaterialBoxService
|
|
|
->whereNotIn("status",[0,4])->get();
|
|
|
$haiBoxes->each(function ($haiBox)use(&$notCodes){$notCodes[$haiBox->bin_code] = true;});
|
|
|
|
|
|
- //检测FLUX
|
|
|
+ //剔除FLUX已有库存并且库位内种类超出的料箱
|
|
|
$ides = [];
|
|
|
$str = "(";
|
|
|
foreach ($boxes as $box){
|
|
|
@@ -64,17 +65,33 @@ class MaterialBoxService
|
|
|
if (!$ides)continue;
|
|
|
$str = rtrim($str,",").")";
|
|
|
$sql = <<<sql
|
|
|
-SELECT LOCATIONID,SUM(QTY+QTYPA) qty FROM INV_LOT_LOC_ID WHERE LOCATIONID IN {$str} GROUP BY LOCATIONID
|
|
|
+SELECT LOCATIONID FROM (SELECT LOCATIONID FROM (SELECT LOCATIONID,SUM(QTY+QTYPA) qty FROM INV_LOT_LOC_ID WHERE LOCATIONID IN {$str} GROUP BY LOCATIONID,LOTNUM,CUSTOMERID,SKU) where qty>0) GROUP BY
|
|
|
+ LOCATIONID HAVING (COUNT(*)>={$model->maximum_kind});
|
|
|
sql;
|
|
|
- foreach (DB::connection("oracle")->select(DB::raw($sql)) as $item){
|
|
|
- if ((int)$item->qty==0)return $ides[$item->locationid];
|
|
|
- unset($ides[$item->locationid]);
|
|
|
- }
|
|
|
+ foreach (DB::connection("oracle")->select(DB::raw($sql)) as $item)unset($ides[$item->locationid]);
|
|
|
if ($ides)return current($ides);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取所有者排序的空盒子
|
|
|
+ *
|
|
|
+ * @param integer|null $ownerId
|
|
|
+ * @param array $blacklist
|
|
|
+ *
|
|
|
+ * @return MaterialBox|null
|
|
|
+ */
|
|
|
+ public function getAnEmptyBoxSortedByOwner(?int $ownerId=null, array $blacklist=[]):?MaterialBox
|
|
|
+ {
|
|
|
+ $models = app("MaterialBoxModelService")->getModelSortedByOwner($ownerId);
|
|
|
+ foreach ($models as $model){
|
|
|
+ $box = $this->getAnEmptyBox($model,$blacklist);
|
|
|
+ if ($box)return $box;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取料箱所在库区
|
|
|
*
|