Compare commits
No commits in common. '7f4a06b0db8693a668a2f3e8e514bbba126d4e84' and 'e714fed62c58abaa9f9a990f291294d284e127ec' have entirely different histories.
7f4a06b0db
...
e714fed62c
@ -1,216 +1,273 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/models/helper_data_models/workorder/work_order_helper_models.dart';
|
||||
import 'package:test_sa/models/new_models/work_order_detail_model.dart';
|
||||
import 'package:test_sa/modules/cm_module/cm_detail_provider.dart';
|
||||
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
||||
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||
import 'package:test_sa/providers/service_request_providers/equipment_status_provider.dart';
|
||||
|
||||
class CostDetailFormScreen extends StatefulWidget {
|
||||
static const String id = "/cost-detail-form-screen";
|
||||
final WorkOrderCostModel? model;
|
||||
final dynamic provider; // CMDetailProvider or PpmProvider
|
||||
bool isEdit = false;
|
||||
|
||||
const CostDetailFormScreen({
|
||||
Key? key,
|
||||
required this.model,
|
||||
required this.provider,
|
||||
}) : super(key: key);
|
||||
CostDetailFormScreen({Key? key, required this.isEdit}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CostDetailFormScreenState createState() => _CostDetailFormScreenState();
|
||||
}
|
||||
|
||||
class _CostDetailFormScreenState extends State<CostDetailFormScreen> {
|
||||
late WorkOrderCostModel _localModel;
|
||||
class _CostDetailFormScreenState extends State<CostDetailFormScreen> with TickerProviderStateMixin {
|
||||
CMDetailProvider? _requestDetailProvider;
|
||||
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_localModel = WorkOrderCostModel(
|
||||
workOrderId: widget.model?.workOrderId,
|
||||
labourCost: widget.model?.labourCost,
|
||||
sparePartCost: widget.model?.sparePartCost,
|
||||
travelCost: widget.model?.travelCost,
|
||||
qAmount: widget.model?.qAmount,
|
||||
prNo: widget.model?.prNo,
|
||||
poNo: widget.model?.poNo,
|
||||
mrNo: widget.model?.mrNo,
|
||||
exchangeCost: widget.model?.exchangeCost,
|
||||
}
|
||||
|
||||
void assignValues() {
|
||||
// ServiceRequestDetailProvider requestDetailProvider = Provider.of<ServiceRequestDetailProvider>(context, listen: false);
|
||||
// _requestDetailProvider = Provider.of<ServiceRequestDetailProvider>(context, listen: false);
|
||||
WorkOrderData currentWorkOrderData = _requestDetailProvider!.currentWorkOrder!.data!;
|
||||
_requestDetailProvider!.workOrderCostModel = WorkOrderCostModel(
|
||||
workOrderId: currentWorkOrderData.requestId,
|
||||
labourCost: currentWorkOrderData.labourCost,
|
||||
sparePartCost: currentWorkOrderData.sparePartCost,
|
||||
travelCost: currentWorkOrderData.travelCost,
|
||||
qAmount: currentWorkOrderData.qAmount,
|
||||
prNo: currentWorkOrderData.prNo,
|
||||
poNo: currentWorkOrderData.poNo,
|
||||
mrNo: currentWorkOrderData.mrNo,
|
||||
exchangeCost: currentWorkOrderData.exchangeCost,
|
||||
);
|
||||
log('Initialized Cost Model: ${_localModel.toJson()}');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_requestDetailProvider == null) {
|
||||
_requestDetailProvider = Provider.of<CMDetailProvider>(context, listen: false);
|
||||
assignValues();
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: const DefaultAppBar(title: "Cost Details"),
|
||||
body: ListenableBuilder(
|
||||
listenable: widget.provider,
|
||||
builder: (context, child) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AppTextFormField(
|
||||
labelText: "Spare Part Cost",
|
||||
backgroundColor: AppColor.neutral100,
|
||||
initialValue: _localModel.sparePartCost?.toString() ?? '0',
|
||||
textAlign: TextAlign.center,
|
||||
enable: false,
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle,
|
||||
textInputType: TextInputType.number,
|
||||
showShadow: false,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: _localModel.labourCost?.toString() ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
labelText: "Labor Cost",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.labourCost = num.tryParse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Travel Cost",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: _localModel.travelCost?.toString() ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.travelCost = num.tryParse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Quot Amount",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: _localModel.qAmount?.toString() ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.qAmount = num.tryParse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "PR No",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: _localModel.prNo ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: TextInputType.text,
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.prNo = value.isEmpty ? null : value;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "PO No",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: _localModel.poNo ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: TextInputType.text,
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.poNo = value.isEmpty ? null : value;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "MR No",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: _localModel.mrNo ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: TextInputType.text,
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.mrNo = value.isEmpty ? null : value;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Exchange Cost",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: _localModel.exchangeCost?.toString() ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
_localModel.exchangeCost = num.tryParse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
).toShadowContainer(context).paddingAll(16),
|
||||
),
|
||||
body: Consumer<CMDetailProvider>(builder: (context, CMDetailProvider requestDetailProvider, child) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AppTextFormField(
|
||||
labelText: "Spare Part Cost",
|
||||
backgroundColor: AppColor.neutral100,
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.sparePartCost?.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
enable: false,
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle,
|
||||
textInputType: TextInputType.number,
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.sparePartCost = num.parse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.labourCost?.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
labelText: "Labor Cost",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.labourCost = num.parse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Travel Cost",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.travelCost?.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.travelCost = num.parse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Quot Amount",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.qAmount?.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.qAmount = num.parse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "PR No",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.prNo,
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.prNo = value;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "PO No",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.poNo,
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.poNo = value;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "MR No",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.mrNo,
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.mrNo = value;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Exchange Cost",
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
initialValue: requestDetailProvider.workOrderCostModel?.exchangeCost != null ? requestDetailProvider.workOrderCostModel?.exchangeCost.toString() : '',
|
||||
textAlign: TextAlign.center,
|
||||
textInputType: const TextInputType.numberWithOptions(decimal: true),
|
||||
showShadow: false,
|
||||
onChange: (value) {
|
||||
requestDetailProvider.workOrderCostModel?.exchangeCost = num.parse(value);
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
).toShadowContainer(context).paddingAll(16),
|
||||
).expanded,
|
||||
FooterActionButton.footerContainer(
|
||||
context: context,
|
||||
child: AppFilledButton(
|
||||
label: "Update Cost Details",
|
||||
buttonColor: AppColor.primary10,
|
||||
onPressed: () async {
|
||||
if (validateForm(requestDetailProvider: requestDetailProvider)) {
|
||||
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||||
await requestDetailProvider.engineerUpdateCost().then((success) {
|
||||
Navigator.pop(context);
|
||||
if (success) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
FooterActionButton.footerContainer(
|
||||
context: context,
|
||||
child: AppFilledButton(
|
||||
label: "Update Cost Details",
|
||||
buttonColor: AppColor.primary10,
|
||||
onPressed: () => _onSubmit(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onSubmit() async {
|
||||
widget.provider.workOrderCostModel = _localModel;
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const AppLazyLoading(),
|
||||
);
|
||||
|
||||
try {
|
||||
final success = await widget.provider.engineerUpdateCost();
|
||||
|
||||
if (mounted) Navigator.pop(context); // Close loading
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) Navigator.pop(context);
|
||||
log('Error updating cost: $e');
|
||||
bool validateForm({required CMDetailProvider requestDetailProvider}) {
|
||||
bool isValid = true;
|
||||
if (!widget.isEdit) {
|
||||
return true;
|
||||
}
|
||||
// if (requestDetailProvider.engineerUpdateWorkOrderHelperModel!.equipmentStatus != null) {
|
||||
// if (requestDetailProvider.engineerUpdateWorkOrderHelperModel!.equipmentStatus!.value == 1 || requestDetailProvider.engineerUpdateWorkOrderHelperModel!.equipmentStatus!.value == 2) {
|
||||
// if (requestDetailProvider.engineerUpdateWorkOrderHelperModel!.returnToService == null) {
|
||||
// Fluttertoast.showToast(msg: "Return to service is required ", toastLength: Toast.LENGTH_LONG);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return isValid;
|
||||
}
|
||||
|
||||
Widget assetStatusWidget({required BuildContext context, required EngineerUpdateWorkOrderHelperModel workOrderData}) {
|
||||
return Consumer<EquipmentStatusProvider>(builder: (cxt, snapshot, _) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
context.translation.assetStatus.bodyText(context).custom(color: AppColor.black20),
|
||||
8.height,
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
children: [
|
||||
for (var element in snapshot.items)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: Radio(
|
||||
value: element,
|
||||
activeColor: Colors.red,
|
||||
fillColor: WidgetStateColor.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) return AppColor.primary10;
|
||||
return AppColor.neutral130;
|
||||
}),
|
||||
groupValue: workOrderData.equipmentStatus,
|
||||
onChanged: (state) {
|
||||
setState(() {
|
||||
workOrderData.equipmentStatus = element;
|
||||
});
|
||||
}),
|
||||
),
|
||||
8.width,
|
||||
Text(element.name ?? '', style: AppTextStyles.tinyFont.copyWith(color: AppColor.neutral120)),
|
||||
],
|
||||
)
|
||||
],
|
||||
).toShimmer(isShow: snapshot.loading, context: context),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,214 +0,0 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||
import 'package:test_sa/controllers/providers/api/ppm_provider.dart';
|
||||
import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/models/enums/user_types.dart';
|
||||
import 'package:test_sa/models/helper_data_models/spare_part/activity_spare_part_model.dart';
|
||||
import 'package:test_sa/models/plan_preventive_visit/plan_preventive_visit_model.dart';
|
||||
import 'package:test_sa/models/service_request/spare_parts.dart';
|
||||
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
||||
import 'package:test_sa/modules/cm_module/views/forms/spare_part/spare_part_request.dart';
|
||||
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||
import 'package:test_sa/views/widgets/images/files_list.dart';
|
||||
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
|
||||
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
|
||||
import 'package:test_sa/views/widgets/requests/request_status.dart';
|
||||
|
||||
class PmActivitiesListView extends StatefulWidget {
|
||||
static const String id = "/activities-list";
|
||||
|
||||
const PmActivitiesListView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_PmActivitiesListViewState createState() {
|
||||
return _PmActivitiesListViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _PmActivitiesListViewState extends State<PmActivitiesListView> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
List<PMSparePartActivityModel> activities = [];
|
||||
|
||||
bool disableNewActivity = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
UserProvider userProvider = Provider.of<UserProvider>(context);
|
||||
return Scaffold(
|
||||
appBar: DefaultAppBar(
|
||||
showHomeActionButton: true,
|
||||
title: context.translation.activities,
|
||||
),
|
||||
body: Consumer<PpmProvider>(builder: (context, PpmProvider pmProvider, child) {
|
||||
activities = pmProvider.planPreventiveVisit?.activities ?? [];
|
||||
if (activities.isNotEmpty && (activities.last.activityStatus!.value == 14 || activities.last.activityStatus!.value == 19)) {
|
||||
disableNewActivity = true;
|
||||
} else {
|
||||
disableNewActivity = false;
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
(activities.isEmpty)
|
||||
? NoDataFound(message: context.translation.noDataFound).center.expanded
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: activities.length,
|
||||
separatorBuilder: (czt, index) => 12.height,
|
||||
itemBuilder: (context, index) {
|
||||
return sparePartActivityCard(pmProvider: pmProvider, userProvider: userProvider, context: context, activity: activities[index]);
|
||||
},
|
||||
).expanded,
|
||||
if (userProvider.user!.type == UsersTypes.engineer &&
|
||||
(pmProvider.planPreventiveVisit?.visitStatus?.value != 5 && pmProvider.planPreventiveVisit?.visitStatus?.value != 3))
|
||||
FooterActionButton.footerContainer(
|
||||
context: context,
|
||||
child: AppFilledButton(
|
||||
label: context.translation.createNewActivity,
|
||||
maxWidth: true,
|
||||
buttonColor: AppColor.primary10,
|
||||
loading: pmProvider.isLoading,
|
||||
disableButton: disableNewActivity,
|
||||
onPressed: () async {
|
||||
final model = SparePartHelperModel(
|
||||
id: 0,
|
||||
pmVisitId: pmProvider.planPreventiveVisit?.id,
|
||||
);
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SparePartRequest(
|
||||
model: model,
|
||||
provider: pmProvider,
|
||||
fromCm: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
))
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget sparePartActivityCard({required PpmProvider pmProvider, required UserProvider userProvider, required BuildContext context, required PMSparePartActivityModel activity}) {
|
||||
bool showActionButtons = userProvider.user!.userID == pmProvider.planPreventiveVisit?.assignedEmployee?.userId &&
|
||||
userProvider.user!.type == UsersTypes.engineer &&
|
||||
pmProvider.planPreventiveVisit?.visitStatus?.value != 5 &&
|
||||
pmProvider.planPreventiveVisit?.visitStatus?.value != 3;
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
StatusLabel(
|
||||
label: activity.activityStatus?.name,
|
||||
textColor: AppColor.white10,
|
||||
backgroundColor: AppColor.primary10,
|
||||
),
|
||||
if (showActionButtons)
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
"edit_icon".toSvgAsset(height: 24, width: 24, color: AppColor.icon2Color(context)).onPress(() {
|
||||
editSparePartRequest(context: context, pmProvider: pmProvider, activity: activity);
|
||||
}),
|
||||
12.width,
|
||||
"delete_icon".toSvgAsset(height: 24, width: 24).onPress(() async {
|
||||
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||||
int status = await pmProvider.deleteActivitySparePart(id: activity.id!);
|
||||
if (status == 200) {
|
||||
await pmProvider.getPlanPreventiveVisitById((int.tryParse(pmProvider.planPreventiveVisit?.id ?? '')) as int);
|
||||
Navigator.pop(context);
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
6.height,
|
||||
InfoTextWidget(
|
||||
label: context.translation.partName,
|
||||
value: activity.partCatalogItem?.partName,
|
||||
),
|
||||
InfoTextWidget(
|
||||
label: context.translation.partNo,
|
||||
value: activity.partCatalogItem?.partNumber,
|
||||
),
|
||||
InfoTextWidget(
|
||||
label: context.translation.oracleCode,
|
||||
value: activity.partCatalogItem?.oracleCode,
|
||||
),
|
||||
if (activity.comment?.isNotEmpty ?? false) ...[
|
||||
const Divider().defaultStyle(context),
|
||||
InfoTextLabelWidget(label: activity.comment ?? ""),
|
||||
],
|
||||
if (activity.activitySparePartPPMAttachments.isNotEmpty) ...[
|
||||
const Divider().defaultStyle(context),
|
||||
FilesList(images: activity.activitySparePartPPMAttachments.map((toElement) => URLs.getFileUrl(toElement.name??'')??'').toList()),
|
||||
],
|
||||
],
|
||||
).toShadowContainer(context, showShadow: false).onPress(() {
|
||||
if (showActionButtons) return;
|
||||
if (pmProvider.isReadOnlyRequest) {
|
||||
editSparePartRequest(context: context, pmProvider: pmProvider, activity: activity);
|
||||
} else if (userProvider.user!.userID == pmProvider.planPreventiveVisit?.assignedEmployee?.userId) {
|
||||
pmProvider.isReadOnlyRequest = true;
|
||||
editSparePartRequest(context: context, pmProvider: pmProvider, activity: activity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void editSparePartRequest({required BuildContext context, required PpmProvider pmProvider, required PMSparePartActivityModel activity}) async {
|
||||
final model = SparePartHelperModel(
|
||||
id: activity.id,
|
||||
pmVisitId: pmProvider.planPreventiveVisit?.id,
|
||||
comment: activity.comment,
|
||||
sparePartAttachments: activity.activitySparePartPPMAttachments,
|
||||
activityStatus: activity.activityStatus,
|
||||
sparePart: SparePart(
|
||||
id: activity.partCatalogItem?.id,
|
||||
partName: activity.partCatalogItem?.partName,
|
||||
partNo: activity.partCatalogItem?.partNumber,
|
||||
oracleCode: activity.partCatalogItem?.oracleCode,
|
||||
),
|
||||
quantity: activity.quantity,
|
||||
installQty: activity.installQty,
|
||||
returnQty: activity.returnQty,
|
||||
activityStatusId: activity.activityStatus?.id,
|
||||
);
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => SparePartRequest(
|
||||
model: model,
|
||||
provider: pmProvider,
|
||||
fromCm: false, // This is PM, not CM
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue