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_reimburse.dart 11KB

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