|
|
|
|
@ -1620,7 +1620,7 @@ exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
|
const i_id = await generatequatationId();
|
|
|
|
|
const quatationId = `AWQU${i_id}`;
|
|
|
|
|
const { surveyId } = req.params;
|
|
|
|
|
const { customerId, masters, slaves, sensors, motor_switches, electricals } = req.body;
|
|
|
|
|
const { customerId, masters, slaves, sensors, motor_switches, electricals,master_connections } = req.body;
|
|
|
|
|
|
|
|
|
|
// Format electricals field
|
|
|
|
|
const formattedElectricals = electricals.map((item) => ({
|
|
|
|
|
@ -1629,6 +1629,16 @@ exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
|
switch: item.switch || "",
|
|
|
|
|
text: item.text || "",
|
|
|
|
|
}));
|
|
|
|
|
const formattedMasterDetails = master_connections.map((item) => ({
|
|
|
|
|
master_name: item.master_name || "",
|
|
|
|
|
slaves: item.slaves || "",
|
|
|
|
|
tanks: Array.isArray(item.tanks)
|
|
|
|
|
? item.tanks.map(tank => ({
|
|
|
|
|
tankName: tank.tankName || "",
|
|
|
|
|
tankLocation: tank.tankLocation || ""
|
|
|
|
|
}))
|
|
|
|
|
: []
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Fetch pricing data from Iotprice database
|
|
|
|
|
const getPrice = async (name, type) => {
|
|
|
|
|
@ -1662,7 +1672,7 @@ exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
|
const newQuotation = new SensorQuotation({
|
|
|
|
|
quatationId,
|
|
|
|
|
customerId,
|
|
|
|
|
|
|
|
|
|
master_connections: formattedMasterDetails,
|
|
|
|
|
surveyId,
|
|
|
|
|
quote_status: "sentfromsurvey",
|
|
|
|
|
masters,
|
|
|
|
|
@ -1697,7 +1707,7 @@ exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
|
exports.editQuotationForSensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { quatationId } = req.params; // Get the ID of the quotation to edit
|
|
|
|
|
const { masters, slaves, sensors, motor_switches, electricals } = req.body;
|
|
|
|
|
const { masters, slaves, sensors, motor_switches, electricals, master_connections } = req.body;
|
|
|
|
|
|
|
|
|
|
// Format electricals field
|
|
|
|
|
const formattedElectricals = electricals.map((item) => ({
|
|
|
|
|
@ -1707,6 +1717,20 @@ exports.editQuotationForSensor = async (req, reply) => {
|
|
|
|
|
text: item.text || "",
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Format master_connections field
|
|
|
|
|
const formattedMasterDetails = master_connections.map((item) => ({
|
|
|
|
|
master_name: item.master_name || "",
|
|
|
|
|
slaves: item.slaves || "",
|
|
|
|
|
tanks: Array.isArray(item.tanks)
|
|
|
|
|
? item.tanks.map(tank => ({
|
|
|
|
|
tankName: tank.tankName || "",
|
|
|
|
|
tankLocation: tank.tankLocation || ""
|
|
|
|
|
}))
|
|
|
|
|
: []
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
console.log("Formatted Master Connections:", formattedMasterDetails); // Debugging
|
|
|
|
|
|
|
|
|
|
// Find and update the quotation
|
|
|
|
|
const updatedQuotation = await SensorQuotation.findOneAndUpdate(
|
|
|
|
|
{ quatationId },
|
|
|
|
|
@ -1716,6 +1740,7 @@ exports.editQuotationForSensor = async (req, reply) => {
|
|
|
|
|
sensors,
|
|
|
|
|
motor_switches,
|
|
|
|
|
electricals: formattedElectricals,
|
|
|
|
|
master_connections: formattedMasterDetails, // <- Ensure it's included
|
|
|
|
|
updated_at: dayjs().tz("Asia/Kolkata").format('DD-MMM-YYYY - HH:mm'),
|
|
|
|
|
},
|
|
|
|
|
{ new: true } // Return the updated document
|
|
|
|
|
|