From cd3a547fe20e8430ff58918a522779fe0e6839e1 Mon Sep 17 00:00:00 2001 From: varun Date: Tue, 16 May 2023 05:02:10 -0400 Subject: [PATCH 1/3] made changes in tanks start and stop --- src/controllers/tanksController.js | 47 +++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 5dff432e..b07d2d5c 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -219,22 +219,25 @@ exports.getTanklevels = async (req, reply) => { } }; - - +const intervals = {}; +let sum_oh_count = 0 +let bore_sump_count = 0 exports.motorAction = async (req, reply) => { try { //let start_time,stop_time + const customerId = req.params.customerId; const action = req.body.action const receiver_tank = req.body.to const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}); const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10) const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10) - const intervals = {}; + const supplier_tank = req.body.from const supplier_tank_type = (req.body.from_type).toLowerCase() const receiver_type = (req.body.to_type).toLowerCase() console.log(supplier_tank) + const interval_variable = supplier_tank+receiver_tank if(action === "start"){ const start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) @@ -259,14 +262,15 @@ exports.motorAction = async (req, reply) => { await overheadTank.save(); } - + sum_oh_count++; + console.log(sum_oh_count) // await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info); let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10) // console.log(supplier_waterlevel) let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) - intervals[receiver_tank] = setInterval(async function () { + intervals[interval_variable] = setInterval(async function () { // Calculate new water levels const supplier_tank_info2 = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type}); const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type}); @@ -276,8 +280,9 @@ exports.motorAction = async (req, reply) => { console.log((newSupplierWaterLevel/supplier_capacity)*100) // Check if updating should stop if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0") { - clearInterval(intervals[receiver_tank]); // Clear the interval for this tank - delete intervals[receiver_tank]; + clearInterval(intervals[interval_variable]); // Clear the interval for this tank + delete intervals[interval_variable]; + sum_oh_count--; await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } }); const overheadTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type }); const connection = overheadTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank); @@ -359,6 +364,7 @@ exports.motorAction = async (req, reply) => { if(supplier_tank_type==="bore" && receiver_type === "sump"){ const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10) // console.log(receiver_capacity,"0",receiver_tank_info.tankName) + bore_sump_count++; await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "1" } }); const sumpTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type }); const connection = sumpTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank); @@ -371,7 +377,7 @@ exports.motorAction = async (req, reply) => { let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) // console.log(receiver_waterlevel,"1") - intervals[receiver_tank] = setInterval(async function () { + intervals[interval_variable] = setInterval(async function () { // Calculate new water levels const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type}); //console.log(rcvr_info) @@ -382,8 +388,9 @@ exports.motorAction = async (req, reply) => { if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0" ) { await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } }); - clearInterval(intervals[receiver_tank]); // Clear the interval for this tank - delete intervals[receiver_tank]; + clearInterval(intervals[interval_variable]); // Clear the interval for this tank + delete intervals[interval_variable]; + bore_sump_count--; const sumpTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type }); const connection = sumpTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank); @@ -449,6 +456,23 @@ exports.motorAction = async (req, reply) => { else if (action === "stop") { const stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) + clearInterval(intervals[interval_variable]); // Clear the interval for this tank + delete intervals[interval_variable]; + if (supplier_tank_type === "sump"){ + sum_oh_count--; + if (sum_oh_count===0){ + await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } }); + + } + } + if (supplier_tank_type === "bore"){ + bore_sump_count--; + if (bore_sump_count===0){ + await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } }); + + } + } + const overheadTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type }); const connection = overheadTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank); @@ -458,7 +482,8 @@ exports.motorAction = async (req, reply) => { } // console.log(stop_time) // clearInterval(intervalId); - await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } }); + + // await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } }); reply.send({ status_code: 200, "stop time": stop_time}); } else { From da98313cd9934226068226e97c88e59c1754fa5c Mon Sep 17 00:00:00 2001 From: varun Date: Tue, 16 May 2023 07:39:41 -0400 Subject: [PATCH 2/3] made changes in tanks start and stop --- src/controllers/tanksController.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index b07d2d5c..b5713a7b 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -274,7 +274,7 @@ exports.motorAction = async (req, reply) => { // Calculate new water levels const supplier_tank_info2 = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type}); const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type}); - const newWaterLevel = receiver_waterlevel + 250//Math.floor(supplier_waterlevel * 0.1); + const newWaterLevel = receiver_waterlevel + (250*sum_oh_count)//Math.floor(supplier_waterlevel * 0.1); const newSupplierWaterLevel = supplier_waterlevel//Math.floor(supplier_waterlevel * 0.1); const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10) console.log((newSupplierWaterLevel/supplier_capacity)*100) @@ -283,7 +283,11 @@ exports.motorAction = async (req, reply) => { clearInterval(intervals[interval_variable]); // Clear the interval for this tank delete intervals[interval_variable]; sum_oh_count--; + if (sum_oh_count===0){ await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } }); + + + } const overheadTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type }); const connection = overheadTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank); @@ -382,15 +386,18 @@ exports.motorAction = async (req, reply) => { const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type}); //console.log(rcvr_info) //console.log(rcvr_info.motor_status) - const newWaterLevel = receiver_waterlevel+250; + const newWaterLevel = receiver_waterlevel+(250*bore_sump_count); //console.log(newWaterLevel,"2",receiver_tank_info.tankName) // Check if updating should stop if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0" ) { - await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } }); clearInterval(intervals[interval_variable]); // Clear the interval for this tank delete intervals[interval_variable]; bore_sump_count--; + if (bore_sump_count===0){ + await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } }); + + } const sumpTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type }); const connection = sumpTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank); @@ -442,6 +449,7 @@ exports.motorAction = async (req, reply) => { } const motor_data = await motorData.save(); + console.log(motor_data) // reply.send({ status_code: 200, data: motor_data }); From 2de94606315bc6dd9a43eb30bc999ac1d7eba4e2 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 17 May 2023 02:32:23 -0400 Subject: [PATCH 3/3] made changes in distrubance amount --- src/controllers/supplierOrderController.js | 19 +++++++++++++ src/controllers/tankersController.js | 6 ++--- src/models/tankers.js | 1 + src/routes/supplierOrdersRoutes.js | 31 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index 9a9cf817..472c8152 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -784,4 +784,23 @@ exports.getBillingInfo = async (req, reply) => { } catch (err) { reply.status(400).send({ message: err.message }); } +}; + + +exports.getAlldistrubanceamountsdetails = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, payment_status: "due",distrubance_status:"1"}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } }; \ No newline at end of file diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 759b1631..4159a4a8 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -684,15 +684,15 @@ exports.distrubanceStatus = async (req, reply) => { const distrubance_price = parseInt(booking.distrubance_price .replace(/,/g, ''), 10) const price = parseInt(booking.price.replace(/,/g, ''), 10) const amount_due = parseInt(booking.amount_due .replace(/,/g, ''), 10) - const price_variation = price-distrubance_price + const price_variation = price-distrubance_price if (action === "accept") { - await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: price,amount_difference:"0" } }); + await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: distrubance_price,amount_difference:price_variation},distrubance_status:"1" }); } if (action === "reject") { - await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: distrubance_price,amount_difference:"0" } }); + await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: price,amount_difference:"0",distrubance_status:"0" } }); } diff --git a/src/models/tankers.js b/src/models/tankers.js index 017002cc..7614c549 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -71,6 +71,7 @@ const tankersbookingSchema = new mongoose.Schema({ longitude: { type : Number,default: 0.0}, latitude: {type: Number,default: 0.0}, deliveredDate: { type: String, default: null }, + distrubance_status: { type: String, default: "0" }, }); const boreSchema = new mongoose.Schema({ diff --git a/src/routes/supplierOrdersRoutes.js b/src/routes/supplierOrdersRoutes.js index 6c2a9b20..669ec2a4 100644 --- a/src/routes/supplierOrdersRoutes.js +++ b/src/routes/supplierOrdersRoutes.js @@ -712,6 +712,37 @@ module.exports = function (fastify, opts, next) { }); + fastify.route({ + method: "GET", + url: "/api/getAlldistrubanceamountsdetails/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is to get all distrubance amount accounts", + summary: "This is to get all distrubance amount accounts", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAlldistrubanceamountsdetails, + + }); + + + next(); }