|
|
|
@ -251,7 +251,7 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
quotation = new Order({
|
|
|
|
|
installationId,
|
|
|
|
|
quatationId: quotationId,
|
|
|
|
|
assignedTeamMembers: [],
|
|
|
|
|
assignedTeamMembers: [], // Ensure assignedTeamMembers array is initialized
|
|
|
|
|
status: "Pending", // Default status when created
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -268,9 +268,13 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
// 🔹 Update order status when a team member is assigned
|
|
|
|
|
quotation.status = "Assigned"; // Update status
|
|
|
|
|
|
|
|
|
|
// 🔹 Save the updated quotation
|
|
|
|
|
// 🔹 Save the updated quotation in the Order schema
|
|
|
|
|
await quotation.save();
|
|
|
|
|
|
|
|
|
|
// 🔹 Update Installation schema with quotationId
|
|
|
|
|
installation.quatationId = quotationId;
|
|
|
|
|
await installation.save();
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
@ -436,4 +440,94 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getQuotationsByInstallationId = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { installationId } = request.params;
|
|
|
|
|
|
|
|
|
|
if (!installationId) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "Installation ID is required",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 🔹 Fetch quotations based on installationId
|
|
|
|
|
const quotations = await Order.find({ installationId });
|
|
|
|
|
|
|
|
|
|
if (!quotations || quotations.length === 0) {
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "No quotations found for this installation ID",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "Quotations fetched successfully",
|
|
|
|
|
quotations,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching quotations:", err);
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "Internal server error",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.getQuotationsByInstallationAndTeamMember = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { installationId, teamMemberId } = request.params;
|
|
|
|
|
|
|
|
|
|
if (!installationId || !teamMemberId) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "Both installationId and teamMemberId are required",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 🔹 Fetch quotations where installationId matches and teamMemberId is assigned
|
|
|
|
|
const quotations = await Order.find({
|
|
|
|
|
installationId,
|
|
|
|
|
assignedTeamMembers: teamMemberId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!quotations || quotations.length === 0) {
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "No quotations found for this installation and team member",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "Quotations fetched successfully",
|
|
|
|
|
quotations,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching quotations:", err);
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "Internal server error",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|