diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-12-24 08:51:37 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-12-24 08:51:37 +0700 |
| commit | 22bf497d3fd524a95982e090f2c8a1be6bde656b (patch) | |
| tree | 1c394154c78ea81e06b302eeffcb9dfb14497144 /src/lib/transaction | |
| parent | b2afb5c847c9983b098a3223fbcfdb666e65c8cb (diff) | |
| parent | d76f96c44f85e7e0efbd544e6b97bd80920b0039 (diff) | |
Merge branch 'new-release' into Feature/switch-account
# Conflicts:
# src-migrate/modules/register/components/FormBisnis.tsx
# src/lib/auth/components/Menu.jsx
Diffstat (limited to 'src/lib/transaction')
| -rw-r--r-- | src/lib/transaction/api/checkoutPoApi.js | 19 | ||||
| -rw-r--r-- | src/lib/transaction/components/Transaction.jsx | 132 |
2 files changed, 131 insertions, 20 deletions
diff --git a/src/lib/transaction/api/checkoutPoApi.js b/src/lib/transaction/api/checkoutPoApi.js index 04421368..3376e773 100644 --- a/src/lib/transaction/api/checkoutPoApi.js +++ b/src/lib/transaction/api/checkoutPoApi.js @@ -1,13 +1,14 @@ -import odooApi from '@/core/api/odooApi' -import { getAuth } from '@/core/utils/auth' +import odooApi from '@/core/api/odooApi'; +import { getAuth } from '@/core/utils/auth'; -const checkoutPoApi = async ({ id }) => { - const auth = getAuth() +const checkoutPoApi = async ({ id, status }) => { + const auth = getAuth(); const dataCheckout = await odooApi( 'POST', - `/api/v1/partner/${auth?.partnerId}/sale_order/${id}/checkout` - ) - return dataCheckout -} + `/api/v1/partner/${auth?.partnerId}/sale_order/${id}/checkout`, + { status } + ); + return dataCheckout; +}; -export default checkoutPoApi +export default checkoutPoApi; diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index d001c7f4..f5dc507a 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -38,7 +38,9 @@ import aprpoveApi from '../api/approveApi'; import rejectApi from '../api/rejectApi'; import rejectProductApi from '../api/rejectProductApi'; import { useRouter } from 'next/router'; - +import { gtagPurchase } from '@/core/utils/googleTag'; +import { deleteItemCart } from '@/core/utils/cart'; +import axios from 'axios'; const Transaction = ({ id }) => { const router = useRouter(); const [isModalOpen, setIsModalOpen] = useState(false); @@ -46,9 +48,8 @@ const Transaction = ({ id }) => { const [reason, setReason] = useState(''); const auth = useAuth(); const { transaction } = useTransaction({ id }); - const statusApprovalWeb = transaction.data?.approvalStep; - + const [isLoading, setIsLoading] = useState(false); const { queryAirwayBill } = useAirwayBill({ orderId: id }); const [airwayBillPopup, setAirwayBillPopup] = useState(null); @@ -84,8 +85,26 @@ const Transaction = ({ id }) => { }; const [cancelTransaction, setCancelTransaction] = useState(false); + const [continueNoPo, setContinueNoPo] = useState(false); + const [continueTransaction, setContinueTransaction] = useState(false); const openCancelTransaction = () => setCancelTransaction(true); + const openContinueTransaction = () => { + if (auth.partnerTempo) { + checkout(); + } else { + if (!transaction.data?.purchaseOrderFile) { + setContinueTransaction(true); + } else { + checkoutNoPO(); + } + } + }; + // const ContinueTransaction = () => { + // setContinueNoPo(true); + // checkoutNoPO(); + // }; const closeCancelTransaction = () => setCancelTransaction(false); + const closeContinueTransaction = () => setContinueTransaction(false); const [rejectTransaction, setRejectTransaction] = useState(false); @@ -101,15 +120,70 @@ const Transaction = ({ id }) => { } closeCancelTransaction(); }; - const checkout = async () => { if (!transaction.data?.purchaseOrderFile) { toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan'); return; } - await checkoutPoApi({ id }); + await checkoutPoApi({ id, status: true }); + toast.success('Berhasil melanjutkan pesanan'); + transaction.refetch(); + }; + + const checkoutNoPO = async () => { + setIsLoading(true); + gtagPurchase( + transaction.data.products, + transaction.data.deliveryAmount, + transaction.data.name + ); + + gtag('event', 'conversion', { + send_to: 'AW-954540379/nDymCL3BhaQYENvClMcD', + value: + transaction.data?.amountTotal + + Math.round(parseInt(transaction.data.deliveryAmount * 1.1) / 1000) * + 1000, + currency: 'IDR', + transaction_id: transaction.data.id, + }); + + for (const product of transaction.data.products) + deleteItemCart({ productId: product.id }); + if (transaction.data?.amountTotal > 0) { + const payment = await axios.post( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${transaction.data.id}` + ); + setIsLoading(false); + window.location.href = payment.data.redirectUrl; + } else { + window.location.href = `${ + process.env.NEXT_PUBLIC_SELF_HOST + }/shop/checkout/success?order_id=${transaction.data.name.replace( + /\//g, + '-' + )}`; + } toast.success('Berhasil melanjutkan pesanan'); transaction.refetch(); + + /* const midtrans = async () => { + for (const product of products) deleteItemCart({ productId: product.id }); + if (grandTotal > 0) { + const payment = await axios.post( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` + ); + setIsLoading(false); + window.location.href = payment.data.redirectUrl; + } else { + window.location.href = `${ + process.env.NEXT_PUBLIC_SELF_HOST + }/shop/checkout/success?order_id=${isCheckouted.name.replace( + /\//g, + '-' + )}`; + } + };*/ }; const handleApproval = async () => { @@ -208,6 +282,32 @@ const Transaction = ({ id }) => { transaction.data?.name && ( <> <BottomPopup + active={continueTransaction} + close={closeContinueTransaction} + title='Lanjutkan Transaksi' + > + <div className='leading-7 text-gray_r-12/80'> + Apakah anda yakin melanjutkan tanpa upload PO?{' '} + <span className='underline'>{transaction.data?.name}</span>? + </div> + <div className='flex justify-end mt-6 gap-x-4'> + <button + className='btn-solid-red w-full md:w-fit' + type='button' + onClick={checkoutNoPO} + > + Ya, Lanjutkan + </button> + <button + className='btn-light w-full md:w-fit' + type='button' + onClick={closeContinueTransaction} + > + Batal + </button> + </div> + </BottomPopup> + <BottomPopup active={cancelTransaction} close={closeCancelTransaction} title='Batalkan Transaksi' @@ -469,7 +569,10 @@ const Transaction = ({ id }) => { )} {transaction.data?.status == 'draft' && !auth?.feature?.soApproval && ( - <button className='btn-yellow w-full mt-4' onClick={checkout}> + <button + className='btn-yellow w-full mt-4' + onClick={openContinueTransaction} + > Lanjutkan Transaksi </button> )} @@ -563,7 +666,10 @@ const Transaction = ({ id }) => { )} {transaction.data?.status == 'draft' && !auth?.feature.soApproval && ( - <button className='btn-yellow' onClick={checkout}> + <button + className='btn-yellow' + onClick={openContinueTransaction} + > Lanjutkan Transaksi </button> )} @@ -778,10 +884,14 @@ const Transaction = ({ id }) => { ? `| ${product?.attributes.join(', ')}` : ''} </div> - <div className='text-[10px] text-red-500 italic mt-2'> - {product.availableQuantity} barang ini bisa di - pickup maksimal pukul 16.00 - </div> + {product.soQty && product.reservedStockQty && ( + <div className='text-[10px] text-red-500 italic mt-2'> + {product.soQty !== product.reservedStockQty + ? 'Barang sedang disiapkan' + : `${product.reservedStockQty} barang bisa di + kirim/pickup`} + </div> + )} </div> </td> {/* <td> |
