callHistoryApi method

void callHistoryApi({
  1. String? status,
  2. String? search,
  3. int offset = 0,
})

Implementation

void callHistoryApi({
  String? status,
  String? search,
  int offset = 0,
}) async {
  BuildContext context = Get.context!;
  if (offset == 0 && search == null) {
    isSearching.value = true;
    //Helper.progressDialog(context, "Please wait..");
  }
  if (search != null) {
    isSearching.value = true;
  }
  try {
    String requestTime = "";
    String responseTime = "";
    CollectStockHistoryModel model = await ApiClient(
      baseUrl: ApiConstant.posBFF,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "collectStockHistory",
    ).getCollectStockHistoryTransactions(
      toPartyId: null,
      fromPartyId: SecureStorageService.readSecureData(
            SecureStorageService.partnerIdLogin,
          ) ??
          "",
      transactionByParty: "",
      limit: "10",
      offset: offset.toString(),
      type: "SCAN_IN",
      xUserId: SecureStorageService.readSecureData(
            SecureStorageService.xUserId,
          ) ??
          "",
      status: status ?? "COMPLETED",
      search: search,
      fromDate: isDateSelected.value
          ? DateFormat("dd-MM-yyyy")
              .format(DateTime.parse(fromDateController.value.text))
          : null,
      toDate: isDateSelected.value
          ? DateFormat("dd-MM-yyyy")
              .format(DateTime.parse(toDateController.value.text))
          : null,
    );
    Helper.logEvent(
      "RESPONSE_EVENT",
      success: true,
      endPoint: "${Api.getCollectStockHistoryTransactions}/SCAN_IN",
      responseDate: responseTime,
      screenName: "collectStockHistory",
      requestDate: requestTime,
    );
    if (offset == 0) {
      //Get.back();
    }
    if (model.status == "POS200") {
      if (offset == 0) {
        transactionHistoryList.value = model.data!.list ?? [];
        searchedOrderList.value = transactionHistoryList;
      } else {
        transactionHistoryList.addAll(model.data!.list ?? []);
        searchedOrderList.value = transactionHistoryList;
      }
      isLoadingMore.value = false;
    } else {
      if (model.errors != null) {
        Helper.messageDialog(
          Get.context!,
          model.errors![0].code ?? "Try again!!",
          model.errors![0].description ?? "Something went wrong",
        );
      }
    }
    isSearching.value = false;
  } catch (err, stacktrace) {
    ConditionalLogs().customLog("$stacktrace");
    isSearching.value = false;
    if (offset == 0) {
      //Get.back();
    }
    MainController mainController = Get.put(MainController());
    mainController.showErrorPopup();
  }
}