authorize('inventory.manage'); } /** * @return list */ #[Computed] public function groups(): array { return app(StockQueries::class)->groups(); } public function add(AddStockItemGroup $addGroup): void { $this->authorize('inventory.manage'); try { $addGroup->execute($this->newName); } catch (InvalidStockName) { $this->addError('newName', __('inventory.errors.name')); return; } catch (StockNameTaken) { $this->addError('newName', __('inventory.errors.name_taken')); return; } $this->message = __('inventory.groups.added', ['name' => trim($this->newName)]); $this->newName = ''; unset($this->groups); $this->js("document.getElementById('new-group-name')?.focus()"); } public function startRename(int $groupId): void { $this->authorize('inventory.manage'); $group = collect($this->groups)->firstWhere('id', $groupId) ?? abort(404); $this->editingId = $group->id; $this->editingName = $group->name; $this->resetErrorBag(); $this->js("setTimeout(() => document.getElementById('rename-group')?.focus())"); } public function cancelRename(): void { $id = $this->editingId; $this->editingId = null; $this->js("document.getElementById('rename-group-{$id}')?.focus()"); } public function rename(ChangeStockItemGroup $change): void { $this->authorize('inventory.manage'); try { $change->rename((int) $this->editingId, $this->editingName); } catch (InvalidStockName) { $this->addError('editingName', __('inventory.errors.name')); return; } catch (StockNameTaken) { $this->addError('editingName', __('inventory.errors.name_taken')); return; } catch (StockItemGroupNotFound) { $this->message = __('inventory.errors.not_found'); } $id = $this->editingId; $this->message = __('inventory.groups.renamed', ['name' => trim($this->editingName)]); $this->editingId = null; unset($this->groups); $this->js("document.getElementById('rename-group-{$id}')?.focus()"); } public function move(int $groupId, string $direction, ChangeStockItemGroup $change): void { $this->authorize('inventory.manage'); $group = collect($this->groups)->firstWhere('id', $groupId) ?? abort(404); $up = $direction === 'up'; try { $moved = $change->move($groupId, $up); } catch (StockItemGroupNotFound) { $this->message = __('inventory.errors.not_found'); return; } $this->message = __('inventory.groups.'.($moved ? ($up ? 'moved_up' : 'moved_down') : ($up ? 'first' : 'last')), ['name' => $group->name]); unset($this->groups); } public function toggleActive(int $groupId, ChangeStockItemGroup $change): void { $this->authorize('inventory.manage'); $group = collect($this->groups)->firstWhere('id', $groupId) ?? abort(404); try { $change->setActive($groupId, ! $group->isActive); } catch (StockItemGroupNotFound) { $this->message = __('inventory.errors.not_found'); return; } $this->message = __($group->isActive ? 'inventory.groups.deactivated' : 'inventory.groups.activated', ['name' => $group->name]); unset($this->groups); } public function render(): mixed { return $this->view()->title(__('inventory.groups.title')); } }; ?>

{{ __('inventory.groups.title') }}

{{ __('inventory.groups.intro') }}

{{ __('inventory.groups.back') }}

{{ $message }}

@if ($this->groups === [])

{{ __('inventory.groups.none') }}

@else
    @foreach ($this->groups as $group)
  • @if ($editingId === $group->id)
    @else

    {{ $group->name }}

    {{ trans_choice('inventory.groups.items', $group->itemCount, ['count' => $group->itemCount]) }} @unless ($group->isActive) · {{ __('inventory.status.inactive') }} @endunless

    @endif
  • @endforeach
@endif