|  |  |  | @ -193,7 +193,7 @@ exports.getactivedeliveryboysofsupplier = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | const intervals = {}; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | exports.deliveryboystartandstop = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |    | 
			
		
	
		
			
				
					|  |  |  |  |   try { | 
			
		
	
	
		
			
				
					|  |  |  | @ -212,34 +212,36 @@ exports.deliveryboystartandstop = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |    // console.log(receiver_tank_info,"1")
 | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     const receiver_capacity =  parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10) | 
			
		
	
		
			
				
					|  |  |  |  |    // console.log(receiver_capacity,"2")
 | 
			
		
	
		
			
				
					|  |  |  |  |    //console.log(bookingdata,customerId,receiver_tank,receiver_tank_info,receiver_capacity,"2")
 | 
			
		
	
		
			
				
					|  |  |  |  |     | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |    const intervals = {}; | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |        | 
			
		
	
		
			
				
					|  |  |  |  |     if(action === "start"){ | 
			
		
	
		
			
				
					|  |  |  |  |      // console.log("started")
 | 
			
		
	
		
			
				
					|  |  |  |  |      start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) | 
			
		
	
		
			
				
					|  |  |  |  |      const initial_receiver_waterlevel =  parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) | 
			
		
	
		
			
				
					|  |  |  |  |       const start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) | 
			
		
	
		
			
				
					|  |  |  |  |       const initial_receiver_waterlevel =  parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |      await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { initial_water_level: initial_receiver_waterlevel ,start_time:start_time} }); | 
			
		
	
		
			
				
					|  |  |  |  |       await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { initial_water_level: initial_receiver_waterlevel ,start_time:start_time,tankerRunningStatus:"1"} }); | 
			
		
	
		
			
				
					|  |  |  |  |         | 
			
		
	
		
			
				
					|  |  |  |  |         | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |          let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) | 
			
		
	
		
			
				
					|  |  |  |  |         // console.log(receiver_waterlevel,"1")
 | 
			
		
	
		
			
				
					|  |  |  |  |          const intervalId = setInterval(async function () { | 
			
		
	
		
			
				
					|  |  |  |  |         intervals[bookingId]= setInterval(async function () { | 
			
		
	
		
			
				
					|  |  |  |  |           // Calculate new water levels
 | 
			
		
	
		
			
				
					|  |  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |  |           const newWaterLevel = receiver_waterlevel+450; | 
			
		
	
		
			
				
					|  |  |  |  |           const booking_data = await Tankerbooking.findOne({bookingid:bookingId}) | 
			
		
	
		
			
				
					|  |  |  |  |           const tankerStatus = booking_data.tankerRunningStatus | 
			
		
	
		
			
				
					|  |  |  |  |           //console.log(newWaterLevel,"2",receiver_tank_info.tankName)
 | 
			
		
	
		
			
				
					|  |  |  |  |           // Check if updating should stop
 | 
			
		
	
		
			
				
					|  |  |  |  |           if ((newWaterLevel/receiver_capacity)*100 >= 97 ) { | 
			
		
	
		
			
				
					|  |  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |  |           if ((newWaterLevel/receiver_capacity)*100 >= 97, tankerStatus ==="0" ) { | 
			
		
	
		
			
				
					|  |  |  |  |             clearInterval(intervals[bookingId]); // Clear the interval for this tank
 | 
			
		
	
		
			
				
					|  |  |  |  |             delete intervals[bookingId];  | 
			
		
	
		
			
				
					|  |  |  |  |             await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { initial_water_level: initial_receiver_waterlevel ,start_time:start_time,tankerRunningStatus:"0"} }); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             | 
			
		
	
		
			
				
					|  |  |  |  |             clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
 | 
			
		
	
		
			
				
					|  |  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |  |             delete intervals[receiver_tank];  | 
			
		
	
		
			
				
					|  |  |  |  |             stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             const final_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:"sump"}); | 
			
		
	
	
		
			
				
					|  |  |  | @ -258,7 +260,7 @@ exports.deliveryboystartandstop = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |            // console.log(intervals,"check1")
 | 
			
		
	
		
			
				
					|  |  |  |  |           } | 
			
		
	
		
			
				
					|  |  |  |  |         }, 2000); | 
			
		
	
		
			
				
					|  |  |  |  |         intervals[receiver_tank] = intervalId; | 
			
		
	
		
			
				
					|  |  |  |  |        | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -266,7 +268,7 @@ exports.deliveryboystartandstop = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |      // console.log(customerId,req.body.from,req.body.from_type,receiver_tank,req.body.to_type,)
 | 
			
		
	
		
			
				
					|  |  |  |  |       | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       reply.send({ status_code: 200, "start time": start_time,}); | 
			
		
	
		
			
				
					|  |  |  |  |       reply.send({ status_code: 200, "start time": start_time,"initial water level":initial_receiver_waterlevel}); | 
			
		
	
		
			
				
					|  |  |  |  |       console.log(start_time) | 
			
		
	
		
			
				
					|  |  |  |  |        | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -274,15 +276,16 @@ exports.deliveryboystartandstop = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     if (action === "stop") { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       const booking_data = await Tankerbooking.findOne({bookingid: bookingId}) | 
			
		
	
		
			
				
					|  |  |  |  |       console.log(intervals,"hii3") | 
			
		
	
		
			
				
					|  |  |  |  |       try { | 
			
		
	
		
			
				
					|  |  |  |  |         clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
 | 
			
		
	
		
			
				
					|  |  |  |  |         delete intervals[receiver_tank]; // Delete the interval ID for this tank from the intervals object
 | 
			
		
	
		
			
				
					|  |  |  |  |         clearInterval(intervals[bookingId]); // Clear the interval for this tank
 | 
			
		
	
		
			
				
					|  |  |  |  |         delete intervals[bookingId]; // Delete the interval ID for this tank from the intervals object
 | 
			
		
	
		
			
				
					|  |  |  |  |       } catch (err) { | 
			
		
	
		
			
				
					|  |  |  |  |         console.log(err); | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
		
			
				
					|  |  |  |  |       stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) | 
			
		
	
		
			
				
					|  |  |  |  |      const stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) | 
			
		
	
		
			
				
					|  |  |  |  |       const final_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:"sump"}); | 
			
		
	
		
			
				
					|  |  |  |  |      // console.log(final_tank_info,"hii")
 | 
			
		
	
		
			
				
					|  |  |  |  |       const final_receiver_waterlevel =  parseInt(final_tank_info.waterlevel.replace(/,/g, ''), 10) | 
			
		
	
	
		
			
				
					|  |  |  | @ -290,8 +293,8 @@ exports.deliveryboystartandstop = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |       const start_water_level =  parseInt(booking_data.initial_water_level.replace(/,/g, ''), 10) | 
			
		
	
		
			
				
					|  |  |  |  |       const quantity_delivered = final_receiver_waterlevel-start_water_level | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |       await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { final_water_level: final_receiver_waterlevel ,stop_time:stop_time,quantityDelivered:quantity_delivered} }); | 
			
		
	
		
			
				
					|  |  |  |  |        reply.send({ status_code: 200, "stop time": stop_time}); | 
			
		
	
		
			
				
					|  |  |  |  |       await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { final_water_level: final_receiver_waterlevel ,stop_time:stop_time,quantityDelivered:quantity_delivered,tankerRunningStatus:"0"} }); | 
			
		
	
		
			
				
					|  |  |  |  |        reply.send({ status_code: 200, "stop time": stop_time,"final water level":final_receiver_waterlevel}); | 
			
		
	
		
			
				
					|  |  |  |  |     } else { | 
			
		
	
		
			
				
					|  |  |  |  |           throw new Error("Invalid action"); | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |