From 593dd8e50a55e7e33fe0a672c382e1228b0bb6bc Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 14 Apr 2023 15:21:49 +0700
Subject: fix

---
 src/lib/transaction/components/Transaction.jsx | 61 ++++++--------------------
 1 file changed, 14 insertions(+), 47 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 b4e050c6..3e3f2cc7 100644
--- a/src/lib/transaction/components/Transaction.jsx
+++ b/src/lib/transaction/components/Transaction.jsx
@@ -25,25 +25,8 @@ import toTitleCase from '@/core/utils/toTitleCase'
 const Transaction = ({ id }) => {
   const { transaction } = useTransaction({ id })
 
-  const [totalAmount, setTotalAmount] = useState(0)
-  const [totalDiscountAmount, setTotalDiscountAmount] = useState(0)
-
-  useEffect(() => {
-    if (transaction?.data?.products) {
-      let calculateTotalAmount = 0
-      let calculateTotalDiscountAmount = 0
-      transaction.data.products.forEach((product) => {
-        calculateTotalAmount += product.price.price * product.quantity
-        calculateTotalDiscountAmount +=
-          (product.price.price - product.price.priceDiscount) * product.quantity
-      })
-      setTotalAmount(calculateTotalAmount)
-      setTotalDiscountAmount(calculateTotalDiscountAmount)
-    }
-  }, [transaction])
-
-  const poNumber = useRef('')
-  const poFile = useRef('')
+  const poNumber = useRef(null)
+  const poFile = useRef(null)
   const [uploadPo, setUploadPo] = useState(false)
   const openUploadPo = () => setUploadPo(true)
   const closeUploadPo = () => setUploadPo(false)
@@ -97,11 +80,7 @@ const Transaction = ({ id }) => {
         <VariantGroupCard variants={transaction.data?.products} buyMore />
         <div className='flex justify-between mt-1'>
           <p className='text-gray_r-12/70'>Subtotal</p>
-          <p>{currencyFormat(totalAmount)}</p>
-        </div>
-        <div className='flex justify-between mt-1'>
-          <p className='text-gray_r-12/70'>Total Diskon</p>
-          <p>{currencyFormat(-totalDiscountAmount)}</p>
+          <p>{currencyFormat(transaction.data?.amountUntaxed)}</p>
         </div>
         <div className='flex justify-between mt-1'>
           <p className='text-gray_r-12/70'>PPN 11%</p>
@@ -113,7 +92,7 @@ const Transaction = ({ id }) => {
         </div>
       </div>
     ),
-    [transaction.data, totalAmount, totalDiscountAmount]
+    [transaction.data]
   )
 
   if (transaction.isLoading) {
@@ -295,7 +274,6 @@ const Transaction = ({ id }) => {
               <button
                 type='button'
                 className='btn-solid-red px-3 py-2'
-                // disabled={transaction.data?.status != 'draft'}
                 onClick={() => downloadQuotation(transaction.data)}
               >
                 Download
@@ -337,14 +315,6 @@ const Transaction = ({ id }) => {
                   <div className='font-medium mb-4'>Detail Pelanggan</div>
                   <SectionContent address={transaction?.data?.address?.customer} />
                 </div>
-                {/* <div className='border border-gray_r-6 rounded p-3'>
-                  <div className='font-medium mb-4'>Detail Pengiriman</div>
-                  <SectionContent address={transaction?.data?.address?.shipping} />
-                </div>
-                <div className='border border-gray_r-6 rounded p-3'>
-                  <div className='font-medium mb-4'>Detail Penagihan</div>
-                  <SectionContent address={transaction?.data?.address?.invoice} />
-                </div> */}
               </div>
 
               <div className='text-h-sm font-semibold mt-6 mb-4'>Rincian Pembelian</div>
@@ -352,9 +322,9 @@ const Transaction = ({ id }) => {
                 <thead>
                   <tr>
                     <th>Nama Produk</th>
+                    <th>Diskon</th>
                     <th>Jumlah</th>
                     <th>Harga</th>
-                    <th>Diskon</th>
                     <th>Subtotal</th>
                   </tr>
                 </thead>
@@ -368,12 +338,12 @@ const Transaction = ({ id }) => {
                             product?.parent.name,
                             product?.parent.id
                           )}
-                          className='w-[25%] flex-shrink-0'
+                          className='w-[20%] flex-shrink-0'
                         >
                           <Image
                             src={product?.parent?.image}
                             alt={product?.name}
-                            className='object-contain object-center border border-gray_r-6 h-40 w-full rounded-md'
+                            className='object-contain object-center border border-gray_r-6 h-32 w-full rounded-md'
                           />
                         </Link>
                         <div className='px-2 text-left'>
@@ -395,6 +365,11 @@ const Transaction = ({ id }) => {
                           </div>
                         </div>
                       </td>
+                      <td>
+                        {product.price.discountPercentage > 0
+                          ? `${product.price.discountPercentage}%`
+                          : ''}
+                      </td>
                       <td>{product.quantity}</td>
                       <td>
                         {product.price.discountPercentage > 0 && (
@@ -404,11 +379,6 @@ const Transaction = ({ id }) => {
                         )}
                         <div>{currencyFormat(product.price.priceDiscount)}</div>
                       </td>
-                      <td>
-                        {product.price.discountPercentage > 0
-                          ? `${product.price.discountPercentage}%`
-                          : ''}
-                      </td>
                       <td>{currencyFormat(product.price.subtotal)}</td>
                     </tr>
                   ))}
@@ -418,11 +388,8 @@ const Transaction = ({ id }) => {
               <div className='flex justify-end mt-4'>
                 <div className='w-1/4 grid grid-cols-2 gap-y-3 text-gray_r-12/80'>
                   <div className='text-right'>Subtotal</div>
-                  <div className='text-right font-medium'>{currencyFormat(totalAmount)}</div>
-
-                  <div className='text-right'>Total Diskon</div>
-                  <div className='text-right font-medium text-danger-500'>
-                    {currencyFormat(-totalDiscountAmount)}
+                  <div className='text-right font-medium'>
+                    {currencyFormat(transaction.data?.amountUntaxed)}
                   </div>
 
                   <div className='text-right'>PPN 11%</div>
-- 
cgit v1.2.3

