Compare commits

...

2 Commits

@ -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;
}

@ -377,7 +377,7 @@ class _SparePartRequestState extends State<SparePartRequest> {
if (mounted) Navigator.pop(context); // Close form
if (model?.id == 0&&widget.fromCm) {
if (model?.id == 0 && widget.fromCm) {
ServiceRequestBottomSheet.addAnotherSpareRequestBottomSheet(context: context, fromCm: widget.fromCm);
const SizedBox().flushBar(
context: context,
@ -403,35 +403,37 @@ class PartDetailBottomSheetSheet extends StatelessWidget {
return SizedBox(
height: SizeConfig.screenHeight! / 2.2,
width: SizeConfig.screenWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
12.height,
'Parts Availability'.heading4(context),
Expanded(
child: ListenableBuilder(
listenable: provider,
builder: (context, _) {
return provider.isLoading
? CircularProgressIndicator(
color: AppColor.loadingColor(context),
).center
: provider.storeAvailability.isEmpty
? const NoDataFound().center
: ListView.separated(
padding: const EdgeInsets.only(top: 12),
itemCount: provider.storeAvailability.length,
separatorBuilder: (czt, index) => 12.height,
itemBuilder: (context, index) {
StoreAvailability model = provider.storeAvailability[index];
return _partAvailableQuantityCard(context: context, model: model);
},
);
},
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
12.height,
'Parts Availability'.heading4(context),
Expanded(
child: ListenableBuilder(
listenable: provider,
builder: (context, _) {
return provider.isLoading
? CircularProgressIndicator(
color: AppColor.loadingColor(context),
).center
: provider.storeAvailability.isEmpty
? const NoDataFound().center
: ListView.separated(
padding: const EdgeInsets.only(top: 12,bottom: 12),
itemCount: provider.storeAvailability.length,
separatorBuilder: (czt, index) => 12.height,
itemBuilder: (context, index) {
StoreAvailability model = provider.storeAvailability[index];
return _partAvailableQuantityCard(context: context, model: model);
},
);
},
),
),
),
],
],
),
),
);
}

@ -287,7 +287,7 @@ class _UpdatePpmState extends State<UpdatePpm> with TickerProviderStateMixin {
onPressed: () async {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const PmActivitiesListView()));
},
buttonColor: AppColor.neutral50,
buttonColor: context.isDark ? AppColor.primary10 : AppColor.neutral50,
label: "View Spare Parts",
),
],

Loading…
Cancel
Save