callCreditLimitValidation method

Future<void> callCreditLimitValidation(
  1. String? serialNum,
  2. String? serialStartRange,
  3. String? serialEndRange,
  4. String? productCode,
)

Implementation

Future<void> callCreditLimitValidation(
    String? serialNum,
    String? serialStartRange,
    String? serialEndRange,
    String? productCode) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  try {
    String requestTime = "";
    String responseTime = "";
    CreditLimitValidationModel model = await ApiClient(
      baseUrl: ApiConstant.posBFF,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "collectStockSubmit",
      buttonName: "submit",
    ).creditLimitValidation(
      cartId: cartId,
      xRoles: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
      xUserId: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
    );

    if (model.status == "POS200") {
      Helper.logEvent(
        "RESPONSE_EVENT",
        success: true,
        endPoint: "${Api.creditLimitValidation}/$cartId",
        responseDate: responseTime,
        screenName: "collectStockSubmit",
        buttonName: "submit",
        requestDate: requestTime,
        transactionId: cartId,
      );
      availableCreditBalance.value =
          double.parse(model.data!.creditLimitInfo!.limit!.amount ?? "0.0");
      usedCreditBalance.value =
          double.parse(model.data!.creditLimitInfo!.used!.amount ?? "0.0");
      totalCreditBalance.value = // credit balance
          double.parse(model.data!.creditLimitInfo!.balance!.amount ?? "0.0");
      if (usedCreditBalance.value != 0.0) {
        percentageCreditBalance.value =
            usedCreditBalance.value / availableCreditBalance.value;
      }
      Helper.close();
    } else if (model.status == "POS401" &&
        (serialNum != null || serialStartRange != null)) {
      Helper.close();
      await Helper.messageDialog(
        Get.context!,
        localization.translate("tryAgain"),
        model.errors?[0].localeMessage ?? "",
      );
      callDeleteAssetByIdApi(
          serialNum, serialStartRange, serialEndRange, productCode, true);
    } else {
      Helper.close();
    }
  } catch (err, stacktrace) {
    ConditionalLogs().customLog("$err");
    ConditionalLogs().customLog("$stacktrace");
    MainController mainController = Get.put(MainController());
    mainController.showErrorPopup();
  }
}