diff --git a/src/index.js b/src/index.js index 32935e5..8a829f2 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 = "https://cheminova-api-2.onrender.com"; - axios.defaults.baseURL = "https://api.cnapp.co.in"; + 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.headers = { "Cache-Control": "no-cache,no-store", diff --git a/src/views/orders/ViewOrders.js b/src/views/orders/ViewOrders.js index 7db94ce..25d7a3f 100644 --- a/src/views/orders/ViewOrders.js +++ b/src/views/orders/ViewOrders.js @@ -8,25 +8,23 @@ import { Dialog, DialogActions, DialogContent, + Table, + TableBody, + TableCell, + TableHead, + TableRow, + Paper, DialogContentText, DialogTitle, TextField, - Card, - CardMedia, - CardContent, Divider, - Paper, - Table, - TableHead, - TableRow, - TableCell, - TableBody, } from "@mui/material"; import { useNavigate, useParams } from "react-router-dom"; import { TableContainer } from "@material-ui/core"; import axios from "axios"; // Import axios for HTTP requests import { isAutheticated } from "src/auth"; import Swal from "sweetalert2"; +import OrderDetailsDialog from "./partialOrderModal"; const ViewOrders = () => { const [order, setOrder] = useState(null); // State to store order details @@ -44,7 +42,9 @@ const ViewOrders = () => { const [loading, setLoading] = useState(true); // Loading state const [error, setError] = useState(null); // Error state const navigate = useNavigate(); - const { id } = useParams(); // Get order ID from URL params + const { id } = useParams(); + const [parialModal, setOpnePartialModal] = useState(false); + // Get order ID from URL params useEffect(() => { const fetchOrderDetails = async () => { @@ -78,6 +78,8 @@ const ViewOrders = () => { const handleUpdateClick = () => { if (orderStatus === "dispatched") { setOpenDispatchDialog(true); + } else if (orderStatus === "partial-processing") { + setOpnePartialModal(true); } else if (orderStatus === "cancelled") { setOpenCancelDialog(true); } else if (orderStatus === "delivered") { @@ -94,10 +96,9 @@ const ViewOrders = () => { if (!cancellationReason) { Swal.fire("Please give the order cancellation reason"); } - const cancellationRes = await axios.patch( - `/api/change/status/${id}`, + const cancellationRes = await axios.put( + `/api/cancel-order/${id}`, { - status: orderStatus, ReasonforCancellation: cancellationReason, }, { @@ -159,10 +160,16 @@ const ViewOrders = () => { navigate(`/orders/${orderStatus}`); } } else if (orderStatus === "processing") { - const cancellationRes = await axios.patch( - `/api/change/status/${id}`, + const processingOrderInvoice = order?.orderItem.map((item) => ({ + ...item, + processquantity: item.quantity, + })); + console.log(""); + const cancellationRes = await axios.post( + `/api/processing-order`, { - status: orderStatus, + invoiceItems: processingOrderInvoice, + orderId: order._id, }, { headers: { @@ -180,6 +187,7 @@ const ViewOrders = () => { Swal.fire("Something went wrong ", error.message, "error"); } // Perform update logic here + setOpnePartialModal(false); setOpenConfirmDialog(false); setOpenDispatchDialog(false); setOpenCancelDialog(false); @@ -192,6 +200,32 @@ const ViewOrders = () => { setOpenCancelDialog(false); setOpenDeliveredDialog(false); // Close delivered dialog }; + const handlePartialOrderClose = () => { + setOpnePartialModal(false); + }; + const handlePartialProcess = async (availability) => { + try { + const cancellationRes = await axios.post( + `/api/processing-order`, + { + invoiceItems: availability, + 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}`); + } + } catch (error) { + Swal.fire("Something went wrong ", error.message, "error"); + } + }; const timelineData = [ { event: "Order Placed On", date: order?.createdAt }, @@ -238,48 +272,58 @@ const ViewOrders = () => { - {order?.orderItem.map((item, index) => ( - - - - - - {item.productId.name} - - - Price:₹{item.price} - - - Quantity: {item.quantity} - - - Subtotal: ₹{item.price * item.quantity} - - - GST ({item.GST}%): ₹ - {((item.GST * item.price) / 100) * item.quantity} - - - Total with GST: ₹{" "} - {((item.GST * item.price) / 100) * item.quantity + - item.price * item.quantity} - - - - - ))} + + + + + + Product + Price (₹) + Quantity + Subtotal (₹) + GST (%) + GST Amount (₹) + Total with GST (₹) + + + + {order?.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} + + ); + })} + +
+
+
+ { <> + )} @@ -593,6 +640,14 @@ const ViewOrders = () => { + + {/* partial processing */} + ); }; diff --git a/src/views/orders/partialOrderModal.js b/src/views/orders/partialOrderModal.js new file mode 100644 index 0000000..9f8f68f --- /dev/null +++ b/src/views/orders/partialOrderModal.js @@ -0,0 +1,128 @@ +import React, { useState } from "react"; +import { + Dialog, + DialogActions, + DialogContent, + DialogTitle, + Button, + TextField, + Typography, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Paper, + Grid, +} from "@mui/material"; + +const OrderDetailsDialog = ({ open, onClose, order, onSubmit }) => { + // Create a state to store availability input for each product + const [availability, setAvailability] = useState( + order?.orderItem.map((item) => ({ + ...item, // Keep all original properties from orderItem + processquantity: item.quantity, // Add availability field with default value equal to quantity + })) + ); + + // Handle input change for availability + const handleAvailabilityChange = (index, value) => { + const updatedAvailability = [...availability]; + const newValue = Math.max( + 0, + Math.min(value, updatedAvailability[index].quantity) + ); // Ensure value is between 0 and available quantity + updatedAvailability[index].processquantity = newValue; + setAvailability(updatedAvailability); + }; + + // Handle form submission + const handleSubmit = () => { + onSubmit(availability); // Pass updated availability to parent component + onClose(); // Close modal + }; + + return ( + + Modify Product Availability + + + + + + + + Product + Price (₹) + Quantity + Availability + Subtotal (₹) + GST (%) + GST Amount (₹) + Total with GST (₹) + + + + {order?.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} + + + handleAvailabilityChange( + index, + Number(e.target.value) + ) + } + inputProps={{ + min: 0, + max: item.quantity, + }} + style={{ width: "60px", textAlign: "center" }} + /> + + ₹{subtotal} + {item.GST}% + ₹{gstAmount} + ₹{totalWithGST} + + ); + })} + +
+
+
+
+
+ + + + +
+ ); +}; + +export default OrderDetailsDialog;