diff --git a/lib/models/device/device_transfer.dart b/lib/models/device/device_transfer.dart index ec1d5bfb..84ab75c2 100644 --- a/lib/models/device/device_transfer.dart +++ b/lib/models/device/device_transfer.dart @@ -66,7 +66,6 @@ class DeviceTransfer { startAt: DateTime.tryParse(parsedJson["senderStartDate"] ?? ""), endAt: DateTime.tryParse(parsedJson["senderEndDate"] ?? ""), durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(), - stopped: parsedJson["workingHours"] == null ? null : true, ), // startDate: parsedJson["senderStartDate"] == null ? null : DateTime.parse(parsedJson["senderStartDate"]), // endDate: parsedJson["senderEndDate"] == null ? null : DateTime.parse(parsedJson["senderEndDate"]), diff --git a/lib/models/device/device_transfer_info.dart b/lib/models/device/device_transfer_info.dart index 00e1d387..093beb46 100644 --- a/lib/models/device/device_transfer_info.dart +++ b/lib/models/device/device_transfer_info.dart @@ -81,7 +81,6 @@ class DeviceTransferInfo { startAt: DateTime.tryParse(parsedJson["${key}start_date"] ?? ""), endAt: DateTime.tryParse(parsedJson["${key}end_date"] ?? ""), durationInSecond: ((parsedJson["${key}working_hours"] ?? 0) * 60 * 60).toInt(), - stopped: parsedJson["${key}working_hours"] == null || (parsedJson["${key}working_hours"] as String).isEmpty ? null : true, ), travelingHours: parsedJson["${key}travel_hours"], userName: parsedJson["${key}name"], diff --git a/lib/models/pantry/pentry.dart b/lib/models/pantry/pentry.dart index 40a9034e..5d3a4163 100644 --- a/lib/models/pantry/pentry.dart +++ b/lib/models/pantry/pentry.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/pantry/calibration_tools.dart'; @@ -45,12 +46,28 @@ class Pentry { this.localNurseSignature, this.localEngineerSignature}); - bool validate() { - if (actualVisitDate == null) return false; - if (expectedVisitDate == null) return false; - if (timer == null && timer.endAt != null) return false; + Future validate() async { + if (actualVisitDate == null) { + await Fluttertoast.showToast(msg: "Actual visit date is Required"); + return false; + } + if (expectedVisitDate == null) { + await Fluttertoast.showToast(msg: "expected visit date is 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 (ppmVisitStatus == null) return false; - //if(status == null) return false; + if (status?.id == null) { + await Fluttertoast.showToast(msg: "Device Status is Required"); + return false; + } return true; } @@ -121,7 +138,6 @@ class Pentry { startAt: DateTime.tryParse(map["startDate"] ?? ""), endAt: DateTime.tryParse(map["endDate"] ?? ""), durationInSecond: (int.tryParse(map["workingHours"] ?? "") ?? 0) * 60 * 60, - stopped: map["workingHours"] == null ? null : true, ), // contacts: contacts, ppmCheckLists: ppmCheckLists, diff --git a/lib/models/service_report.dart b/lib/models/service_report.dart index a8284224..7abb59cb 100644 --- a/lib/models/service_report.dart +++ b/lib/models/service_report.dart @@ -104,7 +104,7 @@ class ServiceReport { // "workPerformed":workPreformed // }; // } - _map["faultDescription"] = faultDescription?.id ==null ? null :{"id": faultDescription?.id ?? 0, "workPerformed": faultDescription?.workPerformed}; + _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) { @@ -161,6 +161,14 @@ class ServiceReport { await Fluttertoast.showToast(msg: "Visit 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; @@ -217,7 +225,6 @@ class ServiceReport { startAt: DateTime.tryParse(parsedJson["startofWorkTime"] ?? ""), endAt: DateTime.tryParse(parsedJson["endofWorkTime"] ?? ""), durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 * 60).toInt(), - stopped: parsedJson["workingHours"] == null ? null : true, ), //workPreformed: parsedJson["work_performed"], device: Device.fromJson(parsedJson["callRequest"]["asset"]), diff --git a/lib/models/timer_model.dart b/lib/models/timer_model.dart index 907d006d..1e68767d 100644 --- a/lib/models/timer_model.dart +++ b/lib/models/timer_model.dart @@ -2,7 +2,7 @@ class TimerModel { DateTime startAt; DateTime endAt; int durationInSecond; - bool stopped; + // bool stopped; - TimerModel({this.startAt, this.endAt, this.durationInSecond, this.stopped}); + TimerModel({this.startAt, this.endAt, this.durationInSecond}); } diff --git a/lib/views/pages/device_transfer/update_device_transfer.dart b/lib/views/pages/device_transfer/update_device_transfer.dart index a2787979..9a870ad9 100644 --- a/lib/views/pages/device_transfer/update_device_transfer.dart +++ b/lib/views/pages/device_transfer/update_device_transfer.dart @@ -45,12 +45,13 @@ class _UpdateDeviceTransferState extends State { final GlobalKey _scaffoldKey = GlobalKey(); _update() async { - if (_formModel?.workingHours == null || _formModel.workingHours.isEmpty) { - await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started"); - return; - } else if ((_formModel?.timer?.stopped ?? false) == false) { - await Fluttertoast.showToast(msg: "Stop The Timer"); - return; + if (_formModel?.timer?.startAt == null) { + await Fluttertoast.showToast(msg: "Working Hours Required"); + return false; + } + if (_formModel?.timer?.endAt == null) { + await Fluttertoast.showToast(msg: "Please Stop The Timer"); + return false; } _validate = true; if (!_formKey.currentState.validate()) { @@ -202,9 +203,8 @@ class _UpdateDeviceTransferState extends State { onSaved: (signature) { _signature = signature; if (signature == null || signature.isEmpty) return; - _formModel.signature = - "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - // base64Encode(signature); + _formModel.signature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + // base64Encode(signature); }, ), Padding( 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 df6e58f0..e91de02e 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 @@ -157,9 +157,6 @@ class _WorkOrderDetailsBottomSheetState extends State with TickerProvid if (_serviceReport?.workingHours == null) { await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started"); return; - } else if ((_serviceReport?.timer?.stopped ?? false) == false) { - await Fluttertoast.showToast(msg: "Stop The Timer"); - return; } _validate = true; print("jere1245"); diff --git a/lib/views/pages/user/visits/pantry/edit_pentry.dart b/lib/views/pages/user/visits/pantry/edit_pentry.dart index d2d52054..744c0a20 100644 --- a/lib/views/pages/user/visits/pantry/edit_pentry.dart +++ b/lib/views/pages/user/visits/pantry/edit_pentry.dart @@ -42,7 +42,7 @@ class _EditPentryState extends State with SingleTickerProviderStateM _onSubmit() async { _validate = true; - if (!_pentry.validate()) { + if (!(await _pentry.validate())) { setState(() {}); return; } diff --git a/lib/views/widgets/pentry/pentry_info_form.dart b/lib/views/widgets/pentry/pentry_info_form.dart index 33ccd2ed..37989014 100644 --- a/lib/views/widgets/pentry/pentry_info_form.dart +++ b/lib/views/widgets/pentry/pentry_info_form.dart @@ -72,6 +72,7 @@ class _PentryInfoFormState extends State { ), AppTimer( timer: widget.model.timer, + enabled: widget.model.timer.endAt == null, onChange: (timer) async { widget.model.timer = timer; return true; diff --git a/lib/views/widgets/timer/app_timer.dart b/lib/views/widgets/timer/app_timer.dart index 9e887905..e67a34ce 100644 --- a/lib/views/widgets/timer/app_timer.dart +++ b/lib/views/widgets/timer/app_timer.dart @@ -34,7 +34,7 @@ class _AppTimerState extends State { _startTimer() async { if (!_running) { final time = DateTime.now(); - bool result = await widget.onChange(TimerModel(startAt: time, endAt: null, durationInSecond: _delay, stopped: false)); + bool result = await widget.onChange(TimerModel(startAt: time, endAt: null, durationInSecond: _delay)); if (!result) return; _running = true; @@ -54,7 +54,7 @@ class _AppTimerState extends State { _stopTimer() async { final time = DateTime.now(); final tempStartAt = _startAt.add(Duration(seconds: _delay)); - bool result = await widget.onChange(TimerModel(startAt: tempStartAt, endAt: time, durationInSecond: _delay, stopped: true)); + bool result = await widget.onChange(TimerModel(startAt: tempStartAt, endAt: time, durationInSecond: _delay)); if (!result) return; _running = false; _endAt = time;