forked from dienianindya/gsi_ess_mobile
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.
297 lines
11 KiB
297 lines
11 KiB
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;
|
|
},
|
|
);
|
|
}
|