order related things done
This commit is contained in:
parent
0bf978357d
commit
05c9d902ff
@ -15,9 +15,9 @@ import { cibGmail } from "@coreui/icons";
|
|||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
|
|
||||||
const setupAxios = () => {
|
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://cheminova-api-2.onrender.com";
|
||||||
// axios.defaults.baseURL = "https://api.cnapp.co.in";
|
axios.defaults.baseURL = "https://api.cnapp.co.in";
|
||||||
|
|
||||||
axios.defaults.headers = {
|
axios.defaults.headers = {
|
||||||
"Cache-Control": "no-cache,no-store",
|
"Cache-Control": "no-cache,no-store",
|
||||||
|
@ -33,15 +33,19 @@ const ProcessingOrders = () => {
|
|||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
const searchRef = useRef();
|
const searchRef = useRef();
|
||||||
const fetchOrdersDebounced = useRef(
|
const fetchOrdersDebounced = useRef(
|
||||||
debounce((page, limit, searchField, searchText) => {
|
debounce((page, limit, searchField, searchText) => {
|
||||||
fetchOrders(page, limit, searchField, searchText);
|
fetchOrders(page, limit, searchField, searchText);
|
||||||
}, 500)
|
}, 500)
|
||||||
).current;
|
).current;
|
||||||
|
|
||||||
|
const fetchOrders = async (
|
||||||
const fetchOrders = async (page, limit, searchField = "", searchText = "") => {
|
page,
|
||||||
|
limit,
|
||||||
|
searchField = "",
|
||||||
|
searchText = ""
|
||||||
|
) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios.get("/api/get-delivered-invoice-admin", {
|
const response = await axios.get("/api/get-delivered-invoice-admin", {
|
||||||
@ -50,8 +54,9 @@ const ProcessingOrders = () => {
|
|||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
limit,
|
limit,
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
[searchField === "Order ID" ? "orderId" : "invoiceId"]: searchText || "",
|
[searchField === "Order ID" ? "orderId" : "invoiceId"]:
|
||||||
|
searchText || "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setOrders(response?.data?.invoices);
|
setOrders(response?.data?.invoices);
|
||||||
@ -65,7 +70,7 @@ const ProcessingOrders = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchOrdersDebounced(page, rowsPerPage, searchField, searchText);
|
fetchOrdersDebounced(page, rowsPerPage, searchField, searchText);
|
||||||
}, [page, rowsPerPage, searchField, searchText]);
|
}, [page, rowsPerPage, searchField, searchText]);
|
||||||
|
|
||||||
const handleSearchChange = (event) => {
|
const handleSearchChange = (event) => {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
@ -78,12 +83,12 @@ const ProcessingOrders = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChangePage = (event, newPage) => {
|
const handleChangePage = (event, newPage) => {
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
const handleChangeRowsPerPage = (event) => {
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
setRowsPerPage(parseInt(event.target.value, 10));
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -141,8 +146,12 @@ const ProcessingOrders = () => {
|
|||||||
<TableCell>{invoice.orderId.uniqueId}</TableCell>
|
<TableCell>{invoice.orderId.uniqueId}</TableCell>
|
||||||
<TableCell>{invoice.invoiceId}</TableCell>
|
<TableCell>{invoice.invoiceId}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(invoice.courierstatus_timeline.delivered).toDateString()}
|
{new Date(
|
||||||
<span>, {formatAMPM(invoice.courierstatus_timeline.delivered)}</span>
|
invoice.courierstatus_timeline.delivered
|
||||||
|
).toDateString()}
|
||||||
|
<span>
|
||||||
|
, {formatAMPM(invoice.courierstatus_timeline.delivered)}
|
||||||
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{invoice.items.length}</TableCell>
|
<TableCell>{invoice.items.length}</TableCell>
|
||||||
<TableCell>{invoice.invoiceAmount}</TableCell>
|
<TableCell>{invoice.invoiceAmount}</TableCell>
|
||||||
@ -152,7 +161,9 @@ const ProcessingOrders = () => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/orders/${invoice.courierStatus}/${invoice._id}`)
|
navigate(
|
||||||
|
`/orders/invoice/${invoice.courierStatus}/${invoice._id}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
View
|
View
|
||||||
@ -174,7 +185,7 @@ const ProcessingOrders = () => {
|
|||||||
component="div"
|
component="div"
|
||||||
count={totalOrders}
|
count={totalOrders}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
page={page}
|
page={page}
|
||||||
onPageChange={handleChangePage}
|
onPageChange={handleChangePage}
|
||||||
onRowsPerPageChange={handleChangeRowsPerPage}
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
||||||
/>
|
/>
|
||||||
|
@ -33,15 +33,19 @@ const ProcessingOrders = () => {
|
|||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
const searchRef = useRef();
|
const searchRef = useRef();
|
||||||
const fetchOrdersDebounced = useRef(
|
const fetchOrdersDebounced = useRef(
|
||||||
debounce((page, limit, searchField, searchText) => {
|
debounce((page, limit, searchField, searchText) => {
|
||||||
fetchOrders(page, limit, searchField, searchText);
|
fetchOrders(page, limit, searchField, searchText);
|
||||||
}, 500)
|
}, 500)
|
||||||
).current;
|
).current;
|
||||||
|
|
||||||
|
const fetchOrders = async (
|
||||||
const fetchOrders = async (page, limit, searchField = "", searchText = "") => {
|
page,
|
||||||
|
limit,
|
||||||
|
searchField = "",
|
||||||
|
searchText = ""
|
||||||
|
) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios.get("/api/get-dispatched-invoice-admin", {
|
const response = await axios.get("/api/get-dispatched-invoice-admin", {
|
||||||
@ -50,8 +54,9 @@ const ProcessingOrders = () => {
|
|||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
limit,
|
limit,
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
[searchField === "Order ID" ? "orderId" : "invoiceId"]: searchText || "",
|
[searchField === "Order ID" ? "orderId" : "invoiceId"]:
|
||||||
|
searchText || "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setOrders(response?.data?.invoices);
|
setOrders(response?.data?.invoices);
|
||||||
@ -65,7 +70,7 @@ const ProcessingOrders = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchOrdersDebounced(page, rowsPerPage, searchField, searchText);
|
fetchOrdersDebounced(page, rowsPerPage, searchField, searchText);
|
||||||
}, [page, rowsPerPage, searchField, searchText]);
|
}, [page, rowsPerPage, searchField, searchText]);
|
||||||
|
|
||||||
const handleSearchChange = (event) => {
|
const handleSearchChange = (event) => {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
@ -78,12 +83,12 @@ const ProcessingOrders = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChangePage = (event, newPage) => {
|
const handleChangePage = (event, newPage) => {
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
const handleChangeRowsPerPage = (event) => {
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
setRowsPerPage(parseInt(event.target.value, 10));
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -141,8 +146,12 @@ const ProcessingOrders = () => {
|
|||||||
<TableCell>{invoice.orderId.uniqueId}</TableCell>
|
<TableCell>{invoice.orderId.uniqueId}</TableCell>
|
||||||
<TableCell>{invoice.invoiceId}</TableCell>
|
<TableCell>{invoice.invoiceId}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(invoice.courierstatus_timeline.dispatched).toDateString()}
|
{new Date(
|
||||||
<span>, {formatAMPM(invoice.courierstatus_timeline.dispatched)}</span>
|
invoice.courierstatus_timeline.dispatched
|
||||||
|
).toDateString()}
|
||||||
|
<span>
|
||||||
|
, {formatAMPM(invoice.courierstatus_timeline.dispatched)}
|
||||||
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{invoice.items.length}</TableCell>
|
<TableCell>{invoice.items.length}</TableCell>
|
||||||
<TableCell>{invoice.invoiceAmount}</TableCell>
|
<TableCell>{invoice.invoiceAmount}</TableCell>
|
||||||
@ -152,7 +161,9 @@ const ProcessingOrders = () => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/orders/${invoice.courierStatus}/${invoice._id}`)
|
navigate(
|
||||||
|
`/orders/invoice/${invoice.courierStatus}/${invoice._id}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
View
|
View
|
||||||
@ -174,7 +185,7 @@ const ProcessingOrders = () => {
|
|||||||
component="div"
|
component="div"
|
||||||
count={totalOrders}
|
count={totalOrders}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
page={page}
|
page={page}
|
||||||
onPageChange={handleChangePage}
|
onPageChange={handleChangePage}
|
||||||
onRowsPerPageChange={handleChangeRowsPerPage}
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
||||||
/>
|
/>
|
||||||
|
@ -33,15 +33,19 @@ const ProcessingOrders = () => {
|
|||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
const searchRef = useRef();
|
const searchRef = useRef();
|
||||||
const fetchOrdersDebounced = useRef(
|
const fetchOrdersDebounced = useRef(
|
||||||
debounce((page, limit, searchField, searchText) => {
|
debounce((page, limit, searchField, searchText) => {
|
||||||
fetchOrders(page, limit, searchField, searchText);
|
fetchOrders(page, limit, searchField, searchText);
|
||||||
}, 500)
|
}, 500)
|
||||||
).current;
|
).current;
|
||||||
|
|
||||||
|
const fetchOrders = async (
|
||||||
const fetchOrders = async (page, limit, searchField = "", searchText = "") => {
|
page,
|
||||||
|
limit,
|
||||||
|
searchField = "",
|
||||||
|
searchText = ""
|
||||||
|
) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios.get("/api/get-processing-invoice-admin", {
|
const response = await axios.get("/api/get-processing-invoice-admin", {
|
||||||
@ -50,8 +54,9 @@ const ProcessingOrders = () => {
|
|||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
limit,
|
limit,
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
[searchField === "Order ID" ? "orderId" : "invoiceId"]: searchText || "",
|
[searchField === "Order ID" ? "orderId" : "invoiceId"]:
|
||||||
|
searchText || "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setOrders(response?.data?.invoices);
|
setOrders(response?.data?.invoices);
|
||||||
@ -65,7 +70,7 @@ const ProcessingOrders = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchOrdersDebounced(page, rowsPerPage, searchField, searchText);
|
fetchOrdersDebounced(page, rowsPerPage, searchField, searchText);
|
||||||
}, [page, rowsPerPage, searchField, searchText]);
|
}, [page, rowsPerPage, searchField, searchText]);
|
||||||
|
|
||||||
const handleSearchChange = (event) => {
|
const handleSearchChange = (event) => {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
@ -78,12 +83,12 @@ const ProcessingOrders = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChangePage = (event, newPage) => {
|
const handleChangePage = (event, newPage) => {
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
const handleChangeRowsPerPage = (event) => {
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
setRowsPerPage(parseInt(event.target.value, 10));
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -141,8 +146,12 @@ const ProcessingOrders = () => {
|
|||||||
<TableCell>{invoice.orderId.uniqueId}</TableCell>
|
<TableCell>{invoice.orderId.uniqueId}</TableCell>
|
||||||
<TableCell>{invoice.invoiceId}</TableCell>
|
<TableCell>{invoice.invoiceId}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(invoice.courierstatus_timeline.processing).toDateString()}
|
{new Date(
|
||||||
<span>, {formatAMPM(invoice.courierstatus_timeline.processing)}</span>
|
invoice.courierstatus_timeline.processing
|
||||||
|
).toDateString()}
|
||||||
|
<span>
|
||||||
|
, {formatAMPM(invoice.courierstatus_timeline.processing)}
|
||||||
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{invoice.items.length}</TableCell>
|
<TableCell>{invoice.items.length}</TableCell>
|
||||||
<TableCell>{invoice.invoiceAmount}</TableCell>
|
<TableCell>{invoice.invoiceAmount}</TableCell>
|
||||||
@ -152,7 +161,9 @@ const ProcessingOrders = () => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/orders/${invoice.courierStatus}/${invoice._id}`)
|
navigate(
|
||||||
|
`/orders/invoice/${invoice.courierStatus}/${invoice._id}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
View
|
View
|
||||||
@ -174,7 +185,7 @@ const ProcessingOrders = () => {
|
|||||||
component="div"
|
component="div"
|
||||||
count={totalOrders}
|
count={totalOrders}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
page={page}
|
page={page}
|
||||||
onPageChange={handleChangePage}
|
onPageChange={handleChangePage}
|
||||||
onRowsPerPageChange={handleChangeRowsPerPage}
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
||||||
/>
|
/>
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
TextField,
|
TextField,
|
||||||
Divider,
|
Divider,
|
||||||
|
Chip,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import onvoicesData from "../../assets/incoicedata.json";
|
import onvoicesData from "../../assets/incoicedata.json";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
@ -52,20 +53,18 @@ const ViewInvoices = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchOrderDetails = async () => {
|
const fetchOrderDetails = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(
|
const response = await axios.get(`/api/invoice/details/${id}`, {
|
||||||
`/api/get-single-placed-order-pd/${id}`,
|
headers: {
|
||||||
{
|
Authorization: `Bearer ${token}`,
|
||||||
headers: {
|
},
|
||||||
Authorization: `Bearer ${token}`,
|
});
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
setOrder(response.data.singleOrder);
|
setInvoice(response.data);
|
||||||
setStatus(response.data.singleOrder?.status);
|
setStatus(response.data.courierStatus);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
setError("Failed to fetch order details");
|
setError("Failed to fetch order details");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@ -79,53 +78,40 @@ const ViewInvoices = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdateClick = () => {
|
const handleUpdateClick = () => {
|
||||||
if (orderStatus === "dispatched") {
|
if (invoiceStatus === "dispatched") {
|
||||||
setOpenDispatchDialog(true);
|
setOpenDispatchDialog(true);
|
||||||
} else if (orderStatus === "partial-processing") {
|
} else if (invoiceStatus === "delivered") {
|
||||||
setOpnePartialModal(true);
|
|
||||||
} else if (orderStatus === "cancelled") {
|
|
||||||
setOpenCancelDialog(true);
|
|
||||||
} else if (orderStatus === "delivered") {
|
|
||||||
setOpenDeliveredDialog(true);
|
setOpenDeliveredDialog(true);
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmUpdate = async (e) => {
|
const handleConfirmUpdate = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
if (orderStatus === "cancelled") {
|
if (invoiceStatus === "dispatched") {
|
||||||
if (!cancellationReason) {
|
const res = await axios.put(
|
||||||
Swal.fire("Please give the order cancellation reason");
|
`/api/invoice/dispatched/${id}`,
|
||||||
}
|
|
||||||
const cancellationRes = await axios.put(
|
|
||||||
`/api/cancel-order/${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,
|
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: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
"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");
|
Swal.fire("Order Status updated", `Order Dispatched`, "success");
|
||||||
|
|
||||||
navigate(`/orders/${orderStatus}`);
|
navigate(`/orders/delivered`);
|
||||||
}
|
|
||||||
} 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}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Swal.fire("Something went wrong ", error.message, "error");
|
Swal.fire("Something went wrong ", error.message, "error");
|
||||||
}
|
}
|
||||||
// Perform update logic here
|
|
||||||
|
|
||||||
setOpenDispatchDialog(false);
|
setOpenDispatchDialog(false);
|
||||||
|
|
||||||
@ -220,7 +157,7 @@ const ViewInvoices = () => {
|
|||||||
mb={5}
|
mb={5}
|
||||||
>
|
>
|
||||||
<Typography variant="h4" sx={{ flexGrow: 1, textAlign: "center" }}>
|
<Typography variant="h4" sx={{ flexGrow: 1, textAlign: "center" }}>
|
||||||
Invoice Id : {order?.uniqueId}
|
Invoice Id : {invoice?.invoiceId}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
@ -236,9 +173,53 @@ const ViewInvoices = () => {
|
|||||||
<Typography variant="h4" gutterBottom>
|
<Typography variant="h4" gutterBottom>
|
||||||
Invoice
|
Invoice
|
||||||
</Typography>
|
</Typography>
|
||||||
<InvoiceTable invoices={invoice} />
|
{/* <InvoiceTable invoices={invoice} /> */}
|
||||||
|
<TableContainer component={Paper}>
|
||||||
|
<Table>
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>Invoice ID</TableCell>
|
||||||
|
|
||||||
<Typography variant="h4" my={3} gutterBottom>
|
<TableCell>Items</TableCell>
|
||||||
|
<TableCell>Subtotal</TableCell>
|
||||||
|
<TableCell>GST Total</TableCell>
|
||||||
|
<TableCell>Invoice Amount</TableCell>
|
||||||
|
<TableCell>Courier Status</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow key={invoice.invoiceId}>
|
||||||
|
<TableCell>{invoice.invoiceId}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
{invoice.items.map((item) => (
|
||||||
|
<div key={item.productId}>
|
||||||
|
{item.name} ({item.SKU}) x{" "}
|
||||||
|
<b>{item.processquantity}</b>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{invoice.subtotal}</TableCell>
|
||||||
|
<TableCell>{invoice.gstTotal}</TableCell>
|
||||||
|
<TableCell>{invoice.invoiceAmount}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Chip
|
||||||
|
label={invoice.courierStatus}
|
||||||
|
color={
|
||||||
|
invoice.courierStatus === "delivered"
|
||||||
|
? "success"
|
||||||
|
: invoice.courierStatus === "dispatched"
|
||||||
|
? "primary"
|
||||||
|
: "warning"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
|
||||||
|
{/* <Typography variant="h4" my={3} gutterBottom>
|
||||||
Order Summary
|
Order Summary
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
@ -258,7 +239,7 @@ const ViewInvoices = () => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{order?.orderItem.map((item, index) => {
|
{invoice?.orderId?.orderItem.map((item, index) => {
|
||||||
const subtotal = item.price * item.quantity;
|
const subtotal = item.price * item.quantity;
|
||||||
const gstAmount =
|
const gstAmount =
|
||||||
((item.GST * item.price) / 100) * item.quantity;
|
((item.GST * item.price) / 100) * item.quantity;
|
||||||
@ -293,7 +274,7 @@ const ViewInvoices = () => {
|
|||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid> */}
|
||||||
|
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid item sm={6} md={6} xl={6}>
|
<Grid item sm={6} md={6} xl={6}>
|
||||||
@ -306,17 +287,15 @@ const ViewInvoices = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="h5" gutterBottom>
|
<Typography variant="h5" gutterBottom>
|
||||||
Order Summary
|
Invoice Summary
|
||||||
</Typography>
|
</Typography>
|
||||||
<Divider sx={{ marginBottom: 2 }} />
|
<Divider sx={{ marginBottom: 2 }} />
|
||||||
<Typography>
|
<Typography>Total Items: {invoice?.items.length}</Typography>
|
||||||
Total Items: {order?.orderItem.length}
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Typography>Total Subtotal: ₹{order?.subtotal}</Typography>
|
<Typography>Total Subtotal: ₹{invoice?.subtotal}</Typography>
|
||||||
<Typography>Total GST: ₹{order?.gstTotal}</Typography>
|
<Typography>Total GST: ₹{invoice?.gstTotal}</Typography>
|
||||||
<Typography variant="h5" sx={{ marginTop: 2 }}>
|
<Typography variant="h5" sx={{ marginTop: 2 }}>
|
||||||
Grand Total: ₹{order?.grandTotal}
|
Grand Total: ₹{invoice?.invoiceAmount}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -337,50 +316,54 @@ const ViewInvoices = () => {
|
|||||||
Customer Details
|
Customer Details
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
<strong>SBU:</strong> {order?.addedBy.SBU}
|
<strong>SBU:</strong> {invoice?.orderId?.addedBy.SBU}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
<strong>Name:</strong> {order?.addedBy.name}
|
<strong>Name:</strong> {invoice?.orderId?.addedBy.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
<strong>Email id:</strong> {order?.addedBy.email}
|
<strong>Email id:</strong> {invoice?.orderId?.addedBy.email}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
<strong>Number:</strong> {order?.addedBy.phone}
|
<strong>Number:</strong> {invoice?.orderId?.addedBy.phone}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={6} md={6} lg={6}>
|
<Grid item sm={6} md={6} lg={6}>
|
||||||
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
||||||
Bill Address
|
Bill Address
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>{order?.billTo}</Typography>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
|
{invoice?.orderId?.billTo}
|
||||||
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={6} md={6} lg={6}>
|
<Grid item sm={6} md={6} lg={6}>
|
||||||
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
||||||
Ship Address
|
Ship Address
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>{order?.shipTo}</Typography>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
|
{invoice?.orderId?.shipTo}
|
||||||
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={6} md={6} lg={6}>
|
<Grid item sm={6} md={6} lg={6}>
|
||||||
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
||||||
Payment mode
|
Payment mode
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>
|
<Typography sx={{ mb: "0.5rem" }}>
|
||||||
{order?.paymentMode}
|
{invoice?.orderId?.paymentMode}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item sm={12} md={12} lg={12}>
|
{/* <Grid item sm={12} md={12} lg={12}>
|
||||||
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
<Typography variant="h5" sx={{ mb: "0.5rem" }}>
|
||||||
Order Status
|
Order Status
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ mb: "0.5rem" }}>{order?.status}</Typography>
|
<Typography sx={{ mb: "0.5rem" }}>{order?.status}</Typography>
|
||||||
{order?.status === "cancelled" && (
|
{invoice?.courierStatus === "cancelled" && (
|
||||||
<Typography sx={{ mb: "0.5rem", color: "red" }}>
|
<Typography sx={{ mb: "0.5rem", color: "red" }}>
|
||||||
{order?.order_Cancelled_Reason}
|
{order?.order_Cancelled_Reason}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid> */}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
{invoice?.status !== "delivered" && (
|
{invoice?.status !== "delivered" && (
|
||||||
@ -388,7 +371,7 @@ const ViewInvoices = () => {
|
|||||||
<select
|
<select
|
||||||
className="form-control"
|
className="form-control"
|
||||||
onChange={handleStatusChange}
|
onChange={handleStatusChange}
|
||||||
value={orderStatus}
|
value={invoiceStatus}
|
||||||
>
|
>
|
||||||
{status === "processing" && (
|
{status === "processing" && (
|
||||||
<>
|
<>
|
||||||
@ -406,7 +389,7 @@ const ViewInvoices = () => {
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{orderStatus && (
|
{invoiceStatus && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
@ -424,7 +407,7 @@ const ViewInvoices = () => {
|
|||||||
<DialogTitle>Update Order Status</DialogTitle>
|
<DialogTitle>Update Order Status</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContentText>
|
<DialogContentText>
|
||||||
Are you sure you want to update the status to {orderStatus}?
|
Are you sure you want to update the status to {invoiceStatus}?
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
@ -482,37 +465,6 @@ const ViewInvoices = () => {
|
|||||||
</form>
|
</form>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
{/* Dialog for cancellation reason */}
|
|
||||||
<Dialog open={openCancelDialog} onClose={handleCancel}>
|
|
||||||
<DialogTitle>Cancellation Reason</DialogTitle>
|
|
||||||
<form onSubmit={handleConfirmUpdate}>
|
|
||||||
<DialogContent>
|
|
||||||
<DialogContentText>
|
|
||||||
Please provide a reason for cancelling the order:
|
|
||||||
</DialogContentText>
|
|
||||||
<TextField
|
|
||||||
autoFocus
|
|
||||||
required
|
|
||||||
margin="dense"
|
|
||||||
label="Cancellation Reason"
|
|
||||||
fullWidth
|
|
||||||
variant="outlined"
|
|
||||||
value={cancellationReason}
|
|
||||||
onChange={(e) => setCancellationReason(e.target.value)}
|
|
||||||
/>
|
|
||||||
</DialogContent>
|
|
||||||
<DialogActions>
|
|
||||||
<Button onClick={handleCancel} color="primary">
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" variant="contained" color="success" autoFocus>
|
|
||||||
Confirm
|
|
||||||
</Button>
|
|
||||||
</DialogActions>
|
|
||||||
</form>
|
|
||||||
</Dialog>
|
|
||||||
|
|
||||||
{/* Dialog for delivery confirmation */}
|
|
||||||
<Dialog open={openDeliveredDialog} onClose={handleCancel}>
|
<Dialog open={openDeliveredDialog} onClose={handleCancel}>
|
||||||
<DialogTitle>Confirm Delivery</DialogTitle>
|
<DialogTitle>Confirm Delivery</DialogTitle>
|
||||||
<form onSubmit={handleConfirmUpdate}>
|
<form onSubmit={handleConfirmUpdate}>
|
||||||
@ -552,14 +504,6 @@ const ViewInvoices = () => {
|
|||||||
</DialogActions>
|
</DialogActions>
|
||||||
</form>
|
</form>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
{/* partial processing */}
|
|
||||||
<OrderDetailsDialog
|
|
||||||
open={parialModal}
|
|
||||||
onClose={handlePartialOrderClose}
|
|
||||||
order={order}
|
|
||||||
onSubmit={handlePartialProcess}
|
|
||||||
/>
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user