説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

slipgaji_screen.dart 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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:employee_selfservice_mobile/Screens/Menu/SlipGaji/RequestHttp/detailSlipGaji_post.dart';
  6. import 'package:employee_selfservice_mobile/Screens/Menu/SlipGaji/RequestHttp/downloadSlipGaji_post.dart';
  7. import 'package:employee_selfservice_mobile/Screens/Menu/SlipGaji/RequestHttp/historySlipGaji_post.dart';
  8. import 'package:employee_selfservice_mobile/Screens/Menu/SlipGaji/background.dart';
  9. import 'package:employee_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. await 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. await 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. await loading.hide();
  128. }
  129. } else {
  130. setState((){
  131. alertDialogFailedResponse(context);
  132. });
  133. await loading.hide();
  134. }
  135. await loading.hide();
  136. });
  137. return HistoryLength;
  138. }
  139. getDetailData () async {
  140. ProgressDialog loading = ProgressDialog(context);
  141. loading = ProgressDialog(context,
  142. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  143. loading.style(
  144. message: 'Please Wait .....',
  145. borderRadius: 3,
  146. backgroundColor: Colors.white,
  147. progressWidget: CircularProgressIndicator(),
  148. elevation: 10.0,
  149. padding: EdgeInsets.all(10),
  150. insetAnimCurve: Curves.easeInOut,
  151. progress: 0.0,
  152. maxProgress: 100.0,
  153. progressTextStyle: TextStyle(
  154. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  155. messageTextStyle: TextStyle(
  156. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  157. await loading.show();
  158. final SharedPreferences prefs = await SharedPreferences.getInstance();
  159. DetailSlipGaji_Post.connectToAPI(batchID_List[indexBatchID]).then((valueResult) async {
  160. Map<String, dynamic> object = json.decode(valueResult);
  161. if (object.containsKey("result").toString() == "true"){
  162. String result = object['result'].toString();
  163. if (result.contains("failed")) {
  164. await loading.hide();
  165. logDev.log("ERROR", name: "FAILED RESULT");
  166. setState(() {
  167. alertDialogFailedRetrievedData(context);
  168. });
  169. } else {
  170. List <dynamic> detailSlipGaji = object['result'];
  171. setState(() {
  172. position = prefs.getString('position')!;
  173. logDev.log(position, name: "POSITION");
  174. for (int i = 0; i < detailSlipGaji.length; i++){
  175. String nomor = detailSlipGaji[i]['number'].toString();
  176. logDev.log(nomor, name: "NOMOR/NUMBER");
  177. String tanggalAwal = detailSlipGaji[i]['date_from'];
  178. String tanggalAkhir = detailSlipGaji[i]['date_to'];
  179. String namaPegawai = detailSlipGaji[i]['employee'];
  180. String status = detailSlipGaji[i]['status'];
  181. String structure =detailSlipGaji[i]['structure'];
  182. //number_List.add(nomor);
  183. structure_List.add(structure);
  184. period_List.add(tanggalAwal + " to " + tanggalAkhir);
  185. namaPegawai_List.add(namaPegawai);
  186. status_List.add(status);
  187. List <dynamic> component =detailSlipGaji[i]['component'];
  188. logDev.log(component.length.toString(), name: "BANYAK COMPONENT");
  189. for (int j = 0; j < component.length; j++){
  190. String name = component[j]['name'].toString();
  191. String category = component[j]['category'].toString();
  192. double total = component[j]['total'];
  193. name_List.add(name);
  194. category_List.add(category);
  195. total_List.add(total.toString());
  196. }
  197. }
  198. number_List.remove(0);
  199. structure_List.removeAt(0);
  200. period_List.removeAt(0);
  201. namaPegawai_List.removeAt(0);
  202. status_List.removeAt(0);
  203. name_List.removeAt(0);
  204. category_List.removeAt(0);
  205. total_List.removeAt(0);
  206. });
  207. await loading.hide();
  208. }
  209. } else {
  210. setState((){
  211. alertDialogFailedResponse(context);
  212. logDev.log("ERROR", name: "RESPONSE FAILED RESULT");
  213. /* Fluttertoast.showToast(
  214. msg: "Server Response Error",
  215. toastLength: Toast.LENGTH_SHORT,
  216. gravity: ToastGravity.CENTER,
  217. timeInSecForIosWeb: 1,
  218. textColor: Colors.white,
  219. fontSize: 16.0);*/
  220. });
  221. await loading.hide();
  222. }
  223. await loading.hide();
  224. });
  225. }
  226. @override
  227. Widget build(BuildContext context) {
  228. var size = MediaQuery.sizeOf(context);
  229. return Scaffold(
  230. body: SingleChildScrollView(
  231. child: Column(
  232. children: <Widget>[
  233. Stack(
  234. children: [
  235. WavyHeader(),
  236. Container(
  237. margin: EdgeInsets.only(top: MediaQuery.of(context).size.height/6 - 20),
  238. padding: EdgeInsets.fromLTRB(20, 5, 25, 5),
  239. child: Row(
  240. mainAxisAlignment: MainAxisAlignment.end,
  241. crossAxisAlignment: CrossAxisAlignment.end,
  242. children: [
  243. Text(
  244. 'Pay Slip\t\t',
  245. maxLines: 1,
  246. style: GoogleFonts.luckiestGuy(
  247. fontSize: 28,
  248. color: Color(0xFF4858A7),
  249. fontStyle: FontStyle.italic,
  250. ),
  251. ),
  252. Image.asset('assets/icons/ic_salary.png', width: 40, height: 40,),
  253. ],
  254. )
  255. ),
  256. SafeArea(
  257. child: Container(
  258. width: MediaQuery.of(context).size.width,
  259. margin: EdgeInsets.only(
  260. top: MediaQuery.of(context).size.height / 5,
  261. left: 15,
  262. right: 15,
  263. ),
  264. child: Column(
  265. children: [
  266. Container(
  267. margin: EdgeInsets.only(bottom: 20),
  268. child: Row(
  269. children: [
  270. Expanded(
  271. flex: 2,
  272. child: Text(
  273. 'Date\t:\t',
  274. style: GoogleFonts.inconsolata(fontSize: 20),
  275. )),
  276. Expanded(
  277. flex: 8,
  278. child: Container(
  279. decoration: BoxDecoration(
  280. color: CupertinoColors.systemGrey2,
  281. borderRadius: BorderRadius.circular(5)),
  282. child: DropdownButton(
  283. menuMaxHeight: size.height * 0.31,
  284. value: this.selectedDate,
  285. isExpanded: true,
  286. underline: SizedBox(),
  287. hint: Text(
  288. '\t\t\tChoose Date',
  289. style: TextStyle(color: Colors.black54),
  290. ),
  291. onChanged: (value) {
  292. print(value);
  293. setState(() {
  294. selectedDate = value!;
  295. if (selectedDate == value){
  296. visible = true;
  297. for (int i = 0; i < dateTo_List.length; i ++){
  298. if (selectedDate == dateTo_List[i]){
  299. indexBatchID = i;
  300. break;
  301. }
  302. }
  303. //logDev.log(indexBatchID.toString(), name: "INDEX BATCH ID");
  304. getDetailData();
  305. } else {
  306. visible = false;
  307. }
  308. });
  309. },
  310. items: dateTo_List
  311. .map(
  312. (e) => DropdownMenuItem(
  313. value: e,
  314. child: Text("\t\t\t" + e)),
  315. )
  316. .toList(),
  317. ),
  318. )),
  319. ],
  320. ),
  321. ),
  322. Visibility(
  323. visible: visible,
  324. child: Text(
  325. 'Pay Slip ' + selectedDate.toString() + "\nPT. Global Service Indonesia",
  326. textAlign: TextAlign.center,
  327. style: GoogleFonts.viga(
  328. fontSize: 15,
  329. fontWeight: FontWeight.bold,
  330. ),
  331. ),
  332. ),
  333. Visibility(
  334. visible: visible,
  335. child: ListView.builder(
  336. shrinkWrap: true,
  337. itemCount: 1,
  338. itemBuilder: (context, int indexBatchID){
  339. return Container(
  340. //height: 200,
  341. margin: EdgeInsets.fromLTRB(0, 15, 0, 10),
  342. decoration: BoxDecoration(
  343. color: Color(0XFFFFFEFC),
  344. borderRadius: BorderRadius.circular(10),
  345. ),
  346. child: Card(
  347. elevation: 5,
  348. child: Column(
  349. children: [
  350. Text(number_List[indexBatchID], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  351. Text(structure_List[indexBatchID], style: GoogleFonts.nunito(fontSize: 15)),
  352. Text(period_List[indexBatchID], style: GoogleFonts.nunito(fontSize: 15)),
  353. Text(name_List[indexBatchID], style: GoogleFonts.nunito(fontSize: 15)),
  354. Text(position, style: GoogleFonts.nunito(fontSize: 15)),
  355. Text("Payment : " /*+ payment_List[i]*/, style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  356. Text(number_List[indexBatchID], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  357. ],
  358. ),
  359. ),
  360. );
  361. },
  362. ),
  363. ),
  364. Visibility(
  365. visible: visible,
  366. child: Container(
  367. alignment: Alignment.centerRight,
  368. child: ElevatedButton(
  369. onPressed: () async {
  370. ProgressDialog loading = ProgressDialog(context);
  371. loading = ProgressDialog(context,
  372. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  373. loading.style(
  374. message: 'Please Wait .....',
  375. borderRadius: 3,
  376. backgroundColor: Colors.white,
  377. progressWidget: CircularProgressIndicator(),
  378. elevation: 10.0,
  379. padding: EdgeInsets.all(10),
  380. insetAnimCurve: Curves.easeInOut,
  381. progress: 0.0,
  382. maxProgress: 100.0,
  383. progressTextStyle: TextStyle(
  384. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  385. messageTextStyle: TextStyle(
  386. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  387. await loading.show();
  388. DownloadSlipGaji_Post.connectToAPI(batchID_List[indexBatchID]).then((valueResult) async {
  389. Map<String, dynamic> object = json.decode(valueResult);
  390. if (object.containsKey("result").toString() == "true"){
  391. String result = object['result'].toString();
  392. if (result.contains("failed")) {
  393. await loading.hide();
  394. setState(() {
  395. alertDialogFailedDownloadPayslip(context);
  396. });
  397. } else if (result.contains("url")){
  398. await loading.hide();
  399. setState(() {
  400. //_launchURL(Uri.parse(baseURL + object['result']['url'].toString()));
  401. Uri url = Uri.parse(Uri.encodeFull(baseURL + object['result']['url'.toString()]));
  402. launchUrl(url, mode: LaunchMode.externalApplication);
  403. });
  404. }
  405. } else {
  406. await loading.hide();
  407. setState((){
  408. alertDialogFailedResponse(context);
  409. });
  410. }
  411. await loading.hide();
  412. });
  413. },
  414. style: ElevatedButton.styleFrom(),
  415. child: Text('Download Slip Gaji'),
  416. ),
  417. ),
  418. ),
  419. ],
  420. ),
  421. )),
  422. ],
  423. ),
  424. ],
  425. )),
  426. );
  427. }
  428. }
  429. const List<Color> Gradients1 = [
  430. Color(0xFF0EDED2),
  431. Color(0xFF03A0FE),
  432. ];
  433. launchURL(Uri url) async {
  434. if (await canLaunchUrl(url)) {
  435. await launchUrl(url);
  436. } else {
  437. throw 'Could not launch $url';
  438. }
  439. }
  440. alertDialogFailedRetrievedData(BuildContext context){
  441. Widget okButton = TextButton(
  442. child: Text("Refresh"),
  443. onPressed: () {
  444. Navigator.of(context, rootNavigator: true).pop();
  445. Navigator.pushReplacement(context, MaterialPageRoute(
  446. builder: (context) => SlipGajiScreen()));
  447. },
  448. );
  449. Widget noButton = TextButton(
  450. child: Text("Back"),
  451. onPressed: () {
  452. Navigator.of(context, rootNavigator: true).pop();
  453. Navigator.pop(context);
  454. },
  455. );
  456. // set up the AlertDialog
  457. AlertDialog alert = AlertDialog(
  458. title: Text(appName),
  459. content: Text("Failed to Retrieve Data"),
  460. actions: [
  461. noButton,
  462. okButton,
  463. ],
  464. );
  465. // show the dialog
  466. showDialog(
  467. context: context,
  468. barrierDismissible: false,
  469. builder: (BuildContext context) {
  470. return alert;
  471. },
  472. );
  473. }
  474. alertDialogFailedResponse(BuildContext context){
  475. Widget okButton = TextButton(
  476. child: Text("Refresh"),
  477. onPressed: () {
  478. Navigator.of(context, rootNavigator: true).pop();
  479. Navigator.pushReplacement(context, MaterialPageRoute(
  480. builder: (context) => SlipGajiScreen()));
  481. },
  482. );
  483. Widget noButton = TextButton(
  484. child: Text("Back"),
  485. onPressed: () {
  486. Navigator.of(context, rootNavigator: true).pop();
  487. Navigator.pop(context);
  488. },
  489. );
  490. // set up the AlertDialog
  491. AlertDialog alert = AlertDialog(
  492. title: Text(appName),
  493. content: Text("Server Response Error"),
  494. actions: [
  495. noButton,
  496. okButton,
  497. ],
  498. );
  499. // show the dialog
  500. showDialog(
  501. context: context,
  502. barrierDismissible: false,
  503. builder: (BuildContext context) {
  504. return alert;
  505. },
  506. );
  507. }
  508. alertDialogFailedDownloadPayslip(BuildContext context){
  509. Widget okButton = TextButton(
  510. child: Text("Try Again"),
  511. onPressed: () {
  512. Navigator.of(context, rootNavigator: true).pop();
  513. Navigator.pop(context);
  514. },
  515. );
  516. // set up the AlertDialog
  517. AlertDialog alert = AlertDialog(
  518. title: Text(appName),
  519. content: Text("Failed to Download Payslip"),
  520. actions: [
  521. okButton,
  522. ],
  523. );
  524. // show the dialog
  525. showDialog(
  526. context: context,
  527. barrierDismissible: false,
  528. builder: (BuildContext context) {
  529. return alert;
  530. },
  531. );
  532. }