@@ -1,4 +1,7 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import BudgetDistributionFields, {
|
||||
type BudgetDistributionOption,
|
||||
} from '@/components/budget-distribution-fields';
|
||||
import AgreementOrderBindings, {
|
||||
type OrderAgreementBinding,
|
||||
type OrderAgreementOption,
|
||||
@@ -19,11 +22,12 @@ import { money, roleLabels, date } from '@/types/procurement';
|
||||
import type { MatrixRow, PurchaseAward } from '@/types/purchase';
|
||||
|
||||
type Props = {
|
||||
budgetDistributionOptions?: BudgetDistributionOption[] | null;
|
||||
agreementOrderLimitsReady?: boolean;
|
||||
agreementOptions?: OrderAgreementOption[];
|
||||
agreementLines?: OrderAgreementLine[];
|
||||
agreementSearch?: string;
|
||||
requisition: { id: number; number: string };
|
||||
requisition: { id: number; number: string; process_version?: number };
|
||||
comparison: {
|
||||
rows: MatrixRow[];
|
||||
ready: boolean;
|
||||
@@ -50,17 +54,51 @@ export default function Award({
|
||||
agreementOptions = [],
|
||||
agreementLines = [],
|
||||
agreementSearch = '',
|
||||
budgetDistributionOptions = null,
|
||||
}: Props) {
|
||||
const selection = useForm({
|
||||
quotation_id: '',
|
||||
justification: '',
|
||||
delivery_date: '',
|
||||
delivery_location: '',
|
||||
});
|
||||
const actor = usePage().props.auth?.user;
|
||||
const selection = useForm(
|
||||
`award-selection:${actor?.tenant_id}:${actor?.id}:${requisition.id}:${requisition.process_version ?? 0}`,
|
||||
{
|
||||
quotation_id: '',
|
||||
justification: '',
|
||||
delivery_date: '',
|
||||
delivery_location: '',
|
||||
...(budgetDistributionOptions === null
|
||||
? {}
|
||||
: {
|
||||
budget_distribution_preparation:
|
||||
budgetDistributionOptions.map(
|
||||
({
|
||||
allocation_key,
|
||||
line_id,
|
||||
centre_id,
|
||||
subtotal,
|
||||
total,
|
||||
}) => ({
|
||||
allocation_key,
|
||||
line_id,
|
||||
centre_id,
|
||||
subtotal,
|
||||
total,
|
||||
}),
|
||||
),
|
||||
reason: '',
|
||||
}),
|
||||
},
|
||||
);
|
||||
const decision = useForm({ decision: 'approved', comment: '' });
|
||||
const issue = useForm({
|
||||
agreement_bindings: [] as OrderAgreementBinding[],
|
||||
});
|
||||
const selectedQuote = comparison.rows.find(
|
||||
(row) => String(row.id) === selection.data.quotation_id,
|
||||
);
|
||||
const selectedReference =
|
||||
selectedQuote?.reference_amounts ??
|
||||
(selectedQuote && (selectedQuote.currency ?? 'MZN') === 'MZN'
|
||||
? selectedQuote
|
||||
: null);
|
||||
return (
|
||||
<>
|
||||
<Head title={`Adjudicação · ${requisition.number}`} />
|
||||
@@ -81,9 +119,12 @@ export default function Award({
|
||||
/>
|
||||
<div className="rounded-xl border border-amber-200 bg-amber-50 p-5 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
|
||||
Ambiente de desenvolvimento: os documentos não autorizam
|
||||
compras reais. O orçamento ainda não é verificado. Excepções
|
||||
à regra preservada neste processo ou à maior pontuação
|
||||
exigem um circuito próprio de revisão.
|
||||
compras reais.{' '}
|
||||
{budgetDistributionOptions === null
|
||||
? 'O orçamento ainda não é verificado.'
|
||||
: 'O saldo de cada parcela é conferido no controlo orçamental.'}{' '}
|
||||
Excepções à regra preservada neste processo ou à maior
|
||||
pontuação exigem um circuito próprio de revisão.
|
||||
</div>
|
||||
<Panel
|
||||
title="Comparação actual"
|
||||
@@ -201,12 +242,14 @@ export default function Award({
|
||||
className={controlClass}
|
||||
required
|
||||
value={selection.data.quotation_id}
|
||||
onChange={(e) =>
|
||||
onChange={(e) => {
|
||||
selection.setData(
|
||||
'quotation_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
);
|
||||
if (budgetDistributionOptions !== null)
|
||||
selection.setData('reason', '');
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Seleccione uma proposta no topo
|
||||
@@ -233,6 +276,37 @@ export default function Award({
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{budgetDistributionOptions !== null &&
|
||||
selection.data.quotation_id !== '' && (
|
||||
<div className="space-y-3">
|
||||
<p>
|
||||
{selectedReference
|
||||
? `Referência da proposta em MZN: sem IVA ${money(selectedReference.subtotal_minor, 'MZN')} · total ${money(selectedReference.total_minor, 'MZN')}. Confira as parcelas abaixo.`
|
||||
: 'Referência em MZN indisponível. Confira a proposta e a taxa congelada.'}
|
||||
</p>
|
||||
<BudgetDistributionFields
|
||||
options={budgetDistributionOptions}
|
||||
rows={
|
||||
selection.data
|
||||
.budget_distribution_preparation ??
|
||||
[]
|
||||
}
|
||||
onChange={(rows) =>
|
||||
selection.setData(
|
||||
'budget_distribution_preparation',
|
||||
rows,
|
||||
)
|
||||
}
|
||||
reason={selection.data.reason ?? ''}
|
||||
onReason={(value) =>
|
||||
selection.setData(
|
||||
'reason',
|
||||
value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="award-justification">
|
||||
Justificação da adjudicação
|
||||
@@ -297,7 +371,11 @@ export default function Award({
|
||||
</p>
|
||||
<Button
|
||||
disabled={
|
||||
selection.processing || !comparison.ready
|
||||
selection.processing ||
|
||||
!comparison.ready ||
|
||||
(budgetDistributionOptions !== null &&
|
||||
selectedQuote !== undefined &&
|
||||
selectedReference === null)
|
||||
}
|
||||
>
|
||||
Registar adjudicação para aprovação
|
||||
|
||||
@@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -49,14 +49,14 @@ export default function Orders({
|
||||
{order.number}
|
||||
</Link>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{
|
||||
order.snapshot.requisition
|
||||
.number
|
||||
}
|
||||
{order.snapshot.requisition
|
||||
?.number ??
|
||||
'Referência não preservada no original'}
|
||||
</p>
|
||||
</td>
|
||||
<td className="pr-4">
|
||||
{order.snapshot.supplier.name}
|
||||
{order.snapshot.supplier?.name ??
|
||||
'Fornecedor não preservado no original'}
|
||||
</td>
|
||||
<td className="pr-4">
|
||||
{date(order.issued_at)}
|
||||
|
||||
@@ -26,6 +26,7 @@ type Props = {
|
||||
decisions: {
|
||||
area: string;
|
||||
role: string;
|
||||
role_label?: string | null;
|
||||
decision: string;
|
||||
actor: string | null;
|
||||
date: string | null;
|
||||
@@ -60,6 +61,7 @@ const events: Record<string, string> = {
|
||||
'opening.recorded': 'Versão da acta de abertura registada',
|
||||
'requisition.created': 'Requisição criada',
|
||||
'requisition.updated': 'Requisição actualizada',
|
||||
'requisition.allocations_prepared': 'Distribuição preparada',
|
||||
'requisition.submitted': 'Requisição submetida',
|
||||
'requisition.revision_created': 'Revisão criada em novo processo',
|
||||
'approval.approved': 'Etapa da estimativa aprovada',
|
||||
@@ -80,6 +82,12 @@ const events: Record<string, string> = {
|
||||
'budget.award': 'Reserva ajustada à adjudicação',
|
||||
'budget.commit': 'Compromisso registado',
|
||||
'budget.release': 'Reserva libertada',
|
||||
'budget.distribution_reserve': 'Reserva distribuída registada',
|
||||
'budget.distribution_award': 'Distribuição da adjudicação confirmada',
|
||||
'budget.distribution_commit': 'Compromisso distribuído registado',
|
||||
'budget.distribution_release': 'Reserva distribuída libertada',
|
||||
'budget.distribution_cancel': 'Compromisso distribuído cancelado',
|
||||
'budget.distribution_amended': 'Compromisso reafectado por Finanças',
|
||||
'cancellation.requested': 'Cancelamento solicitado',
|
||||
'cancellation.approved': 'Cancelamento aprovado',
|
||||
'cancellation.rejected': 'Cancelamento rejeitado',
|
||||
@@ -217,7 +225,8 @@ export default function PurchaseProcess({
|
||||
<div className="flex flex-wrap justify-between gap-2">
|
||||
<strong className="font-medium">
|
||||
{decision.area} ·{' '}
|
||||
{roleLabels[decision.role] ??
|
||||
{decision.role_label ??
|
||||
roleLabels[decision.role] ??
|
||||
decision.role}
|
||||
</strong>
|
||||
<span>
|
||||
|
||||
@@ -28,12 +28,81 @@ export default function OrderShow({
|
||||
order,
|
||||
history,
|
||||
orderCancellation,
|
||||
snapshotComplete = true,
|
||||
}: {
|
||||
order: PurchaseOrder;
|
||||
history: History[];
|
||||
orderCancellation?: OrderCancellationState;
|
||||
snapshotComplete?: boolean;
|
||||
}) {
|
||||
const snapshot = order.snapshot;
|
||||
if (!snapshotComplete) {
|
||||
return (
|
||||
<>
|
||||
<Head title={order.number} />
|
||||
<div className="mx-auto grid w-full max-w-6xl min-w-0 gap-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras"
|
||||
title={order.number}
|
||||
description="Consulta dos dados preservados na emissão."
|
||||
/>
|
||||
<Panel title="Documento original incompleto">
|
||||
<p>
|
||||
Este documento não conserva todos os elementos da
|
||||
emissão. Os dados disponíveis são apresentados sem
|
||||
reconstruir condições ou aprovações a partir dos
|
||||
cadastros actuais.
|
||||
</p>
|
||||
<dl className="mt-4 grid gap-3 text-sm">
|
||||
<div>
|
||||
<dt>Fornecedor preservado</dt>
|
||||
<dd>
|
||||
{snapshot.supplier?.name ??
|
||||
'Não registado no original'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Emissão</dt>
|
||||
<dd>{date(order.issued_at)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Total com IVA</dt>
|
||||
<dd>
|
||||
{money(order.total_minor, order.currency)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p className="mt-4">
|
||||
Confira o documento de origem antes de o utilizar
|
||||
como comprovativo completo.
|
||||
</p>
|
||||
</Panel>
|
||||
<Panel title="Artigos preservados">
|
||||
<ul className="grid gap-3">
|
||||
{order.items.map((item) => (
|
||||
<li key={item.id} className="break-words">
|
||||
{item.description} · {item.quantity}{' '}
|
||||
{item.unit} ·{' '}
|
||||
{money(item.total_minor, order.currency)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Panel>
|
||||
<a
|
||||
className="underline"
|
||||
href={`/ordens/${order.id}/imprimir`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Imprimir os dados preservados
|
||||
</a>
|
||||
<Link className="underline" href="/ordens">
|
||||
Voltar às ordens
|
||||
</Link>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Head title={order.number} />
|
||||
|
||||
Reference in New Issue
Block a user