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

View File

@ -213,20 +213,6 @@ class _$PaymentEntitySerializer implements StructuredSerializer<PaymentEntity> {
serializers.serialize(object.id, specifiedType: const FullType(String)),
];
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;
if (value != null) {
result
@ -383,14 +369,6 @@ class _$PaymentEntitySerializer implements StructuredSerializer<PaymentEntity> {
result.currencyId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
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':
result.isApplying = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
@ -783,10 +761,6 @@ class _$PaymentEntity extends PaymentEntity {
@override
final String currencyId;
@override
final bool isForInvoice;
@override
final bool isForCredit;
@override
final bool isApplying;
@override
final bool sendEmail;
@ -842,8 +816,6 @@ class _$PaymentEntity extends PaymentEntity {
this.clientContactId,
this.companyGatewayId,
this.currencyId,
this.isForInvoice,
this.isForCredit,
this.isApplying,
this.sendEmail,
this.gatewayRefund,
@ -948,8 +920,6 @@ class _$PaymentEntity extends PaymentEntity {
clientContactId == other.clientContactId &&
companyGatewayId == other.companyGatewayId &&
currencyId == other.currencyId &&
isForInvoice == other.isForInvoice &&
isForCredit == other.isForCredit &&
isApplying == other.isApplying &&
sendEmail == other.sendEmail &&
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(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),
vendorId.hashCode),
invitationId.hashCode),
clientContactId.hashCode),
companyGatewayId.hashCode),
currencyId.hashCode),
isForInvoice.hashCode),
isForCredit.hashCode),
isApplying.hashCode),
sendEmail.hashCode),
gatewayRefund.hashCode),
@ -1035,8 +1005,6 @@ class _$PaymentEntity extends PaymentEntity {
..add('clientContactId', clientContactId)
..add('companyGatewayId', companyGatewayId)
..add('currencyId', currencyId)
..add('isForInvoice', isForInvoice)
..add('isForCredit', isForCredit)
..add('isApplying', isApplying)
..add('sendEmail', sendEmail)
..add('gatewayRefund', gatewayRefund)
@ -1155,14 +1123,6 @@ class PaymentEntityBuilder
String get currencyId => _$this._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 get isApplying => _$this._isApplying;
set isApplying(bool isApplying) => _$this._isApplying = isApplying;
@ -1256,8 +1216,6 @@ class PaymentEntityBuilder
_clientContactId = $v.clientContactId;
_companyGatewayId = $v.companyGatewayId;
_currencyId = $v.currencyId;
_isForInvoice = $v.isForInvoice;
_isForCredit = $v.isForCredit;
_isApplying = $v.isApplying;
_sendEmail = $v.sendEmail;
_gatewayRefund = $v.gatewayRefund;
@ -1326,8 +1284,6 @@ class PaymentEntityBuilder
clientContactId: BuiltValueNullFieldError.checkNotNull(clientContactId, 'PaymentEntity', 'clientContactId'),
companyGatewayId: BuiltValueNullFieldError.checkNotNull(companyGatewayId, 'PaymentEntity', 'companyGatewayId'),
currencyId: BuiltValueNullFieldError.checkNotNull(currencyId, 'PaymentEntity', 'currencyId'),
isForInvoice: isForInvoice,
isForCredit: isForCredit,
isApplying: isApplying,
sendEmail: sendEmail,
gatewayRefund: gatewayRefund,

View File

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

View File

@ -645,7 +645,6 @@ void handleInvoiceAction(BuildContext context, List<BaseEntity> invoices,
createEntity(
context: context,
entity: PaymentEntity(state: state).rebuild((b) => b
..isForInvoice = true
..clientId = invoice.clientId
..invoices.addAll(invoices
.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(
key: _formKey,
child: Column(
@ -250,9 +257,7 @@ class _PaymentEditState extends State<PaymentEdit> {
paymentable: invoicePaymentables[index],
index: index,
entityType: EntityType.invoice,
limit: payment.amount == 0
? null
: payment.amount - paymentTotal,
limit: limit,
),
if (payment.isApplying != true)
DatePicker(
@ -725,7 +730,7 @@ class _PaymentableEditorState extends State<PaymentableEditor> {
autocorrect: false,
keyboardType:
TextInputType.numberWithOptions(decimal: true, signed: true),
label: payment.isForInvoice == true
label: widget.entityType == EntityType.invoice
? localization.amount
: localization.applied,
onSavePressed: viewModel.onSavePressed,

View File

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