improvements-cont

main_production_spare_part
Sikander Saleem 10 hours ago
parent d63f7d8939
commit 30a69b1ca6

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

Loading…
Cancel
Save