UpdateInventoryAccount.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Tests\Inventory;
  3. use App\InventoryAccount;
  4. use App\Services\common\BatchUpdateService;
  5. use Carbon\Carbon;
  6. use Tests\TestCase;
  7. class UpdateInventoryAccount extends TestCase
  8. {
  9. public $inventoryAccounts;
  10. public function setUp(): void
  11. {
  12. parent::setUp(); // TODO: Change the autogenerated stub
  13. $this->inventoryAccounts=InventoryAccount::query()->get();
  14. }
  15. public function testUpdateInventoryAccount(){
  16. $updateParams = [[
  17. 'id','processed','ignored','updated_at'
  18. ]];
  19. $updated_at=Carbon::now()->toDateTimeString();
  20. foreach ($this->inventoryAccounts as $inventoryAccount){
  21. if ($inventoryAccount->getIgnoredAmount()>0){
  22. $updateParams[] = [
  23. 'id'=>$inventoryAccount->id,
  24. 'processed'=>$inventoryAccount->getProcessedAmount(),
  25. 'ignored' => $inventoryAccount->getIgnoredAmount(),
  26. 'updated_at'=>$updated_at,
  27. ];
  28. }
  29. }
  30. if(count($updateParams) > 1){
  31. $this->batchUpdate($updateParams);
  32. }
  33. }
  34. public function batchUpdate($params){
  35. return app(BatchUpdateService::class)->batchUpdate('inventory_accounts',$params);
  36. }
  37. }