rd order andpd order fixed
This commit is contained in:
parent
68f120e854
commit
3e7452a484
@ -1477,11 +1477,15 @@ export const getAllOrdersByDistributor = async (req, res) => {
|
|||||||
export const gettotalorderandvalueofpd = async (req, res) => {
|
export const gettotalorderandvalueofpd = async (req, res) => {
|
||||||
const { distributorId } = req.params;
|
const { distributorId } = req.params;
|
||||||
try {
|
try {
|
||||||
const orders = await PdOrder.find({ addedBy: distributorId });
|
const orders = await PdOrder.find({ addedBy: distributorId }).sort({ createdAt: -1 });
|
||||||
|
|
||||||
const totalOrders = orders.length;
|
const totalOrders = orders.length;
|
||||||
const totalValue = orders.reduce((acc, order) => acc + order.grandTotal, 0);
|
const totalValue = orders.reduce((acc, order) => acc + order.grandTotal, 0).toFixed(2);
|
||||||
|
|
||||||
|
// Get the date of the last order
|
||||||
|
const lastPurchaseOrderDate = totalOrders > 0 ? orders[0].createdAt : null;
|
||||||
|
|
||||||
res.status(200).json({ totalOrders, totalValue });
|
res.status(200).json({ totalOrders, totalValue: parseFloat(totalValue), lastPurchaseOrderDate });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching orders:", error);
|
console.error("Error fetching orders:", error);
|
||||||
res.status(500).json({ message: "Server error", error });
|
res.status(500).json({ message: "Server error", error });
|
||||||
|
@ -1535,3 +1535,21 @@ export const getAllOrdersByDistributor = async (req, res) => {
|
|||||||
res.status(500).json({ message: "Server error", error });
|
res.status(500).json({ message: "Server error", error });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const gettotalorderandvalueofrd = async (req, res) => {
|
||||||
|
const { distributorId } = req.params;
|
||||||
|
try {
|
||||||
|
const orders = await RdOrder.find({ addedBy: distributorId }).sort({ createdAt: -1 });
|
||||||
|
|
||||||
|
const totalOrders = orders.length;
|
||||||
|
const totalValue = orders.reduce((acc, order) => acc + order.grandTotal, 0).toFixed(2);
|
||||||
|
|
||||||
|
// Get the date of the last order
|
||||||
|
const lastPurchaseOrderDate = totalOrders > 0 ? orders[0].createdAt : null;
|
||||||
|
|
||||||
|
res.status(200).json({ totalOrders, totalValue: parseFloat(totalValue), lastPurchaseOrderDate });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching orders:", error);
|
||||||
|
res.status(500).json({ message: "Server error", error });
|
||||||
|
}
|
||||||
|
};
|
@ -15,6 +15,7 @@ import {
|
|||||||
getProcessingInvoicesForPd,
|
getProcessingInvoicesForPd,
|
||||||
getSinglePlacedOrderForPD,
|
getSinglePlacedOrderForPD,
|
||||||
getSinglePlacedOrderForRD,
|
getSinglePlacedOrderForRD,
|
||||||
|
gettotalorderandvalueofrd,
|
||||||
processOrder,
|
processOrder,
|
||||||
updateCourierStatusToDeliveredForPD,
|
updateCourierStatusToDeliveredForPD,
|
||||||
updateCourierStatusToDispatchedForPD,
|
updateCourierStatusToDispatchedForPD,
|
||||||
@ -80,5 +81,7 @@ router.route("/invoice/delivered/:invoiceId").put(
|
|||||||
|
|
||||||
updateCourierStatusToDeliveredForPD
|
updateCourierStatusToDeliveredForPD
|
||||||
);
|
);
|
||||||
|
router
|
||||||
|
.route("/single-rd-ordercount/:distributorId")
|
||||||
|
.get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
Reference in New Issue
Block a user