|
|
|
@ -1203,17 +1203,31 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
let 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
|
|
|
|
|
|
|
|
|
|
const isSameTime = start.getTime() === end.getTime();
|
|
|
|
|
const isEndToday = moment(end).isSame(moment(), 'day');
|
|
|
|
|
|
|
|
|
|
if (isSameTime || !isEndToday) {
|
|
|
|
|
// If single timestamp OR end is not today, only use records
|
|
|
|
|
consumption = total_consumption_from_records;
|
|
|
|
|
} else {
|
|
|
|
|
// Normal case => use full calculation
|
|
|
|
|
// If end is today, add real-time values
|
|
|
|
|
consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
if (tank.typeOfWater === "bore" || tank.typeOfWater === "Bore Water") {
|
|
|
|
|
totalBoreConsumptionForSelectedBlockAndTypeOfWater += consumption;
|
|
|
|
|