Skip to content

Commit

Permalink
attendance Controller Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharjeel007305 committed May 17, 2022
1 parent 37634bf commit e10d42d
Showing 1 changed file with 176 additions and 93 deletions.
269 changes: 176 additions & 93 deletions backend/controllers/attendance_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const fs = require("fs");

module.exports.attendance = async (req, res) => {
const DateStr = new Date(req.body.Date);
console.log("Body Date ",req.body.Date);
console.log("Converted Date ",DateStr);
console.log("Body Date ", req.body.Date);
console.log("Converted Date ", DateStr);
const TransactionType = req.body.TransactionType;
const ActionDetails = {
ActionTakenByName: req.user.FirstName + ' ' + req.user.LastName,
Expand Down Expand Up @@ -111,112 +111,195 @@ module.exports.register = (req, res) => {


module.exports.report = async (req, res) => {
console.log (req.body,"Danish")
const aggr = [
// {
// '$addFields': {
// 'month': {
// '$month': new Date('Tue, 26 Apr 2022 00:00:00 GMT')
// },
// 'Year': {
// '$year': new Date('Tue, 26 Apr 2022 00:00:00 GMT')
// },
// 'Day': {
// '$dayOfMonth': new Date(req.body.)
// }
// }
// },
{
'$match': {
'ActionDetails.ActionTakenOn': {
'$gte': new Date(req.body.StartDate),
'$lte': new Date(new Date(req.body.EndDate).setHours(23, 59, 59))
console.log(req.body, "Danish")
let startDate = new Date(req.body.StartDate);
let endDate = new Date(req.body.EndDate);
// console.log("===> ", startDate.getDate())
// console.log("===> ",startDate.getMonth())
// console.log("===> ",startDate.getFullYear())
// console.log(endDate.getDate())
// console.log(endDate.getMonth())
// console.log(endDate.getFullYear())
const aggr = [
{
// '$match': {
// 'ActionDetails.ActionTakenOn': {
// '$gte': new Date(req.body.StartDate),
// '$lte': new Date(new Date(req.body.EndDate).setHours(23, 59, 59))
// },
'$match': {
'Date.Day': {
'$gte': startDate.getDate()
},
// 'Date.Month': 3,
// 'Date.Day': 18,
// 'Date.Year': 2022
'Date.Month': {
'$gte': startDate.getMonth()
},
'Date.Year': {
'$gte': startDate.getFullYear()
},
'Date.Day': {
'$lte': endDate.getDate()
},
'Date.Month': {
'$lte': endDate.getMonth()
},
'Date.Year': {
'$lte': endDate.getFullYear()
}
}
}, {
'$addFields': {
}, {
'$addFields': {
'HOUR': {
'$divide': [
{
'$subtract': [
'$TakenOut', '$TakenIn'
]
}, 3600000
]
'$divide': [
{
'$subtract': [
'$TakenOut', '$TakenIn'
]
}, 3600000
]
}
}
}, {
'$group': {
'_id': '$UserID',
}
}, {
'$group': {
'_id': '$UserID',
'Details': {
'$push': '$$ROOT'
},
'$push': '$$ROOT'
},
'TotalHours': {
'$sum': '$HOUR'
},
'$sum': '$HOUR'
},
'WorkingHours': {
'$sum': '$WorkingHours'
},
'$sum': '$WorkingHours'
},
'ManualAttendance': {
'$sum': {
'$cond': [
{
'$eq': [
'$WorkingHours', true
'$sum': {
'$cond': [
{
'$eq': [
'$WorkingHours', true
]
}, 1, 0
]
}, 1, 0
]
}
},
}
},
'TotalHolidays': {
'$sum': {
'$cond': [
{
'$eq': [
'$TransactionType', 'Holiday'
]
}, 1, 0
]
}
},
'Leave': {
'$sum': {
'$cond': [
{
'$and': [
{
'$eq': [
'$TransactionType', 'Leave'
]
}, {
'$eq': [
'$Status', 'Approved'
]
}
]
}, 1, 0
]
'$sum': {
'$cond': [
{
'$eq': [
'$TransactionType', 'Holiday'
]
}, 1, 0
]
}
},
'Leave': {
'$sum': {
'$cond': [
{
'$and': [
{
'$eq': [
'$TransactionType', 'Leave'
]
}, {
'$eq': [
'$Status', 'Approved'
]
}
]
}, 1, 0
]
}
}
}
}

}
]

console.log(req.body)
}
]
// const LeaveShow =
// [
// {
// '$match': {
// 'Date.Day': {
// '$gte': startDate.getDate()
// },
// 'Date.Month': {
// '$gte': startDate.getMonth()
// },
// 'Date.Year': {
// '$gte': startDate.getFullYear()
// },
// 'Date.Day': {
// '$lte': endDate.getDate()
// },
// 'Date.Month': {
// '$lte': endDate.getMonth()
// },
// 'Date.Year': {
// '$lte': endDate.getFullYear()
// }
// }
// }, {
// '$group': {
// '_id': '$UserID',
// 'Details': {
// '$push': '$$ROOT'
// },
// 'TotalHolidays': {
// '$sum': {
// '$cond': [
// {
// '$eq': [
// '$TransactionType', 'Holiday'
// ]
// }, 1, 0
// ]
// }
// },
// 'Leave': {
// '$sum': {
// '$cond': [
// {
// '$and': [
// {
// '$eq': [
// '$TransactionType', 'Leave'
// ]
// }, {
// '$eq': [
// '$Status', 'Approved'
// ]
// }
// ]
// }, 1, 0
// ]
// }
// }
// }
// }
// ]
console.log(req.body)
if (req.body.userIds && req.body.userIds.length) {
aggr[0].$match['UserName'] = { $in: req.body.userIds }
}
attendance_repo.aggregate(aggr)
.then(attendance => {
res.send({ Status: true, data: attendance })
console.log(aggr)
})
.catch(error => {
res.send({ Status: false, message: error.message })
})
attendance_repo.aggregate(aggr).then((attend) => {
res.send({ Status: true, data: attend })
}).catch(error => {
res.send({ Status: false, msg: "Msg "+error })
})
//const show = await attendance_repo.aggregate(LeaveShow)
//console.log(show, 'show =======')
//console.log(rep, ' rep =======')
// let attend = []
// attend.push(rep)
// console.log("242 =====>> ",attend)
// rep.then(attend => {
// console.log(attend, 'Sharjeel')
// res.send({ Status: true, data: attend })
// })
// .catch(error => {
// res.send({ Status: false, msg: "Msg "+error })
// })
}

module.exports.holiday = async (req, res) => {
Expand Down

0 comments on commit e10d42d

Please sign in to comment.