This commit is contained in:
Sibunnayak 2024-04-01 16:24:17 +05:30
commit 2cf3842b91
6 changed files with 83 additions and 27 deletions

View File

@ -65,7 +65,7 @@ const _nav = [
}, },
{ {
component: CNavItem, component: CNavItem,
name: "Gst Rate", name: "GST Rate",
icon: <CIcon icon={cilTablet} customClassName="nav-icon" />, icon: <CIcon icon={cilTablet} customClassName="nav-icon" />,
to: "/tax", to: "/tax",
}, },

View File

@ -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(data);
console.log(productImages); // console.log(productImages);
return ( return (
<div className="container"> <div className="container">
<div className="row"> <div className="row">
@ -253,13 +266,13 @@ const AddProduct = () => {
className="form-control" className="form-control"
id="name" id="name"
value={name} value={name}
maxLength={25} maxLength={35}
onChange={(e) => setName(e.target.value)} onChange={(e) => setName(e.target.value)}
/> />
{name ? ( {name ? (
<> <>
<small className="charLeft mt-4 fst-italic"> <small className="charLeft mt-4 fst-italic">
{25 - name.length} characters left {35 - name.length} characters left
</small> </small>
</> </>
) : ( ) : (
@ -271,18 +284,19 @@ const AddProduct = () => {
<label htmlFor="title" className="form-label"> <label htmlFor="title" className="form-label">
Description* Description*
</label> </label>
<input <textarea
type="text" type="text"
className="form-control" className="form-control"
id="description" id="description"
value={description} value={description}
maxLength="100" rows={8}
maxLength="400"
onChange={(e) => setDescription(e.target.value)} onChange={(e) => setDescription(e.target.value)}
/> />
{description ? ( {description ? (
<> <>
<small className="charLeft mt-4 fst-italic"> <small className="charLeft mt-4 fst-italic">
{100 - description.length} characters left {400 - description.length} characters left
</small> </small>
</> </>
) : ( ) : (
@ -405,7 +419,7 @@ const AddProduct = () => {
className="form-control" className="form-control"
id="price" id="price"
value={price} value={price}
onChange={(e) => setPrice(e.target.value)} onChange={(e) => handlePriceChange(e)}
/> />
</div> </div>
<div className=""> <div className="">
@ -464,7 +478,7 @@ const AddProduct = () => {
{allTax.length > 0 && ( {allTax.length > 0 && (
<div className=" mb-3"> <div className=" mb-3">
<label htmlFor="title" className="form-label"> <label htmlFor="title" className="form-label">
Gst* GST*
</label>{" "} </label>{" "}
<select <select
className="form-control" className="form-control"
@ -485,7 +499,7 @@ const AddProduct = () => {
<div className="mb-3 me-3"> <div className="mb-3 me-3">
<label htmlFor="title" className="form-label"> <label htmlFor="title" className="form-label">
Gst Amount (Rs) * GST Amount (Rs) *
</label> </label>
<input <input
disabled disabled

View File

@ -33,6 +33,7 @@ const EditProduct = () => {
const [price, setPrice] = useState(""); const [price, setPrice] = useState("");
const [category, setCategoryName] = useState(""); const [category, setCategoryName] = useState("");
const [error, setError] = useState(""); const [error, setError] = useState("");
const [initTax, setInitTax] = useState();
const [selectedTax, setselectedTax] = useState(); const [selectedTax, setselectedTax] = useState();
const [totalAmt, setTotalAmt] = useState(0); const [totalAmt, setTotalAmt] = useState(0);
const [gst_amount, setGst_amount] = useState(0); const [gst_amount, setGst_amount] = useState(0);
@ -48,13 +49,14 @@ const EditProduct = () => {
}, },
}) })
.then((res) => { .then((res) => {
console.log(res?.data?.product?.gst?._id); // console.log(res?.data?.product?.gst?._id);
setName(res?.data?.product.name); setName(res?.data?.product.name);
setDescription(res.data.product.description); setDescription(res.data.product.description);
setProductImages(res.data.product.image); setProductImages(res.data.product.image);
setPrice(res.data.product.price); setPrice(res.data.product.price);
setCategoryName(res.data.product?.category?._id); 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); setTotalAmt(res.data.product?.total_amount);
setGst_amount(res.data.product?.gst_amount); setGst_amount(res.data.product?.gst_amount);
}) })
@ -68,6 +70,7 @@ const EditProduct = () => {
}); });
}); });
}; };
// console.log(selectedTax, "selectedTax");
const getCategories = async () => { const getCategories = async () => {
try { try {
@ -111,6 +114,7 @@ const EditProduct = () => {
}, [token]); }, [token]);
const TaxRatechange = async (e) => { const TaxRatechange = async (e) => {
let m = JSON.parse(e.target.value); let m = JSON.parse(e.target.value);
setInitTax("");
if (m?.tax) { if (m?.tax) {
let totalprice = Number(price) + Number((price * m?.tax) / 100); let totalprice = Number(price) + Number((price * m?.tax) / 100);
setGst_amount(Number((price * m?.tax) / 100)?.toFixed(2)); setGst_amount(Number((price * m?.tax) / 100)?.toFixed(2));
@ -118,7 +122,29 @@ const EditProduct = () => {
setselectedTax(m?._id); 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 = () => { const handleSubmit = () => {
// console.log("selected Tax", selectedTax);
if ( if (
name === "" || name === "" ||
description === "" || description === "" ||
@ -127,6 +153,8 @@ const EditProduct = () => {
selectedTax === "" || selectedTax === "" ||
gst_amount === "" || gst_amount === "" ||
price === "" || price === "" ||
totalAmt === "" ||
gst_amount === "" ||
(productImages.length == 0 && newUpdatedImages.length == 0) (productImages.length == 0 && newUpdatedImages.length == 0)
) { ) {
swal({ swal({
@ -148,7 +176,7 @@ const EditProduct = () => {
formData.append("total_amount", totalAmt); formData.append("total_amount", totalAmt);
formData.append("gst_amount", gst_amount); formData.append("gst_amount", gst_amount);
formData.append("gst", selectedTax); formData.append("gst", initTax === "" ? selectedTax : initTax);
newUpdatedImages.length > 0 && newUpdatedImages.length > 0 &&
newUpdatedImages.forEach((Singleimage) => { newUpdatedImages.forEach((Singleimage) => {
@ -280,7 +308,7 @@ const EditProduct = () => {
onClick={() => handleSubmit()} onClick={() => handleSubmit()}
disabled={loading} disabled={loading}
> >
{loading ? "Loading" : "Edit"} {loading ? "Loading" : "Save"}
</Button> </Button>
<Link to="/products"> <Link to="/products">
<Button <Button
@ -312,13 +340,13 @@ const EditProduct = () => {
className="form-control" className="form-control"
id="name" id="name"
value={name} value={name}
maxLength={25} maxLength={35}
onChange={(e) => setName(e.target.value)} onChange={(e) => setName(e.target.value)}
/> />
{name ? ( {name ? (
<> <>
<small className="charLeft mt-4 fst-italic"> <small className="charLeft mt-4 fst-italic">
{25 - name.length} characters left {35 - name.length} characters left
</small> </small>
</> </>
) : ( ) : (
@ -330,18 +358,19 @@ const EditProduct = () => {
<label htmlFor="title" className="form-label"> <label htmlFor="title" className="form-label">
Description* Description*
</label> </label>
<input <textarea
type="text" type="text"
className="form-control" className="form-control"
id="description" id="description"
rows="8"
value={description} value={description}
maxLength="100" maxLength="400"
onChange={(e) => setDescription(e.target.value)} onChange={(e) => setDescription(e.target.value)}
/> />
{description ? ( {description ? (
<> <>
<small className="charLeft mt-4 fst-italic"> <small className="charLeft mt-4 fst-italic">
{100 - description.length} characters left {400 - description.length} characters left
</small> </small>
</> </>
) : ( ) : (
@ -477,7 +506,7 @@ const EditProduct = () => {
className="form-control" className="form-control"
id="price" id="price"
value={price} value={price}
onChange={(e) => setPrice(e.target.value)} onChange={(e) => handlePriceChange(e)}
/> />
</div> </div>
<div> <div>
@ -501,16 +530,22 @@ const EditProduct = () => {
{allTax.length > 0 && ( {allTax.length > 0 && (
<div className=" mb-3"> <div className=" mb-3">
<label htmlFor="title" className="form-label"> <label htmlFor="title" className="form-label">
Gst* GST*
</label>{" "} </label>{" "}
<select <select
className=" form-control" className=" form-control"
name="" name=""
id="" id=""
value={JSON.stringify(selectedTax?._id)}
onChange={(e) => TaxRatechange(e)} onChange={(e) => TaxRatechange(e)}
> >
<option value="">--Select--</option> {selectedTax?.tax && (
<option
value={selectedTax && JSON.stringify(selectedTax)}
>
{selectedTax?.tax}% {selectedTax?.name}
</option>
)}
{allTax.map((t, i) => ( {allTax.map((t, i) => (
<option key={i} value={JSON.stringify(t)}> <option key={i} value={JSON.stringify(t)}>
{t.tax}% {t.name} {t.tax}% {t.name}
@ -522,7 +557,7 @@ const EditProduct = () => {
<div className="mb-3 me-3"> <div className="mb-3 me-3">
<label htmlFor="title" className="form-label"> <label htmlFor="title" className="form-label">
Gst Amount (Rs) * GST Amount (Rs) *
</label> </label>
<input <input
disabled disabled

View File

@ -62,6 +62,7 @@ const Products = () => {
useEffect(() => { useEffect(() => {
getProductsData(); getProductsData();
}, [success]); }, [success]);
console.log(productsData);
useEffect(() => { useEffect(() => {
const loadData = () => { const loadData = () => {
@ -143,6 +144,9 @@ const Products = () => {
} }
setTimeout(() => handleSearchClick(query), 100); setTimeout(() => handleSearchClick(query), 100);
}, [query]); }, [query]);
const uniqueCategoryNames = [
...new Set(showData?.map((product) => product?.category?.categoryName)),
];
useEffect(() => { useEffect(() => {
setTimeout(() => { setTimeout(() => {
if (filterCategory !== "") { if (filterCategory !== "") {
@ -301,7 +305,7 @@ const Products = () => {
setFilterCategory(e.target.value) setFilterCategory(e.target.value)
} }
> >
{showData.map((product, i) => ( {uniqueCategoryNames.map((categoryName, i) => (
<MenuItem <MenuItem
key={i} key={i}
style={{ style={{
@ -311,9 +315,9 @@ const Products = () => {
textAlign: "left", textAlign: "left",
padding: "0.5rem", padding: "0.5rem",
}} }}
value={product.category?.categoryName} value={categoryName}
> >
{product.category?.categoryName} {categoryName}
</MenuItem> </MenuItem>
))} ))}
</Select> </Select>

View File

@ -10,6 +10,7 @@ function NewOrders() {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [success, setSuccess] = useState(true); const [success, setSuccess] = useState(true);
const [newOrdersData, setNewOrdersData] = useState([]); const [newOrdersData, setNewOrdersData] = useState([]);
console.log(newOrdersData);
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
const [itemPerPage, setItemPerPage] = useState(10); const [itemPerPage, setItemPerPage] = useState(10);

View File

@ -137,6 +137,8 @@ function ViewOrders() {
status: orderStatus, status: orderStatus,
courierName, courierName,
TrackingID, TrackingID,
sendemail: orderDetails?.user?.email,
customerName: orderDetails?.user?.name,
}, },
{ {
headers: { headers: {