This commit is contained in:
Sibunnayak 2024-10-04 10:31:39 +05:30
commit e9a74b3d63
2 changed files with 25 additions and 12 deletions

View File

@ -4,6 +4,8 @@ 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) => {
@ -28,9 +30,22 @@ export const createOrderRD = async (req, res) => {
return res.status(404).json({ message: "Retail Distributor not found" });
}
const pdId = rd.principal_distributer._id; // Get the associated PD
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,
});
}
// Create the order
const newOrder = new RdOrder({
paymentMode,
shipTo,
@ -674,7 +689,6 @@ 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" };
@ -733,14 +747,13 @@ 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: "PdOrder",
model: "RdOrder",
populate: {
path: "addedBy",
model: "RetailDistributor",
select: "name email phone ", // Select only specific fields
select: "name email mobile_number ",
},
});
if (!invoice) {
return res.status(404).json({ error: "Invoice not found" });
}
@ -1060,7 +1073,7 @@ export const updateCourierStatusToDeliveredForPD = async (req, res) => {
};
export const getDispatchedInvoicesForPd = async (req, res) => {
try {
const pdId = req.params.pdId; // Ensure this is passed in your route, or retrieve it from the logged-in user
const pdId = req.user._id; // 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;
@ -1121,7 +1134,7 @@ export const getDispatchedInvoicesForPd = async (req, res) => {
};
export const getDeliveredInvoicesForPd = async (req, res) => {
try {
const pdId = req.params.pdId; // Ensure this is passed in your route, or retrieve it from the logged-in user
const pdId = req.user._id; // 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("/invoice/dispatched/:invoiceId").put(
router.route("/pd-invoice/dispatched/:invoiceId").put(
isAuthenticatedUser,
updateCourierStatusToDispatchedForPD
);
router.route("/invoice/delivered/:invoiceId").put(
router.route("/pd-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;