master^2
Varun 8 months ago
parent 3979e22b7f
commit 72a278ae6c

@ -1065,7 +1065,13 @@ exports.consumption = async (request, reply) => {
// Construct the query object
const tankQuery = { customerId, tankLocation: "overhead" };
if (block !== "All") tankQuery.blockName = block;
if (typeofwater !== "all") tankQuery.typeOfWater = typeofwater;
// Add typeofwater filter
if (typeofwater === "bore") {
tankQuery.typeOfWater = { $in: ["bore", "Bore Water"] };
} else if (typeofwater === "drinking") {
tankQuery.typeOfWater = { $in: ["drinking", "Drinking Water"] };
}
const tanks = await Tank.find(tankQuery);
const tankData = [];
@ -1087,7 +1093,8 @@ exports.consumption = async (request, reply) => {
tankName: tank.tankName,
tankLocation: tank.tankLocation,
...(block !== "All" && { block: tank.blockName }),
...(typeofwater !== "all" && { typeofwater: tank.typeOfWater }),
...(typeofwater === "bore" && { typeofwater: { $in: ["bore", "Bore Water"] } }),
...(typeofwater === "drinking" && { typeofwater: { $in: ["drinking", "Drinking Water"] } }),
});
const filteredConsumptions = tankConsumptions.filter((record) => {
@ -1102,11 +1109,10 @@ 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 and capacities based on water type
if (tank.typeOfWater === "bore") {
if (tank.typeOfWater === "bore" || tank.typeOfWater === "Bore Water") {
totalBoreConsumptionForSelectedBlockAndTypeOfWater += consumption;
totalBoreCapacityForSelectedBlockAndTypeOfWater += capacity;
}
if (tank.typeOfWater === "drinking") {
} else if (tank.typeOfWater === "drinking" || tank.typeOfWater === "Drinking Water") {
totalDrinkingConsumptionForSelectedBlockAndTypeOfWater += consumption;
totalDrinkingCapacityForSelectedBlockAndTypeOfWater += capacity;
}
@ -1127,7 +1133,7 @@ exports.consumption = async (request, reply) => {
});
}
// Calculate total consumption percentage
// Calculate total consumption percentages
const boreConsumptionPercentage = totalBoreCapacityForSelectedBlockAndTypeOfWater
? ((totalBoreConsumptionForSelectedBlockAndTypeOfWater / totalBoreCapacityForSelectedBlockAndTypeOfWater) * 100).toFixed(2)
: 0;
@ -1141,7 +1147,10 @@ exports.consumption = async (request, reply) => {
? boreConsumptionPercentage
: typeofwater === "drinking"
? drinkingConsumptionPercentage
: 0;
: ((totalBoreConsumptionForSelectedBlockAndTypeOfWater + totalDrinkingConsumptionForSelectedBlockAndTypeOfWater) /
(totalBoreCapacityForSelectedBlockAndTypeOfWater + totalDrinkingCapacityForSelectedBlockAndTypeOfWater) *
100
).toFixed(2);
// Include the total consumption in the response
const response = {
@ -1149,11 +1158,19 @@ exports.consumption = async (request, reply) => {
tankData,
consumptiorecordsdatewise: tankconsumptionData,
totalConsumptionPercentage,
[`total consumption of ${typeofwater} and selected block`]: typeofwater === "bore"
? totalBoreConsumptionForSelectedBlockAndTypeOfWater
: typeofwater === "drinking"
? totalDrinkingConsumptionForSelectedBlockAndTypeOfWater
: totalBoreConsumptionForSelectedBlockAndTypeOfWater + totalDrinkingConsumptionForSelectedBlockAndTypeOfWater,
...(typeofwater === "all"
? {
totalConsumptionPercentageForBore: boreConsumptionPercentage,
totalConsumptionPercentageForDrinking: drinkingConsumptionPercentage,
totalConsumptionForBore: totalBoreConsumptionForSelectedBlockAndTypeOfWater,
totalConsumptionForDrinking: totalDrinkingConsumptionForSelectedBlockAndTypeOfWater,
}
: {
[`total consumption of ${typeofwater} and selected block`]:
typeofwater === "bore"
? totalBoreConsumptionForSelectedBlockAndTypeOfWater
: totalDrinkingConsumptionForSelectedBlockAndTypeOfWater,
}),
};
reply.send(response);
@ -1163,6 +1180,7 @@ exports.consumption = async (request, reply) => {
};
exports.consumptiondatewiseofalltanks = async (request, reply) => {
try {
const { customerId } = request.params;
@ -2347,7 +2365,7 @@ exports.motorAction = async (req, reply) => {
const blockName = req.body.from || "Unknown Block"; // Provide a fallback if `from` is missing
const tankName = req.body.to || "Unknown Tank"; // Provide a fallback if `to` is missing
const stopTime = req.body.stopTime
const motorOnType = req.body.motor_on_type;
const motorOnType = "manual";
const manual_threshold_time = req.body.manual_threshold_time;
let hasNotifiedStart = false;
let hasNotifiedStop = false;
@ -2402,7 +2420,7 @@ exports.motorAction = async (req, reply) => {
{ $set: { "connections.inputConnections.$.motor_stop_status": "2",
"connections.inputConnections.$.manual_threshold_time": manual_threshold_time,
"connections.inputConnections.$.threshold_type": "time",
"connections.inputConnections.$.motor_on_type": motorOnType } }
"connections.inputConnections.$.motor_on_type": "manual" } }
);
// await Tank.updateOne(

Loading…
Cancel
Save