feat(FE-311): Use latest_approval for purchase approvals

This commit is contained in:
rstubryan
2025-12-08 17:42:23 +07:00
parent 7cc2a31745
commit 68874a1c14
2 changed files with 14 additions and 13 deletions
@@ -156,9 +156,9 @@ const PurchaseOrderDetail = ({
}, [goodsReceiptItems]);
const approvalStep = useMemo(() => {
if (!initialValues?.approval) return null;
return initialValues.approval.step_number;
}, [initialValues?.approval]);
if (!initialValues?.latest_approval) return null;
return initialValues.latest_approval.step_number;
}, [initialValues?.latest_approval]);
const {
approvals,
@@ -166,7 +166,7 @@ const PurchaseOrderDetail = ({
rawDataApprovals,
refresh: refreshApprovals,
} = useApprovalSteps({
latestApproval: initialValues?.approval,
latestApproval: initialValues?.latest_approval,
approvalLines: PURCHASE_ORDER_APPROVAL_LINE,
moduleName: 'PURCHASES',
moduleId: initialValues?.id?.toString() ?? '',
@@ -180,16 +180,16 @@ const PurchaseOrderDetail = ({
approvalStep !== null && approvalStep >= 1 && approvalStep <= 3;
const canDeleteItems = useMemo(() => {
if (!initialValues?.approval) return false;
if (!initialValues?.latest_approval) return false;
const currentStep = initialValues.approval.step_number;
const currentStep = initialValues.latest_approval.step_number;
const hasReachedStep5 = rawDataApprovals?.some(
(approval) => approval.step_number === 5
);
return currentStep === 3 && !hasReachedStep5;
}, [initialValues?.approval, rawDataApprovals]);
}, [initialValues?.latest_approval, rawDataApprovals]);
const handleApprovalClick = () => {
if (!approvalStep) return;
@@ -222,18 +222,18 @@ const PurchaseOrderDetail = ({
};
const canShowPurchaseOrderInvoice = useMemo(() => {
if (!initialValues?.approval) return false;
if (!initialValues?.latest_approval) return false;
const currentStep = initialValues.approval.step_number;
const currentStep = initialValues.latest_approval.step_number;
return currentStep >= 3;
}, [initialValues?.approval]);
}, [initialValues?.latest_approval]);
const canShowPenerimaanBarang = useMemo(() => {
if (!initialValues?.approval) return false;
if (!initialValues?.latest_approval) return false;
const currentStep = initialValues.approval.step_number;
const currentStep = initialValues.latest_approval.step_number;
return currentStep === 5;
}, [initialValues?.approval]);
}, [initialValues?.latest_approval]);
const totalBeforeTax = useMemo(() => {
return purchaseOrderItems.reduce(
+1
View File
@@ -62,6 +62,7 @@ export type BasePurchase = {
warehouse?: Warehouse;
items?: PurchaseItem[];
approval?: BaseApproval;
latest_approval?: BaseApproval;
};
export type Purchase = BaseMetadata & BasePurchase;