master^2
Varun 6 months ago
parent 6032ccd6c8
commit 8838b64a92

@ -1201,8 +1201,18 @@ exports.consumption = async (request, reply) => {
return acc + parseInt(record.consumption, 10); return acc + parseInt(record.consumption, 10);
}, 0); }, 0);
const consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records; let consumption;
totalConsumptionForSelectedBlockAndTypeOfWater += consumption;
const isSameTime = start.getTime() === end.getTime();
const isToday = moment(start).isSame(moment(), 'day');
if (isSameTime && !isToday) {
// Same date & time and NOT today => use only records
consumption = total_consumption_from_records;
} else {
// Normal case => use full calculation
consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
}
// Add to the total consumption and capacities based on water type // Add to the total consumption and capacities based on water type
if (tank.typeOfWater === "bore" || tank.typeOfWater === "Bore Water") { if (tank.typeOfWater === "bore" || tank.typeOfWater === "Bore Water") {

Loading…
Cancel
Save