Repository: incubator-fineract Updated Branches: refs/heads/develop 60588a78e -> 3970b2ede
Issues Found during QA Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/3970b2ed Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/3970b2ed Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/3970b2ed Branch: refs/heads/develop Commit: 3970b2ede1658ab9730b1ffec04a62fc7e0d4b3a Parents: 60588a7 Author: Nazeer Hussain Shaik <[email protected]> Authored: Thu Apr 21 18:29:07 2016 +0530 Committer: Nazeer Hussain Shaik <[email protected]> Committed: Thu Apr 21 18:29:07 2016 +0530 ---------------------------------------------------------------------- .../domain/ShareAccountCharge.java | 12 ++--- .../ShareAccountDataSerializer.java | 50 ++++++++++---------- ...ntWritePlatformServiceJpaRepositoryImpl.java | 24 ++++------ .../shareproducts/domain/ShareProduct.java | 8 +++- 4 files changed, 48 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3970b2ed/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountCharge.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountCharge.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountCharge.java index 2587dd6..7b8a356 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountCharge.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/domain/ShareAccountCharge.java @@ -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; http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3970b2ed/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java index 1e63050..18411b6 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/serialization/ShareAccountDataSerializer.java @@ -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); http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3970b2ed/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java index e97f6e3..d4f4cd7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java @@ -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)); http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/3970b2ed/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java index 6cf301e..b761d94 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/domain/ShareProduct.java @@ -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 ; }
