No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

absensi_history_screen.dart 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. import 'dart:convert';
  2. import 'package:firebase_core/firebase_core.dart';
  3. import 'package:firebase_crashlytics/firebase_crashlytics.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:google_fonts/google_fonts.dart';
  6. import 'package:employee_selfservice_mobile/constants.dart';
  7. import 'package:intl/intl.dart';
  8. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  9. import 'dart:developer' as logDev;
  10. import '../AjukanCuti/backgroundHistory.dart';
  11. import 'RequestHttp/historyAbsensi_post.dart';
  12. class HistoryAbsensi extends StatefulWidget {
  13. const HistoryAbsensi({Key? key}) : super(key: key);
  14. @override
  15. State<HistoryAbsensi> createState() => _HistoryAbsensi();
  16. }
  17. class _HistoryAbsensi extends State<HistoryAbsensi> {
  18. late List <String> id_List;
  19. late List <String> employee_name_List;
  20. late List <String> check_in_List;
  21. late List <String> check_out_List;
  22. late List <String> worked_hours_List;
  23. late List <String> dayDate_List;
  24. late List <String> date_List;
  25. late List <String> month_List;
  26. //late List <String> workingHours_List;
  27. late List <String> showCheckIn_List;
  28. late List <String> showCheckOut_List;
  29. int HistoryLength = 0;
  30. //List Visibility Double Date
  31. late List <bool> visibilityDate2;
  32. late List <String> dayDate_list_2;
  33. late List <String> date_list_2;
  34. late List <String> month_list_2;
  35. @override
  36. initState() {
  37. super.initState();
  38. id_List = [""];
  39. employee_name_List = [""];
  40. check_in_List = [""];
  41. check_out_List = [""];
  42. worked_hours_List = [""];
  43. dayDate_List = [""];
  44. date_List = [""];
  45. month_List = [""];
  46. //workingHours_List = [""];
  47. showCheckIn_List = [""];
  48. showCheckOut_List = [""];
  49. visibilityDate2 = [false];
  50. dayDate_list_2 = [""];
  51. date_list_2 = [""];
  52. month_list_2 = [""];
  53. WidgetsBinding.instance.addPostFrameCallback((_) async {
  54. getHistoryData();
  55. });
  56. }
  57. getHistoryData() async {
  58. ProgressDialog loading = ProgressDialog(context);
  59. loading = ProgressDialog(context,
  60. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  61. loading.style(
  62. message: 'Please Wait .....',
  63. borderRadius: 3,
  64. backgroundColor: Colors.white,
  65. progressWidget: CircularProgressIndicator(),
  66. elevation: 10.0,
  67. padding: EdgeInsets.all(10),
  68. insetAnimCurve: Curves.easeInOut,
  69. progress: 0.0,
  70. maxProgress: 100.0,
  71. progressTextStyle: TextStyle(
  72. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  73. messageTextStyle: TextStyle(
  74. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  75. await loading.show();
  76. HistoryAbsensi_Post.connectToAPI().then((valueResult) async {
  77. Map<String, dynamic> object = jsonDecode(valueResult);
  78. if (object.containsKey("result").toString() == "true") {
  79. String result = object['result'].toString();
  80. if (result.contains("failed")) {
  81. await loading.hide();
  82. alertDialogFailedRetrievedData(context);
  83. } else {
  84. List <dynamic> historyAbsensi = object['result'];
  85. await loading.hide();
  86. setState(() {
  87. for (int i = 0; i < historyAbsensi.length; i++){
  88. String id = historyAbsensi[i]['id'].toString();
  89. String employee_name = historyAbsensi[i]['employee_name'].toString();
  90. String check_in = historyAbsensi[i]['check_in'].toString();
  91. String check_out = historyAbsensi[i]['check_out'].toString();
  92. String worked_hours = historyAbsensi[i]['worked_hours'].toString();
  93. //String coordinate = historyAbsensi[i]['coordinate'].toString();
  94. double hours = double.parse(worked_hours);
  95. //Jika Sudah Checkin
  96. if (check_in != "false"){
  97. //Convert UTC to Local Time - Check In Time
  98. DateTime checkInTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(check_in, true);
  99. String showCheckInTime = checkInTime.toLocal().toString().substring(11, 19);
  100. showCheckIn_List.add(showCheckInTime.substring(0,5));
  101. //Jika belum check in
  102. } else if (check_in == "false"){
  103. String show_check_in = "-";
  104. showCheckIn_List.add(show_check_in);
  105. }
  106. //Jika Sudah Checkout
  107. if (check_out != "false"){
  108. //Convert UTC to Local Time - Check Out Time
  109. DateTime checkOutTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(check_out, true);
  110. String showCheckOutTime = checkOutTime.toLocal().toString().substring(11, 19);
  111. showCheckOut_List.add(showCheckOutTime.substring(0,5));
  112. //Jika tanggal check in sama dengan tanggal check out
  113. if (check_in.substring(0, 10) == check_out.substring(0,10)){
  114. //Get Day Check In
  115. String dayDateIn = DateFormat('EEEE').format(DateTime.parse(check_in));
  116. String dateIn = DateFormat('dd').format(DateTime.parse(check_in));
  117. String monthIn = DateFormat('MMM').format(DateTime.parse(check_in));
  118. dayDate_List.add(dayDateIn.substring(0,3));
  119. date_List.add(dateIn);
  120. month_List.add(monthIn);
  121. dayDate_list_2.add("");
  122. date_list_2.add("");
  123. month_list_2.add("");
  124. visibilityDate2.add(false);
  125. //Jika tangagal check in tidak sama dengan tanggal checkout
  126. } else if (check_in.substring(0, 10) != check_out.substring(0,10)){
  127. //Get Day Check In & Check Out
  128. String dayDateIn = DateFormat('EEEE').format(DateTime.parse(check_in));
  129. String dateIn = DateFormat('dd').format(DateTime.parse(check_in));
  130. String monthIn = DateFormat('MMM').format(DateTime.parse(check_in));
  131. String dayDateOut = DateFormat('EEEE').format(DateTime.parse(check_out));
  132. String dateOut = DateFormat('dd').format(DateTime.parse(check_out));
  133. String monthOut = DateFormat('MMM').format(DateTime.parse(check_out));
  134. dayDate_List.add(dayDateIn.substring(0,3));
  135. date_List.add(dateIn);
  136. month_List.add(monthIn);
  137. dayDate_list_2.add(dayDateOut.substring(0,3));
  138. date_list_2.add(dateOut);
  139. month_list_2.add(monthOut);
  140. visibilityDate2.add(true);
  141. }
  142. //Jika belum checkout
  143. } else if (check_out == "false"){
  144. String show_check_out = "-";
  145. showCheckOut_List.add(show_check_out);
  146. String dayDateIn = DateFormat('EEEE').format(DateTime.parse(check_in));
  147. String dateIn = DateFormat('dd').format(DateTime.parse(check_in));
  148. String monthIn = DateFormat('MMM').format(DateTime.parse(check_in));
  149. dayDate_List.add(dayDateIn.substring(0,3));
  150. date_List.add(dateIn);
  151. month_List.add(monthIn);
  152. visibilityDate2.add(false);
  153. dayDate_list_2.add("");
  154. date_list_2.add("");
  155. month_list_2.add("");
  156. }
  157. /*if (check_in == "true" && check_out == "false"){
  158. visibilityDate2.add(false);
  159. } else if (check_in == "false" && check_out == "false"){
  160. visibilityDate2.add(false);
  161. } else if (check_in == "true" && check_out == "true"){
  162. visibilityDate2.add(true);
  163. }*/
  164. id_List.add(id);
  165. employee_name_List.add(employee_name);
  166. check_in_List.add(check_in);
  167. check_out_List.add(check_out);
  168. worked_hours_List.add(hours.toStringAsFixed(3));
  169. }
  170. id_List.removeAt(0);
  171. employee_name_List.removeAt(0);
  172. check_in_List.removeAt(0);
  173. check_out_List.removeAt(0);
  174. worked_hours_List.removeAt(0);
  175. dayDate_List.removeAt(0);
  176. date_List.removeAt(0);
  177. month_List.removeAt(0);
  178. //workingHours_List.removeAt(0);
  179. showCheckIn_List.removeAt(0);
  180. showCheckOut_List.removeAt(0);
  181. visibilityDate2.removeAt(0);
  182. logDev.log(visibilityDate2.toString(), name: "VISIBILITY DATE");
  183. dayDate_list_2.removeAt(0);
  184. date_list_2.removeAt(0);
  185. month_list_2.removeAt(0);
  186. HistoryLength = historyAbsensi.length;
  187. });
  188. }
  189. } else {
  190. alertDialogFailedRetrievedData(context);
  191. await loading.hide();
  192. }
  193. });
  194. }
  195. @override
  196. Widget build(BuildContext context) {
  197. var size = MediaQuery.of(context).size;
  198. return Scaffold(
  199. body: Stack(
  200. children: [
  201. Column(
  202. children: <Widget>[
  203. Stack(
  204. children: [
  205. WavyHeader(),
  206. Container(
  207. margin: EdgeInsets.only(
  208. top: (size.height / 6) - 20),
  209. padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
  210. child: Row(
  211. mainAxisAlignment: MainAxisAlignment.end,
  212. crossAxisAlignment: CrossAxisAlignment.end,
  213. children: [
  214. Text(
  215. 'Attendance History\t\t',
  216. maxLines: 1,
  217. style: GoogleFonts.luckiestGuy(
  218. fontSize: 28,
  219. color: Color(0xFF4858A7),
  220. //fontWeight: FontWeight.bold,
  221. fontStyle: FontStyle.italic,
  222. ),
  223. ),
  224. Image.asset(
  225. 'assets/images/ic_history.png',
  226. width: 40,
  227. height: 40,
  228. ),
  229. ],
  230. )
  231. ),
  232. ],
  233. ),
  234. ],
  235. ),
  236. Container(
  237. margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40,
  238. left: 5, right: 5, bottom: 10),
  239. child: ListView.builder(
  240. scrollDirection: Axis.vertical,
  241. shrinkWrap: true,
  242. itemCount: HistoryLength,
  243. itemBuilder: (context, int i) {
  244. return Container(
  245. margin: EdgeInsets.fromLTRB(5, 5, 5, 5),
  246. child: InkWell(
  247. child: Card(
  248. elevation: 8,
  249. child: Container(
  250. padding: EdgeInsets.all(10),
  251. child: Row(
  252. children: [
  253. Expanded(
  254. flex: 3,
  255. child:
  256. Container(
  257. alignment: Alignment.center,
  258. padding: EdgeInsets.all(5),
  259. decoration: BoxDecoration(
  260. border: Border.all(color: Colors.black),
  261. borderRadius: BorderRadius.all(Radius.circular(3)),
  262. ),
  263. child: Row(
  264. crossAxisAlignment: CrossAxisAlignment.center,
  265. mainAxisAlignment: MainAxisAlignment.center,
  266. children: [
  267. Column(
  268. children: [
  269. Text(dayDate_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
  270. Text(date_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  271. Text(month_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  272. ],
  273. ),
  274. Visibility(
  275. visible: visibilityDate2[i],
  276. child: Column(
  277. children: [
  278. Text("\t|\t", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
  279. Text("\t|\t", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  280. Text("\t|\t", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  281. ],
  282. ),
  283. ),
  284. Visibility(
  285. visible: visibilityDate2[i],
  286. child: Column(
  287. children: [
  288. Text(dayDate_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
  289. Text(date_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  290. Text(month_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  291. ],
  292. ),
  293. ),
  294. /*Expanded(
  295. flex: 1,
  296. child: Column(
  297. mainAxisAlignment: MainAxisAlignment.center,
  298. crossAxisAlignment: CrossAxisAlignment.center,
  299. children: [
  300. Text(dayDate_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.right,),
  301. Text(date_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.right),
  302. Text(month_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.right),
  303. ],
  304. )
  305. ),
  306. Expanded(
  307. flex: 1,
  308. child: Visibility(
  309. visible: visibilityDate2[i],
  310. child: Column(
  311. children: [
  312. Text("|", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
  313. Text("|", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  314. Text("|", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
  315. ],
  316. ),
  317. )
  318. ),
  319. Expanded(
  320. flex: 1,
  321. child: Visibility(
  322. visible: visibilityDate2[i],
  323. child: Column(
  324. children: [
  325. Text(dayDate_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.left,),
  326. Text(date_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.left),
  327. Text(month_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.left),
  328. ],
  329. ),
  330. ))*/
  331. ],
  332. ),
  333. )
  334. ),
  335. Expanded(
  336. flex: 2,
  337. child: Column(
  338. children: [
  339. Text("Check In", style: GoogleFonts.fredoka(fontSize: 16),textAlign: TextAlign.center),
  340. Text(showCheckIn_List[i], style: GoogleFonts.barlowSemiCondensed(fontSize: 16),textAlign: TextAlign.center),
  341. ],
  342. ),
  343. ),
  344. Expanded(
  345. flex: 2,
  346. child: Column(
  347. children: [
  348. Text("Check Out", style: GoogleFonts.fredoka(fontSize: 16),textAlign: TextAlign.center),
  349. Text(showCheckOut_List[i], style: GoogleFonts.barlowSemiCondensed(fontSize: 16),textAlign: TextAlign.center),
  350. ],
  351. ),
  352. ),
  353. Expanded(
  354. flex: 2,
  355. child: Column(
  356. children: [
  357. Text("Working\nHours", style: GoogleFonts.fredoka(fontSize: 16), textAlign: TextAlign.center),
  358. Text(worked_hours_List[i], style: GoogleFonts.barlowSemiCondensed(fontSize: 16),textAlign: TextAlign.center),
  359. ],
  360. ),
  361. ),
  362. ],
  363. ),
  364. ),
  365. ),
  366. onTap: (){
  367. setState(() {
  368. //visible[i] = !visible[i];
  369. });
  370. },
  371. ),
  372. );
  373. },
  374. ),
  375. )
  376. ]),
  377. );
  378. }
  379. }
  380. alertDialogFailedRetrievedData(BuildContext context) {
  381. Widget okButton = TextButton(
  382. child: Text("Refresh"),
  383. onPressed: () {
  384. Navigator.of(context, rootNavigator: true).pop();
  385. Navigator.pushReplacement(
  386. context, MaterialPageRoute(builder: (context) => HistoryAbsensi()));
  387. },
  388. );
  389. Widget noButton = TextButton(
  390. child: Text("Back"),
  391. onPressed: () {
  392. Navigator.of(context, rootNavigator: true).pop();
  393. Navigator.pop(context);
  394. },
  395. );
  396. // set up the AlertDialog
  397. AlertDialog alert = AlertDialog(
  398. title: Text(appName),
  399. content: Text("Failed to Retrieve Data"),
  400. actions: [
  401. noButton,
  402. okButton,
  403. ],
  404. );
  405. // show the dialog
  406. showDialog(
  407. context: context,
  408. barrierDismissible: false,
  409. builder: (BuildContext context) {
  410. return alert;
  411. },
  412. );
  413. }
  414. alertDialogFailedResponse(BuildContext context){
  415. Widget okButton = TextButton(
  416. child: Text("Refresh"),
  417. onPressed: () {
  418. Navigator.of(context, rootNavigator: true).pop();
  419. Navigator.pushReplacement(context, MaterialPageRoute(
  420. builder: (context) => HistoryAbsensi()));
  421. },
  422. );
  423. Widget noButton = TextButton(
  424. child: Text("Back"),
  425. onPressed: () {
  426. Navigator.of(context, rootNavigator: true).pop();
  427. Navigator.pop(context);
  428. },
  429. );
  430. // set up the AlertDialog
  431. AlertDialog alert = AlertDialog(
  432. title: Text(appName),
  433. content: Text("Server Response Error"),
  434. actions: [
  435. noButton,
  436. okButton,
  437. ],
  438. );
  439. // show the dialog
  440. showDialog(
  441. context: context,
  442. barrierDismissible: false,
  443. builder: (BuildContext context) {
  444. return alert;
  445. },
  446. );
  447. }