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]); }, [goodsReceiptItems]);
const approvalStep = useMemo(() => { const approvalStep = useMemo(() => {
if (!initialValues?.approval) return null; if (!initialValues?.latest_approval) return null;
return initialValues.approval.step_number; return initialValues.latest_approval.step_number;
}, [initialValues?.approval]); }, [initialValues?.latest_approval]);
const { const {
approvals, approvals,
@@ -166,7 +166,7 @@ const PurchaseOrderDetail = ({
rawDataApprovals, rawDataApprovals,
refresh: refreshApprovals, refresh: refreshApprovals,
} = useApprovalSteps({ } = useApprovalSteps({
latestApproval: initialValues?.approval, latestApproval: initialValues?.latest_approval,
approvalLines: PURCHASE_ORDER_APPROVAL_LINE, approvalLines: PURCHASE_ORDER_APPROVAL_LINE,
moduleName: 'PURCHASES', moduleName: 'PURCHASES',
moduleId: initialValues?.id?.toString() ?? '', moduleId: initialValues?.id?.toString() ?? '',
@@ -180,16 +180,16 @@ const PurchaseOrderDetail = ({
approvalStep !== null && approvalStep >= 1 && approvalStep <= 3; approvalStep !== null && approvalStep >= 1 && approvalStep <= 3;
const canDeleteItems = useMemo(() => { 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( const hasReachedStep5 = rawDataApprovals?.some(
(approval) => approval.step_number === 5 (approval) => approval.step_number === 5
); );
return currentStep === 3 && !hasReachedStep5; return currentStep === 3 && !hasReachedStep5;
}, [initialValues?.approval, rawDataApprovals]); }, [initialValues?.latest_approval, rawDataApprovals]);
const handleApprovalClick = () => { const handleApprovalClick = () => {
if (!approvalStep) return; if (!approvalStep) return;
@@ -222,18 +222,18 @@ const PurchaseOrderDetail = ({
}; };
const canShowPurchaseOrderInvoice = useMemo(() => { 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; return currentStep >= 3;
}, [initialValues?.approval]); }, [initialValues?.latest_approval]);
const canShowPenerimaanBarang = useMemo(() => { 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; return currentStep === 5;
}, [initialValues?.approval]); }, [initialValues?.latest_approval]);
const totalBeforeTax = useMemo(() => { const totalBeforeTax = useMemo(() => {
return purchaseOrderItems.reduce( return purchaseOrderItems.reduce(
+1
View File
@@ -62,6 +62,7 @@ export type BasePurchase = {
warehouse?: Warehouse; warehouse?: Warehouse;
items?: PurchaseItem[]; items?: PurchaseItem[];
approval?: BaseApproval; approval?: BaseApproval;
latest_approval?: BaseApproval;
}; };
export type Purchase = BaseMetadata & BasePurchase; export type Purchase = BaseMetadata & BasePurchase;