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 15KB

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