|
|
|
@ -3791,7 +3791,7 @@ const updatetotalConsumptiontillmidnight = async () => {
|
|
|
|
|
const formattedDate = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
|
|
|
|
|
|
// Check if the record already exists
|
|
|
|
|
const existingRecord = await TankConsumptionOriginalSchema.findOne({
|
|
|
|
|
const existingRecord = await TankConsumptionSchema.findOne({
|
|
|
|
|
customerId: tank.customerId,
|
|
|
|
|
tankName: tank.tankName,
|
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
@ -3800,7 +3800,7 @@ const updatetotalConsumptiontillmidnight = async () => {
|
|
|
|
|
|
|
|
|
|
if (!existingRecord) {
|
|
|
|
|
// Create and save the new document if it doesn't exist
|
|
|
|
|
const newTankConsumption = new TankConsumptionOriginalSchema({
|
|
|
|
|
const newTankConsumption = new TankConsumptionSchema({
|
|
|
|
|
customerId: tank.customerId,
|
|
|
|
|
tankName: tank.tankName,
|
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
@ -4408,14 +4408,18 @@ client.on('message', async (topic, message) => {
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//const moment = require('moment');
|
|
|
|
|
|
|
|
|
|
exports.consumptionofparticulartank = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = request.params;
|
|
|
|
|
const { startDate, stopDate, tankName, tankLocation, block } = request.body;
|
|
|
|
|
|
|
|
|
|
// Ensure dates are formatted or parsed correctly for the query
|
|
|
|
|
const start = startDate;
|
|
|
|
|
const end = stopDate;
|
|
|
|
|
// Convert input dates into strings in the same format as stored in the database
|
|
|
|
|
const start = moment(startDate, "DD-MMM-YYYY - HH:mm").format("DD-MMM-YYYY - HH:mm");
|
|
|
|
|
const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").format("DD-MMM-YYYY - HH:mm");
|
|
|
|
|
|
|
|
|
|
// Find the tank by customerId, tankLocation, and tankName
|
|
|
|
|
const tank = await Tank.findOne({
|
|
|
|
@ -4435,17 +4439,16 @@ exports.consumptionofparticulartank = async (request, reply) => {
|
|
|
|
|
const total_water_added_from_midnight = parseInt(tank.total_water_added_from_midnight.replace(/,/g, ""), 10);
|
|
|
|
|
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ""), 10);
|
|
|
|
|
|
|
|
|
|
// Find consumption records for the tank between the given dates
|
|
|
|
|
// Find consumption records by comparing string dates
|
|
|
|
|
const tankConsumptions = await TankConsumptionOriginalSchema.find({
|
|
|
|
|
customerId,
|
|
|
|
|
tankName,
|
|
|
|
|
tankLocation: tankLocation,
|
|
|
|
|
time: {
|
|
|
|
|
$gte: start,
|
|
|
|
|
$lte: end,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
$gte: start, // Start date as string
|
|
|
|
|
$lte: end, // End date as string
|
|
|
|
|
}
|
|
|
|
|
}).sort({ time: 1 });
|
|
|
|
|
|
|
|
|
|
// Calculate total consumption from records
|
|
|
|
|
const total_consumption_from_records = tankConsumptions.reduce((acc, record) => {
|
|
|
|
@ -4479,3 +4482,5 @@ exports.consumptionofparticulartank = async (request, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|