commit de armazens
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-04 09:40:26 +02:00
parent e753f7a0a4
commit 63d20b10fc
245 changed files with 10847 additions and 230 deletions
+63
View File
@@ -1,3 +1,9 @@
import { AdministrativeLocation } from '@/components/administrative-location';
import type {
GeographyDescription,
GeographyReference,
} from '@/components/administrative-location';
import { TerritorialFilter } from '@/components/territorial-filter';
import { Head, useForm, Link } from '@inertiajs/react';
import { useState } from 'react';
import { InventoryNotice, InventoryPagination } from '@/components/inventory';
@@ -20,6 +26,7 @@ type Level = {
is_critical: boolean;
};
type Asset = {
geography_reference?: GeographyReference | null;
id: number;
code: string;
description: string;
@@ -57,6 +64,9 @@ type History = {
};
};
type Props = {
geographyEnabled?: boolean;
equipmentGeography?: Record<number, GeographyDescription>;
geographyFilter?: GeographyDescription;
equipment: Asset[];
parts: Part[];
levels: Level[];
@@ -98,6 +108,9 @@ export default function EquipmentPage({
canManage,
canConfigure,
demo = false,
geographyEnabled = false,
equipmentGeography = {},
geographyFilter = null,
}: Props) {
const [message, setMessage] = useState('');
const category = useForm({
@@ -107,6 +120,7 @@ export default function EquipmentPage({
is_critical: '',
});
const asset = useForm({
geography_reference: null as GeographyReference | null,
id: '',
version: '',
code: '',
@@ -143,6 +157,14 @@ export default function EquipmentPage({
description="Cadastro, peças compatíveis, mínimos explícitos e rastreabilidade das saídas."
/>
<InventoryNotice />
{geographyEnabled && !demo && (
<Panel title="Localização dos equipamentos">
<TerritorialFilter
target="/equipamentos"
initial={geographyFilter}
/>
</Panel>
)}
{demo && (
<p className="rounded-lg border bg-teal-50 p-4 text-sm text-teal-900">
Dados fictícios para revisão sem login. Formulários
@@ -179,6 +201,12 @@ export default function EquipmentPage({
<strong>
{e.code} · {e.description}
</strong>
<Link
className="mt-2 block underline"
href={`/equipamentos/${e.id}`}
>
Acompanhar compras e movimentos
</Link>
<p className="mt-2">
{e.area} ·{' '}
{
@@ -193,6 +221,14 @@ export default function EquipmentPage({
Criticidade:{' '}
{criticality(e.criticality_level_id)?.name}
</p>
{equipmentGeography[e.id]?.path.length ? (
<p className="text-muted-foreground">
Localização actual:{' '}
{equipmentGeography[e.id]?.path
.map((node) => node.name)
.join(' / ')}
</p>
) : null}
{e.stock_item_id && (
<p>
Artigo: {stock(e.stock_item_id)?.code}
@@ -220,6 +256,9 @@ export default function EquipmentPage({
variant="outline"
onClick={() =>
asset.setData({
geography_reference:
e.geography_reference ??
null,
id: String(e.id),
version: String(e.version),
code: e.code,
@@ -332,12 +371,36 @@ export default function EquipmentPage({
simulate();
return;
}
asset.transform((data) => {
const { geography_reference, ...rest } =
data;
return geographyEnabled
? { ...rest, geography_reference }
: rest;
});
asset.post('/equipamentos/activos', {
onSuccess: () => asset.reset(),
});
}}
>
<FormErrors errors={asset.errors} />
{geographyEnabled && !demo && (
<AdministrativeLocation
key={asset.data.id || 'new'}
value={asset.data.geography_reference}
initial={
equipmentGeography[
Number(asset.data.id)
] ?? null
}
onChange={(value) =>
asset.setData(
'geography_reference',
value,
)
}
/>
)}
{(
[
'code',
+286
View File
@@ -0,0 +1,286 @@
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: '#' },
],
};