|
|
|
@ -702,9 +702,6 @@ let supplier_tanks = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
@ -771,7 +768,6 @@ let supplier_tanks = [];
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// // console.log(customerId,req.body.from,req.body.from_type,receiver_tank,req.body.to_type,)
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// else if (action === "stop") {
|
|
|
|
@ -944,6 +940,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
const { customerId } = request.params;
|
|
|
|
|
const { startDate, stopDate, block } = request.body;
|
|
|
|
|
let { typeofwater } = request.body;
|
|
|
|
|
|
|
|
|
|
// Convert typeofwater to lowercase
|
|
|
|
|
typeofwater = typeofwater.toLowerCase();
|
|
|
|
|
const start = startDate;
|
|
|
|
@ -963,6 +960,9 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
const tanks = await Tank.find(tankQuery);
|
|
|
|
|
const tankData = [];
|
|
|
|
|
|
|
|
|
|
// Variable to track total consumption for the selected block and typeofwater
|
|
|
|
|
let totalConsumptionForSelectedBlockAndTypeOfWater = 0;
|
|
|
|
|
|
|
|
|
|
for (const tank of tanks) {
|
|
|
|
|
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);
|
|
|
|
@ -987,6 +987,9 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
const consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
|
|
|
|
|
|
|
|
|
|
// Add to the total consumption for the selected block and typeofwater
|
|
|
|
|
totalConsumptionForSelectedBlockAndTypeOfWater += consumption;
|
|
|
|
|
|
|
|
|
|
tankData.push({
|
|
|
|
|
tankname,
|
|
|
|
|
totalConsumption: consumption,
|
|
|
|
@ -998,7 +1001,14 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, tankData });
|
|
|
|
|
// Include the total consumption in the response
|
|
|
|
|
const response = {
|
|
|
|
|
status_code: 200,
|
|
|
|
|
tankData,
|
|
|
|
|
[`total consumption of ${typeofwater} and selected block`]: totalConsumptionForSelectedBlockAndTypeOfWater
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reply.send(response);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
@ -1009,6 +1019,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
|
|
|
|
|
|
//const moment = require('moment'); // Import moment.js for date/time operations
|
|
|
|
|