diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index cb2c6bb..a229b07 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -96,8 +96,12 @@ class GasRefillProvider extends ChangeNotifier { "token": user.token ?? "", "building": {"id": building?.id, "name": building?.name, "value": building?.value}, "floor": {"id": floor.id, "name": floor.name, "value": floor.value}, - "expectedDate": "2023-06-08T07:03:07.866Z", - "expectedTime": "2023-06-08T07:03:07.866Z", + if (expectedDateTime != null) "expectedDate": expectedDateTime, + if (expectedDateTime != null) "expectedTime": expectedDateTime, + if (startDate != null) "startDate": startDate, + if (startDate != null) "startTime": startDate, + if (endDate != null) "endDate": endDate, + if (endDate != null) "endTime": endDate, "department": {"id": department.id, "departmentName": department.name, "departmentCode": "", "ntCode": ""}, "GazRefillNo": "GR-${DateTime.now().toString().split(" ").first}", "status": model.status.toMap(), @@ -174,4 +178,6 @@ class GasRefillProvider extends ChangeNotifier { Floors floor; Departments department; DateTime expectedDateTime; + DateTime startDate; + DateTime endDate; } 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 d3903a4..716a7e6 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -27,6 +27,7 @@ import 'package:test_sa/views/widgets/status/gas_refill/gas_type.dart'; import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; import '../../../../controllers/localization/localization.dart'; +import '../../../../models/enums/user_types.dart'; class RequestGasRefill extends StatefulWidget { static const String id = "/request-gas-refill"; @@ -227,24 +228,89 @@ class _RequestGasRefillState extends State { }, ), const SizedBox(height: 8), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const ASubTitle("Expected Date Time"), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - ADateTimePicker( - date: _gasRefillProvider.expectedDateTime, - from: DateTime.now().subtract(const Duration(days: 365)), - to: DateTime.now().add(const Duration(days: 365)), - onDateTimePicker: (date) { - _gasRefillProvider.expectedDateTime = date; - setState(() {}); - }, - ), - ], - ), + if (_userProvider.user?.type == UsersTypes.normal_user) + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("Expected Date Time"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _gasRefillProvider.expectedDateTime, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _gasRefillProvider.expectedDateTime = date; + setState(() {}); + }, + ), + ], + ), + if (_userProvider.user?.type == UsersTypes.engineer) + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("Start of Work"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _gasRefillProvider.startDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _gasRefillProvider.startDate = date; + setState(() {}); + }, + ), + ], + ), + ), + const SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const ASubTitle("End of Work"), + SizedBox( + height: 8 * AppStyle.getScaleFactor(context), + ), + ADateTimePicker( + date: _gasRefillProvider.endDate, + from: DateTime.now().subtract(const Duration(days: 365)), + to: DateTime.now().add(const Duration(days: 365)), + onDateTimePicker: (date) { + _gasRefillProvider.endDate = date; + setState(() {}); + }, + ), + ], + ), + ), + ], + ), + if (_userProvider.user?.type == UsersTypes.engineer) const SizedBox(height: 8), + if (_userProvider.user?.type == UsersTypes.engineer) ASubTitle(_subtitle.workingHours), + if (_userProvider.user?.type == UsersTypes.engineer) const SizedBox(height: 4), + if (_userProvider.user?.type == UsersTypes.engineer) + ATextFormField( + initialValue: null, + textAlign: TextAlign.center, + hintText: _gasRefillProvider.startDate == null + ? "0" + : ((_gasRefillProvider.endDate?.difference(_gasRefillProvider.startDate)?.inMinutes ?? 0) / 60)?.toStringAsFixed(2)?.toString() ?? "0", + enable: false, + style: Theme.of(context).textTheme.subtitle1, + validator: (value) => Validator.isNumeric(value) ? null : _subtitle.requiredWord, + textInputType: TextInputType.number, + onSaved: (value) { + // _serviceReport.workHours = value; + }, + ), const SizedBox(height: 8), Divider(color: Theme.of(context).colorScheme.primary), const SizedBox(height: 4),