Compare commits

..

2 Commits

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

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

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

Loading…
Cancel
Save