|
|
|
|
@ -72,6 +72,7 @@ class PpmProvider extends ChangeNotifier {
|
|
|
|
|
nextPage = true;
|
|
|
|
|
stateCode = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<StoreAvailability> _storeAvailability = [];
|
|
|
|
|
|
|
|
|
|
List<StoreAvailability> get storeAvailability => _storeAvailability;
|
|
|
|
|
@ -191,24 +192,22 @@ class PpmProvider extends ChangeNotifier {
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
ppmPlanAttachments = [];
|
|
|
|
|
planPreventiveVisit = PlanPreventiveVisit.fromJson(json.decode(response.body)["data"]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set isReadOnly based on visit status (1 or 3 means closed/completed)
|
|
|
|
|
if (planPreventiveVisit?.visitStatus?.value! == 1 || planPreventiveVisit?.visitStatus?.value == 3) {
|
|
|
|
|
isReadOnly = true;
|
|
|
|
|
} else {
|
|
|
|
|
isReadOnly = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set isReadOnlyRequest based on visit status - same logic as CMDetailProvider
|
|
|
|
|
//Need to confirm this with backend Status values: 3 = Closed, 5 = Completed, 6 = Cancelled (adjust based on your PM status values)
|
|
|
|
|
if (planPreventiveVisit?.visitStatus?.value == 3 ||
|
|
|
|
|
planPreventiveVisit?.visitStatus?.value == 5 ||
|
|
|
|
|
planPreventiveVisit?.visitStatus?.value == 6) {
|
|
|
|
|
if (planPreventiveVisit?.visitStatus?.value == 3 || planPreventiveVisit?.visitStatus?.value == 5 || planPreventiveVisit?.visitStatus?.value == 6) {
|
|
|
|
|
isReadOnlyRequest = true;
|
|
|
|
|
} else {
|
|
|
|
|
isReadOnlyRequest = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return planPreventiveVisit;
|
|
|
|
|
@ -428,22 +427,23 @@ class PpmProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> updateActivitySparePart() async {
|
|
|
|
|
isLoading = true;
|
|
|
|
|
Future<String> updateActivitySparePart(BuildContext context) async {
|
|
|
|
|
Response response;
|
|
|
|
|
try {
|
|
|
|
|
response = await ApiManager.instance.post(URLs.updatePmActivitySparePart, body: sparePartHelperModel!.toPMJson());
|
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
|
isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (stateCode == 200) {
|
|
|
|
|
response = await ApiManager.instance.post(URLs.updatePmActivitySparePart, body: sparePartHelperModel!.toPMJson(), showToast: false);
|
|
|
|
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
final responseBody = jsonDecode(response.body);
|
|
|
|
|
if (responseBody is Map<String, dynamic>) {
|
|
|
|
|
final message = responseBody["message"]; // Reuse parsed body
|
|
|
|
|
if (message != null && message.toString().isNotEmpty) {
|
|
|
|
|
Fluttertoast.showToast(msg: message, toastLength: Toast.LENGTH_LONG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
isLoading = false;
|
|
|
|
|
stateCode = -1;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -454,8 +454,7 @@ class PpmProvider extends ChangeNotifier {
|
|
|
|
|
try {
|
|
|
|
|
final response = await ApiManager.instance.delete('${URLs.deletePmActivitySparePart}?activitySparePartPPMId=$id', body: {});
|
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
}
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {}
|
|
|
|
|
isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return response.statusCode;
|
|
|
|
|
@ -476,16 +475,14 @@ class PpmProvider extends ChangeNotifier {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (stateCode == 200) {
|
|
|
|
|
planPreventiveVisit = PlanPreventiveVisit.fromJson(json.decode(response.body)["data"]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update isReadOnlyRequest after fetching updated data
|
|
|
|
|
if (planPreventiveVisit?.visitStatus?.value == 3 ||
|
|
|
|
|
planPreventiveVisit?.visitStatus?.value == 5 ||
|
|
|
|
|
planPreventiveVisit?.visitStatus?.value == 6) {
|
|
|
|
|
if (planPreventiveVisit?.visitStatus?.value == 3 || planPreventiveVisit?.visitStatus?.value == 5 || planPreventiveVisit?.visitStatus?.value == 6) {
|
|
|
|
|
isReadOnlyRequest = true;
|
|
|
|
|
} else {
|
|
|
|
|
isReadOnlyRequest = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|