|
|
@@ -13,6 +13,7 @@ use App\Services\LogService;
|
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
+use App\Store;
|
|
|
use App\StoreItem;
|
|
|
use App\TaskTransaction;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
@@ -92,13 +93,48 @@ class StorageController extends Controller
|
|
|
*/
|
|
|
public function checkMaximum()
|
|
|
{
|
|
|
- $item = app("StoreItemService")->getMaxAvailableDetail(request("asn"),request("barCode"));
|
|
|
- if (!$item)$this->error("无此单据记录");
|
|
|
- $models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
|
|
|
+ $track = request("track");
|
|
|
+ $barCode = request("barCode");
|
|
|
+ $lotNum = request("lotNum");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT * FROM INV_LOT_ATT WHERE LOTNUM = '{$lotNum}'
|
|
|
+SQL;
|
|
|
+ $lot = DB::connection("oracle")->selectOne(DB::raw($sql));
|
|
|
+ if (!$lot)$this->error("批次丢失");
|
|
|
+ $commodity = Commodity::query()->whereHas("owner",function ($query)use($lot){
|
|
|
+ $query->where("code",$lot->customerid);
|
|
|
+ })->where("sku",$lot->sku)->first();
|
|
|
+ if (!$commodity)$this->error("WAS无此商品信息");
|
|
|
+ $models = CommodityMaterialBoxModel::query()->where("commodity_id",$commodity->id)->get();
|
|
|
if ($models->count()==0)$this->success(["material_box_model_id"=>null]);
|
|
|
$map = [];
|
|
|
foreach ($models as $model)$map[$model->material_box_model_id] = $model;
|
|
|
- $this->getMaterBoxModel($item,$map);
|
|
|
+ $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
|
+ $m = null;
|
|
|
+ foreach ($models as $model){
|
|
|
+ if (!isset($map[$model->id]))continue;
|
|
|
+ $model->maximum = $map[$model->id]->maximum;
|
|
|
+ $boxes = app("MaterialBoxService")->getModelAvailableBox($model->id);
|
|
|
+ if ($boxes->count()==0)continue;
|
|
|
+ if (!$m)$m = $model;
|
|
|
+ $boxCodes = "";
|
|
|
+ foreach ($boxes as $box){
|
|
|
+ $boxCodes .= "'".$box->code."',";
|
|
|
+ }
|
|
|
+ $boxCodes = rtrim($boxCodes,",");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT LOCATIONID,({$model->maximum}-QTY) AS QTY FROM INV_LOT_LOC_ID WHERE LOTNUM = '{$lotNum}'
|
|
|
+AND LOCATIONID IN ({$boxCodes}) AND TRACEID = '*' AND {$model->maximum}-QTY > 0 ORDER BY (CASE QTY WHEN 0 THEN 1 ELSE 0 END),{$model->maximum}-QTY
|
|
|
+SQL;
|
|
|
+ $res = DB::connection("oracle")->selectOne(DB::raw($sql));
|
|
|
+ if ($res){
|
|
|
+ $m = $model;
|
|
|
+ $m->maximum = $res->qty;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$m)$this->error("没有可用料箱");
|
|
|
+ $this->success(["need"=>$m->maximum,"material_box_model_id"=>$m->id,"commodity_id"=>$commodity->id]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -399,7 +435,7 @@ sql;
|
|
|
$map = [];
|
|
|
$ids = [];
|
|
|
foreach (request("models") as $model){
|
|
|
- $insert[] = [
|
|
|
+ $in[] = [
|
|
|
"commodity_id" => $commodityId,
|
|
|
"material_box_model_id" => $model["id"],
|
|
|
"maximum" => $model["maximum"]
|
|
|
@@ -413,9 +449,14 @@ sql;
|
|
|
list($in,$map,$ids) = $insert(request("commodityId"));
|
|
|
if ($ids){
|
|
|
$map = array_flip($ids);
|
|
|
- foreach (CommodityMaterialBoxModel::query()->whereIn("id",$ids)->lockForUpdate()->get() as $model){
|
|
|
- $index = $map[$model->id];
|
|
|
- if ($model->maximum != $in[$index]["maximum"])$model->update(["maximum"=>$in[$index]["maximum"]]);
|
|
|
+ foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
|
|
|
+ ->lockForUpdate()->get() as $model){
|
|
|
+ $index = $map[$model->material_box_model_id];
|
|
|
+ if ($model->maximum != $in[$index]["maximum"]){
|
|
|
+ CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
|
|
|
+ ->where("material_box_model_id",$model->material_box_model_id)
|
|
|
+ ->update(["maximum"=>$in[$index]["maximum"]]);
|
|
|
+ }
|
|
|
unset($in[$index]);
|
|
|
}
|
|
|
$in = array_values($in);
|
|
|
@@ -440,17 +481,18 @@ sql;
|
|
|
$this->getMaterBoxModel($item,$map);
|
|
|
}
|
|
|
|
|
|
- private function getMaterBoxModel($item,$map)
|
|
|
+ private function getMaterBoxModel($commodity,$map)
|
|
|
{
|
|
|
- $models = app("MaterialBoxModelService")->getModelSortedByOwner($item->store->owner_id);
|
|
|
+ $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
|
foreach ($models as $model){
|
|
|
if (!isset($map[$model->id]))continue;
|
|
|
- $result = app("StorageService")->getHalfBoxLocation($map[$model->id],$item,$item->store->asn_code);
|
|
|
+ //$result = app("StorageService")->getHalfBoxLocation($map[$model->id],$item,$item->store->asn_code);
|
|
|
+ $result = app("StorageService")->getMaxAvailableHalfBoxLocation($map[$model->id],$item,$item->store->asn_code);
|
|
|
if (!$result)continue;
|
|
|
$result->maximum = $model->maximum-$result->amount;
|
|
|
$this->success($result);
|
|
|
}
|
|
|
- $this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$item->commodity_id]);
|
|
|
+ $this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$commodity->id]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -458,11 +500,95 @@ sql;
|
|
|
*/
|
|
|
public function searchBarCode()
|
|
|
{
|
|
|
- $commodities = Commodity::query()->whereHas("barcodes",function (Builder $query){
|
|
|
+ $commodities = Commodity::query()->with("owner")->whereHas("barcodes",function (Builder $query){
|
|
|
$query->where("code",request("barCode"));
|
|
|
})->get();
|
|
|
if (!$commodities->count())$this->error("库内无此商品信息");
|
|
|
if ($commodities->count()>1)$commodities->load("owner");
|
|
|
$this->success($commodities);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据商品ID检索已存在的上限设定
|
|
|
+ */
|
|
|
+ public function searchModel()
|
|
|
+ {
|
|
|
+ $mapping = [];
|
|
|
+ foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("id"))->get() as $model){
|
|
|
+ $mapping[$model->material_box_model_id] = $model->maximum;
|
|
|
+ }
|
|
|
+ $this->success($mapping);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ASN号检索未设定商品型号上限的信息
|
|
|
+ */
|
|
|
+ public function searchAsn()
|
|
|
+ {
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT CUSTOMERID,SKU FROM TSK_TASKLISTS WHERE DOCNO = ? AND TASKPROCESS = '00' AND TASKTYPE = 'PA' GROUP BY CUSTOMERID,SKU
|
|
|
+SQL;
|
|
|
+ $store = Store::query()->select("owner_id")->where("asn_code",request("asn"))->first();
|
|
|
+ if (!$store || !$store->owner_id)$this->error("WAS内无此ASN单信息");
|
|
|
+
|
|
|
+ $tasks = DB::connection("oracle")->select(DB::raw($sql),[request("asn")]);
|
|
|
+ $codes = array_column($tasks,"sku");
|
|
|
+ $model = MaterialBoxModel::query()->where("maximum_kind",1)->first();
|
|
|
+ if (!$model)$this->error("单品型号缺失");
|
|
|
+ $commodities = Commodity::query()->with("model")->where("owner_id",$store->owner_id)
|
|
|
+ ->whereIn("sku",$codes)->get()->toArray();
|
|
|
+ if (count($codes)!=count($commodities))$this->error("WAS商品信息不全");
|
|
|
+ foreach ($commodities as $index=>$commodity){
|
|
|
+ if ($commodity->model)unset($commodities[$index]);
|
|
|
+ }
|
|
|
+ $this->success(["commodities"=>array_values($commodities),"model"=>$model]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置商品上限
|
|
|
+ */
|
|
|
+ public function settingCommodityMaximum()
|
|
|
+ {
|
|
|
+ $modelId = request("modelId");
|
|
|
+ $insert = [];
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+ foreach (request("commodities") as $commodity){
|
|
|
+ $insert[] = [
|
|
|
+ "commodity_id" => $commodity["id"],
|
|
|
+ "material_box_model_id" => $modelId,
|
|
|
+ "maximum" => $commodity->maximum,
|
|
|
+ "created_at" => $date,
|
|
|
+ "updated_at" => $date,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->success(CommodityMaterialBoxModel::query()->insert($insert));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查任务获取多批次
|
|
|
+ */
|
|
|
+ public function checkTask()
|
|
|
+ {
|
|
|
+ $track = request("track");
|
|
|
+ $barCode = request("barCode");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT TSK_TASKLISTS.FMLOTNUM FROM TSK_TASKLISTS LEFT JOIN BAS_SKU ON TSK_TASKLISTS.CUSTOMERID = BAS_SKU.CUSTOMERID
|
|
|
+AND TSK_TASKLISTS.SKU = BAS_SKU.SKU
|
|
|
+WHERE FMID = ? AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ? OR ALTERNATE_SKU3 = ?)
|
|
|
+AND TASKPROCESS = '00' AND TASKTYPE = 'PA' GROUP BY FMID,FMLOTNUM
|
|
|
+SQL;
|
|
|
+ $tasks = DB::connection("oracle")->select(DB::raw($sql),[$track,$barCode,$barCode,$barCode]);
|
|
|
+ $result = ["count"=>count($tasks)];
|
|
|
+ if (count($tasks)>1){
|
|
|
+ $lotNums = "";
|
|
|
+ foreach ($tasks as $task)$lotNums .= "'".$task->fmlotnum."',";
|
|
|
+ $lotNums = rtrim($lotNums,",");
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT * FROM INV_LOT_ATT WHERE LOTNUM IN ({$lotNums});
|
|
|
+SQL;
|
|
|
+ $result["lots"] = DB::connection("oracle")->select(DB::raw($sql));
|
|
|
+ }
|
|
|
+ if (count($tasks)==1)$result["lots"] = $tasks[0]->fmlotnum;
|
|
|
+ $this->success($result);
|
|
|
+ }
|
|
|
}
|