@@ -7,6 +7,7 @@ import 'package:propview/config.dart';
77import 'package:propview/models/Attendance.dart' ;
88import 'package:propview/models/User.dart' ;
99import 'package:propview/services/attendanceService.dart' ;
10+ import 'package:propview/services/mailService.dart' ;
1011import 'package:propview/services/userService.dart' ;
1112import 'package:propview/utils/progressBar.dart' ;
1213import '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