Issues Found during QA

This commit is contained in:
Nazeer Hussain Shaik
2016-04-21 18:29:07 +05:30
parent 60588a78e0
commit 3970b2ede1
4 changed files with 48 additions and 46 deletions
@@ -375,12 +375,12 @@ public class ShareAccountCharge extends AbstractPersistable<Long> {
return this.chargeTime;
}
public BigDecimal deriveChargeAmount(BigDecimal transactionAmount) {
public BigDecimal deriveChargeAmount(BigDecimal transactionAmount, final MonetaryCurrency currency) {
BigDecimal toReturnAmount = amountOrPercentage;
if (ChargeCalculationType.fromInt(this.chargeCalculation) == ChargeCalculationType.PERCENT_OF_AMOUNT) {
toReturnAmount = percentageOf(transactionAmount, this.percentage);
toReturnAmount = Money.of(currency, percentageOf(transactionAmount, this.percentage)).getAmount() ;
this.amountPercentageAppliedTo = transactionAmount;
this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage);
this.amount = Money.of(currency, percentageOf(this.amountPercentageAppliedTo, this.percentage)).getAmount() ;
this.amountPaid = null;
this.amountOutstanding = calculateOutstanding();
this.amountWaived = null;
@@ -394,12 +394,12 @@ public class ShareAccountCharge extends AbstractPersistable<Long> {
return toReturnAmount;
}
public BigDecimal updateChargeDetailsForAdditionalSharesRequest(final BigDecimal transactionAmount) {
public BigDecimal updateChargeDetailsForAdditionalSharesRequest(final BigDecimal transactionAmount, final MonetaryCurrency currency) {
BigDecimal toReturnAmount = amountOrPercentage;
if (ChargeCalculationType.fromInt(this.chargeCalculation) == ChargeCalculationType.PERCENT_OF_AMOUNT) {
toReturnAmount = percentageOf(transactionAmount, this.percentage);
toReturnAmount = Money.of(currency, percentageOf(transactionAmount, this.percentage)).getAmount() ;
this.amountPercentageAppliedTo = this.amountPercentageAppliedTo.add(transactionAmount);
this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage);
this.amount = Money.of(currency, percentageOf(this.amountPercentageAppliedTo, this.percentage)).getAmount() ;
this.amountOutstanding = calculateOutstanding();
this.amountWaived = null;
this.amountWrittenOff = null;
@@ -203,7 +203,7 @@ public class ShareAccountDataSerializer {
Date currentDate = DateUtils.getLocalDateOfTenant().toDate();
for (ShareAccountCharge charge : charges) {
if (charge.isActive() && charge.isShareAccountActivation()) {
charge.deriveChargeAmount(totalChargeAmount);
charge.deriveChargeAmount(totalChargeAmount, account.getCurrency());
ShareAccountTransaction chargeTransaction = ShareAccountTransaction.createChargeTransaction(currentDate, charge);
ShareAccountChargePaidBy paidBy = new ShareAccountChargePaidBy(chargeTransaction, charge, charge.percentageOrAmount());
chargeTransaction.addShareAccountChargePaidBy(paidBy);
@@ -215,7 +215,7 @@ public class ShareAccountDataSerializer {
for (ShareAccountTransaction pending : pendingApprovalTransaction) {
for (ShareAccountCharge charge : charges) {
if (charge.isActive() && charge.isSharesPurchaseCharge()) {
BigDecimal amount = charge.deriveChargeAmount(pending.amount());
BigDecimal amount = charge.deriveChargeAmount(pending.amount(), account.getCurrency());
ShareAccountChargePaidBy paidBy = new ShareAccountChargePaidBy(pending, charge, amount);
pending.addShareAccountChargePaidBy(paidBy);
totalChargeAmount = totalChargeAmount.add(amount);
@@ -481,7 +481,7 @@ public class ShareAccountDataSerializer {
for(ShareAccountCharge charge: charges) {
if(charge.isActive() && charge.isSharesPurchaseCharge()) {
charge.update(transactionAmount, charge.percentageOrAmount()) ;
charge.deriveChargeAmount(transactionAmount);
charge.deriveChargeAmount(transactionAmount, shareAccount.getCurrency());
}
}
Set<ShareAccountTransaction> transactions = shareAccount.getShareAccountTransactions();
@@ -632,7 +632,7 @@ public class ShareAccountDataSerializer {
BigDecimal totalChargeAmount = BigDecimal.ZERO;
for (ShareAccountCharge charge : charges) {
if (charge.isActive() && charge.isSharesPurchaseCharge()) {
BigDecimal amount = charge.updateChargeDetailsForAdditionalSharesRequest(purchaseTransaction.amount());
BigDecimal amount = charge.updateChargeDetailsForAdditionalSharesRequest(purchaseTransaction.amount(), account.getCurrency());
ShareAccountChargePaidBy paidBy = new ShareAccountChargePaidBy(purchaseTransaction, charge, amount);
purchaseTransaction.addShareAccountChargePaidBy(paidBy);
totalChargeAmount = totalChargeAmount.add(amount);
@@ -758,7 +758,7 @@ public class ShareAccountDataSerializer {
boolean isTransactionBeforeExistingTransactions = false ;
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions() ;
for(ShareAccountTransaction transaction: transactions) {
if(!transaction.isChargeTransaction()) {
if(!transaction.isChargeTransaction() && transaction.isActive()) {
LocalDate transactionDate = new LocalDate(transaction.getPurchasedDate()) ;
if(requestedDate.isBefore(transactionDate)) {
isTransactionBeforeExistingTransactions = true ;
@@ -772,12 +772,12 @@ public class ShareAccountDataSerializer {
.failWithCodeNoParameterAddedToErrorCode("redeem.transaction.date.cannot.be.before.existing.transactions");
}
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction(requestedDate.toDate(), sharesRequested,
unitPrice);
validateRedeemRequest(account, transaction, baseDataValidator, dataValidationErrors) ;
account.addAdditionalPurchasedShares(transaction);
actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, transaction);
validateRedeemRequest(account, transaction, baseDataValidator, dataValidationErrors) ;
handleRedeemSharesChargeTransactions(account, transaction);
return actualChanges;
}
@@ -840,22 +840,24 @@ public class ShareAccountDataSerializer {
}
private LocalDate deriveLockinPeriodDuration(final Integer lockinPeriod, final PeriodFrequencyType periodType, LocalDate purchaseDate) {
LocalDate lockinDate = null ;
switch(periodType) {
case INVALID: //It never comes in to this state.
break ;
case DAYS:
lockinDate = purchaseDate.plusDays(lockinPeriod) ;
break ;
case WEEKS:
lockinDate = purchaseDate.plusWeeks(lockinPeriod) ;
break ;
case MONTHS:
lockinDate = purchaseDate.plusMonths(lockinPeriod) ;
break ;
case YEARS:
lockinDate = purchaseDate.plusYears(lockinPeriod) ;
break ;
LocalDate lockinDate = purchaseDate ;
if(periodType != null) {
switch(periodType) {
case INVALID: //It never comes in to this state.
break ;
case DAYS:
lockinDate = purchaseDate.plusDays(lockinPeriod) ;
break ;
case WEEKS:
lockinDate = purchaseDate.plusWeeks(lockinPeriod) ;
break ;
case MONTHS:
lockinDate = purchaseDate.plusMonths(lockinPeriod) ;
break ;
case YEARS:
lockinDate = purchaseDate.plusYears(lockinPeriod) ;
break ;
}
}
return lockinDate ;
}
@@ -865,7 +867,7 @@ public class ShareAccountDataSerializer {
BigDecimal totalChargeAmount = BigDecimal.ZERO;
for (ShareAccountCharge charge : charges) {
if (charge.isActive() && charge.isSharesRedeemCharge()) {
BigDecimal amount = charge.updateChargeDetailsForAdditionalSharesRequest(transaction.amount());
BigDecimal amount = charge.updateChargeDetailsForAdditionalSharesRequest(transaction.amount(), account.getCurrency());
ShareAccountChargePaidBy paidBy = new ShareAccountChargePaidBy(transaction, charge, amount);
transaction.addShareAccountChargePaidBy(paidBy);
totalChargeAmount = totalChargeAmount.add(amount);
@@ -273,6 +273,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
journalTransactions.add(transaction);
}
}
this.journalEntryWritePlatformService.createJournalEntriesForShares(populateJournalEntries(account, journalTransactions));
return new CommandProcessingResultBuilder() //
.withCommandId(jsonCommand.commandId()) //
@@ -413,21 +414,14 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
this.shareAccountRepository.save(account);
ShareAccountTransaction transaction = (ShareAccountTransaction) changes
.get(ShareAccountApiConstants.requestedshares_paramname);
transaction = account.getShareAccountTransaction(transaction); // after
// saving,
// entity
// will
// have
// different
// object.
// So
// need
// to
// retrieve
// to
// get
// the
// id
// after saving, entity will have different object. So need to retrieve the entity object
transaction = account.getShareAccountTransaction(transaction);
Long redeemShares = transaction.getTotalShares() ;
ShareProduct shareProduct = account.getShareProduct() ;
//remove the redeem shares from total subscribed shares
shareProduct.removeSubscribedShares(redeemShares);
this.shareProductRepository.save(shareProduct);
Set<ShareAccountTransaction> transactions = new HashSet<>();
transactions.add(transaction);
this.journalEntryWritePlatformService.createJournalEntriesForShares(populateJournalEntries(account, transactions));
@@ -33,6 +33,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@@ -100,6 +101,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "maximum_client_shares")
private Long maximumShares;
@OrderBy(value = "fromDate,id")
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product", orphanRemoval = true)
Set<ShareProductMarketPrice> marketPrice;
@@ -415,7 +417,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
if (this.marketPrice != null && !this.marketPrice.isEmpty()) {
for (ShareProductMarketPrice data : this.marketPrice) {
Date futureDate = data.getStartDate();
if (currentDate.after(futureDate)) {
if (currentDate.equals(futureDate) || currentDate.after(futureDate)) {
marketValue = data.getPrice();
}
}
@@ -430,6 +432,10 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
this.totalSubscribedShares += subscribedShares ;
}
public void removeSubscribedShares(final Long subscribedShares) {
this.totalSubscribedShares -= subscribedShares ;
}
public Long getSubscribedShares() {
return this.totalSubscribedShares ;
}