Compare commits

..

No commits in common. "208d35600926353236128f5fe3e0d4258e034ff2" and "8222e2177083bddf6e33071572a9d7dfeede75a1" have entirely different histories.

View File

@ -877,7 +877,7 @@ export const getInvoiceDetailsById = async (req, res) => {
export const updateCourierStatusToDispatched = async (req, res) => {
const { invoiceId } = req.params;
const { courierName, couriertrackingId, transporterName } = req.body;
const { courierName, couriertrackingId } = req.body;
try {
// Find the invoice by ID
const invoice = await Invoice.findById(invoiceId).populate({
@ -896,7 +896,6 @@ export const updateCourierStatusToDispatched = async (req, res) => {
invoice.courierstatus_timeline.dispatched = new Date();
invoice.courier_name = courierName;
invoice.courier_tracking_id = couriertrackingId;
invoice.transpoter_Name = transporterName;
// Save the updated invoice
await invoice.save();
@ -1478,25 +1477,15 @@ export const getAllOrdersByDistributor = async (req, res) => {
export const gettotalorderandvalueofpd = async (req, res) => {
const { distributorId } = req.params;
try {
const orders = await PdOrder.find({ addedBy: distributorId }).sort({
createdAt: -1,
});
const orders = await PdOrder.find({ addedBy: distributorId }).sort({ createdAt: -1 });
const totalOrders = orders.length;
const totalValue = orders
.reduce((acc, order) => acc + order.grandTotal, 0)
.toFixed(2);
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,
});
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 });