From 2bfa2138be7135dc12daa98262fbaf8305698f00 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 7 Nov 2024 13:55:10 +0700
Subject: <iman> add logic quotation no po

---
 src/lib/transaction/components/Transaction.jsx | 116 +++++++++++++++++++++++--
 1 file changed, 110 insertions(+), 6 deletions(-)

(limited to 'src/lib/transaction/components/Transaction.jsx')

diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx
index 4d401037..777dd771 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);
@@ -48,7 +50,7 @@ const Transaction = ({ id }) => {
   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 +86,22 @@ 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 (!transaction.data?.purchaseOrderFile) {
+      setContinueTransaction(true);
+    } else {
+      checkout();
+    }
+  };
+  const ContinueTransaction = () => {
+    setContinueNoPo(true);
+    checkoutNoPO();
+  };
   const closeCancelTransaction = () => setCancelTransaction(false);
+  const closeContinueTransaction = () => setContinueTransaction(false);
 
   const [rejectTransaction, setRejectTransaction] = useState(false);
 
@@ -101,7 +117,6 @@ const Transaction = ({ id }) => {
     }
     closeCancelTransaction();
   };
-
   const checkout = async () => {
     if (!transaction.data?.purchaseOrderFile) {
       toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan');
@@ -112,6 +127,63 @@ const Transaction = ({ id }) => {
     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,
+        '-'
+      )}`;
+    }
+
+    /* 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,
+            '-'
+          )}`;
+        }
+      };*/
+    toast.success('Berhasil melanjutkan pesanan');
+    transaction.refetch();
+    y;
+  };
+
   const handleApproval = async () => {
     await aprpoveApi({ id });
     toast.success('Berhasil melanjutkan approval');
@@ -207,6 +279,32 @@ const Transaction = ({ id }) => {
   return (
     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}
@@ -469,7 +567,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 +664,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>
                   )}
@@ -879,7 +983,7 @@ const Transaction = ({ id }) => {
                     </div>
                   </div>
                 </div>
-              )} 
+              )}
 
               {transaction?.data?.productsRejectLine.length > 0 && (
                 <div className='text-h-sm font-semibold mt-10 mb-4'>
-- 
cgit v1.2.3


From 2d99c50da37c2e68ed33a4bc20e9b2ff06578bbe Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 7 Nov 2024 15:55:15 +0700
Subject: <iman> update code

---
 src/lib/transaction/components/Transaction.jsx | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

(limited to 'src/lib/transaction/components/Transaction.jsx')

diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx
index 777dd771..f64945f5 100644
--- a/src/lib/transaction/components/Transaction.jsx
+++ b/src/lib/transaction/components/Transaction.jsx
@@ -117,11 +117,12 @@ const Transaction = ({ id }) => {
     }
     closeCancelTransaction();
   };
+  console.log('transaction', transaction);
   const checkout = async () => {
-    if (!transaction.data?.purchaseOrderFile) {
-      toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan');
-      return;
-    }
+    // if (!transaction.data?.purchaseOrderFile) {
+    //   toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan');
+    //   return;
+    // }
     await checkoutPoApi({ id });
     toast.success('Berhasil melanjutkan pesanan');
     transaction.refetch();
@@ -161,6 +162,8 @@ const Transaction = ({ id }) => {
         '-'
       )}`;
     }
+    toast.success('Berhasil melanjutkan pesanan');
+    transaction.refetch();
 
     /* const midtrans = async () => {
         for (const product of products) deleteItemCart({ productId: product.id });
@@ -179,9 +182,6 @@ const Transaction = ({ id }) => {
           )}`;
         }
       };*/
-    toast.success('Berhasil melanjutkan pesanan');
-    transaction.refetch();
-    y;
   };
 
   const handleApproval = async () => {
-- 
cgit v1.2.3


From f80551e64e7b4fa1463ecd47d744f7f2846abfda Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 7 Nov 2024 16:49:38 +0700
Subject: <iman> update quotation

---
 src/lib/transaction/components/Transaction.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/lib/transaction/components/Transaction.jsx')

diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx
index f64945f5..d9edb670 100644
--- a/src/lib/transaction/components/Transaction.jsx
+++ b/src/lib/transaction/components/Transaction.jsx
@@ -123,7 +123,7 @@ const Transaction = ({ id }) => {
     //   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();
   };
-- 
cgit v1.2.3


From 88198c83806b69ce6ab7815cee5c139536849c9f Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 8 Nov 2024 13:55:44 +0700
Subject: <iman> update quotation website

---
 src/lib/transaction/components/Transaction.jsx | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

(limited to 'src/lib/transaction/components/Transaction.jsx')

diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx
index d9edb670..6277e3e0 100644
--- a/src/lib/transaction/components/Transaction.jsx
+++ b/src/lib/transaction/components/Transaction.jsx
@@ -90,16 +90,20 @@ const Transaction = ({ id }) => {
   const [continueTransaction, setContinueTransaction] = useState(false);
   const openCancelTransaction = () => setCancelTransaction(true);
   const openContinueTransaction = () => {
-    if (!transaction.data?.purchaseOrderFile) {
-      setContinueTransaction(true);
-    } else {
+    if (auth.partnerTempo) {
       checkout();
+    } else {
+      if (!transaction.data?.purchaseOrderFile) {
+        setContinueTransaction(true);
+      } else {
+        checkoutNoPO();
+      }
     }
   };
-  const ContinueTransaction = () => {
-    setContinueNoPo(true);
-    checkoutNoPO();
-  };
+  // const ContinueTransaction = () => {
+  //   setContinueNoPo(true);
+  //   checkoutNoPO();
+  // };
   const closeCancelTransaction = () => setCancelTransaction(false);
   const closeContinueTransaction = () => setContinueTransaction(false);
 
@@ -119,10 +123,10 @@ const Transaction = ({ id }) => {
   };
   console.log('transaction', transaction);
   const checkout = async () => {
-    // if (!transaction.data?.purchaseOrderFile) {
-    //   toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan');
-    //   return;
-    // }
+    if (!transaction.data?.purchaseOrderFile) {
+      toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan');
+      return;
+    }
     await checkoutPoApi({ id, status: true });
     toast.success('Berhasil melanjutkan pesanan');
     transaction.refetch();
-- 
cgit v1.2.3


From da8350ee1de81d668e117744c3735d848dd53f6e Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 29 Nov 2024 10:13:41 +0700
Subject: <iman> delete console log

---
 src/lib/transaction/components/Transaction.jsx | 1 -
 1 file changed, 1 deletion(-)

(limited to 'src/lib/transaction/components/Transaction.jsx')

diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx
index b1e92f1b..63230cb8 100644
--- a/src/lib/transaction/components/Transaction.jsx
+++ b/src/lib/transaction/components/Transaction.jsx
@@ -121,7 +121,6 @@ const Transaction = ({ id }) => {
     }
     closeCancelTransaction();
   };
-  console.log('transaction', transaction);
   const checkout = async () => {
     if (!transaction.data?.purchaseOrderFile) {
       toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan');
-- 
cgit v1.2.3

