loadData method

void loadData()

Implementation

void loadData() {
  widget.erpNextAPI.getLeaveEncashment(
    widget.employeeId,
    (leaveEncashmentDetails) {
      List<LeaveEncashmentModel> tempLeaveEncashments = [];
      for (var leave in leaveEncashmentDetails) {
        if (leave.isNotEmpty) {
          tempLeaveEncashments.add(LeaveEncashmentModel.fromJson(leave));
        }
      }
      setState(() {
        encashmentList = tempLeaveEncashments;
      });
    },
    (errorDetails) {
      MyAlertDialog().showMyAlertDialog(context, errorDetails);
    },
  );
  widget.erpNextAPI.getHolidayList(
    (holidayDetails) {
      List<HolidayModel> tempHolidayList = [];
      for (var holiday in holidayDetails) {
        if (holiday.isNotEmpty) {
          tempHolidayList.add(HolidayModel.fromJson(holiday));
        }
      }
      setState(() {
        holidayList = tempHolidayList;
      });
    },
    (errorDetails) {
      MyAlertDialog().showMyAlertDialog(context, errorDetails);
    },
  );
  widget.erpNextAPI.getLeaveAllotment(
    widget.employeeId,
    (allotmentDetails) {
      String fromDate = "";
      String toDate = "";
      for (var allotment in allotmentDetails) {
        if (allotment["from_date"] != null) {
          if (fromDate.isNotEmpty) {
            if (DateTime.parse(
                  allotment["from_date"],
                ).compareTo(DateTime.parse(fromDate)) <
                0) {
              fromDate = allotment["from_date"];
            }
          } else {
            fromDate = allotment["from_date"];
          }
        }
        if (allotment["to_date"] != null) {
          if (toDate.isNotEmpty) {
            if (DateTime.parse(
                  allotment["to_date"],
                ).compareTo(DateTime.parse(toDate)) <
                0) {
              toDate = allotment["to_date"];
            }
          } else {
            toDate = allotment["to_date"];
          }
        }
      }
      if (toDate.isEmpty) {
        if (fromDate.isEmpty) {
          toDate = DateTime.now().toString();
          fromDate = DateTime.now().subtract(Duration(days: 30)).toString();
        } else {
          toDate =
              DateTime.parse(fromDate).add(Duration(days: 30)).toString();
        }
      } else {
        if (fromDate.isEmpty) {
          fromDate =
              DateTime.parse(toDate).subtract(Duration(days: 30)).toString();
        }
      }
      if (toDate.isNotEmpty && fromDate.isNotEmpty) {
        widget.erpNextAPI.getLeaveBalanceReport(
          widget.employeeId,
          fromDate,
          toDate,
          (leaveBalanceDetails) {
            List<LeaveBalanceReportModel> tempLeaveBalances = [];
            for (var leaveBalance in leaveBalanceDetails) {
              if (leaveBalance.isNotEmpty) {
                tempLeaveBalances.add(
                  LeaveBalanceReportModel.fromJson(leaveBalance),
                );
              }
            }
            setState(() {
              leaveBalanceReport = tempLeaveBalances;
            });
          },
          (errorDetails) {
            MyAlertDialog().showMyAlertDialog(context, errorDetails);
          },
        );
      }
    },
    (errorDetails) {
      MyAlertDialog().showMyAlertDialog(context, errorDetails);
    },
  );
  DateTime currentDate = DateTime.now();
  widget.erpNextAPI.getLeaveBalanceSummary(
    widget.employeeId,
    widget.company,
    currentDate.toString().substring(0, 10),
    (leaveBalanceDetails) {
      List<LeaveBalanceSummaryModel> tempLeaveBalanceSummary = [];
      for (var leaveBalance in leaveBalanceDetails) {
        if (leaveBalance.isNotEmpty) {
          tempLeaveBalanceSummary.add(
            LeaveBalanceSummaryModel.fromJson(leaveBalance),
          );
        }
      }
      setState(() {
        leaveBalanceSummary = tempLeaveBalanceSummary;
      });
    },
    (errorDetails) {
      MyAlertDialog().showMyAlertDialog(context, errorDetails);
    },
  );
}