diff --git a/assets/translations/ar.json b/assets/translations/ar.json index ae6efa25..d93fe7f1 100644 --- a/assets/translations/ar.json +++ b/assets/translations/ar.json @@ -35,5 +35,8 @@ "onlyNumbers": "يسمح بإدخال الأرقام فقط", "youHaveToSelect" : "يجب عليك إختيار", "building" : "المبنى", - "floor" : "الطابق" + "floor" : "الطابق", + "youHaveToAddRequests" : "يجب إضافة طلبات", + "createdSuccessfully" : "إكتمل الطلب بنجاح", + "failedToCompleteRequest" : "فشل إتمام الطلب" } \ No newline at end of file diff --git a/assets/translations/en.json b/assets/translations/en.json index c0632955..b2ebe0c6 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -35,5 +35,8 @@ "onlyNumbers": "Only Numbers Allowed", "youHaveToSelect" : "You have to select", "building" : "Building", - "floor" : "Floor" + "floor" : "Floor", + "youHaveToAddRequests" : "You have to add requests", + "createdSuccessfully" : "Created successfully", + "failedToCompleteRequest" : "Failed to complete request" } \ No newline at end of file diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index d758828d..5b631d5d 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -96,16 +96,16 @@ class GasRefillProvider extends ChangeNotifier { Map body = { "uid": user.id.toString(), "token": user.token ?? "", - "site": hospital?.toMap(), - "building": {"id": building?.id, "name": building?.name, "value": building?.value}, - "floor": {"id": floor?.id, "name": floor?.name, "value": floor?.value}, + "site": model.site?.toJson(), + "building": model.building != null ? {"id": model.building?.id, "name": model.building?.name, "value": model.building?.value} : null, + "floor": model.floor != null ? {"id": model.floor?.id, "name": model.floor?.name, "value": model.floor?.value} : null, //if (expectedDateTime != null) "expectedDate": expectedDateTime?.toIso8601String(), if (expectedDateTime != null) "expectedTime": expectedDateTime?.toIso8601String(), if (timer?.startAt != null) "startDate": timer.startAt.toIso8601String(), if (timer?.startAt != null) "startTime": timer.startAt.toIso8601String(), if (timer?.endAt != null) "endDate": timer.endAt.toIso8601String(), if (timer?.endAt != null) "endTime": timer.endAt.toIso8601String(), - "department": {"id": department?.id, "departmentName": department?.name, "departmentCode": "", "ntCode": ""}, + "department": model.department?.toJson(), "GazRefillNo": "GR-${DateTime.now().toString().split(" ").first}", "status": model.status?.toMap(), }; diff --git a/lib/models/enums/translation_keys.dart b/lib/models/enums/translation_keys.dart index abfa82b4..69c9368e 100644 --- a/lib/models/enums/translation_keys.dart +++ b/lib/models/enums/translation_keys.dart @@ -37,4 +37,6 @@ enum TranslationKeys { building, floor, createdSuccessfully, + failedToCompleteRequest, + youHaveToAddRequests, } diff --git a/lib/new_views/pages/new_gas_refill_request_page.dart b/lib/new_views/pages/new_gas_refill_request_page.dart index df5f2cd8..e3b77b3d 100644 --- a/lib/new_views/pages/new_gas_refill_request_page.dart +++ b/lib/new_views/pages/new_gas_refill_request_page.dart @@ -25,6 +25,7 @@ import 'package:test_sa/providers/loading_list_notifier.dart'; import '../../controllers/providers/api/gas_refill_provider.dart'; import '../../controllers/validator/validator.dart'; +import '../common_widgets/app_lazy_loading.dart'; import '../common_widgets/default_app_bar.dart'; class NewGasRefillRequestPage extends StatefulWidget { @@ -208,8 +209,10 @@ class _NewGasRefillRequestPageState extends State { ], ), const Divider().defaultStyle(context), - ("${context.translate(TranslationKeys.department)}: ${_gasModel.department?.departmentCode}").bodyText(context), - ("${context.translate(TranslationKeys.site)}: ${_gasModel.department?.departmentName}").bodyText(context), + ("${context.translate(TranslationKeys.site)}: ${_gasModel.site?.custName}").bodyText(context), + ("${context.translate(TranslationKeys.building)}: ${_gasModel.building?.name}").bodyText(context), + ("${context.translate(TranslationKeys.floor)}: ${_gasModel.floor?.name}").bodyText(context), + ("${context.translate(TranslationKeys.department)}: ${_gasModel.department?.departmentName}").bodyText(context), ], ).paddingAll(16), ); @@ -242,14 +245,22 @@ class _NewGasRefillRequestPageState extends State { } Future _submit() async { + if (_gasModel.gazRefillDetails?.isEmpty ?? true) { + Fluttertoast.showToast(msg: context.translate(TranslationKeys.youHaveToAddRequests)); + return; + } + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); final status = await Provider.of(context, listen: false).createModel( user: Provider.of(context, listen: false).user, model: _gasModel, ); + Navigator.pop(context); if (status >= 200 && status < 300) { Fluttertoast.showToast(msg: context.translate(TranslationKeys.createdSuccessfully)); Navigator.of(context).pop(); setState(() {}); + } else { + Fluttertoast.showToast(msg: context.translate(TranslationKeys.failedToCompleteRequest)); } } }