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) => {
try {
const { quotationId } = req.params;
@ -2109,19 +2110,36 @@ exports.acceptQuotation = async (req, reply) => {
for (const sensor of sensorTypes) {
if (sensor.count > 0) {
await Insensors.updateMany(
{ storeId, type: sensor.type, status: "available" },
{ $set: { status: "blocked", customerId } },
{ limit: sensor.count }
);
// Update SensorStock
await SensorStock.updateOne(
{ storeId, type: sensor.type },
{
$inc: { total_available: -sensor.count, total_blocked: sensor.count },
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(
{ storeId, type: sensor.type, status: "available" },
{ $set: { status: "blocked", customerId } },
{ limit: toBlock }
);
}
);
// Update SensorStock
await SensorStock.updateOne(
{ storeId, type: sensor.type },
{
$inc: {
total_available: -toBlock,
total_blocked: toBlock,
excess_needed: excessNeeded > 0 ? excessNeeded : 0,
},
}
);
}
}
}

@ -5865,7 +5865,6 @@ client.on('connect', () => {
});
client.on('message', async (topic, message) => {
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) {
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
inputConnection.motor_stop_status = "1";
inputConnection.motor_on_type = "manual";
inputConnection.stopTime = currentTime;
}
@ -5987,6 +5985,8 @@ client.on('message', async (topic, message) => {
});
//
// API function to get survey data for a particular installer
//

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

Loading…
Cancel
Save