Skip to content

Commit 66cf3db

Browse files
committed
up
1 parent 424a49b commit 66cf3db

File tree

3 files changed

+101
-42
lines changed

3 files changed

+101
-42
lines changed

lib/services/mailService.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:propview/services/authService.dart';
2+
import 'package:http/http.dart' as http;
3+
4+
class MailService extends AuthService {
5+
static Future<bool> sendMail(var payload) async {
6+
print(payload);
7+
http.Response response = await AuthService.makeAuthenticatedRequest(
8+
AuthService.BASE_URI + 'api/mail/send/',
9+
method: 'POST',
10+
body: payload);
11+
print(response.body);
12+
if (response.statusCode == 200) {
13+
print("success");
14+
return true;
15+
} else {
16+
print("failure");
17+
return false;
18+
}
19+
}
20+
}

lib/views/Admin/Attendance/SoloAttendance.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:propview/config.dart';
66
import 'package:propview/models/Attendance.dart';
77
import 'package:propview/models/User.dart';
88
import 'package:propview/services/attendanceService.dart';
9+
import 'package:propview/services/mailService.dart';
910
import 'package:propview/services/userService.dart';
1011
import 'package:propview/utils/progressBar.dart';
1112
import 'package:propview/utils/snackBar.dart';
@@ -100,6 +101,13 @@ class _SoloAttendanceState extends State<SoloAttendance> {
100101
tempAttendance.diff_km =
101102
user.bikeReading == 1 ? endMeter - startMeter : 0;
102103
}
104+
MailService.sendMail(jsonEncode({
105+
"name": user.name,
106+
"type": "Punch Out",
107+
"lat": position.latitude,
108+
"long": position.longitude,
109+
110+
}));
103111
var result = await AttendanceService.updateLog(tempAttendance.toJson(), id);
104112
if (result && id != "-") {
105113
showInSnackBar(
@@ -114,6 +122,7 @@ class _SoloAttendanceState extends State<SoloAttendance> {
114122
1500,
115123
);
116124
}
125+
Navigator.of(context).pop();
117126
}
118127

119128
createLog() async {
@@ -140,6 +149,13 @@ class _SoloAttendanceState extends State<SoloAttendance> {
140149
position.latitude.toString() + "," + position.longitude.toString(),
141150
"geo_out": 0,
142151
};
152+
MailService.sendMail(jsonEncode({
153+
"name": user.name,
154+
"type": "Punch In",
155+
"lat": position.latitude,
156+
"long": position.longitude,
157+
158+
}));
143159
var result = await AttendanceService.createLog(payload);
144160
if (result != false) {
145161
setState(() {
@@ -184,7 +200,7 @@ class _SoloAttendanceState extends State<SoloAttendance> {
184200
@override
185201
Widget build(BuildContext context) {
186202
return WillPopScope(
187-
onWillPop: () async{
203+
onWillPop: () async {
188204
Navigator.of(context).push(
189205
MaterialPageRoute(
190206
builder: (context) => LandingScreen(
@@ -791,6 +807,5 @@ class _SoloAttendanceState extends State<SoloAttendance> {
791807
reset = true;
792808
});
793809
updateLog();
794-
Navigator.of(context).pop();
795810
}
796811
}

lib/views/Employee/Attendance/SoloAttendanceScreen.dart

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:propview/config.dart';
77
import 'package:propview/models/Attendance.dart';
88
import 'package:propview/models/User.dart';
99
import 'package:propview/services/attendanceService.dart';
10+
import 'package:propview/services/mailService.dart';
1011
import 'package:propview/services/userService.dart';
1112
import 'package:propview/utils/progressBar.dart';
1213
import 'package:propview/utils/snackBar.dart';
@@ -52,6 +53,7 @@ class _SoloAttendanceState extends State<SoloAttendance> {
5253
});
5354
await getLocation();
5455
user = await UserService.getUser();
56+
print(user.parentId);
5557
if (widget.attendanceElement != null) {
5658
attendanceElement = await AttendanceService.getLogById(
5759
widget.attendanceElement.attendanceId);
@@ -85,36 +87,42 @@ class _SoloAttendanceState extends State<SoloAttendance> {
8587
});
8688
}
8789

88-
updateLog() async {
89-
DateTime startTime = DateTime.parse(start);
90-
DateTime endTime = DateTime.parse(end);
91-
AttendanceElement tempAttendance;
92-
if (id != "-") {
93-
tempAttendance = await AttendanceService.getLogById(id);
94-
print(tempAttendance.toJson());
95-
tempAttendance.geo_out =
96-
position.latitude.toString() + "," + position.longitude.toString();
97-
tempAttendance.meterOut = user.bikeReading == 1 ? endMeter : 0;
98-
tempAttendance.punchOut = endTime;
99-
tempAttendance.workHour = endTime.difference(startTime).inHours;
100-
tempAttendance.diff_km =
101-
user.bikeReading == 1 ? endMeter - startMeter : 0;
102-
}
103-
var result =
104-
await AttendanceService.updateLog(tempAttendance.toJson(), id);
105-
if (result && id != "-") {
106-
showInSnackBar(
107-
context,
108-
"Attendance updated successfully",
109-
1500,
110-
);
111-
} else {
112-
showInSnackBar(
113-
context,
114-
"Attendance updation failed",
115-
1500,
116-
);
117-
}
90+
updateLog() async {
91+
DateTime startTime = DateTime.parse(start);
92+
DateTime endTime = DateTime.parse(end);
93+
AttendanceElement tempAttendance;
94+
await MailService.sendMail(jsonEncode({
95+
"name": user.name,
96+
"type": "Punch Out",
97+
"lat": position.latitude,
98+
"long": position.longitude,
99+
100+
}));
101+
if (id != "-") {
102+
tempAttendance = await AttendanceService.getLogById(id);
103+
print(tempAttendance.toJson());
104+
tempAttendance.geo_out =
105+
position.latitude.toString() + "," + position.longitude.toString();
106+
tempAttendance.meterOut = user.bikeReading == 1 ? endMeter : 0;
107+
tempAttendance.punchOut = endTime;
108+
tempAttendance.workHour = endTime.difference(startTime).inHours;
109+
tempAttendance.diff_km =
110+
user.bikeReading == 1 ? endMeter - startMeter : 0;
111+
}
112+
var result = await AttendanceService.updateLog(tempAttendance.toJson(), id);
113+
if (result && id != "-") {
114+
showInSnackBar(
115+
context,
116+
"Attendance updated successfully",
117+
1500,
118+
);
119+
} else {
120+
showInSnackBar(
121+
context,
122+
"Attendance updation failed",
123+
1500,
124+
);
125+
}
118126
}
119127

120128
createLog() async {
@@ -141,6 +149,13 @@ class _SoloAttendanceState extends State<SoloAttendance> {
141149
position.latitude.toString() + "," + position.longitude.toString(),
142150
"geo_out": 0,
143151
};
152+
await MailService.sendMail(jsonEncode({
153+
"name": user.name,
154+
"type": "Punch In",
155+
"lat": position.latitude,
156+
"long": position.longitude,
157+
158+
}));
144159
var result = await AttendanceService.createLog(payload);
145160
if (result != false) {
146161
setState(() {
@@ -184,7 +199,7 @@ class _SoloAttendanceState extends State<SoloAttendance> {
184199
@override
185200
Widget build(BuildContext context) {
186201
return WillPopScope(
187-
onWillPop: () async{
202+
onWillPop: () async {
188203
Navigator.of(context).push(
189204
MaterialPageRoute(
190205
builder: (context) => LandingScreen(
@@ -299,10 +314,12 @@ class _SoloAttendanceState extends State<SoloAttendance> {
299314
Padding(
300315
padding: EdgeInsets.symmetric(horizontal: 32.0),
301316
child: Row(
302-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
317+
mainAxisAlignment:
318+
MainAxisAlignment.spaceBetween,
303319
children: [
304320
Column(
305-
crossAxisAlignment: CrossAxisAlignment.start,
321+
crossAxisAlignment:
322+
CrossAxisAlignment.start,
306323
mainAxisSize: MainAxisSize.min,
307324
children: [
308325
Text(
@@ -353,7 +370,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
353370
],
354371
),
355372
Column(
356-
crossAxisAlignment: CrossAxisAlignment.start,
373+
crossAxisAlignment:
374+
CrossAxisAlignment.start,
357375
mainAxisSize: MainAxisSize.min,
358376
children: [
359377
Text(
@@ -416,7 +434,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
416434
if (start == "--/--/-- -- : --") {
417435
showDialog(
418436
context: context,
419-
builder: (context) => AlertDialog(
437+
builder: (context) =>
438+
AlertDialog(
420439
content: Text(
421440
"Do you want to punch in now?"),
422441
actions: [
@@ -430,7 +449,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
430449
} else {
431450
showDialog(
432451
context: context,
433-
builder: (context) => AlertDialog(
452+
builder: (context) =>
453+
AlertDialog(
434454
content: Text(
435455
"Do you want to punch out now?"),
436456
actions: [
@@ -447,7 +467,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
447467
if (start == "--/--/-- -- : --") {
448468
showDialog(
449469
context: context,
450-
builder: (context) => AlertDialog(
470+
builder: (context) =>
471+
AlertDialog(
451472
content: Text(
452473
"Do you want to punch in now?"),
453474
actions: [
@@ -461,7 +482,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
461482
} else {
462483
showDialog(
463484
context: context,
464-
builder: (context) => AlertDialog(
485+
builder: (context) =>
486+
AlertDialog(
465487
content: Text(
466488
"Do you want to punch out now?"),
467489
actions: [
@@ -529,7 +551,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
529551
if (start == "--/--/-- -- : --") {
530552
showDialog(
531553
context: context,
532-
builder: (context) => AlertDialog(
554+
builder: (context) =>
555+
AlertDialog(
533556
content: Text(
534557
"Do you want to punch in now?"),
535558
actions: [
@@ -570,7 +593,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
570593
if (start == "--/--/-- -- : --") {
571594
showDialog(
572595
context: context,
573-
builder: (context) => AlertDialog(
596+
builder: (context) =>
597+
AlertDialog(
574598
content: Text(
575599
"Do you want to punch in now?"),
576600
actions: [

0 commit comments

Comments
 (0)