Просмотр исходного кода

库存盘点--生成盘点任务时可添加条码条件

haozi 5 лет назад
Родитель
Сommit
a1ba938148

+ 2 - 1
app/Http/Controllers/InventoryAccountController.php

@@ -31,7 +31,8 @@ class InventoryAccountController extends Controller
         $date_end=$request->input('date_end');
         $ownerId=$request->input('owner_id');
         $location=$request->input('location');
-        $inventoryAccount=app('inventoryAccountService')->createMission($date_start,$date_end,$ownerId,$location);
+        $barcode=$request->input('barcode');
+        $inventoryAccount=app('inventoryAccountService')->createMission($date_start,$date_end,$ownerId,$location,$barcode);
         $inventoryAccount=InventoryAccount::with('owner')->find($inventoryAccount->id);
         if (is_null($inventoryAccount)) return ['success'=>false,'data'=>'参数错误!'];
         return ['success'=>true,'data'=>$inventoryAccount];

+ 122 - 15
app/Services/InventoryAccountService.php

@@ -61,7 +61,7 @@ class InventoryAccountService
             ->whereIn('id',explode(',',$queryParam['data']))->get();
     }
     //动盘查询
-    public function conditionPortStock($date_start,$date_end,$ownerId,$location){
+    public function conditionPortStock($date_start,$date_end,$ownerId,$location,$barcode){
         if (!$ownerId) return null;
         $descr_c=Owner::where('id',$ownerId)->value('name');
         $sql='select * from (select result.*,rownum rn from (';
@@ -95,25 +95,18 @@ class InventoryAccountService
         $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
         $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
         $sql.=' and storeStatus.LocationID=stockLog.库位 ';
-        if ($location)$sql.=" where storeStatus.LocationID like '".$location."%' ";
         $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1,sku.ALTERNATE_SKU2,sku.ALTERNATE_SKU3 ';
         $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt01,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
         $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,stockLog.客户  ';
         $sql.=' )result where 1=1 ';
-        if ($descr_c){
-            $sql .= ' and 货主 in (';
-            $descr_cs = explode(',',$descr_c);
-            foreach ($descr_cs as $index => $descr_c){
-                if ($index != 0)$sql .= ',';
-                $sql .= "'".$descr_c."'";
-            }
-            $sql .= ') ';
-        }
+        if ($descr_c)$sql.=" and 货主 = '".$descr_c."' ";
+        if ($location)$sql.=" and 库位 like '".$location."%' ";
+        if ($barcode)$sql=$this->动盘局部盘点按条码查询($sql,$barcode);
         $sql.=' )  ';
         return DB::connection('oracle')->select($sql);
     }
     //全盘查询
-    private function conditionTotalStock($ownerId,$location){
+    private function conditionTotalStock($ownerId,$location,$barcode){
         $descr_c=Owner::where('id',$ownerId)->value('name');
         $sql='select * from (select result.* from (';
         $sql.=' select customer.Descr_C as 货主,storeStatus.CUSTOMERID 客户,storeStatus.LocationID 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码1, sku.ALTERNATE_SKU2 产品条码2, sku.ALTERNATE_SKU3 产品条码3, ';
@@ -125,29 +118,142 @@ class InventoryAccountService
         $sql.=' left join BAS_SKU sku on sku.SKU=storeStatus.SKU and sku.CUSTOMERID=storeStatus.CUSTOMERID ';
         $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM = storeStatus.LOTNUM AND lot.CUSTOMERID = storeStatus.CUSTOMERID ';
         if ($location)$sql.=" where storeStatus.LocationID like '".$location."%' ";
+        if ($barcode&&$location)$sql=$this->局部盘点按条码查询_有库位前缀字母($sql,$barcode);
+        if ($barcode&&!$location)$sql=$this->局部盘点按条码查询_无库位前缀字母($sql,$barcode);
         $sql.=' group by storeStatus.LocationID,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1,sku.ALTERNATE_SKU2,sku.ALTERNATE_SKU3 ';
         $sql.=' ,sku.Descr_C,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
         $sql.=' ,storeStatus.CUSTOMERID,lot.LotAtt01 ';
         $sql.=' )result where 1=1 ';
         if ($descr_c)$sql.=" and 货主 = '".$descr_c."' ";
+        if ($location&&$barcode)$sql.=" and 库位 like '".$location."%' ";
         $sql.=' )  ';
         return DB::connection('oracle')->select($sql);
 
     }
+    private function 局部盘点按条码查询_有库位前缀字母($sql,$barcode){
+        $arr=array_filter(preg_split('/[,, ]+/is', $barcode));
+        if (count($arr)==1){
+            $sql.=" and (sku.ALTERNATE_SKU1 like '".$barcode."%' or sku.ALTERNATE_SKU2 like '".$barcode."%' or sku.ALTERNATE_SKU3 like '".$barcode."%')";
+        }
+        if (count($arr)>1){
+            $sql.="  and (sku.ALTERNATE_SKU1 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+            $sql.=" or sku.ALTERNATE_SKU2 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+            $sql.=" or sku.ALTERNATE_SKU3 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+                $sql.=")";
+        }
+        return $sql;
+    }
+    private function 动盘局部盘点按条码查询($sql,$barcode){
+        $arr=array_filter(preg_split('/[,, ]+/is', $barcode));
+        if (count($arr)==1){
+            $sql.=" and (产品条码1 like '".$barcode."%' or 产品条码2 like '".$barcode."%' or 产品条码3 like '".$barcode."%')";
+        }
+        if (count($arr)>1){
+            $sql.="  and (产品条码1 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+            $sql.=" or 产品条码2 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+            $sql.=" or 产品条码3 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+                $sql.=")";
+        }
+        return $sql;
+    }
+    private function 局部盘点按条码查询_无库位前缀字母($sql,$barcode){
+        $arr=array_filter(preg_split('/[,, ]+/is', $barcode));
+        if (count($arr)==1){
+            $sql.="where  sku.ALTERNATE_SKU1 like '".$barcode."%' or sku.ALTERNATE_SKU2 like '".$barcode."%' or sku.ALTERNATE_SKU3 like '".$barcode."%'";
+        }
+        if (count($arr)>1){
+            $sql.="where sku.ALTERNATE_SKU1 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+            $sql.=" or sku.ALTERNATE_SKU2 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+            $sql.=" or sku.ALTERNATE_SKU3 in (";
+            foreach ($arr as $index=>$str){
+                if ($index==0){
+                    $sql.="'".$str."'";
+                    continue;
+                }
+                $sql.=",'".$str."'";
+            }
+            $sql.=")";
+        }
+        return $sql;
+    }
     //创建盘点任务
-    public function createMission($date_start,$date_end,$ownerId,$location){
+    public function createMission($date_start,$date_end,$ownerId,$location,$barcode){
         if (!$ownerId) return null;
         if ($date_start&&$date_end){
             $date_end_time=$date_end.' 23:59:59';
             $type='动盘';
-            $wmsInventories=$this->conditionPortStock($date_start,$date_end,$ownerId,$location);
+            $wmsInventories=$this->conditionPortStock($date_start,$date_end,$ownerId,$location,$barcode);
         }elseif (!$date_start&&!$date_end){
             $name=Owner::where('id',$ownerId)->value('name');
             $ownerName=OracleBasCustomer::where('customer_type','OW')->where('active_flag','Y')->where('descr_c',$name)->value('customerid');
             $date_start=OracleInvLotLocId::where('customerid',$ownerName)->orderBy('addtime','ASC')->value('addtime');
             $date_end_time=OracleInvLotLocId::where('customerid',$ownerName)->orderBy('addtime','DESC')->value('addtime');
             $type='全盘';
-            $wmsInventories=$this->conditionTotalStock($ownerId,$location);
+            $wmsInventories=$this->conditionTotalStock($ownerId,$location,$barcode);
         }else{
             return null;
         }
@@ -169,6 +275,7 @@ class InventoryAccountService
             'date_end'=>$date_end,
             'ownerId'=>$ownerId,
             'location'=>$location,
+            'barcode'=>$barcode,
             'inventoryId'=>$inventory['id'],
         ];
         Controller::logS(__METHOD__,"创建盘点任务__".__FUNCTION__,json_encode($request),Auth::user()['id']);

+ 2 - 1
resources/views/inventory/stockInventory/inventoryMission.blade.php

@@ -71,7 +71,7 @@
             @{{ inventory.type }}
         </span>
             <span v-if="!listMode">
-            <span v-if="inventory.status==='盘点中' ||inventory.status=='待盘点'" class="btn  col-md-2 font-weight-bold btn-outline-secondary" style="max-width: 160px" @click="stockInventoryEnd(inventory.id)">结束</span>
+            <span v-if="inventory.status==='盘点中' ||inventory.status=='待盘点'" class="btn col-md-2 font-weight-bold btn-outline-secondary" style="max-width: 160px" @click="stockInventoryEnd(inventory.id)">结束</span>
             <span v-if="inventory.status==='复盘中'" class="btn  col-md-2 font-weight-bold" style="cursor: default;max-width: 160px" :class="inventory.status=='盘点中' ||inventory.status=='待盘点'?'btn-outline-info disabled':'bg-info'">复盘</span>
         </span>
         </div>
@@ -815,6 +815,7 @@
                 stockInventoryEnd(id){
                     let _this=this;
                     let url='{{url('inventory/stockInventoryEnd')}}';
+                    if(!confirm('确定要结束初盘任务,进入复盘吗?')){return}
                     axios.post(url,{id:id}).then(function (response) {
                         if (!response.data.success){
                             tempTip.setDuration(2000);

+ 5 - 8
resources/views/inventory/stockInventory/mission.blade.php

@@ -5,7 +5,7 @@
 @section('content')
     @component('inventory.stockInventory.menu')@endcomponent
     <div id="list" class="container-fluid" style="min-width: 1500px">
-        <form class="form-inline mt-3">
+        <form class="form-inline mt-2">
             <span class="form-inline ml-5">
                  <span class="btn btn-sm btn-outline-secondary tooltipTarget" @click="syncOwners">同步货主</span>
                 <select class="form-control form-control-sm tooltipTarget" name="owner_id" id="owner_id" style="width: 150px;position: relative" title="选择指定货主">
@@ -17,8 +17,8 @@
             <span class="form-inline">
                 <input type="date" @change="hasDateStart" class="form-control form-control-sm ml-5 tooltipTarget" name="date_start" id="date_start"  title="选择创建日期的开始时间" style="width: 150px">
                 <input type="date" @change="hasDateEnd" class="form-control form-control-sm ml-5 tooltipTarget" name="date_end" id="date_end"  title="选择创建日期的结束时间" style="width: 150px">
-                <input type="text" @change="hasLocation" class="form-control form-control-sm ml-5 tooltipTarget" name="location" id="location"  title="选择创建盘点任务库位的前缀字母" placeholder="库位前缀字母" style="width: 150px">
-
+                <input type="text"  class="form-control form-control-sm ml-5 tooltipTarget" name="location" id="location"  title="选择创建盘点任务库位的前缀字母" placeholder="库位前缀字母" style="width: 150px" autocomplete="off">
+                <input type="text"  class="form-control form-control-sm ml-5 tooltipTarget" name="barcode" id="barcode"  title="商品条码,糊模查找需要在左边打上%符号" placeholder="条码" style="width: 200px" autocomplete="off">
             </span>
             <span class="ml-5">
             @can('库存管理-盘点')
@@ -113,7 +113,6 @@
                 // formData:{},
                 date_end:'',
                 date_start:'',
-                location:'',
                 fakeOwners:'',
             },
             mounted: function () {
@@ -199,6 +198,7 @@
                     const date_start=document.getElementById('date_start').value;
                     const owner_id=$('#owner_id').val();
                     const location=$('#location').val().trim();
+                    const barcode=$('#barcode').val();
                     //console.log(location)
                     if(owner_id===''){
                         tempTip.setDuration(2000);
@@ -223,7 +223,7 @@
                     //     return;
                     // }
                     let url='{{url('inventory/stockInventory/createStockInventoryMission')}}';
-                    axios.post(url,{date_end:date_end,date_start:date_start,owner_id:owner_id,location:location}).then(function (response) {
+                    axios.post(url,{date_end:date_end,date_start:date_start,owner_id:owner_id,location:location,barcode:barcode}).then(function (response) {
                         tempTip.setDuration(2000);
                         tempTip.cancelWaitingTip();
                         if(!response.data.success){
@@ -315,9 +315,6 @@
                 hasDateEnd(){
                     this.date_end=document.getElementById('date_end').value;
                 },
-                hasLocation(){
-                    this.location=$('#location').val().trim();
-                },
             }
         });
     </script>