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 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>
|
||||
|
||||
Reference in New Issue
Block a user