dashboard apis added.
parent
8a097a1ed6
commit
ff80897a3c
@ -1,47 +1,213 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||
import 'package:test_sa/models/all_requests_and_count_model.dart';
|
||||
|
||||
class AllRequestsProvider extends ChangeNotifier {
|
||||
bool isLoading;
|
||||
|
||||
// Future<int> getAllRequests() async {
|
||||
// if (isLoading == true) return -2;
|
||||
// isLoading = true;
|
||||
// if (serviceRequests?.isEmpty ?? false) notifyListeners();
|
||||
// Response response;
|
||||
// try {
|
||||
// Map<String, dynamic> body = {};
|
||||
// body.addAll(search.toMap());
|
||||
// body["pageNumber"] = (serviceRequests?.length ?? 0) ~/ pageItemNumber + 1;
|
||||
// body["pageSize"] = pageItemNumber;
|
||||
//
|
||||
// response = await ApiManager.instance.post(
|
||||
// URLs.getServiceRequests,
|
||||
// body: body,
|
||||
// );
|
||||
//
|
||||
// stateCode = response.statusCode;
|
||||
// if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
// // client's request was successfully received
|
||||
// List requestsListJson = json.decode(response.body)["data"];
|
||||
// List<ServiceRequest> serviceRequestsPage = requestsListJson.map((request) => ServiceRequest.fromJson(request)).toList();
|
||||
// serviceRequests ??= [];
|
||||
// serviceRequests.addAll(serviceRequestsPage);
|
||||
// notifyListeners();
|
||||
// if (serviceRequestsPage.length == pageItemNumber) {
|
||||
// nextPage = true;
|
||||
// } else {
|
||||
// nextPage = false;
|
||||
// }
|
||||
// }
|
||||
// isLoading = false;
|
||||
// notifyListeners();
|
||||
// return response.statusCode;
|
||||
// } catch (error) {
|
||||
// isLoading = false;
|
||||
// stateCode = -1;
|
||||
// notifyListeners();
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
bool isAllLoading = false;
|
||||
bool isOpenLoading = false;
|
||||
bool isInProgressLoading = false;
|
||||
bool isCloseLoading = false;
|
||||
bool isOverdueLoading = false;
|
||||
bool isHighPriorityLoading = false;
|
||||
|
||||
int stateCode;
|
||||
|
||||
AllRequestsAndCount allRequestsAndCount;
|
||||
AllRequestsAndCount openRequests;
|
||||
AllRequestsAndCount inProgressRequests;
|
||||
AllRequestsAndCount closeRequests;
|
||||
AllRequestsAndCount overdueRequests;
|
||||
AllRequestsAndCount highPriorityRequests;
|
||||
|
||||
void getRequests() {
|
||||
getHighPriorityRequests();
|
||||
getOverdueRequests();
|
||||
getOpenRequests();
|
||||
getInProgressRequests();
|
||||
getCloseRequests();
|
||||
}
|
||||
|
||||
Future<int> getAllRequests() async {
|
||||
if (isAllLoading == true) return -2;
|
||||
isAllLoading = true;
|
||||
if (allRequestsAndCount == null) notifyListeners();
|
||||
Response response;
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"typeTransaction": [1, 2, 3, 4],
|
||||
"statusTransaction": [1, 2, 3],
|
||||
"priority": [0, 1],
|
||||
"displayData": [1]
|
||||
};
|
||||
response = await ApiManager.instance.post(URLs.getAllRequestsAndCount, body: body);
|
||||
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
allRequestsAndCount = AllRequestsAndCount.fromJson(json.decode(response.body)["data"]);
|
||||
notifyListeners();
|
||||
}
|
||||
isAllLoading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
isAllLoading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> getHighPriorityRequests() async {
|
||||
if (isHighPriorityLoading == true) return -2;
|
||||
isHighPriorityLoading = true;
|
||||
if (highPriorityRequests == null) notifyListeners();
|
||||
Response response;
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"typeTransaction": [1, 2, 3, 4],
|
||||
"statusTransaction": [1, 2, 3],
|
||||
"priority": [0],
|
||||
"displayData": []
|
||||
};
|
||||
response = await ApiManager.instance.post(URLs.getAllRequestsAndCount, body: body);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
highPriorityRequests = AllRequestsAndCount.fromJson(json.decode(response.body)["data"]);
|
||||
print("highPriorityRequests:${highPriorityRequests.total}");
|
||||
notifyListeners();
|
||||
}
|
||||
isHighPriorityLoading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
isHighPriorityLoading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> getOverdueRequests() async {
|
||||
if (isOverdueLoading == true) return -2;
|
||||
isOverdueLoading = true;
|
||||
if (overdueRequests == null) notifyListeners();
|
||||
Response response;
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"typeTransaction": [1, 2, 3, 4],
|
||||
"statusTransaction": [1, 2, 3],
|
||||
"priority": [],
|
||||
"displayData": [1]
|
||||
};
|
||||
response = await ApiManager.instance.post(URLs.getAllRequestsAndCount, body: body);
|
||||
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
overdueRequests = AllRequestsAndCount.fromJson(json.decode(response.body)["data"]);
|
||||
notifyListeners();
|
||||
}
|
||||
isOverdueLoading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
isOverdueLoading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> getOpenRequests() async {
|
||||
if (isOpenLoading == true) return -2;
|
||||
isOpenLoading = true;
|
||||
if (openRequests == null) notifyListeners();
|
||||
Response response;
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"typeTransaction": [1, 2, 3, 4],
|
||||
"statusTransaction": [1],
|
||||
"priority": [],
|
||||
"displayData": []
|
||||
};
|
||||
response = await ApiManager.instance.post(URLs.getAllRequestsAndCount, body: body);
|
||||
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
openRequests = AllRequestsAndCount.fromJson(json.decode(response.body)["data"]);
|
||||
notifyListeners();
|
||||
}
|
||||
isOpenLoading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
isOpenLoading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> getInProgressRequests() async {
|
||||
if (isInProgressLoading == true) return -2;
|
||||
isInProgressLoading = true;
|
||||
if (inProgressRequests == null) notifyListeners();
|
||||
Response response;
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"typeTransaction": [1, 2, 3, 4],
|
||||
"statusTransaction": [2],
|
||||
"priority": [],
|
||||
"displayData": []
|
||||
};
|
||||
response = await ApiManager.instance.post(URLs.getAllRequestsAndCount, body: body);
|
||||
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
inProgressRequests = AllRequestsAndCount.fromJson(json.decode(response.body)["data"]);
|
||||
notifyListeners();
|
||||
}
|
||||
isInProgressLoading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
isInProgressLoading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> getCloseRequests() async {
|
||||
if (isCloseLoading == true) return -2;
|
||||
isCloseLoading = true;
|
||||
if (closeRequests == null) notifyListeners();
|
||||
Response response;
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"typeTransaction": [1, 2, 3, 4],
|
||||
"statusTransaction": [3],
|
||||
"priority": [],
|
||||
"displayData": []
|
||||
};
|
||||
response = await ApiManager.instance.post(URLs.getAllRequestsAndCount, body: body);
|
||||
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
closeRequests = AllRequestsAndCount.fromJson(json.decode(response.body)["data"]);
|
||||
notifyListeners();
|
||||
}
|
||||
isCloseLoading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
isCloseLoading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,157 @@
|
||||
class AllRequestsAndCount {
|
||||
CountServiceRequest countServiceRequest;
|
||||
CountServiceRequest countGasRefill;
|
||||
CountServiceRequest countAssetTransfer;
|
||||
CountServiceRequest countPPM;
|
||||
DetailsStatusTotal detailsStatusTotal;
|
||||
CountServiceRequest total;
|
||||
List<RequestsDetails> requestsDetails;
|
||||
|
||||
AllRequestsAndCount({this.countServiceRequest, this.countGasRefill, this.countAssetTransfer, this.countPPM, this.detailsStatusTotal, this.total, this.requestsDetails});
|
||||
|
||||
AllRequestsAndCount.fromJson(Map<String, dynamic> json) {
|
||||
countServiceRequest = json['countServiceRequest'] != null ? new CountServiceRequest.fromJson(json['countServiceRequest']) : null;
|
||||
countGasRefill = json['countGasRefill'] != null ? new CountServiceRequest.fromJson(json['countGasRefill']) : null;
|
||||
countAssetTransfer = json['countAssetTransfer'] != null ? new CountServiceRequest.fromJson(json['countAssetTransfer']) : null;
|
||||
countPPM = json['countPPM'] != null ? new CountServiceRequest.fromJson(json['countPPM']) : null;
|
||||
detailsStatusTotal = json['detailsStatusTotal'] != null ? new DetailsStatusTotal.fromJson(json['detailsStatusTotal']) : null;
|
||||
total = json['total'] != null ? new CountServiceRequest.fromJson(json['total']) : null;
|
||||
if (json['requestsDetails'] != null) {
|
||||
requestsDetails = <RequestsDetails>[];
|
||||
json['requestsDetails'].forEach((v) {
|
||||
requestsDetails.add(new RequestsDetails.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
if (this.countServiceRequest != null) {
|
||||
data['countServiceRequest'] = this.countServiceRequest.toJson();
|
||||
}
|
||||
|
||||
if (this.countGasRefill != null) {
|
||||
data['countGasRefill'] = this.countGasRefill.toJson();
|
||||
}
|
||||
if (this.countAssetTransfer != null) {
|
||||
data['countAssetTransfer'] = this.countAssetTransfer.toJson();
|
||||
}
|
||||
if (this.countPPM != null) {
|
||||
data['countPPM'] = this.countPPM.toJson();
|
||||
}
|
||||
|
||||
if (this.detailsStatusTotal != null) {
|
||||
data['detailsStatusTotal'] = this.detailsStatusTotal.toJson();
|
||||
}
|
||||
if (this.total != null) {
|
||||
data['total'] = this.total.toJson();
|
||||
}
|
||||
if (this.requestsDetails != null) {
|
||||
data['requestsDetails'] = this.requestsDetails.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class CountServiceRequest {
|
||||
int count;
|
||||
|
||||
CountServiceRequest({this.count});
|
||||
|
||||
CountServiceRequest.fromJson(Map<String, dynamic> json) {
|
||||
count = json['count'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['count'] = this.count;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class DetailsStatusTotal {
|
||||
int open;
|
||||
int inProgress;
|
||||
int closed;
|
||||
|
||||
DetailsStatusTotal({this.open, this.inProgress, this.closed});
|
||||
|
||||
DetailsStatusTotal.fromJson(Map<String, dynamic> json) {
|
||||
open = json['open'];
|
||||
inProgress = json['inProgress'];
|
||||
closed = json['closed'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['open'] = this.open;
|
||||
data['inProgress'] = this.inProgress;
|
||||
data['closed'] = this.closed;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class RequestsDetails {
|
||||
String nameOfType;
|
||||
String status;
|
||||
String statusReceiver;
|
||||
String assetName;
|
||||
String assetNo;
|
||||
String requestType;
|
||||
String requestNo;
|
||||
String gasType;
|
||||
String site;
|
||||
String assetTransferFrom;
|
||||
String assetTransferTo;
|
||||
String assetSN;
|
||||
String code;
|
||||
|
||||
RequestsDetails(
|
||||
{this.nameOfType,
|
||||
this.status,
|
||||
this.statusReceiver,
|
||||
this.assetName,
|
||||
this.assetNo,
|
||||
this.requestType,
|
||||
this.requestNo,
|
||||
this.gasType,
|
||||
this.site,
|
||||
this.assetTransferFrom,
|
||||
this.assetTransferTo,
|
||||
this.assetSN,
|
||||
this.code});
|
||||
|
||||
RequestsDetails.fromJson(Map<String, dynamic> json) {
|
||||
nameOfType = json['nameOfType'];
|
||||
status = json['status'];
|
||||
statusReceiver = json['statusReceiver'];
|
||||
assetName = json['assetName'];
|
||||
assetNo = json['assetNo'];
|
||||
requestType = json['requestType'];
|
||||
requestNo = json['requestNo'];
|
||||
gasType = json['gasType'];
|
||||
site = json['site'];
|
||||
assetTransferFrom = json['assetTransferFrom'];
|
||||
assetTransferTo = json['assetTransferTo'];
|
||||
assetSN = json['assetSN'];
|
||||
code = json['code'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['nameOfType'] = this.nameOfType;
|
||||
data['status'] = this.status;
|
||||
data['statusReceiver'] = this.statusReceiver;
|
||||
data['assetName'] = this.assetName;
|
||||
data['assetNo'] = this.assetNo;
|
||||
data['requestType'] = this.requestType;
|
||||
data['requestNo'] = this.requestNo;
|
||||
data['gasType'] = this.gasType;
|
||||
data['site'] = this.site;
|
||||
data['assetTransferFrom'] = this.assetTransferFrom;
|
||||
data['assetTransferTo'] = this.assetTransferTo;
|
||||
data['assetSN'] = this.assetSN;
|
||||
data['code'] = this.code;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue