From 1f838f067e124d4fd1c499f9c3b1af31e8d3495a Mon Sep 17 00:00:00 2001 From: Rao Shahbaz Date: Tue, 14 Jun 2022 13:36:36 +0500 Subject: [PATCH] attendance details --- backend/controllers/attendance_controller.js | 30 ++-- backend/routes/routes.js | 2 +- login_app/lib/pages/monthly_attendance.dart | 173 ++++++++++++++++--- 3 files changed, 166 insertions(+), 39 deletions(-) diff --git a/backend/controllers/attendance_controller.js b/backend/controllers/attendance_controller.js index 59e0edd..a2b629a 100644 --- a/backend/controllers/attendance_controller.js +++ b/backend/controllers/attendance_controller.js @@ -784,18 +784,21 @@ module.exports.GetReportDailyAtt = async (req, res) => { res.send({ Status: false, message: error.message }) }) } -module.exports.GetLastReport = async (req, res) => { +module.exports.GetLastReport = (req, res) => { let startDate; let endDate; - if(req.body.StartDate) startDate = new Date(req.body.StartDate) - else startDate = new Date(new Date().setDate(1)) + if(req.body.StartDate) { + startDate = new Date(req.body.StartDate) + } + else { + startDate = new Date(new Date().setDate(1)) + } if(req.body.EndDate) endDate = new Date(req.body.EndDate) else endDate = new Date(new Date().setDate(30)) - console.log("startDate", "-------") const reportagg = [ { '$match': { - 'UserID': req.body.UserID, + 'UserID': req.user._id.toString(), '$and': [ { '$and': [ @@ -847,13 +850,12 @@ module.exports.GetLastReport = async (req, res) => { } } ] - await attendance_repo.aggregate(reportagg) - - .then(lastReport => { - console.log(lastReport) - res.send({ Status: true, data: lastReport }) - }) - .catch(error => { - res.send({ Status: false, message: error.message }) - }) + + attendance_repo.aggregate(reportagg).then(function(success){ + console.log(success) + res.send({ Status: true, data: success }) + }).catch(function(err){ + console.log(err) + res.send({ Status: false, message: err.message }) + }) } \ No newline at end of file diff --git a/backend/routes/routes.js b/backend/routes/routes.js index f6e1369..a6408f5 100644 --- a/backend/routes/routes.js +++ b/backend/routes/routes.js @@ -34,7 +34,7 @@ routes.get('/users', controller.getUsers); routes.get('/gettodayattendance',auth.authMiddleware,attendance_controller.gettodayattendance) routes.get('/getreportholiday',auth.authMiddleware,attendance_controller.getreportholiday) routes.get ('/getalltitles', auth.authMiddleware,titlesDictionary.getAllTitles) -routes.get ('/GetLastReport', auth.authMiddleware,attendance_controller.GetLastReport) +routes.post ('/GetLastReport', auth.authMiddleware,attendance_controller.GetLastReport) routes.put('/rejectedLeave/:id',auth.authMiddleware,attendance_controller.rejectedLeave) routes.put('/approvalLeave/:id',auth.authMiddleware,attendance_controller.approvedLeave) diff --git a/login_app/lib/pages/monthly_attendance.dart b/login_app/lib/pages/monthly_attendance.dart index 3afb80a..018395e 100644 --- a/login_app/lib/pages/monthly_attendance.dart +++ b/login_app/lib/pages/monthly_attendance.dart @@ -16,23 +16,11 @@ class _MonthlyAttendanceState extends State { var url; String msg = ""; var takenIn; + DateTime? startDate; + DateTime? endDate; + + List _list = [ - List _list = [ - { - 'TakenIn': "2022-05-17 11:14", - 'TakenOut': "2022-05-17 11:14", - 'WorkingHours': "8" - }, - { - 'TakenIn': "2022-05-17 11:14", - 'TakenOut': "2022-05-17 11:14", - 'WorkingHours': "8" - }, - { - 'TakenIn': "2022-05-17 11:14", - 'TakenOut': "2022-05-17 11:14", - 'WorkingHours': "8" - } ]; DataTable _createDataTable() { @@ -73,9 +61,13 @@ class _MonthlyAttendanceState extends State { List _createRows() { return _list .map((list) => DataRow(cells: [ - DataCell(Text(list['TakenIn'])), - DataCell(Text(list['TakenOut'])), - DataCell(Text(list['WorkingHours'])), + + DataCell(Text('${DateFormat('dd-MM-yyyy h:mma').format(DateTime.parse(list['TakenIn'].toString()).toLocal())}')), + DataCell(Text( + (list['TakenOut'] != null) ? + '${DateFormat('dd-MM-yyyy h:mma').format(DateTime.parse(list['TakenOut'].toString()).toLocal())}' : "--" + )), + DataCell(Text(list['TotalHours'].toString())), ])) .toList(); } @@ -99,25 +91,38 @@ class _MonthlyAttendanceState extends State { url = box1.get('updateUrl'); print(takenIn); print('takenIn'); - monthlyReport(); } } void monthlyReport() async { + _list = []; print('token'); print(box1.get('token')); - var response = await http.get( + var response = await http.post( Uri.parse(url + "/api/GetLastReport"), headers: { 'Content-Type': 'application/json', 'Authorization': token - }); + }, + body: jsonEncode({ + 'StartDate': startDate?.toString(), + 'EndDate': endDate?.toString(), + })); + print(response.body); if (response.statusCode == 200 && - jsonDecode(response.body)["status"] == false) { + jsonDecode(response.body)["Status"] == false) { print('Error'); } else { msg = "Monthly Report Fetched Successfully"; print("Response from monthly"); print(response.body); + List data = jsonDecode(response.body)['data']; + print(data); + setState(() { + _list.addAll(data); + }); + + print("YA string ha"); + print(_list); var snackBar = SnackBar( content: Text(msg, style: TextStyle(fontSize: 16.5)), backgroundColor: Colors.green, @@ -125,6 +130,65 @@ class _MonthlyAttendanceState extends State { ScaffoldMessenger.of(context).showSnackBar(snackBar); } } + Future pickDate(BuildContext context) async { + final initialDate = DateTime.now(); + final newDate = await showDatePicker( + context: context, + initialDate: startDate ?? initialDate, + firstDate: DateTime(DateTime.now().year - 5), + lastDate: DateTime(DateTime.now().year + 5), + ); + return newDate!; + } + + Future startDateTime(BuildContext context) async { + final date = await pickDate(context); + if (date == null) return; + + setState(() { + startDate = DateTime( + date.year, + date.month, + date.day, + ); + }); + } + + Future endDateTime(BuildContext context) async { + final date = await pickDate(context); + if (date == null) return; + + setState(() { + endDate = DateTime( + date.year, + date.month, + date.day, + ); + }); + } + + String selectStartDate() { + if (startDate == null) { + return 'Select First Date'; + } else { + return DateFormat.yMMMEd().format(startDate!); + } + } + + String selectEndDate() { + if (endDate == null) { + return 'Select Last Date'; + } else { + return DateFormat.yMMMEd().format(endDate!); + } + } + + void onSubmitDataMultiple() { + if (startDate == null || endDate == null) { + return; + } + monthlyReport(); + } @override Widget build(BuildContext context) { @@ -132,7 +196,68 @@ class _MonthlyAttendanceState extends State { appBar: AppBar( title: const Text('Monthly Attendance'), ), - body: SingleChildScrollView(child: _createDataTable()), + body: SingleChildScrollView(child: Column( + children: [ + SizedBox(height: 15,), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(20.0)), + ), + child: Text('Start Date'), + onPressed: () { + startDateTime(context); + }), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(20.0)), + ), + child: Text('End Date'), + onPressed: () { + endDateTime(context); + }), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Text(startDate == null + ? 'Select Start Date' + : selectStartDate()), + Text(endDate == null + ? 'Select Last Date' + : selectEndDate()), + ], + ), + SizedBox( + height: 15, + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20.0)), + ), + onPressed: () => onSubmitDataMultiple(), + child: Text( + 'Search', + style: TextStyle(fontSize: 16), + ), + ), + _createDataTable() + ], + )), ); } }