callDeleteAssetByIdApi method

Future<void> callDeleteAssetByIdApi(
  1. String? serialNum,
  2. String? serialStartRange,
  3. String? serialEndRange,
  4. String? productCode,
  5. bool isReverseTheLimit,
)

Implementation

Future<void> callDeleteAssetByIdApi(
    String? serialNum,
    String? serialStartRange,
    String? serialEndRange,
    String? productCode,
    bool isReverseTheLimit) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  try {
    String requestTime = "";
    String responseTime = "";
    await ApiClient(
      baseUrl: ApiConstant.posBL,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "collectStock",
      buttonName: "delete",
    )
        .deleteAssetById(
      cartId: cartId,
      assetId: serialNum,
      startRange: serialStartRange,
      productCode: productCode,
      endRange: serialEndRange,
      xRoles: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
      xUserId: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
    )
        .then((response) async {
      cart.CartModel model = response;
      if (model.status == "POS200") {
        Helper.logEvent(
          "RESPONSE_EVENT",
          success: true,
          endPoint: "${Api.addToCart}/$cartId/assets",
          responseDate: responseTime,
          screenName: "collectStock",
          buttonName: "delete",
          requestDate: requestTime,
          transactionId: cartId,
        );
        // deleteSingleIds(
        //     cartModel: model,
        //     product: product,
        //     id: serialNum,
        //     start: serialStartRange,
        //     end: serialEndRange);
        Helper.close();
        if (!isReverseTheLimit) {
          var isProductExists = false;
          for (int i = 0; i < productDataScannedList.length; i++) {
            if (currentProduct.productCode ==
                productDataScannedList[i].productCode) {
              if (productDataScannedList[i].scannedQty == 1) {
                isProductExists = true;
              }

              break;
            }
          }
          if (isProductExists) {
            Helper.close();
          }
        }
        Future.delayed(const Duration(milliseconds: 500), () {
          cartId = model.data!.cartId!;
          discountList.value = model.data!.cartDiscountsList!;
          if (currentScan == ScanType.spotSellThru) {
            updateSpotSellThruOrder(model);
          } else if (currentScan == ScanType.sellThru) {
            updateSellThruOrder(model);
          } else if (currentScan == ScanType.collectStock) {
            totalRetailPrice = model.data!.totalRetailPrice as double;
            updateCollectStock(model, serialNum, serialStartRange,
                serialEndRange, productCode);
          }
        });
      } else {
        Helper.close();
        if (model.errors != null) {
          Helper.messageDialog(
              Get.context!,
              model.errors![0].code ?? "Try again!!",
              model.errors![0].localeMessage ?? "Something went wrong");
        }
      }
    }).catchError((error) {
      ConditionalLogs().customLog("$error");
      Helper.close();
      MainController mainController = Get.put(MainController());
      mainController.showErrorPopup();
    });
  } catch (err, stacktrace) {
    ConditionalLogs().customLog("$err");
    ConditionalLogs().customLog("$stacktrace");
    Helper.close();
  }
}