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.

slipgaji_screen.dart 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. import 'dart:convert';
  2. import 'package:flutter/cupertino.dart';
  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/SlipGaji/RequestHttp/detailSlipGaji_post.dart';
  7. import 'package:hris_selfservice_mobile/Screens/Menu/SlipGaji/RequestHttp/historySlipGaji_post.dart';
  8. import 'package:hris_selfservice_mobile/Screens/Menu/SlipGaji/background.dart';
  9. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  10. import 'dart:developer' as logDev;
  11. import 'package:shared_preferences/shared_preferences.dart';
  12. class SlipGajiScreen extends StatefulWidget {
  13. const SlipGajiScreen({Key? key}) : super(key: key);
  14. @override
  15. State<SlipGajiScreen> createState() => _SlipGajiScreenState();
  16. }
  17. class _SlipGajiScreenState extends State<SlipGajiScreen> {
  18. //History Slip Gaji
  19. late List <String> dateTo_List;
  20. late List <String> batchID_List;
  21. //Detail Slip Gaji
  22. late List <String> number_List;
  23. late List <String> period_List;
  24. late List <String> namaPegawai_List;
  25. late List <String> status_List;
  26. late List <String> structure_List;
  27. late String position;
  28. //Komponen Gaji
  29. late List <String> name_List;
  30. late List <String> category_List;
  31. late List <String> total_List;
  32. int HistoryLength = 0;
  33. late int indexBatchID = 0;
  34. var selectedDate;
  35. bool visible = false;
  36. @override
  37. void initState() {
  38. super.initState();
  39. dateTo_List = [""];
  40. batchID_List = [""];
  41. number_List = [""];
  42. period_List = [""];
  43. namaPegawai_List = [""];
  44. status_List = [""];
  45. structure_List = [""];
  46. position = "";
  47. name_List = [""];
  48. category_List = [""];
  49. total_List = [""];
  50. WidgetsBinding.instance.addPostFrameCallback((_) {
  51. getHistoryData();
  52. });
  53. }
  54. getHistoryData() async {
  55. ProgressDialog loading = ProgressDialog(context);
  56. loading = ProgressDialog(context,
  57. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  58. loading.style(
  59. message: 'Please Wait .....',
  60. borderRadius: 3,
  61. backgroundColor: Colors.white,
  62. progressWidget: CircularProgressIndicator(),
  63. elevation: 10.0,
  64. padding: EdgeInsets.all(10),
  65. insetAnimCurve: Curves.easeInOut,
  66. progress: 0.0,
  67. maxProgress: 100.0,
  68. progressTextStyle: TextStyle(
  69. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  70. messageTextStyle: TextStyle(
  71. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  72. loading.show();
  73. HistorySlipGaji_Post.connectToAPI().then((valueResult) async {
  74. Map<String, dynamic> object = json.decode(valueResult);
  75. if (object.containsKey("result").toString() == "true"){
  76. String result = object['result'].toString();
  77. if (result.contains("failed")) {
  78. loading.hide();
  79. setState(() {
  80. alertDialogFailedRetrievedData(context);
  81. });
  82. } else {
  83. List <dynamic> historySlipGaji = object['result'];
  84. setState(() {
  85. for (int i = 0; i < historySlipGaji.length; i++){
  86. String dateTo = historySlipGaji[i]['date_to'].toString();
  87. String bulan = dateTo.substring(5,7);
  88. String tahun = dateTo.substring(0,4);
  89. String batchID = historySlipGaji[i]['batch_id'].toString();
  90. String bulanStr = "";
  91. if (bulan == "01"){
  92. bulanStr = "January";
  93. } else if (bulan == "02"){
  94. bulanStr = "February";
  95. } else if (bulan == "03"){
  96. bulanStr = "March";
  97. } else if (bulan == "04"){
  98. bulanStr = "April";
  99. } else if (bulan == "05"){
  100. bulanStr = "May";
  101. } else if (bulan == "06"){
  102. bulanStr = "June";
  103. } else if (bulan == "07"){
  104. bulanStr = "July";
  105. } else if (bulan == "08"){
  106. bulanStr = "August";
  107. } else if (bulan == "09"){
  108. bulanStr = "September";
  109. } else if (bulan == "10"){
  110. bulanStr = "October";
  111. } else if (bulan == "11"){
  112. bulanStr = "November";
  113. } else if (bulan == "12"){
  114. bulanStr = "December";
  115. }
  116. String bulanTahun = bulanStr + " " + tahun;
  117. dateTo_List.add(bulanTahun);
  118. batchID_List.add(batchID);
  119. }
  120. dateTo_List.removeAt(0);
  121. batchID_List.removeAt(0);
  122. logDev.log(dateTo_List.toString(), name: "LIST DATE");
  123. HistoryLength = historySlipGaji.length;
  124. });
  125. loading.hide();
  126. }
  127. } else {
  128. setState((){
  129. alertDialogFailedResponse(context);
  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. loading.hide();
  139. }
  140. });
  141. return HistoryLength;
  142. }
  143. getDetailData () async {
  144. ProgressDialog loading = ProgressDialog(context);
  145. loading = ProgressDialog(context,
  146. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  147. loading.style(
  148. message: 'Please Wait .....',
  149. borderRadius: 3,
  150. backgroundColor: Colors.white,
  151. progressWidget: CircularProgressIndicator(),
  152. elevation: 10.0,
  153. padding: EdgeInsets.all(10),
  154. insetAnimCurve: Curves.easeInOut,
  155. progress: 0.0,
  156. maxProgress: 100.0,
  157. progressTextStyle: TextStyle(
  158. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  159. messageTextStyle: TextStyle(
  160. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  161. loading.show();
  162. //logDev.log(batchID_List.toString(), name: "ALL BATCH ID");
  163. final SharedPreferences prefs = await SharedPreferences.getInstance();
  164. DetailSlipGaji_Post.connectToAPI(batchID_List[indexBatchID]).then((valueResult) async {
  165. Map<String, dynamic> object = json.decode(valueResult);
  166. if (object.containsKey("result").toString() == "true"){
  167. String result = object['result'].toString();
  168. if (result.contains("failed")) {
  169. loading.hide();
  170. logDev.log("ERROR", name: "FAILED RESULT");
  171. setState(() {
  172. alertDialogFailedRetrievedData(context);
  173. });
  174. } else {
  175. //List <dynamic> detailSlipGaji = object['result'];
  176. setState(() {
  177. position = prefs.getString('position')!;
  178. String nomor = object['result']['number'];
  179. String tanggalAwal = object['result']['date_from'];
  180. String tanggalAkhir = object['result']['date_to'];
  181. String namaPegawai = object['result']['employee'];
  182. String status = object['result']['status'];
  183. String structure =object['result']['structure'];
  184. number_List.add(nomor);
  185. structure_List.add(structure);
  186. period_List.add(tanggalAwal + " to " + tanggalAkhir);
  187. namaPegawai_List.add(namaPegawai);
  188. status_List.add(status);
  189. List <dynamic> component = object['result']['component'];
  190. logDev.log(component.length.toString(), name: "BANYAK COMPONENT");
  191. for (int j = 0; j < component.length; j++){
  192. String name = component[j]['name'].toString();
  193. String category = component[j]['category'].toString();
  194. int total = component[j]['total'];
  195. name_List.add(name);
  196. category_List.add(category);
  197. total_List.add(total.toString());
  198. }
  199. number_List.remove(0);
  200. structure_List.removeAt(0);
  201. period_List.removeAt(0);
  202. namaPegawai_List.removeAt(0);
  203. status_List.removeAt(0);
  204. name_List.removeAt(0);
  205. category_List.removeAt(0);
  206. total_List.removeAt(0);
  207. });
  208. loading.hide();
  209. }
  210. } else {
  211. setState((){
  212. alertDialogFailedResponse(context);
  213. logDev.log("ERROR", name: "RESPONSE FAILED RESULT");
  214. /* Fluttertoast.showToast(
  215. msg: "Server Response Error",
  216. toastLength: Toast.LENGTH_SHORT,
  217. gravity: ToastGravity.CENTER,
  218. timeInSecForIosWeb: 1,
  219. textColor: Colors.white,
  220. fontSize: 16.0);*/
  221. });
  222. loading.hide();
  223. }
  224. });
  225. }
  226. @override
  227. Widget build(BuildContext context) {
  228. return Scaffold(
  229. body: SingleChildScrollView(
  230. child: Column(
  231. children: <Widget>[
  232. Stack(
  233. children: [
  234. WavyHeader(),
  235. Container(
  236. margin: EdgeInsets.only(top: MediaQuery.of(context).size.height/6 - 20),
  237. padding: EdgeInsets.fromLTRB(20, 5, 25, 5),
  238. child: Row(
  239. mainAxisAlignment: MainAxisAlignment.end,
  240. crossAxisAlignment: CrossAxisAlignment.end,
  241. children: [
  242. Text(
  243. 'Pay Slip\t\t',
  244. maxLines: 1,
  245. style: GoogleFonts.luckiestGuy(
  246. fontSize: 28,
  247. color: Colors.red,
  248. fontStyle: FontStyle.italic,
  249. ),
  250. ),
  251. Image.asset('assets/icons/ic_salary.png', width: 40, height: 40,),
  252. ],
  253. )
  254. ),
  255. SafeArea(
  256. child: Container(
  257. width: MediaQuery.of(context).size.width,
  258. margin: EdgeInsets.only(
  259. top: MediaQuery.of(context).size.height / 5,
  260. left: 15,
  261. right: 15,
  262. ),
  263. child: Column(
  264. children: [
  265. Container(
  266. margin: EdgeInsets.only(bottom: 20),
  267. child: Row(
  268. children: [
  269. Expanded(
  270. flex: 2,
  271. child: Text(
  272. 'Date\t:\t',
  273. style: GoogleFonts.inconsolata(fontSize: 20),
  274. )),
  275. Expanded(
  276. flex: 8,
  277. child: Container(
  278. decoration: BoxDecoration(
  279. color: CupertinoColors.systemGrey2,
  280. borderRadius: BorderRadius.circular(5)),
  281. child: DropdownButton(
  282. value: this.selectedDate,
  283. isExpanded: true,
  284. underline: SizedBox(),
  285. hint: Text(
  286. '\t\t\tChoose Date',
  287. style: TextStyle(color: Colors.black54),
  288. ),
  289. onChanged: (value) {
  290. print(value);
  291. setState(() {
  292. selectedDate = value!;
  293. if (selectedDate == value){
  294. visible = true;
  295. for (int i = 0; i < dateTo_List.length; i ++){
  296. if (selectedDate == dateTo_List[i]){
  297. indexBatchID = i;
  298. break;
  299. }
  300. }
  301. //logDev.log(indexBatchID.toString(), name: "INDEX BATCH ID");
  302. getDetailData();
  303. } else {
  304. visible = false;
  305. }
  306. });
  307. },
  308. items: dateTo_List
  309. .map(
  310. (e) => DropdownMenuItem(
  311. value: e,
  312. child: Text("\t\t\t" + e)),
  313. )
  314. .toList(),
  315. ),
  316. )),
  317. ],
  318. ),
  319. ),
  320. Visibility(
  321. visible: visible,
  322. child: Text(
  323. 'Pay Slip ' + selectedDate.toString() + "\nPT. Global Service Indonesia",
  324. textAlign: TextAlign.center,
  325. style: GoogleFonts.viga(
  326. fontSize: 15,
  327. fontWeight: FontWeight.bold,
  328. ),
  329. ),
  330. ),
  331. Visibility(
  332. visible: visible,
  333. child: ListView.builder(
  334. shrinkWrap: true,
  335. itemCount: 1,
  336. itemBuilder: (context, int indexBatchID){
  337. return Container(
  338. //height: 200,
  339. margin: EdgeInsets.fromLTRB(0, 15, 0, 10),
  340. decoration: BoxDecoration(
  341. color: Color(0XFFFFFEFC),
  342. borderRadius: BorderRadius.circular(10),
  343. ),
  344. child: Card(
  345. elevation: 5,
  346. child: Column(
  347. children: [
  348. Text(number_List[indexBatchID], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  349. Text(number_List[indexBatchID], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  350. Text(structure_List[indexBatchID], style: GoogleFonts.nunito(fontSize: 15)),
  351. Text(period_List[indexBatchID], style: GoogleFonts.nunito(fontSize: 15)),
  352. Text(name_List[indexBatchID], style: GoogleFonts.nunito(fontSize: 15)),
  353. Text(position, style: GoogleFonts.nunito(fontSize: 15)),
  354. Text("Payment : " /*+ payment_List[i]*/, style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic))],
  355. ),
  356. ),
  357. );
  358. },
  359. ),
  360. ),
  361. Visibility(
  362. visible: visible,
  363. child: Container(
  364. alignment: Alignment.centerRight,
  365. child: ElevatedButton(
  366. onPressed: () {},
  367. style: ElevatedButton.styleFrom(),
  368. child: Text('Download Slip Gaji'),
  369. ),
  370. ),
  371. ),
  372. ],
  373. ),
  374. )),
  375. ],
  376. ),
  377. ],
  378. )),
  379. );
  380. }
  381. }
  382. const List<Color> Gradients1 = [
  383. Color(0xFF0EDED2),
  384. Color(0xFF03A0FE),
  385. ];
  386. alertDialogFailedRetrievedData(BuildContext context){
  387. Widget okButton = TextButton(
  388. child: Text("Refresh"),
  389. onPressed: () {
  390. Navigator.of(context, rootNavigator: true).pop();
  391. Navigator.pushReplacement(context, MaterialPageRoute(
  392. builder: (context) => SlipGajiScreen()));
  393. },
  394. );
  395. Widget noButton = TextButton(
  396. child: Text("Back"),
  397. onPressed: () {
  398. Navigator.of(context, rootNavigator: true).pop();
  399. Navigator.pop(context);
  400. },
  401. );
  402. // set up the AlertDialog
  403. AlertDialog alert = AlertDialog(
  404. title: Text("Employee Self Service"),
  405. content: Text("Failed to Retrieve Data"),
  406. actions: [
  407. noButton,
  408. okButton,
  409. ],
  410. );
  411. // show the dialog
  412. showDialog(
  413. context: context,
  414. builder: (BuildContext context) {
  415. return alert;
  416. },
  417. );
  418. }
  419. alertDialogFailedResponse(BuildContext context){
  420. Widget okButton = TextButton(
  421. child: Text("Refresh"),
  422. onPressed: () {
  423. Navigator.of(context, rootNavigator: true).pop();
  424. Navigator.pushReplacement(context, MaterialPageRoute(
  425. builder: (context) => SlipGajiScreen()));
  426. },
  427. );
  428. Widget noButton = TextButton(
  429. child: Text("Back"),
  430. onPressed: () {
  431. Navigator.of(context, rootNavigator: true).pop();
  432. Navigator.pop(context);
  433. },
  434. );
  435. // set up the AlertDialog
  436. AlertDialog alert = AlertDialog(
  437. title: Text("Employee Self Service"),
  438. content: Text("Server Response Error"),
  439. actions: [
  440. noButton,
  441. okButton,
  442. ],
  443. );
  444. // show the dialog
  445. showDialog(
  446. context: context,
  447. builder: (BuildContext context) {
  448. return alert;
  449. },
  450. );
  451. }