@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user