Prevent negative payment
This commit is contained in:
parent
95ffdb778c
commit
2a3018d71c
|
|
@ -20,7 +20,7 @@ class ErrorDialog extends StatelessWidget {
|
|||
final store = StoreProvider.of<AppState>(context);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(localization.anErrorOccurred),
|
||||
title: Text(localization.error),
|
||||
content: error != null ? Text(error.toString()) : SizedBox(),
|
||||
actions: [
|
||||
if (clearErrorOnDismiss && !Config.DEMO_MODE)
|
||||
|
|
|
|||
|
|
@ -53,11 +53,9 @@ class _ClientEditState extends State<ClientEdit>
|
|||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
/*
|
||||
setState(() {
|
||||
autoValidate = !isValid ?? false;
|
||||
//autoValidate = !isValid;
|
||||
});
|
||||
*/
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -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<ErrorDialog>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ErrorDialog(
|
||||
AppLocalization.of(context).negativePaymentError);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
final Completer<PaymentEntity> completer = Completer<PaymentEntity>();
|
||||
store.dispatch(
|
||||
SavePaymentRequest(completer: completer, payment: payment));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
static final Map<String, Map<String, String>> _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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue