authorize('inventory.count'); abort_if(app(InventoryCountQueries::class)->findCount($count) === null, 404); $this->countId = $count; } #[Computed] public function count(): InventoryCountSummary { return app(InventoryCountQueries::class)->findCount($this->countId) ?? abort(404); } /** * @return list */ #[Computed] public function lines(): array { return app(InventoryCountQueries::class)->lines($this->countId); } /** * The lines shown, by group name. * * @return array> */ public function groupedLines(): array { $groups = []; foreach ($this->lines as $line) { if (! $this->onlyUncounted || ! $line->isCounted()) { $groups[$line->groupName][] = $line; } } return $groups; } public function uncountedCount(): int { return count(array_filter($this->lines, fn (InventoryCountLine $line): bool => ! $line->isCounted())); } public function updatedOnlyUncounted(): void { $this->authorize('inventory.count'); } public function saveCounted(int $itemId, string $value, InventoryCounts $counts): void { $this->authorize('inventory.count'); $this->resetErrorBag('counted.'.$itemId); $line = collect($this->lines)->firstWhere('itemId', $itemId) ?? abort(404); try { $book = $counts->record($this->countId, $itemId, $value, (int) auth()->id()); } catch (InvalidStockQuantity) { $this->addError('counted.'.$itemId, __('inventory.counts.errors.quantity')); return; } catch (InventoryCountConfirmed) { $this->message = __('inventory.counts.errors.confirmed'); return; } catch (InventoryCountNotFound|StockItemNotFound|StockItemNotInCount) { $this->message = __('inventory.errors.not_found'); return; } unset($this->lines); if ($book === null) { $this->message = __('inventory.counts.cleared', ['item' => $line->itemName]); return; } $counted = (int) StockQuantity::parse($value)?->milli; $this->message = __('inventory.counts.saved', [ 'item' => $line->itemName, 'counted' => $this->quantity($counted, $line->unit), 'difference' => $this->signed($counted - $book, $line->unit), ]); } public function confirmCount(): void { $this->authorize('inventory.manage-counts'); $this->js("document.getElementById('confirm-count-dialog').showModal()"); } public function confirm(InventoryCounts $counts): void { $this->authorize('inventory.manage-counts'); try { $adjustments = $counts->confirm($this->countId, (int) auth()->id()); $this->message = trans_choice('inventory.counts.confirmed_message', $adjustments, ['count' => $adjustments]); } catch (InventoryCountConfirmed) { $this->message = __('inventory.counts.errors.confirmed'); } catch (InventoryCountNotFound|StockItemNotFound) { $this->message = __('inventory.errors.not_found'); } unset($this->count, $this->lines); $this->js("document.getElementById('confirm-count-dialog').close(); document.getElementById('count-status').focus()"); } public function signed(int $milli, mixed $unit): string { return ($milli > 0 ? '+' : '').$this->quantity($milli, $unit); } public function differenceValue(InventoryCountLine $line): int { return StockValuation::valueCents((int) $line->differenceMilli(), $line->unitCostHundredths); } public function render(): mixed { return $this->view()->title(__('inventory.counts.name', ['date' => $this->dateLabel($this->count->countedOn)])); } }; ?>
@php($count = $this->count)

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

{{ __('inventory.counts.name', ['date' => $this->dateLabel($count->countedOn)]) }}

{{ $count->groupNames === [] ? __('inventory.counts.whole_stock') : implode(', ', $count->groupNames) }} · {{ __('inventory.counts.started_by', ['name' => $count->startedByName]) }}

@if ($count->isConfirmed)

@can('inventory.see-value')

{{ __('inventory.counts.values', ['before' => $this->money((int) $count->valueBeforeCents), 'after' => $this->money((int) $count->valueAfterCents)]) }}

@endcan @else

{{ __('inventory.counts.count_help') }}

@endif

{{ $message }}

@unless ($count->isConfirmed) @endunless

{{ trans_choice('inventory.counts.uncounted', $this->uncountedCount(), ['count' => $this->uncountedCount()]) }}

@if (! $count->isConfirmed) @can('inventory.manage-counts') @endcan @else @can('inventory.manage-counts') @endcan @endif
@forelse ($this->groupedLines() as $groupName => $lines)

{{ $groupName }}

    @foreach ($lines as $line) @php($difference = $line->differenceMilli())
  • {{ $line->itemName }}

    @if ($line->isCounted()) {{ __('inventory.counts.book', ['book' => $this->quantity((int) $line->bookMilli, $line->unit)]) }} · {{ __('inventory.counts.difference', ['difference' => $this->signed((int) $difference, $line->unit)]) }} @can('inventory.see-value') ({{ $this->money($this->differenceValue($line)) }}) @endcan · {{ $line->countedByName }}, {{ $this->dateLabel((string) $line->countedAt) }} @else · {{ __('inventory.counts.current', ['balance' => $this->quantity($line->currentBalanceMilli, $line->unit)]) }} @endif

    @if ($count->isConfirmed)

    {{ $line->isCounted() ? $this->quantity((int) $line->countedMilli, $line->unit) : '–' }}

    @else
    itemId) aria-invalid="true" aria-describedby="counted-{{ $line->itemId }}-error" @enderror class="mt-1 h-10 w-full rounded-md border border-zinc-500 bg-white px-2 text-right text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300 dark:border-zinc-400 dark:bg-zinc-900 dark:text-zinc-100" /> @error('counted.'.$line->itemId)

    {{ $message }}

    @enderror
    @endif
  • @endforeach
@empty

{{ __('inventory.counts.no_lines') }}

@endforelse @can('inventory.manage-counts')

{{ __('inventory.counts.confirm_text') }}

@if ($this->uncountedCount() > 0)

{{ trans_choice('inventory.counts.confirm_uncounted', $this->uncountedCount(), ['count' => $this->uncountedCount()]) }}

@endif
@endcan