|
|
@ -969,7 +969,7 @@ 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 TankConsumptionSchema.find({
|
|
|
|
const tankConsumptions = await TankConsumptionOriginalSchema.find({
|
|
|
|
customerId,
|
|
|
|
customerId,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
@ -3437,13 +3437,15 @@ const updatetotalConsumptiontillmidnight = async () => {
|
|
|
|
const waterlevel_at_midnight = parseInt((tank.waterlevel_at_midnight).replace(/,/g, ''), 10);
|
|
|
|
const waterlevel_at_midnight = parseInt((tank.waterlevel_at_midnight).replace(/,/g, ''), 10);
|
|
|
|
const total_water_added_from_midnight = parseInt((tank.total_water_added_from_midnight).replace(/,/g, ''), 10);
|
|
|
|
const total_water_added_from_midnight = parseInt((tank.total_water_added_from_midnight).replace(/,/g, ''), 10);
|
|
|
|
const waterlevel = parseInt((tank.waterlevel).replace(/,/g, ''), 10);
|
|
|
|
const waterlevel = parseInt((tank.waterlevel).replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
console.log(waterlevel_at_midnight,total_water_added_from_midnight,waterlevel)
|
|
|
|
const totalconsumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel;
|
|
|
|
const totalconsumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel;
|
|
|
|
|
|
|
|
console.log(totalconsumption,tank.tankName)
|
|
|
|
|
|
|
|
|
|
|
|
// Format the date in the desired format
|
|
|
|
// Format the date in the desired format
|
|
|
|
const formattedDate = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
const formattedDate = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the record already exists
|
|
|
|
// Check if the record already exists
|
|
|
|
const existingRecord = await TankConsumptionOriginalSchema.findOne({
|
|
|
|
const existingRecord = await TankConsumptionSchema.findOne({
|
|
|
|
customerId: tank.customerId,
|
|
|
|
customerId: tank.customerId,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
@ -3452,7 +3454,7 @@ const updatetotalConsumptiontillmidnight = async () => {
|
|
|
|
|
|
|
|
|
|
|
|
if (!existingRecord) {
|
|
|
|
if (!existingRecord) {
|
|
|
|
// Create and save the new document if it doesn't exist
|
|
|
|
// Create and save the new document if it doesn't exist
|
|
|
|
const newTankConsumption = new TankConsumptionOriginalSchema({
|
|
|
|
const newTankConsumption = new TankConsumptionSchema({
|
|
|
|
customerId: tank.customerId,
|
|
|
|
customerId: tank.customerId,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankName: tank.tankName,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
@ -3478,7 +3480,7 @@ const updatetotalConsumptiontillmidnight = async () => {
|
|
|
|
clearConsumptionSchedule();
|
|
|
|
clearConsumptionSchedule();
|
|
|
|
|
|
|
|
|
|
|
|
// Schedule the task to run every day at 12:49 PM IST and store the reference
|
|
|
|
// Schedule the task to run every day at 12:49 PM IST and store the reference
|
|
|
|
consumptionTask = cron.schedule('55 23 * * *', updatetotalConsumptiontillmidnight, {
|
|
|
|
consumptionTask = cron.schedule('32 15 * * *', updatetotalConsumptiontillmidnight, {
|
|
|
|
timezone: "Asia/Kolkata"
|
|
|
|
timezone: "Asia/Kolkata"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -3900,10 +3902,16 @@ exports.getBlockData = async (req, reply) => {
|
|
|
|
// Remove duplicates by converting the array to a Set and then back to an array
|
|
|
|
// Remove duplicates by converting the array to a Set and then back to an array
|
|
|
|
const uniqueBlockNames = [...new Set(blockNames)];
|
|
|
|
const uniqueBlockNames = [...new Set(blockNames)];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add "all" and "nduku sneha antha kopam" to the block names
|
|
|
|
|
|
|
|
uniqueBlockNames.unshift("All", "nduku sneha antha kopam","em sadistav cheppu");
|
|
|
|
|
|
|
|
|
|
|
|
// Send the unique blockNames in the response
|
|
|
|
// Send the unique blockNames in the response
|
|
|
|
reply.code(200).send({ blockNames: uniqueBlockNames });
|
|
|
|
reply.code(200).send({ blockNames: uniqueBlockNames });
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
// Log the error for debugging purposes
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
|
|
|
|
// Send an error response
|
|
|
|
// Send an error response
|
|
|
|
reply.code(500).send({ error: err.message });
|
|
|
|
reply.code(500).send({ error: err.message });
|
|
|
|
}
|
|
|
|
}
|
|
|
|