|
|
|
@ -2021,7 +2021,7 @@ exports.getOrdersByCustomer = async (req, reply) => {
|
|
|
|
exports.acceptQuotation = async (req, reply) => {
|
|
|
|
exports.acceptQuotation = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { quotationId } = req.params;
|
|
|
|
const { quotationId } = req.params;
|
|
|
|
let { action } = req.body;
|
|
|
|
let { action, storeId } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
action = action.toLowerCase(); // Convert action to lowercase
|
|
|
|
action = action.toLowerCase(); // Convert action to lowercase
|
|
|
|
|
|
|
|
|
|
|
|
@ -2041,9 +2041,10 @@ exports.acceptQuotation = async (req, reply) => {
|
|
|
|
message: "Quotation rejected successfully",
|
|
|
|
message: "Quotation rejected successfully",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (action === "accept") {
|
|
|
|
} else if (action === "accept") {
|
|
|
|
// Convert quotation to an order object
|
|
|
|
// Convert quotation to an order object and include storeId
|
|
|
|
const newOrder = new Order({
|
|
|
|
const newOrder = new Order({
|
|
|
|
...quotation.toObject(), // Copy all fields
|
|
|
|
...quotation.toObject(), // Copy all fields from quotation
|
|
|
|
|
|
|
|
storeId: storeId, // Ensure storeId is included
|
|
|
|
status: "pending", // Set status to "pending"
|
|
|
|
status: "pending", // Set status to "pending"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@ -2066,3 +2067,27 @@ exports.acceptQuotation = async (req, reply) => {
|
|
|
|
return reply.status(500).send({ error: "Internal server error" });
|
|
|
|
return reply.status(500).send({ error: "Internal server error" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getOrdersByStoreId = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { storeId } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!storeId) {
|
|
|
|
|
|
|
|
return reply.status(400).send({ error: "storeId is required" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch orders with the matching storeId
|
|
|
|
|
|
|
|
const orders = await Order.find({ storeId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
|
|
|
status_code: 200,
|
|
|
|
|
|
|
|
message: "Orders fetched successfully",
|
|
|
|
|
|
|
|
data: orders,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error("Error fetching orders:", err);
|
|
|
|
|
|
|
|
return reply.status(500).send({ error: "Internal server error" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|