287 lines
12 KiB
TypeScript
287 lines
12 KiB
TypeScript
import type { GeographyDescription } from '@/components/administrative-location';
|
|
import { Head, Link } from '@inertiajs/react';
|
|
import { PageTitle, Panel } from '@/components/procurement';
|
|
import { quantity, warehouseStateLabels } from '@/types/inventory';
|
|
import { statusLabels } from '@/types/procurement';
|
|
|
|
type Page<T> = {
|
|
data: T[];
|
|
total: number;
|
|
current_page: number;
|
|
last_page: number;
|
|
prev_page_url: string | null;
|
|
next_page_url: string | null;
|
|
};
|
|
type Purchase = {
|
|
id: number;
|
|
number: string;
|
|
status: string;
|
|
needed_by: string;
|
|
items: {
|
|
id: number;
|
|
description: string;
|
|
quantity: string;
|
|
unit: string;
|
|
}[];
|
|
};
|
|
type Movement = {
|
|
id: number;
|
|
kind: string;
|
|
reference: string;
|
|
recorded_at: string;
|
|
quantity_milli: number;
|
|
item: { code: string; name: string; unit: string } | null;
|
|
warehouse: { code: string; name: string } | null;
|
|
};
|
|
|
|
function Pages({ page, label }: { page: Page<unknown>; label: string }) {
|
|
return (
|
|
<nav aria-label={label} className="mt-4 flex gap-4 text-sm">
|
|
<span>
|
|
Página {page.current_page} de {page.last_page}
|
|
</span>
|
|
{page.prev_page_url && (
|
|
<Link href={page.prev_page_url} preserveScroll>
|
|
Anterior
|
|
</Link>
|
|
)}
|
|
{page.next_page_url && (
|
|
<Link href={page.next_page_url} preserveScroll>
|
|
Seguinte
|
|
</Link>
|
|
)}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
export default function EquipmentShow({
|
|
equipment,
|
|
geography = null,
|
|
purchases,
|
|
movements,
|
|
warehouseRequests = null,
|
|
}: {
|
|
geography?: GeographyDescription;
|
|
equipment: {
|
|
id: number;
|
|
code: string;
|
|
description: string;
|
|
area: string;
|
|
status: string;
|
|
};
|
|
purchases: Page<Purchase>;
|
|
movements: Page<Movement>;
|
|
warehouseRequests?: Page<{
|
|
id: number;
|
|
state: string;
|
|
version: number;
|
|
reservation_ready: boolean;
|
|
lines: {
|
|
line: number;
|
|
item: { code: string; name: string; unit: string };
|
|
destination: string;
|
|
requested_milli: number;
|
|
reserved_milli: number;
|
|
delivered_milli: number;
|
|
remaining_milli: number;
|
|
cancelled_milli: number;
|
|
}[];
|
|
}> | null;
|
|
}) {
|
|
return (
|
|
<>
|
|
<Head title={equipment.code} />
|
|
<div className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-5 lg:p-8">
|
|
<PageTitle
|
|
eyebrow="Equipamentos"
|
|
title={`${equipment.code} · ${equipment.description}`}
|
|
description={equipment.area}
|
|
/>
|
|
<Link className="text-sm underline" href="/equipamentos">
|
|
Voltar a Equipamentos e peças
|
|
</Link>
|
|
{geography && (
|
|
<Panel title="Localização actual">
|
|
<p>
|
|
{geography.path
|
|
.map((node) => node.name)
|
|
.join(' / ')}
|
|
</p>
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
|
Referência actual do cadastro. Os documentos e
|
|
movimentos anteriores conservam os seus dados de
|
|
origem.
|
|
</p>
|
|
</Panel>
|
|
)}
|
|
<Panel
|
|
title={`Requisições de compra associadas · ${purchases.total}`}
|
|
>
|
|
<p className="mb-4 text-sm">
|
|
Estas quantidades representam pedidos de compra. Não
|
|
comprovam recepção, entrega ao equipamento ou consumo.
|
|
Cada processo conserva as suas aprovações.
|
|
</p>
|
|
{purchases.data.map((purchase) => (
|
|
<article
|
|
key={purchase.id}
|
|
className="mb-3 rounded border p-3 text-sm"
|
|
>
|
|
<Link
|
|
className="font-medium underline"
|
|
href={`/requisicoes/${purchase.id}/processo`}
|
|
>
|
|
{purchase.number}
|
|
</Link>
|
|
<p>
|
|
Estado do processo:{' '}
|
|
{statusLabels[purchase.status] ??
|
|
purchase.status}{' '}
|
|
· Necessário até {purchase.needed_by}
|
|
</p>
|
|
{purchase.items.map((item) => (
|
|
<p key={item.id}>
|
|
{item.description} · Pedido: {item.quantity}{' '}
|
|
{item.unit}
|
|
</p>
|
|
))}
|
|
</article>
|
|
))}
|
|
{!purchases.data.length && (
|
|
<p>Sem requisições associadas que possa consultar.</p>
|
|
)}
|
|
<Pages
|
|
page={purchases}
|
|
label="Páginas de compras do equipamento"
|
|
/>
|
|
</Panel>
|
|
<Panel
|
|
title={`Requisições internas ao armazém${warehouseRequests ? ' · ' + warehouseRequests.total : ''}`}
|
|
>
|
|
<p className="mb-4 text-sm">
|
|
Pedidos e reservas para este equipamento, conforme os
|
|
seus acessos ao armazém. As entregas acumuladas não
|
|
descontam devoluções ou correcções posteriores.
|
|
</p>
|
|
{warehouseRequests === null ? (
|
|
<p>
|
|
Consulta indisponível para o seu acesso ou nesta
|
|
instalação.
|
|
</p>
|
|
) : (
|
|
<>
|
|
{warehouseRequests.data.map((record) => (
|
|
<article
|
|
key={record.id}
|
|
className="mb-3 rounded border p-3 text-sm"
|
|
>
|
|
<Link
|
|
className="font-medium underline"
|
|
href={`/stock/requisicoes/${record.id}`}
|
|
>
|
|
RA-{record.id}
|
|
</Link>
|
|
<p>
|
|
{warehouseStateLabels[record.state] ??
|
|
record.state}{' '}
|
|
· Versão {record.version}
|
|
</p>
|
|
{record.lines.map((line) => (
|
|
<div key={line.line} className="mt-3">
|
|
<p>
|
|
{line.item.code} ·{' '}
|
|
{line.item.name} ·{' '}
|
|
{line.destination}
|
|
</p>
|
|
<p>
|
|
Pedida:{' '}
|
|
{quantity(line.requested_milli)}{' '}
|
|
{line.item.unit} · Reservada
|
|
agora:{' '}
|
|
{record.reservation_ready
|
|
? quantity(
|
|
line.reserved_milli,
|
|
)
|
|
: 'Indisponível'}{' '}
|
|
· Entregue acumulada:{' '}
|
|
{quantity(line.delivered_milli)}{' '}
|
|
· Por entregar:{' '}
|
|
{quantity(line.remaining_milli)}{' '}
|
|
· Cancelada:{' '}
|
|
{quantity(line.cancelled_milli)}
|
|
</p>
|
|
</div>
|
|
))}
|
|
</article>
|
|
))}
|
|
{!warehouseRequests.data.length && (
|
|
<p>
|
|
Sem requisições internas visíveis para este
|
|
equipamento.
|
|
</p>
|
|
)}
|
|
<Pages
|
|
page={warehouseRequests}
|
|
label="Páginas de requisições internas do equipamento"
|
|
/>
|
|
</>
|
|
)}
|
|
</Panel>
|
|
<Panel
|
|
title={`Movimentos físicos associados · ${movements.total}`}
|
|
>
|
|
<p className="mb-4 text-sm">
|
|
Documentos originais ligados ao equipamento, pela ordem
|
|
de registo. Um estorno tem documento próprio; estas
|
|
quantidades não são um saldo nem comprovam consumo
|
|
técnico.
|
|
</p>
|
|
{movements.data.map((movement) => (
|
|
<article
|
|
key={movement.id}
|
|
className="mb-3 rounded border p-3 text-sm"
|
|
>
|
|
<p className="font-medium">
|
|
{movement.reference} ·{' '}
|
|
{movement.kind === 'issue'
|
|
? 'Saída'
|
|
: movement.kind === 'reversal'
|
|
? 'Estorno'
|
|
: movement.kind}
|
|
</p>
|
|
<p>
|
|
{movement.recorded_at} ·{' '}
|
|
{movement.warehouse?.code}{' '}
|
|
{movement.warehouse?.name}
|
|
</p>
|
|
<p>
|
|
{movement.item?.code} · {movement.item?.name} ·
|
|
Quantidade do documento:{' '}
|
|
{quantity(movement.quantity_milli)}{' '}
|
|
{movement.item?.unit}
|
|
</p>
|
|
</article>
|
|
))}
|
|
{!movements.data.length && (
|
|
<p>
|
|
Sem movimentos físicos registados para este
|
|
equipamento.
|
|
</p>
|
|
)}
|
|
<Pages
|
|
page={movements}
|
|
label="Páginas de movimentos do equipamento"
|
|
/>
|
|
</Panel>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
EquipmentShow.layout = {
|
|
breadcrumbs: [
|
|
{ title: 'Equipamentos', href: '/equipamentos' },
|
|
{ title: 'Acompanhamento', href: '#' },
|
|
],
|
|
};
|