Compare commits
No commits in common. "5cb19705eb0524b5fd763eed4f1c47877f4112bb" and "3e7452a484b42f7546da6e9f58fe5a77990dfaef" have entirely different histories.
5cb19705eb
...
3e7452a484
@ -4,8 +4,6 @@ import RetailDistributor from "../RetailDistributor/RetailDistributorModel.js";
|
|||||||
import { InvoiceRd } from "./invoiceModalRD.js";
|
import { InvoiceRd } from "./invoiceModalRD.js";
|
||||||
import { RdOrder } from "./rdOrderModal.js";
|
import { RdOrder } from "./rdOrderModal.js";
|
||||||
import { PDStock } from "../Stock/PdStockModel.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
|
// Controller to create a new order by RD
|
||||||
export const createOrderRD = async (req, res) => {
|
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" });
|
return res.status(404).json({ message: "Retail Distributor not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const pdId = rd.principal_distributer._id;
|
const pdId = rd.principal_distributer._id; // Get the associated PD
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Create the order
|
||||||
const newOrder = new RdOrder({
|
const newOrder = new RdOrder({
|
||||||
paymentMode,
|
paymentMode,
|
||||||
shipTo,
|
shipTo,
|
||||||
@ -689,6 +674,7 @@ export const getProcessingInvoicesForPd = async (req, res) => {
|
|||||||
if (!pdId) {
|
if (!pdId) {
|
||||||
return res.status(400).json({ message: "PD ID is required" });
|
return res.status(400).json({ message: "PD ID is required" });
|
||||||
}
|
}
|
||||||
|
console.log(pdId);
|
||||||
|
|
||||||
// Build the base query for fetching processing invoices
|
// Build the base query for fetching processing invoices
|
||||||
let query = { courierStatus: "processing" };
|
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
|
// Find the invoice by ID and populate the orderId and addedBy fields
|
||||||
const invoice = await InvoiceRd.findById(invoiceId).populate({
|
const invoice = await InvoiceRd.findById(invoiceId).populate({
|
||||||
path: "orderId",
|
path: "orderId",
|
||||||
model: "RdOrder",
|
model: "PdOrder",
|
||||||
populate: {
|
populate: {
|
||||||
path: "addedBy",
|
path: "addedBy",
|
||||||
model: "RetailDistributor",
|
model: "RetailDistributor",
|
||||||
select: "name email mobile_number ",
|
select: "name email phone ", // Select only specific fields
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!invoice) {
|
if (!invoice) {
|
||||||
return res.status(404).json({ error: "Invoice not found" });
|
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) => {
|
export const getDispatchedInvoicesForPd = async (req, res) => {
|
||||||
try {
|
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 page = parseInt(req.query.page, 10) || 1; // Default page is 1
|
||||||
const limit = parseInt(req.query.limit, 10) || 5; // Default limit is 5
|
const limit = parseInt(req.query.limit, 10) || 5; // Default limit is 5
|
||||||
const skip = (page - 1) * limit;
|
const skip = (page - 1) * limit;
|
||||||
@ -1134,7 +1121,7 @@ export const getDispatchedInvoicesForPd = async (req, res) => {
|
|||||||
};
|
};
|
||||||
export const getDeliveredInvoicesForPd = async (req, res) => {
|
export const getDeliveredInvoicesForPd = async (req, res) => {
|
||||||
try {
|
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 page = parseInt(req.query.page, 10) || 1; // Default page is 1
|
||||||
const limit = parseInt(req.query.limit, 10) || 5; // Default limit is 5
|
const limit = parseInt(req.query.limit, 10) || 5; // Default limit is 5
|
||||||
const skip = (page - 1) * limit;
|
const skip = (page - 1) * limit;
|
||||||
|
@ -70,18 +70,18 @@ router
|
|||||||
router
|
router
|
||||||
.route("/pd-cancel-order/:id")
|
.route("/pd-cancel-order/:id")
|
||||||
.put(isAuthenticatedUser, cancelOrderController);
|
.put(isAuthenticatedUser, cancelOrderController);
|
||||||
router.route("/pd-invoice/dispatched/:invoiceId").put(
|
router.route("/invoice/dispatched/:invoiceId").put(
|
||||||
isAuthenticatedUser,
|
isAuthenticatedUser,
|
||||||
|
|
||||||
updateCourierStatusToDispatchedForPD
|
updateCourierStatusToDispatchedForPD
|
||||||
);
|
);
|
||||||
|
|
||||||
router.route("/pd-invoice/delivered/:invoiceId").put(
|
router.route("/invoice/delivered/:invoiceId").put(
|
||||||
isAuthenticatedUser,
|
isAuthenticatedUser,
|
||||||
|
|
||||||
updateCourierStatusToDeliveredForPD
|
updateCourierStatusToDeliveredForPD
|
||||||
);
|
);
|
||||||
router
|
router
|
||||||
.route("/single-rd-ordercount/:distributorId")
|
.route("/single-rd-ordercount/:distributorId")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
Reference in New Issue
Block a user