From e407b0063095f41ccb8e46a4a853f576a8091713 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Mon, 30 Oct 2023 16:52:17 +0300 Subject: [PATCH 1/2] New Work Order [In Progress] --- assets/images/back.svg | 3 + assets/images/clear.svg | 3 + assets/images/done.svg | 3 + assets/images/image_placeholder.svg | 3 + assets/images/redo.svg | 3 + lib/attachment.dart | 27 + .../providers/api/gas_refill_provider.dart | 13 +- .../providers/api/parts_provider.dart | 24 +- .../api/service_requests_provider.dart | 146 +- ...e_report_assistants_employee_provider.dart | 13 +- .../service_report_last_calls_provider.dart | 19 +- .../report/vendor_provider.dart | 8 +- lib/l10n/app_ar.arb | 8 +- lib/l10n/app_en.arb | 8 +- lib/main.dart | 4 + .../call_request_for_work_order_model.dart | 320 --- lib/models/engineer.dart | 6 +- lib/models/gas_refill/gas_refill_details.dart | 47 - lib/models/gas_refill/gas_refill_model.dart | 108 - lib/models/new_models/assistant_employee.dart | 31 + lib/models/part.dart | 40 - lib/models/service_report.dart | 250 -- .../call_site_contact_person.dart | 63 + .../contact_person_work_order.dart | 63 + .../service_request/search_work_order.dart | 2313 +---------------- .../service_request/service_report.dart | 304 +++ .../service_request_search.dart | 2 +- lib/models/service_request/spare_parts.dart | 91 + .../sub_work_order_details.dart | 146 +- .../supp_engineer_work_orders.dart | 57 + .../service_request/supplier_details.dart | 411 +++ .../service_request/wo_call_request.dart | 122 + lib/models/service_request/wo_parent.dart | 163 ++ lib/providers/work_order/reason_provider.dart | 36 + .../work_order/service_type_provider.dart | 36 + .../auto_generated_vendor_name.dart | 6 +- .../create_sub_workorder_page.dart | 11 +- .../search_sub_workorder_page.dart | 4 +- .../spare_parts_details_bottom_sheet.dart | 42 +- .../work_order_details_bottom_sheet.dart | 21 +- .../requests/service_request_details.dart | 12 +- .../work_order/create_service_report.dart | 1040 ++------ .../work_order/edit_service_report.dart | 347 ++- .../work_order/future_service_report.dart | 4 +- .../work_order/work_orders_list_page.dart | 6 +- .../widgets/date_and_time/date_picker.dart | 2 +- .../widgets/e_signature/e_signature.dart | 158 +- .../parts/auto_complete_parts_field.dart | 20 +- lib/views/widgets/parts/part_item.dart | 26 +- .../widgets/pentry/pentry_pm_kit_form.dart | 4 +- .../search/service_request_search_bar.dart | 5 +- .../status/assistant_employee_menu.dart | 100 +- ...ervice_report_assistant_employee_menu.dart | 9 +- .../service_report_equipment_status.dart | 18 +- .../report/service_report_last_call.dart | 34 +- .../status/report/service_report_status.dart | 18 +- .../supplier_engineers_menu.dart | 4 +- .../widgets/status/single_status_menu.dart | 103 +- 58 files changed, 2320 insertions(+), 4568 deletions(-) create mode 100644 assets/images/back.svg create mode 100644 assets/images/clear.svg create mode 100644 assets/images/done.svg create mode 100644 assets/images/image_placeholder.svg create mode 100644 assets/images/redo.svg create mode 100644 lib/attachment.dart delete mode 100644 lib/models/call_request_for_work_order_model.dart delete mode 100644 lib/models/gas_refill/gas_refill_details.dart delete mode 100644 lib/models/gas_refill/gas_refill_model.dart create mode 100644 lib/models/new_models/assistant_employee.dart delete mode 100644 lib/models/part.dart delete mode 100644 lib/models/service_report.dart create mode 100644 lib/models/service_request/call_site_contact_person.dart create mode 100644 lib/models/service_request/contact_person_work_order.dart create mode 100644 lib/models/service_request/service_report.dart create mode 100644 lib/models/service_request/spare_parts.dart create mode 100644 lib/models/service_request/supp_engineer_work_orders.dart create mode 100644 lib/models/service_request/supplier_details.dart create mode 100644 lib/models/service_request/wo_call_request.dart create mode 100644 lib/models/service_request/wo_parent.dart create mode 100644 lib/providers/work_order/reason_provider.dart create mode 100644 lib/providers/work_order/service_type_provider.dart diff --git a/assets/images/back.svg b/assets/images/back.svg new file mode 100644 index 0000000..d2ee2dc --- /dev/null +++ b/assets/images/back.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/clear.svg b/assets/images/clear.svg new file mode 100644 index 0000000..a380bde --- /dev/null +++ b/assets/images/clear.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/done.svg b/assets/images/done.svg new file mode 100644 index 0000000..32580c3 --- /dev/null +++ b/assets/images/done.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/image_placeholder.svg b/assets/images/image_placeholder.svg new file mode 100644 index 0000000..34ee503 --- /dev/null +++ b/assets/images/image_placeholder.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/redo.svg b/assets/images/redo.svg new file mode 100644 index 0000000..ddf5a67 --- /dev/null +++ b/assets/images/redo.svg @@ -0,0 +1,3 @@ + + + diff --git a/lib/attachment.dart b/lib/attachment.dart new file mode 100644 index 0000000..a89ae4a --- /dev/null +++ b/lib/attachment.dart @@ -0,0 +1,27 @@ +class Attachment { + Attachment({ + this.id, + this.name, + }); + + Attachment.fromJson(dynamic json) { + id = json['id']; + name = json['name']; + } + num id; + String name; + Attachment copyWith({ + num id, + String name, + }) => + Attachment( + id: id ?? this.id, + name: name ?? this.name, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['name'] = name; + return map; + } +} diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index 4e20959..ff4f190 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -7,9 +7,8 @@ import 'package:http/http.dart'; import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/gas_refill/gas_refill_model.dart'; import 'package:test_sa/models/hospital.dart'; -import 'package:test_sa/models/new_models/gas_refill_model.dart' as gasModel; +import 'package:test_sa/models/new_models/gas_refill_model.dart'; import 'package:test_sa/models/timer_model.dart'; import 'package:test_sa/models/user.dart'; @@ -39,7 +38,7 @@ class GasRefillProvider extends ChangeNotifier { bool nextPage = true; // list of user requests - List items; + List items; // when requests in-process _loading = true // done _loading = true @@ -71,7 +70,7 @@ class GasRefillProvider extends ChangeNotifier { if (stateCode >= 200 && stateCode < 300) { // client's request was successfully received List requestsListJson = json.decode(response.body)["data"]; - List itemsPage = requestsListJson.map((request) => gasModel.GasRefillModel.fromJson(request)).toList(); + List itemsPage = requestsListJson.map((request) => GasRefillModel.fromJson(request)).toList(); items ??= []; items.addAll(itemsPage); notifyListeners(); @@ -96,7 +95,7 @@ class GasRefillProvider extends ChangeNotifier { Future createModel({ @required BuildContext context, @required User user, - @required gasModel.GasRefillModel model, + @required GasRefillModel model, }) async { Response response; try { @@ -128,8 +127,8 @@ class GasRefillProvider extends ChangeNotifier { Future updateModel({ @required String host, @required User user, - @required gasModel.GasRefillModel oldModel, - @required gasModel.GasRefillModel newModel, + @required GasRefillModel oldModel, + @required GasRefillModel newModel, }) async { Map body = { "id": newModel.id, diff --git a/lib/controllers/providers/api/parts_provider.dart b/lib/controllers/providers/api/parts_provider.dart index de14ce4..aae9475 100644 --- a/lib/controllers/providers/api/parts_provider.dart +++ b/lib/controllers/providers/api/parts_provider.dart @@ -5,8 +5,7 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart'; import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; -import 'package:test_sa/models/part.dart'; -import 'package:test_sa/models/user.dart'; +import 'package:test_sa/models/service_request/spare_parts.dart'; class PartsProvider extends ChangeNotifier { // number of items call in each request @@ -32,9 +31,9 @@ class PartsProvider extends ChangeNotifier { // contain user data // when user not login or register _user = null - List _parts; + List _parts; - List get parts => _parts; + List get parts => _parts; // when categories in-process _loading = true // done _loading = true @@ -53,7 +52,7 @@ class PartsProvider extends ChangeNotifier { /// return state code if request complete may be 200, 404 or 403 /// for more details check http state manager /// lib\controllers\http_status_manger\http_status_manger.dart - Future getParts({String host, User user, String title}) async { + Future getParts({String title}) async { if (_loading == true) return -2; _loading = true; notifyListeners(); @@ -64,10 +63,9 @@ class PartsProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received List categoriesListJson = json.decode(utf8.decode(response.bodyBytes)); - List _page = categoriesListJson.map((part) => Part.fromJson(part)).toList(); - if (parts == null) _parts = []; - - _parts.addAll(_page); + List _page = categoriesListJson.map((part) => SparePart.fromJson(part)).toList(); + _parts ??= []; + _parts.addAll(_page.map((e) => SparePartsWorkOrders(sparePart: e)).toList()); if (_page.length >= pageItemNumber) { _nextPage = true; } else { @@ -90,19 +88,19 @@ class PartsProvider extends ChangeNotifier { /// return state code if request complete may be 200, 404 or 403 /// for more details check http state manager /// lib\controllers\http_status_manger\http_status_manger.dart - Future> getPartsList({String host, User user, num assetId, String title}) async { + Future> getPartsList({num assetId, String title}) async { Response response; try { - if (int.tryParse(title) != null) { + if (int.tryParse(title ?? "") != null) { response = await ApiManager.instance.post(URLs.getPartNumber, body: {if (title != null && title.isNotEmpty) "partNo": title, "assetId": assetId}); } else { response = await ApiManager.instance.post(URLs.getPartNumber, body: {if (title != null && title.isNotEmpty) "partName": title, "assetId": assetId}); } - List page = []; + List page = []; if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received List categoriesListJson = json.decode(response.body)["data"]; - page = categoriesListJson.map((part) => Part.fromJson(part)).toList(); + page = categoriesListJson.map((part) => SparePart.fromJson(part)).toList(); } return page; } catch (error) { diff --git a/lib/controllers/providers/api/service_requests_provider.dart b/lib/controllers/providers/api/service_requests_provider.dart index b00f79b..0d20dde 100644 --- a/lib/controllers/providers/api/service_requests_provider.dart +++ b/lib/controllers/providers/api/service_requests_provider.dart @@ -9,16 +9,15 @@ import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/http_status_manger.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/call_request_for_work_order_model.dart'; import 'package:test_sa/models/issue.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/service_report.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/service_request/service_request_search.dart'; import 'package:test_sa/models/timer_model.dart'; import '../../../models/service_request/search_work_order.dart'; -import '../../../models/service_request/sub_work_order_details.dart'; +import '../../../models/service_request/wo_call_request.dart'; import '../../../models/user.dart'; import '../../../new_views/common_widgets/app_lazy_loading.dart'; @@ -310,74 +309,69 @@ class ServiceRequestsProvider extends ChangeNotifier { } } - Future createServiceReport({ - @required String host, - @required User user, - @required ServiceReport report, - @required ServiceRequest request, - }) async { + Future createServiceReport({@required ServiceReport report, @required ServiceRequest request}) async { Response response; try { - Map body = { - "id": 0, - "parentWOId": null, - "workOrderNo": "", - "workOrderYear": null, - "workOrderSequennce": null, - "callRequest": { - "id": request.id, - }, - "assetType": report.assetType?.toJson(), - "assignedEmployee": {"id": report.engineer?.id, "name": report.engineer?.name ?? ""}, - "visitDate": report.returnToService?.toIso8601String() ?? "", - // "assistantEmployees": [ - // {"id": report.engineer.id, "name": report.engineer.name}, - // ], - "supplier": null, - "vendorTicketNumber": null, - "contactPersonWorkOrders": [ - { - "id": 0, - // "employeeCode": "", - "name": user.userName, - "telephone": user.phoneNumber, - // "job": "", - "email": user.email, - // "land": "", - "contactUserId": user.userID, - } - ], - "calllastSituation": report.callLastSituation?.toJson(), - "currentSituation": null, - "repairLocation": report.repairLocation?.toJson(), - "reason": report.reason?.toJson(), - "startofWorkTime": report.timer?.startAt?.toIso8601String() ?? "", - "endofWorkTime": report.timer?.endAt?.toIso8601String() ?? "", - "workingHours": report?.workingHours, - "travelingHours": report.travelingHours, - "travelingExpenses": report.travelingExpense ?? 0, - if (report.faultDescription != null) "faultDescription": report.faultDescription.toJson(), - "sparePartsWorkOrders": report.parts - ?.map( - (p) => { - "id": p.reportPartID ?? 0, - "sparePart": {"id": p.id, "partNo": p.partNo, "partName": p.partName}, - "qty": p.quantity - }, - ) - ?.toList(), - "reviewComment": "", - "comment": report.comment, - "attachmentsWorkOrder": request.devicePhotos?.map((e) => {"name": e})?.toList(), - "equipmentStatus": report.equipmentStatus?.toJson(), - "suppEngineerWorkOrders": null, - "engSignature": report.signatureEngineer, - "nurseSignature": report.signatureNurse, - "woParentDto": null, - }; + // Map body = { + // "id": 0, + // "parentWOId": null, + // "workOrderNo": "", + // "workOrderYear": null, + // "workOrderSequennce": null, + // "callRequest": { + // "id": request.id, + // }, + // "assetType": report.assetType?.toJson(), + // "assignedEmployee": {"id": report.engineer?.id, "name": report.engineer?.name ?? ""}, + // "visitDate": report.returnToService?.toIso8601String() ?? "", + // // "assistantEmployees": [ + // // {"id": report.engineer.id, "name": report.engineer.name}, + // // ], + // "supplier": null, + // "vendorTicketNumber": null, + // "contactPersonWorkOrders": [ + // { + // "id": 0, + // // "employeeCode": "", + // "name": user.userName, + // "telephone": user.phoneNumber, + // // "job": "", + // "email": user.email, + // // "land": "", + // "contactUserId": user.userID, + // } + // ], + // "calllastSituation": report.callLastSituation?.toJson(), + // "currentSituation": null, + // "repairLocation": report.repairLocation?.toJson(), + // "reason": report.reason?.toJson(), + // "startofWorkTime": report.timer?.startAt?.toIso8601String() ?? "", + // "endofWorkTime": report.timer?.endAt?.toIso8601String() ?? "", + // "workingHours": report?.workingHours, + // "travelingHours": report.travelingHours, + // "travelingExpenses": report.travelingExpense ?? 0, + // if (report.faultDescription != null) "faultDescription": report.faultDescription.toJson(), + // "sparePartsWorkOrders": report.parts + // ?.map( + // (p) => { + // "id": p.reportPartID ?? 0, + // "sparePart": {"id": p.id, "partNo": p.partNo, "partName": p.partName}, + // "qty": p.quantity + // }, + // ) + // ?.toList(), + // "reviewComment": "", + // "comment": report.comment, + // "attachmentsWorkOrder": request.devicePhotos?.map((e) => {"name": e})?.toList(), + // "equipmentStatus": report.equipmentStatus?.toJson(), + // "suppEngineerWorkOrders": null, + // "engSignature": report.signatureEngineer, + // "nurseSignature": report.signatureNurse, + // "woParentDto": null, + // }; // body["uid"] = user.id; // body["token"] = user.token; - response = await ApiManager.instance.post(URLs.createServiceReport, body: body); + response = await ApiManager.instance.post(URLs.createServiceReport, body: {}); // response = await post( // Uri.parse( // host+URLs.createServiceReport), @@ -415,9 +409,9 @@ class ServiceRequestsProvider extends ChangeNotifier { } } - CallRequestForWorkOrder callRequestForWorkOrder; + CallRequest callRequestForWorkOrder; - Future getCallRequestForWorkOrder({String callId}) async { + Future getCallRequestForWorkOrder({String callId}) async { Response response; try { response = await ApiManager.instance.get( @@ -428,7 +422,7 @@ class ServiceRequestsProvider extends ChangeNotifier { // client's request was successfully received Map listJson = json.decode(response.body)["data"]; log(listJson?.toString()); - callRequestForWorkOrder = CallRequestForWorkOrder.fromJson(listJson); + callRequestForWorkOrder = CallRequest.fromJson(listJson); } notifyListeners(); @@ -466,7 +460,7 @@ class ServiceRequestsProvider extends ChangeNotifier { } } - Future getSubWorkOrderDetails({@required String parentId}) async { + Future getSubWorkOrderDetails({@required String parentId}) async { Response response; try { response = await ApiManager.instance.get(URLs.getSubWorkerInfoAccordingToPreviousStep + "?parentId=$parentId"); @@ -474,7 +468,7 @@ class ServiceRequestsProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received final workOrderJson = json.decode(response.body)["data"]; - return SubWorkOrderDetails.fromJson(workOrderJson); + return ServiceReport.fromJson(workOrderJson); } return null; } catch (e) { @@ -525,7 +519,10 @@ class ServiceRequestsProvider extends ChangeNotifier { // body["job_id"] = request.id; // body["report_id"] = request.reportID; // try { - Map body = report.toMap(request); + Map body = report.toJson(); + + /// todo [zaid] : don't forget to add [request] data to [body] + // Map body = report.toMap(request); // body["uid"] = user.id; // body["token"] = user.token; response = await ApiManager.instance.put(URLs.updateServiceReport, body: body); @@ -626,7 +623,8 @@ class ServiceRequestsProvider extends ChangeNotifier { // If the call to the server was successful, parse the JSON. if (response.statusCode >= 200 && response.statusCode < 300) { // If the call to the server was successful, parse the JSON. - return ServiceReport.fromJson(json.decode(response.body)["data"], reportId); + /// todo [zaid]: check [reportId] below + return ServiceReport.fromJson(json.decode(response.body)["data"] /*, reportId*/); } else { throw (HttpStatusManger.getStatusMessage(status: response.statusCode, subtitle: subtitle)); } diff --git a/lib/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart b/lib/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart index 922242a..3dbfc74 100644 --- a/lib/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart +++ b/lib/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart @@ -5,7 +5,10 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart'; import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; -import 'package:test_sa/models/service_request/search_work_order.dart'; +import 'package:test_sa/models/engineer.dart'; + +import '../../../../../models/new_models/assigned_employee.dart'; +import '../../../../../models/new_models/assistant_employee.dart'; class ServiceReportAssistantsEmployeeProvider extends ChangeNotifier { //reset provider data @@ -41,15 +44,13 @@ class ServiceReportAssistantsEmployeeProvider extends ChangeNotifier { /// return state code if request complete may be 200, 404 or 403 /// for more details check http state manager /// lib\controllers\http_status_manger\http_status_manger.dart - Future getAssistantEmployees() async { + Future getAssistantEmployees(num assetId) async { if (_loading == true) return -2; _loading = true; notifyListeners(); Response response; try { - response = await ApiManager.instance.get( - "${URLs.getEngineers}", - ); + response = await ApiManager.instance.get("${URLs.getEngineers}&assetId=$assetId"); // response = await get( // Uri.parse( // URLs.getServiceReportLastCalls @@ -61,7 +62,7 @@ class ServiceReportAssistantsEmployeeProvider extends ChangeNotifier { // client's request was successfully received List usersListJson = json.decode(response.body); _assistantEmployees = []; - _assistantEmployees = usersListJson.map((type) => AssistantEmployees.fromJson(type ?? {})).toList(); + _assistantEmployees = usersListJson.map((type) => Engineer.fromJson(type ?? {})).map((e) => AssistantEmployees(user: AssignedEmployee(id: e.id, name: e.name))).toList(); } _loading = false; notifyListeners(); diff --git a/lib/controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart b/lib/controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart index 7551ad5..8785cbe 100644 --- a/lib/controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart +++ b/lib/controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart @@ -6,7 +6,6 @@ import 'package:http/http.dart'; import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/user.dart'; class ServiceReportLastCallsProvider extends ChangeNotifier { //reset provider data @@ -42,29 +41,15 @@ class ServiceReportLastCallsProvider extends ChangeNotifier { /// return state code if request complete may be 200, 404 or 403 /// for more details check http state manager /// lib\controllers\http_status_manger\http_status_manger.dart - Future getCalls({ - String host, - User user, - int serviceStatus, - String woId, - int id, - String typeName, - }) async { + Future getCalls({String parentId, int id, String typeName}) async { if (_loading == true) return -2; _loading = true; notifyListeners(); Response response; try { - // todo request new api from backend to make filter work response = await ApiManager.instance.get( - "${URLs.getServiceReportLastCalls}?parentWOId=${woId ?? id}&isAdd=true&id=${id ?? 0}&typeTransaction=$typeName", + "${URLs.getServiceReportLastCalls}?parentWOId=${parentId ?? id}&isAdd=true&id=${id ?? 0}&typeTransaction=$typeName", ); - // response = await get( - // Uri.parse( - // URLs.getServiceReportLastCalls - // +(serviceStatus == null ? "" : "?service_status=$serviceStatus") - // ), - // ); _stateCode = response.statusCode; if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received diff --git a/lib/controllers/providers/api/status_drop_down/report/vendor_provider.dart b/lib/controllers/providers/api/status_drop_down/report/vendor_provider.dart index 4271e00..8e3549d 100644 --- a/lib/controllers/providers/api/status_drop_down/report/vendor_provider.dart +++ b/lib/controllers/providers/api/status_drop_down/report/vendor_provider.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart'; import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; -import 'package:test_sa/models/service_request/search_work_order.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; class VendorProvider extends ChangeNotifier { void reset() { @@ -17,8 +17,8 @@ class VendorProvider extends ChangeNotifier { int _stateCode; int get stateCode => _stateCode; - List _vendors; - List get vendors => _vendors; + List _vendors; + List get vendors => _vendors; bool _loading; bool get isLoading => _loading; @@ -38,7 +38,7 @@ class VendorProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received List suppliersJson = json.decode(response.body)["data"]; - _vendors = suppliersJson.map((type) => Supplier.fromJson(type)).toList(); + _vendors = suppliersJson.map((type) => SupplierDetails.fromJson(type)).toList(); } _loading = false; notifyListeners(); diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 733a78a..da3950b 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -171,6 +171,7 @@ "partNumberName": "رقم/اسم القطعة", "quantity": "كمية", "reasons": "الاسباب", + "reason": "السبب", "reportStatus": "حالة التقرير", "reportType": "نوع التقرير", "callId": "رقم الطلب", @@ -287,5 +288,10 @@ "pickADate" : "إختر تاريخ", "firstActionStatus" : "حالة الإجراء الأول", "loanAvailability" : "توافر القرض", - "save" : "حفظ" + "save" : "حفظ", + "serviceType" : "نوع الخدمة", + "assistantEmployee" : "موظف مساعد", + "assignAssistant" : "تعيين مساعد", + "partNo" : "الجزء رقم", + "engSign" : "توقيع المهندس" } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index b7ac86a..8ca93ef 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -171,6 +171,7 @@ "partNumberName": "Part Number/Name", "quantity": "Quantity", "reasons": "Reasons", + "reason": "Reason", "reportStatus": "Report Status", "reportType": "Report Type", "callId": "Call Id", @@ -292,5 +293,10 @@ "pickADate" : "Pick a date", "firstActionStatus" : "First Action Status", "loanAvailability" : "Loan Availability", - "save" : "Save" + "save" : "Save", + "serviceType" : "Service Type", + "assistantEmployee" : "Assistant Employee", + "assignAssistant" : "Assign Assistant", + "partNo" : "Part No.", + "engSign" : "Engineer Signature" } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 54a7493..be728ba 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -59,6 +59,8 @@ import 'package:test_sa/providers/service_request_providers/loan_availability_pr import 'package:test_sa/providers/service_request_providers/priority_provider.dart'; import 'package:test_sa/providers/service_request_providers/requested_through_provider.dart'; import 'package:test_sa/providers/service_request_providers/type_of_request_provider.dart'; +import 'package:test_sa/providers/work_order/reason_provider.dart'; +import 'package:test_sa/providers/work_order/service_type_provider.dart'; import 'package:test_sa/views/pages/device_transfer/asset_filter_screen.dart'; import 'package:test_sa/views/pages/device_transfer/asset_search_screen.dart'; import 'package:test_sa/views/pages/device_transfer/request_device_transfer.dart'; @@ -170,6 +172,8 @@ class MyApp extends StatelessWidget { ChangeNotifierProvider(create: (_) => TypeOfRequestProvider()), ChangeNotifierProvider(create: (_) => FirstActionStatusProvider()), ChangeNotifierProvider(create: (_) => LoanAvailabilityProvider()), + ChangeNotifierProvider(create: (_) => ReasonProvider()), + ChangeNotifierProvider(create: (_) => ServiceTypeProvider()), ], child: GestureDetector( onTap: () { diff --git a/lib/models/call_request_for_work_order_model.dart b/lib/models/call_request_for_work_order_model.dart deleted file mode 100644 index 574bcda..0000000 --- a/lib/models/call_request_for_work_order_model.dart +++ /dev/null @@ -1,320 +0,0 @@ -import 'device/asset.dart'; - -class CallRequestForWorkOrder { - int id; - String callNo; - Asset asset; - AssignedEmployee assignedEmployee; - List callSiteContactPerson; - Status status; - Status callLastSituation; - Status defectType; - Status firstAction; - int assetType; - - CallRequestForWorkOrder( - {this.id, this.callNo, this.asset, this.assignedEmployee, this.callSiteContactPerson, this.status, this.callLastSituation, this.defectType, this.firstAction, this.assetType}); - - CallRequestForWorkOrder.fromJson(Map json) { - id = json['id']; - callNo = json['callNo']; - asset = json['asset'] != null ? new Asset.fromJson(json['asset']) : null; - assignedEmployee = json['assignedEmployee'] != null ? new AssignedEmployee.fromJson(json['assignedEmployee']) : null; - if (json['callSiteContactPerson'] != null) { - callSiteContactPerson = []; - json['callSiteContactPerson'].forEach((v) { - callSiteContactPerson.add(new CallSiteContactPerson.fromJson(v)); - }); - } - status = json['status'] != null ? new Status.fromJson(json['status']) : null; - callLastSituation = json['callLastSituation'] != null ? new Status.fromJson(json['callLastSituation']) : null; - defectType = json['defectType'] != null ? new Status.fromJson(json['defectType']) : null; - firstAction = json['firstAction'] != null ? new Status.fromJson(json['firstAction']) : null; - assetType = json['assetType']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['callNo'] = this.callNo; - if (this.asset != null) { - data['asset'] = this.asset.toJson(); - } - if (this.assignedEmployee != null) { - data['assignedEmployee'] = this.assignedEmployee.toJson(); - } - if (this.callSiteContactPerson != null) { - data['callSiteContactPerson'] = this.callSiteContactPerson.map((v) => v.toJson()).toList(); - } - if (this.status != null) { - data['status'] = this.status.toJson(); - } - if (this.callLastSituation != null) { - data['callLastSituation'] = this.callLastSituation.toJson(); - } - if (this.defectType != null) { - data['defectType'] = this.defectType.toJson(); - } - if (this.firstAction != null) { - data['firstAction'] = this.firstAction.toJson(); - } - data['assetType'] = this.assetType; - return data; - } -} - -class ModelDefinition { - int id; - String assetName; - String modelDefCode; - String modelName; - int manufacturerId; - String manufacturerName; - String supplierName; - String replacementDate; - int lifeSpan; - List modelDefRelatedDefects; - List suppliers; - - ModelDefinition( - {this.id, - this.assetName, - this.modelDefCode, - this.modelName, - this.manufacturerId, - this.manufacturerName, - this.supplierName, - this.replacementDate, - this.lifeSpan, - this.modelDefRelatedDefects, - this.suppliers}); - - ModelDefinition.fromJson(Map json) { - id = json['id']; - assetName = json['assetName']; - modelDefCode = json['modelDefCode']; - modelName = json['modelName']; - manufacturerId = json['manufacturerId']; - manufacturerName = json['manufacturerName']; - supplierName = json['supplierName']; - replacementDate = json['replacementDate']; - lifeSpan = json['lifeSpan']; - if (json['modelDefRelatedDefects'] != null) { - modelDefRelatedDefects = []; - json['modelDefRelatedDefects'].forEach((v) { - modelDefRelatedDefects.add(new ModelDefRelatedDefects.fromJson(v)); - }); - } - if (json['suppliers'] != null) { - suppliers = []; - json['suppliers'].forEach((v) { - // suppliers!.add(new Null.fromJson(v)); - }); - } - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['assetName'] = this.assetName; - data['modelDefCode'] = this.modelDefCode; - data['modelName'] = this.modelName; - data['manufacturerId'] = this.manufacturerId; - data['manufacturerName'] = this.manufacturerName; - data['supplierName'] = this.supplierName; - data['replacementDate'] = this.replacementDate; - data['lifeSpan'] = this.lifeSpan; - if (this.modelDefRelatedDefects != null) { - data['modelDefRelatedDefects'] = this.modelDefRelatedDefects.map((v) => v.toJson()).toList(); - } - if (this.suppliers != null) { - data['suppliers'] = this.suppliers.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class ModelDefRelatedDefects { - int id; - String defectName; - String workPerformed; - String estimatedTime; - - ModelDefRelatedDefects({this.id, this.defectName, this.workPerformed, this.estimatedTime}); - - ModelDefRelatedDefects.fromJson(Map json) { - id = json['id']; - defectName = json['defectName']; - workPerformed = json['workPerformed']; - estimatedTime = json['estimatedTime']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['defectName'] = this.defectName; - data['workPerformed'] = this.workPerformed; - data['estimatedTime'] = this.estimatedTime; - return data; - } -} - -class Site { - int id; - int customerCode; - String custName; - List buildings; - - Site({this.id, this.customerCode, this.custName, this.buildings}); - - Site.fromJson(Map json) { - id = json['id']; - customerCode = json['customerCode']; - custName = json['custName']; - if (json['buildings'] != null) { - buildings = []; - json['buildings'].forEach((v) { - // buildings!.add(new Null.fromJson(v)); - }); - } - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['customerCode'] = this.customerCode; - data['custName'] = this.custName; - if (this.buildings != null) { - data['buildings'] = this.buildings.map((v) => v.toJson()).toList(); - } - return data; - } -} - -class Department { - int id; - String departmentName; - String departmentCode; - String ntCode; - - Department({this.id, this.departmentName, this.departmentCode, this.ntCode}); - - Department.fromJson(Map json) { - id = json['id']; - departmentName = json['departmentName']; - departmentCode = json['departmentCode']; - ntCode = json['ntCode']; - } - - Map toJson() { - final Map data = {}; - data['id'] = id; - data['departmentName'] = departmentName; - data['departmentCode'] = departmentCode; - data['ntCode'] = ntCode; - return data; - } -} - -class AssignedEmployee { - String id; - String name; - - AssignedEmployee({this.id, this.name}); - - AssignedEmployee.fromJson(Map json) { - id = json['id']; - name = json['name']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['name'] = this.name; - return data; - } -} - -class CallSiteContactPerson { - int id; - String employeeCode; - String name; - String telephone; - String job; - String email; - String land; - String contactUserId; - - CallSiteContactPerson({this.id, this.employeeCode, this.name, this.telephone, this.job, this.email, this.land, this.contactUserId}); - - CallSiteContactPerson.fromJson(Map json) { - id = json['id']; - employeeCode = json['employeeCode']; - name = json['name']; - telephone = json['telephone']; - job = json['job']; - email = json['email']; - land = json['land']; - contactUserId = json['contactUserId']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['employeeCode'] = this.employeeCode; - data['name'] = this.name; - data['telephone'] = this.telephone; - data['job'] = this.job; - data['email'] = this.email; - data['land'] = this.land; - data['contactUserId'] = this.contactUserId; - return data; - } -} - -class Status { - int id; - String name; - int value; - - Status({this.id, this.name, this.value}); - - Status.fromJson(Map json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['name'] = this.name; - data['value'] = this.value; - return data; - } -} - -class Building { - int id; - String name; - int value; - var floor; - - Building({this.id, this.name, this.value, this.floor}); - - Building.fromJson(Map json) { - id = json['id']; - name = json['name']; - value = json['value']; - floor = json['floor']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['name'] = this.name; - data['value'] = this.value; - data['floor'] = this.floor; - return data; - } -} diff --git a/lib/models/engineer.dart b/lib/models/engineer.dart index e53b0af..b285a0c 100644 --- a/lib/models/engineer.dart +++ b/lib/models/engineer.dart @@ -27,10 +27,10 @@ class Engineer { @override int get hashCode => id.hashCode; - Map toMap() { + Map toJson({bool userPrefix = false}) { return { - 'id': id, - 'name': name, + userPrefix ? "userId" : "id": id, + userPrefix ? "userName" : "name": name, }; } } diff --git a/lib/models/gas_refill/gas_refill_details.dart b/lib/models/gas_refill/gas_refill_details.dart deleted file mode 100644 index 5016677..0000000 --- a/lib/models/gas_refill/gas_refill_details.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:test_sa/models/lookup.dart'; - -@Deprecated("Use the model inside lib/models/new_models folder") -class GasRefillDetails { - Lookup type; - Lookup cylinderSize; - Lookup cylinderType; - double requestedQuantity; - double deliveredQuantity; - bool selectedForEditing; - - GasRefillDetails({ - this.type, - this.cylinderSize, - this.cylinderType, - this.requestedQuantity, - this.deliveredQuantity, - this.selectedForEditing, - }); - - bool validate() { - //if(cylinderSize == null) return false; - if (type == null) return false; - if (requestedQuantity == null) return false; - return true; - } - - factory GasRefillDetails.fromJson(Map parsedJson) { - return GasRefillDetails( - type: Lookup.fromJson(parsedJson["gasType"]), - cylinderSize: Lookup.fromJson(parsedJson["cylinderSize"]), - cylinderType: Lookup.fromJson(parsedJson["cylinderType"]), - requestedQuantity: parsedJson["requestedQty"], - deliveredQuantity: parsedJson["deliverdQty"], - ); - } - - factory GasRefillDetails.fromDetails(GasRefillDetails details) { - return GasRefillDetails( - type: Lookup.fromStatus(details.type), - cylinderSize: Lookup.fromStatus(details.cylinderSize), - cylinderType: Lookup.fromStatus(details.cylinderType), - requestedQuantity: details.requestedQuantity, - deliveredQuantity: details.deliveredQuantity, - ); - } -} diff --git a/lib/models/gas_refill/gas_refill_model.dart b/lib/models/gas_refill/gas_refill_model.dart deleted file mode 100644 index cc34dc6..0000000 --- a/lib/models/gas_refill/gas_refill_model.dart +++ /dev/null @@ -1,108 +0,0 @@ -import 'dart:typed_data'; - -import 'package:test_sa/models/gas_refill/gas_refill_details.dart'; -import 'package:test_sa/models/lookup.dart'; - -import '../../controllers/api_routes/urls.dart'; -import '../call_request_for_work_order_model.dart'; - -@Deprecated("Use the new model [lib/models/new_models/gas_refill_model.dart]") -class GasRefillModel { - int id; - - //String userId; - String clientName; - String title; - Lookup status; - Lookup building; - Lookup floor; - Department department; - List details; - AssignedEmployee assignedEmployee; - String signatureNurse; - String signatureEngineer; - Uint8List localNurseSignature; - Uint8List localEngineerSignature; - num workingHours; - DateTime startDate, endDate, expectedDate; - - GasRefillModel({ - this.id, - //this.userId, - this.clientName, - this.title, - this.status, - this.details, - this.building, - this.floor, - this.startDate, - this.endDate, - this.expectedDate, - this.department, - this.assignedEmployee, - this.signatureNurse, - this.signatureEngineer, - this.localEngineerSignature, - this.localNurseSignature, - this.workingHours, - }); - - bool validate() { - if (title == null) return false; - if (status == null) return false; - // if (building == null) return false; - // if (floor == null) return false; - // if (department == null) return false; - // if (startDate == null) return false; - // if (endDate == null) return false; - if (details == null && details.isEmpty) return false; - return true; - } - - fromGasRefillModel(GasRefillModel model) { - id = model.id; - //userId = model.userId; - clientName = model.clientName; - title = model.title; - status = Lookup.fromStatus(model.status); - details = model.details.map((e) => GasRefillDetails.fromDetails(e)).toList(); - building = model.building; - floor = model.floor; - department = model.department; - startDate = model.startDate; - endDate = model.endDate; - expectedDate = model.expectedDate; - assignedEmployee = model.assignedEmployee; - localEngineerSignature = model.localEngineerSignature; - localNurseSignature = model.localNurseSignature; - signatureEngineer = model.signatureEngineer; - signatureNurse = model.signatureNurse; - workingHours = model.workingHours; - } - - factory GasRefillModel.fromJson(Map parsedJson) { - List details = []; - if (parsedJson["gazRefillDetails"] != null) { - List list = parsedJson["gazRefillDetails"]; - details = list.map((e) => GasRefillDetails.fromJson(e)).toList(); - } - return GasRefillModel( - id: parsedJson["id"], - //userId: parsedJson["uid"], - title: parsedJson["gazRefillNo"], - clientName: parsedJson["site"] == null ? null : parsedJson["site"]["custName"], - status: Lookup.fromJson(parsedJson["status"] ?? {}), - details: details, - building: Lookup.fromJson(parsedJson["building"] ?? {}), - floor: Lookup.fromJson(parsedJson["floor"] ?? {}), - department: Department.fromJson(parsedJson["department"] ?? {}), - startDate: DateTime.tryParse(parsedJson['startDate'] ?? ""), - endDate: DateTime.tryParse(parsedJson['endDate'] ?? ""), - expectedDate: DateTime.tryParse(parsedJson['expectedDate'] ?? ""), - assignedEmployee: AssignedEmployee.fromJson(parsedJson['assignedEmployee'] ?? {}), - signatureEngineer: URLs.getFileUrl(parsedJson["engSignature"]), - signatureNurse: URLs.getFileUrl(parsedJson["nurseSignature"]), - workingHours: parsedJson["workingHours"], - ); - } -} diff --git a/lib/models/new_models/assistant_employee.dart b/lib/models/new_models/assistant_employee.dart new file mode 100644 index 0000000..9a351b2 --- /dev/null +++ b/lib/models/new_models/assistant_employee.dart @@ -0,0 +1,31 @@ +import 'package:test_sa/models/new_models/assigned_employee.dart'; + +class AssistantEmployees { + AssistantEmployees({ + this.id, + this.user, + }); + + AssistantEmployees.fromJson(dynamic json) { + id = json['id']; + user = json['user'] != null ? AssignedEmployee.fromJson(json['user']) : null; + } + num id; + AssignedEmployee user; + AssistantEmployees copyWith({ + num id, + AssignedEmployee user, + }) => + AssistantEmployees( + id: id ?? this.id, + user: user ?? this.user, + ); + Map toJson() { + final map = {}; + map['id'] = id; + if (user != null) { + map['user'] = user.toJson(); + } + return map; + } +} diff --git a/lib/models/part.dart b/lib/models/part.dart deleted file mode 100644 index 9f8b0ca..0000000 --- a/lib/models/part.dart +++ /dev/null @@ -1,40 +0,0 @@ -class Part { - int id; - int reportPartID; - String partNo; - String partName; - int quantity; - double returnQty, installQty; - - Part({ - this.id, - this.reportPartID, - this.partNo, - this.partName, - this.quantity = 1, - this.installQty, - this.returnQty, - }); - - Map toJson() { - return { - "id": reportPartID ?? 0, - "sparePart": {"id": id, "partNo": partNo, "partName": partName}, - "qty": quantity, - if (returnQty != null) "returnQty": returnQty, - if (installQty != null) "installQty": installQty, - }; - } - - factory Part.fromJson(Map parsedJson, {Map reportJson}) { - return Part( - id: parsedJson["id"], - reportPartID: reportJson != null ? reportJson["id"] : null, - partNo: parsedJson["partNo"], - partName: parsedJson["partName"], - quantity: reportJson != null ? (reportJson["qty"] ?? 1).toInt() : 1, - returnQty: parsedJson["returnQty"], - installQty: parsedJson["installQty"], - ); - } -} diff --git a/lib/models/service_report.dart b/lib/models/service_report.dart deleted file mode 100644 index 0b128d8..0000000 --- a/lib/models/service_report.dart +++ /dev/null @@ -1,250 +0,0 @@ -import 'dart:typed_data'; - -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:test_sa/controllers/api_routes/urls.dart'; -import 'package:test_sa/models/device/asset.dart'; -import 'package:test_sa/models/engineer.dart'; -import 'package:test_sa/models/fault_description.dart'; -import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/part.dart'; -import 'package:test_sa/models/service_request/service_request.dart'; -import 'package:test_sa/models/timer_model.dart'; - -class ServiceReport { - int id; - double operatingHours; - DateTime visitDate; - DateTime returnToService; - - // DateTime endDate; - // DateTime startDate; - Lookup assetType; - Lookup callLastSituation; - Lookup currentSituation; - Lookup repairLocation; - Engineer engineer; - Lookup equipmentStatus; - Lookup type; - Lookup reason; - int faultDescriptionId; - String workPreformed; - - num workingHours; - double travelingHours; - String invoiceNumber; - String invoiceCode; - List parts; - List files; - Asset device; - String quantity; - String jobSheetNumber; - TimerModel timer; - String signatureNurse; - String signatureEngineer; - String comment; - Uint8List localNurseSignature; - Uint8List localEngineerSignature; - num travelingExpense; - String reviewComment; - FaultDescription faultDescription; - - ServiceReport( - {this.id, - this.visitDate, - // this.endDate, - this.assetType, - this.equipmentStatus, - this.type, - this.faultDescriptionId, - this.workingHours, - this.travelingHours, - this.parts, - this.engineer, - this.workPreformed, - this.reason, - this.operatingHours, - this.callLastSituation, - this.currentSituation, - this.jobSheetNumber, - this.files, - this.device, - this.invoiceCode, - this.invoiceNumber, - this.quantity = "1", - this.timer, - this.signatureNurse, - this.signatureEngineer, - this.localNurseSignature, - this.localEngineerSignature, - this.comment, - this.repairLocation, - this.travelingExpense, - // this.startDate, - this.reviewComment, - this.faultDescription, - this.returnToService}); - - Map toMap(ServiceRequest request) { - Map _map = {}; - if (id != null) _map["id"] = id; - if (visitDate != null) _map["visitDate"] = visitDate.toIso8601String(); - if (returnToService != null) _map["replacementDate"] = returnToService.toIso8601String(); - - //if(serviceType != null) _map["service_type"] = serviceType.id.toString(); - if (equipmentStatus != null) _map["equipmentStatus"] = equipmentStatus?.toJson(); - if (type != null) _map["typeOfWO"] = type?.toJson(); - if (assetType != null) _map["TypeOfWO"] = assetType?.toJson(); - //if(faultDescriptionId != null && faultDescriptionId.isNotEmpty) _map["fault_description"] = faultDescriptionId; - //if(workHours != null && workHours.isNotEmpty) _map["working_hours"] = workHours; - if (timer != null) { - _map["startofWorkTime"] = timer.startAt.toIso8601String(); - _map["endofWorkTime"] = (timer.endAt ?? DateTime.now()).toIso8601String(); - _map["workingHours"] = (timer.durationInSecond / 60 / 60).toStringAsFixed(5); - } - if (travelingHours != null && travelingHours.toString().isNotEmpty) _map["travelingHours"] = travelingHours; - // if(workPreformed != null && workPreformed.isNotEmpty){ - // _map["faultDescription"] = { - // "id":faultDescriptionId ?? 0, - // "workPerformed":workPreformed - // }; - // } - _map["faultDescription"] = faultDescription?.id == null ? null : {"id": faultDescription?.id ?? 0, "workPerformed": faultDescription?.workPerformed}; - if (travelingHours != null) _map["travelingHours"] = travelingHours; - // if (workingHours != null) _map["workingHours"] = workingHours; - // if (workPreformed != null && workPreformed.isNotEmpty) { - // _map["faultDescription"] = faultDescription.toJson(); - // } - if (jobSheetNumber != null && jobSheetNumber.isNotEmpty) _map["job_sheet_no"] = jobSheetNumber; - if (parts != null && parts.isNotEmpty) { - _map["sparePartsWorkOrders"] = parts.map((e) => e.toJson()).toList(); - } - if (device != null && device.id != null) { - _map["callRequest"] = { - "id": request.id, - // "asset": device?.toJson(assetType), - "asset": device?.toJson(), - }; - _map["callRequest"]["asset"]["invoiceNumber"] = invoiceNumber; - } - _map["AssignedEmployee"] = engineer?.toMap(); - _map["repairLocation"] = repairLocation?.toJson(); - //if(quantity != null && quantity.isNotEmpty) _map["qty"] = quantity; - //if(endDate != null) _map["end_date"] = (endDate.millisecondsSinceEpoch ~/ 1000).toString(); - if (reason != null) _map["reason"] = reason.toJson(); - //if(operatingHours != null && operatingHours.isNotEmpty) _map["operation_hours"] = operatingHours; - if (callLastSituation != null) _map["calllastSituation"] = callLastSituation.toJson(); - if (currentSituation != null) _map["currentSituation"] = currentSituation.toJson(); - //if(image != null) _map["image"] = image; - //if(invoiceCode != null) _map["invoice_no"] = invoiceCode; - //if(invoiceNumber != null) _map["invoice_code"] = invoiceNumber; - if (files != null) { - _map["attachmentsWorkOrder"] = files.map((e) => {"name": e}).toList(); - } - _map["nurseSignature"] = signatureNurse; - _map["engSignature"] = signatureEngineer; - _map["comment"] = comment; - _map["travelingExpenses"] = travelingExpense; - // _map["startofWorkTime"] = startDate.toIso8601String(); - // _map["endofWorkTime"] = endDate.toIso8601String(); - // _map["workingHours"] = endDate?.difference(startDate)?.inHours ?? 0; - if (timer?.startAt != null) _map["startofWorkTime"] = timer?.startAt?.toIso8601String(); - if (timer?.endAt != null) _map["endofWorkTime"] = timer?.endAt?.toIso8601String(); - _map["workingHours"] = workingHours; - _map["reviewComment"] = reviewComment; - return _map; - } - - Future validate() async { - // if (visitDate == null) { - // await Fluttertoast.showToast(msg: "Visit Date Required"); - // return false; - // } - // if (returnToService == null) { - // await Fluttertoast.showToast(msg: "Return To Service Date Required"); - // return false; - // } - if (timer?.startAt == null) { - await Fluttertoast.showToast(msg: "Working Hours Required"); - return false; - } - if (timer?.endAt == null) { - await Fluttertoast.showToast(msg: "Please Stop The Timer"); - return false; - } - //if(serviceType == null) return false; - if (equipmentStatus == null) return false; - //if (type == null && assetType == null) return false; - // if (engineer == null) return false; - if (callLastSituation == null) return false; - if (callLastSituation?.value == 12) { - // if(invoiceCode != null || invoiceCode?.isEmpty == true) return false; - if (invoiceNumber != null || invoiceNumber?.isEmpty == true) return false; - } - if (parts == null) return false; - //if(endDate == null) return false; - if (reason == null) return false; - //todo uncoment this line - //if((device?.id == null || device.id.isEmpty) && type?.id != 1) return false; - //if(quantity == null || quantity.isEmpty) return false; - //if(image == null) return false; - return true; - } - - factory ServiceReport.fromJson(Map parsedJson, int id) { - List _parts = []; - if (parsedJson["sparePartsWorkOrders"] != null) { - if ((parsedJson["sparePartsWorkOrders"] as List).isNotEmpty && parsedJson["sparePartsWorkOrders"][0]["id"] != null) { - List partsList = parsedJson["sparePartsWorkOrders"]; - _parts = partsList.map((e) => Part.fromJson(e["sparePart"], reportJson: e)).toList(); - } - } - List _files = []; - if (parsedJson["attachmentsWorkOrder"] != null && parsedJson["attachmentsWorkOrder"] is List) { - List list = parsedJson["attachmentsWorkOrder"]; - _files = list.map((e) => (URLs.getFileUrl(e["name"]))).toList(); - } - return ServiceReport( - id: id, - assetType: Lookup.fromJson(parsedJson["assetType"]), - callLastSituation: Lookup.fromJson(parsedJson["calllastSituation"]), - currentSituation: Lookup.fromJson(parsedJson["currentSituation"]), - repairLocation: Lookup.fromJson(parsedJson["repairLocation"]), - reason: Lookup.fromJson(parsedJson["reason"]), - equipmentStatus: Lookup.fromJson(parsedJson["equipmentStatus"]), - type: Lookup.fromJson(parsedJson["typeOfWO"]), - faultDescription: parsedJson['faultDescription'] != null ? FaultDescription.fromJson(parsedJson['faultDescription']) : null, - files: _files, - // faultDescription: parsedJson["faultDescription"], - // startDate: DateTime.tryParse(parsedJson["startofWorkTime"] ?? ""), - // endDate: DateTime.tryParse(parsedJson["endofWorkTime"] ?? ""), - //invoiceCode: parsedJson["invoice_code"], - //invoiceNumber: parsedJson["invoice_no"], - //jobSheetNumber: parsedJson["job_sheet_no"], - // workingHours: parsedJson["workingHours"], - engineer: Engineer.fromJson(parsedJson["assignedEmployee"]), - parts: _parts, - //quantity: parsedJson["nid"], - travelingHours: parsedJson["travelingHours"], - travelingExpense: parsedJson["travelingExpenses"], - visitDate: DateTime.tryParse(parsedJson["visitDate"] ?? ""), - returnToService: DateTime.tryParse(parsedJson["replacementDate"] ?? ""), - workingHours: parsedJson["workingHours"], - timer: TimerModel( - startAt: DateTime.tryParse(parsedJson["startofWorkTime"] ?? ""), - endAt: DateTime.tryParse(parsedJson["endofWorkTime"] ?? ""), - durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(), - ), - //workPreformed: parsedJson["work_performed"], - device: Asset.fromJson(parsedJson["callRequest"]["asset"]), - signatureNurse: URLs.getFileUrl(parsedJson["nurseSignature"]), - signatureEngineer: URLs.getFileUrl(parsedJson["engSignature"]), - comment: parsedJson['comment'], - reviewComment: parsedJson['reviewComment'], - ); - } - -// static getDate(String date){ -// return date == null || date.isEmpty -// ? null : DateTime.fromMillisecondsSinceEpoch(int.tryParse(date) * 1000); -// } -} diff --git a/lib/models/service_request/call_site_contact_person.dart b/lib/models/service_request/call_site_contact_person.dart new file mode 100644 index 0000000..d9246ab --- /dev/null +++ b/lib/models/service_request/call_site_contact_person.dart @@ -0,0 +1,63 @@ +class CallSiteContactPerson { + CallSiteContactPerson({ + this.id, + this.employeeCode, + this.name, + this.telephone, + this.job, + this.email, + this.land, + this.contactUserId, + }); + + CallSiteContactPerson.fromJson(dynamic json) { + id = json['id']; + employeeCode = json['employeeCode']; + name = json['name']; + telephone = json['telephone']; + job = json['job']; + email = json['email']; + land = json['land']; + contactUserId = json['contactUserId']; + } + num id; + String employeeCode; + String name; + String telephone; + String job; + String email; + String land; + String contactUserId; + CallSiteContactPerson copyWith({ + num id, + String employeeCode, + String name, + String telephone, + String job, + String email, + String land, + String contactUserId, + }) => + CallSiteContactPerson( + id: id ?? this.id, + employeeCode: employeeCode ?? this.employeeCode, + name: name ?? this.name, + telephone: telephone ?? this.telephone, + job: job ?? this.job, + email: email ?? this.email, + land: land ?? this.land, + contactUserId: contactUserId ?? this.contactUserId, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['employeeCode'] = employeeCode; + map['name'] = name; + map['telephone'] = telephone; + map['job'] = job; + map['email'] = email; + map['land'] = land; + map['contactUserId'] = contactUserId; + return map; + } +} diff --git a/lib/models/service_request/contact_person_work_order.dart b/lib/models/service_request/contact_person_work_order.dart new file mode 100644 index 0000000..0fe22b4 --- /dev/null +++ b/lib/models/service_request/contact_person_work_order.dart @@ -0,0 +1,63 @@ +class ContactPersonWorkOrder { + ContactPersonWorkOrder({ + this.id, + this.employeeCode, + this.name, + this.telephone, + this.job, + this.email, + this.land, + this.contactUserId, + }); + + ContactPersonWorkOrder.fromJson(dynamic json) { + id = json['id']; + employeeCode = json['employeeCode']; + name = json['name']; + telephone = json['telephone']; + job = json['job']; + email = json['email']; + land = json['land']; + contactUserId = json['contactUserId']; + } + num id; + String employeeCode; + String name; + String telephone; + String job; + String email; + String land; + String contactUserId; + ContactPersonWorkOrder copyWith({ + num id, + String employeeCode, + String name, + String telephone, + String job, + String email, + String land, + String contactUserId, + }) => + ContactPersonWorkOrder( + id: id ?? this.id, + employeeCode: employeeCode ?? this.employeeCode, + name: name ?? this.name, + telephone: telephone ?? this.telephone, + job: job ?? this.job, + email: email ?? this.email, + land: land ?? this.land, + contactUserId: contactUserId ?? this.contactUserId, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['employeeCode'] = employeeCode; + map['name'] = name; + map['telephone'] = telephone; + map['job'] = job; + map['email'] = email; + map['land'] = land; + map['contactUserId'] = contactUserId; + return map; + } +} diff --git a/lib/models/service_request/search_work_order.dart b/lib/models/service_request/search_work_order.dart index 5e85556..f3b3791 100644 --- a/lib/models/service_request/search_work_order.dart +++ b/lib/models/service_request/search_work_order.dart @@ -1,9 +1,17 @@ import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/service_request/sub_work_order_details.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; +import 'package:test_sa/models/service_request/spare_parts.dart'; +import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; +import 'package:test_sa/models/service_request/wo_call_request.dart'; +import 'package:test_sa/models/service_request/wo_parent.dart'; import 'package:test_sa/models/timer_model.dart'; -import '../device/asset.dart'; +import '../../attachment.dart'; import '../fault_description.dart'; +import '../new_models/assigned_employee.dart'; +import '../new_models/assistant_employee.dart'; +import 'contact_person_work_order.dart'; class SearchWorkOrder { SearchWorkOrder({ @@ -60,12 +68,12 @@ class SearchWorkOrder { assistantEmployees.add(AssistantEmployees.fromJson(v)); }); } - supplier = json['supplier'] != null ? SupplierModel.fromJson(json['supplier']) : null; + supplier = json['supplier'] != null ? SupplierDetails.fromJson(json['supplier']) : null; vendorTicketNumber = json['vendorTicketNumber']; if (json['contactPersonWorkOrders'] != null) { contactPersonWorkOrders = []; json['contactPersonWorkOrders'].forEach((v) { - contactPersonWorkOrders.add(ContactPersonWorkOrders.fromJson(v)); + contactPersonWorkOrders.add(ContactPersonWorkOrder.fromJson(v)); }); } calllastSituation = json['calllastSituation'] != null ? Lookup.fromJson(json['calllastSituation']) : null; @@ -94,7 +102,7 @@ class SearchWorkOrder { if (json['attachmentsWorkOrder'] != null) { attachmentsWorkOrder = []; json['attachmentsWorkOrder'].forEach((v) { - attachmentsWorkOrder.add(AttachmentsWorkOrder.fromJson(v)); + attachmentsWorkOrder.add(Attachment.fromJson(v)); }); } equipmentStatus = json['equipmentStatus'] != null ? Lookup.fromJson(json['equipmentStatus']) : null; @@ -106,7 +114,7 @@ class SearchWorkOrder { } engSignature = json['engSignature']; nurseSignature = json['nurseSignature']; - woParentDto = json['woParentDto'] != null ? WoParentDto.fromJson(json['woParentDto']) : null; + woParentDto = json['woParentDto'] != null ? WoParent.fromJson(json['woParentDto']) : null; } void copyFrom(SearchWorkOrder wo) { @@ -125,9 +133,9 @@ class SearchWorkOrder { })) ?.toList() ?? []; - if (wo.supplier != null) supplier = SupplierModel.fromJson((wo.supplier)?.toJson() ?? {}); + if (wo.supplier != null) supplier = SupplierDetails.fromJson((wo.supplier)?.toJson() ?? {}); vendorTicketNumber = wo.vendorTicketNumber ?? vendorTicketNumber; - contactPersonWorkOrders = (wo.contactPersonWorkOrders ?? contactPersonWorkOrders)?.map((e) => ContactPersonWorkOrders.fromJson(e?.toJson() ?? {}))?.toList() ?? []; + contactPersonWorkOrders = (wo.contactPersonWorkOrders ?? contactPersonWorkOrders)?.map((e) => ContactPersonWorkOrder.fromJson(e?.toJson() ?? {}))?.toList() ?? []; calllastSituation = Lookup.fromJson((wo.calllastSituation ?? calllastSituation)?.toJson() ?? {}); if (wo.currentSituation != null) currentSituation = Lookup.fromJson((wo.currentSituation)?.toJson() ?? {}); repairLocation = Lookup.fromJson((wo.repairLocation ?? repairLocation)?.toJson() ?? {}); @@ -142,7 +150,7 @@ class SearchWorkOrder { sparePartsWorkOrders = (wo.sparePartsWorkOrders ?? sparePartsWorkOrders)?.map((e) => SparePartsWorkOrders.fromJson(e?.toJson() ?? {}))?.toList() ?? []; reviewComment = wo.reviewComment ?? reviewComment; comment = wo.comment ?? comment; - attachmentsWorkOrder = (wo.attachmentsWorkOrder ?? attachmentsWorkOrder)?.map((e) => AttachmentsWorkOrder.fromJson(e?.toJson() ?? {}))?.toList() ?? []; + attachmentsWorkOrder = (wo.attachmentsWorkOrder ?? attachmentsWorkOrder)?.map((e) => Attachment.fromJson(e?.toJson() ?? {}))?.toList() ?? []; equipmentStatus = Lookup.fromJson((wo.equipmentStatus ?? equipmentStatus)?.toJson() ?? {}); suppEngineerWorkOrders = (wo.suppEngineerWorkOrders ?? suppEngineerWorkOrders)?.map((e) => SuppEngineerWorkOrders.fromJson(e?.toJson() ?? {}))?.toList() ?? []; engSignature = wo.engSignature ?? engSignature; @@ -161,9 +169,9 @@ class SearchWorkOrder { AssignedEmployee assignedEmployee; String visitDate; List assistantEmployees; - SupplierModel supplier; + SupplierDetails supplier; String vendorTicketNumber; - List contactPersonWorkOrders; + List contactPersonWorkOrders; Lookup calllastSituation; Lookup currentSituation; Lookup repairLocation; @@ -177,12 +185,12 @@ class SearchWorkOrder { List sparePartsWorkOrders; String reviewComment; String comment; - List attachmentsWorkOrder; + List attachmentsWorkOrder; Lookup equipmentStatus; List suppEngineerWorkOrders; String engSignature; String nurseSignature; - WoParentDto woParentDto; + WoParent woParentDto; TimerModel timer; String mrNumber; @@ -197,9 +205,9 @@ class SearchWorkOrder { AssignedEmployee assignedEmployee, String visitDate, List assistantEmployees, - SupplierModel supplier, + SupplierDetails supplier, String vendorTicketNumber, - List contactPersonWorkOrders, + List contactPersonWorkOrders, Lookup calllastSituation, Lookup currentSituation, Lookup repairLocation, @@ -213,12 +221,12 @@ class SearchWorkOrder { List sparePartsWorkOrders, String reviewComment, String comment, - List attachmentsWorkOrder, + List attachmentsWorkOrder, Lookup equipmentStatus, List suppEngineerWorkOrders, String engSignature, String nurseSignature, - WoParentDto woParentDto, + WoParent woParentDto, TimerModel timer, String mrNumber, }) => @@ -332,7 +340,7 @@ class SearchWorkOrder { return map; } - void copyDetails(SubWorkOrderDetails subWoDetails) { + void copyDetails(ServiceReport subWoDetails) { equipmentStatus = subWoDetails.equipmentStatus; reason = subWoDetails.reason; faultDescription = subWoDetails.faultDescription; @@ -341,2272 +349,3 @@ class SearchWorkOrder { supplier = subWoDetails.supplier; } } - -class WoParentDto { - WoParentDto({ - this.callLastSituation, - this.supplier, - this.assetType, - this.vendorTicketNumber, - this.callId, - this.id, - this.stepsWorkOrderDto, - this.suppEngineerWorkOrders, - this.equipmentStatus, - this.currentSituation, - }); - - WoParentDto.fromJson(dynamic json) { - callLastSituation = json['callLastSituation'] != null ? Lookup.fromJson(json['callLastSituation']) : null; - supplier = json['supplier'] != null ? SupplierModel.fromJson(json['supplier']) : null; - assetType = json['assetType'] != null ? Lookup.fromJson(json['assetType']) : null; - vendorTicketNumber = json['vendorTicketNumber']; - callId = json['callId']; - id = json['id']; - stepsWorkOrderDto = json['stepsWorkOrderDto'] != null ? StepsWorkOrderDto.fromJson(json['stepsWorkOrderDto']) : null; - if (json['suppEngineerWorkOrders'] != null) { - suppEngineerWorkOrders = []; - json['suppEngineerWorkOrders'].forEach((v) { - suppEngineerWorkOrders.add(SuppEngineerWorkOrders.fromJson(v)); - }); - } - equipmentStatus = json['equipmentStatus'] != null ? Lookup.fromJson(json['equipmentStatus']) : null; - currentSituation = json['currentSituation'] != null ? Lookup.fromJson(json['currentSituation']) : null; - } - - Lookup callLastSituation; - SupplierModel supplier; - Lookup assetType; - String vendorTicketNumber; - num callId; - num id; - StepsWorkOrderDto stepsWorkOrderDto; - List suppEngineerWorkOrders; - Lookup equipmentStatus; - Lookup currentSituation; - - WoParentDto copyWith({ - Lookup callLastSituation, - SupplierModel supplier, - Lookup assetType, - String vendorTicketNumber, - num callId, - num id, - StepsWorkOrderDto stepsWorkOrderDto, - List suppEngineerWorkOrders, - Lookup equipmentStatus, - Lookup currentSituation, - }) => - WoParentDto( - callLastSituation: callLastSituation ?? this.callLastSituation, - supplier: supplier ?? this.supplier, - assetType: assetType ?? this.assetType, - vendorTicketNumber: vendorTicketNumber ?? this.vendorTicketNumber, - callId: callId ?? this.callId, - id: id ?? this.id, - stepsWorkOrderDto: stepsWorkOrderDto ?? this.stepsWorkOrderDto, - suppEngineerWorkOrders: suppEngineerWorkOrders ?? this.suppEngineerWorkOrders, - equipmentStatus: equipmentStatus ?? this.equipmentStatus, - currentSituation: currentSituation ?? this.currentSituation, - ); - - Map toJson() { - final map = {}; - if (callLastSituation != null) { - map['callLastSituation'] = callLastSituation.toJson(); - } - if (supplier != null) { - map['supplier'] = supplier.toJson(); - } - if (assetType != null) { - map['assetType'] = assetType.toJson(); - } - map['vendorTicketNumber'] = vendorTicketNumber; - map['callId'] = callId ?? 0; - map['id'] = id ?? 0; - if (stepsWorkOrderDto != null) { - map['stepsWorkOrderDto'] = stepsWorkOrderDto.toJson(); - } - if (suppEngineerWorkOrders != null) { - map['suppEngineerWorkOrders'] = suppEngineerWorkOrders.map((v) => v.toJson()).toList(); - } - if (equipmentStatus != null) { - map['equipmentStatus'] = equipmentStatus.toJson(); - } - if (currentSituation != null) { - map['currentSituation'] = currentSituation.toJson(); - } - return map; - } -} - -class SuppEngineerWorkOrders { - SuppEngineerWorkOrders({ - this.id, - this.supplierContactId, - this.personName, - this.personRoleName, - this.contact, - this.externalEngCode, - this.email, - }); - - SuppEngineerWorkOrders.fromJson(dynamic json) { - id = json['id']; - supplierContactId = json['supplierContactId']; - personName = json['personName']; - personRoleName = json['personRoleName']; - contact = json['contact']; - externalEngCode = json['externalEngCode']; - email = json['email']; - } - - num id; - num supplierContactId; - String personName; - String personRoleName; - String contact; - String externalEngCode; - String email; - - SuppEngineerWorkOrders copyWith({ - num id, - num supplierContactId, - String personName, - String personRoleName, - String contact, - String externalEngCode, - String email, - }) => - SuppEngineerWorkOrders( - id: id ?? this.id, - supplierContactId: supplierContactId ?? this.supplierContactId, - personName: personName ?? this.personName, - personRoleName: personRoleName ?? this.personRoleName, - contact: contact ?? this.contact, - externalEngCode: externalEngCode ?? this.externalEngCode, - email: email ?? this.email, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['supplierContactId'] = supplierContactId; - map['personName'] = personName; - map['personRoleName'] = personRoleName; - map['contact'] = contact; - map['externalEngCode'] = externalEngCode; - map['email'] = email; - return map; - } -} - -class StepsWorkOrderDto { - StepsWorkOrderDto({ - this.sequence, - this.id, - this.name, - this.statusValue, - this.typeTransaction, - this.processed, - this.parentWOId, - this.callId, - }); - - StepsWorkOrderDto.fromJson(dynamic json) { - sequence = json['sequence']; - id = json['id']; - name = json['name']; - statusValue = json['statusValue']; - typeTransaction = json['typeTransaction']; - processed = json['processed']; - parentWOId = json['parentWOId']; - callId = json['callId']; - } - - num sequence; - num id; - String name; - num statusValue; - String typeTransaction; - bool processed; - num parentWOId; - num callId; - - StepsWorkOrderDto copyWith({ - num sequence, - num id, - String name, - num statusValue, - String typeTransaction, - bool processed, - num parentWOId, - num callId, - }) => - StepsWorkOrderDto( - sequence: sequence ?? this.sequence, - id: id ?? this.id, - name: name ?? this.name, - statusValue: statusValue ?? this.statusValue, - typeTransaction: typeTransaction ?? this.typeTransaction, - processed: processed ?? this.processed, - parentWOId: parentWOId ?? this.parentWOId, - callId: callId ?? this.callId, - ); - - Map toJson() { - final map = {}; - map['sequence'] = sequence; - map['id'] = id ?? 0; - map['name'] = name; - map['statusValue'] = statusValue; - map['typeTransaction'] = typeTransaction; - map['processed'] = processed; - map['parentWOId'] = parentWOId; - map['callId'] = callId; - return map; - } -} - -class SupplierModel { - SupplierModel({ - this.id, - this.suppliername, - this.name, - this.website, - this.email, - this.code, - this.suppNo, - this.suppStatusId, - this.cityId, - this.person, - this.comment, - this.zipcode, - this.contact, - this.telephones, - this.faxes, - this.addresses, - this.attachments, - this.suppPersons, - this.suppTCodes, - }); - - SupplierModel.fromJson(dynamic json) { - id = json['id'] ?? 0; - suppliername = json['suppliername']; - name = json['name']; - website = json['website']; - email = json['email']; - code = json['code']; - suppNo = json['suppNo']; - suppStatusId = json['suppStatusId']; - cityId = json['cityId']; - person = json['person']; - comment = json['comment']; - zipcode = json['zipcode']; - contact = json['contact']; - if (json['telephones'] != null) { - telephones = []; - json['telephones'].forEach((v) { - telephones.add(Telephones.fromJson(v)); - }); - } - if (json['faxes'] != null) { - faxes = []; - json['faxes'].forEach((v) { - faxes.add(Faxes.fromJson(v)); - }); - } - if (json['addresses'] != null) { - addresses = []; - json['addresses'].forEach((v) { - addresses.add(Addresses.fromJson(v)); - }); - } - if (json['attachments'] != null) { - attachments = []; - json['attachments'].forEach((v) { - attachments.add(Attachments.fromJson(v)); - }); - } - if (json['suppPersons'] != null) { - suppPersons = []; - json['suppPersons'].forEach((v) { - suppPersons.add(SuppPersons.fromJson(v)); - }); - } - if (json['suppTCodes'] != null) { - suppTCodes = []; - json['suppTCodes'].forEach((v) { - suppTCodes.add(SuppTCodes.fromJson(v)); - }); - } - } - - num id; - String suppliername; - String name; - String website; - String email; - String code; - num suppNo; - num suppStatusId; - num cityId; - String person; - String comment; - num zipcode; - String contact; - List telephones; - List faxes; - List addresses; - List attachments; - List suppPersons; - List suppTCodes; - - SupplierModel copyWith({ - num id, - String suppliername, - String name, - String website, - String email, - String code, - num suppNo, - num suppStatusId, - num cityId, - String person, - String comment, - num zipcode, - String contact, - List telephones, - List faxes, - List addresses, - List attachments, - List suppPersons, - List suppTCodes, - }) => - SupplierModel( - id: id ?? this.id ?? 0, - suppliername: suppliername ?? this.suppliername, - name: name ?? this.name, - website: website ?? this.website, - email: email ?? this.email, - code: code ?? this.code, - suppNo: suppNo ?? this.suppNo, - suppStatusId: suppStatusId ?? this.suppStatusId, - cityId: cityId ?? this.cityId, - person: person ?? this.person, - comment: comment ?? this.comment, - zipcode: zipcode ?? this.zipcode, - contact: contact ?? this.contact, - telephones: telephones ?? this.telephones, - faxes: faxes ?? this.faxes, - addresses: addresses ?? this.addresses, - attachments: attachments ?? this.attachments, - suppPersons: suppPersons ?? this.suppPersons, - suppTCodes: suppTCodes ?? this.suppTCodes, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['suppliername'] = suppliername; - map['name'] = name; - map['website'] = website; - map['email'] = email; - map['code'] = code; - map['suppNo'] = suppNo; - map['suppStatusId'] = suppStatusId; - map['cityId'] = cityId; - map['person'] = person; - map['comment'] = comment; - map['zipcode'] = zipcode; - map['contact'] = contact; - if (telephones != null) { - map['telephones'] = telephones.map((v) => v.toJson()).toList(); - } - if (faxes != null) { - map['faxes'] = faxes.map((v) => v.toJson()).toList(); - } - if (addresses != null) { - map['addresses'] = addresses.map((v) => v.toJson()).toList(); - } - if (attachments != null) { - map['attachments'] = attachments.map((v) => v.toJson()).toList(); - } - if (suppPersons != null) { - map['suppPersons'] = suppPersons.map((v) => v.toJson()).toList(); - } - if (suppTCodes != null) { - map['suppTCodes'] = suppTCodes.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class SuppTCodes { - SuppTCodes({ - this.id, - this.supplierId, - this.codeTypeId, - this.codeValue, - }); - - SuppTCodes.fromJson(dynamic json) { - id = json['id']; - supplierId = json['supplierId']; - codeTypeId = json['codeTypeId']; - codeValue = json['codeValue']; - } - - num id; - num supplierId; - num codeTypeId; - String codeValue; - - SuppTCodes copyWith({ - num id, - num supplierId, - num codeTypeId, - String codeValue, - }) => - SuppTCodes( - 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['supplierId'] = supplierId; - map['codeTypeId'] = codeTypeId; - map['codeValue'] = codeValue; - return map; - } -} - -class SuppPersons { - SuppPersons({ - this.id, - this.supplierId, - this.personName, - this.personRoleId, - this.contact, - this.externalEngCode, - this.email, - }); - - SuppPersons.fromJson(dynamic json) { - id = json['id']; - supplierId = json['supplierId']; - personName = json['personName']; - personRoleId = json['personRoleId']; - contact = json['contact']; - externalEngCode = json['externalEngCode']; - email = json['email']; - } - - num id; - num supplierId; - String personName; - num personRoleId; - String contact; - String externalEngCode; - String email; - - SuppPersons copyWith({ - num id, - num supplierId, - String personName, - num personRoleId, - String contact, - String externalEngCode, - String email, - }) => - SuppPersons( - id: id ?? this.id, - supplierId: supplierId ?? this.supplierId, - personName: personName ?? this.personName, - personRoleId: personRoleId ?? this.personRoleId, - contact: contact ?? this.contact, - externalEngCode: externalEngCode ?? this.externalEngCode, - email: email ?? this.email, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['supplierId'] = supplierId; - map['personName'] = personName; - map['personRoleId'] = personRoleId; - map['contact'] = contact; - map['externalEngCode'] = externalEngCode; - map['email'] = email; - return map; - } -} - -class Attachments { - Attachments({ - this.id, - this.supplierId, - this.attachmentName, - this.attachmentURL, - }); - - Attachments.fromJson(dynamic json) { - id = json['id']; - supplierId = json['supplierId']; - attachmentName = json['attachmentName']; - attachmentURL = json['attachmentURL']; - } - - num id; - num supplierId; - String attachmentName; - String attachmentURL; - - Attachments copyWith({ - num id, - num supplierId, - String attachmentName, - String attachmentURL, - }) => - Attachments( - id: id ?? this.id, - supplierId: supplierId ?? this.supplierId, - attachmentName: attachmentName ?? this.attachmentName, - attachmentURL: attachmentURL ?? this.attachmentURL, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['supplierId'] = supplierId; - map['attachmentName'] = attachmentName; - map['attachmentURL'] = attachmentURL; - return map; - } -} - -class Addresses { - Addresses({ - this.id, - this.supplierId, - this.address, - }); - - Addresses.fromJson(dynamic json) { - id = json['id']; - supplierId = json['supplierId']; - address = json['address']; - } - - num id; - num supplierId; - String address; - - Addresses copyWith({ - num id, - num supplierId, - String address, - }) => - Addresses( - id: id ?? this.id, - supplierId: supplierId ?? this.supplierId, - address: address ?? this.address, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['supplierId'] = supplierId; - map['address'] = address; - return map; - } -} - -class Faxes { - Faxes({ - this.id, - this.supplierId, - this.fax, - }); - - Faxes.fromJson(dynamic json) { - id = json['id']; - supplierId = json['supplierId']; - fax = json['fax']; - } - - num id; - num supplierId; - String fax; - - Faxes copyWith({ - num id, - num supplierId, - String fax, - }) => - Faxes( - id: id ?? this.id, - supplierId: supplierId ?? this.supplierId, - fax: fax ?? this.fax, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['supplierId'] = supplierId; - map['fax'] = fax; - return map; - } -} - -class Telephones { - Telephones({ - this.id, - this.supplierId, - this.telephone, - }); - - Telephones.fromJson(dynamic json) { - id = json['id']; - supplierId = json['supplierId']; - telephone = json['telephone']; - } - - num id; - num supplierId; - String telephone; - - Telephones copyWith({ - num id, - num supplierId, - String telephone, - }) => - Telephones( - id: id ?? this.id, - supplierId: supplierId ?? this.supplierId, - telephone: telephone ?? this.telephone, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['supplierId'] = supplierId; - map['telephone'] = telephone; - return map; - } -} - -class AttachmentsWorkOrder { - AttachmentsWorkOrder({ - this.id, - this.name, - }); - - AttachmentsWorkOrder.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - } - - num id; - String name; - - AttachmentsWorkOrder copyWith({ - num id, - String name, - }) => - AttachmentsWorkOrder( - id: id ?? this.id, - name: name ?? this.name, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - return map; - } -} - -class SparePartsWorkOrders { - SparePartsWorkOrders({ - this.id, - this.sparePart, - this.qty, - this.returnQty, - this.installQty, - }); - - SparePartsWorkOrders.fromJson(dynamic json) { - id = json['id']; - sparePart = json['sparePart'] != null ? SparePart.fromJson(json['sparePart']) : null; - qty = json['qty']; - returnQty = json['returnQty']; - installQty = json['installQty']; - } - - num id; - SparePart sparePart; - num qty; - num returnQty; - num installQty; - - SparePartsWorkOrders copyWith({ - num id, - SparePart sparePart, - num qty, - num returnQty, - num installQty, - }) => - SparePartsWorkOrders( - id: id ?? this.id, - sparePart: sparePart ?? this.sparePart, - qty: qty ?? this.qty, - returnQty: returnQty ?? this.returnQty, - installQty: installQty ?? this.installQty, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - if (sparePart != null) { - map['sparePart'] = sparePart.toJson(); - } - map['qty'] = qty; - map['returnQty'] = returnQty; - map['installQty'] = installQty; - return map; - } -} - -class SparePart { - SparePart({ - this.id, - this.partNo, - this.partName, - }); - - SparePart.fromJson(dynamic json) { - id = json['id']; - partNo = json['partNo']; - partName = json['partName']; - } - - num id; - String partNo; - String partName; - - SparePart copyWith({ - num id, - String partNo, - String partName, - }) => - SparePart( - id: id ?? this.id, - partNo: partNo ?? this.partNo, - partName: partName ?? this.partName, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['partNo'] = partNo; - map['partName'] = partName; - return map; - } -} - -class ContactPersonWorkOrders { - ContactPersonWorkOrders({ - this.id, - this.employeeCode, - this.name, - this.telephone, - this.job, - this.email, - this.land, - this.contactUserId, - }); - - ContactPersonWorkOrders.fromJson(dynamic json) { - id = json['id']; - employeeCode = json['employeeCode']; - name = json['name']; - telephone = json['telephone']; - job = json['job']; - email = json['email']; - land = json['land']; - contactUserId = json['contactUserId']; - } - - num id; - String employeeCode; - String name; - String telephone; - String job; - String email; - String land; - String contactUserId; - - ContactPersonWorkOrders copyWith({ - num id, - String employeeCode, - String name, - String telephone, - String job, - String email, - String land, - String contactUserId, - }) => - ContactPersonWorkOrders( - id: id ?? this.id, - employeeCode: employeeCode ?? this.employeeCode, - name: name ?? this.name, - telephone: telephone ?? this.telephone, - job: job ?? this.job, - email: email ?? this.email, - land: land ?? this.land, - contactUserId: contactUserId ?? this.contactUserId, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['employeeCode'] = employeeCode; - map['name'] = name; - map['telephone'] = telephone; - map['job'] = job; - map['email'] = email; - map['land'] = land; - map['contactUserId'] = contactUserId; - return map; - } -} - -class AssistantEmployees { - AssistantEmployees({ - this.id, - this.user, - }); - - AssistantEmployees.fromJson(dynamic json) { - id = json['id']; - user = json['user'] != null ? UserModel.fromJson(json['user']) : UserModel(name: json['userName'], id: json['userId']); - } - - num id; - UserModel user; - - AssistantEmployees copyWith({ - num id, - UserModel user, - }) => - AssistantEmployees( - id: id ?? this.id, - user: user ?? this.user, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - if (user != null) { - map['user'] = user.toJson(); - } - return map; - } -} - -class UserModel { - UserModel({ - this.id, - this.name, - }); - - UserModel.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - } - - String id; - String name; - - UserModel copyWith({ - String id, - String name, - }) => - UserModel( - id: id ?? this.id, - name: name ?? this.name, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - return map; - } -} - -class AssignedEmployee { - AssignedEmployee({ - this.id, - this.name, - }); - - AssignedEmployee.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - } - - String id; - String name; - - AssignedEmployee copyWith({ - String id, - String name, - }) => - AssignedEmployee( - id: id ?? this.id, - name: name ?? this.name, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - return map; - } -} - -class CallRequest { - CallRequest({ - this.id, - this.callNo, - this.callComments, - this.asset, - this.assignedEmployee, - this.callSiteContactPerson, - this.status, - this.callLastSituation, - this.defectType, - this.firstAction, - this.assetType, - }); - - CallRequest.fromJson(dynamic json) { - id = json['id']; - callNo = json['callNo']; - callComments = json['callComments']; - asset = json['asset'] != null ? Asset.fromJson(json['asset']) : null; - assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null; - if (json['callSiteContactPerson'] != null) { - callSiteContactPerson = []; - json['callSiteContactPerson'].forEach((v) { - callSiteContactPerson.add(CallSiteContactPerson.fromJson(v)); - }); - } - status = json['status'] != null ? Status.fromJson(json['status']) : null; - callLastSituation = json['callLastSituation'] != null ? Lookup.fromJson(json['callLastSituation']) : null; - defectType = json['defectType'] != null ? DefectType.fromJson(json['defectType']) : null; - firstAction = json['firstAction'] != null ? FirstAction.fromJson(json['firstAction']) : null; - assetType = json['assetType']; - } - - num id; - String callNo; - String callComments; - Asset asset; - AssignedEmployee assignedEmployee; - List callSiteContactPerson; - Status status; - Lookup callLastSituation; - DefectType defectType; - FirstAction firstAction; - num assetType; - - CallRequest copyWith({ - num id, - String callNo, - String callComments, - Asset asset, - AssignedEmployee assignedEmployee, - List callSiteContactPerson, - Status status, - Lookup callLastSituation, - DefectType defectType, - FirstAction firstAction, - num assetType, - }) => - CallRequest( - id: id ?? this.id, - callNo: callNo ?? this.callNo, - callComments: callComments ?? this.callComments, - asset: asset ?? this.asset, - assignedEmployee: assignedEmployee ?? this.assignedEmployee, - callSiteContactPerson: callSiteContactPerson ?? this.callSiteContactPerson, - status: status ?? this.status, - callLastSituation: callLastSituation ?? this.callLastSituation, - defectType: defectType ?? this.defectType, - firstAction: firstAction ?? this.firstAction, - assetType: assetType ?? this.assetType, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['callNo'] = callNo; - map['callComments'] = callComments; - if (asset != null) { - map['asset'] = asset.toJson(); - } - if (assignedEmployee != null) { - map['assignedEmployee'] = assignedEmployee.toJson(); - } - if (callSiteContactPerson != null) { - map['callSiteContactPerson'] = callSiteContactPerson.map((v) => v.toJson()).toList(); - } - if (status != null) { - map['status'] = status.toJson(); - } - if (callLastSituation != null) { - map['callLastSituation'] = callLastSituation.toJson(); - } - if (defectType != null) { - map['defectType'] = defectType.toJson(); - } - if (firstAction != null) { - map['firstAction'] = firstAction.toJson(); - } - map['assetType'] = assetType; - return map; - } -} - -class FirstAction { - FirstAction({ - this.id, - this.name, - this.value, - }); - - FirstAction.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - FirstAction copyWith({ - num id, - String name, - num value, - }) => - FirstAction( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class DefectType { - DefectType({ - this.id, - this.name, - this.value, - }); - - DefectType.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - DefectType copyWith({ - num id, - String name, - num value, - }) => - DefectType( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class Status { - Status({ - this.id, - this.name, - this.value, - }); - - Status.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - Status copyWith({ - num id, - String name, - num value, - }) => - Status( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class CallSiteContactPerson { - CallSiteContactPerson({ - this.id, - this.employeeCode, - this.name, - this.telephone, - this.job, - this.email, - this.land, - this.contactUserId, - }); - - CallSiteContactPerson.fromJson(dynamic json) { - id = json['id']; - employeeCode = json['employeeCode']; - name = json['name']; - telephone = json['telephone']; - job = json['job']; - email = json['email']; - land = json['land']; - contactUserId = json['contactUserId']; - } - - num id; - String employeeCode; - String name; - String telephone; - String job; - String email; - String land; - String contactUserId; - - CallSiteContactPerson copyWith({ - num id, - String employeeCode, - String name, - String telephone, - String job, - String email, - String land, - String contactUserId, - }) => - CallSiteContactPerson( - id: id ?? this.id, - employeeCode: employeeCode ?? this.employeeCode, - name: name ?? this.name, - telephone: telephone ?? this.telephone, - job: job ?? this.job, - email: email ?? this.email, - land: land ?? this.land, - contactUserId: contactUserId ?? this.contactUserId, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['employeeCode'] = employeeCode; - map['name'] = name; - map['telephone'] = telephone; - map['job'] = job; - map['email'] = email; - map['land'] = land; - map['contactUserId'] = contactUserId; - return map; - } -} - -class TechnicalGuidanceBooks { - TechnicalGuidanceBooks({ - this.id, - this.guidanceBook, - }); - - TechnicalGuidanceBooks.fromJson(dynamic json) { - id = json['id']; - guidanceBook = json['guidanceBook'] != null ? GuidanceBook.fromJson(json['guidanceBook']) : null; - } - - num id; - GuidanceBook guidanceBook; - - TechnicalGuidanceBooks copyWith({ - num id, - GuidanceBook guidanceBook, - }) => - TechnicalGuidanceBooks( - id: id ?? this.id, - guidanceBook: guidanceBook ?? this.guidanceBook, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - if (guidanceBook != null) { - map['guidanceBook'] = guidanceBook.toJson(); - } - return map; - } -} - -class GuidanceBook { - GuidanceBook({ - this.id, - this.name, - this.value, - }); - - GuidanceBook.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - GuidanceBook copyWith({ - num id, - String name, - num value, - }) => - GuidanceBook( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class RemainderWarrantyMonths { - RemainderWarrantyMonths({ - this.id, - this.name, - this.value, - }); - - RemainderWarrantyMonths.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - RemainderWarrantyMonths copyWith({ - num id, - String name, - num value, - }) => - RemainderWarrantyMonths( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class ExtendedWarrantyMonths { - ExtendedWarrantyMonths({ - this.id, - this.name, - this.value, - }); - - ExtendedWarrantyMonths.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - ExtendedWarrantyMonths copyWith({ - num id, - String name, - num value, - }) => - ExtendedWarrantyMonths( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class SiteWarrantyMonths { - SiteWarrantyMonths({ - this.id, - this.name, - this.value, - }); - - SiteWarrantyMonths.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - SiteWarrantyMonths copyWith({ - num id, - String name, - num value, - }) => - SiteWarrantyMonths( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class CommissioningStatus { - CommissioningStatus({ - this.id, - this.name, - this.value, - }); - - CommissioningStatus.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - CommissioningStatus copyWith({ - num id, - String name, - num value, - }) => - CommissioningStatus( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class OriginSite { - OriginSite({ - this.id, - this.customerCode, - this.custName, - this.buildings, - }); - - OriginSite.fromJson(dynamic json) { - id = json['id']; - customerCode = json['customerCode']; - custName = json['custName']; - if (json['buildings'] != null) { - buildings = []; - json['buildings'].forEach((v) { - buildings.add(Buildings.fromJson(v)); - }); - } - } - - num id; - num customerCode; - String custName; - List buildings; - - OriginSite copyWith({ - num id, - num customerCode, - String custName, - List buildings, - }) => - OriginSite( - id: id ?? this.id, - customerCode: customerCode ?? this.customerCode, - custName: custName ?? this.custName, - buildings: buildings ?? this.buildings, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['customerCode'] = customerCode; - map['custName'] = custName; - if (buildings != null) { - map['buildings'] = buildings.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class Buildings { - Buildings({ - this.id, - this.name, - this.value, - this.floors, - }); - - Buildings.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - if (json['floors'] != null) { - floors = []; - json['floors'].forEach((v) { - floors.add(Floors.fromJson(v)); - }); - } - } - - num id; - String name; - num value; - List floors; - - Buildings copyWith({ - num id, - String name, - num value, - List floors, - }) => - Buildings( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - floors: floors ?? this.floors, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - if (floors != null) { - map['floors'] = floors.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class Floors { - Floors({ - this.id, - this.name, - this.value, - this.departments, - }); - - Floors.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - if (json['departments'] != null) { - departments = []; - json['departments'].forEach((v) { - departments.add(Departments.fromJson(v)); - }); - } - } - - num id; - String name; - num value; - List departments; - - Floors copyWith({ - num id, - String name, - num value, - List departments, - }) => - Floors( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - departments: departments ?? this.departments, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - if (departments != null) { - map['departments'] = departments.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class Departments { - Departments({ - this.id, - this.name, - }); - - Departments.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - } - - num id; - String name; - - Departments copyWith({ - num id, - String name, - }) => - Departments( - id: id ?? this.id, - name: name ?? this.name, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - return map; - } -} - -class OriginDepartment { - OriginDepartment({ - this.id, - this.departmentName, - this.departmentCode, - this.ntCode, - }); - - OriginDepartment.fromJson(dynamic json) { - id = json['id']; - departmentName = json['departmentName']; - departmentCode = json['departmentCode']; - ntCode = json['ntCode']; - } - - num id; - String departmentName; - String departmentCode; - String ntCode; - - OriginDepartment copyWith({ - num id, - String departmentName, - String departmentCode, - String ntCode, - }) => - OriginDepartment( - id: id ?? this.id ?? 0, - departmentName: departmentName ?? this.departmentName, - departmentCode: departmentCode ?? this.departmentCode, - ntCode: ntCode ?? this.ntCode, - ); - - Map toJson() { - final map = {}; - map['id'] = id; - map['departmentName'] = departmentName; - map['departmentCode'] = departmentCode; - map['ntCode'] = ntCode; - return map; - } -} - -class Currency { - Currency({ - this.id, - this.name, - this.value, - }); - - Currency.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - Currency copyWith({ - num id, - String name, - num value, - }) => - Currency( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class Department { - Department({ - this.id, - this.departmentName, - this.departmentCode, - this.ntCode, - }); - - Department.fromJson(dynamic json) { - id = json['id']; - departmentName = json['departmentName']; - departmentCode = json['departmentCode']; - ntCode = json['ntCode']; - } - - num id; - String departmentName; - String departmentCode; - String ntCode; - - Department copyWith({ - num id, - String departmentName, - String departmentCode, - String ntCode, - }) => - Department( - id: id ?? this.id, - departmentName: departmentName ?? this.departmentName, - departmentCode: departmentCode ?? this.departmentCode, - ntCode: ntCode ?? this.ntCode, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['departmentName'] = departmentName; - map['departmentCode'] = departmentCode; - map['ntCode'] = ntCode; - return map; - } -} - -class Floor { - Floor({ - this.id, - this.name, - this.value, - }); - - Floor.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - Floor copyWith({ - num id, - String name, - num value, - }) => - Floor( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class Building { - Building({ - this.id, - this.name, - this.value, - }); - - Building.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - Building copyWith({ - num id, - String name, - num value, - }) => - Building( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class Site { - Site({ - this.id, - this.customerCode, - this.custName, - this.buildings, - }); - - Site.fromJson(dynamic json) { - id = json['id']; - customerCode = json['customerCode']; - custName = json['custName']; - if (json['buildings'] != null) { - buildings = []; - json['buildings'].forEach((v) { - buildings.add(Buildings.fromJson(v)); - }); - } - } - - num id; - num customerCode; - String custName; - List buildings; - - Site copyWith({ - num id, - num customerCode, - String custName, - List buildings, - }) => - Site( - id: id ?? this.id, - customerCode: customerCode ?? this.customerCode, - custName: custName ?? this.custName, - buildings: buildings ?? this.buildings, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['customerCode'] = customerCode; - map['custName'] = custName; - if (buildings != null) { - map['buildings'] = buildings.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class ParentAsset { - ParentAsset({ - this.id, - this.assetSerialNo, - this.assetNumber, - this.tagCode, - this.systemId, - }); - - ParentAsset.fromJson(dynamic json) { - id = json['id']; - assetSerialNo = json['assetSerialNo']; - assetNumber = json['assetNumber']; - tagCode = json['tagCode']; - systemId = json['systemId']; - } - - num id; - String assetSerialNo; - String assetNumber; - String tagCode; - String systemId; - - ParentAsset copyWith({ - num id, - String assetSerialNo, - String assetNumber, - String tagCode, - String systemId, - }) => - ParentAsset( - id: id ?? this.id, - assetSerialNo: assetSerialNo ?? this.assetSerialNo, - assetNumber: assetNumber ?? this.assetNumber, - tagCode: tagCode ?? this.tagCode, - systemId: systemId ?? this.systemId, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['assetSerialNo'] = assetSerialNo; - map['assetNumber'] = assetNumber; - map['tagCode'] = tagCode; - map['systemId'] = systemId; - return map; - } -} - -class IsParent { - IsParent({ - this.id, - this.name, - this.value, - }); - - IsParent.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - IsParent copyWith({ - num id, - String name, - num value, - }) => - IsParent( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class OldAsset { - OldAsset({ - this.id, - this.assetSerialNo, - this.assetNumber, - this.tagCode, - this.systemId, - }); - - OldAsset.fromJson(dynamic json) { - id = json['id']; - assetSerialNo = json['assetSerialNo']; - assetNumber = json['assetNumber']; - tagCode = json['tagCode']; - systemId = json['systemId']; - } - - num id; - String assetSerialNo; - String assetNumber; - String tagCode; - String systemId; - - OldAsset copyWith({ - num id, - String assetSerialNo, - String assetNumber, - String tagCode, - String systemId, - }) => - OldAsset( - id: id ?? this.id ?? 0, - assetSerialNo: assetSerialNo ?? this.assetSerialNo, - assetNumber: assetNumber ?? this.assetNumber, - tagCode: tagCode ?? this.tagCode, - systemId: systemId ?? this.systemId, - ); - - Map toJson() { - final map = {}; - map['id'] = id; - map['assetSerialNo'] = assetSerialNo; - map['assetNumber'] = assetNumber; - map['tagCode'] = tagCode; - map['systemId'] = systemId; - return map; - } -} - -class AssetReplace { - AssetReplace({ - this.id, - this.name, - this.value, - }); - - AssetReplace.fromJson(dynamic json) { - id = json['id']; - name = json['name']; - value = json['value']; - } - - num id; - String name; - num value; - - AssetReplace copyWith({ - num id, - String name, - num value, - }) => - AssetReplace( - id: id ?? this.id, - name: name ?? this.name, - value: value ?? this.value, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['name'] = name; - map['value'] = value; - return map; - } -} - -class Supplier { - Supplier({ - this.id, - this.suppliername, - this.suppPersons, - }); - - Supplier.fromJson(dynamic json) { - id = json['id']; - suppliername = json['suppliername']; - if (json['suppPersons'] != null) { - suppPersons = []; - json['suppPersons'].forEach((v) { - suppPersons.add(SuppPersons.fromJson(v)); - }); - } - } - - num id; - String suppliername; - List suppPersons; - - SupplierModel copyWith({ - num id, - String suppliername, - List suppPersons, - }) => - SupplierModel( - id: id ?? this.id, - suppliername: suppliername ?? this.suppliername, - suppPersons: suppPersons ?? this.suppPersons, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['suppliername'] = suppliername; - if (suppPersons != null) { - map['suppPersons'] = suppPersons.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class ModelDefinition { - ModelDefinition({ - this.id, - this.assetName, - this.modelDefCode, - this.modelName, - this.manufacturerId, - this.manufacturerName, - this.supplierName, - this.replacementDate, - this.essentialEquipement, - this.businessCritical, - this.lifeSpan, - this.modelDefRelatedDefects, - this.suppliers, - }); - - ModelDefinition.fromJson(dynamic json) { - id = json['id']; - assetName = json['assetName']; - modelDefCode = json['modelDefCode']; - modelName = json['modelName']; - manufacturerId = json['manufacturerId']; - manufacturerName = json['manufacturerName']; - supplierName = json['supplierName']; - replacementDate = json['replacementDate']; - essentialEquipement = json['essentialEquipement']; - businessCritical = json['businessCritical']; - lifeSpan = json['lifeSpan']; - if (json['modelDefRelatedDefects'] != null) { - modelDefRelatedDefects = []; - json['modelDefRelatedDefects'].forEach((v) { - modelDefRelatedDefects.add(ModelDefRelatedDefects.fromJson(v)); - }); - } - if (json['suppliers'] != null) { - suppliers = []; - json['suppliers'].forEach((v) { - suppliers.add(Suppliers.fromJson(v)); - }); - } - } - - num id; - String assetName; - String modelDefCode; - String modelName; - num manufacturerId; - String manufacturerName; - String supplierName; - String replacementDate; - String essentialEquipement; - String businessCritical; - num lifeSpan; - List modelDefRelatedDefects; - List suppliers; - - ModelDefinition copyWith({ - num id, - String assetName, - String modelDefCode, - String modelName, - num manufacturerId, - String manufacturerName, - String supplierName, - String replacementDate, - String essentialEquipement, - String businessCritical, - num lifeSpan, - List modelDefRelatedDefects, - List suppliers, - }) => - ModelDefinition( - id: id ?? this.id, - assetName: assetName ?? this.assetName, - modelDefCode: modelDefCode ?? this.modelDefCode, - modelName: modelName ?? this.modelName, - manufacturerId: manufacturerId ?? this.manufacturerId, - manufacturerName: manufacturerName ?? this.manufacturerName, - supplierName: supplierName ?? this.supplierName, - replacementDate: replacementDate ?? this.replacementDate, - essentialEquipement: essentialEquipement ?? this.essentialEquipement, - businessCritical: businessCritical ?? this.businessCritical, - lifeSpan: lifeSpan ?? this.lifeSpan, - modelDefRelatedDefects: modelDefRelatedDefects ?? this.modelDefRelatedDefects, - suppliers: suppliers ?? this.suppliers, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['assetName'] = assetName; - map['modelDefCode'] = modelDefCode; - map['modelName'] = modelName; - map['manufacturerId'] = manufacturerId; - map['manufacturerName'] = manufacturerName; - map['supplierName'] = supplierName; - map['replacementDate'] = replacementDate; - map['essentialEquipement'] = essentialEquipement; - map['businessCritical'] = businessCritical; - map['lifeSpan'] = lifeSpan; - if (modelDefRelatedDefects != null) { - map['modelDefRelatedDefects'] = modelDefRelatedDefects.map((v) => v.toJson()).toList(); - } - if (suppliers != null) { - map['suppliers'] = suppliers.map((v) => v.toJson()).toList(); - } - return map; - } -} - -class Suppliers { - Suppliers({ - this.id, - this.suppliername, - }); - - Suppliers.fromJson(dynamic json) { - id = json['id']; - suppliername = json['suppliername']; - } - - num id; - String suppliername; - - Suppliers copyWith({ - num id, - String suppliername, - }) => - Suppliers( - id: id ?? this.id, - suppliername: suppliername ?? this.suppliername, - ); - - Map toJson() { - final map = {}; - map['id'] = id ?? 0; - map['suppliername'] = suppliername; - return map; - } -} - -class ModelDefRelatedDefects { - ModelDefRelatedDefects({ - this.id, - this.defectName, - this.workPerformed, - this.estimatedTime, - }); - - ModelDefRelatedDefects.fromJson(dynamic json) { - id = json['id']; - defectName = json['defectName']; - workPerformed = json['workPerformed']; - estimatedTime = json['estimatedTime']; - } - - num id; - String defectName; - String workPerformed; - String estimatedTime; - - ModelDefRelatedDefects copyWith({ - num id, - String defectName, - String workPerformed, - String estimatedTime, - }) => - ModelDefRelatedDefects( - id: id ?? this.id ?? 0, - defectName: defectName ?? this.defectName, - workPerformed: workPerformed ?? this.workPerformed, - estimatedTime: estimatedTime ?? this.estimatedTime, - ); - - Map toJson() { - final map = {}; - map['id'] = id; - map['defectName'] = defectName; - map['workPerformed'] = workPerformed; - map['estimatedTime'] = estimatedTime; - return map; - } -} diff --git a/lib/models/service_request/service_report.dart b/lib/models/service_request/service_report.dart new file mode 100644 index 0000000..d97a3f9 --- /dev/null +++ b/lib/models/service_request/service_report.dart @@ -0,0 +1,304 @@ +import 'dart:typed_data'; + +import 'package:test_sa/models/lookup.dart'; +import 'package:test_sa/models/service_request/spare_parts.dart'; +import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; +import 'package:test_sa/models/service_request/wo_call_request.dart'; +import 'package:test_sa/models/service_request/wo_parent.dart'; + +import '../../attachment.dart'; +import '../device/asset.dart'; +import '../fault_description.dart'; +import '../new_models/assigned_employee.dart'; +import '../new_models/assistant_employee.dart'; +import 'contact_person_work_order.dart'; + +class ServiceReport { + ServiceReport({ + this.id, + this.parentWOId, + this.workOrderNo, + this.workOrderYear, + this.workOrderSequennce, + this.callRequest, + this.assetType, + this.assignedEmployee, + this.visitDate, + this.assistantEmployees, + this.supplier, + this.vendorTicketNumber, + this.mrNumber, + this.contactPersonWorkOrders, + this.calllastSituation, + this.currentSituation, + this.repairLocation, + this.reason, + this.startofWorkTime, + this.endofWorkTime, + this.workingHours, + this.travelingHours, + this.travelingExpenses, + this.faultDescription, + this.sparePartsWorkOrders, + this.reviewComment, + this.comment, + this.attachmentsWorkOrder, + this.equipmentStatus, + this.suppEngineerWorkOrders, + this.engSignature, + this.nurseSignature, + this.woParentDto, + this.loanAvailablity, + this.assetLoan, + }); + + ServiceReport.fromJson(dynamic json) { + id = json['id']; + parentWOId = json['parentWOId']; + workOrderNo = json['workOrderNo']; + workOrderYear = json['workOrderYear']; + workOrderSequennce = json['workOrderSequennce']; + callRequest = json['callRequest'] != null ? CallRequest.fromJson(json['callRequest']) : null; + assetType = json['assetType'] != null ? Lookup.fromJson(json['assetType']) : null; + assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null; + visitDate = json['visitDate']; + if (json['assistantEmployees'] != null) { + assistantEmployees = []; + json['assistantEmployees'].forEach((v) { + assistantEmployees.add(AssistantEmployees.fromJson(v)); + }); + } + supplier = json['supplier'] != null ? SupplierDetails.fromJson(json['supplier']) : null; + vendorTicketNumber = json['vendorTicketNumber']; + mrNumber = json['mrNumber']; + if (json['contactPersonWorkOrders'] != null) { + contactPersonWorkOrders = []; + json['contactPersonWorkOrders'].forEach((v) { + contactPersonWorkOrders.add(ContactPersonWorkOrder.fromJson(v)); + }); + } + calllastSituation = json['calllastSituation'] != null ? Lookup.fromJson(json['calllastSituation']) : null; + currentSituation = json['currentSituation'] != null ? Lookup.fromJson(json['currentSituation']) : null; + repairLocation = json['repairLocation'] != null ? Lookup.fromJson(json['repairLocation']) : null; + reason = json['reason'] != null ? Lookup.fromJson(json['reason']) : null; + startofWorkTime = json['startofWorkTime']; + endofWorkTime = json['endofWorkTime']; + workingHours = json['workingHours']; + travelingHours = json['travelingHours']; + travelingExpenses = json['travelingExpenses']; + faultDescription = json['faultDescription'] != null ? FaultDescription.fromJson(json['faultDescription']) : null; + if (json['sparePartsWorkOrders'] != null) { + sparePartsWorkOrders = []; + json['sparePartsWorkOrders'].forEach((v) { + sparePartsWorkOrders.add(SparePartsWorkOrders.fromJson(v)); + }); + } + reviewComment = json['reviewComment']; + comment = json['comment']; + if (json['attachmentsWorkOrder'] != null) { + attachmentsWorkOrder = []; + json['attachmentsWorkOrder'].forEach((v) { + attachmentsWorkOrder.add(Attachment.fromJson(v)); + }); + } + equipmentStatus = json['equipmentStatus'] != null ? Lookup.fromJson(json['equipmentStatus']) : null; + if (json['suppEngineerWorkOrders'] != null) { + suppEngineerWorkOrders = []; + json['suppEngineerWorkOrders'].forEach((v) { + suppEngineerWorkOrders.add(SuppEngineerWorkOrders.fromJson(v)); + }); + } + engSignature = json['engSignature']; + nurseSignature = json['nurseSignature']; + woParentDto = json['woParentDto'] != null ? WoParent.fromJson(json['woParentDto']) : null; + loanAvailablity = json['loanAvailablity'] != null ? Lookup.fromJson(json['loanAvailablity']) : null; + assetLoan = json['assetLoan'] != null ? AssetInfo.fromJson(json['assetLoan']) : null; + } + num id; + num parentWOId; + String workOrderNo; + num workOrderYear; + num workOrderSequennce; + CallRequest callRequest; + Lookup assetType; + AssignedEmployee assignedEmployee; + String visitDate; + List assistantEmployees; + SupplierDetails supplier; + String vendorTicketNumber; + String mrNumber; + List contactPersonWorkOrders; + Lookup calllastSituation; + Lookup currentSituation; + Lookup repairLocation; + Lookup reason; + String startofWorkTime; + String endofWorkTime; + num workingHours; + num travelingHours; + num travelingExpenses; + FaultDescription faultDescription; + List sparePartsWorkOrders; + String reviewComment; + String comment; + List attachmentsWorkOrder; + Lookup equipmentStatus; + List suppEngineerWorkOrders; + String engSignature; + Uint8List localEngSignature; + String nurseSignature; + Uint8List localNurseSignature; + WoParent woParentDto; + Lookup loanAvailablity; + AssetInfo assetLoan; + ServiceReport copyWith({ + num id, + num parentWOId, + String workOrderNo, + num workOrderYear, + num workOrderSequennce, + CallRequest callRequest, + Lookup assetType, + AssignedEmployee assignedEmployee, + String visitDate, + List assistantEmployees, + SupplierDetails supplier, + String vendorTicketNumber, + String mrNumber, + List contactPersonWorkOrders, + Lookup calllastSituation, + Lookup currentSituation, + Lookup repairLocation, + Lookup reason, + String startofWorkTime, + String endofWorkTime, + num workingHours, + num travelingHours, + num travelingExpenses, + FaultDescription faultDescription, + List sparePartsWorkOrders, + String reviewComment, + String comment, + List attachmentsWorkOrder, + Lookup equipmentStatus, + List suppEngineerWorkOrders, + String engSignature, + String nurseSignature, + WoParent woParentDto, + Lookup loanAvailablity, + AssetInfo assetLoan, + }) => + ServiceReport( + id: id ?? this.id, + parentWOId: parentWOId ?? this.parentWOId, + workOrderNo: workOrderNo ?? this.workOrderNo, + workOrderYear: workOrderYear ?? this.workOrderYear, + workOrderSequennce: workOrderSequennce ?? this.workOrderSequennce, + callRequest: callRequest ?? this.callRequest, + assetType: assetType ?? this.assetType, + assignedEmployee: assignedEmployee ?? this.assignedEmployee, + visitDate: visitDate ?? this.visitDate, + assistantEmployees: assistantEmployees ?? this.assistantEmployees, + supplier: supplier ?? this.supplier, + vendorTicketNumber: vendorTicketNumber ?? this.vendorTicketNumber, + mrNumber: mrNumber ?? this.mrNumber, + contactPersonWorkOrders: contactPersonWorkOrders ?? this.contactPersonWorkOrders, + calllastSituation: calllastSituation ?? this.calllastSituation, + currentSituation: currentSituation ?? this.currentSituation, + repairLocation: repairLocation ?? this.repairLocation, + reason: reason ?? this.reason, + startofWorkTime: startofWorkTime ?? this.startofWorkTime, + endofWorkTime: endofWorkTime ?? this.endofWorkTime, + workingHours: workingHours ?? this.workingHours, + travelingHours: travelingHours ?? this.travelingHours, + travelingExpenses: travelingExpenses ?? this.travelingExpenses, + faultDescription: faultDescription ?? this.faultDescription, + sparePartsWorkOrders: sparePartsWorkOrders ?? this.sparePartsWorkOrders, + reviewComment: reviewComment ?? this.reviewComment, + comment: comment ?? this.comment, + attachmentsWorkOrder: attachmentsWorkOrder ?? this.attachmentsWorkOrder, + equipmentStatus: equipmentStatus ?? this.equipmentStatus, + suppEngineerWorkOrders: suppEngineerWorkOrders ?? this.suppEngineerWorkOrders, + engSignature: engSignature ?? this.engSignature, + nurseSignature: nurseSignature ?? this.nurseSignature, + woParentDto: woParentDto ?? this.woParentDto, + loanAvailablity: loanAvailablity ?? this.loanAvailablity, + assetLoan: assetLoan ?? this.assetLoan, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['parentWOId'] = parentWOId; + map['workOrderNo'] = workOrderNo; + map['workOrderYear'] = workOrderYear; + map['workOrderSequennce'] = workOrderSequennce; + if (callRequest != null) { + map['callRequest'] = callRequest.toJson(); + } + if (assetType != null) { + map['assetType'] = assetType.toJson(); + } + if (assignedEmployee != null) { + map['assignedEmployee'] = assignedEmployee.toJson(); + } + map['visitDate'] = visitDate; + if (assistantEmployees != null) { + map['assistantEmployees'] = assistantEmployees.map((v) => v.toJson()).toList(); + } + if (supplier != null) { + map['supplier'] = supplier.toJson(); + } + map['vendorTicketNumber'] = vendorTicketNumber; + map['mrNumber'] = mrNumber; + if (contactPersonWorkOrders != null) { + map['contactPersonWorkOrders'] = contactPersonWorkOrders.map((v) => v.toJson()).toList(); + } + if (calllastSituation != null) { + map['calllastSituation'] = calllastSituation.toJson(); + } + if (currentSituation != null) { + map['currentSituation'] = currentSituation.toJson(); + } + if (repairLocation != null) { + map['repairLocation'] = repairLocation.toJson(); + } + if (reason != null) { + map['reason'] = reason.toJson(); + } + map['startofWorkTime'] = startofWorkTime; + map['endofWorkTime'] = endofWorkTime; + map['workingHours'] = workingHours; + map['travelingHours'] = travelingHours; + map['travelingExpenses'] = travelingExpenses; + if (faultDescription != null) { + map['faultDescription'] = faultDescription.toJson(); + } + if (sparePartsWorkOrders != null) { + map['sparePartsWorkOrders'] = sparePartsWorkOrders.map((v) => v.toJson()).toList(); + } + map['reviewComment'] = reviewComment; + map['comment'] = comment; + if (attachmentsWorkOrder != null) { + map['attachmentsWorkOrder'] = attachmentsWorkOrder.map((v) => v.toJson()).toList(); + } + if (equipmentStatus != null) { + map['equipmentStatus'] = equipmentStatus.toJson(); + } + if (suppEngineerWorkOrders != null) { + map['suppEngineerWorkOrders'] = suppEngineerWorkOrders.map((v) => v.toJson()).toList(); + } + map['engSignature'] = engSignature; + map['nurseSignature'] = nurseSignature; + if (woParentDto != null) { + map['woParentDto'] = woParentDto.toJson(); + } + if (loanAvailablity != null) { + map['loanAvailablity'] = loanAvailablity.toJson(); + } + if (assetLoan != null) { + map['assetLoan'] = assetLoan.toJson(); + } + return map; + } +} diff --git a/lib/models/service_request/service_request_search.dart b/lib/models/service_request/service_request_search.dart index d461c62..19dc1d4 100644 --- a/lib/models/service_request/service_request_search.dart +++ b/lib/models/service_request/service_request_search.dart @@ -1,7 +1,7 @@ import 'package:test_sa/models/hospital.dart'; import 'package:test_sa/models/lookup.dart'; -import '../call_request_for_work_order_model.dart'; +import '../new_models/assigned_employee.dart'; class ServiceRequestSearch { String callId; diff --git a/lib/models/service_request/spare_parts.dart b/lib/models/service_request/spare_parts.dart new file mode 100644 index 0000000..cd981eb --- /dev/null +++ b/lib/models/service_request/spare_parts.dart @@ -0,0 +1,91 @@ +import '../base.dart'; + +class SparePartsWorkOrders extends Base { + SparePartsWorkOrders({ + this.id, + this.sparePart, + this.qty, + this.returnQty, + this.installQty, + }) : super(identifier: id?.toString(), name: sparePart?.partName); + + SparePartsWorkOrders.fromJson(dynamic json) { + id = json['id']; + sparePart = json['sparePart'] != null ? SparePart.fromJson(json['sparePart']) : null; + qty = json['qty']; + returnQty = json['returnQty']; + installQty = json['installQty']; + } + num id; + SparePart sparePart; + num qty; + num returnQty; + num installQty; + SparePartsWorkOrders copyWith({ + num id, + SparePart sparePart, + num qty, + num returnQty, + num installQty, + }) => + SparePartsWorkOrders( + id: id ?? this.id, + sparePart: sparePart ?? this.sparePart, + qty: qty ?? this.qty, + returnQty: returnQty ?? this.returnQty, + installQty: installQty ?? this.installQty, + ); + Map toJson() { + final map = {}; + map['id'] = id; + if (sparePart != null) { + map['sparePart'] = sparePart.toJson(); + } + map['qty'] = qty; + map['returnQty'] = returnQty; + map['installQty'] = installQty; + return map; + } +} + +class SparePart extends Base { + SparePart({ + this.id, + this.partNo, + this.partName, + this.assetId, + }) : super(identifier: id?.toString(), name: partName); + + SparePart.fromJson(dynamic json) { + id = json['id']; + identifier = id?.toString(); + partNo = json['partNo']; + partName = json['partName']; + name = partName; + assetId = json['assetId']; + } + num id; + String partNo; + String partName; + num assetId; + SparePart copyWith({ + num id, + String partNo, + String partName, + num assetId, + }) => + SparePart( + id: id ?? this.id, + partNo: partNo ?? this.partNo, + partName: partName ?? this.partName, + assetId: assetId ?? this.assetId, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['partNo'] = partNo; + map['partName'] = partName; + map['assetId'] = assetId; + return map; + } +} diff --git a/lib/models/service_request/sub_work_order_details.dart b/lib/models/service_request/sub_work_order_details.dart index 48bcdcc..1c78ed4 100644 --- a/lib/models/service_request/sub_work_order_details.dart +++ b/lib/models/service_request/sub_work_order_details.dart @@ -1,73 +1,73 @@ -import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/service_request/search_work_order.dart'; - -import '../fault_description.dart'; - -class SubWorkOrderDetails { - Lookup equipmentStatus; - Lookup reason; - FaultDescription faultDescription; - List sparePartsWorkOrders; - List suppEngineerWorkOrders; - SupplierModel supplier; - - SubWorkOrderDetails({ - this.equipmentStatus, - this.reason, - this.faultDescription, - this.sparePartsWorkOrders, - this.supplier, - this.suppEngineerWorkOrders, - }); - - SubWorkOrderDetails.fromJson(dynamic json) { - if (json['equipmentStatus'] != null) equipmentStatus = Lookup.fromJson(json['equipmentStatus']); - if (json['reason'] != null) reason = Lookup.fromJson(json['reason']); - if (json['faultDescription'] != null) faultDescription = FaultDescription.fromJson(json['faultDescription']); - if (json['supplier'] != null) supplier = SupplierModel.fromJson(json['supplier']); - if (json['sparePartsWorkOrders'] != null) { - sparePartsWorkOrders = []; - json['sparePartsWorkOrders'].forEach((v) { - sparePartsWorkOrders.add(SparePartsWorkOrders.fromJson(v)); - }); - } - if (json['suppEngineerWorkOrders'] != null) { - suppEngineerWorkOrders = []; - json['suppEngineerWorkOrders'].forEach((v) { - suppEngineerWorkOrders.add(SuppEngineerWorkOrders.fromJson(v)); - }); - } - } - - SubWorkOrderDetails copyWith({ - Lookup equipmentStatus, - Lookup reason, - FaultDescription faultDescription, - List sparePartsWorkOrders, - SupplierModel supplier, - SuppEngineerWorkOrders suppEngineerWorkOrders, - }) => - SubWorkOrderDetails( - equipmentStatus: equipmentStatus ?? this.equipmentStatus, - reason: reason ?? this.reason, - faultDescription: faultDescription ?? this.faultDescription, - sparePartsWorkOrders: sparePartsWorkOrders ?? this.sparePartsWorkOrders, - supplier: supplier ?? this.supplier, - suppEngineerWorkOrders: suppEngineerWorkOrders ?? this.suppEngineerWorkOrders, - ); - - Map toJson() { - final map = {}; - map['equipmentStatus'] = equipmentStatus?.toJson(); - map['reason'] = reason?.toJson(); - map['faultDescription'] = faultDescription?.toJson(); - if (sparePartsWorkOrders?.isNotEmpty ?? false) { - map['sparePartsWorkOrders'] = sparePartsWorkOrders?.map((e) => e.toJson())?.toList(); - } - if (suppEngineerWorkOrders?.isNotEmpty ?? false) { - map['suppEngineerWorkOrders'] = suppEngineerWorkOrders?.map((e) => e.toJson())?.toList(); - } - map['supplier'] = supplier?.toJson(); - return map; - } -} +// import 'package:test_sa/models/lookup.dart'; +// import 'package:test_sa/models/service_request/search_work_order.dart'; +// +// import '../fault_description.dart'; +// +// class SubWorkOrderDetails { +// Lookup equipmentStatus; +// Lookup reason; +// FaultDescription faultDescription; +// List sparePartsWorkOrders; +// List suppEngineerWorkOrders; +// SupplierModel supplier; +// +// SubWorkOrderDetails({ +// this.equipmentStatus, +// this.reason, +// this.faultDescription, +// this.sparePartsWorkOrders, +// this.supplier, +// this.suppEngineerWorkOrders, +// }); +// +// SubWorkOrderDetails.fromJson(dynamic json) { +// if (json['equipmentStatus'] != null) equipmentStatus = Lookup.fromJson(json['equipmentStatus']); +// if (json['reason'] != null) reason = Lookup.fromJson(json['reason']); +// if (json['faultDescription'] != null) faultDescription = FaultDescription.fromJson(json['faultDescription']); +// if (json['supplier'] != null) supplier = SupplierModel.fromJson(json['supplier']); +// if (json['sparePartsWorkOrders'] != null) { +// sparePartsWorkOrders = []; +// json['sparePartsWorkOrders'].forEach((v) { +// sparePartsWorkOrders.add(SparePartsWorkOrders.fromJson(v)); +// }); +// } +// if (json['suppEngineerWorkOrders'] != null) { +// suppEngineerWorkOrders = []; +// json['suppEngineerWorkOrders'].forEach((v) { +// suppEngineerWorkOrders.add(SuppEngineerWorkOrders.fromJson(v)); +// }); +// } +// } +// +// SubWorkOrderDetails copyWith({ +// Lookup equipmentStatus, +// Lookup reason, +// FaultDescription faultDescription, +// List sparePartsWorkOrders, +// SupplierModel supplier, +// SuppEngineerWorkOrders suppEngineerWorkOrders, +// }) => +// SubWorkOrderDetails( +// equipmentStatus: equipmentStatus ?? this.equipmentStatus, +// reason: reason ?? this.reason, +// faultDescription: faultDescription ?? this.faultDescription, +// sparePartsWorkOrders: sparePartsWorkOrders ?? this.sparePartsWorkOrders, +// supplier: supplier ?? this.supplier, +// suppEngineerWorkOrders: suppEngineerWorkOrders ?? this.suppEngineerWorkOrders, +// ); +// +// Map toJson() { +// final map = {}; +// map['equipmentStatus'] = equipmentStatus?.toJson(); +// map['reason'] = reason?.toJson(); +// map['faultDescription'] = faultDescription?.toJson(); +// if (sparePartsWorkOrders?.isNotEmpty ?? false) { +// map['sparePartsWorkOrders'] = sparePartsWorkOrders?.map((e) => e.toJson())?.toList(); +// } +// if (suppEngineerWorkOrders?.isNotEmpty ?? false) { +// map['suppEngineerWorkOrders'] = suppEngineerWorkOrders?.map((e) => e.toJson())?.toList(); +// } +// map['supplier'] = supplier?.toJson(); +// return map; +// } +// } diff --git a/lib/models/service_request/supp_engineer_work_orders.dart b/lib/models/service_request/supp_engineer_work_orders.dart new file mode 100644 index 0000000..e70034b --- /dev/null +++ b/lib/models/service_request/supp_engineer_work_orders.dart @@ -0,0 +1,57 @@ +class SuppEngineerWorkOrders { + SuppEngineerWorkOrders({ + this.id, + this.supplierContactId, + this.personName, + this.personRoleName, + this.contact, + this.externalEngCode, + this.email, + }); + + SuppEngineerWorkOrders.fromJson(dynamic json) { + id = json['id']; + supplierContactId = json['supplierContactId']; + personName = json['personName']; + personRoleName = json['personRoleName']; + contact = json['contact']; + externalEngCode = json['externalEngCode']; + email = json['email']; + } + num id; + num supplierContactId; + String personName; + String personRoleName; + String contact; + String externalEngCode; + String email; + SuppEngineerWorkOrders copyWith({ + num id, + num supplierContactId, + String personName, + String personRoleName, + String contact, + String externalEngCode, + String email, + }) => + SuppEngineerWorkOrders( + id: id ?? this.id, + supplierContactId: supplierContactId ?? this.supplierContactId, + personName: personName ?? this.personName, + personRoleName: personRoleName ?? this.personRoleName, + contact: contact ?? this.contact, + externalEngCode: externalEngCode ?? this.externalEngCode, + email: email ?? this.email, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierContactId'] = supplierContactId; + map['personName'] = personName; + map['personRoleName'] = personRoleName; + map['contact'] = contact; + map['externalEngCode'] = externalEngCode; + map['email'] = email; + return map; + } +} diff --git a/lib/models/service_request/supplier_details.dart b/lib/models/service_request/supplier_details.dart new file mode 100644 index 0000000..a4f9b29 --- /dev/null +++ b/lib/models/service_request/supplier_details.dart @@ -0,0 +1,411 @@ +class SupplierDetails { + SupplierDetails({ + this.id, + this.suppliername, + this.name, + this.website, + this.email, + this.code, + this.suppNo, + this.suppStatusId, + this.cityId, + this.person, + this.comment, + this.zipcode, + this.contact, + this.telephones, + this.faxes, + this.addresses, + this.attachments, + this.suppPersons, + this.suppTCodes, + }); + + SupplierDetails.fromJson(dynamic json) { + id = json['id']; + suppliername = json['suppliername']; + name = json['name']; + website = json['website']; + email = json['email']; + code = json['code']; + suppNo = json['suppNo']; + suppStatusId = json['suppStatusId']; + cityId = json['cityId']; + person = json['person']; + comment = json['comment']; + zipcode = json['zipcode']; + contact = json['contact']; + if (json['telephones'] != null) { + telephones = []; + json['telephones'].forEach((v) { + telephones.add(Telephones.fromJson(v)); + }); + } + if (json['faxes'] != null) { + faxes = []; + json['faxes'].forEach((v) { + faxes.add(Faxes.fromJson(v)); + }); + } + if (json['addresses'] != null) { + addresses = []; + json['addresses'].forEach((v) { + addresses.add(Addresses.fromJson(v)); + }); + } + if (json['attachments'] != null) { + attachments = []; + json['attachments'].forEach((v) { + attachments.add(Attachments.fromJson(v)); + }); + } + if (json['suppPersons'] != null) { + suppPersons = []; + json['suppPersons'].forEach((v) { + suppPersons.add(SuppPersons.fromJson(v)); + }); + } + if (json['suppTCodes'] != null) { + suppTCodes = []; + json['suppTCodes'].forEach((v) { + suppTCodes.add(SuppTCodes.fromJson(v)); + }); + } + } + num id; + String suppliername; + String name; + String website; + String email; + String code; + num suppNo; + num suppStatusId; + num cityId; + String person; + String comment; + num zipcode; + String contact; + List telephones; + List faxes; + List addresses; + List attachments; + List suppPersons; + List suppTCodes; + SupplierDetails copyWith({ + num id, + String suppliername, + String name, + String website, + String email, + String code, + num suppNo, + num suppStatusId, + num cityId, + String person, + String comment, + num zipcode, + String contact, + List telephones, + List faxes, + List addresses, + List attachments, + List suppPersons, + List suppTCodes, + }) => + SupplierDetails( + id: id ?? this.id, + suppliername: suppliername ?? this.suppliername, + name: name ?? this.name, + website: website ?? this.website, + email: email ?? this.email, + code: code ?? this.code, + suppNo: suppNo ?? this.suppNo, + suppStatusId: suppStatusId ?? this.suppStatusId, + cityId: cityId ?? this.cityId, + person: person ?? this.person, + comment: comment ?? this.comment, + zipcode: zipcode ?? this.zipcode, + contact: contact ?? this.contact, + telephones: telephones ?? this.telephones, + faxes: faxes ?? this.faxes, + addresses: addresses ?? this.addresses, + attachments: attachments ?? this.attachments, + suppPersons: suppPersons ?? this.suppPersons, + suppTCodes: suppTCodes ?? this.suppTCodes, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['suppliername'] = suppliername; + map['name'] = name; + map['website'] = website; + map['email'] = email; + map['code'] = code; + map['suppNo'] = suppNo; + map['suppStatusId'] = suppStatusId; + map['cityId'] = cityId; + map['person'] = person; + map['comment'] = comment; + map['zipcode'] = zipcode; + map['contact'] = contact; + if (telephones != null) { + map['telephones'] = telephones.map((v) => v.toJson()).toList(); + } + if (faxes != null) { + map['faxes'] = faxes.map((v) => v.toJson()).toList(); + } + if (addresses != null) { + map['addresses'] = addresses.map((v) => v.toJson()).toList(); + } + if (attachments != null) { + map['attachments'] = attachments.map((v) => v.toJson()).toList(); + } + if (suppPersons != null) { + map['suppPersons'] = suppPersons.map((v) => v.toJson()).toList(); + } + if (suppTCodes != null) { + map['suppTCodes'] = suppTCodes.map((v) => v.toJson()).toList(); + } + return map; + } +} + +class SuppTCodes { + SuppTCodes({ + this.id, + this.supplierId, + this.codeTypeId, + this.codeValue, + }); + + SuppTCodes.fromJson(dynamic json) { + id = json['id']; + supplierId = json['supplierId']; + codeTypeId = json['codeTypeId']; + codeValue = json['codeValue']; + } + num id; + num supplierId; + num codeTypeId; + String codeValue; + SuppTCodes copyWith({ + num id, + num supplierId, + num codeTypeId, + String codeValue, + }) => + SuppTCodes( + id: id ?? this.id, + supplierId: supplierId ?? this.supplierId, + codeTypeId: codeTypeId ?? this.codeTypeId, + codeValue: codeValue ?? this.codeValue, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierId'] = supplierId; + map['codeTypeId'] = codeTypeId; + map['codeValue'] = codeValue; + return map; + } +} + +class SuppPersons { + SuppPersons({ + this.id, + this.supplierId, + this.personName, + this.personRoleId, + this.contact, + this.externalEngCode, + this.email, + }); + + SuppPersons.fromJson(dynamic json) { + id = json['id']; + supplierId = json['supplierId']; + personName = json['personName']; + personRoleId = json['personRoleId']; + contact = json['contact']; + externalEngCode = json['externalEngCode']; + email = json['email']; + } + num id; + num supplierId; + String personName; + num personRoleId; + String contact; + String externalEngCode; + String email; + SuppPersons copyWith({ + num id, + num supplierId, + String personName, + num personRoleId, + String contact, + String externalEngCode, + String email, + }) => + SuppPersons( + id: id ?? this.id, + supplierId: supplierId ?? this.supplierId, + personName: personName ?? this.personName, + personRoleId: personRoleId ?? this.personRoleId, + contact: contact ?? this.contact, + externalEngCode: externalEngCode ?? this.externalEngCode, + email: email ?? this.email, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierId'] = supplierId; + map['personName'] = personName; + map['personRoleId'] = personRoleId; + map['contact'] = contact; + map['externalEngCode'] = externalEngCode; + map['email'] = email; + return map; + } +} + +class Attachments { + Attachments({ + this.id, + this.supplierId, + this.attachmentName, + this.attachmentURL, + }); + + Attachments.fromJson(dynamic json) { + id = json['id']; + supplierId = json['supplierId']; + attachmentName = json['attachmentName']; + attachmentURL = json['attachmentURL']; + } + num id; + num supplierId; + String attachmentName; + String attachmentURL; + Attachments copyWith({ + num id, + num supplierId, + String attachmentName, + String attachmentURL, + }) => + Attachments( + id: id ?? this.id, + supplierId: supplierId ?? this.supplierId, + attachmentName: attachmentName ?? this.attachmentName, + attachmentURL: attachmentURL ?? this.attachmentURL, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierId'] = supplierId; + map['attachmentName'] = attachmentName; + map['attachmentURL'] = attachmentURL; + return map; + } +} + +class Addresses { + Addresses({ + this.id, + this.supplierId, + this.address, + }); + + Addresses.fromJson(dynamic json) { + id = json['id']; + supplierId = json['supplierId']; + address = json['address']; + } + num id; + num supplierId; + String address; + Addresses copyWith({ + num id, + num supplierId, + String address, + }) => + Addresses( + id: id ?? this.id, + supplierId: supplierId ?? this.supplierId, + address: address ?? this.address, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierId'] = supplierId; + map['address'] = address; + return map; + } +} + +class Faxes { + Faxes({ + this.id, + this.supplierId, + this.fax, + }); + + Faxes.fromJson(dynamic json) { + id = json['id']; + supplierId = json['supplierId']; + fax = json['fax']; + } + num id; + num supplierId; + String fax; + Faxes copyWith({ + num id, + num supplierId, + String fax, + }) => + Faxes( + id: id ?? this.id, + supplierId: supplierId ?? this.supplierId, + fax: fax ?? this.fax, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierId'] = supplierId; + map['fax'] = fax; + return map; + } +} + +class Telephones { + Telephones({ + this.id, + this.supplierId, + this.telephone, + }); + + Telephones.fromJson(dynamic json) { + id = json['id']; + supplierId = json['supplierId']; + telephone = json['telephone']; + } + num id; + num supplierId; + String telephone; + Telephones copyWith({ + num id, + num supplierId, + String telephone, + }) => + Telephones( + id: id ?? this.id, + supplierId: supplierId ?? this.supplierId, + telephone: telephone ?? this.telephone, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['supplierId'] = supplierId; + map['telephone'] = telephone; + return map; + } +} diff --git a/lib/models/service_request/wo_call_request.dart b/lib/models/service_request/wo_call_request.dart new file mode 100644 index 0000000..c9d1a63 --- /dev/null +++ b/lib/models/service_request/wo_call_request.dart @@ -0,0 +1,122 @@ +import 'package:test_sa/models/new_models/assigned_employee.dart'; + +import '../device/asset.dart'; +import '../lookup.dart'; +import 'call_site_contact_person.dart'; + +class CallRequest { + CallRequest({ + this.id, + this.callNo, + this.callComments, + this.asset, + this.assignedEmployee, + this.callSiteContactPerson, + this.status, + this.callLastSituation, + this.defectType, + this.firstAction, + this.loanAvailablity, + this.assetLoan, + this.assetType, + }); + + CallRequest.fromJson(dynamic json) { + id = json['id']; + callNo = json['callNo']; + callComments = json['callComments']; + asset = json['asset'] != null ? Asset.fromJson(json['asset']) : null; + assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null; + if (json['callSiteContactPerson'] != null) { + callSiteContactPerson = []; + json['callSiteContactPerson'].forEach((v) { + callSiteContactPerson.add(CallSiteContactPerson.fromJson(v)); + }); + } + status = json['status'] != null ? Lookup.fromJson(json['status']) : null; + callLastSituation = json['callLastSituation'] != null ? Lookup.fromJson(json['callLastSituation']) : null; + defectType = json['defectType'] != null ? Lookup.fromJson(json['defectType']) : null; + firstAction = json['firstAction'] != null ? Lookup.fromJson(json['firstAction']) : null; + loanAvailablity = json['loanAvailablity'] != null ? Lookup.fromJson(json['loanAvailablity']) : null; + assetLoan = json['assetLoan'] != null ? AssetInfo.fromJson(json['assetLoan']) : null; + assetType = json['assetType']; + } + num id; + String callNo; + String callComments; + Asset asset; + AssignedEmployee assignedEmployee; + List callSiteContactPerson; + Lookup status; + Lookup callLastSituation; + Lookup defectType; + Lookup firstAction; + Lookup loanAvailablity; + AssetInfo assetLoan; + num assetType; + CallRequest copyWith({ + num id, + String callNo, + String callComments, + Asset asset, + AssignedEmployee assignedEmployee, + List callSiteContactPerson, + Lookup status, + Lookup callLastSituation, + Lookup defectType, + Lookup firstAction, + Lookup loanAvailablity, + AssetInfo assetLoan, + num assetType, + }) => + CallRequest( + id: id ?? this.id, + callNo: callNo ?? this.callNo, + callComments: callComments ?? this.callComments, + asset: asset ?? this.asset, + assignedEmployee: assignedEmployee ?? this.assignedEmployee, + callSiteContactPerson: callSiteContactPerson ?? this.callSiteContactPerson, + status: status ?? this.status, + callLastSituation: callLastSituation ?? this.callLastSituation, + defectType: defectType ?? this.defectType, + firstAction: firstAction ?? this.firstAction, + loanAvailablity: loanAvailablity ?? this.loanAvailablity, + assetLoan: assetLoan ?? this.assetLoan, + assetType: assetType ?? this.assetType, + ); + Map toJson() { + final map = {}; + map['id'] = id; + map['callNo'] = callNo; + map['callComments'] = callComments; + if (asset != null) { + map['asset'] = asset.toJson(); + } + if (assignedEmployee != null) { + map['assignedEmployee'] = assignedEmployee.toJson(); + } + if (callSiteContactPerson != null) { + map['callSiteContactPerson'] = callSiteContactPerson.map((v) => v.toJson()).toList(); + } + if (status != null) { + map['status'] = status.toJson(); + } + if (callLastSituation != null) { + map['callLastSituation'] = callLastSituation.toJson(); + } + if (defectType != null) { + map['defectType'] = defectType.toJson(); + } + if (firstAction != null) { + map['firstAction'] = firstAction.toJson(); + } + if (loanAvailablity != null) { + map['loanAvailablity'] = loanAvailablity.toJson(); + } + if (assetLoan != null) { + map['assetLoan'] = assetLoan.toJson(); + } + map['assetType'] = assetType; + return map; + } +} diff --git a/lib/models/service_request/wo_parent.dart b/lib/models/service_request/wo_parent.dart new file mode 100644 index 0000000..e8b9b3e --- /dev/null +++ b/lib/models/service_request/wo_parent.dart @@ -0,0 +1,163 @@ +import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; + +import '../lookup.dart'; + +class WoParent { + WoParent({ + this.callLastSituation, + this.supplier, + this.assetType, + this.vendorTicketNumber, + this.callId, + this.id, + this.stepsWorkOrder, + this.suppEngineerWorkOrders, + this.equipmentStatus, + this.currentSituation, + }); + + WoParent.fromJson(dynamic json) { + callLastSituation = json['callLastSituation'] != null ? Lookup.fromJson(json['callLastSituation']) : null; + supplier = json['supplier'] != null ? SupplierDetails.fromJson(json['supplier']) : null; + assetType = json['assetType'] != null ? Lookup.fromJson(json['assetType']) : null; + vendorTicketNumber = json['vendorTicketNumber']; + callId = json['callId']; + id = json['id']; + stepsWorkOrder = json['stepsWorkOrderDto'] != null ? StepsWorkOrder.fromJson(json['stepsWorkOrderDto']) : null; + if (json['suppEngineerWorkOrders'] != null) { + suppEngineerWorkOrders = []; + json['suppEngineerWorkOrders'].forEach((v) { + suppEngineerWorkOrders.add(SuppEngineerWorkOrders.fromJson(v)); + }); + } + equipmentStatus = json['equipmentStatus'] != null ? Lookup.fromJson(json['equipmentStatus']) : null; + currentSituation = json['currentSituation'] != null ? Lookup.fromJson(json['currentSituation']) : null; + } + Lookup callLastSituation; + SupplierDetails supplier; + Lookup assetType; + String vendorTicketNumber; + num callId; + num id; + StepsWorkOrder stepsWorkOrder; + List suppEngineerWorkOrders; + Lookup equipmentStatus; + Lookup currentSituation; + WoParent copyWith({ + Lookup callLastSituation, + SupplierDetails supplier, + Lookup assetType, + String vendorTicketNumber, + num callId, + num id, + StepsWorkOrder stepsWorkOrder, + List suppEngineerWorkOrders, + Lookup equipmentStatus, + Lookup currentSituation, + }) => + WoParent( + callLastSituation: callLastSituation ?? this.callLastSituation, + supplier: supplier ?? this.supplier, + assetType: assetType ?? this.assetType, + vendorTicketNumber: vendorTicketNumber ?? this.vendorTicketNumber, + callId: callId ?? this.callId, + id: id ?? this.id, + stepsWorkOrder: stepsWorkOrder ?? this.stepsWorkOrder, + suppEngineerWorkOrders: suppEngineerWorkOrders ?? this.suppEngineerWorkOrders, + equipmentStatus: equipmentStatus ?? this.equipmentStatus, + currentSituation: currentSituation ?? this.currentSituation, + ); + Map toJson() { + final map = {}; + if (callLastSituation != null) { + map['callLastSituation'] = callLastSituation.toJson(); + } + if (supplier != null) { + map['supplier'] = supplier.toJson(); + } + if (assetType != null) { + map['assetType'] = assetType.toJson(); + } + map['vendorTicketNumber'] = vendorTicketNumber; + map['callId'] = callId; + map['id'] = id; + if (stepsWorkOrder != null) { + map['stepsWorkOrderDto'] = stepsWorkOrder.toJson(); + } + if (suppEngineerWorkOrders != null) { + map['suppEngineerWorkOrders'] = suppEngineerWorkOrders.map((v) => v.toJson()).toList(); + } + if (equipmentStatus != null) { + map['equipmentStatus'] = equipmentStatus.toJson(); + } + if (currentSituation != null) { + map['currentSituation'] = currentSituation.toJson(); + } + return map; + } +} + +class StepsWorkOrder { + StepsWorkOrder({ + this.sequence, + this.id, + this.name, + this.statusValue, + this.typeTransaction, + this.processed, + this.parentWOId, + this.callId, + }); + + StepsWorkOrder.fromJson(dynamic json) { + sequence = json['sequence']; + id = json['id']; + name = json['name']; + statusValue = json['statusValue']; + typeTransaction = json['typeTransaction']; + processed = json['processed']; + parentWOId = json['parentWOId']; + callId = json['callId']; + } + num sequence; + num id; + String name; + num statusValue; + String typeTransaction; + bool processed; + num parentWOId; + num callId; + StepsWorkOrder copyWith({ + num sequence, + num id, + String name, + num statusValue, + String typeTransaction, + bool processed, + num parentWOId, + num callId, + }) => + StepsWorkOrder( + sequence: sequence ?? this.sequence, + id: id ?? this.id, + name: name ?? this.name, + statusValue: statusValue ?? this.statusValue, + typeTransaction: typeTransaction ?? this.typeTransaction, + processed: processed ?? this.processed, + parentWOId: parentWOId ?? this.parentWOId, + callId: callId ?? this.callId, + ); + Map toJson() { + final map = {}; + map['sequence'] = sequence; + map['id'] = id; + map['name'] = name; + map['statusValue'] = statusValue; + map['typeTransaction'] = typeTransaction; + map['processed'] = processed; + map['parentWOId'] = parentWOId; + map['callId'] = callId; + return map; + } +} diff --git a/lib/providers/work_order/reason_provider.dart b/lib/providers/work_order/reason_provider.dart new file mode 100644 index 0000000..39830c2 --- /dev/null +++ b/lib/providers/work_order/reason_provider.dart @@ -0,0 +1,36 @@ +import 'dart:convert'; + +import 'package:http/http.dart'; +import 'package:test_sa/providers/loading_list_notifier.dart'; + +import '../../controllers/api_routes/api_manager.dart'; +import '../../controllers/api_routes/urls.dart'; +import '../../models/lookup.dart'; + +class ReasonProvider extends LoadingListNotifier { + @override + Future getDate() async { + if (loading == true) return -2; + loading = true; + notifyListeners(); + loading = true; + notifyListeners(); + try { + Response response = await ApiManager.instance.get(URLs.getServiceReportReasons); + stateCode = response.statusCode; + if (response.statusCode >= 200 && response.statusCode < 300) { + // client's request was successfully received + List categoriesListJson = json.decode(response.body)["data"]; + items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList(); + } + loading = false; + notifyListeners(); + return response.statusCode; + } catch (error) { + loading = false; + stateCode = -1; + notifyListeners(); + return -1; + } + } +} diff --git a/lib/providers/work_order/service_type_provider.dart b/lib/providers/work_order/service_type_provider.dart new file mode 100644 index 0000000..824a7ae --- /dev/null +++ b/lib/providers/work_order/service_type_provider.dart @@ -0,0 +1,36 @@ +import 'dart:convert'; + +import 'package:http/http.dart'; +import 'package:test_sa/providers/loading_list_notifier.dart'; + +import '../../controllers/api_routes/api_manager.dart'; +import '../../controllers/api_routes/urls.dart'; +import '../../models/lookup.dart'; + +class ServiceTypeProvider extends LoadingListNotifier { + @override + Future getDate() async { + if (loading == true) return -2; + loading = true; + notifyListeners(); + loading = true; + notifyListeners(); + try { + Response response = await ApiManager.instance.get(URLs.getServiceReportTypes); + stateCode = response.statusCode; + if (response.statusCode >= 200 && response.statusCode < 300) { + // client's request was successfully received + List categoriesListJson = json.decode(response.body)["data"]; + items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList(); + } + loading = false; + notifyListeners(); + return response.statusCode; + } catch (error) { + loading = false; + stateCode = -1; + notifyListeners(); + return -1; + } + } +} diff --git a/lib/views/pages/sub_workorder/auto_generated_vendor_name.dart b/lib/views/pages/sub_workorder/auto_generated_vendor_name.dart index 41244de..7275a7b 100644 --- a/lib/views/pages/sub_workorder/auto_generated_vendor_name.dart +++ b/lib/views/pages/sub_workorder/auto_generated_vendor_name.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:provider/provider.dart'; -import 'package:test_sa/models/service_request/search_work_order.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; import '../../../controllers/providers/api/status_drop_down/report/vendor_provider.dart'; import '../../app_style/colors.dart'; @@ -9,7 +9,7 @@ import '../../app_style/sizing.dart'; class AutoGeneratedVendorName extends StatefulWidget { final String initialValue; - final Function(Supplier) onSearch; + final Function(SupplierDetails) onSearch; const AutoGeneratedVendorName({Key key, this.initialValue, this.onSearch}) : super(key: key); @override @@ -55,7 +55,7 @@ class _AutoGeneratedVendorNameState extends State { // AppStyle.boxShadow // ] ), - child: TypeAheadField( + child: TypeAheadField( textFieldConfiguration: TextFieldConfiguration( style: Theme.of(context).textTheme.titleLarge, controller: _controller, 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 6604135..5eba98c 100644 --- a/lib/views/pages/sub_workorder/create_sub_workorder_page.dart +++ b/lib/views/pages/sub_workorder/create_sub_workorder_page.dart @@ -9,10 +9,9 @@ import 'package:test_sa/controllers/providers/api/service_requests_provider.dart import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_types_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; -import 'package:test_sa/models/call_request_for_work_order_model.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/service_report.dart'; import 'package:test_sa/models/service_request/search_work_order.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart'; import 'package:test_sa/views/pages/sub_workorder/work_order_details_bottom_sheet.dart'; @@ -21,8 +20,10 @@ import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; import 'package:test_sa/views/widgets/status/service_request/service_request_defect_types_mune.dart'; +import '../../../attachment.dart'; import '../../../controllers/api_routes/http_status_manger.dart'; import '../../../controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart'; +import '../../../models/service_request/wo_call_request.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/buttons/app_back_button.dart'; import '../../widgets/buttons/app_button.dart'; @@ -59,13 +60,13 @@ class _CreateSubWorkOrderPageState extends State { supplier: null, parentWOId: widget.workOrder.id, ); - _serviceReport = ServiceReport(id: widget.workOrder.id, type: widget.workOrder.assetType, equipmentStatus: widget.workOrder.equipmentStatus); + _serviceReport = ServiceReport(id: widget.workOrder.id, assetType: widget.workOrder.assetType, equipmentStatus: widget.workOrder.equipmentStatus); _isLoading = true; super.initState(); } var assetTypesProvider; - CallRequestForWorkOrder _callRequestForWorkOrder; + CallRequest _callRequestForWorkOrder; Future getAssetType() async { //if (assetTypesProvider == null) { @@ -335,7 +336,7 @@ class _CreateSubWorkOrderPageState extends State { } _subWorkOrders.attachmentsWorkOrder ??= []; for (var file in _files) { - _subWorkOrders.attachmentsWorkOrder.add(AttachmentsWorkOrder(name: "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}")); + _subWorkOrders.attachmentsWorkOrder.add(Attachment(name: "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}")); } if (_subWorkOrders.timer?.startAt == null || _subWorkOrders.timer?.endAt == null) { Fluttertoast.showToast(msg: "Working hours required"); diff --git a/lib/views/pages/sub_workorder/search_sub_workorder_page.dart b/lib/views/pages/sub_workorder/search_sub_workorder_page.dart index 40c2294..91c9a25 100644 --- a/lib/views/pages/sub_workorder/search_sub_workorder_page.dart +++ b/lib/views/pages/sub_workorder/search_sub_workorder_page.dart @@ -5,15 +5,14 @@ import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/models/engineer.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/service_request/search_work_order.dart'; -import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/pages/sub_workorder/workorder_list.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/date_and_time/date_picker.dart'; import 'package:test_sa/views/widgets/hospitals/hospital_auto_complete_field_new.dart'; import '../../../controllers/api_routes/http_status_manger.dart'; -import '../../../controllers/localization/localization.dart'; import '../../../controllers/providers/api/status_drop_down/report/service_report_maintenance_situation_provider.dart'; +import '../../../models/new_models/assigned_employee.dart'; import '../../app_style/colors.dart'; import '../../widgets/buttons/app_back_button.dart'; import '../../widgets/buttons/app_button.dart'; @@ -49,7 +48,6 @@ class _SearchSubWorkOrderPageState extends State { @override Widget build(BuildContext context) { - return Scaffold( body: SafeArea( child: SingleChildScrollView( diff --git a/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart b/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart index 497f4a1..1b6cf52 100644 --- a/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart +++ b/lib/views/pages/sub_workorder/spare_parts_details_bottom_sheet.dart @@ -1,14 +1,12 @@ import 'package:flutter/material.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/part.dart'; import 'package:test_sa/models/service_request/search_work_order.dart'; import 'package:test_sa/views/app_style/colors.dart'; -import '../../../controllers/localization/localization.dart'; +import '../../../models/service_request/spare_parts.dart'; import '../../app_style/sizing.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/buttons/app_button.dart'; -import '../../widgets/parts/auto_complete_parts_field.dart'; import '../../widgets/parts/part_item.dart'; import '../../widgets/titles/app_sub_title.dart'; @@ -97,19 +95,19 @@ class _SparePartsBottomSheetState extends State { ) : const SizedBox.shrink(), const SizedBox(height: 4), - AutoCompletePartsField( - assetId: widget.assetId, - onPick: (part) { - _workOrder.sparePartsWorkOrders ??= []; - _workOrder.sparePartsWorkOrders.add(SparePartsWorkOrders( - id: part.reportPartID, - qty: part.quantity, - sparePart: SparePart(id: part.id, partName: part.partName, partNo: part.partNo), - installQty: part.installQty, - returnQty: part.returnQty, - )); - }, - ), + // AutoCompletePartsField( + // assetId: widget.assetId, + // onPick: (part) { + // _workOrder.sparePartsWorkOrders ??= []; + // _workOrder.sparePartsWorkOrders.add(SparePartsWorkOrders( + // id: part.reportPartID, + // qty: part.quantity, + // sparePart: SparePart(id: part.id, partName: part.partName, partNo: part.partNo), + // installQty: part.installQty, + // returnQty: part.returnQty, + // )); + // }, + // ), ], ), ), @@ -131,12 +129,14 @@ class _SparePartsBottomSheetState extends State { _workOrder.sparePartsWorkOrders?.length, (index) { final spare = _workOrder.sparePartsWorkOrders[index]; - Part part = Part( + SparePartsWorkOrders part = SparePartsWorkOrders( id: spare.sparePart?.id, - reportPartID: spare.id, - partNo: spare.sparePart?.partNo, - partName: spare.sparePart?.partName, - quantity: spare.qty?.toInt(), + sparePart: SparePart( + id: spare.id, + partNo: spare.sparePart?.partNo, + partName: spare.sparePart?.partName, + ), + qty: spare.qty?.toInt(), installQty: spare.installQty, returnQty: spare.returnQty, ); 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 c29b0a1..54e01c4 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 @@ -4,16 +4,15 @@ import 'package:provider/provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/service_request/search_work_order.dart'; -import 'package:test_sa/models/subtitle.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; -import 'package:test_sa/views/widgets/status/report/service_report_assistant_employee_menu.dart'; import 'package:test_sa/views/widgets/status/report/service_report_maintenance_situation.dart'; import 'package:test_sa/views/widgets/status/report/service_report_repair_location.dart'; import 'package:test_sa/views/widgets/status/service_request/supplier_engineers_menu.dart'; -import '../../../controllers/localization/localization.dart'; import '../../../controllers/providers/api/status_drop_down/report/service_report_maintenance_situation_provider.dart'; +import '../../../models/service_request/supp_engineer_work_orders.dart'; import '../../widgets/timer/app_timer.dart'; import '../../widgets/titles/app_sub_title.dart'; import 'auto_generated_vendor_name.dart'; @@ -41,7 +40,7 @@ class _WorkOrderDetailsBottomSheetState extends State(context, listen: false).reset(); @@ -91,12 +90,12 @@ class _WorkOrderDetailsBottomSheetState extends State with TickerPr SettingProvider _settingProvider; ServiceRequestsProvider _serviceRequestsProvider; ServiceStatusProvider _assetTypeProvider; - bool _validate = false; + PartsProvider _partsProvider; ServiceReport _serviceReport; bool _isLoading = false; - bool _showCommentField = false; + List _spareParts = []; final List _files = []; final GlobalKey _formKey = GlobalKey(); @@ -67,10 +65,10 @@ class _CreateServiceReportState extends State with TickerPr @override void initState() { _serviceReport = ServiceReport( - returnToService: DateTime.now(), - //type: const Lookup(value: 2), - device: widget.request.device, - parts: [], + // returnToService: DateTime.now(), + // //type: const Lookup(value: 2), + // device: widget.request.device, + sparePartsWorkOrders: [], ); super.initState(); // _isLoading = true; @@ -83,14 +81,13 @@ class _CreateServiceReportState extends State with TickerPr super.dispose(); } - CallRequestForWorkOrder _callRequestForWorkOrder; - void getRequestForWorkOrder() async { _isLoading = true; setState(() {}); - _callRequestForWorkOrder = await _serviceRequestsProvider.getCallRequestForWorkOrder(callId: widget.request.id); - _serviceReport.engineer = Engineer.fromJson(_callRequestForWorkOrder?.assignedEmployee?.toJson()); + _serviceReport.callRequest = await _serviceRequestsProvider.getCallRequestForWorkOrder(callId: widget.request.id); await _assetTypeProvider.getTypes(user: _userProvider.user, host: _settingProvider.host); + // _serviceReport.engineer = Engineer.fromJson(_callRequestForWorkOrder?.assignedEmployee?.toJson()); + _spareParts = await _partsProvider.getPartsList(assetId: widget.request.deviceId); _isLoading = false; setState(() {}); } @@ -101,16 +98,18 @@ class _CreateServiceReportState extends State with TickerPr _settingProvider = Provider.of(context); _serviceRequestsProvider = Provider.of(context); _assetTypeProvider = Provider.of(context); - if (_callRequestForWorkOrder == null) { + _partsProvider = Provider.of(context); + if (_serviceReport.callRequest == null) { getRequestForWorkOrder(); } _serviceReport.assetType = _assetTypeProvider.statuses?.firstWhere( - (element) => element.value == _callRequestForWorkOrder?.assetType, + (element) => element.value == _serviceReport.callRequest?.assetType, orElse: () => null, ); return Scaffold( key: _scaffoldKey, + appBar: DefaultAppBar(title: context.translation.newServiceReport), body: SafeArea( child: LoadingManager( isLoading: _isLoading, @@ -119,847 +118,152 @@ class _CreateServiceReportState extends State with TickerPr onRefresh: () async {}, child: Form( key: _formKey, - child: Stack( + child: Column( children: [ - ListView( - padding: const EdgeInsets.all(16), - children: [ - //AppNameBar(), - const SizedBox( - height: 16, - ), - Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - context.translation.newServiceReport, - style: Theme.of(context).textTheme.headline5.copyWith(color: AColors.cyan, fontSize: 28, fontWeight: FontWeight.bold), - ), + SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + widget.request.hospitalName.heading5(context), + 8.height, + "${context.translation.assetNo}: ${widget.request.deviceNumber}".bodyText(context), + "${context.translation.callId}: ${widget.request.requestCode}".bodyText(context), + ], + ).paddingAll(16), ), - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle("Caller Info"), - const SizedBox(height: 8), - Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - margin: const EdgeInsets.symmetric(vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: const [ - BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ) - ]), - child: Wrap( - direction: Axis.vertical, - spacing: 10, - children: [ - ASubTitle( - "${context.translation.callId}: ${widget.request.requestCode}", - font: 14, - ), - ASubTitle( - "${context.translation.assetNumber}: ${widget.request.deviceNumber}", - font: 14, - ), - widget.request.deviceSerialNumber == null - ? const SizedBox() - : ASubTitle( - "${context.translation.deviceSN}: ${widget.request.deviceSerialNumber}", - font: 14, - ), - Text( - "${context.translation.customer}: ${widget.request.hospitalName}", - style: Theme.of(context).textTheme.subtitle1.copyWith( - fontWeight: FontWeight.bold, - fontSize: 12, - ), - textScaleFactor: AppStyle.getScaleFactor(context), - ) - ], - ), - ), - - ASubTitle("Work Order Details"), - Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - margin: const EdgeInsets.symmetric(vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [ - BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ), - ]), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Report type and Reasons - // device sn - Visibility( - visible: widget.request.deviceSerialNumber == null, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.deviceSN), - _validate && _serviceReport.device?.id == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - AutoCompleteDeviceField( - hospitalId: widget.request.hospitalId, - initialValue: _serviceReport.device, - onPick: (id) { - _serviceReport.device.id = id; - }, - ), - const SizedBox( - height: 8, - ), - ], - ), - ), - const SizedBox( - height: 8, - ), - ASubTitle(context.translation.assetType ?? ""), - _validate && _serviceReport.assetType == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - - LoadingManager( - isLoading: _assetTypeProvider.isLoading, - isFailedLoading: _assetTypeProvider.statuses == null, - stateCode: _assetTypeProvider.stateCode, - onRefresh: () async { - _assetTypeProvider.reset(); - await _assetTypeProvider.getTypes(user: _userProvider.user, host: _settingProvider.host); - _serviceReport?.assetType = _assetTypeProvider.statuses?.firstWhere( - (element) => element.value == _callRequestForWorkOrder.assetType, - orElse: () => null, - ); - }, - child: ATextFormField( - initialValue: _serviceReport?.assetType?.name ?? "NULL", - textAlign: TextAlign.center, - enable: false, - style: Theme.of(context).textTheme.titleMedium, - ), - ), - // ServiceAssetTypeMenu( - // initialValue: _serviceReport.assetType, - // onSelect: (status) { - // _serviceReport.assetType = status; - // }, - // ), - const SizedBox( - height: 8, - ), - // Report status and Asset Type - Row( - children: [ - // report status - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // ASubTitle(context.translation.reportStatus), - ASubTitle("Equipment Status"), - _validate && _serviceReport.equipmentStatus == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - // ServiceReportStatusMenu( - // report: _serviceReport, - // request: widget.request, - // onSelect: (status) { - // _serviceReport.status = status; - // }, - // ), - ServiceReportEquipmentStatusMenu( - report: _serviceReport, - request: widget.request, - onSelect: (status) { - _serviceReport.equipmentStatus = status; - }, - ) - ], - ), - ), - const SizedBox( - width: 8, - ), - // Provider.of(context).isLoading == null - // ? const SizedBox.shrink(): - // Call's last Situation - Consumer( - builder: (_, provider, __) { - if (provider.isLoading == null) return const SizedBox.shrink(); - return Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.callLastSituation), - _validate && _serviceReport.callLastSituation == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - ServiceReportLastCallsMenu( - report: _serviceReport, - onSelect: (status) { - if (status?.value == 12 || _serviceReport.callLastSituation?.value == 12) { - _serviceReport.callLastSituation = status; - setState(() {}); - } else { - _serviceReport.callLastSituation = status; - } - }, - ), - ], - ), - ); - }, - ), - ], - ), - // if (_showCommentField) - // const SizedBox( - // height: 8, - // ), - // if (_showCommentField) - // ATextFormField( - // initialValue: _serviceReport?.reviewComment, - // hintText: "Review Comment", - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.titleMedium, - // textInputType: TextInputType.multiline, - // onSaved: (value) { - // _serviceReport.reviewComment = value; - // }, - // ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - Row( - children: [ - // Report Status - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.reportType), - // _validate && _serviceReport.type == null ? - // ASubTitle(context.translation.requiredWord,color: Colors.red,): - // const SizedBox.shrink(), - // const SizedBox(height: 4,), - // ServiceReportTypeMenu( - // initialValue: _serviceReport.type, - // onSelect: (status){ - // _serviceReport.type = status; - // }, - // ), - // ], - // ), - // ), - // const SizedBox(width: 8,), - // visit date - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const ASubTitle("Return to Service"), - // _validate && _serviceReport.returnToService == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - Row( - children: [ - Expanded( - child: ADatePicker( - date: _serviceReport.returnToService, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDatePicker: (date) { - _serviceReport.returnToService = date; - setState(() {}); - }, - ), - ), - ], - ), - ], - ), - ), - ], - ), - const SizedBox( - height: 8, - ), - ASubTitle(context.translation.workingHours), - const SizedBox(height: 8), - Row( - children: [ - Expanded( - child: AppTimer( - timer: _serviceReport.timer, - onChange: (timer) async { - _serviceReport.timer = timer; - _serviceReport.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); - return true; - }, - ), - ), - ], - ), - const SizedBox(height: 16), - // device sn - Visibility( - visible: widget.request.deviceSerialNumber == null, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.deviceSN), - _validate && _serviceReport.device?.id == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - AutoCompleteDeviceField( - hospitalId: widget.request.hospitalId, - initialValue: _serviceReport.device, - onPick: (id) { - _serviceReport.device.id = id; - }, - ), - const SizedBox( - height: 8, - ), - ], - ), - ), - - // Report status and Asset Type - - if (_showCommentField) - const SizedBox( - height: 8, - ), - if (_showCommentField) - ATextFormField( - initialValue: _serviceReport?.reviewComment, - hintText: "Review Comment", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.reviewComment = value; - }, - ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - - // invoice number & code - _serviceReport.callLastSituation?.id != 12 - ? const SizedBox.shrink() - : Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.invoiceNumber), - const SizedBox( - height: 8, - ), - ATextFormField( - initialValue: _serviceReport?.invoiceNumber, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.invoiceNumber = value; - }, - ), - ], - ), - ), - const SizedBox( - width: 8, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.invoiceCode), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.invoiceCode, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - textInputType: TextInputType.text, - onSaved: (value) { - _serviceReport.invoiceCode = value; - }, - ), - ], - ), - ), - ], - ), - const SizedBox(height: 8), - ASubTitle(context.translation.faultDescription), - const SizedBox( - height: 4, - ), - ServiceReportFaultDescription( - requestId: widget.request?.id, - initialValue: _serviceReport.faultDescription, - onSelect: (status) { - if (status != null) { - _serviceReport.faultDescription = status; - setState(() {}); - } - }, - ), - const SizedBox( - height: 4, - ), - // ATextFormField( - // initialValue: _serviceReport?.faultDescriptionId?.toString(), - // textAlign: TextAlign.center, - // controller: _faultController, - // style: Theme.of(context).textTheme.titleMedium, - // validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - // textInputType: TextInputType.multiline, - // onSaved: (value) { - // _serviceReport.faultDescriptionId = int.tryParse(value) ?? 0; - // }, - // ), - const SizedBox( - height: 8, - ), - Row( - children: [ - const ASubTitle("Solutions"), - // Expanded( - // child: SizedBox( - // height: 32 * AppStyle.getScaleFactor(context), - // child: SpeechToTextButton( - // controller: _workPreformedController, - // mini: true, - // ), - // ), - // ), - ], - ), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.workPreformed, - textAlign: TextAlign.center, - enable: false, - hintText: _serviceReport.faultDescription?.workPerformed ?? "", - controller: _workPreformedController, - style: Theme.of(context).textTheme.titleMedium, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.workPreformed = value; - }, - ), - const SizedBox( - height: 8, - ), - - const SizedBox(height: 8), - Row( - children: [ - // reasons - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const ASubTitle("Failure Reason"), - _validate && _serviceReport.reason?.id == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox(height: 4), - ServiceReportReasonsMenu( - initialValue: _serviceReport.reason, - onSelect: (status) { - _serviceReport.reason = status; - }, - ), - ], - ), - ), - const SizedBox(width: 8), - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // const ASubTitle("Attachments"), - // AMiniOneFilePicker( - // //error: _validate && _serviceReport.image == null, - // file: _file, - // onPick: (file) { - // _file = file; - // _serviceReport.files[0] = "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}"; - // }, - // ), - // ], - // ), - // ), - ], - ), - const SizedBox(height: 8), - MultiFilesPicker(label: "Attachments", files: _files), - const SizedBox(height: 8), - ASubTitle(context.translation.repairLocation), - const SizedBox(height: 4), - ServiceReportRepairLocation( - initialValue: _serviceReport.repairLocation, - onSelect: (status) { - _serviceReport.repairLocation = status; - }, - ), - const SizedBox(height: 16), - const ASubTitle("Travel Expenses"), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.travelingExpense?.toString(), - hintText: "i.e 3, 3.5, 4", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.travelingExpense = int.tryParse(value) ?? 0; - }, - ), - - const SizedBox( - height: 8, - ), - // Traveling Hours & Working Hours - Row( - children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.workingHours), - // const SizedBox( - // height: 8, - // ), - // Row( - // children: [ - // Expanded( - // child: AppTimer( - // timer: _serviceReport.timer, - // onChange: (timer) async { - // _serviceReport.timer = timer; - // return true; - // }, - // ), - // ), - // ], - // ), - // // ATextFormField( - // // initialValue: _serviceReport?.workHours, - // // textAlign: TextAlign.center, - // // hintText: "i.e 3, 3.5, 4", - // // style: Theme.of(context).textTheme.subtitle1, - // // validator: (value) => - // // Validator.isNumeric(value) - // // ? null : context.translation.requiredWord, - // // textInputType: TextInputType.number, - // // onSaved: (value){ - // // _serviceReport.workHours = value; - // // }, - // // ), - // ], - // ), - // ), - // const SizedBox(width: 8,), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.travelingHours), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: _serviceReport?.travelingHours?.toString(), - textAlign: TextAlign.center, - hintText: "i.e 3, 3.5, 4", - style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.isNumeric(value) - // ? null : context.translation.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.travelingHours = double.tryParse(value) ?? 0.0; - }, - ), - ], - ), - ), - ], - ), - const SizedBox( - height: 8, - ), - // Operating Hours and Job Sheet Number - // Row( - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.operatingHours), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.operatingHours, - // textAlign: TextAlign.center, - // hintText: "i.e 3, 3.5, 4", - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.isNumeric(value) - // ? null : context.translation.requiredWord, - // textInputType: TextInputType.number, - // onSaved: (value){ - // _serviceReport.operatingHours = value; - // }, - // ), - // ], - // ), - // ), - // const SizedBox(width: 8,), - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.jobSheetNumber), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.jobSheetNumber, - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.subtitle1, - // textInputType: TextInputType.name, - // onSaved: (value){ - // _serviceReport.jobSheetNumber = value; - // }, - // ), - // ], - // ), - // ), - // ], - // ), - - const SizedBox(height: 8), - const ASubTitle("Technical comment"), - const SizedBox(height: 4), - ATextFormField( - initialValue: _serviceReport?.comment, - hintText: "Technical Comment", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.comment = value; - }, - ), - const SizedBox(height: 8), - const ASubTitle("Nurse Signature"), - ESignature( - oldSignature: _serviceReport.signatureNurse, - newSignature: _serviceReport.localNurseSignature, - onSaved: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _serviceReport.localNurseSignature = signature; - _serviceReport.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - const SizedBox(height: 8), - const ASubTitle("Engineer Signature"), - ESignature( - oldSignature: _serviceReport.signatureEngineer, - newSignature: _serviceReport.localNurseSignature, - onSaved: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _serviceReport.localNurseSignature = signature; - _serviceReport.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - const SizedBox( - height: 8, - ), - ], - ), - ), - - // Part Number and Quantity - ASubTitle("Spare Parts"), - Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - margin: const EdgeInsets.symmetric(vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [ - BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ) - ]), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Row( - children: [ - Expanded( - flex: 3, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.partNumberName), - _validate && _serviceReport.parts == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - AutoCompletePartsField( - assetId: _serviceReport?.device?.id, - onPick: (part) { - _serviceReport.parts.add(part); - }, - ), - ], - ), - ), - ], - ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - Row( - children: [ - Expanded(flex: 3, child: Text(context.translation.number)), - Expanded(flex: 1, child: Text(context.translation.quantity)), - ], - ), - Column( - children: List.generate(_serviceReport.parts.length, (index) { - Part part = _serviceReport.parts[index]; - return PartItem( - part: part, - onDelete: (part) { - _serviceReport.parts.remove(part); - setState(() {}); - }, - ); - }), - ), - const SizedBox( - height: 16, - ), - ], - ), - ), - ], - ), - AButton( - text: context.translation.submit, - onPressed: () async { - _validate = true; - // if (!_formKey.currentState.validate()) { - // setState(() {}); - // return; - // } - if (!(await _serviceReport.validate())) { + 8.height, + ADatePicker( + label: context.translation.visitDate, + date: DateTime.tryParse(_serviceReport.visitDate ?? ""), + onDatePicker: (date) { + _serviceReport.visitDate = date?.toIso8601String(); setState(() {}); - return; - } - _formKey.currentState.save(); + }, + ), + 8.height, + AppTextFormField( + labelText: context.translation.workingHours, + textInputType: TextInputType.number, + onSaved: (text) { + _serviceReport.workingHours = num.tryParse(text ?? ""); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.reason, + initialValue: _serviceReport.reason, + onSelect: (value) { + _serviceReport.reason = value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.serviceType, + onSelect: (value) {}, + ), + 8.height, + ServiceReportLastCallsMenu( + report: _serviceReport, + title: context.translation.callLastSituation, + parentId: widget.request.id, + onSelect: (status) { + _serviceReport.calllastSituation = status; + }, + ), + 8.height, + ServiceReportAssistantEmployeeMenu( + title: context.translation.assignAssistant, + assetId: _serviceReport.callRequest?.asset?.id, + initialValue: (_serviceReport.assistantEmployees?.isNotEmpty ?? false) ? _serviceReport.assistantEmployees?.first : null, + onSelect: (employee) { + _serviceReport.assistantEmployees = [employee]; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.partNo, + staticData: _spareParts, + initialValue: (_serviceReport.sparePartsWorkOrders?.isNotEmpty ?? false) ? _serviceReport.sparePartsWorkOrders.first.sparePart : null, + onSelect: (part) { + log(part.toJson().toString()); + _serviceReport.sparePartsWorkOrders.clear(); + _serviceReport.sparePartsWorkOrders.add(SparePartsWorkOrders(sparePart: part)); + setState(() {}); + }, + ), + 8.height, + AppTextFormField( + labelText: context.translation.quantity, + textInputType: TextInputType.number, + enable: _serviceReport.sparePartsWorkOrders.isNotEmpty, + onSaved: (text) { + _serviceReport.sparePartsWorkOrders.first.qty = num.tryParse(text ?? ""); + }, + ), + 8.height, + MultiFilesPicker(label: context.translation.attachImage, files: _files), + ESignature( + title: context.translation.engSign, + oldSignature: _serviceReport.engSignature, + newSignature: _serviceReport.localEngSignature, + onSaved: (signature) { + if (signature == null || signature.isEmpty) { + setState(() {}); + return; + } + _serviceReport.localEngSignature = signature; + _serviceReport.engSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + }, + ), + 24.height, + ], + ), + ).expanded, + AppFilledButton( + label: context.translation.submitRequest, + onPressed: () async { + // if (!_formKey.currentState.validate()) { + // setState(() {}); + // return; + // } + // if (!(await _serviceReport.validate())) { + // setState(() {}); + // return; + // } + _formKey.currentState.save(); - _isLoading = true; - setState(() {}); - _serviceReport.files ??= []; - for (var file in _files) { - _serviceReport.files.add("${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}"); - } - int status = await _serviceRequestsProvider.createServiceReport( - user: _userProvider.user, - host: _settingProvider.host, - report: _serviceReport, - request: widget.request, - ); - _isLoading = false; - setState(() {}); - if (status >= 200 && status < 300) { - Fluttertoast.showToast( - msg: context.translation.successfulRequestMessage, - ); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - } else { - String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(errorMessage), - )); - } - }, - ), - const SizedBox( - height: 300, - ) - ], + _isLoading = true; + setState(() {}); + _serviceReport.attachmentsWorkOrder ??= []; + for (var file in _files) { + _serviceReport.attachmentsWorkOrder.add(Attachment(name: "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}")); + } + int status = await _serviceRequestsProvider.createServiceReport(report: _serviceReport, request: widget.request); + _isLoading = false; + setState(() {}); + if (status >= 200 && status < 300) { + Fluttertoast.showToast( + msg: context.translation.successfulRequestMessage, + ); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + } else { + String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation); + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(errorMessage), + )); + } + }, ), - const ABackButton(), ], - ), + ).paddingAll(16), ), ), ), diff --git a/lib/views/pages/user/requests/work_order/edit_service_report.dart b/lib/views/pages/user/requests/work_order/edit_service_report.dart index 2193471..8915d49 100644 --- a/lib/views/pages/user/requests/work_order/edit_service_report.dart +++ b/lib/views/pages/user/requests/work_order/edit_service_report.dart @@ -1,4 +1,3 @@ -import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -12,30 +11,22 @@ import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/controllers/validator/validator.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/call_request_for_work_order_model.dart'; -import 'package:test_sa/models/engineer.dart'; -import 'package:test_sa/models/part.dart'; -import 'package:test_sa/models/service_report.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; -import 'package:test_sa/views/widgets/date_and_time/date_picker.dart'; -import 'package:test_sa/views/widgets/e_signature/e_signature.dart'; -import 'package:test_sa/views/widgets/equipment/auto_complete_devices_field.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; -import 'package:test_sa/views/widgets/parts/auto_complete_parts_field.dart'; -import 'package:test_sa/views/widgets/parts/part_item.dart'; import 'package:test_sa/views/widgets/status/report/service_report_equipment_status.dart'; import 'package:test_sa/views/widgets/status/report/service_report_fault_description.dart'; import 'package:test_sa/views/widgets/status/report/service_report_last_call.dart'; import 'package:test_sa/views/widgets/status/report/service_report_reasons.dart'; import 'package:test_sa/views/widgets/status/report/service_report_repair_location.dart'; -import 'package:test_sa/views/widgets/timer/app_timer.dart'; import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; +import '../../../../../models/service_request/wo_call_request.dart'; import '../../../../widgets/images/multi_image_picker.dart'; class EditServiceReport extends StatefulWidget { @@ -67,12 +58,12 @@ class _EditServiceReportState extends State with TickerProvid ServiceStatusProvider _assetTypeProvider; - CallRequestForWorkOrder _callRequestForWorkOrder; + CallRequest _callRequestForWorkOrder; @override void initState() { _serviceReport = widget.report; - _images = widget.report?.files?.map((e) => File(e))?.toList(); + // _images = widget.report?.files?.map((e) => File(e))?.toList(); super.initState(); } @@ -80,7 +71,7 @@ class _EditServiceReportState extends State with TickerProvid _isLoading = true; setState(() {}); _callRequestForWorkOrder = await _serviceRequestsProvider.getCallRequestForWorkOrder(callId: widget.request.id); - _serviceReport.engineer = Engineer.fromJson(_callRequestForWorkOrder?.assignedEmployee?.toJson()); + // _serviceReport.engineer = Engineer.fromJson(_callRequestForWorkOrder?.assignedEmployee?.toJson()); await _assetTypeProvider.getTypes(user: _userProvider.user, host: _settingProvider.host); _isLoading = false; setState(() {}); @@ -259,29 +250,29 @@ class _EditServiceReportState extends State with TickerProvid // height: 8, // ), // device sn - Visibility( - visible: widget.request.deviceSerialNumber == null, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.deviceSN), - _validate && _serviceReport.device?.id == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - AutoCompleteDeviceField( - hospitalId: widget.request.hospitalId, - initialValue: _serviceReport.device, - onPick: (id) { - _serviceReport.device.id = id; - }, - ), - const SizedBox(height: 8), - ], - ), - ), + // Visibility( + // visible: widget.request.deviceSerialNumber == null, + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // ASubTitle(context.translation.deviceSN), + // _validate && _serviceReport.device?.id == null + // ? ASubTitle( + // context.translation.requiredWord, + // color: Colors.red, + // ) + // : const SizedBox.shrink(), + // AutoCompleteDeviceField( + // hospitalId: widget.request.hospitalId, + // initialValue: _serviceReport.device, + // onPick: (id) { + // _serviceReport.device.id = id; + // }, + // ), + // const SizedBox(height: 8), + // ], + // ), + // ), const SizedBox(height: 8), ASubTitle(context.translation.assetType), _validate && _serviceReport.assetType == null @@ -370,7 +361,7 @@ class _EditServiceReportState extends State with TickerProvid crossAxisAlignment: CrossAxisAlignment.start, children: [ ASubTitle(context.translation.callLastSituation), - _validate && _serviceReport.callLastSituation == null + _validate && _serviceReport.calllastSituation == null ? ASubTitle( context.translation.requiredWord, color: Colors.red, @@ -380,11 +371,11 @@ class _EditServiceReportState extends State with TickerProvid ServiceReportLastCallsMenu( report: _serviceReport, onSelect: (status) { - if (status?.value == 12 || _serviceReport.callLastSituation?.value == 12) { - _serviceReport.callLastSituation = status; + if (status?.value == 12 || _serviceReport.calllastSituation?.value == 12) { + _serviceReport.calllastSituation = status; setState(() {}); } else { - _serviceReport.callLastSituation = status; + _serviceReport.calllastSituation = status; setState(() {}); } }, @@ -400,22 +391,22 @@ class _EditServiceReportState extends State with TickerProvid height: 8, ), const ASubTitle("Return to Service"), - Row( - children: [ - Expanded( - child: ADatePicker( - date: _serviceReport.returnToService, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDatePicker: (date) { - _serviceReport.returnToService = date; - setState(() {}); - }, - ), - ), - ], - ), - if (_serviceReport?.callLastSituation?.value == 2) + // Row( + // children: [ + // Expanded( + // child: ADatePicker( + // date: _serviceReport.returnToService, + // from: DateTime.now().subtract(const Duration(days: 365)), + // to: DateTime.now().add(const Duration(days: 365)), + // onDatePicker: (date) { + // _serviceReport.returnToService = date; + // setState(() {}); + // }, + // ), + // ), + // ], + // ), + if (_serviceReport?.calllastSituation?.value == 2) Column( children: [ const SizedBox( @@ -557,31 +548,31 @@ class _EditServiceReportState extends State with TickerProvid height: 8, ), // invoice number & code - _serviceReport.callLastSituation?.value != 12 + _serviceReport.calllastSituation?.value != 12 ? const SizedBox.shrink() : Row( children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.invoiceNumber), - const SizedBox( - height: 8, - ), - ATextFormField( - initialValue: _serviceReport?.invoiceNumber, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.invoiceNumber = value; - }, - ), - ], - ), - ), + // Expanded( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // ASubTitle(context.translation.invoiceNumber), + // const SizedBox( + // height: 8, + // ), + // ATextFormField( + // initialValue: _serviceReport?.invoiceNumber, + // textAlign: TextAlign.center, + // style: Theme.of(context).textTheme.subtitle1, + // validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, + // textInputType: TextInputType.number, + // onSaved: (value) { + // _serviceReport.invoiceNumber = value; + // }, + // ), + // ], + // ), + // ), const SizedBox( width: 8, ), @@ -593,16 +584,16 @@ class _EditServiceReportState extends State with TickerProvid const SizedBox( height: 4, ), - ATextFormField( - initialValue: _serviceReport?.invoiceCode, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - textInputType: TextInputType.text, - onSaved: (value) { - _serviceReport.invoiceCode = value; - }, - ), + // ATextFormField( + // initialValue: _serviceReport?.invoiceCode, + // textAlign: TextAlign.center, + // style: Theme.of(context).textTheme.subtitle1, + // validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, + // textInputType: TextInputType.text, + // onSaved: (value) { + // _serviceReport.invoiceCode = value; + // }, + // ), ], ), ), @@ -671,21 +662,21 @@ class _EditServiceReportState extends State with TickerProvid const SizedBox(height: 8), ASubTitle(context.translation.workingHours), const SizedBox(height: 8), - Row( - children: [ - Expanded( - child: AppTimer( - timer: _serviceReport.timer, - enabled: false, - // onChange: (timer) async { - // _serviceReport.timer = timer; - // _serviceReport.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); - // return true; - // }, - ), - ), - ], - ), + // Row( + // children: [ + // Expanded( + // child: AppTimer( + // timer: _serviceReport.timer, + // enabled: false, + // // onChange: (timer) async { + // // _serviceReport.timer = timer; + // // _serviceReport.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); + // // return true; + // // }, + // ), + // ), + // ], + // ), const SizedBox(height: 16), if (_showCommentField) const SizedBox( @@ -724,7 +715,7 @@ class _EditServiceReportState extends State with TickerProvid const ASubTitle("Solutions"), const SizedBox(height: 4), ATextFormField( - initialValue: _serviceReport?.workPreformed, + initialValue: "_serviceReport?.workPreformed", textAlign: TextAlign.center, enable: false, hintText: _serviceReport.faultDescription?.workPerformed ?? "", @@ -784,16 +775,16 @@ class _EditServiceReportState extends State with TickerProvid height: 4, ), ATextFormField( - initialValue: _serviceReport?.travelingExpense?.toString(), + initialValue: " _serviceReport?.travelingExpense?.toString()", hintText: context.translation.travelingExpense, textAlign: TextAlign.center, style: Theme.of(context).textTheme.titleMedium, textInputType: TextInputType.number, onSaved: (value) { - if (value != null && value.isEmpty) { - _serviceReport.travelingExpense = num.tryParse(_serviceReport?.travelingExpense?.toString() ?? "") ?? 0; - } else - _serviceReport.travelingExpense = num.tryParse(value) ?? 0; + // if (value != null && value.isEmpty) { + // _serviceReport.travelingExpense = num.tryParse(_serviceReport?.travelingExpense?.toString() ?? "") ?? 0; + // } else + // _serviceReport.travelingExpense = num.tryParse(value) ?? 0; }, ), @@ -944,32 +935,32 @@ class _EditServiceReportState extends State with TickerProvid ), const SizedBox(height: 8), const ASubTitle("Nurse Signature"), - ESignature( - oldSignature: _serviceReport.signatureNurse, - newSignature: _serviceReport.localNurseSignature, - onSaved: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _serviceReport.localNurseSignature = signature; - _serviceReport.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), - const SizedBox( - height: 8, - ), - const ASubTitle("Engineer Signature"), - ESignature( - oldSignature: _serviceReport.signatureEngineer, - newSignature: _serviceReport.localNurseSignature, - onSaved: (signature) { - if (signature == null || signature.isEmpty) { - return; - } - _serviceReport.localNurseSignature = signature; - _serviceReport.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - }, - ), + // ESignature( + // oldSignature: _serviceReport.signatureNurse, + // newSignature: _serviceReport.localNurseSignature, + // onSaved: (signature) { + // if (signature == null || signature.isEmpty) { + // return; + // } + // _serviceReport.localNurseSignature = signature; + // _serviceReport.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + // }, + // ), + // const SizedBox( + // height: 8, + // ), + // const ASubTitle("Engineer Signature"), + // ESignature( + // oldSignature: _serviceReport.signatureEngineer, + // newSignature: _serviceReport.localNurseSignature, + // onSaved: (signature) { + // if (signature == null || signature.isEmpty) { + // return; + // } + // _serviceReport.localNurseSignature = signature; + // _serviceReport.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + // }, + // ), const SizedBox( height: 8, ), @@ -993,35 +984,35 @@ class _EditServiceReportState extends State with TickerProvid child: Column( mainAxisSize: MainAxisSize.min, children: [ - Row( - children: [ - Expanded( - flex: 3, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.partNumberName), - _validate && _serviceReport.parts == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - AutoCompletePartsField( - assetId: _serviceReport?.device?.id, - onPick: (part) { - _serviceReport.parts.add(part); - setState(() {}); - }, - ), - ], - ), - ), - ], - ), + // Row( + // children: [ + // Expanded( + // flex: 3, + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // ASubTitle(context.translation.partNumberName), + // _validate && _serviceReport.parts == null + // ? ASubTitle( + // context.translation.requiredWord, + // color: Colors.red, + // ) + // : const SizedBox.shrink(), + // const SizedBox( + // height: 4, + // ), + // AutoCompletePartsField( + // assetId: _serviceReport?.device?.id, + // onPick: (part) { + // _serviceReport.parts.add(part); + // setState(() {}); + // }, + // ), + // ], + // ), + // ), + // ], + // ), SizedBox( height: 8 * AppStyle.getScaleFactor(context), ), @@ -1031,18 +1022,18 @@ class _EditServiceReportState extends State with TickerProvid Expanded(flex: 1, child: Text(context.translation.quantity)), ], ), - Column( - children: List.generate(_serviceReport.parts.length, (index) { - Part _part = _serviceReport.parts[index]; - return PartItem( - part: _part, - onDelete: (part) { - _serviceReport.parts.remove(part); - setState(() {}); - }, - ); - }), - ), + // Column( + // children: List.generate(_serviceReport.parts.length, (index) { + // Part _part = _serviceReport.parts[index]; + // return PartItem( + // part: _part, + // onDelete: (part) { + // _serviceReport.parts.remove(part); + // setState(() {}); + // }, + // ); + // }), + // ), const SizedBox( height: 16, ), @@ -1071,7 +1062,7 @@ class _EditServiceReportState extends State with TickerProvid _isLoading = true; setState(() {}); - _serviceReport.files = _images.map((e) => _isLocalUrl(e.path) ? "${e.path.split("/").last}|${base64Encode(e.readAsBytesSync())}" : e.path).toList(); + // _serviceReport.files = _images.map((e) => _isLocalUrl(e.path) ? "${e.path.split("/").last}|${base64Encode(e.readAsBytesSync())}" : e.path).toList(); int status = await _serviceRequestsProvider.updateServiceReport(user: _userProvider.user, host: _settingProvider.host, report: _serviceReport, request: widget.request); _isLoading = false; setState(() {}); diff --git a/lib/views/pages/user/requests/work_order/future_service_report.dart b/lib/views/pages/user/requests/work_order/future_service_report.dart index c290d9b..937262b 100644 --- a/lib/views/pages/user/requests/work_order/future_service_report.dart +++ b/lib/views/pages/user/requests/work_order/future_service_report.dart @@ -1,14 +1,12 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/service_requests_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import 'package:test_sa/models/service_report.dart'; import 'package:test_sa/models/service_request/search_work_order.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; -import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; import 'package:test_sa/views/widgets/loaders/failed_loading.dart'; diff --git a/lib/views/pages/user/requests/work_order/work_orders_list_page.dart b/lib/views/pages/user/requests/work_order/work_orders_list_page.dart index a7b4ef7..2cac7c9 100644 --- a/lib/views/pages/user/requests/work_order/work_orders_list_page.dart +++ b/lib/views/pages/user/requests/work_order/work_orders_list_page.dart @@ -13,13 +13,9 @@ import 'package:test_sa/models/service_request/service_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/default_app_bar.dart'; -import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/pages/user/requests/work_order/create_service_report.dart'; import 'package:test_sa/views/pages/user/requests/work_order/future_service_report.dart'; -import 'package:test_sa/views/widgets/buttons/app_button.dart'; -import 'package:test_sa/views/widgets/requests/info_row.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; -import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; class WorkOrderListPage extends StatelessWidget { static const String id = "/work-order-list"; @@ -116,7 +112,7 @@ class WorkOrderListPage extends StatelessWidget { ), ], ).expanded, - Text(workOrders[index].visitDate.toServiceRequestCardFormat, textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), + Text(workOrders[index].visitDate?.toServiceRequestCardFormat ?? "", textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), ], ), Text( diff --git a/lib/views/widgets/date_and_time/date_picker.dart b/lib/views/widgets/date_and_time/date_picker.dart index df0e981..4700d96 100644 --- a/lib/views/widgets/date_and_time/date_picker.dart +++ b/lib/views/widgets/date_and_time/date_picker.dart @@ -47,7 +47,7 @@ class ADatePicker extends StatelessWidget { firstDate: from ?? DateTime.now(), lastDate: to ?? DateTime.now().add(const Duration(days: 365)), ); - onDatePicker(picked); + if (onDatePicker != null) onDatePicker(picked); } : null); } diff --git a/lib/views/widgets/e_signature/e_signature.dart b/lib/views/widgets/e_signature/e_signature.dart index 2c5dcc4..3ed1105 100644 --- a/lib/views/widgets/e_signature/e_signature.dart +++ b/lib/views/widgets/e_signature/e_signature.dart @@ -1,16 +1,18 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:signature/signature.dart'; -import 'package:test_sa/views/app_style/colors.dart'; -import 'package:test_sa/views/app_style/sizing.dart'; -import 'package:test_sa/views/widgets/loaders/image_loader.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/new_views/app_style/app_color.dart'; class ESignature extends StatefulWidget { final String oldSignature; final Uint8List newSignature; final Function(Uint8List) onSaved; final Function(Uint8List) onChange; - const ESignature({Key key, this.oldSignature, this.onSaved, this.onChange, this.newSignature}) : super(key: key); + final String title; + const ESignature({Key key, this.title, this.oldSignature, this.onSaved, this.onChange, this.newSignature}) : super(key: key); @override State createState() => _ESignatureState(); @@ -26,13 +28,15 @@ class _ESignatureState extends State { Uint8List signature; - bool _unpaint = false; + bool _editable = false; + @override void initState() { if (widget.newSignature != null) { signature = widget.newSignature; + } else if (widget.oldSignature != null || signature != null) { + signature = widget.oldSignature.codeUnits; } - // TODO: implement initState super.initState(); } @@ -46,12 +50,12 @@ class _ESignatureState extends State { Widget build(BuildContext context) { return Column( children: [ - if (widget.oldSignature != null || signature != null) - Container( - width: MediaQuery.of(context).size.width, - padding: const EdgeInsets.only(bottom: 8), - height: 90 * AppStyle.getScaleFactor(context), - child: signature != null ? Image.memory(signature) : ImageLoader(boxFit: BoxFit.contain, url: widget.oldSignature)), + // if (widget.oldSignature != null || signature != null) + // Container( + // width: MediaQuery.of(context).size.width, + // padding: const EdgeInsets.only(bottom: 8), + // height: 90 * AppStyle.getScaleFactor(context), + // child: signature != null ? Image.memory(signature) : ImageLoader(boxFit: BoxFit.contain, url: widget.oldSignature)), FormField(onSaved: (_) async { widget.onSaved(signature); }, builder: (FormFieldState state) { @@ -59,59 +63,95 @@ class _ESignatureState extends State { children: [ Container( width: MediaQuery.of(context).size.width, - padding: const EdgeInsets.symmetric(horizontal: 16), + padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: AColors.black), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - boxShadow: const [AppStyle.boxShadow]), - child: AbsorbPointer( - absorbing: _unpaint, - child: Signature( - controller: _controller, - height: 160 * AppStyle.getScaleFactor(context), - backgroundColor: Colors.transparent, - ), + color: Colors.white, + borderRadius: _editable ? const BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)) : BorderRadius.circular(10), + boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + widget.title.tinyFont(context).paddingOnly(top: 8), + (!_editable + ? "edit".toSvgAsset(width: 48).paddingOnly(top: 8) + : Container( + width: 48.toScreenWidth, + height: 48.toScreenWidth, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(100), border: Border.all(color: AppColor.neutral30)), + padding: const EdgeInsets.all(11), + margin: const EdgeInsets.only(top: 8), + child: "done".toSvgAsset(width: 26), + )) + .onPress(() async { + if (_editable) { + signature = await _controller.toPngBytes(); + if (widget.onChange != null) { + widget.onChange(signature); + } + } + _editable = !_editable; + setState(() {}); + }), + ], + ), + AbsorbPointer( + absorbing: !_editable, + child: Signature( + controller: _controller, + height: 135.toScreenHeight, + width: MediaQuery.of(context).size.width - 64.toScreenWidth, + backgroundColor: Colors.transparent, + ), + ), + ], ), ), - Row( - children: [ - IconButton( - onPressed: () { + if (_editable) + Container( + decoration: const BoxDecoration( + color: AppColor.neutral30, + borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)), + ), + child: Row( + children: [ + "clear".toSvgAsset(width: 14).paddingOnly(start: 16).onPress(() { _controller.clear(); - }, - icon: const Icon(Icons.clear)), - IconButton( - onPressed: () { + }), + 35.width, + "back".toSvgAsset(width: 17).onPress(() { _controller.undo(); - }, - icon: const Icon(Icons.undo)), - IconButton( - onPressed: () { + }), + 27.width, + "redo".toSvgAsset(width: 17).onPress(() { _controller.redo(); - }, - icon: const Icon(Icons.redo)), - IconButton( - onPressed: () { - _unpaint = !_unpaint; - setState(() {}); - }, - icon: Icon( - _unpaint ? Icons.draw : Icons.ac_unit, - color: _unpaint ? AColors.orange : null, - )), - const Spacer(), - IconButton( - onPressed: () async { - signature = await _controller.toPngBytes(); - if (widget.onChange != null) { - widget.onChange(signature); - } - setState(() {}); - }, - icon: const Icon(Icons.check)), - ], - ) + }), + // IconButton( + // onPressed: () { + // _unpaint = !_unpaint; + // setState(() {}); + // }, + // icon: Icon( + // _unpaint ? Icons.draw : Icons.ac_unit, + // color: _unpaint ? AColors.orange : null, + // )), + // const Spacer(), + // IconButton( + // onPressed: () async { + // signature = await _controller.toPngBytes(); + // if (widget.onChange != null) { + // widget.onChange(signature); + // } + // setState(() {}); + // }, + // icon: const Icon(Icons.check)), + ], + ).paddingOnly(top: 12, bottom: 12), + ) ], ); }), diff --git a/lib/views/widgets/parts/auto_complete_parts_field.dart b/lib/views/widgets/parts/auto_complete_parts_field.dart index 1ac563f..7bd26d3 100644 --- a/lib/views/widgets/parts/auto_complete_parts_field.dart +++ b/lib/views/widgets/parts/auto_complete_parts_field.dart @@ -1,18 +1,18 @@ import 'package:flutter/material.dart'; -import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/controllers/providers/api/parts_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; -import 'package:test_sa/models/part.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; +import '../../../models/service_request/spare_parts.dart'; + class AutoCompletePartsField extends StatefulWidget { final String initialValue; final num assetId; final bool clearAfterPick; - final Function(Part) onPick; + final Function(SparePartsWorkOrders) onPick; const AutoCompletePartsField({Key key, this.initialValue, this.assetId, this.onPick, this.clearAfterPick = true}) : super(key: key); @@ -51,7 +51,8 @@ class _AutoCompletePartsFieldState extends State { border: Border.all(color: AColors.black), borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), boxShadow: const [AppStyle.boxShadow]), - child: TypeAheadField( + child: + Container() /*TypeAheadField( textFieldConfiguration: TextFieldConfiguration( style: Theme.of(context).textTheme.subtitle1, controller: _controller, @@ -65,13 +66,13 @@ class _AutoCompletePartsFieldState extends State { textInputAction: TextInputAction.search, ), suggestionsCallback: (vale) async { - return await _partsProvider.getPartsList(host: _settingProvider.host, title: vale, assetId: widget.assetId); + return await _partsProvider.getPartsList(title: vale, assetId: widget.assetId); }, itemBuilder: (context, part) { return ListTile( - title: Text(part.partNo), + title: Text(part?.sparePart?.partNo ?? ""), subtitle: Text( - part.partName, + part?.sparePart?.partName ?? "", style: Theme.of(context).textTheme.caption, ), ); @@ -80,11 +81,12 @@ class _AutoCompletePartsFieldState extends State { if (widget.clearAfterPick) { _controller.clear(); } else { - _controller.text = part.partNo; + _controller.text = part?.sparePart?.partNo; } widget.onPick(part); }, - ), + )*/ + , ); } } diff --git a/lib/views/widgets/parts/part_item.dart b/lib/views/widgets/parts/part_item.dart index bade755..33b0af3 100644 --- a/lib/views/widgets/parts/part_item.dart +++ b/lib/views/widgets/parts/part_item.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/models/part.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/buttons/app_icon_button2.dart'; +import '../../../models/service_request/spare_parts.dart'; + class PartItem extends StatefulWidget { - final Part part; - final Function(Part) onDelete; + final SparePartsWorkOrders part; + final Function(SparePartsWorkOrders) onDelete; final Function(int qty) onEdit; const PartItem({Key key, this.part, this.onEdit, this.onDelete}) : super(key: key); @@ -17,7 +18,6 @@ class PartItem extends StatefulWidget { class _PartItemState extends State { @override Widget build(BuildContext context) { - return Column( children: [ const Divider(), @@ -32,7 +32,7 @@ class _PartItemState extends State { children: [ Expanded( child: Text( - widget?.part?.partNo ?? "", + widget?.part?.sparePart?.partNo ?? "", style: Theme.of(context).textTheme.bodyText1.copyWith(fontSize: 12, fontWeight: FontWeight.bold), ), ), @@ -41,9 +41,9 @@ class _PartItemState extends State { color: Theme.of(context).primaryColor, onPressed: () { if (widget.onEdit == null) { - ++widget.part.quantity; + ++widget.part.qty; } else { - widget.onEdit(++widget.part.quantity); + widget.onEdit(++widget.part.qty); } setState(() {}); }, @@ -51,13 +51,13 @@ class _PartItemState extends State { AIconButton2( iconData: Icons.remove, color: Theme.of(context).primaryColor, - onPressed: widget.part.quantity < 2 + onPressed: widget.part.qty < 2 ? null : () { if (widget.onEdit == null) { - --widget.part.quantity; + --widget.part.qty; } else { - widget.onEdit(--widget.part.quantity); + widget.onEdit(--widget.part.qty); } setState(() {}); }, @@ -66,7 +66,7 @@ class _PartItemState extends State { width: 8 * AppStyle.getScaleFactor(context), ), Text( - widget.part.quantity.toString(), + widget.part.qty.toString(), style: Theme.of(context).textTheme.headline6.copyWith( //fontSize: 12, //fontWeight: FontWeight.bold @@ -77,10 +77,10 @@ class _PartItemState extends State { ), ], ), - widget.part.partName == null + widget.part?.sparePart?.partName == null ? const SizedBox.shrink() : Text( - widget.part.partName, + widget.part?.sparePart?.partName, style: Theme.of(context).textTheme.caption.copyWith(fontSize: 11, fontWeight: FontWeight.bold), maxLines: 1, overflow: TextOverflow.ellipsis, diff --git a/lib/views/widgets/pentry/pentry_pm_kit_form.dart b/lib/views/widgets/pentry/pentry_pm_kit_form.dart index 28cadee..72df9d7 100644 --- a/lib/views/widgets/pentry/pentry_pm_kit_form.dart +++ b/lib/views/widgets/pentry/pentry_pm_kit_form.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/pantry/pm_kit.dart'; @@ -27,7 +26,6 @@ class PentryPMKitForm extends StatefulWidget { class _PentryPMKitFormState extends State { @override Widget build(BuildContext context) { - return ListView.builder( padding: EdgeInsets.only( top: 12 * AppStyle.getScaleFactor(context), @@ -78,7 +76,7 @@ class _PentryPMKitFormState extends State { clearAfterPick: false, initialValue: (model.itemCode?.name ?? "").toString(), onPick: (part) { - model.itemCode = Lookup(id: part.id, name: part.partNo); + model.itemCode = Lookup(id: part.id, name: part?.sparePart?.partNo); }, ), const SizedBox( diff --git a/lib/views/widgets/search/service_request_search_bar.dart b/lib/views/widgets/search/service_request_search_bar.dart index acf54c0..fd2b2f4 100644 --- a/lib/views/widgets/search/service_request_search_bar.dart +++ b/lib/views/widgets/search/service_request_search_bar.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/service_request/service_request_search.dart'; -import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; import 'package:test_sa/views/widgets/buttons/app_small_button.dart'; @@ -12,8 +10,8 @@ import 'package:test_sa/views/widgets/status/service_request/service_request_sta import 'package:test_sa/views/widgets/switch_button.dart'; import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; -import '../../../models/call_request_for_work_order_model.dart'; import '../../../models/engineer.dart'; +import '../../../models/new_models/assigned_employee.dart'; import '../app_text_form_field.dart'; import '../date_and_time/date_picker.dart'; import '../status/report/service_report_all_users.dart'; @@ -62,7 +60,6 @@ class _ServiceRequestsSearchDialogState extends State statuses; final AssistantEmployees initialStatus; final Function(AssistantEmployees) onSelect; + final String title; - const AssistantEmployeeMenu({Key key, this.statuses, this.onSelect, this.initialStatus}) : super(key: key); + const AssistantEmployeeMenu({Key key, this.statuses, this.title, this.onSelect, this.initialStatus}) : super(key: key); @override _SingleAssistantEmployeeMenuState createState() => _SingleAssistantEmployeeMenuState(); @@ -61,48 +63,58 @@ class _SingleAssistantEmployeeMenuState extends State { @override Widget build(BuildContext context) { return Container( - padding: const EdgeInsets.symmetric(horizontal: 16), + height: 60.toScreenHeight, + padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth), decoration: BoxDecoration( - color: AColors.inputFieldBackgroundColor, - border: Border.all( - color: Color(0xffefefef), - ), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - // boxShadow: const [ - // AppStyle.boxShadow - // ] + color: context.isDark ? AppColor.neutral50 : Colors.white, + borderRadius: BorderRadius.circular(10), + boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], ), - child: DropdownButton( - value: _selectedStatus, - iconSize: 24, - icon: const Icon(Icons.keyboard_arrow_down_rounded), - elevation: 0, - isExpanded: true, - hint: Text( - "Select", - style: Theme.of(context).textTheme.subtitle1, - ), - style: TextStyle(color: Theme.of(context).primaryColor), - underline: const SizedBox.shrink(), - onChanged: (AssistantEmployees newValue) { - setState(() { - _selectedStatus = newValue; - }); - widget.onSelect(newValue); - }, - items: widget.statuses.map>((AssistantEmployees value) { - return DropdownMenuItem( - value: value, - child: Text( - value.user?.name ?? "NULL", - style: Theme.of(context).textTheme.titleMedium.copyWith( - color: Theme.of(context).primaryColor, - fontSize: 11, - //fontWeight: FontWeight.bold - ), - ), - ); - }).toList(), + child: Stack( + alignment: Alignment.center, + children: [ + const PositionedDirectional(end: 0, child: Icon(Icons.keyboard_arrow_down_rounded)), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (widget.title != null) + Text( + widget.title, + style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500), + ), + DropdownButton( + value: _selectedStatus, + iconSize: 24, + isDense: true, + icon: const SizedBox.shrink(), + elevation: 0, + isExpanded: true, + hint: Text( + context.translation.select, + style: Theme.of(context).textTheme.bodyLarge, + ), + style: TextStyle(color: Theme.of(context).primaryColor), + underline: const SizedBox.shrink(), + onChanged: (AssistantEmployees newValue) { + setState(() { + _selectedStatus = newValue; + }); + widget.onSelect(newValue); + }, + items: widget.statuses.map>((AssistantEmployees value) { + return DropdownMenuItem( + value: value, + child: Text( + value.user?.name ?? "NULL", + style: Theme.of(context).textTheme.bodyLarge, + ), + ); + }).toList(), + ), + ], + ), + ], ), ); } diff --git a/lib/views/widgets/status/report/service_report_assistant_employee_menu.dart b/lib/views/widgets/status/report/service_report_assistant_employee_menu.dart index 1bf2c49..1f46500 100644 --- a/lib/views/widgets/status/report/service_report_assistant_employee_menu.dart +++ b/lib/views/widgets/status/report/service_report_assistant_employee_menu.dart @@ -1,15 +1,17 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:test_sa/models/service_request/search_work_order.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import 'package:test_sa/views/widgets/status/assistant_employee_menu.dart'; import '../../../../controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart'; +import '../../../../models/new_models/assistant_employee.dart'; class ServiceReportAssistantEmployeeMenu extends StatelessWidget { final Function(AssistantEmployees) onSelect; final AssistantEmployees initialValue; - const ServiceReportAssistantEmployeeMenu({Key key, @required this.onSelect, this.initialValue}) : super(key: key); + final String title; + final num assetId; + const ServiceReportAssistantEmployeeMenu({Key key, @required this.onSelect, @required this.assetId, this.title, this.initialValue}) : super(key: key); @override Widget build(BuildContext context) { ServiceReportAssistantsEmployeeProvider menuProvider = Provider.of(context); @@ -18,9 +20,10 @@ class ServiceReportAssistantEmployeeMenu extends StatelessWidget { isFailedLoading: menuProvider.assistantEmployees == null, stateCode: menuProvider.stateCode, onRefresh: () async { - await menuProvider.getAssistantEmployees(); + await menuProvider.getAssistantEmployees(assetId); }, child: AssistantEmployeeMenu( + title: title, initialStatus: initialValue, statuses: menuProvider.assistantEmployees, onSelect: onSelect, diff --git a/lib/views/widgets/status/report/service_report_equipment_status.dart b/lib/views/widgets/status/report/service_report_equipment_status.dart index 63f9dfc..50ccd84 100644 --- a/lib/views/widgets/status/report/service_report_equipment_status.dart +++ b/lib/views/widgets/status/report/service_report_equipment_status.dart @@ -7,7 +7,7 @@ import 'package:test_sa/controllers/providers/api/status_drop_down/report/servic import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/service_report.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import 'package:test_sa/views/widgets/status/single_status_menu.dart'; @@ -42,12 +42,9 @@ class _ServiceReportEquipmentStatusMenuState extends State(context); + ServiceReportLastCallsProvider menuProvider = Provider.of(context); return LoadingManager( - isLoading: _menuProvider.isLoading, - isFailedLoading: _menuProvider.calls == null, - stateCode: _menuProvider.stateCode, - onRefresh: () async {}, - child: SingleStatusMenu( - initialStatus: report?.callLastSituation, - statuses: _menuProvider.calls, - onSelect: onSelect, - )); + isLoading: menuProvider.isLoading, + isFailedLoading: menuProvider.calls == null, + stateCode: menuProvider.stateCode, + onRefresh: () async { + await menuProvider.getCalls( + typeName: report.assetType?.name, + id: report.id, + parentId: parentId, + ); + }, + child: SingleStatusMenu( + title: title, + initialStatus: report?.calllastSituation, + statuses: menuProvider.calls, + onSelect: onSelect, + ), + ); } } diff --git a/lib/views/widgets/status/report/service_report_status.dart b/lib/views/widgets/status/report/service_report_status.dart index b21057c..1c78915 100644 --- a/lib/views/widgets/status/report/service_report_status.dart +++ b/lib/views/widgets/status/report/service_report_status.dart @@ -7,7 +7,7 @@ import 'package:test_sa/controllers/providers/api/status_drop_down/report/servic import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/models/service_report.dart'; +import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import 'package:test_sa/views/widgets/status/single_status_menu.dart'; @@ -42,12 +42,9 @@ class _ServiceReportStatusMenuState extends State { stateCode: menuProvider.stateCode == null || callsLastSituationsProvider.stateCode == null ? null : max(menuProvider.stateCode ?? 0, callsLastSituationsProvider.stateCode ?? 0), onRefresh: () async { await callsLastSituationsProvider.getCalls( - user: userProvider.user, - host: settingProvider.host, - serviceStatus: widget.report.equipmentStatus?.id, - typeName: widget.report.type?.name, + typeName: widget.report.assetType?.name, id: widget.report.id, - woId: widget.request.id, + parentId: widget.request.id, ); if (menuProvider.stateCode == null) { menuProvider.reset(); @@ -59,14 +56,11 @@ class _ServiceReportStatusMenuState extends State { statuses: menuProvider.statuses, initialStatus: widget.report.equipmentStatus, onSelect: (status) { - widget.report.callLastSituation = null; + widget.report.calllastSituation = null; callsLastSituationsProvider.getCalls( - user: userProvider.user, - host: settingProvider.host, - serviceStatus: status.id, id: widget.report.id, - woId: widget.request.id, - typeName: widget.report.type?.name, + parentId: widget.request.id, + typeName: widget.report.assetType?.name, ); widget.onSelect(status); diff --git a/lib/views/widgets/status/service_request/supplier_engineers_menu.dart b/lib/views/widgets/status/service_request/supplier_engineers_menu.dart index 44b30c8..03f2b50 100644 --- a/lib/views/widgets/status/service_request/supplier_engineers_menu.dart +++ b/lib/views/widgets/status/service_request/supplier_engineers_menu.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:test_sa/models/service_request/search_work_order.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; +import '../../../../models/service_request/supp_engineer_work_orders.dart'; +import '../../../../models/service_request/supplier_details.dart'; + class SupplierEngineersMenu extends StatefulWidget { final List engineers; final SuppEngineerWorkOrders initialValue; diff --git a/lib/views/widgets/status/single_status_menu.dart b/lib/views/widgets/status/single_status_menu.dart index 6a9a990..b035de1 100644 --- a/lib/views/widgets/status/single_status_menu.dart +++ b/lib/views/widgets/status/single_status_menu.dart @@ -1,15 +1,18 @@ import 'package:flutter/material.dart'; +import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/models/lookup.dart'; -import 'package:test_sa/views/app_style/colors.dart'; -import 'package:test_sa/views/app_style/sizing.dart'; + +import '../../../new_views/app_style/app_color.dart'; class SingleStatusMenu extends StatefulWidget { final List statuses; final Lookup initialStatus; final Function(Lookup) onSelect; final bool enabled; + final String title; - const SingleStatusMenu({Key key, this.enabled = true, this.statuses, this.onSelect, this.initialStatus}) : super(key: key); + const SingleStatusMenu({Key key, this.enabled = true, this.title, this.statuses, this.onSelect, this.initialStatus}) : super(key: key); @override _SingleStatusMenuState createState() => _SingleStatusMenuState(); @@ -61,50 +64,60 @@ class _SingleStatusMenuState extends State { @override Widget build(BuildContext context) { return Container( - padding: const EdgeInsets.symmetric(horizontal: 16), + height: 60.toScreenHeight, + padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth), decoration: BoxDecoration( - color: AColors.inputFieldBackgroundColor, - border: Border.all( - color: Color(0xffefefef), - ), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - // boxShadow: const [ - // AppStyle.boxShadow - // ] + color: context.isDark ? AppColor.neutral50 : Colors.white, + borderRadius: BorderRadius.circular(10), + boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], ), - child: DropdownButton( - value: _selectedStatus, - iconSize: 24, - icon: const Icon(Icons.keyboard_arrow_down_rounded), - elevation: 0, - isExpanded: true, - hint: Text( - "Select", - style: Theme.of(context).textTheme.subtitle1, - ), - style: TextStyle(color: Theme.of(context).primaryColor), - underline: const SizedBox.shrink(), - onChanged: widget.enabled == false - ? null - : (Lookup newValue) { - setState(() { - _selectedStatus = newValue; - }); - widget.onSelect(newValue); - }, - items: widget.statuses.map>((Lookup value) { - return DropdownMenuItem( - value: value, - child: Text( - value.name, - style: Theme.of(context).textTheme.subtitle1.copyWith( - color: widget.enabled ? Theme.of(context).primaryColor : Colors.grey, - fontSize: 11, - //fontWeight: FontWeight.bold - ), - ), - ); - }).toList(), + child: Stack( + alignment: Alignment.center, + children: [ + if (widget.enabled) const PositionedDirectional(end: 0, child: Icon(Icons.keyboard_arrow_down_rounded)), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (widget.title != null) + Text( + widget.title, + style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500), + ), + DropdownButton( + value: _selectedStatus, + iconSize: 24, + isDense: true, + icon: const SizedBox.shrink(), + elevation: 0, + isExpanded: true, + hint: Text( + context.translation.select, + style: Theme.of(context).textTheme.bodyLarge, + ), + style: TextStyle(color: Theme.of(context).primaryColor), + underline: const SizedBox.shrink(), + onChanged: widget.enabled == false + ? null + : (Lookup newValue) { + setState(() { + _selectedStatus = newValue; + }); + widget.onSelect(newValue); + }, + items: widget.statuses?.map>((value) { + return DropdownMenuItem( + value: value, + child: Text( + value?.name ?? "", + style: Theme.of(context).textTheme.bodyLarge, + ), + ); + })?.toList(), + ), + ], + ), + ], ), ); } From 43b2f18a1a251cff652262a08f685b14a1e7f034 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 31 Oct 2023 10:43:07 +0300 Subject: [PATCH 2/2] New Work Order [In Progress] --- .../api/service_requests_provider.dart | 92 +++++-------------- .../service_request/service_report.dart | 6 +- .../work_order/create_service_report.dart | 47 +++------- 3 files changed, 43 insertions(+), 102 deletions(-) diff --git a/lib/controllers/providers/api/service_requests_provider.dart b/lib/controllers/providers/api/service_requests_provider.dart index 0d20dde..e3428ed 100644 --- a/lib/controllers/providers/api/service_requests_provider.dart +++ b/lib/controllers/providers/api/service_requests_provider.dart @@ -309,82 +309,40 @@ class ServiceRequestsProvider extends ChangeNotifier { } } - Future createServiceReport({@required ServiceReport report, @required ServiceRequest request}) async { + Future createServiceReport(BuildContext context, {@required ServiceReport report, @required User user, @required ServiceRequest request}) async { Response response; try { - // Map body = { - // "id": 0, - // "parentWOId": null, - // "workOrderNo": "", - // "workOrderYear": null, - // "workOrderSequennce": null, - // "callRequest": { - // "id": request.id, - // }, - // "assetType": report.assetType?.toJson(), - // "assignedEmployee": {"id": report.engineer?.id, "name": report.engineer?.name ?? ""}, - // "visitDate": report.returnToService?.toIso8601String() ?? "", - // // "assistantEmployees": [ - // // {"id": report.engineer.id, "name": report.engineer.name}, - // // ], - // "supplier": null, - // "vendorTicketNumber": null, - // "contactPersonWorkOrders": [ - // { - // "id": 0, - // // "employeeCode": "", - // "name": user.userName, - // "telephone": user.phoneNumber, - // // "job": "", - // "email": user.email, - // // "land": "", - // "contactUserId": user.userID, - // } - // ], - // "calllastSituation": report.callLastSituation?.toJson(), - // "currentSituation": null, - // "repairLocation": report.repairLocation?.toJson(), - // "reason": report.reason?.toJson(), - // "startofWorkTime": report.timer?.startAt?.toIso8601String() ?? "", - // "endofWorkTime": report.timer?.endAt?.toIso8601String() ?? "", - // "workingHours": report?.workingHours, - // "travelingHours": report.travelingHours, - // "travelingExpenses": report.travelingExpense ?? 0, - // if (report.faultDescription != null) "faultDescription": report.faultDescription.toJson(), - // "sparePartsWorkOrders": report.parts - // ?.map( - // (p) => { - // "id": p.reportPartID ?? 0, - // "sparePart": {"id": p.id, "partNo": p.partNo, "partName": p.partName}, - // "qty": p.quantity - // }, - // ) - // ?.toList(), - // "reviewComment": "", - // "comment": report.comment, - // "attachmentsWorkOrder": request.devicePhotos?.map((e) => {"name": e})?.toList(), - // "equipmentStatus": report.equipmentStatus?.toJson(), - // "suppEngineerWorkOrders": null, - // "engSignature": report.signatureEngineer, - // "nurseSignature": report.signatureNurse, - // "woParentDto": null, - // }; - // body["uid"] = user.id; - // body["token"] = user.token; - response = await ApiManager.instance.post(URLs.createServiceReport, body: {}); - // response = await post( - // Uri.parse( - // host+URLs.createServiceReport), - // body: body, - // ); - + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); + final body = report.toJson(); + final callRequest = CallRequest(id: num.tryParse(request?.id ?? "")).toJson(); + final contactPerson = [ + { + "id": 0, + // "employeeCode": "", + "name": user.userName, + "telephone": user.phoneNumber, + // "job": "", + "email": user.email, + // "land": "", + "contactUserId": user.userID, + } + ]; + body.update("contactPersonWorkOrders", (value) => contactPerson, ifAbsent: () => contactPerson); + body.update("callRequest", (value) => callRequest, ifAbsent: () => callRequest); + response = await ApiManager.instance.post(URLs.createServiceReport, body: body); stateCode = response.statusCode; if (response.statusCode >= 200 && response.statusCode < 300) { reset(); notifyListeners(); + Fluttertoast.showToast(msg: context.translation.successfulRequestMessage); + Navigator.of(context).pop(); + } else { + Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest}: ${json.decode(response.body)['message']}"); } + Navigator.pop(context); return response.statusCode; } catch (error) { + Navigator.pop(context); print(error); return -1; } diff --git a/lib/models/service_request/service_report.dart b/lib/models/service_request/service_report.dart index d97a3f9..25ae4cc 100644 --- a/lib/models/service_request/service_report.dart +++ b/lib/models/service_request/service_report.dart @@ -228,7 +228,7 @@ class ServiceReport { ); Map toJson() { final map = {}; - map['id'] = id; + map['id'] = id ?? 0; map['parentWOId'] = parentWOId; map['workOrderNo'] = workOrderNo; map['workOrderYear'] = workOrderYear; @@ -301,4 +301,8 @@ class ServiceReport { } return map; } + + Future validate() async { + return true; + } } diff --git a/lib/views/pages/user/requests/work_order/create_service_report.dart b/lib/views/pages/user/requests/work_order/create_service_report.dart index 11ac10e..84c9f65 100644 --- a/lib/views/pages/user/requests/work_order/create_service_report.dart +++ b/lib/views/pages/user/requests/work_order/create_service_report.dart @@ -3,7 +3,6 @@ import 'dart:developer'; import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/attachment.dart'; import 'package:test_sa/controllers/providers/api/parts_provider.dart'; @@ -24,7 +23,6 @@ import 'package:test_sa/views/widgets/e_signature/e_signature.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import 'package:test_sa/views/widgets/status/report/service_report_last_call.dart'; -import '../../../../../controllers/api_routes/http_status_manger.dart'; import '../../../../../controllers/providers/api/status_drop_down/report/service_types_provider.dart'; import '../../../../../models/lookup.dart'; import '../../../../../models/service_request/spare_parts.dart'; @@ -182,6 +180,7 @@ class _CreateServiceReportState extends State with TickerPr assetId: _serviceReport.callRequest?.asset?.id, initialValue: (_serviceReport.assistantEmployees?.isNotEmpty ?? false) ? _serviceReport.assistantEmployees?.first : null, onSelect: (employee) { + log(employee.toJson().toString()); _serviceReport.assistantEmployees = [employee]; }, ), @@ -192,7 +191,6 @@ class _CreateServiceReportState extends State with TickerPr staticData: _spareParts, initialValue: (_serviceReport.sparePartsWorkOrders?.isNotEmpty ?? false) ? _serviceReport.sparePartsWorkOrders.first.sparePart : null, onSelect: (part) { - log(part.toJson().toString()); _serviceReport.sparePartsWorkOrders.clear(); _serviceReport.sparePartsWorkOrders.add(SparePartsWorkOrders(sparePart: part)); setState(() {}); @@ -214,12 +212,12 @@ class _CreateServiceReportState extends State with TickerPr oldSignature: _serviceReport.engSignature, newSignature: _serviceReport.localEngSignature, onSaved: (signature) { - if (signature == null || signature.isEmpty) { - setState(() {}); - return; - } + // if (signature == null || signature.isEmpty) { + // setState(() {}); + // return; + // } _serviceReport.localEngSignature = signature; - _serviceReport.engSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + _serviceReport.engSignature = signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}" : null; }, ), 24.height, @@ -229,37 +227,18 @@ class _CreateServiceReportState extends State with TickerPr AppFilledButton( label: context.translation.submitRequest, onPressed: () async { - // if (!_formKey.currentState.validate()) { - // setState(() {}); - // return; - // } - // if (!(await _serviceReport.validate())) { - // setState(() {}); - // return; - // } + if ((!_formKey.currentState.validate()) || (!(await _serviceReport.validate()))) { + setState(() {}); + return; + } _formKey.currentState.save(); - - _isLoading = true; - setState(() {}); _serviceReport.attachmentsWorkOrder ??= []; + if (_files.isEmpty) _serviceReport.attachmentsWorkOrder = []; for (var file in _files) { _serviceReport.attachmentsWorkOrder.add(Attachment(name: "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}")); } - int status = await _serviceRequestsProvider.createServiceReport(report: _serviceReport, request: widget.request); - _isLoading = false; - setState(() {}); - if (status >= 200 && status < 300) { - Fluttertoast.showToast( - msg: context.translation.successfulRequestMessage, - ); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - } else { - String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(errorMessage), - )); - } + final user = Provider.of(context, listen: false).user; + await _serviceRequestsProvider.createServiceReport(context, report: _serviceReport, request: widget.request, user: user); }, ), ],