diff --git a/src/_nav.js b/src/_nav.js index 6eddd7e..41df504 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -65,7 +65,7 @@ const _nav = [ }, { component: CNavItem, - name: "Gst Rate", + name: "GST Rate", icon: , to: "/tax", }, diff --git a/src/views/Products/AddProduct.js b/src/views/Products/AddProduct.js index f6daddb..96270c5 100644 --- a/src/views/Products/AddProduct.js +++ b/src/views/Products/AddProduct.js @@ -187,8 +187,21 @@ const AddProduct = () => { }); }); }; + const handlePriceChange = (e) => { + const newPrice = e.target.value; + setPrice(newPrice); + const selectedTaxObj = allTax.find((t) => t._id === selectedTax); + + if (selectedTaxObj && !isNaN(newPrice)) { + const gstAmount = (newPrice * selectedTaxObj.tax) / 100; + const totalAmount = Number(newPrice) + gstAmount; + + setGst_amount(gstAmount.toFixed(2)); + setTotalAmt(totalAmount.toFixed(2)); + } + }; // console.log(data); - console.log(productImages); + // console.log(productImages); return (
@@ -253,13 +266,13 @@ const AddProduct = () => { className="form-control" id="name" value={name} - maxLength={25} + maxLength={35} onChange={(e) => setName(e.target.value)} /> {name ? ( <> - {25 - name.length} characters left + {35 - name.length} characters left ) : ( @@ -271,18 +284,19 @@ const AddProduct = () => { - setDescription(e.target.value)} /> {description ? ( <> - {100 - description.length} characters left + {400 - description.length} characters left ) : ( @@ -405,7 +419,7 @@ const AddProduct = () => { className="form-control" id="price" value={price} - onChange={(e) => setPrice(e.target.value)} + onChange={(e) => handlePriceChange(e)} />
@@ -464,7 +478,7 @@ const AddProduct = () => { {allTax.length > 0 && (
{" "} { const [price, setPrice] = useState(""); const [category, setCategoryName] = useState(""); const [error, setError] = useState(""); + const [initTax, setInitTax] = useState(); const [selectedTax, setselectedTax] = useState(); const [totalAmt, setTotalAmt] = useState(0); const [gst_amount, setGst_amount] = useState(0); @@ -48,13 +49,14 @@ const EditProduct = () => { }, }) .then((res) => { - console.log(res?.data?.product?.gst?._id); + // console.log(res?.data?.product?.gst?._id); setName(res?.data?.product.name); setDescription(res.data.product.description); setProductImages(res.data.product.image); setPrice(res.data.product.price); setCategoryName(res.data.product?.category?._id); - setselectedTax(res.data.product?.gst?.name); + setselectedTax(res.data.product?.gst); + setInitTax(res.data.product?.gst?._id); setTotalAmt(res.data.product?.total_amount); setGst_amount(res.data.product?.gst_amount); }) @@ -68,6 +70,7 @@ const EditProduct = () => { }); }); }; + // console.log(selectedTax, "selectedTax"); const getCategories = async () => { try { @@ -111,6 +114,7 @@ const EditProduct = () => { }, [token]); const TaxRatechange = async (e) => { let m = JSON.parse(e.target.value); + setInitTax(""); if (m?.tax) { let totalprice = Number(price) + Number((price * m?.tax) / 100); setGst_amount(Number((price * m?.tax) / 100)?.toFixed(2)); @@ -118,7 +122,29 @@ const EditProduct = () => { setselectedTax(m?._id); } }; + // console.log(selectedTax, "inisele"); + const handlePriceChange = (e) => { + const newPrice = e.target.value; + + setPrice(newPrice); + const selectedTaxObj = allTax.find( + (t) => + t._id === + (typeof selectedTax === "object" ? selectedTax._id : selectedTax) + ); + // console.log(selectedTax); + // console.log(selectedTaxObj, "this is ", selectedTax); + + if (selectedTaxObj && !isNaN(newPrice)) { + const gstAmount = (newPrice * selectedTaxObj.tax) / 100; + const totalAmount = Number(newPrice) + gstAmount; + + setGst_amount(gstAmount.toFixed(2)); + setTotalAmt(totalAmount.toFixed(2)); + } + }; const handleSubmit = () => { + // console.log("selected Tax", selectedTax); if ( name === "" || description === "" || @@ -127,6 +153,8 @@ const EditProduct = () => { selectedTax === "" || gst_amount === "" || price === "" || + totalAmt === "" || + gst_amount === "" || (productImages.length == 0 && newUpdatedImages.length == 0) ) { swal({ @@ -148,7 +176,7 @@ const EditProduct = () => { formData.append("total_amount", totalAmt); formData.append("gst_amount", gst_amount); - formData.append("gst", selectedTax); + formData.append("gst", initTax === "" ? selectedTax : initTax); newUpdatedImages.length > 0 && newUpdatedImages.forEach((Singleimage) => { @@ -280,7 +308,7 @@ const EditProduct = () => { onClick={() => handleSubmit()} disabled={loading} > - {loading ? "Loading" : "Edit"} + {loading ? "Loading" : "Save"}
@@ -501,16 +530,22 @@ const EditProduct = () => { {allTax.length > 0 && (
{" "} { useEffect(() => { getProductsData(); }, [success]); + console.log(productsData); useEffect(() => { const loadData = () => { @@ -143,6 +144,9 @@ const Products = () => { } setTimeout(() => handleSearchClick(query), 100); }, [query]); + const uniqueCategoryNames = [ + ...new Set(showData?.map((product) => product?.category?.categoryName)), + ]; useEffect(() => { setTimeout(() => { if (filterCategory !== "") { @@ -301,7 +305,7 @@ const Products = () => { setFilterCategory(e.target.value) } > - {showData.map((product, i) => ( + {uniqueCategoryNames.map((categoryName, i) => ( { textAlign: "left", padding: "0.5rem", }} - value={product.category?.categoryName} + value={categoryName} > - {product.category?.categoryName} + {categoryName} ))} diff --git a/src/views/orders/NewOrders.js b/src/views/orders/NewOrders.js index 9980372..11a4ae1 100644 --- a/src/views/orders/NewOrders.js +++ b/src/views/orders/NewOrders.js @@ -10,6 +10,7 @@ function NewOrders() { const [loading, setLoading] = useState(true); const [success, setSuccess] = useState(true); const [newOrdersData, setNewOrdersData] = useState([]); + console.log(newOrdersData); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); diff --git a/src/views/orders/ViewOrders.js b/src/views/orders/ViewOrders.js index 5f1eb1a..d7cbf6c 100644 --- a/src/views/orders/ViewOrders.js +++ b/src/views/orders/ViewOrders.js @@ -137,6 +137,8 @@ function ViewOrders() { status: orderStatus, courierName, TrackingID, + sendemail: orderDetails?.user?.email, + customerName: orderDetails?.user?.name, }, { headers: {