@@ -1,5 +1,15 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import {
|
||||
Head,
|
||||
Link,
|
||||
router,
|
||||
useForm,
|
||||
usePage,
|
||||
useRemember,
|
||||
} from '@inertiajs/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
import {
|
||||
ReceiptConversionFields,
|
||||
type ReceiptConversion,
|
||||
@@ -120,13 +130,43 @@ const quantity = (milli: number) =>
|
||||
(milli / 1000).toLocaleString('pt-MZ', { maximumFractionDigits: 3 });
|
||||
|
||||
function Prepare({ props, old }: { props: Props; old?: RecordVersion }) {
|
||||
const [conversion, setConversion] = useState<ReceiptConversion>(
|
||||
old?.snapshot.quantity_conversion ?? {
|
||||
numerator: '',
|
||||
denominator: '',
|
||||
source: '',
|
||||
version: '',
|
||||
},
|
||||
const identity = `${useCoordinationIdentity(props, old)}:prepare`;
|
||||
return (
|
||||
<PrepareForm
|
||||
key={identity}
|
||||
props={props}
|
||||
old={old}
|
||||
identity={identity}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function useCoordinationIdentity(props: Props, record?: RecordVersion) {
|
||||
const page = usePage().props;
|
||||
const actor = page.auth?.user;
|
||||
const context = page.workContext as WorkContextState | null | undefined;
|
||||
return `supply-coordination:${actor?.tenant_id}:${actor?.id}:${props.kind}:${props.ready}:${props.canPrepare}:${props.canReview}:${props.conversionQaEnabled ?? false}:${record?.record_key ?? 'new'}:${record?.version ?? 0}:${record?.state ?? 'new'}:${record ? (props.pending[record.record_key] ?? '') : ''}${context?.active ? `:context:${context.active}` : ''}`;
|
||||
}
|
||||
|
||||
function PrepareForm({
|
||||
props,
|
||||
old,
|
||||
identity,
|
||||
}: {
|
||||
props: Props;
|
||||
old?: RecordVersion;
|
||||
identity: string;
|
||||
}) {
|
||||
const initialConversion: ReceiptConversion = old?.snapshot
|
||||
.quantity_conversion ?? {
|
||||
numerator: '',
|
||||
denominator: '',
|
||||
source: '',
|
||||
version: '',
|
||||
};
|
||||
const [conversion, setConversion] = useRemember<ReceiptConversion>(
|
||||
initialConversion,
|
||||
`${identity}:conversion`,
|
||||
);
|
||||
const [orderLines, setOrderLines] = useState(props.orderLines);
|
||||
const [requestLines, setRequestLines] = useState(props.requestLines);
|
||||
@@ -173,14 +213,20 @@ function Prepare({ props, old }: { props: Props; old?: RecordVersion }) {
|
||||
if (old.data.quantity_milli !== undefined)
|
||||
defaults.quantity = Number(old.data.quantity_milli) / 1000;
|
||||
}
|
||||
const form = useForm({
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: old?.record_key,
|
||||
version: old?.version ?? 0,
|
||||
action: 'save',
|
||||
reason: '',
|
||||
data: defaults,
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(
|
||||
{ ...initial, conversion: initialConversion },
|
||||
{ ...form.data, conversion },
|
||||
);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
const documentUnit =
|
||||
orderLines.find(
|
||||
(line) => line.id === Number(form.data.data.purchase_order_item_id),
|
||||
@@ -270,6 +316,8 @@ function Prepare({ props, old }: { props: Props; old?: RecordVersion }) {
|
||||
);
|
||||
return (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -291,8 +339,21 @@ function Prepare({ props, old }: { props: Props; old?: RecordVersion }) {
|
||||
});
|
||||
form.post(`/compras/fornecimento/${props.kind}`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () =>
|
||||
form.setData('operation_key', crypto.randomUUID()),
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
setConversion(initialConversion);
|
||||
router.remember(clean, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
router.remember(
|
||||
initialConversion,
|
||||
`${identity}:conversion`,
|
||||
);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -542,14 +603,33 @@ function Prepare({ props, old }: { props: Props; old?: RecordVersion }) {
|
||||
}
|
||||
|
||||
function Actions({ props, record }: { props: Props; record: RecordVersion }) {
|
||||
const [action, setAction] = useState('');
|
||||
const identity = `${useCoordinationIdentity(props, record)}:action:${record.canApprove}:${record.canReturn}:${record.canSuspend}:${record.canEdit}:${record.canFulfil}:${record.canCancel}`;
|
||||
return (
|
||||
<ActionsForm
|
||||
key={identity}
|
||||
props={props}
|
||||
record={record}
|
||||
identity={identity}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ActionsForm({
|
||||
props,
|
||||
record,
|
||||
identity,
|
||||
}: {
|
||||
props: Props;
|
||||
record: RecordVersion;
|
||||
identity: string;
|
||||
}) {
|
||||
const [issueSearch, setIssueSearch] = useState(props.issueSearch ?? '');
|
||||
const [operationOptions, setOperationOptions] = useState(props.operations);
|
||||
useEffect(() => {
|
||||
if (props.issueRecordId === record.id)
|
||||
setOperationOptions(props.operations);
|
||||
}, [props.issueRecordId, props.operations, record.id]);
|
||||
const form = useForm({
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: record.record_key,
|
||||
version: record.version,
|
||||
@@ -557,7 +637,11 @@ function Actions({ props, record }: { props: Props; record: RecordVersion }) {
|
||||
reason: '',
|
||||
data: { stock_operation_id: '', quantity_milli: 0 },
|
||||
quantity: '',
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const action = form.data.action;
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty, Boolean(action));
|
||||
const choices =
|
||||
props.kind === 'alternative'
|
||||
? [
|
||||
@@ -620,7 +704,6 @@ function Actions({ props, record }: { props: Props; record: RecordVersion }) {
|
||||
className={controlClass}
|
||||
value={action}
|
||||
onChange={(e) => {
|
||||
setAction(e.target.value);
|
||||
form.setData('action', e.target.value);
|
||||
}}
|
||||
>
|
||||
@@ -635,6 +718,8 @@ function Actions({ props, record }: { props: Props; record: RecordVersion }) {
|
||||
)}
|
||||
{action && (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -649,6 +734,16 @@ function Actions({ props, record }: { props: Props; record: RecordVersion }) {
|
||||
}));
|
||||
form.post(`/compras/fornecimento/${props.kind}`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(clean, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, router, useForm, usePage } from '@inertiajs/react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
@@ -107,7 +110,34 @@ const qty = (milli: number | string, mean = false) =>
|
||||
});
|
||||
|
||||
function Prepare({ props, old }: { props: Props; old?: HistoryRecord }) {
|
||||
const form = useForm({
|
||||
const identity = `${useHistoryIdentity(props, old)}:prepare`;
|
||||
return (
|
||||
<PrepareForm
|
||||
key={identity}
|
||||
props={props}
|
||||
old={old}
|
||||
identity={identity}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function useHistoryIdentity(props: Props, record?: HistoryRecord) {
|
||||
const page = usePage().props;
|
||||
const actor = page.auth?.user;
|
||||
const context = page.workContext as WorkContextState | null | undefined;
|
||||
return `supply-history:${actor?.tenant_id}:${props.actorId ?? actor?.id}:${props.ready}:${props.canPrepare}:${props.canReview}:${record?.record_key ?? 'new'}:${record?.version ?? 0}:${record?.state ?? 'new'}${context?.active ? `:context:${context.active}` : ''}`;
|
||||
}
|
||||
|
||||
function PrepareForm({
|
||||
props,
|
||||
old,
|
||||
identity,
|
||||
}: {
|
||||
props: Props;
|
||||
old?: HistoryRecord;
|
||||
identity: string;
|
||||
}) {
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: old?.record_key,
|
||||
version: old?.version ?? 0,
|
||||
@@ -122,7 +152,10 @@ function Prepare({ props, old }: { props: Props; old?: HistoryRecord }) {
|
||||
quality: old?.data.quality ?? 'unknown',
|
||||
pattern: old?.data.pattern ?? 'unknown',
|
||||
},
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
const select = (
|
||||
key: keyof typeof form.data.data,
|
||||
label: string,
|
||||
@@ -153,11 +186,23 @@ function Prepare({ props, old }: { props: Props; old?: HistoryRecord }) {
|
||||
);
|
||||
return (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/compras/fornecimento/history', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(clean, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -393,21 +438,32 @@ function Facts({
|
||||
);
|
||||
}
|
||||
|
||||
function Decision({
|
||||
function Decision(input: { props: Props; record: HistoryRecord }) {
|
||||
const r = input.record;
|
||||
const identity = `${useHistoryIdentity(input.props, r)}:decision:${r.canApprove}:${r.canReturn}:${r.canSuspend}`;
|
||||
return <DecisionForm key={identity} {...input} identity={identity} />;
|
||||
}
|
||||
|
||||
function DecisionForm({
|
||||
props,
|
||||
record: r,
|
||||
identity,
|
||||
}: {
|
||||
props: Props;
|
||||
record: HistoryRecord;
|
||||
identity: string;
|
||||
}) {
|
||||
const form = useForm({
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: r.record_key,
|
||||
version: r.version,
|
||||
action: '',
|
||||
reason: '',
|
||||
data: { confirm_scope: false },
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty, Boolean(form.data.action));
|
||||
return (
|
||||
<div className="mt-4 space-y-4">
|
||||
{props.canPrepare && ['draft', 'returned'].includes(r.state) && (
|
||||
@@ -449,11 +505,29 @@ function Decision({
|
||||
</label>
|
||||
{form.data.action && (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/compras/fornecimento/history', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(
|
||||
clean,
|
||||
`${identity}:data`,
|
||||
);
|
||||
router.remember(
|
||||
{},
|
||||
`${identity}:errors`,
|
||||
);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, router, useForm, usePage } from '@inertiajs/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
@@ -244,14 +247,34 @@ function PreservedData({ record }: { record: SupplyRecord }) {
|
||||
);
|
||||
}
|
||||
|
||||
function Preparation({
|
||||
function useSupplyIdentity(props: Props, record?: SupplyRecord) {
|
||||
const page = usePage().props;
|
||||
const actor = page.auth?.user;
|
||||
const context = page.workContext as WorkContextState | null | undefined;
|
||||
return `supply:${actor?.tenant_id}:${actor?.id}:${props.kind}:${props.view}:${props.linkedContractKey ?? ''}:${props.linkedAgreementKey ?? ''}:${props.ready}:${props.canPrepare}:${props.canReview}:${props.canCustoms}:${props.orderLimitsReady ?? false}:${record?.record_key ?? 'new'}:${record?.version ?? 0}:${record?.state ?? 'new'}${context?.active ? `:context:${context.active}` : ''}`;
|
||||
}
|
||||
|
||||
function Preparation(input: {
|
||||
props: Props;
|
||||
record?: SupplyRecord;
|
||||
copy?: boolean;
|
||||
}) {
|
||||
const historyKey = `${useSupplyIdentity(input.props, input.record)}:${input.copy ? 'copy' : 'prepare'}`;
|
||||
return (
|
||||
<PreparationForm key={historyKey} {...input} historyKey={historyKey} />
|
||||
);
|
||||
}
|
||||
|
||||
function PreparationForm({
|
||||
props,
|
||||
record,
|
||||
copy = false,
|
||||
historyKey,
|
||||
}: {
|
||||
props: Props;
|
||||
record?: SupplyRecord;
|
||||
copy?: boolean;
|
||||
historyKey: string;
|
||||
}) {
|
||||
const defaults: Data =
|
||||
props.kind === 'policy'
|
||||
@@ -350,14 +373,17 @@ function Preparation({
|
||||
}
|
||||
}
|
||||
}
|
||||
const form = useForm({
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: copy ? undefined : record?.record_key,
|
||||
version: copy ? 0 : (record?.version ?? 0),
|
||||
action: 'save',
|
||||
reason: '',
|
||||
data: defaults,
|
||||
});
|
||||
};
|
||||
const form = useForm(historyKey, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
const [orderSearch, setOrderSearch] = useState(props.orderSearch ?? '');
|
||||
const [historyOptions, setHistoryOptions] = useState(props.histories);
|
||||
const [periodFrom, setPeriodFrom] = useState('');
|
||||
@@ -517,6 +543,8 @@ function Preparation({
|
||||
);
|
||||
return (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -557,8 +585,16 @@ function Preparation({
|
||||
});
|
||||
form.post(`/compras/fornecimento/${props.kind}`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () =>
|
||||
form.setData('operation_key', crypto.randomUUID()),
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(clean, `${historyKey}:data`);
|
||||
router.remember({}, `${historyKey}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -1119,22 +1155,38 @@ function Preparation({
|
||||
);
|
||||
}
|
||||
|
||||
function RecordActions({
|
||||
function RecordActions(input: { record: SupplyRecord; props: Props }) {
|
||||
const historyKey = `${useSupplyIdentity(input.props, input.record)}:action:${input.record.canApprove}:${input.record.canReturn}:${input.record.canSuspend}`;
|
||||
return (
|
||||
<RecordActionsForm
|
||||
key={historyKey}
|
||||
{...input}
|
||||
historyKey={historyKey}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function RecordActionsForm({
|
||||
record,
|
||||
props,
|
||||
historyKey,
|
||||
}: {
|
||||
record: SupplyRecord;
|
||||
props: Props;
|
||||
historyKey: string;
|
||||
}) {
|
||||
const [action, setAction] = useState('');
|
||||
const form = useForm({
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: record.record_key,
|
||||
version: record.version,
|
||||
action: '',
|
||||
reason: '',
|
||||
data: { evidence: '', event_date: '' },
|
||||
});
|
||||
};
|
||||
const form = useForm(historyKey, initial);
|
||||
const action = form.data.action;
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty, Boolean(action));
|
||||
const imports = props.kind === 'import';
|
||||
const choices: [string, string][] = imports
|
||||
? [
|
||||
@@ -1198,7 +1250,6 @@ function RecordActions({
|
||||
className={controlClass}
|
||||
value={action}
|
||||
onChange={(e) => {
|
||||
setAction(e.target.value);
|
||||
form.setData('action', e.target.value);
|
||||
}}
|
||||
>
|
||||
@@ -1214,11 +1265,23 @@ function RecordActions({
|
||||
)}
|
||||
{action && (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post(`/compras/fornecimento/${props.kind}`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(clean, `${historyKey}:data`);
|
||||
router.remember({}, `${historyKey}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, router, useForm, usePage } from '@inertiajs/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
@@ -110,7 +113,33 @@ const quantity = (value: number) =>
|
||||
(value / 1000).toLocaleString('pt-MZ', { maximumFractionDigits: 3 });
|
||||
|
||||
function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
const [selected, setSelected] = useState(old?.data.policy_key ?? '');
|
||||
const identity = `${useSuggestionIdentity(props, old)}:prepare`;
|
||||
return (
|
||||
<PrepareForm
|
||||
key={identity}
|
||||
props={props}
|
||||
old={old}
|
||||
identity={identity}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function useSuggestionIdentity(props: Props, record?: Suggestion) {
|
||||
const page = usePage().props;
|
||||
const actor = page.auth?.user;
|
||||
const context = page.workContext as WorkContextState | null | undefined;
|
||||
return `supply-suggestion:${actor?.tenant_id}:${props.actorId ?? actor?.id}:${props.ready}:${props.canPrepare}:${props.canReview}:${props.canConvert}:${record?.record_key ?? 'new'}:${record?.version ?? 0}:${record?.state ?? 'new'}${context?.active ? `:context:${context.active}` : ''}`;
|
||||
}
|
||||
|
||||
function PrepareForm({
|
||||
props,
|
||||
old,
|
||||
identity,
|
||||
}: {
|
||||
props: Props;
|
||||
old?: Suggestion;
|
||||
identity: string;
|
||||
}) {
|
||||
const [policies, setPolicies] = useState(props.policies);
|
||||
const [policySearch, setPolicySearch] = useState(props.policySearch ?? '');
|
||||
const formKey = `suggestion:${old?.id ?? 'new'}`;
|
||||
@@ -118,8 +147,8 @@ function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
if (!props.policyFormKey || props.policyFormKey === formKey)
|
||||
setPolicies(props.policies);
|
||||
}, [props.policyFormKey, props.policies, formKey]);
|
||||
const option = policies.find((p) => p.key === selected);
|
||||
const form = useForm({
|
||||
const originalOption = policies.find((p) => p.key === old?.data.policy_key);
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: old?.record_key,
|
||||
version: old?.version ?? 0,
|
||||
@@ -127,14 +156,20 @@ function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
reason: '',
|
||||
data: {
|
||||
policy_key: old?.data.policy_key ?? '',
|
||||
unit_price: option?.unit_price ?? old?.data.unit_price ?? '',
|
||||
tax_rate: option?.tax_rate ?? old?.data.tax_rate ?? '',
|
||||
unit_price:
|
||||
originalOption?.unit_price ?? old?.data.unit_price ?? '',
|
||||
tax_rate: originalOption?.tax_rate ?? old?.data.tax_rate ?? '',
|
||||
quantity: old?.data.manual_plan
|
||||
? String(old.data.quantity_milli / 1000)
|
||||
: '',
|
||||
delivery_on: old?.data.manual_plan ? old.data.delivery_on : '',
|
||||
},
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const selected = form.data.data.policy_key;
|
||||
const option = policies.find((p) => p.key === selected);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
const searchPolicies = () =>
|
||||
router.get(
|
||||
'/compras/fornecimento',
|
||||
@@ -156,6 +191,8 @@ function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
);
|
||||
return (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -176,6 +213,16 @@ function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
}));
|
||||
form.post('/compras/fornecimento/suggestion', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(clean, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -227,7 +274,6 @@ function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
const p = policies.find(
|
||||
(o) => o.key === e.target.value,
|
||||
);
|
||||
setSelected(e.target.value);
|
||||
form.setData('data', {
|
||||
policy_key: e.target.value,
|
||||
unit_price: p?.unit_price ?? '',
|
||||
@@ -249,6 +295,11 @@ function Prepare({ props, old }: { props: Props; old?: Suggestion }) {
|
||||
indisponível
|
||||
</option>
|
||||
)}
|
||||
{!old && selected && !option && (
|
||||
<option value={selected}>
|
||||
Política seleccionada — procurar para conferir
|
||||
</option>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
{option?.issue && (
|
||||
@@ -522,14 +573,37 @@ function Facts({
|
||||
}
|
||||
|
||||
function Decisions({ props, record: r }: { props: Props; record: Suggestion }) {
|
||||
const form = useForm({
|
||||
const identity = `${useSuggestionIdentity(props, r)}:decision:${r.canApprove}:${r.canReturn}:${r.canConvert}:${r.canCancel}:${r.canClose}:${props.excess[r.record_key] ?? false}`;
|
||||
return (
|
||||
<DecisionsForm
|
||||
key={identity}
|
||||
props={props}
|
||||
record={r}
|
||||
identity={identity}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DecisionsForm({
|
||||
props,
|
||||
record: r,
|
||||
identity,
|
||||
}: {
|
||||
props: Props;
|
||||
record: Suggestion;
|
||||
identity: string;
|
||||
}) {
|
||||
const initial = {
|
||||
operation_key: crypto.randomUUID(),
|
||||
record_key: r.record_key,
|
||||
version: r.version,
|
||||
action: '',
|
||||
reason: '',
|
||||
data: { cost_center_id: '', confirm_exception: false },
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty, Boolean(form.data.action));
|
||||
const choices: [string, string][] = [];
|
||||
if (r.canApprove && !props.excess[r.record_key])
|
||||
choices.push(['approve', 'Aprovar para requisitar']);
|
||||
@@ -574,11 +648,23 @@ function Decisions({ props, record: r }: { props: Props; record: Suggestion }) {
|
||||
)}
|
||||
{form.data.action && (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/compras/fornecimento/suggestion', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const clean = {
|
||||
...initial,
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(clean);
|
||||
form.clearErrors();
|
||||
router.remember(clean, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user