|  |  |  | @ -824,34 +824,53 @@ let supplier_tanks = []; | 
			
		
	
		
			
				
					|  |  |  |  | // };
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  | exports.consumption = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |   try { | 
			
		
	
		
			
				
					|  |  |  |  |     const customerId = req.params.customerId; | 
			
		
	
		
			
				
					|  |  |  |  |     const tanks = await Tank.find({ customerId,tankLocation:"overhead"}); | 
			
		
	
		
			
				
					|  |  |  |  |     const tankData = [];  | 
			
		
	
		
			
				
					|  |  |  |  |     for (const tank of tanks) { | 
			
		
	
		
			
				
					|  |  |  |  |       const tankId = tank._id; | 
			
		
	
		
			
				
					|  |  |  |  |       const waterlevel_at_midnight = parseInt(tank.waterlevel_at_midnight.replace(/,/g, ''), 10); | 
			
		
	
		
			
				
					|  |  |  |  |       const total_water_added_from_midnight = parseInt(tank.total_water_added_from_midnight.replace(/,/g, ''), 10); | 
			
		
	
		
			
				
					|  |  |  |  |       const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); | 
			
		
	
		
			
				
					|  |  |  |  | exports.consumption = async (request, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |   // try {
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   const customerId = req.params.customerId;
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   const tanks = await Tank.find({ customerId,tankLocation:"overhead"});
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   const tankData = []; 
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   for (const tank of tanks) {
 | 
			
		
	
		
			
				
					|  |  |  |  |   //     const tankId = tank._id;
 | 
			
		
	
		
			
				
					|  |  |  |  |   //     const waterlevel_at_midnight = parseInt(tank.waterlevel_at_midnight.replace(/,/g, ''), 10);
 | 
			
		
	
		
			
				
					|  |  |  |  |   //     const total_water_added_from_midnight = parseInt(tank.total_water_added_from_midnight.replace(/,/g, ''), 10);
 | 
			
		
	
		
			
				
					|  |  |  |  |   //     const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
 | 
			
		
	
		
			
				
					|  |  |  |  |        | 
			
		
	
		
			
				
					|  |  |  |  |   //     const tankname = tank.tankName
 | 
			
		
	
		
			
				
					|  |  |  |  |   //     const consumption = (waterlevel_at_midnight+total_water_added_from_midnight)-waterlevel
 | 
			
		
	
		
			
				
					|  |  |  |  |       | 
			
		
	
		
			
				
					|  |  |  |  |       const tankname = tank.tankName | 
			
		
	
		
			
				
					|  |  |  |  |       const consumption = (waterlevel_at_midnight+total_water_added_from_midnight)-waterlevel | 
			
		
	
		
			
				
					|  |  |  |  |   //       const newWaterLevel1 = Math.floor(consumption);
 | 
			
		
	
		
			
				
					|  |  |  |  |   //       const newWaterLevel=Math.abs(newWaterLevel1)
 | 
			
		
	
		
			
				
					|  |  |  |  |   //       tankData.push({ tankname, waterLevel: newWaterLevel }); 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         const newWaterLevel1 = Math.floor(consumption); | 
			
		
	
		
			
				
					|  |  |  |  |         const newWaterLevel=Math.abs(newWaterLevel1) | 
			
		
	
		
			
				
					|  |  |  |  |         tankData.push({ tankname, waterLevel: newWaterLevel });  | 
			
		
	
		
			
				
					|  |  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |  |   //      // console.log(newWaterLevel);
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   }
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   reply.send({ status_code: 200, tankData }); 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   return { message: 'Water level updates started' };
 | 
			
		
	
		
			
				
					|  |  |  |  |   // } catch (err) {
 | 
			
		
	
		
			
				
					|  |  |  |  |   //   throw boom.boomify(err);
 | 
			
		
	
		
			
				
					|  |  |  |  |   // }
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |        // console.log(newWaterLevel);
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   try { | 
			
		
	
		
			
				
					|  |  |  |  |     const { customerId } = request.params; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     const tank = await Tank.find({ customerId, tankLocation:"overhead" }); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     if (!tank) { | 
			
		
	
		
			
				
					|  |  |  |  |       return reply.status(404).send({ error: 'Tank not found' }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     reply.send({ status_code: 200, tankData });  | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     return { message: 'Water level updates started' }; | 
			
		
	
		
			
				
					|  |  |  |  |   } catch (err) { | 
			
		
	
		
			
				
					|  |  |  |  |     throw boom.boomify(err); | 
			
		
	
		
			
				
					|  |  |  |  |     // Here you can process and return the consumption data as needed
 | 
			
		
	
		
			
				
					|  |  |  |  |     return reply.send(tank); | 
			
		
	
		
			
				
					|  |  |  |  |   } catch (error) { | 
			
		
	
		
			
				
					|  |  |  |  |     request.log.error(error); | 
			
		
	
		
			
				
					|  |  |  |  |     return reply.status(500).send({ error: 'Internal Server Error' }); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |