@@ -0,0 +1,310 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { InventoryPagination } from '@/components/inventory';
|
||||
import { date, money } from '@/types/procurement';
|
||||
|
||||
type Filters = { search: string; validity: string; expires_by: string };
|
||||
export type AgreementFollowupRow = {
|
||||
currency?: string | null;
|
||||
max_order_value_minor?: number | null;
|
||||
periodicity_days?: number | null;
|
||||
approved_articles?: number;
|
||||
articles_href?: string;
|
||||
id: number;
|
||||
record_key: string;
|
||||
version: number;
|
||||
reference: string | null;
|
||||
supplier: string | null;
|
||||
item_code: string | null;
|
||||
item: string | null;
|
||||
warehouse: string | null;
|
||||
valid_from: string | null;
|
||||
valid_until: string | null;
|
||||
validity: string;
|
||||
approved_policies: number;
|
||||
href: string;
|
||||
policies_href: string;
|
||||
};
|
||||
type Props = {
|
||||
kind?: 'agreement' | 'contract';
|
||||
asOf: string;
|
||||
filters: Filters;
|
||||
errors?: Record<string, string>;
|
||||
records: {
|
||||
data: AgreementFollowupRow[];
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
all: 'Todas as situações',
|
||||
current: 'Vigentes',
|
||||
expired: 'Expirados',
|
||||
future: 'Por iniciar',
|
||||
unknown: 'Datas indeterminadas',
|
||||
};
|
||||
export default function AgreementFollowup({
|
||||
kind = 'agreement',
|
||||
asOf,
|
||||
filters,
|
||||
records,
|
||||
errors = {},
|
||||
}: Props) {
|
||||
const [draft, setDraft] = useState(filters);
|
||||
const csv = new URLSearchParams({
|
||||
...filters,
|
||||
...(kind === 'contract' ? { kind } : {}),
|
||||
}).toString();
|
||||
const contracts = kind === 'contract';
|
||||
const title = contracts
|
||||
? 'Vigência dos contratos globais'
|
||||
: 'Vigência dos acordos';
|
||||
return (
|
||||
<>
|
||||
<Head title={title} />
|
||||
<div className="mx-auto max-w-7xl space-y-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras · Fornecimento"
|
||||
title={title}
|
||||
description={`Últimas versões aprovadas, consultadas em ${date(asOf)}.`}
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
A vigência não comprova, por si só, elegibilidade do
|
||||
fornecedor ou autorização de compra. Consultar não renova
|
||||
acordos nem altera políticas de reposição.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-4 text-sm">
|
||||
<Link
|
||||
href={`/compras/fornecimento?view=${contracts ? 'contracts' : 'agreements'}`}
|
||||
className="underline"
|
||||
>
|
||||
{contracts
|
||||
? 'Voltar aos contratos'
|
||||
: 'Voltar aos acordos'}
|
||||
</Link>
|
||||
<a
|
||||
href={`/compras/acordos/vigencia.csv?${csv}`}
|
||||
className="underline"
|
||||
>
|
||||
Descarregar todos os resultados em CSV
|
||||
</a>
|
||||
</div>
|
||||
<Panel
|
||||
title={
|
||||
contracts ? 'Encontrar contratos' : 'Encontrar acordos'
|
||||
}
|
||||
>
|
||||
<form
|
||||
className="grid gap-4 md:grid-cols-3"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
router.get('/compras/acordos/vigencia', {
|
||||
...draft,
|
||||
...(contracts ? { kind } : {}),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Referência, fornecedor, artigo ou armazém
|
||||
<Input
|
||||
maxLength={100}
|
||||
value={draft.search}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
search: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Situação de vigência
|
||||
<select
|
||||
className={controlClass}
|
||||
value={draft.validity}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
validity: event.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
{Object.entries(states).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Vigência termina até
|
||||
<Input
|
||||
type="date"
|
||||
value={draft.expires_by}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
expires_by: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<div className="flex items-center gap-4">
|
||||
<Button type="submit">Aplicar filtros</Button>
|
||||
<Link
|
||||
href={
|
||||
contracts
|
||||
? '/compras/acordos/vigencia?kind=contract'
|
||||
: '/compras/acordos/vigencia'
|
||||
}
|
||||
className="text-sm underline"
|
||||
>
|
||||
Limpar filtros
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
<div className="mt-4">
|
||||
<FormErrors errors={errors} />
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted-foreground">
|
||||
Escolha a data-limite conforme a conferência pretendida.
|
||||
O filtro por data não inclui acordos sem data de fim
|
||||
conhecida. O CSV usa os filtros já aplicados.
|
||||
</p>
|
||||
</Panel>
|
||||
<Panel
|
||||
title={`${records.total} ${contracts ? 'contrato(s)' : 'acordo(s)'} encontrado(s)`}
|
||||
>
|
||||
<div className="divide-y">
|
||||
{records.data.map((record) => (
|
||||
<article
|
||||
key={record.record_key}
|
||||
className="space-y-2 py-4 text-sm"
|
||||
>
|
||||
<div className="flex flex-wrap justify-between gap-2">
|
||||
<h2 className="font-semibold">
|
||||
{record.reference ??
|
||||
'Referência não disponível'}{' '}
|
||||
· versão {record.version}
|
||||
</h2>
|
||||
<span>
|
||||
{states[record.validity] ??
|
||||
'Datas indeterminadas'}
|
||||
</span>
|
||||
</div>
|
||||
<p>
|
||||
{record.supplier ??
|
||||
'Fornecedor não disponível'}{' '}
|
||||
{!contracts && (
|
||||
<>
|
||||
{' '}
|
||||
·{' '}
|
||||
{record.item_code ??
|
||||
'Código não disponível'}{' '}
|
||||
·{' '}
|
||||
{record.item ??
|
||||
'Artigo não disponível'}{' '}
|
||||
·{' '}
|
||||
{record.warehouse ??
|
||||
'Armazém não disponível'}
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
{contracts ? (
|
||||
<p>
|
||||
Limite global por ordem:{' '}
|
||||
{record.max_order_value_minor ===
|
||||
null ||
|
||||
record.max_order_value_minor ===
|
||||
undefined
|
||||
? 'Não definido'
|
||||
: record.currency
|
||||
? money(
|
||||
record.max_order_value_minor,
|
||||
record.currency,
|
||||
)
|
||||
: `${record.max_order_value_minor} centavos (moeda indisponível)`}
|
||||
. Cada ordem pode usar o limite
|
||||
completo. Periodicidade prevista:{' '}
|
||||
{record.periodicity_days === null ||
|
||||
record.periodicity_days === undefined
|
||||
? 'Não definida'
|
||||
: `${record.periodicity_days} dias`}
|
||||
. Não gera ordens automáticas.
|
||||
</p>
|
||||
) : null}
|
||||
<p>
|
||||
Início:{' '}
|
||||
{record.valid_from
|
||||
? date(record.valid_from)
|
||||
: 'Não disponível'}{' '}
|
||||
· Fim:{' '}
|
||||
{record.valid_until
|
||||
? date(record.valid_until)
|
||||
: 'Não disponível'}
|
||||
</p>
|
||||
{contracts ? (
|
||||
<p>
|
||||
{record.approved_articles ?? 0}{' '}
|
||||
artigo(s) aprovado(s) ligado(s). A
|
||||
contagem não substitui a conferência da
|
||||
versão, moeda e vigência na emissão.
|
||||
</p>
|
||||
) : (
|
||||
<p>
|
||||
{record.approved_policies} política(s)
|
||||
aprovada(s) ligada(s). Confira a versão
|
||||
adoptada e a vigência antes de
|
||||
interpretar o prazo de reposição.
|
||||
</p>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Link
|
||||
className="underline"
|
||||
href={record.href}
|
||||
>
|
||||
{contracts
|
||||
? 'Conferir contrato'
|
||||
: 'Conferir acordo'}
|
||||
</Link>
|
||||
<Link
|
||||
className="underline"
|
||||
href={
|
||||
contracts
|
||||
? (record.articles_href ??
|
||||
record.href)
|
||||
: record.policies_href
|
||||
}
|
||||
>
|
||||
{contracts
|
||||
? 'Consultar artigos ligados'
|
||||
: 'Consultar políticas ligadas'}
|
||||
</Link>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
{records.data.length === 0 && (
|
||||
<p className="py-5 text-sm text-muted-foreground">
|
||||
{contracts
|
||||
? 'Não existem contratos aprovados que correspondam aos filtros.'
|
||||
: 'Não existem acordos aprovados que correspondam aos filtros.'}
|
||||
</p>
|
||||
)}
|
||||
<InventoryPagination page={records} />
|
||||
</Panel>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user