Merge branch 'main' of https://git.cnapp.co.in/gitadmin/api
This commit is contained in:
commit
e9a74b3d63
@ -4,6 +4,8 @@ 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) => {
|
||||||
@ -28,9 +30,22 @@ 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; // 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({
|
const newOrder = new RdOrder({
|
||||||
paymentMode,
|
paymentMode,
|
||||||
shipTo,
|
shipTo,
|
||||||
@ -674,7 +689,6 @@ 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" };
|
||||||
@ -733,14 +747,13 @@ 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: "PdOrder",
|
model: "RdOrder",
|
||||||
populate: {
|
populate: {
|
||||||
path: "addedBy",
|
path: "addedBy",
|
||||||
model: "RetailDistributor",
|
model: "RetailDistributor",
|
||||||
select: "name email phone ", // Select only specific fields
|
select: "name email mobile_number ",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!invoice) {
|
if (!invoice) {
|
||||||
return res.status(404).json({ error: "Invoice not found" });
|
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) => {
|
export const getDispatchedInvoicesForPd = async (req, res) => {
|
||||||
try {
|
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 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;
|
||||||
@ -1121,7 +1134,7 @@ export const getDispatchedInvoicesForPd = async (req, res) => {
|
|||||||
};
|
};
|
||||||
export const getDeliveredInvoicesForPd = async (req, res) => {
|
export const getDeliveredInvoicesForPd = async (req, res) => {
|
||||||
try {
|
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 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,13 +70,13 @@ router
|
|||||||
router
|
router
|
||||||
.route("/pd-cancel-order/:id")
|
.route("/pd-cancel-order/:id")
|
||||||
.put(isAuthenticatedUser, cancelOrderController);
|
.put(isAuthenticatedUser, cancelOrderController);
|
||||||
router.route("/invoice/dispatched/:invoiceId").put(
|
router.route("/pd-invoice/dispatched/:invoiceId").put(
|
||||||
isAuthenticatedUser,
|
isAuthenticatedUser,
|
||||||
|
|
||||||
updateCourierStatusToDispatchedForPD
|
updateCourierStatusToDispatchedForPD
|
||||||
);
|
);
|
||||||
|
|
||||||
router.route("/invoice/delivered/:invoiceId").put(
|
router.route("/pd-invoice/delivered/:invoiceId").put(
|
||||||
isAuthenticatedUser,
|
isAuthenticatedUser,
|
||||||
|
|
||||||
updateCourierStatusToDeliveredForPD
|
updateCourierStatusToDeliveredForPD
|
||||||
|
Loading…
Reference in New Issue
Block a user