From 7035020bf2d59891ff7b419dffc8922b9078160f Mon Sep 17 00:00:00 2001 From: sharjeel khan Date: Mon, 16 May 2022 12:53:04 +0500 Subject: [PATCH] attendance controller changes --- backend/controllers/attendance_controller.js | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/backend/controllers/attendance_controller.js b/backend/controllers/attendance_controller.js index 4a500fe..0f42aff 100644 --- a/backend/controllers/attendance_controller.js +++ b/backend/controllers/attendance_controller.js @@ -150,9 +150,29 @@ module.exports.report = (req, res) => { $cond: [{ $eq: ['$WorkingHours', true] }, 1, 0] } }, - 'TotalHolidays': { + + } + } + ] + + const ShowLeaveagg = [ + { + '$match': { + 'Date.Month': req.body.Month, + 'Date.Day': req.body.Day, + 'Date.Year': req.body.Year + } + }, + { + '$group': { + '_id': '$UserID', + 'Details': { + '$push': '$$ROOT' + }, + + 'ManualAttendance': { '$sum': { - $cond: [{ $eq: ['$TransactionType', "Holiday"] }, 1, 0] + $cond: [{ $eq: ['$WorkingHours', true] }, 1, 0] } }, 'Leave': { @@ -174,13 +194,18 @@ module.exports.report = (req, res) => { ] } }, + } + } - ] + ] if (req.body.userIds && req.body.userIds.length) { aggr[0].$match['UserName'] = { $in: req.body.userIds } } - attendance_repo.aggregate(aggr) + attendance_repo.aggregate(aggr); + attendance_repo.aggregate(ShowLeaveagg); + let attendance = []; + attendance.push(aggr.ShowLeaveagg) .then(attendance => { res.send({ Status: true, data: attendance }) })