Geen omschrijving
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 21KB

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