diff --git a/src/views/orders/ViewOrders.js b/src/views/orders/ViewOrders.js index af7eeeb..93e3ba7 100644 --- a/src/views/orders/ViewOrders.js +++ b/src/views/orders/ViewOrders.js @@ -102,7 +102,7 @@ const ViewOrders = () => { const cancellationRes = await axios.put( `/api/cancel-order/${id}`, { - ReasonforCancellation: cancellationReason, + cancellationReason: cancellationReason, }, { headers: { @@ -163,12 +163,14 @@ const ViewOrders = () => { navigate(`/orders/${orderStatus}`); } } else if (orderStatus === "processing") { - const processingOrderInvoice = order?.orderItem.map((item) => ({ + const processingOrderInvoice = order?.orderItem + .filter((item) => item.remainingQuantity > 0) // Only include items with remainingQuantity > 0 + .map((item) => ({ ...item, productId: item.productId._id, - processquantity: item.quantity, - })); - console.log(""); + processquantity: item.remainingQuantity, // Add processquantity only for items with remainingQuantity > 0 + })); + console.log(processingOrderInvoice); const cancellationRes = await axios.post( `/api/processing-order`, { @@ -208,31 +210,33 @@ const ViewOrders = () => { setOpnePartialModal(false); }; const handlePartialProcess = async (availability) => { - const prepareData = availability.map( - ({ - productId, - SKU, - name, - categoryName, - brandName, - price, - GST, - HSN_Code, - description, - processquantity, - }) => ({ - productId: productId._id, - SKU, - name, - categoryName, - brandName, - price, - GST, - HSN_Code, - description, - processquantity, - }) - ); + const prepareData = availability + .filter(({ processquantity }) => processquantity > 0) + .map( + ({ + productId, + SKU, + name, + categoryName, + brandName, + price, + GST, + HSN_Code, + description, + processquantity, + }) => ({ + productId: productId._id, + SKU, + name, + categoryName, + brandName, + price, + GST, + HSN_Code, + description, + processquantity, + }) + ); console.log(prepareData); try { @@ -251,7 +255,7 @@ const ViewOrders = () => { ); if (cancellationRes.status === 200) { Swal.fire("Order Status updated", `Order in processing`, "success"); - navigate(`/orders/${orderStatus}`); + navigate(`/orders/pending`); } } catch (error) { Swal.fire("Something went wrong ", error.message, "error"); @@ -528,6 +532,7 @@ const ViewOrders = () => { )} {status === "pending" && ( <> +