diff --git a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart index e3bade3b..eee409d8 100644 --- a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart +++ b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart @@ -113,6 +113,7 @@ class _CreateSubWorkOrderPageState extends State { initialSupplier = subWoDetails.supplier; _serviceReport.faultDescription = subWoDetails.faultDescription; _subWorkOrders.visitDate = subWoDetails.visitDate; + _subWorkOrders.sparePartsWorkOrders = subWoDetails.sparePartsWorkOrders; } await assetTypesProvider.getTypes(); _subWorkOrders?.assetType = assetTypesProvider.statuses?.firstWhere( @@ -149,12 +150,13 @@ class _CreateSubWorkOrderPageState extends State { // _subWorkOrders.assistantEmployees = [widget.workOrder.assistantEmployees?.first?.copyWith(id: 0)]; _subWorkOrders.assistantEmployees = [AssistantEmployees(id: 0, user: AssignedEmployee(id: user.userID, name: user.username))]; } else {} - print("isCurrentUserIsAssistantEmp:$isCurrentUserIsAssistantEmp:${widget.workOrder.assistantEmployees?.length}"); if (_callRequestForWorkOrder == null) { _partsProvider = Provider.of(context); getAssetType(); } + bool disablePart = _subWorkOrders.calllastSituation?.value == 12; + return Scaffold( appBar: DefaultAppBar(title: context.translation.createSubWorkOrder), body: SafeArea( @@ -421,6 +423,7 @@ class _CreateSubWorkOrderPageState extends State { PartNoButton( controller: _partQtyController, spareParts: _spareParts, + disablePartEdit: disablePart, initialList: _subWorkOrders.sparePartsWorkOrders, onChange: (parts) { _subWorkOrders.sparePartsWorkOrders = parts; diff --git a/lib/views/pages/user/requests/work_order/part_no_button.dart b/lib/views/pages/user/requests/work_order/part_no_button.dart index 9d8dfe67..d06ed373 100644 --- a/lib/views/pages/user/requests/work_order/part_no_button.dart +++ b/lib/views/pages/user/requests/work_order/part_no_button.dart @@ -16,9 +16,10 @@ class PartNoButton extends StatefulWidget { final List spareParts; final List initialList; final TextEditingController controller; + final bool disablePartEdit; final Function(List sparePart) onChange; - const PartNoButton({@required this.spareParts, @required this.controller, this.initialList, this.onChange, Key key}) : super(key: key); + const PartNoButton({@required this.spareParts, @required this.controller, this.initialList, this.onChange, this.disablePartEdit = false, Key key}) : super(key: key); @override State createState() => _PartNoButtonState(); @@ -93,17 +94,19 @@ class _PartNoButtonState extends State { label: context.translation.add, maxWidth: true, textColor: Colors.white, - buttonColor: AppColor.neutral50, - onPressed: () { - if (current != null && _formKey.currentState.validate()) { - _formKey.currentState.save(); - list.add(current); - if (widget.onChange != null) widget.onChange(list); - current = SparePartsWorkOrders(); - widget.controller.text = ""; - setState(() {}); - } - }, + buttonColor: widget.disablePartEdit ? AppColor.neutral20 : AppColor.neutral50, + onPressed: widget.disablePartEdit + ? null + : () { + if (current != null && _formKey.currentState.validate()) { + _formKey.currentState.save(); + list.add(current); + if (widget.onChange != null) widget.onChange(list); + current = SparePartsWorkOrders(); + widget.controller.text = ""; + setState(() {}); + } + }, ), 16.height, const Divider().defaultStyle(context), @@ -114,17 +117,70 @@ class _PartNoButtonState extends State { itemCount: list.length, padding: EdgeInsets.only(bottom: 16.toScreenHeight), physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) => Row( - crossAxisAlignment: CrossAxisAlignment.start, + itemBuilder: (context, index) => Column( + mainAxisSize: MainAxisSize.min, children: [ - "${list[index].sparePart.partNo} / ${list[index].sparePart.partName}".bodyText(context).expanded, - list[index].qty.toString().bodyText(context), - 32.width, - "trash".toSvgAsset().onPress(() { - list.remove(list[index]); - if (widget.onChange != null) widget.onChange(list); - setState(() {}); - }), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + "${list[index].sparePart.partNo} / ${list[index].sparePart.partName}".bodyText(context).expanded, + list[index].qty.toString().bodyText(context), + 32.width, + "trash".toSvgAsset(color: widget.disablePartEdit ? Colors.grey : null).onPress(widget.disablePartEdit + ? null + : () { + list.remove(list[index]); + if (widget.onChange != null) widget.onChange(list); + setState(() {}); + }), + ], + ), + if (widget.disablePartEdit) + Row( + children: [ + AppTextFormField( + controller: TextEditingController(), + labelText: "Installed Qty", + textInputType: TextInputType.number, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral30, + enable: true, + initialValue: list[index].installQty?.toInt()?.toString() ?? "", + validator: (value) => value == null || value.isEmpty + ? context.translation.requiredField + : Validator.isNumeric(value) + ? null + : context.translation.onlyNumbers, + onChange: (text) { + list[index].installQty = num.tryParse(text ?? ""); + if (widget.onChange != null) widget.onChange(list); + }, + onSaved: (text) { + list[index].installQty = num.tryParse(text ?? ""); + }, + ).expanded, + 8.width, + AppTextFormField( + controller: TextEditingController(), + labelText: "Returned Qty", + textInputType: TextInputType.number, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral30, + enable: true, + initialValue: list[index].returnQty?.toInt()?.toString() ?? "", + validator: (value) => value == null || value.isEmpty + ? context.translation.requiredField + : Validator.isNumeric(value) + ? null + : context.translation.onlyNumbers, + onChange: (text) { + list[index].returnQty = num.tryParse(text ?? ""); + if (widget.onChange != null) widget.onChange(list); + }, + onSaved: (text) { + list[index].returnQty = num.tryParse(text ?? ""); + }, + ).expanded, + ], + ).paddingOnly(top: 4, bottom: 4), ], ).paddingOnly(top: 4, bottom: 4), separatorBuilder: (context, index) => 8.height,