callARMMultipleStockDeliveryScanApi method
Implementation
Future<void> callARMMultipleStockDeliveryScanApi(
String? serialNum,
String? serialStartRange,
String? serialEndRange,
int pageNo,
String requestToPartnerId) async {
BuildContext context = Get.context!;
Helper.progressDialog(context, "Please wait..");
// pageNum = pageNo;
passedAssets = <PassedAssets>[].obs;
var action = "";
if (currentScan == ScanType.sellThru) {
action = "INV_SELL_THRU_DELIVERY";
} else if (currentScan == ScanType.collectStock) {
action = "INV_SCAN_IN_ALLOCATION";
} else if (currentScan == ScanType.spotSellThru) {
action = "INV_SCAN_IN_ALLOCATION";
} else {
action = "INV_SELL_THRU_DELIVERY";
}
try {
String requestTime = "";
String responseTime = "";
StockDeliveryScanModel model = await ApiClient(
baseUrl: ApiConstant.armBaseUrl,
onFetchRequestTime: (time) {
requestTime = time;
},
onFetchResponseTime: (time) {
responseTime = time;
},
screenName: "collectStock",
).validateAssetsV2(
xUserId: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
) ??
"",
action: action,
assetIds: serialNum != null
? checkValue(serialNum)
: checkValue(serialStartRange),
pageNo: pageNo,
// assetStartRange: checkValue(serialStartRange),
// assetEndRange: checkValue(serialEndRange),
fromPartnerId: requestToPartnerId,
);
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint: Api.validateAssetsV2,
responseDate: responseTime,
screenName: "collectStock",
requestDate: requestTime,
);
isLoadingAssets.value = false;
if (model.status == true) {
var isValidated = false;
if (model.data != null &&
model.data!.passedAssets != null &&
model.data!.passedAssets!.isNotEmpty) {
var isSameCode = true;
if (model.data!.passedAssets!.length > 1) {
var code = model.data!.passedAssets![0].productCode ?? "";
for (int i = 1; i < model.data!.passedAssets!.length; i++) {
if (model.data!.passedAssets![i].productCode != code) {
isSameCode = false;
break;
}
}
}
// if (pageNo == 1) {
if (model.data!.passedAssets!.length == 1 || isSameCode) {
Helper.close();
if (currentScan == ScanType.sellThru) {
for (var element in productDataScannedList) {
if (element.productCode ==
model.data!.passedAssets![0].productCode) {
isValidated = true;
break;
}
}
if (isValidated) {
if (cartId.isNotEmpty) {
await callUpdateCartApi(serialNum, serialStartRange,
serialEndRange, model.data!.passedAssets![0].productCode);
} else {
await callAddToCartApi(serialNum, serialStartRange,
serialEndRange, model.data!.passedAssets![0].productCode);
}
} else {
Future.delayed(Durations.medium4, () async {
Helper.messageDialog(
Get.context!,
localization.translate("assetNotMatchTitle"),
localization.translate("assetNotMatchMsg"),
isDismissible: false,
onTap: () {
isScanning.value = false;
Helper.close();
},
);
});
}
} else {
if (cartId.isNotEmpty) {
await callUpdateCartApi(serialNum, serialStartRange,
serialEndRange, model.data!.passedAssets![0].productCode);
} else {
await callAddToCartApi(serialNum, serialStartRange,
serialEndRange, model.data!.passedAssets![0].productCode);
}
}
isValidated = false;
} else {
Helper.close();
passedAssets.addAll(model.data!.passedAssets!);
// 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"),
isDismissible: false,
onTap: () {
isScanning.value = false;
Helper.close();
},
);
}
} else {
Helper.close();
if (model.errors != null) {
Helper.messageDialog(
Get.context!,
model.errors![0].errorCode ?? "Try again!!",
model.errors![0].errorDescription ?? "Something went wrong",
isDismissible: false,
onTap: () {
isScanning.value = false;
Helper.close();
},
);
}
}
} catch (err, stacktrace) {
isLoadingAssets.value = false;
Helper.close();
ConditionalLogs().customLog("$err");
ConditionalLogs().customLog("$stacktrace");
Helper.messageDialog(
Get.context!,
localization.translate("tryAgain"),
localization.translate("technicalErrorMsg"),
isDismissible: false,
onTap: () {
isScanning.value = false;
Helper.close();
},
);
}
}