From bec9c38269d139eb95544a191ab889911375284a Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Sun, 6 Aug 2023 11:47:21 +0300 Subject: [PATCH] In track gas refill update: - add timer for working hours. - enable the engineer to add start and end date. --- .../providers/api/gas_refill_provider.dart | 13 +++++++---- lib/models/gas_refill/gas_refill_model.dart | 6 ++++- .../user/gas_refill/request_gas_refill.dart | 23 ++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index 5097f742..9fde956b 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -6,6 +6,7 @@ import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/models/gas_refill/gas_refill_model.dart'; import 'package:test_sa/models/hospital.dart'; +import 'package:test_sa/models/timer_model.dart'; import 'package:test_sa/models/user.dart'; class GasRefillProvider extends ChangeNotifier { @@ -158,11 +159,12 @@ class GasRefillProvider extends ChangeNotifier { "status": newModel.status.toMap(), "expectedDate": newModel.expectedDate?.toIso8601String(), "expectedTime": newModel.expectedDate?.toIso8601String(), - "startDate": startDate?.toIso8601String(), - "startTime": startDate?.toIso8601String(), - "endDate": endDate?.toIso8601String(), - "endTime": endDate?.toIso8601String(), - "workingHours": ((endDate?.difference(startDate)?.inMinutes ?? 0) / 60), + "startDate": newModel.startDate?.toIso8601String(), + "startTime": newModel.startDate?.toIso8601String(), + "endDate": newModel.endDate?.toIso8601String(), + "endTime": newModel.endDate?.toIso8601String(), + // "workingHours": ((endDate?.difference(startDate)?.inMinutes ?? 0) / 60), + 'workingHours': newModel.workingHours, "assignedEmployee": oldModel?.assignedEmployee?.id == null ? null : oldModel?.assignedEmployee?.toJson(), "site": hospital?.toMap(), "building": building?.toJson(includeFloors: false), @@ -208,4 +210,5 @@ class GasRefillProvider extends ChangeNotifier { DateTime expectedDateTime; DateTime startDate; DateTime endDate; + TimerModel timer; } diff --git a/lib/models/gas_refill/gas_refill_model.dart b/lib/models/gas_refill/gas_refill_model.dart index 291ee5ad..7dbcaaa2 100644 --- a/lib/models/gas_refill/gas_refill_model.dart +++ b/lib/models/gas_refill/gas_refill_model.dart @@ -21,8 +21,9 @@ class GasRefillModel { String signatureEngineer; Uint8List localNurseSignature; Uint8List localEngineerSignature; - + num workingHours; DateTime startDate, endDate, expectedDate; + GasRefillModel({ this.id, //this.userId, @@ -41,6 +42,7 @@ class GasRefillModel { this.signatureEngineer, this.localEngineerSignature, this.localNurseSignature, + this.workingHours, }); bool validate() { @@ -73,6 +75,7 @@ class GasRefillModel { localNurseSignature = model.localNurseSignature; signatureEngineer = model.signatureEngineer; signatureNurse = model.signatureNurse; + workingHours = model.workingHours; } factory GasRefillModel.fromJson(Map parsedJson) { @@ -97,6 +100,7 @@ class GasRefillModel { assignedEmployee: AssignedEmployee.fromJson(parsedJson['assignedEmployee'] ?? {}), signatureEngineer: URLs.getFileUrl(parsedJson["engSignature"]), signatureNurse: URLs.getFileUrl(parsedJson["nurseSignature"]), + workingHours: parsedJson["workingHours"], ); } } diff --git a/lib/views/pages/user/gas_refill/request_gas_refill.dart b/lib/views/pages/user/gas_refill/request_gas_refill.dart index 9335cd04..c8c6c8fb 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -32,6 +32,7 @@ import '../../../../controllers/localization/localization.dart'; import '../../../../controllers/providers/api/hospitals_provider.dart'; import '../../../../models/enums/user_types.dart'; import '../../../widgets/e_signature/e_signature.dart'; +import '../../../widgets/timer/app_timer.dart'; class RequestGasRefill extends StatefulWidget { static const String id = "/request-gas-refill"; @@ -275,11 +276,31 @@ class _RequestGasRefillState extends State { }, ), const SizedBox(height: 8), + ASubTitle(_subtitle.workingHours), + if (widget.gasRefillModel != null) const SizedBox(height: 8), + if (widget.gasRefillModel != null) + Row( + children: [ + Expanded( + child: AppTimer( + timer: _gasRefillProvider.timer, + onChange: (timer) async { + _gasRefillProvider.timer = timer; + _formModel.startDate ??= timer.startAt; + _gasRefillProvider.endDate = timer.endAt; + _formModel.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); + return true; + }, + ), + ), + ], + ), + const SizedBox(height: 8), if (_userProvider.user?.type == UsersTypes.normal_user || widget.gasRefillModel != null) Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - const ASubTitle("Expected Date Time"), + const ASubTitle("Expected Date"), SizedBox( height: 8 * AppStyle.getScaleFactor(context), ),