From a5db88b5e8574edb1908fd2a9b9fa6cf5ed2ff05 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 6 Mar 2024 14:30:27 +0700 Subject: add approve dan reject --- src/lib/transaction/api/approveApi.js | 13 ++++ src/lib/transaction/api/rejectApi.js | 13 ++++ src/lib/transaction/components/Transaction.jsx | 83 ++++++++++++++++++++------ src/lib/transaction/components/stepper.jsx | 26 +++++--- 4 files changed, 109 insertions(+), 26 deletions(-) create mode 100644 src/lib/transaction/api/approveApi.js create mode 100644 src/lib/transaction/api/rejectApi.js (limited to 'src/lib') diff --git a/src/lib/transaction/api/approveApi.js b/src/lib/transaction/api/approveApi.js new file mode 100644 index 00000000..891f0235 --- /dev/null +++ b/src/lib/transaction/api/approveApi.js @@ -0,0 +1,13 @@ +import odooApi from '@/core/api/odooApi' +import { getAuth } from '@/core/utils/auth' + +const aprpoveApi = async ({ id }) => { + const auth = getAuth() + const dataCheckout = await odooApi( + 'POST', + `/api/v1/partner/${auth?.partnerId}/sale_order/${id}/approve` + ) + return dataCheckout +} + +export default aprpoveApi diff --git a/src/lib/transaction/api/rejectApi.js b/src/lib/transaction/api/rejectApi.js new file mode 100644 index 00000000..127c0d38 --- /dev/null +++ b/src/lib/transaction/api/rejectApi.js @@ -0,0 +1,13 @@ +import odooApi from '@/core/api/odooApi' +import { getAuth } from '@/core/utils/auth' + +const rejectApi = async ({ id }) => { + const auth = getAuth() + const dataCheckout = await odooApi( + 'POST', + `/api/v1/partner/${auth?.partnerId}/sale_order/${id}/reject` + ) + return dataCheckout +} + +export default rejectApi diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index ab76c671..8f4b2038 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -31,13 +31,16 @@ import useAirwayBill from '../hooks/useAirwayBill'; import Manifest from '@/lib/treckingAwb/component/Manifest'; import useAuth from '@/core/hooks/useAuth'; import StepApproval from './stepper'; +import aprpoveApi from '../api/approveApi'; +import rejectApi from '../api/rejectApi'; const Transaction = ({ id }) => { - const auth = { ...useAuth(), web_role: 2, feature: { so_approval: true } }; - const statusApprovalWeb = 1 + const auth = useAuth(); const { transaction } = useTransaction({ id }); - const { queryAirwayBill } = useAirwayBill({ orderId: id }); + + const statusApprovalWeb = transaction.data?.approvalStep + const { queryAirwayBill } = useAirwayBill({ orderId: id }); const [airwayBillPopup, setAirwayBillPopup] = useState(null); const poNumber = useRef(null); @@ -73,6 +76,11 @@ const Transaction = ({ id }) => { const [cancelTransaction, setCancelTransaction] = useState(false); const openCancelTransaction = () => setCancelTransaction(true); const closeCancelTransaction = () => setCancelTransaction(false); + + const [rejectTransaction, setRejectTransaction] = useState(false); + + const openRejectTransaction = () => setRejectTransaction(true); + const closeRejectTransaction = () => setRejectTransaction(false); const submitCancelTransaction = async () => { const isCancelled = await cancelTransactionApi({ transaction: transaction.data, @@ -94,6 +102,18 @@ const Transaction = ({ id }) => { transaction.refetch(); }; + const handleApproval = async () => { + await aprpoveApi({ id }); + toast.success('Berhasil melanjutkan approval'); + transaction.refetch(); + } + + const handleReject = async () => { + await rejectApi({ id }); + closeRejectTransaction() + transaction.refetch(); + } + const memoizeVariantGroupCard = useMemo( () => (
@@ -161,6 +181,33 @@ const Transaction = ({ id }) => {
+ +
+ Apakah anda yakin Membatalkan transaksi{' '} + {transaction.data?.name}? +
+
+ + +
+
+
@@ -246,7 +293,7 @@ const Transaction = ({ id }) => { - {!auth.feature.so_approval && ( + {!auth?.feature.soApproval && (
{transaction.data?.purchaseOrderName || '-'} @@ -312,13 +359,13 @@ const Transaction = ({ id }) => {
- {transaction.data?.status == 'draft' && auth.feature.so_approval && ( + {transaction.data?.status == 'draft' && auth?.feature.soApproval && (
)} - {transaction.data?.status == 'draft' && !auth.feature.so_approval && ( + {transaction.data?.status == 'draft' && !auth?.feature?.soApproval && ( @@ -368,10 +415,10 @@ const Transaction = ({ id }) => {

Detail Transaksi

- {auth.feature.so_approval && ( + {auth?.feature?.soApproval && ( )} @@ -392,22 +439,22 @@ const Transaction = ({ id }) => { Download {transaction.data?.status == 'draft' && - auth.feature.so_approval && auth.web_role && ( + auth?.feature?.soApproval && auth?.webRole && (
)} {transaction.data?.status == 'draft' && - !auth.feature.so_approval && ( + !auth?.feature.soApproval && ( )} - {transaction.data?.status != 'draft' && ( + {transaction.data?.status != 'draft' && !auth?.feature.soApproval && (