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