@@ -89,6 +89,7 @@ export default function RequisitionForm({
|
||||
stockItems = [],
|
||||
defaultTaxRate = '16.00',
|
||||
catalogue,
|
||||
incompleteDraftsAvailable = false,
|
||||
}: {
|
||||
costCenters: CostCenter[];
|
||||
requisition: Requisition | null;
|
||||
@@ -97,37 +98,57 @@ export default function RequisitionForm({
|
||||
stockItems?: { id: number; code: string; name: string; unit: string }[];
|
||||
defaultTaxRate?: string;
|
||||
catalogue?: CatalogueOptions;
|
||||
incompleteDraftsAvailable?: boolean;
|
||||
}) {
|
||||
const ready = usePage().props.internalRequisitionReady === true;
|
||||
const prepared = requisition?.draft_input?.values;
|
||||
const preparedLines = prepared?.items?.map(
|
||||
(row) =>
|
||||
Object.fromEntries(
|
||||
Object.keys(emptyLine(defaultTaxRate)).map((key) => [
|
||||
key,
|
||||
key === 'key'
|
||||
? crypto.randomUUID()
|
||||
: String(row[key] ?? ''),
|
||||
]),
|
||||
) as Line,
|
||||
);
|
||||
const form = useForm({
|
||||
operation_key: ready ? crypto.randomUUID() : null,
|
||||
process_version: requisition?.process_version ?? null,
|
||||
cost_center_id: requisition ? String(requisition.cost_center_id) : '',
|
||||
priority: requisition?.priority ?? 'normal',
|
||||
needed_by: requisition?.needed_by ?? '',
|
||||
justification: requisition?.justification ?? '',
|
||||
items: requisition?.items.map((i) => ({
|
||||
source_line_id: i.id ? String(i.id) : '',
|
||||
catalogue_entry_id: i.catalogue_entry_id
|
||||
? String(i.catalogue_entry_id)
|
||||
: '',
|
||||
catalogue_version: i.catalogue_snapshot
|
||||
? String(i.catalogue_snapshot.version)
|
||||
: '',
|
||||
catalogue_code: i.catalogue_snapshot?.code ?? '',
|
||||
key: String(i.id),
|
||||
description: i.description,
|
||||
category: i.category,
|
||||
purchase_type: i.purchase_type,
|
||||
quantity: String(i.quantity),
|
||||
unit: i.unit,
|
||||
unit_price: (i.unit_price_minor / 100).toFixed(2),
|
||||
tax_rate: String(i.tax_rate),
|
||||
equipment_id: i.equipment_id ? String(i.equipment_id) : '',
|
||||
spare_part_id: i.spare_part_id ? String(i.spare_part_id) : '',
|
||||
production_area: i.production_area ?? '',
|
||||
downtime_started_at: i.downtime_started_at?.slice(0, 16) ?? '',
|
||||
})) ?? [emptyLine(defaultTaxRate)],
|
||||
cost_center_id:
|
||||
prepared?.cost_center_id != null
|
||||
? String(prepared.cost_center_id)
|
||||
: requisition?.cost_center_id != null
|
||||
? String(requisition.cost_center_id)
|
||||
: '',
|
||||
priority: prepared?.priority ?? requisition?.priority ?? 'normal',
|
||||
needed_by: prepared?.needed_by ?? requisition?.needed_by ?? '',
|
||||
justification:
|
||||
prepared?.justification ?? requisition?.justification ?? '',
|
||||
items: preparedLines ??
|
||||
requisition?.items.map((i) => ({
|
||||
source_line_id: i.id ? String(i.id) : '',
|
||||
catalogue_entry_id: i.catalogue_entry_id
|
||||
? String(i.catalogue_entry_id)
|
||||
: '',
|
||||
catalogue_version: i.catalogue_snapshot
|
||||
? String(i.catalogue_snapshot.version)
|
||||
: '',
|
||||
catalogue_code: i.catalogue_snapshot?.code ?? '',
|
||||
key: String(i.id),
|
||||
description: i.description,
|
||||
category: i.category,
|
||||
purchase_type: i.purchase_type,
|
||||
quantity: String(i.quantity),
|
||||
unit: i.unit,
|
||||
unit_price: (i.unit_price_minor / 100).toFixed(2),
|
||||
tax_rate: String(i.tax_rate),
|
||||
equipment_id: i.equipment_id ? String(i.equipment_id) : '',
|
||||
spare_part_id: i.spare_part_id ? String(i.spare_part_id) : '',
|
||||
production_area: i.production_area ?? '',
|
||||
downtime_started_at: i.downtime_started_at?.slice(0, 16) ?? '',
|
||||
})) ?? [emptyLine(defaultTaxRate)],
|
||||
});
|
||||
const formElement = useRef<HTMLFormElement>(null);
|
||||
useEffect(() => {
|
||||
@@ -171,6 +192,7 @@ export default function RequisitionForm({
|
||||
<form
|
||||
ref={formElement}
|
||||
data-context-save
|
||||
noValidate={incompleteDraftsAvailable}
|
||||
className="space-y-6"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -191,6 +213,15 @@ export default function RequisitionForm({
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{incompleteDraftsAvailable && (
|
||||
<p className="rounded-lg border p-4 text-sm">
|
||||
Pode guardar esta preparação mesmo com campos em
|
||||
falta. Os valores conhecidos são conferidos; os
|
||||
montantes incompletos ficam por completar. A
|
||||
submissão só fica disponível depois de completar o
|
||||
pedido.
|
||||
</p>
|
||||
)}
|
||||
{costCenters.length === 0 && (
|
||||
<div
|
||||
role="alert"
|
||||
@@ -198,7 +229,9 @@ export default function RequisitionForm({
|
||||
>
|
||||
O seu departamento ainda não tem centros de custo.
|
||||
Peça ao administrador para criar um antes de
|
||||
registar pedidos.
|
||||
{incompleteDraftsAvailable
|
||||
? 'submeter pedidos. Pode guardar a preparação enquanto aguarda.'
|
||||
: 'registar pedidos.'}
|
||||
</div>
|
||||
)}
|
||||
<Panel
|
||||
@@ -687,17 +720,22 @@ export default function RequisitionForm({
|
||||
Total estimado com IVA{' '}
|
||||
<strong className="ml-3 text-lg">
|
||||
{money(
|
||||
Number.isFinite(estimate)
|
||||
form.data.items.length > 0 &&
|
||||
form.data.items.every(
|
||||
(line) =>
|
||||
line.quantity !== '' &&
|
||||
line.unit_price !== '' &&
|
||||
line.tax_rate !== '',
|
||||
) &&
|
||||
Number.isFinite(estimate)
|
||||
? estimate
|
||||
: 0,
|
||||
: null,
|
||||
)}
|
||||
</strong>
|
||||
</p>
|
||||
</div>
|
||||
<p className="mt-4 text-xs text-muted-foreground">
|
||||
O servidor confirma os cálculos ao guardar.
|
||||
Equipamentos e peças terão formulários próprios numa
|
||||
próxima etapa.
|
||||
</p>
|
||||
</Panel>
|
||||
<div className="flex justify-end gap-3">
|
||||
@@ -714,7 +752,9 @@ export default function RequisitionForm({
|
||||
</Button>
|
||||
<Button
|
||||
disabled={
|
||||
form.processing || costCenters.length === 0
|
||||
form.processing ||
|
||||
(!incompleteDraftsAvailable &&
|
||||
costCenters.length === 0)
|
||||
}
|
||||
>
|
||||
<Save className="size-4" />
|
||||
|
||||
@@ -74,6 +74,10 @@ export default function Show({
|
||||
href: string | null;
|
||||
destination: string;
|
||||
equipment: { code: string; description: string } | null;
|
||||
production?: {
|
||||
reference: string | null;
|
||||
verification: 'user_supplied';
|
||||
};
|
||||
remaining_milli: number;
|
||||
}[];
|
||||
} | null;
|
||||
@@ -169,6 +173,8 @@ export default function Show({
|
||||
</>
|
||||
)}{' '}
|
||||
· Utilização: {o.destination}
|
||||
{o.production &&
|
||||
` · Insumos para produção${o.production.reference ? ` · Referência declarada: ${o.production.reference}` : ''}`}
|
||||
{o.equipment
|
||||
? ` · Equipamento ${o.equipment.code} · ${o.equipment.description}`
|
||||
: ''}{' '}
|
||||
@@ -209,87 +215,89 @@ export default function Show({
|
||||
<Panel title="Regra de comparação deste processo">
|
||||
<ComparisonPolicySummary policy={comparisonPolicy} />
|
||||
</Panel>
|
||||
{r.items.some((i) => i.purchase_type === 'equipment') && (
|
||||
<Panel title="Validação técnica do equipamento">
|
||||
<p className="mb-4 text-sm">
|
||||
Responsável da área, distinto do solicitante.
|
||||
Finanças é obrigatória para qualquer valor. A
|
||||
adjudicação e a emissão exigem regra de investimento
|
||||
vigente, com duas aprovações administrativas, e
|
||||
reserva em dotação de investimento. Sem estas
|
||||
condições permanecem bloqueadas. O orçamento ainda
|
||||
não é validado; documentos de desenvolvimento não
|
||||
autorizam compras reais.
|
||||
</p>
|
||||
{technical?.reviews.map((t) => (
|
||||
<p
|
||||
key={t.id}
|
||||
className="mb-3 rounded-lg border p-3 text-sm"
|
||||
>
|
||||
{t.decision === 'approved'
|
||||
? 'Validado'
|
||||
: 'Rejeitado'}{' '}
|
||||
por {t.snapshot.reviewer.name} ·{' '}
|
||||
{t.basis_hash === technical.basis_hash
|
||||
? 'Versão actual'
|
||||
: 'Versão anterior, decisão preservada'}{' '}
|
||||
· {t.reason}
|
||||
{!r.draft_input?.incomplete &&
|
||||
r.items.some((i) => i.purchase_type === 'equipment') && (
|
||||
<Panel title="Validação técnica do equipamento">
|
||||
<p className="mb-4 text-sm">
|
||||
Responsável da área, distinto do solicitante.
|
||||
Finanças é obrigatória para qualquer valor. A
|
||||
adjudicação e a emissão exigem regra de
|
||||
investimento vigente, com duas aprovações
|
||||
administrativas, e reserva em dotação de
|
||||
investimento. Sem estas condições permanecem
|
||||
bloqueadas. O orçamento ainda não é validado;
|
||||
documentos de desenvolvimento não autorizam
|
||||
compras reais.
|
||||
</p>
|
||||
))}
|
||||
{technical?.canReview && (
|
||||
<form
|
||||
className="grid gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
review.transform((d) => ({
|
||||
...d,
|
||||
basis_hash: technical.basis_hash,
|
||||
}));
|
||||
review.post(
|
||||
`/requisicoes/${r.id}/validacao-tecnica`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<select
|
||||
aria-label="Decisão técnica"
|
||||
className={controlClass}
|
||||
value={review.data.decision}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'decision',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
{technical?.reviews.map((t) => (
|
||||
<p
|
||||
key={t.id}
|
||||
className="mb-3 rounded-lg border p-3 text-sm"
|
||||
>
|
||||
<option value="approved">
|
||||
Validar tecnicamente
|
||||
</option>
|
||||
<option value="rejected">
|
||||
Rejeitar tecnicamente
|
||||
</option>
|
||||
</select>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Fundamento técnico
|
||||
<textarea
|
||||
required
|
||||
{t.decision === 'approved'
|
||||
? 'Validado'
|
||||
: 'Rejeitado'}{' '}
|
||||
por {t.snapshot.reviewer.name} ·{' '}
|
||||
{t.basis_hash === technical.basis_hash
|
||||
? 'Versão actual'
|
||||
: 'Versão anterior, decisão preservada'}{' '}
|
||||
· {t.reason}
|
||||
</p>
|
||||
))}
|
||||
{technical?.canReview && (
|
||||
<form
|
||||
className="grid gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
review.transform((d) => ({
|
||||
...d,
|
||||
basis_hash: technical.basis_hash,
|
||||
}));
|
||||
review.post(
|
||||
`/requisicoes/${r.id}/validacao-tecnica`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<select
|
||||
aria-label="Decisão técnica"
|
||||
className={controlClass}
|
||||
value={review.data.reason}
|
||||
value={review.data.decision}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'reason',
|
||||
'decision',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<FormErrors errors={review.errors} />
|
||||
<Button disabled={review.processing}>
|
||||
Registar decisão técnica
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
)}
|
||||
>
|
||||
<option value="approved">
|
||||
Validar tecnicamente
|
||||
</option>
|
||||
<option value="rejected">
|
||||
Rejeitar tecnicamente
|
||||
</option>
|
||||
</select>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Fundamento técnico
|
||||
<textarea
|
||||
required
|
||||
className={controlClass}
|
||||
value={review.data.reason}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'reason',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<FormErrors errors={review.errors} />
|
||||
<Button disabled={review.processing}>
|
||||
Registar decisão técnica
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
)}
|
||||
{conflictBlocked && (
|
||||
<div className="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
|
||||
Existe um conflito de interesses activo que impede a
|
||||
@@ -302,32 +310,49 @@ export default function Show({
|
||||
.
|
||||
</div>
|
||||
)}
|
||||
{canEdit && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border bg-muted/30 p-5">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Confira o pedido antes de o enviar para aprovação.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/editar`}>
|
||||
<Pencil className="size-4" />
|
||||
Editar
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
disabled={submission.processing}
|
||||
onClick={() =>
|
||||
submission.post(
|
||||
`/requisicoes/${r.id}/submeter`,
|
||||
)
|
||||
}
|
||||
{canEdit &&
|
||||
(r.draft_input?.incomplete ? (
|
||||
<div role="status" className="rounded-xl border p-5">
|
||||
<p>
|
||||
Rascunho incompleto guardado. Os montantes estão
|
||||
por completar; não há submissão nem reserva
|
||||
orçamental. As linhas anteriormente completas
|
||||
não representam esta preparação.
|
||||
</p>
|
||||
<Link
|
||||
className="mt-3 inline-block underline"
|
||||
href={`/requisicoes/${r.id}/editar`}
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Submeter para aprovação
|
||||
</Button>
|
||||
Continuar a preparação
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border bg-muted/30 p-5">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Confira o pedido antes de o enviar para
|
||||
aprovação.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/requisicoes/${r.id}/editar`}>
|
||||
<Pencil className="size-4" />
|
||||
Editar
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
disabled={submission.processing}
|
||||
onClick={() =>
|
||||
submission.post(
|
||||
`/requisicoes/${r.id}/submeter`,
|
||||
)
|
||||
}
|
||||
>
|
||||
<Send className="size-4" />
|
||||
Submeter para aprovação
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
<Panel title="Detalhes do pedido">
|
||||
@@ -337,8 +362,9 @@ export default function Show({
|
||||
Centro de custo
|
||||
</dt>
|
||||
<dd className="mt-1 font-medium">
|
||||
{r.cost_center?.code} ·{' '}
|
||||
{r.cost_center?.name}
|
||||
{r.cost_center
|
||||
? `${r.cost_center.code} · ${r.cost_center.name}`
|
||||
: 'Por completar'}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
@@ -367,85 +393,106 @@ export default function Show({
|
||||
</div>
|
||||
</dl>
|
||||
</Panel>
|
||||
<Panel
|
||||
title="Artigos e valores"
|
||||
description="Moeda: MZN · Montantes estimados"
|
||||
>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="border-b text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th className="pb-3">Artigo</th>
|
||||
<th className="pr-3">Qtd.</th>
|
||||
<th className="pr-3">
|
||||
Preço s/ IVA
|
||||
</th>
|
||||
<th className="pr-3">IVA</th>
|
||||
<th className="text-right">
|
||||
Total c/ IVA
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.items.map((i) => (
|
||||
<tr key={i.id} className="border-b">
|
||||
<td className="py-4 pr-4">
|
||||
<p className="font-medium">
|
||||
{i.description}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{i.category}
|
||||
</p>
|
||||
{i.equipment_id && (
|
||||
<p className="mt-1 text-xs">
|
||||
Equipamento #
|
||||
{i.equipment_id} ·
|
||||
Peça #
|
||||
{i.spare_part_id}
|
||||
{i.downtime_started_at &&
|
||||
` · Paragem: ${i.downtime_started_at} UTC`}
|
||||
</p>
|
||||
)}
|
||||
{i.production_area && (
|
||||
<p className="mt-1 text-xs">
|
||||
Área de destino:{' '}
|
||||
{i.production_area}
|
||||
</p>
|
||||
)}
|
||||
</td>
|
||||
<td className="pr-3 whitespace-nowrap">
|
||||
{Number(i.quantity)}{' '}
|
||||
{i.unit}
|
||||
</td>
|
||||
<td className="pr-3 whitespace-nowrap">
|
||||
{money(i.unit_price_minor)}
|
||||
</td>
|
||||
<td className="pr-3">
|
||||
{Number(i.tax_rate)}%
|
||||
</td>
|
||||
<td className="text-right whitespace-nowrap">
|
||||
{money(i.total_minor)}
|
||||
</td>
|
||||
{r.draft_input?.incomplete ? (
|
||||
<Panel title="Linhas em preparação">
|
||||
<p>
|
||||
Os valores ainda não estão completos. Abra
|
||||
«Continuar a preparação» para recuperar as
|
||||
linhas guardadas. Não são apresentados
|
||||
totais estimados nem linhas antigas como
|
||||
valores desta preparação.
|
||||
</p>
|
||||
</Panel>
|
||||
) : (
|
||||
<Panel
|
||||
title="Artigos e valores"
|
||||
description="Moeda: MZN · Montantes estimados"
|
||||
>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="border-b text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th className="pb-3">Artigo</th>
|
||||
<th className="pr-3">Qtd.</th>
|
||||
<th className="pr-3">
|
||||
Preço s/ IVA
|
||||
</th>
|
||||
<th className="pr-3">IVA</th>
|
||||
<th className="text-right">
|
||||
Total c/ IVA
|
||||
</th>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<dl className="mt-5 ml-auto max-w-xs space-y-3 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<dt>Subtotal sem IVA</dt>
|
||||
<dd>{money(r.subtotal_minor)}</dd>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.items.map((i) => (
|
||||
<tr
|
||||
key={i.id}
|
||||
className="border-b"
|
||||
>
|
||||
<td className="py-4 pr-4">
|
||||
<p className="font-medium">
|
||||
{i.description}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{i.category}
|
||||
</p>
|
||||
{i.equipment_id && (
|
||||
<p className="mt-1 text-xs">
|
||||
Equipamento #
|
||||
{i.equipment_id}{' '}
|
||||
· Peça #
|
||||
{
|
||||
i.spare_part_id
|
||||
}
|
||||
{i.downtime_started_at &&
|
||||
` · Paragem: ${i.downtime_started_at} UTC`}
|
||||
</p>
|
||||
)}
|
||||
{i.production_area && (
|
||||
<p className="mt-1 text-xs">
|
||||
Área de destino:{' '}
|
||||
{
|
||||
i.production_area
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</td>
|
||||
<td className="pr-3 whitespace-nowrap">
|
||||
{Number(i.quantity)}{' '}
|
||||
{i.unit}
|
||||
</td>
|
||||
<td className="pr-3 whitespace-nowrap">
|
||||
{money(
|
||||
i.unit_price_minor,
|
||||
)}
|
||||
</td>
|
||||
<td className="pr-3">
|
||||
{Number(i.tax_rate)}%
|
||||
</td>
|
||||
<td className="text-right whitespace-nowrap">
|
||||
{money(i.total_minor)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<dt>IVA</dt>
|
||||
<dd>{money(r.tax_minor)}</dd>
|
||||
</div>
|
||||
<div className="flex justify-between border-t pt-3 text-base font-semibold">
|
||||
<dt>Total com IVA</dt>
|
||||
<dd>{money(r.total_minor)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</Panel>
|
||||
<dl className="mt-5 ml-auto max-w-xs space-y-3 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<dt>Subtotal sem IVA</dt>
|
||||
<dd>{money(r.subtotal_minor)}</dd>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<dt>IVA</dt>
|
||||
<dd>{money(r.tax_minor)}</dd>
|
||||
</div>
|
||||
<div className="flex justify-between border-t pt-3 text-base font-semibold">
|
||||
<dt>Total com IVA</dt>
|
||||
<dd>{money(r.total_minor)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</Panel>
|
||||
)}
|
||||
{canDecide && (
|
||||
<Panel
|
||||
title="Registar decisão"
|
||||
|
||||
Reference in New Issue
Block a user