From 575005ebdd0571f601bd6e2947af205f9cd1393d Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 20 Jun 2023 16:31:17 +0300 Subject: [PATCH] Enhancements --- ...ice_report_fault_description_provider.dart | 2 +- .../service_request/search_work_order.dart | 110 +++++++++--------- .../create_sub_workorder_page.dart | 45 +++---- .../work_order_details_bottom_sheet.dart | 13 ++- 4 files changed, 82 insertions(+), 88 deletions(-) diff --git a/lib/controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart b/lib/controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart index 8946bd0a..bc47dfb8 100644 --- a/lib/controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart +++ b/lib/controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart @@ -55,7 +55,7 @@ class ServiceRequestFaultDescriptionProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received List listJson = json.decode(response.body)["data"]['asset']['modelDefinition']['modelDefRelatedDefects']; - _items = listJson.map((type) => FaultDescription.fromJson(type)).toList(); + _items = listJson?.map((type) => FaultDescription.fromJson(type))?.toList() ?? []; } _loading = false; notifyListeners(); diff --git a/lib/models/service_request/search_work_order.dart b/lib/models/service_request/search_work_order.dart index 38c75f4d..735fedd4 100644 --- a/lib/models/service_request/search_work_order.dart +++ b/lib/models/service_request/search_work_order.dart @@ -234,7 +234,7 @@ class SearchWorkOrder { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['parentWOId'] = parentWOId; map['workOrderNo'] = workOrderNo; map['workOrderYear'] = workOrderYear; @@ -250,7 +250,7 @@ class SearchWorkOrder { } map['visitDate'] = visitDate; if (assistantEmployees != null) { - map['assistantEmployees'] = assistantEmployees.map((v) => v?.user?.id).toList(); + map['assistantEmployees'] = assistantEmployees.map((v) => v?.toJson()).toList(); } if (supplier != null) { map['supplier'] = supplier.toJson(); @@ -379,8 +379,8 @@ class WoParentDto { map['assetType'] = assetType.toMap(); } map['vendorTicketNumber'] = vendorTicketNumber; - map['callId'] = callId??0; - map['id'] = id??0; + map['callId'] = callId ?? 0; + map['id'] = id ?? 0; if (stepsWorkOrderDto != null) { map['stepsWorkOrderDto'] = stepsWorkOrderDto.toJson(); } @@ -444,7 +444,7 @@ class SuppEngineerWorkOrders { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierContactId'] = supplierContactId; map['personName'] = personName; map['personRoleName'] = personRoleName; @@ -508,7 +508,7 @@ class StepsWorkOrderDto { Map toJson() { final map = {}; map['sequence'] = sequence; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['statusValue'] = statusValue; map['typeTransaction'] = typeTransaction; @@ -543,7 +543,7 @@ class SupplierModel { }); SupplierModel.fromJson(dynamic json) { - id = json['id']??0; + id = json['id'] ?? 0; suppliername = json['suppliername']; name = json['name']; website = json['website']; @@ -634,7 +634,7 @@ class SupplierModel { List suppTCodes, }) => SupplierModel( - id: id ?? this.id??0, + id: id ?? this.id ?? 0, suppliername: suppliername ?? this.suppliername, name: name ?? this.name, website: website ?? this.website, @@ -656,7 +656,7 @@ class SupplierModel { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['suppliername'] = suppliername; map['name'] = name; map['website'] = website; @@ -716,14 +716,14 @@ class SuppTCodes { String codeValue, }) => SuppTCodes( - id: id ?? this.id??0, + id: id ?? this.id ?? 0, supplierId: supplierId ?? this.supplierId, codeTypeId: codeTypeId ?? this.codeTypeId, codeValue: codeValue ?? this.codeValue, ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierId'] = supplierId; map['codeTypeId'] = codeTypeId; map['codeValue'] = codeValue; @@ -778,7 +778,7 @@ class SuppPersons { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierId'] = supplierId; map['personName'] = personName; map['personRoleId'] = personRoleId; @@ -821,7 +821,7 @@ class Attachments { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierId'] = supplierId; map['attachmentName'] = attachmentName; map['attachmentURL'] = attachmentURL; @@ -856,7 +856,7 @@ class Addresses { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierId'] = supplierId; map['address'] = address; return map; @@ -890,7 +890,7 @@ class Faxes { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierId'] = supplierId; map['fax'] = fax; return map; @@ -924,7 +924,7 @@ class Telephones { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['supplierId'] = supplierId; map['telephone'] = telephone; return map; @@ -953,7 +953,7 @@ class AttachmentsWorkOrder { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; return map; } @@ -996,7 +996,7 @@ class SparePartsWorkOrders { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; if (sparePart != null) { map['sparePart'] = sparePart.toJson(); } @@ -1034,7 +1034,7 @@ class SparePart { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['partNo'] = partNo; map['partName'] = partName; return map; @@ -1093,7 +1093,7 @@ class ContactPersonWorkOrders { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['employeeCode'] = employeeCode; map['name'] = name; map['telephone'] = telephone; @@ -1127,7 +1127,7 @@ class AssistantEmployees { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; if (user != null) { map['user'] = user.toJson(); } @@ -1157,7 +1157,7 @@ class UserModel { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; return map; } @@ -1185,7 +1185,7 @@ class AssignedEmployee { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; return map; } @@ -1263,7 +1263,7 @@ class CallRequest { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['callNo'] = callNo; map['callComments'] = callComments; if (asset != null) { @@ -1319,7 +1319,7 @@ class FirstAction { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -1353,7 +1353,7 @@ class DefectType { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -1387,7 +1387,7 @@ class Status { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -1446,7 +1446,7 @@ class CallSiteContactPerson { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['employeeCode'] = employeeCode; map['name'] = name; map['telephone'] = telephone; @@ -1516,7 +1516,7 @@ class Asset { systemID = json['systemID']; assetNumber = json['assetNumber']; modelDefinition = json['modelDefinition'] != null ? ModelDefinition.fromJson(json['modelDefinition']) : null; - supplier = json['supplier'] != null ? SupplierModel.fromJson(json['supplier']) : null; + supplier = json['supplier'] != null ? Supplier.fromJson(json['supplier']) : null; ipAddress = json['ipAddress']; macAddress = json['macAddress']; portNumber = json['portNumber']; @@ -1570,7 +1570,7 @@ class Asset { String systemID; String assetNumber; ModelDefinition modelDefinition; - SupplierModel supplier; + Supplier supplier; String ipAddress; String macAddress; String portNumber; @@ -1715,7 +1715,7 @@ class Asset { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['assetSerialNo'] = assetSerialNo; map['systemID'] = systemID; map['assetNumber'] = assetNumber; @@ -1831,7 +1831,7 @@ class TechnicalGuidanceBooks { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; if (guidanceBook != null) { map['guidanceBook'] = guidanceBook.toJson(); } @@ -1866,7 +1866,7 @@ class GuidanceBook { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -1900,7 +1900,7 @@ class RemainderWarrantyMonths { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -1934,7 +1934,7 @@ class ExtendedWarrantyMonths { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -1968,7 +1968,7 @@ class SiteWarrantyMonths { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2002,7 +2002,7 @@ class CommissioningStatus { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2046,7 +2046,7 @@ class OriginSite { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['customerCode'] = customerCode; map['custName'] = custName; if (buildings != null) { @@ -2093,7 +2093,7 @@ class Buildings { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; if (floors != null) { @@ -2140,7 +2140,7 @@ class Floors { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; if (departments != null) { @@ -2172,7 +2172,7 @@ class Departments { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; return map; } @@ -2203,7 +2203,7 @@ class OriginDepartment { String ntCode, }) => OriginDepartment( - id: id ?? this.id??0, + id: id ?? this.id ?? 0, departmentName: departmentName ?? this.departmentName, departmentCode: departmentCode ?? this.departmentCode, ntCode: ntCode ?? this.ntCode, @@ -2245,7 +2245,7 @@ class Currency { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2284,7 +2284,7 @@ class Department { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['departmentName'] = departmentName; map['departmentCode'] = departmentCode; map['ntCode'] = ntCode; @@ -2319,7 +2319,7 @@ class Floor { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2353,7 +2353,7 @@ class Building { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2397,7 +2397,7 @@ class Site { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['customerCode'] = customerCode; map['custName'] = custName; if (buildings != null) { @@ -2444,7 +2444,7 @@ class ParentAsset { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['assetSerialNo'] = assetSerialNo; map['assetNumber'] = assetNumber; map['tagCode'] = tagCode; @@ -2480,7 +2480,7 @@ class IsParent { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2516,7 +2516,7 @@ class OldAsset { String systemId, }) => OldAsset( - id: id ?? this.id??0, + id: id ?? this.id ?? 0, assetSerialNo: assetSerialNo ?? this.assetSerialNo, assetNumber: assetNumber ?? this.assetNumber, tagCode: tagCode ?? this.tagCode, @@ -2560,7 +2560,7 @@ class AssetReplace { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['name'] = name; map['value'] = value; return map; @@ -2589,7 +2589,7 @@ class Supplier { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['suppliername'] = suppliername; return map; } @@ -2682,7 +2682,7 @@ class ModelDefinition { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['assetName'] = assetName; map['modelDefCode'] = modelDefCode; map['modelName'] = modelName; @@ -2725,7 +2725,7 @@ class Suppliers { ); Map toJson() { final map = {}; - map['id'] = id??0; + map['id'] = id ?? 0; map['suppliername'] = suppliername; return map; } @@ -2756,7 +2756,7 @@ class ModelDefRelatedDefects { String estimatedTime, }) => ModelDefRelatedDefects( - id: id ?? this.id??0, + id: id ?? this.id ?? 0, defectName: defectName ?? this.defectName, workPerformed: workPerformed ?? this.workPerformed, estimatedTime: estimatedTime ?? this.estimatedTime, 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 cc7ac230..79fcbef0 100644 --- a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart +++ b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart @@ -47,7 +47,7 @@ class _CreateSubWorkOrderPageState extends State { @override void initState() { - _subWorkOrders =SearchWorkOrder(assignedEmployee: widget.workOrder.assignedEmployee, callRequest: CallRequest()); + _subWorkOrders = SearchWorkOrder(assignedEmployee: widget.workOrder.assignedEmployee, callRequest: CallRequest()); _serviceReport = ServiceReport(id: widget.workOrder.id, type: widget.workOrder.assetType, equipmentStatus: widget.workOrder.equipmentStatus); super.initState(); } @@ -182,7 +182,7 @@ class _CreateSubWorkOrderPageState extends State { height: 4, ), ServiceReportFaultDescription( - requestId: widget.workOrder.callRequest.id.toString(), + requestId: widget.workOrder?.id?.toString(), initialValue: _subWorkOrders.faultDescription, onSelect: (status) { _subWorkOrders.faultDescription = status; @@ -195,15 +195,11 @@ class _CreateSubWorkOrderPageState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ASubTitle("Solution"), + const ASubTitle("Solution"), const SizedBox( height: 4, ), - ATextFormField( - labelText: _subWorkOrders.faultDescription?.workPerformed??"", - textInputType: TextInputType.multiline, - enable:false - ), + ATextFormField(labelText: _subWorkOrders.faultDescription?.workPerformed ?? "", textInputType: TextInputType.multiline, enable: false), ], ), const SizedBox(height: 8), @@ -283,25 +279,20 @@ class _CreateSubWorkOrderPageState extends State { child: AButton( text: subtitle.create, onPressed: () async { - _subWorkOrders.parentWOId=widget.workOrder.id; + _subWorkOrders.parentWOId = widget.workOrder.id; _validate = true; - setState(() {}); - if(validate()){ - if(_subWorkOrders.startofWorkTime == null) - { - Fluttertoast.showToast(msg: subtitle.startDate + " required"); + setState(() {}); + if (validate()) { + if (_subWorkOrders.startofWorkTime == null) { + Fluttertoast.showToast(msg: "${subtitle.startDate} required"); + return; + } else if (_subWorkOrders.endofWorkTime == null) { + Fluttertoast.showToast(msg: "${subtitle.endDate} required"); return; - } else - if(_subWorkOrders.endofWorkTime == null) - { - Fluttertoast.showToast(msg: subtitle.endDate + " required"); + } else if (_subWorkOrders.calllastSituation == null) { + Fluttertoast.showToast(msg: "${subtitle.callLastSituation} required"); return; - } else - if(_subWorkOrders.calllastSituation == null) - { - Fluttertoast.showToast(msg: subtitle.callLastSituation + " required"); - return; - } + } _validate = false; _isLoading = true; setState(() {}); @@ -311,7 +302,7 @@ class _CreateSubWorkOrderPageState extends State { final status = await serviceRequestsProvider.createSubWorkOrder(workOrder: _subWorkOrders); _isLoading = false; setState(() {}); - if (status>= 200 && status< 300) { + if (status >= 200 && status < 300) { Fluttertoast.showToast(msg: subtitle.requestCompleteSuccessfully); Navigator.of(context).pop(); Navigator.of(context).pop(); @@ -328,8 +319,8 @@ class _CreateSubWorkOrderPageState extends State { ); } - bool validate(){ - if(_subWorkOrders.faultDescription == null || _subWorkOrders.reason == null || _subWorkOrders.equipmentStatus == null|| _subWorkOrders.visitDate == null) { + bool validate() { + if (_subWorkOrders.faultDescription == null || _subWorkOrders.reason == null || _subWorkOrders.equipmentStatus == null || _subWorkOrders.visitDate == null) { return false; } else { return true; diff --git a/lib/views/pages/sub_workorder/work_order_details_bottom_sheet.dart b/lib/views/pages/sub_workorder/work_order_details_bottom_sheet.dart index 1896435c..bb08dc43 100644 --- a/lib/views/pages/sub_workorder/work_order_details_bottom_sheet.dart +++ b/lib/views/pages/sub_workorder/work_order_details_bottom_sheet.dart @@ -85,7 +85,7 @@ class _WorkOrderDetailsBottomSheetState extends State Validator.isNumeric(value) ? null : _subtitle.requiredWord, textInputType: TextInputType.number, onSaved: (value) { - _workOrder.workingHours = double.tryParse(value); + _workOrder.workingHours = double.tryParse( + ((DateTime.tryParse(_workOrder.endofWorkTime ?? "")?.difference(DateTime.tryParse(_workOrder.startofWorkTime ?? ""))?.inMinutes ?? 0) / 60) + ?.toStringAsFixed(2) + ?.toString() ?? + "0"); }, ), const SizedBox(height: 8),