|
|
@ -941,11 +941,11 @@ exports.consumption = async (request, reply) => {
|
|
|
|
const { customerId } = request.params;
|
|
|
|
const { customerId } = request.params;
|
|
|
|
const { startDate, stopDate, block } = request.body;
|
|
|
|
const { startDate, stopDate, block } = request.body;
|
|
|
|
let { typeofwater } = request.body;
|
|
|
|
let { typeofwater } = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
// Convert typeofwater to lowercase
|
|
|
|
// Convert typeofwater to lowercase
|
|
|
|
typeofwater = typeofwater.toLowerCase();
|
|
|
|
typeofwater = typeofwater.toLowerCase();
|
|
|
|
const start = startDate;
|
|
|
|
const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
const end = stopDate;
|
|
|
|
const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the query object based on block and typeofwater inputs
|
|
|
|
// Construct the query object based on block and typeofwater inputs
|
|
|
|
const tankQuery = { customerId, tankLocation: "overhead" };
|
|
|
|
const tankQuery = { customerId, tankLocation: "overhead" };
|
|
|
@ -970,19 +970,24 @@ exports.consumption = async (request, reply) => {
|
|
|
|
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
const tankname = tank.tankName;
|
|
|
|
const tankname = tank.tankName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tankConsumptions = await TankConsumptionOriginalSchema.find({
|
|
|
|
const tankConsumptions = await TankConsumptionOriginalSchema.find({
|
|
|
|
customerId,
|
|
|
|
customerId,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
time: {
|
|
|
|
|
|
|
|
$gte: start,
|
|
|
|
|
|
|
|
$lte: end
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
...(block !== "All" && { block: tank.blockName }), // Ensure correct field names
|
|
|
|
...(block !== "All" && { block: tank.blockName }), // Ensure correct field names
|
|
|
|
...(typeofwater !== "all" && { typeofwater: tank.typeOfWater }) // Ensure correct field names
|
|
|
|
...(typeofwater !== "all" && { typeofwater: tank.typeOfWater }) // Ensure correct field names
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const total_consumption_from_records = tankConsumptions.reduce((acc, record) => {
|
|
|
|
const filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
|
|
|
const recordTime = moment(record.time, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
|
|
|
return recordTime >= start && recordTime <= end;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => {
|
|
|
|
return acc + parseInt(record.consumption, 10);
|
|
|
|
return acc + parseInt(record.consumption, 10);
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
|
|