123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- import 'dart:convert';
- import 'package:firebase_core/firebase_core.dart';
- import 'package:firebase_crashlytics/firebase_crashlytics.dart';
- import 'package:flutter/material.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:employee_selfservice_mobile/constants.dart';
- import 'package:intl/intl.dart';
- import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
- import 'dart:developer' as logDev;
-
- import '../AjukanCuti/backgroundHistory.dart';
- import 'RequestHttp/historyAbsensi_post.dart';
-
- class HistoryAbsensi extends StatefulWidget {
- const HistoryAbsensi({Key? key}) : super(key: key);
-
- @override
- State<HistoryAbsensi> createState() => _HistoryAbsensi();
- }
-
- class _HistoryAbsensi extends State<HistoryAbsensi> {
- late List <String> id_List;
- late List <String> employee_name_List;
- late List <String> check_in_List;
- late List <String> check_out_List;
- late List <String> worked_hours_List;
-
- late List <String> dayDate_List;
- late List <String> date_List;
- late List <String> month_List;
-
- //late List <String> workingHours_List;
- late List <String> showCheckIn_List;
- late List <String> showCheckOut_List;
-
- int HistoryLength = 0;
-
- //List Visibility Double Date
- late List <bool> visibilityDate2;
-
- late List <String> dayDate_list_2;
- late List <String> date_list_2;
- late List <String> month_list_2;
-
-
- @override
- initState() {
- super.initState();
- id_List = [""];
- employee_name_List = [""];
- check_in_List = [""];
- check_out_List = [""];
- worked_hours_List = [""];
-
- dayDate_List = [""];
- date_List = [""];
- month_List = [""];
-
- //workingHours_List = [""];
- showCheckIn_List = [""];
- showCheckOut_List = [""];
-
- visibilityDate2 = [false];
- dayDate_list_2 = [""];
- date_list_2 = [""];
- month_list_2 = [""];
-
- 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();
- HistoryAbsensi_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> historyAbsensi = object['result'];
- await loading.hide();
- setState(() {
- for (int i = 0; i < historyAbsensi.length; i++){
- String id = historyAbsensi[i]['id'].toString();
- String employee_name = historyAbsensi[i]['employee_name'].toString();
- String check_in = historyAbsensi[i]['check_in'].toString();
- String check_out = historyAbsensi[i]['check_out'].toString();
- String worked_hours = historyAbsensi[i]['worked_hours'].toString();
- //String coordinate = historyAbsensi[i]['coordinate'].toString();
-
- double hours = double.parse(worked_hours);
-
- //Jika Sudah Checkin
- if (check_in != "false"){
- //Convert UTC to Local Time - Check In Time
- DateTime checkInTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(check_in, true);
- String showCheckInTime = checkInTime.toLocal().toString().substring(11, 19);
- showCheckIn_List.add(showCheckInTime.substring(0,5));
- //Jika belum check in
- } else if (check_in == "false"){
- String show_check_in = "-";
- showCheckIn_List.add(show_check_in);
- }
-
- //Jika Sudah Checkout
- if (check_out != "false"){
- //Convert UTC to Local Time - Check Out Time
- DateTime checkOutTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(check_out, true);
- String showCheckOutTime = checkOutTime.toLocal().toString().substring(11, 19);
- showCheckOut_List.add(showCheckOutTime.substring(0,5));
- //Jika tanggal check in sama dengan tanggal check out
- if (check_in.substring(0, 10) == check_out.substring(0,10)){
- //Get Day Check In
- String dayDateIn = DateFormat('EEEE').format(DateTime.parse(check_in));
- String dateIn = DateFormat('dd').format(DateTime.parse(check_in));
- String monthIn = DateFormat('MMM').format(DateTime.parse(check_in));
- dayDate_List.add(dayDateIn.substring(0,3));
- date_List.add(dateIn);
- month_List.add(monthIn);
-
- dayDate_list_2.add("");
- date_list_2.add("");
- month_list_2.add("");
-
- visibilityDate2.add(false);
-
- //Jika tangagal check in tidak sama dengan tanggal checkout
- } else if (check_in.substring(0, 10) != check_out.substring(0,10)){
- //Get Day Check In & Check Out
- String dayDateIn = DateFormat('EEEE').format(DateTime.parse(check_in));
- String dateIn = DateFormat('dd').format(DateTime.parse(check_in));
- String monthIn = DateFormat('MMM').format(DateTime.parse(check_in));
-
- String dayDateOut = DateFormat('EEEE').format(DateTime.parse(check_out));
- String dateOut = DateFormat('dd').format(DateTime.parse(check_out));
- String monthOut = DateFormat('MMM').format(DateTime.parse(check_out));
-
- dayDate_List.add(dayDateIn.substring(0,3));
- date_List.add(dateIn);
- month_List.add(monthIn);
-
- dayDate_list_2.add(dayDateOut.substring(0,3));
- date_list_2.add(dateOut);
- month_list_2.add(monthOut);
-
- visibilityDate2.add(true);
- }
- //Jika belum checkout
- } else if (check_out == "false"){
- String show_check_out = "-";
- showCheckOut_List.add(show_check_out);
-
- String dayDateIn = DateFormat('EEEE').format(DateTime.parse(check_in));
- String dateIn = DateFormat('dd').format(DateTime.parse(check_in));
- String monthIn = DateFormat('MMM').format(DateTime.parse(check_in));
- dayDate_List.add(dayDateIn.substring(0,3));
- date_List.add(dateIn);
- month_List.add(monthIn);
-
- visibilityDate2.add(false);
-
- dayDate_list_2.add("");
- date_list_2.add("");
- month_list_2.add("");
- }
-
- /*if (check_in == "true" && check_out == "false"){
- visibilityDate2.add(false);
- } else if (check_in == "false" && check_out == "false"){
- visibilityDate2.add(false);
- } else if (check_in == "true" && check_out == "true"){
- visibilityDate2.add(true);
- }*/
-
- id_List.add(id);
- employee_name_List.add(employee_name);
- check_in_List.add(check_in);
- check_out_List.add(check_out);
- worked_hours_List.add(hours.toStringAsFixed(3));
- }
-
- id_List.removeAt(0);
- employee_name_List.removeAt(0);
- check_in_List.removeAt(0);
- check_out_List.removeAt(0);
- worked_hours_List.removeAt(0);
-
- dayDate_List.removeAt(0);
- date_List.removeAt(0);
- month_List.removeAt(0);
-
- //workingHours_List.removeAt(0);
- showCheckIn_List.removeAt(0);
- showCheckOut_List.removeAt(0);
-
- visibilityDate2.removeAt(0);
- logDev.log(visibilityDate2.toString(), name: "VISIBILITY DATE");
- dayDate_list_2.removeAt(0);
- date_list_2.removeAt(0);
- month_list_2.removeAt(0);
-
- HistoryLength = historyAbsensi.length;
- });
- }
- } else {
- alertDialogFailedRetrievedData(context);
- 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(
- 'Attendance History\t\t',
- maxLines: 1,
- style: GoogleFonts.luckiestGuy(
- fontSize: 28,
- color: Color(0xFF4858A7),
- //fontWeight: FontWeight.bold,
- 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(
- margin: EdgeInsets.fromLTRB(5, 5, 5, 5),
- child: InkWell(
- child: Card(
- elevation: 8,
- child: Container(
- padding: EdgeInsets.all(10),
- child: Row(
- children: [
- Expanded(
- flex: 3,
- child:
- Container(
- alignment: Alignment.center,
- padding: EdgeInsets.all(5),
- decoration: BoxDecoration(
- border: Border.all(color: Colors.black),
- borderRadius: BorderRadius.all(Radius.circular(3)),
- ),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Column(
- children: [
- Text(dayDate_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
- Text(date_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- Text(month_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- ],
- ),
- Visibility(
- visible: visibilityDate2[i],
- child: Column(
- children: [
- Text("\t|\t", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
- Text("\t|\t", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- Text("\t|\t", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- ],
- ),
- ),
- Visibility(
- visible: visibilityDate2[i],
- child: Column(
- children: [
- Text(dayDate_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
- Text(date_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- Text(month_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- ],
- ),
- ),
- /*Expanded(
- flex: 1,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text(dayDate_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.right,),
- Text(date_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.right),
- Text(month_List[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.right),
- ],
- )
- ),
- Expanded(
- flex: 1,
- child: Visibility(
- visible: visibilityDate2[i],
- child: Column(
- children: [
- Text("|", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center,),
- Text("|", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- Text("|", style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.center),
- ],
- ),
- )
- ),
- Expanded(
- flex: 1,
- child: Visibility(
- visible: visibilityDate2[i],
- child: Column(
- children: [
- Text(dayDate_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.left,),
- Text(date_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.left),
- Text(month_list_2[i], style: GoogleFonts.fredoka(fontSize: 15, color: Colors.blueGrey), textAlign: TextAlign.left),
- ],
- ),
- ))*/
- ],
- ),
- )
- ),
- Expanded(
- flex: 2,
- child: Column(
- children: [
- Text("Check In", style: GoogleFonts.fredoka(fontSize: 16),textAlign: TextAlign.center),
- Text(showCheckIn_List[i], style: GoogleFonts.barlowSemiCondensed(fontSize: 16),textAlign: TextAlign.center),
- ],
- ),
- ),
- Expanded(
- flex: 2,
- child: Column(
- children: [
- Text("Check Out", style: GoogleFonts.fredoka(fontSize: 16),textAlign: TextAlign.center),
- Text(showCheckOut_List[i], style: GoogleFonts.barlowSemiCondensed(fontSize: 16),textAlign: TextAlign.center),
- ],
- ),
- ),
- Expanded(
- flex: 2,
- child: Column(
- children: [
- Text("Working\nHours", style: GoogleFonts.fredoka(fontSize: 16), textAlign: TextAlign.center),
- Text(worked_hours_List[i], style: GoogleFonts.barlowSemiCondensed(fontSize: 16),textAlign: TextAlign.center),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- 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) => HistoryAbsensi()));
- },
- );
-
- 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(appName),
- content: Text("Failed to Retrieve Data"),
- actions: [
- noButton,
- okButton,
- ],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
-
- alertDialogFailedResponse(BuildContext context){
- Widget okButton = TextButton(
- child: Text("Refresh"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pushReplacement(context, MaterialPageRoute(
- builder: (context) => HistoryAbsensi()));
- },
- );
-
- 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(appName),
- content: Text("Server Response Error"),
- actions: [
- noButton,
- okButton,
- ],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
|