add validation for charges
This commit is contained in:
+40
-37
@@ -335,8 +335,9 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
|
||||
if (!CollectionUtils.isEmpty(savingsAccountCharges)) {
|
||||
this.charges = associateChargesWithThisSavingsAccount(savingsAccountCharges);
|
||||
//TODO:Add charges details to savings summary
|
||||
//this.summary = updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
|
||||
// TODO:Add charges details to savings summary
|
||||
// this.summary =
|
||||
// updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
|
||||
}
|
||||
|
||||
this.summary = new SavingsAccountSummary();
|
||||
@@ -827,7 +828,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
|
||||
throw new PlatformApiDataValidationException(dataValidationErrors);
|
||||
}
|
||||
validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_PAY_FEE, annualFeeTransactionDate);
|
||||
validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_PAY_CHARGE, annualFeeTransactionDate);
|
||||
|
||||
existingTransactionIds.addAll(findExistingTransactionIds());
|
||||
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
|
||||
@@ -1100,7 +1101,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
//charges
|
||||
// charges
|
||||
final String chargesParamName = "charges";
|
||||
if (command.hasParameter(chargesParamName)) {
|
||||
JsonArray jsonArray = command.arrayOfParameterNamed(chargesParamName);
|
||||
@@ -1115,8 +1116,6 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
this.annualFeeOnMonth = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
validateLockinDetails();
|
||||
validateWithdrawalFeeDetails();
|
||||
validateAnnualFeeDetails();
|
||||
@@ -1498,7 +1497,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
this.annualFeeNextDueDate = newAnnualFeeNextDueDate.toDate();
|
||||
}
|
||||
} else if (transactionToUndo.isCharge()) {
|
||||
//undo charge
|
||||
// undo charge
|
||||
final Set<SavingsAccountChargePaidBy> chargesPaidBy = transactionToUndo.getSavingsAccountChargesPaid();
|
||||
for (SavingsAccountChargePaidBy savingsAccountChargePaidBy : chargesPaidBy) {
|
||||
final SavingsAccountCharge chargeToUndo = savingsAccountChargePaidBy.getSavingsAccountCharge();
|
||||
@@ -1885,19 +1884,19 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
public boolean update(final Set<SavingsAccountCharge> newSavingsAccountCharges) {
|
||||
if (newSavingsAccountCharges == null) return false;
|
||||
|
||||
if(this.charges == null) this.charges = new HashSet<SavingsAccountCharge>();
|
||||
if (this.charges == null) this.charges = new HashSet<SavingsAccountCharge>();
|
||||
this.charges.clear();
|
||||
this.charges.addAll(associateChargesWithThisSavingsAccount(newSavingsAccountCharges));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasCurrencyCodeOf(final String matchingCurrencyCode) {
|
||||
//TODO AA: revisit
|
||||
if(this.currency == null) return false;
|
||||
// TODO AA: revisit
|
||||
if (this.currency == null) return false;
|
||||
return this.currency.getCode().equalsIgnoreCase(matchingCurrencyCode);
|
||||
}
|
||||
|
||||
public void removeCharge(final SavingsAccountCharge charge){
|
||||
public void removeCharge(final SavingsAccountCharge charge) {
|
||||
this.charges.remove(charge);
|
||||
}
|
||||
|
||||
@@ -1921,10 +1920,10 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
final SavingsAccountCharge savingsAccountCharge = this.getCharge(savingsAccountChargeId);
|
||||
|
||||
// validate charge is not already paid or waived
|
||||
if(savingsAccountCharge.isWaived()){
|
||||
if (savingsAccountCharge.isWaived()) {
|
||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.charge.is.already.waived");
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}else if(savingsAccountCharge.isPaid()){
|
||||
} else if (savingsAccountCharge.isPaid()) {
|
||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.charge.is.paid");
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
@@ -1932,18 +1931,19 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
existingTransactionIds.addAll(findExistingTransactionIds());
|
||||
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
|
||||
|
||||
//waive charge
|
||||
// waive charge
|
||||
final Money amountWaived = savingsAccountCharge.waive(this.getCurrency());
|
||||
//TODO : AA revisit the code
|
||||
/*Money feeChargesWaived = amountWaived;
|
||||
Money penaltyChargesWaived = Money.zero(this.getCurrency());
|
||||
if (savingsAccountCharge.isPenaltyCharge()) {
|
||||
penaltyChargesWaived = amountWaived;
|
||||
feeChargesWaived = Money.zero(this.getCurrency());
|
||||
}*/
|
||||
// TODO : AA revisit the code
|
||||
/*
|
||||
* Money feeChargesWaived = amountWaived; Money penaltyChargesWaived =
|
||||
* Money.zero(this.getCurrency()); if
|
||||
* (savingsAccountCharge.isPenaltyCharge()) { penaltyChargesWaived =
|
||||
* amountWaived; feeChargesWaived = Money.zero(this.getCurrency()); }
|
||||
*/
|
||||
|
||||
//persist an entry in transaction details
|
||||
SavingsAccountTransaction chargeTransaction = SavingsAccountTransaction.charge(this, this.office(), savingsAccountCharge.getDueLocalDate(), amountWaived);
|
||||
// persist an entry in transaction details
|
||||
SavingsAccountTransaction chargeTransaction = SavingsAccountTransaction.charge(this, this.office(),
|
||||
savingsAccountCharge.getDueLocalDate(), amountWaived);
|
||||
|
||||
this.transactions.add(chargeTransaction);
|
||||
|
||||
@@ -1952,7 +1952,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
calculateInterestUsing(mc, savingsAccountCharge.getDueLocalDate());
|
||||
}
|
||||
|
||||
public void addCharge(final DateTimeFormatter formatter, final SavingsAccountCharge savingsAccountCharge, final Charge chargeDefinition){
|
||||
public void addCharge(final DateTimeFormatter formatter, final SavingsAccountCharge savingsAccountCharge, final Charge chargeDefinition) {
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
@@ -1969,7 +1969,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
if (!this.hasCurrencyCodeOf(chargeDefinition.getCurrencyCode())) {
|
||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.currency.and.charge.currency.not.same");
|
||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
|
||||
"transaction.invalid.account.currency.and.charge.currency.not.same");
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
|
||||
@@ -1981,7 +1982,9 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
throw new PlatformApiDataValidationException(dataValidationErrors);
|
||||
}
|
||||
|
||||
//add new charge to savings account
|
||||
validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLY_CHARGE, chargeDueDate);
|
||||
|
||||
// add new charge to savings account
|
||||
getCharges().add(savingsAccountCharge);
|
||||
|
||||
}
|
||||
@@ -2006,10 +2009,10 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
final SavingsAccountCharge savingsAccountCharge = this.getCharge(savingsAccountChargeId);
|
||||
|
||||
// validate charge is not already paid or waived
|
||||
if(savingsAccountCharge.isWaived()){
|
||||
if (savingsAccountCharge.isWaived()) {
|
||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.charge.is.already.waived");
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}else if(savingsAccountCharge.isPaid()){
|
||||
} else if (savingsAccountCharge.isPaid()) {
|
||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.charge.is.paid");
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
@@ -2019,12 +2022,15 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
|
||||
final Money chargePaid = savingsAccountCharge.pay(this.getCurrency(), amountPaid);
|
||||
|
||||
// If null reset to current date
|
||||
final LocalDate transactionDate = (savingsAccountCharge.getDueLocalDate() == null) ? DateUtils.getLocalDateOfTenant()
|
||||
: savingsAccountCharge.getDueLocalDate();//If null reset to current date
|
||||
//persist an entry in transaction details
|
||||
: savingsAccountCharge.getDueLocalDate();
|
||||
|
||||
// persist an entry in transaction details
|
||||
SavingsAccountTransaction chargeTransaction = SavingsAccountTransaction.charge(this, this.office(), transactionDate, chargePaid);
|
||||
|
||||
final SavingsAccountChargePaidBy chargePaidBy = SavingsAccountChargePaidBy.instance(chargeTransaction, savingsAccountCharge, amountPaid);
|
||||
final SavingsAccountChargePaidBy chargePaidBy = SavingsAccountChargePaidBy.instance(chargeTransaction, savingsAccountCharge,
|
||||
amountPaid);
|
||||
chargeTransaction.getSavingsAccountChargesPaid().add(chargePaidBy);
|
||||
this.transactions.add(chargeTransaction);
|
||||
|
||||
@@ -2043,24 +2049,21 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private SavingsAccountCharge getCharge(Long savingsAccountChargeId) {
|
||||
SavingsAccountCharge charge = null;
|
||||
for (SavingsAccountCharge existingCharge : this.charges) {
|
||||
if(existingCharge.getId().equals(savingsAccountChargeId)) {
|
||||
if (existingCharge.getId().equals(savingsAccountChargeId)) {
|
||||
charge = existingCharge;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(charge == null){
|
||||
throw new SavingsAccountChargeNotFoundException(savingsAccountChargeId, getId());
|
||||
}
|
||||
if (charge == null) { throw new SavingsAccountChargeNotFoundException(savingsAccountChargeId, getId()); }
|
||||
|
||||
return charge;
|
||||
}
|
||||
|
||||
private Set<SavingsAccountCharge> getCharges(){
|
||||
private Set<SavingsAccountCharge> getCharges() {
|
||||
return (this.charges == null) ? new HashSet<SavingsAccountCharge>() : this.charges;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -20,8 +20,9 @@ public enum SavingsEvent {
|
||||
SAVINGS_POST_INTEREST("interest.post"), //
|
||||
SAVINGS_UNDO_TRANSACTION("transaction.undo"), //
|
||||
SAVINGS_ADJUST_TRANSACTION("transaction.adjust"), //
|
||||
SAVINGS_APPLY_FEE("fee.apply"), //
|
||||
SAVINGS_PAY_FEE("fee.pay"), //
|
||||
SAVINGS_APPLY_CHARGE("charge.apply"), //
|
||||
SAVINGS_WAIVE_CHARGE("charge.waive"), //
|
||||
SAVINGS_PAY_CHARGE("charge.pay"), //
|
||||
SAVINGS_CLOSE_ACCOUNT("account.close");
|
||||
|
||||
private final String value;
|
||||
|
||||
Reference in New Issue
Block a user