Эх сурвалжийг харах

盘点任务--添加跳过数,并更新数据

haozi 5 жил өмнө
parent
commit
ca603038d1

+ 6 - 6
app/InventoryAccount.php

@@ -12,10 +12,10 @@ class InventoryAccount extends Model
     use ModelTimeFormat;
     use SoftDeletes;
     protected $fillable=[
-        'id','owner_id','type', 'start_at', 'end_at','total','processed','difference','returned','deleted_at','created_at','status','remark','auditor'
+        'id','owner_id','type', 'start_at', 'end_at','total','processed','difference','returned','deleted_at','created_at','status','remark','auditor','ignored'
     ];
     protected $appends = [
-            'surplus','check_surplus','ignored'
+            'surplus','check_surplus'
     ];
     public function creator(){
         return $this->hasOne('App\Sign','signable_id','id')
@@ -35,10 +35,10 @@ class InventoryAccount extends Model
     {
         return $this['total'] ? $this['total']-($this['processed']+$this['ignored']):0;
     }
-    public function getProcessedAttribute(){
+    public function getProcessedAmount(){
         return $this->inventoryMissions()->whereIn('checked',['是','确认差异','已复核'])->where('inventory_account_id',$this['id'])->count();
     }
-    public function getIgnoredAttribute(){
+    public function getIgnoredAmount(){
         return $this->inventoryMissions()->where('checked','跳过')->where('inventory_account_id',$this['id'])->count();
     }
     //复盘剩余数
@@ -47,11 +47,11 @@ class InventoryAccount extends Model
         $re_checked_amount=$this->inventoryMissions()->where('inventory_account_id',$this['id'])->whereNotNull('re_checked_amount')->count();
         return $this['total'] ? $this['total']-$re_checked_amount:null;
     }
-    public function getDifferenceAttribute(){
+    public function getDifferenceAmount(){
         return $this->inventoryMissions()->where('inventory_account_id',$this['id'])->where('difference_amount','!=',0)->count();
     }
     //复盘归位
-    public function getReturnedAttribute(){
+    public function getReturnedAmount(){
         return $this->inventoryMissions()->where('inventory_account_id',$this['id'])->where('returned','是')->count();
 
     }

+ 20 - 15
app/Services/InventoryAccountService.php

@@ -346,9 +346,10 @@ class InventoryAccountService
     //盘点修改盘点任务数据
     public function updateInventory($inventoryAccountId){
         $inventoryAccount=InventoryAccount::find($inventoryAccountId);
-        $inventoryAccount->processed=$inventoryAccount->getProcessedAttribute();//已盘点数
-        $inventoryAccount->difference=$inventoryAccount->getDifferenceAttribute();//盘点差异数
-        $inventoryAccount->returned=$inventoryAccount->getReturnedAttribute(); //复盘归位数
+        $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
+        $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
+        $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
+        $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount(); //跳过数
         if($inventoryAccount->status=='待盘点')
             $inventoryAccount->status='盘点中';
         $inventoryAccount->update();
@@ -430,9 +431,10 @@ class InventoryAccountService
             Controller::logS(__METHOD__,"增加盘点人".__FUNCTION__,json_encode($inventoryId));
             $inventoryAccount=InventoryAccount::query()->find($inventoryId);
             $inventoryAccount->total=$inventoryAccount->total+1;
-            $inventoryAccount->processed=$inventoryAccount->getProcessedAttribute();//已盘点数
-            $inventoryAccount->difference=$inventoryAccount->getDifferenceAttribute();//盘点差异数
-            $inventoryAccount->returned=$inventoryAccount->getReturnedAttribute(); //复盘归位数
+            $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
+            $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
+            $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
+            $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount();
             $inventoryAccount->update();
             Controller::logS(__METHOD__,"修改盘点任务记录".__FUNCTION__,json_encode($inventoryId));
             $inventoryAccountMission=InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])->where('id',$inventoryAccountMission->id)->first();
@@ -539,9 +541,10 @@ class InventoryAccountService
         if ($inventoryAccountMission>0){
             $inventoryAccount=InventoryAccount::query()->find($inventoryAccountId);
             $inventoryAccount->total=$inventoryAccount->total-1;
-            $inventoryAccount->processed=$inventoryAccount->getProcessedAttribute();//已盘点数
-            $inventoryAccount->difference=$inventoryAccount->getDifferenceAttribute();//盘点差异数
-            $inventoryAccount->returned=$inventoryAccount->getReturnedAttribute(); //复盘归位数
+            $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
+            $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
+            $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
+            $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount();
             $inventoryAccount->update();
             Controller::logS(__METHOD__,'删除盘点记录时修改盘点任务信息'.__FUNCTION__,json_encode($inventoryAccountId));
         }
@@ -554,9 +557,10 @@ class InventoryAccountService
         app('LogService')->log(__METHOD__,"跳过盘点记录修改checked状态",json_encode($inventoryAccountMissionId));
         if ($inventoryAccountMission->checked=='跳过'){
             $inventoryAccount=InventoryAccount::query()->find($inventoryAccountId);
-            $inventoryAccount->processed=$inventoryAccount->getProcessedAttribute();//已盘点数
-            $inventoryAccount->difference=$inventoryAccount->getDifferenceAttribute();//盘点差异数
-            $inventoryAccount->returned=$inventoryAccount->getReturnedAttribute(); //复盘归位数
+            $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
+            $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
+            $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
+            $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount();
             $inventoryAccount->update();
             Controller::logS(__METHOD__,'跳过盘点记录时修改盘点任务信息'.__FUNCTION__,json_encode($inventoryAccountId));
         }
@@ -582,9 +586,10 @@ class InventoryAccountService
         }
         app('LogService')->log(__METHOD__,"批量跳过或确认差异",json_encode($checkData));
         $inventoryAccount=InventoryAccount::query()->find($inventoryAccountId);
-        $inventoryAccount->processed=$inventoryAccount->getProcessedAttribute();//已盘点数
-        $inventoryAccount->difference=$inventoryAccount->getDifferenceAttribute();//盘点差异数
-        $inventoryAccount->returned=$inventoryAccount->getReturnedAttribute(); //复盘归位数
+        $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();//已盘点数
+        $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();//盘点差异数
+        $inventoryAccount->returned=$inventoryAccount->getReturnedAmount(); //复盘归位数
+        $inventoryAccount->ignored=$inventoryAccount->getIgnoredAmount();
         $inventoryAccount->update();
         Controller::logS(__METHOD__,'批量跳过或确认差异修改盘点任务信息'.__FUNCTION__,json_encode($inventoryAccountId));
         return $inventoryAccountMissions;

+ 32 - 0
database/migrations/2020_11_11_130723_add_ignored_to_inventory__accounts.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddIgnoredToInventoryAccounts extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('inventory_accounts', function (Blueprint $table) {
+            $table->integer('ignored')->nullable()->comment('跳过数');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('inventory_accounts', function (Blueprint $table) {
+            $table->dropColumn('ignored');
+        });
+    }
+}

+ 0 - 21
tests/Inventory/ExampleTest.php

@@ -1,21 +0,0 @@
-<?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);
-    }
-
-}

+ 44 - 0
tests/Inventory/UpdateInventoryAccount.php

@@ -0,0 +1,44 @@
+<?php
+
+
+namespace Tests\Inventory;
+
+
+use App\InventoryAccount;
+use App\Services\common\BatchUpdateService;
+use Carbon\Carbon;
+use Tests\TestCase;
+
+class UpdateInventoryAccount extends TestCase
+{
+    public $inventoryAccounts;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->inventoryAccounts=InventoryAccount::query()->get();
+    }
+
+    public function testUpdateInventoryAccount(){
+        $updateParams = [[
+            'id','processed','ignored','updated_at'
+        ]];
+        $updated_at=Carbon::now()->toDateTimeString();
+        foreach ($this->inventoryAccounts as $inventoryAccount){
+            if ($inventoryAccount->getIgnoredAmount()>0){
+                $updateParams[] = [
+                    'id'=>$inventoryAccount->id,
+                    'processed'=>$inventoryAccount->getProcessedAmount(),
+                    'ignored' => $inventoryAccount->getIgnoredAmount(),
+                    'updated_at'=>$updated_at,
+                ];
+            }
+        }
+        if(count($updateParams) > 1){
+            $this->batchUpdate($updateParams);
+        }
+    }
+    public function batchUpdate($params){
+        return app(BatchUpdateService::class)->batchUpdate('inventory_accounts',$params);
+    }
+
+}