1665 lines
74 KiB
TypeScript
1665 lines
74 KiB
TypeScript
import { Head, Link, useForm, useRemember } from '@inertiajs/react';
|
|
import { useEffect, useRef, type RefObject } from 'react';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
FormErrors,
|
|
PageTitle,
|
|
Panel,
|
|
controlClass,
|
|
} from '@/components/procurement';
|
|
import { orderPartMinor } from '@/lib/order-parts';
|
|
import { money } from '@/types/procurement';
|
|
import ImportTariffSummary, {
|
|
type FrozenImportTariff,
|
|
} from '@/components/import-tariff-summary';
|
|
|
|
type Money = {
|
|
subtotal_minor: number;
|
|
tax_minor: number;
|
|
total_minor: number;
|
|
reference_subtotal_minor: number;
|
|
reference_tax_minor: number;
|
|
reference_total_minor: number;
|
|
};
|
|
type Selection = {
|
|
origin: string;
|
|
kind: string;
|
|
id: number;
|
|
label?: string;
|
|
currency?: string;
|
|
};
|
|
type Component = Money & {
|
|
component_key: string;
|
|
kind: string;
|
|
origin: string;
|
|
};
|
|
type PlanData = {
|
|
budget_id: number;
|
|
documents: Selection[];
|
|
components: Component[];
|
|
item_references?: {
|
|
component_key: string;
|
|
purchase_order_item_ids: number[];
|
|
}[];
|
|
};
|
|
type OrderItem = {
|
|
id: number;
|
|
description: string;
|
|
unit: string;
|
|
quantity: string;
|
|
};
|
|
type Plan = {
|
|
item_references?: Record<string, OrderItem[]>;
|
|
document_details: Record<
|
|
string,
|
|
{
|
|
reference: string;
|
|
creditor: string;
|
|
currency: string;
|
|
financial_authority: 'native_invoice' | 'documentary_source_only';
|
|
exchange_basis: {
|
|
rate: string;
|
|
quoted_on: string;
|
|
source: string;
|
|
} | null;
|
|
}
|
|
>;
|
|
components: Component[];
|
|
total_minor: number;
|
|
budget_amount_minor: number;
|
|
includes_tax: boolean;
|
|
fingerprint: string;
|
|
documents: Record<
|
|
string,
|
|
{ creditor_key: string; currency: string; total_minor: number }
|
|
>;
|
|
};
|
|
type Version = {
|
|
id: number;
|
|
record_key: string;
|
|
version: number;
|
|
state: string;
|
|
reason: string;
|
|
data: PlanData;
|
|
snapshot: { contributors: number[]; plan: Plan };
|
|
};
|
|
type Page<T> = {
|
|
data: T[];
|
|
prev_page_url: string | null;
|
|
next_page_url: string | null;
|
|
};
|
|
type Doc = {
|
|
id: number;
|
|
record_key: string;
|
|
version: number;
|
|
data: {
|
|
issued_on: string;
|
|
creditor_reference: string;
|
|
exchange_basis: {
|
|
rate: string;
|
|
quoted_on: string;
|
|
source: string;
|
|
} | null;
|
|
reference: string;
|
|
kind: string;
|
|
currency: string;
|
|
subtotal_minor: number;
|
|
tax_minor: number;
|
|
total_minor: number;
|
|
};
|
|
};
|
|
type Props = {
|
|
importTariffs: Record<number, FrozenImportTariff>;
|
|
orderItems: OrderItem[];
|
|
financialEvents: Page<{
|
|
id: number;
|
|
version: number;
|
|
reason: string;
|
|
created_by: number;
|
|
data: { action: string; financial_plan_version: number };
|
|
snapshot: {
|
|
common_result: {
|
|
additional_amount_minor: number;
|
|
reserved_delta_minor?: number;
|
|
committed_delta_minor?: number;
|
|
consumed_delta_minor?: number;
|
|
};
|
|
actor?: { name: string };
|
|
};
|
|
}>;
|
|
financialReady: boolean;
|
|
financialState: {
|
|
revision: number;
|
|
native_plan_id: number | null;
|
|
reserved_minor: number;
|
|
committed_minor: number;
|
|
consumed_minor: number;
|
|
origins: {
|
|
source_key: string;
|
|
source_version: number;
|
|
phase: string;
|
|
documented_amount_minor: number;
|
|
reserved_minor: number;
|
|
committed_minor: number;
|
|
consumed_minor: number;
|
|
reference: string;
|
|
evidence_url: string;
|
|
}[];
|
|
version: number;
|
|
plan_hash: string;
|
|
phase: string;
|
|
additional_amount_minor: number;
|
|
total_reference_minor: number;
|
|
} | null;
|
|
importRecord: {
|
|
id: number;
|
|
record_key: string;
|
|
context_changed: boolean;
|
|
context: Record<string, string | null>;
|
|
version: number;
|
|
order_id: number;
|
|
order_number: string;
|
|
};
|
|
documents: Page<Doc>;
|
|
invoices: Page<{
|
|
id: number;
|
|
number: string;
|
|
currency: string;
|
|
purchase_order_id: number;
|
|
total_minor: number;
|
|
}>;
|
|
budgets: Page<{
|
|
id: number;
|
|
cost_center_id: number;
|
|
kind: string;
|
|
includes_tax: boolean;
|
|
}>;
|
|
history: Page<Version>;
|
|
latest: Version | null;
|
|
preview: Plan | null;
|
|
actorId: number;
|
|
tenantId: number;
|
|
};
|
|
const fields = [
|
|
'subtotal_minor',
|
|
'tax_minor',
|
|
'total_minor',
|
|
'reference_subtotal_minor',
|
|
'reference_tax_minor',
|
|
'reference_total_minor',
|
|
] as const;
|
|
const labels = [
|
|
'Base documental',
|
|
'Imposto documental',
|
|
'Total documental',
|
|
'Base em MZN',
|
|
'Imposto em MZN',
|
|
'Total em MZN',
|
|
];
|
|
const componentKinds = {
|
|
goods: 'Mercadoria',
|
|
freight: 'Frete',
|
|
insurance: 'Seguro',
|
|
duty: 'Direitos aduaneiros',
|
|
ice: 'ICE',
|
|
vat: 'IVA aduaneiro',
|
|
other: 'Outro custo documentado',
|
|
};
|
|
const financialActions: Record<string, string> = {
|
|
reserve: 'Reserva',
|
|
commit: 'Compromisso',
|
|
consume: 'Consumo',
|
|
amend: 'Reafectação documentada',
|
|
cancel: 'Libertação de saldo',
|
|
};
|
|
const decimal = (value: number) =>
|
|
`${Math.floor(value / 100)}.${String(value % 100).padStart(2, '0')}`;
|
|
type DraftComponent = {
|
|
component_key: string;
|
|
kind: string;
|
|
origin: string;
|
|
values: string[];
|
|
};
|
|
|
|
function useGuard(ref: RefObject<HTMLFormElement | null>, dirty: boolean) {
|
|
useEffect(() => {
|
|
const element = ref.current;
|
|
window.dispatchEvent(
|
|
new CustomEvent('sgc:context-dirty', {
|
|
detail: { form: element, dirty },
|
|
}),
|
|
);
|
|
return () => {
|
|
window.dispatchEvent(
|
|
new CustomEvent('sgc:context-dirty', {
|
|
detail: { form: element, dirty: false },
|
|
}),
|
|
);
|
|
};
|
|
}, [ref, dirty]);
|
|
}
|
|
|
|
function Pagination({
|
|
page,
|
|
}: {
|
|
page: { prev_page_url: string | null; next_page_url: string | null };
|
|
}) {
|
|
return (
|
|
<nav
|
|
className="mt-3 flex flex-wrap gap-4"
|
|
aria-label="Páginas desta lista"
|
|
>
|
|
{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>
|
|
);
|
|
}
|
|
|
|
function DocumentForm({
|
|
url,
|
|
historyKey,
|
|
documents,
|
|
}: {
|
|
url: string;
|
|
historyKey: string;
|
|
documents: Doc[];
|
|
}) {
|
|
const form = useForm(historyKey, {
|
|
operation_key: crypto.randomUUID(),
|
|
record_key: null as string | null,
|
|
version: 0,
|
|
kind: 'customs_assessment',
|
|
reference: '',
|
|
issued_on: '',
|
|
creditor_reference: '',
|
|
currency: 'MZN',
|
|
subtotal: '',
|
|
tax: '',
|
|
total: '',
|
|
rate: '',
|
|
quoted_on: '',
|
|
source: '',
|
|
reason: '',
|
|
file: null as File | null,
|
|
}).dontRemember('file');
|
|
const ref = useRef<HTMLFormElement>(null);
|
|
useGuard(ref, form.isDirty);
|
|
return (
|
|
<Panel title="Registar documento adicional">
|
|
<p className="mb-4">
|
|
Conserve a referência, o credor e os valores do documento. Este
|
|
registo não cria uma factura de fornecedor nem executa
|
|
pagamentos. Depois de recarregar, seleccione novamente o
|
|
ficheiro.
|
|
</p>
|
|
<form
|
|
ref={ref}
|
|
className="grid gap-4"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
form.transform((data) => ({
|
|
operation_key: data.operation_key,
|
|
record_key: data.record_key,
|
|
version: data.version,
|
|
kind: data.kind,
|
|
reference: data.reference,
|
|
issued_on: data.issued_on,
|
|
creditor_reference: data.creditor_reference,
|
|
currency: data.currency,
|
|
subtotal_minor: orderPartMinor(data.subtotal),
|
|
tax_minor: orderPartMinor(data.tax),
|
|
total_minor: orderPartMinor(data.total),
|
|
exchange_basis:
|
|
data.currency === 'MZN'
|
|
? null
|
|
: {
|
|
rate: data.rate,
|
|
quoted_on: data.quoted_on,
|
|
source: data.source,
|
|
},
|
|
reason: data.reason,
|
|
file: data.file,
|
|
}));
|
|
form.post(`${url}/documentos`, {
|
|
onSuccess: () => {
|
|
form.reset();
|
|
form.setData('operation_key', crypto.randomUUID());
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<label>
|
|
Documento novo ou correcção
|
|
<select
|
|
className={controlClass}
|
|
value={form.data.record_key ?? ''}
|
|
onChange={(e) => {
|
|
const document = documents.find(
|
|
(row) => row.record_key === e.target.value,
|
|
);
|
|
if (!document) {
|
|
form.reset();
|
|
form.setData(
|
|
'operation_key',
|
|
crypto.randomUUID(),
|
|
);
|
|
return;
|
|
}
|
|
form.setData({
|
|
operation_key: crypto.randomUUID(),
|
|
record_key: document.record_key,
|
|
version: document.version,
|
|
kind: document.data.kind,
|
|
reference: document.data.reference,
|
|
issued_on: document.data.issued_on,
|
|
creditor_reference:
|
|
document.data.creditor_reference,
|
|
currency: document.data.currency,
|
|
subtotal: decimal(document.data.subtotal_minor),
|
|
tax: decimal(document.data.tax_minor),
|
|
total: decimal(document.data.total_minor),
|
|
rate: document.data.exchange_basis?.rate ?? '',
|
|
quoted_on:
|
|
document.data.exchange_basis?.quoted_on ??
|
|
'',
|
|
source:
|
|
document.data.exchange_basis?.source ?? '',
|
|
reason: '',
|
|
file: null,
|
|
});
|
|
}}
|
|
>
|
|
<option value="">Novo documento</option>
|
|
{documents.map((document) => (
|
|
<option
|
|
key={document.id}
|
|
value={document.record_key}
|
|
>
|
|
{document.data.reference} · Corrigir versão{' '}
|
|
{document.version}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Tipo de documento
|
|
<select
|
|
className={controlClass}
|
|
value={form.data.kind}
|
|
onChange={(e) => form.setData('kind', e.target.value)}
|
|
>
|
|
<option value="customs_assessment">
|
|
Liquidação aduaneira
|
|
</option>
|
|
<option value="other_charge">
|
|
Outra imposição documentada
|
|
</option>
|
|
</select>
|
|
</label>
|
|
{(
|
|
[
|
|
'reference',
|
|
'issued_on',
|
|
'creditor_reference',
|
|
'currency',
|
|
'subtotal',
|
|
'tax',
|
|
'total',
|
|
] as const
|
|
).map((field, i) => (
|
|
<label key={field}>
|
|
{
|
|
[
|
|
'Referência documental',
|
|
'Data do documento',
|
|
'Credor / entidade destinatária',
|
|
'Moeda original',
|
|
'Base documental',
|
|
'Imposto documental',
|
|
'Total documental',
|
|
][i]
|
|
}
|
|
<input
|
|
className={controlClass}
|
|
required
|
|
type={field === 'issued_on' ? 'date' : 'text'}
|
|
disabled={
|
|
form.data.record_key !== null &&
|
|
field === 'currency'
|
|
}
|
|
inputMode={
|
|
['subtotal', 'tax', 'total'].includes(field)
|
|
? 'decimal'
|
|
: undefined
|
|
}
|
|
value={form.data[field]}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
field,
|
|
field === 'currency'
|
|
? e.target.value.toUpperCase()
|
|
: e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
))}
|
|
{form.data.currency !== 'MZN' && (
|
|
<fieldset className="grid gap-3 rounded border p-4">
|
|
<legend>
|
|
Taxa explícita de Finanças, congelada neste
|
|
documento
|
|
</legend>
|
|
{(['rate', 'quoted_on', 'source'] as const).map(
|
|
(field, i) => (
|
|
<label key={field}>
|
|
{
|
|
[
|
|
'Taxa para MZN',
|
|
'Data da taxa',
|
|
'Fonte da taxa',
|
|
][i]
|
|
}
|
|
<input
|
|
required
|
|
className={controlClass}
|
|
disabled={form.data.record_key !== null}
|
|
type={
|
|
field === 'quoted_on'
|
|
? 'date'
|
|
: 'text'
|
|
}
|
|
value={form.data[field]}
|
|
onChange={(e) =>
|
|
form.setData(field, e.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
),
|
|
)}
|
|
</fieldset>
|
|
)}
|
|
<label>
|
|
Fundamento
|
|
<textarea
|
|
className={controlClass}
|
|
required
|
|
minLength={10}
|
|
value={form.data.reason}
|
|
onChange={(e) => form.setData('reason', e.target.value)}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Evidência privada (PDF ou imagem, até 2 MB)
|
|
<input
|
|
required
|
|
type="file"
|
|
key={form.data.operation_key}
|
|
accept=".pdf,.jpg,.jpeg,.png"
|
|
onChange={(e) =>
|
|
form.setData('file', e.target.files?.[0] ?? null)
|
|
}
|
|
/>
|
|
</label>
|
|
<Button disabled={form.processing}>
|
|
Conservar o documento
|
|
</Button>
|
|
</form>
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
function CostPreparation(props: Props & { url: string; historyKey: string }) {
|
|
const { latest, url } = props;
|
|
const [invoiceRoles, setInvoiceRoles] = useRemember<Record<number, string>>(
|
|
{},
|
|
`${props.historyKey}:invoice-types`,
|
|
);
|
|
const form = useForm(`${props.historyKey}:plan:${latest?.version ?? 0}`, {
|
|
operation_key: crypto.randomUUID(),
|
|
budget_id: latest?.data.budget_id ? String(latest.data.budget_id) : '',
|
|
documents: latest?.data.documents ?? ([] as Selection[]),
|
|
itemReferences: Object.fromEntries(
|
|
(latest?.data.item_references ?? []).map((row) => [
|
|
row.component_key,
|
|
row.purchase_order_item_ids,
|
|
]),
|
|
) as Record<string, number[]>,
|
|
components:
|
|
latest?.data.components.map((row) => ({
|
|
component_key: row.component_key,
|
|
kind: row.kind,
|
|
origin: row.origin,
|
|
values: fields.map((field) => decimal(row[field])),
|
|
})) ?? ([] as DraftComponent[]),
|
|
reason: '',
|
|
});
|
|
const ref = useRef<HTMLFormElement>(null);
|
|
useGuard(ref, form.isDirty);
|
|
const selection = () => ({
|
|
budget_id: form.data.budget_id,
|
|
item_references: form.data.components
|
|
.filter(
|
|
(row) => form.data.itemReferences[row.component_key]?.length,
|
|
)
|
|
.map((row) => ({
|
|
component_key: row.component_key,
|
|
purchase_order_item_ids:
|
|
form.data.itemReferences[row.component_key],
|
|
})),
|
|
documents: form.data.documents.map(({ origin, kind, id }) => ({
|
|
origin,
|
|
kind,
|
|
id,
|
|
})),
|
|
components: form.data.components.map((row) => ({
|
|
component_key: row.component_key,
|
|
kind: row.kind,
|
|
origin: row.origin,
|
|
subtotal_minor: orderPartMinor(row.values[0]),
|
|
tax_minor: orderPartMinor(row.values[1]),
|
|
total_minor: orderPartMinor(row.values[2]),
|
|
reference_subtotal_minor: orderPartMinor(row.values[3]),
|
|
reference_tax_minor: orderPartMinor(row.values[4]),
|
|
reference_total_minor: orderPartMinor(row.values[5]),
|
|
})),
|
|
});
|
|
const add = (source: Selection) => {
|
|
if (form.data.documents.some((old) => old.origin === source.origin))
|
|
return;
|
|
form.setData((data) => ({
|
|
...data,
|
|
documents: [...data.documents, source],
|
|
components: [
|
|
...data.components,
|
|
{
|
|
component_key: crypto.randomUUID(),
|
|
origin: source.origin,
|
|
kind:
|
|
source.kind === 'supplier_invoice'
|
|
? 'goods'
|
|
: source.kind === 'carrier_invoice'
|
|
? 'freight'
|
|
: source.kind === 'insurer_invoice'
|
|
? 'insurance'
|
|
: source.kind === 'customs_assessment'
|
|
? 'duty'
|
|
: 'other',
|
|
values: fields.map(() => ''),
|
|
},
|
|
],
|
|
}));
|
|
};
|
|
return (
|
|
<Panel title="Preparar os componentes e as origens">
|
|
<p className="mb-4">
|
|
Cada documento conserva o seu credor e principal. Indique
|
|
valores explícitos, usando ponto para os decimais; um imposto
|
|
desconhecido deve ser esclarecido antes da conferência. A
|
|
preparação fica conservada para este utilizador e empresa.
|
|
Inclua como custo adicional apenas encargos que ainda não
|
|
estejam incluídos nas facturas seleccionadas.
|
|
</p>
|
|
<div className="mb-6 grid gap-4">
|
|
<h3 className="font-semibold">Facturas validadas</h3>
|
|
{props.invoices.data.map((invoice) => (
|
|
<div
|
|
key={invoice.id}
|
|
className="flex flex-wrap items-center gap-3 rounded border p-3"
|
|
>
|
|
<span>
|
|
{invoice.number} ·{' '}
|
|
{money(invoice.total_minor, invoice.currency)} ·
|
|
Ordem #{invoice.purchase_order_id}
|
|
</span>
|
|
<Link
|
|
className="underline"
|
|
href={`/ordens/${invoice.purchase_order_id}`}
|
|
>
|
|
Consultar a origem
|
|
</Link>
|
|
<label>
|
|
Natureza desta factura
|
|
<select
|
|
className={controlClass}
|
|
value={invoiceRoles[invoice.id] ?? ''}
|
|
onChange={(event) =>
|
|
setInvoiceRoles((roles) => ({
|
|
...roles,
|
|
[invoice.id]: event.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="">Seleccione</option>
|
|
{invoice.purchase_order_id ===
|
|
props.importRecord.order_id && (
|
|
<option value="supplier_invoice">
|
|
Mercadoria
|
|
</option>
|
|
)}
|
|
<option value="carrier_invoice">
|
|
Transporte
|
|
</option>
|
|
<option value="insurer_invoice">Seguro</option>
|
|
</select>
|
|
</label>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
disabled={!invoiceRoles[invoice.id]}
|
|
onClick={() =>
|
|
add({
|
|
origin: `invoice:${invoice.id}`,
|
|
kind: invoiceRoles[invoice.id],
|
|
id: invoice.id,
|
|
label: invoice.number,
|
|
currency: invoice.currency,
|
|
})
|
|
}
|
|
>
|
|
Incluir factura
|
|
</Button>
|
|
</div>
|
|
))}
|
|
<Pagination page={props.invoices} />
|
|
<h3 className="font-semibold">Documentos adicionais</h3>
|
|
{props.documents.data.map((document) => (
|
|
<div
|
|
key={document.id}
|
|
className="flex flex-wrap items-center gap-3 rounded border p-3"
|
|
>
|
|
<span>
|
|
{document.data.reference} ·{' '}
|
|
{money(
|
|
document.data.total_minor,
|
|
document.data.currency,
|
|
)}
|
|
</span>
|
|
<a
|
|
href={`${url}/documentos/${document.id}`}
|
|
className="underline"
|
|
>
|
|
Consultar evidência
|
|
</a>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() =>
|
|
add({
|
|
origin: `cost:${document.id}`,
|
|
kind: document.data.kind,
|
|
id: document.id,
|
|
label: document.data.reference,
|
|
currency: document.data.currency,
|
|
})
|
|
}
|
|
>
|
|
Incluir documento
|
|
</Button>
|
|
</div>
|
|
))}
|
|
<Pagination page={props.documents} />
|
|
</div>
|
|
<form
|
|
ref={ref}
|
|
className="grid gap-4"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
form.transform(selection);
|
|
form.post(url, {
|
|
preserveState: true,
|
|
preserveScroll: true,
|
|
});
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<label>
|
|
Dotação de referência
|
|
<select
|
|
required
|
|
className={controlClass}
|
|
value={form.data.budget_id}
|
|
onChange={(e) =>
|
|
form.setData('budget_id', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Seleccione</option>
|
|
{props.budgets.data.map((budget) => (
|
|
<option key={budget.id} value={budget.id}>
|
|
#{budget.id} · Centro #{budget.cost_center_id} ·{' '}
|
|
{budget.kind === 'investment'
|
|
? 'Investimento'
|
|
: 'Funcionamento'}{' '}
|
|
·{' '}
|
|
{budget.includes_tax
|
|
? 'Com imposto'
|
|
: 'Sem imposto'}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<Pagination page={props.budgets} />
|
|
{form.data.documents.map((source) => (
|
|
<fieldset
|
|
key={source.origin}
|
|
className="grid min-w-0 gap-3 rounded border p-4"
|
|
>
|
|
<legend>
|
|
{source.label ??
|
|
latest?.snapshot.plan.document_details[
|
|
source.origin
|
|
]?.reference ??
|
|
`Documento #${source.id}`}{' '}
|
|
·{' '}
|
|
{source.currency ??
|
|
latest?.snapshot.plan.document_details[
|
|
source.origin
|
|
]?.currency ??
|
|
'Consulte a moeda na origem'}
|
|
</legend>
|
|
<label>
|
|
Natureza do documento
|
|
<select
|
|
className={controlClass}
|
|
value={source.kind}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'documents',
|
|
form.data.documents.map((row) =>
|
|
row.origin === source.origin
|
|
? {
|
|
...row,
|
|
kind: e.target.value,
|
|
}
|
|
: row,
|
|
),
|
|
)
|
|
}
|
|
>
|
|
{source.origin.startsWith('invoice:') ? (
|
|
<>
|
|
<option value="supplier_invoice">
|
|
Factura de mercadoria
|
|
</option>
|
|
<option value="carrier_invoice">
|
|
Factura de transporte
|
|
</option>
|
|
<option value="insurer_invoice">
|
|
Factura de seguro
|
|
</option>
|
|
</>
|
|
) : (
|
|
<option value={source.kind}>
|
|
{source.kind === 'customs_assessment'
|
|
? 'Liquidação aduaneira'
|
|
: 'Outra imposição'}
|
|
</option>
|
|
)}
|
|
</select>
|
|
</label>
|
|
{form.data.components
|
|
.filter((row) => row.origin === source.origin)
|
|
.map((row) => (
|
|
<fieldset
|
|
key={row.component_key}
|
|
className="grid min-w-0 gap-3 rounded border p-3"
|
|
>
|
|
<legend>Componente</legend>
|
|
<label>
|
|
Tipo
|
|
<select
|
|
className={controlClass}
|
|
value={row.kind}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'components',
|
|
form.data.components.map(
|
|
(old) =>
|
|
old.component_key ===
|
|
row.component_key
|
|
? {
|
|
...old,
|
|
kind: e
|
|
.target
|
|
.value,
|
|
}
|
|
: old,
|
|
),
|
|
)
|
|
}
|
|
>
|
|
{Object.entries(componentKinds).map(
|
|
([key, label]) => (
|
|
<option
|
|
key={key}
|
|
value={key}
|
|
>
|
|
{label}
|
|
</option>
|
|
),
|
|
)}
|
|
</select>
|
|
</label>
|
|
<div className="grid min-w-0 gap-3 sm:grid-cols-2">
|
|
{fields.map((field, index) => (
|
|
<label key={field}>
|
|
{labels[index]}
|
|
<input
|
|
required
|
|
inputMode="decimal"
|
|
className={controlClass}
|
|
value={row.values[index]}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'components',
|
|
form.data.components.map(
|
|
(old) =>
|
|
old.component_key ===
|
|
row.component_key
|
|
? {
|
|
...old,
|
|
values: old.values.map(
|
|
(
|
|
value,
|
|
position,
|
|
) =>
|
|
position ===
|
|
index
|
|
? e
|
|
.target
|
|
.value
|
|
: value,
|
|
),
|
|
}
|
|
: old,
|
|
),
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
))}
|
|
</div>
|
|
<label>
|
|
Artigos associados (opcional)
|
|
<select
|
|
multiple
|
|
className={controlClass}
|
|
value={(
|
|
form.data.itemReferences[
|
|
row.component_key
|
|
] ?? []
|
|
).map(String)}
|
|
onChange={(event) =>
|
|
form.setData('itemReferences', {
|
|
...form.data.itemReferences,
|
|
[row.component_key]:
|
|
Array.from(
|
|
event.currentTarget
|
|
.selectedOptions,
|
|
(option) =>
|
|
Number(
|
|
option.value,
|
|
),
|
|
),
|
|
})
|
|
}
|
|
>
|
|
{props.orderItems.map((item) => (
|
|
<option
|
|
key={item.id}
|
|
value={item.id}
|
|
>
|
|
{item.description} ·{' '}
|
|
{item.quantity} {item.unit}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<span className="block text-sm text-muted-foreground">
|
|
Referência para integração futura.
|
|
Não calcula rateios nem altera o
|
|
custo ou o stock. Sem selecção, o
|
|
componente permanece ao nível da
|
|
importação.
|
|
</span>
|
|
</label>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() =>
|
|
form.setData(
|
|
'components',
|
|
form.data.components.filter(
|
|
(old) =>
|
|
old.component_key !==
|
|
row.component_key,
|
|
),
|
|
)
|
|
}
|
|
>
|
|
Retirar componente
|
|
</Button>
|
|
</fieldset>
|
|
))}
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() =>
|
|
form.setData('components', [
|
|
...form.data.components,
|
|
{
|
|
component_key: crypto.randomUUID(),
|
|
kind: 'other',
|
|
origin: source.origin,
|
|
values: fields.map(() => ''),
|
|
},
|
|
])
|
|
}
|
|
>
|
|
Acrescentar componente
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() =>
|
|
form.setData((data) => ({
|
|
...data,
|
|
documents: data.documents.filter(
|
|
(row) => row.origin !== source.origin,
|
|
),
|
|
components: data.components.filter(
|
|
(row) => row.origin !== source.origin,
|
|
),
|
|
}))
|
|
}
|
|
>
|
|
Retirar origem desta preparação
|
|
</Button>
|
|
</fieldset>
|
|
))}
|
|
<label>
|
|
Fundamento da preparação
|
|
<textarea
|
|
className={controlClass}
|
|
minLength={10}
|
|
value={form.data.reason}
|
|
onChange={(e) => form.setData('reason', e.target.value)}
|
|
/>
|
|
</label>
|
|
<div className="flex flex-wrap gap-3">
|
|
<Button disabled={form.processing}>Conferir valores</Button>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
disabled={
|
|
form.processing ||
|
|
form.data.reason.trim().length < 10
|
|
}
|
|
onClick={() => {
|
|
form.transform(() => ({
|
|
operation_key: form.data.operation_key,
|
|
record_key: latest?.record_key ?? null,
|
|
version: latest?.version ?? 0,
|
|
action: 'save',
|
|
reason: form.data.reason,
|
|
data: selection(),
|
|
}));
|
|
form.post(`${url}/preparacao`, {
|
|
onSuccess: () =>
|
|
form.setData(
|
|
'operation_key',
|
|
crypto.randomUUID(),
|
|
),
|
|
});
|
|
}}
|
|
>
|
|
Guardar para revisão
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
function FinancialStage({
|
|
latest,
|
|
importRecord,
|
|
financialState: state,
|
|
financialReady,
|
|
url,
|
|
historyKey,
|
|
}: Props & { url: string; historyKey: string }) {
|
|
const form = useForm(`${historyKey}:financial`, {
|
|
operation_key: crypto.randomUUID(),
|
|
reason: '',
|
|
sources: [] as string[],
|
|
});
|
|
const ref = useRef<HTMLFormElement>(null);
|
|
useGuard(ref, form.isDirty);
|
|
if (!financialReady || !latest) return null;
|
|
const current = latest.state === 'approved';
|
|
const changed =
|
|
state &&
|
|
(state.version !== latest.version ||
|
|
state.plan_hash !== latest.snapshot.plan.fingerprint);
|
|
const origins = state?.origins ?? [];
|
|
const selected =
|
|
form.data.sources.length === 0
|
|
? origins
|
|
: origins.filter((origin) =>
|
|
form.data.sources.includes(origin.source_key),
|
|
);
|
|
const actions: [string, string, number][] = [];
|
|
const eligible = (phase: string) =>
|
|
selected.some((origin) => origin.phase === phase);
|
|
if (current && !importRecord.context_changed) {
|
|
if (!state) {
|
|
if (
|
|
Object.values(latest.snapshot.plan.document_details).some(
|
|
(document) =>
|
|
document.financial_authority ===
|
|
'documentary_source_only',
|
|
)
|
|
)
|
|
actions.push([
|
|
'reserve',
|
|
'Reservar a preparação adicional conferida',
|
|
latest.id,
|
|
]);
|
|
} else if (changed)
|
|
actions.push([
|
|
'amend',
|
|
'Aplicar toda a nova preparação conferida',
|
|
latest.id,
|
|
]);
|
|
else {
|
|
if (eligible('reserved'))
|
|
actions.push([
|
|
'commit',
|
|
'Comprometer as origens elegíveis',
|
|
latest.id,
|
|
]);
|
|
if (eligible('committed'))
|
|
actions.push([
|
|
'consume',
|
|
'Consumir as origens elegíveis',
|
|
latest.id,
|
|
]);
|
|
}
|
|
}
|
|
if (
|
|
state?.native_plan_id &&
|
|
(eligible('reserved') || eligible('committed'))
|
|
)
|
|
actions.push([
|
|
'cancel',
|
|
'Libertar apenas o saldo não consumido',
|
|
state.native_plan_id,
|
|
]);
|
|
const phaseLabels: Record<string, string> = {
|
|
reserved: 'Reservado',
|
|
committed: 'Comprometido',
|
|
consumed: 'Consumido',
|
|
cancelled: 'Saldo não consumido libertado',
|
|
mixed: 'Origens em fases distintas',
|
|
};
|
|
return (
|
|
<Panel title="Aplicação orçamental dos custos adicionais">
|
|
<p>
|
|
As facturas mantêm os efeitos financeiros nativos. Esta etapa
|
|
movimenta apenas as origens adicionais; não executa pagamentos
|
|
ou submissões JUE. Um consumo anterior nunca é repetido ao
|
|
acrescentar custos.
|
|
</p>
|
|
{state && (
|
|
<>
|
|
<dl className="my-4 grid gap-3 sm:grid-cols-2">
|
|
<div>
|
|
<dt>Situação</dt>
|
|
<dd>{phaseLabels[state.phase] ?? state.phase}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Custo adicional documentado</dt>
|
|
<dd>{money(state.additional_amount_minor)}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Reserva actual</dt>
|
|
<dd>{money(state.reserved_minor)}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Compromisso actual</dt>
|
|
<dd>{money(state.committed_minor)}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Consumo preservado</dt>
|
|
<dd>{money(state.consumed_minor)}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Referência global com documentos nativos</dt>
|
|
<dd>{money(state.total_reference_minor)}</dd>
|
|
</div>
|
|
</dl>
|
|
<p className="my-3">
|
|
Sem seleccionar origens, a acção abrange todas as que
|
|
estão na etapa indicada. A reafectação aplica sempre a
|
|
preparação conferida completa.
|
|
</p>
|
|
{origins.map((origin) => (
|
|
<fieldset
|
|
className="my-3 grid gap-2 rounded border p-3"
|
|
key={origin.source_key}
|
|
>
|
|
<legend>
|
|
{origin.reference} · Documento, versão{' '}
|
|
{origin.source_version}
|
|
</legend>
|
|
<a className="underline" href={origin.evidence_url}>
|
|
Consultar esta evidência
|
|
</a>
|
|
<p>
|
|
{phaseLabels[origin.phase] ?? origin.phase} ·
|
|
Custo documentado:{' '}
|
|
{money(origin.documented_amount_minor)}
|
|
</p>
|
|
{['reserved', 'committed'].includes(
|
|
origin.phase,
|
|
) && (
|
|
<label>
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.sources.includes(
|
|
origin.source_key,
|
|
)}
|
|
onChange={(event) =>
|
|
form.setData(
|
|
'sources',
|
|
event.target.checked
|
|
? [
|
|
...form.data.sources,
|
|
origin.source_key,
|
|
]
|
|
: form.data.sources.filter(
|
|
(key) =>
|
|
key !==
|
|
origin.source_key,
|
|
),
|
|
)
|
|
}
|
|
/>{' '}
|
|
Seleccionar esta origem
|
|
</label>
|
|
)}
|
|
<p>
|
|
Reserva: {money(origin.reserved_minor)} ·
|
|
Compromisso: {money(origin.committed_minor)} ·
|
|
Consumo: {money(origin.consumed_minor)}
|
|
</p>
|
|
</fieldset>
|
|
))}
|
|
</>
|
|
)}
|
|
{(!current || importRecord.context_changed) && (
|
|
<p className="my-3">
|
|
Prepare e confira a versão actual antes de continuar. Os
|
|
efeitos anteriores ficam preservados; o saldo ainda não
|
|
consumido pode ser libertado separadamente.
|
|
</p>
|
|
)}
|
|
{actions.length > 0 && (
|
|
<form
|
|
ref={ref}
|
|
className="mt-4 grid gap-3"
|
|
onSubmit={(event) => event.preventDefault()}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<label>
|
|
Fundamento da acção orçamental
|
|
<textarea
|
|
required
|
|
minLength={10}
|
|
className={controlClass}
|
|
value={form.data.reason}
|
|
onChange={(event) =>
|
|
form.setData('reason', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<div className="flex flex-wrap gap-3">
|
|
{actions.map(([action, label, planId]) => (
|
|
<Button
|
|
key={action}
|
|
type="button"
|
|
variant={
|
|
action === 'cancel' ? 'outline' : 'default'
|
|
}
|
|
disabled={
|
|
form.processing ||
|
|
form.data.reason.trim().length < 10
|
|
}
|
|
onClick={() => {
|
|
const applicable =
|
|
action === 'commit'
|
|
? selected.filter(
|
|
(origin) =>
|
|
origin.phase ===
|
|
'reserved',
|
|
)
|
|
: action === 'consume'
|
|
? selected.filter(
|
|
(origin) =>
|
|
origin.phase ===
|
|
'committed',
|
|
)
|
|
: selected.filter((origin) =>
|
|
[
|
|
'reserved',
|
|
'committed',
|
|
].includes(origin.phase),
|
|
);
|
|
form.transform((data) => ({
|
|
operation_key: data.operation_key,
|
|
reason: data.reason,
|
|
action,
|
|
financial_revision:
|
|
state?.revision ?? 0,
|
|
sources:
|
|
action === 'reserve' ||
|
|
action === 'amend'
|
|
? []
|
|
: applicable.map(
|
|
(origin) =>
|
|
origin.source_key,
|
|
),
|
|
}));
|
|
form.post(`${url}/${planId}/orcamento`, {
|
|
onSuccess: () => {
|
|
form.reset();
|
|
form.setData(
|
|
'operation_key',
|
|
crypto.randomUUID(),
|
|
);
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
{label}
|
|
</Button>
|
|
))}
|
|
</div>
|
|
</form>
|
|
)}
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
export default function ImportCosts(props: Props) {
|
|
const url = `/compras/importacoes/${props.importRecord.id}/custos`;
|
|
const key = `import-costs:${props.tenantId}:${props.actorId}:${props.importRecord.record_key}:${props.importRecord.order_id}`;
|
|
const latest = props.latest;
|
|
const decision = useForm(`${key}:review:${latest?.version ?? 0}`, {
|
|
operation_key: crypto.randomUUID(),
|
|
reason: '',
|
|
});
|
|
const decisionRef = useRef<HTMLFormElement>(null);
|
|
useGuard(decisionRef, decision.isDirty);
|
|
return (
|
|
<>
|
|
<Head title="Custo de aterragem" />
|
|
<div className="grid min-w-0 gap-6 p-4 sm:p-6">
|
|
<PageTitle
|
|
eyebrow="Importações"
|
|
title="Custo de aterragem"
|
|
description={`${props.importRecord.order_number} · Importação, versão ${props.importRecord.version}`}
|
|
action={
|
|
<Link href={`/ordens/${props.importRecord.order_id}`}>
|
|
Voltar à ordem
|
|
</Link>
|
|
}
|
|
/>
|
|
<Panel title="Contexto da importação">
|
|
<dl className="grid gap-3 sm:grid-cols-2">
|
|
{Object.entries({
|
|
purpose: 'Finalidade',
|
|
jurisdiction: 'Jurisdição',
|
|
origin_country: 'País de origem',
|
|
dispatch_country: 'País de expedição',
|
|
incoterm: 'Incoterm',
|
|
regime: 'Regime',
|
|
}).map(([field, label]) => (
|
|
<div key={field}>
|
|
<dt>{label}</dt>
|
|
<dd>
|
|
{field === 'purpose'
|
|
? props.importRecord.context[field] ===
|
|
'resale'
|
|
? 'Revenda'
|
|
: props.importRecord.context[
|
|
field
|
|
] === 'internal'
|
|
? 'Uso interno'
|
|
: 'Por completar'
|
|
: props.importRecord.context[field] ||
|
|
'Por completar'}
|
|
</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
{props.importRecord.context_changed && (
|
|
<p className="mt-3">
|
|
O contexto relevante para os custos mudou. Conserve
|
|
a preparação anterior e confira uma nova versão.
|
|
</p>
|
|
)}
|
|
</Panel>
|
|
<p className="rounded border p-4">
|
|
A conferência documental conserva as origens e não executa
|
|
movimentos orçamentais, pagamentos ou submissões JUE. A
|
|
aplicação financeira é uma etapa separada.
|
|
</p>
|
|
<ImportTariffSummary records={props.importTariffs} />
|
|
<DocumentForm
|
|
key={key}
|
|
url={url}
|
|
historyKey={`${key}:document`}
|
|
documents={props.documents.data}
|
|
/>
|
|
<CostPreparation
|
|
key={`${key}:plan:${latest?.version ?? 0}`}
|
|
{...props}
|
|
url={url}
|
|
historyKey={key}
|
|
/>
|
|
{props.preview && (
|
|
<Panel title="Conferência dos valores">
|
|
<p>
|
|
Total em MZN: {money(props.preview.total_minor)} ·
|
|
Referência orçamental:{' '}
|
|
{money(props.preview.budget_amount_minor)} (
|
|
{props.preview.includes_tax
|
|
? 'com imposto'
|
|
: 'sem imposto'}
|
|
).
|
|
</p>
|
|
<p>
|
|
Os documentos e credores mantêm os seus valores
|
|
próprios. Guarde a preparação para a revisão
|
|
independente.
|
|
</p>
|
|
</Panel>
|
|
)}
|
|
{latest?.state === 'draft' &&
|
|
!latest.snapshot.contributors.includes(props.actorId) && (
|
|
<Panel title="Revisão independente de Finanças">
|
|
<form
|
|
ref={decisionRef}
|
|
className="grid gap-3"
|
|
onSubmit={(event) => event.preventDefault()}
|
|
>
|
|
<FormErrors errors={decision.errors} />
|
|
<label>
|
|
Fundamento da decisão
|
|
<textarea
|
|
required
|
|
minLength={10}
|
|
className={controlClass}
|
|
value={decision.data.reason}
|
|
onChange={(e) =>
|
|
decision.setData(
|
|
'reason',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
<div className="flex flex-wrap gap-3">
|
|
{[
|
|
[
|
|
'approve',
|
|
'Confirmar conferência documental',
|
|
],
|
|
['return', 'Devolver para correcção'],
|
|
].map(([action, label]) => (
|
|
<Button
|
|
key={action}
|
|
type="button"
|
|
disabled={
|
|
decision.processing ||
|
|
decision.data.reason.trim()
|
|
.length < 10
|
|
}
|
|
onClick={() => {
|
|
decision.transform((data) => ({
|
|
...data,
|
|
record_key:
|
|
latest.record_key,
|
|
version: latest.version,
|
|
action,
|
|
data: [],
|
|
}));
|
|
decision.post(
|
|
`${url}/preparacao`,
|
|
{
|
|
onSuccess: () => {
|
|
decision.reset();
|
|
decision.setData(
|
|
'operation_key',
|
|
crypto.randomUUID(),
|
|
);
|
|
},
|
|
},
|
|
);
|
|
}}
|
|
>
|
|
{label}
|
|
</Button>
|
|
))}
|
|
</div>
|
|
</form>
|
|
</Panel>
|
|
)}
|
|
<FinancialStage
|
|
key={key}
|
|
{...props}
|
|
url={url}
|
|
historyKey={key}
|
|
/>
|
|
{props.financialEvents.data.length > 0 && (
|
|
<Panel title="Histórico orçamental adicional">
|
|
{props.financialEvents.data.map((event) => (
|
|
<article
|
|
key={event.id}
|
|
className="mb-3 rounded border p-4"
|
|
>
|
|
<h3 className="font-semibold">
|
|
{financialActions[event.data.action] ??
|
|
event.data.action}{' '}
|
|
· Movimento {event.version} · Preparação
|
|
financeira, versão{' '}
|
|
{event.data.financial_plan_version}
|
|
</h3>
|
|
<p>
|
|
{event.snapshot.actor?.name ??
|
|
`Interveniente #${event.created_by}`}{' '}
|
|
· Custo adicional documentado:{' '}
|
|
{money(
|
|
event.snapshot.common_result
|
|
.additional_amount_minor,
|
|
)}
|
|
</p>
|
|
<dl className="my-3 grid gap-3 sm:grid-cols-3">
|
|
<div>
|
|
<dt>Variação da reserva</dt>
|
|
<dd>
|
|
{money(
|
|
event.snapshot.common_result
|
|
.reserved_delta_minor,
|
|
)}
|
|
</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Variação do compromisso</dt>
|
|
<dd>
|
|
{money(
|
|
event.snapshot.common_result
|
|
.committed_delta_minor,
|
|
)}
|
|
</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Variação do consumo</dt>
|
|
<dd>
|
|
{money(
|
|
event.snapshot.common_result
|
|
.consumed_delta_minor,
|
|
)}
|
|
</dd>
|
|
</div>
|
|
</dl>
|
|
<p>{event.reason}</p>
|
|
</article>
|
|
))}
|
|
<Pagination page={props.financialEvents} />
|
|
</Panel>
|
|
)}
|
|
<Panel title="Versões preservadas">
|
|
{props.history.data.map((version) => (
|
|
<details
|
|
className="mb-4 rounded border p-4"
|
|
key={version.id}
|
|
open={version.id === latest?.id}
|
|
>
|
|
<summary>
|
|
Versão {version.version} ·{' '}
|
|
{version.state === 'approved'
|
|
? 'Conferida'
|
|
: version.state === 'returned'
|
|
? 'Devolvida'
|
|
: 'Em preparação'}{' '}
|
|
· {money(version.snapshot.plan.total_minor)}
|
|
</summary>
|
|
<p>{version.reason}</p>
|
|
{version.snapshot.plan.components.map(
|
|
(component) => (
|
|
<fieldset
|
|
key={component.component_key}
|
|
className="my-3 grid gap-2 rounded border p-3"
|
|
>
|
|
<legend>
|
|
{Object.entries(
|
|
componentKinds,
|
|
).find(
|
|
([kind]) =>
|
|
kind === component.kind,
|
|
)?.[1] ?? component.kind}
|
|
</legend>
|
|
<p>
|
|
Artigos associados:{' '}
|
|
{version.snapshot.plan.item_references?.[
|
|
component.component_key
|
|
]
|
|
?.map(
|
|
(item) =>
|
|
`${item.description} (${item.quantity} ${item.unit})`,
|
|
)
|
|
.join('; ') ||
|
|
'Ao nível da importação, sem associação por artigo'}
|
|
</p>
|
|
<p>
|
|
Documento:{' '}
|
|
{
|
|
version.snapshot.plan
|
|
.document_details[
|
|
component.origin
|
|
].reference
|
|
}{' '}
|
|
· Credor:{' '}
|
|
{
|
|
version.snapshot.plan
|
|
.document_details[
|
|
component.origin
|
|
].creditor
|
|
}
|
|
</p>
|
|
{version.snapshot.plan.document_details[
|
|
component.origin
|
|
].exchange_basis && (
|
|
<p>
|
|
Taxa congelada:{' '}
|
|
{
|
|
version.snapshot.plan
|
|
.document_details[
|
|
component.origin
|
|
].exchange_basis?.rate
|
|
}{' '}
|
|
· Data:{' '}
|
|
{
|
|
version.snapshot.plan
|
|
.document_details[
|
|
component.origin
|
|
].exchange_basis?.quoted_on
|
|
}{' '}
|
|
· Fonte:{' '}
|
|
{
|
|
version.snapshot.plan
|
|
.document_details[
|
|
component.origin
|
|
].exchange_basis?.source
|
|
}
|
|
</p>
|
|
)}
|
|
<dl className="grid gap-2 sm:grid-cols-2">
|
|
{fields.map((field, index) => (
|
|
<div key={field}>
|
|
<dt>{labels[index]}</dt>
|
|
<dd>
|
|
{money(
|
|
component[field],
|
|
index < 3
|
|
? version
|
|
.snapshot
|
|
.plan
|
|
.documents[
|
|
component
|
|
.origin
|
|
].currency
|
|
: 'MZN',
|
|
)}
|
|
</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
</fieldset>
|
|
),
|
|
)}
|
|
<p>
|
|
Referência orçamental:{' '}
|
|
{money(
|
|
version.snapshot.plan.budget_amount_minor,
|
|
)}
|
|
. A conferência não executa efeitos financeiros.
|
|
</p>
|
|
{Object.entries(
|
|
version.snapshot.plan.documents,
|
|
).map(([origin, doc]) => (
|
|
<p key={origin}>
|
|
{origin} ·{' '}
|
|
{money(doc.total_minor, doc.currency)}
|
|
</p>
|
|
))}
|
|
</details>
|
|
))}
|
|
<Pagination page={props.history} />
|
|
</Panel>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|