move into sonardesk

This commit is contained in:
Mark Gregory
2026-10-12 14:50:13 +01:00
parent 5f0d2ceb72
commit 38b4a7406f
879 changed files with 24021 additions and 1 deletions
@@ -0,0 +1,24 @@
<?php
namespace Modules\Commerce\Services;
use Illuminate\Support\Facades\DB;
use Modules\Commerce\Contracts\InventoryProvider;
use Modules\Commerce\Models\InventoryMovement;
use Modules\Commerce\Models\Product;
final class DatabaseInventoryProvider implements InventoryProvider
{
public function adjust(Product $product, int $quantity, string $reason, ?int $userId = null): void
{
DB::transaction(function () use ($product, $quantity, $reason, $userId) {
$product->increment('stock_quantity', $quantity);
InventoryMovement::create(['product_id' => $product->id, 'quantity' => $quantity, 'reason' => $reason, 'created_by' => $userId]);
});
}
public function available(Product $product): int
{
return max(0, (int) $product->stock_quantity);
}
}