From bad8abd263bd43c59dad8e61e2f5f35bfe5b7746 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 8 Aug 2024 11:37:58 +0700
Subject: <iman> update quotation pop up

---
 src/lib/quotation/components/Quotationheader.jsx | 38 +++++++++++++++++++++---
 1 file changed, 34 insertions(+), 4 deletions(-)

(limited to 'src/lib/quotation/components/Quotationheader.jsx')

diff --git a/src/lib/quotation/components/Quotationheader.jsx b/src/lib/quotation/components/Quotationheader.jsx
index 79011682..14743fd6 100644
--- a/src/lib/quotation/components/Quotationheader.jsx
+++ b/src/lib/quotation/components/Quotationheader.jsx
@@ -30,6 +30,7 @@ const Quotationheader = (quotationCount) => {
 
   const [isHovered, setIsHovered] = useState(false);
   const [isTop, setIsTop] = useState(true);
+
   const qotation = useMemo(() => {
     return productQuotation || [];
   }, [productQuotation]);
@@ -49,6 +50,7 @@ const Quotationheader = (quotationCount) => {
     }
   };
   let { transactions } = useTransactions({ query });
+
   const refreshCartf = useCallback(async () => {
     setIsloading(true);
     let pendingTransactions = transactions?.data?.saleOrders.filter(transaction => transaction.status === 'draft');
@@ -57,6 +59,18 @@ const Quotationheader = (quotationCount) => {
     setIsloading(false);
   }, [setProductQuotation, setIsloading]);
 
+  useEffect(() => {
+    if (!qotation) return
+
+    let calculateTotalDiscountAmount = 0
+    for (const product of qotation) {
+      // if (qotation.quantity == '') continue  
+      calculateTotalDiscountAmount += product.amountUntaxed
+    }
+    let subTotal = calculateTotalDiscountAmount
+    setSubTotal(subTotal)
+  }, [qotation])
+
   useEffect(() => {
     if (refreshQuotation) {
       refreshCartf();
@@ -84,8 +98,6 @@ const Quotationheader = (quotationCount) => {
     router.push('/shop/quotation');
   };
 
-  console.log("quotation",qotation)
-
   return (
     <div className='relative group'>
       <div>
@@ -211,8 +223,8 @@ const Quotationheader = (quotationCount) => {
                                     </div>
                                     <div className='my-0.5 h-0.5 bg-gray-200'></div>
                                     <div className='bagian bawah flex justify-between mt-2'>
-                                      <p className='font-semibold text-base'>Total</p>
-                                      <p className='font-semibold text-base'>{currencyFormat(product.amountTotal)}</p>
+                                      <p className='font-semibold text-sm'>Total</p>
+                                      <p className='font-semibold text-sm'>{currencyFormat(product.amountUntaxed)}</p>
                                     </div>
                                 </Link>
                                 </div>
@@ -224,6 +236,24 @@ const Quotationheader = (quotationCount) => {
                     </>
                   )}
                 </div>
+                {auth && qotation.length > 0 && !isLoading && (
+                  <>
+                    <div className='mt-3'>
+                      <span className='text-gray-400 text-caption-2'>Subtotal Sebelum PPN : </span>
+                      <span className='font-semibold text-red-600'>{currencyFormat(subTotal)}</span>
+                    </div>
+                    <div className='mt-5 mb-2'>
+                      <button
+                        type='button'
+                        className='btn-yellow rounded-lg w-full'
+                        onClick={handleCheckout}
+                        disabled={buttonLoading}
+                      >
+                        {buttonLoading ? 'Loading...' : 'Buat Quotation'}
+                      </button>
+                    </div>
+                  </>
+                )}
               </motion.div>
             </motion.div>
           </>
-- 
cgit v1.2.3

