@@ -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