removed unused warnings and code and format of code.
This commit is contained in:
+110
-109
@@ -28,7 +28,6 @@ import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerServi
|
|||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
|
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
|
||||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
||||||
@@ -95,16 +94,14 @@ public class SavingsAccountApiResource {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer;
|
private ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FromJsonHelper fromJsonHelper;
|
|
||||||
|
|
||||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "status", "externalId",
|
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "status", "externalId",
|
||||||
"clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod",
|
"clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod",
|
||||||
"savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType",
|
"savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType",
|
||||||
"interestCalculationMethod", "tenure", "tenureType", "projectedCommencementDate", "actualCommencementDate", "maturesOnDate",
|
"interestCalculationMethod", "tenure", "tenureType", "projectedCommencementDate", "actualCommencementDate", "maturesOnDate",
|
||||||
"projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount",
|
"projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount",
|
||||||
"preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed",
|
"preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed",
|
||||||
"lockinPeriod", "lockinPeriodType","outstandingAmount","savingScheduleData","transactions","interestPostEvery","interestPostFrequency"));
|
"lockinPeriod", "lockinPeriodType", "outstandingAmount", "savingScheduleData", "transactions", "interestPostEvery",
|
||||||
|
"interestPostFrequency"));
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@@ -181,140 +178,145 @@ public class SavingsAccountApiResource {
|
|||||||
responseParameters.addAll(typicalResponseParameters);
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
SavingAccountData account = this.savingAccountReadPlatformService.retrieveSavingsAccount(accountId);
|
SavingAccountData account = this.savingAccountReadPlatformService.retrieveSavingsAccount(accountId);
|
||||||
|
|
||||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||||
if (template) {
|
if (template) {
|
||||||
account = handleTemplateRelatedData(responseParameters, account);
|
account = handleTemplateRelatedData(responseParameters, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
if (associationParameters.contains("all")) {
|
if (associationParameters.contains("all")) {
|
||||||
associationParameters.addAll(Arrays.asList("savingScheduleData","transactions"));
|
associationParameters.addAll(Arrays.asList("savingScheduleData", "transactions"));
|
||||||
responseParameters.addAll(Arrays.asList("permissions","savingScheduleData","transactions"));
|
responseParameters.addAll(Arrays.asList("permissions", "savingScheduleData", "transactions"));
|
||||||
} else {
|
} else {
|
||||||
responseParameters.addAll(associationParameters);
|
responseParameters.addAll(associationParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (associationParameters.contains("savingScheduleData")) {
|
if (associationParameters.contains("savingScheduleData")) {
|
||||||
CurrencyData currencyData = account.getCurrencyData();
|
CurrencyData currencyData = account.getCurrencyData();
|
||||||
savingScheduleData = this.savingAccountReadPlatformService.retrieveSavingsAccountSchedule(accountId,currencyData);
|
savingScheduleData = this.savingAccountReadPlatformService.retrieveSavingsAccountSchedule(accountId, currencyData);
|
||||||
account = new SavingAccountData(account,savingScheduleData);
|
account = new SavingAccountData(account, savingScheduleData);
|
||||||
}
|
}
|
||||||
if (associationParameters.contains("transactions")) {
|
if (associationParameters.contains("transactions")) {
|
||||||
transactions = this.savingAccountReadPlatformService.retrieveSavingsAccountTransactions(accountId);
|
transactions = this.savingAccountReadPlatformService.retrieveSavingsAccountTransactions(accountId);
|
||||||
account = new SavingAccountData(account,transactions);
|
account = new SavingAccountData(account, transactions);
|
||||||
}
|
}
|
||||||
permissions = this.savingAccountReadPlatformService.retrieveSavingAccountPermissions(account);
|
permissions = this.savingAccountReadPlatformService.retrieveSavingAccountPermissions(account);
|
||||||
account = new SavingAccountData(account, permissions);
|
account = new SavingAccountData(account, permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account);
|
return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("template")
|
@Path("template")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveNewDepositAccountDetails(
|
public String retrieveNewDepositAccountDetails(@QueryParam("clientId") final Long clientId,
|
||||||
@QueryParam("clientId") final Long clientId,
|
@QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) {
|
||||||
@QueryParam("productId") final Long productId,
|
|
||||||
@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (responseParameters.isEmpty()) {
|
if (responseParameters.isEmpty()) {
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
}
|
}
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
SavingAccountData account = this.savingAccountReadPlatformService.retrieveNewSavingsAccountDetails(clientId, productId);
|
SavingAccountData account = this.savingAccountReadPlatformService.retrieveNewSavingsAccountDetails(clientId, productId);
|
||||||
account = handleTemplateRelatedData(responseParameters,account);
|
account = handleTemplateRelatedData(responseParameters, account);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account);
|
return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SavingAccountData handleTemplateRelatedData(Set<String> responseParameters, SavingAccountData account) {
|
private SavingAccountData handleTemplateRelatedData(Set<String> responseParameters, SavingAccountData account) {
|
||||||
responseParameters.addAll(Arrays.asList("productOptions", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions",
|
responseParameters.addAll(Arrays.asList("productOptions", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions",
|
||||||
"savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions", "dueAmount"));
|
"savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions",
|
||||||
|
"dueAmount"));
|
||||||
|
|
||||||
Collection<SavingProductLookup> productOptions = savingProductReadPlatformService.retrieveAllSavingProductsForLookup();
|
Collection<SavingProductLookup> productOptions = savingProductReadPlatformService.retrieveAllSavingProductsForLookup();
|
||||||
List<CurrencyData> currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies();
|
List<CurrencyData> currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||||
|
|
||||||
EnumOptionData recurring = SavingProductEnumerations.savingProductType(SavingProductType.RECURRING);
|
EnumOptionData recurring = SavingProductEnumerations.savingProductType(SavingProductType.RECURRING);
|
||||||
EnumOptionData regular = SavingProductEnumerations.savingProductType(SavingProductType.REGULAR);
|
EnumOptionData regular = SavingProductEnumerations.savingProductType(SavingProductType.REGULAR);
|
||||||
List<EnumOptionData> savingsProductTypeOptions = Arrays.asList(recurring, regular);
|
List<EnumOptionData> savingsProductTypeOptions = Arrays.asList(recurring, regular);
|
||||||
|
|
||||||
EnumOptionData fixed = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.FIXED_PERIOD);
|
EnumOptionData fixed = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.FIXED_PERIOD);
|
||||||
EnumOptionData perpetual = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.PERPETUAL);
|
EnumOptionData perpetual = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.PERPETUAL);
|
||||||
List<EnumOptionData> tenureTypeOptions = Arrays.asList(fixed, perpetual);
|
List<EnumOptionData> tenureTypeOptions = Arrays.asList(fixed, perpetual);
|
||||||
|
|
||||||
EnumOptionData monthly = SavingProductEnumerations.interestFrequencyType(SavingFrequencyType.MONTHLY);
|
EnumOptionData monthly = SavingProductEnumerations.interestFrequencyType(SavingFrequencyType.MONTHLY);
|
||||||
List<EnumOptionData> savingFrequencyOptions = Arrays.asList(monthly);
|
List<EnumOptionData> savingFrequencyOptions = Arrays.asList(monthly);
|
||||||
|
|
||||||
EnumOptionData simple = SavingProductEnumerations.savingInterestType(SavingsInterestType.SIMPLE);
|
EnumOptionData simple = SavingProductEnumerations.savingInterestType(SavingsInterestType.SIMPLE);
|
||||||
EnumOptionData compounding = SavingProductEnumerations.savingInterestType(SavingsInterestType.COMPOUNDING);
|
EnumOptionData compounding = SavingProductEnumerations.savingInterestType(SavingsInterestType.COMPOUNDING);
|
||||||
List<EnumOptionData> savingsInterestTypeOptions = Arrays.asList(simple, compounding);
|
List<EnumOptionData> savingsInterestTypeOptions = Arrays.asList(simple, compounding);
|
||||||
|
|
||||||
EnumOptionData months = SavingProductEnumerations.savingsLockinPeriod(SavingsLockinPeriodEnum.MONTHS);
|
EnumOptionData months = SavingProductEnumerations.savingsLockinPeriod(SavingsLockinPeriodEnum.MONTHS);
|
||||||
List<EnumOptionData> lockinPeriodTypeOptions = Arrays.asList(months);
|
List<EnumOptionData> lockinPeriodTypeOptions = Arrays.asList(months);
|
||||||
|
|
||||||
EnumOptionData averagebal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.AVERAGEBAL);
|
EnumOptionData averagebal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.AVERAGEBAL);
|
||||||
// EnumOptionData minbal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MINBAL);
|
// EnumOptionData minbal =
|
||||||
EnumOptionData monthlyCollection = SavingProductEnumerations
|
// SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MINBAL);
|
||||||
.savingInterestCalculationMethod(SavingInterestCalculationMethod.MONTHLYCOLLECTION);
|
EnumOptionData monthlyCollection = SavingProductEnumerations
|
||||||
List<EnumOptionData> interestCalculationOptions = Arrays.asList(averagebal, monthlyCollection);
|
.savingInterestCalculationMethod(SavingInterestCalculationMethod.MONTHLYCOLLECTION);
|
||||||
BigDecimal dueAmount = this.savingAccountReadPlatformService.deriveSavingDueAmount(account);
|
List<EnumOptionData> interestCalculationOptions = Arrays.asList(averagebal, monthlyCollection);
|
||||||
return new SavingAccountData(account, productOptions, currencyOptions, savingsProductTypeOptions,tenureTypeOptions,savingFrequencyOptions,
|
BigDecimal dueAmount = this.savingAccountReadPlatformService.deriveSavingDueAmount(account);
|
||||||
savingsInterestTypeOptions,lockinPeriodTypeOptions,interestCalculationOptions, dueAmount);
|
return new SavingAccountData(account, productOptions, currencyOptions, savingsProductTypeOptions, tenureTypeOptions,
|
||||||
}
|
savingFrequencyOptions, savingsInterestTypeOptions, lockinPeriodTypeOptions, interestCalculationOptions, dueAmount);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean is(final String commandParam, final String commandValue) {
|
private boolean is(final String commandParam, final String commandValue) {
|
||||||
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
|
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam, final String jsonRequestBody) {
|
public Response savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam,
|
||||||
Response response = null;
|
final String jsonRequestBody) {
|
||||||
if (is(commandParam, "approve")) {
|
Response response = null;
|
||||||
SavingAccountApprovalCommand command = this.apiDataConversionService.convertJsonToSavingApprovalCommand(accountId, jsonRequestBody);
|
if (is(commandParam, "approve")) {
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.approveSavingAccount(command);
|
SavingAccountApprovalCommand command = this.apiDataConversionService.convertJsonToSavingApprovalCommand(accountId,
|
||||||
response = Response.ok().entity(identifier).build();
|
jsonRequestBody);
|
||||||
} else if (is(commandParam, "depositmoney")) {
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.approveSavingAccount(command);
|
||||||
SavingAccountDepositCommand command = this.apiDataConversionService.convertJsonToSavingAccountDepositCommand(accountId, jsonRequestBody);
|
response = Response.ok().entity(identifier).build();
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.depositMoney(command);
|
} else if (is(commandParam, "depositmoney")) {
|
||||||
response = Response.ok().entity(identifier).build();
|
SavingAccountDepositCommand command = this.apiDataConversionService.convertJsonToSavingAccountDepositCommand(accountId,
|
||||||
} else if (is(commandParam, "withdraw")) {
|
jsonRequestBody);
|
||||||
SavingAccountWithdrawalCommand command = this.apiDataConversionService.convertJsonToSavingAccountWithdrawalCommand(accountId, jsonRequestBody);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.depositMoney(command);
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingAmount(command);
|
response = Response.ok().entity(identifier).build();
|
||||||
response = Response.ok().entity(identifier).build();
|
} else if (is(commandParam, "withdraw")) {
|
||||||
} else {
|
SavingAccountWithdrawalCommand command = this.apiDataConversionService.convertJsonToSavingAccountWithdrawalCommand(accountId,
|
||||||
SavingStateTransitionsCommand command = this.apiDataConversionService.convertJsonToSavingStateTransitionCommand(accountId, jsonRequestBody);
|
jsonRequestBody);
|
||||||
if (is(commandParam, "reject")) {
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingAmount(command);
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.rejectSavingApplication(command);
|
response = Response.ok().entity(identifier).build();
|
||||||
response = Response.ok().entity(identifier).build();
|
} else {
|
||||||
} else if (is(commandParam, "withdrewbyclient")) {
|
SavingStateTransitionsCommand command = this.apiDataConversionService.convertJsonToSavingStateTransitionCommand(accountId,
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingApplication(command);
|
jsonRequestBody);
|
||||||
response = Response.ok().entity(identifier).build();
|
if (is(commandParam, "reject")) {
|
||||||
}
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.rejectSavingApplication(command);
|
||||||
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
|
response = Response.ok().entity(identifier).build();
|
||||||
if (is(commandParam, "undoapproval")) {
|
} else if (is(commandParam, "withdrewbyclient")) {
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.undoSavingAccountApproval(undoCommand);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingApplication(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
}
|
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
|
||||||
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
if (is(commandParam, "undoapproval")) {
|
||||||
return response;
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.undoSavingAccountApproval(undoCommand);
|
||||||
}
|
response = Response.ok().entity(identifier).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@@ -325,16 +327,15 @@ public class SavingsAccountApiResource {
|
|||||||
return Response.ok(new CommandProcessingResult(accountId)).build();
|
return Response.ok(new CommandProcessingResult(accountId)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("postinterest")
|
@Path("postinterest")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response postInterest() {
|
public Response postInterest() {
|
||||||
|
|
||||||
Collection<SavingAccountForLookup> savingAccounts = this.savingAccountReadPlatformService.retrieveSavingAccountsForLookUp();
|
Collection<SavingAccountForLookup> savingAccounts = this.savingAccountReadPlatformService.retrieveSavingAccountsForLookUp();
|
||||||
CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.postInterest(savingAccounts);
|
CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.postInterest(savingAccounts);
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return Response.ok().entity(entityIdentifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+49
-202
@@ -11,7 +11,7 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
|||||||
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductLookup;
|
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductLookup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable data object reprsenting a savings account.
|
* Immutable data object representing a savings account.
|
||||||
*/
|
*/
|
||||||
public class SavingAccountData {
|
public class SavingAccountData {
|
||||||
|
|
||||||
@@ -50,32 +50,24 @@ public class SavingAccountData {
|
|||||||
private final EnumOptionData lockinPeriodType;
|
private final EnumOptionData lockinPeriodType;
|
||||||
private final Integer depositEvery;
|
private final Integer depositEvery;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<SavingProductLookup> productOptions;
|
private final List<SavingProductLookup> productOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<CurrencyData> currencyOptions;
|
private final List<CurrencyData> currencyOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<EnumOptionData> savingsProductTypeOptions;
|
private final List<EnumOptionData> savingsProductTypeOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<EnumOptionData> tenureTypeOptions;
|
private final List<EnumOptionData> tenureTypeOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<EnumOptionData> savingFrequencyOptions;
|
private final List<EnumOptionData> savingFrequencyOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<EnumOptionData> savingsInterestTypeOptions;
|
private final List<EnumOptionData> savingsInterestTypeOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<EnumOptionData> lockinPeriodTypeOptions;
|
private final List<EnumOptionData> lockinPeriodTypeOptions;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private final List<EnumOptionData> interestCalculationOptions;
|
private final List<EnumOptionData> interestCalculationOptions;
|
||||||
|
|
||||||
private final Collection<SavingScheduleData> savingScheduleDatas;
|
private final Collection<SavingScheduleData> savingScheduleDatas;
|
||||||
private final SavingPermissionData permissions;
|
private final SavingPermissionData permissions;
|
||||||
private final BigDecimal outstandingAmount;
|
private final BigDecimal outstandingAmount;
|
||||||
private final BigDecimal dueAmount;
|
private final BigDecimal dueAmount;
|
||||||
private final SavingScheduleData savingScheduleData;
|
private final SavingScheduleData savingScheduleData;
|
||||||
private final Collection<SavingAccountTransactionsData> transactions;
|
private final Collection<SavingAccountTransactionsData> transactions;
|
||||||
|
|
||||||
private final Integer interestPostEvery;
|
private final Integer interestPostEvery;
|
||||||
private final EnumOptionData interestPostFrequency;
|
private final EnumOptionData interestPostFrequency;
|
||||||
|
|
||||||
public static SavingAccountData createFrom(final Long clientId, final String clientDisplayName) {
|
public static SavingAccountData createFrom(final Long clientId, final String clientDisplayName) {
|
||||||
return new SavingAccountData(clientId, clientDisplayName);
|
return new SavingAccountData(clientId, clientDisplayName);
|
||||||
@@ -89,7 +81,8 @@ public class SavingAccountData {
|
|||||||
BigDecimal projectedInterestAccuredOnMaturity, BigDecimal actualInterestAccured, BigDecimal projectedMaturityAmount,
|
BigDecimal projectedInterestAccuredOnMaturity, BigDecimal actualInterestAccured, BigDecimal projectedMaturityAmount,
|
||||||
BigDecimal actualMaturityAmount, boolean preClosureAllowed, BigDecimal preClosureInterestRate, LocalDate withdrawnonDate,
|
BigDecimal actualMaturityAmount, boolean preClosureAllowed, BigDecimal preClosureInterestRate, LocalDate withdrawnonDate,
|
||||||
LocalDate rejectedonDate, LocalDate closedonDate, boolean isLockinPeriodAllowed, Integer lockinPeriod,
|
LocalDate rejectedonDate, LocalDate closedonDate, boolean isLockinPeriodAllowed, Integer lockinPeriod,
|
||||||
EnumOptionData lockinPeriodType, Integer depositEvery, BigDecimal outstandingAmount, Integer interestPostEvery, EnumOptionData interestPostFrequency) {
|
EnumOptionData lockinPeriodType, Integer depositEvery, BigDecimal outstandingAmount, Integer interestPostEvery,
|
||||||
|
EnumOptionData interestPostFrequency) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.externalId = externalId;
|
this.externalId = externalId;
|
||||||
@@ -188,17 +181,17 @@ public class SavingAccountData {
|
|||||||
this.savingScheduleDatas = null;
|
this.savingScheduleDatas = null;
|
||||||
this.permissions = null;
|
this.permissions = null;
|
||||||
this.outstandingAmount = BigDecimal.ZERO;
|
this.outstandingAmount = BigDecimal.ZERO;
|
||||||
this.dueAmount =BigDecimal.ZERO;
|
this.dueAmount = BigDecimal.ZERO;
|
||||||
this.savingScheduleData = null;
|
this.savingScheduleData = null;
|
||||||
this.transactions = null;
|
this.transactions = null;
|
||||||
this.interestPostEvery =null;
|
this.interestPostEvery = null;
|
||||||
this.interestPostFrequency = null;
|
this.interestPostFrequency = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingAccountData(SavingAccountData account, Collection<SavingProductLookup> productOptions, List<CurrencyData> currencyOptions,
|
public SavingAccountData(SavingAccountData account, Collection<SavingProductLookup> productOptions, List<CurrencyData> currencyOptions,
|
||||||
List<EnumOptionData> savingsProductTypeOptions, List<EnumOptionData> tenureTypeOptions,
|
List<EnumOptionData> savingsProductTypeOptions, List<EnumOptionData> tenureTypeOptions,
|
||||||
List<EnumOptionData> savingFrequencyOptions, List<EnumOptionData> savingsInterestTypeOptions,
|
List<EnumOptionData> savingFrequencyOptions, List<EnumOptionData> savingsInterestTypeOptions,
|
||||||
List<EnumOptionData> lockinPeriodTypeOptions, List<EnumOptionData> interestCalculationOptions,BigDecimal dueAmount) {
|
List<EnumOptionData> lockinPeriodTypeOptions, List<EnumOptionData> interestCalculationOptions, BigDecimal dueAmount) {
|
||||||
this.id = account.id;
|
this.id = account.id;
|
||||||
this.status = account.status;
|
this.status = account.status;
|
||||||
this.externalId = account.externalId;
|
this.externalId = account.externalId;
|
||||||
@@ -259,7 +252,6 @@ public class SavingAccountData {
|
|||||||
Integer tenure, EnumOptionData savingsFrequencyType, EnumOptionData interestType, EnumOptionData interestCalculationMethod,
|
Integer tenure, EnumOptionData savingsFrequencyType, EnumOptionData interestType, EnumOptionData interestCalculationMethod,
|
||||||
BigDecimal minimumBalanceForWithdrawal, boolean partialDepositAllowed, boolean lockinPeriodAllowed, Integer lockinPeriod,
|
BigDecimal minimumBalanceForWithdrawal, boolean partialDepositAllowed, boolean lockinPeriodAllowed, Integer lockinPeriod,
|
||||||
EnumOptionData lockinPeriodType, Integer depositEvery) {
|
EnumOptionData lockinPeriodType, Integer depositEvery) {
|
||||||
|
|
||||||
this.id = null;
|
this.id = null;
|
||||||
this.status = null;
|
this.status = null;
|
||||||
this.externalId = null;
|
this.externalId = null;
|
||||||
@@ -308,12 +300,12 @@ public class SavingAccountData {
|
|||||||
this.dueAmount = BigDecimal.ZERO;
|
this.dueAmount = BigDecimal.ZERO;
|
||||||
this.savingScheduleData = null;
|
this.savingScheduleData = null;
|
||||||
this.transactions = null;
|
this.transactions = null;
|
||||||
this.interestPostEvery =3;
|
this.interestPostEvery = 3;
|
||||||
this.interestPostFrequency = savingsFrequencyType;
|
this.interestPostFrequency = savingsFrequencyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingAccountData(SavingAccountData account, SavingPermissionData permissions) {
|
public SavingAccountData(SavingAccountData account, SavingPermissionData permissions) {
|
||||||
this.id = account.id;
|
this.id = account.id;
|
||||||
this.status = account.status;
|
this.status = account.status;
|
||||||
this.externalId = account.externalId;
|
this.externalId = account.externalId;
|
||||||
this.clientId = account.clientId;
|
this.clientId = account.clientId;
|
||||||
@@ -364,10 +356,10 @@ public class SavingAccountData {
|
|||||||
this.transactions = account.transactions;
|
this.transactions = account.transactions;
|
||||||
this.interestPostEvery = account.interestPostEvery;
|
this.interestPostEvery = account.interestPostEvery;
|
||||||
this.interestPostFrequency = account.interestPostFrequency;
|
this.interestPostFrequency = account.interestPostFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingAccountData(SavingAccountData account, SavingScheduleData savingScheduleData) {
|
public SavingAccountData(SavingAccountData account, SavingScheduleData savingScheduleData) {
|
||||||
this.id = account.id;
|
this.id = account.id;
|
||||||
this.status = account.status;
|
this.status = account.status;
|
||||||
this.externalId = account.externalId;
|
this.externalId = account.externalId;
|
||||||
this.clientId = account.clientId;
|
this.clientId = account.clientId;
|
||||||
@@ -418,10 +410,10 @@ public class SavingAccountData {
|
|||||||
this.transactions = account.transactions;
|
this.transactions = account.transactions;
|
||||||
this.interestPostEvery = account.interestPostEvery;
|
this.interestPostEvery = account.interestPostEvery;
|
||||||
this.interestPostFrequency = account.interestPostFrequency;
|
this.interestPostFrequency = account.interestPostFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingAccountData(SavingAccountData account, Collection<SavingAccountTransactionsData> transactions) {
|
public SavingAccountData(SavingAccountData account, Collection<SavingAccountTransactionsData> transactions) {
|
||||||
this.id = account.id;
|
this.id = account.id;
|
||||||
this.status = account.status;
|
this.status = account.status;
|
||||||
this.externalId = account.externalId;
|
this.externalId = account.externalId;
|
||||||
this.clientId = account.clientId;
|
this.clientId = account.clientId;
|
||||||
@@ -472,186 +464,41 @@ public class SavingAccountData {
|
|||||||
this.transactions = transactions;
|
this.transactions = transactions;
|
||||||
this.interestPostEvery = account.interestPostEvery;
|
this.interestPostEvery = account.interestPostEvery;
|
||||||
this.interestPostFrequency = account.interestPostFrequency;
|
this.interestPostFrequency = account.interestPostFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public EnumOptionData getStatus() {
|
||||||
return this.id;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumOptionData getStatus() {
|
public CurrencyData getCurrencyData() {
|
||||||
return this.status;
|
return this.currencyData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExternalId() {
|
public BigDecimal getSavingsDepostiAmountPerPeriod() {
|
||||||
return this.externalId;
|
return this.savingsDepositAmountPerPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getClientId() {
|
public Integer getTenure() {
|
||||||
return this.clientId;
|
return this.tenure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientName() {
|
public EnumOptionData getTenureType() {
|
||||||
return this.clientName;
|
return this.tenureType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getProductId() {
|
public LocalDate getActualCommencementDate() {
|
||||||
return this.productId;
|
return this.actualCommencementDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProductName() {
|
public LocalDate getMaturesOnDate() {
|
||||||
return this.productName;
|
return this.maturesOnDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumOptionData getProductType() {
|
public Integer getDepositEvery() {
|
||||||
return this.productType;
|
return this.depositEvery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyData getCurrencyData() {
|
|
||||||
return this.currencyData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getSavingsDepostiAmountPerPeriod() {
|
|
||||||
return this.savingsDepositAmountPerPeriod;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData getSavingsFrequencyType() {
|
|
||||||
return this.savingsFrequencyType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getTotalDepositAmount() {
|
|
||||||
return this.totalDepositAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getReccuringInterestRate() {
|
|
||||||
return this.recurringInterestRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getSavingInterestRate() {
|
|
||||||
return this.savingInterestRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData getInterestType() {
|
|
||||||
return this.interestType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData getInterestCalculationMethod() {
|
|
||||||
return this.interestCalculationMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTenure() {
|
|
||||||
return this.tenure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData getTenureType() {
|
|
||||||
return this.tenureType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getProjectedCommencementDate() {
|
|
||||||
return this.projectedCommencementDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getActualCommencementDate() {
|
|
||||||
return this.actualCommencementDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getMaturesOnDate() {
|
|
||||||
return this.maturesOnDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getProjectedInterestAccuredOnMaturity() {
|
|
||||||
return this.projectedInterestAccuredOnMaturity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getActualInterestAccured() {
|
|
||||||
return this.actualInterestAccured;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getProjectedMaturityAmount() {
|
|
||||||
return this.projectedMaturityAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getActualMaturityAmount() {
|
|
||||||
return this.actualMaturityAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPreClosureAllowed() {
|
|
||||||
return this.preClosureAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getPreClosureInterestRate() {
|
|
||||||
return this.preClosureInterestRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getWithdrawnonDate() {
|
|
||||||
return this.withdrawnonDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getRejectedonDate() {
|
|
||||||
return this.rejectedonDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getClosedonDate() {
|
|
||||||
return this.closedonDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLockinPeriodAllowed() {
|
|
||||||
return this.isLockinPeriodAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getLockinPeriod() {
|
|
||||||
return this.lockinPeriod;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData getLockinPeriodType() {
|
|
||||||
return this.lockinPeriodType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getDepositEvery() {
|
|
||||||
return this.depositEvery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SavingProductLookup> getProductOptions() {
|
|
||||||
return this.productOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CurrencyData> getCurrencyOptions() {
|
|
||||||
return this.currencyOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EnumOptionData> getSavingsProductTypeOptions() {
|
|
||||||
return this.savingsProductTypeOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EnumOptionData> getTenureTypeOptions() {
|
|
||||||
return this.tenureTypeOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EnumOptionData> getSavingFrequencyOptions() {
|
|
||||||
return this.savingFrequencyOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EnumOptionData> getSavingsInterestTypeOptions() {
|
|
||||||
return this.savingsInterestTypeOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EnumOptionData> getLockinPeriodTypeOptions() {
|
|
||||||
return this.lockinPeriodTypeOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EnumOptionData> getInterestCalculationOptions() {
|
|
||||||
return this.interestCalculationOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getOutstandingAmount() {
|
|
||||||
return this.outstandingAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getInterestPostEvery() {
|
|
||||||
return this.interestPostEvery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnumOptionData getInterestPostFrequency() {
|
|
||||||
return this.interestPostFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public BigDecimal getOutstandingAmount() {
|
||||||
|
return this.outstandingAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+211
-202
@@ -43,7 +43,7 @@ import org.mifosplatform.portfolio.savingsdepositproduct.domain.TenureTypeEnum;
|
|||||||
import org.mifosplatform.useradministration.domain.AppUser;
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "m_saving_account", uniqueConstraints = @UniqueConstraint(name="saving_acc_external_id", columnNames = { "external_id" }))
|
@Table(name = "m_saving_account", uniqueConstraints = @UniqueConstraint(name = "saving_acc_external_id", columnNames = { "external_id" }))
|
||||||
public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@@ -60,14 +60,12 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
@Column(name = "external_id")
|
@Column(name = "external_id")
|
||||||
private String externalId;
|
private String externalId;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Embedded
|
@Embedded
|
||||||
private MonetaryCurrency currency;
|
private MonetaryCurrency currency;
|
||||||
|
|
||||||
@Column(name = "deposit_amount_per_period", scale = 6, precision = 19, nullable = false)
|
@Column(name = "deposit_amount_per_period", scale = 6, precision = 19, nullable = false)
|
||||||
private BigDecimal savingsDepositAmountPerPeriod;
|
private BigDecimal savingsDepositAmountPerPeriod;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Column(name = "total_deposit_amount", scale = 6, precision = 19, nullable = false)
|
@Column(name = "total_deposit_amount", scale = 6, precision = 19, nullable = false)
|
||||||
private BigDecimal totalSavingsAmount;
|
private BigDecimal totalSavingsAmount;
|
||||||
|
|
||||||
@@ -96,7 +94,6 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
@Column(name = "projected_commencement_date")
|
@Column(name = "projected_commencement_date")
|
||||||
private Date projectedCommencementDate;
|
private Date projectedCommencementDate;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
@Column(name = "actual_commencement_date")
|
@Column(name = "actual_commencement_date")
|
||||||
private Date actualCommencementDate;
|
private Date actualCommencementDate;
|
||||||
@@ -191,39 +188,42 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "savingAccount", orphanRemoval = true)
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "savingAccount", orphanRemoval = true)
|
||||||
private final List<SavingAccountTransaction> savingAccountTransactions = new ArrayList<SavingAccountTransaction>();
|
private final List<SavingAccountTransaction> savingAccountTransactions = new ArrayList<SavingAccountTransaction>();
|
||||||
|
|
||||||
public SavingAccount() {
|
protected SavingAccount() {
|
||||||
// TODO Auto-generated constructor stub
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SavingAccount openNew(Client client, SavingProduct product, String externalId, Money savingsDeposit,
|
public static SavingAccount openNew(Client client, SavingProduct product, String externalId, Money savingsDeposit,
|
||||||
BigDecimal reccuringInterestRate, BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate,
|
BigDecimal reccuringInterestRate, BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate,
|
||||||
TenureTypeEnum tenureTypeEnum, SavingProductType savingProductType, SavingFrequencyType savingFrequencyType,
|
TenureTypeEnum tenureTypeEnum, SavingProductType savingProductType, SavingFrequencyType savingFrequencyType,
|
||||||
SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod,
|
SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod,
|
||||||
boolean isLockinPeriodAllowed, Integer lockinPeriod, PeriodFrequencyType lockinPeriodType,
|
boolean isLockinPeriodAllowed, Integer lockinPeriod, PeriodFrequencyType lockinPeriodType,
|
||||||
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final DepositLifecycleStateMachine lifecycleStateMachine,
|
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,
|
||||||
Integer depositEvery, Integer interestPostEvery, Integer interestPostFrequency) {
|
final DepositLifecycleStateMachine lifecycleStateMachine, Integer depositEvery, Integer interestPostEvery,
|
||||||
|
Integer interestPostFrequency) {
|
||||||
|
|
||||||
Money futureValueOnMaturity = null;
|
Money futureValueOnMaturity = null;
|
||||||
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
|
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
|
||||||
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
|
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
|
||||||
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod,depositEvery);
|
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod,
|
||||||
|
depositEvery);
|
||||||
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
|
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
|
||||||
futureValueOnMaturity = savingsDeposit;
|
futureValueOnMaturity = savingsDeposit;
|
||||||
} else {
|
} else {
|
||||||
futureValueOnMaturity = savingsDeposit;
|
futureValueOnMaturity = savingsDeposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SavingAccount(client, externalId, product, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure,
|
return new SavingAccount(client, externalId, product, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure,
|
||||||
commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, interestType, savingInterestCalculationMethod,
|
commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, interestType, savingInterestCalculationMethod,
|
||||||
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, futureValueOnMaturity, lifecycleStateMachine,depositEvery,interestPostEvery, interestPostFrequency);
|
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, futureValueOnMaturity, lifecycleStateMachine, depositEvery,
|
||||||
|
interestPostEvery, interestPostFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingAccount(Client client, String externalId, SavingProduct product, Money savingsDeposit, BigDecimal reccuringInterestRate,
|
public SavingAccount(Client client, String externalId, SavingProduct product, Money savingsDeposit, BigDecimal reccuringInterestRate,
|
||||||
BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum,
|
BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum,
|
||||||
SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, SavingsInterestType interestType,
|
SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, SavingsInterestType interestType,
|
||||||
SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod,
|
SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod,
|
||||||
PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, final DepositLifecycleStateMachine lifecycleStateMachine,Integer payEvery,
|
PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, final DepositLifecycleStateMachine lifecycleStateMachine,
|
||||||
Integer interestPostEvery, Integer interestPostFrequency) {
|
Integer payEvery, Integer interestPostEvery, Integer interestPostFrequency) {
|
||||||
|
|
||||||
DepositAccountStatus from = null;
|
DepositAccountStatus from = null;
|
||||||
if (accountStatus != null) {
|
if (accountStatus != null) {
|
||||||
@@ -256,29 +256,35 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
this.lockinPeriod = lockinPeriod;
|
this.lockinPeriod = lockinPeriod;
|
||||||
this.lockinPeriodType = lockinPeriodType.getValue();
|
this.lockinPeriodType = lockinPeriodType.getValue();
|
||||||
this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount();
|
this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount();
|
||||||
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); //presently only for months
|
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(
|
||||||
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring : BigDecimal.ZERO;
|
BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); // presently
|
||||||
|
// only
|
||||||
|
// for
|
||||||
|
// months
|
||||||
|
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring
|
||||||
|
: BigDecimal.ZERO;
|
||||||
this.payEvery = payEvery;
|
this.payEvery = payEvery;
|
||||||
this.outstandingAmount = BigDecimal.ZERO;
|
this.outstandingAmount = BigDecimal.ZERO;
|
||||||
this.interestPostEvery = interestPostEvery;
|
this.interestPostEvery = interestPostEvery;
|
||||||
this.interestPostFrequency=interestPostFrequency;
|
this.interestPostFrequency = interestPostFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modifyAccount(SavingProduct product, String externalId, Money savingsDeposit, BigDecimal reccuringInterestRate,
|
public void modifyAccount(SavingProduct product, String externalId, Money savingsDeposit, BigDecimal reccuringInterestRate,
|
||||||
BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum,
|
BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum,
|
||||||
SavingProductType savingProductType, SavingFrequencyType savingFrequencyType,
|
SavingProductType savingProductType, SavingFrequencyType savingFrequencyType,
|
||||||
SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod,
|
SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod,
|
||||||
PeriodFrequencyType lockinPeriodType, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,Integer payEvery,
|
PeriodFrequencyType lockinPeriodType, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer payEvery,
|
||||||
SavingsInterestType interestType, Integer interestPostEvery, Integer interestPostFrequency) {
|
SavingsInterestType interestType, Integer interestPostEvery, Integer interestPostFrequency) {
|
||||||
|
|
||||||
Money futureValueOnMaturity = null;
|
Money futureValueOnMaturity = null;
|
||||||
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
|
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
|
||||||
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
|
futureValueOnMaturity = reccuringDepositInterestCalculator
|
||||||
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod,payEvery);
|
.calculateInterestOnMaturityFor(savingsDeposit, tenure, reccuringInterestRate, commencementDate, tenureTypeEnum,
|
||||||
|
savingFrequencyType, savingInterestCalculationMethod, payEvery);
|
||||||
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
|
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
|
||||||
futureValueOnMaturity = savingsDeposit;
|
futureValueOnMaturity = savingsDeposit;
|
||||||
} else {
|
} else {
|
||||||
futureValueOnMaturity = savingsDeposit;
|
futureValueOnMaturity = savingsDeposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.product = product;
|
this.product = product;
|
||||||
@@ -299,12 +305,17 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
this.payEvery = payEvery;
|
this.payEvery = payEvery;
|
||||||
this.outstandingAmount = BigDecimal.ZERO;
|
this.outstandingAmount = BigDecimal.ZERO;
|
||||||
this.interestPostEvery = interestPostEvery;
|
this.interestPostEvery = interestPostEvery;
|
||||||
this.interestPostFrequency=interestPostFrequency;
|
this.interestPostFrequency = interestPostFrequency;
|
||||||
this.savingScheduleInstallments.clear();
|
this.savingScheduleInstallments.clear();
|
||||||
|
|
||||||
this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount();
|
this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount();
|
||||||
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); //presently only for months
|
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(
|
||||||
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring : BigDecimal.ZERO;
|
BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); // presently
|
||||||
|
// only
|
||||||
|
// for
|
||||||
|
// months
|
||||||
|
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring
|
||||||
|
: BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDeleted() {
|
public boolean isDeleted() {
|
||||||
@@ -392,32 +403,31 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer getPayEvery() {
|
public Integer getPayEvery() {
|
||||||
return this.payEvery;
|
return this.payEvery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getOutstandingAmount() {
|
public BigDecimal getOutstandingAmount() {
|
||||||
return this.outstandingAmount;
|
return this.outstandingAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getInterestPostEvery() {
|
public Integer getInterestPostEvery() {
|
||||||
return this.interestPostEvery;
|
return this.interestPostEvery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getInterestPostFrequency() {
|
public Integer getInterestPostFrequency() {
|
||||||
return this.interestPostFrequency;
|
return this.interestPostFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SavingAccountTransaction> getSavingAccountTransactions() {
|
public List<SavingAccountTransaction> getSavingAccountTransactions() {
|
||||||
return this.savingAccountTransactions;
|
return this.savingAccountTransactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSavingScheduleInstallment(final SavingScheduleInstallments installment) {
|
public void addSavingScheduleInstallment(final SavingScheduleInstallments installment) {
|
||||||
installment.updateAccount(this);
|
installment.updateAccount(this);
|
||||||
this.savingScheduleInstallments.add(installment);
|
this.savingScheduleInstallments.add(installment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reject(LocalDate rejectedOn, DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
public void reject(LocalDate rejectedOn, DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
||||||
|
|
||||||
|
|
||||||
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED,
|
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED,
|
||||||
DepositAccountStatus.fromInt(this.accountStatus));
|
DepositAccountStatus.fromInt(this.accountStatus));
|
||||||
@@ -432,7 +442,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
final String errorMessage = "The date on which a saving account is rejected cannot be before its submittal date: "
|
final String errorMessage = "The date on which a saving account is rejected cannot be before its submittal date: "
|
||||||
+ projectedCommencementDate().toString();
|
+ projectedCommencementDate().toString();
|
||||||
throw new InvalidDepositStateTransitionException("reject", "cannot.be.before.submittal.date", errorMessage, rejectedOn,
|
throw new InvalidDepositStateTransitionException("reject", "cannot.be.before.submittal.date", errorMessage, rejectedOn,
|
||||||
projectedCommencementDate());
|
projectedCommencementDate());
|
||||||
|
|
||||||
}
|
}
|
||||||
if (rejectedOn.isAfter(new LocalDate())) {
|
if (rejectedOn.isAfter(new LocalDate())) {
|
||||||
@@ -442,10 +452,9 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public LocalDate projectedCommencementDate() {
|
||||||
|
|
||||||
public LocalDate projectedCommencementDate() {
|
|
||||||
LocalDate date = null;
|
LocalDate date = null;
|
||||||
if (this.projectedCommencementDate != null) {
|
if (this.projectedCommencementDate != null) {
|
||||||
date = new LocalDate(this.projectedCommencementDate);
|
date = new LocalDate(this.projectedCommencementDate);
|
||||||
@@ -453,9 +462,9 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withdrawnByApplicant(LocalDate withdrawnOn, DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
public void withdrawnByApplicant(LocalDate withdrawnOn, DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
||||||
|
|
||||||
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_WITHDRAWN,
|
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_WITHDRAWN,
|
||||||
DepositAccountStatus.fromInt(this.accountStatus));
|
DepositAccountStatus.fromInt(this.accountStatus));
|
||||||
this.accountStatus = statusEnum.getValue();
|
this.accountStatus = statusEnum.getValue();
|
||||||
|
|
||||||
@@ -468,8 +477,8 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
|
|
||||||
final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: "
|
final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: "
|
||||||
+ projectedCommencementDate().toString();
|
+ projectedCommencementDate().toString();
|
||||||
throw new InvalidDepositStateTransitionException("withdrawnbyclient", "cannot.be.before.submittal.date", errorMessage, withdrawnOn,
|
throw new InvalidDepositStateTransitionException("withdrawnbyclient", "cannot.be.before.submittal.date", errorMessage,
|
||||||
projectedCommencementDate());
|
withdrawnOn, projectedCommencementDate());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,22 +486,22 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
final String errorMessage = "The date on which a deposit is rejected cannot be in the future.";
|
final String errorMessage = "The date on which a deposit is rejected cannot be in the future.";
|
||||||
throw new InvalidDepositStateTransitionException("withdrawnbyclient", "cannot.be.a.future.date", errorMessage, withdrawnOn);
|
throw new InvalidDepositStateTransitionException("withdrawnbyclient", "cannot.be.a.future.date", errorMessage, withdrawnOn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undoSavingAccountApproval(DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
public void undoSavingAccountApproval(DepositLifecycleStateMachine depositLifecycleStateMachine) {
|
||||||
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVAL_UNDO,
|
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVAL_UNDO,
|
||||||
DepositAccountStatus.fromInt(this.accountStatus));
|
DepositAccountStatus.fromInt(this.accountStatus));
|
||||||
this.accountStatus = statusEnum.getValue();
|
this.accountStatus = statusEnum.getValue();
|
||||||
this.savingScheduleInstallments.clear();
|
this.savingScheduleInstallments.clear();
|
||||||
this.closedOnDate = new Date();
|
this.closedOnDate = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void approveSavingAccount(LocalDate approvalDate, BigDecimal savingsDepositAmountPerPeriod, BigDecimal recurringInterestRate,
|
public void approveSavingAccount(LocalDate approvalDate, BigDecimal savingsDepositAmountPerPeriod, BigDecimal recurringInterestRate,
|
||||||
BigDecimal savingInterestRate, Integer interestType, Integer tenure, Integer tenureType, Integer frequency, Integer payEvery,
|
BigDecimal savingInterestRate, Integer interestType, Integer tenure, Integer tenureType, Integer frequency, Integer payEvery,
|
||||||
DepositLifecycleStateMachine depositLifecycleStateMachine, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,
|
DepositLifecycleStateMachine depositLifecycleStateMachine,
|
||||||
Integer interestPostEvery, Integer interestPostFrequency) {
|
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer interestPostEvery, Integer interestPostFrequency) {
|
||||||
|
|
||||||
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED,
|
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED,
|
||||||
DepositAccountStatus.fromInt(this.accountStatus));
|
DepositAccountStatus.fromInt(this.accountStatus));
|
||||||
this.accountStatus = statusEnum.getValue();
|
this.accountStatus = statusEnum.getValue();
|
||||||
|
|
||||||
@@ -504,106 +513,114 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
Money futureValueOnMaturity = null;
|
Money futureValueOnMaturity = null;
|
||||||
if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod()) {
|
if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod()) {
|
||||||
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsAmountPerPeriod, tenure,
|
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsAmountPerPeriod, tenure,
|
||||||
recurringInterestRate, approvalDate, tenureTypeEnum, savingFrequencyType, interestCalculationMethod,payEvery);
|
recurringInterestRate, approvalDate, tenureTypeEnum, savingFrequencyType, interestCalculationMethod, payEvery);
|
||||||
} else if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isPerpetual()) {
|
} else if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isPerpetual()) {
|
||||||
futureValueOnMaturity = savingsAmountPerPeriod;
|
futureValueOnMaturity = savingsAmountPerPeriod;
|
||||||
} else {
|
} else {
|
||||||
futureValueOnMaturity = savingsAmountPerPeriod;
|
futureValueOnMaturity = savingsAmountPerPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.actualCommencementDate = approvalDate.toDate();
|
this.actualCommencementDate = approvalDate.toDate();
|
||||||
this.savingsDepositAmountPerPeriod = savingsDepositAmountPerPeriod;
|
this.savingsDepositAmountPerPeriod = savingsDepositAmountPerPeriod;
|
||||||
this.reccuringInterestRate = recurringInterestRate;
|
this.reccuringInterestRate = recurringInterestRate;
|
||||||
this.savingInterestRate = savingInterestRate;
|
this.savingInterestRate = savingInterestRate;
|
||||||
this.interestType = interestType;
|
this.interestType = interestType;
|
||||||
this.tenure = tenure;
|
this.tenure = tenure;
|
||||||
this.tenureType = tenureType;
|
this.tenureType = tenureType;
|
||||||
this.frequency = frequency;
|
this.frequency = frequency;
|
||||||
this.payEvery = payEvery;
|
this.payEvery = payEvery;
|
||||||
this.savingScheduleInstallments.clear();
|
this.savingScheduleInstallments.clear();
|
||||||
this.total=futureValueOnMaturity.getAmount();
|
this.total = futureValueOnMaturity.getAmount();
|
||||||
BigDecimal interestForReccuring = futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDepositAmountPerPeriod.doubleValue() * tenure.doubleValue()/payEvery.doubleValue())); //presently only for months
|
BigDecimal interestForReccuring = futureValueOnMaturity.getAmount().subtract(
|
||||||
this.interestAccrued = SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod() ? interestForReccuring : BigDecimal.ZERO;
|
BigDecimal.valueOf(savingsDepositAmountPerPeriod.doubleValue() * tenure.doubleValue() / payEvery.doubleValue())); // presently
|
||||||
this.interestPostEvery = interestPostEvery;
|
// only
|
||||||
this.interestPostFrequency = interestPostFrequency;
|
// for
|
||||||
|
// months
|
||||||
|
this.interestAccrued = SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod() ? interestForReccuring
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
this.interestPostEvery = interestPostEvery;
|
||||||
|
this.interestPostFrequency = interestPostFrequency;
|
||||||
|
|
||||||
// for interest posting initializing
|
// for interest posting initializing
|
||||||
this.lastInterestPostedDate = this.actualCommencementDate;
|
this.lastInterestPostedDate = this.actualCommencementDate;
|
||||||
this.nextInterestPostingDate = new LocalDate(this.lastInterestPostedDate).plusMonths(this.interestPostEvery).toDate();
|
this.nextInterestPostingDate = new LocalDate(this.lastInterestPostedDate).plusMonths(this.interestPostEvery).toDate();
|
||||||
this.interestPostedAmount = BigDecimal.ZERO;
|
this.interestPostedAmount = BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void depositMoney(SavingAccountDepositCommand command) {
|
public void depositMoney(SavingAccountDepositCommand command) {
|
||||||
|
|
||||||
BigDecimal depositAmount = BigDecimal.ZERO;
|
BigDecimal depositAmount = BigDecimal.ZERO;
|
||||||
BigDecimal remainAmountToBePaid = BigDecimal.ZERO;
|
BigDecimal remainAmountToBePaid = BigDecimal.ZERO;
|
||||||
BigDecimal commandRemainDepositAmount = command.getSavingsDepostiAmountPerPeriod();
|
BigDecimal commandRemainDepositAmount = command.getSavingsDepostiAmountPerPeriod();
|
||||||
|
|
||||||
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.deposit(command.getSavingsDepostiAmountPerPeriod(),command.getDepositDate());
|
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.deposit(command.getSavingsDepostiAmountPerPeriod(),
|
||||||
savingAccountTransaction.updateAccount(this);
|
command.getDepositDate());
|
||||||
this.savingAccountTransactions.add(savingAccountTransaction);
|
savingAccountTransaction.updateAccount(this);
|
||||||
this.outstandingAmount = this.outstandingAmount.add(command.getSavingsDepostiAmountPerPeriod());
|
this.savingAccountTransactions.add(savingAccountTransaction);
|
||||||
this.totalSavingsAmount = this.totalSavingsAmount.add(command.getSavingsDepostiAmountPerPeriod());
|
this.outstandingAmount = this.outstandingAmount.add(command.getSavingsDepostiAmountPerPeriod());
|
||||||
|
this.totalSavingsAmount = this.totalSavingsAmount.add(command.getSavingsDepostiAmountPerPeriod());
|
||||||
|
|
||||||
if(SavingProductType.fromInt(this.savingProductType).isReccuring() && TenureTypeEnum.fromInt(tenureType).isFixedPeriod()) {
|
if (SavingProductType.fromInt(this.savingProductType).isReccuring() && TenureTypeEnum.fromInt(tenureType).isFixedPeriod()) {
|
||||||
for(SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments){
|
for (SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments) {
|
||||||
if(!savingScheduleInstallment.isCompleted()){
|
if (!savingScheduleInstallment.isCompleted()) {
|
||||||
depositAmount = savingScheduleInstallment.getDeposit();
|
depositAmount = savingScheduleInstallment.getDeposit();
|
||||||
remainAmountToBePaid = depositAmount.subtract(savingScheduleInstallment.getDepositPaid());
|
remainAmountToBePaid = depositAmount.subtract(savingScheduleInstallment.getDepositPaid());
|
||||||
if (remainAmountToBePaid.doubleValue() > 0) {
|
if (remainAmountToBePaid.doubleValue() > 0) {
|
||||||
if (commandRemainDepositAmount.doubleValue() > 0) {
|
if (commandRemainDepositAmount.doubleValue() > 0) {
|
||||||
if (commandRemainDepositAmount.doubleValue() >= remainAmountToBePaid.doubleValue()) {
|
if (commandRemainDepositAmount.doubleValue() >= remainAmountToBePaid.doubleValue()) {
|
||||||
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment.getDepositPaid()));
|
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment
|
||||||
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
|
.getDepositPaid()));
|
||||||
savingScheduleInstallment.setCompleted(true);
|
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
|
||||||
commandRemainDepositAmount = commandRemainDepositAmount.subtract(remainAmountToBePaid);
|
savingScheduleInstallment.setCompleted(true);
|
||||||
} else if(commandRemainDepositAmount.doubleValue() < remainAmountToBePaid.doubleValue()){
|
commandRemainDepositAmount = commandRemainDepositAmount.subtract(remainAmountToBePaid);
|
||||||
savingScheduleInstallment.setDepositPaid(commandRemainDepositAmount.add(savingScheduleInstallment.getDepositPaid()));
|
} else if (commandRemainDepositAmount.doubleValue() < remainAmountToBePaid.doubleValue()) {
|
||||||
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
|
savingScheduleInstallment.setDepositPaid(commandRemainDepositAmount.add(savingScheduleInstallment
|
||||||
commandRemainDepositAmount = BigDecimal.ZERO;
|
.getDepositPaid()));
|
||||||
}
|
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
|
||||||
}
|
commandRemainDepositAmount = BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
for(SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments){
|
}
|
||||||
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment.getDepositPaid()));
|
} else {
|
||||||
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
|
for (SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments) {
|
||||||
}
|
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment.getDepositPaid()));
|
||||||
}
|
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return DepositAccountStatus.fromInt(this.accountStatus).isActive();
|
return DepositAccountStatus.fromInt(this.accountStatus).isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withdrawAmount(BigDecimal amount, LocalDate transactionDate) {
|
public void withdrawAmount(BigDecimal amount, LocalDate transactionDate) {
|
||||||
this.outstandingAmount = this.outstandingAmount.subtract(amount);
|
this.outstandingAmount = this.outstandingAmount.subtract(amount);
|
||||||
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount,transactionDate);
|
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount, transactionDate);
|
||||||
savingAccountTransaction.updateAccount(this);
|
savingAccountTransaction.updateAccount(this);
|
||||||
this.savingAccountTransactions.add(savingAccountTransaction);
|
this.savingAccountTransactions.add(savingAccountTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
|
||||||
* Delete is a <i>soft delete</i>. Updates flag on account so it wont appear
|
* Delete is a <i>soft delete</i>. Updates flag on account so it wont appear
|
||||||
* in query/report results.
|
* in query/report results.
|
||||||
*
|
*
|
||||||
* Any fields with unique constraints and prepended with id of record.
|
* Any fields with unique constraints and prepended with id of record.
|
||||||
*/
|
*/
|
||||||
public void delete() {
|
public void delete() {
|
||||||
this.deleted = true;
|
this.deleted = true;
|
||||||
this.externalId = this.getId() + "_" + this.externalId;
|
this.externalId = this.getId() + "_" + this.externalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postInterest() {
|
public void postInterest() {
|
||||||
|
|
||||||
LocalDate lastInterestPostedDate = getLastInterestPostedDate();
|
LocalDate lastInterestPostedDate = getLastInterestPostedDate();
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
LocalDate nextInterestPostingDate = getNextInterestPostedDate();
|
LocalDate nextInterestPostingDate = getNextInterestPostedDate();
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(this.interestCalculationMethod);
|
SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod
|
||||||
|
.fromInt(this.interestCalculationMethod);
|
||||||
|
|
||||||
Integer monthsForInterestCalculation = Months.monthsBetween(lastInterestPostedDate, new LocalDate()).getMonths();
|
Integer monthsForInterestCalculation = Months.monthsBetween(lastInterestPostedDate, new LocalDate()).getMonths();
|
||||||
Integer postInterestItereations = monthsForInterestCalculation / this.interestPostEvery;
|
Integer postInterestItereations = monthsForInterestCalculation / this.interestPostEvery;
|
||||||
@@ -612,73 +629,75 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
final Integer monthsInYear = 12;
|
final Integer monthsInYear = 12;
|
||||||
|
|
||||||
BigDecimal totalDepositedAmount = BigDecimal.ZERO;
|
BigDecimal totalDepositedAmount = BigDecimal.ZERO;
|
||||||
BigDecimal totalWithdrawableAmount = BigDecimal.ZERO;
|
BigDecimal totalWithdrawableAmount = BigDecimal.ZERO;
|
||||||
BigDecimal totalOutstandingAmount = BigDecimal.ZERO;
|
BigDecimal totalOutstandingAmount = BigDecimal.ZERO;
|
||||||
boolean isOutstandingAmountCalculated = false;
|
boolean isOutstandingAmountCalculated = false;
|
||||||
|
|
||||||
while (postInterestItereations > 0 ) {
|
while (postInterestItereations > 0) {
|
||||||
lastInterestPostedDate = getLastInterestPostedDate();
|
lastInterestPostedDate = getLastInterestPostedDate();
|
||||||
nextInterestPostingDate = getNextInterestPostedDate();
|
nextInterestPostingDate = getNextInterestPostedDate();
|
||||||
LocalDate transactionStartDate = lastInterestPostedDate;
|
LocalDate transactionStartDate = lastInterestPostedDate;
|
||||||
|
|
||||||
BigDecimal termTotalAmount = BigDecimal.ZERO;
|
BigDecimal termTotalAmount = BigDecimal.ZERO;
|
||||||
BigDecimal averageBalanceForTerm = BigDecimal.ZERO;
|
BigDecimal averageBalanceForTerm = BigDecimal.ZERO;
|
||||||
|
|
||||||
for (int i=0; i< interestPostEvery; i++){
|
for (int i = 0; i < interestPostEvery; i++) {
|
||||||
//default for months here
|
// default for months here
|
||||||
LocalDate transactionEndDate = transactionStartDate.plusMonths(1);
|
LocalDate transactionEndDate = transactionStartDate.plusMonths(1);
|
||||||
BigDecimal depositedAmount = BigDecimal.ZERO;
|
BigDecimal depositedAmount = BigDecimal.ZERO;
|
||||||
BigDecimal withdrawableAmount = BigDecimal.ZERO;
|
BigDecimal withdrawableAmount = BigDecimal.ZERO;
|
||||||
BigDecimal outstandingAmount = BigDecimal.ZERO;
|
BigDecimal outstandingAmount = BigDecimal.ZERO;
|
||||||
|
|
||||||
for(SavingAccountTransaction savingAccountTransaction : this.savingAccountTransactions){
|
for (SavingAccountTransaction savingAccountTransaction : this.savingAccountTransactions) {
|
||||||
LocalDate actualTransactionDate = savingAccountTransaction.getTransactionDate();
|
LocalDate actualTransactionDate = savingAccountTransaction.getTransactionDate();
|
||||||
if (actualTransactionDate != null && (actualTransactionDate.isAfter(transactionStartDate) || actualTransactionDate.isEqual(transactionStartDate))) {
|
if (actualTransactionDate != null
|
||||||
if (actualTransactionDate.isBefore(transactionEndDate)) {
|
&& (actualTransactionDate.isAfter(transactionStartDate) || actualTransactionDate.isEqual(transactionStartDate))) {
|
||||||
if(savingAccountTransaction.getTypeOf().isDeposit()){
|
if (actualTransactionDate.isBefore(transactionEndDate)) {
|
||||||
depositedAmount = depositedAmount.add(savingAccountTransaction.getAmount());
|
if (savingAccountTransaction.getTypeOf().isDeposit()) {
|
||||||
} else if (savingAccountTransaction.getTypeOf().isWithdraw()) {
|
depositedAmount = depositedAmount.add(savingAccountTransaction.getAmount());
|
||||||
withdrawableAmount = withdrawableAmount.add(savingAccountTransaction.getAmount());
|
} else if (savingAccountTransaction.getTypeOf().isWithdraw()) {
|
||||||
}
|
withdrawableAmount = withdrawableAmount.add(savingAccountTransaction.getAmount());
|
||||||
}
|
}
|
||||||
} else if (actualTransactionDate != null && (actualTransactionDate.isBefore(transactionStartDate))) {
|
}
|
||||||
if(!isOutstandingAmountCalculated){
|
} else if (actualTransactionDate != null && (actualTransactionDate.isBefore(transactionStartDate))) {
|
||||||
if(savingAccountTransaction.getTypeOf().isDeposit()){
|
if (!isOutstandingAmountCalculated) {
|
||||||
depositedAmount = depositedAmount.add(savingAccountTransaction.getAmount());
|
if (savingAccountTransaction.getTypeOf().isDeposit()) {
|
||||||
} else if (savingAccountTransaction.getTypeOf().isWithdraw()) {
|
depositedAmount = depositedAmount.add(savingAccountTransaction.getAmount());
|
||||||
withdrawableAmount = withdrawableAmount.add(savingAccountTransaction.getAmount());
|
} else if (savingAccountTransaction.getTypeOf().isWithdraw()) {
|
||||||
}
|
withdrawableAmount = withdrawableAmount.add(savingAccountTransaction.getAmount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outstandingAmount = depositedAmount.subtract(withdrawableAmount);
|
}
|
||||||
totalDepositedAmount = totalDepositedAmount.add(depositedAmount);
|
outstandingAmount = depositedAmount.subtract(withdrawableAmount);
|
||||||
totalWithdrawableAmount = totalWithdrawableAmount.add(withdrawableAmount);
|
totalDepositedAmount = totalDepositedAmount.add(depositedAmount);
|
||||||
totalOutstandingAmount = totalOutstandingAmount.add(outstandingAmount);
|
totalWithdrawableAmount = totalWithdrawableAmount.add(withdrawableAmount);
|
||||||
termTotalAmount = termTotalAmount.add(totalOutstandingAmount);
|
totalOutstandingAmount = totalOutstandingAmount.add(outstandingAmount);
|
||||||
transactionStartDate = transactionEndDate;
|
termTotalAmount = termTotalAmount.add(totalOutstandingAmount);
|
||||||
isOutstandingAmountCalculated = true;
|
transactionStartDate = transactionEndDate;
|
||||||
|
isOutstandingAmountCalculated = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
// TODO- calculate interest on calculation method
|
// TODO- calculate interest on calculation method
|
||||||
|
|
||||||
// if (savingInterestCalculationMethod.isAverageBalance()) {
|
// if (savingInterestCalculationMethod.isAverageBalance()) {
|
||||||
averageBalanceForTerm =BigDecimal.valueOf(termTotalAmount.doubleValue()/this.interestPostEvery);
|
averageBalanceForTerm = BigDecimal.valueOf(termTotalAmount.doubleValue() / this.interestPostEvery);
|
||||||
BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue()/monthsInYear.doubleValue()*this.interestPostEvery.doubleValue());
|
BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue() / monthsInYear.doubleValue()
|
||||||
BigDecimal interestPerTerm = averageBalanceForTerm.multiply(interestRatePerTerm);
|
* this.interestPostEvery.doubleValue());
|
||||||
this.interestPostedAmount = this.interestPostedAmount.add(interestPerTerm);
|
BigDecimal interestPerTerm = averageBalanceForTerm.multiply(interestRatePerTerm);
|
||||||
totalOutstandingAmount = totalOutstandingAmount.add(interestPerTerm);
|
this.interestPostedAmount = this.interestPostedAmount.add(interestPerTerm);
|
||||||
// } else if(savingInterestCalculationMethod.isMonthlyCollection()){
|
totalOutstandingAmount = totalOutstandingAmount.add(interestPerTerm);
|
||||||
|
// } else if(savingInterestCalculationMethod.isMonthlyCollection()){
|
||||||
|
|
||||||
//}
|
// }
|
||||||
this.outstandingAmount = this.outstandingAmount . add(interestPerTerm);
|
this.outstandingAmount = this.outstandingAmount.add(interestPerTerm);
|
||||||
this.lastInterestPostedDate = getNextInterestPostedDate().toDate();
|
this.lastInterestPostedDate = getNextInterestPostedDate().toDate();
|
||||||
this.nextInterestPostingDate = getNextInterestPostedDate().plusMonths(this.interestPostEvery).toDate();
|
this.nextInterestPostingDate = getNextInterestPostedDate().plusMonths(this.interestPostEvery).toDate();
|
||||||
postInterestItereations--;
|
postInterestItereations--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final LocalDate getLastInterestPostedDate() {
|
private final LocalDate getLastInterestPostedDate() {
|
||||||
LocalDate lastInterestPostedDate;
|
LocalDate lastInterestPostedDate;
|
||||||
if (this.lastInterestPostedDate == null) {
|
if (this.lastInterestPostedDate == null) {
|
||||||
lastInterestPostedDate = new LocalDate(this.actualCommencementDate);
|
lastInterestPostedDate = new LocalDate(this.actualCommencementDate);
|
||||||
@@ -697,14 +716,4 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
}
|
}
|
||||||
return nextInterestPostingDate;
|
return nextInterestPostingDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final LocalDate getMaturityDate(){
|
|
||||||
LocalDate commencementDate;
|
|
||||||
if (this.actualCommencementDate == null) {
|
|
||||||
commencementDate = new LocalDate(this.projectedCommencementDate).plusMonths(this.tenure);
|
|
||||||
} else {
|
|
||||||
commencementDate = new LocalDate(this.actualCommencementDate).plusMonths(this.tenure);
|
|
||||||
}
|
|
||||||
return commencementDate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+30
-36
@@ -23,7 +23,6 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
|
|||||||
@JoinColumn(name = "saving_account_id", nullable = false)
|
@JoinColumn(name = "saving_account_id", nullable = false)
|
||||||
private SavingAccount savingAccount;
|
private SavingAccount savingAccount;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
@Column(name = "duedate", nullable = false)
|
@Column(name = "duedate", nullable = false)
|
||||||
private final Date dueDate;
|
private final Date dueDate;
|
||||||
@@ -32,16 +31,13 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
|
|||||||
@Column(name = "installment", nullable = false)
|
@Column(name = "installment", nullable = false)
|
||||||
private final Integer installmentNumber;
|
private final Integer installmentNumber;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Column(name = "deposit", scale = 6, precision = 19, nullable = false)
|
@Column(name = "deposit", scale = 6, precision = 19, nullable = false)
|
||||||
private BigDecimal deposit;
|
private BigDecimal deposit;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
@Column(name = "payment_date", nullable = true)
|
@Column(name = "payment_date", nullable = true)
|
||||||
private Date paymentDate;
|
private Date paymentDate;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Column(name = "deposit_paid", scale = 6, precision = 19, nullable = true)
|
@Column(name = "deposit_paid", scale = 6, precision = 19, nullable = true)
|
||||||
private BigDecimal depositPaid;
|
private BigDecimal depositPaid;
|
||||||
|
|
||||||
@@ -49,17 +45,17 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
|
|||||||
@Column(name = "interest_accured", scale = 6, precision = 19, nullable = true)
|
@Column(name = "interest_accured", scale = 6, precision = 19, nullable = true)
|
||||||
private BigDecimal interstAccured;
|
private BigDecimal interstAccured;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Column(name = "completed_derived", nullable = false)
|
@Column(name = "completed_derived", nullable = false)
|
||||||
private boolean completed;
|
private boolean completed;
|
||||||
|
|
||||||
public SavingScheduleInstallments() {
|
public SavingScheduleInstallments() {
|
||||||
this.dueDate = null;
|
this.dueDate = null;
|
||||||
this.installmentNumber = null;
|
this.installmentNumber = null;
|
||||||
this.paymentDate = null;
|
this.paymentDate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingScheduleInstallments(SavingAccount account, Date dueDate, Integer installmentNumber, BigDecimal deposit, BigDecimal interstAccured) {
|
public SavingScheduleInstallments(SavingAccount account, Date dueDate, Integer installmentNumber, BigDecimal deposit,
|
||||||
|
BigDecimal interstAccured) {
|
||||||
this.savingAccount = account;
|
this.savingAccount = account;
|
||||||
this.dueDate = dueDate;
|
this.dueDate = dueDate;
|
||||||
this.installmentNumber = installmentNumber;
|
this.installmentNumber = installmentNumber;
|
||||||
@@ -74,37 +70,35 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
|
|||||||
this.savingAccount = account;
|
this.savingAccount = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getPaymentDate() {
|
public Date getPaymentDate() {
|
||||||
return this.paymentDate;
|
return this.paymentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPaymentDate(Date paymentDate) {
|
public void setPaymentDate(Date paymentDate) {
|
||||||
this.paymentDate = paymentDate;
|
this.paymentDate = paymentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getDepositPaid() {
|
public BigDecimal getDepositPaid() {
|
||||||
return this.depositPaid;
|
return this.depositPaid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDepositPaid(BigDecimal depositPaid) {
|
public void setDepositPaid(BigDecimal depositPaid) {
|
||||||
this.depositPaid = depositPaid;
|
this.depositPaid = depositPaid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDueDate() {
|
public Date getDueDate() {
|
||||||
return this.dueDate;
|
return this.dueDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getDeposit() {
|
public BigDecimal getDeposit() {
|
||||||
return this.deposit;
|
return this.deposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
return this.completed;
|
return this.completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCompleted(boolean completed) {
|
|
||||||
this.completed = completed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public void setCompleted(boolean completed) {
|
||||||
|
this.completed = completed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+145
-141
@@ -43,11 +43,11 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SavingAccountReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
public SavingAccountReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||||
ClientReadPlatformService clientReadPlatformService, SavingProductReadPlatformService savingProductReadPlatformService) {
|
ClientReadPlatformService clientReadPlatformService, SavingProductReadPlatformService savingProductReadPlatformService) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
this.clientReadPlatformService = clientReadPlatformService;
|
this.clientReadPlatformService = clientReadPlatformService;
|
||||||
this.savingProductReadPlatformService=savingProductReadPlatformService;
|
this.savingProductReadPlatformService = savingProductReadPlatformService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -155,179 +155,183 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
|
|||||||
Integer depositEvery = JdbcSupport.getInteger(rs, "depositEvery");
|
Integer depositEvery = JdbcSupport.getInteger(rs, "depositEvery");
|
||||||
|
|
||||||
Integer interestPostEvery = JdbcSupport.getInteger(rs, "interestPostEvery");
|
Integer interestPostEvery = JdbcSupport.getInteger(rs, "interestPostEvery");
|
||||||
EnumOptionData interestPostFrequency = SavingProductEnumerations.interestFrequencyType(JdbcSupport.getInteger(rs, "interestPostFrequency"));
|
EnumOptionData interestPostFrequency = SavingProductEnumerations.interestFrequencyType(JdbcSupport.getInteger(rs,
|
||||||
|
"interestPostFrequency"));
|
||||||
|
|
||||||
return new SavingAccountData(id, status, externalId, clientId, clientName, productId, productName, productType, currencyData,
|
return new SavingAccountData(id, status, externalId, clientId, clientName, productId, productName, productType, currencyData,
|
||||||
savingsDepostiAmountPerPeriod, savingsFrequencyType, totalDepositAmount, reccuringInterestRate, savingInterestRate,
|
savingsDepostiAmountPerPeriod, savingsFrequencyType, totalDepositAmount, reccuringInterestRate, savingInterestRate,
|
||||||
interestType, interestCalculationMethod, tenure, tenureType, projectedCommencementDate, actualCommencementDate,
|
interestType, interestCalculationMethod, tenure, tenureType, projectedCommencementDate, actualCommencementDate,
|
||||||
maturesOnDate, projectedInterestAccuredOnMaturity, actualInterestAccured, projectedMaturityAmount,
|
maturesOnDate, projectedInterestAccuredOnMaturity, actualInterestAccured, projectedMaturityAmount,
|
||||||
actualMaturityAmount, preClosureAllowed, preClosureInterestRate, withdrawnonDate, rejectedonDate, closedonDate,
|
actualMaturityAmount, preClosureAllowed, preClosureInterestRate, withdrawnonDate, rejectedonDate, closedonDate,
|
||||||
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType,depositEvery,outstandingAmount, interestPostEvery, interestPostFrequency);
|
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, depositEvery, outstandingAmount, interestPostEvery,
|
||||||
|
interestPostFrequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SavingAccountData retrieveNewSavingsAccountDetails(Long clientId, Long productId) {
|
public SavingAccountData retrieveNewSavingsAccountDetails(Long clientId, Long productId) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
|
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
|
||||||
SavingAccountData accountData = null;
|
SavingAccountData accountData = null;
|
||||||
Collection<SavingProductLookup> savingProducts = this.savingProductReadPlatformService.retrieveAllSavingProductsForLookup();
|
Collection<SavingProductLookup> savingProducts = this.savingProductReadPlatformService.retrieveAllSavingProductsForLookup();
|
||||||
|
|
||||||
if (productId != null && productId != -1) {
|
if (productId != null && productId != -1) {
|
||||||
SavingProductData selectedProduct = findSavingProductById(savingProducts, productId);
|
SavingProductData selectedProduct = findSavingProductById(savingProducts, productId);
|
||||||
|
|
||||||
CurrencyData currency = selectedProduct.getCurrency();
|
CurrencyData currency = selectedProduct.getCurrency();
|
||||||
|
|
||||||
accountData = new SavingAccountData(clientAccount.id(), clientAccount.displayName(), selectedProduct.getId(),
|
accountData = new SavingAccountData(clientAccount.id(), clientAccount.displayName(), selectedProduct.getId(),
|
||||||
selectedProduct.getName(), currency, selectedProduct.getInterestRate(), selectedProduct.getSavingsDepositAmount(),
|
selectedProduct.getName(), currency, selectedProduct.getInterestRate(), selectedProduct.getSavingsDepositAmount(),
|
||||||
selectedProduct.getSavingProductType(), selectedProduct.getTenureType(), selectedProduct.getTenure(), selectedProduct.getSavingFrequencyType(),
|
selectedProduct.getSavingProductType(), selectedProduct.getTenureType(), selectedProduct.getTenure(),
|
||||||
selectedProduct.getInterestType(), selectedProduct.getInterestCalculationMethod(),selectedProduct.getMinimumBalanceForWithdrawal(),
|
selectedProduct.getSavingFrequencyType(), selectedProduct.getInterestType(),
|
||||||
selectedProduct.isPartialDepositAllowed(), selectedProduct.isLockinPeriodAllowed(),selectedProduct.getLockinPeriod(),
|
selectedProduct.getInterestCalculationMethod(), selectedProduct.getMinimumBalanceForWithdrawal(),
|
||||||
selectedProduct.getLockinPeriodType(),selectedProduct.getDepositEvery());
|
selectedProduct.isPartialDepositAllowed(), selectedProduct.isLockinPeriodAllowed(), selectedProduct.getLockinPeriod(),
|
||||||
|
selectedProduct.getLockinPeriodType(), selectedProduct.getDepositEvery());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
accountData = SavingAccountData.createFrom(clientAccount.id(), clientAccount.displayName());
|
accountData = SavingAccountData.createFrom(clientAccount.id(), clientAccount.displayName());
|
||||||
}
|
}
|
||||||
return accountData;
|
return accountData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SavingProductData findSavingProductById( Collection<SavingProductLookup> savingProducts, Long productId) {
|
private SavingProductData findSavingProductById(Collection<SavingProductLookup> savingProducts, Long productId) {
|
||||||
SavingProductData match = this.savingProductReadPlatformService.retrieveNewSavingProductDetails();
|
SavingProductData match = this.savingProductReadPlatformService.retrieveNewSavingProductDetails();
|
||||||
for (SavingProductLookup savingProductLookup : savingProducts) {
|
for (SavingProductLookup savingProductLookup : savingProducts) {
|
||||||
if (savingProductLookup.hasId(productId)) {
|
if (savingProductLookup.hasId(productId)) {
|
||||||
match = this.savingProductReadPlatformService.retrieveSavingProduct(savingProductLookup.getId());
|
match = this.savingProductReadPlatformService.retrieveSavingProduct(savingProductLookup.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SavingPermissionData retrieveSavingAccountPermissions(SavingAccountData savingAccountData) {
|
public SavingPermissionData retrieveSavingAccountPermissions(SavingAccountData savingAccountData) {
|
||||||
boolean pendingApproval = (savingAccountData.getStatus().getId().equals(100L));
|
boolean pendingApproval = (savingAccountData.getStatus().getId().equals(100L));
|
||||||
boolean undoApprovalAllowed = (savingAccountData.getStatus().getId().equals(300L));
|
boolean undoApprovalAllowed = (savingAccountData.getStatus().getId().equals(300L));
|
||||||
boolean renewelAllowed = false;
|
boolean renewelAllowed = false;
|
||||||
if (savingAccountData.getMaturesOnDate() != null && savingAccountData.getTenureType().equals(TenureTypeEnum.FIXED_PERIOD)) {
|
if (savingAccountData.getMaturesOnDate() != null && savingAccountData.getTenureType().equals(TenureTypeEnum.FIXED_PERIOD)) {
|
||||||
if (new LocalDate().isAfter(savingAccountData.getMaturesOnDate())) {
|
if (new LocalDate().isAfter(savingAccountData.getMaturesOnDate())) {
|
||||||
renewelAllowed = true;
|
renewelAllowed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean rejectAllowed = pendingApproval;
|
boolean rejectAllowed = pendingApproval;
|
||||||
boolean withdrawnByApplicantAllowed = pendingApproval;
|
boolean withdrawnByApplicantAllowed = pendingApproval;
|
||||||
boolean isMaturedDepositAccount = (savingAccountData.getStatus().getId().equals(700L));
|
boolean isMaturedDepositAccount = (savingAccountData.getStatus().getId().equals(700L));
|
||||||
return new SavingPermissionData(rejectAllowed, withdrawnByApplicantAllowed, undoApprovalAllowed, pendingApproval, renewelAllowed, isMaturedDepositAccount);
|
return new SavingPermissionData(rejectAllowed, withdrawnByApplicantAllowed, undoApprovalAllowed, pendingApproval, renewelAllowed,
|
||||||
}
|
isMaturedDepositAccount);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal deriveSavingDueAmount(SavingAccountData account) {
|
public BigDecimal deriveSavingDueAmount(SavingAccountData account) {
|
||||||
|
|
||||||
BigDecimal dueAmount = BigDecimal.ZERO;
|
BigDecimal dueAmount = BigDecimal.ZERO;
|
||||||
EnumOptionData status = account.getStatus();
|
EnumOptionData status = account.getStatus();
|
||||||
LocalDate date = account.getActualCommencementDate();
|
LocalDate date = account.getActualCommencementDate();
|
||||||
|
|
||||||
if (account.getStatus() != null && account.getActualCommencementDate() != null) {
|
if (account.getStatus() != null && account.getActualCommencementDate() != null) {
|
||||||
BigDecimal amountPerPeriod = account.getSavingsDepostiAmountPerPeriod();
|
BigDecimal amountPerPeriod = account.getSavingsDepostiAmountPerPeriod();
|
||||||
Integer tenure = account.getTenure();
|
Integer tenure = account.getTenure();
|
||||||
Integer depositEvery = account.getDepositEvery();
|
Integer depositEvery = account.getDepositEvery();
|
||||||
Integer noOfPeriods = tenure/depositEvery ;
|
Integer noOfPeriods = tenure / depositEvery;
|
||||||
Integer noOfMonths = Months.monthsBetween(date, new LocalDate()).getMonths();
|
Integer noOfMonths = Months.monthsBetween(date, new LocalDate()).getMonths();
|
||||||
Integer noOfPeriodsExistedTillDate = noOfMonths/depositEvery;
|
Integer noOfPeriodsExistedTillDate = noOfMonths / depositEvery;
|
||||||
BigDecimal totalAmountToBePaidTillDate = BigDecimal.valueOf(noOfPeriodsExistedTillDate.doubleValue()*amountPerPeriod.doubleValue());
|
BigDecimal totalAmountToBePaidTillDate = BigDecimal.valueOf(noOfPeriodsExistedTillDate.doubleValue()
|
||||||
dueAmount = dueAmount.add(BigDecimal.valueOf(totalAmountToBePaidTillDate.doubleValue() - account.getOutstandingAmount().doubleValue()));
|
* amountPerPeriod.doubleValue());
|
||||||
|
dueAmount = dueAmount.add(BigDecimal.valueOf(totalAmountToBePaidTillDate.doubleValue()
|
||||||
|
- account.getOutstandingAmount().doubleValue()));
|
||||||
|
|
||||||
}
|
}
|
||||||
dueAmount = dueAmount.doubleValue() < 0 ? BigDecimal.ZERO : dueAmount;
|
dueAmount = dueAmount.doubleValue() < 0 ? BigDecimal.ZERO : dueAmount;
|
||||||
return dueAmount;
|
return dueAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SavingScheduleData retrieveSavingsAccountSchedule(Long accountId, CurrencyData currency) {
|
public SavingScheduleData retrieveSavingsAccountSchedule(Long accountId, CurrencyData currency) {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
SavingAccountScheduleMapper mapper = new SavingAccountScheduleMapper();
|
SavingAccountScheduleMapper mapper = new SavingAccountScheduleMapper();
|
||||||
String sql = "Select " + mapper.savingScheduleSchema() +" where ss.saving_account_id =? order by ss.installment";
|
String sql = "Select " + mapper.savingScheduleSchema() + " where ss.saving_account_id =? order by ss.installment";
|
||||||
List<SavingSchedulePeriodData> periods = this.jdbcTemplate.query(sql, mapper, new Object[]{accountId});
|
List<SavingSchedulePeriodData> periods = this.jdbcTemplate.query(sql, mapper, new Object[] { accountId });
|
||||||
BigDecimal cumulativeDepositDue = BigDecimal.ZERO;
|
BigDecimal cumulativeDepositDue = BigDecimal.ZERO;
|
||||||
BigDecimal cumulativeDepositPaid = BigDecimal.ZERO;
|
BigDecimal cumulativeDepositPaid = BigDecimal.ZERO;
|
||||||
BigDecimal cummulativeInterestAccured = BigDecimal.ZERO;
|
BigDecimal cummulativeInterestAccured = BigDecimal.ZERO;
|
||||||
for(SavingSchedulePeriodData data : periods){
|
for (SavingSchedulePeriodData data : periods) {
|
||||||
cumulativeDepositDue = cumulativeDepositDue.add(data.getDepositDue())/*.subtract(data.getDepositPaid())*/;
|
cumulativeDepositDue = cumulativeDepositDue.add(data.getDepositDue());
|
||||||
cumulativeDepositPaid = cumulativeDepositPaid.add(data.getDepositPaid());
|
cumulativeDepositPaid = cumulativeDepositPaid.add(data.getDepositPaid());
|
||||||
cummulativeInterestAccured = cummulativeInterestAccured.add(data.getInterestAccured());
|
cummulativeInterestAccured = cummulativeInterestAccured.add(data.getInterestAccured());
|
||||||
}
|
}
|
||||||
SavingScheduleData scheduleData = new SavingScheduleData(currency, cumulativeDepositDue, cumulativeDepositPaid, cummulativeInterestAccured, periods);
|
SavingScheduleData scheduleData = new SavingScheduleData(currency, cumulativeDepositDue, cumulativeDepositPaid,
|
||||||
return scheduleData;
|
cummulativeInterestAccured, periods);
|
||||||
}
|
return scheduleData;
|
||||||
|
}
|
||||||
|
|
||||||
public static final class SavingAccountScheduleMapper implements RowMapper<SavingSchedulePeriodData> {
|
public static final class SavingAccountScheduleMapper implements RowMapper<SavingSchedulePeriodData> {
|
||||||
|
|
||||||
public String savingScheduleSchema(){
|
public String savingScheduleSchema() {
|
||||||
return "ss.id as id, ss.saving_account_id as savingAccountId, ss.duedate as dueDate, ss.installment as installment, "
|
return "ss.id as id, ss.saving_account_id as savingAccountId, ss.duedate as dueDate, ss.installment as installment, "
|
||||||
+ " ss.deposit as deposit, ss.payment_date as paymentDate, ss.deposit_paid as depositPaid, "
|
+ " ss.deposit as deposit, ss.payment_date as paymentDate, ss.deposit_paid as depositPaid, "
|
||||||
+ " ss.completed_derived as completedDerived, ss.interest_accured AS interestAccured FROM m_saving_schedule ss";
|
+ " ss.completed_derived as completedDerived, ss.interest_accured AS interestAccured FROM m_saving_schedule ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SavingSchedulePeriodData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
public SavingSchedulePeriodData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||||
|
|
||||||
LocalDate dueDate = JdbcSupport.getLocalDate(rs, "dueDate");
|
LocalDate dueDate = JdbcSupport.getLocalDate(rs, "dueDate");
|
||||||
Integer installment = JdbcSupport.getInteger(rs, "installment");
|
Integer installment = JdbcSupport.getInteger(rs, "installment");
|
||||||
BigDecimal depositDue = rs.getBigDecimal("deposit");
|
BigDecimal depositDue = rs.getBigDecimal("deposit");
|
||||||
BigDecimal depositPaid = rs.getBigDecimal("depositPaid");
|
BigDecimal depositPaid = rs.getBigDecimal("depositPaid");
|
||||||
BigDecimal interestAccured = rs.getBigDecimal("interestAccured");
|
BigDecimal interestAccured = rs.getBigDecimal("interestAccured");
|
||||||
|
|
||||||
return new SavingSchedulePeriodData(installment, dueDate, depositDue, depositPaid, interestAccured);
|
return new SavingSchedulePeriodData(installment, dueDate, depositDue, depositPaid, interestAccured);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SavingAccountForLookup> retrieveSavingAccountsForLookUp() {
|
public Collection<SavingAccountForLookup> retrieveSavingAccountsForLookUp() {
|
||||||
SavingAccountLookupMapper mapper = new SavingAccountLookupMapper();
|
SavingAccountLookupMapper mapper = new SavingAccountLookupMapper();
|
||||||
String sql = "select "+ mapper.schema();
|
String sql = "select " + mapper.schema();
|
||||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class SavingAccountLookupMapper implements RowMapper<SavingAccountForLookup> {
|
private static final class SavingAccountLookupMapper implements RowMapper<SavingAccountForLookup> {
|
||||||
|
|
||||||
public String schema(){
|
public String schema() {
|
||||||
return " sa.id as id from m_saving_account sa where sa.is_deleted=0 and sa.status_enum=300";
|
return " sa.id as id from m_saving_account sa where sa.is_deleted=0 and sa.status_enum=300";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SavingAccountForLookup mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
public SavingAccountForLookup mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||||
Long id = rs.getLong("id");
|
Long id = rs.getLong("id");
|
||||||
return new SavingAccountForLookup(id);
|
return new SavingAccountForLookup(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SavingAccountTransactionsData> retrieveSavingsAccountTransactions(Long accountId) {
|
public Collection<SavingAccountTransactionsData> retrieveSavingsAccountTransactions(Long accountId) {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
SavingAccountTransactionMapper savingAccountTransactionMapper = new SavingAccountTransactionMapper();
|
SavingAccountTransactionMapper savingAccountTransactionMapper = new SavingAccountTransactionMapper();
|
||||||
String sql = "select "+ savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? ";
|
String sql = "select " + savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? ";
|
||||||
return jdbcTemplate.query(sql, savingAccountTransactionMapper, new Object[] {accountId});
|
return jdbcTemplate.query(sql, savingAccountTransactionMapper, new Object[] { accountId });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class SavingAccountTransactionMapper implements RowMapper<SavingAccountTransactionsData> {
|
private static final class SavingAccountTransactionMapper implements RowMapper<SavingAccountTransactionsData> {
|
||||||
|
|
||||||
public String schema() {
|
public String schema() {
|
||||||
return "stxn.id as id, stxn.transaction_type_enum as type, stxn.transaction_date as transactionDate, stxn.amount as amount FROM m_saving_account_transaction stxn";
|
return "stxn.id as id, stxn.transaction_type_enum as type, stxn.transaction_date as transactionDate, stxn.amount as amount FROM m_saving_account_transaction stxn";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SavingAccountTransactionsData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
|
||||||
Long id = rs.getLong("id");
|
|
||||||
LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate");
|
|
||||||
Integer transactionTypeValue = JdbcSupport.getInteger(rs, "type");
|
|
||||||
EnumOptionData transactionType = DepositAccountTransactionEnumerations.depositType(transactionTypeValue);
|
|
||||||
BigDecimal amount = rs.getBigDecimal("amount");
|
|
||||||
return new SavingAccountTransactionsData(id, transactionDate, transactionType, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SavingAccountTransactionsData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||||
|
Long id = rs.getLong("id");
|
||||||
|
LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate");
|
||||||
|
Integer transactionTypeValue = JdbcSupport.getInteger(rs, "type");
|
||||||
|
EnumOptionData transactionType = DepositAccountTransactionEnumerations.depositType(transactionTypeValue);
|
||||||
|
BigDecimal amount = rs.getBigDecimal("amount");
|
||||||
|
return new SavingAccountTransactionsData(id, transactionDate, transactionType, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user