getStockHistory method
dynamic
getStockHistory(})
Implementation
getStockHistory(
BuildContext context,
String? date,
String partnerId, {
String? state,
String? fromDate,
String? toDate,
int offset = 0,
}) async {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (offset == 0) {
Helper.progressDialog(context, "Please wait..");
}
});
// printLogs(dio);
var query = [
{
"action": "null",
"query": "category",
"value": "sell-thru,spot-sell-thru"
},
{
"action": "and",
"query": "relatedParty.role",
"value": "ToDistributorId"
},
{
"action": "and",
"query": "relatedParty.name",
"value": storage.read("PARTNER_ID_LOGIN")
// "value": partnerId,
},
{
"action": "and",
"query": "state",
"value": state ?? "ACKNOWLEDGED,INPROGRESS,COMPLETED"
}
];
if (fromDate != null && toDate != null) {
query.add({"query": "fromOrderDate", "value": fromDate, "action": "and"});
query.add({"query": "toOrderDate", "value": toDate, "action": "and"});
}
dio
.post(
'${ApiConstant.romBaseUrl}rom-core-svc/tmf-api/productOrderingManagement/v4/elastic/productOrder',
queryParameters: {
'fieldName': 'orderDate',
'sortBy': 'DESC',
'offset': offset,
'limit': 50,
},
data: json.encode({"hsQuery": query}),
options: Options(
headers: {
'X-User-Id': storage.read("XUSER_ID"),
'X-User-Name': storage.read("XUSER_ID")
},
),
)
.then((response) {
if (offset == 0) {
Get.back();
}
if (response.data != null) {
// 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;
print('getStockHistoryList1-->${getStockHistoryList1.toString()}');
}
}, onError: (error) {
print(error.toString());
if (offset == 0) {
Get.back();
}
Helper.messageDialog(Get.context!, "Try Again!!", error.toString());
});
}