|
|
@ -10,7 +10,7 @@ const fastify = require("fastify")({
|
|
|
|
return uuidv4();
|
|
|
|
return uuidv4();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors} = require("../models/store");
|
|
|
|
const { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors,generatequatationId} = require("../models/store");
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1075,36 +1075,34 @@ exports.getusersofParticularInstaller = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
exports.createquotationforSensor = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Extract parameters and body data from the request
|
|
|
|
const i_id = await generatequatationId();
|
|
|
|
|
|
|
|
const quatationId = `AWQU${i_id}`;
|
|
|
|
const { installationId } = req.params;
|
|
|
|
const { installationId } = req.params;
|
|
|
|
const { customerId, masters, slaves, motor_switches, electricals,master_type,sensor_type,switch_type } = req.body;
|
|
|
|
const { customerId, masters, slaves, motor_switches, electricals,master_type,sensor_type,switch_type } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
// Validate electricals field to ensure it's an array of objects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a new SensorQuotation document
|
|
|
|
// Create a new SensorQuotation document
|
|
|
|
const newQuotation = new SensorQuotation({
|
|
|
|
const newQuotation = new SensorQuotation({
|
|
|
|
|
|
|
|
quatationId,
|
|
|
|
customerId: customerId,
|
|
|
|
customerId: customerId,
|
|
|
|
installationId: installationId, // Using installationId for the field
|
|
|
|
installationId: installationId,
|
|
|
|
masters,
|
|
|
|
masters,
|
|
|
|
slaves,
|
|
|
|
slaves,
|
|
|
|
motor_switches,
|
|
|
|
motor_switches,
|
|
|
|
electricals,
|
|
|
|
electricals,
|
|
|
|
switch_type,
|
|
|
|
switch_type,
|
|
|
|
master_type,
|
|
|
|
master_type,
|
|
|
|
sensor_type// This will store the array of electrical items (objects)
|
|
|
|
sensor_type
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Save the document to the database
|
|
|
|
|
|
|
|
const savedQuotation = await newQuotation.save();
|
|
|
|
const savedQuotation = await newQuotation.save();
|
|
|
|
|
|
|
|
|
|
|
|
// Send a success response with the saved document
|
|
|
|
|
|
|
|
reply.code(200).send({
|
|
|
|
reply.code(200).send({
|
|
|
|
success: true,
|
|
|
|
success: true,
|
|
|
|
message: 'Quotation for sensors created successfully.',
|
|
|
|
message: 'Quotation for sensors created successfully.',
|
|
|
|
data: savedQuotation,
|
|
|
|
data: savedQuotation,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
// Handle errors and send error response
|
|
|
|
|
|
|
|
console.error('Error creating quotation:', error);
|
|
|
|
console.error('Error creating quotation:', error);
|
|
|
|
reply.code(500).send({
|
|
|
|
reply.code(500).send({
|
|
|
|
success: false,
|
|
|
|
success: false,
|
|
|
@ -1131,3 +1129,102 @@ exports.getallquotationdata = async (req, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.saveQuotationData = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { quotationId } = req.params; // Retrieve the quotationId from the request parameters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch the quotation data from the database
|
|
|
|
|
|
|
|
const quotation = await SensorQuotation.findOne({ quatationId: quotationId });
|
|
|
|
|
|
|
|
console.log(quotation)
|
|
|
|
|
|
|
|
if (!quotation) {
|
|
|
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Quotation not found.'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extract the price-per-unit and total price values from the request body
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
masters_quantity_price,
|
|
|
|
|
|
|
|
masters_total_price,
|
|
|
|
|
|
|
|
slaves_quantity_price,
|
|
|
|
|
|
|
|
slaves_total_price,
|
|
|
|
|
|
|
|
motor_switches_quantity_price,
|
|
|
|
|
|
|
|
motor_switches_total_price,
|
|
|
|
|
|
|
|
electricals_quantity_price,
|
|
|
|
|
|
|
|
electricals_total_price,
|
|
|
|
|
|
|
|
master_type_quantity_price,
|
|
|
|
|
|
|
|
master_type_total_price,
|
|
|
|
|
|
|
|
sensor_type_quantity_price,
|
|
|
|
|
|
|
|
sensor_type_total_price,
|
|
|
|
|
|
|
|
switch_type_quantity_price,
|
|
|
|
|
|
|
|
switch_type_total_price,
|
|
|
|
|
|
|
|
quotation_total_price
|
|
|
|
|
|
|
|
} = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the quotation document with the data from the request body
|
|
|
|
|
|
|
|
quotation.masters_quantity_price = masters_quantity_price;
|
|
|
|
|
|
|
|
quotation.masters_total_price = masters_total_price;
|
|
|
|
|
|
|
|
quotation.slaves_quantity_price = slaves_quantity_price;
|
|
|
|
|
|
|
|
quotation.slaves_total_price = slaves_total_price;
|
|
|
|
|
|
|
|
quotation.motor_switches_quantity_price = motor_switches_quantity_price;
|
|
|
|
|
|
|
|
quotation.motor_switches_total_price = motor_switches_total_price;
|
|
|
|
|
|
|
|
quotation.electricals_quantity_price = electricals_quantity_price;
|
|
|
|
|
|
|
|
quotation.electricals_total_price = electricals_total_price;
|
|
|
|
|
|
|
|
quotation.master_type_quantity_price = master_type_quantity_price;
|
|
|
|
|
|
|
|
quotation.master_type_total_price = master_type_total_price;
|
|
|
|
|
|
|
|
quotation.sensor_type_quantity_price = sensor_type_quantity_price;
|
|
|
|
|
|
|
|
quotation.sensor_type_total_price = sensor_type_total_price;
|
|
|
|
|
|
|
|
quotation.switch_type_quantity_price = switch_type_quantity_price;
|
|
|
|
|
|
|
|
quotation.switch_type_total_price = switch_type_total_price;
|
|
|
|
|
|
|
|
quotation.qutation_total_price = quotation_total_price;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the updated document back to the database
|
|
|
|
|
|
|
|
await quotation.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send back the updated data
|
|
|
|
|
|
|
|
reply.code(200).send({
|
|
|
|
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
message: 'Quotation data saved successfully.',
|
|
|
|
|
|
|
|
data: quotation
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('Error saving quotation data to the database:', error);
|
|
|
|
|
|
|
|
reply.code(500).send({
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Failed to save quotation data.',
|
|
|
|
|
|
|
|
error: error.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getSinleQuotationData = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { quotationId } = req.params; // Correct the parameter name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch the quotation data from the database
|
|
|
|
|
|
|
|
const quotation = await SensorQuotation.findOne({ quatationId: quotationId }); // Correctly referencing quotationId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!quotation) {
|
|
|
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Quotation not found.'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.code(200).send({
|
|
|
|
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
message: 'Quotation data retrieved successfully.',
|
|
|
|
|
|
|
|
data: quotation
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('Error fetching quotation data:', error);
|
|
|
|
|
|
|
|
reply.code(500).send({
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'Failed to retrieve quotation data.',
|
|
|
|
|
|
|
|
error: error.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|