123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- import 'dart:convert';
-
- import 'package:flutter/material.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
- import 'dart:developer' as logDev;
-
- import '../AjukanCuti/backgroundHistory.dart';
- import 'RequestHttp/historyReimburse_post.dart';
-
- class HistoryReimburse extends StatefulWidget {
- const HistoryReimburse({Key? key}) : super(key: key);
-
- @override
- State<HistoryReimburse> createState() => _HistoryReimburse();
- }
-
- class _HistoryReimburse extends State<HistoryReimburse> {
- late List <String> date_List;
- late List <String> name_List;
- late List <String> employee_List;
- late List <String> payment_List;
- late List <String> activity_List;
- late List <String> total_List;
- late List <String> status_List;
-
- late List <Color> statusColor;
- late List <bool> visible;
-
- int HistoryLength = 0;
-
- @override
- initState() {
- super.initState();
- date_List = [""];
- name_List = [""];
- employee_List = [""];
- payment_List = [""];
- activity_List = [""];
- total_List = [""];
- status_List = [""];
-
- statusColor = [Colors.black54];
- visible = [false];
-
- WidgetsBinding.instance.addPostFrameCallback((_) async {
- getHistoryData();
- });
- }
-
- getHistoryData() async {
- ProgressDialog loading = ProgressDialog(context);
- loading = ProgressDialog(context,
- type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
- loading.style(
- message: 'Please Wait .....',
- borderRadius: 3,
- backgroundColor: Colors.white,
- progressWidget: CircularProgressIndicator(),
- elevation: 10.0,
- padding: EdgeInsets.all(10),
- insetAnimCurve: Curves.easeInOut,
- progress: 0.0,
- maxProgress: 100.0,
- progressTextStyle: TextStyle(
- color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
- messageTextStyle: TextStyle(
- color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
-
- await loading.show();
- HistoryReimburse_Post.connectToAPI().then((valueResult) async {
- Map<String, dynamic> object = jsonDecode(valueResult);
- if (object.containsKey("result").toString() == "true") {
- String result = object['result'].toString();
- if (result.contains("failed")) {
- await loading.hide();
- alertDialogFailedRetrievedData(context);
- } else {
- List <dynamic> historyReimburse = object['result'];
- await loading.hide();
- setState(() {
- for (int i = 0; i < historyReimburse.length; i++){
- String date = historyReimburse[i]['date'].toString();
- String name = historyReimburse[i]['name'].toString();
- String employee = historyReimburse[i]['employee'].toString();
- String payment = historyReimburse[i]['payment'].toString();
- String activity = historyReimburse[i]['activity'].toString();
- String total = historyReimburse[i]['total'].toString();
- String status = historyReimburse[i]['status'].toString();
-
- /*if (detail == "false"){
- detail = "-";
- }*/
-
- date_List.add(date);
- name_List.add(name);
- employee_List.add(employee);
- payment_List.add(payment);
- activity_List.add(activity);
- total_List.add(total);
- status_List.add(status);
- visible.add(false);
-
- var statColor;
- if (status == "draft"){
- statColor = Colors.red;
- } else if (status == "approved"){
- statColor = Colors.green;
- } else if (status == "done"){
- statColor = Colors.blueAccent;
- }
- statusColor.add(statColor);
- }
-
- date_List.removeAt(0);
- name_List.removeAt(0);
- employee_List.removeAt(0);
- payment_List.removeAt(0);
- activity_List.removeAt(0);
- total_List.removeAt(0);
- status_List.removeAt(0);
- statusColor.removeAt(0);
- visible.removeAt(0);
-
- HistoryLength = historyReimburse.length;
- });
- }
- } else {
- Fluttertoast.showToast(
- msg: "Server Response Error",
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.CENTER,
- timeInSecForIosWeb: 1,
- textColor: Colors.white,
- fontSize: 16.0);
- }
- });
- await loading.hide();
- }
-
- @override
- Widget build(BuildContext context) {
- var size = MediaQuery.of(context).size;
- return Scaffold(
- body: Stack(
- children: [
- Column(
- children: <Widget>[
- Stack(
- children: [
- WavyHeader(),
- Container(
- margin: EdgeInsets.only(
- top: (size.height / 6) - 20),
- padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- Text(
- 'Reimburse History\t\t',
- maxLines: 1,
- style: GoogleFonts.luckiestGuy(
- fontSize: 28,
- color: Color(0xFF4858A7),
- fontStyle: FontStyle.italic,
- ),
- ),
- Image.asset(
- 'assets/images/ic_history.png',
- width: 40,
- height: 40,
- ),
- ],
- )
- ),
- ],
- ),
- ],
- ),
- Container(
- margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40,
- left: 5, right: 5, bottom: 10),
- child: ListView.builder(
- scrollDirection: Axis.vertical,
- shrinkWrap: true,
- itemCount: HistoryLength,
- itemBuilder: (context, int i) {
- return Container(
- child: InkWell(
- child: Card(
- elevation: 10,
- child: Column(
- children: [
- Row(
- children: [
- Expanded(
- flex: 8,
- child: Padding(
- padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(name_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)),
- Text(activity_List[i], style: GoogleFonts.nunito(fontSize: 15)),
- Text(date_List[i], style: GoogleFonts.nunito(fontSize: 15)),
- Text("\Total : " + total_List[i], style: GoogleFonts.nunito(fontSize: 15)),
- Text("Payment : " + payment_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
- ],
- ),
- )
- ),
- Expanded(
- flex: 2,
- child: Padding(
- padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
- child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17),
- ),
- )
- ),
- ],
- ),
- Align(
- alignment: Alignment.centerLeft,
- child: Visibility(
- visible: visible[i],
- child: Padding(
- padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text("\nAttachment : ", style: GoogleFonts.josefinSans(fontSize: 15, fontWeight: FontWeight.bold)),
- Text("\Total : " + total_List[i], style: GoogleFonts.nunito(fontSize: 15)),
- Text("Payment : " + payment_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
- ],
- ),
- )
- ),
- )
- ],
- ),
- ),
- onTap: (){
- setState(() {
- visible[i] = !visible[i];
- });
- },
- ),
- );
- },
- ),
- )
- ]),
- );
- }
- }
-
- alertDialogFailedRetrievedData(BuildContext context) {
- Widget okButton = TextButton(
- child: Text("Refresh"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pushReplacement(
- context, MaterialPageRoute(builder: (context) => HistoryReimburse()));
- },
- );
-
- Widget noButton = TextButton(
- child: Text("Back"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pop(context);
- },
- );
-
- // set up the AlertDialog
- AlertDialog alert = AlertDialog(
- title: Text("Employee Self Service"),
- content: Text("Failed to Retrieve Data"),
- actions: [
- noButton,
- okButton,
- ],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
|