162 lines
6.7 KiB
TypeScript
162 lines
6.7 KiB
TypeScript
import { Head, Link, useForm } from '@inertiajs/react';
|
|
import {
|
|
FormErrors,
|
|
PageTitle,
|
|
Panel,
|
|
controlClass,
|
|
} from '@/components/procurement';
|
|
import { Button } from '@/components/ui/button';
|
|
import { SavedProcurementSearches } from '@/components/saved-procurement-searches';
|
|
import type { SavedSearches } from '@/components/saved-procurement-searches';
|
|
|
|
type Group = {
|
|
key: string;
|
|
title: string;
|
|
records: {
|
|
total: number;
|
|
current_page: number;
|
|
last_page: number;
|
|
prev_page_url: string | null;
|
|
next_page_url: string | null;
|
|
data: { id: number; title: string; detail: string; href: string }[];
|
|
};
|
|
};
|
|
const statuses: Record<string, string> = {
|
|
draft: 'Rascunho',
|
|
pending: 'Pendente',
|
|
approved: 'Aprovada',
|
|
rejected: 'Rejeitada',
|
|
cancelled: 'Cancelada',
|
|
issued: 'Emitida',
|
|
active: 'Activo',
|
|
inactive: 'Inactivo',
|
|
confirmed: 'Confirmada',
|
|
};
|
|
export default function ProcurementSearch({
|
|
term,
|
|
groups,
|
|
invoiceSearchAvailable = false,
|
|
savedSearches = null,
|
|
}: {
|
|
term: string;
|
|
groups: Group[];
|
|
invoiceSearchAvailable?: boolean;
|
|
savedSearches?: SavedSearches | null;
|
|
}) {
|
|
const form = useForm({ q: term });
|
|
return (
|
|
<>
|
|
<Head title="Pesquisar processos" />
|
|
<div className="mx-auto grid w-full max-w-7xl min-w-0 gap-6 p-5 lg:p-8">
|
|
<PageTitle
|
|
eyebrow="Compras"
|
|
title="Pesquisar processos"
|
|
description="Procure processos e cadastros de Compras a partir de um único local, dentro do seu acesso actual."
|
|
/>
|
|
<Panel
|
|
title="Pesquisa transversal de Compras"
|
|
description={`Pesquise requisições, ordens, fornecedores, recepções, equipamentos, artigos e armazéns por referência, necessidade, nome, código ou NUIT.${invoiceSearchAvailable ? ' Pode também procurar facturas de fornecedor pelo número, dentro do seu acesso financeiro.' : ''} A pesquisa não inclui Pessoas, conteúdo de anexos ou arquivos externos.`}
|
|
>
|
|
<form
|
|
className="flex flex-wrap items-end gap-3"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.get('/compras/pesquisa', {
|
|
preserveState: true,
|
|
});
|
|
}}
|
|
>
|
|
<label
|
|
className="grid min-w-0 flex-1 gap-2"
|
|
htmlFor="procurement-search"
|
|
>
|
|
Texto a procurar
|
|
<input
|
|
className={controlClass}
|
|
id="procurement-search"
|
|
type="search"
|
|
minLength={2}
|
|
maxLength={100}
|
|
value={form.data.q}
|
|
onChange={(e) =>
|
|
form.setData('q', e.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<Button disabled={form.processing}>Pesquisar</Button>
|
|
</form>
|
|
<FormErrors errors={form.errors} />
|
|
{invoiceSearchAvailable && (
|
|
<p className="mt-3 text-sm text-muted-foreground">
|
|
Os resultados de facturas mostram a referência e o
|
|
estado. Abra a factura para consultar os valores e
|
|
documentos autorizados.
|
|
</p>
|
|
)}
|
|
</Panel>
|
|
{savedSearches && (
|
|
<SavedProcurementSearches
|
|
key={term}
|
|
saved={savedSearches}
|
|
term={term}
|
|
/>
|
|
)}
|
|
{term.trim().length < 2 && (
|
|
<p role="status">
|
|
Introduza pelo menos dois caracteres para pesquisar.
|
|
</p>
|
|
)}
|
|
{groups.map((group) => (
|
|
<Panel
|
|
key={group.key}
|
|
title={`${group.title} (${group.records.total})`}
|
|
>
|
|
{group.records.data.length === 0 ? (
|
|
<p>Nenhum resultado no seu âmbito de acesso.</p>
|
|
) : (
|
|
<ul className="divide-y">
|
|
{group.records.data.map((record) => (
|
|
<li
|
|
key={record.id}
|
|
className="flex min-w-0 flex-wrap justify-between gap-3 py-3"
|
|
>
|
|
<Link
|
|
className="min-w-0 font-medium break-words underline"
|
|
href={record.href}
|
|
>
|
|
{record.title}
|
|
</Link>
|
|
<span>
|
|
{statuses[record.detail] ??
|
|
record.detail}
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
<nav
|
|
aria-label={`Páginas de ${group.title}`}
|
|
className="mt-4 flex flex-wrap items-center gap-4"
|
|
>
|
|
<span>
|
|
Página {group.records.current_page} de{' '}
|
|
{group.records.last_page}
|
|
</span>
|
|
{group.records.prev_page_url && (
|
|
<Link href={group.records.prev_page_url}>
|
|
Anterior
|
|
</Link>
|
|
)}
|
|
{group.records.next_page_url && (
|
|
<Link href={group.records.next_page_url}>
|
|
Seguinte
|
|
</Link>
|
|
)}
|
|
</nav>
|
|
</Panel>
|
|
))}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|