master
Varun 12 months ago
parent 1e606bf465
commit cbe5683cdd

@ -4453,7 +4453,7 @@ exports.consumptionofparticulartank = async (request, reply) => {
customerId,
tankName,
tankLocation: tankLocation,
}).sort({ time: 1 });
});
// Filter records in JavaScript by comparing the 'time' field after converting to Date
const filteredConsumptions = tankConsumptions.filter((record) => {
@ -4461,6 +4461,13 @@ exports.consumptionofparticulartank = async (request, reply) => {
return recordTime >= start && recordTime <= end;
});
// Sort filtered records by date (ascending)
filteredConsumptions.sort((a, b) => {
const dateA = moment(a.time, "DD-MMM-YYYY - HH:mm").toDate();
const dateB = moment(b.time, "DD-MMM-YYYY - HH:mm").toDate();
return dateA - dateB; // Sort in ascending order
});
// Calculate total consumption from filtered records
const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => {
return acc + parseInt(record.consumption, 10);
@ -4496,3 +4503,5 @@ exports.consumptionofparticulartank = async (request, reply) => {

Loading…
Cancel
Save