From 02fbca0f66aac32e562364ddfda9c5bae4177e96 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 26 Jul 2023 14:31:59 +0700
Subject: fix error quotation

---
 src/lib/quotation/components/Quotation.jsx | 41 +++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 15 deletions(-)

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

diff --git a/src/lib/quotation/components/Quotation.jsx b/src/lib/quotation/components/Quotation.jsx
index 9ffc2fbb..c2a36001 100644
--- a/src/lib/quotation/components/Quotation.jsx
+++ b/src/lib/quotation/components/Quotation.jsx
@@ -9,17 +9,23 @@ import _ from 'lodash'
 import { deleteItemCart, getCart, getItemCart } from '@/core/utils/cart'
 import currencyFormat from '@/core/utils/currencyFormat'
 import { toast } from 'react-hot-toast'
-import checkoutApi from '@/lib/checkout/api/checkoutApi'
+// import checkoutApi from '@/lib/checkout/api/checkoutApi'
 import { useRouter } from 'next/router'
 import VariantGroupCard from '@/lib/variant/components/VariantGroupCard'
 import MobileView from '@/core/components/views/MobileView'
 import DesktopView from '@/core/components/views/DesktopView'
 import Image from '@/core/components/elements/Image/Image'
+import { useQuery } from 'react-query'
+
+const { checkoutApi } = require('@/lib/checkout/api/checkoutApi')
+const { getProductsCheckout } = require('@/lib/checkout/api/checkoutApi')
 
 const Quotation = () => {
   const router = useRouter()
   const auth = useAuth()
 
+  const { data: cartCheckout } = useQuery('cartCheckout', () => getProductsCheckout())
+
   const [products, setProducts] = useState(null)
   const [totalAmount, setTotalAmount] = useState(0)
   const [totalDiscountAmount, setTotalDiscountAmount] = useState(0)
@@ -43,9 +49,13 @@ const Quotation = () => {
         })
       }
     }
-    loadProducts()
+    // loadProducts()
   }, [])
 
+  useEffect(() => {
+    setProducts(cartCheckout?.products)
+  }, [cartCheckout])
+
   useEffect(() => {
     if (products) {
       let calculateTotalAmount = 0
@@ -118,26 +128,26 @@ const Quotation = () => {
           <div className='flex flex-col gap-y-4'>
             <div className='flex gap-x-2 justify-between'>
               <div className='text-gray_r-11'>Total Belanja</div>
-              <div>{currencyFormat(totalAmount)}</div>
+              <div>{currencyFormat(cartCheckout?.totalPurchase)}</div>
             </div>
             <div className='flex gap-x-2 justify-between'>
-              <div className='text-gray_r-11'>Total Diskon</div>
-              <div className='text-danger-500'>- {currencyFormat(totalDiscountAmount)}</div>
+              <div className='text-gray_r-11'>Diskon Produk</div>
+              <div className='text-danger-500'>- {currencyFormat(cartCheckout?.totalDiscount)}</div>
             </div>
             <div className='flex gap-x-2 justify-between'>
               <div className='text-gray_r-11'>Subtotal</div>
-              <div>{currencyFormat(totalAmount - totalDiscountAmount)}</div>
+              <div>{currencyFormat(cartCheckout?.subtotal)}</div>
             </div>
             <div className='flex gap-x-2 justify-between'>
               <div className='text-gray_r-11'>PPN 11%</div>
-              <div>{currencyFormat(taxTotal)}</div>
+              <div>{currencyFormat(cartCheckout?.tax)}</div>
             </div>
           </div>
           <hr className='my-4 border-gray_r-6' />
           <div className='flex gap-x-2 justify-between mb-4'>
             <div>Grand Total</div>
             <div className='font-semibold text-gray_r-12'>
-              {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}
+              {currencyFormat(cartCheckout?.grandTotal)}
             </div>
           </div>
           <p className='text-caption-2 text-gray_r-10 mb-2'>*) Belum termasuk biaya pengiriman</p>
@@ -237,23 +247,24 @@ const Quotation = () => {
               </div>
 
               <hr className='my-4 border-gray_r-6' />
-
               <div className='flex flex-col gap-y-4'>
                 <div className='flex gap-x-2 justify-between'>
                   <div className='text-gray_r-11'>Total Belanja</div>
-                  <div>{currencyFormat(totalAmount)}</div>
+                  <div>{currencyFormat(cartCheckout?.totalPurchase)}</div>
                 </div>
                 <div className='flex gap-x-2 justify-between'>
-                  <div className='text-gray_r-11'>Total Diskon</div>
-                  <div className='text-danger-500'>- {currencyFormat(totalDiscountAmount)}</div>
+                  <div className='text-gray_r-11'>Diskon Produk</div>
+                  <div className='text-danger-500'>
+                    - {currencyFormat(cartCheckout?.totalDiscount)}
+                  </div>
                 </div>
                 <div className='flex gap-x-2 justify-between'>
                   <div className='text-gray_r-11'>Subtotal</div>
-                  <div>{currencyFormat(totalAmount - totalDiscountAmount)}</div>
+                  <div>{currencyFormat(cartCheckout?.subtotal)}</div>
                 </div>
                 <div className='flex gap-x-2 justify-between'>
                   <div className='text-gray_r-11'>PPN 11%</div>
-                  <div>{currencyFormat(taxTotal)}</div>
+                  <div>{currencyFormat(cartCheckout?.tax)}</div>
                 </div>
               </div>
 
@@ -262,7 +273,7 @@ const Quotation = () => {
               <div className='flex gap-x-2 justify-between mb-4'>
                 <div>Grand Total</div>
                 <div className='font-semibold text-gray_r-12'>
-                  {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}
+                  {currencyFormat(cartCheckout?.grandTotal)}
                 </div>
               </div>
               <p className='text-caption-2 text-gray_r-11 mb-2'>
-- 
cgit v1.2.3


From d7e6a3cf7f7d2f3338c0b82dfe6109754dc9a921 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 26 Jul 2023 16:56:30 +0700
Subject: error user id

---
 src/lib/quotation/components/Quotation.jsx | 1 +
 1 file changed, 1 insertion(+)

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

diff --git a/src/lib/quotation/components/Quotation.jsx b/src/lib/quotation/components/Quotation.jsx
index c2a36001..cee35457 100644
--- a/src/lib/quotation/components/Quotation.jsx
+++ b/src/lib/quotation/components/Quotation.jsx
@@ -82,6 +82,7 @@ const Quotation = () => {
     let data = {
       partner_shipping_id: auth.partnerId,
       partner_invoice_id: auth.partnerId,
+      user_id: auth.id,
       order_line: JSON.stringify(productOrder)
     }
     const isSuccess = await checkoutApi({ data })
-- 
cgit v1.2.3

