Adjust credits/payments

This commit is contained in:
Hillel Coren 2022-04-05 10:57:57 +03:00
parent fb1d033ae4
commit f79eb22124
6 changed files with 16 additions and 66 deletions

View File

@ -114,7 +114,6 @@ abstract class PaymentEntity extends Object
clientContactId: '', clientContactId: '',
currencyId: '', currencyId: '',
invitationId: '', invitationId: '',
isForInvoice: false,
isApplying: false, isApplying: false,
); );
} }
@ -195,12 +194,6 @@ abstract class PaymentEntity extends Object
@BuiltValueField(wireName: 'currency_id') @BuiltValueField(wireName: 'currency_id')
String get currencyId; String get currencyId;
@nullable
bool get isForInvoice;
@nullable
bool get isForCredit;
@nullable @nullable
bool get isApplying; bool get isApplying;

View File

@ -213,20 +213,6 @@ class _$PaymentEntitySerializer implements StructuredSerializer<PaymentEntity> {
serializers.serialize(object.id, specifiedType: const FullType(String)), serializers.serialize(object.id, specifiedType: const FullType(String)),
]; ];
Object value; Object value;
value = object.isForInvoice;
if (value != null) {
result
..add('isForInvoice')
..add(
serializers.serialize(value, specifiedType: const FullType(bool)));
}
value = object.isForCredit;
if (value != null) {
result
..add('isForCredit')
..add(
serializers.serialize(value, specifiedType: const FullType(bool)));
}
value = object.isApplying; value = object.isApplying;
if (value != null) { if (value != null) {
result result
@ -383,14 +369,6 @@ class _$PaymentEntitySerializer implements StructuredSerializer<PaymentEntity> {
result.currencyId = serializers.deserialize(value, result.currencyId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String; specifiedType: const FullType(String)) as String;
break; break;
case 'isForInvoice':
result.isForInvoice = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
break;
case 'isForCredit':
result.isForCredit = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
break;
case 'isApplying': case 'isApplying':
result.isApplying = serializers.deserialize(value, result.isApplying = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool; specifiedType: const FullType(bool)) as bool;
@ -783,10 +761,6 @@ class _$PaymentEntity extends PaymentEntity {
@override @override
final String currencyId; final String currencyId;
@override @override
final bool isForInvoice;
@override
final bool isForCredit;
@override
final bool isApplying; final bool isApplying;
@override @override
final bool sendEmail; final bool sendEmail;
@ -842,8 +816,6 @@ class _$PaymentEntity extends PaymentEntity {
this.clientContactId, this.clientContactId,
this.companyGatewayId, this.companyGatewayId,
this.currencyId, this.currencyId,
this.isForInvoice,
this.isForCredit,
this.isApplying, this.isApplying,
this.sendEmail, this.sendEmail,
this.gatewayRefund, this.gatewayRefund,
@ -948,8 +920,6 @@ class _$PaymentEntity extends PaymentEntity {
clientContactId == other.clientContactId && clientContactId == other.clientContactId &&
companyGatewayId == other.companyGatewayId && companyGatewayId == other.companyGatewayId &&
currencyId == other.currencyId && currencyId == other.currencyId &&
isForInvoice == other.isForInvoice &&
isForCredit == other.isForCredit &&
isApplying == other.isApplying && isApplying == other.isApplying &&
sendEmail == other.sendEmail && sendEmail == other.sendEmail &&
gatewayRefund == other.gatewayRefund && gatewayRefund == other.gatewayRefund &&
@ -987,12 +957,12 @@ class _$PaymentEntity extends PaymentEntity {
$jc( $jc(
$jc( $jc(
$jc( $jc(
$jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, amount.hashCode), applied.hashCode), refunded.hashCode), number.hashCode), clientId.hashCode), statusId.hashCode), transactionReference.hashCode), date.hashCode), typeId.hashCode), privateNotes.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), exchangeRate.hashCode), exchangeCurrencyId.hashCode), isManual.hashCode), projectId.hashCode), vendorId.hashCode), invitationId.hashCode), $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, amount.hashCode), applied.hashCode), refunded.hashCode), number.hashCode), clientId.hashCode), statusId.hashCode), transactionReference.hashCode), date.hashCode), typeId.hashCode), privateNotes.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), exchangeRate.hashCode), exchangeCurrencyId.hashCode), isManual.hashCode), projectId.hashCode),
clientContactId.hashCode), vendorId.hashCode),
companyGatewayId.hashCode), invitationId.hashCode),
currencyId.hashCode), clientContactId.hashCode),
isForInvoice.hashCode), companyGatewayId.hashCode),
isForCredit.hashCode), currencyId.hashCode),
isApplying.hashCode), isApplying.hashCode),
sendEmail.hashCode), sendEmail.hashCode),
gatewayRefund.hashCode), gatewayRefund.hashCode),
@ -1035,8 +1005,6 @@ class _$PaymentEntity extends PaymentEntity {
..add('clientContactId', clientContactId) ..add('clientContactId', clientContactId)
..add('companyGatewayId', companyGatewayId) ..add('companyGatewayId', companyGatewayId)
..add('currencyId', currencyId) ..add('currencyId', currencyId)
..add('isForInvoice', isForInvoice)
..add('isForCredit', isForCredit)
..add('isApplying', isApplying) ..add('isApplying', isApplying)
..add('sendEmail', sendEmail) ..add('sendEmail', sendEmail)
..add('gatewayRefund', gatewayRefund) ..add('gatewayRefund', gatewayRefund)
@ -1155,14 +1123,6 @@ class PaymentEntityBuilder
String get currencyId => _$this._currencyId; String get currencyId => _$this._currencyId;
set currencyId(String currencyId) => _$this._currencyId = currencyId; set currencyId(String currencyId) => _$this._currencyId = currencyId;
bool _isForInvoice;
bool get isForInvoice => _$this._isForInvoice;
set isForInvoice(bool isForInvoice) => _$this._isForInvoice = isForInvoice;
bool _isForCredit;
bool get isForCredit => _$this._isForCredit;
set isForCredit(bool isForCredit) => _$this._isForCredit = isForCredit;
bool _isApplying; bool _isApplying;
bool get isApplying => _$this._isApplying; bool get isApplying => _$this._isApplying;
set isApplying(bool isApplying) => _$this._isApplying = isApplying; set isApplying(bool isApplying) => _$this._isApplying = isApplying;
@ -1256,8 +1216,6 @@ class PaymentEntityBuilder
_clientContactId = $v.clientContactId; _clientContactId = $v.clientContactId;
_companyGatewayId = $v.companyGatewayId; _companyGatewayId = $v.companyGatewayId;
_currencyId = $v.currencyId; _currencyId = $v.currencyId;
_isForInvoice = $v.isForInvoice;
_isForCredit = $v.isForCredit;
_isApplying = $v.isApplying; _isApplying = $v.isApplying;
_sendEmail = $v.sendEmail; _sendEmail = $v.sendEmail;
_gatewayRefund = $v.gatewayRefund; _gatewayRefund = $v.gatewayRefund;
@ -1326,8 +1284,6 @@ class PaymentEntityBuilder
clientContactId: BuiltValueNullFieldError.checkNotNull(clientContactId, 'PaymentEntity', 'clientContactId'), clientContactId: BuiltValueNullFieldError.checkNotNull(clientContactId, 'PaymentEntity', 'clientContactId'),
companyGatewayId: BuiltValueNullFieldError.checkNotNull(companyGatewayId, 'PaymentEntity', 'companyGatewayId'), companyGatewayId: BuiltValueNullFieldError.checkNotNull(companyGatewayId, 'PaymentEntity', 'companyGatewayId'),
currencyId: BuiltValueNullFieldError.checkNotNull(currencyId, 'PaymentEntity', 'currencyId'), currencyId: BuiltValueNullFieldError.checkNotNull(currencyId, 'PaymentEntity', 'currencyId'),
isForInvoice: isForInvoice,
isForCredit: isForCredit,
isApplying: isApplying, isApplying: isApplying,
sendEmail: sendEmail, sendEmail: sendEmail,
gatewayRefund: gatewayRefund, gatewayRefund: gatewayRefund,

View File

@ -575,7 +575,6 @@ Future handleCreditAction(
createEntity( createEntity(
context: context, context: context,
entity: PaymentEntity(state: state).rebuild((b) => b entity: PaymentEntity(state: state).rebuild((b) => b
..isForCredit = true
..typeId = kPaymentTypeCredit ..typeId = kPaymentTypeCredit
..clientId = credit.clientId ..clientId = credit.clientId
..credits.addAll(credits ..credits.addAll(credits

View File

@ -645,7 +645,6 @@ void handleInvoiceAction(BuildContext context, List<BaseEntity> invoices,
createEntity( createEntity(
context: context, context: context,
entity: PaymentEntity(state: state).rebuild((b) => b entity: PaymentEntity(state: state).rebuild((b) => b
..isForInvoice = true
..clientId = invoice.clientId ..clientId = invoice.clientId
..invoices.addAll(invoices ..invoices.addAll(invoices
.where((invoice) => !(invoice as InvoiceEntity).isPaid) .where((invoice) => !(invoice as InvoiceEntity).isPaid)

View File

@ -191,6 +191,13 @@ class _PaymentEditState extends State<PaymentEdit> {
} }
} }
double limit;
if (payment.amount != 0) {
limit = payment.amount - paymentTotal;
} else {
limit = creditTotal;
}
final body = Form( final body = Form(
key: _formKey, key: _formKey,
child: Column( child: Column(
@ -250,9 +257,7 @@ class _PaymentEditState extends State<PaymentEdit> {
paymentable: invoicePaymentables[index], paymentable: invoicePaymentables[index],
index: index, index: index,
entityType: EntityType.invoice, entityType: EntityType.invoice,
limit: payment.amount == 0 limit: limit,
? null
: payment.amount - paymentTotal,
), ),
if (payment.isApplying != true) if (payment.isApplying != true)
DatePicker( DatePicker(
@ -725,7 +730,7 @@ class _PaymentableEditorState extends State<PaymentableEditor> {
autocorrect: false, autocorrect: false,
keyboardType: keyboardType:
TextInputType.numberWithOptions(decimal: true, signed: true), TextInputType.numberWithOptions(decimal: true, signed: true),
label: payment.isForInvoice == true label: widget.entityType == EntityType.invoice
? localization.amount ? localization.amount
: localization.applied, : localization.applied,
onSavePressed: viewModel.onSavePressed, onSavePressed: viewModel.onSavePressed,

View File

@ -89,9 +89,7 @@ class PaymentEditVM {
showDialog<ErrorDialog>( showDialog<ErrorDialog>(
context: navigatorKey.currentContext, context: navigatorKey.currentContext,
builder: (BuildContext context) { builder: (BuildContext context) {
return ErrorDialog(payment.isForCredit return ErrorDialog(localization.negativePaymentError);
? localization.creditIsMoreThanInvoice
: localization.negativePaymentError);
}); });
return null; return null;
} }