Skip to content

Commit

Permalink
attendance details
Browse files Browse the repository at this point in the history
  • Loading branch information
shahbaz-rao committed Jun 14, 2022
1 parent 222de37 commit 1f838f0
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 39 deletions.
30 changes: 16 additions & 14 deletions backend/controllers/attendance_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down Expand Up @@ -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 })
})
}
2 changes: 1 addition & 1 deletion backend/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
173 changes: 149 additions & 24 deletions login_app/lib/pages/monthly_attendance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@ class _MonthlyAttendanceState extends State<MonthlyAttendance> {
var url;
String msg = "";
var takenIn;
DateTime? startDate;
DateTime? endDate;

List _list = [

List<Map> _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() {
Expand Down Expand Up @@ -73,9 +61,13 @@ class _MonthlyAttendanceState extends State<MonthlyAttendance> {
List<DataRow> _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();
}
Expand All @@ -99,40 +91,173 @@ class _MonthlyAttendanceState extends State<MonthlyAttendance> {
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: <String, String>{
'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,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
Future<DateTime> 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) {
return Scaffold(
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()
],
)),
);
}
}

0 comments on commit 1f838f0

Please sign in to comment.