@@ -0,0 +1,820 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { date } from '@/types/procurement';
|
||||
|
||||
type Document = {
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
data: { type: string; reference: string; issuer_reference: string };
|
||||
};
|
||||
type Frozen = {
|
||||
id: number;
|
||||
type: string;
|
||||
reference: string;
|
||||
version: number;
|
||||
issuer_reference: string;
|
||||
};
|
||||
type BankRecord = {
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
state: string;
|
||||
reason: string;
|
||||
issues?: string[];
|
||||
snapshot: { documents: Frozen[] };
|
||||
data: {
|
||||
commitment_document_id: number;
|
||||
declaration_document_id: number | null;
|
||||
support_document_ids: number[];
|
||||
submission_document_id: number | null;
|
||||
submission_basis: string | null;
|
||||
submitted_on: string | null;
|
||||
requirements_known: boolean;
|
||||
required_support_types: string[];
|
||||
required_support_counts: Record<string, number>;
|
||||
requirements_basis: string;
|
||||
due_on: string | null;
|
||||
deadline_basis: string | null;
|
||||
};
|
||||
};
|
||||
type Page<T> = {
|
||||
data: T[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Props = {
|
||||
importRecord: { id: number; record_key: string; version: number };
|
||||
order: { id: number; number: string };
|
||||
current: Page<BankRecord>;
|
||||
history: Page<BankRecord>;
|
||||
documents: Page<Document>;
|
||||
types: Record<string, string>;
|
||||
canWrite: boolean;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
today?: string;
|
||||
};
|
||||
const stateLabels: Record<string, string> = {
|
||||
tracking: 'Documentação incompleta',
|
||||
ready: 'Documentos reunidos; entrega por documentar',
|
||||
documented: 'Comprovativo de entrega associado',
|
||||
};
|
||||
function Pages({ page }: { page: Page<unknown> }) {
|
||||
return (
|
||||
<nav className="mt-3 flex gap-4" aria-label="Páginas">
|
||||
{page.prev_page_url && (
|
||||
<Link preserveState href={page.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{page.next_page_url && (
|
||||
<Link preserveState href={page.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
export default function ImportBankSupport(props: Props) {
|
||||
const url = `/compras/importacoes/${props.importRecord.id}/suporte-bancario`;
|
||||
const form = useForm(
|
||||
`import-bank:${props.tenantId}:${props.actorId}:${props.importRecord.record_key}:${props.importRecord.version}`,
|
||||
{
|
||||
operation_key: '',
|
||||
record_key: null as string | null,
|
||||
version: 0,
|
||||
commitment_document_id: '',
|
||||
commitment_label: '',
|
||||
declaration_document_id: '',
|
||||
declaration_label: '',
|
||||
support: [] as { id: number; reference: string }[],
|
||||
submission_document_id: '',
|
||||
submission_label: '',
|
||||
submission_basis: '',
|
||||
submitted_on: '',
|
||||
requirements_known: false,
|
||||
counts: {} as Record<string, string>,
|
||||
requirements_basis: '',
|
||||
due_on: '',
|
||||
deadline_basis: '',
|
||||
reason: '',
|
||||
},
|
||||
);
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
useEffect(() => {
|
||||
const node = ref.current;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: node, dirty: form.isDirty },
|
||||
}),
|
||||
);
|
||||
return () => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: node, dirty: false },
|
||||
}),
|
||||
);
|
||||
};
|
||||
}, [form.isDirty]);
|
||||
const edit = (record: BankRecord) => {
|
||||
const label = (id: number | null) =>
|
||||
record.snapshot.documents.find((doc) => doc.id === id)?.reference ??
|
||||
'';
|
||||
form.setData({
|
||||
operation_key: '',
|
||||
record_key: record.record_key,
|
||||
version: record.version,
|
||||
commitment_document_id: String(record.data.commitment_document_id),
|
||||
commitment_label: label(record.data.commitment_document_id),
|
||||
declaration_document_id:
|
||||
record.data.declaration_document_id === null
|
||||
? ''
|
||||
: String(record.data.declaration_document_id),
|
||||
declaration_label: label(record.data.declaration_document_id),
|
||||
support: record.data.support_document_ids.map((id) => ({
|
||||
id,
|
||||
reference: label(id),
|
||||
})),
|
||||
submission_document_id:
|
||||
record.data.submission_document_id === null
|
||||
? ''
|
||||
: String(record.data.submission_document_id),
|
||||
submission_label: label(record.data.submission_document_id),
|
||||
submission_basis: record.data.submission_basis ?? '',
|
||||
submitted_on: record.data.submitted_on ?? '',
|
||||
requirements_known: record.data.requirements_known,
|
||||
counts: Object.fromEntries(
|
||||
Object.entries(record.data.required_support_counts).map(
|
||||
([type, count]) => [type, String(count)],
|
||||
),
|
||||
),
|
||||
requirements_basis: record.data.requirements_basis,
|
||||
due_on: record.data.due_on ?? '',
|
||||
deadline_basis: record.data.deadline_basis ?? '',
|
||||
reason: '',
|
||||
});
|
||||
form.clearErrors();
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Head title="Suporte documental bancário" />
|
||||
<main className="mx-auto max-w-6xl space-y-5 px-5 py-8">
|
||||
<PageTitle
|
||||
eyebrow="Acompanhamento da importação"
|
||||
title="Suporte documental bancário"
|
||||
description={`Ordem ${props.order.number}. Ligue o termo de compromisso ao documento único e acompanhe os documentos pedidos pelo banco.`}
|
||||
/>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/compras/importacoes/${props.importRecord.id}/documentos`}
|
||||
>
|
||||
Originais do dossiê
|
||||
</Link>
|
||||
<a className="underline" href={`${url}.csv`}>
|
||||
Exportar acompanhamento CSV
|
||||
</a>
|
||||
</div>
|
||||
<Panel
|
||||
title="Situação por termo"
|
||||
description="Documentos reunidos não demonstram a entrega ao banco. Um comprovativo registado não certifica cumprimento bancário, nem executa transferência ou submissão na JUE."
|
||||
>
|
||||
{props.current.data.length === 0 && (
|
||||
<p>Ainda não há termos acompanhados neste âmbito.</p>
|
||||
)}
|
||||
{props.current.data.map((record) => (
|
||||
<article
|
||||
key={record.id}
|
||||
className="space-y-2 border-b py-4"
|
||||
>
|
||||
<p className="font-medium">
|
||||
{
|
||||
record.snapshot.documents.find(
|
||||
(doc) =>
|
||||
doc.id ===
|
||||
record.data.commitment_document_id,
|
||||
)?.reference
|
||||
}{' '}
|
||||
· versão {record.version}
|
||||
</p>
|
||||
<p>{stateLabels[record.state] ?? record.state}</p>
|
||||
<p>
|
||||
Prazo:{' '}
|
||||
{record.data.due_on
|
||||
? date(record.data.due_on)
|
||||
: 'Por indicar'}{' '}
|
||||
·{' '}
|
||||
{record.data.deadline_basis ??
|
||||
'Sem prazo presumido'}
|
||||
</p>
|
||||
{(record.issues ?? []).map((issue) => (
|
||||
<p key={issue} role="status">
|
||||
{issue}
|
||||
</p>
|
||||
))}
|
||||
<p>
|
||||
Entrega documentada:{' '}
|
||||
{record.data.submitted_on
|
||||
? date(record.data.submitted_on)
|
||||
: 'Por indicar'}{' '}
|
||||
· {record.data.submission_basis}
|
||||
</p>
|
||||
<p>{record.reason}</p>
|
||||
{props.canWrite && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => edit(record)}
|
||||
>
|
||||
Preparar nova versão
|
||||
</Button>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
<Pages page={props.current} />
|
||||
</Panel>
|
||||
{props.canWrite && (
|
||||
<Panel
|
||||
title={
|
||||
form.data.record_key
|
||||
? `Rever acompanhamento · versão ${form.data.version}`
|
||||
: 'Acompanhar um termo existente'
|
||||
}
|
||||
description="Seleccione os originais já registados. Indique apenas requisitos, prazos e informação novos deste acompanhamento."
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
className="space-y-5"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const operation =
|
||||
form.data.operation_key ||
|
||||
crypto.randomUUID();
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
operation_key: operation,
|
||||
record_key: data.record_key,
|
||||
version: data.version,
|
||||
commitment_document_id:
|
||||
data.commitment_document_id,
|
||||
declaration_document_id:
|
||||
data.declaration_document_id || null,
|
||||
support_document_ids: data.support.map(
|
||||
(doc) => doc.id,
|
||||
),
|
||||
submission_document_id:
|
||||
data.submission_document_id || null,
|
||||
submission_basis:
|
||||
data.submission_basis || null,
|
||||
submitted_on: data.submission_document_id
|
||||
? data.submitted_on || null
|
||||
: null,
|
||||
requirements_known: data.requirements_known,
|
||||
required_support_types:
|
||||
data.requirements_known
|
||||
? Object.keys(data.counts)
|
||||
: [],
|
||||
required_support_counts:
|
||||
data.requirements_known
|
||||
? data.counts
|
||||
: {},
|
||||
requirements_basis: data.requirements_basis,
|
||||
due_on: data.due_on || null,
|
||||
deadline_basis: data.deadline_basis || null,
|
||||
reason: data.reason,
|
||||
}));
|
||||
form.post(url, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
router.visit(url, {
|
||||
preserveState: false,
|
||||
preserveScroll: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
<label className="grid gap-1">
|
||||
Termo de compromisso
|
||||
<select
|
||||
required
|
||||
className={controlClass}
|
||||
value={form.data.commitment_document_id}
|
||||
onChange={(e) => {
|
||||
const doc =
|
||||
props.documents.data.find(
|
||||
(d) =>
|
||||
String(d.id) ===
|
||||
e.target.value,
|
||||
);
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
commitment_document_id:
|
||||
e.target.value,
|
||||
commitment_label:
|
||||
doc?.data.reference ?? '',
|
||||
}));
|
||||
}}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{form.data.commitment_document_id &&
|
||||
!props.documents.data.some(
|
||||
(doc) =>
|
||||
String(doc.id) ===
|
||||
form.data
|
||||
.commitment_document_id,
|
||||
) && (
|
||||
<option
|
||||
value={
|
||||
form.data
|
||||
.commitment_document_id
|
||||
}
|
||||
>
|
||||
{form.data.commitment_label}{' '}
|
||||
· seleccionado noutra página
|
||||
</option>
|
||||
)}
|
||||
{props.documents.data
|
||||
.filter(
|
||||
(doc) =>
|
||||
doc.data.type ===
|
||||
'bank_commitment',
|
||||
)
|
||||
.map((doc) => (
|
||||
<option
|
||||
key={doc.id}
|
||||
value={doc.id}
|
||||
>
|
||||
{doc.data.reference} · v
|
||||
{doc.version}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Documento único / declaração
|
||||
<select
|
||||
className={controlClass}
|
||||
value={
|
||||
form.data.declaration_document_id
|
||||
}
|
||||
onChange={(e) => {
|
||||
const doc =
|
||||
props.documents.data.find(
|
||||
(d) =>
|
||||
String(d.id) ===
|
||||
e.target.value,
|
||||
);
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
declaration_document_id:
|
||||
e.target.value,
|
||||
declaration_label:
|
||||
doc?.data.reference ?? '',
|
||||
}));
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Ainda por associar
|
||||
</option>
|
||||
{form.data.declaration_document_id &&
|
||||
!props.documents.data.some(
|
||||
(doc) =>
|
||||
String(doc.id) ===
|
||||
form.data
|
||||
.declaration_document_id,
|
||||
) && (
|
||||
<option
|
||||
value={
|
||||
form.data
|
||||
.declaration_document_id
|
||||
}
|
||||
>
|
||||
{
|
||||
form.data
|
||||
.declaration_label
|
||||
}{' '}
|
||||
· seleccionado noutra página
|
||||
</option>
|
||||
)}
|
||||
{props.documents.data
|
||||
.filter(
|
||||
(doc) =>
|
||||
doc.data.type ===
|
||||
'customs_declaration',
|
||||
)
|
||||
.map((doc) => (
|
||||
<option
|
||||
key={doc.id}
|
||||
value={doc.id}
|
||||
>
|
||||
{doc.data.reference} · v
|
||||
{doc.version}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Comprovativo de entrega ao banco
|
||||
<select
|
||||
className={controlClass}
|
||||
value={form.data.submission_document_id}
|
||||
onChange={(e) => {
|
||||
const doc =
|
||||
props.documents.data.find(
|
||||
(d) =>
|
||||
String(d.id) ===
|
||||
e.target.value,
|
||||
);
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
submission_document_id:
|
||||
e.target.value,
|
||||
submission_label:
|
||||
doc?.data.reference ?? '',
|
||||
}));
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Ainda por associar
|
||||
</option>
|
||||
{form.data.submission_document_id &&
|
||||
!props.documents.data.some(
|
||||
(doc) =>
|
||||
String(doc.id) ===
|
||||
form.data
|
||||
.submission_document_id,
|
||||
) && (
|
||||
<option
|
||||
value={
|
||||
form.data
|
||||
.submission_document_id
|
||||
}
|
||||
>
|
||||
{form.data.submission_label}{' '}
|
||||
· seleccionado noutra página
|
||||
</option>
|
||||
)}
|
||||
{props.documents.data
|
||||
.filter(
|
||||
(doc) =>
|
||||
doc.data.type ===
|
||||
'bank_support',
|
||||
)
|
||||
.map((doc) => (
|
||||
<option
|
||||
key={doc.id}
|
||||
value={doc.id}
|
||||
>
|
||||
{doc.data.reference} · v
|
||||
{doc.version}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
{form.data.submission_document_id && (
|
||||
<label className="grid gap-1">
|
||||
Fundamento do comprovativo de entrega
|
||||
<textarea
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={1000}
|
||||
className={controlClass}
|
||||
value={form.data.submission_basis}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'submission_basis',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
{form.data.submission_document_id && (
|
||||
<label className="grid gap-1">
|
||||
Data efectiva da entrega documentada
|
||||
<input
|
||||
type="date"
|
||||
required
|
||||
max={props.today}
|
||||
className={controlClass}
|
||||
value={form.data.submitted_on}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'submitted_on',
|
||||
event.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
<fieldset className="space-y-3 rounded border p-4">
|
||||
<legend>
|
||||
Documentos de suporte seleccionados
|
||||
</legend>
|
||||
{form.data.support.map((doc) => (
|
||||
<div
|
||||
key={doc.id}
|
||||
className="flex flex-wrap items-center gap-3"
|
||||
>
|
||||
<span>{doc.reference}</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() =>
|
||||
form.setData(
|
||||
'support',
|
||||
form.data.support.filter(
|
||||
(d) => d.id !== doc.id,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar da preparação
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
{props.documents.data
|
||||
.filter(
|
||||
(doc) =>
|
||||
doc.data.type !== 'bank_commitment',
|
||||
)
|
||||
.map((doc) => (
|
||||
<label
|
||||
key={doc.id}
|
||||
className="flex gap-2"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.support.some(
|
||||
(selected) =>
|
||||
selected.id === doc.id,
|
||||
)}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'support',
|
||||
e.target.checked
|
||||
? [
|
||||
...form.data
|
||||
.support,
|
||||
{
|
||||
id: doc.id,
|
||||
reference:
|
||||
doc
|
||||
.data
|
||||
.reference,
|
||||
},
|
||||
]
|
||||
: form.data.support.filter(
|
||||
(d) =>
|
||||
d.id !==
|
||||
doc.id,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span>
|
||||
{props.types[doc.data.type]} ·{' '}
|
||||
{doc.data.reference} · v
|
||||
{doc.version}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
<Pages page={props.documents} />
|
||||
</fieldset>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.requirements_known}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'requirements_known',
|
||||
e.target.checked,
|
||||
)
|
||||
}
|
||||
/>
|
||||
Os requisitos documentais pedidos pelo banco
|
||||
estão identificados
|
||||
</label>
|
||||
{form.data.requirements_known && (
|
||||
<fieldset className="grid gap-3 rounded border p-4 sm:grid-cols-2">
|
||||
<legend>
|
||||
Tipos e quantidades pedidos pelo banco
|
||||
</legend>
|
||||
{Object.entries(props.types)
|
||||
.filter(
|
||||
([type]) =>
|
||||
type !== 'bank_commitment',
|
||||
)
|
||||
.map(([type, label]) => (
|
||||
<div
|
||||
key={type}
|
||||
className="space-y-1"
|
||||
>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Object.hasOwn(
|
||||
form.data.counts,
|
||||
type,
|
||||
)}
|
||||
onChange={(e) => {
|
||||
const counts = {
|
||||
...form.data
|
||||
.counts,
|
||||
};
|
||||
if (
|
||||
e.target.checked
|
||||
)
|
||||
counts[type] =
|
||||
'';
|
||||
else
|
||||
delete counts[
|
||||
type
|
||||
];
|
||||
form.setData(
|
||||
'counts',
|
||||
counts,
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{label}
|
||||
</label>
|
||||
{Object.hasOwn(
|
||||
form.data.counts,
|
||||
type,
|
||||
) && (
|
||||
<label className="grid gap-1">
|
||||
Quantidade solicitada
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={100}
|
||||
step={1}
|
||||
className={
|
||||
controlClass
|
||||
}
|
||||
value={
|
||||
form.data
|
||||
.counts[
|
||||
type
|
||||
]
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'counts',
|
||||
{
|
||||
...form
|
||||
.data
|
||||
.counts,
|
||||
[type]: e
|
||||
.target
|
||||
.value,
|
||||
},
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
<label className="grid gap-1">
|
||||
Fonte dos requisitos ou informação ainda em
|
||||
falta
|
||||
<textarea
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={1000}
|
||||
className={controlClass}
|
||||
value={form.data.requirements_basis}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'requirements_basis',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<label className="grid gap-1">
|
||||
Prazo documental indicado
|
||||
<input
|
||||
type="date"
|
||||
className={controlClass}
|
||||
value={form.data.due_on}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'due_on',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Fonte do prazo
|
||||
<textarea
|
||||
required={Boolean(form.data.due_on)}
|
||||
minLength={3}
|
||||
maxLength={1000}
|
||||
className={controlClass}
|
||||
value={form.data.deadline_basis}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'deadline_basis',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<label className="grid gap-1">
|
||||
Motivo desta versão
|
||||
<textarea
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
className={controlClass}
|
||||
value={form.data.reason}
|
||||
onChange={(e) =>
|
||||
form.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>
|
||||
Guardar acompanhamento documental
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Histórico preservado">
|
||||
{props.history.data.map((record) => (
|
||||
<article
|
||||
key={record.id}
|
||||
className="space-y-1 border-b py-3"
|
||||
>
|
||||
<p>
|
||||
Versão {record.version} ·{' '}
|
||||
{stateLabels[record.state] ?? record.state}
|
||||
</p>
|
||||
<p>{record.reason}</p>
|
||||
<p>
|
||||
Requisitos:{' '}
|
||||
{record.data.requirements_known
|
||||
? record.data.required_support_types
|
||||
.map(
|
||||
(type) =>
|
||||
`${props.types[type]}: ${record.data.required_support_counts[type]}`,
|
||||
)
|
||||
.join('; ') ||
|
||||
'Nenhum tipo exigido segundo a fonte registada'
|
||||
: 'Ainda desconhecidos'}{' '}
|
||||
· {record.data.requirements_basis}
|
||||
</p>
|
||||
<p>
|
||||
Entrega documentada:{' '}
|
||||
{record.data.submitted_on
|
||||
? date(record.data.submitted_on)
|
||||
: 'Por indicar'}{' '}
|
||||
· {record.data.submission_basis}
|
||||
</p>
|
||||
<p>
|
||||
Prazo:{' '}
|
||||
{record.data.due_on
|
||||
? date(record.data.due_on)
|
||||
: 'Desconhecido'}{' '}
|
||||
· {record.data.deadline_basis}
|
||||
</p>
|
||||
{record.snapshot.documents.map((doc) => (
|
||||
<p key={doc.id}>
|
||||
<a
|
||||
className="underline"
|
||||
href={`/compras/importacoes/${props.importRecord.id}/documentos/${doc.id}`}
|
||||
>
|
||||
{props.types[doc.type]} ·{' '}
|
||||
{doc.reference} · v{doc.version}
|
||||
</a>
|
||||
</p>
|
||||
))}
|
||||
</article>
|
||||
))}
|
||||
<Pages page={props.history} />
|
||||
</Panel>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -38,6 +38,8 @@ type Props = {
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
parties?: ImportPartyWorkspace;
|
||||
bankSupportReady?: boolean;
|
||||
readinessReady?: boolean;
|
||||
};
|
||||
|
||||
export default function Dossier({
|
||||
@@ -49,6 +51,8 @@ export default function Dossier({
|
||||
actorId,
|
||||
tenantId,
|
||||
parties,
|
||||
bankSupportReady = false,
|
||||
readinessReady = false,
|
||||
}: Props) {
|
||||
const form = useForm(
|
||||
`import-dossier:${tenantId}:${actorId}:${importRecord.record_key}:${importRecord.version}`,
|
||||
@@ -116,6 +120,22 @@ export default function Dossier({
|
||||
<Link className="underline" href={`/ordens/${order.id}`}>
|
||||
Consultar a ordem e as suas origens
|
||||
</Link>
|
||||
{readinessReady && (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/compras/importacoes/${importRecord.id}/acompanhamento`}
|
||||
>
|
||||
Consultar alertas e próximos passos
|
||||
</Link>
|
||||
)}
|
||||
{bankSupportReady && (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/compras/importacoes/${importRecord.id}/suporte-bancario`}
|
||||
>
|
||||
Acompanhar termo e suporte bancário
|
||||
</Link>
|
||||
)}
|
||||
{parties && (
|
||||
<ImportPartySelection
|
||||
workspace={parties}
|
||||
|
||||
@@ -33,6 +33,14 @@ type Version = {
|
||||
reason: string;
|
||||
data: { budget_id: number; components: Component[] };
|
||||
snapshot: {
|
||||
legal_sources?: Record<
|
||||
string,
|
||||
{
|
||||
estimate_id: number;
|
||||
estimate_version: number;
|
||||
charge_key: string;
|
||||
}
|
||||
>;
|
||||
plan: {
|
||||
complete: boolean;
|
||||
budget_amount_minor: number | null;
|
||||
@@ -47,6 +55,23 @@ type Page<T> = {
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Props = {
|
||||
legalAmounts?: {
|
||||
id: number;
|
||||
version: number;
|
||||
snapshot: {
|
||||
item: { description: string };
|
||||
legal_rule: { data: { official_reference: string } };
|
||||
result: {
|
||||
lines: {
|
||||
key: string;
|
||||
kind: string;
|
||||
label: string;
|
||||
method: string;
|
||||
amount_minor: number | null;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
}[];
|
||||
requisition: {
|
||||
id: number;
|
||||
number: string;
|
||||
@@ -105,6 +130,12 @@ export default function ImportEstimate(props: Props) {
|
||||
subtotal: estimateMoney(row.subtotal_minor),
|
||||
tax: estimateMoney(row.tax_minor),
|
||||
total: estimateMoney(row.total_minor),
|
||||
legal_estimate_id:
|
||||
latest?.snapshot.legal_sources?.[row.key]?.estimate_id ??
|
||||
(null as number | null),
|
||||
legal_charge_key:
|
||||
latest?.snapshot.legal_sources?.[row.key]?.charge_key ??
|
||||
(null as string | null),
|
||||
})),
|
||||
},
|
||||
);
|
||||
@@ -185,6 +216,25 @@ export default function ImportEstimate(props: Props) {
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
...data,
|
||||
legal_sources: Object.fromEntries(
|
||||
data.components
|
||||
.filter(
|
||||
(row) =>
|
||||
row.legal_estimate_id !==
|
||||
null &&
|
||||
row.legal_charge_key !==
|
||||
null,
|
||||
)
|
||||
.map((row) => [
|
||||
row.key,
|
||||
{
|
||||
estimate_id:
|
||||
row.legal_estimate_id,
|
||||
charge_key:
|
||||
row.legal_charge_key,
|
||||
},
|
||||
]),
|
||||
),
|
||||
operation_key: operation,
|
||||
components: data.components.map((row) => ({
|
||||
key: row.key,
|
||||
@@ -260,6 +310,174 @@ export default function ImportEstimate(props: Props) {
|
||||
<legend>
|
||||
{labels[row.kind] ?? row.kind}
|
||||
</legend>
|
||||
{((props.legalAmounts?.length ?? 0) > 0 ||
|
||||
row.legal_estimate_id !== null) && (
|
||||
<label className="grid gap-1">
|
||||
Reutilizar uma imposição calculada
|
||||
<select
|
||||
className={controlClass}
|
||||
value={
|
||||
row.legal_estimate_id ===
|
||||
null
|
||||
? ''
|
||||
: `${row.legal_estimate_id}:${row.legal_charge_key}`
|
||||
}
|
||||
onChange={(event) => {
|
||||
const candidates = (
|
||||
props.legalAmounts ?? []
|
||||
).flatMap((estimate) =>
|
||||
estimate.snapshot.result.lines
|
||||
.filter(
|
||||
(line) =>
|
||||
line.kind ===
|
||||
row.kind,
|
||||
)
|
||||
.map((line) => ({
|
||||
estimate,
|
||||
line,
|
||||
value: `${estimate.id}:${line.key}`,
|
||||
})),
|
||||
);
|
||||
const selected =
|
||||
candidates.find(
|
||||
(candidate) =>
|
||||
candidate.value ===
|
||||
event.target
|
||||
.value,
|
||||
);
|
||||
form.setData(
|
||||
'components',
|
||||
form.data.components.map(
|
||||
(component, at) =>
|
||||
at !== index
|
||||
? component
|
||||
: selected
|
||||
? {
|
||||
...component,
|
||||
legal_estimate_id:
|
||||
selected
|
||||
.estimate
|
||||
.id,
|
||||
legal_charge_key:
|
||||
selected
|
||||
.line
|
||||
.key,
|
||||
status:
|
||||
selected
|
||||
.line
|
||||
.amount_minor ===
|
||||
null
|
||||
? 'unknown'
|
||||
: selected
|
||||
.line
|
||||
.method ===
|
||||
'not_applicable'
|
||||
? 'not_applicable'
|
||||
: 'known',
|
||||
basis: `Estimativa legal #${selected.estimate.id}, versão ${selected.estimate.version}; ${selected.line.label}. Fonte: ${selected.estimate.snapshot.legal_rule.data.official_reference}.`,
|
||||
total: estimateMoney(
|
||||
selected
|
||||
.line
|
||||
.amount_minor,
|
||||
),
|
||||
subtotal:
|
||||
selected
|
||||
.line
|
||||
.amount_minor ===
|
||||
0
|
||||
? '0.00'
|
||||
: '',
|
||||
tax:
|
||||
selected
|
||||
.line
|
||||
.amount_minor ===
|
||||
0
|
||||
? '0.00'
|
||||
: '',
|
||||
}
|
||||
: {
|
||||
...component,
|
||||
legal_estimate_id:
|
||||
null,
|
||||
legal_charge_key:
|
||||
null,
|
||||
},
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Pressuposto manual / retirar
|
||||
ligação e conservar os
|
||||
valores
|
||||
</option>
|
||||
{row.legal_estimate_id !==
|
||||
null &&
|
||||
!(
|
||||
props.legalAmounts ?? []
|
||||
).some(
|
||||
(estimate) =>
|
||||
estimate.id ===
|
||||
row.legal_estimate_id,
|
||||
) && (
|
||||
<option
|
||||
value={`${row.legal_estimate_id}:${row.legal_charge_key}`}
|
||||
>
|
||||
Versão preservada da
|
||||
estimativa #
|
||||
{
|
||||
row.legal_estimate_id
|
||||
}
|
||||
</option>
|
||||
)}
|
||||
{(
|
||||
props.legalAmounts ?? []
|
||||
).flatMap((estimate) =>
|
||||
estimate.snapshot.result.lines
|
||||
.filter(
|
||||
(line) =>
|
||||
line.kind ===
|
||||
row.kind,
|
||||
)
|
||||
.map((line) => (
|
||||
<option
|
||||
key={`${estimate.id}:${line.key}`}
|
||||
value={`${estimate.id}:${line.key}`}
|
||||
>
|
||||
{
|
||||
estimate
|
||||
.snapshot
|
||||
.item
|
||||
.description
|
||||
}{' '}
|
||||
· {line.label} ·
|
||||
estimativa #
|
||||
{estimate.id} v
|
||||
{
|
||||
estimate.version
|
||||
}{' '}
|
||||
·{' '}
|
||||
{line.amount_minor ===
|
||||
null
|
||||
? 'Por determinar'
|
||||
: `${estimateMoney(line.amount_minor)} MZN`}
|
||||
</option>
|
||||
)),
|
||||
)}
|
||||
</select>
|
||||
{row.legal_estimate_id !== null && (
|
||||
<span>
|
||||
O total conserva a fonte
|
||||
seleccionada. Indique
|
||||
explicitamente a divisão
|
||||
entre base e imposto segundo
|
||||
o orçamento. Para alterar o
|
||||
montante, retire primeiro a
|
||||
ligação.
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
)}
|
||||
<label className="grid gap-1">
|
||||
Situação
|
||||
<select
|
||||
@@ -366,6 +584,54 @@ export default function ImportEstimate(props: Props) {
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={
|
||||
form.data.components.length >=
|
||||
100
|
||||
}
|
||||
onClick={() =>
|
||||
form.setData('components', [
|
||||
...form.data.components,
|
||||
{
|
||||
key: crypto.randomUUID(),
|
||||
kind: row.kind,
|
||||
status: 'unknown',
|
||||
basis: '',
|
||||
subtotal: '',
|
||||
tax: '',
|
||||
total: '',
|
||||
legal_estimate_id: null,
|
||||
legal_charge_key: null,
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
Acrescentar parcela desta família
|
||||
</Button>
|
||||
{form.data.components.filter(
|
||||
(component) =>
|
||||
component.kind === row.kind,
|
||||
).length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
form.setData(
|
||||
'components',
|
||||
form.data.components.filter(
|
||||
(_, at) =>
|
||||
at !== index,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar parcela da preparação
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</fieldset>
|
||||
))}
|
||||
<label className="grid gap-1">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { PageTitle, Panel } from '@/components/procurement';
|
||||
import { date } from '@/types/procurement';
|
||||
|
||||
type Props = {
|
||||
importRecord: { id: number; version: number; state: string };
|
||||
order: { id: number; number: string };
|
||||
expectedUsableOn: string | null;
|
||||
checkedAt: string;
|
||||
complete: boolean;
|
||||
alerts: { key: string; category: string; text: string; href: string }[];
|
||||
};
|
||||
export default function ImportReadiness(props: Props) {
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl space-y-5 px-5 py-8">
|
||||
<Head title="Acompanhamento da importação" />
|
||||
<PageTitle
|
||||
eyebrow={`Ordem ${props.order.number}`}
|
||||
title="Acompanhamento da importação"
|
||||
description="Consulte os documentos em falta, alterações de fontes e próximos passos dos percursos existentes."
|
||||
/>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/compras/importacoes/${props.importRecord.id}/documentos`}
|
||||
>
|
||||
Abrir dossiê
|
||||
</Link>
|
||||
<Link className="underline" href="/compras/fornecimento/import">
|
||||
Voltar às importações
|
||||
</Link>
|
||||
</div>
|
||||
<Panel
|
||||
title="Situação actual"
|
||||
description="A consulta não certifica cumprimento legal, não encerra alertas por silêncio e não envia avisos ou executa operações."
|
||||
>
|
||||
<p>
|
||||
Versão logística: {props.importRecord.version} · previsão de
|
||||
recepção utilizável:{' '}
|
||||
{props.expectedUsableOn
|
||||
? date(props.expectedUsableOn)
|
||||
: 'Por indicar'}
|
||||
</p>
|
||||
{!props.complete && (
|
||||
<p role="status">
|
||||
Verificação incompleta: consulte as limitações abaixo
|
||||
antes de concluir a conferência.
|
||||
</p>
|
||||
)}
|
||||
{props.alerts.length === 0 && (
|
||||
<p>
|
||||
Sem alertas identificados no âmbito verificado. Conserve
|
||||
a conferência humana dos requisitos aplicáveis.
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-4 grid gap-4">
|
||||
{props.alerts.map((alert) => (
|
||||
<article
|
||||
key={alert.key}
|
||||
className="space-y-2 rounded border p-4"
|
||||
>
|
||||
<h2 className="font-medium">{alert.category}</h2>
|
||||
<p>{alert.text}</p>
|
||||
<Link className="underline" href={alert.href}>
|
||||
Abrir percurso relacionado
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</Panel>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@/components/procurement';
|
||||
|
||||
type RecordVersion = {
|
||||
legal_changed?: boolean;
|
||||
id: number;
|
||||
version: number;
|
||||
state: string;
|
||||
@@ -38,6 +39,7 @@ type Page<T> = {
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Props = {
|
||||
legalReady?: boolean;
|
||||
requisition: { id: number; number: string };
|
||||
items: {
|
||||
id: number;
|
||||
@@ -142,6 +144,12 @@ function ItemForm({
|
||||
? `Confirmado: ${latest.data.confirmed_code} · ${latest.snapshot.confirmed_by?.name ?? 'Comprador registado'}`
|
||||
: 'Código pautal por confirmar pelo comprador.'}
|
||||
</p>
|
||||
{latest?.legal_changed && (
|
||||
<p role="status">
|
||||
A fonte legal aplicada foi substituída ou retirada. Reveja a
|
||||
classificação; a decisão anterior permanece no histórico.
|
||||
</p>
|
||||
)}
|
||||
{latest?.snapshot.master && (
|
||||
<p>
|
||||
Proposta reutilizada de {latest.snapshot.master.item.code} ·{' '}
|
||||
@@ -368,6 +376,14 @@ export default function ImportTariffs(props: Props) {
|
||||
percurso.
|
||||
</p>
|
||||
</Panel>
|
||||
{props.legalReady && (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/requisicoes/${props.requisition.id}/base-legal`}
|
||||
>
|
||||
Consultar base legal e sugestões
|
||||
</Link>
|
||||
)}
|
||||
<Panel title="Localizar material ou código">
|
||||
<form
|
||||
method="get"
|
||||
|
||||
Reference in New Issue
Block a user