small fix :

This commit is contained in:
ROSHAN GARG 2024-11-04 10:31:18 +05:30
parent 53a020c3cf
commit efd5e01dbb

View File

@ -877,7 +877,7 @@ export const getInvoiceDetailsById = async (req, res) => {
export const updateCourierStatusToDispatched = async (req, res) => { export const updateCourierStatusToDispatched = async (req, res) => {
const { invoiceId } = req.params; const { invoiceId } = req.params;
const { courierName, couriertrackingId } = req.body; const { courierName, couriertrackingId, transporterName } = req.body;
try { try {
// Find the invoice by ID // Find the invoice by ID
const invoice = await Invoice.findById(invoiceId).populate({ const invoice = await Invoice.findById(invoiceId).populate({
@ -896,6 +896,7 @@ export const updateCourierStatusToDispatched = async (req, res) => {
invoice.courierstatus_timeline.dispatched = new Date(); invoice.courierstatus_timeline.dispatched = new Date();
invoice.courier_name = courierName; invoice.courier_name = courierName;
invoice.courier_tracking_id = couriertrackingId; invoice.courier_tracking_id = couriertrackingId;
invoice.transpoter_Name = transporterName;
// Save the updated invoice // Save the updated invoice
await invoice.save(); await invoice.save();
@ -1095,7 +1096,7 @@ export const updateCourierStatusToDelivered = async (req, res) => {
} }
// Check if PDStock exists for the user // Check if PDStock exists for the user
let pdStock = await PDStock.findOne({ userId }); let pdStock = await PDStock.findOne({ userId });
if (!pdStock) { if (!pdStock) {
// If no stock record exists, create a new one // If no stock record exists, create a new one
pdStock = new PDStock({ pdStock = new PDStock({
@ -1371,7 +1372,7 @@ export const getAllOrdersByDistributor = async (req, res) => {
const page = parseInt(req.query.page, 10) || 1; const page = parseInt(req.query.page, 10) || 1;
const limit = parseInt(req.query.limit, 10) || 5; const limit = parseInt(req.query.limit, 10) || 5;
const skip = (page - 1) * limit; const skip = (page - 1) * limit;
// console.log(distributorId, orderId, status, page, limit, skip); // console.log(distributorId, orderId, status, page, limit, skip);
try { try {
let orders; let orders;
@ -1477,15 +1478,25 @@ 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 }).sort({ createdAt: -1 }); 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).toFixed(2); const totalValue = orders
.reduce((acc, order) => acc + order.grandTotal, 0)
.toFixed(2);
// Get the date of the last order // Get the date of the last order
const lastPurchaseOrderDate = totalOrders > 0 ? orders[0].createdAt : null; 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) { } 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 });