commit melhorias compras4
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-22 16:28:03 +02:00
parent efd97e265b
commit 36dcfdf00c
118 changed files with 6042 additions and 92 deletions
@@ -0,0 +1,139 @@
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<HTMLFormElement>(null);
const dirty = hasPreparationChanges(initial, form.data);
useEffect(() => {
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form: formElement.current, dirty },
}),
);
}, [dirty]);
return (
<>
<Head title={`Reafectação · ${order.number}`} />
<div className="mx-auto flex w-full max-w-5xl flex-col gap-6 p-5 lg:p-8">
<PageTitle
eyebrow="Finanças"
title="Reafectar compromisso em MZN"
description={`${order.number} · Documento em ${order.currency} · Versão ${version}`}
/>
<p>
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.
</p>
<FormErrors errors={form.errors} />
<form
ref={formElement}
className="space-y-5"
onSubmit={(event) => {
event.preventDefault();
form.post(`/ordens/${order.id}/reafectacao`);
}}
>
<BudgetDistributionFields
options={options}
rows={form.data.budget_distribution_preparation}
onChange={(rows) =>
form.setData(
'budget_distribution_preparation',
rows,
)
}
reason={form.data.reason}
onReason={(reason) => form.setData('reason', reason)}
/>
<div className="flex flex-wrap gap-3">
<Button disabled={form.processing}>
Confirmar nova versão
</Button>
<Button variant="outline" asChild>
<Link href={`/ordens/${order.id}`}>
Voltar à ordem
</Link>
</Button>
</div>
</form>
<Panel title="Histórico preservado">
{history.map((event, index) => (
<details key={index} className="border-b py-3">
<summary>
{event.version === null
? event.kind
: `Reafectação · versão ${event.version}`}{' '}
· {event.created_at} · Interveniente #
{event.created_by}
</summary>
{event.reason && <p>{event.reason}</p>}
<ul>
{event.allocations.map((row) => (
<li key={row.allocation_key}>
Artigo #{row.line_id} · Centro #
{row.centre_id} · Sem IVA:{' '}
{money(row.subtotal_minor)} · Total:{' '}
{money(row.total_minor)}
</li>
))}
</ul>
</details>
))}
</Panel>
</div>
</>
);
}