import { Head, Link, useForm } from '@inertiajs/react'; import { InventoryNotice, InventoryPagination } from '@/components/inventory'; import { FormErrors, PageTitle, Panel, controlClass, } from '@/components/procurement'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { date } from '@/types/procurement'; import { quantity } from '@/types/inventory'; import type { Page, StockItem, StockMovement, Warehouse, } from '@/types/inventory'; type Props = { items: StockItem[]; warehouses: Warehouse[]; balances: { stock_item_id: number; warehouse_id: number; quantity_milli: number; }[]; movements: Page; filters: { search?: string; warehouse_id?: number }; canManage: boolean; }; export default function Stock({ items, warehouses, balances, movements, filters, canManage, }: Props) { const search = useForm({ search: filters.search ?? '', warehouse_id: filters.warehouse_id ? String(filters.warehouse_id) : '', }); const item = useForm({ code: '', name: '', unit: '' }); const warehouse = useForm({ code: '', name: '' }); return ( <>
Saídas, transferências e inventários →
{ e.preventDefault(); search.get('/stock', { preserveState: true }); }} > search.setData('search', e.target.value) } />
{balances.map((balance) => { const article = items.find( (i) => i.id === balance.stock_item_id, ); return ( ); })}
Artigo Armazém Quantidade em stock
{article?.code}{' '} · {article?.name} { warehouses.find( (w) => w.id === balance.warehouse_id, )?.name } {quantity( balance.quantity_milli, )}{' '} {article?.unit}
{balances.length === 0 && (

Não há entradas confirmadas para estes filtros. Criar um artigo não cria stock.

)}
{movements.data.map((m) => (
{m.quantity_milli > 0 ? '+' : ''} {quantity(m.quantity_milli)}{' '} {m.snapshot.stock_item.unit} ·{' '} {m.snapshot.stock_item.code}

{m.snapshot.stock_item.name} ·{' '} {m.snapshot.warehouse.name} {m.snapshot.equipment && ` · Equipamento ${m.snapshot.equipment.code}`}

{date(m.moved_at)} · Utilizador # {m.moved_by} ·{' '} {m.snapshot.reference ?? m.snapshot.order_number}{' '} · {m.movement_type} {m.snapshot.delivery_note && ` · Guia ${m.snapshot.delivery_note}`}

{m.snapshot.receipt_id ? 'Abrir recepção' : 'Abrir operações'}
))}
{movements.data.length === 0 && (

Ainda não há movimentos disponíveis.

)}

Movimentos confirmados preservados. As transferências têm duas linhas ligadas à mesma operação.

{items.map((i) => (

{i.code} · {i.name} ·{' '} {i.unit}

))}
{canManage && (
{ e.preventDefault(); item.post('/stock/artigos', { preserveScroll: true, onSuccess: () => item.reset(), }); }} > {(['code', 'name', 'unit'] as const).map( (key) => (
item.setData( key, e.target.value, ) } />
), )} )}
{warehouses.map((w) => (

{w.code} · {w.name}

))}
{canManage && (
{ e.preventDefault(); warehouse.post('/stock/armazens', { preserveScroll: true, onSuccess: () => warehouse.reset(), }); }} > {(['code', 'name'] as const).map((key) => (
warehouse.setData( key, e.target.value, ) } />
))} )}
); } Stock.layout = { breadcrumbs: [{ title: 'Stock e movimentos', href: '/stock' }], };