Ver código fonte

库存--库存对比修改差值,导出重复

haozi 5 anos atrás
pai
commit
7bb80fba33

+ 1 - 0
app/Http/Controllers/InventoryCompareController.php

@@ -135,6 +135,7 @@ class InventoryCompareController extends Controller
             $params = $request->input();
             unset($params['checkAllSign']);
             $sql=app('inventoryCompareService')->getSql($params);
+//            dd($sql);
         }else{
             $sql=app('inventoryCompareService')->getSql(['id'=>$request->data]);
         }

+ 8 - 1
app/Imports/InventoryCompareImport.php

@@ -130,7 +130,14 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
                 $owner=Owner::find($this->owner_id);
                 if(!$commodityInWMS) {
                     $commodityInWMS = OracleBasSKU::query()->where('sku', "$row[$skuName]")->where('customerid', "$owner->code")->first();
-                    $commodity=Commodity::query()->firstOrCreate(['owner_id'=>$this->owner_id,'sku'=>$row[$skuName],'name'=>$commodityInWMS['descr_c'],'length'=>$commodityInWMS['skulength'],'width'=>$commodityInWMS['skuwidth'],'height'=>$commodityInWMS['skuhigh'],'volumn'=>$commodityInWMS['skulength']*$commodityInWMS['skuwidth']*$commodityInWMS['skuhigh']]);
+                    $commodity=Commodity::query()->firstOrCreate([
+                        'owner_id'=>$this->owner_id,
+                        'sku'=>$row[$skuName],
+                        'name'=>$commodityInWMS['descr_c'],
+                        'length'=>$commodityInWMS['skulength'],
+                        'width'=>$commodityInWMS['skuwidth'],
+                        'height'=>$commodityInWMS['skuhigh'],
+                        'volumn'=>$commodityInWMS['skulength']*$commodityInWMS['skuwidth']*$commodityInWMS['skuhigh']]);
                     $barcode = $commodityInWMS['alternate_sku1']??$commodityInWMS['alternate_sku2']??$commodityInWMS['alternate_sku3'];
                     if($barcode)
                         $commodity->newBarcode($barcode);

+ 11 - 71
app/Services/InventoryCompareService.php

@@ -66,7 +66,7 @@ class InventoryCompareService
         $inventoryCompare->quality='正品';
         $inventoryCompare->amount_in_sys=0;
         $inventoryCompare->amount_in_compare=$amount;
-        $inventoryCompare->differ=0-$amount;
+        $inventoryCompare->differ=$amount-0;
         $inventoryCompare->mission_code= $creatingMissionCode;
         $inventoryCompare->save();
         Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($creatingMissionCode));
@@ -106,10 +106,10 @@ class InventoryCompareService
             $wmsInventoryCompareZp=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->where('质量状态','ZP')->first();
             $wmsInventoryCompareCc=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->where('质量状态','CC')->first();
             $wmsInventoryCompareDj=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->where('质量状态','DJ')->first();
-            $unknownQualityStatus=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->whereNotIn('质量状态',['DJ','CC','ZP']);
-            if (!$wmsInventoryCompareZp&&!$wmsInventoryCompareCc&&!$wmsInventoryCompareDj&&$unknownQualityStatus->isEmpty()){
-                $inventoryCompare=$this->createInventoryCompare_underImport($sku, $custom_location, $amount, $owner_id,$owner_name);
-            }
+            //$unknownQualityStatus=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->whereNotIn('质量状态',['DJ','CC','ZP']);
+            //if (!$wmsInventoryCompareZp&&!$wmsInventoryCompareCc&&!$wmsInventoryCompareDj&&$unknownQualityStatus->isEmpty()){
+                //$inventoryCompare=$this->createInventoryCompare_underImport($sku, $custom_location, $amount, $owner_id,$owner_name);
+            //}
             $creatingMissionCode = $this->getCreatingMissionCode($owner_name);
             $commodityId=Commodity::where('sku',$sku)->where('owner_id',$owner_id)->value('id');
             if ($wmsInventoryCompareZp||$wmsInventoryCompareDj) {
@@ -120,9 +120,9 @@ class InventoryCompareService
                     'custom_location' => $custom_location,
                     'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
                     'quality' => '正品',
-                    'amount_in_sys' => ($wmsInventoryCompareZp['在库数量'] ?? 0) + ($wmsInventoryCompareDj['在库数量'] ?? 0),
+                    'amount_in_sys' => ($wmsInventoryCompareZp['在库数量'] ?? 0)+($wmsInventoryCompareDj['在库数量'] ?? 0),
                     'amount_in_compare' => $amount,
-                    'differ' => $amount - ($wmsInventoryCompareZp['在库数量'] ?? 0) - ($wmsInventoryCompareDj['在库数量'] ?? 0),
+                    'differ' => $amount-(($wmsInventoryCompareZp['在库数量'] ?? 0) + ($wmsInventoryCompareDj['在库数量'] ?? 0)),
                 ];
                 array_push($wasInventoryCompares,$wasInventoryCompareZP);
             }
@@ -135,12 +135,12 @@ class InventoryCompareService
                     'created_at'=>Carbon::now()->format('Y-m-d H:i:s'),
                     'quality'=>'次品',
                     'amount_in_sys'=>$wmsInventoryCompareCc['在库数量'],
-                    'amount_in_compare' =>'',
-                    'differ' =>'',
+                    'amount_in_compare' =>$amount,
+                    'differ' =>$amount-($wmsInventoryCompareCc['在库数量']??0),
                 ];
                 array_push($wasInventoryCompares,$wasInventoryCompareCC);
             }
-            if($unknownQualityStatus->isNotEmpty())return null;
+            //if($unknownQualityStatus->isNotEmpty())return null;
         }
         $inventoryCompares=DB::table('inventory_compares')->insert($wasInventoryCompares);
         if (!$inventoryCompares)return null;
@@ -187,70 +187,10 @@ class InventoryCompareService
                 ->selectRaw('commodities.name commodity_name,commodities.sku commodity_sku')
             ->leftJoin('commodity_barcodes','commodity_barcodes.commodity_id','commodities.id')
                 ->selectRaw('commodity_barcodes.code commodity_barcode_code')
+                ->groupBy('owner_name','commodity_sku','inventory_compares.custom_location','inventory_compares.quality')
             ->sql();
     }
 
-
-//    public function createInventoryCompare($SKU,$LotAtt05,$amount,$ownerId){
-//        $ownerName=Owner::where('id',$ownerId)->value('name');
-//        $request=[
-//            '产品编码'=>$SKU,
-//            '属性仓'=>$LotAtt05,
-//            '数量'=>$amount,
-//            '货主'=>$ownerId,
-//        ];
-//        $wmsInventories=$this->conditionQuery($SKU,$LotAtt05,$ownerName);
-//        if (count($wmsInventories)==0) return null;
-//        $zpAmount=0;
-//        $ccAmount=0;
-//        $amountTotal=0;
-//        foreach ($wmsInventories as $wmsInventory){
-//            $commodity=Commodity::query()->firstOrCreate([
-//                'owner_id'=>$ownerId,
-//                'sku'=>$wmsInventory->产品编码,
-//                'name'=>$wmsInventory->商品名称,
-//            ]);
-//            Controller::logS(__METHOD__,"根据wms产品编码和货主查询或创建商品信息__".__FUNCTION__,json_encode($wmsInventory));
-//            $commodity->newBarcode($wmsInventory->产品条码);
-//            Controller::logS(__METHOD__,"根据wms产品条码和商品id查询或创建商品条码信息__".__FUNCTION__,json_encode($wmsInventory));
-//            $amountTotal=$amountTotal+$wmsInventory->在库数量;
-//            if ($wmsInventory->质量状态=='DJ'||$wmsInventory->质量状态=='ZP'){
-//                $zpAmount=$zpAmount+$wmsInventory->在库数量;
-//            }
-//            if ($wmsInventory->质量状态=='CC'){
-//                $ccAmount=$ccAmount+$wmsInventory->在库数量;
-//            }
-//        }
-//        $unknownStatusAmount=$amountTotal-$ccAmount-$zpAmount;
-//        $creatingMissionCode = $this->getCreatingMissionCode($ownerName);
-//        $commodityId=Commodity::where('sku',$SKU)->where('owner_id',$ownerId)->value('id');
-//        $inventoryCompare=new InventoryCompare();
-//        $inventoryCompare->owner_id=$ownerId;
-//        $inventoryCompare->commodity_id=$commodityId;
-//        $inventoryCompare->mission_code=Uuid::uuid1();
-//        $inventoryCompare->custom_location=$LotAtt05;
-//        $inventoryCompare->created_at=Carbon::now()->format('Y-m-d H:i:s');
-//        $inventoryCompare->mission_code=$creatingMissionCode;
-//        if ($zpAmount!=0){
-//            $inventoryCompare->quality='正品';
-//            $inventoryCompare->amount_in_sys=$zpAmount;
-//            $inventoryCompare->amount_in_compare=$amount;
-//            $inventoryCompare->differ=$zpAmount-$amount;
-//        }
-//        if ($ccAmount!=0){
-//            $inventoryCompare->quality='次品';
-//            $inventoryCompare['amount_in_sys']=$ccAmount;
-//        }
-//        if ($unknownStatusAmount!=0){
-//            $inventoryCompare->quality='未知';
-//            $inventoryCompare->amount_in_sys=$unknownStatusAmount;
-//        }
-//        $inventoryCompare->save();
-//        Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
-//        Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($creatingMissionCode));
-//        return $inventoryCompare;
-//    }
-//
     public function batchUpdateItself($column, array $params)
     {
         return app(BatchUpdateService::class)->batchUpdateItself('inventory_compares', $column, $params);

+ 2 - 1
resources/views/inventory/statement/inventoryCompare.blade.php

@@ -127,6 +127,7 @@
                     <td>@{{ inventoryCompare.differ }}</td>
                 </tr>
             </table>
+            <div class="text-info h5 btn btn">{{$inventoryCompares->count()}}/@{{ sum }}</div>
             {{$inventoryCompares->appends($param)->links()}}
         </div>
     </div>
@@ -140,7 +141,6 @@
         let vue = new Vue({
             el:"#container",
             data:{
-                {{--inventoryCompares:{!! $inventoryCompares->toJson() !!}['data'],--}}
                 inventoryCompares : [
                         @foreach($inventoryCompares as $inventoryCompare)
                     {id:'{{$inventoryCompare->id}}',owner_name:'{{$inventoryCompare->owner ? $inventoryCompare->owner->name : ''}}',
@@ -165,6 +165,7 @@
                     {name:"{{$owner->id}}",value:"{{$owner->name}}"},
                     @endforeach
                 ],
+                sum:{!! $inventoryCompares->total() !!},
                 checkData:[],
                 fakeOwners:'',
                 isSubmit:false,