From 2d1b3997b10a7241a2bf924aaa3825c72ac412d3 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 31 Aug 2018 10:00:47 -0700 Subject: [PATCH] Payments --- lib/data/models/payment_model.dart | 8 +- lib/data/models/payment_model.g.dart | 51 +++++++++++- .../models/static/payment_type_model.g.dart | 44 ++++++----- lib/redux/payment/payment_selectors.dart | 10 +++ lib/ui/payment/payment_list_vm.dart | 2 +- lib/ui/payment/view/payment_view.dart | 79 ++++++++++++------- lib/utils/localization.dart | 3 + 7 files changed, 143 insertions(+), 54 deletions(-) diff --git a/lib/data/models/payment_model.dart b/lib/data/models/payment_model.dart index ed169be59..ad68f8a08 100644 --- a/lib/data/models/payment_model.dart +++ b/lib/data/models/payment_model.dart @@ -58,7 +58,8 @@ abstract class PaymentEntity extends Object with BaseEntity implements Built { 'amount', serializers.serialize(object.amount, specifiedType: const FullType(double)), + 'refunded', + serializers.serialize(object.refunded, + specifiedType: const FullType(double)), + 'payment_status_id', + serializers.serialize(object.paymentStatusId, + specifiedType: const FullType(int)), 'transaction_reference', serializers.serialize(object.transactionReference, specifiedType: const FullType(String)), @@ -207,6 +213,14 @@ class _$PaymentEntitySerializer implements StructuredSerializer { result.amount = serializers.deserialize(value, specifiedType: const FullType(double)) as double; break; + case 'refunded': + result.refunded = serializers.deserialize(value, + specifiedType: const FullType(double)) as double; + break; + case 'payment_status_id': + result.paymentStatusId = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; case 'transaction_reference': result.transactionReference = serializers.deserialize(value, specifiedType: const FullType(String)) as String; @@ -455,6 +469,10 @@ class _$PaymentEntity extends PaymentEntity { @override final double amount; @override + final double refunded; + @override + final int paymentStatusId; + @override final String transactionReference; @override final String paymentDate; @@ -488,6 +506,8 @@ class _$PaymentEntity extends PaymentEntity { _$PaymentEntity._( {this.amount, + this.refunded, + this.paymentStatusId, this.transactionReference, this.paymentDate, this.paymentTypeId, @@ -505,6 +525,10 @@ class _$PaymentEntity extends PaymentEntity { : super._() { if (amount == null) throw new BuiltValueNullFieldError('PaymentEntity', 'amount'); + if (refunded == null) + throw new BuiltValueNullFieldError('PaymentEntity', 'refunded'); + if (paymentStatusId == null) + throw new BuiltValueNullFieldError('PaymentEntity', 'paymentStatusId'); if (transactionReference == null) throw new BuiltValueNullFieldError( 'PaymentEntity', 'transactionReference'); @@ -536,6 +560,8 @@ class _$PaymentEntity extends PaymentEntity { if (identical(other, this)) return true; if (other is! PaymentEntity) return false; return amount == other.amount && + refunded == other.refunded && + paymentStatusId == other.paymentStatusId && transactionReference == other.transactionReference && paymentDate == other.paymentDate && paymentTypeId == other.paymentTypeId && @@ -569,8 +595,14 @@ class _$PaymentEntity extends PaymentEntity { $jc( $jc( $jc( - 0, - amount + $jc( + $jc( + 0, + amount + .hashCode), + refunded + .hashCode), + paymentStatusId .hashCode), transactionReference .hashCode), @@ -593,6 +625,8 @@ class _$PaymentEntity extends PaymentEntity { String toString() { return (newBuiltValueToStringHelper('PaymentEntity') ..add('amount', amount) + ..add('refunded', refunded) + ..add('paymentStatusId', paymentStatusId) ..add('transactionReference', transactionReference) ..add('paymentDate', paymentDate) ..add('paymentTypeId', paymentTypeId) @@ -619,6 +653,15 @@ class PaymentEntityBuilder double get amount => _$this._amount; set amount(double amount) => _$this._amount = amount; + double _refunded; + double get refunded => _$this._refunded; + set refunded(double refunded) => _$this._refunded = refunded; + + int _paymentStatusId; + int get paymentStatusId => _$this._paymentStatusId; + set paymentStatusId(int paymentStatusId) => + _$this._paymentStatusId = paymentStatusId; + String _transactionReference; String get transactionReference => _$this._transactionReference; set transactionReference(String transactionReference) => @@ -683,6 +726,8 @@ class PaymentEntityBuilder PaymentEntityBuilder get _$this { if (_$v != null) { _amount = _$v.amount; + _refunded = _$v.refunded; + _paymentStatusId = _$v.paymentStatusId; _transactionReference = _$v.transactionReference; _paymentDate = _$v.paymentDate; _paymentTypeId = _$v.paymentTypeId; @@ -718,6 +763,8 @@ class PaymentEntityBuilder final _$result = _$v ?? new _$PaymentEntity._( amount: amount, + refunded: refunded, + paymentStatusId: paymentStatusId, transactionReference: transactionReference, paymentDate: paymentDate, paymentTypeId: paymentTypeId, diff --git a/lib/data/models/static/payment_type_model.g.dart b/lib/data/models/static/payment_type_model.g.dart index 31b4d0b3b..2ae9ef700 100644 --- a/lib/data/models/static/payment_type_model.g.dart +++ b/lib/data/models/static/payment_type_model.g.dart @@ -128,11 +128,15 @@ class _$PaymentTypeEntitySerializer Iterable serialize(Serializers serializers, PaymentTypeEntity object, {FullType specifiedType = FullType.unspecified}) { final result = [ - 'id', - serializers.serialize(object.id, specifiedType: const FullType(int)), 'name', serializers.serialize(object.name, specifiedType: const FullType(String)), ]; + if (object.id != null) { + result + ..add('id') + ..add(serializers.serialize(object.id, + specifiedType: const FullType(int))); + } return result; } @@ -148,14 +152,14 @@ class _$PaymentTypeEntitySerializer iterator.moveNext(); final dynamic value = iterator.current; switch (key) { - case 'id': - result.id = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - break; case 'name': result.name = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; } } @@ -352,17 +356,15 @@ class PaymentTypeItemResponseBuilder } class _$PaymentTypeEntity extends PaymentTypeEntity { - @override - final int id; @override final String name; + @override + final int id; factory _$PaymentTypeEntity([void updates(PaymentTypeEntityBuilder b)]) => (new PaymentTypeEntityBuilder()..update(updates)).build(); - _$PaymentTypeEntity._({this.id, this.name}) : super._() { - if (id == null) - throw new BuiltValueNullFieldError('PaymentTypeEntity', 'id'); + _$PaymentTypeEntity._({this.name, this.id}) : super._() { if (name == null) throw new BuiltValueNullFieldError('PaymentTypeEntity', 'name'); } @@ -379,19 +381,19 @@ class _$PaymentTypeEntity extends PaymentTypeEntity { bool operator ==(dynamic other) { if (identical(other, this)) return true; if (other is! PaymentTypeEntity) return false; - return id == other.id && name == other.name; + return name == other.name && id == other.id; } @override int get hashCode { - return $jf($jc($jc(0, id.hashCode), name.hashCode)); + return $jf($jc($jc(0, name.hashCode), id.hashCode)); } @override String toString() { return (newBuiltValueToStringHelper('PaymentTypeEntity') - ..add('id', id) - ..add('name', name)) + ..add('name', name) + ..add('id', id)) .toString(); } } @@ -400,20 +402,20 @@ class PaymentTypeEntityBuilder implements Builder { _$PaymentTypeEntity _$v; - int _id; - int get id => _$this._id; - set id(int id) => _$this._id = id; - String _name; String get name => _$this._name; set name(String name) => _$this._name = name; + int _id; + int get id => _$this._id; + set id(int id) => _$this._id = id; + PaymentTypeEntityBuilder(); PaymentTypeEntityBuilder get _$this { if (_$v != null) { - _id = _$v.id; _name = _$v.name; + _id = _$v.id; _$v = null; } return this; @@ -432,7 +434,7 @@ class PaymentTypeEntityBuilder @override _$PaymentTypeEntity build() { - final _$result = _$v ?? new _$PaymentTypeEntity._(id: id, name: name); + final _$result = _$v ?? new _$PaymentTypeEntity._(name: name, id: id); replace(_$result); return _$result; } diff --git a/lib/redux/payment/payment_selectors.dart b/lib/redux/payment/payment_selectors.dart index b8f9a9e92..053fef603 100644 --- a/lib/redux/payment/payment_selectors.dart +++ b/lib/redux/payment/payment_selectors.dart @@ -1,8 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_redux/flutter_redux.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:memoize/memoize.dart'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart'; +ClientEntity paymentClientSelector(int paymentId, BuildContext context) { + final state = StoreProvider.of(context).state; + final payment = state.paymentState.map[paymentId]; + final invoice = state.invoiceState.map[payment.invoiceId]; + return state.clientState.map[invoice.clientId]; +} + var memoizedDropdownPaymentList = memo2( (BuiltMap paymentMap, BuiltList paymentList) => dropdownPaymentsSelector(paymentMap, paymentList)); diff --git a/lib/ui/payment/payment_list_vm.dart b/lib/ui/payment/payment_list_vm.dart index 9c2ab5378..4fec37abc 100644 --- a/lib/ui/payment/payment_list_vm.dart +++ b/lib/ui/payment/payment_list_vm.dart @@ -76,7 +76,7 @@ class PaymentListVM { isLoaded: state.paymentState.isLoaded, filter: state.paymentUIState.listUIState.filter, onPaymentTap: (context, payment) { - store.dispatch(EditPayment(payment: payment, context: context)); + store.dispatch(ViewPayment(paymentId: payment.id, context: context)); }, onEntityAction: (context, payment, action) { switch (action) { diff --git a/lib/ui/payment/view/payment_view.dart b/lib/ui/payment/view/payment_view.dart index 5cf3ec55e..08c39c8f1 100644 --- a/lib/ui/payment/view/payment_view.dart +++ b/lib/ui/payment/view/payment_view.dart @@ -1,8 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:invoiceninja_flutter/redux/payment/payment_selectors.dart'; import 'package:invoiceninja_flutter/ui/app/actions_menu_button.dart'; +import 'package:invoiceninja_flutter/ui/app/icon_message.dart'; +import 'package:invoiceninja_flutter/ui/app/one_value_header.dart'; +import 'package:invoiceninja_flutter/ui/app/two_value_header.dart'; import 'package:invoiceninja_flutter/ui/payment/view/payment_view_vm.dart'; -import 'package:invoiceninja_flutter/ui/app/form_card.dart'; +import 'package:invoiceninja_flutter/utils/formatting.dart'; +import 'package:invoiceninja_flutter/utils/localization.dart'; class PaymentView extends StatefulWidget { final PaymentViewVM viewModel; @@ -21,35 +26,51 @@ class _PaymentViewState extends State { Widget build(BuildContext context) { final viewModel = widget.viewModel; final payment = viewModel.payment; + final localization = AppLocalization.of(context); return Scaffold( - appBar: AppBar( - title: Text(payment.transactionReference), - actions: payment.isNew - ? [] - : [ - IconButton( - icon: Icon(Icons.edit), - onPressed: () { - viewModel.onEditPressed(context); - }, - ), - ActionMenuButton( - user: viewModel.company.user, - isSaving: viewModel.isSaving, - entity: payment, - onSelected: viewModel.onActionSelected, - ) - ], - ), - body: FormCard(children: [ - // STARTER: widgets - do not remove comment - Text(payment.amount.toString(), style: Theme.of(context).textTheme.title), - SizedBox(height: 12.0), - - Text(payment.transactionReference), - Text(payment.privateNotes), - ]), - ); + appBar: AppBar( + title: Text(payment.transactionReference), + actions: payment.isNew + ? [] + : [ + IconButton( + icon: Icon(Icons.edit), + onPressed: () { + viewModel.onEditPressed(context); + }, + ), + ActionMenuButton( + user: viewModel.company.user, + isSaving: viewModel.isSaving, + entity: payment, + onSelected: viewModel.onActionSelected, + ) + ], + ), + body: ListView( + children: [ + payment.refunded > 0 + ? TwoValueHeader( + label1: localization.amount, + value1: formatNumber(payment.amount, context, + clientId: + paymentClientSelector(payment.id, context).id), + label2: localization.refunded, + value2: formatNumber(payment.refunded, context, + clientId: + paymentClientSelector(payment.id, context).id), + ) + : OneValueHeader( + label: localization.amount, + value: formatNumber(payment.amount, context, + clientId: + paymentClientSelector(payment.id, context).id), + ), + payment.privateNotes != null && payment.privateNotes.isNotEmpty + ? IconMessage(payment.privateNotes) + : Container(), + ], + )); } } diff --git a/lib/utils/localization.dart b/lib/utils/localization.dart index c036a59ec..837d91234 100644 --- a/lib/utils/localization.dart +++ b/lib/utils/localization.dart @@ -209,6 +209,7 @@ class AppLocalization { 'history': 'History', 'payment': 'Payment', 'payments': 'Payments', + 'refunded': 'Refunded', 'payment_type': 'Payment Type', 'transaction_reference': 'Transaction Reference', 'enter_payment': 'Enter Payment', @@ -7536,6 +7537,8 @@ class AppLocalization { String get payments => _localizedValues[locale.languageCode]['payments']; + String get refunded => _localizedValues[locale.languageCode]['refunded']; + String get paymentType => _localizedValues[locale.languageCode]['payment_type'];