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

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