callARMMultipleGrnScanApi method

Future<void> callARMMultipleGrnScanApi(
  1. String? serialNum,
  2. String? serialStartRange,
  3. String? serialEndRange,
  4. int pageNo,
  5. String requestToPartnerId,
)

Implementation

Future<void> callARMMultipleGrnScanApi(
    String? serialNum,
    String? serialStartRange,
    String? serialEndRange,
    int pageNo,
    String requestToPartnerId) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  passedAssets = <PassedAssets>[].obs;
  try {
    String requestTime = "";
    String responseTime = "";
    StockDeliveryScanModel model = await ApiClient(
      baseUrl: ApiConstant.armBaseUrl,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "grn",
    ).validateAssets(
        xUserId: SecureStorageService.readSecureData(
          SecureStorageService.xUserId,
        ),
        action: "INV_OPERATOR_STOCK_GR",
        assetIds: serialNum,
        assetStartRange: serialStartRange,
        assetEndRange: serialEndRange,
        fromPartnerId: requestToPartnerId);
    Helper.logEvent(
      "RESPONSE_EVENT",
      success: true,
      endPoint: Api.validateAssets,
      responseDate: responseTime,
      screenName: "grn",
      requestDate: requestTime,
    );
    isLoadingAssets.value = false;
    if (model.status == true) {
      var isValidated = false;
      if (model.data != null &&
          model.data!.passedAssets != null &&
          model.data!.passedAssets!.isNotEmpty) {
        // if (pageNo == 1) {
        if (model.data!.passedAssets!.length == 1) {
          var tempIccids = <String>[].obs;
          tempIccids.addAll(scannedIccidList);
          RxList<ProductContentModel> temp = <ProductContentModel>[].obs;
          temp.addAll(productDataScannedList);
          for (int i = 0; i < temp.length; i++) {
            if (model.data != null &&
                model.data!.passedAssets != null &&
                model.data!.passedAssets!.isNotEmpty) {
              if (temp[i].productCode ==
                  model.data!.passedAssets![0].productCode) {
                List<SingleScannedModel> iccidList = [];
                iccidList.addAll(temp[i].iccidList ?? []);
                for (final PassedAssets asset
                    in model.data!.passedAssets ?? []) {
                  tempIccids.add(asset.serialnumber ?? "");
                  iccidList.add(
                    SingleScannedModel(
                      iccid: asset.serialnumber,
                    ),
                  );
                }
                var grnProduct = temp[i].copyWith(
                    iccidList: iccidList, scannedQty: iccidList.length);
                temp[i] = grnProduct;
              }
            }
          }
          scannedIccidList = tempIccids; // assigning all the scanned iccids;
          productDataScannedList.value = [...temp]; // assigning product list
          isScanning.value = false;
          Helper.close();
        } else {
          passedAssets.addAll(model.data!.passedAssets!);
          Helper.close();
          // if (pageNo == 1) {
          ProductsBottomsheet().multipleProductsBottomsheet(
              context,
              localization.translate("selectProductUnderSerial"),
              serialNum,
              serialStartRange,
              serialEndRange,
              requestToPartnerId);
          // }
        }
        // }
      } else {
        Helper.close();
        Helper.messageDialog(
          Get.context!,
          localization.translate("unavailable"),
          localization.translate("scannedAssetNotAvailable"),
          onTap: () {
            Helper.close();
            isScanning.value = false;
          },
        );
      }
    } else {
      Helper.close();
      isScanning.value = false;
      if (model.errors != null) {
        Helper.messageDialog(
          Get.context!,
          model.errors![0].errorCode ?? "Try again!!",
          model.errors![0].errorDescription ?? "Something went wrong",
          onTap: () {
            Helper.close();
            isScanning.value = false;
          },
        );
      }
    }
  } catch (err, stacktrace) {
    isLoadingAssets.value = false;
    ConditionalLogs().customLog("$err");
    ConditionalLogs().customLog("$stacktrace");
    Helper.close();
    Helper.messageDialog(
      Get.context!,
      localization.translate("tryAgain"),
      localization.translate("technicalErrorMsg"),
      onTap: () {
        Helper.close();
        isScanning.value = false;
      },
    );
  }
}