changes in accept

master^2
Varun 8 months ago
parent 2dfbc8c640
commit a0429afc6d

@ -2065,6 +2065,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;
@ -2109,21 +2110,38 @@ exports.acceptQuotation = async (req, reply) => {
for (const sensor of sensorTypes) { for (const sensor of sensorTypes) {
if (sensor.count > 0) { if (sensor.count > 0) {
const stock = await SensorStock.findOne({ storeId, type: sensor.type });
if (stock) {
let available = stock.total_available || 0;
let needed = sensor.count;
let toBlock = Math.min(available, needed);
let excessNeeded = needed - toBlock;
// Update Insensors for available sensors
if (toBlock > 0) {
await Insensors.updateMany( await Insensors.updateMany(
{ storeId, type: sensor.type, status: "available" }, { storeId, type: sensor.type, status: "available" },
{ $set: { status: "blocked", customerId } }, { $set: { status: "blocked", customerId } },
{ limit: sensor.count } { limit: toBlock }
); );
}
// Update SensorStock // Update SensorStock
await SensorStock.updateOne( await SensorStock.updateOne(
{ storeId, type: sensor.type }, { storeId, type: sensor.type },
{ {
$inc: { total_available: -sensor.count, total_blocked: sensor.count }, $inc: {
total_available: -toBlock,
total_blocked: toBlock,
excess_needed: excessNeeded > 0 ? excessNeeded : 0,
},
} }
); );
} }
} }
}
// Delete the record from SensorQuotation // Delete the record from SensorQuotation
await SensorQuotation.deleteOne({ quatationId: quotationId }); await SensorQuotation.deleteOne({ quatationId: quotationId });

@ -5865,7 +5865,6 @@ client.on('connect', () => {
}); });
client.on('message', async (topic, message) => { client.on('message', async (topic, message) => {
console.log(`Message received on topic ${topic}:`, message.toString()); console.log(`Message received on topic ${topic}:`, message.toString());
@ -5971,7 +5970,6 @@ client.on('message', async (topic, message) => {
if (inputConnection.motor_stop_status === "2" && status === 1) { if (inputConnection.motor_stop_status === "2" && status === 1) {
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
inputConnection.motor_stop_status = "1"; inputConnection.motor_stop_status = "1";
inputConnection.motor_on_type = "manual";
inputConnection.stopTime = currentTime; inputConnection.stopTime = currentTime;
} }
@ -5987,6 +5985,8 @@ client.on('message', async (topic, message) => {
}); });
// //
// API function to get survey data for a particular installer // API function to get survey data for a particular installer
// //

@ -500,6 +500,11 @@ const SensorStockSchema = new mongoose.Schema({
required: true, required: true,
default: 0, default: 0,
}, },
excess_needed: {
type: Number,
required: true,
default: 0,
},
total_installed: { total_installed: {
type: Number, type: Number,
required: true, required: true,

Loading…
Cancel
Save