refactor(inventory): record stock operations consistently
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Commerce\Purchase\Services;
|
||||
|
||||
use App\Domains\Commerce\Catalog\Models\Inventory;
|
||||
use App\Domains\Commerce\Purchase\Models\Purchase;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -69,15 +70,12 @@ class TenantTransactionResetService
|
||||
'users_preserved' => DB::table('users')->where('tenant_codigo', $tenantCode)->count(),
|
||||
];
|
||||
|
||||
DB::table('inventories')
|
||||
->whereIn('id', $scope['inventory_ids'])
|
||||
->update([
|
||||
'real_stock' => DB::raw('real_stock + sold_units - refunded_units'),
|
||||
'reserved_stock' => 0,
|
||||
'entry_reserved_stock' => 0,
|
||||
'sold_units' => 0,
|
||||
'refunded_units' => 0,
|
||||
]);
|
||||
Inventory::query()
|
||||
->whereKey($scope['inventory_ids'])
|
||||
->orderBy('id')
|
||||
->lockForUpdate()
|
||||
->get()
|
||||
->each(fn (Inventory $inventory) => $inventory->resetTransactionCounters());
|
||||
|
||||
return $summary;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user