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
+93 -21
View File
@@ -1,5 +1,7 @@
import { InventoryEventActions } from '@/components/inventory-event-actions';
import { Head, Link, useForm } from '@inertiajs/react';
import { Head, Link, router, useForm } from '@inertiajs/react';
import { useEffect, useState } from 'react';
import CorrectionSourceSearch from '@/components/correction-source-search';
import {
FormErrors,
PageTitle,
@@ -7,6 +9,12 @@ import {
controlClass,
} from '@/components/procurement';
import { Button } from '@/components/ui/button';
import SupplyPagination, {
type SupplyPageInfo,
} from '@/components/supply-pagination';
import InventoryCorrectionFilters, {
type CorrectionFilters,
} from '@/components/inventory-correction-filters';
type Source = {
item: { code: string; name: string; unit: string };
@@ -19,6 +27,10 @@ type Source = {
} | null;
};
type RecordEntry = {
executionSourceCurrent?: boolean | null;
canApprove?: boolean;
canReturn?: boolean;
canExecute?: boolean;
id: number;
record_key: string;
version: number;
@@ -44,6 +56,12 @@ type RecordEntry = {
};
};
type Props = {
sourceSearch?: string;
sourceFormKey?: string | null;
recordPagination?: SupplyPageInfo | null;
filters: CorrectionFilters;
focusRecordId?: number | null;
focusChanged?: boolean;
canViewReversals: boolean;
correctedOperations?: Record<number, string>;
canViewOperations: boolean;
@@ -83,6 +101,12 @@ const states: Record<string, string> = {
};
function Prepare({ props, old }: { props: Props; old?: RecordEntry }) {
const [receipts, setReceipts] = useState(props.receipts);
const formKey = `disposition:${old?.id ?? 'new'}`;
useEffect(() => {
if (!props.sourceFormKey || props.sourceFormKey === formKey)
setReceipts(props.receipts);
}, [props.sourceFormKey, props.receipts, formKey]);
const form = useForm({
operation_key: crypto.randomUUID(),
record_key: old?.record_key,
@@ -101,6 +125,27 @@ function Prepare({ props, old }: { props: Props; old?: RecordEntry }) {
reference: old?.data.reference ?? '',
},
});
const searchSources = (value: string) =>
router.get(
'/stock/ocorrencias',
{
records_page: props.recordPagination?.current_page,
search: props.filters.search || undefined,
state: props.filters.state || undefined,
...(props.focusRecordId
? { record_id: props.focusRecordId }
: {}),
source_search: value,
source_form_key: formKey,
selected_receipt_id:
form.data.data.receipt_item_id || undefined,
},
{
only: ['receipts', 'sourceSearch', 'sourceFormKey'],
preserveState: true,
preserveScroll: true,
},
);
const change = (update: Partial<typeof form.data.data>) =>
form.setData('data', { ...form.data.data, ...update });
const lots = props.lots.filter(
@@ -119,6 +164,10 @@ function Prepare({ props, old }: { props: Props; old?: RecordEntry }) {
}}
>
<FormErrors errors={form.errors} />
<CorrectionSourceSearch
initial={props.sourceSearch}
search={searchSources}
/>
<label className="grid gap-1 text-sm">
Operação
<select
@@ -148,7 +197,7 @@ function Prepare({ props, old }: { props: Props; old?: RecordEntry }) {
className={controlClass}
value={form.data.data.receipt_item_id}
onChange={(e) => {
const source = props.receipts.find(
const source = receipts.find(
(r) => String(r.id) === e.target.value,
);
change({
@@ -164,7 +213,7 @@ function Prepare({ props, old }: { props: Props; old?: RecordEntry }) {
}}
>
<option value="">Seleccione a recepção aceite</option>
{props.receipts.map((r) => (
{receipts.map((r) => (
<option key={r.id} value={r.id}>
{r.label} · Devolvível da origem:{' '}
{quantity(r.accepted_milli - r.returned_milli)}
@@ -274,23 +323,11 @@ function RecordActions({
record: RecordEntry;
}) {
const choices: { value: string; label: string }[] = [];
if (
props.capabilities.review &&
!record.snapshot.contributors.includes(props.actorId)
) {
if (['draft', 'returned'].includes(record.state))
choices.push({ value: 'approve', label: 'Conferir e aprovar' });
if (['draft', 'returned', 'approved'].includes(record.state))
choices.push({
value: 'return',
label: 'Devolver para actualização',
});
}
if (
props.capabilities.execute &&
record.state === 'approved' &&
record.snapshot.reviewed_by !== props.actorId
)
if (record.canApprove)
choices.push({ value: 'approve', label: 'Conferir e aprovar' });
if (record.canReturn)
choices.push({ value: 'return', label: 'Devolver para actualização' });
if (record.canExecute && record.executionSourceCurrent !== false)
choices.push({ value: 'execute', label: 'Confirmar saída física' });
return (
<InventoryEventActions
@@ -342,11 +379,34 @@ export default function Dispositions(props: Props) {
</Panel>
) : (
<>
{props.capabilities.prepare && (
{props.focusRecordId && (
<div className="space-y-2 text-sm">
<Link
href="/stock/ocorrencias"
className="underline"
>
Ver todas as ocorrências
</Link>
{props.focusChanged && (
<p role="status">
Esta ocorrência foi actualizada. Está a
consultar a versão actual; as anteriores
permanecem no histórico.
</p>
)}
</div>
)}
{props.capabilities.prepare && !props.focusRecordId && (
<Panel title="Preparar saída">
<Prepare props={props} />
</Panel>
)}
{!props.focusRecordId && (
<InventoryCorrectionFilters
path="/stock/ocorrencias"
filters={props.filters}
/>
)}
{props.records.map((record) => (
<Panel
key={record.id}
@@ -360,6 +420,14 @@ export default function Dispositions(props: Props) {
: states[record.state]
}
>
<div id={`disposition-${record.id}`} />
{record.executionSourceCurrent === false && (
<p role="status" className="mb-3 text-sm">
A origem ou o saldo mudou. A execução
aguarda reposição válida ou devolução
pelo conferente para nova preparação.
</p>
)}
<p className="text-sm">
{record.snapshot.source.item.code} ·{' '}
{record.snapshot.source.item.name} ·{' '}
@@ -447,6 +515,10 @@ export default function Dispositions(props: Props) {
</details>
</Panel>
))}
<SupplyPagination
page={props.recordPagination}
label="Paginação das ocorrências de stock"
/>
</>
)}
</div>
+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>
</>
+32 -17
View File
@@ -7,6 +7,8 @@ import {
} from '@/components/procurement';
import { Button } from '@/components/ui/button';
type RecordRow = {
canApprove?: boolean;
canSuspend?: boolean;
id: number;
record_key: string;
version: number;
@@ -72,6 +74,8 @@ function Pagination<T>({
) : null;
}
type Props = {
focusRuleId?: number | null;
focusChanged?: boolean;
ready: boolean;
canPrepare: boolean;
canReview: boolean;
@@ -376,7 +380,19 @@ export default function Replenishment(props: Props) {
</Panel>
) : (
<>
{props.canPrepare && (
{props.focusRuleId != null && (
<Link className="underline" href="/stock/reposicao">
Ver todas as parametrizações e necessidades
</Link>
)}
{props.focusChanged && (
<p className="rounded border p-3 text-sm">
A parametrização mudou desde o encaminhamento.
Confira a versão actual e o histórico antes de
intervir.
</p>
)}
{props.canPrepare && props.focusRuleId == null && (
<Panel title="Parametrizar artigo e armazém">
<RuleForm props={props} />
</Panel>
@@ -458,6 +474,7 @@ export default function Replenishment(props: Props) {
) : (
props.rules?.data.map((r) => (
<div
id={`supply-rule-${r.id}`}
className="mb-4 rounded border p-4"
key={r.id}
>
@@ -477,22 +494,20 @@ export default function Replenishment(props: Props) {
MZN · Imposto {r.data.tax_rate}% ·
Validade {r.data.valid_until}
</p>
{props.canReview &&
r.state === 'draft' && (
<Decision
key={`approve:${r.id}`}
rule={r}
action="approve"
/>
)}
{props.canReview &&
r.state === 'approved' && (
<Decision
key={`suspend:${r.id}`}
rule={r}
action="suspend"
/>
)}
{r.canApprove && (
<Decision
key={`approve:${r.id}`}
rule={r}
action="approve"
/>
)}
{r.canSuspend && (
<Decision
key={`suspend:${r.id}`}
rule={r}
action="suspend"
/>
)}
{props.canPrepare && (
<details className="mt-3">
<summary>
+104 -21
View File
@@ -1,5 +1,7 @@
import { InventoryEventActions } from '@/components/inventory-event-actions';
import { Head, Link, useForm } from '@inertiajs/react';
import { Head, Link, router, useForm } from '@inertiajs/react';
import { useEffect, useState } from 'react';
import CorrectionSourceSearch from '@/components/correction-source-search';
import {
FormErrors,
PageTitle,
@@ -7,6 +9,12 @@ import {
controlClass,
} from '@/components/procurement';
import { Button } from '@/components/ui/button';
import SupplyPagination, {
type SupplyPageInfo,
} from '@/components/supply-pagination';
import InventoryCorrectionFilters, {
type CorrectionFilters,
} from '@/components/inventory-correction-filters';
type Row = {
source_movement_id: number;
@@ -18,6 +26,10 @@ type Row = {
lots: { lot_id: number | null; code: string | null; quantity: number }[];
};
type Entry = {
executionSourceCurrent?: boolean | null;
canApprove?: boolean;
canReturn?: boolean;
canExecute?: boolean;
id: number;
record_key: string;
version: number;
@@ -48,6 +60,12 @@ type Entry = {
};
};
type Props = {
sourceSearch?: string;
sourceFormKey?: string | null;
recordPagination?: SupplyPageInfo | null;
filters: CorrectionFilters;
focusRecordId?: number | null;
focusChanged?: boolean;
ready: boolean;
actorId: number;
today: string;
@@ -68,6 +86,15 @@ const states: Record<string, string> = {
};
function Prepare({ props, old }: { props: Props; old?: Entry }) {
const [operations, setOperations] = useState(props.operations);
const [receipts, setReceipts] = useState(props.receipts);
const formKey = `reversal:${old?.id ?? 'new'}`;
useEffect(() => {
if (!props.sourceFormKey || props.sourceFormKey === formKey) {
setOperations(props.operations);
setReceipts(props.receipts);
}
}, [props.sourceFormKey, props.operations, props.receipts, formKey]);
const form = useForm({
operation_key: crypto.randomUUID(),
record_key: old?.record_key,
@@ -85,6 +112,34 @@ function Prepare({ props, old }: { props: Props; old?: Entry }) {
: '',
},
});
const searchSources = (value: string) =>
router.get(
'/stock/estornos',
{
records_page: props.recordPagination?.current_page,
search: props.filters.search || undefined,
state: props.filters.state || undefined,
...(props.focusRecordId
? { record_id: props.focusRecordId }
: {}),
source_search: value,
source_form_key: formKey,
selected_operation_id:
form.data.data.source_operation_id || undefined,
selected_receipt_id:
form.data.data.receipt_item_id || undefined,
},
{
only: [
'operations',
'receipts',
'sourceSearch',
'sourceFormKey',
],
preserveState: true,
preserveScroll: true,
},
);
return (
<form
className="grid gap-4 md:grid-cols-2"
@@ -94,6 +149,10 @@ function Prepare({ props, old }: { props: Props; old?: Entry }) {
}}
>
<FormErrors errors={form.errors} />
<CorrectionSourceSearch
initial={props.sourceSearch}
search={searchSources}
/>
<label className="grid gap-1 text-sm">
Origem
<select
@@ -131,7 +190,7 @@ function Prepare({ props, old }: { props: Props; old?: Entry }) {
<option value="">
Seleccione a operação a corrigir
</option>
{props.operations.map((op) => (
{operations.map((op) => (
<option key={op.id} value={op.id}>
{op.label}
</option>
@@ -153,7 +212,7 @@ function Prepare({ props, old }: { props: Props; old?: Entry }) {
}
>
<option value="">Seleccione a linha a anular</option>
{props.receipts.map((receipt) => (
{receipts.map((receipt) => (
<option key={receipt.id} value={receipt.id}>
{receipt.label}
</option>
@@ -200,23 +259,11 @@ function Prepare({ props, old }: { props: Props; old?: Entry }) {
}
function RecordActions({ props, record }: { props: Props; record: Entry }) {
const choices: { value: string; label: string }[] = [];
if (
props.capabilities.review &&
!record.snapshot.contributors.includes(props.actorId)
) {
if (['draft', 'returned'].includes(record.state))
choices.push({ value: 'approve', label: 'Conferir e aprovar' });
if (['draft', 'returned', 'approved'].includes(record.state))
choices.push({
value: 'return',
label: 'Devolver para actualização',
});
}
if (
props.capabilities.execute &&
record.state === 'approved' &&
record.snapshot.reviewed_by !== props.actorId
)
if (record.canApprove)
choices.push({ value: 'approve', label: 'Conferir e aprovar' });
if (record.canReturn)
choices.push({ value: 'return', label: 'Devolver para actualização' });
if (record.canExecute && record.executionSourceCurrent !== false)
choices.push({ value: 'execute', label: 'Confirmar estorno integral' });
return (
<InventoryEventActions
@@ -274,17 +321,49 @@ export default function Reversals(props: Props) {
</Panel>
) : (
<>
{props.capabilities.prepare && (
{props.focusRecordId && (
<div className="space-y-2 text-sm">
<Link
href="/stock/estornos"
className="underline"
>
Ver todos os estornos
</Link>
{props.focusChanged && (
<p role="status">
Este estorno foi actualizado. Está a
consultar a versão actual; as anteriores
permanecem no histórico.
</p>
)}
</div>
)}
{props.capabilities.prepare && !props.focusRecordId && (
<Panel title="Preparar correcção">
<Prepare props={props} />
</Panel>
)}
{!props.focusRecordId && (
<InventoryCorrectionFilters
path="/stock/estornos"
filters={props.filters}
/>
)}
{props.records.map((record) => (
<Panel
key={record.id}
title={`${record.data.reference} · ${states[record.state]}`}
description={`Origem: ${record.snapshot.source.document.reference}`}
>
<div id={`reversal-${record.id}`} />
{record.executionSourceCurrent === false && (
<p role="status" className="mb-3 text-sm">
A origem ou o saldo mudou. A execução
aguarda disponibilidade válida ou
devolução pelo conferente para nova
preparação.
</p>
)}
<p className="text-sm">
{record.snapshot.source.item.code} ·{' '}
{record.snapshot.source.item.name}
@@ -402,6 +481,10 @@ export default function Reversals(props: Props) {
</details>
</Panel>
))}
<SupplyPagination
page={props.recordPagination}
label="Paginação dos estornos de stock"
/>
</>
)}
</div>