Преглед изворни кода

库存管理--盘点
盘点测试

haozi пре 5 година
родитељ
комит
510cc10f49
27 измењених фајлова са 1277 додато и 96 уклоњено
  1. 39 18
      app/Http/Controllers/InventoryController.php
  2. 19 3
      app/Inventory.php
  3. 67 42
      app/Services/InventoryService.php
  4. 67 2
      app/Services/common/QueryService.php
  5. 2 1
      database/factories/UserFactory.php
  6. 1 0
      phpunit-Inventory.bat
  7. 3 0
      phpunit.xml
  8. 63 23
      resources/views/inventory/stockInventory/inventoryMission.blade.php
  9. 32 5
      resources/views/inventory/stockInventory/mission.blade.php
  10. 9 0
      routes/web.php
  11. 21 0
      tests/Inventory/ExampleTest.php
  12. 27 0
      tests/Inventory/Services/InventoryService/InventoryService_ConditionSearchTest.php
  13. 116 0
      tests/Inventory/Services/InventoryService/InventoryService_CreateInventoryMissionRecordTest.php
  14. 45 0
      tests/Inventory/Services/InventoryService/InventoryService_CreateMissionTest.php
  15. 24 0
      tests/Inventory/Services/InventoryService/InventoryService_GetTest.php
  16. 39 0
      tests/Inventory/Services/InventoryService/InventoryService_PaginateTest.php
  17. 73 0
      tests/Inventory/Services/InventoryService/InventoryService_SearchStockInventoryRecordTest.php
  18. 45 0
      tests/Inventory/Services/InventoryService/InventoryService_SomeTest.php
  19. 70 0
      tests/Inventory/Services/InventoryService/InventoryService_StockInventoryTest.php
  20. 61 0
      tests/Inventory/http/InventoryControllor/InventoryController_CreateStockInventoryMissionTest.php
  21. 53 0
      tests/Inventory/http/InventoryControllor/InventoryController_DeleteStockInventoryMissionTest.php
  22. 91 0
      tests/Inventory/http/InventoryControllor/InventoryController_EnterStockInventoryTest.php
  23. 58 0
      tests/Inventory/http/InventoryControllor/InventoryController_MissionTest.php
  24. 83 0
      tests/Inventory/http/InventoryControllor/InventoryController_SearchStockInventoryRecordTest.php
  25. 91 0
      tests/Inventory/http/InventoryControllor/InventoryController_StockInventoryTest.php
  26. 78 0
      tests/Inventory/model/InventoryTest.php
  27. 0 2
      tests/Unit/CarTypeTest.php

+ 39 - 18
app/Http/Controllers/InventoryController.php

@@ -162,49 +162,68 @@ class InventoryController extends Controller
         return Excel::download(new Export($row,$list),date('YmdHis', time()).'-动库报表单.xlsx');
     }
 
+
+
+
+
     //创建盘点任务
     public function createStockInventoryMission(Request $request){
         if(!Gate::allows("库存管理-盘点")){ return redirect(url('/'));  }
-        $inventory=app('inventoryService')->createMission($request);
+        $date_start=$request->input('formData.date_start');
+        $date_end=$request->input('formData.date_end');
+        $ownerId=$request->input('formData.owner_id')[0];
+        $inventory=app('inventoryService')->createMission($date_start,$date_end,$ownerId);
+        $inventory=Inventory::with('owner')->find($inventory->id);
         if (is_null($inventory)) return ['success'=>false,'data'=>'参数错误!'];
         return ['success'=>true,'data'=>$inventory];
     }
-
+    //删除盘点任务
+    public function deleteStockInventoryMission($id){
+        if(!Gate::allows('库存管理-盘点')){return['success'=>0,'status'=>'没有权限'];}
+        if(is_null($id)){return ['success'=>false,'data'=>'传入id为空'];}
+        $inventory=Inventory::where('id',$id)->delete();
+        return ['success'=>true,'data'=>$inventory];
+    }
     //盘点-任务页面
     public function mission(Request $request){
         if(!Gate::allows("库存管理-盘点")){ return redirect(url('/'));  }
         $paginateParams = $request->input();
-        $inventories=app('inventoryService')->paginate($request);
+        $queryParam=$request->all();
+        $inventories=app('inventoryService')->paginate($queryParam);
         $owners=Owner::select('id','name')->get();
         return view('inventory.stockInventory.mission',compact('owners','inventories','paginateParams'));
     }
-    //进入盘点页面
+    //进入盘点中或复盘页面
     public function enterStockInventory($id){
         if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
         if (!$id) return ['success'=>false,'data'=>'参数错误!'];
         $inventory=Inventory::with('owner')->find($id);
-        $inventoryMissions=InventoryMission::with(['commodity'])->where('inventory_id',$id)->get();
+        $inventoryMissions=InventoryMission::with(['commodity'])->where('inventory_id',$id)->orderBy('difference_amount','desc')->get();
         return view('inventory.stockInventory.inventoryMission',compact('inventory','inventoryMissions'));
     }
     //依据盘点任务id进行 --盘点
     public function stockInventory(Request $request){
         if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
+        $location=$request->input('location');
+        $barcode=$request->input('barcode');
+        $inventoryId=$request->input('inventoryId');
         $count=$request->input('count');
         if (is_null($count)) return ['success'=>false,'data'=>'盘点数不能为空!'];
-        $inventoryMission=app('inventoryService')->stockInventory($request);
+        $inventoryMission=app('inventoryService')->stockInventory($location,$barcode,$count,$inventoryId);
         if (!$inventoryMission)return ['success'=>false,'data'=>'参数错误!'];
-        $inventory=app('inventoryService')->updateInventoryMissionProcessed($request);
+        $inventory=app('inventoryService')->updateInventory($inventoryId);
         return ['success'=>true,'inventoryMission'=>$inventoryMission,'inventory'=>$inventory];
     }
-
-
-
-
-
-
-
-
-
+    //根据该库存和产品条码查询该条盘点记录
+    public function searchStockInventoryRecord(Request $request){
+        if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
+        $location=$request->input('location');
+        $barcode=$request->input('barcode');
+        $inventoryId=$request->input('inventoryId');
+        $inventoryMission=app('inventoryService')->searchStockInventoryRecord($location,$barcode,$inventoryId);
+        if (!$inventoryMission)return ['success'=>false,'data'=>'参数错误!'];
+        return ['success'=>true,'data'=>$inventoryMission];
+    }
 
     //盘点任务导出
     public function stockInventoryExport(Request $request){
@@ -213,9 +232,11 @@ class InventoryController extends Controller
         ini_set('memory_limit','3526M');
         if ($request->checkAllSign){
             $request->offsetUnset('checkAllSign');
-            $inventories=app('inventoryService')->get($request);
+            $queryParam=$request->all();
+            $inventories=app('inventoryService')->get($queryParam);
         }else{
-            $inventories=app('inventoryService')->some($request);
+            $queryParam=$request->all();
+            $inventories=app('inventoryService')->some($queryParam);
         }
         $row=[[
             'id'=>'盘点编号',

+ 19 - 3
app/Inventory.php

@@ -11,10 +11,10 @@ class Inventory extends Model
     use ModelTimeFormat;
     use SoftDeletes;
     protected $fillable=[
-        'id','owner_id','owner_id','type', 'start_at', 'end_at','total','processed','difference','returned','deleted_at','created_at',
+        'id','owner_id','type', 'start_at', 'end_at','total','processed','difference','returned','deleted_at','created_at',
     ];
     protected $appends = [
-            'surplus'
+            'surplus','check_surplus'
     ];
     public function owner(){
         return $this->belongsTo('App\Owner','owner_id','id');
@@ -25,6 +25,22 @@ class Inventory extends Model
 
     public function getSurplusAttribute()
     {
-        return $this['total'] ? $this['total']-$this['processed']:null;
+        return $this['total'] ? $this['total']-$this['processed']:0;
+    }
+    public function getProcessedAmount(){
+        return $this->inventoryMissions()->where('checked','是')->where('inventory_id',$this['id'])->count();
+    }
+    //复盘剩余数
+    public function getCheckSurplusAttribute()
+    {
+        $re_checked_amount=$this->inventoryMissions()->where('inventory_id',$this['id'])->whereNotNull('re_checked_amount')->count();
+        return $this['total'] ? $this['total']-$re_checked_amount:null;
+    }
+    public function getDifferenceAmount(){
+        return $this->inventoryMissions()->where('inventory_id',$this['id'])->where('difference_amount','>',0)->count();
+    }
+    public function getReturnedAmount(){
+        return $this->inventoryMissions()->where('inventory_id',$this['id'])->where('returned','是')->count();
+
     }
 }

+ 67 - 42
app/Services/InventoryService.php

@@ -12,6 +12,7 @@ use App\OracleActTransactionLog;
 use App\Owner;
 use App\Services\common\QueryService;
 use Illuminate\Http\Request;
+use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Gate;
@@ -19,36 +20,33 @@ use Illuminate\Support\Facades\Gate;
 class InventoryService
 {
 
-    private function conditionQuery(Request $request){
+    private function conditionQuery($queryParam){
         $inventories=Inventory::query()->with(['owner'])->orderBy('id','desc');
         $columnQueryRules=[
             'owner_id' => ['multi' => ','],
             'date_start' => ['alias' => 'created_at' , 'startDate' => ' 00:00:00'],
             'date_end' => ['alias' => 'created_at' , 'endDate' => ' 23:59:59'],
         ];
-        $inventories = app(QueryService::class)->query($request,$inventories,$columnQueryRules);
+        $inventories = app(QueryService::class)->queryCondition($queryParam,$inventories,$columnQueryRules);
         return $inventories;
     }
-    public function paginate(Request $request){
-        $inventories = $this->conditionQuery($request);
-        return $inventories->paginate($request->paginate ?? 50);
+    public function paginate($queryParam){
+        $inventories = $this->conditionQuery($queryParam);
+        return $inventories->paginate($queryParam['paginate'] ?? 50);
     }
 
-    public function get(Request $request){
-        $inventories = $this->conditionQuery($request);
+    public function get($queryParam){
+        $inventories = $this->conditionQuery($queryParam);
         return $inventories->get();
     }
 
-    public function some(Request $request){
+    public function some($queryParam){
         return Inventory::query()->with(['owner'])->orderBy('id','DESC')
-            ->whereIn('id',explode(',',$request->data))->get();
+            ->whereIn('id',explode(',',$queryParam['data']))->get();
     }
 
-    public function conditionSearch(Request $request){
-        if(!Gate::allows("库存管理-盘点")){ return redirect(url('/'));  }
-        $date_start=$request->input('formData.date_start');
-        $date_end=$request->input('formData.date_end');
-        $ownerId=$request->input('formData.owner_id')[0];
+    public function conditionSearch($date_start,$date_end,$ownerId){
+        if (!$ownerId) return null;
         $descr_c=Owner::where('id',$ownerId)->value('name');
         $sql='select * from (select result.*,rownum rn from (';
         $sql.=' select customer.Descr_C as 货主,stockLog.客户 客户, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
@@ -98,33 +96,35 @@ class InventoryService
         return DB::connection('oracle')->select($sql);
     }
     //创建盘点任务
-    public function createMission(Request $request){
-        if(!Gate::allows("库存管理-盘点")){ return redirect(url('/'));  }
-        $date_start=$request->input('formData.date_start');
-        $date_end=$request->input('formData.date_end');
-        $ownerIds=$request->input('formData.owner_id');
-        if (count($ownerIds)<=0) return null;
+    public function createMission($date_start,$date_end,$ownerId){
+        if (!$ownerId) return null;
         if ($date_start&&$date_end){
+            $date_end_time=$date_end.' 23:59:59';
             $type='动盘';
         }elseif (!$date_start&&!$date_end){
-            $name=Owner::where('id',$ownerIds[0])->value('name');
+            $name=Owner::where('id',$ownerId)->value('name');
             $ownerName=OraccleBasCustomer::where('customer_type','OW')->where('active_flag','Y')->where('descr_c',$name)->value('customerid');
             $date_start=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','asc')->value('addtime');
-            $date_end=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','desc')->value('addtime');
+            $date_end_time=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','desc')->value('addtime');
             $type='全盘';
         }else{
             return null;
         }
-        $ownerId=$ownerIds[0];
         $inventory=new Inventory([
             'owner_id'=>$ownerId,
             'type'=>$type,
             'start_at'=>$date_start,
-            'end_at'=>$date_end,
+            'end_at'=>$date_end_time,
         ]);
         $inventory->save();
-        $this->createInventoryMissionRecord($request,$inventory['id'],$ownerId);
-        Controller::logS(__METHOD__,"创建盘点记录任务__".__FUNCTION__,json_encode($request,$inventory['id'],$ownerId),Auth::user()['id']);
+        $this->createInventoryMissionRecord($date_start,$date_end,$ownerId,$inventory['id']);
+        $request=[
+            'date_start'=>$date_start,
+            'date_end'=>$date_end,
+            'ownerId'=>$ownerId,
+            'inventoryId'=>$inventory['id'],
+        ];
+        Controller::logS(__METHOD__,"创建盘点记录任务__".__FUNCTION__,json_encode($request),Auth::user()['id']);
         $inventoryMissionCount=InventoryMission::where('inventory_id',$inventory['id'])->count();
         $inventory->total=$inventoryMissionCount;
         $inventory->update();
@@ -133,8 +133,9 @@ class InventoryService
     }
 
     //创建盘点记录任务
-    public function createInventoryMissionRecord($request,$inventoryId,$ownerId){
-        $wmsInventories=$this->conditionSearch($request);
+    public function createInventoryMissionRecord($date_start,$date_end,$ownerId,$inventoryId){
+        if (!$ownerId) return null;
+        $wmsInventories=$this->conditionSearch($date_start,$date_end,$ownerId);
         foreach ($wmsInventories as $wmsInventory){
             $commodity=Commodity::query()->firstOrCreate([
                 'owner_id'=>$ownerId,
@@ -161,36 +162,60 @@ class InventoryService
             $inventoryMission->occupied_amount=$wmsInventory->占用数量;
             $inventoryMission->save();
         }
+
     }
     //盘点库存
-    public function stockInventory($request){
-        $inventoryId=$request->inventoryId;
-        $count=$request->count;
-        $location=$request->location;
-        $barcode=$request->barcode;
+    public function stockInventory($location,$barcode,$count,$inventoryId){
         $inventoryMission=InventoryMission::with(['commodity'=>function($query)use($barcode){
             return $query->with(['barcodes'=>function($sql)use($barcode){
                 return $sql->where('code',$barcode);
             }]);
         }])->where('location',$location)->where('inventory_id',$inventoryId)->first();
         if (!$inventoryMission) return null;
-        $inventoryMission->verified_amount=$count;
-        $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
-        $inventoryMission->checked='是';
+        $inventory=Inventory::find($inventoryId);
+        if ($inventory->surplus!=0){
+            $inventoryMission->verified_amount=$count;
+            $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
+            $inventoryMission->checked='是';
+        }else{
+            $inventoryMission->re_checked_amount=$count;
+            $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
+            if ($inventoryMission->difference_amount==0){
+                $inventoryMission->returned='是';
+            }else{
+                $inventoryMission->returned='否';
+            }
+        }
         $inventoryMission->update();
+        $request=[
+            'location'=>$location,
+            'barcode'=>$barcode,
+            'count'=>$count,
+            'inventoryId'=>$inventoryId,
+        ];
         Controller::logS(__METHOD__,"盘点__".__FUNCTION__,json_encode($request));
         return $inventoryMission;
     }
-    //盘点修改盘点任务中的已盘条数
-    public function updateInventoryMissionProcessed($request){
-        $inventoryId=$request->inventoryId;
+    //盘点修改盘点任务数据
+    public function updateInventory($inventoryId){
         $inventory=Inventory::find($inventoryId);
-        $processed=InventoryMission::where('checked','是')->where('inventory_id',$inventoryId)->count();
-        $inventory->processed=$processed;
+        $inventory->processed=$inventory->getProcessedAmount();
+        $inventory->difference=$inventory->getDifferenceAmount();
+        $inventory->returned=$inventory->getReturnedAmount();
         $inventory->update();
-        Controller::logS(__METHOD__,"盘点修改盘点任务中的已盘条数__".__FUNCTION__,json_encode($request));
+        Controller::logS(__METHOD__,"盘点修改盘点任务中的已盘条数__".__FUNCTION__,json_encode($inventoryId));
         return $inventory;
     }
+    //根据该库存和产品条码查询该条盘点记录
+    public function searchStockInventoryRecord($location,$barcode,$inventoryId){
+        $inventoryMission=InventoryMission::with(['commodity'=>function($query)use($barcode){
+            return $query->with(['barcodes'=>function($sql)use($barcode){
+                return $sql->where('code',$barcode);
+            }]);
+        }])->where('location',$location)->where('inventory_id',$inventoryId)->first();
+        if (!$inventoryMission) return null;
+        return  $inventoryMission;
+    }
 
 
 }

+ 67 - 2
app/Services/common/QueryService.php

@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 namespace App\Services\common;
 
@@ -10,6 +10,71 @@ Class QueryService
 {
 
     /**
+     * parameter - query(sql) - special column description
+     *
+     * @param $queryParam ($request->all())
+     * @param object $query
+     * @param array $columnQueryRules
+     * @param string $tableName
+     * @return object
+     */
+    public function queryCondition($queryParam,$query,array $columnQueryRules,$tableName = null)
+    {
+        if ($tableName) $tableName .= ".";
+        foreach ($queryParam as $param => $value){
+            if ($param === 'paginate' || $param === 'page')continue;
+            if (!$value || isset($columnQueryRules[$param]))continue;
+            $query = $query->where($tableName.$param,$value);
+        }
+        //rules: alias timeLimit startDate endDate like multi
+        foreach ($columnQueryRules as $param => $rules){
+            $queryCondition=$queryParam[$param]??null;
+            if (!$queryCondition)continue;
+            $isExecute = true;
+            $column = $param;
+            foreach ($rules as $rule => $value){
+                if ($rule === 'alias'){
+                    $column = $value;
+                    $isExecute = false;
+                }
+                if ($rule === 'timeLimit'){
+                    $today=Carbon::now()->subDays($value);
+                    $queryTemp=clone $query;
+                    $queryTemp=$queryTemp->where($tableName.$column,'like','%'.$queryCondition.'%')
+                        ->where($tableName.'created_at','>',$today);
+                    if($queryTemp->count()==0 || $queryTemp->first()[$column]==$queryCondition){
+                        $query=$query->where($tableName.$column,$queryCondition);
+                    }else{
+                        $query=$query->where($tableName.$column,'like','%'.$queryCondition.'%')
+                            ->where($tableName.'created_at','>',$today);
+                    }
+                    $isExecute = true;
+                }
+                if ($rule === 'startDate'){
+                    $startDate = $queryCondition.$value;
+                    $query = $query->where($tableName.$column,'>=',$startDate);
+                    $isExecute = true;
+                }
+                if ($rule === 'endDate'){
+                    $endDate = $queryCondition.$value;
+                    $query = $query->where($tableName.$column,'<=',$endDate);
+                    $isExecute = true;
+                }
+                if ($rule === 'like'){
+                    $query = $query->where($tableName.$column,'like',$value.$queryCondition.$value);
+                    $isExecute = true;
+                }
+                if ($rule === 'multi'){
+                    $query = $query->whereIn($tableName.$column,explode($value,$queryCondition));
+                    $isExecute = true;
+                }
+            }
+            if (!$isExecute) $query = $query->where($tableName.$column,$queryCondition);
+        }
+        return $query;
+    }
+
+/**
      * parameter - query(sql) - special column description
      *
      * @param Request $request
@@ -73,4 +138,4 @@ Class QueryService
         return $query;
     }
 
-}
+}

+ 2 - 1
database/factories/UserFactory.php

@@ -17,8 +17,9 @@ use Faker\Generator as Faker;
 */
 
 $factory->define(User::class, function (Faker $faker) {
+    $userNames=config('users.superAdmin');
     return [
-        'name' => $faker->name,
+        'name' => $userNames[0],
         'email' =>  $faker->unique()->safeEmail,
         'email_verified_at' => now(),
         'password' => '$2y$10$vvcID/Akq2KjOZwRUUgBJOpVyGi.nTDT8Yb7gxiy5Xj9/5GnpzBMi', // password

+ 1 - 0
phpunit-Inventory.bat

@@ -0,0 +1 @@
+vendor\bin\phpunit.bat --testsuite=Inventory

+ 3 - 0
phpunit.xml

@@ -18,6 +18,9 @@
         <testsuite name="Feature">
             <directory suffix="Test.php">./tests/Feature</directory>
         </testsuite>
+        <testsuite name="Inventory">
+            <directory suffix="Test.php">./tests/Inventory</directory>
+        </testsuite>
     </testsuites>
     <filter>
         <whitelist processUncoveredFilesFromWhitelist="true">

+ 63 - 23
resources/views/inventory/stockInventory/inventoryMission.blade.php

@@ -5,7 +5,7 @@
 @section('content')
     @component('inventory.stockInventory.menu')
         <li class="nav-item">
-            <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('enterStockInventory',3)}">盘点中({!! $inventory->id !!})</a>
+            <a  class="nav-link" href="{{URL::current()}}" :class="{active:isActive('enterStockInventory',3)}">盘点中({!! $inventory->id !!})</a>
         </li>
     @endcomponent
     <div id="list" class="container-fluid" style="min-width: 1500px">
@@ -21,33 +21,53 @@
         <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded">
             <label class="col-1 font-weight-bold">时间范围:</label><span>@{{ inventory.start_at }}——@{{ inventory.end_at }}</span>
         </span>
-            <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded">
+        <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded" v-if="inventory.surplus!=0">
             <label class="col-1 font-weight-bold">已盘点:</label><span>@{{ inventory.processed }}/总数:@{{ inventory.total }}</span>
         </span>
-            <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded">
+        <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded" v-if="inventory.surplus!=0">
             <label class="col-1 font-weight-bold">剩余数:</label><span>@{{ inventory.surplus }}</span>
+        </span>
+            <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded" v-if="inventory.surplus==0">
+            <label class="col-1 font-weight-bold">盘点记录数:</label><span>@{{ inventory.total }}</span>
+        </span>
+            <span class="form-group pl-5 shadow-sm p-2 mb-5 bg-white rounded" v-if="inventory.surplus==0">
+            <label class="col-1 font-weight-bold">复盘剩余数:</label><span>@{{ inventory.check_surplus }}/复盘总数:@{{ inventory.total }}</span>
         </span>
         </div>
         <div class="mt-4 ml-5" >
-        <span class="btn col-1 font-weight-bold"  style="cursor: default" :class="inventory.surplus!=0?'bg-info':''">
+        <span class="btn col-1 font-weight-bold"  style="cursor: default" :class="inventory.surplus!=0?'bg-info':'btn-outline-info disabled'">
             @{{ inventory.type }}
         </span>
-            <span class="btn btn-outline-info col-1 disabled font-weight-bold">复盘</span>
+            <span class="btn col-1 font-weight-bold" style="cursor: default" :class="inventory.surplus!=0?'btn-outline-info disabled':'bg-info'">复盘</span>
         </div>
-{{--        method="POST"  action='{{url('inventory/stockInventory/stockInventory/'.$inventory->owner['id'])}}' @csrf   @method('PUT')--}}
-        <form id="form"   class="mt-3 pl-5">
-            <div class="row row-cols-3">
+
+        <form id="form"  class="mt-3 pl-5">
+            <div class="row" :class="inventory.surplus!=0?'row-cols-3':'row-cols-5'">
         <span>
-            <label class="text-secondary font-weight-bold">请输入库位</label>
-            <input id="inventoryInput" name="location" type="text" class="form-control col-6 input"  autocomplete="off">
+            <label for="location" class="text-secondary font-weight-bold">请输入库位</label>
+            <input id="inventoryInput" name="location" type="text" class="form-control col-6 input"  autocomplete="off" value="@if(old('location')){{old('location')}}@endif">
         </span>
-                <span>
-                    <label class="text-secondary font-weight-bold">请输入产品条码</label>
-                    <input id="barcode" name="barcode" type="text" class="form-control col-6 input" autocomplete="off" @blur="searchBarcode">
-                </span>
-                <span>
-            <label class="text-secondary font-weight-bold">请输入盘点数</label>
-            <input type="text" id="count" name="count" class="form-control col-6 input"  autocomplete="off">
+        <span>
+            <label for="barcode" class="text-secondary font-weight-bold">请输入产品条码</label>
+            <input id="barcode" name="barcode" type="text" value="@if(old('barcode')){{old('barcode')}}@endif" class="form-control col-6 input" autocomplete="off" @blur="searchBarcode">
+        </span>
+        <span>
+            <label for="count" class="text-secondary font-weight-bold">请输入盘点数</label>
+            <input type="text" id="count" name="count" class="form-control col-6 input" value="@if(old('count')){{old('count')}}@endif"  autocomplete="off">
+        </span>
+
+        <span v-if="inventory.surplus==0">
+            <label for="count" class="text-secondary font-weight-bold">上一次盘点数</label>
+            <span v-if="!inventoryMissionRecord.re_checked_amount">
+                <input type="text" id="count" name="count" v-model="inventoryMissionRecord.verified_amount" class="form-control col-6 input" readonly>
+            </span>
+            <span v-if="inventoryMissionRecord.re_checked_amount">
+                <input type="text" id="count" name="count" v-model="inventoryMissionRecord.re_checked_amount" class="form-control col-6 input" readonly>
+            </span>
+        </span>
+        <span v-if="inventory.surplus==0">
+            <label for="count" class="text-secondary font-weight-bold">盘点差异数</label>
+            <input type="text" id="count" name="count" v-model="inventoryMissionRecord.difference_amount" class="form-control col-6 input" readonly>
         </span>
             </div>
         </form>
@@ -71,7 +91,8 @@
                 <th>盘点差异</th>
                 <th>分配数量</th>
             </tr>
-            <tr v-for="(inventoryMission,i) in inventoryMissions" v-if="inventoryMission.checked=='是'"  @click="selectedColor(inventoryMission.id)" :style="{'font-weight': inventory.id==selectedStyle?'bold':''}">
+{{--            v-if="inventoryMission.checked=='是'"--}}
+            <tr v-for="(inventoryMission,i) in inventoryMissions"    @click="selectedColor(inventoryMission.id)" :style="{'font-weight': inventory.id==selectedStyle?'bold':''}">
                 <td>@{{ i+1 }}</td>
                 <td>@{{ inventoryMission.location }}</td>
                 <td v-if="inventoryMission.commodity">@{{ inventoryMission.commodity.name }}</td>
@@ -103,6 +124,7 @@
                 inventoryMissions:{!! $inventoryMissions !!},
                 checkData: [],
                 selectedStyle:'',
+                inventoryMissionRecord:{},
             },
             mounted: function () {
                 $(".tooltipTarget").tooltip({'trigger': 'hover'});
@@ -119,15 +141,31 @@
                 },
                 //验证输入盘点产品条码对应是否有商品
                 searchBarcode(){
-                    let barcode=document.getElementById('barcode').value;
                     let _this=this;
+                    let barcode=document.getElementById('barcode').value;
+                    let location=document.getElementById('inventoryInput').value;
+                    let inventoryId=_this.inventory.id;
                     let barcodes=[];
                     _this.inventoryMissions.forEach(function (inventoryMission) {
                         barcodes.push(inventoryMission.commodity.barcode);
                     });
                     if (!barcodes.includes(barcode)){
                         tempTip.setDuration(2000);
-                        tempTip.show('你输入的产品条码没有对应的产品!');
+                        tempTip.show('输入的产品条码没有对应的产品!');
+                    }else {
+                        //根据该库存和产品条码查询该条盘点记录
+                        let url='{{url('inventory/searchStockInventoryRecord')}}';
+                        axios.post(url,{location:location,barcode:barcode,inventoryId:inventoryId}).then(function (response) {
+                            if (!response.data.success){
+                                tempTip.setDuration(2000);
+                                tempTip.show('复盘!'+'   '+response.data.data);
+                            }else {
+                                _this.inventoryMissionRecord=response.data.data;
+                            }
+                        }).catch(function (err) {
+                            tempTip.setDuration(2000);
+                            tempTip.show('网络错误'+err);
+                        });
                     }
                 },
                 //提交盘点
@@ -147,12 +185,14 @@
                                 if (_this.inventory.id==response.data.inventory.id){
                                     _this.inventory.processed=response.data.inventory.processed;
                                     _this.inventory.surplus=response.data.inventory.surplus;
+                                    _this.inventory.check_surplus=response.data.inventory.check_surplus;
                                 }
                                 _this.inventoryMissions.every(function (inventoryMission,i) {
                                     if (inventoryMission.id==response.data.inventoryMission.id){
                                         inventoryMission.checked=response.data.inventoryMission.checked;
                                         inventoryMission.verified_amount=response.data.inventoryMission.verified_amount;
                                         inventoryMission.difference_amount=response.data.inventoryMission.difference_amount;
+                                        inventoryMission.re_checked_amount=response.data.inventoryMission.re_checked_amount;
                                         _this.inventoryMissions.splice(i,1)
                                         _this.inventoryMissions.unshift(inventoryMission);
                                         return false;
@@ -162,7 +202,7 @@
                                 tempTip.setDuration(3000);
                                 tempTip.showSuccess('盘点成功!');
                             }
-                    }).catch(function (err) {
+                        }).catch(function (err) {
                         tempTip.setDuration(2000);
                         tempTip.show('盘点失败!'+'网络错误'+err);
                     })
@@ -176,13 +216,13 @@
                 let inputs = $("#form .input");
                 let idx = inputs.index(this);     // 获取当前焦点输入框所处的位置
                 let location=document.getElementById('inventoryInput').value;
-                if (idx == inputs.length - 1) {       // 判断是否是最后一个输入框
+                if (idx == 2) {       // 判断是否是最后一个输入框
                     if (location==''||location==undefined||location==null){
                         document.getElementById('inventoryInput').focus();
                         return;
                     }
                     listVue.submitStockInventory();
-                    $("#form .input").val('');
+                    $("#form .input").val(' ');
                     document.getElementById('inventoryInput').focus();
                 } else {
                     inputs[idx + 1].focus(); // 设置焦点

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

@@ -62,7 +62,7 @@
                 <td>@{{ inventory.difference }}</td>
                 <td>@{{ inventory.returned }}</td>
                 <td>
-                    <span class="btn  btn-sm btn-outline-danger">删除</span>
+                    <span class="btn  btn-sm btn-outline-danger" @click="deleteStockInventoryMission(inventory.id)">删除</span>
                 </td>
             </tr>
         </table>
@@ -138,6 +138,11 @@
                 //生成盘点任务
                 createInventoryMission(){
                     let _this=this;
+                    if (_this.formData.owner_id.length<=0){
+                        tempTip.setDuration(1000);
+                        tempTip.show('生成盘点任务失败'+'   '+'请先选择货主!');
+                        return;
+                    }
                     let url='{{url('inventory/stockInventory/createStockInventoryMission')}}';
                     axios.post(url,{formData:_this.formData}).then(function (response) {
                             if(!response.data.success){
@@ -147,7 +152,7 @@
                             }else{
                                 let inventory=response.data.data;
                                 _this.inventories.push(inventory);
-                                tempTip.setDuration(1000);
+                                tempTip.setDuration(2000);
                                 tempTip.showSuccess('生成盘点任务成功!');
                             }
                         })
@@ -156,10 +161,32 @@
                             tempTip.show('生成盘点任务失败!'+'网络错误:' + err);
                         });
                 },
-                //进入盘点中页面
+                //进入盘点中页面  或者复盘页面
                 enterStockInventory(id){
-                        location.href="{{url('inventory/stockInventory/enterStockInventory')}}/"+id;
-                    },
+                        location.href='{{url('inventory/stockInventory/enterStockInventory')}}/'+id;
+                },
+                //删除盘点任务
+                deleteStockInventoryMission(id){
+                    if(!confirm('确定要删除盘点单号为:“'+id+'”的运单吗?')){return};
+                    let url = '{{url('inventory/deleteStockInventoryMission')}}/'+id;
+                    axios.delete(url).then(
+                        function (response) {
+                            if(!response.data.success){
+                                tempTip.setDuration(3000);
+                                tempTip.show('盘点单号:'+id+'删除失败!');
+                            }else {
+                                tempTip.setDuration(3000);
+                                tempTip.showSuccess('盘点单号:'+id+'删除成功!');
+                                setInterval(function () {
+                                    window.location.reload();
+                                },1000)
+                            }
+                        }
+                    ).catch(function (err) {
+                        tempTip.setDuration(3000);
+                        tempTip.show('删除失败,网络链接错误!'+err);
+                    });
+                },
             }
         });
     </script>

+ 9 - 0
routes/web.php

@@ -298,11 +298,20 @@ Route::group(['prefix'=>'inventory'],function (){
     Route::get('statement/allInventory','InventoryController@allInventory');
     //库存盘点
     Route::get('stockInventory/mission','InventoryController@mission');
+    //创建盘点任务
     Route::post('stockInventory/createStockInventoryMission','InventoryController@createStockInventoryMission');
+    //删除盘点任务
+    Route::any('deleteStockInventoryMission/{id}','InventoryController@deleteStockInventoryMission');
+    //进入盘点或者复盘页面
     Route::any('stockInventory/enterStockInventory/{id}','InventoryController@enterStockInventory');
     //盘点任务导出
     Route::any('stockInventoryExport','InventoryController@stockInventoryExport');
+    //盘点库存
     Route::any('stockInventory','InventoryController@stockInventory');
+    //复盘查询盘点记录
+    Route::post('searchStockInventoryRecord','InventoryController@searchStockInventoryRecord');
+
+
 });
 
 /**

+ 21 - 0
tests/Inventory/ExampleTest.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Tests\Unit;
+
+use App\Authority;
+use App\Carrier;
+use App\Role;
+use App\User;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+
+class ExampleTest extends TestCase
+{
+
+    public function testExample(){
+        $this->assertEquals(2,1+1);
+    }
+
+}

+ 27 - 0
tests/Inventory/Services/InventoryService/InventoryService_ConditionSearchTest.php

@@ -0,0 +1,27 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryServiceConditionSearchTest extends TestCase
+{
+    public $data;
+    public $ownerId=null;
+    function testConditionSearchFail(){
+        $inventoryService=new InventoryService();
+        $this->data=$inventoryService->conditionSearch('','',$this->ownerId);
+        $this->assertNull($this->data);
+    }
+    function testConditionSearchCanSearchData(){
+        $inventoryService=new InventoryService();
+        $this->ownerId=3;
+        $this->data=$inventoryService->conditionSearch('2020-08-19','2020-08-19',$this->ownerId);
+        $this->assertNotEmpty($this->data);
+    }
+
+}
+

+ 116 - 0
tests/Inventory/Services/InventoryService/InventoryService_CreateInventoryMissionRecordTest.php

@@ -0,0 +1,116 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Inventory;
+use App\InventoryMission;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryServiceCreateInventoryMissionRecordTest extends TestCase
+{
+
+    public $inventory;
+    public $inventoryMissions;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->inventory=factory(Inventory::class)->create();
+    }
+        function testCreateInventoryMissionsFail(){
+        $realService=new InventoryService();
+        $inventoryMissions=$realService->createInventoryMissionRecord('2020-08-20','2020-08-20','',$this->inventory['id']);
+        $this->assertNull($inventoryMissions);
+    }
+    function testCreateInventoryMissionsSuccess(){
+        $realService=new InventoryService();
+        $realService->createInventoryMissionRecord('2020-08-20','2020-08-20',3,$this->inventory['id']);
+        $this->inventoryMissions=InventoryMission::where('inventory_id',$this->inventory['id'])->get();
+        $this->assertNotEmpty($this->inventoryMissions);
+    }
+    function tearDown(): void
+    {
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+
+
+}
+
+
+//function testMock(){
+//    $realService=new InventoryService();
+//    $mockService=$this->createMock(InventoryService=>=>class);
+//    $mockService->method('conditionSearch')->willReturn(new Collection(['a'=>'11','b'=>22]));
+//    $mockService->method('createInventoryMissionRecord')->willReturn($realService->createInventoryMissionRecord(11,22,33));
+//    $this->assertEquals(2,$mockService->createInventoryMissionRecord());
+//}
+//$array=[
+//    0 => [
+//        "货主"=>"金宝贝",
+//        "客户"=> "JINBAOBEI",
+//        "库位"=> "G08-05-01",
+//        "产品编码"=> "900317006-ORANGE",
+//        "产品条码"=> "240041417",
+//        "商品名称"=> "麦克风橙色",
+//        "属性仓"=> "JBB-ZP",
+//        "质量状态"=> "ZP",
+//        "失效日期"=> null,
+//        "批号"=> null,
+//        "生产日期"=> null,
+//        "入库日期"=> null,
+//        "移出数量"=> "3",
+//        "移入数量"=> "0",
+//        "在库数量"=> "745",
+//        "占用数量"=> "0",
+//        "sum"=> "6954",
+//        "rn"=> "1",
+//    ],
+//    1 => [
+//        "货主"=> "金宝贝",
+//        "客户"=> "JINBAOBEI",
+//        "库位"=> "G05-20-03",
+//        "产品编码"=> "8809465536572",
+//        "产品条码"=> "8809465536572",
+//        "商品名称"=> "STICK-O益智磁力片金宝核心套组",
+//        "属性仓"=> "JBB-ZP",
+//        "质量状态"=> "ZP",
+//        "失效日期"=> null,
+//        "批号"=> null,
+//        "生产日期"=> null,
+//        "入库日期"=> null,
+//        "移出数量"=> "22",
+//        "移入数量"=> "0",
+//        "在库数量"=> "98",
+//        "占用数量"=> "5",
+//        "sum"=> "6954",
+//        "rn"=> "2",
+//    ],
+//    2 => [
+//        "货主"=> "金宝贝",
+//        "客户"=> "JINBAOBEI",
+//        "库位"=> "G08-28-01",
+//        "产品编码"=> "6972392150141",
+//        "产品条码"=> "6972392150141",
+//        "商品名称"=> "皆蓝迪雅婴儿泡沫免洗洗手液 50ml",
+//        "属性仓"=> null,
+//        "质量状态"=> "ZP",
+//        "失效日期"=> "2023-04-19",
+//        "批号"=> "20DZK1Y01",
+//        "生产日期"=> null,
+//        "入库日期"=> null,
+//        "移出数量"=> "0",
+//        "移入数量"=> "10000",
+//        "在库数量"=> null,
+//        "占用数量"=> null,
+//        "sum"=> "6954",
+//        "rn"=> "3",
+//    ],
+//];
+
+
+
+

+ 45 - 0
tests/Inventory/Services/InventoryService/InventoryService_CreateMissionTest.php

@@ -0,0 +1,45 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Inventory;
+use App\InventoryMission;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryService_CreateMissionTest extends TestCase
+{
+
+    public $inventory;
+    public $inventoryMissions;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+    }
+        function testCreateMissionsFail(){
+        $realService=new InventoryService();
+        $this->inventory=$realService->createMission('2020-08-20','2020-08-20','');
+        $this->assertNull($this->inventory);
+    }
+    function testCreateMissionsSuccess(){
+        $realService=new InventoryService();
+        $this->inventory=$realService->createMission('2020-08-20','2020-08-20',3);
+        $this->assertIsObject($this->inventory);
+        $this->assertNotEmpty($this->inventory);
+    }
+    function tearDown(): void
+    {
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+
+
+}
+
+
+
+
+

+ 24 - 0
tests/Inventory/Services/InventoryService/InventoryService_GetTest.php

@@ -0,0 +1,24 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Inventory;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryService_GetTest extends TestCase
+{
+    public $inventories;
+    public $inventorys;
+    public $queryParam=[];
+    function testGet(){
+        $inventoryService=new InventoryService();
+        $this->inventories=$inventoryService->get($this->queryParam);
+        $this->inventorys=Inventory::with(['owner'])->orderBy('id','desc')->get();
+        $this->assertEquals(count($this->inventorys),count($this->inventories));
+        $this->assertEquals($this->inventorys,$this->inventories);
+    }
+}
+

+ 39 - 0
tests/Inventory/Services/InventoryService/InventoryService_PaginateTest.php

@@ -0,0 +1,39 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Inventory;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryService_PaginateTest extends TestCase
+{
+    public $inventories;
+    public $inventorys;
+    public $queryParam=[];
+    //没有任何搜索条件情况
+    function testPaginateSuccess(){
+        $inventoryService=new InventoryService();
+        $this->inventories=$inventoryService->paginate($this->queryParam);
+        $this->inventorys=Inventory::get();
+        $this->assertEquals(count($this->inventorys),$this->inventories->total());
+        $this->assertEquals(50,$this->inventories->perPage());
+    }
+    //有搜索条件的情况
+    function testPaginateSuccessHasParam(){
+        $this->queryParam=[
+            "owner_id" => "3",
+            "paginate" => "100",
+        ];
+        $inventoryService=new InventoryService();
+        $this->inventories=$inventoryService->paginate($this->queryParam);
+        $this->inventorys=Inventory::where('owner_id',3)->get();
+        $this->assertEquals(count($this->inventorys),$this->inventories->total());
+        $this->assertEquals(100,$this->inventories->perPage());
+    }
+
+
+}
+

+ 73 - 0
tests/Inventory/Services/InventoryService/InventoryService_SearchStockInventoryRecordTest.php

@@ -0,0 +1,73 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Commodity;
+use App\CommodityBarcode;
+use App\Inventory;
+use App\InventoryMission;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryServiceSearchStockInventoryRecordTest extends TestCase
+{
+    public $inventory;
+    public $inventoryMission;
+    public $commodity;
+    public $commodityBarcode;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->commodity=Commodity::create([
+            'name'=>'棒棒糖',
+            'sku'=>'525252525252525',
+            'owner'=>3,
+        ]);
+        $this->commodityBarcode=CommodityBarcode::create([
+            'code'=>'89898989',
+            'commodity_id'=>$this->commodity['id'],
+        ]);
+        $this->inventory=factory(Inventory::class)->create();
+        $this->inventoryMission=InventoryMission::create([
+            'inventory_id'=>$this->inventory['id'],
+            'location'=>'A21-02-02',
+            'commodity_id'=>$this->commodity['id'],
+            'produced_at'=>null,
+            'valid_at'=>null,
+            'stored_at'=>null,
+            'batch_number'=>'',
+            'erp_type_position'=>'',
+            'quality'=>'',
+            'stored_amount'=>50,
+            'valid_amount'=>'',
+            'verified_amount'=>null,
+            're_checked_amount'=>'',
+            'difference_amount'=>null,
+            'occupied_amount'=>'',
+            'checked'=>'否',
+            'returned'=>'无',
+        ]);
+    }
+    function testSearchStockInventoryNotEmpty(){
+        $inventoryService=new InventoryService();
+        $inventoryMission=$inventoryService->searchStockInventoryRecord('A21-02-02','89898989',$this->inventory['id']);
+        $this->assertNotEmpty($inventoryMission);
+    }
+    function testSearchStockInventoryEmpty(){
+        $inventoryService=new InventoryService();
+        $inventoryMission=$inventoryService->searchStockInventoryRecord('','',$this->inventory['id']);
+        $this->assertEmpty($inventoryMission);
+    }
+
+    function tearDown(): void
+    {
+        CommodityBarcode::where('commodity_id',$this->commodity['id'])->delete();
+        Commodity::where('id',$this->commodity['id'])->delete();
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}
+

+ 45 - 0
tests/Inventory/Services/InventoryService/InventoryService_SomeTest.php

@@ -0,0 +1,45 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Inventory;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryService_SomeTest extends TestCase
+{
+    public $inventories;
+    public $inventorys;
+    public $queryParam=[];
+    public $first;
+    public $second;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->first=factory(Inventory::class)->create();
+        $this->second=factory(Inventory::class)->create();
+    }
+
+    function testSome(){
+        $this->queryParam=[
+            'data'=>'"'.$this->first['id'].','.$this->second['id'].'"',
+        ];
+        $inventoryService=new InventoryService();
+        $this->inventories=$inventoryService->some($this->queryParam);
+        $this->inventorys=Inventory::query()->with(['owner'])->orderBy('id','DESC')
+            ->whereIn('id',explode(',','"'.$this->first['id'].','.$this->second['id'].'"'))->get();
+        $this->assertEquals(count($this->inventorys),count($this->inventories));
+        $this->assertEquals($this->inventorys,$this->inventories);
+    }
+    function tearDown(): void
+    {
+        Inventory::where('id',$this->first['id'])->forceDelete();
+        Inventory::where('id',$this->second['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+
+
+}
+

+ 70 - 0
tests/Inventory/Services/InventoryService/InventoryService_StockInventoryTest.php

@@ -0,0 +1,70 @@
+<?php
+
+
+namespace Tests\Inventory\Services\InventoryService;
+
+
+use App\Commodity;
+use App\CommodityBarcode;
+use App\Inventory;
+use App\InventoryMission;
+use App\Services\InventoryService;
+use Tests\TestCase;
+
+class InventoryServiceStockInventoryTest extends TestCase
+{
+    public $inventory;
+    public $inventoryMission;
+    public $commodity;
+    public $commodityBarcode;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->commodity=Commodity::create([
+            'name'=>'如意精箍棒',
+            'sku'=>'525252525252525',
+            'owner'=>3,
+        ]);
+        $this->commodityBarcode=CommodityBarcode::create([
+            'code'=>'89898989',
+            'commodity_id'=>$this->commodity['id'],
+        ]);
+        $this->inventory=factory(Inventory::class)->create();
+        $this->inventoryMission=InventoryMission::create([
+            'inventory_id'=>$this->inventory['id'],
+            'location'=>'A21-02-02',
+            'commodity_id'=>$this->commodity['id'],
+            'produced_at'=>null,
+            'valid_at'=>null,
+            'stored_at'=>null,
+            'batch_number'=>'',
+            'erp_type_position'=>'',
+            'quality'=>'',
+            'stored_amount'=>50,
+            'valid_amount'=>'',
+            'verified_amount'=>null,
+            're_checked_amount'=>'',
+            'difference_amount'=>null,
+            'occupied_amount'=>'',
+            'checked'=>'否',
+            'returned'=>'无',
+        ]);
+    }
+    function testStockInventoryNoDifferenceAndStockSuccess(){
+        $inventoryService=new InventoryService();
+        $inventoryMission=$inventoryService->stockInventory('A21-02-02','89898989','50',$this->inventory['id']);
+        $this->assertEquals('是',$inventoryMission['checked']);
+        $this->assertEquals(0,$inventoryMission['difference_amount']);
+        $this->assertEquals(50,$inventoryMission['verified_amount']);
+    }
+
+    function tearDown(): void
+    {
+        CommodityBarcode::where('commodity_id',$this->commodity['id'])->delete();
+        Commodity::where('id',$this->commodity['id'])->delete();
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}
+

+ 61 - 0
tests/Inventory/http/InventoryControllor/InventoryController_CreateStockInventoryMissionTest.php

@@ -0,0 +1,61 @@
+<?php
+
+
+namespace Tests\Inventory\Http\InventoryController;
+
+
+use App\Authority;
+use App\Inventory;
+use App\InventoryMission;
+use App\Owner;
+use App\Role;
+use App\User;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class InventoryControllerCreateStockInventoryMissionTestMissionTest extends TestCase
+{
+    public $response=null;
+    public $role;
+    public $user;
+    public $inventory;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        if(!$this->user){
+            $this->user = factory(User::class)->create();
+            $this->role= Role::firstOrCreate([
+                'name'=>'testRole',
+            ]);
+            $this->assertNotEmpty($this->role->id);
+            $authority= Authority::where('name','库存管理-盘点')->first();
+            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
+            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
+        }
+        $this->response=$this->actingAs($this->user)->json('post','http://bswas/inventory/stockInventory/createStockInventoryMission/',
+            ['formData'=>[
+                'date_end'=>'2020-08-17',
+                'date_start'=>'2020-08-17',
+                'owner_id'=>[3],
+            ]]);
+    }
+    function testCreateStockInventoryMissionNotHavingException(){
+        $this->response->assertDontSee('Exception');
+    }
+    function testCreateStockInventoryMissionStatusCode(){
+        $this->response->assertStatus(200);
+    }
+    function testCreateStockInventoryMissionSuccessJson(){
+        $this->response->assertJson(['success'=>true,'data'=>$this->response->json()['data']]);
+    }
+    function tearDown(): void
+    {
+        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
+        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
+        User::where('id',$this->user['id'])->delete();
+        Role::where('id',$this->role['id'])->delete();
+        InventoryMission::where('inventory_id',$this->response->json()['data']['id'])->delete();
+        Inventory::where('id',$this->response->json()['data']['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 53 - 0
tests/Inventory/http/InventoryControllor/InventoryController_DeleteStockInventoryMissionTest.php

@@ -0,0 +1,53 @@
+<?php
+
+
+namespace Tests\Inventory\Http\InventoryController;
+
+
+use App\Authority;
+use App\Inventory;
+use App\Owner;
+use App\Role;
+use App\User;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class InventoryControllerDeleteStockInventoryMissionTestMissionTest extends TestCase
+{
+    public $response=null;
+    public $role;
+    public $user;
+    public $inventory;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        if(!$this->user){
+            $this->user = factory(User::class)->create();
+            $this->role= Role::firstOrCreate([
+                'name'=>'testRole',
+            ]);
+            $this->assertNotEmpty($this->role->id);
+            $authority= Authority::where('name','库存管理-盘点')->first();
+            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
+            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
+            $this->inventory=factory(Inventory::class)->create();
+        }
+        $this->response=$this->actingAs($this->user)->json('delete','http://bswas/inventory/deleteStockInventoryMission/'.$this->inventory['id']);
+    }
+
+    function testDeleteStockInventoryMissionNotHavingException(){
+        $this->response->assertDontSee('Exception');
+    }
+    function testDeleteStockInventoryMissionHasSuccessJson(){
+        $this->response->assertJson(['success'=>true,]);
+    }
+    function tearDown(): void
+    {
+        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
+        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
+        User::where('id',$this->user['id'])->delete();
+        Role::where('id',$this->role['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 91 - 0
tests/Inventory/http/InventoryControllor/InventoryController_EnterStockInventoryTest.php

@@ -0,0 +1,91 @@
+<?php
+
+
+namespace Tests\Inventory\Http\InventoryController;
+
+
+use App\Authority;
+use App\Commodity;
+use App\Inventory;
+use App\InventoryMission;
+use App\Owner;
+use App\Role;
+use App\Services\InventoryService;
+use App\Services\UnitService;
+use App\User;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+class InventoryControllerEnterStockInventoryMissionTestTest extends TestCase
+{
+    public $response=null;
+    public $role;
+    public $user;
+    public $inventory;
+    public $inventoryMissions;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        if(!$this->user){
+            $this->user = factory(User::class)->create();
+            $this->role= Role::firstOrCreate([
+                'name'=>'testRole',
+            ]);
+            $this->assertNotEmpty($this->role->id);
+            $authority= Authority::where('name','库存管理-盘点')->first();
+            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
+            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
+            $this->inventory=factory(Inventory::class)->create();
+            $total=$this->inventory['total'];
+            for ($i=0;$i<$total;$i++){
+                $this->inventoryMissions=InventoryMission::create([
+                    'inventory_id'=>$this->inventory['id'],
+                    'location'=>Str::random(5),
+                    'commodity_id'=>256226,
+                    'produced_at'=>null,
+                    'valid_at'=>null,
+                    'stored_at'=>null,
+                    'batch_number'=>'',
+                    'erp_type_position'=>'',
+                    'quality'=>'',
+                    'stored_amount'=>50,
+                    'valid_amount'=>'',
+                    'verified_amount'=>'',
+                    're_checked_amount'=>'',
+                    'difference_amount'=>'',
+                    'occupied_amount'=>'',
+                    'checked'=>'否',
+                    'returned'=>'无',
+                ]);
+            }
+        }
+        $this->response=$this->actingAs($this->user)->json('get','http://bswas/inventory/stockInventory/enterStockInventory/'.$this->inventory['id']);
+    }
+
+    function testEnterStockInventoryNotHavingException(){
+        $this->response->assertDontSee('Exception');
+    }
+
+    function testStockInventoryViewIsRight(){
+        $this->response->assertViewIs('inventory.stockInventory.inventoryMission');
+    }
+    function testStockInventoryViewHasInventoryAndInventoryMissions(){
+        //$inventory=Inventory::with('owner')->find($this->inventory['id']);
+        //$inventoryMissions=InventoryMission::with(['commodity'])->where('inventory_id',$this->inventory['id'])->orderBy('difference_amount','desc')->get();
+        $this->response->assertViewHas('inventoryMissions');
+        $this->response->assertViewHas('inventory');
+    }
+    function tearDown(): void
+    {
+        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
+        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
+        User::where('id',$this->user['id'])->delete();
+        Role::where('id',$this->role['id'])->delete();
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}
+

+ 58 - 0
tests/Inventory/http/InventoryControllor/InventoryController_MissionTest.php

@@ -0,0 +1,58 @@
+<?php
+
+
+namespace Tests\Inventory\Http\InventoryController;
+
+
+use App\Authority;
+use App\Owner;
+use App\Role;
+use App\User;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class InventoryControllerMissionTest extends TestCase
+{
+    public $response=null;
+    public $role;
+    public $user;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        if(!$this->user){
+            $this->user = factory(User::class)->create();
+            $this->role= Role::firstOrCreate([
+                'name'=>'testRole',
+            ]);
+            $this->assertNotEmpty($this->role->id);
+            $authority= Authority::where('name','库存管理-盘点')->first();
+            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
+            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
+        }
+        $url = 'http://bswas/inventory/stockInventory/mission';
+        $this->response=$this->actingAs($this->user)->get($url);
+    }
+
+    function testMissionNotHavingException(){
+        $this->response->assertDontSee('Exception');
+    }
+    function testMissionViewIsRight(){
+        $this->response->assertViewIs('inventory.stockInventory.mission');
+    }
+    function testMissionHasOwners(){
+        $owners=Owner::select('id','name')->get();
+        $this->response->assertViewHas('owners',$owners);
+    }
+    function testMissionHasInventories(){
+        $this->response->assertViewHas('inventories');
+    }
+
+    function tearDown(): void
+    {
+        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
+        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
+        User::where('id',$this->user['id'])->delete();
+        Role::where('id',$this->role['id'])->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 83 - 0
tests/Inventory/http/InventoryControllor/InventoryController_SearchStockInventoryRecordTest.php

@@ -0,0 +1,83 @@
+<?php
+
+
+namespace Tests\Inventory\Http\InventoryController;
+
+
+use App\Authority;
+use App\Inventory;
+use App\InventoryMission;
+use App\Owner;
+use App\Role;
+use App\User;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+class InventoryController_SearchStockInventoryRecordTest extends TestCase
+{
+    public $response=null;
+    public $role;
+    public $user;
+    public $inventory;
+    public $inventoryMissions;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        if(!$this->user){
+            $this->user = factory(User::class)->create();
+            $this->role= Role::firstOrCreate([
+                'name'=>'testRole',
+            ]);
+            $this->assertNotEmpty($this->role->id);
+            $authority= Authority::where('name','库存管理-盘点')->first();
+            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
+            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
+            $this->inventory=factory(Inventory::class)->create();
+            $this->inventoryMissions=InventoryMission::create([
+                'inventory_id'=>$this->inventory['id'],
+                'location'=>'A12-10-01',
+                'commodity_id'=>256226,
+                'produced_at'=>null,
+                'valid_at'=>null,
+                'stored_at'=>null,
+                'batch_number'=>'',
+                'erp_type_position'=>'',
+                'quality'=>'',
+                'stored_amount'=>50,
+                'valid_amount'=>'',
+                'verified_amount'=>'',
+                're_checked_amount'=>'',
+                'difference_amount'=>'',
+                'occupied_amount'=>'',
+                'checked'=>'否',
+                'returned'=>'无',
+            ]);
+        }
+        $this->response=$this->actingAs($this->user)->json('post','http://bswas/inventory/searchStockInventoryRecord',
+            [   'location'=>'A12-10-01',
+                'barcode'=>'9787511715364',
+                'inventoryId'=>$this->inventory['id'],
+                ]);
+    }
+    function testSearchStockInventoryRecordNotHavingException(){
+        $this->response->assertDontSee('Exception');
+    }
+    function testSearchStockInventoryRecordSuccessJson(){
+        $this->response->assertJson([
+            'success'=>true,
+            'data'=>$this->response->json()['data'],
+        ]);
+    }
+
+    function tearDown(): void
+    {
+        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
+        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
+        User::where('id',$this->user['id'])->delete();
+        Role::where('id',$this->role['id'])->delete();
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 91 - 0
tests/Inventory/http/InventoryControllor/InventoryController_StockInventoryTest.php

@@ -0,0 +1,91 @@
+<?php
+
+
+namespace Tests\Inventory\Http\InventoryController;
+
+
+use App\Authority;
+use App\Inventory;
+use App\InventoryMission;
+use App\Owner;
+use App\Role;
+use App\User;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class InventoryControllerStockInventoryMissionTestTest extends TestCase
+{
+    public $response=null;
+    public $role;
+    public $user;
+    public $inventory;
+    public $inventoryMissions;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        if(!$this->user){
+            $this->user = factory(User::class)->create();
+            $this->role= Role::firstOrCreate([
+                'name'=>'testRole',
+            ]);
+            $this->assertNotEmpty($this->role->id);
+            $authority= Authority::where('name','库存管理-盘点')->first();
+            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
+            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
+            $this->inventory=factory(Inventory::class)->create();
+            $this->inventoryMissions=InventoryMission::create([
+                'inventory_id'=>$this->inventory['id'],
+                'location'=>'A12-10-01',
+                'commodity_id'=>256226,
+                'produced_at'=>null,
+                'valid_at'=>null,
+                'stored_at'=>null,
+                'batch_number'=>'',
+                'erp_type_position'=>'',
+                'quality'=>'',
+                'stored_amount'=>50,
+                'valid_amount'=>'',
+                'verified_amount'=>'',
+                're_checked_amount'=>'',
+                'difference_amount'=>'',
+                'occupied_amount'=>'',
+                'checked'=>'否',
+                'returned'=>'无',
+            ]);
+        }
+        $this->response=$this->actingAs($this->user)->json('post','http://bswas/inventory/stockInventory',
+            [   'location'=>'A12-10-01',
+                'barcode'=>'9787511715364',
+                'count'=>50,
+                'inventoryId'=>$this->inventory['id'],
+            ]);
+    }
+    function testStockInventoryNotHavingException(){
+        $this->response->assertDontSee('Exception');
+    }
+//    function testStockInventoryFailJson(){
+//        $this->response->assertJson([
+//            'success'=>false,
+//            'data'=>'盘点数不能为空!',
+//        ]);
+//    }
+    function testStockInventorySuccessJson(){
+        $this->response->assertJson([
+            'success'=>true,
+            'inventoryMission'=>$this->response->json()['inventoryMission'],
+            'inventory'=>$this->response->json()['inventory'],
+        ]);
+    }
+
+
+    function tearDown(): void
+    {
+        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
+        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
+        User::where('id',$this->user['id'])->delete();
+        Role::where('id',$this->role['id'])->delete();
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 78 - 0
tests/Inventory/model/InventoryTest.php

@@ -0,0 +1,78 @@
+<?php
+
+
+namespace Tests\Inventory\model;
+
+
+use App\Inventory;
+use App\InventoryMission;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+
+
+class InventoryTest extends TestCase
+{
+
+    public $inventory;
+    public $inventoryMission;
+    function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->inventory=factory(Inventory::class)->create();
+        $total=$this->inventory['total'];
+        for ($i=0;$i<$total;$i++){
+            $this->inventoryMissions=InventoryMission::create([
+                'inventory_id'=>$this->inventory['id'],
+                'location'=>Str::random(5),
+                'commodity_id'=>256226,
+                'produced_at'=>null,
+                'valid_at'=>null,
+                'stored_at'=>null,
+                'batch_number'=>'',
+                'erp_type_position'=>'',
+                'quality'=>'',
+                'stored_amount'=>50,
+                'valid_amount'=>'',
+                'verified_amount'=>'',
+                're_checked_amount'=>'',
+                'difference_amount'=>'',
+                'occupied_amount'=>'',
+                'checked'=>'否',
+                'returned'=>'无',
+            ]);
+        }
+    }
+
+    function testOwner(){
+        $this->assertEquals($this->inventory['owner_id'],$this->inventory->owner['id']);
+    }
+
+    function testInventoryMissions(){
+        $this->assertEquals($this->inventory->id,$this->inventory->inventoryMissions['inventory_id']);
+    }
+    function testGetSurplusAttribute(){
+        $surplus=$this->inventory['surplus'];
+        $this->assertEquals($surplus,$this->inventory['total']-$this->inventory['processed']);
+    }
+    function testGetProcessedAmount(){
+        $processed=InventoryMission::where('inventory_id',$this->inventory['id'])->where('checked','是')->count();
+        $this->assertEquals($processed,$this->inventory['processed']);
+    }
+    function testGetDifferenceAmount(){
+        $difference=InventoryMission::where('inventory_id',$this->inventory['id'])->where('difference_amount','>',0)->count();
+        $this->assertEquals($difference,$this->inventory['difference']);
+    }
+    function testGetReturnedAmount(){
+        $returned=InventoryMission::where('inventory_id',$this->inventory['id'])->where('returned','是')->count();
+        $this->assertEquals($returned,$this->inventory['returned']);
+    }
+
+    function tearDown(): void
+    {
+        InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
+        Inventory::where('id',$this->inventory['id'])->forceDelete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}
+

+ 0 - 2
tests/Unit/CarTypeTest.php

@@ -8,8 +8,6 @@ use App\Role;
 use App\User;
 use Illuminate\Support\Facades\DB;
 use Tests\TestCase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Illuminate\Foundation\Testing\RefreshDatabase;
 
 class CarTypeTest extends TestCase
 {