From c5469f7e6437a867bf26847ab34acb230b7c745e Mon Sep 17 00:00:00 2001 From: shabeelashraf5 <05shebz@gmail.com> Date: Mon, 20 Jan 2025 10:01:12 +0530 Subject: [PATCH] Modified All tables --- server/controller/accountingController.js | 5 ++--- server/controller/purchaseController.js | 2 +- server/controller/salesController.js | 14 +++++++++----- server/controller/shipmentController.js | 6 +++--- server/routes/shipment.js | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/server/controller/accountingController.js b/server/controller/accountingController.js index 41efc07..986e548 100644 --- a/server/controller/accountingController.js +++ b/server/controller/accountingController.js @@ -39,8 +39,7 @@ const loadInv = async (req, res) => { } } } - }) - .exec(); + }).sort({ createdAt: -1 }).exec(); console.log('invData:', invData); @@ -189,7 +188,7 @@ const loadTrans = async (req, res) => { } } } - }).exec(); + }).sort({ createdAt: -1 }).exec(); console.log('transData:', transData); diff --git a/server/controller/purchaseController.js b/server/controller/purchaseController.js index 98ce7f6..01c5cfb 100644 --- a/server/controller/purchaseController.js +++ b/server/controller/purchaseController.js @@ -26,7 +26,7 @@ const loadPo = async (req, res) => { path: 'salesRFQ_id', model: 'sales-rfq', select: 'srfq' - } }).exec(); + } }).sort({ createdAt: -1 }).exec(); console.log('Supplier PO:', supplierPO); if (!supplierPO || supplierPO.length === 0) { diff --git a/server/controller/salesController.js b/server/controller/salesController.js index a6790c1..1f00e4d 100644 --- a/server/controller/salesController.js +++ b/server/controller/salesController.js @@ -67,11 +67,15 @@ const loadRfq = async (req, res) => { res.setHeader('Cache-Control', 'no-cache, no-store'); - const customerRFQ = await salesRFQ.find({ employee_id: employeeId }).populate({ + const customerRFQ = await salesRFQ + .find({ employee_id: employeeId }) + .populate({ path: 'employee_id', - select: 'fname lname', - model: 'employee' - }).exec(); + select: 'fname lname', + model: 'employee', + }) + .sort({ createdAt: -1 }) // Sort by `createdAt` in descending order + .exec(); console.log('Customer RFQ:', customerRFQ); if (!customerRFQ || customerRFQ.length === 0) { @@ -244,7 +248,7 @@ const loadSalesOrder = async (req , res) => { path: 'employee_id', select: 'fname lname', model: 'employee' - }).populate({path: 'salesRFQ_id', select: 'srfq'}).exec(); + }).populate({path: 'salesRFQ_id', select: 'srfq'}).sort({ createdAt: -1 }).exec(); console.log('ClientDetails:',salesOrder); console.log(salesOrder) diff --git a/server/controller/shipmentController.js b/server/controller/shipmentController.js index a3e2fdd..268f263 100644 --- a/server/controller/shipmentController.js +++ b/server/controller/shipmentController.js @@ -4,7 +4,7 @@ let express = require('express'); const collectionshipment = require('../model/shipmentDB') -const loadInv = async (req, res) => { +const loadShip = async (req, res) => { try { @@ -41,7 +41,7 @@ const loadInv = async (req, res) => { } } } - }).exec(); + }).sort({ createdAt: -1 }).exec(); console.log('shipData:', shipData); @@ -84,7 +84,7 @@ const changeStatus = async (req , res) => { module.exports = { - loadInv, + loadShip, changeStatus } \ No newline at end of file diff --git a/server/routes/shipment.js b/server/routes/shipment.js index 3990ce3..fd209a3 100644 --- a/server/routes/shipment.js +++ b/server/routes/shipment.js @@ -7,7 +7,7 @@ const {verifyToken} = require('../token/tokenauth') -router.get('/shipment-history', verifyToken , shipmentController.loadInv) +router.get('/shipment-history', verifyToken , shipmentController.loadShip) router.put('/:id/update-status', verifyToken , shipmentController.changeStatus)