Let a service unit use stock and machines

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:01:59 +02:00
co-authored by Claude Sonnet 5.5
parent d160854b79
commit 361a2974cf
16 changed files with 204 additions and 13 deletions
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Modules\Catalog\Application\UseCases;
use App\Modules\Catalog\Domain\Contracts\ServiceUnitRepository;
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
use App\Modules\Catalog\Domain\Exceptions\SharedUnitCannotUseStock;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Turns the stock and machine features on or off in a service unit. Turning
* them off hides the features; recorded movements and work lists stay.
*/
final class SetServiceUnitUsesStock
{
public function __construct(
private ServiceUnitRepository $serviceUnits,
private TransactionManager $transactions,
) {}
/**
* @throws CatalogItemNotFound
* @throws SharedUnitCannotUseStock
*/
public function execute(int $serviceUnitId, bool $usesStock): void
{
$this->transactions->run(function () use ($serviceUnitId, $usesStock): void {
$unit = $this->serviceUnits->findById($serviceUnitId) ?? throw new CatalogItemNotFound(CatalogLevel::ServiceUnit, $serviceUnitId);
$unit->useStock($usesStock);
$this->serviceUnits->save($unit);
});
}
}