Merge branch 'pullrequest97' into develop
This commit is contained in:
+2
@@ -58,4 +58,6 @@ public interface SavingsAccountReadPlatformService {
|
||||
List<Long> retrieveSavingsIdsPendingDormant(LocalDate tenantLocalDate);
|
||||
|
||||
List<Long> retrieveSavingsIdsPendingEscheat(LocalDate tenantLocalDate);
|
||||
boolean isAccountBelongsToClient(final Long clientId, final Long accountId, final DepositAccountType depositAccountType, final String currencyCode) ;
|
||||
|
||||
}
|
||||
+12
-2
@@ -24,7 +24,6 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -40,7 +39,6 @@ import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||
import org.apache.fineract.organisation.staff.data.StaffData;
|
||||
import org.apache.fineract.organisation.staff.service.StaffReadPlatformService;
|
||||
import org.apache.fineract.portfolio.account.data.AccountTransferData;
|
||||
import org.apache.fineract.portfolio.calendar.service.CalendarUtils;
|
||||
import org.apache.fineract.portfolio.charge.data.ChargeData;
|
||||
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
|
||||
import org.apache.fineract.portfolio.client.data.ClientData;
|
||||
@@ -1156,6 +1154,18 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountBelongsToClient(final Long clientId, final Long accountId, final DepositAccountType depositAccountType,
|
||||
final String currencyCode) {
|
||||
try {
|
||||
final StringBuffer buff = new StringBuffer("select count(*) from m_savings_account sa ") ;
|
||||
buff.append(" where sa.id = ? and sa.client_id = ? and sa.deposit_type_enum = ? and sa.currency_code = ? and sa.status_enum = 300");
|
||||
return this.jdbcTemplate.queryForObject(buff.toString(),
|
||||
new Object[] { accountId, clientId, depositAccountType.getValue(), currencyCode }, Integer.class) > 0;
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
throw new SavingsAccountNotFoundException(accountId);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* private static final class SavingsAccountAnnualFeeMapper implements
|
||||
* RowMapper<SavingsAccountAnnualFeeData> {
|
||||
|
||||
+4
-7
@@ -238,7 +238,7 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
|
||||
public boolean setExternalId(final String externalId) {
|
||||
boolean toReturn = false;
|
||||
if (!this.externalId.equals(externalId)) {
|
||||
if (this.externalId == null || !this.externalId.equals(externalId)) {
|
||||
this.externalId = externalId;
|
||||
toReturn = true;
|
||||
}
|
||||
@@ -272,10 +272,7 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
|
||||
public boolean setAllowDividendCalculationForInactiveClients(Boolean allowDividendCalculationForInactiveClients) {
|
||||
boolean returnValue = false;
|
||||
if (this.allowDividendCalculationForInactiveClients == null) {
|
||||
this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients;
|
||||
returnValue = true;
|
||||
} else if (!this.allowDividendCalculationForInactiveClients.equals(allowDividendCalculationForInactiveClients)) {
|
||||
if (this.allowDividendCalculationForInactiveClients == null || !this.allowDividendCalculationForInactiveClients.equals(allowDividendCalculationForInactiveClients)) {
|
||||
this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -293,7 +290,7 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
|
||||
public boolean setLockPeriodFrequencyEnum(final PeriodFrequencyType lockinPeriodFrequencyType) {
|
||||
boolean returnValue = false;
|
||||
if (!this.lockinPeriodFrequencyType.getValue().equals(lockinPeriodFrequencyType.getValue())) {
|
||||
if (this.lockinPeriodFrequencyType == null || !this.lockinPeriodFrequencyType.getValue().equals(lockinPeriodFrequencyType.getValue())) {
|
||||
this.lockinPeriodFrequencyType = lockinPeriodFrequencyType;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -311,7 +308,7 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
|
||||
public boolean setminimumActivePeriodTypeEnum(final PeriodFrequencyType minimumActivePeriodForDividends) {
|
||||
boolean returnValue = false;
|
||||
if (!this.minimumActivePeriodFrequencyType.getValue().equals(minimumActivePeriodForDividends.getValue())) {
|
||||
if (this.minimumActivePeriodFrequencyType == null || !this.minimumActivePeriodFrequencyType.getValue().equals(minimumActivePeriodForDividends.getValue())) {
|
||||
this.minimumActivePeriodFrequencyType = minimumActivePeriodForDividends;
|
||||
returnValue = true;
|
||||
}
|
||||
|
||||
+3
-1
@@ -243,5 +243,7 @@ public class ShareAccountTransaction extends AbstractPersistable<Long> {
|
||||
return this.active ;
|
||||
}
|
||||
|
||||
|
||||
public BigDecimal shareValue() {
|
||||
return this.shareValue ;
|
||||
}
|
||||
}
|
||||
|
||||
+43
-18
@@ -49,8 +49,11 @@ import org.apache.fineract.portfolio.client.domain.Client;
|
||||
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
|
||||
import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
|
||||
import org.apache.fineract.portfolio.loanproduct.exception.InvalidCurrencyException;
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountType;
|
||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
|
||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
|
||||
import org.apache.fineract.portfolio.savings.exception.SavingsAccountNotFoundException;
|
||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformService;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountCharge;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountChargePaidBy;
|
||||
@@ -84,16 +87,20 @@ public class ShareAccountDataSerializer {
|
||||
|
||||
private final ShareProductRepositoryWrapper shareProductRepository;
|
||||
|
||||
private final SavingsAccountReadPlatformService savingsAccountReadPlatformService ;
|
||||
|
||||
@Autowired
|
||||
public ShareAccountDataSerializer(final PlatformSecurityContext platformSecurityContext, final FromJsonHelper fromApiJsonHelper,
|
||||
final ChargeRepositoryWrapper chargeRepository, final SavingsAccountRepositoryWrapper savingsAccountRepositoryWrapper,
|
||||
final ClientRepositoryWrapper clientRepositoryWrapper, final ShareProductRepositoryWrapper shareProductRepository) {
|
||||
final ClientRepositoryWrapper clientRepositoryWrapper, final ShareProductRepositoryWrapper shareProductRepository,
|
||||
final SavingsAccountReadPlatformService savingsAccountReadPlatformService) {
|
||||
this.platformSecurityContext = platformSecurityContext;
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.chargeRepository = chargeRepository;
|
||||
this.savingsAccountRepositoryWrapper = savingsAccountRepositoryWrapper;
|
||||
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
||||
this.shareProductRepository = shareProductRepository;
|
||||
this.savingsAccountReadPlatformService = savingsAccountReadPlatformService ;
|
||||
}
|
||||
|
||||
public ShareAccount validateAndCreate(JsonCommand jsonCommand) {
|
||||
@@ -120,16 +127,16 @@ public class ShareAccountDataSerializer {
|
||||
Long savingsAccountId = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.savingsaccountid_paramname, element);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.savingsaccountid_paramname).value(savingsAccountId).notNull()
|
||||
.longGreaterThanZero();
|
||||
|
||||
final Long requestedShares = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares).notNull()
|
||||
.longGreaterThanZero();
|
||||
if(requestedShares < shareProduct.getMinimumClientShares()) {
|
||||
|
||||
if(shareProduct.getMinimumClientShares() != null && requestedShares < shareProduct.getMinimumClientShares()) {
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares)
|
||||
.failWithCode("client.can.not.purchase.shares.lessthan.product.definition", "Client can not purchase shares less than product definition");
|
||||
}
|
||||
|
||||
if(requestedShares > shareProduct.getMaximumClientShares()) {
|
||||
if(shareProduct.getMaximumClientShares() != null && requestedShares > shareProduct.getMaximumClientShares()) {
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares)
|
||||
.failWithCode("client.can.not.purchase.shares.morethan.product.definition", "Client can not purchase shares more than product definition");
|
||||
}
|
||||
@@ -156,7 +163,10 @@ public class ShareAccountDataSerializer {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
|
||||
Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
|
||||
SavingsAccount savingsAccount = this.savingsAccountRepositoryWrapper.findOneWithNotFoundDetection(savingsAccountId);
|
||||
if(!this.savingsAccountReadPlatformService.isAccountBelongsToClient(clientId, savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT, shareProduct.getCurrency().getCode())) {
|
||||
throw new SavingsAccountNotFoundException(savingsAccountId) ;
|
||||
}
|
||||
SavingsAccount savingsAccount = this.savingsAccountRepositoryWrapper.findOneWithNotFoundDetection(savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT);
|
||||
final MonetaryCurrency currency = shareProduct.getCurrency();
|
||||
Set<ShareAccountCharge> charges = assembleListOfAccountCharges(element, currency.getCode());
|
||||
|
||||
@@ -266,6 +276,9 @@ public class ShareAccountDataSerializer {
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.savingsaccountid_paramname).value(savingsAccountId).notNull()
|
||||
.longGreaterThanZero();
|
||||
if(savingsAccountId != null) {
|
||||
if(!this.savingsAccountReadPlatformService.isAccountBelongsToClient(account.getClientId(), savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT, shareProduct.getCurrency().getCode())) {
|
||||
throw new SavingsAccountNotFoundException(savingsAccountId) ;
|
||||
}
|
||||
SavingsAccount savingsAccount = this.savingsAccountRepositoryWrapper.findOneWithNotFoundDetection(savingsAccountId);
|
||||
if (account.setSavingsAccount(savingsAccount)) {
|
||||
actualChanges.put(ShareAccountApiConstants.savingsaccountid_paramname, savingsAccount.getId());
|
||||
@@ -273,43 +286,55 @@ public class ShareAccountDataSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
Date existingApplicationDate = null ;
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.requestedshares_paramname, element)
|
||||
|| this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.charges_paramname, element)) {
|
||||
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
|
||||
List<Long> reveralIds = new ArrayList<>();
|
||||
for (ShareAccountTransaction transaction : transactions) {
|
||||
transaction.setActive(false);
|
||||
if(!transaction.isChargeTransaction()) {
|
||||
existingApplicationDate = transaction.getPurchasedDate() ;
|
||||
}
|
||||
reveralIds.add(transaction.getId());
|
||||
}
|
||||
|
||||
actualChanges.put("reversalIds", reveralIds);
|
||||
account.removeTransactions();
|
||||
account.removeCharges();
|
||||
Set<ShareAccountCharge> charges = account.getCharges() ;
|
||||
for(ShareAccountCharge charge: charges) {
|
||||
charge.setActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.requestedshares_paramname, element)) {
|
||||
Long requestedShares = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
|
||||
/*
|
||||
* BigDecimal unitPrice =
|
||||
* this.fromApiJsonHelper.extractBigDecimalNamed
|
||||
* (ShareAccountApiConstants.purchasedprice_paramname, element,
|
||||
* locale);
|
||||
*/
|
||||
Date applicationDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.applicationdate_param, element)
|
||||
.toDate();
|
||||
Date applicationDate = null ;
|
||||
if(this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.applicationdate_param, element)) {
|
||||
applicationDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.applicationdate_param, element)
|
||||
.toDate();
|
||||
}else {
|
||||
applicationDate = existingApplicationDate ;
|
||||
}
|
||||
BigDecimal unitPrice = shareProduct.deriveMarketPrice(applicationDate);
|
||||
ShareAccountTransaction transaction = new ShareAccountTransaction(applicationDate, requestedShares, unitPrice);
|
||||
account.addTransaction(transaction);
|
||||
actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, "Transaction");
|
||||
|
||||
if(requestedShares < shareProduct.getMinimumClientShares()) {
|
||||
if(shareProduct.getMinimumClientShares() != null && requestedShares < shareProduct.getMinimumClientShares()) {
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares)
|
||||
.failWithCode("client.can.not.purchase.shares.lessthan.product.definition", "Client can not purchase shares less than product definition");
|
||||
}
|
||||
|
||||
if(requestedShares > shareProduct.getMaximumClientShares()) {
|
||||
if(shareProduct.getMaximumClientShares() != null && requestedShares > shareProduct.getMaximumClientShares()) {
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares)
|
||||
.failWithCode("client.can.not.purchase.shares.morethan.product.definition", "Client can not purchase shares more than product definition");
|
||||
}
|
||||
}
|
||||
}/*else if(this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.charges_paramname, element)) {
|
||||
//Since we are removing all purchase transactions when either charge param or requestedShares param exists
|
||||
for(ShareAccountTransaction transaction:existingTransactions) {
|
||||
account.addTransaction(transaction);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.allowdividendcalculationforinactiveclients_paramname, element)) {
|
||||
Boolean allowdividendsForInactiveClients = this.fromApiJsonHelper.extractBooleanNamed(
|
||||
|
||||
+12
-24
@@ -196,7 +196,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setDescription(String description) {
|
||||
boolean returnValue = false;
|
||||
if (!this.description.equals(description)) {
|
||||
if (this.description == null || !this.description.equals(description)) {
|
||||
this.description = description;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setExternalId(String externalId) {
|
||||
boolean returnValue = false;
|
||||
if (!this.externalId.equals(externalId)) {
|
||||
if (this.externalId == null || !this.externalId.equals(externalId)) {
|
||||
this.externalId = externalId;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -228,10 +228,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setTotalIssuedShares(Long totalSharesIssued) {
|
||||
boolean returnValue = false;
|
||||
if(this.totalSharesIssued == null) {
|
||||
this.totalSharesIssued = totalSharesIssued ;
|
||||
returnValue = true ;
|
||||
}else if (!this.totalSharesIssued.equals(totalSharesIssued)) {
|
||||
if (this.totalSharesIssued == null || !this.totalSharesIssued.equals(totalSharesIssued)) {
|
||||
this.totalSharesIssued = totalSharesIssued;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -262,7 +259,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setMinimumShares(final Long minimumShares) {
|
||||
boolean returnValue = false;
|
||||
if (!this.minimumShares.equals(minimumShares)) {
|
||||
if (this.minimumShares == null || !this.minimumShares.equals(minimumShares)) {
|
||||
this.minimumShares = minimumShares;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -280,7 +277,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setMaximumShares(final Long maximumShares) {
|
||||
boolean returnValue = false;
|
||||
if (!this.maximumShares.equals(maximumShares)) {
|
||||
if (this.maximumShares == null || !this.maximumShares.equals(maximumShares)) {
|
||||
this.maximumShares = maximumShares;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -316,7 +313,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setAllowDividendCalculationForInactiveClients(Boolean allowDividendCalculationForInactiveClients) {
|
||||
boolean returnValue = false;
|
||||
if (!this.allowDividendCalculationForInactiveClients.equals(allowDividendCalculationForInactiveClients)) {
|
||||
if (this.allowDividendCalculationForInactiveClients == null || !this.allowDividendCalculationForInactiveClients.equals(allowDividendCalculationForInactiveClients)) {
|
||||
this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -325,10 +322,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setLockinPeriod(final Integer lockinPeriod) {
|
||||
boolean returnValue = false;
|
||||
if (this.lockinPeriod == null) {
|
||||
this.lockinPeriod = lockinPeriod;
|
||||
returnValue = true;
|
||||
} else if (!this.lockinPeriod.equals(lockinPeriod)) {
|
||||
if (this.lockinPeriod == null || !this.lockinPeriod.equals(lockinPeriod)) {
|
||||
this.lockinPeriod = lockinPeriod;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -337,7 +331,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setLockPeriodFrequencyType(final PeriodFrequencyType lockPeriod) {
|
||||
boolean returnValue = false;
|
||||
if (!this.lockPeriodType.equals(lockPeriod)) {
|
||||
if (this.lockPeriodType == null || !this.lockPeriodType.equals(lockPeriod)) {
|
||||
this.lockPeriodType = lockPeriod;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -346,10 +340,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setminimumActivePeriod(final Integer minimumActivePeriod) {
|
||||
boolean returnValue = false;
|
||||
if (this.minimumActivePeriod == null) {
|
||||
this.minimumActivePeriod = minimumActivePeriod;
|
||||
returnValue = true;
|
||||
} else if (!this.minimumActivePeriod.equals(minimumActivePeriod)) {
|
||||
if (this.minimumActivePeriod == null || !this.minimumActivePeriod.equals(minimumActivePeriod)) {
|
||||
this.minimumActivePeriod = minimumActivePeriod;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -358,7 +349,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setminimumActivePeriodFrequencyType(final PeriodFrequencyType minimumActivePeriodForDividends) {
|
||||
boolean returnValue = false;
|
||||
if (!this.minimumActivePeriodType.equals(minimumActivePeriodForDividends)) {
|
||||
if (this.minimumActivePeriodType == null || !this.minimumActivePeriodType.equals(minimumActivePeriodForDividends)) {
|
||||
this.minimumActivePeriodType = minimumActivePeriodForDividends;
|
||||
returnValue = true;
|
||||
}
|
||||
@@ -371,10 +362,7 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public boolean setshareCapitalValue(BigDecimal shareCapitalValue) {
|
||||
boolean updated = false;
|
||||
if (this.shareCapital == null) {
|
||||
this.shareCapital = shareCapitalValue;
|
||||
updated = true;
|
||||
} else if (!this.shareCapital.equals(shareCapitalValue)) {
|
||||
if (this.shareCapital == null || !this.shareCapital.equals(shareCapitalValue)) {
|
||||
this.shareCapital = shareCapitalValue;
|
||||
updated = true;
|
||||
}
|
||||
@@ -451,4 +439,4 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
public Long getDefaultClientShares() {
|
||||
return this.nominalShares ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user