import { Head, useForm } from '@inertiajs/react'; import { useState } from 'react'; import { InventoryNotice, InventoryPagination } from '@/components/inventory'; import { PageTitle, Panel, FormErrors, controlClass, } from '@/components/procurement'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { quantity } from '@/types/inventory'; import type { StockItem, Warehouse, Page } from '@/types/inventory'; type Operation = { id: number; kind: string; reference: string; reason: string; destination?: string; quantity_milli: number; theoretical_milli: number; stock_item_id: number; warehouse_id: number; recorded_at: string; snapshot: { actor: { name: string }; responsible: { name: string }; stock_item: { name: string; unit: string }; warehouse: { name: string }; destination_warehouse?: { name: string } | null; equipment?: { code: string; description: string } | null; }; }; type Props = { items: StockItem[]; warehouses: Warehouse[]; users: { id: number; name: string }[]; balances: { stock_item_id: number; warehouse_id: number; quantity: number; version: number; }[]; operations: Page; counts: Operation[]; canOperate: boolean; demo?: boolean; equipment?: { id: number; code: string; description: string }[]; }; const kinds: Record = { issue: 'Saída', transfer: 'Transferência', count: 'Contagem física', adjustment: 'Ajuste de inventário', }; export default function Operations({ items, warehouses, users, balances, operations, counts, canOperate, demo = false, equipment = [], }: Props) { const [message, setMessage] = useState(''); const form = useForm({ kind: 'issue', reference: '', idempotency_key: crypto.randomUUID(), stock_item_id: String(items[0]?.id ?? ''), warehouse_id: String(warehouses[0]?.id ?? ''), destination_warehouse_id: '', responsible_id: '', destination: '', reason: '', quantity: '', count_id: '', ledger_version: 0, equipment_id: '', }); const balance = balances.find( (b) => String(b.stock_item_id) === form.data.stock_item_id && String(b.warehouse_id) === form.data.warehouse_id, ); return ( <>
{canOperate && form.data.kind === 'issue' && ( )} {demo && (

Demonstração pública com dados fictícios. O formulário apenas simula a revisão.

)} {canOperate ? (
{ e.preventDefault(); if (demo) { setMessage( 'Simulação revista. Nenhum movimento real foi criado.', ); return; } form.transform((d) => ({ ...d, ledger_version: balance?.version ?? 0, })); form.post('/stock/operacoes', { onSuccess: () => { form.setData({ ...form.data, idempotency_key: crypto.randomUUID(), reference: '', quantity: '', reason: '', }); }, }); }} >

Stock teórico:{' '} {quantity(balance?.quantity ?? 0)} · versão{' '} {balance?.version ?? 0}. Confirme a contagem física sobre este saldo; movimentos posteriores exigem nova contagem.

{form.data.kind === 'transfer' && ( )} {form.data.kind === 'issue' && ( )} {form.data.kind === 'adjustment' ? ( ) : ( )}