import { Head, Link, useForm, usePage } from '@inertiajs/react'; import { useEffect, useRef } from 'react'; import { hasPreparationChanges } from '@/lib/requisition-history'; import BudgetDistributionFields, { type BudgetDistributionOption, } from '@/components/budget-distribution-fields'; import { FormErrors, PageTitle, Panel } from '@/components/procurement'; import { Button } from '@/components/ui/button'; import { money } from '@/types/procurement'; export default function Amendment({ order, options, planHash, version, history, }: { order: { id: number; number: string; currency: string }; options: BudgetDistributionOption[]; planHash: string; version: number; history: { kind: string; created_at: string; created_by: number; version: number | null; reason: string | null; allocations: { allocation_key: string; line_id: number; centre_id: number; subtotal_minor: number; total_minor: number; }[]; }[]; }) { const actor = usePage().props.auth?.user; const initial = { operation_key: crypto.randomUUID(), expected_plan_hash: planHash, reason: '', budget_distribution_preparation: options.map( ({ allocation_key, line_id, centre_id, subtotal, total }) => ({ allocation_key, line_id, centre_id, subtotal, total, }), ), }; const form = useForm( `distribution-amendment:${actor?.tenant_id}:${actor?.id}:${order.id}:${planHash}`, initial, ); const formElement = useRef(null); const dirty = hasPreparationChanges(initial, form.data); useEffect(() => { window.dispatchEvent( new CustomEvent('sgc:context-dirty', { detail: { form: formElement.current, dirty }, }), ); }, [dirty]); return ( <>

Confira a imputação exigida pela conversão cumulativa da factura parcial. Os totais documentais e a taxa congelada permanecem preservados. A alteração exige saldo disponível e conserva os valores já consumidos.

{ event.preventDefault(); form.post(`/ordens/${order.id}/reafectacao`); }} > form.setData( 'budget_distribution_preparation', rows, ) } reason={form.data.reason} onReason={(reason) => form.setData('reason', reason)} />
{history.map((event, index) => (
{event.version === null ? event.kind : `Reafectação · versão ${event.version}`}{' '} · {event.created_at} · Interveniente # {event.created_by} {event.reason &&

{event.reason}

}
    {event.allocations.map((row) => (
  • Artigo #{row.line_id} · Centro # {row.centre_id} · Sem IVA:{' '} {money(row.subtotal_minor)} · Total:{' '} {money(row.total_minor)}
  • ))}
))}
); }