callStockDeliveryARMScanApi method

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

Implementation

Future<void> callStockDeliveryARMScanApi(
    String? serialNum,
    String? serialStartRange,
    String? serialEndRange,
    String requestToPartnerId) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  try {
    String requestTime = "";
    String responseTime = "";
    StockDeliveryScanModel model = await ApiClient(
      baseUrl: ApiConstant.armBaseUrl,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "scan",
    ).validateAssets(
        xUserId: SecureStorageService.readSecureData(
          SecureStorageService.xUserId,
        ),
        action: "INV_SELL_THRU_DELIVERY",
        assetIds: serialNum,
        assetStartRange: serialStartRange,
        assetEndRange: serialEndRange,
        fromPartnerId: requestToPartnerId);
    Helper.close();
    Helper.logEvent(
      "RESPONSE_EVENT",
      success: true,
      endPoint: Api.validateAssets,
      responseDate: responseTime,
      screenName: "scan",
      requestDate: requestTime,
    );
    if (model.status == true) {
      var isValidated = false;
      productDataScannedList.forEach((element) {
        if (model.data != null &&
            model.data!.passedAssets != null &&
            model.data!.passedAssets!.isNotEmpty) {
          if (element.productCode ==
              model.data!.passedAssets![0].productCode) {
            isValidated = true;
          }
        }
      });
      if (isValidated) {
        if (cartId.isNotEmpty) {
          callUpdateCartApi(
              serialNum, serialStartRange, serialEndRange, null);
        } else {
          callAddToCartApi(serialNum, serialStartRange, serialEndRange, null);
        }
      }
      isValidated = false;
    } else {
      if (model.errors != null) {
        Helper.messageDialog(
            Get.context!,
            model.errors![0].errorCode ?? "Try again!!",
            model.errors![0].errorDescription ?? "Something went wrong");
      }
    }
  } catch (err, stacktrace) {
    Helper.close();
    ConditionalLogs().customLog("$err");
    ConditionalLogs().customLog("$stacktrace");
    MainController mainController = Get.put(MainController());
    mainController.showErrorPopup();
  }
}