فهرست منبع

半箱入库:检查库存时合并批次属性
拆分任务
无限组合合并任务上架
页面BUG修复与样式修正

Zhouzhendong 4 سال پیش
والد
کامیت
2986c39ea1

+ 41 - 5
app/Http/Controllers/StorageController.php

@@ -97,13 +97,49 @@ class StorageController extends Controller
         $models = CommodityMaterialBoxModel::query()->where("commodity_id",$item->commodity_id)->get();
         if ($models->count()==0)$this->error("商品首入,请使用缓存架空箱入库");
         foreach ($models as $model){
-            $box = Storage::query()->select(DB::raw("MAX({$model->maximum}-amount) need"),"material_box_id")
-                ->whereHas("materialBox",function (Builder $query)use($model){
+            $stationCodes = '';//拼接库位编码
+            $map = [];//库位与库存映射
+            //查询填充
+            Storage::query()->with("station")->whereHas("materialBox",function (Builder $query)use($model){
                 $query->where("material_box_model_id",$model->material_box_model_id);
             })->where("commodity_id",$model->commodity_id)->where("amount","<",$model->maximum)
-                ->where("status",0)->first();
-            $box->commodity_id = $item->commodity_id;
-            if ($box)$this->success($box);
+                ->where("status",0)->where(DB::raw("{$model->maximum}-amount"),">",0)->get()
+                ->each(function ($storage)use(&$stationCodes,&$map){
+                    $stationCodes .= "'".$storage->station->code."',";
+                    $map[$storage->station->code] = $storage;
+                });
+            //不存在跳出
+            if (!$stationCodes)continue;
+            $stationCodes = mb_substr($stationCodes,0,-1);
+            //查询对应asn detail
+            $detail = DB::connection("oracle")->selectOne(DB::raw("SELECT * FROM DOC_ASN_DETAILS WHERE ASNNO = ? AND ASNLINENO = ?"),[
+                request("asn"),$item->asn_line_code
+            ]);
+            if($detail)continue;
+            $detail = get_object_vars($detail);
+            //查询对应批次属性
+            $lot = DB::connection("oracle")->selectOne(DB::raw("SELECT * FROM BAS_LOTID WHERE LOTID = (SELECT LOTID FROM BAS_SKU WHERE CUSTOMERID = ? AND SKU = ?)"),[
+                $detail["customerid"],$detail["sku"]
+            ]);
+            if($lot)continue;
+            //通过符合条件的批次号来查询 库存
+            $lot = get_object_vars($lot);
+            $sql = <<<sql
+SELECT * FROM INV_LOT_LOC_ID WHERE LOTNUM IN
+ (SELECT LOTNUM FROM INV_LOT_ATT WHERE INV_LOT_ATT.CUSTOMERID = ? AND SKU = ?
+sql;
+            //拼接可以合并的批次属性要求
+            for ($i=1;$i<=8;$i++){
+                if ($lot["lotkey0{$i}"]=='Y'){
+                    $val = $detail["lotatt0{$i}"] ? "'{$detail["lotatt0{$i}"]}'" : null;
+                    $sql .= " AND LOTATT0{$i} = $val";
+                }
+            }
+            $sql .= ") AND LOCATIONID IN ({$stationCodes}) AND TRACEID = '*' AND {$model->maximum}-QTY > 0 ORDER BY {$model->maximum}-QTY";
+            $res = DB::connection("oracle")->selectOne(DB::raw($sql),[
+                $detail["customerid"],$detail["sku"]
+            ]);
+            if ($res)$this->success($map[$res->locationid]);
         }
         $this->success(["need"=>$models[0]->maximum,"material_box_model_id"=>$models[0]->material_box_model_id,"commodity_id"=>$item->commodity_id]);
     }

+ 16 - 3
app/Http/Controllers/TestController.php

@@ -141,11 +141,24 @@ class TestController extends Controller
     {
         return call_user_func([$this, $method], $request);
     }
-
+    public function test3(){
+        $nums = [1,2,3,4,5,6,7];
+        $target = 3;
+        $sum = 0;
+        $res = $this->test1($nums,$target);
+        dump($res);
+        if (!$res)return null;
+        if (!is_array($res))dd($nums[$res]);
+        foreach ($res as $item){
+            dump($nums[$item]);
+            $sum += $nums[$item];
+        }
+        dd($sum);
+    }
     public function test1()
     {
-        $box = app("MaterialBoxService")->getAnEmptyBox([],$modelId);
-        return view("test");
+        $unit = DB::selectOne("SELECT * FROM UNITS where id = 9999");
+        dd(get_object_vars($unit));
     }
 
     public function test2()

+ 7 - 1
app/Services/OrderService.php

@@ -90,27 +90,32 @@ class OrderService
         if ($ordernos){
             $sql .= " AND orderno IN ".$ordernos;
         }
-//        if ($c_contact) $sql .= " AND c_contact like '".$c_contact."'";
         if ($c_contact)$sql=$this->sqlSearchWay($sql,$c_contact,'c_contact');
         if ($c_tel2){
+            $c_tel2 = str_replace("'",'"',$c_tel2);
             $sql .= " AND (c_tel2 like '".$c_tel2."' OR c_tel1 like '".$c_tel2."')";
         }
         if ($c_province){
+            $c_province = str_replace("'",'"',$c_province);
             if ($c_province=='空')$sql .= " AND c_province is null";
             else$sql .= " AND c_province like '".$c_province."'";
         }
         if ($c_city){
+            $c_city = str_replace("'",'"',$c_city);
             if ($c_city=='空')$sql .= " AND c_city is null";
             else$sql .= " AND c_city like '".$c_city."'";
         }
         if ($c_district){
+            $c_district = str_replace("'",'"',$c_district);
             if ($c_district=='空')$sql .= " AND c_district is null";
             else$sql .= " AND c_district like '".$c_district."'";
         }
         if ($releasestatus){
+            $releasestatus = str_replace("'",'"',$releasestatus);
             $sql .= " AND releasestatus = '".$releasestatus."'";
         }
         if ($alternate_sku1){
+            $alternate_sku1 = str_replace("'",'"',$alternate_sku1);
             if ($checkAllSign) $detailsOrderno = $this->getOrdersNo($alternate_sku1,false);
             else $detailsOrderno = $this->getOrdersNo($alternate_sku1,true, $params['page'] ?? 1, $params['paginate'] ?? 50);
             if (count($detailsOrderno)>0){
@@ -184,6 +189,7 @@ class OrderService
             $sql.=" and notes like '%".$notes."%'";
         }
         if ($soreference5){
+            $soreference5 = str_replace("'",'"',$soreference5);
             $arr=array_values(array_filter(preg_split('/[,, ]+/is', $soreference5)));
             if (count($arr)>0){
                 $sql.=" and (soreference5 in (";

+ 133 - 31
app/Services/StorageService.php

@@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Model;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Str;
 
 class StorageService
 {
@@ -237,7 +238,7 @@ class StorageService
      *
      * @return array|null
      */
-    public function getFluxTask($asn,$barCode,$amount):?array
+    public function getFluxTask(string $asn,string $barCode,int $amount):array
     {
         $sql = <<<sql
 SELECT * FROM DOC_ASN_DETAILS LEFT JOIN BAS_SKU ON DOC_ASN_DETAILS.CUSTOMERID = BAS_SKU.CUSTOMERID AND DOC_ASN_DETAILS.SKU = BAS_SKU.SKU
@@ -246,15 +247,123 @@ WHERE ASNNO = ? AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ? OR ALTERNATE_SKU3
   AND TASKPROCESS = '00' AND TASKTYPE = 'PA'
 sql;
         $asns = DB::connection("oracle")->select(DB::raw($sql),[$asn,$barCode,$barCode,$barCode,$amount]);
-        if (!$asns)return null;
+        if (!$asns)return [];
         $nums = [];
-        foreach ($asns as $asn){
+        $sum = 0;
+        $maxIndex = null;
+        foreach ($asns as $i => $asn){
             if ((int)$asn->fmqty == $amount)return [$asn];
             $nums[] = (int)$asn->fmqty;
+            $sum += (int)$asn->fmqty;
+            if ((int)$asn->fmqty>$amount)$maxIndex = $i;
         }
-        $result = $this->twoSum($nums,$amount);
-        if ($result)return [$asns[$result[0]],$asns[$result[1]]];
-        return null;
+        if ($sum<$amount)return []; //上架数大于入库数
+        $result = $this->getMatch($nums,$amount);
+        if (!$result)return $this->splitTask($asns,$maxIndex,$amount);
+        $arr = [];
+        foreach ($result as $index)$arr[] = $asns[$index];
+        return $arr;
+    }
+
+    /**
+     * 拆分任务
+     * @param array $asns
+     * @param int|null $maxIndex
+     * @param int $amount
+     *
+     * @return array
+     */
+    private function splitTask($asns,$maxIndex,$amount):array
+    {
+        $result = [];
+        if ($maxIndex===null){
+            foreach ($asns as $asn){
+                if ($amount>(int)$asn->fmqty){
+                    $result[] = $asn;
+                    $amount-=(int)$asn->fmqty;
+                }else $splitTarget = $asn;
+            }
+        }else $splitTarget = $asns[$maxIndex];
+        $result[] = $this->copyTask($splitTarget,$amount);
+        return $result;
+    }
+
+    /**
+     * @param \stdClass $task
+     * @param int $amount
+     *
+     * @return \stdClass
+     *
+     * @throws
+     */
+    private function copyTask($task,$amount)
+    {
+        DB::connection("oracle")->beginTransaction();
+        try {
+            $columns = '';
+            $values = '';
+            $seq = 0;
+            foreach ($task as $key=>$val){
+                if (Str::upper($key)=='TASKID_SEQUENCE') {
+                    $taskMax = DB::connection("oracle")->selectOne(DB::raw("select MAX(TASKID_SEQUENCE) maxseq from TSK_TASKLISTS where taskid = ?"),[$task->taskid]);
+                    $val = $taskMax->maxseq + 1;
+                    $seq = $val;
+                }
+                if (Str::upper($key)=='FMQTY' || Str::upper($key)=='FMQTY_EACH')$val = $amount;
+                if (Str::upper($key)=='FMID')$val = "WAS".$val;
+                $columns .= "'".$key."',";
+                $values .= "'".$val."',";
+            }
+            $columns = mb_substr($columns,0,-1);
+            $values = mb_substr($values,0,-1);
+            $sql = <<<sql
+    INSERT INTO TSK_TASKLISTS({$columns}) VALUES({$values})
+sql;
+            DB::connection("oracle")->insert(DB::raw($sql));
+            DB::connection("oracle")->update(DB::raw("UPDATE TSK_TASKLISTS SET FMQTY = FMQTY-?,FMQTY_EACH = FMQTY_EACH-? WHERE TASKID = ? AND TASKID_SEQUENCE = ?"),[
+                $amount,$amount,$task->taskid,$task->taskid_sequence
+            ]);
+            $invs = DB::connection("oracle")->select(DB::raw("SELECT * FROM INV_LOT_LOC_ID WHERE LOTNUM = ? AND LOCATIONID IN (?,?) AND TRACEID = ?"),[
+                $task->fmlotnum,$task->fmlocation,$task->plantolocation,$task->fmid
+            ]);
+            foreach ($invs as $inv){
+                $columns = '';
+                $values = '';
+                if ($inv->locationid==$task->fmlocation){
+                    DB::connection("oracle")->update(DB::raw("UPDATE inv_lot_loc_id SET qty = qty-? WHERE lotnum = ? AND locationid = ? AND traceid = ?"),[
+                        $amount,$inv->lotnum,$inv->locationid,$inv->traceid
+                    ]);
+                    foreach ($inv as $key=>$val){
+                        if (Str::upper($key)=='TRACEID') $val = "WAS".$task->fmid;
+                        if (Str::upper($key)=='QTY') $val = $amount;
+                        $columns .= "'".$key."',";
+                        $values .= "'".$val."',";
+                    }
+                    $columns = mb_substr($columns,0,-1);
+                    $values = mb_substr($values,0,-1);
+                    DB::connection("oracle")->insert(DB::raw("INSERT INTO inv_lot_loc_id({$columns}) VALUES({$values})"));
+                }
+                if ($inv->locationid==$task->plantolocation){
+                    DB::connection("oracle")->update(DB::raw("UPDATE inv_lot_loc_id SET QTYPA = QTYPA-? WHERE lotnum = ? AND locationid = ? AND traceid = ?"),[
+                        $amount,$inv->lotnum,$inv->locationid,$inv->traceid
+                    ]);
+                    foreach ($inv as $key=>$val){
+                        if (Str::upper($key)=='TRACEID') $val = "WAS".$task->fmid;
+                        if (Str::upper($key)=='QTYPA') $val = $amount;
+                        $columns .= "'".$key."',";
+                        $values .= "'".$val."',";
+                    }
+                    $columns = mb_substr($columns,0,-1);
+                    $values = mb_substr($values,0,-1);
+                    DB::connection("oracle")->insert(DB::raw("INSERT INTO inv_lot_loc_id({$columns}) VALUES({$values})"));
+                }
+            }
+            DB::connection("oracle")->commit();
+        }catch(\Exception $e) {
+            DB::connection("oracle")->rollBack();
+            throw new \Exception("拆分任务失败:".$e->getMessage());
+        }
+        return DB::connection("oracle")->selectOne(DB::raw("SELECT * FROM TSK_TASKLISTS WHERE TASKID = ? AND TASKID_SEQUENCE = ?"),[$task->taskid,$seq]);
     }
 
     /**
@@ -264,14 +373,23 @@ sql;
      * @param Integer $target
      * @return Integer[]|null
      */
-    protected function twoSum($nums, $target) {
+    protected function getMatch(array $nums,int $target) :?array
+    {
         $map=[];
-        for($i=0;$i<count($nums);$i++){
-            $complement=$target-$nums[$i];
-            if(array_key_exists($complement,$map)){
-                return [$map[$complement],$i];
+        foreach ($nums as $index=>$val){
+            $complement=$target-$val;
+            if(array_key_exists($complement,$map))return [$map[$complement],$index];
+            if ($val==$target)return [$index];
+            $map[$val]=$index;
+            if ($val<$target){
+                $temp = $nums;
+                unset($temp[$index]);
+                $arr = $this->getMatch($temp,$target-$val);
+                if ($arr) {
+                    $arr[] = $index;
+                    return $arr;
+                }
             }
-            $map[$nums[$i]]=$i;
         }
         return null;
     }
@@ -296,22 +414,6 @@ sql;
         if (!$inv)return false;//余量与入库不符
         DB::connection("oracle")->transaction(function ()use($inv,$amount,$ide,$asn,&$who){
             $db = DB::connection("oracle");
-            /*$qty = $amount;
-            foreach ($inv as $in){
-                if ($qty==0)break;
-                if ($in->qty > $qty){
-                    $db->update(DB::raw("update inv_lot_loc_id set qty = qty-?,qtymvout = qty-? where lotnum = ? and locationid = ? and traceid = ?"),[
-                        $qty,$qty,$in->lotnum,$in->locationid,$in->traceid
-                    ]);
-                    $in->qty = $in->qty-$qty;
-                    $qty = 0;
-                }else{
-                    $db->delete(DB::raw("DELETE FROM inv_lot_loc_id WHERE lotnum = ? and locationid = ? and traceid = ?"),[
-                        $in->lotnum,$in->locationid,$in->traceid
-                    ]);
-                    $qty = $qty-$in->qty;
-                }
-            }*/
             $db->delete(DB::raw("DELETE FROM inv_lot_loc_id WHERE lotnum = ? AND traceid = ? AND traceid != '*'  AND qty = 0"),[
                 $inv->lotnum,$inv->traceid
             ]);
@@ -341,13 +443,13 @@ sql;
             ]);
             $this->setTrNumber($max);
             $sql = <<<sql
-update TSK_TASKLISTS set TASKPROCESS = '99',REASONCODE = 'OK',PLANTOLOCATION = ?,PLANLOGICALTOSEQUENCE = ?,
-CREATE_TRANSACTIONID = ?,OPENWHO = ?,OPENTIME = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),
+update TSK_TASKLISTS set TASKPROCESS = '99',REASONCODE = 'OK',PLANTOLOCATION = ?,PLANLOGICALTOSEQUENCE = ?,FMID = '*'
+COMPLETED_TRANSACTIONID = ?,OPENWHO = ?,OPENTIME = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),
  CLOSEWHO = ?,CLOSETIME = ?,EDITTIME = ?,EDITWHO = ?
  where taskid = ? AND TASKID_SEQUENCE = ?
 sql;
             $db->update(DB::raw($sql),[
-                $ide,$ide,$trid,$who,date("Y-m-d H:i:s"),$who,date("Y-m-d H:i:s"),date("Y-m-d H:i:s"),$who,$asn->taskid,$asn->taskid_sequence
+                $ide,'0',$trid,$who,date("Y-m-d H:i:s"),$who,date("Y-m-d H:i:s"),date("Y-m-d H:i:s"),$who,$asn->taskid,$asn->taskid_sequence
             ]);
         });
         //成功后应去修改ASN状态及数量 暂时不知上架后ASN应为状态

+ 2 - 2
resources/views/store/inStorage/halfChestStorage.blade.php

@@ -87,7 +87,7 @@
                 },
                 errors:{},
                 ov:{},//溢出减量数值
-                checkSign:false;
+                checkSign:false,
             },
             mounted(){
                 this.codeFocus();
@@ -164,7 +164,7 @@
                     this.checkSign = false;
                 },
                 checkMaximum(){
-                    if (!this.info.asn || !this.info.barCode)return;
+                    if (!this.info.asn || !this.info.barCode || this.checkSign)return;
                     window.tempTip.postBasicRequest("{{url('store/inStorage/checkMaximum')}}",this.info,res=>{
                         this.info.maximum = res.need;
                         this.info.material_box_id = res.material_box_id;