|
|
|
|
@ -2021,11 +2021,9 @@ exports.getOrdersByCustomer = async (req, reply) => {
|
|
|
|
|
exports.acceptQuotation = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { quotationId } = req.params;
|
|
|
|
|
const { action } = req.body;
|
|
|
|
|
let { action } = req.body;
|
|
|
|
|
|
|
|
|
|
if (action !== "accept") {
|
|
|
|
|
return reply.status(400).send({ error: "Invalid action" });
|
|
|
|
|
}
|
|
|
|
|
action = action.toLowerCase(); // Convert action to lowercase
|
|
|
|
|
|
|
|
|
|
// Find the quotation by ID
|
|
|
|
|
const quotation = await SensorQuotation.findOne({ quatationId: quotationId });
|
|
|
|
|
@ -2034,26 +2032,37 @@ exports.acceptQuotation = async (req, reply) => {
|
|
|
|
|
return reply.status(404).send({ error: "Quotation not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert quotation to an order object
|
|
|
|
|
const newOrder = new Order({
|
|
|
|
|
...quotation.toObject(), // Copy all fields
|
|
|
|
|
status: "pending", // Set status to "pending"
|
|
|
|
|
});
|
|
|
|
|
if (action === "reject") {
|
|
|
|
|
// Update status to "rejected" in SensorQuotation
|
|
|
|
|
await SensorQuotation.updateOne({ quatationId: quotationId }, { $set: { status: "rejected" } });
|
|
|
|
|
|
|
|
|
|
// Save to the Orders collection
|
|
|
|
|
await newOrder.save();
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Quotation rejected successfully",
|
|
|
|
|
});
|
|
|
|
|
} else if (action === "accept") {
|
|
|
|
|
// Convert quotation to an order object
|
|
|
|
|
const newOrder = new Order({
|
|
|
|
|
...quotation.toObject(), // Copy all fields
|
|
|
|
|
status: "pending", // Set status to "pending"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Delete the record from SensorQuotation
|
|
|
|
|
await SensorQuotation.deleteOne({ quatationId: quotationId });
|
|
|
|
|
// Save to the Orders collection
|
|
|
|
|
await newOrder.save();
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Quotation accepted and moved to Orders",
|
|
|
|
|
data: newOrder,
|
|
|
|
|
});
|
|
|
|
|
// Delete the record from SensorQuotation
|
|
|
|
|
await SensorQuotation.deleteOne({ quatationId: quotationId });
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Quotation accepted and moved to Orders",
|
|
|
|
|
data: newOrder,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return reply.status(400).send({ error: "Invalid action" });
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error accepting quotation:", err);
|
|
|
|
|
console.error("Error processing quotation:", err);
|
|
|
|
|
return reply.status(500).send({ error: "Internal server error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|