diff --git a/lib/data/models/payment_model.dart b/lib/data/models/payment_model.dart index 4e5ca7bf3..b835aa4f7 100644 --- a/lib/data/models/payment_model.dart +++ b/lib/data/models/payment_model.dart @@ -81,7 +81,7 @@ abstract class PaymentEntity extends Object customValue2: '', customValue3: '', customValue4: '', - paymentables: BuiltList(), + paymentables: BuiltList([PaymentableEntity()]), ); } diff --git a/lib/ui/payment/edit/payment_edit.dart b/lib/ui/payment/edit/payment_edit.dart index 3289d9718..2d6afb960 100644 --- a/lib/ui/payment/edit/payment_edit.dart +++ b/lib/ui/payment/edit/payment_edit.dart @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/models/invoice_model.dart'; +import 'package:invoiceninja_flutter/data/models/payment_model.dart'; import 'package:invoiceninja_flutter/redux/invoice/invoice_selectors.dart'; import 'package:invoiceninja_flutter/redux/client/client_selectors.dart'; import 'package:invoiceninja_flutter/redux/static/static_selectors.dart'; @@ -132,27 +133,6 @@ class _PaymentEditState extends State { entityList: memoizedDropdownClientList( viewModel.clientMap, viewModel.clientList), ), - EntityDropdown( - key: Key('__invoice_${payment.clientId}__'), - entityType: EntityType.invoice, - labelText: AppLocalization.of(context).invoice, - entityId: payment.invoiceId, - entityList: memoizedDropdownInvoiceList( - viewModel.invoiceMap, - viewModel.clientMap, - viewModel.invoiceList, - payment.clientId), - onSelected: (selected) { - final invoice = selected as InvoiceEntity; - _amountController.text = formatNumber( - invoice.balance, context, - formatNumberType: FormatNumberType.input); - viewModel.onChanged(payment.rebuild((b) => b - ..invoiceId = invoice.id - ..clientId = invoice.clientId - ..amount = invoice.balance)); - }, - ), DecoratedFormField( controller: _amountController, autocorrect: false, @@ -161,6 +141,12 @@ class _PaymentEditState extends State { label: localization.amount, ), ], + for (final paymentable in payment.paymentables) + PaymentableEditor( + viewModel: viewModel, + paymentable: paymentable, + onChanged: () {}, + ), EntityDropdown( key: ValueKey('__payment_type_${payment.typeId}__'), entityType: EntityType.paymentType, @@ -168,8 +154,8 @@ class _PaymentEditState extends State { viewModel.staticState.paymentTypeMap), labelText: localization.paymentType, entityId: payment.typeId, - onSelected: (paymentType) => viewModel.onChanged(payment - .rebuild((b) => b..typeId = paymentType.id)), + onSelected: (paymentType) => viewModel.onChanged( + payment.rebuild((b) => b..typeId = paymentType.id)), ), DatePicker( validator: (String val) => val.trim().isEmpty @@ -179,8 +165,7 @@ class _PaymentEditState extends State { labelText: localization.paymentDate, selectedDate: payment.date, onSelected: (date) { - viewModel.onChanged( - payment.rebuild((b) => b..date = date)); + viewModel.onChanged(payment.rebuild((b) => b..date = date)); }, ), DecoratedFormField( @@ -212,3 +197,61 @@ class _PaymentEditState extends State { ); } } + +class PaymentableEditor extends StatelessWidget { + const PaymentableEditor({ + @required this.viewModel, + @required this.paymentable, + @required this.onChanged, + }); + + final PaymentEditVM viewModel; + final PaymentableEntity paymentable; + final Function onChanged; + + @override + Widget build(BuildContext context) { + final payment = viewModel.payment; + final localization = AppLocalization.of(context); + + return Row( + children: [ + Expanded( + child: EntityDropdown( + key: Key('__invoice_${payment.clientId}__'), + entityType: EntityType.invoice, + labelText: AppLocalization.of(context).invoice, + entityId: payment.invoiceId, + entityList: memoizedDropdownInvoiceList(viewModel.invoiceMap, + viewModel.clientMap, viewModel.invoiceList, payment.clientId), + onSelected: (selected) { + final invoice = selected as InvoiceEntity; + /* + _amountController.text = formatNumber( + invoice.balance, context, + formatNumberType: FormatNumberType.input); + */ + viewModel.onChanged(payment.rebuild((b) => b + ..invoiceId = invoice.id + ..clientId = invoice.clientId + ..amount = invoice.balance)); + }, + ), + ), + Expanded( + child: TextFormField( + decoration: InputDecoration( + labelText: localization.applied, + ), + ), + ), + FlatButton( + child: Text(localization.remove), + onPressed: () { + // TODO + }, + ) + ], + ); + } +} diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index e7425d4b2..583df7c8e 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -14,6 +14,7 @@ abstract class LocaleCodeAware { mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { + 'applied': 'Applied', 'include_recent_errors': 'Include recent errors from the logs', 'your_message_has_been_received': 'We have received your message and will try to respond promptly.', 'message': 'Message', @@ -15926,7 +15927,8 @@ mixin LocalizationsProvider on LocaleCodeAware { String get includeRecentErrors => _localizedValues[localeCode]['include_recent_errors']; - + String get applied => + _localizedValues[localeCode]['applied']; String lookup(String key) {