diff --git a/lib/data/models/payment_model.dart b/lib/data/models/payment_model.dart index 7123a0e89..99dd9834e 100644 --- a/lib/data/models/payment_model.dart +++ b/lib/data/models/payment_model.dart @@ -61,8 +61,8 @@ abstract class PaymentEntity extends Object isChanged: false, amount: 0.0, transactionReference: '', - paymentDate: convertDateTimeToSqlDate(), - paymentTypeId: state?.company != null && + date: convertDateTimeToSqlDate(), + typeId: state?.company != null && (state.company.settings.defaultPaymentTypeId ?? '').isNotEmpty ? state.company.settings.defaultPaymentTypeId : '', @@ -72,10 +72,11 @@ abstract class PaymentEntity extends Object exchangeRate: 0.0, exchangeCurrencyId: '', refunded: 0.0, - paymentStatusId: '', + statusId: '', updatedAt: 0, archivedAt: 0, isDeleted: false, + isManual: true, customValue1: '', customValue2: '', customValue3: '', @@ -92,7 +93,6 @@ abstract class PaymentEntity extends Object double get amount; - @nullable double get refunded; @nullable @@ -104,17 +104,17 @@ abstract class PaymentEntity extends Object String get clientId; @nullable - @BuiltValueField(wireName: 'payment_status_id') - String get paymentStatusId; + @BuiltValueField(wireName: 'status_id') + String get statusId; @BuiltValueField(wireName: 'transaction_reference') String get transactionReference; - @BuiltValueField(wireName: 'payment_date') - String get paymentDate; + @BuiltValueField(wireName: 'date') + String get date; - @BuiltValueField(wireName: 'payment_type_id') - String get paymentTypeId; + @BuiltValueField(wireName: 'type_id') + String get typeId; @nullable @BuiltValueField(wireName: 'invoice_id') @@ -148,6 +148,9 @@ abstract class PaymentEntity extends Object @BuiltValueField(wireName: 'exchange_currency_id') String get exchangeCurrencyId; + @BuiltValueField(wireName: 'is_manual') + bool get isManual; + int compareTo(PaymentEntity credit, String sortField, bool sortAscending) { int response = 0; final PaymentEntity paymentA = sortAscending ? this : credit; @@ -162,7 +165,7 @@ abstract class PaymentEntity extends Object .compareTo(paymentB.transactionReference); break; case PaymentFields.paymentDate: - response = paymentA.paymentDate.compareTo(paymentB.paymentDate); + response = paymentA.date.compareTo(paymentB.date); break; case PaymentFields.updatedAt: response = paymentA.updatedAt.compareTo(paymentB.updatedAt); @@ -266,8 +269,8 @@ abstract class PaymentEntity extends Object double get listDisplayAmount => amount; bool isBetween(String startDate, String endDate) { - return startDate.compareTo(paymentDate) <= 0 && - endDate.compareTo(paymentDate) >= 0; + return startDate.compareTo(date) <= 0 && + endDate.compareTo(date) >= 0; } @override @@ -275,7 +278,7 @@ abstract class PaymentEntity extends Object double get completedAmount { if ([kPaymentStatusVoided, kPaymentStatusFailed] - .contains(paymentStatusId)) { + .contains(statusId)) { return 0.0; } diff --git a/lib/data/models/payment_model.g.dart b/lib/data/models/payment_model.g.dart index 94f5b5a68..836970e0d 100644 --- a/lib/data/models/payment_model.g.dart +++ b/lib/data/models/payment_model.g.dart @@ -121,22 +121,21 @@ class _$PaymentEntitySerializer implements StructuredSerializer { 'amount', serializers.serialize(object.amount, specifiedType: const FullType(double)), + 'refunded', + serializers.serialize(object.refunded, + specifiedType: const FullType(double)), 'transaction_reference', serializers.serialize(object.transactionReference, specifiedType: const FullType(String)), - 'payment_date', - serializers.serialize(object.paymentDate, - specifiedType: const FullType(String)), - 'payment_type_id', - serializers.serialize(object.paymentTypeId, + 'date', + serializers.serialize(object.date, specifiedType: const FullType(String)), + 'type_id', + serializers.serialize(object.typeId, specifiedType: const FullType(String)), + 'is_manual', + serializers.serialize(object.isManual, + specifiedType: const FullType(bool)), ]; - if (object.refunded != null) { - result - ..add('refunded') - ..add(serializers.serialize(object.refunded, - specifiedType: const FullType(double))); - } if (object.number != null) { result ..add('number') @@ -149,10 +148,10 @@ class _$PaymentEntitySerializer implements StructuredSerializer { ..add(serializers.serialize(object.clientId, specifiedType: const FullType(String))); } - if (object.paymentStatusId != null) { + if (object.statusId != null) { result - ..add('payment_status_id') - ..add(serializers.serialize(object.paymentStatusId, + ..add('status_id') + ..add(serializers.serialize(object.statusId, specifiedType: const FullType(String))); } if (object.invoiceId != null) { @@ -282,20 +281,20 @@ class _$PaymentEntitySerializer implements StructuredSerializer { result.clientId = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; - case 'payment_status_id': - result.paymentStatusId = serializers.deserialize(value, + case 'status_id': + result.statusId = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; case 'transaction_reference': result.transactionReference = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; - case 'payment_date': - result.paymentDate = serializers.deserialize(value, + case 'date': + result.date = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; - case 'payment_type_id': - result.paymentTypeId = serializers.deserialize(value, + case 'type_id': + result.typeId = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; case 'invoice_id': @@ -330,6 +329,10 @@ class _$PaymentEntitySerializer implements StructuredSerializer { result.exchangeCurrencyId = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; + case 'is_manual': + result.isManual = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + break; case 'isChanged': result.isChanged = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -568,13 +571,13 @@ class _$PaymentEntity extends PaymentEntity { @override final String clientId; @override - final String paymentStatusId; + final String statusId; @override final String transactionReference; @override - final String paymentDate; + final String date; @override - final String paymentTypeId; + final String typeId; @override final String invoiceId; @override @@ -592,6 +595,8 @@ class _$PaymentEntity extends PaymentEntity { @override final String exchangeCurrencyId; @override + final bool isManual; + @override final bool isChanged; @override final int createdAt; @@ -616,10 +621,10 @@ class _$PaymentEntity extends PaymentEntity { this.refunded, this.number, this.clientId, - this.paymentStatusId, + this.statusId, this.transactionReference, - this.paymentDate, - this.paymentTypeId, + this.date, + this.typeId, this.invoiceId, this.privateNotes, this.customValue1, @@ -628,6 +633,7 @@ class _$PaymentEntity extends PaymentEntity { this.customValue4, this.exchangeRate, this.exchangeCurrencyId, + this.isManual, this.isChanged, this.createdAt, this.updatedAt, @@ -640,15 +646,21 @@ class _$PaymentEntity extends PaymentEntity { if (amount == null) { throw new BuiltValueNullFieldError('PaymentEntity', 'amount'); } + if (refunded == null) { + throw new BuiltValueNullFieldError('PaymentEntity', 'refunded'); + } if (transactionReference == null) { throw new BuiltValueNullFieldError( 'PaymentEntity', 'transactionReference'); } - if (paymentDate == null) { - throw new BuiltValueNullFieldError('PaymentEntity', 'paymentDate'); + if (date == null) { + throw new BuiltValueNullFieldError('PaymentEntity', 'date'); } - if (paymentTypeId == null) { - throw new BuiltValueNullFieldError('PaymentEntity', 'paymentTypeId'); + if (typeId == null) { + throw new BuiltValueNullFieldError('PaymentEntity', 'typeId'); + } + if (isManual == null) { + throw new BuiltValueNullFieldError('PaymentEntity', 'isManual'); } } @@ -667,10 +679,10 @@ class _$PaymentEntity extends PaymentEntity { refunded == other.refunded && number == other.number && clientId == other.clientId && - paymentStatusId == other.paymentStatusId && + statusId == other.statusId && transactionReference == other.transactionReference && - paymentDate == other.paymentDate && - paymentTypeId == other.paymentTypeId && + date == other.date && + typeId == other.typeId && invoiceId == other.invoiceId && privateNotes == other.privateNotes && customValue1 == other.customValue1 && @@ -679,6 +691,7 @@ class _$PaymentEntity extends PaymentEntity { customValue4 == other.customValue4 && exchangeRate == other.exchangeRate && exchangeCurrencyId == other.exchangeCurrencyId && + isManual == other.isManual && isChanged == other.isChanged && createdAt == other.createdAt && updatedAt == other.updatedAt && @@ -709,18 +722,18 @@ class _$PaymentEntity extends PaymentEntity { $jc( $jc( $jc( - $jc($jc($jc($jc($jc($jc(0, amount.hashCode), refunded.hashCode), number.hashCode), clientId.hashCode), paymentStatusId.hashCode), - transactionReference.hashCode), - paymentDate.hashCode), - paymentTypeId.hashCode), - invoiceId.hashCode), - privateNotes.hashCode), - customValue1.hashCode), - customValue2.hashCode), - customValue3.hashCode), - customValue4.hashCode), - exchangeRate.hashCode), - exchangeCurrencyId.hashCode), + $jc($jc($jc($jc($jc($jc($jc(0, amount.hashCode), refunded.hashCode), number.hashCode), clientId.hashCode), statusId.hashCode), transactionReference.hashCode), + date.hashCode), + typeId.hashCode), + invoiceId.hashCode), + privateNotes.hashCode), + customValue1.hashCode), + customValue2.hashCode), + customValue3.hashCode), + customValue4.hashCode), + exchangeRate.hashCode), + exchangeCurrencyId.hashCode), + isManual.hashCode), isChanged.hashCode), createdAt.hashCode), updatedAt.hashCode), @@ -738,10 +751,10 @@ class _$PaymentEntity extends PaymentEntity { ..add('refunded', refunded) ..add('number', number) ..add('clientId', clientId) - ..add('paymentStatusId', paymentStatusId) + ..add('statusId', statusId) ..add('transactionReference', transactionReference) - ..add('paymentDate', paymentDate) - ..add('paymentTypeId', paymentTypeId) + ..add('date', date) + ..add('typeId', typeId) ..add('invoiceId', invoiceId) ..add('privateNotes', privateNotes) ..add('customValue1', customValue1) @@ -750,6 +763,7 @@ class _$PaymentEntity extends PaymentEntity { ..add('customValue4', customValue4) ..add('exchangeRate', exchangeRate) ..add('exchangeCurrencyId', exchangeCurrencyId) + ..add('isManual', isManual) ..add('isChanged', isChanged) ..add('createdAt', createdAt) ..add('updatedAt', updatedAt) @@ -782,24 +796,22 @@ class PaymentEntityBuilder String get clientId => _$this._clientId; set clientId(String clientId) => _$this._clientId = clientId; - String _paymentStatusId; - String get paymentStatusId => _$this._paymentStatusId; - set paymentStatusId(String paymentStatusId) => - _$this._paymentStatusId = paymentStatusId; + String _statusId; + String get statusId => _$this._statusId; + set statusId(String statusId) => _$this._statusId = statusId; String _transactionReference; String get transactionReference => _$this._transactionReference; set transactionReference(String transactionReference) => _$this._transactionReference = transactionReference; - String _paymentDate; - String get paymentDate => _$this._paymentDate; - set paymentDate(String paymentDate) => _$this._paymentDate = paymentDate; + String _date; + String get date => _$this._date; + set date(String date) => _$this._date = date; - String _paymentTypeId; - String get paymentTypeId => _$this._paymentTypeId; - set paymentTypeId(String paymentTypeId) => - _$this._paymentTypeId = paymentTypeId; + String _typeId; + String get typeId => _$this._typeId; + set typeId(String typeId) => _$this._typeId = typeId; String _invoiceId; String get invoiceId => _$this._invoiceId; @@ -834,6 +846,10 @@ class PaymentEntityBuilder set exchangeCurrencyId(String exchangeCurrencyId) => _$this._exchangeCurrencyId = exchangeCurrencyId; + bool _isManual; + bool get isManual => _$this._isManual; + set isManual(bool isManual) => _$this._isManual = isManual; + bool _isChanged; bool get isChanged => _$this._isChanged; set isChanged(bool isChanged) => _$this._isChanged = isChanged; @@ -876,10 +892,10 @@ class PaymentEntityBuilder _refunded = _$v.refunded; _number = _$v.number; _clientId = _$v.clientId; - _paymentStatusId = _$v.paymentStatusId; + _statusId = _$v.statusId; _transactionReference = _$v.transactionReference; - _paymentDate = _$v.paymentDate; - _paymentTypeId = _$v.paymentTypeId; + _date = _$v.date; + _typeId = _$v.typeId; _invoiceId = _$v.invoiceId; _privateNotes = _$v.privateNotes; _customValue1 = _$v.customValue1; @@ -888,6 +904,7 @@ class PaymentEntityBuilder _customValue4 = _$v.customValue4; _exchangeRate = _$v.exchangeRate; _exchangeCurrencyId = _$v.exchangeCurrencyId; + _isManual = _$v.isManual; _isChanged = _$v.isChanged; _createdAt = _$v.createdAt; _updatedAt = _$v.updatedAt; @@ -922,10 +939,10 @@ class PaymentEntityBuilder refunded: refunded, number: number, clientId: clientId, - paymentStatusId: paymentStatusId, + statusId: statusId, transactionReference: transactionReference, - paymentDate: paymentDate, - paymentTypeId: paymentTypeId, + date: date, + typeId: typeId, invoiceId: invoiceId, privateNotes: privateNotes, customValue1: customValue1, @@ -934,6 +951,7 @@ class PaymentEntityBuilder customValue4: customValue4, exchangeRate: exchangeRate, exchangeCurrencyId: exchangeCurrencyId, + isManual: isManual, isChanged: isChanged, createdAt: createdAt, updatedAt: updatedAt, diff --git a/lib/redux/dashboard/dashboard_selectors.dart b/lib/redux/dashboard/dashboard_selectors.dart index ed71e2f62..b010d5619 100644 --- a/lib/redux/dashboard/dashboard_selectors.dart +++ b/lib/redux/dashboard/dashboard_selectors.dart @@ -318,9 +318,9 @@ List chartPayments( } else if (!settings.matchesCurrency(currencyId)) { // skip it } else { - if (totals[STATUS_ACTIVE][payment.paymentDate] == null) { - totals[STATUS_ACTIVE][payment.paymentDate] = 0.0; - totals[STATUS_REFUNDED][payment.paymentDate] = 0.0; + if (totals[STATUS_ACTIVE][payment.date] == null) { + totals[STATUS_ACTIVE][payment.date] = 0.0; + totals[STATUS_REFUNDED][payment.date] = 0.0; } double completedAmount = payment.completedAmount; @@ -335,8 +335,8 @@ List chartPayments( fromCurrencyId: currencyId, toCurrencyId: company.currencyId); } - totals[STATUS_ACTIVE][payment.paymentDate] += completedAmount; - totals[STATUS_REFUNDED][payment.paymentDate] += refunded ?? 0; + totals[STATUS_ACTIVE][payment.date] += completedAmount; + totals[STATUS_REFUNDED][payment.date] += refunded ?? 0; counts[STATUS_ACTIVE]++; if ((payment.refunded ?? 0) > 0) { diff --git a/lib/ui/invoice/view/invoice_view_overview.dart b/lib/ui/invoice/view/invoice_view_overview.dart index a9ce115c0..83e4dc082 100644 --- a/lib/ui/invoice/view/invoice_view_overview.dart +++ b/lib/ui/invoice/view/invoice_view_overview.dart @@ -112,7 +112,7 @@ class InvoiceOverview extends StatelessWidget { subtitle: Text( formatNumber(payment.amount, context, clientId: client.id) + ' • ' + - formatDate(payment.paymentDate, context)), + formatDate(payment.date, context)), leading: Icon(FontAwesomeIcons.creditCard, size: 18.0), trailing: Icon(Icons.navigate_next), onTap: () => viewModel.onPaymentPressed(context, payment), diff --git a/lib/ui/payment/edit/payment_edit.dart b/lib/ui/payment/edit/payment_edit.dart index e8b39789f..3289d9718 100644 --- a/lib/ui/payment/edit/payment_edit.dart +++ b/lib/ui/payment/edit/payment_edit.dart @@ -162,14 +162,14 @@ class _PaymentEditState extends State { ), ], EntityDropdown( - key: ValueKey('__payment_type_${payment.paymentTypeId}__'), + key: ValueKey('__payment_type_${payment.typeId}__'), entityType: EntityType.paymentType, entityList: memoizedPaymentTypeList( viewModel.staticState.paymentTypeMap), labelText: localization.paymentType, - entityId: payment.paymentTypeId, + entityId: payment.typeId, onSelected: (paymentType) => viewModel.onChanged(payment - .rebuild((b) => b..paymentTypeId = paymentType.id)), + .rebuild((b) => b..typeId = paymentType.id)), ), DatePicker( validator: (String val) => val.trim().isEmpty @@ -177,10 +177,10 @@ class _PaymentEditState extends State { : null, autoValidate: autoValidate, labelText: localization.paymentDate, - selectedDate: payment.paymentDate, + selectedDate: payment.date, onSelected: (date) { viewModel.onChanged( - payment.rebuild((b) => b..paymentDate = date)); + payment.rebuild((b) => b..date = date)); }, ), DecoratedFormField( diff --git a/lib/ui/payment/payment_list_item.dart b/lib/ui/payment/payment_list_item.dart index 365cfad66..35c17edb3 100644 --- a/lib/ui/payment/payment_list_item.dart +++ b/lib/ui/payment/payment_list_item.dart @@ -48,7 +48,7 @@ class PaymentListItem extends StatelessWidget { ? payment.matchesFilterValue(filter) : null; final subtitle = filterMatch ?? - (payment.number ?? '') + ' • ' + formatDate(payment.paymentDate, context); + (payment.number ?? '') + ' • ' + formatDate(payment.date, context); return DismissibleEntity( isSelected: payment.id == @@ -105,10 +105,10 @@ class PaymentListItem extends StatelessWidget { ), Text( localization - .lookup('payment_status_${payment.paymentStatusId}'), + .lookup('payment_status_${payment.statusId}'), style: TextStyle( color: - PaymentStatusColors.colors[payment.paymentStatusId], + PaymentStatusColors.colors[payment.statusId], )), ], ), diff --git a/lib/ui/payment/view/payment_view.dart b/lib/ui/payment/view/payment_view.dart index 1af074a4a..775a87e0c 100644 --- a/lib/ui/payment/view/payment_view.dart +++ b/lib/ui/payment/view/payment_view.dart @@ -40,14 +40,14 @@ class _PaymentViewState extends State { final fields = {}; fields[PaymentFields.paymentStatusId] = - localization.lookup('payment_status_${payment.paymentStatusId}'); - if (payment.paymentDate.isNotEmpty) { + localization.lookup('payment_status_${payment.statusId}'); + if (payment.date.isNotEmpty) { fields[PaymentFields.paymentDate] = - formatDate(payment.paymentDate, context); + formatDate(payment.date, context); } - if ((payment.paymentTypeId ?? '').isNotEmpty) { + if ((payment.typeId ?? '').isNotEmpty) { final paymentType = - state.staticState.paymentTypeMap[payment.paymentTypeId]; + state.staticState.paymentTypeMap[payment.typeId]; if (paymentType != null) { fields[PaymentFields.paymentTypeId] = paymentType.name; } @@ -68,7 +68,7 @@ class _PaymentViewState extends State { (payment.refunded ?? 0) > 0 ? EntityHeader( backgroundColor: - PaymentStatusColors.colors[payment.paymentStatusId], + PaymentStatusColors.colors[payment.statusId], label: localization.amount, value: formatNumber(payment.amount, context, clientId: client.id), @@ -78,7 +78,7 @@ class _PaymentViewState extends State { ) : EntityHeader( backgroundColor: - PaymentStatusColors.colors[payment.paymentStatusId], + PaymentStatusColors.colors[payment.statusId], label: localization.amount, value: formatNumber(payment.amount, context, clientId: client.id),