GSI - Employe Self Service Mobile
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.

307 lines
12 KiB

2 months ago
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:fluttertoast/fluttertoast.dart';
  4. import 'package:google_fonts/google_fonts.dart';
  5. import 'package:employee_selfservice_mobile/Screens/Menu/AjukanCuti/RequestHttp/historyCuti_post.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. class HistoryCuti extends StatefulWidget {
  10. const HistoryCuti({Key? key}) : super(key: key);
  11. @override
  12. State<HistoryCuti> createState() => _HistoryCutiState();
  13. }
  14. class _HistoryCutiState extends State<HistoryCuti> {
  15. late List <String> id_List;
  16. late List <String> name_List;
  17. late List <String> type_cuti_List;
  18. late List <String> detail_List;
  19. late List <String> created_on_List;
  20. late List <String> created_by_List;
  21. late List <String> start_date_List;
  22. late List <String> end_date_List;
  23. late List <String> duration_List;
  24. late List <String> status_List;
  25. late List <Color> statusColor;
  26. late List <bool> visible;
  27. int HistoryLength = 0;
  28. @override
  29. initState() {
  30. super.initState();
  31. id_List = [""];
  32. name_List = [""];
  33. type_cuti_List = [""];
  34. detail_List = [""];
  35. created_on_List = [""];
  36. created_by_List = [""];
  37. start_date_List = [""];
  38. end_date_List = [""];
  39. duration_List = [""];
  40. status_List = [""];
  41. statusColor = [Colors.black54];
  42. visible = [false];
  43. WidgetsBinding.instance.addPostFrameCallback((_) async {
  44. getHistoryData();
  45. });
  46. logDev.log(HistoryLength.toString(), name: "Banyak History");
  47. }
  48. getHistoryData() async {
  49. ProgressDialog loading = ProgressDialog(context);
  50. loading = ProgressDialog(context,
  51. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  52. loading.style(
  53. message: 'Please Wait .....',
  54. borderRadius: 3,
  55. backgroundColor: Colors.white,
  56. progressWidget: CircularProgressIndicator(),
  57. elevation: 10.0,
  58. padding: EdgeInsets.all(10),
  59. insetAnimCurve: Curves.easeInOut,
  60. progress: 0.0,
  61. maxProgress: 100.0,
  62. progressTextStyle: TextStyle(
  63. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  64. messageTextStyle: TextStyle(
  65. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  66. await loading.show();
  67. HistoryCuti_Post.connectToAPI().then((valueResult) async {
  68. Map<String, dynamic> object = jsonDecode(valueResult);
  69. if (object.containsKey("result").toString() == "true") {
  70. String result = object['result'].toString();
  71. if (result.contains("Failed")) {
  72. await loading.hide();
  73. alertDialogFailedRetrievedData(context);
  74. } else {
  75. List <dynamic> historyCuti = object['result'];
  76. /* logDev.log(historyCuti.toString(), name: "History Cuti");
  77. logDev.log(historyCuti.length.toString(), name: "Banyaknya History Cuti");*/
  78. setState(() {
  79. for (int i = 0; i < historyCuti.length; i++){
  80. String id = historyCuti[i]['id'].toString();
  81. String name = historyCuti[i]['name'].toString();
  82. String type_cuti = historyCuti[i]['type_cuti'].toString();
  83. String detail = historyCuti[i]['detail'].toString();
  84. String created_on = historyCuti[i]['created_on'].toString();
  85. String created_by = historyCuti[i]['created_by'].toString();
  86. String start_date = historyCuti[i]['start_date'].toString();
  87. String end_date = historyCuti[i]['end_date'].toString();
  88. String duration = historyCuti[i]['duration'].toString();
  89. String status = historyCuti[i]['status'].toString();
  90. if (detail == "false"){
  91. detail = "-";
  92. }
  93. id_List.add(id);
  94. name_List.add(name);
  95. type_cuti_List.add(type_cuti);
  96. detail_List.add(detail);
  97. created_on_List.add(created_on);
  98. created_by_List.add(created_by);
  99. start_date_List.add(start_date.substring(0,10));
  100. end_date_List.add(end_date.substring(0,10));
  101. duration_List.add(duration);
  102. status_List.add(status);
  103. visible.add(false);
  104. var statColor;
  105. if (status == "To Approve"){
  106. statColor = Colors.red;
  107. } else if (status == "Second Approval"){
  108. statColor = Colors.green;
  109. } else if (status == "Approved"){
  110. statColor = Colors.blueAccent;
  111. }
  112. statusColor.add(statColor);
  113. }
  114. id_List.removeAt(0);
  115. name_List.removeAt(0);
  116. type_cuti_List.removeAt(0);
  117. detail_List.removeAt(0);
  118. created_on_List.removeAt(0);
  119. created_by_List.removeAt(0);
  120. start_date_List.removeAt(0);
  121. end_date_List.removeAt(0);
  122. duration_List.removeAt(0);
  123. status_List.removeAt(0);
  124. statusColor.removeAt(0);
  125. visible.removeAt(0);
  126. HistoryLength = historyCuti.length;
  127. });
  128. }
  129. } else {
  130. Fluttertoast.showToast(
  131. msg: "Server Response Error",
  132. toastLength: Toast.LENGTH_SHORT,
  133. gravity: ToastGravity.CENTER,
  134. timeInSecForIosWeb: 1,
  135. textColor: Colors.white,
  136. fontSize: 16.0);
  137. }
  138. await loading.hide();
  139. });
  140. }
  141. @override
  142. Widget build(BuildContext context) {
  143. var size = MediaQuery.of(context).size;
  144. return Scaffold(
  145. body: Stack(
  146. children: [
  147. Column(
  148. children: <Widget>[
  149. Stack(
  150. children: [
  151. WavyHeader(),
  152. Container(
  153. margin: EdgeInsets.only(top: (size.height / 6) - 20),
  154. padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
  155. child: Row(
  156. mainAxisAlignment: MainAxisAlignment.end,
  157. crossAxisAlignment: CrossAxisAlignment.end,
  158. children: [
  159. Text(
  160. 'Leaves History\t\t',
  161. maxLines: 1,
  162. style: GoogleFonts.luckiestGuy(
  163. fontSize: 28,
  164. color: Color(0xFF4858A7),
  165. fontStyle: FontStyle.italic,
  166. ),
  167. ),
  168. Image.asset(
  169. 'assets/images/ic_history.png',
  170. width: 40,
  171. height: 40,
  172. ),
  173. ],
  174. )
  175. ),
  176. ],
  177. ),
  178. ],
  179. ),
  180. Container(
  181. margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10),
  182. child: ListView.builder(
  183. scrollDirection: Axis.vertical,
  184. shrinkWrap: true,
  185. itemCount: HistoryLength,
  186. itemBuilder: (context, int i) {
  187. return Container(
  188. child: InkWell(
  189. child: Card(
  190. elevation: 10,
  191. child: Column(
  192. children: [
  193. Row(
  194. children: [
  195. Expanded(
  196. flex: 8,
  197. child: Padding(
  198. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  199. child: Column(
  200. mainAxisAlignment: MainAxisAlignment.center,
  201. crossAxisAlignment: CrossAxisAlignment.start,
  202. children: [
  203. Text(type_cuti_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  204. Text(start_date_List[i] + " - " + end_date_List[i] + " (" + duration_List[i] + ") ", style: GoogleFonts.nunito(fontSize: 15)),
  205. Text("\nDescription : " + detail_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  206. Text("\nCreated : " + created_on_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  207. ],
  208. ),
  209. )
  210. ),
  211. Expanded(
  212. flex: 2,
  213. child: Padding(
  214. padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
  215. child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17),
  216. ),
  217. )
  218. ),
  219. ],
  220. ),
  221. Align(
  222. alignment: Alignment.centerLeft,
  223. child: Visibility(
  224. visible: visible[i],
  225. child: Padding(
  226. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  227. child: Column(
  228. mainAxisAlignment: MainAxisAlignment.start,
  229. crossAxisAlignment: CrossAxisAlignment.start,
  230. children: [
  231. Text("\nAttachment : ", style: GoogleFonts.josefinSans(fontSize: 15, fontWeight: FontWeight.bold)),
  232. Text("Created : " + created_on_List[i], style: GoogleFonts.nunito(fontSize: 15, fontStyle: FontStyle.italic)),
  233. ],
  234. ),
  235. )
  236. ),
  237. )
  238. ],
  239. ),
  240. ),
  241. onTap: (){
  242. setState(() {
  243. visible[i] = !visible[i];
  244. });
  245. },
  246. ),
  247. );
  248. },
  249. ),
  250. )
  251. ]),
  252. );
  253. }
  254. }
  255. alertDialogFailedRetrievedData(BuildContext context) {
  256. Widget okButton = TextButton(
  257. child: Text("Refresh"),
  258. onPressed: () {
  259. Navigator.of(context, rootNavigator: true).pop();
  260. Navigator.pushReplacement(
  261. context, MaterialPageRoute(builder: (context) => HistoryCuti()));
  262. },
  263. );
  264. Widget noButton = TextButton(
  265. child: Text("Back"),
  266. onPressed: () {
  267. Navigator.of(context, rootNavigator: true).pop();
  268. Navigator.pop(context);
  269. },
  270. );
  271. // set up the AlertDialog
  272. AlertDialog alert = AlertDialog(
  273. title: Text("Employee Self Service"),
  274. content: Text("Failed to Retrieve Data"),
  275. actions: [
  276. noButton,
  277. okButton,
  278. ],
  279. );
  280. // show the dialog
  281. showDialog(
  282. context: context,
  283. builder: (BuildContext context) {
  284. return alert;
  285. },
  286. );
  287. }