@@ -0,0 +1,54 @@
|
||||
import { Panel } from '@/components/procurement';
|
||||
|
||||
export type FrozenCapitalAssignment = {
|
||||
id: number;
|
||||
version: number;
|
||||
reason: string;
|
||||
snapshot: {
|
||||
item: { description: string };
|
||||
source: {
|
||||
version: number;
|
||||
data: {
|
||||
type: string;
|
||||
code: string;
|
||||
name: string;
|
||||
reference: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
export default function CapitalAssignmentSummary({
|
||||
records,
|
||||
}: {
|
||||
records?: Record<number, FrozenCapitalAssignment>;
|
||||
}) {
|
||||
const rows = Object.values(records ?? {});
|
||||
if (!rows.length) return null;
|
||||
return (
|
||||
<Panel
|
||||
title="Projectos e imobilizado"
|
||||
description="Referências preservadas na emissão desta ordem."
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<article
|
||||
key={row.id}
|
||||
className="space-y-2 border-b py-3 break-words"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
{row.snapshot.item.description}
|
||||
</h3>
|
||||
<p>
|
||||
{row.snapshot.source.data.type === 'project'
|
||||
? 'Projecto'
|
||||
: 'Imobilizado'}{' '}
|
||||
· {row.snapshot.source.data.code} ·{' '}
|
||||
{row.snapshot.source.data.name} · versão{' '}
|
||||
{row.snapshot.source.version}
|
||||
</p>
|
||||
<p>{row.snapshot.source.data.reference}</p>
|
||||
<p>{row.reason}</p>
|
||||
</article>
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
import { controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { estimateMoney } from '@/lib/import-estimate-money';
|
||||
import { money } from '@/types/procurement';
|
||||
|
||||
export type LegalCharge = {
|
||||
key: string;
|
||||
kind: string;
|
||||
label: string;
|
||||
method: string;
|
||||
rate_percent: string | null;
|
||||
specific_minor: number | null;
|
||||
quantity_unit: string | null;
|
||||
basis_reference: string;
|
||||
};
|
||||
export type LegalChargeDraft = {
|
||||
key: string;
|
||||
kind: string;
|
||||
label: string;
|
||||
method: string;
|
||||
rate_percent: string;
|
||||
specific_amount: string;
|
||||
quantity_unit: string;
|
||||
basis_reference: string;
|
||||
};
|
||||
export const chargeDrafts = (charges: LegalCharge[]) =>
|
||||
charges.map((charge): LegalChargeDraft => ({
|
||||
key: charge.key,
|
||||
kind: charge.kind,
|
||||
label: charge.label,
|
||||
method: charge.method,
|
||||
rate_percent: charge.rate_percent ?? '',
|
||||
specific_amount: estimateMoney(charge.specific_minor),
|
||||
quantity_unit: charge.quantity_unit ?? '',
|
||||
basis_reference: charge.basis_reference,
|
||||
}));
|
||||
export function LegalChargeSummary({ charges }: { charges: LegalCharge[] }) {
|
||||
const methods: Record<string, string> = {
|
||||
unknown: 'Por determinar',
|
||||
not_applicable: 'Não aplicável segundo a fonte',
|
||||
ad_valorem: 'Percentagem sobre base em MZN',
|
||||
specific: 'Montante por unidade',
|
||||
maximum: 'Maior valor entre percentagem e montante por unidade',
|
||||
};
|
||||
if (charges.length === 0)
|
||||
return <p>Imposições ainda por parametrizar nesta regra.</p>;
|
||||
return (
|
||||
<div className="grid gap-3">
|
||||
{charges.map((charge) => (
|
||||
<dl key={charge.key} className="rounded border p-3">
|
||||
<dt className="font-medium">{charge.label}</dt>
|
||||
<dd>{methods[charge.method]}</dd>
|
||||
{charge.rate_percent !== null && (
|
||||
<dd>Taxa: {charge.rate_percent}%</dd>
|
||||
)}
|
||||
{charge.specific_minor !== null && (
|
||||
<dd>
|
||||
Taxa específica: {money(charge.specific_minor)} por{' '}
|
||||
{charge.quantity_unit}
|
||||
</dd>
|
||||
)}
|
||||
<dt>Base e condições</dt>
|
||||
<dd>{charge.basis_reference}</dd>
|
||||
</dl>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default function LegalChargeFields({
|
||||
charges,
|
||||
onChange,
|
||||
}: {
|
||||
charges: LegalChargeDraft[];
|
||||
onChange: (charges: LegalChargeDraft[]) => void;
|
||||
}) {
|
||||
const change = (index: number, values: Partial<LegalChargeDraft>) =>
|
||||
onChange(
|
||||
charges.map((charge, at) =>
|
||||
at === index ? { ...charge, ...values } : charge,
|
||||
),
|
||||
);
|
||||
return (
|
||||
<fieldset className="space-y-4 rounded border p-4">
|
||||
<legend>Imposições documentadas para estimativa</legend>
|
||||
<p>
|
||||
Sem taxas parametrizadas, os montantes permanecem por
|
||||
determinar. Registe a base legal de cada método; não aplique
|
||||
isenções sem os seus requisitos.
|
||||
</p>
|
||||
{charges.map((charge, index) => (
|
||||
<div
|
||||
key={charge.key}
|
||||
className="grid gap-3 border-b pb-4 sm:grid-cols-2"
|
||||
>
|
||||
<label className="grid gap-1">
|
||||
Imposição
|
||||
<select
|
||||
className={controlClass}
|
||||
value={charge.kind}
|
||||
onChange={(e) =>
|
||||
change(index, { kind: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="duty">Direitos aduaneiros</option>
|
||||
<option value="ice">ICE</option>
|
||||
<option value="vat">IVA da importação</option>
|
||||
<option value="other">Outro encargo</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Designação
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={2}
|
||||
maxLength={120}
|
||||
value={charge.label}
|
||||
onChange={(e) =>
|
||||
change(index, { label: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Método previsto na fonte
|
||||
<select
|
||||
className={controlClass}
|
||||
value={charge.method}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
method: e.target.value,
|
||||
rate_percent: '',
|
||||
specific_amount: '',
|
||||
quantity_unit: '',
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="unknown">Por determinar</option>
|
||||
<option value="not_applicable">
|
||||
Não aplicável segundo a fonte
|
||||
</option>
|
||||
<option value="ad_valorem">
|
||||
Percentagem sobre base expressa em MZN
|
||||
</option>
|
||||
<option value="specific">
|
||||
Montante em MZN por unidade
|
||||
</option>
|
||||
<option value="maximum">
|
||||
Maior valor entre percentagem e taxa por unidade
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{['ad_valorem', 'maximum'].includes(charge.method) && (
|
||||
<label className="grid gap-1">
|
||||
Taxa percentual
|
||||
<input
|
||||
required
|
||||
inputMode="decimal"
|
||||
pattern="[0-9]+([.][0-9]{1,6})?"
|
||||
className={controlClass}
|
||||
value={charge.rate_percent}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
rate_percent: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
{['specific', 'maximum'].includes(charge.method) && (
|
||||
<>
|
||||
<label className="grid gap-1">
|
||||
Taxa específica em MZN por unidade
|
||||
<input
|
||||
required
|
||||
inputMode="decimal"
|
||||
className={controlClass}
|
||||
value={charge.specific_amount}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
specific_amount: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Unidade da taxa específica
|
||||
<input
|
||||
required
|
||||
maxLength={40}
|
||||
className={controlClass}
|
||||
value={charge.quantity_unit}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
quantity_unit: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
<label className="grid gap-1 sm:col-span-2">
|
||||
Artigo e condições da base de incidência ou da não
|
||||
aplicação
|
||||
<textarea
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={4000}
|
||||
className={controlClass}
|
||||
value={charge.basis_reference}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
basis_reference: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
onChange(charges.filter((_, at) => at !== index))
|
||||
}
|
||||
>
|
||||
Retirar desta preparação
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={charges.length >= 20}
|
||||
onClick={() =>
|
||||
onChange([
|
||||
...charges,
|
||||
{
|
||||
key: crypto.randomUUID(),
|
||||
kind: 'duty',
|
||||
label: '',
|
||||
method: 'unknown',
|
||||
rate_percent: '',
|
||||
specific_amount: '',
|
||||
quantity_unit: '',
|
||||
basis_reference: '',
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
Acrescentar imposição documentada
|
||||
</Button>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
@@ -13,6 +13,16 @@ export type FrozenImportTariff = {
|
||||
};
|
||||
confirmed_by: { name: string };
|
||||
reason: string;
|
||||
legal_rule?: {
|
||||
version: number;
|
||||
data: {
|
||||
official_reference: string;
|
||||
citation: string;
|
||||
obligations: string;
|
||||
document_types: string[];
|
||||
};
|
||||
context: { date: string; origin_country: string; sector: string };
|
||||
} | null;
|
||||
};
|
||||
export default function ImportTariffSummary({
|
||||
records,
|
||||
@@ -42,6 +52,18 @@ export default function ImportTariffSummary({
|
||||
</dd>
|
||||
<dt>Fonte da confirmação</dt>
|
||||
<dd>{record.data.confirmation_source}</dd>
|
||||
{record.legal_rule && (
|
||||
<>
|
||||
<dt>Regra legal aplicada</dt>
|
||||
<dd>
|
||||
{record.legal_rule.data.official_reference}{' '}
|
||||
· {record.legal_rule.data.citation} · versão{' '}
|
||||
{record.legal_rule.version}
|
||||
</dd>
|
||||
<dt>Condições preservadas</dt>
|
||||
<dd>{record.legal_rule.data.obligations}</dd>
|
||||
</>
|
||||
)}
|
||||
<dt>
|
||||
{record.data.deviation
|
||||
? 'Justificação do desvio'
|
||||
|
||||
@@ -37,6 +37,61 @@ function topic(
|
||||
}
|
||||
|
||||
export const journeyHelp: JourneyHelp[] = [
|
||||
topic(
|
||||
'import-readiness',
|
||||
'Acompanhar pendências da importação',
|
||||
['supply/import-readiness'],
|
||||
'Reunir os alertas factuais da ordem e abrir o percurso que permite resolver cada pendência.',
|
||||
[
|
||||
'Confira a previsão de recepção utilizável com os marcos logísticos e as quantidades efectivamente aceites.',
|
||||
'Consulte originais em falta ou alterados e os documentos indicados nas fontes legais preservadas.',
|
||||
'Reveja alterações de fontes, intervenientes, instruções e suporte bancário nos respectivos percursos.',
|
||||
'Finanças consulta as preparações de custo pendentes no circuito financeiro existente.',
|
||||
],
|
||||
[
|
||||
'Informação desconhecida permanece por determinar e verificações indisponíveis são identificadas.',
|
||||
'A consulta não concede competências, não envia notificações e não certifica cumprimento ou pagamentos.',
|
||||
],
|
||||
'Se a importação mudou, abra a versão actual e volte a conferir as pendências; os originais e decisões anteriores permanecem preservados.',
|
||||
'Abra o percurso relacionado com a pendência e regresse para consultar a situação actualizada.',
|
||||
),
|
||||
topic(
|
||||
'import-legal',
|
||||
'Consultar e manter a base legal de importação',
|
||||
['supply/import-legal'],
|
||||
'Consultar fontes aplicáveis ao código, origem, sector e período e preparar a classificação do artigo.',
|
||||
[
|
||||
'Indique o contexto e a data. Sem correspondência publicada, a regra permanece por determinar.',
|
||||
'Seleccione o artigo e prepare uma proposta com a fonte escolhida; confirme ou justifique o desvio na classificação pautal.',
|
||||
'A área aduaneira conserva exemplar, diploma, citação e vigência antes de validar e publicar a preparação.',
|
||||
'Uma revisão conserva a publicação anterior até nova validação. A retirada impede novas sugestões.',
|
||||
],
|
||||
[
|
||||
'Publicar uma fonte não activa cálculos, isenções, pagamentos ou submissões JUE.',
|
||||
'Uma mudança da regra sinaliza a decisão anterior, conservando a fonte e o histórico aplicados.',
|
||||
],
|
||||
'Se a regra mudou ou o exemplar divergiu, preserve a preparação e seleccione uma fonte actual antes da confirmação.',
|
||||
'Regresse à classificação pautal para confirmar a proposta ou justificar o desvio.',
|
||||
),
|
||||
topic(
|
||||
'import-bank-support',
|
||||
'Acompanhar o suporte documental bancário',
|
||||
['supply/import-bank-support'],
|
||||
'Associar o termo de compromisso ao documento único, reunir os suportes solicitados e conservar o comprovativo de entrega ao banco.',
|
||||
[
|
||||
'Seleccione os originais já registados no dossiê; não reintroduza referências ou entidades emitentes.',
|
||||
'Identifique os tipos e quantidades pedidos pelo banco, com a fonte dos requisitos.',
|
||||
'Indique apenas um prazo documentado e a sua fonte; informação desconhecida permanece por indicar.',
|
||||
'Reunir documentos não demonstra entrega. Seleccione o comprovativo de entrega quando estiver disponível.',
|
||||
'Corrija por nova versão e consulte os alertas, o histórico e o CSV do âmbito completo.',
|
||||
],
|
||||
[
|
||||
'A correcção ou perda de um original reabre o alerta; o registo anterior não é apagado.',
|
||||
'O acompanhamento não executa transferências ou submissões na JUE e não certifica cumprimento bancário.',
|
||||
],
|
||||
'Conserve a preparação se a versão mudou. Seleccione explicitamente os novos originais e explique a correcção.',
|
||||
'Consulte os prazos e documentos em falta e prossiga no percurso próprio da importação.',
|
||||
),
|
||||
topic(
|
||||
'import-estimate',
|
||||
'Preparar o custo estimado da importação',
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Data = {
|
||||
type: string;
|
||||
code: string;
|
||||
name: string;
|
||||
department_id: number;
|
||||
equipment_id: number | null;
|
||||
reference: string;
|
||||
};
|
||||
type Record = {
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
state: string;
|
||||
data: Data;
|
||||
reason: string;
|
||||
};
|
||||
type Props = {
|
||||
trace?: {
|
||||
orders: { data: { id: number; description: string; quantity: string; unit: string; order_id: number; order_number: string }[]; prev_page_url: string | null; next_page_url: string | null };
|
||||
receipts: { data: { id: number; description: string | null; unit: string | null; receipt_id: number; order_id: number | null; received_on: string | null; quality_status: string; accepted_quantity: string; reversed: boolean; returned_quantity: string }[]; prev_page_url: string | null; next_page_url: string | null };
|
||||
} | null;
|
||||
history: {
|
||||
data: Record[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
} | null;
|
||||
records: {
|
||||
data: Record[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
departments: { id: number; name: string }[];
|
||||
equipment: {
|
||||
id: number;
|
||||
code: string;
|
||||
description: string;
|
||||
department_id: number;
|
||||
}[];
|
||||
canManage: boolean;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
};
|
||||
export default function CapitalRegister(props: Props) {
|
||||
const url = '/projectos-imobilizado';
|
||||
const form = useForm(
|
||||
`capital-register:${props.tenantId}:${props.actorId}`,
|
||||
{
|
||||
operation_key: '',
|
||||
record_key: null as string | null,
|
||||
version: 0,
|
||||
type: 'project',
|
||||
code: '',
|
||||
name: '',
|
||||
department_id: '',
|
||||
equipment_id: '',
|
||||
reference: '',
|
||||
state: 'active',
|
||||
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: Record) =>
|
||||
form.setData({
|
||||
...record.data,
|
||||
operation_key: '',
|
||||
record_key: record.record_key,
|
||||
version: record.version,
|
||||
department_id: String(record.data.department_id),
|
||||
equipment_id:
|
||||
record.data.equipment_id === null
|
||||
? ''
|
||||
: String(record.data.equipment_id),
|
||||
state: record.state,
|
||||
reason: '',
|
||||
});
|
||||
return (
|
||||
<div className="mx-auto grid w-full max-w-6xl min-w-0 gap-6 p-5 lg:p-8">
|
||||
<Head title="Projectos e imobilizado" />
|
||||
<PageTitle
|
||||
eyebrow="Cadastro de Compras"
|
||||
title="Projectos e imobilizado"
|
||||
description="Identifique o projecto ou a referência de imobilizado da compra. A ligação ao equipamento reutiliza a ficha física existente."
|
||||
/>
|
||||
<Link className="underline" href="/equipamentos">
|
||||
Consultar equipamentos e peças
|
||||
</Link>
|
||||
<Panel
|
||||
title="Identidades registadas"
|
||||
description="As revisões conservam o código e o histórico. Arquivar impede novas escolhas sem apagar ligações anteriores."
|
||||
>
|
||||
{props.records.data.length === 0 && (
|
||||
<p>Ainda não há registos neste âmbito.</p>
|
||||
)}
|
||||
{props.records.data.map((record) => (
|
||||
<article
|
||||
key={record.id}
|
||||
className="min-w-0 space-y-2 border-b py-4 break-words"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
{record.data.code} · {record.data.name}
|
||||
</h3>
|
||||
<p>
|
||||
{record.data.type === 'project'
|
||||
? 'Projecto'
|
||||
: 'Imobilizado'}{' '}
|
||||
·{' '}
|
||||
{record.state === 'active' ? 'Activo' : 'Arquivado'}{' '}
|
||||
· versão {record.version}
|
||||
</p>
|
||||
<p>{record.data.reference}</p>
|
||||
<p>{record.reason}</p>
|
||||
<Link
|
||||
className="underline"
|
||||
preserveState
|
||||
href={`${url}?history=${record.record_key}`}
|
||||
>
|
||||
Consultar versões e origens
|
||||
</Link>
|
||||
{props.canManage && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => edit(record)}
|
||||
>
|
||||
Preparar nova versão
|
||||
</Button>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
<nav
|
||||
className="mt-4 flex gap-4"
|
||||
aria-label="Páginas do cadastro"
|
||||
>
|
||||
{props.records.prev_page_url && (
|
||||
<Link preserveState href={props.records.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.records.next_page_url && (
|
||||
<Link preserveState href={props.records.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
{props.history && (
|
||||
<Panel title="Histórico do registo">
|
||||
{props.history.data.map((record) => (
|
||||
<article
|
||||
key={record.id}
|
||||
className="space-y-2 border-b py-4 break-words"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
{record.data.code} · versão {record.version}
|
||||
</h3>
|
||||
<p>
|
||||
{record.data.name} ·{' '}
|
||||
{record.state === 'active'
|
||||
? 'Activo'
|
||||
: 'Arquivado'}
|
||||
</p>
|
||||
<p>{record.data.reference}</p>
|
||||
<p>{record.reason}</p>
|
||||
</article>
|
||||
))}
|
||||
<nav
|
||||
className="mt-4 flex gap-4"
|
||||
aria-label="Páginas do histórico"
|
||||
>
|
||||
{props.history.prev_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
href={props.history.prev_page_url}
|
||||
>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.history.next_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
href={props.history.next_page_url}
|
||||
>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
)}
|
||||
{props.trace && <Panel title="Ordens que preservaram esta referência" description="As ligações vêm dos documentos emitidos, incluindo escolhas anteriores a revisões do cadastro.">
|
||||
{props.trace.orders.data.length === 0 && <p>Ainda não há ordens visíveis com esta referência preservada.</p>}
|
||||
{props.trace.orders.data.map(line => <article key={line.id} className="space-y-2 border-b py-3 break-words"><Link className="underline" href={`/ordens/${line.order_id}`}>{line.order_number}</Link><p>{line.description} · {line.quantity} {line.unit}</p></article>)}
|
||||
<nav className="flex gap-4" aria-label="Ordens de origem">{props.trace.orders.prev_page_url && <Link preserveState href={props.trace.orders.prev_page_url}>Anterior</Link>}{props.trace.orders.next_page_url && <Link preserveState href={props.trace.orders.next_page_url}>Seguinte</Link>}</nav>
|
||||
</Panel>}
|
||||
{props.trace && <Panel title="Recepções destas origens" description="A quantidade aceite é a do documento original. Estornos e devoluções actuais são apresentados separadamente; a recepção não certifica capitalização contabilística.">
|
||||
{props.trace.receipts.data.length === 0 && <p>Ainda não há recepções visíveis nestas origens.</p>}
|
||||
{props.trace.receipts.data.map(receipt => <article key={receipt.id} className="space-y-2 border-b py-3 break-words"><h3 className="font-semibold">Recepção #{receipt.receipt_id} · {receipt.description || 'Descrição por conferir'}</h3><p>Data: {receipt.received_on || 'Por conferir'} · Aceite no original: {receipt.accepted_quantity} {receipt.unit || ''}</p><p>Qualidade registada: {receipt.quality_status === 'compliant' ? 'Conforme' : receipt.quality_status === 'quarantined' ? 'Em quarentena' : 'Com divergência'}</p>{receipt.reversed && <p className="font-semibold">Recepção estornada; o original permanece no histórico.</p>}{receipt.returned_quantity !== '0.000' && <p>Devolução ao fornecedor: {receipt.returned_quantity} {receipt.unit || ''}</p>}{receipt.order_id && <Link className="underline" href={`/ordens/${receipt.order_id}`}>Conferir documentos e movimentos da ordem</Link>}</article>)}
|
||||
<nav className="flex gap-4" aria-label="Recepções de origem">{props.trace.receipts.prev_page_url && <Link preserveState href={props.trace.receipts.prev_page_url}>Anterior</Link>}{props.trace.receipts.next_page_url && <Link preserveState href={props.trace.receipts.next_page_url}>Seguinte</Link>}</nav>
|
||||
</Panel>}
|
||||
{props.canManage && (
|
||||
<Panel
|
||||
title={
|
||||
form.data.record_key
|
||||
? `Rever cadastro · versão ${form.data.version}`
|
||||
: 'Novo registo'
|
||||
}
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const operation =
|
||||
form.data.operation_key || crypto.randomUUID();
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
...data,
|
||||
operation_key: operation,
|
||||
equipment_id: data.equipment_id || null,
|
||||
}));
|
||||
form.post(url, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
form.clearErrors();
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<label className="grid gap-2">
|
||||
Tipo
|
||||
<select
|
||||
className={controlClass}
|
||||
disabled={form.data.record_key !== null}
|
||||
value={form.data.type}
|
||||
onChange={(e) =>
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
type: e.target.value,
|
||||
equipment_id: '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
<option value="project">Projecto</option>
|
||||
<option value="asset">Imobilizado</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-2">
|
||||
Código
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
readOnly={form.data.record_key !== null}
|
||||
maxLength={40}
|
||||
value={form.data.code}
|
||||
onChange={(e) =>
|
||||
form.setData('code', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-2">
|
||||
Designação
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={200}
|
||||
value={form.data.name}
|
||||
onChange={(e) =>
|
||||
form.setData('name', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-2">
|
||||
Departamento
|
||||
<select
|
||||
className={controlClass}
|
||||
required
|
||||
value={form.data.department_id}
|
||||
onChange={(e) =>
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
department_id: e.target.value,
|
||||
equipment_id: '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{props.departments.map((d) => (
|
||||
<option key={d.id} value={d.id}>
|
||||
{d.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{form.data.type === 'asset' && (
|
||||
<label className="grid gap-2">
|
||||
Equipamento identificado, quando disponível
|
||||
<select
|
||||
className={controlClass}
|
||||
value={form.data.equipment_id}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'equipment_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Ainda sem ligação à ficha física
|
||||
</option>
|
||||
{props.equipment
|
||||
.filter(
|
||||
(e) =>
|
||||
String(e.department_id) ===
|
||||
form.data.department_id,
|
||||
)
|
||||
.map((e) => (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.code} · {e.description}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
<label className="grid gap-2">
|
||||
Referência documental
|
||||
<textarea
|
||||
className={controlClass}
|
||||
required
|
||||
maxLength={1000}
|
||||
value={form.data.reference}
|
||||
onChange={(e) =>
|
||||
form.setData('reference', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-2">
|
||||
Disponibilidade para novas escolhas
|
||||
<select
|
||||
className={controlClass}
|
||||
value={form.data.state}
|
||||
onChange={(e) =>
|
||||
form.setData('state', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="active">Activo</option>
|
||||
<option value="archived">Arquivado</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-2">
|
||||
Motivo desta versão
|
||||
<textarea
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={4000}
|
||||
value={form.data.reason}
|
||||
onChange={(e) =>
|
||||
form.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
O cadastro conserva referências documentais. Não
|
||||
regista capitalização, depreciação ou movimentos
|
||||
contabilísticos.
|
||||
</p>
|
||||
<Button disabled={form.processing}>
|
||||
Guardar versão do cadastro
|
||||
</Button>
|
||||
{form.data.record_key && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
form.reset();
|
||||
form.clearErrors();
|
||||
}}
|
||||
>
|
||||
Preparar outro registo
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
</Panel>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -64,6 +64,7 @@ type History = {
|
||||
};
|
||||
};
|
||||
type Props = {
|
||||
capitalRegisterReady?: boolean;
|
||||
geographyEnabled?: boolean;
|
||||
equipmentGeography?: Record<number, GeographyDescription>;
|
||||
geographyFilter?: GeographyDescription;
|
||||
@@ -107,6 +108,7 @@ export default function EquipmentPage({
|
||||
history,
|
||||
canManage,
|
||||
canConfigure,
|
||||
capitalRegisterReady = false,
|
||||
demo = false,
|
||||
geographyEnabled = false,
|
||||
equipmentGeography = {},
|
||||
@@ -157,6 +159,11 @@ export default function EquipmentPage({
|
||||
description="Cadastro, peças compatíveis, mínimos explícitos e rastreabilidade das saídas."
|
||||
/>
|
||||
<InventoryNotice />
|
||||
{capitalRegisterReady && (
|
||||
<Link className="underline" href="/projectos-imobilizado">
|
||||
Projectos e imobilizado
|
||||
</Link>
|
||||
)}
|
||||
{geographyEnabled && !demo && (
|
||||
<Panel title="Localização dos equipamentos">
|
||||
<TerritorialFilter
|
||||
|
||||
@@ -9,6 +9,7 @@ import { date, money, roleLabels } from '@/types/procurement';
|
||||
import { ExchangeSummary } from '@/components/quotation-exchange-panel';
|
||||
import type { PurchaseOrder } from '@/types/purchase';
|
||||
import ImportTariffSummary from '@/components/import-tariff-summary';
|
||||
import CapitalAssignmentSummary from '@/components/capital-assignment-summary';
|
||||
import OrderCancellationRequest, {
|
||||
type OrderCancellationState,
|
||||
} from '@/components/order-cancellation-request';
|
||||
@@ -171,6 +172,9 @@ export default function OrderShow({
|
||||
</Link>
|
||||
)}
|
||||
<ImportTariffSummary records={snapshot.import_tariffs} />
|
||||
<CapitalAssignmentSummary
|
||||
records={snapshot.capital_assignments}
|
||||
/>
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
{snapshot.investment_rules && (
|
||||
<Panel title="Regra de investimento congelada">
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Source = {
|
||||
id: number;
|
||||
version: number;
|
||||
data: { code: string; name: string; type: string; reference: string };
|
||||
};
|
||||
type Assignment = {
|
||||
id: number;
|
||||
version: number;
|
||||
state: string;
|
||||
reason: string;
|
||||
data: { requisition_item_id: number };
|
||||
snapshot: { item: { description: string }; source: Source | null };
|
||||
};
|
||||
type Page<T> = {
|
||||
data: T[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
type Props = {
|
||||
requisition: { id: number; number: string; status: string };
|
||||
items: { id: number; description: string }[];
|
||||
current: Assignment[];
|
||||
history: Page<Assignment>;
|
||||
choices: Page<Source>;
|
||||
canWrite: boolean;
|
||||
actorId: number;
|
||||
tenantId: number;
|
||||
};
|
||||
export default function CapitalAssignments(props: Props) {
|
||||
const url = `/requisicoes/${props.requisition.id}/projectos-imobilizado`;
|
||||
const form = useForm(
|
||||
`capital-assignment:${props.tenantId}:${props.actorId}:${props.requisition.id}`,
|
||||
{
|
||||
operation_key: '',
|
||||
item_id: '',
|
||||
version: 0,
|
||||
capital_id: '',
|
||||
capital_label: '',
|
||||
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 chooseItem = (id: string) => {
|
||||
const old = props.current.find(
|
||||
(row) => String(row.data.requisition_item_id) === id,
|
||||
);
|
||||
const source = old?.snapshot.source;
|
||||
form.setData({
|
||||
operation_key: '',
|
||||
item_id: id,
|
||||
version: old?.version ?? 0,
|
||||
capital_id: source ? String(source.id) : '',
|
||||
capital_label: source
|
||||
? `${source.data.code} · ${source.data.name} · v${source.version}`
|
||||
: '',
|
||||
reason: '',
|
||||
});
|
||||
};
|
||||
return (
|
||||
<div className="mx-auto grid w-full max-w-6xl min-w-0 gap-6 p-5 lg:p-8">
|
||||
<Head title="Destino por projecto ou imobilizado" />
|
||||
<PageTitle
|
||||
eyebrow={props.requisition.number}
|
||||
title="Projecto ou imobilizado por artigo"
|
||||
description="Seleccione a referência do cadastro próprio de Compras. A ligação preserva a versão escolhida e acompanha as novas ordens."
|
||||
/>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/requisicoes/${props.requisition.id}`}
|
||||
>
|
||||
Voltar à requisição
|
||||
</Link>
|
||||
<Panel title="Ligações actuais">
|
||||
{props.current.length === 0 && (
|
||||
<p>
|
||||
Ainda não há ligações registadas. As origens anteriores
|
||||
permanecem preservadas.
|
||||
</p>
|
||||
)}
|
||||
{props.current.map((row) => (
|
||||
<article
|
||||
key={row.id}
|
||||
className="space-y-2 border-b py-4 break-words"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
{row.snapshot.item.description} · versão{' '}
|
||||
{row.version}
|
||||
</h3>
|
||||
<p>
|
||||
{row.state === 'cleared'
|
||||
? 'Ligação retirada explicitamente'
|
||||
: `${row.snapshot.source?.data.code} · ${row.snapshot.source?.data.name} · versão ${row.snapshot.source?.version}`}
|
||||
</p>
|
||||
<p>{row.reason}</p>
|
||||
</article>
|
||||
))}
|
||||
</Panel>
|
||||
{props.canWrite && (
|
||||
<Panel
|
||||
title="Preparar ligação"
|
||||
description="A escolha é explícita. As distribuições e decisões orçamentais conservam o seu percurso próprio."
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const operation =
|
||||
form.data.operation_key || crypto.randomUUID();
|
||||
form.setData('operation_key', operation);
|
||||
form.transform((data) => ({
|
||||
operation_key: operation,
|
||||
item_id: data.item_id,
|
||||
version: data.version,
|
||||
capital_id: data.capital_id || null,
|
||||
reason: data.reason,
|
||||
}));
|
||||
form.post(url, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
form.clearErrors();
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<label className="grid gap-2">
|
||||
Artigo
|
||||
<select
|
||||
required
|
||||
className={controlClass}
|
||||
value={form.data.item_id}
|
||||
onChange={(event) =>
|
||||
chooseItem(event.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{props.items.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.description}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<p>
|
||||
Referência seleccionada:{' '}
|
||||
{form.data.capital_label || 'Sem ligação'} · versão
|
||||
da preparação {form.data.version}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Reveja o artigo actual antes de guardar. Uma
|
||||
referência arquivada conserva-se no histórico e nas
|
||||
escolhas já aceites; para uma nova ligação, escolha
|
||||
uma versão activa.
|
||||
</p>
|
||||
{props.choices.data.map((source) => (
|
||||
<article
|
||||
key={source.id}
|
||||
className="min-w-0 space-y-2 border-b py-3 break-words"
|
||||
>
|
||||
<p>
|
||||
{source.data.type === 'project'
|
||||
? 'Projecto'
|
||||
: 'Imobilizado'}{' '}
|
||||
· {source.data.code} · {source.data.name} ·
|
||||
versão {source.version}
|
||||
</p>
|
||||
<p>{source.data.reference}</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={!form.data.item_id}
|
||||
onClick={() =>
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
capital_id: String(source.id),
|
||||
capital_label: `${source.data.code} · ${source.data.name} · v${source.version}`,
|
||||
operation_key: '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
Escolher {source.data.code}
|
||||
</Button>
|
||||
</article>
|
||||
))}
|
||||
{props.choices.data.length === 0 && (
|
||||
<p>
|
||||
Não há referências activas no departamento desta
|
||||
requisição.
|
||||
</p>
|
||||
)}
|
||||
<nav
|
||||
className="flex gap-4"
|
||||
aria-label="Referências do cadastro"
|
||||
>
|
||||
{props.choices.prev_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
href={props.choices.prev_page_url}
|
||||
>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.choices.next_page_url && (
|
||||
<Link
|
||||
preserveState
|
||||
href={props.choices.next_page_url}
|
||||
>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={!form.data.item_id}
|
||||
onClick={() =>
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
capital_id: '',
|
||||
capital_label: '',
|
||||
operation_key: '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
Retirar ligação desta preparação
|
||||
</Button>
|
||||
<label className="grid gap-2">
|
||||
Motivo
|
||||
<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 || !form.data.item_id}
|
||||
>
|
||||
Guardar ligação
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Histórico preservado">
|
||||
{props.history.data.map((row) => (
|
||||
<article
|
||||
key={row.id}
|
||||
className="space-y-2 border-b py-3 break-words"
|
||||
>
|
||||
<p>
|
||||
{row.snapshot.item.description} · versão{' '}
|
||||
{row.version} ·{' '}
|
||||
{row.snapshot.source
|
||||
? `${row.snapshot.source.data.code} · v${row.snapshot.source.version}`
|
||||
: 'Sem ligação'}
|
||||
</p>
|
||||
<p>{row.reason}</p>
|
||||
</article>
|
||||
))}
|
||||
<nav className="flex gap-4" aria-label="Histórico das ligações">
|
||||
{props.history.prev_page_url && (
|
||||
<Link preserveState href={props.history.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{props.history.next_page_url && (
|
||||
<Link preserveState href={props.history.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -55,8 +55,10 @@ export default function Show({
|
||||
canPrepareDistributions = false,
|
||||
importTariffsReady = false,
|
||||
importEstimatesReady = false,
|
||||
capitalRegisterReady = false,
|
||||
}: {
|
||||
importEstimatesReady?: boolean;
|
||||
capitalRegisterReady?: boolean;
|
||||
importTariffsReady?: boolean;
|
||||
canPrepareDistributions?: boolean;
|
||||
requisition: Requisition;
|
||||
@@ -165,6 +167,15 @@ export default function Show({
|
||||
}
|
||||
/>
|
||||
<FormErrors errors={submission.errors} />
|
||||
{capitalRegisterReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link
|
||||
href={`/requisicoes/${r.id}/projectos-imobilizado`}
|
||||
>
|
||||
Ligar artigos a projecto ou imobilizado
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{importEstimatesReady && (
|
||||
<Button asChild variant="outline">
|
||||
<Link
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { CommercialTerms } from '@/components/quotation-commercial-terms';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
import type { ExchangeBasis } from '@/components/quotation-exchange-panel';
|
||||
import type { FrozenImportTariff } from '@/components/import-tariff-summary';
|
||||
import type { FrozenCapitalAssignment } from '@/components/capital-assignment-summary';
|
||||
|
||||
export type MatrixRow = {
|
||||
currency?: string;
|
||||
@@ -99,6 +100,7 @@ export type PurchaseOrder = {
|
||||
total_minor: number;
|
||||
items: OrderItem[];
|
||||
snapshot: {
|
||||
capital_assignments?: Record<number, FrozenCapitalAssignment>;
|
||||
import_tariffs?: Record<number, FrozenImportTariff>;
|
||||
budget_checked?: boolean;
|
||||
agreement_bindings?: Record<string, FrozenOrderAgreement>;
|
||||
|
||||
Reference in New Issue
Block a user