commit21
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user