diff --git a/lib/ui/app/dialogs/error_dialog.dart b/lib/ui/app/dialogs/error_dialog.dart index 365d4d0ef..b755ffadf 100644 --- a/lib/ui/app/dialogs/error_dialog.dart +++ b/lib/ui/app/dialogs/error_dialog.dart @@ -20,7 +20,7 @@ class ErrorDialog extends StatelessWidget { final store = StoreProvider.of(context); return AlertDialog( - title: Text(localization.anErrorOccurred), + title: Text(localization.error), content: error != null ? Text(error.toString()) : SizedBox(), actions: [ if (clearErrorOnDismiss && !Config.DEMO_MODE) diff --git a/lib/ui/client/edit/client_edit.dart b/lib/ui/client/edit/client_edit.dart index 9011a2cd7..130278db2 100644 --- a/lib/ui/client/edit/client_edit.dart +++ b/lib/ui/client/edit/client_edit.dart @@ -53,11 +53,9 @@ class _ClientEditState extends State onSavePressed: (context) { final bool isValid = _formKey.currentState.validate(); - /* setState(() { - autoValidate = !isValid ?? false; + //autoValidate = !isValid; }); - */ if (!isValid) { return; diff --git a/lib/ui/payment/edit/payment_edit_vm.dart b/lib/ui/payment/edit/payment_edit_vm.dart index e27caadd6..a79eb4fb9 100644 --- a/lib/ui/payment/edit/payment_edit_vm.dart +++ b/lib/ui/payment/edit/payment_edit_vm.dart @@ -8,6 +8,7 @@ import 'package:invoiceninja_flutter/redux/ui/pref_state.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/payment/view/payment_view_vm.dart'; +import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/redux/payment/payment_actions.dart'; @@ -70,6 +71,18 @@ class PaymentEditVM { store.dispatch(UpdateCurrentRoute(state.uiState.previousRoute)); }, onSavePressed: (BuildContext context) { + double amount = 0; + payment.invoices.forEach((invoice) => amount += invoice.amount); + payment.credits.forEach((credit) => amount -= credit.amount); + if (amount < 0) { + showDialog( + context: context, + builder: (BuildContext context) { + return ErrorDialog( + AppLocalization.of(context).negativePaymentError); + }); + return null; + } final Completer completer = Completer(); store.dispatch( SavePaymentRequest(completer: completer, payment: payment)); diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index c51d2c368..450d770d2 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -15,6 +15,8 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'negative_payment_error': + 'The credit amount cannot exceed the payment amount', 'view_changes': 'View Changes', 'force_update': 'Force Update', 'force_update_help': @@ -4673,6 +4675,9 @@ mixin LocalizationsProvider on LocaleCodeAware { String get viewChanges => _localizedValues[localeCode]['view_changes'] ?? ''; + String get negativePaymentError => + _localizedValues[localeCode]['negative_payment_error'] ?? ''; + String lookup(String key) { final lookupKey = toSnakeCase(key);