Let a service unit use stock and machines
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -38,6 +38,14 @@ interface CatalogQueries
|
||||
*/
|
||||
public function activeWorkTypesFor(array $serviceUnitIds): array;
|
||||
|
||||
/**
|
||||
* Active service units where stock and machine features are in use
|
||||
* (spec 19), in catalog order.
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
public function stockServiceUnitIds(): array;
|
||||
|
||||
public function findServiceUnit(int $id): ?ServiceUnitSummary;
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,5 +11,6 @@ final readonly class ServiceUnitSummary
|
||||
public string $name,
|
||||
public bool $isShared,
|
||||
public bool $isActive,
|
||||
public bool $usesStock = false,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user