@@ -6,6 +6,7 @@ import 'package:propview/config.dart';
66import 'package:propview/models/Attendance.dart' ;
77import 'package:propview/models/User.dart' ;
88import 'package:propview/services/attendanceService.dart' ;
9+ import 'package:propview/services/mailService.dart' ;
910import 'package:propview/services/userService.dart' ;
1011import 'package:propview/utils/progressBar.dart' ;
1112import 'package:propview/utils/snackBar.dart' ;
@@ -46,16 +47,29 @@ class _SoloAttendanceState extends State<SoloAttendance> {
4647 desiredAccuracy: LocationAccuracy .high);
4748 }
4849
50+ List <String > parentEmail = [];
4951 getData () async {
5052 setState (() {
5153 loading = true ;
5254 });
5355 await getLocation ();
5456 user = await UserService .getUser ();
57+ if (user.parentId != "" ) {
58+ var parentIdList = user.parentId.split ("," );
59+ print ((parentIdList));
60+ print (parentIdList.length);
61+ for (var i = 0 ; i < parentIdList.length; i++ ) {
62+ User parent = await UserService .getUserById (parentIdList[i]);
63+ setState (() {
64+ parentEmail.add (parent.officialEmail);
65+ });
66+ }
67+ }
5568 if (widget.attendanceElement != null ) {
5669 attendanceElement = await AttendanceService .getLogById (
5770 widget.attendanceElement.attendanceId);
5871 }
72+ print ((parentEmail));
5973 getPunch ();
6074 setState (() {
6175 loading = false ;
@@ -85,36 +99,44 @@ class _SoloAttendanceState extends State<SoloAttendance> {
8599 });
86100 }
87101
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- }
102+ updateLog () async {
103+ DateTime startTime = DateTime .parse (start);
104+ DateTime endTime = DateTime .parse (end);
105+ AttendanceElement tempAttendance;
106+ if (id != "-" ) {
107+ tempAttendance = await AttendanceService .getLogById (id);
108+ print (tempAttendance.toJson ());
109+ tempAttendance.geo_out =
110+ position.latitude.toString () + "," + position.longitude.toString ();
111+ tempAttendance.meterOut = user.bikeReading == 1 ? endMeter : 0 ;
112+ tempAttendance.punchOut = endTime;
113+ tempAttendance.workHour = endTime.difference (startTime).inHours;
114+ tempAttendance.diff_km =
115+ user.bikeReading == 1 ? endMeter - startMeter : 0 ;
116+ }
117+ if (parentEmail.isNotEmpty) {
118+ MailService .sendMail (jsonEncode ({
119+ "name" : user.name,
120+ "type" : "Punch Out" ,
121+ "lat" : position.latitude,
122+ "long" : position.longitude,
123+ "to" : parentEmail
124+ }));
125+ }
126+ var result = await AttendanceService .updateLog (tempAttendance.toJson (), id);
127+ if (result && id != "-" ) {
128+ showInSnackBar (
129+ context,
130+ "Attendance updated successfully" ,
131+ 1500 ,
132+ );
133+ } else {
134+ showInSnackBar (
135+ context,
136+ "Attendance updation failed" ,
137+ 1500 ,
138+ );
139+ }
118140 }
119141
120142 createLog () async {
@@ -141,6 +163,15 @@ class _SoloAttendanceState extends State<SoloAttendance> {
141163 position.latitude.toString () + "," + position.longitude.toString (),
142164 "geo_out" : 0 ,
143165 };
166+ if (parentEmail.isNotEmpty) {
167+ MailService .sendMail (jsonEncode ({
168+ "name" : user.name,
169+ "type" : "Punch In" ,
170+ "lat" : position.latitude,
171+ "long" : position.longitude,
172+ "to" : parentEmail
173+ }));
174+ }
144175 var result = await AttendanceService .createLog (payload);
145176 if (result != false ) {
146177 setState (() {
@@ -185,7 +216,7 @@ class _SoloAttendanceState extends State<SoloAttendance> {
185216 @override
186217 Widget build (BuildContext context) {
187218 return WillPopScope (
188- onWillPop: () async {
219+ onWillPop: () async {
189220 Navigator .of (context).push (
190221 MaterialPageRoute (
191222 builder: (context) => LandingScreen (
@@ -300,10 +331,12 @@ class _SoloAttendanceState extends State<SoloAttendance> {
300331 Padding (
301332 padding: EdgeInsets .symmetric (horizontal: 32.0 ),
302333 child: Row (
303- mainAxisAlignment: MainAxisAlignment .spaceBetween,
334+ mainAxisAlignment:
335+ MainAxisAlignment .spaceBetween,
304336 children: [
305337 Column (
306- crossAxisAlignment: CrossAxisAlignment .start,
338+ crossAxisAlignment:
339+ CrossAxisAlignment .start,
307340 mainAxisSize: MainAxisSize .min,
308341 children: [
309342 Text (
@@ -354,7 +387,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
354387 ],
355388 ),
356389 Column (
357- crossAxisAlignment: CrossAxisAlignment .start,
390+ crossAxisAlignment:
391+ CrossAxisAlignment .start,
358392 mainAxisSize: MainAxisSize .min,
359393 children: [
360394 Text (
@@ -417,7 +451,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
417451 if (start == "--/--/-- -- : --" ) {
418452 showDialog (
419453 context: context,
420- builder: (context) => AlertDialog (
454+ builder: (context) =>
455+ AlertDialog (
421456 content: Text (
422457 "Do you want to punch in now?" ),
423458 actions: [
@@ -431,7 +466,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
431466 } else {
432467 showDialog (
433468 context: context,
434- builder: (context) => AlertDialog (
469+ builder: (context) =>
470+ AlertDialog (
435471 content: Text (
436472 "Do you want to punch out now?" ),
437473 actions: [
@@ -448,7 +484,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
448484 if (start == "--/--/-- -- : --" ) {
449485 showDialog (
450486 context: context,
451- builder: (context) => AlertDialog (
487+ builder: (context) =>
488+ AlertDialog (
452489 content: Text (
453490 "Do you want to punch in now?" ),
454491 actions: [
@@ -462,7 +499,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
462499 } else {
463500 showDialog (
464501 context: context,
465- builder: (context) => AlertDialog (
502+ builder: (context) =>
503+ AlertDialog (
466504 content: Text (
467505 "Do you want to punch out now?" ),
468506 actions: [
@@ -530,7 +568,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
530568 if (start == "--/--/-- -- : --" ) {
531569 showDialog (
532570 context: context,
533- builder: (context) => AlertDialog (
571+ builder: (context) =>
572+ AlertDialog (
534573 content: Text (
535574 "Do you want to punch in now?" ),
536575 actions: [
@@ -571,7 +610,8 @@ class _SoloAttendanceState extends State<SoloAttendance> {
571610 if (start == "--/--/-- -- : --" ) {
572611 showDialog (
573612 context: context,
574- builder: (context) => AlertDialog (
613+ builder: (context) =>
614+ AlertDialog (
575615 content: Text (
576616 "Do you want to punch in now?" ),
577617 actions: [
0 commit comments