RD stock page create
This commit is contained in:
parent
d33a4bebbd
commit
fc12e4e760
@ -156,6 +156,7 @@ import PendingOrders from "./views/orders/pendingOrders";
|
||||
import ViewInvoices from "./views/orders/viewInoices";
|
||||
import Stocks from "./views/PrincipalDistributors/Stock";
|
||||
import SingleDistributorOrder from "./views/RetailDistributors/DistributorOrders";
|
||||
import DistributorStocks from "./views/RetailDistributors/DistributorStock";
|
||||
const routes = [
|
||||
//dashboard
|
||||
|
||||
@ -377,6 +378,12 @@ const routes = [
|
||||
element: SingleDistributorOrder,
|
||||
navName: "Distributor",
|
||||
},
|
||||
{
|
||||
path: "/:distributortype/stocks/:id",
|
||||
name: " Distributor Stocks",
|
||||
element: DistributorStocks,
|
||||
navName: "Distributor",
|
||||
},
|
||||
//----------------------- End Product Management Routes------------------------------------------------
|
||||
|
||||
//Departure
|
||||
|
@ -225,13 +225,13 @@ const principalDistributor = () => {
|
||||
<th>Last Purchase</th>
|
||||
<th>Orders</th>
|
||||
<th>Mapping</th>
|
||||
<th>Action</th>
|
||||
<th className="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{loading ? (
|
||||
<tr className="text-center">
|
||||
<td colSpan="6">
|
||||
<td colSpan="9">
|
||||
<h5>Loading....</h5>
|
||||
</td>
|
||||
</tr>
|
||||
@ -381,13 +381,13 @@ const principalDistributor = () => {
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="mt-1 btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
||||
className=" btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
||||
>
|
||||
View
|
||||
</button>
|
||||
</Link>
|
||||
<Link
|
||||
to={`/pd-stock/${user?._id}`}
|
||||
to={`/principaldistributor/stocks/${user?._id}`}
|
||||
>
|
||||
<button
|
||||
style={{
|
||||
@ -399,7 +399,6 @@ const principalDistributor = () => {
|
||||
btn btn-info btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
"
|
||||
>
|
||||
@ -411,7 +410,7 @@ const principalDistributor = () => {
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan="6" className="text-center">
|
||||
<td colSpan="9" className="text-center">
|
||||
<h5>No Principal Distributor found!</h5>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -62,13 +62,16 @@ const SingleDistributorOrder = () => {
|
||||
const newSearchField = event.target.value;
|
||||
setSearchField(newSearchField);
|
||||
|
||||
// Clear the search text and references
|
||||
setSearchText("");
|
||||
|
||||
if (newSearchField === "Order ID") {
|
||||
searchStatusRef.current = "";
|
||||
} else {
|
||||
searchOrderIdRef.current = "";
|
||||
}
|
||||
searchStatusRef.current = "";
|
||||
|
||||
// Reset page to 0
|
||||
setPage(0);
|
||||
|
||||
// Fetch total orders without any search filters
|
||||
fetchOrdersDebounced(1, rowsPerPage, "", "");
|
||||
};
|
||||
|
||||
// When search text is typed
|
||||
|
504
src/views/RetailDistributors/DistributorStock.js
Normal file
504
src/views/RetailDistributors/DistributorStock.js
Normal file
@ -0,0 +1,504 @@
|
||||
import React, { useState, useEffect, useRef, useCallback } from "react";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import axios from "axios";
|
||||
import Button from "@material-ui/core/Button";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { isAutheticated } from "src/auth";
|
||||
import swal from "sweetalert";
|
||||
import debounce from "lodash.debounce";
|
||||
import { Typography,Paper } from "@mui/material";
|
||||
const DistributorStocks = () => {
|
||||
const token = isAutheticated();
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const { distributortype } = useParams();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [productsData, setProductsData] = useState([]);
|
||||
const [categories, setCategories] = useState([]);
|
||||
const [brands, setBrands] = useState([]);
|
||||
const [user, setUser] = useState(null);
|
||||
|
||||
const nameRef = useRef();
|
||||
const categoryRef = useRef();
|
||||
const brandRef = useRef();
|
||||
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [itemPerPage, setItemPerPage] = useState(10);
|
||||
const [totalData, setTotalData] = useState(0);
|
||||
// Fetch User Details
|
||||
const getUserDetails = useCallback(async () => {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
distributortype === "principaldistributor"
|
||||
? `/api/v1/admin/user/${id}`
|
||||
: `/api/getRD/${id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
distributortype === "principaldistributor"
|
||||
? setUser(response.data.user)
|
||||
: setUser(response.data);
|
||||
} catch (error) {
|
||||
swal({
|
||||
title: "Warning",
|
||||
text: error.message,
|
||||
icon: "error",
|
||||
button: "Close",
|
||||
dangerMode: true,
|
||||
});
|
||||
}
|
||||
}, [id, token]);
|
||||
|
||||
// Call getUserDetails on component mount
|
||||
useEffect(() => {
|
||||
getUserDetails();
|
||||
}, [getUserDetails]);
|
||||
|
||||
const getProductsData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await axios.get( distributortype === "principaldistributor"
|
||||
? `/api/pd/stock/${id}`
|
||||
: `/api/rd/stock/${id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
params: {
|
||||
page: currentPage,
|
||||
show: itemPerPage,
|
||||
name: nameRef.current?.value || "",
|
||||
category: categoryRef.current?.value || "",
|
||||
brand: brandRef.current?.value || "",
|
||||
},
|
||||
});
|
||||
// console.log(response.data);
|
||||
setProductsData(response.data?.products || []);
|
||||
setTotalData(response.data?.totalProducts || 0);
|
||||
} catch (err) {
|
||||
const msg = err?.response?.data?.msg || "Something went wrong!";
|
||||
swal({
|
||||
title: "Error",
|
||||
text: msg,
|
||||
icon: "error",
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getCatagories = () => {
|
||||
axios
|
||||
.get(`/api/category/getCategories`, {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
// console.log(res?.data?.categories);
|
||||
setCategories(res?.data?.categories);
|
||||
});
|
||||
};
|
||||
const getBrands = () => {
|
||||
axios
|
||||
.get(`/api/brand/getBrands`, {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
// console.log(res?.data?.brands);
|
||||
setBrands(res?.data?.brands);
|
||||
});
|
||||
};
|
||||
|
||||
const [currencyDetails, setCurrencyDetails] = useState(null);
|
||||
|
||||
const getCurrency = async () => {
|
||||
try {
|
||||
const response = await axios.get("/api/currency/getall", {
|
||||
// headers: {
|
||||
// Authorization: `Bearer ${token}`,
|
||||
// },
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
setCurrencyDetails(response?.data?.currency[0]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
getCatagories();
|
||||
getCurrency();
|
||||
getBrands();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getProductsData();
|
||||
}, [itemPerPage, currentPage]);
|
||||
|
||||
const debouncedSearch = useCallback(
|
||||
debounce(() => {
|
||||
setCurrentPage(1);
|
||||
getProductsData();
|
||||
}, 500),
|
||||
[]
|
||||
);
|
||||
|
||||
const handleSearchChange = () => {
|
||||
debouncedSearch();
|
||||
};
|
||||
const handleCancel = () => {
|
||||
navigate(
|
||||
distributortype === "principaldistributor"
|
||||
? "/principal-distributor"
|
||||
: "/retail-distributor"
|
||||
);
|
||||
};
|
||||
return (
|
||||
<div className="main-content">
|
||||
<div className="page-content">
|
||||
<div className="container-fluid">
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<Paper sx={{ p: 2 }}>
|
||||
<div
|
||||
className="
|
||||
page-title-box
|
||||
d-flex
|
||||
align-items-center
|
||||
justify-content-between
|
||||
"
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Typography>
|
||||
<strong>Name:</strong> {user?.name}
|
||||
</Typography>
|
||||
<Typography>
|
||||
<strong>Mobile Number:</strong>{" "}
|
||||
{distributortype === "principaldistributor"
|
||||
? user?.phone
|
||||
: user?.mobile_number}
|
||||
</Typography>
|
||||
<Typography>
|
||||
<strong>Email:</strong> {user?.email}
|
||||
</Typography>
|
||||
</div>
|
||||
|
||||
{/* Back Button on the right */}
|
||||
<div className="page-title-right">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="secondary"
|
||||
style={{
|
||||
fontWeight: "bold",
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
onClick={handleCancel}
|
||||
>
|
||||
Back
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Paper>
|
||||
{/* Section Heading: Product Stocks */}
|
||||
<div className="row mt-2 mb-1">
|
||||
<div className="col-12">
|
||||
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||
Product Stocks
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row">
|
||||
<div className="col-lg-12">
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="row ml-0 mr-0 mb-10">
|
||||
<div className="col-lg-1">
|
||||
<div className="dataTables_length">
|
||||
<label className="w-100">
|
||||
Show
|
||||
<select
|
||||
onChange={(e) => {
|
||||
setItemPerPage(e.target.value);
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
className="form-control"
|
||||
disabled={loading}
|
||||
>
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
entries
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<label>Product Name:</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="product name"
|
||||
className="form-control"
|
||||
ref={nameRef}
|
||||
onChange={handleSearchChange}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<label>Filter by Category:</label>
|
||||
<select
|
||||
className="form-control"
|
||||
ref={categoryRef}
|
||||
onChange={handleSearchChange}
|
||||
disabled={loading}
|
||||
>
|
||||
<option value="">All</option>
|
||||
{categories?.map((e, i) => (
|
||||
<option key={i} value={e._id}>
|
||||
{e?.categoryName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<label>Filter by Brand:</label>
|
||||
<select
|
||||
className="form-control"
|
||||
ref={brandRef}
|
||||
onChange={handleSearchChange}
|
||||
disabled={loading}
|
||||
>
|
||||
<option value="">All</option>
|
||||
{brands?.map((e, i) => (
|
||||
<option key={i} value={e._id}>
|
||||
{e?.brandName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="table-responsive table-shoot mt-3">
|
||||
<table
|
||||
className="table table-centered table-nowrap"
|
||||
style={{ border: "1px solid" }}
|
||||
>
|
||||
<thead
|
||||
className="thead-light"
|
||||
style={{ background: "#ecdddd" }}
|
||||
>
|
||||
<tr>
|
||||
<th className="text-start">Image</th>
|
||||
<th className="text-start">SKU</th>
|
||||
<th className="text-start">Product</th>
|
||||
<th className="text-start">Category Name</th>
|
||||
<th className="text-start">Brand Name</th>
|
||||
<th className="text-start">Price</th>
|
||||
<th className="text-start">Added On</th>
|
||||
<th className="text-start">Stock</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{loading ? (
|
||||
<tr>
|
||||
<td className="text-center" colSpan="6">
|
||||
Loading...
|
||||
</td>
|
||||
</tr>
|
||||
) : productsData?.length > 0 ? (
|
||||
productsData?.map((product, i) => {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<th>
|
||||
{product?.image &&
|
||||
product?.image?.length !== 0 ? (
|
||||
<>
|
||||
<img
|
||||
src={product?.image[0]?.url}
|
||||
width="50"
|
||||
alt="preview"
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div
|
||||
className=""
|
||||
style={{ fontSize: "13px" }}
|
||||
>
|
||||
<p className="m-0">No</p>
|
||||
<p className="m-0">image</p>
|
||||
<p className="m-0">uploaded!</p>
|
||||
</div>
|
||||
)}
|
||||
</th>
|
||||
<td className="text-start">{product.SKU}</td>
|
||||
<td className="text-start">{product.name}</td>
|
||||
<td className="text-start">
|
||||
{product.category !== ""
|
||||
? product.category
|
||||
: "Category Not selected "}
|
||||
</td>
|
||||
<td className="text-start">
|
||||
{product.brand !== ""
|
||||
? product.brand
|
||||
: "Brand Not selected "}
|
||||
</td>
|
||||
<th className="text-start">
|
||||
{currencyDetails?.CurrencySymbol}
|
||||
{product?.price}
|
||||
</th>
|
||||
<td className="text-start">
|
||||
{new Date(product.createdAt).toLocaleString(
|
||||
"en-IN",
|
||||
{
|
||||
weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: true,
|
||||
}
|
||||
)}
|
||||
</td>
|
||||
<td className="text-start">{product.stock}</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
!loading &&
|
||||
productsData?.length === 0 && (
|
||||
<tr className="text-center">
|
||||
<td colSpan="8">
|
||||
<h5>No Product Available...</h5>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div className="row mt-20">
|
||||
<div className="col-sm-12 col-md-6 mb-20">
|
||||
<div
|
||||
className="dataTables_info"
|
||||
id="datatable_info"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||
{Math.min(currentPage * itemPerPage, totalData)} of{" "}
|
||||
{totalData} entries
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-sm-12 col-md-6">
|
||||
<div className="d-flex">
|
||||
<ul className="pagination ms-auto">
|
||||
<li
|
||||
className={
|
||||
currentPage === 1
|
||||
? "paginate_button page-item previous disabled"
|
||||
: "paginate_button page-item previous"
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => setCurrentPage((prev) => prev - 1)}
|
||||
disabled={loading}
|
||||
>
|
||||
Previous
|
||||
</span>
|
||||
</li>
|
||||
|
||||
{!(currentPage - 1 < 1) && (
|
||||
<li className="paginate_button page-item">
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={(e) =>
|
||||
setCurrentPage((prev) => prev - 1)
|
||||
}
|
||||
disabled={loading}
|
||||
>
|
||||
{currentPage - 1}
|
||||
</span>
|
||||
</li>
|
||||
)}
|
||||
|
||||
<li className="paginate_button page-item active">
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
{currentPage}
|
||||
</span>
|
||||
</li>
|
||||
|
||||
{!(
|
||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||
totalData - 1
|
||||
) && (
|
||||
<li className="paginate_button page-item ">
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => {
|
||||
setCurrentPage((prev) => prev + 1);
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
{currentPage + 1}
|
||||
</span>
|
||||
</li>
|
||||
)}
|
||||
|
||||
<li
|
||||
className={
|
||||
!(
|
||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||
totalData - 1
|
||||
)
|
||||
? "paginate_button page-item next"
|
||||
: "paginate_button page-item next disabled"
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => setCurrentPage((prev) => prev + 1)}
|
||||
disabled={loading}
|
||||
>
|
||||
Next
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DistributorStocks;
|
@ -162,14 +162,14 @@ const RetailDistributor = () => {
|
||||
<th className="text-start">Sales Coordinator</th>
|
||||
<th className="text-start">Orders</th>
|
||||
<th className="text-start">Mapping</th>
|
||||
<th className="text-start">Action</th>
|
||||
<th className="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{loading ? (
|
||||
<tr>
|
||||
<td className="text-center" colSpan="7">
|
||||
<td className="text-center" colSpan="9">
|
||||
Loading...
|
||||
</td>
|
||||
</tr>
|
||||
@ -186,13 +186,13 @@ const RetailDistributor = () => {
|
||||
{new Date(
|
||||
retailDistributor.createdAt
|
||||
).toLocaleString("en-IN", {
|
||||
weekday: "short",
|
||||
// weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: true,
|
||||
// hour: "numeric",
|
||||
// minute: "numeric",
|
||||
// hour12: true,
|
||||
})}
|
||||
</td>
|
||||
<td className="text-start">
|
||||
@ -244,16 +244,36 @@ const RetailDistributor = () => {
|
||||
<Link
|
||||
to={`/retaildistributor/view/${retailDistributor._id}`}
|
||||
>
|
||||
<Button variant="contained" color="primary">
|
||||
<button
|
||||
type="button"
|
||||
className=" btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
||||
>
|
||||
View
|
||||
</Button>
|
||||
</button>
|
||||
</Link>
|
||||
<Link to={`/retailerdistributor/stocks/${retailDistributor?._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-info btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
"
|
||||
>
|
||||
Stock
|
||||
</button>
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td className="text-center" colSpan="7">
|
||||
<td className="text-center" colSpan="9">
|
||||
No Retail Distributor found!
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user