getStockHistory method
dynamic
getStockHistory(})
Implementation
getStockHistory(
BuildContext context,
String? date,
String partnerId, {
String? state,
String? fromDate,
String? toDate,
int offset = 0,
String? orderId,
}) async {
Helper.hideKeyboard();
String requestTime = DateTime.now().toString();
try {
if (offset == 0) {
Helper.progressDialog(context, "Please wait..");
}
// printLogs(dio);
var query = [
{
"action": null,
"query": "category",
"value": "sell-thru,spot-sell-thru"
},
{
"action": null,
"query": "relatedParty",
"value": "ToDistributorId:${SecureStorageService.readSecureData(
SecureStorageService.partnerIdLogin,
) ?? ""}"
},
{
"action": null,
"query": "state",
"value": state ?? "ACKNOWLEDGED,INPROGRESS,COMPLETED,FAILED"
}
];
if (fromDate != null && toDate != null) {
query
.add({"query": "fromOrderDate", "value": fromDate, "action": null});
query.add({"query": "toOrderDate", "value": toDate, "action": null});
}
if (orderId != null && orderId.isNotEmpty) {
query.add({"query": "id", "value": orderId, "action": null});
}
dio
.post(
'${ApiConstant.romBaseUrl}rom-core-svc/tmf-api/productOrderingManagement/v4/elastic/productOrder',
queryParameters: {
'fieldName': 'orderDate',
'sortBy': 'DESC',
'offset': offset,
'limit': 10,
},
data: json.encode({"hsQuery": query}),
options: Options(
headers: {
'x-request-txn-id': UDID.uDID,
'X-User-Id': SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
'X-User-Name': SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
'Authorization': "Bearer ${SecureStorageService.readSecureData(
SecureStorageService.accessToken,
)}",
},
),
)
.then((response) {
UDID.setTraceId(response.headers.map[Constants.traceIdKey]?[0] ?? "");
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint:
"rom-core-svc/tmf-api/productOrderingManagement/v4/elastic/productOrder",
responseDate: DateTime.now().toString(),
screenName: "orderStockHistory",
requestDate: requestTime,
);
if (response.data != null &&
response.data.toString().trim().isNotEmpty) {
// print('getStockHistory${response.data}');
List<dynamic> jsonList = response.data;
List<StockHistoryResponse> myModels = jsonList
.map((json) => StockHistoryResponse.fromJson(json))
.toList();
if (offset == 0) {
getStockHistoryList1.value = myModels;
} else {
getStockHistoryList1.addAll(myModels);
}
isLoadingMore.value = false;
ConditionalLogs().customLog('getStockHistoryList1-->');
// for (var _ in getStockHistoryList1) {
// debugPrint(_.toString());
// }
}
if (offset == 0) {
Get.back();
}
}).catchError((error) {
ConditionalLogs().customLog("$error");
if (offset == 0) {
Get.back();
}
if (error is DioException) {
UDID.setTraceId(
error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
endPoint:
"rom-core-svc/tmf-api/productOrderingManagement/v4/elastic/productOrder",
requestDate: requestTime,
responseDate: DateTime.now().toString(),
screenName: "orderStockHistory",
error: error,
);
}
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
});
} catch (e) {
if (offset == 0) {
Get.back();
}
if (e is DioException) {
UDID.setTraceId(
e.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
);
Helper.logEvent(
"ERROR_EVENT",
failure: true,
endPoint:
"rom-core-svc/tmf-api/productOrderingManagement/v4/elastic/productOrder",
requestDate: requestTime,
responseDate: DateTime.now().toString(),
screenName: "orderStockHistory",
error: e,
);
}
}
}