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
@@ -162,6 +162,13 @@ new class extends Component
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('catalog.shared') }}</p>
@endif
@if ($unit->usesStock)
<p class="flex items-center gap-1 text-sm text-zinc-600 dark:text-zinc-300">
<x-icon name="archive-box" class="size-4" aria-hidden="true" />
{{ __('catalog.service_units.uses_stock_on') }}
</p>
@endif
@foreach ($node->services as $serviceNode)
@php($service = $serviceNode->service)
@@ -3,6 +3,7 @@
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Catalog\Application\UseCases\AddServiceUnit;
use App\Modules\Catalog\Application\UseCases\RenameCatalogItem;
use App\Modules\Catalog\Application\UseCases\SetServiceUnitUsesStock;
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
use App\Modules\Catalog\Presentation\Livewire\Forms\CatalogItemForm;
@@ -11,7 +12,8 @@ use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Add page (no {serviceUnit}) and edit page (with {serviceUnit}) of a service unit.
* Add page (no {serviceUnit}) and edit page (with {serviceUnit}) of a service unit:
* its name and whether stock and machine features are used in it (spec 19).
*/
new class extends Component
{
@@ -21,6 +23,11 @@ new class extends Component
#[Locked]
public string $unitName = '';
#[Locked]
public bool $isShared = false;
public bool $usesStock = false;
public CatalogItemForm $form;
public function mount(CatalogQueries $catalogQueries, ?int $serviceUnit = null): void
@@ -37,9 +44,11 @@ new class extends Component
$this->serviceUnitId = $summary->id;
$this->form->name = $summary->name;
$this->isShared = $summary->isShared;
$this->usesStock = $summary->usesStock;
}
public function save(AddServiceUnit $addServiceUnit, RenameCatalogItem $renameItem): void
public function save(AddServiceUnit $addServiceUnit, RenameCatalogItem $renameItem, SetServiceUnitUsesStock $setUsesStock): void
{
$this->authorize('catalog.manage');
@@ -47,10 +56,12 @@ new class extends Component
try {
if ($this->serviceUnitId === null) {
$addServiceUnit->execute($name);
$id = $addServiceUnit->execute($name);
$setUsesStock->execute($id, $this->usesStock);
session()->flash('status', __('catalog.status.created', ['name' => trim($name)]));
} else {
$renameItem->execute(CatalogLevel::ServiceUnit, $this->serviceUnitId, $name);
$setUsesStock->execute($this->serviceUnitId, $this->usesStock && ! $this->isShared);
session()->flash('status', __('catalog.status.updated', ['name' => trim($name)]));
}
} catch (CatalogItemNotFound) {
@@ -85,6 +96,13 @@ new class extends Component
<form wire:submit="save" class="space-y-6" novalidate>
<x-input wire:model="form.name" :label="__('catalog.fields.name')" autocomplete="off" required />
@unless ($isShared)
<div class="space-y-1">
<x-checkbox id="uses-stock" wire:model="usesStock" :label="__('catalog.service_units.uses_stock')" />
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('catalog.service_units.uses_stock_hint') }}</p>
</div>
@endunless
<div class="flex flex-wrap gap-3">
<x-button submit :text="__('catalog.save')" />
<x-button :href="route('catalog.index')" wire:navigate subtle color="black" :text="__('catalog.cancel')" />