diff --git a/src/index.js b/src/index.js index 8a829f2..0ab534a 100644 --- a/src/index.js +++ b/src/index.js @@ -15,9 +15,9 @@ import { cibGmail } from "@coreui/icons"; import { createRoot } from "react-dom/client"; const setupAxios = () => { - axios.defaults.baseURL = "http://localhost:5000"; + // axios.defaults.baseURL = "http://localhost:5000"; // axios.defaults.baseURL = "https://cheminova-api-2.onrender.com"; - // axios.defaults.baseURL = "https://api.cnapp.co.in"; + axios.defaults.baseURL = "https://api.cnapp.co.in"; axios.defaults.headers = { "Cache-Control": "no-cache,no-store", diff --git a/src/views/orders/DeliveredOrders.js b/src/views/orders/DeliveredOrders.js index 66c423c..4caf288 100644 --- a/src/views/orders/DeliveredOrders.js +++ b/src/views/orders/DeliveredOrders.js @@ -33,15 +33,19 @@ const ProcessingOrders = () => { const [searchText, setSearchText] = useState(""); const navigate = useNavigate(); const token = isAutheticated(); - const searchRef = useRef(); + const searchRef = useRef(); const fetchOrdersDebounced = useRef( debounce((page, limit, searchField, searchText) => { fetchOrders(page, limit, searchField, searchText); }, 500) ).current; - - const fetchOrders = async (page, limit, searchField = "", searchText = "") => { + const fetchOrders = async ( + page, + limit, + searchField = "", + searchText = "" + ) => { setLoading(true); try { const response = await axios.get("/api/get-delivered-invoice-admin", { @@ -50,8 +54,9 @@ const ProcessingOrders = () => { }, params: { limit, - page: page + 1, - [searchField === "Order ID" ? "orderId" : "invoiceId"]: searchText || "", + page: page + 1, + [searchField === "Order ID" ? "orderId" : "invoiceId"]: + searchText || "", }, }); setOrders(response?.data?.invoices); @@ -65,7 +70,7 @@ const ProcessingOrders = () => { useEffect(() => { fetchOrdersDebounced(page, rowsPerPage, searchField, searchText); - }, [page, rowsPerPage, searchField, searchText]); + }, [page, rowsPerPage, searchField, searchText]); const handleSearchChange = (event) => { const value = event.target.value; @@ -78,12 +83,12 @@ const ProcessingOrders = () => { }; const handleChangePage = (event, newPage) => { - setPage(newPage); + setPage(newPage); }; const handleChangeRowsPerPage = (event) => { setRowsPerPage(parseInt(event.target.value, 10)); - setPage(0); + setPage(0); }; return ( @@ -141,8 +146,12 @@ const ProcessingOrders = () => { {invoice.orderId.uniqueId} {invoice.invoiceId} - {new Date(invoice.courierstatus_timeline.delivered).toDateString()} - , {formatAMPM(invoice.courierstatus_timeline.delivered)} + {new Date( + invoice.courierstatus_timeline.delivered + ).toDateString()} + + , {formatAMPM(invoice.courierstatus_timeline.delivered)} + {invoice.items.length} {invoice.invoiceAmount} @@ -152,7 +161,9 @@ const ProcessingOrders = () => { variant="contained" color="primary" onClick={() => - navigate(`/orders/${invoice.courierStatus}/${invoice._id}`) + navigate( + `/orders/invoice/${invoice.courierStatus}/${invoice._id}` + ) } > View @@ -174,7 +185,7 @@ const ProcessingOrders = () => { component="div" count={totalOrders} rowsPerPage={rowsPerPage} - page={page} + page={page} onPageChange={handleChangePage} onRowsPerPageChange={handleChangeRowsPerPage} /> diff --git a/src/views/orders/DispatchedOrders.js b/src/views/orders/DispatchedOrders.js index aad1602..e257e01 100644 --- a/src/views/orders/DispatchedOrders.js +++ b/src/views/orders/DispatchedOrders.js @@ -33,15 +33,19 @@ const ProcessingOrders = () => { const [searchText, setSearchText] = useState(""); const navigate = useNavigate(); const token = isAutheticated(); - const searchRef = useRef(); + const searchRef = useRef(); const fetchOrdersDebounced = useRef( debounce((page, limit, searchField, searchText) => { fetchOrders(page, limit, searchField, searchText); }, 500) ).current; - - const fetchOrders = async (page, limit, searchField = "", searchText = "") => { + const fetchOrders = async ( + page, + limit, + searchField = "", + searchText = "" + ) => { setLoading(true); try { const response = await axios.get("/api/get-dispatched-invoice-admin", { @@ -50,8 +54,9 @@ const ProcessingOrders = () => { }, params: { limit, - page: page + 1, - [searchField === "Order ID" ? "orderId" : "invoiceId"]: searchText || "", + page: page + 1, + [searchField === "Order ID" ? "orderId" : "invoiceId"]: + searchText || "", }, }); setOrders(response?.data?.invoices); @@ -65,7 +70,7 @@ const ProcessingOrders = () => { useEffect(() => { fetchOrdersDebounced(page, rowsPerPage, searchField, searchText); - }, [page, rowsPerPage, searchField, searchText]); + }, [page, rowsPerPage, searchField, searchText]); const handleSearchChange = (event) => { const value = event.target.value; @@ -78,12 +83,12 @@ const ProcessingOrders = () => { }; const handleChangePage = (event, newPage) => { - setPage(newPage); + setPage(newPage); }; const handleChangeRowsPerPage = (event) => { setRowsPerPage(parseInt(event.target.value, 10)); - setPage(0); + setPage(0); }; return ( @@ -141,8 +146,12 @@ const ProcessingOrders = () => { {invoice.orderId.uniqueId} {invoice.invoiceId} - {new Date(invoice.courierstatus_timeline.dispatched).toDateString()} - , {formatAMPM(invoice.courierstatus_timeline.dispatched)} + {new Date( + invoice.courierstatus_timeline.dispatched + ).toDateString()} + + , {formatAMPM(invoice.courierstatus_timeline.dispatched)} + {invoice.items.length} {invoice.invoiceAmount} @@ -152,7 +161,9 @@ const ProcessingOrders = () => { variant="contained" color="primary" onClick={() => - navigate(`/orders/${invoice.courierStatus}/${invoice._id}`) + navigate( + `/orders/invoice/${invoice.courierStatus}/${invoice._id}` + ) } > View @@ -174,7 +185,7 @@ const ProcessingOrders = () => { component="div" count={totalOrders} rowsPerPage={rowsPerPage} - page={page} + page={page} onPageChange={handleChangePage} onRowsPerPageChange={handleChangeRowsPerPage} /> diff --git a/src/views/orders/ProcessingOrders.js b/src/views/orders/ProcessingOrders.js index 7ab46d5..22a7822 100644 --- a/src/views/orders/ProcessingOrders.js +++ b/src/views/orders/ProcessingOrders.js @@ -33,15 +33,19 @@ const ProcessingOrders = () => { const [searchText, setSearchText] = useState(""); const navigate = useNavigate(); const token = isAutheticated(); - const searchRef = useRef(); + const searchRef = useRef(); const fetchOrdersDebounced = useRef( debounce((page, limit, searchField, searchText) => { fetchOrders(page, limit, searchField, searchText); }, 500) ).current; - - const fetchOrders = async (page, limit, searchField = "", searchText = "") => { + const fetchOrders = async ( + page, + limit, + searchField = "", + searchText = "" + ) => { setLoading(true); try { const response = await axios.get("/api/get-processing-invoice-admin", { @@ -50,8 +54,9 @@ const ProcessingOrders = () => { }, params: { limit, - page: page + 1, - [searchField === "Order ID" ? "orderId" : "invoiceId"]: searchText || "", + page: page + 1, + [searchField === "Order ID" ? "orderId" : "invoiceId"]: + searchText || "", }, }); setOrders(response?.data?.invoices); @@ -65,7 +70,7 @@ const ProcessingOrders = () => { useEffect(() => { fetchOrdersDebounced(page, rowsPerPage, searchField, searchText); - }, [page, rowsPerPage, searchField, searchText]); + }, [page, rowsPerPage, searchField, searchText]); const handleSearchChange = (event) => { const value = event.target.value; @@ -78,12 +83,12 @@ const ProcessingOrders = () => { }; const handleChangePage = (event, newPage) => { - setPage(newPage); + setPage(newPage); }; const handleChangeRowsPerPage = (event) => { setRowsPerPage(parseInt(event.target.value, 10)); - setPage(0); + setPage(0); }; return ( @@ -141,8 +146,12 @@ const ProcessingOrders = () => { {invoice.orderId.uniqueId} {invoice.invoiceId} - {new Date(invoice.courierstatus_timeline.processing).toDateString()} - , {formatAMPM(invoice.courierstatus_timeline.processing)} + {new Date( + invoice.courierstatus_timeline.processing + ).toDateString()} + + , {formatAMPM(invoice.courierstatus_timeline.processing)} + {invoice.items.length} {invoice.invoiceAmount} @@ -152,7 +161,9 @@ const ProcessingOrders = () => { variant="contained" color="primary" onClick={() => - navigate(`/orders/${invoice.courierStatus}/${invoice._id}`) + navigate( + `/orders/invoice/${invoice.courierStatus}/${invoice._id}` + ) } > View @@ -174,7 +185,7 @@ const ProcessingOrders = () => { component="div" count={totalOrders} rowsPerPage={rowsPerPage} - page={page} + page={page} onPageChange={handleChangePage} onRowsPerPageChange={handleChangeRowsPerPage} /> diff --git a/src/views/orders/viewInoices.js b/src/views/orders/viewInoices.js index d4677ef..697712b 100644 --- a/src/views/orders/viewInoices.js +++ b/src/views/orders/viewInoices.js @@ -18,6 +18,7 @@ import { DialogTitle, TextField, Divider, + Chip, } from "@mui/material"; import onvoicesData from "../../assets/incoicedata.json"; import { useNavigate, useParams } from "react-router-dom"; @@ -52,20 +53,18 @@ const ViewInvoices = () => { useEffect(() => { const fetchOrderDetails = async () => { try { - const response = await axios.get( - `/api/get-single-placed-order-pd/${id}`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); + const response = await axios.get(`/api/invoice/details/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); console.log(response); - setOrder(response.data.singleOrder); - setStatus(response.data.singleOrder?.status); + setInvoice(response.data); + setStatus(response.data.courierStatus); setLoading(false); } catch (err) { + console.log(err); setError("Failed to fetch order details"); setLoading(false); } @@ -79,53 +78,40 @@ const ViewInvoices = () => { }; const handleUpdateClick = () => { - if (orderStatus === "dispatched") { + if (invoiceStatus === "dispatched") { setOpenDispatchDialog(true); - } else if (orderStatus === "partial-processing") { - setOpnePartialModal(true); - } else if (orderStatus === "cancelled") { - setOpenCancelDialog(true); - } else if (orderStatus === "delivered") { + } else if (invoiceStatus === "delivered") { setOpenDeliveredDialog(true); - } else { } }; const handleConfirmUpdate = async (e) => { e.preventDefault(); try { - if (orderStatus === "cancelled") { - if (!cancellationReason) { - Swal.fire("Please give the order cancellation reason"); - } - const cancellationRes = await axios.put( - `/api/cancel-order/${id}`, + if (invoiceStatus === "dispatched") { + const res = await axios.put( + `/api/invoice/dispatched/${id}`, { - cancellationReason: cancellationReason, - }, - { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - } - ); - if (cancellationRes.status === 200) { - Swal.fire( - "Order Status updated", - `Order got cancelled due to${cancellationReason}`, - "success" - ); - navigate(`/orders/${orderStatus}`); - } - } else if (orderStatus === "dispatched") { - const cancellationRes = await axios.patch( - `/api/change/status/${id}`, - { - status: orderStatus, courierName, - TrackingID: couriertrackingId, + couriertrackingId, }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + console.log(res); + if (res.status === 200) { + Swal.fire("Invoice Status updated", "Invoice Dispatched", "success"); + navigate(`/orders/dispatched`); + } + } else if (invoiceStatus === "delivered") { + const deli = await axios.put( + `/api/invoice/delivered/${id}`, + {}, + { headers: { "Access-Control-Allow-Origin": "*", @@ -133,65 +119,16 @@ const ViewInvoices = () => { }, } ); - if (cancellationRes.status === 200) { + + if (deli.status === 200) { Swal.fire("Order Status updated", `Order Dispatched`, "success"); - navigate(`/orders/${orderStatus}`); - } - } else if (orderStatus === "delivered") { - if (!deliveryDate) { - Swal.fire("Please enter the Delivery Date"); - setOpenDeliveredDialog(false); - return; - } - const cancellationRes = await axios.patch( - `/api/change/status/${id}`, - { - status: orderStatus, - DDate: deliveryDate, - }, - { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - } - ); - if (cancellationRes.status === 200) { - Swal.fire("Order Status updated", `Order in processing`, "success"); - navigate(`/orders/${orderStatus}`); - } - } else if (orderStatus === "processing") { - const processingOrderInvoice = order?.orderItem - .filter((item) => item.remainingQuantity > 0) // Only include items with remainingQuantity > 0 - .map((item) => ({ - ...item, - productId: item.productId._id, - processquantity: item.remainingQuantity, // Add processquantity only for items with remainingQuantity > 0 - })); - console.log(processingOrderInvoice); - const cancellationRes = await axios.post( - `/api/processing-order`, - { - invoiceItems: processingOrderInvoice, - orderId: order._id, - }, - { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - } - ); - if (cancellationRes.status === 200) { - Swal.fire("Order Status updated", `Order in processing`, "success"); - navigate(`/orders/${orderStatus}`); + navigate(`/orders/delivered`); } } } catch (error) { Swal.fire("Something went wrong ", error.message, "error"); } - // Perform update logic here setOpenDispatchDialog(false); @@ -220,7 +157,7 @@ const ViewInvoices = () => { mb={5} > - Invoice Id : {order?.uniqueId} + Invoice Id : {invoice?.invoiceId} { Invoice - + {/* */} + + + + + Invoice ID - + Items + Subtotal + GST Total + Invoice Amount + Courier Status + + + + + {invoice.invoiceId} + + + {invoice.items.map((item) => ( + + {item.name} ({item.SKU}) x{" "} + {item.processquantity} + + ))} + + {invoice.subtotal} + {invoice.gstTotal} + {invoice.invoiceAmount} + + + + + + + + + {/* Order Summary @@ -258,7 +239,7 @@ const ViewInvoices = () => { - {order?.orderItem.map((item, index) => { + {invoice?.orderId?.orderItem.map((item, index) => { const subtotal = item.price * item.quantity; const gstAmount = ((item.GST * item.price) / 100) * item.quantity; @@ -293,7 +274,7 @@ const ViewInvoices = () => { - + */} @@ -306,17 +287,15 @@ const ViewInvoices = () => { }} > - Order Summary + Invoice Summary - - Total Items: {order?.orderItem.length} - + Total Items: {invoice?.items.length} - Total Subtotal: ₹{order?.subtotal} - Total GST: ₹{order?.gstTotal} + Total Subtotal: ₹{invoice?.subtotal} + Total GST: ₹{invoice?.gstTotal} - Grand Total: ₹{order?.grandTotal} + Grand Total: ₹{invoice?.invoiceAmount} @@ -337,50 +316,54 @@ const ViewInvoices = () => { Customer Details - SBU: {order?.addedBy.SBU} + SBU: {invoice?.orderId?.addedBy.SBU} - Name: {order?.addedBy.name} + Name: {invoice?.orderId?.addedBy.name} - Email id: {order?.addedBy.email} + Email id: {invoice?.orderId?.addedBy.email} - Number: {order?.addedBy.phone} + Number: {invoice?.orderId?.addedBy.phone} Bill Address - {order?.billTo} + + {invoice?.orderId?.billTo} + Ship Address - {order?.shipTo} + + {invoice?.orderId?.shipTo} + Payment mode - {order?.paymentMode} + {invoice?.orderId?.paymentMode} - + {/* Order Status {order?.status} - {order?.status === "cancelled" && ( + {invoice?.courierStatus === "cancelled" && ( {order?.order_Cancelled_Reason} )} - + */} {invoice?.status !== "delivered" && ( @@ -388,7 +371,7 @@ const ViewInvoices = () => { {status === "processing" && ( <> @@ -406,7 +389,7 @@ const ViewInvoices = () => { )} - {orderStatus && ( + {invoiceStatus && ( { Update Order Status - Are you sure you want to update the status to {orderStatus}? + Are you sure you want to update the status to {invoiceStatus}? @@ -482,37 +465,6 @@ const ViewInvoices = () => { - {/* Dialog for cancellation reason */} - - Cancellation Reason - - - - Please provide a reason for cancelling the order: - - setCancellationReason(e.target.value)} - /> - - - - Cancel - - - Confirm - - - - - - {/* Dialog for delivery confirmation */} Confirm Delivery @@ -552,14 +504,6 @@ const ViewInvoices = () => { - - {/* partial processing */} - ); };