improvements-cont

main_production_spare_part
Sikander Saleem 12 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;
@ -201,9 +202,7 @@ class PpmProvider extends ChangeNotifier {
// 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;
@ -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;
@ -478,9 +477,7 @@ class PpmProvider extends ChangeNotifier {
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;

Loading…
Cancel
Save