This commit is contained in:
2026-11-03 11:51:44 +02:00
parent badaada043
commit e753f7a0a4
309 changed files with 14537 additions and 529 deletions
+99 -28
View File
@@ -1,5 +1,5 @@
import { InventoryEventActions } from '@/components/inventory-event-actions';
import { Head, useForm } from '@inertiajs/react';
import { Head, Link, useForm } from '@inertiajs/react';
import {
FormErrors,
PageTitle,
@@ -15,6 +15,7 @@ type Metadata = {
quantity_milli: number;
};
type RecordEntry = {
canActivate?: boolean;
id: number;
record_key: string;
version: number;
@@ -41,6 +42,10 @@ type RecordEntry = {
};
};
type Lot = {
canIdentify: boolean;
canRelease: boolean;
canHold: boolean;
quality_released: boolean;
id: number;
record_key: string;
version: number;
@@ -57,6 +62,11 @@ type Lot = {
release_setup_id?: number | null;
};
type Props = {
controlPagination?: PageInfo | null;
historyPagination?: PageInfo | null;
focusLotId?: number | null;
focusRecordId?: number | null;
focusChanged?: boolean;
ready: boolean;
actorId: number;
capabilities: Record<string, boolean>;
@@ -75,6 +85,47 @@ type Props = {
warehouses: { id: number; code: string; name: string }[];
history: RecordEntry[];
};
type PageInfo = {
current_page: number;
last_page: number;
total: number;
prev_page_url: string | null;
next_page_url: string | null;
};
function Pages({ page, label }: { page?: PageInfo | null; label: string }) {
if (!page) return null;
return (
<nav
aria-label={label}
className="my-4 flex flex-wrap items-center justify-between gap-3 text-sm"
>
<span>
{page.total} · Página {page.current_page} de {page.last_page}
</span>
<div className="flex gap-4">
{page.prev_page_url && (
<Link
preserveScroll
className="underline"
href={page.prev_page_url}
>
Anterior
</Link>
)}
{page.next_page_url && (
<Link
preserveScroll
className="underline"
href={page.next_page_url}
>
Seguinte
</Link>
)}
</div>
</nav>
);
}
const qty = (n: number) =>
(n / 1000).toLocaleString('pt-MZ', { maximumFractionDigits: 3 });
const states: Record<string, string> = {
@@ -518,7 +569,22 @@ export default function Lots(props: Props) {
</Panel>
) : (
<>
{props.capabilities.prepare && (
{props.focusRecordId && (
<div className="space-y-2 text-sm">
<Link href="/stock/lotes" className="underline">
Ver todas as configurações
</Link>
{props.focusChanged && (
<p role="status">
A proposta foi actualizada. É
apresentada a versão actual; a
configuração em vigor permanece visível
quando aplicável.
</p>
)}
</div>
)}
{props.capabilities.prepare && !props.focusRecordId && (
<Panel title="Preparar novo controlo">
<Prepare props={props} />
</Panel>
@@ -533,6 +599,7 @@ export default function Lots(props: Props) {
states[record.state] ?? record.state
}
>
<div id={`lot-setup-${record.id}`} />
<p className="mb-3 text-sm text-muted-foreground">
Validade{' '}
{record.data.requires_expiry
@@ -608,15 +675,12 @@ export default function Lots(props: Props) {
/>
</details>
)}
{props.capabilities.review &&
!record.snapshot.contributors.includes(
props.actorId,
) && (
<Decision
record={record}
action="activate"
/>
)}
{record.canActivate && (
<Decision
record={record}
action="activate"
/>
)}
</>
) : (
context && (
@@ -665,6 +729,7 @@ export default function Lots(props: Props) {
)}
{context.lots.map((lot) => (
<article
id={`lot-${record.data.warehouse_id}-${lot.id}`}
key={lot.id}
className="mt-4 rounded-lg border p-4"
>
@@ -713,8 +778,7 @@ export default function Lots(props: Props) {
{lot.last_usable_on &&
` · Último dia utilizável: ${lot.last_usable_on}`}
</p>
{props.capabilities
.prepare && (
{lot.canIdentify && (
<Identify
key={`identify-${lot.version}`}
lot={lot}
@@ -724,15 +788,9 @@ export default function Lots(props: Props) {
lot.quantity_milli >
0 && (
<>
{props
.capabilities
.release &&
lot.eligible &&
{lot.canRelease &&
lot.state !==
'released' &&
!lot.contributors.includes(
props.actorId,
) && (
'released' && (
<Decision
key={`release-${lot.version}-${lot.state_version}`}
record={
@@ -748,11 +806,8 @@ export default function Lots(props: Props) {
action="release"
/>
)}
{props
.capabilities
.hold &&
lot.state ===
'released' && (
{lot.canHold &&
lot.quality_released && (
<Decision
key={`hold-${lot.version}-${lot.state_version}`}
record={
@@ -778,10 +833,22 @@ export default function Lots(props: Props) {
</Panel>
);
})}
<Pages
page={props.controlPagination}
label="Paginação das configurações de lotes"
/>
<Panel title="Histórico de conferências">
<details>
<details
open={
(props.historyPagination?.current_page ??
1) > 1
}
>
<summary className="cursor-pointer text-sm">
Consultar os últimos 200 registos
Consultar histórico (
{props.historyPagination?.total ??
props.history.length}{' '}
registos)
</summary>
<div className="mt-3 space-y-3">
{props.history.map((record) => (
@@ -795,6 +862,10 @@ export default function Lots(props: Props) {
</p>
))}
</div>
<Pages
page={props.historyPagination}
label="Paginação do histórico de lotes"
/>
</details>
</Panel>
</>