Compare commits

..

No commits in common. "5cb19705eb0524b5fd763eed4f1c47877f4112bb" and "3e7452a484b42f7546da6e9f58fe5a77990dfaef" have entirely different histories.

2 changed files with 12 additions and 25 deletions

View File

@ -4,8 +4,6 @@ import RetailDistributor from "../RetailDistributor/RetailDistributorModel.js";
import { InvoiceRd } from "./invoiceModalRD.js";
import { RdOrder } from "./rdOrderModal.js";
import { PDStock } from "../Stock/PdStockModel.js";
import { createKYC } from "../../Utils/rejectKyc.js";
import { Notification } from "../Notification/notificationModal.js";
// Controller to create a new order by RD
export const createOrderRD = async (req, res) => {
@ -30,22 +28,9 @@ export const createOrderRD = async (req, res) => {
return res.status(404).json({ message: "Retail Distributor not found" });
}
const pdId = rd.principal_distributer._id;
if (pdId) {
await createKYC(
rd.principal_distributer._id,
"New order placed ",
`New Order placed.`
);
await Notification.create({
title: "New order placed ",
msg: `New order placed `,
added_for: rd.principal_distributer._id,
});
}
const pdId = rd.principal_distributer._id; // Get the associated PD
// Create the order
const newOrder = new RdOrder({
paymentMode,
shipTo,
@ -689,6 +674,7 @@ export const getProcessingInvoicesForPd = async (req, res) => {
if (!pdId) {
return res.status(400).json({ message: "PD ID is required" });
}
console.log(pdId);
// Build the base query for fetching processing invoices
let query = { courierStatus: "processing" };
@ -747,13 +733,14 @@ export const getInvoiceDetailsByIdForPD = async (req, res) => {
// Find the invoice by ID and populate the orderId and addedBy fields
const invoice = await InvoiceRd.findById(invoiceId).populate({
path: "orderId",
model: "RdOrder",
model: "PdOrder",
populate: {
path: "addedBy",
model: "RetailDistributor",
select: "name email mobile_number ",
select: "name email phone ", // Select only specific fields
},
});
if (!invoice) {
return res.status(404).json({ error: "Invoice not found" });
}
@ -1073,7 +1060,7 @@ export const updateCourierStatusToDeliveredForPD = async (req, res) => {
};
export const getDispatchedInvoicesForPd = async (req, res) => {
try {
const pdId = req.user._id; // Ensure this is passed in your route, or retrieve it from the logged-in user
const pdId = req.params.pdId; // Ensure this is passed in your route, or retrieve it from the logged-in user
const page = parseInt(req.query.page, 10) || 1; // Default page is 1
const limit = parseInt(req.query.limit, 10) || 5; // Default limit is 5
const skip = (page - 1) * limit;
@ -1134,7 +1121,7 @@ export const getDispatchedInvoicesForPd = async (req, res) => {
};
export const getDeliveredInvoicesForPd = async (req, res) => {
try {
const pdId = req.user._id; // Ensure this is passed in your route, or retrieve it from the logged-in user
const pdId = req.params.pdId; // Ensure this is passed in your route, or retrieve it from the logged-in user
const page = parseInt(req.query.page, 10) || 1; // Default page is 1
const limit = parseInt(req.query.limit, 10) || 5; // Default limit is 5
const skip = (page - 1) * limit;

View File

@ -70,18 +70,18 @@ router
router
.route("/pd-cancel-order/:id")
.put(isAuthenticatedUser, cancelOrderController);
router.route("/pd-invoice/dispatched/:invoiceId").put(
router.route("/invoice/dispatched/:invoiceId").put(
isAuthenticatedUser,
updateCourierStatusToDispatchedForPD
);
router.route("/pd-invoice/delivered/:invoiceId").put(
router.route("/invoice/delivered/:invoiceId").put(
isAuthenticatedUser,
updateCourierStatusToDeliveredForPD
);
router
.route("/single-rd-ordercount/:distributorId")
.get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
.route("/single-rd-ordercount/:distributorId")
.get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
export default router;