@@ -0,0 +1,119 @@
|
||||
import { TableViewport } from '@/components/procurement';
|
||||
import { exactMinorAmount } from '@/components/procurement-payable-insights';
|
||||
|
||||
export type CategoryAttribution = {
|
||||
coverage: { allocated: number; unallocated: number; indeterminate: number };
|
||||
unassigned: {
|
||||
state: string;
|
||||
currency: string;
|
||||
count: number;
|
||||
amount_minor: string;
|
||||
}[];
|
||||
groups: {
|
||||
data: {
|
||||
category: string;
|
||||
currency: string;
|
||||
count: number;
|
||||
amount_minor: string;
|
||||
}[];
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
};
|
||||
};
|
||||
export function ProcurementCategoryInsights({
|
||||
data,
|
||||
pageHref,
|
||||
}: {
|
||||
data: CategoryAttribution;
|
||||
pageHref?: string;
|
||||
}) {
|
||||
const href = (page: number) => {
|
||||
const [path, query] = (pageHref || '/relatorios').split('?');
|
||||
const params = new URLSearchParams(query);
|
||||
params.set('category_page', String(page));
|
||||
return `${path}?${params}`;
|
||||
};
|
||||
return (
|
||||
<section className="mt-5 space-y-3" aria-label="Despesa por categoria">
|
||||
<h3 className="font-semibold">Despesa por categoria</h3>
|
||||
<p className="text-sm">
|
||||
Imputação explícita por Finanças: {data.coverage.allocated}{' '}
|
||||
pagamento(s) imputado(s), {data.coverage.unallocated} por
|
||||
imputar e {data.coverage.indeterminate} com imputação
|
||||
indeterminada. Não há distribuição proporcional automática.
|
||||
</p>
|
||||
{data.unassigned.map((row) => (
|
||||
<p className="text-sm" key={`${row.state}:${row.currency}`}>
|
||||
{row.state === 'unallocated'
|
||||
? 'Despesa não imputada'
|
||||
: 'Imputação indeterminada'}
|
||||
: {exactMinorAmount(row.amount_minor, row.currency)} ·{' '}
|
||||
{row.count} pagamento(s).
|
||||
</p>
|
||||
))}
|
||||
{data.groups.data.length > 0 && (
|
||||
<TableViewport label="Montantes imputados por categoria">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="p-2">Categoria da factura</th>
|
||||
<th className="p-2">Imputações</th>
|
||||
<th className="p-2">
|
||||
Despesa confirmada imputada
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.groups.data.map((row) => (
|
||||
<tr
|
||||
className="border-t"
|
||||
key={`${row.category}:${row.currency}`}
|
||||
>
|
||||
<td className="p-2">{row.category}</td>
|
||||
<td className="p-2">{row.count}</td>
|
||||
<td className="p-2 whitespace-nowrap">
|
||||
{exactMinorAmount(
|
||||
row.amount_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableViewport>
|
||||
)}
|
||||
{data.groups.total > 0 && (
|
||||
<p className="text-sm">
|
||||
{data.groups.total} grupo(s) categoria/moeda · Página{' '}
|
||||
{data.groups.current_page} de {data.groups.last_page}. Um
|
||||
pagamento pode ter imputações em várias categorias.
|
||||
</p>
|
||||
)}
|
||||
{pageHref && (
|
||||
<nav
|
||||
className="flex gap-4 print:hidden"
|
||||
aria-label="Páginas de despesa por categoria"
|
||||
>
|
||||
{data.groups.current_page > 1 && (
|
||||
<a
|
||||
className="underline"
|
||||
href={href(data.groups.current_page - 1)}
|
||||
>
|
||||
Anterior
|
||||
</a>
|
||||
)}
|
||||
{data.groups.current_page < data.groups.last_page && (
|
||||
<a
|
||||
className="underline"
|
||||
href={href(data.groups.current_page + 1)}
|
||||
>
|
||||
Seguinte
|
||||
</a>
|
||||
)}
|
||||
</nav>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Panel, TableViewport } from '@/components/procurement';
|
||||
import { exactMinorAmount } from '@/components/procurement-payable-insights';
|
||||
|
||||
export type ContractInsights = {
|
||||
coverage: Record<string, number>;
|
||||
currencies: {
|
||||
classification: string;
|
||||
currency: string | null;
|
||||
count: number;
|
||||
amount_minor: string | null;
|
||||
}[];
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
contract: 'Todas as linhas com contrato associado',
|
||||
partial: 'Parte das linhas com contrato associado',
|
||||
without_contract: 'Sem contrato associado na emissão',
|
||||
unknown: 'Associação por determinar',
|
||||
};
|
||||
|
||||
export function ProcurementContractInsights({
|
||||
data,
|
||||
exportHref,
|
||||
}: {
|
||||
data: ContractInsights;
|
||||
exportHref?: string;
|
||||
}) {
|
||||
return (
|
||||
<Panel
|
||||
title="Compras e contratos"
|
||||
description="Associações documentais conservadas nas ordens operacionais. Os filtros usam a data de criação dos pedidos; cada ordem consolidada conta uma única vez."
|
||||
>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Os montantes são os totais integrais das ordens, incluindo as
|
||||
parcialmente associadas. Não representam pagamentos nem uma
|
||||
decisão de conformidade contratual.
|
||||
</p>
|
||||
{data.coverage.unknown > 0 && (
|
||||
<p className="mt-3 text-sm" role="status">
|
||||
{data.coverage.unknown} ordem(ns) sem informação suficiente
|
||||
sobre a associação na emissão; não foram classificadas como
|
||||
compras fora de contrato.
|
||||
</p>
|
||||
)}
|
||||
{data.currencies.length === 0 ? (
|
||||
<p className="mt-3">Sem ordens operacionais neste âmbito.</p>
|
||||
) : (
|
||||
<TableViewport label="Associações contratuais das ordens">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="p-2">Associação na emissão</th>
|
||||
<th className="p-2">Ordens</th>
|
||||
<th className="p-2">Montante das ordens</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.currencies.map((row) => (
|
||||
<tr
|
||||
className="border-t"
|
||||
key={`${row.classification}:${row.currency}`}
|
||||
>
|
||||
<td className="p-2">
|
||||
{labels[row.classification] ||
|
||||
'Por determinar'}
|
||||
</td>
|
||||
<td className="p-2">{row.count}</td>
|
||||
<td className="p-2 whitespace-nowrap">
|
||||
{row.currency === null ||
|
||||
row.amount_minor === null
|
||||
? 'Indeterminado'
|
||||
: exactMinorAmount(
|
||||
row.amount_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableViewport>
|
||||
)}
|
||||
{exportHref && (
|
||||
<a className="mt-3 inline-block underline" href={exportHref}>
|
||||
Exportar associações contratuais CSV
|
||||
</a>
|
||||
)}
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { Panel } from '@/components/procurement';
|
||||
|
||||
export type DeliveryInsights = {
|
||||
view: string;
|
||||
coverage: Record<string, number>;
|
||||
pending_lines: number;
|
||||
unknown_lines: number;
|
||||
records: {
|
||||
data: {
|
||||
id: number;
|
||||
number: string;
|
||||
state: string;
|
||||
pending_lines: number;
|
||||
unknown_lines: number;
|
||||
late_days: number | null;
|
||||
quality_pending: boolean;
|
||||
href: string;
|
||||
late_lines: {
|
||||
id: number;
|
||||
description: string;
|
||||
unit: string;
|
||||
promised_on: string;
|
||||
completed_on: string | null;
|
||||
pending_quantity: string;
|
||||
}[];
|
||||
}[];
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
};
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
pending_late: 'Por receber depois da data acordada',
|
||||
pending: 'Por receber, dentro da data acordada',
|
||||
partial_late: 'Recepção parcial tardia; restante em prazo',
|
||||
completed_late: 'Recepção integral depois da data acordada',
|
||||
completed_on_time: 'Recepção integral no prazo acordado',
|
||||
unknown: 'Datas ou quantidades por determinar',
|
||||
};
|
||||
|
||||
export function ProcurementDeliveryInsights({
|
||||
data,
|
||||
pageHref,
|
||||
exportHref,
|
||||
}: {
|
||||
data: DeliveryInsights;
|
||||
pageHref: string;
|
||||
exportHref: string;
|
||||
}) {
|
||||
const href = (view: string, page = 1) => {
|
||||
const [path, query] = pageHref.split('?');
|
||||
const params = new URLSearchParams(query);
|
||||
params.set('delivery_state', view);
|
||||
params.set('delivery_page', String(page));
|
||||
return `${path}?${params}`;
|
||||
};
|
||||
return (
|
||||
<Panel
|
||||
title="Entregas face às datas acordadas"
|
||||
description="Datas conservadas na emissão, incluindo a data própria de cada origem de uma ordem consolidada. Recepções estornadas ficam excluídas; qualidade e aceitação mantêm o seu percurso próprio."
|
||||
>
|
||||
<dl className="grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-3">
|
||||
{Object.entries(labels).map(([key, label]) => (
|
||||
<div key={key}>
|
||||
<dt>{label}</dt>
|
||||
<dd className="font-semibold">
|
||||
{data.coverage[key] ?? 0}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<nav
|
||||
className="my-4 flex flex-wrap gap-4 text-sm print:hidden"
|
||||
aria-label="Filtrar acompanhamento de entregas"
|
||||
>
|
||||
<a className="underline" href={href('attention')}>
|
||||
Atrasos e dados por conferir
|
||||
</a>
|
||||
<a className="underline" href={href('all')}>
|
||||
Todas as ordens operacionais
|
||||
</a>
|
||||
<a className="underline" href={href('pending_late')}>
|
||||
Por receber em atraso
|
||||
</a>
|
||||
<a className="underline" href={href('completed_late')}>
|
||||
Recepções integrais tardias
|
||||
</a>
|
||||
</nav>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{data.pending_lines} linha(s) ainda por receber;{' '}
|
||||
{data.unknown_lines} linha(s) com datas ou quantidades por
|
||||
determinar. Não são presumidas datas a partir da necessidade do
|
||||
requisitante.
|
||||
</p>
|
||||
{data.records.data.length === 0 && (
|
||||
<p className="mt-3">Sem ordens nesta selecção.</p>
|
||||
)}
|
||||
{data.records.data.map((row) => (
|
||||
<article
|
||||
className="space-y-2 border-b py-4 text-sm"
|
||||
key={row.id}
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
<a className="underline" href={row.href}>
|
||||
{row.number}
|
||||
</a>{' '}
|
||||
· {labels[row.state] || 'Por determinar'}
|
||||
</h3>
|
||||
<p>
|
||||
Maior atraso documentado:{' '}
|
||||
{row.late_days === null
|
||||
? 'por determinar'
|
||||
: `${row.late_days} dia(s)`}
|
||||
.{' '}
|
||||
{row.unknown_lines > 0 &&
|
||||
`${row.unknown_lines} linha(s) por conferir.`}
|
||||
</p>
|
||||
{row.quality_pending && (
|
||||
<p>
|
||||
A recepção física está completa; a qualidade ou
|
||||
aceitação permanece pendente.
|
||||
</p>
|
||||
)}
|
||||
<ul>
|
||||
{row.late_lines.map((line) => (
|
||||
<li key={line.id} className="mb-2 break-words">
|
||||
{line.description} · Data acordada:{' '}
|
||||
{line.promised_on} · Recepção integral:{' '}
|
||||
{line.completed_on || 'por completar'} · Por
|
||||
receber: {line.pending_quantity} {line.unit}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</article>
|
||||
))}
|
||||
<p className="mt-3 text-sm">
|
||||
{data.records.total} ordem(ns) nesta selecção · Página{' '}
|
||||
{data.records.current_page} de {data.records.last_page}
|
||||
</p>
|
||||
<nav
|
||||
className="mt-3 flex gap-4 print:hidden"
|
||||
aria-label="Páginas de acompanhamento de entregas"
|
||||
>
|
||||
{data.records.current_page > 1 && (
|
||||
<a
|
||||
className="underline"
|
||||
href={href(data.view, data.records.current_page - 1)}
|
||||
>
|
||||
Anterior
|
||||
</a>
|
||||
)}
|
||||
{data.records.current_page < data.records.last_page && (
|
||||
<a
|
||||
className="underline"
|
||||
href={href(data.view, data.records.current_page + 1)}
|
||||
>
|
||||
Seguinte
|
||||
</a>
|
||||
)}
|
||||
</nav>
|
||||
<a className="mt-3 inline-block underline" href={exportHref}>
|
||||
Exportar acompanhamento de entregas CSV
|
||||
</a>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
@@ -43,6 +43,11 @@ export function ProcurementPayableInsights({
|
||||
período dos filtros refere-se à criação do pedido; os saldos
|
||||
são os actuais, na data de geração do relatório.
|
||||
</p>
|
||||
<p>
|
||||
Cada factura é considerada uma única vez se alguma origem da
|
||||
ordem corresponder aos filtros. A posição apresentada é
|
||||
integral, sem repartição pelos pedidos seleccionados.
|
||||
</p>
|
||||
<p>
|
||||
{data.coverage.recognised} de {data.coverage.invoices}{' '}
|
||||
facturas com posição reconhecida e determinada. Por
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { Panel } from '@/components/procurement';
|
||||
import { Panel, TableViewport } from '@/components/procurement';
|
||||
import {
|
||||
ProcurementCategoryInsights,
|
||||
type CategoryAttribution,
|
||||
} from '@/components/procurement-category-insights';
|
||||
import { exactMinorAmount } from '@/components/procurement-payable-insights';
|
||||
|
||||
export type PaymentInsights = {
|
||||
category_attribution?: CategoryAttribution;
|
||||
from: string | null;
|
||||
to: string | null;
|
||||
coverage: {
|
||||
@@ -9,15 +15,35 @@ export type PaymentInsights = {
|
||||
confirmed_payments: number;
|
||||
};
|
||||
currencies: { currency: string; count: number; amount_minor: string }[];
|
||||
suppliers?: {
|
||||
data: {
|
||||
supplier_id: number;
|
||||
supplier_name: string;
|
||||
currency: string;
|
||||
count: number;
|
||||
amount_minor: string;
|
||||
}[];
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
};
|
||||
};
|
||||
|
||||
export function ProcurementPaymentInsights({
|
||||
data,
|
||||
exportHref,
|
||||
pageHref,
|
||||
}: {
|
||||
data: PaymentInsights;
|
||||
exportHref?: string;
|
||||
pageHref?: string;
|
||||
}) {
|
||||
const supplierHref = (page: number) => {
|
||||
const [path, query] = (pageHref || '/relatorios').split('?');
|
||||
const params = new URLSearchParams(query);
|
||||
params.set('supplier_page', String(page));
|
||||
return `${path}?${params}`;
|
||||
};
|
||||
return (
|
||||
<Panel
|
||||
title="Despesa por período"
|
||||
@@ -28,6 +54,11 @@ export function ProcurementPaymentInsights({
|
||||
{data.to ?? 'Até à data actual'}.{' '}
|
||||
{data.coverage.confirmed_payments} pagamentos confirmados.
|
||||
</p>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Cada factura é considerada uma única vez, mesmo quando a ordem
|
||||
reúne vários pedidos. Os pagamentos são integrais, sem
|
||||
repartição pelos pedidos seleccionados.
|
||||
</p>
|
||||
{data.coverage.indeterminate > 0 && (
|
||||
<p role="status">
|
||||
{data.coverage.indeterminate} facturas com histórico
|
||||
@@ -49,6 +80,89 @@ export function ProcurementPaymentInsights({
|
||||
Nenhum pagamento confirmado determinado neste período.
|
||||
</p>
|
||||
)}
|
||||
{data.suppliers && data.suppliers.total > 0 && (
|
||||
<section
|
||||
className="mt-5 space-y-3"
|
||||
aria-label="Despesa por fornecedor"
|
||||
>
|
||||
<h3 className="font-semibold">Despesa por fornecedor</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Identificação pelo fornecedor da factura; designação
|
||||
conservada no documento. Moedas apresentadas
|
||||
separadamente.
|
||||
</p>
|
||||
<TableViewport>
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="p-2">Fornecedor</th>
|
||||
<th className="p-2">Pagamentos</th>
|
||||
<th className="p-2">Despesa confirmada</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.suppliers.data.map((row) => (
|
||||
<tr
|
||||
key={`${row.supplier_id}:${row.currency}`}
|
||||
className="border-t"
|
||||
>
|
||||
<td className="p-2">
|
||||
{row.supplier_name} · #
|
||||
{row.supplier_id}
|
||||
</td>
|
||||
<td className="p-2">{row.count}</td>
|
||||
<td className="p-2 whitespace-nowrap">
|
||||
{exactMinorAmount(
|
||||
row.amount_minor,
|
||||
row.currency,
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableViewport>
|
||||
<p className="text-sm">
|
||||
{data.suppliers.total} grupo(s) fornecedor/moeda ·
|
||||
Página {data.suppliers.current_page} de{' '}
|
||||
{data.suppliers.last_page}
|
||||
</p>
|
||||
{pageHref && (
|
||||
<nav
|
||||
className="flex gap-4 print:hidden"
|
||||
aria-label="Páginas de despesa por fornecedor"
|
||||
>
|
||||
{data.suppliers.current_page > 1 && (
|
||||
<a
|
||||
className="underline"
|
||||
href={supplierHref(
|
||||
data.suppliers.current_page - 1,
|
||||
)}
|
||||
>
|
||||
Anterior
|
||||
</a>
|
||||
)}
|
||||
{data.suppliers.current_page <
|
||||
data.suppliers.last_page && (
|
||||
<a
|
||||
className="underline"
|
||||
href={supplierHref(
|
||||
data.suppliers.current_page + 1,
|
||||
)}
|
||||
>
|
||||
Seguinte
|
||||
</a>
|
||||
)}
|
||||
</nav>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
{data.category_attribution && (
|
||||
<ProcurementCategoryInsights
|
||||
data={data.category_attribution}
|
||||
pageHref={pageHref}
|
||||
/>
|
||||
)}
|
||||
{exportHref && (
|
||||
<a href={exportHref} className="mt-3 inline-block underline">
|
||||
Exportar despesa CSV
|
||||
|
||||
Reference in New Issue
Block a user