From f15a7f8a4387d215abd1051ee520adca8944fa05 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 28 Mar 2023 16:32:45 +0700 Subject: checkout, quotation --- src/lib/quotation/components/Quotation.jsx | 37 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/lib/quotation') diff --git a/src/lib/quotation/components/Quotation.jsx b/src/lib/quotation/components/Quotation.jsx index 3054616c..a95a149a 100644 --- a/src/lib/quotation/components/Quotation.jsx +++ b/src/lib/quotation/components/Quotation.jsx @@ -15,6 +15,7 @@ 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 variantPriceApi from '@/lib/variant/api/variantPriceApi' const Quotation = () => { const router = useRouter() @@ -31,11 +32,23 @@ const Quotation = () => { .map((o) => o.productId) .join(',') const dataProducts = await CartApi({ variantIds }) - const dataProductsQuantity = _.map(dataProducts, (o) => ({ - ...o, - quantity: getItemCart({ productId: o.id }).quantity - })) - setProducts(dataProductsQuantity) + const productsWithQuantity = dataProducts?.map(async (product) => { + const productPrice = await variantPriceApi({ id: product.id }) + return { + ...product, + price: { + price: productPrice.priceExclude, + discountPercentage: productPrice.discount, + priceDiscount: productPrice.priceExcludeAfterDiscount + }, + quantity: getItemCart({ productId: product.id }).quantity + } + }) + if (productsWithQuantity) { + Promise.all(productsWithQuantity).then((resolvedProducts) => { + setProducts(resolvedProducts) + }) + } } loadProducts() }, []) @@ -78,6 +91,8 @@ const Quotation = () => { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal') } + const taxTotal = (totalAmount - totalDiscountAmount) * 0.11 + return ( <> @@ -121,15 +136,15 @@ const Quotation = () => {
{currencyFormat(totalAmount - totalDiscountAmount)}
-
PPN 11% (Incl.)
-
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
PPN 11%
+
{currencyFormat(taxTotal)}

Grand Total
- {currencyFormat(totalAmount - totalDiscountAmount)} + {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}

*) Belum termasuk biaya pengiriman

@@ -244,8 +259,8 @@ const Quotation = () => {
{currencyFormat(totalAmount - totalDiscountAmount)}
-
PPN 11% (Incl.)
-
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
PPN 11%
+
{currencyFormat(taxTotal)}
@@ -254,7 +269,7 @@ const Quotation = () => {
Grand Total
- {currencyFormat(totalAmount - totalDiscountAmount)} + {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}

-- cgit v1.2.3