From d33a4bebbdffbc814bff93735429951d7f14aef2 Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Thu, 3 Oct 2024 12:04:02 +0530 Subject: [PATCH] rd order and pd order fixed --- src/routes.js | 7 + .../principalDistributor.js | 18 +- .../singlePrincipalDistributorAllDetails.js | 355 +------------ .../RetailDistributors/DistributorOrders.js | 485 ++++++++++++++++++ .../RetailDistributors/RetailDistributor.js | 82 +-- .../SingleRetailDistributor.js | 310 ----------- src/views/orders/ViewOrders.js | 4 +- src/views/orders/invoiceTable.js | 2 +- src/views/orders/pendingOrderTable.js | 24 +- src/views/orders/viewInoices.js | 2 +- 10 files changed, 598 insertions(+), 691 deletions(-) create mode 100644 src/views/RetailDistributors/DistributorOrders.js diff --git a/src/routes.js b/src/routes.js index e42e5ba..135d7e8 100644 --- a/src/routes.js +++ b/src/routes.js @@ -155,6 +155,7 @@ import MapRD from "./views/RetailDistributors/MapRD"; import PendingOrders from "./views/orders/pendingOrders"; import ViewInvoices from "./views/orders/viewInoices"; import Stocks from "./views/PrincipalDistributors/Stock"; +import SingleDistributorOrder from "./views/RetailDistributors/DistributorOrders"; const routes = [ //dashboard @@ -370,6 +371,12 @@ const routes = [ element: MapRD, navName: "RetailDistributor", }, + { + path: "/:distributortype/orders/:id", + name: " Distributor Orders", + element: SingleDistributorOrder, + navName: "Distributor", + }, //----------------------- End Product Management Routes------------------------------------------------ //Departure diff --git a/src/views/PrincipalDistributors/principalDistributor.js b/src/views/PrincipalDistributors/principalDistributor.js index 6c34c5a..a015d76 100644 --- a/src/views/PrincipalDistributors/principalDistributor.js +++ b/src/views/PrincipalDistributors/principalDistributor.js @@ -268,8 +268,22 @@ const principalDistributor = () => { ) : "No purchase"} - - {user.totalOrders} + + + + + {/* {loading1 && ( <> loading... diff --git a/src/views/PrincipalDistributors/singlePrincipalDistributorAllDetails.js b/src/views/PrincipalDistributors/singlePrincipalDistributorAllDetails.js index 2dcd7f2..c8c8ce0 100644 --- a/src/views/PrincipalDistributors/singlePrincipalDistributorAllDetails.js +++ b/src/views/PrincipalDistributors/singlePrincipalDistributorAllDetails.js @@ -1,113 +1,21 @@ -import { debounce } from "lodash"; -import { - Dialog, - DialogTitle, - DialogContent, - DialogActions, - Grid, - Typography, - Box, - FormControl, - InputLabel, - Select, - MenuItem, - TextField, - TableContainer, - Paper, - Table, - TableHead, - TableRow, - TableCell, - TableBody, - Button, - TablePagination, - Skeleton, -} from "@mui/material"; +import { Typography, Button } from "@mui/material"; import axios from "axios"; import React, { useCallback, useEffect, useState, useRef } from "react"; import { Link, useParams, useNavigate } from "react-router-dom"; import swal from "sweetalert"; import { isAutheticated } from "src/auth"; -import InvoiceTable from "../orders/invoiceTable"; -import PendingOrderTable from "../orders/pendingOrderTable"; const SinglePrincipalDistributorAllDetails = () => { const [user, setUser] = useState(null); - const [userOrder, setUserOrder] = useState({ totalOrders: 0, totalValue: 0 }); + const [userOrder, setUserOrder] = useState({ + totalOrders: 0, + totalValue: 0, + lastPurchaseOrderDate: null, + }); const [userAllAddress, setUserAllAddress] = useState([]); - const [orders, setOrders] = useState([]); - const [totalOrders, setTotalOrders] = useState(0); - const [page, setPage] = useState(0); - const [rowsPerPage, setRowsPerPage] = useState(5); - const [loading, setLoading] = useState(true); - const [searchField, setSearchField] = useState("Order ID"); - const [searchText, setSearchText] = useState(""); const token = isAutheticated(); const { _id } = useParams(); - const searchOrderIdRef = useRef(""); - const searchStatusRef = useRef(""); - - // Debounced function to fetch orders - const fetchOrdersDebounced = useRef( - debounce((page, limit, orderId, status) => { - fetchOrders(page, limit, orderId, status); - }, 500) - ).current; - - const handleSearchFieldChange = (event) => { - const newSearchField = event.target.value; - setSearchField(newSearchField); - setSearchText(""); - - if (newSearchField === "Order ID") { - searchStatusRef.current = ""; - } else { - searchOrderIdRef.current = ""; - } - }; - - const handleSearchChange = (event) => { - setSearchText(event.target.value); - if (searchField === "Order ID") { - searchOrderIdRef.current = event.target.value; - } else { - searchStatusRef.current = event.target.value; - } - // Reset page to 0 and fetch orders with the new search term - setPage(0); - fetchOrdersDebounced( - 1, - rowsPerPage, - searchOrderIdRef.current, - searchStatusRef.current - ); - }; - const [openTMModal, setOpenTMModal] = useState(false); - const [singleorder, setSingleOrder] = useState(null); // State to hold fetched order details - - const handleCloseTMModal = () => { - setOpenTMModal(false); - setSingleOrder(null); // Clear the order details when closing the modal - }; - - // Function to fetch order details - const fetchOrderDetails = async (id) => { - try { - const response = await axios.get( - `/api/get-single-placed-order-pd/${id}`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); - setSingleOrder(response.data?.singleOrder); - setOpenTMModal(true); - } catch (error) { - console.error("Error fetching order details:", error); - } - }; // Fetch Shipping address of the individual user const getUserAddress = useCallback(async () => { @@ -172,51 +80,12 @@ const SinglePrincipalDistributorAllDetails = () => { } }, [_id, token]); - // Fetch Orders with Pagination, Order ID, and Status search - const fetchOrders = useCallback( - async (page = 1, limit = rowsPerPage, orderId = "", status = "") => { - setLoading(true); - try { - const response = await axios.get(`/api/single-pd-order/${_id}`, { - headers: { Authorization: `Bearer ${token}` }, - params: { page, limit, orderId, status }, - }); - setOrders(response.data.orders || []); - setTotalOrders(response.data.totalOrders || 0); - } catch (error) { - swal({ - title: "Warning", - text: error.message, - icon: "error", - button: "Close", - dangerMode: true, - }); - } finally { - setLoading(false); - } - }, - [_id, token, rowsPerPage] - ); - useEffect(() => { getOrdersCount(); getUserAddress(); getUserDetails(); }, [_id, getOrdersCount, getUserAddress, getUserDetails]); - useEffect(() => { - fetchOrders(page + 1, rowsPerPage, searchOrderIdRef.current, searchStatusRef.current); - }, [page, rowsPerPage]); - const handleChangePage = (event, newPage) => { - setPage(newPage); - }; - - // Handle rows per page change - const handleChangeRowsPerPage = (event) => { - const newRowsPerPage = parseInt(event.target.value, 10); - setRowsPerPage(newRowsPerPage); - setPage(0); - }; return (
@@ -296,9 +165,10 @@ const SinglePrincipalDistributorAllDetails = () => { }, { label: "Last Purchase", - value: - orders.length > 0 - ? new Date(orders[0]?.createdAt).toLocaleString("en-IN", { + value: userOrder?.lastPurchaseOrderDate + ? new Date(userOrder?.lastPurchaseOrderDate).toLocaleString( + "en-IN", + { weekday: "short", month: "short", day: "numeric", @@ -306,11 +176,20 @@ const SinglePrincipalDistributorAllDetails = () => { hour: "numeric", minute: "numeric", hour12: true, - }) - : "No Purchase", + } + ) + : "No Purchase", + }, + { + label: "Total Orders", + value: userOrder?.totalOrders ? userOrder?.totalOrders : 0, + }, + { + label: "Total Spent", + value: `₹ ${ + userOrder?.totalValue ? userOrder?.totalValue : 0 + }`, }, - { label: "Total Orders", value: userOrder?.totalOrders }, - { label: "Total Spent", value: `₹ ${userOrder?.totalValue}` }, ].map((item, index) => ( {
)}
-
-
• Orders
- - - - Search By - - - - - - - - - Order ID - Order Date - Items - Order Value - Status - Action - - - - {loading ? ( - - - Loading... - - - ) : orders.length === 0 ? ( - - - No Orders Found - - - ) : ( - orders.map((order) => ( - - {order.uniqueId} - - {new Date(order.createdAt).toLocaleString()} - - {order.orderItem.length} - ₹ {order.grandTotal} - {order.status} - - - - - )) - )} - -
-
- {/* Pagination */} - - - Order Details - Order Id : {singleorder?.uniqueId} - - {singleorder?.invoices?.length > 0 && ( - <> - - Invoices - - - - )} - - Order Summary - - - - - - - - - Product - Price (₹) - Quantity - Subtotal (₹) - GST (%) - GST Amount (₹) - - Total with GST (₹) - - - - - {singleorder?.orderItem.map((item, index) => { - const subtotal = item.price * item.quantity; - const gstAmount = - ((item.GST * item.price) / 100) * item.quantity; - const totalWithGST = subtotal + gstAmount; - - return ( - - - {item.productId.name} - - {item.productId.name} - - - - ₹{item.price} - - - {item.quantity} - - ₹{subtotal} - {item.GST}% - - ₹{gstAmount} - - - ₹{totalWithGST} - - - ); - })} - -
-
-
-
- {singleorder?.invoices?.length > 0 && ( - <> - - Order Items{" "} - {singleorder?.status == "pending" - ? "to be Processed" - : "Cancelled"} - - - - )} -
- - - -
-
-
); diff --git a/src/views/RetailDistributors/DistributorOrders.js b/src/views/RetailDistributors/DistributorOrders.js new file mode 100644 index 0000000..c8300f0 --- /dev/null +++ b/src/views/RetailDistributors/DistributorOrders.js @@ -0,0 +1,485 @@ +import React, { useState, useEffect, useRef, useCallback } from "react"; +import axios from "axios"; +import { + Box, + Typography, + Grid, + Paper, + IconButton, + Dialog, + DialogContent, + DialogTitle, + DialogActions, + FormControl, + InputLabel, + Select, + MenuItem, + TextField, + TableContainer, + Table, + TableHead, + TableRow, + TableCell, + TableBody, + Button, + TablePagination, +} from "@mui/material"; +import { useParams, useNavigate } from "react-router-dom"; +import { isAutheticated } from "../../auth"; +import CancelIcon from "@mui/icons-material/Cancel"; // Add this import +import { debounce } from "lodash"; +import InvoiceTable from "../orders/invoiceTable"; +import PendingOrderTable from "../orders/pendingOrderTable"; + +const SingleDistributorOrder = () => { + const { id } = useParams(); + const { distributortype } = useParams(); + const [distributorDetails, setdistributorDetails] = useState(null); + const [orders, setOrders] = useState([]); + const [totalOrders, setTotalOrders] = useState(0); + const [page, setPage] = useState(0); + const [rowsPerPage, setRowsPerPage] = useState(5); + const [loading, setLoading] = useState(true); + const [searchField, setSearchField] = useState("Order ID"); + const [searchText, setSearchText] = useState(""); + const [userOrder, setUserOrder] = useState({ + totalOrders: 0, + totalValue: 0, + lastPurchaseOrderDate: null, + }); + const token = isAutheticated(); + const navigate = useNavigate(); + const searchOrderIdRef = useRef(""); + const searchStatusRef = useRef(""); + // Debounced function to fetch orders + const fetchOrdersDebounced = useRef( + debounce((page, limit, orderId, status) => { + fetchOrders(page, limit, orderId, status); + }, 500) + ).current; + + const handleSearchFieldChange = (event) => { + const newSearchField = event.target.value; + setSearchField(newSearchField); + + setSearchText(""); + + if (newSearchField === "Order ID") { + searchStatusRef.current = ""; + } else { + searchOrderIdRef.current = ""; + } + }; + + // When search text is typed + const handleSearchChange = (event) => { + setSearchText(event.target.value); + if (searchField === "Order ID") { + searchOrderIdRef.current = event.target.value; + } else { + searchStatusRef.current = event.target.value; + } + + // Reset page to 0 and fetch orders with the new search term + setPage(0); + fetchOrdersDebounced( + 1, + rowsPerPage, + searchOrderIdRef.current, + searchStatusRef.current + ); + }; + const [openOrderModal, setopenOrderModal] = useState(false); + const [singleorder, setSingleOrder] = useState(null); + + const handleCloseOrderModal = () => { + setopenOrderModal(false); + setSingleOrder(null); + }; + // Function to fetch order details + const fetchOrderDetails = async (id) => { + try { + const response = await axios.get( + distributortype === "principaldistributor" + ? `/api/get-single-placed-order-pd/${id}` + : `/api/get-single-placed-order-rd/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + setSingleOrder(response.data?.singleOrder); + setopenOrderModal(true); + } catch (error) { + console.error("Error fetching order details:", error); + } + }; + const getUserDetails = useCallback(async () => { + try { + // Commented out the API call and using dummy data + const response = await axios.get( + distributortype === "principaldistributor" + ? `/api/v1/admin/user/${id}` + : `/api/getRD/${id}`, + { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + "Content-Type": "multipart/form-data", + }, + } + ); + distributortype === "principaldistributor"? setdistributorDetails(response.data.user): setdistributorDetails(response.data); + } catch (error) { + console.error("Error fetching data: ", error); + } + }, [id, token, distributortype]); + // Fetch Order Count and Total Value + const getOrdersCount = useCallback(async () => { + try { + const response = await axios.get( + distributortype === "principaldistributor" + ? `/api/single-pd-ordercount/${id}` + : `/api/single-rd-ordercount/${id}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + setUserOrder(response.data); + } catch (error) { + swal({ + title: "Warning", + text: error.message, + icon: "error", + button: "Close", + dangerMode: true, + }); + } + }, [id, token, distributortype]); + // Fetch Orders with Pagination, Order ID, and Status search + const fetchOrders = useCallback( + async (page = 1, limit = rowsPerPage, orderId = "", status = "") => { + setLoading(true); + try { + const response = await axios.get( + distributortype === "principaldistributor" + ? `/api/single-pd-order/${id}` + : `/api/single-rd-order/${id}`, + { + headers: { Authorization: `Bearer ${token}` }, + params: { page, limit, orderId, status }, + } + ); + setOrders(response.data.orders || []); + setTotalOrders(response.data.totalOrders || 0); + } catch (error) { + swal({ + title: "Warning", + text: error.message, + icon: "error", + button: "Close", + dangerMode: true, + }); + } finally { + setLoading(false); + } + }, + [id, token, rowsPerPage, distributortype] + ); + + useEffect(() => { + fetchOrders( + page + 1, + rowsPerPage, + searchOrderIdRef.current, + searchStatusRef.current + ); + }, [page, rowsPerPage]); + + useEffect(() => { + getUserDetails(); + getOrdersCount(); + }, [id, getUserDetails, getOrdersCount, distributortype]); + + const handleCancel = () => { + // Navigate based on distributor type + navigate( + distributortype === "principaldistributor" + ? "/principal-distributor" + : "/retail-distributor" + ); + }; + + if (!distributorDetails) { + return Loading...; + } + + // Handle page change + const handleChangePage = (event, newPage) => { + setPage(newPage); + }; + + // Handle rows per page change + const handleChangeRowsPerPage = (event) => { + const newRowsPerPage = parseInt(event.target.value, 10); + setRowsPerPage(newRowsPerPage); + setPage(0); + }; + return ( + + + {distributortype === "principaldistributor" ? "Principal Distributor Details":"Retail Distributor Details"} + + Cancel + + + + + + Distributor Details + + + + + Name: {distributorDetails.name} + + + Mobile Number:{" "} + {distributortype === "principaldistributor" + ? distributorDetails.phone + : distributorDetails.mobile_number} + + + Email: {distributorDetails.email} + + + + + Last Purchase:{" "} + {userOrder?.lastPurchaseOrderDate + ? new Date(userOrder?.lastPurchaseOrderDate).toLocaleString( + "en-IN", + { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + hour12: true, + } + ) + : "No Purchase"} + + + Total Orders:{" "} + {userOrder?.totalOrders ? userOrder?.totalOrders : 0} + + + Total Spent:{" "} + {userOrder?.totalValue ? userOrder?.totalValue : 0} + + + + + + + Orders + + + + + Search By + + + + + + + + + Order ID + Order Date + Items + Order Value + Status + Action + + + + {loading ? ( + + + Loading... + + + ) : orders.length === 0 ? ( + + + No Orders Found + + + ) : ( + orders.map((order) => ( + + {order.uniqueId} + + {new Date(order.createdAt).toLocaleString()} + + {order.orderItem.length} + ₹ {order.grandTotal} + {order.status} + + + + + )) + )} + +
+
+ {/* Pagination */} + + + Order Details + Order Id : {singleorder?.uniqueId} + + {singleorder?.invoices?.length > 0 && ( + <> + + Invoices + + + + )} + + Order Summary + + + + + + + + + Product + Price (₹) + Order Quantity + Subtotal (₹) + GST (%) + GST Amount (₹) + + Total with GST (₹) + + + + + {singleorder?.orderItem.map((item, index) => { + const subtotal = item.price * item.quantity; + const gstAmount = + ((item.GST * item.price) / 100) * item.quantity; + const totalWithGST = subtotal + gstAmount; + + return ( + + + {item.productId.name} + + {item.productId.name} + + + ₹{item.price} + + {item.quantity} + + ₹{subtotal} + {item.GST}% + ₹{gstAmount} + + ₹{totalWithGST} + + + ); + })} + +
+
+
+
+ {singleorder?.invoices?.length > 0 && ( + <> + + Order Items{" "} + {singleorder?.status == "pending" + ? "to be Processed" + : "Cancelled"} + + + + )} +
+ + + +
+
+
+
+ ); +}; + +export default SingleDistributorOrder; diff --git a/src/views/RetailDistributors/RetailDistributor.js b/src/views/RetailDistributors/RetailDistributor.js index 6897e6d..2629b85 100644 --- a/src/views/RetailDistributors/RetailDistributor.js +++ b/src/views/RetailDistributors/RetailDistributor.js @@ -14,9 +14,9 @@ const RetailDistributor = () => { const [allRetailDistributorsData, setAllRetailDistributorsData] = useState( [] ); -const nameRef = useRef(); -const principalDistributorRef = useRef(); -const [totalPages, setTotalPages] = useState(1); + const nameRef = useRef(); + const principalDistributorRef = useRef(); + const [totalPages, setTotalPages] = useState(1); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); const [totalData, setTotalData] = useState(0); @@ -55,12 +55,15 @@ const [totalPages, setTotalPages] = useState(1); useEffect(() => { getRetailDistributorsData(); - }, [ itemPerPage, currentPage]); + }, [itemPerPage, currentPage]); - const debouncedSearch = useCallback(debounce(() => { - setCurrentPage(1); - getRetailDistributorsData(); - }, 500), []); + const debouncedSearch = useCallback( + debounce(() => { + setCurrentPage(1); + getRetailDistributorsData(); + }, 500), + [] + ); const handleSearchChange = () => { debouncedSearch(); @@ -157,8 +160,8 @@ const [totalPages, setTotalPages] = useState(1); Principal Distributor Territory Manager Sales Coordinator - Mapping Orders + Mapping Action @@ -193,34 +196,50 @@ const [totalPages, setTotalPages] = useState(1); })} - {retailDistributor?.principalDetails - ?.name || "N/A"} + {retailDistributor?.principalDetails?.name || + "N/A"} - {retailDistributor?.mappedTMDetails?.name || "N/A"} + {retailDistributor?.mappedTMDetails?.name || + "N/A"} - {retailDistributor?.mappedSCDetails?.name || "N/A"} + {retailDistributor?.mappedSCDetails?.name || + "N/A"} - - + + - - - {retailDistributor?.totalOrders} - + + + + + + + + + - Showing {allRetailDistributorsData?.length} of {totalData} entries + Showing {allRetailDistributorsData?.length} of{" "} + {totalData} entries diff --git a/src/views/RetailDistributors/SingleRetailDistributor.js b/src/views/RetailDistributors/SingleRetailDistributor.js index 4fe6e3f..7d03fb4 100644 --- a/src/views/RetailDistributors/SingleRetailDistributor.js +++ b/src/views/RetailDistributors/SingleRetailDistributor.js @@ -10,103 +10,21 @@ import { Dialog, DialogContent, DialogTitle, - DialogActions, - FormControl, - InputLabel, - Select, - MenuItem, - TextField, - TableContainer, - Table, - TableHead, - TableRow, - TableCell, - TableBody, - Button, - TablePagination, } from "@mui/material"; import { useParams, useNavigate } from "react-router-dom"; import { format } from "date-fns"; import { isAutheticated } from "../../auth"; import CancelIcon from "@mui/icons-material/Cancel"; // Add this import -import { debounce } from "lodash"; -import InvoiceTable from "../orders/invoiceTable"; -import PendingOrderTable from "../orders/pendingOrderTable"; const SingleRetailDistributor = () => { const { id } = useParams(); const [retailerDetails, setRetailerDetails] = useState(null); const [openPopup, setOpenPopup] = useState(false); const [selectedImage, setSelectedImage] = useState(""); - const [orders, setOrders] = useState([]); - const [totalOrders, setTotalOrders] = useState(0); - const [page, setPage] = useState(0); - const [rowsPerPage, setRowsPerPage] = useState(5); - const [loading, setLoading] = useState(true); - const [searchField, setSearchField] = useState("Order ID"); - const [searchText, setSearchText] = useState(""); const token = isAutheticated(); const navigate = useNavigate(); - const searchOrderIdRef = useRef(""); - const searchStatusRef = useRef(""); - // Debounced function to fetch orders - const fetchOrdersDebounced = useRef( - debounce((page, limit, orderId, status) => { - fetchOrders(page, limit, orderId, status); - }, 500) - ).current; - - const handleSearchFieldChange = (event) => { - const newSearchField = event.target.value; - setSearchField(newSearchField); - - setSearchText(""); - - if (newSearchField === "Order ID") { - searchStatusRef.current = ""; - } else { - searchOrderIdRef.current = ""; - } - }; -// When search text is typed -const handleSearchChange = (event) => { - setSearchText(event.target.value); - if (searchField === "Order ID") { - searchOrderIdRef.current = event.target.value; - } else { - searchStatusRef.current = event.target.value; - } - - // Reset page to 0 and fetch orders with the new search term - setPage(0); - fetchOrdersDebounced(1, rowsPerPage, searchOrderIdRef.current, searchStatusRef.current); -}; - const [openOrderModal, setopenOrderModal] = useState(false); - const [singleorder, setSingleOrder] = useState(null); - - const handleCloseTMModal = () => { - setopenOrderModal(false); - setSingleOrder(null); // Clear the order details when closing the modal - }; - // Function to fetch order details - const fetchOrderDetails = async (id) => { - try { - const response = await axios.get( - `/api/get-single-placed-order-rd/${id}`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); - setSingleOrder(response.data?.singleOrder); - setopenOrderModal(true); - } catch (error) { - console.error("Error fetching order details:", error); - } - }; const getUserDetails = useCallback(async () => { try { // Commented out the API call and using dummy data @@ -123,35 +41,6 @@ const handleSearchChange = (event) => { console.error("Error fetching data: ", error); } }, [id, token]); - // Fetch Orders with Pagination, Order ID, and Status search - const fetchOrders = useCallback( - async (page = 1, limit = rowsPerPage, orderId = "", status = "") => { - setLoading(true); - try { - const response = await axios.get(`/api/single-rd-order/${id}`, { - headers: { Authorization: `Bearer ${token}` }, - params: { page, limit, orderId, status }, - }); - setOrders(response.data.orders || []); - setTotalOrders(response.data.totalOrders || 0); - } catch (error) { - swal({ - title: "Warning", - text: error.message, - icon: "error", - button: "Close", - dangerMode: true, - }); - } finally { - setLoading(false); - } - }, - [id, token, rowsPerPage] - ); - - useEffect(() => { - fetchOrders(page + 1, rowsPerPage, searchOrderIdRef.current, searchStatusRef.current); - }, [page, rowsPerPage]); // Fetch retailer details on mount useEffect(() => { @@ -176,17 +65,6 @@ useEffect(() => { return Loading...; } -// Handle page change -const handleChangePage = (event, newPage) => { - setPage(newPage); -}; - -// Handle rows per page change -const handleChangeRowsPerPage = (event) => { - const newRowsPerPage = parseInt(event.target.value, 10); - setRowsPerPage(newRowsPerPage); - setPage(0); -}; return ( { - - {/*
*/} - - Orders - - - - - Search By - - - - - - - - - Order ID - Order Date - Items - Order Value - Status - Action - - - - {loading ? ( - - - Loading... - - - ) : orders.length === 0 ? ( - - - No Orders Found - - - ) : ( - orders.map((order) => ( - - {order.uniqueId} - - {new Date(order.createdAt).toLocaleString()} - - {order.orderItem.length} - ₹ {order.grandTotal} - {order.status} - - - - - )) - )} - -
-
- {/* Pagination */} - - - Order Details - Order Id : {singleorder?.uniqueId} - - {singleorder?.invoices?.length > 0 && ( - <> - - Invoices - - - - )} - - Order Summary - - - - - - - - - Product - Price (₹) - Quantity - Subtotal (₹) - GST (%) - GST Amount (₹) - - Total with GST (₹) - - - - - {singleorder?.orderItem.map((item, index) => { - const subtotal = item.price * item.quantity; - const gstAmount = - ((item.GST * item.price) / 100) * item.quantity; - const totalWithGST = subtotal + gstAmount; - - return ( - - - {item.productId.name} - - {item.productId.name} - - - ₹{item.price} - - {item.quantity} - - ₹{subtotal} - {item.GST}% - ₹{gstAmount} - - ₹{totalWithGST} - - - ); - })} - -
-
-
-
- {singleorder?.invoices?.length > 0 && ( - <> - - Order Items{" "} - {singleorder?.status == "pending" - ? "to be Processed" - : "Cancelled"} - - - - )} -
- - - -
-
- {/*
*/} -
{ Product Price (₹) - Quantity + Order Quantity Subtotal (₹) GST (%) GST Amount (₹) @@ -353,7 +353,7 @@ const ViewOrders = () => { ₹{item.price} - {item.quantity} + {item.quantity} ₹{subtotal} {item.GST}% ₹{gstAmount} diff --git a/src/views/orders/invoiceTable.js b/src/views/orders/invoiceTable.js index 356687d..1ef0942 100644 --- a/src/views/orders/invoiceTable.js +++ b/src/views/orders/invoiceTable.js @@ -21,7 +21,7 @@ const InvoiceTable = ({ invoices }) => { Invoice ID - Items + Invoice Items Subtotal GST Total Invoice Amount diff --git a/src/views/orders/pendingOrderTable.js b/src/views/orders/pendingOrderTable.js index 87bef79..ca88f06 100644 --- a/src/views/orders/pendingOrderTable.js +++ b/src/views/orders/pendingOrderTable.js @@ -22,12 +22,12 @@ const PendingOrderTable = ({ order }) => { Product - Price (₹) - Quantity - Subtotal (₹) - GST (%) - GST Amount (₹) - Total with GST (₹) + Price (₹) + Pending Quantity + Subtotal (₹) + GST (%) + GST Amount (₹) + Total with GST (₹) @@ -55,14 +55,14 @@ const PendingOrderTable = ({ order }) => { {item.productId.name} - ₹{item.price} - + ₹{item.price} + {item.remainingQuantity} - ₹{subtotal} - {item.GST}% - ₹{gstAmount} - ₹{totalWithGST} + ₹{subtotal} + {item.GST}% + ₹{gstAmount} + ₹{totalWithGST} ); } diff --git a/src/views/orders/viewInoices.js b/src/views/orders/viewInoices.js index 15db7b2..7367bca 100644 --- a/src/views/orders/viewInoices.js +++ b/src/views/orders/viewInoices.js @@ -180,7 +180,7 @@ const ViewInvoices = () => { Invoice ID - Items + Invoice Items Subtotal GST Total Invoice Amount