grnSubmit method
void
grnSubmit()
Implementation
void grnSubmit(
String orderId,
String transferOrderId,
String id,
List<ProductContentModel> products,
String status,
bool isAll,
String? rejectReason,
String? grRejectReasonTypeasync,
) async {
try {
Helper.progressDialog(Get.context!, "");
var object = [];
products.forEach((product) {
product.iccidList?.forEach((element) {
object.add({
"productCode": product.productCode,
"serialNumber": element.iccid,
});
});
});
var body = {
"id": id,
"dealerId": storage.read("PARTNER_ID_LOGIN"),
"content": object,
"all": isAll,
"rejectReason": rejectReason,
"grRejectReasonType": grRejectReasonTypeasync
};
GrnSubmitModel model = await ApiClient(
baseUrl: ApiConstant.posBFF,
receiveTimeout: Constants.defaultSubmitTimeout,
connectTimeout: Constants.defaultSubmitTimeout,
).grnSubmit(
body: json.encode(body),
transferOrderId: transferOrderId,
status: status,
xUserName: storage.read("XUSER_ID"),
xUserId: storage.read("XUSER_ID"),
);
if (model.status == "POS200") {
Get.back();
Get.to(
() => GrnSuccess(
timeStamp: model.timeStamp!,
scanInOrderId: orderId,
isReject: (rejectReason != null && rejectReason.isNotEmpty) ||
(grRejectReasonTypeasync != null &&
grRejectReasonTypeasync.isNotEmpty),
),
);
} else {
Get.back();
if (model.errors != null) {
Helper.messageDialog(
Get.context!,
model.errors![0].code ?? "Try again!!",
model.errors![0].localeMessage ?? "Something went wrong");
}
}
} catch (err, stacktrace) {
Get.back();
log(err.toString());
print(stacktrace);
if (err.runtimeType == DioException) {
var response = err as DioException;
if (response.response?.statusCode == 504) {
print("error grnSubmit: ${response.response?.statusCode}");
var transactionId = "-";
DateTime now = DateTime.now();
// Convert current time to milliseconds since epoch
double currentTimeStamp = now.millisecondsSinceEpoch / 1000;
// Use the existing method to format the date and time
var date = Helper.fromTimeStamptoDateTime(currentTimeStamp);
Get.to(
() => GrnSuccess(
timeStamp: currentTimeStamp,
scanInOrderId: orderId,
isReject: (rejectReason != null && rejectReason.isNotEmpty) ||
(grRejectReasonTypeasync != null &&
grRejectReasonTypeasync.isNotEmpty),
),
);
// Handle the 504 status code here
// Helper.messageDialog(Get.context!, "Gateway Timeout",
// "The server took too long to respond. Please try again later.");
} else {
print("error grnSubmit: ${response.response?.statusCode}");
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
}
} else {
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
}
}
}