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.

history_st.dart 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. import 'dart:convert';
  2. import 'dart:ui';
  3. import 'package:flutter/material.dart';
  4. import 'package:fluttertoast/fluttertoast.dart';
  5. import 'package:google_fonts/google_fonts.dart';
  6. import 'package:hris_selfservice_mobile/Screens/Menu/SuratTugas/RequestHttp/detailST_post.dart';
  7. import 'package:hris_selfservice_mobile/Screens/Menu/SuratTugas/RequestHttp/historyST_post.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. class HistoryST extends StatefulWidget {
  12. const HistoryST({Key? key}) : super(key: key);
  13. @override
  14. State<HistoryST> createState() => _HistoryST();
  15. }
  16. class _HistoryST extends State<HistoryST> {
  17. late List <String> id_List;
  18. late List <String> number_List;
  19. late List <String> keperluan_List;
  20. late List <String> tglDibuat_List;
  21. late List <String> status_List;
  22. late List <String> tglST_List;
  23. late List <String> uMuka_List;
  24. late List <String> tglBerangkat_List;
  25. late List <String> tglKembali_List;
  26. late List <String> tujuan_List;
  27. late List <String> ticketType_List;
  28. late List <String> ticketFrom_List;
  29. late List <String> ticketTo_List;
  30. late List <String> ticketDate_List;
  31. late List <String> ticketPrice_List;
  32. late List <Color> statusColor;
  33. late List <bool> visible;
  34. int HistoryLength = 0;
  35. @override
  36. initState() {
  37. id_List = [""];
  38. number_List = [""];
  39. keperluan_List = [""];
  40. tglDibuat_List = [""];
  41. status_List = [""];
  42. tglST_List = [""];
  43. uMuka_List = [""];
  44. tglBerangkat_List = [""];
  45. tglKembali_List = [""];
  46. tujuan_List = [""];
  47. ticketType_List = [""];
  48. ticketFrom_List = [""];
  49. ticketTo_List = [""];
  50. ticketDate_List = [""];
  51. ticketPrice_List = [""];
  52. statusColor = [Colors.black54];
  53. visible = [false];
  54. WidgetsBinding.instance.addPostFrameCallback((_) async {
  55. getHistoryData();
  56. });
  57. }
  58. getHistoryData() async {
  59. ProgressDialog loading = ProgressDialog(context);
  60. loading = ProgressDialog(context,
  61. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  62. loading.style(
  63. message: 'Please Wait .....',
  64. borderRadius: 3,
  65. backgroundColor: Colors.white,
  66. progressWidget: CircularProgressIndicator(),
  67. elevation: 10.0,
  68. padding: EdgeInsets.all(10),
  69. insetAnimCurve: Curves.easeInOut,
  70. progress: 0.0,
  71. maxProgress: 100.0,
  72. progressTextStyle: TextStyle(
  73. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  74. messageTextStyle: TextStyle(
  75. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  76. loading.show();
  77. HistoryST_Post.connectToAPI().then((valueResult) async {
  78. Map<String, dynamic> object = jsonDecode(valueResult);
  79. if (object.containsKey("result").toString() == "true") {
  80. String result = object['result'].toString();
  81. if (result.contains("failed")) {
  82. loading.hide();
  83. alertDialogFailedRetrievedData(context);
  84. } else {
  85. List <dynamic> historyST = object['result'];
  86. setState(() {
  87. for (int i = 0; i < historyST.length; i++){
  88. String id = historyST[i]['id'].toString();
  89. String number = historyST[i]['number'].toString();
  90. String keperluan = historyST[i]['keperluan'].toString();
  91. String tglDibuat = historyST[i]['tgl_dibuat'].toString();
  92. String status = historyST[i]['status'].toString();
  93. id_List.add(id);
  94. number_List.add(number);
  95. keperluan_List.add(keperluan);
  96. tglDibuat_List.add(tglDibuat);
  97. status_List.add(status);
  98. visible.add(false);
  99. var statColor;
  100. if (status == "draft"){
  101. statColor = Colors.red;
  102. } else if (status == "approved"){
  103. statColor = Colors.green;
  104. } else if (status == "advacanced"){
  105. statColor = Colors.orangeAccent;
  106. } else if (status == "done"){
  107. statColor = Colors.blueAccent;
  108. } else if (status == "close"){
  109. statColor = Colors.deepPurple;
  110. }
  111. statusColor.add(statColor);
  112. }
  113. id_List.removeAt(0);
  114. number_List.removeAt(0);
  115. keperluan_List.removeAt(0);
  116. tglDibuat_List.removeAt(0);
  117. status_List.removeAt(0);
  118. statusColor.removeAt(0);
  119. visible.removeAt(0);
  120. HistoryLength = historyST.length;
  121. logDev.log(HistoryLength.toString(), name: "HISTORY LENGTH");
  122. for (int i = 0; i < HistoryLength;i++){
  123. DetailST_Post.connectToAPI(id_List[i]).then((valueResult) async {
  124. Map<String, dynamic> object = jsonDecode(valueResult);
  125. if (object.containsKey("result").toString() == "true") {
  126. String result = object['result'].toString();
  127. if (result.contains("failed")) {
  128. loading.hide();
  129. alertDialogFailedRetrievedData(context);
  130. } else {
  131. List <dynamic> detailST = object['result'];
  132. loading.hide();
  133. setState(() {
  134. for (int j = 0; j < HistoryLength; j++){
  135. String tglST = detailST[j]['tgl_st'].toString();
  136. String uMuka = detailST[j]['umuka'].toString();
  137. String tglBerangkat = detailST[j]['tgl_berangkat'].toString();
  138. String tglKembali = detailST[j]['tgl_kembali'].toString();
  139. String tujuan = detailST[j]['tujuan'].toString();
  140. List<dynamic> ticketID = object['result']['ticket_ids'];
  141. String ticketType = ticketID[j]['type'].toString();
  142. String ticketFrom = ticketID[j]['from'].toString();
  143. String ticketTo = ticketID[j]['to'].toString();
  144. String ticketDate = ticketID[j]['tgl'].toString();
  145. String ticketPrice = ticketID[j]['harga'].toString();
  146. tglST_List.add(tglST);
  147. uMuka_List.add(uMuka);
  148. tglBerangkat_List.add(tglBerangkat);
  149. tglKembali_List.add(tglKembali);
  150. tujuan_List.add(tujuan);
  151. ticketType_List.add(ticketType);
  152. ticketFrom_List.add(ticketFrom);
  153. ticketTo_List.add(ticketTo);
  154. ticketDate_List.add(ticketDate);
  155. ticketPrice_List.add(ticketPrice);
  156. logDev.log(tglST_List.toString(), name:"semua list");
  157. }
  158. });
  159. }
  160. } else {
  161. Fluttertoast.showToast(
  162. msg: "Server Response Error",
  163. toastLength: Toast.LENGTH_SHORT,
  164. gravity: ToastGravity.CENTER,
  165. timeInSecForIosWeb: 1,
  166. textColor: Colors.white,
  167. fontSize: 16.0);
  168. }
  169. });
  170. }
  171. tglST_List.removeAt(0);
  172. uMuka_List.removeAt(0);
  173. tglBerangkat_List.removeAt(0);
  174. tglKembali_List.removeAt(0);
  175. tujuan_List.removeAt(0);
  176. ticketType_List.removeAt(0);
  177. ticketFrom_List.removeAt(0);
  178. ticketTo_List.removeAt(0);
  179. ticketDate_List.removeAt(0);
  180. ticketPrice_List.removeAt(0);
  181. loading.hide();
  182. });
  183. }
  184. } else {
  185. Fluttertoast.showToast(
  186. msg: "Server Response Error",
  187. toastLength: Toast.LENGTH_SHORT,
  188. gravity: ToastGravity.CENTER,
  189. timeInSecForIosWeb: 1,
  190. textColor: Colors.white,
  191. fontSize: 16.0);
  192. }
  193. loading.hide();
  194. });
  195. }
  196. /*getDetailData() async {
  197. ProgressDialog loading = ProgressDialog(context);
  198. loading = ProgressDialog(context,
  199. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  200. loading.style(
  201. message: 'Please Wait .....',
  202. borderRadius: 3,
  203. backgroundColor: Colors.white,
  204. progressWidget: CircularProgressIndicator(),
  205. elevation: 10.0,
  206. padding: EdgeInsets.all(10),
  207. insetAnimCurve: Curves.easeInOut,
  208. progress: 0.0,
  209. maxProgress: 100.0,
  210. progressTextStyle: TextStyle(
  211. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  212. messageTextStyle: TextStyle(
  213. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  214. logDev.log(HistoryLength.toString(), name: "Banyak History");
  215. for (int i = 0; i < HistoryLength;i++){
  216. DetailST_Post.connectToAPI(id_List[i]).then((valueResult) async {
  217. Map<String, dynamic> object = jsonDecode(valueResult);
  218. if (object.containsKey("result").toString() == "true") {
  219. String result = object['result'].toString();
  220. if (result.contains("failed")) {
  221. loading.hide();
  222. alertDialogFailedRetrievedData(context);
  223. } else {
  224. List <dynamic> detailST = object['result'];
  225. loading.hide();
  226. setState(() {
  227. for (int j = 0; j < HistoryLength; j++){
  228. String tglST = detailST[j]['tgl_st'].toString();
  229. String uMuka = detailST[j]['umuka'].toString();
  230. String tglBerangkat = detailST[j]['tgl_berangkat'].toString();
  231. String tglKembali = detailST[j]['tgl_kembali'].toString();
  232. String tujuan = detailST[j]['tujuan'].toString();
  233. List<dynamic> ticketID = object['result']['ticket_ids'];
  234. String ticketType = ticketID[j]['type'].toString();
  235. String ticketFrom = ticketID[j]['from'].toString();
  236. String ticketTo = ticketID[j]['to'].toString();
  237. String ticketDate = ticketID[j]['tgl'].toString();
  238. String ticketPrice = ticketID[j]['harga'].toString();
  239. tglST_List.add(tglST);
  240. uMuka_List.add(uMuka);
  241. tglBerangkat_List.add(tglBerangkat);
  242. tglKembali_List.add(tglKembali);
  243. tujuan_List.add(tujuan);
  244. ticketType_List.add(ticketType);
  245. ticketFrom_List.add(ticketFrom);
  246. ticketTo_List.add(ticketTo);
  247. ticketDate_List.add(ticketDate);
  248. ticketPrice_List.add(ticketPrice);
  249. logDev.log(tglST_List.toString(), name:"semua list");
  250. }
  251. });
  252. }
  253. } else {
  254. Fluttertoast.showToast(
  255. msg: "Server Response Error",
  256. toastLength: Toast.LENGTH_SHORT,
  257. gravity: ToastGravity.CENTER,
  258. timeInSecForIosWeb: 1,
  259. textColor: Colors.white,
  260. fontSize: 16.0);
  261. }
  262. });
  263. }
  264. tglST_List.removeAt(0);
  265. uMuka_List.removeAt(0);
  266. tglBerangkat_List.removeAt(0);
  267. tglKembali_List.removeAt(0);
  268. tujuan_List.removeAt(0);
  269. ticketType_List.removeAt(0);
  270. ticketFrom_List.removeAt(0);
  271. ticketTo_List.removeAt(0);
  272. ticketDate_List.removeAt(0);
  273. ticketPrice_List.removeAt(0);
  274. loading.hide();
  275. }*/
  276. @override
  277. Widget build(BuildContext context) {
  278. var size = MediaQuery.of(context).size;
  279. return Scaffold(
  280. body: Stack(
  281. children: [
  282. Column(
  283. children: <Widget>[
  284. Stack(
  285. children: [
  286. WavyHeader(),
  287. Container(
  288. margin: EdgeInsets.only(
  289. top: (size.height / 6) - 20),
  290. padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
  291. child: Row(
  292. mainAxisAlignment: MainAxisAlignment.end,
  293. crossAxisAlignment: CrossAxisAlignment.end,
  294. children: [
  295. Text(
  296. 'History\t\t',
  297. maxLines: 1,
  298. style: GoogleFonts.luckiestGuy(
  299. fontSize: 28,
  300. color: Colors.red,
  301. fontStyle: FontStyle.italic,
  302. ),
  303. ),
  304. Image.asset(
  305. 'assets/images/ic_history.png',
  306. width: 40,
  307. height: 40,
  308. ),
  309. ],
  310. )
  311. ),
  312. ],
  313. ),
  314. ],
  315. ),
  316. Container(
  317. margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10),
  318. child: ListView.builder(
  319. scrollDirection: Axis.vertical,
  320. shrinkWrap: true,
  321. itemCount: HistoryLength,
  322. itemBuilder: (context, int i) {
  323. return Container(
  324. child: InkWell(
  325. child: Card(
  326. elevation: 10,
  327. child: Column(
  328. children: [
  329. Row(
  330. children: [
  331. Expanded(
  332. flex: 8,
  333. child: Padding(
  334. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  335. child: Column(
  336. mainAxisAlignment: MainAxisAlignment.center,
  337. crossAxisAlignment: CrossAxisAlignment.start,
  338. children: [
  339. Text(number_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  340. Text(keperluan_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  341. Text("\nCreated : " + tglDibuat_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  342. ],
  343. ),
  344. )
  345. ),
  346. Expanded(
  347. flex: 2,
  348. child: Padding(
  349. padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
  350. child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17),
  351. ),
  352. )
  353. ),
  354. ],
  355. ),
  356. /*Align(
  357. alignment: Alignment.centerLeft,
  358. child: Visibility(
  359. visible: visible[i],
  360. child: Padding(
  361. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  362. child: Column(
  363. mainAxisAlignment: MainAxisAlignment.start,
  364. crossAxisAlignment: CrossAxisAlignment.start,
  365. children: [
  366. *//*Text("\nAssignment Letter Date\t : " + tglST_List[i], style: GoogleFonts.josefinSans(fontSize: 15, fontWeight: FontWeight.bold)),*//*
  367. Text("Down Payment\t\t : " + uMuka_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  368. Text("Departure Date\t\t : " + tglBerangkat_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  369. Text("Return Date\t\t : " + tglKembali_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  370. Text("Destination\t\t : " + tujuan_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  371. *//*Text("Ticket Type\t\t : " + ticketType_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  372. Text("From\t\t\t : " + ticketFrom_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  373. Text("To\t\t : " + ticketTo_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  374. Text("Ticket Date\t\t : " + ticketDate_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  375. Text("Ticket Price\t\t\t : " + ticketPrice_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),*//*
  376. ],
  377. ),
  378. )
  379. ),
  380. )*/
  381. ],
  382. ),
  383. ),
  384. onTap: (){
  385. setState(() {
  386. visible[i] = !visible[i];
  387. });
  388. },
  389. ),
  390. );
  391. },
  392. ),
  393. )
  394. ]),
  395. );
  396. }
  397. }
  398. alertDialogFailedRetrievedData(BuildContext context) {
  399. Widget okButton = TextButton(
  400. child: Text("Refresh"),
  401. onPressed: () {
  402. Navigator.of(context, rootNavigator: true).pop();
  403. Navigator.pushReplacement(
  404. context, MaterialPageRoute(builder: (context) => HistoryST()));
  405. },
  406. );
  407. Widget noButton = TextButton(
  408. child: Text("Back"),
  409. onPressed: () {
  410. Navigator.of(context, rootNavigator: true).pop();
  411. Navigator.pop(context);
  412. },
  413. );
  414. // set up the AlertDialog
  415. AlertDialog alert = AlertDialog(
  416. title: Text("Employee Self Service"),
  417. content: Text("Failed to Retrieve Data"),
  418. actions: [
  419. noButton,
  420. okButton,
  421. ],
  422. );
  423. // show the dialog
  424. showDialog(
  425. context: context,
  426. builder: (BuildContext context) {
  427. return alert;
  428. },
  429. );
  430. }