diff --git a/mifosng-db/patches/patch-05-saving-schedule-creation.sql b/mifosng-db/patches/patch-05-saving-schedule-creation.sql index f6fb8f414..23807a2f4 100644 --- a/mifosng-db/patches/patch-05-saving-schedule-creation.sql +++ b/mifosng-db/patches/patch-05-saving-schedule-creation.sql @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS `m_saving_schedule` +DROP TABLE IF EXISTS `m_saving_schedule`; CREATE TABLE `m_saving_schedule` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `saving_account_id` bigint(20) NOT NULL, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java index 93c84a2a4..387abeb42 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java @@ -39,135 +39,136 @@ import org.springframework.stereotype.Component; @Component @Scope("singleton") public class SavingsAccountApiResource { - - @Autowired - private SavingAccountWritePlatformService savingAccountWritePlatformService; - - @Autowired - private SavingAccountReadPlatformService savingAccountReadPlatformService; - - @Autowired - private PortfolioApiDataConversionService apiDataConversionService; - - @Autowired - private PortfolioApiJsonSerializerService apiJsonSerializerService; - private final String entityType = "SAVINGSACCOUNT"; - - @Autowired - private PlatformSecurityContext context; - - @Autowired - private CalculateSavingSchedule calculateSavingSchedule; - - private static final Set typicalResponseParameters = new HashSet( - Arrays.asList("id", "status", "externalId", "clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod", "savingsFrequencyType", - "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType", "interestCalculationMethod", "tenure", "tenureType", "projectedCommencementDate", - "actualCommencementDate", "maturesOnDate", "projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount", "preClosureAllowed", - "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType")); - - @POST - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String createSavingAccount(@QueryParam("command") final String commandParam, - @Context final UriInfo uriInfo,final String jsonRequestBody){ - - final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(null, jsonRequestBody); - - if (is(commandParam, "calculateSavingSchedule")) { + @Autowired + private SavingAccountWritePlatformService savingAccountWritePlatformService; + + @Autowired + private SavingAccountReadPlatformService savingAccountReadPlatformService; + + @Autowired + private PortfolioApiDataConversionService apiDataConversionService; + + @Autowired + private PortfolioApiJsonSerializerService apiJsonSerializerService; + + private final String entityType = "SAVINGSACCOUNT"; + + @Autowired + private PlatformSecurityContext context; + + @Autowired + private CalculateSavingSchedule calculateSavingSchedule; + + private static final Set typicalResponseParameters = new HashSet(Arrays.asList("id", "status", "externalId", + "clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod", + "savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType", + "interestCalculationMethod", "tenure", "tenureType", "projectedCommencementDate", "actualCommencementDate", "maturesOnDate", + "projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount", + "preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed", + "lockinPeriod", "lockinPeriodType")); + + @POST + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String createSavingAccount(@QueryParam("command") final String commandParam, @Context final UriInfo uriInfo, + final String jsonRequestBody) { + + final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(null, jsonRequestBody); + + if (is(commandParam, "calculateSavingSchedule")) { CalculateSavingScheduleCommand calculateSavingScheduleCommand = command.toCalculateSavingScheduleCommand(); - return calculateSavingSchedule(uriInfo,calculateSavingScheduleCommand); + return calculateSavingSchedule(uriInfo, calculateSavingScheduleCommand); } - - EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.createSavingAccount(command); - - return this.apiJsonSerializerService.serializeEntityIdentifier(entityIdentifier); - } - - private String calculateSavingSchedule(final UriInfo uriInfo, final CalculateSavingScheduleCommand command) { - - SavingScheduleData savingScheduleData = this.calculateSavingSchedule.calculateSavingSchedule(command); - final Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - - return this.apiJsonSerializerService.serializeSavingScheduleDataToJson(prettyPrint, responseParameters, savingScheduleData); - } - @PUT - @Path("{accountId}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response updateSavingAccount(@PathParam("accountId") final Long accountId,final String jsonRequestBody){ - - final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(accountId, jsonRequestBody); - - EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.updateSavingAccount(command); - - return Response.ok().entity(entityIdentifier).build(); - } - - @GET - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String retrieveAllDepositAccounts(@Context final UriInfo uriInfo) { + EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.createSavingAccount(command); - context.authenticatedUser().validateHasReadPermission(entityType); - - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + return this.apiJsonSerializerService.serializeEntityIdentifier(entityIdentifier); + } - Collection accounts = this.savingAccountReadPlatformService.retrieveAllSavingsAccounts(); - - return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, accounts); - } - - @GET - @Path("{accountId}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String retrieveDepositAccount(@PathParam("accountId") final Long accountId, @Context final UriInfo uriInfo) { + private String calculateSavingSchedule(final UriInfo uriInfo, final CalculateSavingScheduleCommand command) { - context.authenticatedUser().validateHasReadPermission(entityType); - - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - - SavingAccountData account = this.savingAccountReadPlatformService.retrieveSavingsAccount(accountId); - - return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account); - } + SavingScheduleData savingScheduleData = this.calculateSavingSchedule.calculateSavingSchedule(command); + final Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - @SuppressWarnings("unused") - @GET - @Path("template") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String retrieveNewDepositAccountDetails( - @QueryParam("clientId") final Long clientId, - @QueryParam("productId") final Long productId, - @Context final UriInfo uriInfo) { + return this.apiJsonSerializerService.serializeSavingScheduleDataToJson(prettyPrint, responseParameters, savingScheduleData); + } + + @PUT + @Path("{accountId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response updateSavingAccount(@PathParam("accountId") final Long accountId, final String jsonRequestBody) { + + final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(accountId, jsonRequestBody); + + EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.updateSavingAccount(command); + + return Response.ok().entity(entityIdentifier).build(); + } + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveAllDepositAccounts(@Context final UriInfo uriInfo) { + + context.authenticatedUser().validateHasReadPermission(entityType); + + Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + if (responseParameters.isEmpty()) { + responseParameters.addAll(typicalResponseParameters); + } + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + + Collection accounts = this.savingAccountReadPlatformService.retrieveAllSavingsAccounts(); + + return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, accounts); + } + + @GET + @Path("{accountId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveDepositAccount(@PathParam("accountId") final Long accountId, @Context final UriInfo uriInfo) { + + context.authenticatedUser().validateHasReadPermission(entityType); + + Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + + if (responseParameters.isEmpty()) { + responseParameters.addAll(typicalResponseParameters); + } + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + + SavingAccountData account = this.savingAccountReadPlatformService.retrieveSavingsAccount(accountId); + + return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account); + } + + @SuppressWarnings("unused") + @GET + @Path("template") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveNewDepositAccountDetails(@QueryParam("clientId") final Long clientId, + @QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) { + + context.authenticatedUser().validateHasReadPermission(entityType); + + Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + if (responseParameters.isEmpty()) { + responseParameters.addAll(typicalResponseParameters); + } + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + + SavingAccountData account = null; + // this.savingAccountReadPlatformService.retrieveNewSavingsAccountDetails(clientId, + // productId); + + return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account); + } - context.authenticatedUser().validateHasReadPermission(entityType); - - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - - SavingAccountData account = null; -// this.savingAccountReadPlatformService.retrieveNewSavingsAccountDetails(clientId, productId); - - return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account); - } - private boolean is(final String commandParam, final String commandValue) { return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java index ea5408b77..a93d8dbfd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java @@ -6,58 +6,54 @@ import org.joda.time.LocalDate; public class CalculateSavingScheduleCommand { - private final Long productId; - private final BigDecimal deposit; - private final Integer payEvery; - private final Integer paymentFrequencyType; - private final BigDecimal interestRate; - private final LocalDate paymentsStartingFromDate; - private final Integer tenure; - - public CalculateSavingScheduleCommand(final Long productId, - final BigDecimal deposit, - final Integer payEvery, - final Integer paymentFrequencyType, - final BigDecimal interestRate, - final LocalDate paymentsStartingFromDate, - final Integer tenure) { - - this.productId = productId; - this.deposit = deposit; - this.payEvery = payEvery; - this.paymentFrequencyType=paymentFrequencyType; - this.interestRate= interestRate; - this.paymentsStartingFromDate=paymentsStartingFromDate; - this.tenure = tenure; - - } + private final Long productId; + private final BigDecimal deposit; + private final Integer payEvery; + private final Integer paymentFrequencyType; + private final BigDecimal interestRate; + private final LocalDate paymentsStartingFromDate; + private final Integer tenure; - public Long getProductId() { - return this.productId; - } + public CalculateSavingScheduleCommand(final Long productId, final BigDecimal deposit, final Integer payEvery, + final Integer paymentFrequencyType, final BigDecimal interestRate, final LocalDate paymentsStartingFromDate, + final Integer tenure) { - public BigDecimal getDeposit() { - return this.deposit; - } + this.productId = productId; + this.deposit = deposit; + this.payEvery = payEvery; + this.paymentFrequencyType = paymentFrequencyType; + this.interestRate = interestRate; + this.paymentsStartingFromDate = paymentsStartingFromDate; + this.tenure = tenure; - public Integer getPayEvery() { - return this.payEvery; - } + } - public Integer getPaymentFrequencyType() { - return this.paymentFrequencyType; - } + public Long getProductId() { + return this.productId; + } - public BigDecimal getInterestRate() { - return this.interestRate; - } + public BigDecimal getDeposit() { + return this.deposit; + } - public LocalDate getPaymentsStartingFromDate() { - return this.paymentsStartingFromDate; - } + public Integer getPayEvery() { + return this.payEvery; + } + + public Integer getPaymentFrequencyType() { + return this.paymentFrequencyType; + } + + public BigDecimal getInterestRate() { + return this.interestRate; + } + + public LocalDate getPaymentsStartingFromDate() { + return this.paymentsStartingFromDate; + } + + public Integer getTenure() { + return this.tenure; + } - public Integer getTenure() { - return this.tenure; - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java index 866e548bb..3c50c51d3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java @@ -6,245 +6,239 @@ import java.util.Set; import org.joda.time.LocalDate; public class SavingAccountCommand { - - - private final Long id; - private final Long clientId; - private final Long productId; - private final String externalId; - private final String currencyCode; - private final Integer digitsAfterDecimal; - private final BigDecimal savingsDepositAmount; - private final BigDecimal recurringInterestRate; - private final BigDecimal savingInterestRate; - private final Integer tenure; - - private final boolean isLockinPeriodAllowed; - private final Integer lockinPeriod; - private final Integer lockinPeriodType; - - private final LocalDate commencementDate; - private final Integer savingProductType; - private final Integer tenureType; - private final Integer frequency; - private final Integer interestType; - - private final Integer interestCalculationMethod; - private final BigDecimal minimumBalanceForWithdrawal; - private final boolean isPartialDepositAllowed; - private final Integer payEvery; - - private final Set modifiedParameters; - - public SavingAccountCommand(final Set modifiedParameters, - final Long id, - final Long clientId, - final Long productId, - final String externalId,final String currencyCode, final Integer digitsAfterDecimal, - final BigDecimal savingsDepositAmount, - final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate, - final Integer tenure, final LocalDate commencementDate, - final Integer savingProductType, final Integer tenureType, final Integer frequency, final Integer interestType, - final BigDecimal minimumBalanceForWithdrawal, final Integer interestCalculationMethod, - final boolean isLockinPeriodAllowed, final boolean isPartialDepositAllowed, final Integer lockInPeriod, final Integer lockinPeriodType, - final Integer payEvery) { - this.id = id; - this.clientId = clientId; - this.productId = productId; - this.externalId = externalId; - - this.currencyCode = currencyCode; - this.digitsAfterDecimal = digitsAfterDecimal; - this.savingsDepositAmount = savingsDepositAmount; - this.recurringInterestRate = recurringInterestRate; - this.savingInterestRate = savingInterestRate; - this.tenure = tenure; - - this.modifiedParameters = modifiedParameters; - this.commencementDate = commencementDate; - - this.savingProductType=savingProductType; - this.tenureType=tenureType; - this.frequency=frequency; - this.interestType=interestType; - this.isPartialDepositAllowed=isPartialDepositAllowed; - - - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockInPeriod; - this.lockinPeriodType = lockinPeriodType; - this.minimumBalanceForWithdrawal=minimumBalanceForWithdrawal; - this.interestCalculationMethod=interestCalculationMethod; - this.payEvery = payEvery; - } + private final Long id; + private final Long clientId; + private final Long productId; + private final String externalId; - public Long getId() { - return id; - } + private final String currencyCode; + private final Integer digitsAfterDecimal; + private final BigDecimal savingsDepositAmount; + private final BigDecimal recurringInterestRate; + private final BigDecimal savingInterestRate; + private final Integer tenure; - public Long getClientId() { - return clientId; - } + private final boolean isLockinPeriodAllowed; + private final Integer lockinPeriod; + private final Integer lockinPeriodType; - public Long getProductId() { - return productId; - } + private final LocalDate commencementDate; + private final Integer savingProductType; + private final Integer tenureType; + private final Integer frequency; + private final Integer interestType; - public String getExternalId() { - return externalId; - } + private final Integer interestCalculationMethod; + private final BigDecimal minimumBalanceForWithdrawal; + private final boolean isPartialDepositAllowed; + private final Integer payEvery; - public String getCurrencyCode() { - return currencyCode; - } + private final Set modifiedParameters; - public Integer getDigitsAfterDecimal() { - return digitsAfterDecimal; - } + public SavingAccountCommand(final Set modifiedParameters, final Long id, final Long clientId, final Long productId, + final String externalId, final String currencyCode, final Integer digitsAfterDecimal, final BigDecimal savingsDepositAmount, + final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate, final Integer tenure, + final LocalDate commencementDate, final Integer savingProductType, final Integer tenureType, final Integer frequency, + final Integer interestType, final BigDecimal minimumBalanceForWithdrawal, final Integer interestCalculationMethod, + final boolean isLockinPeriodAllowed, final boolean isPartialDepositAllowed, final Integer lockInPeriod, + final Integer lockinPeriodType, final Integer payEvery) { + this.id = id; + this.clientId = clientId; + this.productId = productId; + this.externalId = externalId; - public BigDecimal getSavingsDepositAmount() { - return savingsDepositAmount; - } + this.currencyCode = currencyCode; + this.digitsAfterDecimal = digitsAfterDecimal; + this.savingsDepositAmount = savingsDepositAmount; + this.recurringInterestRate = recurringInterestRate; + this.savingInterestRate = savingInterestRate; + this.tenure = tenure; - public BigDecimal getRecurringInterestRate() { - return recurringInterestRate; - } + this.modifiedParameters = modifiedParameters; + this.commencementDate = commencementDate; - public BigDecimal getSavingInterestRate() { - return savingInterestRate; - } + this.savingProductType = savingProductType; + this.tenureType = tenureType; + this.frequency = frequency; + this.interestType = interestType; + this.isPartialDepositAllowed = isPartialDepositAllowed; - public Integer getTenure() { - return tenure; - } + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockInPeriod; + this.lockinPeriodType = lockinPeriodType; + this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; + this.interestCalculationMethod = interestCalculationMethod; + this.payEvery = payEvery; + } - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + public Long getId() { + return id; + } - public Integer getLockinPeriod() { - return lockinPeriod; - } + public Long getClientId() { + return clientId; + } - public Integer getLockinPeriodType() { - return lockinPeriodType; - } + public Long getProductId() { + return productId; + } - public LocalDate getCommencementDate() { - return commencementDate; - } + public String getExternalId() { + return externalId; + } - public Integer getSavingProductType() { - return savingProductType; - } + public String getCurrencyCode() { + return currencyCode; + } - public Integer getTenureType() { - return tenureType; - } + public Integer getDigitsAfterDecimal() { + return digitsAfterDecimal; + } - public Integer getFrequency() { - return frequency; - } + public BigDecimal getSavingsDepositAmount() { + return savingsDepositAmount; + } - public Integer getInterestType() { - return interestType; - } + public BigDecimal getRecurringInterestRate() { + return recurringInterestRate; + } - public Integer getInterestCalculationMethod() { - return interestCalculationMethod; - } + public BigDecimal getSavingInterestRate() { + return savingInterestRate; + } - public BigDecimal getMinimumBalanceForWithdrawal() { - return minimumBalanceForWithdrawal; - } + public Integer getTenure() { + return tenure; + } - public boolean isPartialDepositAllowed() { - return isPartialDepositAllowed; - } + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } - public Integer getPayEvery() { - return this.payEvery; - } + public Integer getLockinPeriod() { + return lockinPeriod; + } - public boolean isNoFieldChanged() { - return this.modifiedParameters.isEmpty(); - } - - public boolean isProductIdChanged(){ - return this.modifiedParameters.contains("productId"); - } - - public boolean isExternalIdChanged(){ - return this.modifiedParameters.contains("externalId"); - } - - public boolean isDepositAmountChanged(){ - return this.modifiedParameters.contains("deposit"); - } + public Integer getLockinPeriodType() { + return lockinPeriodType; + } - public boolean isTenureInMonthsChanged() { - return this.modifiedParameters.contains("tenureInMonths"); - } - - public boolean isLockinPeriodChanged() { - return this.modifiedParameters.contains("lockinPeriod"); - } - - public boolean isPreClosureInterestRateChanged(){ - return this.modifiedParameters.contains("preClosureInterestRate"); - } - - public boolean isPreClosureAllowedChanged() { - return this.modifiedParameters.contains("preClosureAllowed"); - } - - public boolean isCommencementDateChanged() { - return this.modifiedParameters.contains("commencementDate"); - } + public LocalDate getCommencementDate() { + return commencementDate; + } - public boolean isTenureTypeEnumChanged() { - return this.modifiedParameters.contains("tenureType"); - } + public Integer getSavingProductType() { + return savingProductType; + } - public boolean isSavingProductTypeChanged() { - return this.modifiedParameters.contains("savingProductType"); - } + public Integer getTenureType() { + return tenureType; + } - public boolean isSavingFrequencyTypeChanged() { - return this.modifiedParameters.contains("frequency"); - } + public Integer getFrequency() { + return frequency; + } - public boolean isSavingInterestCalculationMethodChanged() { - return this.modifiedParameters.contains("interestCalculationMethod"); - } + public Integer getInterestType() { + return interestType; + } - public boolean isReccuringInterestRateChanged() { - return this.modifiedParameters.contains("recurringInterestRate"); - } + public Integer getInterestCalculationMethod() { + return interestCalculationMethod; + } - public boolean isSavingInterestRateChanged() { - return this.modifiedParameters.contains("savingInterestRate"); - } + public BigDecimal getMinimumBalanceForWithdrawal() { + return minimumBalanceForWithdrawal; + } - public boolean isLockinPeriodAllowedChanged() { - return this.modifiedParameters.contains("isLockinPeriodAllowed"); - } + public boolean isPartialDepositAllowed() { + return isPartialDepositAllowed; + } - public boolean isLockinPeriodTypeChanged() { - return this.modifiedParameters.contains("lockinPeriodType"); - } + public Integer getPayEvery() { + return this.payEvery; + } - public boolean isPartialDepositAllowedChanged() { - return this.modifiedParameters.contains("isPartialDepositAllowed"); - } - - public boolean isPayEveryChanged(){ - return this.modifiedParameters.contains("payEvery"); - } + public boolean isNoFieldChanged() { + return this.modifiedParameters.isEmpty(); + } - public CalculateSavingScheduleCommand toCalculateSavingScheduleCommand() { - return new CalculateSavingScheduleCommand(productId, savingsDepositAmount, payEvery, frequency, recurringInterestRate, commencementDate,tenure); - } + public boolean isProductIdChanged() { + return this.modifiedParameters.contains("productId"); + } + + public boolean isExternalIdChanged() { + return this.modifiedParameters.contains("externalId"); + } + + public boolean isDepositAmountChanged() { + return this.modifiedParameters.contains("deposit"); + } + + public boolean isTenureInMonthsChanged() { + return this.modifiedParameters.contains("tenureInMonths"); + } + + public boolean isLockinPeriodChanged() { + return this.modifiedParameters.contains("lockinPeriod"); + } + + public boolean isPreClosureInterestRateChanged() { + return this.modifiedParameters.contains("preClosureInterestRate"); + } + + public boolean isPreClosureAllowedChanged() { + return this.modifiedParameters.contains("preClosureAllowed"); + } + + public boolean isCommencementDateChanged() { + return this.modifiedParameters.contains("commencementDate"); + } + + public boolean isTenureTypeEnumChanged() { + return this.modifiedParameters.contains("tenureType"); + } + + public boolean isSavingProductTypeChanged() { + return this.modifiedParameters.contains("savingProductType"); + } + + public boolean isSavingFrequencyTypeChanged() { + return this.modifiedParameters.contains("frequency"); + } + + public boolean isSavingInterestCalculationMethodChanged() { + return this.modifiedParameters.contains("interestCalculationMethod"); + } + + public boolean isReccuringInterestRateChanged() { + return this.modifiedParameters.contains("recurringInterestRate"); + } + + public boolean isSavingInterestRateChanged() { + return this.modifiedParameters.contains("savingInterestRate"); + } + + public boolean isLockinPeriodAllowedChanged() { + return this.modifiedParameters.contains("isLockinPeriodAllowed"); + } + + public boolean isLockinPeriodTypeChanged() { + return this.modifiedParameters.contains("lockinPeriodType"); + } + + public boolean isPartialDepositAllowedChanged() { + return this.modifiedParameters.contains("isPartialDepositAllowed"); + } + + public boolean isPayEveryChanged() { + return this.modifiedParameters.contains("payEvery"); + } + + public CalculateSavingScheduleCommand toCalculateSavingScheduleCommand() { + return new CalculateSavingScheduleCommand(productId, savingsDepositAmount, payEvery, frequency, recurringInterestRate, + commencementDate, tenure); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingScheduleData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingScheduleData.java index 8ce7184f7..54cfa60de 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingScheduleData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingScheduleData.java @@ -6,29 +6,29 @@ import java.util.Collection; import org.mifosplatform.organisation.monetary.data.CurrencyData; public class SavingScheduleData { - - private final CurrencyData currency; - private final BigDecimal cumulativeDepositDue; - private final Collection periods; - - public SavingScheduleData(final CurrencyData currency, final BigDecimal cumulativeDepositDue, - final Collection periods) { - this.currency = currency; - this.cumulativeDepositDue= cumulativeDepositDue; - this.periods= periods; - - } - public CurrencyData getCurrency() { - return this.currency; - } + private final CurrencyData currency; + private final BigDecimal cumulativeDepositDue; + private final Collection periods; - public BigDecimal getCumulativeDepositDue() { - return this.cumulativeDepositDue; - } - - public Collection getPeriods() { - return this.periods; - } + public SavingScheduleData(final CurrencyData currency, final BigDecimal cumulativeDepositDue, + final Collection periods) { + this.currency = currency; + this.cumulativeDepositDue = cumulativeDepositDue; + this.periods = periods; + + } + + public CurrencyData getCurrency() { + return this.currency; + } + + public BigDecimal getCumulativeDepositDue() { + return this.cumulativeDepositDue; + } + + public Collection getPeriods() { + return this.periods; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingSchedulePeriodData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingSchedulePeriodData.java index 4708c05db..c20272ecc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingSchedulePeriodData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingSchedulePeriodData.java @@ -5,37 +5,38 @@ import java.math.BigDecimal; import org.joda.time.LocalDate; public class SavingSchedulePeriodData { - - private final Integer period; - private final LocalDate dueDate; - private final BigDecimal depositDue; - private final BigDecimal depositPaid; - - public SavingSchedulePeriodData(final Integer period, final LocalDate dueDate, final BigDecimal depositDue, final BigDecimal depositPaid) { - this.period = period; - this.dueDate = dueDate; - this.depositDue= depositDue; - this.depositPaid= depositPaid; - } - - public static SavingSchedulePeriodData addScheduleInformation(int periodNumber, LocalDate scheduleDate, BigDecimal depositAmountPerPeriod){ - return new SavingSchedulePeriodData(periodNumber, scheduleDate, depositAmountPerPeriod, BigDecimal.ZERO); - } - public Integer getPeriod() { - return this.period; - } + private final Integer period; + private final LocalDate dueDate; + private final BigDecimal depositDue; + private final BigDecimal depositPaid; - public LocalDate getDueDate() { - return this.dueDate; - } + public SavingSchedulePeriodData(final Integer period, final LocalDate dueDate, final BigDecimal depositDue, final BigDecimal depositPaid) { + this.period = period; + this.dueDate = dueDate; + this.depositDue = depositDue; + this.depositPaid = depositPaid; + } - public BigDecimal getDepositDue() { - return this.depositDue; - } + public static SavingSchedulePeriodData addScheduleInformation(int periodNumber, LocalDate scheduleDate, + BigDecimal depositAmountPerPeriod) { + return new SavingSchedulePeriodData(periodNumber, scheduleDate, depositAmountPerPeriod, BigDecimal.ZERO); + } + + public Integer getPeriod() { + return this.period; + } + + public LocalDate getDueDate() { + return this.dueDate; + } + + public BigDecimal getDepositDue() { + return this.depositDue; + } + + public BigDecimal getDepositPaid() { + return this.depositPaid; + } - public BigDecimal getDepositPaid() { - return this.depositPaid; - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java index de9c3ad00..02a39f196 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java @@ -6,7 +6,6 @@ import org.joda.time.LocalDate; import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType; public interface DepositScheduleDateGenerator { - - List generate(LocalDate startDate, Integer paymentPeriods, Integer depositFrequency, PeriodFrequencyType depositFrequencyType); -} + List generate(LocalDate startDate, Integer paymentPeriods, Integer depositFrequency, PeriodFrequencyType depositFrequencyType); +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java index a99657aba..657a8554e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java @@ -37,345 +37,319 @@ import org.mifosplatform.portfolio.savingsdepositproduct.domain.TenureTypeEnum; import org.mifosplatform.useradministration.domain.AppUser; @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 { - - @ManyToOne - @JoinColumn(name = "client_id", nullable = false) - private Client client; - @ManyToOne - @JoinColumn(name = "product_id") - private SavingProduct product; - - // FIXME - MADHUKAR - Do not use the actual enum type here but instead use Integer e.g. private Integer savingProductType; - @Column(name = "savings_product_type", nullable=false) - private SavingProductType savingProductType; - - @Column(name = "external_id") - private String externalId; - - @SuppressWarnings("unused") - @Embedded - private MonetaryCurrency currency; - - @Column(name = "deposit_amount_per_period", scale = 6, precision = 19, nullable = false) - private BigDecimal savingsDepositAmountPerPeriod; - - @SuppressWarnings("unused") - @Column(name = "total_deposit_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal totalSavingsAmount; - - @Column(name = "reccuring_nominal_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal reccuringInterestRate; - - @Column(name = "regular_saving_nominal_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal savingInterestRate; - - @Column(name = "tenure", nullable=false) - private Integer tenure; - - @Column(name = "tenure_type", nullable=false) - private TenureTypeEnum tenureType; - - // FIXME - MADHUKAR - Do not use the actual enum type here but instead use Integer e.g. private Integer savingProductType; - @Column(name = "frequency", nullable=false) - private SavingFrequencyType frequency; - - // FIXME - MADHUKAR - Do not use the actual enum type here but instead use Integer e.g. private Integer savingProductType; - @Column(name = "interest_type", nullable=false) - private SavingsInterestType interestType; - - // FIXME - MADHUKAR - Do not use the actual enum type here but instead use Integer e.g. private Integer savingProductType; - @Column(name = "interest_calculation_method") - private SavingInterestCalculationMethod interestCalculationMethod; - - @Temporal(TemporalType.DATE) - @Column(name = "projected_commencement_date") - private Date projectedCommencementDate; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "actual_commencement_date") - private Date actualCommencementDate; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "matures_on_date") - private Date maturesOnDate; - - @SuppressWarnings("unused") - @Column(name = "projected_interest_accrued_on_maturity", scale = 6, precision = 19, nullable = false) - private BigDecimal projectedInterestAccruedOnMaturity; - - @SuppressWarnings("unused") - @Column(name = "actual_interest_accrued", scale = 6, precision = 19, nullable = false) - private BigDecimal interestAccrued; - - @SuppressWarnings("unused") - @Column(name = "projected_total_maturity_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal projectedTotalOnMaturity; - - @SuppressWarnings("unused") - @Column(name = "actual_total_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal total; - - @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal preClosureInterestRate; - - @Column(name = "is_preclosure_allowed", nullable = false) - private boolean preClosureAllowed = false; - - @Column(name = "is_deleted", nullable=false) - private boolean deleted = false; - - @Column(name = "status_enum", nullable = false) - private Integer accountStatus; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "closedon_date") - private Date closedOnDate; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "rejectedon_date") - private Date rejectedOnDate; - - @Temporal(TemporalType.DATE) - @Column(name = "withdrawnon_date") - private Date withdrawnOnDate; + @ManyToOne + @JoinColumn(name = "client_id", nullable = false) + private Client client; - @Column(name = "is_lock_in_period_allowed", nullable=false) - private boolean isLockinPeriodAllowed = false; - - @Column(name = "lock_in_period", nullable=false) - private Integer lockinPeriod; - - @Column(name = "lock_in_period_type", nullable=false) - private PeriodFrequencyType lockinPeriodType; - - // see - // http://stackoverflow.com/questions/4334970/hibernate-cannot-simultaneously-fetch-multiple-bags - @LazyCollection(LazyCollectionOption.FALSE) - @OneToMany(cascade = CascadeType.ALL, mappedBy = "savingAccount", orphanRemoval = true) - private final List savingScheduleInstallments = new ArrayList(); + @ManyToOne + @JoinColumn(name = "product_id") + private SavingProduct product; + // FIXME - MADHUKAR - Do not use the actual enum type here but instead use + // Integer e.g. private Integer savingProductType; + @Column(name = "savings_product_type", nullable = false) + private SavingProductType savingProductType; - public static SavingAccount openNew( - Client client, - SavingProduct product, - String externalId, - Money savingsDeposit, - BigDecimal reccuringInterestRate, - BigDecimal savingInterestRate, - Integer tenure, - LocalDate commencementDate, - TenureTypeEnum tenureTypeEnum, - SavingProductType savingProductType, - SavingFrequencyType savingFrequencyType, - SavingsInterestType interestType, - SavingInterestCalculationMethod savingInterestCalculationMethod, - boolean isLockinPeriodAllowed, - Integer lockinPeriod, - PeriodFrequencyType lockinPeriodType, - ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, - final DepositLifecycleStateMachine lifecycleStateMachine) { - - Money futureValueOnMaturity = null; - if(savingProductType.isReccuring()){ - futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, reccuringInterestRate, - commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); - } else if(savingProductType.isRegular()){ - futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, savingInterestRate, - commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); - } - - return new SavingAccount(client, externalId, product, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure, - commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, interestType, savingInterestCalculationMethod, - isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, futureValueOnMaturity, lifecycleStateMachine); - } + @Column(name = "external_id") + private String externalId; - public SavingAccount(Client client, String externalId, - SavingProduct product, Money savingsDeposit, - BigDecimal reccuringInterestRate, BigDecimal savingInterestRate, - Integer tenure, LocalDate commencementDate, - TenureTypeEnum tenureTypeEnum, - SavingProductType savingProductType, - SavingFrequencyType savingFrequencyType, SavingsInterestType interestType, - SavingInterestCalculationMethod savingInterestCalculationMethod, - boolean isLockinPeriodAllowed, Integer lockinPeriod, - PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, - final DepositLifecycleStateMachine lifecycleStateMachine) { - - DepositAccountStatus from = null; - if (accountStatus != null) { - from = DepositAccountStatus.fromInt(accountStatus); - } + @SuppressWarnings("unused") + @Embedded + private MonetaryCurrency currency; - DepositAccountStatus statusEnum = lifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CREATED, from); - accountStatus = statusEnum.getValue(); - - this.total=BigDecimal.ZERO; - this.preClosureInterestRate=BigDecimal.ZERO; - this.totalSavingsAmount = BigDecimal.ZERO; - this.interestAccrued = BigDecimal.ZERO; - - this.client = client; - this.externalId = externalId; - this.product = product; - this.savingsDepositAmountPerPeriod = savingsDeposit.getAmount(); - this.currency = savingsDeposit.getCurrency(); - this.reccuringInterestRate = reccuringInterestRate; - this.savingInterestRate = savingInterestRate; - this.tenure =tenure; - this.projectedCommencementDate=commencementDate.toDate(); - this.tenureType = tenureTypeEnum; - this.savingProductType = savingProductType; - this.frequency = savingFrequencyType; - this.interestType = interestType; - this.interestCalculationMethod= savingInterestCalculationMethod; - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockinPeriod; - this.lockinPeriodType = lockinPeriodType; - this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); - this.projectedInterestAccruedOnMaturity =futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue()*tenure.doubleValue())); - } - - public void modifyAccount( - SavingProduct product, - String externalId, - Money savingsDeposit, - BigDecimal reccuringInterestRate, - BigDecimal savingInterestRate, - Integer tenure, - LocalDate commencementDate, - TenureTypeEnum tenureTypeEnum, - SavingProductType savingProductType, - SavingFrequencyType savingFrequencyType, - SavingInterestCalculationMethod savingInterestCalculationMethod, - boolean isLockinPeriodAllowed, - Integer lockinPeriod, - PeriodFrequencyType lockinPeriodType, - ReccuringDepositInterestCalculator reccuringDepositInterestCalculator) { - - - Money futureValueOnMaturity = null; - if(savingProductType.isReccuring()){ - futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, reccuringInterestRate, - commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); - } else if(savingProductType.isRegular()){ - futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, savingInterestRate, - commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); - } - - this.product = product; - this.externalId=externalId; - this.savingsDepositAmountPerPeriod=savingsDeposit.getAmount(); - this.reccuringInterestRate=reccuringInterestRate; - this.savingInterestRate = savingInterestRate; - this.tenure = tenure; - this.projectedCommencementDate = commencementDate.toDate(); - this.tenureType = tenureTypeEnum; - this.savingProductType = savingProductType; - this.frequency =savingFrequencyType; - this.interestCalculationMethod = savingInterestCalculationMethod; - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockinPeriod; - this.lockinPeriodType = lockinPeriodType; - - // FIXME - MADHUKAR - futureValueOnMaturity is possibly null - this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); - this.projectedInterestAccruedOnMaturity =futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue()*tenure.doubleValue())); - } - - public boolean isDeleted() { - return this.deleted; - } + @Column(name = "deposit_amount_per_period", scale = 6, precision = 19, nullable = false) + private BigDecimal savingsDepositAmountPerPeriod; - public boolean isPendingApproval() { - return this.accountStatus.equals(100); - } + @SuppressWarnings("unused") + @Column(name = "total_deposit_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal totalSavingsAmount; - public Client getClient() { - return client; - } + @Column(name = "reccuring_nominal_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal reccuringInterestRate; - public SavingProduct getProduct() { - return product; - } + @Column(name = "regular_saving_nominal_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal savingInterestRate; - public SavingProductType getSavingProductType() { - return savingProductType; - } + @Column(name = "tenure", nullable = false) + private Integer tenure; - public String getExternalId() { - return externalId; - } + @Column(name = "tenure_type", nullable = false) + private TenureTypeEnum tenureType; - public BigDecimal getSavingsDepositAmountPerPeriod() { - return savingsDepositAmountPerPeriod; - } + // FIXME - MADHUKAR - Do not use the actual enum type here but instead use + // Integer e.g. private Integer savingProductType; + @Column(name = "frequency", nullable = false) + private SavingFrequencyType frequency; - public BigDecimal getReccuringInterestRate() { - return reccuringInterestRate; - } + // FIXME - MADHUKAR - Do not use the actual enum type here but instead use + // Integer e.g. private Integer savingProductType; + @Column(name = "interest_type", nullable = false) + private SavingsInterestType interestType; - public BigDecimal getSavingInterestRate() { - return savingInterestRate; - } + // FIXME - MADHUKAR - Do not use the actual enum type here but instead use + // Integer e.g. private Integer savingProductType; + @Column(name = "interest_calculation_method") + private SavingInterestCalculationMethod interestCalculationMethod; - public Integer getTenure() { - return tenure; - } + @Temporal(TemporalType.DATE) + @Column(name = "projected_commencement_date") + private Date projectedCommencementDate; - public TenureTypeEnum getTenureType() { - return tenureType; - } + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "actual_commencement_date") + private Date actualCommencementDate; - public SavingFrequencyType getFrequency() { - return frequency; - } + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "matures_on_date") + private Date maturesOnDate; - public SavingsInterestType getInterestType() { - return interestType; - } + @SuppressWarnings("unused") + @Column(name = "projected_interest_accrued_on_maturity", scale = 6, precision = 19, nullable = false) + private BigDecimal projectedInterestAccruedOnMaturity; - public SavingInterestCalculationMethod getInterestCalculationMethod() { - return interestCalculationMethod; - } + @SuppressWarnings("unused") + @Column(name = "actual_interest_accrued", scale = 6, precision = 19, nullable = false) + private BigDecimal interestAccrued; - public Date getProjectedCommencementDate() { - return projectedCommencementDate; - } + @SuppressWarnings("unused") + @Column(name = "projected_total_maturity_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal projectedTotalOnMaturity; - public BigDecimal getPreClosureInterestRate() { - return preClosureInterestRate; - } + @SuppressWarnings("unused") + @Column(name = "actual_total_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal total; - public boolean isPreClosureAllowed() { - return preClosureAllowed; - } + @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal preClosureInterestRate; - public Date getWithdrawnOnDate() { - return withdrawnOnDate; - } + @Column(name = "is_preclosure_allowed", nullable = false) + private boolean preClosureAllowed = false; - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + @Column(name = "is_deleted", nullable = false) + private boolean deleted = false; - public Integer getLockinPeriod() { - return lockinPeriod; - } + @Column(name = "status_enum", nullable = false) + private Integer accountStatus; + + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "closedon_date") + private Date closedOnDate; + + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "rejectedon_date") + private Date rejectedOnDate; + + @Temporal(TemporalType.DATE) + @Column(name = "withdrawnon_date") + private Date withdrawnOnDate; + + @Column(name = "is_lock_in_period_allowed", nullable = false) + private boolean isLockinPeriodAllowed = false; + + @Column(name = "lock_in_period", nullable = false) + private Integer lockinPeriod; + + @Column(name = "lock_in_period_type", nullable = false) + private PeriodFrequencyType lockinPeriodType; + + // see + // http://stackoverflow.com/questions/4334970/hibernate-cannot-simultaneously-fetch-multiple-bags + @LazyCollection(LazyCollectionOption.FALSE) + @OneToMany(cascade = CascadeType.ALL, mappedBy = "savingAccount", orphanRemoval = true) + private final List savingScheduleInstallments = new ArrayList(); + + public static SavingAccount openNew(Client client, SavingProduct product, String externalId, Money savingsDeposit, + BigDecimal reccuringInterestRate, BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, + TenureTypeEnum tenureTypeEnum, SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, + SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod, + boolean isLockinPeriodAllowed, Integer lockinPeriod, PeriodFrequencyType lockinPeriodType, + ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final DepositLifecycleStateMachine lifecycleStateMachine) { + + Money futureValueOnMaturity = null; + if (savingProductType.isReccuring()) { + futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, + reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); + } else if (savingProductType.isRegular()) { + futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, + savingInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); + } + + return new SavingAccount(client, externalId, product, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure, + commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, interestType, savingInterestCalculationMethod, + isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, futureValueOnMaturity, lifecycleStateMachine); + } + + public SavingAccount(Client client, String externalId, SavingProduct product, Money savingsDeposit, BigDecimal reccuringInterestRate, + BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, + SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, SavingsInterestType interestType, + SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod, + PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, final DepositLifecycleStateMachine lifecycleStateMachine) { + + DepositAccountStatus from = null; + if (accountStatus != null) { + from = DepositAccountStatus.fromInt(accountStatus); + } + + DepositAccountStatus statusEnum = lifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CREATED, from); + accountStatus = statusEnum.getValue(); + + this.total = BigDecimal.ZERO; + this.preClosureInterestRate = BigDecimal.ZERO; + this.totalSavingsAmount = BigDecimal.ZERO; + this.interestAccrued = BigDecimal.ZERO; + + this.client = client; + this.externalId = externalId; + this.product = product; + this.savingsDepositAmountPerPeriod = savingsDeposit.getAmount(); + this.currency = savingsDeposit.getCurrency(); + this.reccuringInterestRate = reccuringInterestRate; + this.savingInterestRate = savingInterestRate; + this.tenure = tenure; + this.projectedCommencementDate = commencementDate.toDate(); + this.tenureType = tenureTypeEnum; + this.savingProductType = savingProductType; + this.frequency = savingFrequencyType; + this.interestType = interestType; + this.interestCalculationMethod = savingInterestCalculationMethod; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; + this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); + this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.getAmount().subtract( + BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue())); + } + + public void modifyAccount(SavingProduct product, String externalId, Money savingsDeposit, BigDecimal reccuringInterestRate, + BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, + SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, + SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod, + PeriodFrequencyType lockinPeriodType, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator) { + + Money futureValueOnMaturity = null; + if (savingProductType.isReccuring()) { + futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, + reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); + } else if (savingProductType.isRegular()) { + futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, + savingInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod); + } + + this.product = product; + this.externalId = externalId; + this.savingsDepositAmountPerPeriod = savingsDeposit.getAmount(); + this.reccuringInterestRate = reccuringInterestRate; + this.savingInterestRate = savingInterestRate; + this.tenure = tenure; + this.projectedCommencementDate = commencementDate.toDate(); + this.tenureType = tenureTypeEnum; + this.savingProductType = savingProductType; + this.frequency = savingFrequencyType; + this.interestCalculationMethod = savingInterestCalculationMethod; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; + + // FIXME - MADHUKAR - futureValueOnMaturity is possibly null + this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); + this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.getAmount().subtract( + BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue())); + } + + public boolean isDeleted() { + return this.deleted; + } + + public boolean isPendingApproval() { + return this.accountStatus.equals(100); + } + + public Client getClient() { + return client; + } + + public SavingProduct getProduct() { + return product; + } + + public SavingProductType getSavingProductType() { + return savingProductType; + } + + public String getExternalId() { + return externalId; + } + + public BigDecimal getSavingsDepositAmountPerPeriod() { + return savingsDepositAmountPerPeriod; + } + + public BigDecimal getReccuringInterestRate() { + return reccuringInterestRate; + } + + public BigDecimal getSavingInterestRate() { + return savingInterestRate; + } + + public Integer getTenure() { + return tenure; + } + + public TenureTypeEnum getTenureType() { + return tenureType; + } + + public SavingFrequencyType getFrequency() { + return frequency; + } + + public SavingsInterestType getInterestType() { + return interestType; + } + + public SavingInterestCalculationMethod getInterestCalculationMethod() { + return interestCalculationMethod; + } + + public Date getProjectedCommencementDate() { + return projectedCommencementDate; + } + + public BigDecimal getPreClosureInterestRate() { + return preClosureInterestRate; + } + + public boolean isPreClosureAllowed() { + return preClosureAllowed; + } + + public Date getWithdrawnOnDate() { + return withdrawnOnDate; + } + + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } + + public Integer getLockinPeriod() { + return lockinPeriod; + } + + public PeriodFrequencyType getLockinPeriodType() { + return lockinPeriodType; + } + + public void addSavingScheduleInstallment(final SavingScheduleInstallments installment) { + installment.updateAccount(this); + this.savingScheduleInstallments.add(installment); + } - public PeriodFrequencyType getLockinPeriodType() { - return lockinPeriodType; - } - - public void addSavingScheduleInstallment(final SavingScheduleInstallments installment) { - installment.updateAccount(this); - this.savingScheduleInstallments.add(installment); - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java index a65b7f432..e36eff016 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java @@ -3,8 +3,6 @@ package org.mifosplatform.portfolio.savingsaccount.domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -public interface SavingAccountRepository extends -JpaRepository, -JpaSpecificationExecutor{ +public interface SavingAccountRepository extends JpaRepository, JpaSpecificationExecutor { } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingScheduleInstallments.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingScheduleInstallments.java index 5f8390510..8ac6be384 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingScheduleInstallments.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingScheduleInstallments.java @@ -15,46 +15,45 @@ import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom; import org.mifosplatform.useradministration.domain.AppUser; @Entity -@Table(name="m_saving_schedule") +@Table(name = "m_saving_schedule") public class SavingScheduleInstallments extends AbstractAuditableCustom { - - @ManyToOne(optional = false) - @JoinColumn(name = "saving_account_id", nullable=false) - private SavingAccount savingAccount; - - @Temporal(TemporalType.DATE) - @Column(name = "duedate", nullable=false) - private final Date dueDate; - - @Column(name = "installment", nullable=false) - private final Integer installmentNumber; - - @Column(name = "deposit", scale=6, precision=19, nullable=false) - private BigDecimal deposit; - - @Temporal(TemporalType.DATE) - @Column(name = "payment_date", nullable=true) - private final Date paymentDate; - - @Column(name = "deposit_paid", scale=6, precision=19, nullable=true) - private BigDecimal depositPaid; - - @Column(name="completed_derived", nullable=false) + + @ManyToOne(optional = false) + @JoinColumn(name = "saving_account_id", nullable = false) + private SavingAccount savingAccount; + + @Temporal(TemporalType.DATE) + @Column(name = "duedate", nullable = false) + private final Date dueDate; + + @Column(name = "installment", nullable = false) + private final Integer installmentNumber; + + @Column(name = "deposit", scale = 6, precision = 19, nullable = false) + private BigDecimal deposit; + + @Temporal(TemporalType.DATE) + @Column(name = "payment_date", nullable = true) + private final Date paymentDate; + + @Column(name = "deposit_paid", scale = 6, precision = 19, nullable = true) + private BigDecimal depositPaid; + + @Column(name = "completed_derived", nullable = false) private boolean completed; - - public SavingScheduleInstallments(SavingAccount account, Date dueDate, - Integer installmentNumber, BigDecimal deposit) { - this.savingAccount = account; - this.dueDate = dueDate; - this.installmentNumber = installmentNumber; - this.deposit = deposit; - this.paymentDate = null; - this.depositPaid = BigDecimal.ZERO; - this.completed = false; - } - - public void updateAccount(SavingAccount account){ - this.savingAccount = account; - } + + public SavingScheduleInstallments(SavingAccount account, Date dueDate, Integer installmentNumber, BigDecimal deposit) { + this.savingAccount = account; + this.dueDate = dueDate; + this.installmentNumber = installmentNumber; + this.deposit = deposit; + this.paymentDate = null; + this.depositPaid = BigDecimal.ZERO; + this.completed = false; + } + + public void updateAccount(SavingAccount account) { + this.savingAccount = account; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/exception/SavingAccountNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/exception/SavingAccountNotFoundException.java index ba2cdf1f9..74becff2d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/exception/SavingAccountNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/exception/SavingAccountNotFoundException.java @@ -4,8 +4,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN public class SavingAccountNotFoundException extends AbstractPlatformResourceNotFoundException { - public SavingAccountNotFoundException(final Long id) { - super("error.msg.saving.account.id.invalid", "Saving account with identifier " + id + " does not exist", id); - } - -} + public SavingAccountNotFoundException(final Long id) { + super("error.msg.saving.account.id.invalid", "Saving account with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingSchedule.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingSchedule.java index 9a75093f5..f0ed31f82 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingSchedule.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingSchedule.java @@ -4,7 +4,6 @@ import org.mifosplatform.portfolio.savingsaccount.command.CalculateSavingSchedul import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData; public interface CalculateSavingSchedule { - - SavingScheduleData calculateSavingSchedule(CalculateSavingScheduleCommand command); -} + SavingScheduleData calculateSavingSchedule(CalculateSavingScheduleCommand command); +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingScheduleImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingScheduleImpl.java index 3d5baaa3c..d6953ac50 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingScheduleImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/CalculateSavingScheduleImpl.java @@ -17,46 +17,44 @@ import org.springframework.stereotype.Service; @Service public class CalculateSavingScheduleImpl implements CalculateSavingSchedule { - - private final PlatformSecurityContext context; - private final SavingProductRepository savingProductRepository; - private final SavingScheduleGenerator savingScheduleGenerator; - private final ApplicationCurrencyRepository applicationCurrencyRepository; - - @Autowired - public CalculateSavingScheduleImpl( - final PlatformSecurityContext context, - final SavingProductRepository savingProductRepository, - final ApplicationCurrencyRepository applicationCurrencyRepository) { - this.context = context; - this.savingProductRepository = savingProductRepository; - this.savingScheduleGenerator = new SavingScheduleGenerator(); - this.applicationCurrencyRepository = applicationCurrencyRepository; - } - @Override - public SavingScheduleData calculateSavingSchedule(CalculateSavingScheduleCommand command) { - - context.authenticatedUser(); - - // FIXME Validations should write here - final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId()); - if (savingProduct == null) - throw new SavingProductNotFoundException(command.getProductId()); - - final Integer depositFrequency = command.getPayEvery(); - final PeriodFrequencyType depositFrequencyType = PeriodFrequencyType.fromInt(command.getPaymentFrequencyType()); - final LocalDate scheduleStartDate = command.getPaymentsStartingFromDate(); - @SuppressWarnings("unused") - final BigDecimal interestRate = command.getInterestRate(); - final BigDecimal depositAmountPerPeriod = command.getDeposit(); - final Integer tenure = command.getTenure(); - final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneByCode(savingProduct.getCurrency().getCode()); - - SavingScheduleData savingScheduleData = savingScheduleGenerator.generate(scheduleStartDate,depositAmountPerPeriod, - depositFrequency,depositFrequencyType,savingProduct,tenure,applicationCurrency); - - return savingScheduleData; - } + private final PlatformSecurityContext context; + private final SavingProductRepository savingProductRepository; + private final SavingScheduleGenerator savingScheduleGenerator; + private final ApplicationCurrencyRepository applicationCurrencyRepository; + + @Autowired + public CalculateSavingScheduleImpl(final PlatformSecurityContext context, final SavingProductRepository savingProductRepository, + final ApplicationCurrencyRepository applicationCurrencyRepository) { + this.context = context; + this.savingProductRepository = savingProductRepository; + this.savingScheduleGenerator = new SavingScheduleGenerator(); + this.applicationCurrencyRepository = applicationCurrencyRepository; + } + + @Override + public SavingScheduleData calculateSavingSchedule(CalculateSavingScheduleCommand command) { + + context.authenticatedUser(); + + // FIXME Validations should write here + final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId()); + if (savingProduct == null) throw new SavingProductNotFoundException(command.getProductId()); + + final Integer depositFrequency = command.getPayEvery(); + final PeriodFrequencyType depositFrequencyType = PeriodFrequencyType.fromInt(command.getPaymentFrequencyType()); + final LocalDate scheduleStartDate = command.getPaymentsStartingFromDate(); + @SuppressWarnings("unused") + final BigDecimal interestRate = command.getInterestRate(); + final BigDecimal depositAmountPerPeriod = command.getDeposit(); + final Integer tenure = command.getTenure(); + final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneByCode(savingProduct.getCurrency() + .getCode()); + + SavingScheduleData savingScheduleData = savingScheduleGenerator.generate(scheduleStartDate, depositAmountPerPeriod, + depositFrequency, depositFrequencyType, savingProduct, tenure, applicationCurrency); + + return savingScheduleData; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/DefaultDepositScheduleDateGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/DefaultDepositScheduleDateGenerator.java index f236fa984..e9712fd63 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/DefaultDepositScheduleDateGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/DefaultDepositScheduleDateGenerator.java @@ -7,41 +7,42 @@ import org.joda.time.LocalDate; import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType; import org.mifosplatform.portfolio.savingsaccount.domain.DepositScheduleDateGenerator; -public class DefaultDepositScheduleDateGenerator implements DepositScheduleDateGenerator { +public class DefaultDepositScheduleDateGenerator implements DepositScheduleDateGenerator { - @Override - public List generate(LocalDate scheuleStartDate, Integer paymentPeriods, Integer depositFrequency, PeriodFrequencyType depositFrequencyType) { - - List duePaymentPeriodDates = new ArrayList(depositFrequency); - LocalDate startDate = scheuleStartDate; - - for (int period=1; period <= paymentPeriods; period++){ - - LocalDate duePaymentPeriodDate = startDate; - if (period == 1) { - duePaymentPeriodDate = startDate; - } else { - switch (depositFrequencyType) { - case DAYS: - duePaymentPeriodDate = startDate.plusDays(depositFrequency); - break; - case WEEKS: - duePaymentPeriodDate = startDate.plusWeeks(depositFrequency); - break; - case MONTHS: - duePaymentPeriodDate = startDate.plusMonths(depositFrequency); - break; - case YEARS: - duePaymentPeriodDate = startDate.plusYears(depositFrequency); - break; - case INVALID: - break; - } - } - duePaymentPeriodDates.add(duePaymentPeriodDate); - startDate = duePaymentPeriodDate; - } - - return duePaymentPeriodDates; - } + @Override + public List generate(LocalDate scheuleStartDate, Integer paymentPeriods, Integer depositFrequency, + PeriodFrequencyType depositFrequencyType) { + + List duePaymentPeriodDates = new ArrayList(depositFrequency); + LocalDate startDate = scheuleStartDate; + + for (int period = 1; period <= paymentPeriods; period++) { + + LocalDate duePaymentPeriodDate = startDate; + if (period == 1) { + duePaymentPeriodDate = startDate; + } else { + switch (depositFrequencyType) { + case DAYS: + duePaymentPeriodDate = startDate.plusDays(depositFrequency); + break; + case WEEKS: + duePaymentPeriodDate = startDate.plusWeeks(depositFrequency); + break; + case MONTHS: + duePaymentPeriodDate = startDate.plusMonths(depositFrequency); + break; + case YEARS: + duePaymentPeriodDate = startDate.plusYears(depositFrequency); + break; + case INVALID: + break; + } + } + duePaymentPeriodDates.add(duePaymentPeriodDate); + startDate = duePaymentPeriodDate; + } + + return duePaymentPeriodDates; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java index 4f46a6d59..326063393 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java @@ -33,191 +33,186 @@ import org.springframework.stereotype.Service; @Service public class SavingAccountAssembler { - - private final ClientRepository clientRepository; - private final SavingProductRepository savingProductRepository; - private final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator; - private final CalculateSavingSchedule calculateSavingSchedule; - - @Autowired - public SavingAccountAssembler(final ClientRepository clientRepository,final SavingProductRepository savingProductRepository, - final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,final CalculateSavingSchedule calculateSavingSchedule) { - this.clientRepository=clientRepository; - this.savingProductRepository=savingProductRepository; - this.reccuringDepositInterestCalculator=reccuringDepositInterestCalculator; - this.calculateSavingSchedule = calculateSavingSchedule; - } - //minimumBalanceForWithdrawal,isPartialDepositAllowed - public SavingAccount assembleFrom(SavingAccountCommand command){ - - Client client = this.clientRepository.findOne(command.getClientId()); - if (client == null || client.isDeleted()) { - throw new ClientNotFoundException(command.getClientId()); - } - - SavingProduct product=this.savingProductRepository.findOne(command.getProductId()); - if(product == null || product.isDeleted()){ - throw new SavingProductNotFoundException(command.getProductId()); - } - - MonetaryCurrency currency = product.getCurrency(); - if(command.getCurrencyCode() != null && command.getDigitsAfterDecimal() != null){ - currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal()); - } - - Money savingsDeposit = Money.of(currency, command.getSavingsDepositAmount()); - - Integer tenure = product.getSavingProductRelatedDetail().getTenure(); - if(command.getTenure() != null){ - tenure=command.getTenure(); - } - - TenureTypeEnum tenureTypeEnum=product.getSavingProductRelatedDetail().getTenureType(); - if (command.getTenureType() != null) { - tenureTypeEnum = TenureTypeEnum.fromInt(command.getTenureType()); - } - - SavingProductType savingProductType= product.getSavingProductRelatedDetail().getSavingProductType(); - if(command.getSavingProductType() != null){ - savingProductType = SavingProductType.fromInt(command.getSavingProductType()); - } - - SavingFrequencyType savingFrequencyType = product.getSavingProductRelatedDetail().getFrequency(); - if (command.getFrequency() != null) { - savingFrequencyType = SavingFrequencyType.fromInt(command.getFrequency()); - } - - SavingInterestCalculationMethod savingInterestCalculationMethod = product.getSavingProductRelatedDetail().getInterestCalculationMethod(); - if (command.getInterestCalculationMethod() != null) { - savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); - } - - SavingsInterestType interestType = product.getSavingProductRelatedDetail().getInterestType(); - if (command.getInterestType() != null) { - interestType = SavingsInterestType.fromInt(command.getInterestType()); - } - - BigDecimal reccuringInterestRate = command.getRecurringInterestRate(); - BigDecimal savingInterestRate = product.getInterestRate(); - if(command.getSavingInterestRate() != null) - savingInterestRate = command.getSavingInterestRate(); - - boolean isLockinPeriodAllowed = product.getSavingProductRelatedDetail().isLockinPeriodAllowed(); - if(command.isLockinPeriodChanged()){ - isLockinPeriodAllowed = command.isLockinPeriodAllowed(); - } - - Integer lockinPeriod = product.getSavingProductRelatedDetail().getLockinPeriod(); - if(command.getLockinPeriod() != null){ - lockinPeriod = command.getLockinPeriod(); - } - - PeriodFrequencyType lockinPeriodType = product.getSavingProductRelatedDetail().getLockinPeriodType(); - if(command.getLockinPeriodType() != null){ - lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - } - - SavingAccount account = SavingAccount.openNew(client, product, command.getExternalId(),savingsDeposit, - reccuringInterestRate,savingInterestRate,tenure,command.getCommencementDate(),tenureTypeEnum, savingProductType, - savingFrequencyType, interestType, savingInterestCalculationMethod, isLockinPeriodAllowed,lockinPeriod, lockinPeriodType, - this.reccuringDepositInterestCalculator, defaultDepositLifecycleStateMachine()); - - SavingScheduleData savingScheduleData = this.calculateSavingSchedule.calculateSavingSchedule(command.toCalculateSavingScheduleCommand()); - for(SavingSchedulePeriodData savingSchedulePeriodData : savingScheduleData.getPeriods()){ - - final SavingScheduleInstallments installment = new SavingScheduleInstallments( - account, - savingSchedulePeriodData.getDueDate().toDate(), - savingSchedulePeriodData.getPeriod(), - savingSchedulePeriodData.getDepositDue()); - account.addSavingScheduleInstallment(installment); - } - - return account; - } - public void assembleFrom(SavingAccountCommand command, SavingAccount account) { - - SavingProduct product=account.getProduct(); - if(command.isProductIdChanged()){ - if(product.getId() != command.getProductId()){ - product = this.savingProductRepository.findOne(command.getProductId()); - if(product == null || product.isDeleted()) - throw new SavingProductNotFoundException(command.getProductId()); - } - } - - String externalId = account.getExternalId(); - if(command.isExternalIdChanged()){ - externalId = command.getExternalId(); - } - - Money savingsDeposit = Money.of(product.getCurrency(), account.getSavingsDepositAmountPerPeriod()); - if(command.isDepositAmountChanged()){ - savingsDeposit = Money.of(product.getCurrency(), command.getSavingsDepositAmount()); - } - Integer tenure = account.getTenure(); - if(command.isTenureInMonthsChanged()){ - tenure = command.getTenure(); - } - - LocalDate commencementDate = new LocalDate(account.getProjectedCommencementDate()); - if (command.isCommencementDateChanged()) { - commencementDate = command.getCommencementDate(); - } - - TenureTypeEnum tenureTypeEnum=account.getTenureType(); - if(command.isTenureTypeEnumChanged()){ - tenureTypeEnum = TenureTypeEnum.fromInt(command.getTenureType()); - } - - SavingProductType savingProductType= account.getSavingProductType(); - if (command.isSavingProductTypeChanged()) { - savingProductType = SavingProductType.fromInt(command.getSavingProductType()); - } - - SavingFrequencyType savingFrequencyType = account.getFrequency(); - if (command.isSavingFrequencyTypeChanged()) { - savingFrequencyType = SavingFrequencyType.fromInt(command.getFrequency()); - } - - SavingInterestCalculationMethod savingInterestCalculationMethod =account.getInterestCalculationMethod(); - if (command.isSavingInterestCalculationMethodChanged()) { - savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); - } - - BigDecimal reccuringInterestRate = account.getReccuringInterestRate(); - if (command.isReccuringInterestRateChanged()) { - reccuringInterestRate = command.getRecurringInterestRate(); - } - - BigDecimal savingInterestRate = account.getSavingInterestRate(); - if (command.isSavingInterestRateChanged()) { - savingInterestRate = command.getSavingInterestRate(); - } - - boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); - if (command.isLockinPeriodAllowedChanged()) { - isLockinPeriodAllowed = command.isLockinPeriodAllowed(); - } - - Integer lockinPeriod =account.getLockinPeriod(); - if (command.isLockinPeriodChanged()) { - lockinPeriod = command.getLockinPeriod(); - } - - PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); - if (command.isLockinPeriodTypeChanged()) { - lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - } - account.modifyAccount(product, externalId, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure, - commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, savingInterestCalculationMethod, - isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, this.reccuringDepositInterestCalculator); - - } - - private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() { - List allowedDepositStatuses = Arrays.asList(DepositAccountStatus.values()); - return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); - } + private final ClientRepository clientRepository; + private final SavingProductRepository savingProductRepository; + private final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator; + private final CalculateSavingSchedule calculateSavingSchedule; + + @Autowired + public SavingAccountAssembler(final ClientRepository clientRepository, final SavingProductRepository savingProductRepository, + final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, + final CalculateSavingSchedule calculateSavingSchedule) { + this.clientRepository = clientRepository; + this.savingProductRepository = savingProductRepository; + this.reccuringDepositInterestCalculator = reccuringDepositInterestCalculator; + this.calculateSavingSchedule = calculateSavingSchedule; + } + + // minimumBalanceForWithdrawal,isPartialDepositAllowed + public SavingAccount assembleFrom(SavingAccountCommand command) { + + Client client = this.clientRepository.findOne(command.getClientId()); + if (client == null || client.isDeleted()) { throw new ClientNotFoundException(command.getClientId()); } + + SavingProduct product = this.savingProductRepository.findOne(command.getProductId()); + if (product == null || product.isDeleted()) { throw new SavingProductNotFoundException(command.getProductId()); } + + MonetaryCurrency currency = product.getCurrency(); + if (command.getCurrencyCode() != null && command.getDigitsAfterDecimal() != null) { + currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal()); + } + + Money savingsDeposit = Money.of(currency, command.getSavingsDepositAmount()); + + Integer tenure = product.getSavingProductRelatedDetail().getTenure(); + if (command.getTenure() != null) { + tenure = command.getTenure(); + } + + TenureTypeEnum tenureTypeEnum = product.getSavingProductRelatedDetail().getTenureType(); + if (command.getTenureType() != null) { + tenureTypeEnum = TenureTypeEnum.fromInt(command.getTenureType()); + } + + SavingProductType savingProductType = product.getSavingProductRelatedDetail().getSavingProductType(); + if (command.getSavingProductType() != null) { + savingProductType = SavingProductType.fromInt(command.getSavingProductType()); + } + + SavingFrequencyType savingFrequencyType = product.getSavingProductRelatedDetail().getFrequency(); + if (command.getFrequency() != null) { + savingFrequencyType = SavingFrequencyType.fromInt(command.getFrequency()); + } + + SavingInterestCalculationMethod savingInterestCalculationMethod = product.getSavingProductRelatedDetail() + .getInterestCalculationMethod(); + if (command.getInterestCalculationMethod() != null) { + savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); + } + + SavingsInterestType interestType = product.getSavingProductRelatedDetail().getInterestType(); + if (command.getInterestType() != null) { + interestType = SavingsInterestType.fromInt(command.getInterestType()); + } + + BigDecimal reccuringInterestRate = command.getRecurringInterestRate(); + BigDecimal savingInterestRate = product.getInterestRate(); + if (command.getSavingInterestRate() != null) savingInterestRate = command.getSavingInterestRate(); + + boolean isLockinPeriodAllowed = product.getSavingProductRelatedDetail().isLockinPeriodAllowed(); + if (command.isLockinPeriodChanged()) { + isLockinPeriodAllowed = command.isLockinPeriodAllowed(); + } + + Integer lockinPeriod = product.getSavingProductRelatedDetail().getLockinPeriod(); + if (command.getLockinPeriod() != null) { + lockinPeriod = command.getLockinPeriod(); + } + + PeriodFrequencyType lockinPeriodType = product.getSavingProductRelatedDetail().getLockinPeriodType(); + if (command.getLockinPeriodType() != null) { + lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + } + + SavingAccount account = SavingAccount.openNew(client, product, command.getExternalId(), savingsDeposit, reccuringInterestRate, + savingInterestRate, tenure, command.getCommencementDate(), tenureTypeEnum, savingProductType, savingFrequencyType, + interestType, savingInterestCalculationMethod, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, + this.reccuringDepositInterestCalculator, defaultDepositLifecycleStateMachine()); + + SavingScheduleData savingScheduleData = this.calculateSavingSchedule.calculateSavingSchedule(command + .toCalculateSavingScheduleCommand()); + for (SavingSchedulePeriodData savingSchedulePeriodData : savingScheduleData.getPeriods()) { + + final SavingScheduleInstallments installment = new SavingScheduleInstallments(account, savingSchedulePeriodData.getDueDate() + .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue()); + account.addSavingScheduleInstallment(installment); + } + + return account; + } + + public void assembleFrom(SavingAccountCommand command, SavingAccount account) { + + SavingProduct product = account.getProduct(); + if (command.isProductIdChanged()) { + if (product.getId() != command.getProductId()) { + product = this.savingProductRepository.findOne(command.getProductId()); + if (product == null || product.isDeleted()) throw new SavingProductNotFoundException(command.getProductId()); + } + } + + String externalId = account.getExternalId(); + if (command.isExternalIdChanged()) { + externalId = command.getExternalId(); + } + + Money savingsDeposit = Money.of(product.getCurrency(), account.getSavingsDepositAmountPerPeriod()); + if (command.isDepositAmountChanged()) { + savingsDeposit = Money.of(product.getCurrency(), command.getSavingsDepositAmount()); + } + Integer tenure = account.getTenure(); + if (command.isTenureInMonthsChanged()) { + tenure = command.getTenure(); + } + + LocalDate commencementDate = new LocalDate(account.getProjectedCommencementDate()); + if (command.isCommencementDateChanged()) { + commencementDate = command.getCommencementDate(); + } + + TenureTypeEnum tenureTypeEnum = account.getTenureType(); + if (command.isTenureTypeEnumChanged()) { + tenureTypeEnum = TenureTypeEnum.fromInt(command.getTenureType()); + } + + SavingProductType savingProductType = account.getSavingProductType(); + if (command.isSavingProductTypeChanged()) { + savingProductType = SavingProductType.fromInt(command.getSavingProductType()); + } + + SavingFrequencyType savingFrequencyType = account.getFrequency(); + if (command.isSavingFrequencyTypeChanged()) { + savingFrequencyType = SavingFrequencyType.fromInt(command.getFrequency()); + } + + SavingInterestCalculationMethod savingInterestCalculationMethod = account.getInterestCalculationMethod(); + if (command.isSavingInterestCalculationMethodChanged()) { + savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); + } + + BigDecimal reccuringInterestRate = account.getReccuringInterestRate(); + if (command.isReccuringInterestRateChanged()) { + reccuringInterestRate = command.getRecurringInterestRate(); + } + + BigDecimal savingInterestRate = account.getSavingInterestRate(); + if (command.isSavingInterestRateChanged()) { + savingInterestRate = command.getSavingInterestRate(); + } + + boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); + if (command.isLockinPeriodAllowedChanged()) { + isLockinPeriodAllowed = command.isLockinPeriodAllowed(); + } + + Integer lockinPeriod = account.getLockinPeriod(); + if (command.isLockinPeriodChanged()) { + lockinPeriod = command.getLockinPeriod(); + } + + PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); + if (command.isLockinPeriodTypeChanged()) { + lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + } + account.modifyAccount(product, externalId, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure, commencementDate, + tenureTypeEnum, savingProductType, savingFrequencyType, savingInterestCalculationMethod, isLockinPeriodAllowed, + lockinPeriod, lockinPeriodType, this.reccuringDepositInterestCalculator); + + } + + private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() { + List allowedDepositStatuses = Arrays.asList(DepositAccountStatus.values()); + return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java index 9733fc603..3f916c876 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java @@ -14,31 +14,27 @@ import org.springframework.stereotype.Service; @Service public class SavingProductRelatedDetailAssembler { - - private final SavingProductRepository savingProductRepository; - - @Autowired - public SavingProductRelatedDetailAssembler(final SavingProductRepository savingProductRepository) { - this.savingProductRepository = savingProductRepository; - } - public SavingProductRelatedDetail assembleFrom(CalculateSavingScheduleCommand command) { - - final BigDecimal depositAmountForPeriod = command.getDeposit(); - final BigDecimal depositInterestRate = command.getInterestRate(); - final LocalDate installmentDate = command.getPaymentsStartingFromDate(); - final Integer payEvery = command.getPayEvery(); - final Integer paymentFrequencyType = command.getPaymentFrequencyType(); - final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId()); - if (savingProduct == null) { - throw new SavingProductNotFoundException(command.getProductId()); - } - - final MonetaryCurrency currency = savingProduct.getCurrency(); - - return null; - } - - + private final SavingProductRepository savingProductRepository; + + @Autowired + public SavingProductRelatedDetailAssembler(final SavingProductRepository savingProductRepository) { + this.savingProductRepository = savingProductRepository; + } + + public SavingProductRelatedDetail assembleFrom(CalculateSavingScheduleCommand command) { + + final BigDecimal depositAmountForPeriod = command.getDeposit(); + final BigDecimal depositInterestRate = command.getInterestRate(); + final LocalDate installmentDate = command.getPaymentsStartingFromDate(); + final Integer payEvery = command.getPayEvery(); + final Integer paymentFrequencyType = command.getPaymentFrequencyType(); + final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId()); + if (savingProduct == null) { throw new SavingProductNotFoundException(command.getProductId()); } + + final MonetaryCurrency currency = savingProduct.getCurrency(); + + return null; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingScheduleGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingScheduleGenerator.java index b96b33942..c569817d7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingScheduleGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingScheduleGenerator.java @@ -17,42 +17,35 @@ import org.mifosplatform.portfolio.savingsaccount.domain.DepositScheduleDateGene import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProduct; public class SavingScheduleGenerator { - - private final DepositScheduleDateGenerator scheduledDateGenerator = new DefaultDepositScheduleDateGenerator(); - public SavingScheduleData generate( - final LocalDate scheduleStartDate, - final BigDecimal depositAmountPerPeriod, - final Integer depositFrequency, - final PeriodFrequencyType depositFrequencyType, - final SavingProduct savingProduct, - final Integer tenure, - final ApplicationCurrency applicationCurrency) { - - LocalDate startDate = scheduleStartDate; - int periodNumber = 1; - - Integer paymentPeriods = tenure/depositFrequency; - final Collection periods = new ArrayList(); - final List scheduledDates = this.scheduledDateGenerator.generate(startDate,paymentPeriods,depositFrequency,depositFrequencyType); - final MonetaryCurrency currency = savingProduct.getCurrency(); - final Money depositAmount = Money.of(currency, depositAmountPerPeriod); - Money totalDeposit = Money.zero(currency); - - for(LocalDate scheduleDate : scheduledDates){ - totalDeposit = totalDeposit.plus(depositAmount); - SavingSchedulePeriodData installment = SavingSchedulePeriodData.addScheduleInformation(periodNumber, scheduleDate, depositAmount.getAmount()); - periods.add(installment); - periodNumber++; - } - CurrencyData currencyData = new CurrencyData( - applicationCurrency.getCode(), - applicationCurrency.getName(), - currency.getDigitsAfterDecimal(), - applicationCurrency.getDisplaySymbol(), - applicationCurrency.getNameCode()); - - return new SavingScheduleData(currencyData, totalDeposit.getAmount(), periods); - } + private final DepositScheduleDateGenerator scheduledDateGenerator = new DefaultDepositScheduleDateGenerator(); + + public SavingScheduleData generate(final LocalDate scheduleStartDate, final BigDecimal depositAmountPerPeriod, + final Integer depositFrequency, final PeriodFrequencyType depositFrequencyType, final SavingProduct savingProduct, + final Integer tenure, final ApplicationCurrency applicationCurrency) { + + LocalDate startDate = scheduleStartDate; + int periodNumber = 1; + + Integer paymentPeriods = tenure / depositFrequency; + final Collection periods = new ArrayList(); + final List scheduledDates = this.scheduledDateGenerator.generate(startDate, paymentPeriods, depositFrequency, + depositFrequencyType); + final MonetaryCurrency currency = savingProduct.getCurrency(); + final Money depositAmount = Money.of(currency, depositAmountPerPeriod); + Money totalDeposit = Money.zero(currency); + + for (LocalDate scheduleDate : scheduledDates) { + totalDeposit = totalDeposit.plus(depositAmount); + SavingSchedulePeriodData installment = SavingSchedulePeriodData.addScheduleInformation(periodNumber, scheduleDate, + depositAmount.getAmount()); + periods.add(installment); + periodNumber++; + } + CurrencyData currencyData = new CurrencyData(applicationCurrency.getCode(), applicationCurrency.getName(), + currency.getDigitsAfterDecimal(), applicationCurrency.getDisplaySymbol(), applicationCurrency.getNameCode()); + + return new SavingScheduleData(currencyData, totalDeposit.getAmount(), periods); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java index 69bd87652..055a2b3a7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java @@ -46,165 +46,168 @@ import org.springframework.stereotype.Component; @Component @Scope("singleton") public class SavingProductsApiResource { - - @Autowired - private SavingProductReadPlatformService savingProductReadPlatformService; - - @Autowired - private SavingProductWritePlatformService savingProductWritePlatformService; - @Autowired - private PortfolioApiDataConversionService apiDataConversionService; - + @Autowired + private SavingProductReadPlatformService savingProductReadPlatformService; + + @Autowired + private SavingProductWritePlatformService savingProductWritePlatformService; + + @Autowired + private PortfolioApiDataConversionService apiDataConversionService; + @Autowired private PortfolioApiJsonSerializerService apiJsonSerializerService; - + @Autowired - private CurrencyReadPlatformService currencyReadPlatformService; + private CurrencyReadPlatformService currencyReadPlatformService; - private final String entityType = "SAVINGSPRODUCT"; - @Autowired - private PlatformSecurityContext context; - - @POST - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response createSavingProduct(final String jsonRequestBody){ - - final SavingProductCommand command=this.apiDataConversionService.convertJsonToSavingProductCommand(null, jsonRequestBody); - - EntityIdentifier entityIdentifier=this.savingProductWritePlatformService.createSavingProduct(command); - - return Response.ok().entity(entityIdentifier).build(); - } - - @PUT - @Path("{productId}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response updateSavingProduct(@PathParam("productId") final Long productId, final String jsonRequestBody){ - - SavingProductCommand command=this.apiDataConversionService.convertJsonToSavingProductCommand(productId, jsonRequestBody); - EntityIdentifier entityIdentifier=this.savingProductWritePlatformService.updateSavingProduct(command); - return Response.ok().entity(entityIdentifier).build(); - } - - @GET - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String retrieveAllSavingProducts(@Context final UriInfo uriInfo) { + private final String entityType = "SAVINGSPRODUCT"; + @Autowired + private PlatformSecurityContext context; - context.authenticatedUser().validateHasReadPermission(entityType); - - Set typicalResponseParameters = new HashSet(Arrays.asList("id", "createdOn", "lastModifedOn", - "locale", "name", "description","currencyCode", "digitsAfterDecimal","interstRate", "minInterestRate","maxInterestRate", - "savingsDepositAmount","savingProductType","tenureType","tenure", "frequency","interestType","interestCalculationMethod", - "minimumBalanceForWithdrawal","isPartialDepositAllowed","isLockinPeriodAllowed","lockinPeriod","lockinPeriodType")); - - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + @POST + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response createSavingProduct(final String jsonRequestBody) { - Collection products = this.savingProductReadPlatformService.retrieveAllSavingProducts(); - - return this.apiJsonSerializerService.serializeSavingProductDataToJson(prettyPrint, responseParameters, products); - } - - @GET - @Path("{productId}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String retrieveSavingProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo) { + final SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(null, jsonRequestBody); - context.authenticatedUser().validateHasReadPermission(entityType); - - Set typicalResponseParameters = new HashSet(Arrays.asList("id", "createdOn", "lastModifedOn", - "locale", "name", "description","currencyCode", "digitsAfterDecimal","interstRate", "minInterestRate","maxInterestRate", - "savingsDepositAmount","savingProductType","tenureType","tenure", "frequency","interestType","interestCalculationMethod", - "minimumBalanceForWithdrawal","isPartialDepositAllowed","isLockinPeriodAllowed","lockinPeriod","lockinPeriodType")); - - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); - if (template) { - responseParameters.addAll(Arrays.asList("currencyOptions")); - } - - SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveSavingProduct(productId); - - return this.apiJsonSerializerService.serializeSavingProductDataToJson(prettyPrint, responseParameters, savingProduct); - } - - @GET - @Path("template") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public String retrieveNewSavingProductDetails(@Context final UriInfo uriInfo) { + EntityIdentifier entityIdentifier = this.savingProductWritePlatformService.createSavingProduct(command); - context.authenticatedUser().validateHasReadPermission(entityType); - - Set typicalResponseParameters = new HashSet( - Arrays.asList("id", "createdOn", "lastModifedOn", - "locale", "name", "description","currencyCode", "digitsAfterDecimal","interstRate", - "savingsDepositAmount","savingProductType","tenureType","tenure", "frequency","interestType","interestCalculationMethod", - "minimumBalanceForWithdrawal","isPartialDepositAllowed","isLockinPeriodAllowed","lockinPeriod","lockinPeriodType","currencyOptions")); - - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); - if (responseParameters.isEmpty()) { - responseParameters.addAll(typicalResponseParameters); - } - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + return Response.ok().entity(entityIdentifier).build(); + } - SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveNewSavingProductDetails(); - savingProduct = handleTemplateRelatedData(responseParameters,savingProduct); - return this.apiJsonSerializerService.serializeSavingProductDataToJson(prettyPrint, responseParameters, savingProduct); - } - - private SavingProductData handleTemplateRelatedData(Set responseParameters, SavingProductData savingProduct) { - - responseParameters.addAll(Arrays.asList("currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", "savingFrequencyOptions", "savingsInterestTypeOptions", - "lockinPeriodTypeOptions", "interestCalculationOptions")); - List currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies(); - - EnumOptionData reccuring = SavingProductEnumerations.savingProductType(SavingProductType.RECCURING); - EnumOptionData regular = SavingProductEnumerations.savingProductType(SavingProductType.REGULAR); - List savingsProductTypeOptions = Arrays.asList(reccuring,regular); - - EnumOptionData fixed = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.FIXED_PERIOD); - EnumOptionData perpetual = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.PERPETUAL); - List tenureTypeOptions = Arrays.asList(fixed,perpetual); - - EnumOptionData monthly = SavingProductEnumerations.interestFrequencyType(SavingFrequencyType.MONTHLY); - List savingFrequencyOptions = Arrays.asList(monthly); - - EnumOptionData simple = SavingProductEnumerations.savingInterestType(SavingsInterestType.SIMPLE); - EnumOptionData compounding = SavingProductEnumerations.savingInterestType(SavingsInterestType.COMPOUNDING); - List savingsInterestTypeOptions = Arrays.asList(simple,compounding); - - EnumOptionData months = SavingProductEnumerations.savingsLockinPeriod(SavingsLockinPeriodEnum.MONTHS); - List lockinPeriodTypeOptions = Arrays.asList(months); - - EnumOptionData averagebal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.AVERAGEBAL); - EnumOptionData minbal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MINBAL); - EnumOptionData monthlyCollection = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MONTHLYCOLLECTION); - List interestCalculationOptions= Arrays.asList(averagebal,minbal,monthlyCollection); - - return new SavingProductData(savingProduct,currencyOptions,savingsProductTypeOptions,tenureTypeOptions,savingFrequencyOptions,savingsInterestTypeOptions,lockinPeriodTypeOptions,interestCalculationOptions); - } + @PUT + @Path("{productId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response updateSavingProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) { - @DELETE - @Path("{productId}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response deleteProduct(@PathParam("productId") final Long productId) { + SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(productId, jsonRequestBody); + EntityIdentifier entityIdentifier = this.savingProductWritePlatformService.updateSavingProduct(command); + return Response.ok().entity(entityIdentifier).build(); + } - this.savingProductWritePlatformService.deleteSavingProduct(productId); + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveAllSavingProducts(@Context final UriInfo uriInfo) { - return Response.ok(new EntityIdentifier(productId)).build(); - } + context.authenticatedUser().validateHasReadPermission(entityType); + + Set typicalResponseParameters = new HashSet(Arrays.asList("id", "createdOn", "lastModifedOn", "locale", "name", + "description", "currencyCode", "digitsAfterDecimal", "interstRate", "minInterestRate", "maxInterestRate", + "savingsDepositAmount", "savingProductType", "tenureType", "tenure", "frequency", "interestType", + "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "isLockinPeriodAllowed", + "lockinPeriod", "lockinPeriodType")); + + Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + if (responseParameters.isEmpty()) { + responseParameters.addAll(typicalResponseParameters); + } + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + + Collection products = this.savingProductReadPlatformService.retrieveAllSavingProducts(); + + return this.apiJsonSerializerService.serializeSavingProductDataToJson(prettyPrint, responseParameters, products); + } + + @GET + @Path("{productId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveSavingProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo) { + + context.authenticatedUser().validateHasReadPermission(entityType); + + Set typicalResponseParameters = new HashSet(Arrays.asList("id", "createdOn", "lastModifedOn", "locale", "name", + "description", "currencyCode", "digitsAfterDecimal", "interstRate", "minInterestRate", "maxInterestRate", + "savingsDepositAmount", "savingProductType", "tenureType", "tenure", "frequency", "interestType", + "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "isLockinPeriodAllowed", + "lockinPeriod", "lockinPeriodType")); + + Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + if (responseParameters.isEmpty()) { + responseParameters.addAll(typicalResponseParameters); + } + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); + if (template) { + responseParameters.addAll(Arrays.asList("currencyOptions")); + } + + SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveSavingProduct(productId); + + return this.apiJsonSerializerService.serializeSavingProductDataToJson(prettyPrint, responseParameters, savingProduct); + } + + @GET + @Path("template") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveNewSavingProductDetails(@Context final UriInfo uriInfo) { + + context.authenticatedUser().validateHasReadPermission(entityType); + + Set typicalResponseParameters = new HashSet(Arrays.asList("id", "createdOn", "lastModifedOn", "locale", "name", + "description", "currencyCode", "digitsAfterDecimal", "interstRate", "savingsDepositAmount", "savingProductType", + "tenureType", "tenure", "frequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", + "isPartialDepositAllowed", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "currencyOptions")); + + Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); + if (responseParameters.isEmpty()) { + responseParameters.addAll(typicalResponseParameters); + } + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + + SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveNewSavingProductDetails(); + savingProduct = handleTemplateRelatedData(responseParameters, savingProduct); + return this.apiJsonSerializerService.serializeSavingProductDataToJson(prettyPrint, responseParameters, savingProduct); + } + + private SavingProductData handleTemplateRelatedData(Set responseParameters, SavingProductData savingProduct) { + + responseParameters.addAll(Arrays.asList("currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", + "savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions")); + List currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies(); + + EnumOptionData reccuring = SavingProductEnumerations.savingProductType(SavingProductType.RECCURING); + EnumOptionData regular = SavingProductEnumerations.savingProductType(SavingProductType.REGULAR); + List savingsProductTypeOptions = Arrays.asList(reccuring, regular); + + EnumOptionData fixed = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.FIXED_PERIOD); + EnumOptionData perpetual = SavingProductEnumerations.tenureTypeEnum(TenureTypeEnum.PERPETUAL); + List tenureTypeOptions = Arrays.asList(fixed, perpetual); + + EnumOptionData monthly = SavingProductEnumerations.interestFrequencyType(SavingFrequencyType.MONTHLY); + List savingFrequencyOptions = Arrays.asList(monthly); + + EnumOptionData simple = SavingProductEnumerations.savingInterestType(SavingsInterestType.SIMPLE); + EnumOptionData compounding = SavingProductEnumerations.savingInterestType(SavingsInterestType.COMPOUNDING); + List savingsInterestTypeOptions = Arrays.asList(simple, compounding); + + EnumOptionData months = SavingProductEnumerations.savingsLockinPeriod(SavingsLockinPeriodEnum.MONTHS); + List lockinPeriodTypeOptions = Arrays.asList(months); + + EnumOptionData averagebal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.AVERAGEBAL); + EnumOptionData minbal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MINBAL); + EnumOptionData monthlyCollection = SavingProductEnumerations + .savingInterestCalculationMethod(SavingInterestCalculationMethod.MONTHLYCOLLECTION); + List interestCalculationOptions = Arrays.asList(averagebal, minbal, monthlyCollection); + + return new SavingProductData(savingProduct, currencyOptions, savingsProductTypeOptions, tenureTypeOptions, savingFrequencyOptions, + savingsInterestTypeOptions, lockinPeriodTypeOptions, interestCalculationOptions); + } + + @DELETE + @Path("{productId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response deleteProduct(@PathParam("productId") final Long productId) { + + this.savingProductWritePlatformService.deleteSavingProduct(productId); + + return Response.ok(new EntityIdentifier(productId)).build(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java index 47a093cae..088189939 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java @@ -4,216 +4,210 @@ import java.math.BigDecimal; import java.util.Set; public class SavingProductCommand { - private final Long id; - private final String name; - private final String description; - private final String currencyCode; - private final Integer digitsAfterDecimal; - private final BigDecimal interestRate; - private final BigDecimal minInterestRate; - private final BigDecimal maxInterestRate; - - private final BigDecimal savingsDepositAmount; - private final Integer savingProductType; - private final Integer tenureType; - private final Integer tenure; - private final Integer frequency; - private final Integer interestType; - private final Integer interestCalculationMethod; - private final BigDecimal minimumBalanceForWithdrawal; - private final boolean isPartialDepositAllowed; - private final boolean isLockinPeriodAllowed; - private final Integer lockinPeriod; - private final Integer lockinPeriodType; - + private final Long id; + private final String name; + private final String description; - private final Set modifiedParameters; - - public SavingProductCommand(Set modifiedParameters, - Long id, String name, String description, - String currencyCode, Integer digitsAfterDecimal, - BigDecimal interestRate, BigDecimal minInterestRate, - BigDecimal maxInterestRate, BigDecimal savingsDepositAmount, - Integer savingProductType, Integer tenureType, Integer tenure, - Integer frequency, Integer interestType, - Integer interestCalculationMethod, - BigDecimal minimumBalanceForWithdrawal, - boolean isPartialDepositAllowed, boolean isLockinPeriodAllowed, - Integer lockinPeriod, Integer lockinPeriodType) { - - this.id = id; - this.name = name; - this.description = description; + private final String currencyCode; + private final Integer digitsAfterDecimal; + private final BigDecimal interestRate; + private final BigDecimal minInterestRate; + private final BigDecimal maxInterestRate; - this.currencyCode = currencyCode; - this.digitsAfterDecimal = digitsAfterDecimal; - this.interestRate = interestRate; - this.minInterestRate = minInterestRate; - this.maxInterestRate = maxInterestRate; - - this.savingsDepositAmount=savingsDepositAmount; - this.savingProductType=savingProductType; - this.tenureType=tenureType; - this.tenure=tenure; - this.frequency=frequency; - this.interestType=interestType; - this.interestCalculationMethod=interestCalculationMethod; - this.minimumBalanceForWithdrawal=minimumBalanceForWithdrawal; - this.isPartialDepositAllowed=isPartialDepositAllowed; - this.isLockinPeriodAllowed=isLockinPeriodAllowed; - this.lockinPeriod=lockinPeriod; - this.lockinPeriodType=lockinPeriodType; + private final BigDecimal savingsDepositAmount; + private final Integer savingProductType; + private final Integer tenureType; + private final Integer tenure; + private final Integer frequency; + private final Integer interestType; + private final Integer interestCalculationMethod; + private final BigDecimal minimumBalanceForWithdrawal; + private final boolean isPartialDepositAllowed; + private final boolean isLockinPeriodAllowed; + private final Integer lockinPeriod; + private final Integer lockinPeriodType; - this.modifiedParameters = modifiedParameters; - } + private final Set modifiedParameters; - public Long getId() { - return id; - } + public SavingProductCommand(Set modifiedParameters, Long id, String name, String description, String currencyCode, + Integer digitsAfterDecimal, BigDecimal interestRate, BigDecimal minInterestRate, BigDecimal maxInterestRate, + BigDecimal savingsDepositAmount, Integer savingProductType, Integer tenureType, Integer tenure, Integer frequency, + Integer interestType, Integer interestCalculationMethod, BigDecimal minimumBalanceForWithdrawal, + boolean isPartialDepositAllowed, boolean isLockinPeriodAllowed, Integer lockinPeriod, Integer lockinPeriodType) { - public String getName() { - return name; - } + this.id = id; + this.name = name; + this.description = description; - public String getDescription() { - return description; - } + this.currencyCode = currencyCode; + this.digitsAfterDecimal = digitsAfterDecimal; + this.interestRate = interestRate; + this.minInterestRate = minInterestRate; + this.maxInterestRate = maxInterestRate; - public String getCurrencyCode() { - return currencyCode; - } + this.savingsDepositAmount = savingsDepositAmount; + this.savingProductType = savingProductType; + this.tenureType = tenureType; + this.tenure = tenure; + this.frequency = frequency; + this.interestType = interestType; + this.interestCalculationMethod = interestCalculationMethod; + this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; + this.isPartialDepositAllowed = isPartialDepositAllowed; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; - public Integer getDigitsAfterDecimal() { - return digitsAfterDecimal; - } + this.modifiedParameters = modifiedParameters; + } - public BigDecimal getInterestRate() { - return interestRate; - } + public Long getId() { + return id; + } - public BigDecimal getMinInterestRate() { - return minInterestRate; - } + public String getName() { + return name; + } - public BigDecimal getMaxInterestRate() { - return maxInterestRate; - } + public String getDescription() { + return description; + } - public BigDecimal getSavingsDepositAmount() { - return savingsDepositAmount; - } + public String getCurrencyCode() { + return currencyCode; + } - public Integer getSavingProductType() { - return savingProductType; - } + public Integer getDigitsAfterDecimal() { + return digitsAfterDecimal; + } - public Integer getTenureType() { - return tenureType; - } + public BigDecimal getInterestRate() { + return interestRate; + } - public Integer getTenure() { - return tenure; - } + public BigDecimal getMinInterestRate() { + return minInterestRate; + } - public Integer getFrequency() { - return frequency; - } + public BigDecimal getMaxInterestRate() { + return maxInterestRate; + } - public Integer getInterestType() { - return interestType; - } + public BigDecimal getSavingsDepositAmount() { + return savingsDepositAmount; + } - public Integer getInterestCalculationMethod() { - return interestCalculationMethod; - } + public Integer getSavingProductType() { + return savingProductType; + } - public BigDecimal getMinimumBalanceForWithdrawal() { - return minimumBalanceForWithdrawal; - } + public Integer getTenureType() { + return tenureType; + } - public boolean isPartialDepositAllowed() { - return isPartialDepositAllowed; - } + public Integer getTenure() { + return tenure; + } - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + public Integer getFrequency() { + return frequency; + } - public Integer getLockinPeriod() { - return lockinPeriod; - } + public Integer getInterestType() { + return interestType; + } - public Integer getLockinPeriodType() { - return lockinPeriodType; - } + public Integer getInterestCalculationMethod() { + return interestCalculationMethod; + } - public boolean isNameChanged() { - return this.modifiedParameters.contains("name"); - } + public BigDecimal getMinimumBalanceForWithdrawal() { + return minimumBalanceForWithdrawal; + } - public boolean isDescriptionChanged() { - return this.modifiedParameters.contains("description"); - } - - public boolean isCurrencyCodeChanged() { - return this.modifiedParameters.contains("currencyCode"); - } + public boolean isPartialDepositAllowed() { + return isPartialDepositAllowed; + } - public boolean isDigitsAfterDecimalChanged() { - return this.modifiedParameters.contains("digitsAfterDecimal"); - } - - public boolean isInterestRateChanged() { - return this.modifiedParameters.contains("interestRate"); - } - - public boolean isSavingsDepositAmountChanged(){ - return this.modifiedParameters.contains("savingsDepositAmount"); - } - - public boolean isSavingProductTypeChanged() { - return this.modifiedParameters.contains("savingProductType"); - } + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } - public boolean isTenureTypeChanged() { - return this.modifiedParameters.contains("tenureType"); - } + public Integer getLockinPeriod() { + return lockinPeriod; + } - public boolean isTenureChanged() { - return this.modifiedParameters.contains("tenure"); - } + public Integer getLockinPeriodType() { + return lockinPeriodType; + } - public boolean isFrequencyChanged() { - return this.modifiedParameters.contains("frequency"); - } + public boolean isNameChanged() { + return this.modifiedParameters.contains("name"); + } - public boolean isInterestTypeChanged() { - return this.modifiedParameters.contains("interestType"); - } + public boolean isDescriptionChanged() { + return this.modifiedParameters.contains("description"); + } - public boolean isInterestCalculationMethodChanged() { - return this.modifiedParameters.contains("interestCalculationMethod"); - } + public boolean isCurrencyCodeChanged() { + return this.modifiedParameters.contains("currencyCode"); + } - public boolean isMinimumBalanceForWithdrawalChanged() { - return this.modifiedParameters.contains("minimumBalanceForWithdrawal"); - } + public boolean isDigitsAfterDecimalChanged() { + return this.modifiedParameters.contains("digitsAfterDecimal"); + } - public boolean isPartialDepositAllowedChanged() { - return this.modifiedParameters.contains("isPartialDepositAllowed"); - } + public boolean isInterestRateChanged() { + return this.modifiedParameters.contains("interestRate"); + } - public boolean isLockinPeriodAllowedChanged() { - return this.modifiedParameters.contains("isLockinPeriodAllowed"); - } + public boolean isSavingsDepositAmountChanged() { + return this.modifiedParameters.contains("savingsDepositAmount"); + } - public boolean isLockinPeriodChanged() { - return this.modifiedParameters.contains("lockinPeriod"); - } + public boolean isSavingProductTypeChanged() { + return this.modifiedParameters.contains("savingProductType"); + } + + public boolean isTenureTypeChanged() { + return this.modifiedParameters.contains("tenureType"); + } + + public boolean isTenureChanged() { + return this.modifiedParameters.contains("tenure"); + } + + public boolean isFrequencyChanged() { + return this.modifiedParameters.contains("frequency"); + } + + public boolean isInterestTypeChanged() { + return this.modifiedParameters.contains("interestType"); + } + + public boolean isInterestCalculationMethodChanged() { + return this.modifiedParameters.contains("interestCalculationMethod"); + } + + public boolean isMinimumBalanceForWithdrawalChanged() { + return this.modifiedParameters.contains("minimumBalanceForWithdrawal"); + } + + public boolean isPartialDepositAllowedChanged() { + return this.modifiedParameters.contains("isPartialDepositAllowed"); + } + + public boolean isLockinPeriodAllowedChanged() { + return this.modifiedParameters.contains("isLockinPeriodAllowed"); + } + + public boolean isLockinPeriodChanged() { + return this.modifiedParameters.contains("lockinPeriod"); + } + + public boolean isLockinPeriodTypeChanged() { + return this.modifiedParameters.contains("lockinPeriodType"); + } - public boolean isLockinPeriodTypeChanged() { - return this.modifiedParameters.contains("lockinPeriodType"); - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductData.java index 9f2fc979c..e5174dff4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductData.java @@ -11,260 +11,250 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData; public class SavingProductData implements Serializable { - private final Long id; - private final String name; - private final String description; - private final CurrencyData currency; - private final Integer digitsAfterDecimal; - - private final BigDecimal interestRate; - private final BigDecimal minInterestRate; - private final BigDecimal maxInterestRate; - private final BigDecimal savingsDepositAmount; - private final EnumOptionData savingProductType; - private final EnumOptionData tenureType; - private final Integer tenure; - private final EnumOptionData savingFrequencyType; - private final EnumOptionData interestType; - private final EnumOptionData interestCalculationMethod; - private final BigDecimal minimumBalanceForWithdrawal; - private final boolean isPartialDepositAllowed; - private final boolean isLockinPeriodAllowed; - private final Integer lockinPeriod; - private final EnumOptionData lockinPeriodType; - - private DateTime createdOn; - private DateTime lastModifedOn; - - private List currencyOptions = new ArrayList(); - List savingsProductTypeOptions = new ArrayList(); - List tenureTypeOptions = new ArrayList(); - List savingFrequencyOptions = new ArrayList(); - List savingsInterestTypeOptions = new ArrayList(); - List lockinPeriodTypeOptions = new ArrayList(); - List interestCalculationOptions = new ArrayList(); - - public SavingProductData(){ - this.createdOn=new DateTime(); - this.lastModifedOn=new DateTime(); - this.id=null; - this.name=null; - this.description=null; - this.interestRate=BigDecimal.ZERO; - this.minInterestRate=BigDecimal.ZERO; - this.maxInterestRate=BigDecimal.ZERO; - this.currency=null; - this.digitsAfterDecimal=null; - this.savingsDepositAmount=null; - this.savingProductType=null; - this.tenureType = null; - this.tenure = null; - this.savingFrequencyType=null; - this.interestType=null; - this.interestCalculationMethod=null; - this.minimumBalanceForWithdrawal=null; - this.isPartialDepositAllowed=true; - this.isLockinPeriodAllowed=true; - this.lockinPeriod=null; - this.lockinPeriodType=null; - } + private final Long id; + private final String name; + private final String description; + private final CurrencyData currency; + private final Integer digitsAfterDecimal; - public SavingProductData(DateTime createdOn, DateTime lastModifedOn, - Long id, String name, String description, - BigDecimal interestRate, BigDecimal minInterestRate, BigDecimal maxInterestRate, CurrencyData currency, - Integer digitsAfterDecimal, BigDecimal savingsDepositAmount, - EnumOptionData savingProductType, - EnumOptionData tenureType, Integer tenure, - EnumOptionData savingFrequencyType, - EnumOptionData savingInterestType, - EnumOptionData interestCalculationMethod, - BigDecimal minimumBalanceForWithdrawal, - boolean isPartialDepositAllowed, boolean isLockinPeriodAllowed, - Integer lockinPeriod, EnumOptionData lockinPeriodType) { - this.createdOn=createdOn; - this.lastModifedOn=lastModifedOn; - this.id=id; - this.name=name; - this.description=description; - this.interestRate=interestRate; - this.minInterestRate=minInterestRate; - this.maxInterestRate=maxInterestRate; - this.currency=currency; - this.digitsAfterDecimal=digitsAfterDecimal; - this.savingsDepositAmount=savingsDepositAmount; - this.savingProductType=savingProductType; - this.tenureType = tenureType; - this.tenure = tenure; - this.savingFrequencyType=savingFrequencyType; - this.interestType=savingInterestType; - this.interestCalculationMethod=interestCalculationMethod; - this.minimumBalanceForWithdrawal=minimumBalanceForWithdrawal; - this.isPartialDepositAllowed=isPartialDepositAllowed; - this.isLockinPeriodAllowed=isLockinPeriodAllowed; - this.lockinPeriod=lockinPeriod; - this.lockinPeriodType=lockinPeriodType; - } + private final BigDecimal interestRate; + private final BigDecimal minInterestRate; + private final BigDecimal maxInterestRate; + private final BigDecimal savingsDepositAmount; + private final EnumOptionData savingProductType; + private final EnumOptionData tenureType; + private final Integer tenure; + private final EnumOptionData savingFrequencyType; + private final EnumOptionData interestType; + private final EnumOptionData interestCalculationMethod; + private final BigDecimal minimumBalanceForWithdrawal; + private final boolean isPartialDepositAllowed; + private final boolean isLockinPeriodAllowed; + private final Integer lockinPeriod; + private final EnumOptionData lockinPeriodType; - public SavingProductData(SavingProductData product, - List currencyOptions, - List savingsProductTypeOptions, - List tenureTypeOptions, - List savingFrequencyOptions, - List savingsInterestTypeOptions, - List lockinPeriodTypeOptions, - List interestCalculationOptions) { - - this.createdOn=product.getCreatedOn(); - this.lastModifedOn=product.getLastModifedOn(); - this.id=product.getId(); - this.name=product.getName(); - this.description=product.getDescription(); - this.interestRate=product.getInterestRate(); - this.minInterestRate=product.getMinInterestRate(); - this.maxInterestRate=product.getMaxInterestRate(); - this.currency=product.getCurrency(); - this.digitsAfterDecimal=product.getDigitsAfterDecimal(); - this.savingsDepositAmount=product.getSavingsDepositAmount(); - this.savingProductType=product.getSavingProductType(); - this.tenureType = product.getTenureType(); - this.tenure = product.getTenure(); - this.savingFrequencyType=product.getSavingFrequencyType(); - this.interestType=product.getInterestType(); - this.interestCalculationMethod=product.getInterestCalculationMethod(); - this.minimumBalanceForWithdrawal=product.getMinimumBalanceForWithdrawal(); - this.isPartialDepositAllowed=product.isPartialDepositAllowed(); - this.isLockinPeriodAllowed=product.isLockinPeriodAllowed(); - this.lockinPeriod=product.getLockinPeriod(); - this.lockinPeriodType=product.getLockinPeriodType(); - - this.currencyOptions=currencyOptions; - this.savingsProductTypeOptions=savingsProductTypeOptions; - this.tenureTypeOptions=tenureTypeOptions; - this.savingFrequencyOptions=savingFrequencyOptions; - this.savingsInterestTypeOptions=savingsInterestTypeOptions; - this.lockinPeriodTypeOptions=lockinPeriodTypeOptions; - this.interestCalculationOptions=interestCalculationOptions; - - } + private DateTime createdOn; + private DateTime lastModifedOn; - public Long getId() { - return id; - } + private List currencyOptions = new ArrayList(); + List savingsProductTypeOptions = new ArrayList(); + List tenureTypeOptions = new ArrayList(); + List savingFrequencyOptions = new ArrayList(); + List savingsInterestTypeOptions = new ArrayList(); + List lockinPeriodTypeOptions = new ArrayList(); + List interestCalculationOptions = new ArrayList(); - public String getName() { - return name; - } + public SavingProductData() { + this.createdOn = new DateTime(); + this.lastModifedOn = new DateTime(); + this.id = null; + this.name = null; + this.description = null; + this.interestRate = BigDecimal.ZERO; + this.minInterestRate = BigDecimal.ZERO; + this.maxInterestRate = BigDecimal.ZERO; + this.currency = null; + this.digitsAfterDecimal = null; + this.savingsDepositAmount = null; + this.savingProductType = null; + this.tenureType = null; + this.tenure = null; + this.savingFrequencyType = null; + this.interestType = null; + this.interestCalculationMethod = null; + this.minimumBalanceForWithdrawal = null; + this.isPartialDepositAllowed = true; + this.isLockinPeriodAllowed = true; + this.lockinPeriod = null; + this.lockinPeriodType = null; + } - public String getDescription() { - return description; - } + public SavingProductData(DateTime createdOn, DateTime lastModifedOn, Long id, String name, String description, BigDecimal interestRate, + BigDecimal minInterestRate, BigDecimal maxInterestRate, CurrencyData currency, Integer digitsAfterDecimal, + BigDecimal savingsDepositAmount, EnumOptionData savingProductType, EnumOptionData tenureType, Integer tenure, + EnumOptionData savingFrequencyType, EnumOptionData savingInterestType, EnumOptionData interestCalculationMethod, + BigDecimal minimumBalanceForWithdrawal, boolean isPartialDepositAllowed, boolean isLockinPeriodAllowed, Integer lockinPeriod, + EnumOptionData lockinPeriodType) { + this.createdOn = createdOn; + this.lastModifedOn = lastModifedOn; + this.id = id; + this.name = name; + this.description = description; + this.interestRate = interestRate; + this.minInterestRate = minInterestRate; + this.maxInterestRate = maxInterestRate; + this.currency = currency; + this.digitsAfterDecimal = digitsAfterDecimal; + this.savingsDepositAmount = savingsDepositAmount; + this.savingProductType = savingProductType; + this.tenureType = tenureType; + this.tenure = tenure; + this.savingFrequencyType = savingFrequencyType; + this.interestType = savingInterestType; + this.interestCalculationMethod = interestCalculationMethod; + this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; + this.isPartialDepositAllowed = isPartialDepositAllowed; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; + } - public CurrencyData getCurrency() { - return currency; - } - - public Integer getDigitsAfterDecimal() { - return digitsAfterDecimal; - } + public SavingProductData(SavingProductData product, List currencyOptions, List savingsProductTypeOptions, + List tenureTypeOptions, List savingFrequencyOptions, + List savingsInterestTypeOptions, List lockinPeriodTypeOptions, + List interestCalculationOptions) { - public BigDecimal getInterestRate() { - return interestRate; - } + this.createdOn = product.getCreatedOn(); + this.lastModifedOn = product.getLastModifedOn(); + this.id = product.getId(); + this.name = product.getName(); + this.description = product.getDescription(); + this.interestRate = product.getInterestRate(); + this.minInterestRate = product.getMinInterestRate(); + this.maxInterestRate = product.getMaxInterestRate(); + this.currency = product.getCurrency(); + this.digitsAfterDecimal = product.getDigitsAfterDecimal(); + this.savingsDepositAmount = product.getSavingsDepositAmount(); + this.savingProductType = product.getSavingProductType(); + this.tenureType = product.getTenureType(); + this.tenure = product.getTenure(); + this.savingFrequencyType = product.getSavingFrequencyType(); + this.interestType = product.getInterestType(); + this.interestCalculationMethod = product.getInterestCalculationMethod(); + this.minimumBalanceForWithdrawal = product.getMinimumBalanceForWithdrawal(); + this.isPartialDepositAllowed = product.isPartialDepositAllowed(); + this.isLockinPeriodAllowed = product.isLockinPeriodAllowed(); + this.lockinPeriod = product.getLockinPeriod(); + this.lockinPeriodType = product.getLockinPeriodType(); - public BigDecimal getMinInterestRate() { - return minInterestRate; - } + this.currencyOptions = currencyOptions; + this.savingsProductTypeOptions = savingsProductTypeOptions; + this.tenureTypeOptions = tenureTypeOptions; + this.savingFrequencyOptions = savingFrequencyOptions; + this.savingsInterestTypeOptions = savingsInterestTypeOptions; + this.lockinPeriodTypeOptions = lockinPeriodTypeOptions; + this.interestCalculationOptions = interestCalculationOptions; - public BigDecimal getMaxInterestRate() { - return maxInterestRate; - } + } - public BigDecimal getSavingsDepositAmount() { - return savingsDepositAmount; - } + public Long getId() { + return id; + } - public EnumOptionData getSavingProductType() { - return savingProductType; - } + public String getName() { + return name; + } - public EnumOptionData getTenureType() { - return tenureType; - } + public String getDescription() { + return description; + } - public Integer getTenure() { - return tenure; - } + public CurrencyData getCurrency() { + return currency; + } - public EnumOptionData getInterestType() { - return interestType; - } + public Integer getDigitsAfterDecimal() { + return digitsAfterDecimal; + } - public EnumOptionData getInterestCalculationMethod() { - return interestCalculationMethod; - } + public BigDecimal getInterestRate() { + return interestRate; + } - public BigDecimal getMinimumBalanceForWithdrawal() { - return minimumBalanceForWithdrawal; - } + public BigDecimal getMinInterestRate() { + return minInterestRate; + } - public boolean isPartialDepositAllowed() { - return isPartialDepositAllowed; - } + public BigDecimal getMaxInterestRate() { + return maxInterestRate; + } - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + public BigDecimal getSavingsDepositAmount() { + return savingsDepositAmount; + } - public Integer getLockinPeriod() { - return lockinPeriod; - } + public EnumOptionData getSavingProductType() { + return savingProductType; + } - public EnumOptionData getLockinPeriodType() { - return lockinPeriodType; - } + public EnumOptionData getTenureType() { + return tenureType; + } - public DateTime getCreatedOn() { - return createdOn; - } + public Integer getTenure() { + return tenure; + } - public DateTime getLastModifedOn() { - return lastModifedOn; - } + public EnumOptionData getInterestType() { + return interestType; + } - public List getCurrencyOptions() { - return currencyOptions; - } + public EnumOptionData getInterestCalculationMethod() { + return interestCalculationMethod; + } - public void setCurrencyOptions(List currencyOptions) { - this.currencyOptions = currencyOptions; - } + public BigDecimal getMinimumBalanceForWithdrawal() { + return minimumBalanceForWithdrawal; + } - public EnumOptionData getSavingFrequencyType() { - return savingFrequencyType; - } + public boolean isPartialDepositAllowed() { + return isPartialDepositAllowed; + } - public List getSavingsProductTypeOptions() { - return savingsProductTypeOptions; - } + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } - public List getTenureTypeOptions() { - return tenureTypeOptions; - } + public Integer getLockinPeriod() { + return lockinPeriod; + } - public List getSavingFrequencyOptions() { - return savingFrequencyOptions; - } + public EnumOptionData getLockinPeriodType() { + return lockinPeriodType; + } - public List getSavingsInterestTypeOptions() { - return savingsInterestTypeOptions; - } + public DateTime getCreatedOn() { + return createdOn; + } - public List getLockinPeriodTypeOptions() { - return lockinPeriodTypeOptions; - } + public DateTime getLastModifedOn() { + return lastModifedOn; + } + + public List getCurrencyOptions() { + return currencyOptions; + } + + public void setCurrencyOptions(List currencyOptions) { + this.currencyOptions = currencyOptions; + } + + public EnumOptionData getSavingFrequencyType() { + return savingFrequencyType; + } + + public List getSavingsProductTypeOptions() { + return savingsProductTypeOptions; + } + + public List getTenureTypeOptions() { + return tenureTypeOptions; + } + + public List getSavingFrequencyOptions() { + return savingFrequencyOptions; + } + + public List getSavingsInterestTypeOptions() { + return savingsInterestTypeOptions; + } + + public List getLockinPeriodTypeOptions() { + return lockinPeriodTypeOptions; + } + + public List getInterestCalculationOptions() { + return interestCalculationOptions; + } - public List getInterestCalculationOptions() { - return interestCalculationOptions; - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java index 52d3d97c0..63526e8af 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java @@ -3,32 +3,33 @@ package org.mifosplatform.portfolio.savingsaccountproduct.data; import java.io.Serializable; public class SavingProductLookup implements Serializable { - private Long id; - private String name; - public SavingProductLookup() { - // - } + private Long id; + private String name; - public SavingProductLookup(Long id, String name) { - this.id = id; - this.name = name; - } + public SavingProductLookup() { + // + } - public Long getId() { - return id; - } + public SavingProductLookup(Long id, String name) { + this.id = id; + this.name = name; + } - public void setId(Long id) { - this.id = id; - } + public Long getId() { + return id; + } - public String getName() { - return name; - } + public void setId(Long id) { + this.id = id; + } - public void setName(String name) { - this.name = name; - } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java index 6fa426f74..0e612a21e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java @@ -1,54 +1,50 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; - public enum SavingFrequencyType { - - INVALID(0,"savingFrequencyType.invalid"), - DAILY(1,"savingFrequencyType.daily"), - MONTHLY(2,"savingFrequencyType.monthly"), - QUATERLY(3,"savingFrequencyType.quaterly"), - HALFYEARLY(4,"savingFrequencyType.halfyearly"), - YEARLY(5,"savingFrequencyType.yearly"); - - private final Integer value; - private final String code; - - private SavingFrequencyType(final Integer value,final String code) { - this.value=value; - this.code=code; - } - - public Integer getValue() { - return value; - } - public String getCode() { - return code; - } - - public static SavingFrequencyType fromInt(final Integer frequency) { - SavingFrequencyType savingFrequencyType = SavingFrequencyType.INVALID; - switch (frequency) { - case 1: - savingFrequencyType = SavingFrequencyType.DAILY; - break; - case 2: - savingFrequencyType = SavingFrequencyType.MONTHLY; - break; - case 3: - savingFrequencyType = SavingFrequencyType.QUATERLY; - break; - case 4: - savingFrequencyType = SavingFrequencyType.HALFYEARLY; - break; - case 5: - savingFrequencyType = SavingFrequencyType.YEARLY; - break; - default: - savingFrequencyType = SavingFrequencyType.INVALID; - break; - } - return savingFrequencyType; - } - + INVALID(0, "savingFrequencyType.invalid"), DAILY(1, "savingFrequencyType.daily"), MONTHLY(2, "savingFrequencyType.monthly"), QUATERLY( + 3, "savingFrequencyType.quaterly"), HALFYEARLY(4, "savingFrequencyType.halfyearly"), YEARLY(5, "savingFrequencyType.yearly"); + + private final Integer value; + private final String code; + + private SavingFrequencyType(final Integer value, final String code) { + this.value = value; + this.code = code; + } + + public Integer getValue() { + return value; + } + + public String getCode() { + return code; + } + + public static SavingFrequencyType fromInt(final Integer frequency) { + + SavingFrequencyType savingFrequencyType = SavingFrequencyType.INVALID; + switch (frequency) { + case 1: + savingFrequencyType = SavingFrequencyType.DAILY; + break; + case 2: + savingFrequencyType = SavingFrequencyType.MONTHLY; + break; + case 3: + savingFrequencyType = SavingFrequencyType.QUATERLY; + break; + case 4: + savingFrequencyType = SavingFrequencyType.HALFYEARLY; + break; + case 5: + savingFrequencyType = SavingFrequencyType.YEARLY; + break; + default: + savingFrequencyType = SavingFrequencyType.INVALID; + break; + } + return savingFrequencyType; + } + } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java index 596f2eada..00fda71f0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java @@ -1,44 +1,43 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; public enum SavingInterestCalculationMethod { - - AVERAGEBAL(1,"savinginterest.calculation.method.averagebal"), - MINBAL(2,"savinginterest.calculation.method.minbal"), - MONTHLYCOLLECTION(3,"savinginterest.calculation.method.monthlycllection"), - INVALID(0,"savinginterest.calculation.method.invalid"); - private final Integer value; - private final String code; - - private SavingInterestCalculationMethod(final Integer value,final String code) { - this.value=value; - this.code=code; - } + AVERAGEBAL(1, "savinginterest.calculation.method.averagebal"), MINBAL(2, "savinginterest.calculation.method.minbal"), MONTHLYCOLLECTION( + 3, "savinginterest.calculation.method.monthlycllection"), INVALID(0, "savinginterest.calculation.method.invalid"); - public Integer getValue() { - return value; - } + private final Integer value; + private final String code; - public String getCode() { - return code; - } - public static SavingInterestCalculationMethod fromInt(final Integer frequency) { + private SavingInterestCalculationMethod(final Integer value, final String code) { + this.value = value; + this.code = code; + } - SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.INVALID; - switch (frequency) { - case 1: - savingInterestCalculationMethod = SavingInterestCalculationMethod.AVERAGEBAL; - break; - case 2: - savingInterestCalculationMethod = SavingInterestCalculationMethod.MINBAL; - break; - case 3: - savingInterestCalculationMethod = SavingInterestCalculationMethod.MONTHLYCOLLECTION; - break; - default: - savingInterestCalculationMethod = SavingInterestCalculationMethod.INVALID; - break; - } - return savingInterestCalculationMethod; - } + public Integer getValue() { + return value; + } + + public String getCode() { + return code; + } + + public static SavingInterestCalculationMethod fromInt(final Integer frequency) { + + SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.INVALID; + switch (frequency) { + case 1: + savingInterestCalculationMethod = SavingInterestCalculationMethod.AVERAGEBAL; + break; + case 2: + savingInterestCalculationMethod = SavingInterestCalculationMethod.MINBAL; + break; + case 3: + savingInterestCalculationMethod = SavingInterestCalculationMethod.MONTHLYCOLLECTION; + break; + default: + savingInterestCalculationMethod = SavingInterestCalculationMethod.INVALID; + break; + } + return savingInterestCalculationMethod; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java index dc859b2b9..425c2673c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java @@ -18,82 +18,87 @@ import org.mifosplatform.useradministration.domain.AppUser; @Entity @Table(name = "m_product_savings") public class SavingProduct extends AbstractAuditableCustom { - - @Column(name = "name", nullable = false) - private String name; - @Column(name = "description") - private String description; - - @Column(name = "is_deleted", nullable=false) - private boolean deleted = false; - - @Embedded - SavingProductRelatedDetail savingProductRelatedDetail; + @Column(name = "name", nullable = false) + private String name; - protected SavingProduct() { - this.name = null; + @Column(name = "description") + private String description; + + @Column(name = "is_deleted", nullable = false) + private boolean deleted = false; + + @Embedded + SavingProductRelatedDetail savingProductRelatedDetail; + + protected SavingProduct() { + this.name = null; this.description = null; this.savingProductRelatedDetail = null; - } - - public SavingProduct(final String name, final String description, final MonetaryCurrency currency,final BigDecimal interestRate, final BigDecimal minInterestRate, final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount, - final SavingProductType savingProductType, final TenureTypeEnum tenureType, final Integer tenure, final SavingFrequencyType savingFrequencyType, - final SavingsInterestType savingsInterestType, SavingInterestCalculationMethod savingInterestCalculationMethod, final BigDecimal minimumBalanceForWithdrawal, - final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType){ - - this.name = name.trim(); - if (StringUtils.isNotBlank(description)) { - this.description = description.trim(); - } else { - this.description = null; - } - this.savingProductRelatedDetail = new SavingProductRelatedDetail(currency, interestRate, minInterestRate, maxInterestRate, savingsDepositAmount, savingProductType, tenureType, tenure, - savingFrequencyType, savingsInterestType, savingInterestCalculationMethod, minimumBalanceForWithdrawal, isPartialDepositAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - } + } - public String getName() { + public SavingProduct(final String name, final String description, final MonetaryCurrency currency, final BigDecimal interestRate, + final BigDecimal minInterestRate, final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount, + final SavingProductType savingProductType, final TenureTypeEnum tenureType, final Integer tenure, + final SavingFrequencyType savingFrequencyType, final SavingsInterestType savingsInterestType, + SavingInterestCalculationMethod savingInterestCalculationMethod, final BigDecimal minimumBalanceForWithdrawal, + final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, + final PeriodFrequencyType lockinPeriodType) { + + this.name = name.trim(); + if (StringUtils.isNotBlank(description)) { + this.description = description.trim(); + } else { + this.description = null; + } + this.savingProductRelatedDetail = new SavingProductRelatedDetail(currency, interestRate, minInterestRate, maxInterestRate, + savingsDepositAmount, savingProductType, tenureType, tenure, savingFrequencyType, savingsInterestType, + savingInterestCalculationMethod, minimumBalanceForWithdrawal, isPartialDepositAllowed, isLockinPeriodAllowed, lockinPeriod, + lockinPeriodType); + } + + public String getName() { return this.name; } public String getDescription() { return this.description; - } - - public MonetaryCurrency getCurrency() { - return this.savingProductRelatedDetail.getCurrency(); } - - public BigDecimal getInterestRate(){ - return this.savingProductRelatedDetail.getInterestRate(); - } - - public BigDecimal getMinimumBalance(){ - return this.savingProductRelatedDetail.getMinimumBalance(); - } - - public boolean isDeleted() { - return deleted; - } - - public void delete() { - this.deleted = true; - } - public SavingProductRelatedDetail getSavingProductRelatedDetail() { - return savingProductRelatedDetail; - } + public MonetaryCurrency getCurrency() { + return this.savingProductRelatedDetail.getCurrency(); + } - public void update(final SavingProductCommand command) { + public BigDecimal getInterestRate() { + return this.savingProductRelatedDetail.getInterestRate(); + } - if (command.isNameChanged()) { - this.name = command.getName(); - } + public BigDecimal getMinimumBalance() { + return this.savingProductRelatedDetail.getMinimumBalance(); + } - if (command.isDescriptionChanged()) { - this.description = command.getDescription(); - } - - this.savingProductRelatedDetail.update(command); - } + public boolean isDeleted() { + return deleted; + } + + public void delete() { + this.deleted = true; + } + + public SavingProductRelatedDetail getSavingProductRelatedDetail() { + return savingProductRelatedDetail; + } + + public void update(final SavingProductCommand command) { + + if (command.isNameChanged()) { + this.name = command.getName(); + } + + if (command.isDescriptionChanged()) { + this.description = command.getDescription(); + } + + this.savingProductRelatedDetail.update(command); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java index 34c5f944d..266a9b547 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java @@ -13,214 +13,212 @@ import org.mifosplatform.portfolio.savingsdepositproduct.domain.TenureTypeEnum; @Embeddable public class SavingProductRelatedDetail { - - @Embedded - private MonetaryCurrency currency; - - @Column(name = "interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal interestRate; - - @SuppressWarnings("unused") - @Column(name = "min_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal minInterestRate; - - @SuppressWarnings("unused") - @Column(name = "max_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal maxInterestRate; - - @Column(name = "savings_deposit_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal savingsDepositAmount; - - @Column(name = "savings_product_type", nullable=false) - private SavingProductType savingProductType; - - @Column(name = "tenure_type", nullable=false) - private TenureTypeEnum tenureType; - - @Column(name = "tenure", nullable=false) - private Integer tenure; - - @Column(name = "frequency", nullable=false) - private SavingFrequencyType frequency; - - @Column(name = "interest_type", nullable=false) - private SavingsInterestType interestType; - - @Column(name = "interest_calculation_method") - private SavingInterestCalculationMethod interestCalculationMethod; - - @Column(name = "min_bal_for_withdrawal", scale = 6, precision = 19, nullable = false) - private BigDecimal minimumBalanceForWithdrawal; - - @Column(name = "is_partial_deposit_allowed", nullable=false) - private boolean isPartialDepositAllowed; - - @Column(name = "is_lock_in_period_allowed", nullable=false) - private boolean isLockinPeriodAllowed; - - @Column(name = "lock_in_period", nullable=false) - private Integer lockinPeriod; - - @Column(name = "lock_in_period_type", nullable=false) - private PeriodFrequencyType lockinPeriodType; - - public SavingProductRelatedDetail() { - this.interestRate=null; - this.savingsDepositAmount=null; - } - - public SavingProductRelatedDetail(final MonetaryCurrency currency,final BigDecimal interestRate, final BigDecimal minInterestRate, final BigDecimal maxInterestRate, - final BigDecimal savingsDepositAmount, final SavingProductType savingProductType, - final TenureTypeEnum tenureType, final Integer tenure, - final SavingFrequencyType frequency, final SavingsInterestType interestType, - final SavingInterestCalculationMethod interestCalculationMethod, - final BigDecimal minimumBalanceForWithdrawal, - final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, - final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { - this.currency=currency; - this.interestRate=interestRate; - this.minInterestRate = minInterestRate; - this.maxInterestRate = maxInterestRate; - this.savingsDepositAmount=savingsDepositAmount; - this.savingProductType=savingProductType; - this.tenureType=tenureType; - this.tenure=tenure; - this.frequency=frequency; - this.interestType=interestType; - this.interestCalculationMethod=interestCalculationMethod; - this.minimumBalanceForWithdrawal=minimumBalanceForWithdrawal; - this.isPartialDepositAllowed=isPartialDepositAllowed; - this.isLockinPeriodAllowed=isLockinPeriodAllowed; - this.lockinPeriod=lockinPeriod; - this.lockinPeriodType=lockinPeriodType; - } - public MonetaryCurrency getCurrency() { - return this.currency.copy(); - } + @Embedded + private MonetaryCurrency currency; - public BigDecimal getInterestRate() { - return BigDecimal.valueOf(Double.valueOf(this.interestRate.stripTrailingZeros().toString())); - } - - public BigDecimal getMinimumBalance(){ - return BigDecimal.valueOf(Double.valueOf(this.savingsDepositAmount.stripTrailingZeros().toString())); - } - - public void update(SavingProductCommand command){ - Integer digitsAfterDecimal = this.currency.getDigitsAfterDecimal(); - if (command.isDigitsAfterDecimalChanged()) { - digitsAfterDecimal = command.getDigitsAfterDecimal(); - } - - String currencyCodeChanged = this.currency.getCode(); - if (command.isCurrencyCodeChanged()) { - currencyCodeChanged = command.getCurrencyCode(); - } - - if (command.isDigitsAfterDecimalChanged() || command.isCurrencyCodeChanged()) { - this.currency = new MonetaryCurrency(currencyCodeChanged, digitsAfterDecimal); - } - - if (command.isInterestRateChanged()) { - this.interestRate = command.getInterestRate(); - } - - if(command.isSavingsDepositAmountChanged()){ - this.savingsDepositAmount=command.getSavingsDepositAmount(); - } - - if (command.isSavingProductTypeChanged()) { - this.savingProductType=SavingProductType.fromInt(command.getSavingProductType()); - } - - if(command.isTenureTypeChanged()){ - this.tenureType=TenureTypeEnum.fromInt(command.getTenureType()); - } - - if (command.isTenureChanged()) { - this.tenure = command.getTenure(); - } - - if (command.isFrequencyChanged()){ - this.frequency = SavingFrequencyType.fromInt(command.getFrequency()); - } - - if (command.isInterestTypeChanged()) { - this.interestType = SavingsInterestType.fromInt(command.getInterestType()); - } - - if (command.isInterestCalculationMethodChanged()){ - this.interestCalculationMethod = SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); - } - - if (command.isMinimumBalanceForWithdrawalChanged()) { - this.minimumBalanceForWithdrawal = command.getMinimumBalanceForWithdrawal(); - } - - if (command.isPartialDepositAllowedChanged()) { - this.isPartialDepositAllowed = command.isPartialDepositAllowed(); - } - - if (command.isLockinPeriodAllowedChanged()){ - this.isLockinPeriodAllowed = command.isLockinPeriodAllowed(); - } - - if (command.isLockinPeriodChanged()){ - this.lockinPeriod = command.getLockinPeriod(); - } - - if (command.isLockinPeriodTypeChanged()){ - this.lockinPeriodType=PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - } - } + @Column(name = "interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal interestRate; - public BigDecimal getSavingsDepositAmount() { - return savingsDepositAmount; - } + @SuppressWarnings("unused") + @Column(name = "min_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal minInterestRate; - public SavingProductType getSavingProductType() { - return savingProductType; - } + @SuppressWarnings("unused") + @Column(name = "max_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal maxInterestRate; - public TenureTypeEnum getTenureType() { - return tenureType; - } + @Column(name = "savings_deposit_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal savingsDepositAmount; - public Integer getTenure() { - return tenure; - } + @Column(name = "savings_product_type", nullable = false) + private SavingProductType savingProductType; - public SavingFrequencyType getFrequency() { - return frequency; - } + @Column(name = "tenure_type", nullable = false) + private TenureTypeEnum tenureType; - public SavingsInterestType getInterestType() { - return interestType; - } + @Column(name = "tenure", nullable = false) + private Integer tenure; - public SavingInterestCalculationMethod getInterestCalculationMethod() { - return interestCalculationMethod; - } + @Column(name = "frequency", nullable = false) + private SavingFrequencyType frequency; - public BigDecimal getMinimumBalanceForWithdrawal() { - return minimumBalanceForWithdrawal; - } + @Column(name = "interest_type", nullable = false) + private SavingsInterestType interestType; - public boolean isPartialDepositAllowed() { - return isPartialDepositAllowed; - } + @Column(name = "interest_calculation_method") + private SavingInterestCalculationMethod interestCalculationMethod; - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + @Column(name = "min_bal_for_withdrawal", scale = 6, precision = 19, nullable = false) + private BigDecimal minimumBalanceForWithdrawal; - public Integer getLockinPeriod() { - return lockinPeriod; - } + @Column(name = "is_partial_deposit_allowed", nullable = false) + private boolean isPartialDepositAllowed; + + @Column(name = "is_lock_in_period_allowed", nullable = false) + private boolean isLockinPeriodAllowed; + + @Column(name = "lock_in_period", nullable = false) + private Integer lockinPeriod; + + @Column(name = "lock_in_period_type", nullable = false) + private PeriodFrequencyType lockinPeriodType; + + public SavingProductRelatedDetail() { + this.interestRate = null; + this.savingsDepositAmount = null; + } + + public SavingProductRelatedDetail(final MonetaryCurrency currency, final BigDecimal interestRate, final BigDecimal minInterestRate, + final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount, final SavingProductType savingProductType, + final TenureTypeEnum tenureType, final Integer tenure, final SavingFrequencyType frequency, + final SavingsInterestType interestType, final SavingInterestCalculationMethod interestCalculationMethod, + final BigDecimal minimumBalanceForWithdrawal, final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, + final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { + this.currency = currency; + this.interestRate = interestRate; + this.minInterestRate = minInterestRate; + this.maxInterestRate = maxInterestRate; + this.savingsDepositAmount = savingsDepositAmount; + this.savingProductType = savingProductType; + this.tenureType = tenureType; + this.tenure = tenure; + this.frequency = frequency; + this.interestType = interestType; + this.interestCalculationMethod = interestCalculationMethod; + this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; + this.isPartialDepositAllowed = isPartialDepositAllowed; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; + } + + public MonetaryCurrency getCurrency() { + return this.currency.copy(); + } + + public BigDecimal getInterestRate() { + return BigDecimal.valueOf(Double.valueOf(this.interestRate.stripTrailingZeros().toString())); + } + + public BigDecimal getMinimumBalance() { + return BigDecimal.valueOf(Double.valueOf(this.savingsDepositAmount.stripTrailingZeros().toString())); + } + + public void update(SavingProductCommand command) { + Integer digitsAfterDecimal = this.currency.getDigitsAfterDecimal(); + if (command.isDigitsAfterDecimalChanged()) { + digitsAfterDecimal = command.getDigitsAfterDecimal(); + } + + String currencyCodeChanged = this.currency.getCode(); + if (command.isCurrencyCodeChanged()) { + currencyCodeChanged = command.getCurrencyCode(); + } + + if (command.isDigitsAfterDecimalChanged() || command.isCurrencyCodeChanged()) { + this.currency = new MonetaryCurrency(currencyCodeChanged, digitsAfterDecimal); + } + + if (command.isInterestRateChanged()) { + this.interestRate = command.getInterestRate(); + } + + if (command.isSavingsDepositAmountChanged()) { + this.savingsDepositAmount = command.getSavingsDepositAmount(); + } + + if (command.isSavingProductTypeChanged()) { + this.savingProductType = SavingProductType.fromInt(command.getSavingProductType()); + } + + if (command.isTenureTypeChanged()) { + this.tenureType = TenureTypeEnum.fromInt(command.getTenureType()); + } + + if (command.isTenureChanged()) { + this.tenure = command.getTenure(); + } + + if (command.isFrequencyChanged()) { + this.frequency = SavingFrequencyType.fromInt(command.getFrequency()); + } + + if (command.isInterestTypeChanged()) { + this.interestType = SavingsInterestType.fromInt(command.getInterestType()); + } + + if (command.isInterestCalculationMethodChanged()) { + this.interestCalculationMethod = SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); + } + + if (command.isMinimumBalanceForWithdrawalChanged()) { + this.minimumBalanceForWithdrawal = command.getMinimumBalanceForWithdrawal(); + } + + if (command.isPartialDepositAllowedChanged()) { + this.isPartialDepositAllowed = command.isPartialDepositAllowed(); + } + + if (command.isLockinPeriodAllowedChanged()) { + this.isLockinPeriodAllowed = command.isLockinPeriodAllowed(); + } + + if (command.isLockinPeriodChanged()) { + this.lockinPeriod = command.getLockinPeriod(); + } + + if (command.isLockinPeriodTypeChanged()) { + this.lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + } + } + + public BigDecimal getSavingsDepositAmount() { + return savingsDepositAmount; + } + + public SavingProductType getSavingProductType() { + return savingProductType; + } + + public TenureTypeEnum getTenureType() { + return tenureType; + } + + public Integer getTenure() { + return tenure; + } + + public SavingFrequencyType getFrequency() { + return frequency; + } + + public SavingsInterestType getInterestType() { + return interestType; + } + + public SavingInterestCalculationMethod getInterestCalculationMethod() { + return interestCalculationMethod; + } + + public BigDecimal getMinimumBalanceForWithdrawal() { + return minimumBalanceForWithdrawal; + } + + public boolean isPartialDepositAllowed() { + return isPartialDepositAllowed; + } + + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } + + public Integer getLockinPeriod() { + return lockinPeriod; + } + + public PeriodFrequencyType getLockinPeriodType() { + return lockinPeriodType; + } - public PeriodFrequencyType getLockinPeriodType() { - return lockinPeriodType; - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRepository.java index d9885cbda..45ca5e10c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRepository.java @@ -3,8 +3,6 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -public interface SavingProductRepository extends - JpaRepository, - JpaSpecificationExecutor { - -} +public interface SavingProductRepository extends JpaRepository, JpaSpecificationExecutor { + // +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductType.java index 127cc5b5b..58d2681fb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductType.java @@ -1,50 +1,48 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; - public enum SavingProductType { - - INVALID(0,"savingProductType.invalid"), - RECCURING(1,"savingProductType.reccuring"), - REGULAR(2,"savingProductType.regular"); - - private final Integer value; - private final String code; - - private SavingProductType(final Integer value,final String code) { - this.value=value; - this.code=code; - } - - public Integer getValue() { - return value; - } - public String getCode() { - return code; - } - - public static SavingProductType fromInt(final Integer frequency) { - SavingProductType savingProductType = SavingProductType.INVALID; - switch (frequency) { - case 1: - savingProductType = SavingProductType.RECCURING; - break; - case 2: - savingProductType = SavingProductType.REGULAR; - break; - default: - savingProductType = SavingProductType.INVALID; - break; - } - return savingProductType; - } - - public boolean isReccuring(){ - return this.value.equals(SavingProductType.RECCURING.getValue()); - } - - public boolean isRegular(){ - return this.value.equals(SavingProductType.REGULAR.getValue()); - } - + INVALID(0, "savingProductType.invalid"), RECCURING(1, "savingProductType.reccuring"), REGULAR(2, "savingProductType.regular"); + + private final Integer value; + private final String code; + + private SavingProductType(final Integer value, final String code) { + this.value = value; + this.code = code; + } + + public Integer getValue() { + return value; + } + + public String getCode() { + return code; + } + + public static SavingProductType fromInt(final Integer frequency) { + + SavingProductType savingProductType = SavingProductType.INVALID; + switch (frequency) { + case 1: + savingProductType = SavingProductType.RECCURING; + break; + case 2: + savingProductType = SavingProductType.REGULAR; + break; + default: + savingProductType = SavingProductType.INVALID; + break; + } + return savingProductType; + } + + public boolean isReccuring() { + return this.value.equals(SavingProductType.RECCURING.getValue()); + } + + public boolean isRegular() { + return this.value.equals(SavingProductType.REGULAR.getValue()); + } + } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java index ed58801e1..a3c42ee51 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java @@ -1,42 +1,40 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; - public enum SavingsInterestType { - - INVALID(0,"savingsInterestType.invalid"), - SIMPLE(1,"savingsInterestType.simple"), - COMPOUNDING(2,"savingsInterestType.compounding"); - - private final Integer value; - private final String code; - - private SavingsInterestType(final Integer value,final String code) { - this.value=value; - this.code=code; - } - - public Integer getValue() { - return value; - } - public String getCode() { - return code; - } - - public static SavingsInterestType fromInt(final Integer frequency) { - SavingsInterestType savingsInterestType = SavingsInterestType.INVALID; - switch (frequency) { - case 1: - savingsInterestType = SavingsInterestType.SIMPLE; - break; - case 2: - savingsInterestType = SavingsInterestType.COMPOUNDING; - break; - default: - savingsInterestType = SavingsInterestType.INVALID; - break; - } - return savingsInterestType; - } - + INVALID(0, "savingsInterestType.invalid"), SIMPLE(1, "savingsInterestType.simple"), COMPOUNDING(2, "savingsInterestType.compounding"); + + private final Integer value; + private final String code; + + private SavingsInterestType(final Integer value, final String code) { + this.value = value; + this.code = code; + } + + public Integer getValue() { + return value; + } + + public String getCode() { + return code; + } + + public static SavingsInterestType fromInt(final Integer frequency) { + + SavingsInterestType savingsInterestType = SavingsInterestType.INVALID; + switch (frequency) { + case 1: + savingsInterestType = SavingsInterestType.SIMPLE; + break; + case 2: + savingsInterestType = SavingsInterestType.COMPOUNDING; + break; + default: + savingsInterestType = SavingsInterestType.INVALID; + break; + } + return savingsInterestType; + } + } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsLockinPeriodEnum.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsLockinPeriodEnum.java index 29ab5621e..985a0daa9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsLockinPeriodEnum.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsLockinPeriodEnum.java @@ -1,52 +1,50 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; - public enum SavingsLockinPeriodEnum { - - DAYS(0, "lockin.period.type.days"), // - WEEKS(1, "lockin.period.type.weeks"), // - MONTHS(2, "lockin.period.type.months"), // - YEARS(3, "lockin.period.type.years"), // - INVALID(4, "lockin.period.type.invalid"); + + DAYS(0, "lockin.period.type.days"), // + WEEKS(1, "lockin.period.type.weeks"), // + MONTHS(2, "lockin.period.type.months"), // + YEARS(3, "lockin.period.type.years"), // + INVALID(4, "lockin.period.type.invalid"); private final Integer value; - private final String code; + private final String code; private SavingsLockinPeriodEnum(final Integer value, final String code) { this.value = value; - this.code = code; + this.code = code; } public Integer getValue() { return this.value; } - - public String getCode() { - return code; - } - - public static SavingsLockinPeriodEnum fromInt(final Integer frequency) { - SavingsLockinPeriodEnum lockinPeriodType = SavingsLockinPeriodEnum.INVALID; - switch (frequency) { - case 0: - lockinPeriodType = SavingsLockinPeriodEnum.DAYS; - break; - case 1: - lockinPeriodType = SavingsLockinPeriodEnum.WEEKS; - break; - case 2: - lockinPeriodType = SavingsLockinPeriodEnum.MONTHS; - break; - case 3: - lockinPeriodType = SavingsLockinPeriodEnum.YEARS; - break; - default: - lockinPeriodType = SavingsLockinPeriodEnum.INVALID; - break; - } - return lockinPeriodType; - } + public String getCode() { + return code; + } + public static SavingsLockinPeriodEnum fromInt(final Integer frequency) { + + SavingsLockinPeriodEnum lockinPeriodType = SavingsLockinPeriodEnum.INVALID; + switch (frequency) { + case 0: + lockinPeriodType = SavingsLockinPeriodEnum.DAYS; + break; + case 1: + lockinPeriodType = SavingsLockinPeriodEnum.WEEKS; + break; + case 2: + lockinPeriodType = SavingsLockinPeriodEnum.MONTHS; + break; + case 3: + lockinPeriodType = SavingsLockinPeriodEnum.YEARS; + break; + default: + lockinPeriodType = SavingsLockinPeriodEnum.INVALID; + break; + } + return lockinPeriodType; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java index efe2a7c39..02a5987f1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java @@ -2,11 +2,9 @@ package org.mifosplatform.portfolio.savingsaccountproduct.exception; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; -public class SavingProductNotFoundException extends - AbstractPlatformResourceNotFoundException { +public class SavingProductNotFoundException extends AbstractPlatformResourceNotFoundException { - public SavingProductNotFoundException(Long id) { - super("error.msg.savingproduct.id.invalid", "Saving product with identifier " + id + " does not exist", id); - } - -} + public SavingProductNotFoundException(Long id) { + super("error.msg.savingproduct.id.invalid", "Saving product with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java index da8226823..290427dc8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java @@ -9,77 +9,89 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation import org.mifosplatform.portfolio.savingsaccountproduct.command.SavingProductCommand; public class SavingProductCommandValidator { - - private final SavingProductCommand command; - - public SavingProductCommandValidator(final SavingProductCommand command) { - this.command=command; - } - - public void validateForUpdate() { - - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("savingsproduct"); - baseDataValidator.reset().parameter("id").value(command.getId()).notNull(); - baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("description").value(command.getDescription()).ignoreIfNull().notExceedingLengthOf(500); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().inMinMaxRange(0, 6); - baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("minInterestRate").value(command.getMinInterestRate()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("maxInterestRate").value(command.getMaxInterestRate()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("interestRate").comapareMinAndMaxOfTwoBigDecmimalNos(command.getInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getInterestRate()); - baseDataValidator.reset().parameter("savingsDepositAmount").value(command.getSavingsDepositAmount()).ignoreIfNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingProductType").value(command.getSavingProductType()).ignoreIfNull(); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).ignoreIfNull(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).ignoreIfNull(); - baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).ignoreIfNull(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull(); - baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).ignoreIfNull(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).ignoreIfNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()).trueOrFalseRequired(command.isPartialDepositAllowedChanged()).ignoreIfNull(); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()).trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).ignoreIfNull(); - baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).ignoreIfNull(); - baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).ignoreIfNull(); - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); - } - } - - public void validateForCreate() { - - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); - baseDataValidator.reset().parameter("name").value(command.getName()).notBlank(); - baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(500); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); - baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6); - baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("minInterestRate").value(command.getMinInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("maxInterestRate").value(command.getMaxInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("interestRate").comapareMinAndMaxOfTwoBigDecmimalNos(command.getInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getInterestRate()); - baseDataValidator.reset().parameter("savingsDepositAmount").value(command.getSavingsDepositAmount()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingProductType").value(command.getSavingProductType()).notNull(); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).notNull(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).notNull(); - baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).notNull(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).notNull(); - baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).notNull(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()).trueOrFalseRequired(command.isPartialDepositAllowedChanged()).notNull(); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()).trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).notNull(); - baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).notNull(); - baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).notNull(); - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); - } - } + private final SavingProductCommand command; + + public SavingProductCommandValidator(final SavingProductCommand command) { + this.command = command; + } + + public void validateForUpdate() { + + List dataValidationErrors = new ArrayList(); + + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("savingsproduct"); + baseDataValidator.reset().parameter("id").value(command.getId()).notNull(); + baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("description").value(command.getDescription()).ignoreIfNull().notExceedingLengthOf(500); + baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().inMinMaxRange(0, 6); + baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("minInterestRate").value(command.getMinInterestRate()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("maxInterestRate").value(command.getMaxInterestRate()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("minInterestRate") + .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getMaxInterestRate()); + baseDataValidator.reset().parameter("interestRate") + .comapareMinAndMaxOfTwoBigDecmimalNos(command.getInterestRate(), command.getMaxInterestRate()); + baseDataValidator.reset().parameter("minInterestRate") + .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getInterestRate()); + baseDataValidator.reset().parameter("savingsDepositAmount").value(command.getSavingsDepositAmount()).ignoreIfNull() + .zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("savingProductType").value(command.getSavingProductType()).ignoreIfNull(); + baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).ignoreIfNull(); + baseDataValidator.reset().parameter("tenure").value(command.getTenure()).ignoreIfNull(); + baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).ignoreIfNull(); + baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull(); + baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).ignoreIfNull(); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).ignoreIfNull() + .zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()) + .trueOrFalseRequired(command.isPartialDepositAllowedChanged()).ignoreIfNull(); + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()) + .trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).ignoreIfNull(); + baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).ignoreIfNull(); + baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).ignoreIfNull(); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } + + public void validateForCreate() { + + List dataValidationErrors = new ArrayList(); + + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); + baseDataValidator.reset().parameter("name").value(command.getName()).notBlank(); + baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(500); + baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); + baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6); + baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).notNull().zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("minInterestRate").value(command.getMinInterestRate()).notNull().zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("maxInterestRate").value(command.getMaxInterestRate()).notNull().zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("minInterestRate") + .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getMaxInterestRate()); + baseDataValidator.reset().parameter("interestRate") + .comapareMinAndMaxOfTwoBigDecmimalNos(command.getInterestRate(), command.getMaxInterestRate()); + baseDataValidator.reset().parameter("minInterestRate") + .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getInterestRate()); + baseDataValidator.reset().parameter("savingsDepositAmount").value(command.getSavingsDepositAmount()).notNull() + .zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("savingProductType").value(command.getSavingProductType()).notNull(); + baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).notNull(); + baseDataValidator.reset().parameter("tenure").value(command.getTenure()).notNull(); + baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).notNull(); + baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).notNull(); + baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).notNull(); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).notNull() + .zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()) + .trueOrFalseRequired(command.isPartialDepositAllowedChanged()).notNull(); + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()) + .trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).notNull(); + baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).notNull(); + baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).notNull(); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductEnumerations.java index 0959deb5b..08cfe6528 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductEnumerations.java @@ -9,155 +9,181 @@ import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingsLockinPer import org.mifosplatform.portfolio.savingsdepositproduct.domain.TenureTypeEnum; public class SavingProductEnumerations { - - public static EnumOptionData savingProductType(final int id) { - return savingProductType(SavingProductType.fromInt(id)); - } - - public static EnumOptionData tenureTypeEnum(final int id) { - return tenureTypeEnum(TenureTypeEnum.fromInt(id)); - } - - public static EnumOptionData interestFrequencyType(final int id) { - return interestFrequencyType(SavingFrequencyType.fromInt(id)); - } - - public static EnumOptionData savingInterestType(final int id) { - return savingInterestType(SavingsInterestType.fromInt(id)); - } - - public static EnumOptionData savingInterestCalculationMethod(final int id) { - return savingInterestCalculationMethod(SavingInterestCalculationMethod.fromInt(id)); - } - - public static EnumOptionData savingsLockinPeriod(final int id){ - return savingsLockinPeriod(SavingsLockinPeriodEnum.fromInt(id)); - } - - public static EnumOptionData savingsLockinPeriod(SavingsLockinPeriodEnum type) { - final String codePrefix = "savings.product."; - EnumOptionData optionData = null; - switch (type) { - case DAYS: - optionData = new EnumOptionData(SavingsLockinPeriodEnum.DAYS.getValue().longValue(), codePrefix+SavingsLockinPeriodEnum.DAYS.getCode(), "Days"); - break; - case MONTHS: - optionData = new EnumOptionData(SavingsLockinPeriodEnum.MONTHS.getValue().longValue(), codePrefix+SavingsLockinPeriodEnum.MONTHS.getCode(), "Months"); - break; - case WEEKS: - optionData = new EnumOptionData(SavingsLockinPeriodEnum.WEEKS.getValue().longValue(), codePrefix+SavingsLockinPeriodEnum.WEEKS.getCode(), "Weeks"); - break; - case YEARS: - optionData = new EnumOptionData(SavingsLockinPeriodEnum.YEARS.getValue().longValue(), codePrefix+SavingsLockinPeriodEnum.YEARS.getCode(), "Years"); - break; - default: - optionData = new EnumOptionData(SavingsLockinPeriodEnum.INVALID.getValue().longValue(), codePrefix+SavingsLockinPeriodEnum.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } - public static EnumOptionData savingInterestCalculationMethod(SavingInterestCalculationMethod type) { - final String codePrefix = "savings.interestCalculation.method."; - EnumOptionData optionData = null; - switch (type) { - case MINBAL: - optionData = new EnumOptionData(SavingInterestCalculationMethod.MINBAL.getValue().longValue(), codePrefix+SavingInterestCalculationMethod.MINBAL.getCode(), "Minimumbalance"); - break; - case AVERAGEBAL: - optionData = new EnumOptionData(SavingInterestCalculationMethod.AVERAGEBAL.getValue().longValue(), codePrefix+SavingInterestCalculationMethod.AVERAGEBAL.getCode(), "AverageBalance"); - break; - case INVALID: - optionData = new EnumOptionData(SavingInterestCalculationMethod.INVALID.getValue().longValue(), codePrefix+SavingInterestCalculationMethod.INVALID.getCode(), "Invalid"); - break; - case MONTHLYCOLLECTION: - optionData = new EnumOptionData(SavingInterestCalculationMethod.MONTHLYCOLLECTION.getValue().longValue(), codePrefix+SavingInterestCalculationMethod.MONTHLYCOLLECTION.getCode(), "MonthlyCollection"); - break; - default: - optionData = new EnumOptionData(SavingInterestCalculationMethod.INVALID.getValue().longValue(), codePrefix+SavingInterestCalculationMethod.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + public static EnumOptionData savingProductType(final int id) { + return savingProductType(SavingProductType.fromInt(id)); + } - public static EnumOptionData savingInterestType(SavingsInterestType type) { - final String codePrefix = "savings.interest.type."; - EnumOptionData optionData = null; - switch (type) { - case COMPOUNDING: - optionData = new EnumOptionData(SavingsInterestType.COMPOUNDING.getValue().longValue(), codePrefix+SavingsInterestType.COMPOUNDING.getCode(), "Compounding"); - break; - case SIMPLE: - optionData = new EnumOptionData(SavingsInterestType.SIMPLE.getValue().longValue(), codePrefix+SavingsInterestType.SIMPLE.getCode(), "Simple"); - break; - default: - optionData = new EnumOptionData(SavingsInterestType.INVALID.getValue().longValue(), codePrefix+SavingsInterestType.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + public static EnumOptionData tenureTypeEnum(final int id) { + return tenureTypeEnum(TenureTypeEnum.fromInt(id)); + } - public static EnumOptionData interestFrequencyType(SavingFrequencyType type) { - final String codePrefix = "saving.product.frequency.period."; - EnumOptionData optionData = null; - switch (type) { - case DAILY: - optionData = new EnumOptionData(SavingFrequencyType.DAILY.getValue().longValue(), codePrefix + SavingFrequencyType.DAILY.getCode(), "Days"); - break; - case MONTHLY: - optionData = new EnumOptionData(SavingFrequencyType.MONTHLY.getValue().longValue(), codePrefix + SavingFrequencyType.MONTHLY.getCode(), "Weeks"); - break; - case QUATERLY: - optionData = new EnumOptionData(SavingFrequencyType.QUATERLY.getValue().longValue(), codePrefix + SavingFrequencyType.QUATERLY.getCode(), "Months"); - break; - case HALFYEARLY: - optionData = new EnumOptionData(SavingFrequencyType.HALFYEARLY.getValue().longValue(), codePrefix + SavingFrequencyType.HALFYEARLY.getCode(), "Months"); - break; - case YEARLY: - optionData = new EnumOptionData(SavingFrequencyType.YEARLY.getValue().longValue(), codePrefix + SavingFrequencyType.YEARLY.getCode(), "Yearly"); - break; - default: - optionData = new EnumOptionData(SavingFrequencyType.INVALID.getValue().longValue(), SavingFrequencyType.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + public static EnumOptionData interestFrequencyType(final int id) { + return interestFrequencyType(SavingFrequencyType.fromInt(id)); + } - public static EnumOptionData tenureTypeEnum(final TenureTypeEnum type) { - final String codePrefix = "savings.tenure."; - EnumOptionData optionData = null; - switch (type) { - case FIXED_PERIOD: - optionData = new EnumOptionData(TenureTypeEnum.FIXED_PERIOD.getValue().longValue(), codePrefix+TenureTypeEnum.FIXED_PERIOD.getCode(), "FixedPeriod"); - break; - case PERPETUAL: - optionData = new EnumOptionData(TenureTypeEnum.PERPETUAL.getValue().longValue(), codePrefix+TenureTypeEnum.PERPETUAL.getCode(), "Perpetual"); - break; - default: - optionData = new EnumOptionData(TenureTypeEnum.INVALID.getValue().longValue(), codePrefix+TenureTypeEnum.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + public static EnumOptionData savingInterestType(final int id) { + return savingInterestType(SavingsInterestType.fromInt(id)); + } - public static EnumOptionData savingProductType(final SavingProductType type) { - final String codePrefix = "savings.product."; - EnumOptionData optionData = null; - switch (type) { - case RECCURING: - optionData = new EnumOptionData(SavingProductType.RECCURING.getValue().longValue(), codePrefix + SavingProductType.RECCURING.getCode(), "Reccuring"); - break; - case REGULAR: - optionData = new EnumOptionData(SavingProductType.REGULAR.getValue().longValue(), codePrefix + SavingProductType.REGULAR.getCode(), "Regular"); - break; - case INVALID: - optionData = new EnumOptionData(SavingProductType.INVALID.getValue().longValue(), codePrefix + SavingProductType.INVALID.getCode(), "Invalid"); - break; - default: - optionData = new EnumOptionData(SavingProductType.INVALID.getValue().longValue(), SavingProductType.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + public static EnumOptionData savingInterestCalculationMethod(final int id) { + return savingInterestCalculationMethod(SavingInterestCalculationMethod.fromInt(id)); + } + + public static EnumOptionData savingsLockinPeriod(final int id) { + return savingsLockinPeriod(SavingsLockinPeriodEnum.fromInt(id)); + } + + public static EnumOptionData savingsLockinPeriod(SavingsLockinPeriodEnum type) { + final String codePrefix = "savings.product."; + EnumOptionData optionData = null; + switch (type) { + case DAYS: + optionData = new EnumOptionData(SavingsLockinPeriodEnum.DAYS.getValue().longValue(), codePrefix + + SavingsLockinPeriodEnum.DAYS.getCode(), "Days"); + break; + case MONTHS: + optionData = new EnumOptionData(SavingsLockinPeriodEnum.MONTHS.getValue().longValue(), codePrefix + + SavingsLockinPeriodEnum.MONTHS.getCode(), "Months"); + break; + case WEEKS: + optionData = new EnumOptionData(SavingsLockinPeriodEnum.WEEKS.getValue().longValue(), codePrefix + + SavingsLockinPeriodEnum.WEEKS.getCode(), "Weeks"); + break; + case YEARS: + optionData = new EnumOptionData(SavingsLockinPeriodEnum.YEARS.getValue().longValue(), codePrefix + + SavingsLockinPeriodEnum.YEARS.getCode(), "Years"); + break; + default: + optionData = new EnumOptionData(SavingsLockinPeriodEnum.INVALID.getValue().longValue(), codePrefix + + SavingsLockinPeriodEnum.INVALID.getCode(), "Invalid"); + break; + } + return optionData; + } + + public static EnumOptionData savingInterestCalculationMethod(SavingInterestCalculationMethod type) { + final String codePrefix = "savings.interestCalculation.method."; + EnumOptionData optionData = null; + switch (type) { + case MINBAL: + optionData = new EnumOptionData(SavingInterestCalculationMethod.MINBAL.getValue().longValue(), codePrefix + + SavingInterestCalculationMethod.MINBAL.getCode(), "Minimumbalance"); + break; + case AVERAGEBAL: + optionData = new EnumOptionData(SavingInterestCalculationMethod.AVERAGEBAL.getValue().longValue(), codePrefix + + SavingInterestCalculationMethod.AVERAGEBAL.getCode(), "AverageBalance"); + break; + case INVALID: + optionData = new EnumOptionData(SavingInterestCalculationMethod.INVALID.getValue().longValue(), codePrefix + + SavingInterestCalculationMethod.INVALID.getCode(), "Invalid"); + break; + case MONTHLYCOLLECTION: + optionData = new EnumOptionData(SavingInterestCalculationMethod.MONTHLYCOLLECTION.getValue().longValue(), codePrefix + + SavingInterestCalculationMethod.MONTHLYCOLLECTION.getCode(), "MonthlyCollection"); + break; + default: + optionData = new EnumOptionData(SavingInterestCalculationMethod.INVALID.getValue().longValue(), codePrefix + + SavingInterestCalculationMethod.INVALID.getCode(), "Invalid"); + break; + } + return optionData; + } + + public static EnumOptionData savingInterestType(SavingsInterestType type) { + final String codePrefix = "savings.interest.type."; + EnumOptionData optionData = null; + switch (type) { + case COMPOUNDING: + optionData = new EnumOptionData(SavingsInterestType.COMPOUNDING.getValue().longValue(), codePrefix + + SavingsInterestType.COMPOUNDING.getCode(), "Compounding"); + break; + case SIMPLE: + optionData = new EnumOptionData(SavingsInterestType.SIMPLE.getValue().longValue(), codePrefix + + SavingsInterestType.SIMPLE.getCode(), "Simple"); + break; + default: + optionData = new EnumOptionData(SavingsInterestType.INVALID.getValue().longValue(), codePrefix + + SavingsInterestType.INVALID.getCode(), "Invalid"); + break; + } + return optionData; + } + + public static EnumOptionData interestFrequencyType(SavingFrequencyType type) { + final String codePrefix = "saving.product.frequency.period."; + EnumOptionData optionData = null; + switch (type) { + case DAILY: + optionData = new EnumOptionData(SavingFrequencyType.DAILY.getValue().longValue(), codePrefix + + SavingFrequencyType.DAILY.getCode(), "Days"); + break; + case MONTHLY: + optionData = new EnumOptionData(SavingFrequencyType.MONTHLY.getValue().longValue(), codePrefix + + SavingFrequencyType.MONTHLY.getCode(), "Weeks"); + break; + case QUATERLY: + optionData = new EnumOptionData(SavingFrequencyType.QUATERLY.getValue().longValue(), codePrefix + + SavingFrequencyType.QUATERLY.getCode(), "Months"); + break; + case HALFYEARLY: + optionData = new EnumOptionData(SavingFrequencyType.HALFYEARLY.getValue().longValue(), codePrefix + + SavingFrequencyType.HALFYEARLY.getCode(), "Months"); + break; + case YEARLY: + optionData = new EnumOptionData(SavingFrequencyType.YEARLY.getValue().longValue(), codePrefix + + SavingFrequencyType.YEARLY.getCode(), "Yearly"); + break; + default: + optionData = new EnumOptionData(SavingFrequencyType.INVALID.getValue().longValue(), SavingFrequencyType.INVALID.getCode(), + "Invalid"); + break; + } + return optionData; + } + + public static EnumOptionData tenureTypeEnum(final TenureTypeEnum type) { + final String codePrefix = "savings.tenure."; + EnumOptionData optionData = null; + switch (type) { + case FIXED_PERIOD: + optionData = new EnumOptionData(TenureTypeEnum.FIXED_PERIOD.getValue().longValue(), codePrefix + + TenureTypeEnum.FIXED_PERIOD.getCode(), "FixedPeriod"); + break; + case PERPETUAL: + optionData = new EnumOptionData(TenureTypeEnum.PERPETUAL.getValue().longValue(), codePrefix + + TenureTypeEnum.PERPETUAL.getCode(), "Perpetual"); + break; + default: + optionData = new EnumOptionData(TenureTypeEnum.INVALID.getValue().longValue(), codePrefix + + TenureTypeEnum.INVALID.getCode(), "Invalid"); + break; + } + return optionData; + } + + public static EnumOptionData savingProductType(final SavingProductType type) { + final String codePrefix = "savings.product."; + EnumOptionData optionData = null; + switch (type) { + case RECCURING: + optionData = new EnumOptionData(SavingProductType.RECCURING.getValue().longValue(), codePrefix + + SavingProductType.RECCURING.getCode(), "Reccuring"); + break; + case REGULAR: + optionData = new EnumOptionData(SavingProductType.REGULAR.getValue().longValue(), codePrefix + + SavingProductType.REGULAR.getCode(), "Regular"); + break; + case INVALID: + optionData = new EnumOptionData(SavingProductType.INVALID.getValue().longValue(), codePrefix + + SavingProductType.INVALID.getCode(), "Invalid"); + break; + default: + optionData = new EnumOptionData(SavingProductType.INVALID.getValue().longValue(), SavingProductType.INVALID.getCode(), + "Invalid"); + break; + } + return optionData; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformService.java index 1be8bd70d..ea90802b3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformService.java @@ -7,11 +7,11 @@ import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductLooku public interface SavingProductReadPlatformService { - Collection retrieveAllSavingProducts(); + Collection retrieveAllSavingProducts(); - Collection retrieveAllSavingProductsForLookup(); + Collection retrieveAllSavingProductsForLookup(); - SavingProductData retrieveSavingProduct(Long productId); + SavingProductData retrieveSavingProduct(Long productId); - SavingProductData retrieveNewSavingProductDetails(); + SavingProductData retrieveNewSavingProductDetails(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformServiceImpl.java index 2b61224e7..275e523b3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductReadPlatformServiceImpl.java @@ -25,150 +25,151 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; @Service -public class SavingProductReadPlatformServiceImpl implements - SavingProductReadPlatformService { - - private final PlatformSecurityContext context; - private final JdbcTemplate jdbcTemplate; - private final CurrencyReadPlatformService currencyReadPlatformService; - - @Autowired - public SavingProductReadPlatformServiceImpl(final PlatformSecurityContext context,final TenantAwareRoutingDataSource dataSource,final CurrencyReadPlatformService currencyReadPlatformService) { - - this.context=context; - jdbcTemplate=new JdbcTemplate(dataSource); - this.currencyReadPlatformService=currencyReadPlatformService; - } +public class SavingProductReadPlatformServiceImpl implements SavingProductReadPlatformService { - @Override - public Collection retrieveAllSavingProducts() { - - this.context.authenticatedUser(); - - SavingProductMapper savingProductMapper=new SavingProductMapper(); - - String sql = "select " + savingProductMapper.savingProductSchema() + " where sp.is_deleted=0"; - - return this.jdbcTemplate.query(sql,savingProductMapper, new Object[]{}); - - } + private final PlatformSecurityContext context; + private final JdbcTemplate jdbcTemplate; + private final CurrencyReadPlatformService currencyReadPlatformService; - @Override - public Collection retrieveAllSavingProductsForLookup() { - - this.context.authenticatedUser(); - - SavingProductLookupMapper savingProductLookupMapper=new SavingProductLookupMapper(); - - String sql="select"+savingProductLookupMapper.savingProductLookupSchema(); - - return this.jdbcTemplate.query(sql, savingProductLookupMapper, new Object[]{}); - } + @Autowired + public SavingProductReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, + final CurrencyReadPlatformService currencyReadPlatformService) { - @Override - public SavingProductData retrieveSavingProduct(Long savingProductId) { - try{ - this.context.authenticatedUser(); - SavingProductMapper savingProductMapper=new SavingProductMapper(); - String sql = "select " + savingProductMapper.savingProductSchema() - + " where sp.id = ? and sp.is_deleted=0"; - SavingProductData productData = this.jdbcTemplate.queryForObject(sql, - savingProductMapper, new Object[] { savingProductId }); - - populateProductDataWithDropdownOptions(productData); + this.context = context; + jdbcTemplate = new JdbcTemplate(dataSource); + this.currencyReadPlatformService = currencyReadPlatformService; + } - return productData; - } catch (EmptyResultDataAccessException e) { - throw new LoanProductNotFoundException(savingProductId); - } - } + @Override + public Collection retrieveAllSavingProducts() { - @Override - public SavingProductData retrieveNewSavingProductDetails() { - - SavingProductData productData=new SavingProductData(); - - populateProductDataWithDropdownOptions(productData); - - return productData; - } - - private static final class SavingProductMapper implements RowMapper { - - public String savingProductSchema(){ - return "sp.id as id,sp.name as name, sp.description as description,sp.currency_code as currencyCode, sp.currency_digits as currencyDigits,sp.interest_rate as interestRate, " - + "sp.min_interest_rate as minInterestRate, sp.max_interest_rate as maxInterstRate, " - + " sp.savings_deposit_amount as savingsDepositAmount, sp.savings_product_type as savingProductType, sp.tenure_type as tenureType, sp.tenure as tenure, sp.frequency as frequency, " - + " sp.interest_type as interestType, sp.interest_calculation_method as interestCalculationMethod, sp.min_bal_for_withdrawal as minimumBalanceForWithdrawal, " - + " sp.is_partial_deposit_allowed as isPartialDepositAllowed, sp.is_lock_in_period_allowed as isLockinPeriodAllowed, sp.lock_in_period as lockinPeriod, sp.lock_in_period_type as lockinPeriodType, " - + " sp.created_date as createdon, sp.lastmodified_date as modifiedon, " - + "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol" - + " from m_product_savings sp join m_currency curr on curr.code = sp.currency_code"; - } + this.context.authenticatedUser(); - @Override - public SavingProductData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) - throws SQLException { - - Long id = rs.getLong("id"); - String name = rs.getString("name"); - String description = rs.getString("description"); - - String currencyCode = rs.getString("currencyCode"); - String currencyName = rs.getString("currencyName"); - String currencyNameCode = rs.getString("currencyNameCode"); - String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol"); - Integer currencyDigits = JdbcSupport.getInteger(rs,"currencyDigits"); - - CurrencyData currencyData = new CurrencyData(currencyCode,currencyName, currencyDigits, currencyDisplaySymbol,currencyNameCode); - BigDecimal interestRate = rs.getBigDecimal("interestRate"); - BigDecimal minInterestRate = rs.getBigDecimal("minInterestRate"); - BigDecimal maxInterestRate = rs.getBigDecimal("maxInterstRate"); - - DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon"); - DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon"); - - BigDecimal savingsDepositAmount=rs.getBigDecimal("savingsDepositAmount"); - EnumOptionData savingProductTypeEnum=SavingProductEnumerations.savingProductType(SavingProductType.fromInt(JdbcSupport.getInteger(rs, "savingProductType"))); - EnumOptionData tenureTypeEnum = SavingProductEnumerations.tenureTypeEnum(JdbcSupport.getInteger(rs, "tenureType")); - Integer tenure = JdbcSupport.getInteger(rs, "tenure"); - EnumOptionData savingFrequencyType = SavingProductEnumerations.interestFrequencyType(JdbcSupport.getInteger(rs, "frequency")); - EnumOptionData savingInterestType = SavingProductEnumerations.savingInterestType(JdbcSupport.getInteger(rs, "interestType")); - EnumOptionData interestCalculationMethodEnum=SavingProductEnumerations.savingInterestCalculationMethod(JdbcSupport.getInteger(rs, "interestCalculationMethod")); - BigDecimal minimumBalanceForWithdrawal=rs.getBigDecimal("minimumBalanceForWithdrawal"); - boolean isPartialDepositAllowed = rs.getBoolean("isPartialDepositAllowed"); - boolean isLockinPeriodAllowed =rs.getBoolean("isLockinPeriodAllowed"); - Integer lockinPeriod=JdbcSupport.getInteger(rs, "lockinPeriod"); - EnumOptionData lockinPeriodType= SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.fromInt(JdbcSupport.getInteger(rs, "lockinPeriodType"))); - - return new SavingProductData(createdOn, lastModifedOn, id, name, description, interestRate, minInterestRate, maxInterestRate, currencyData, currencyDigits, savingsDepositAmount, - savingProductTypeEnum, tenureTypeEnum, tenure, savingFrequencyType, savingInterestType, interestCalculationMethodEnum, - minimumBalanceForWithdrawal, isPartialDepositAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - } - } - - private static final class SavingProductLookupMapper implements - RowMapper { + SavingProductMapper savingProductMapper = new SavingProductMapper(); - public String savingProductLookupSchema() { - return "sp.id as id, sp.name as name from m_product_savings sp"; - } + String sql = "select " + savingProductMapper.savingProductSchema() + " where sp.is_deleted=0"; - @Override - public SavingProductLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) - throws SQLException { + return this.jdbcTemplate.query(sql, savingProductMapper, new Object[] {}); - Long id = rs.getLong("id"); - String name = rs.getString("name"); + } - return new SavingProductLookup(id, name); - } + @Override + public Collection retrieveAllSavingProductsForLookup() { - } - private void populateProductDataWithDropdownOptions(final SavingProductData productData) { + this.context.authenticatedUser(); - List currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); - productData.setCurrencyOptions(currencyOptions); - } + SavingProductLookupMapper savingProductLookupMapper = new SavingProductLookupMapper(); + + String sql = "select" + savingProductLookupMapper.savingProductLookupSchema(); + + return this.jdbcTemplate.query(sql, savingProductLookupMapper, new Object[] {}); + } + + @Override + public SavingProductData retrieveSavingProduct(Long savingProductId) { + try { + this.context.authenticatedUser(); + SavingProductMapper savingProductMapper = new SavingProductMapper(); + String sql = "select " + savingProductMapper.savingProductSchema() + " where sp.id = ? and sp.is_deleted=0"; + SavingProductData productData = this.jdbcTemplate.queryForObject(sql, savingProductMapper, new Object[] { savingProductId }); + + populateProductDataWithDropdownOptions(productData); + + return productData; + } catch (EmptyResultDataAccessException e) { + throw new LoanProductNotFoundException(savingProductId); + } + } + + @Override + public SavingProductData retrieveNewSavingProductDetails() { + + SavingProductData productData = new SavingProductData(); + + populateProductDataWithDropdownOptions(productData); + + return productData; + } + + private static final class SavingProductMapper implements RowMapper { + + public String savingProductSchema() { + return "sp.id as id,sp.name as name, sp.description as description,sp.currency_code as currencyCode, sp.currency_digits as currencyDigits,sp.interest_rate as interestRate, " + + "sp.min_interest_rate as minInterestRate, sp.max_interest_rate as maxInterstRate, " + + " sp.savings_deposit_amount as savingsDepositAmount, sp.savings_product_type as savingProductType, sp.tenure_type as tenureType, sp.tenure as tenure, sp.frequency as frequency, " + + " sp.interest_type as interestType, sp.interest_calculation_method as interestCalculationMethod, sp.min_bal_for_withdrawal as minimumBalanceForWithdrawal, " + + " sp.is_partial_deposit_allowed as isPartialDepositAllowed, sp.is_lock_in_period_allowed as isLockinPeriodAllowed, sp.lock_in_period as lockinPeriod, sp.lock_in_period_type as lockinPeriodType, " + + " sp.created_date as createdon, sp.lastmodified_date as modifiedon, " + + "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol" + + " from m_product_savings sp join m_currency curr on curr.code = sp.currency_code"; + } + + @Override + public SavingProductData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + + Long id = rs.getLong("id"); + String name = rs.getString("name"); + String description = rs.getString("description"); + + String currencyCode = rs.getString("currencyCode"); + String currencyName = rs.getString("currencyName"); + String currencyNameCode = rs.getString("currencyNameCode"); + String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol"); + Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits"); + + CurrencyData currencyData = new CurrencyData(currencyCode, currencyName, currencyDigits, currencyDisplaySymbol, + currencyNameCode); + BigDecimal interestRate = rs.getBigDecimal("interestRate"); + BigDecimal minInterestRate = rs.getBigDecimal("minInterestRate"); + BigDecimal maxInterestRate = rs.getBigDecimal("maxInterstRate"); + + DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon"); + DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon"); + + BigDecimal savingsDepositAmount = rs.getBigDecimal("savingsDepositAmount"); + EnumOptionData savingProductTypeEnum = SavingProductEnumerations.savingProductType(SavingProductType.fromInt(JdbcSupport + .getInteger(rs, "savingProductType"))); + EnumOptionData tenureTypeEnum = SavingProductEnumerations.tenureTypeEnum(JdbcSupport.getInteger(rs, "tenureType")); + Integer tenure = JdbcSupport.getInteger(rs, "tenure"); + EnumOptionData savingFrequencyType = SavingProductEnumerations.interestFrequencyType(JdbcSupport.getInteger(rs, "frequency")); + EnumOptionData savingInterestType = SavingProductEnumerations.savingInterestType(JdbcSupport.getInteger(rs, "interestType")); + EnumOptionData interestCalculationMethodEnum = SavingProductEnumerations.savingInterestCalculationMethod(JdbcSupport + .getInteger(rs, "interestCalculationMethod")); + BigDecimal minimumBalanceForWithdrawal = rs.getBigDecimal("minimumBalanceForWithdrawal"); + boolean isPartialDepositAllowed = rs.getBoolean("isPartialDepositAllowed"); + boolean isLockinPeriodAllowed = rs.getBoolean("isLockinPeriodAllowed"); + Integer lockinPeriod = JdbcSupport.getInteger(rs, "lockinPeriod"); + EnumOptionData lockinPeriodType = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType + .fromInt(JdbcSupport.getInteger(rs, "lockinPeriodType"))); + + return new SavingProductData(createdOn, lastModifedOn, id, name, description, interestRate, minInterestRate, maxInterestRate, + currencyData, currencyDigits, savingsDepositAmount, savingProductTypeEnum, tenureTypeEnum, tenure, savingFrequencyType, + savingInterestType, interestCalculationMethodEnum, minimumBalanceForWithdrawal, isPartialDepositAllowed, + isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); + } + } + + private static final class SavingProductLookupMapper implements RowMapper { + + public String savingProductLookupSchema() { + return "sp.id as id, sp.name as name from m_product_savings sp"; + } + + @Override + public SavingProductLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + Long id = rs.getLong("id"); + String name = rs.getString("name"); + + return new SavingProductLookup(id, name); + } + + } + + private void populateProductDataWithDropdownOptions(final SavingProductData productData) { + + List currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); + productData.setCurrencyOptions(currencyOptions); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java index 669a0280b..cc5e07fb4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java @@ -6,12 +6,12 @@ import org.springframework.security.access.prepost.PreAuthorize; public interface SavingProductWritePlatformService { - @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'CREATE_SAVINGSPRODUCT')") - EntityIdentifier createSavingProduct(SavingProductCommand command); - - @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_SAVINGSPRODUCT')") - EntityIdentifier updateSavingProduct(SavingProductCommand command); - - @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'DELETE_SAVINGSPRODUCT')") - EntityIdentifier deleteSavingProduct(Long productId); + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'CREATE_SAVINGSPRODUCT')") + EntityIdentifier createSavingProduct(SavingProductCommand command); + + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_SAVINGSPRODUCT')") + EntityIdentifier updateSavingProduct(SavingProductCommand command); + + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'DELETE_SAVINGSPRODUCT')") + EntityIdentifier deleteSavingProduct(Long productId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java index e0860ec31..8f611b497 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java @@ -21,70 +21,68 @@ import org.springframework.transaction.annotation.Transactional; @Service public class SavingProductWritePlatformServiceJpaRepositoryImpl implements SavingProductWritePlatformService { - private final PlatformSecurityContext context; - private final SavingProductRepository savingProductRepository; - - @Autowired - public SavingProductWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final SavingProductRepository savingProductRepository) { - this.context=context; - this.savingProductRepository=savingProductRepository; - } - - @Transactional - @Override - public EntityIdentifier createSavingProduct(final SavingProductCommand command) { - - this.context.authenticatedUser(); - SavingProductCommandValidator validator=new SavingProductCommandValidator(command); - validator.validateForCreate(); - - SavingProductType savingProductType = SavingProductType.fromInt(command.getSavingProductType()); - TenureTypeEnum tenureType = TenureTypeEnum.fromInt(command.getTenureType()); - SavingFrequencyType savingFrequencyType=SavingFrequencyType.fromInt(command.getFrequency()); - SavingsInterestType interestType = SavingsInterestType.fromInt(command.getInterestType()); - PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - SavingInterestCalculationMethod savingInterestCalculationMethod=SavingInterestCalculationMethod.fromInt(command.getInterestCalculationMethod()); - MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal()); - - SavingProduct product = new SavingProduct(command.getName(), command.getDescription(), currency, command.getInterestRate(), command.getMinInterestRate(), command.getMaxInterestRate(), - command.getSavingsDepositAmount(), savingProductType, tenureType, command.getTenure(), savingFrequencyType, interestType, - savingInterestCalculationMethod, command.getMinimumBalanceForWithdrawal(), command.isPartialDepositAllowed(), - command.isLockinPeriodAllowed(), command.getLockinPeriod(), lockinPeriodType); - - this.savingProductRepository.save(product); - return new EntityIdentifier(product.getId()); - } + private final PlatformSecurityContext context; + private final SavingProductRepository savingProductRepository; - @Transactional - @Override - public EntityIdentifier updateSavingProduct(final SavingProductCommand command) { - - this.context.authenticatedUser(); - SavingProductCommandValidator validator=new SavingProductCommandValidator(command); - validator.validateForUpdate(); - - SavingProduct product=this.savingProductRepository.findOne(command.getId()); - if (product == null) { - throw new SavingProductNotFoundException(command.getId()); - } - product.update(command); - this.savingProductRepository.save(product); - return new EntityIdentifier(Long.valueOf(product.getId())); - } + @Autowired + public SavingProductWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, + final SavingProductRepository savingProductRepository) { + this.context = context; + this.savingProductRepository = savingProductRepository; + } + + @Transactional + @Override + public EntityIdentifier createSavingProduct(final SavingProductCommand command) { + + this.context.authenticatedUser(); + SavingProductCommandValidator validator = new SavingProductCommandValidator(command); + validator.validateForCreate(); + + SavingProductType savingProductType = SavingProductType.fromInt(command.getSavingProductType()); + TenureTypeEnum tenureType = TenureTypeEnum.fromInt(command.getTenureType()); + SavingFrequencyType savingFrequencyType = SavingFrequencyType.fromInt(command.getFrequency()); + SavingsInterestType interestType = SavingsInterestType.fromInt(command.getInterestType()); + PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(command + .getInterestCalculationMethod()); + MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal()); + + SavingProduct product = new SavingProduct(command.getName(), command.getDescription(), currency, command.getInterestRate(), + command.getMinInterestRate(), command.getMaxInterestRate(), command.getSavingsDepositAmount(), savingProductType, + tenureType, command.getTenure(), savingFrequencyType, interestType, savingInterestCalculationMethod, + command.getMinimumBalanceForWithdrawal(), command.isPartialDepositAllowed(), command.isLockinPeriodAllowed(), + command.getLockinPeriod(), lockinPeriodType); + + this.savingProductRepository.save(product); + return new EntityIdentifier(product.getId()); + } + + @Transactional + @Override + public EntityIdentifier updateSavingProduct(final SavingProductCommand command) { + + this.context.authenticatedUser(); + SavingProductCommandValidator validator = new SavingProductCommandValidator(command); + validator.validateForUpdate(); + + SavingProduct product = this.savingProductRepository.findOne(command.getId()); + if (product == null) { throw new SavingProductNotFoundException(command.getId()); } + product.update(command); + this.savingProductRepository.save(product); + return new EntityIdentifier(Long.valueOf(product.getId())); + } + + @Transactional + @Override + public EntityIdentifier deleteSavingProduct(Long productId) { + + this.context.authenticatedUser(); + SavingProduct product = this.savingProductRepository.findOne(productId); + if (product == null || product.isDeleted()) { throw new SavingsProductNotFoundException(productId); } + product.delete(); + this.savingProductRepository.save(product); + return new EntityIdentifier(Long.valueOf(product.getId())); + } - @Transactional - @Override - public EntityIdentifier deleteSavingProduct(Long productId) { - - this.context.authenticatedUser(); - SavingProduct product=this.savingProductRepository.findOne(productId); - if (product==null || product.isDeleted()) { - throw new SavingsProductNotFoundException(productId); - } - product.delete(); - this.savingProductRepository.save(product); - return new EntityIdentifier(Long.valueOf(product.getId())); - } - - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingsDepositEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingsDepositEnumerations.java index f56a09742..834d17b75 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingsDepositEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingsDepositEnumerations.java @@ -4,28 +4,32 @@ import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType; public class SavingsDepositEnumerations { - - public static EnumOptionData interestCompoundingPeriodType(final int id) { - return interestCompoundingPeriodType(PeriodFrequencyType.fromInt(id)); - } - - public static EnumOptionData interestCompoundingPeriodType(final PeriodFrequencyType type) { - final String codePrefix = "deposit.interest.compounding.period."; - EnumOptionData optionData = null; - switch (type) { - case DAYS: - optionData = new EnumOptionData(PeriodFrequencyType.DAYS.getValue().longValue(), codePrefix + PeriodFrequencyType.DAYS.getCode(), "Days"); - break; - case WEEKS: - optionData = new EnumOptionData(PeriodFrequencyType.WEEKS.getValue().longValue(), codePrefix + PeriodFrequencyType.WEEKS.getCode(), "Weeks"); - break; - case MONTHS: - optionData = new EnumOptionData(PeriodFrequencyType.MONTHS.getValue().longValue(), codePrefix + PeriodFrequencyType.MONTHS.getCode(), "Months"); - break; - default: - optionData = new EnumOptionData(PeriodFrequencyType.INVALID.getValue().longValue(), PeriodFrequencyType.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + + public static EnumOptionData interestCompoundingPeriodType(final int id) { + return interestCompoundingPeriodType(PeriodFrequencyType.fromInt(id)); + } + + public static EnumOptionData interestCompoundingPeriodType(final PeriodFrequencyType type) { + final String codePrefix = "deposit.interest.compounding.period."; + EnumOptionData optionData = null; + switch (type) { + case DAYS: + optionData = new EnumOptionData(PeriodFrequencyType.DAYS.getValue().longValue(), codePrefix + + PeriodFrequencyType.DAYS.getCode(), "Days"); + break; + case WEEKS: + optionData = new EnumOptionData(PeriodFrequencyType.WEEKS.getValue().longValue(), codePrefix + + PeriodFrequencyType.WEEKS.getCode(), "Weeks"); + break; + case MONTHS: + optionData = new EnumOptionData(PeriodFrequencyType.MONTHS.getValue().longValue(), codePrefix + + PeriodFrequencyType.MONTHS.getCode(), "Months"); + break; + default: + optionData = new EnumOptionData(PeriodFrequencyType.INVALID.getValue().longValue(), PeriodFrequencyType.INVALID.getCode(), + "Invalid"); + break; + } + return optionData; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java index a5c15de05..48bacdda9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java @@ -258,16 +258,16 @@ public class DepositAccountsApiResource { private boolean is(final String commandParam, final String commandValue) { return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue); - } - @POST - @Path("postinterest") - @Consumes({ MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_JSON }) - public Response postInterest(){ - Collection accounts = this.depositAccountReadPlatformService.retrieveDepositAccountForLookup(); - @SuppressWarnings("unused") - EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.postInterestToDepositAccount(accounts); - return Response.ok().entity(entityIdentifier).build(); - + } + + @POST + @Path("postinterest") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response postInterest() { + Collection accounts = this.depositAccountReadPlatformService.retrieveDepositAccountForLookup(); + EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.postInterestToDepositAccount(accounts); + return Response.ok().entity(entityIdentifier).build(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountData.java index f196c87ee..d5fedfda3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountData.java @@ -65,11 +65,11 @@ public class DepositAccountData { private final boolean isLockinPeriodAllowed; private final Integer lockinPeriod; private final EnumOptionData lockinPeriodType; - + private final BigDecimal availableInterest; - private final BigDecimal interestPostedAmount; - private final LocalDate lastInterestPostedDate; - private final LocalDate nextInterestPostedDate; + private final BigDecimal interestPostedAmount; + private final LocalDate lastInterestPostedDate; + private final LocalDate nextInterestPostedDate; /* * used when returning account template data but only a clientId is passed, @@ -124,11 +124,11 @@ public class DepositAccountData { this.isLockinPeriodAllowed = true; this.lockinPeriod = null; this.lockinPeriodType = null; - + this.availableInterest = BigDecimal.ZERO; - this.interestPostedAmount = BigDecimal.ZERO; - this.lastInterestPostedDate = null; - this.nextInterestPostedDate = null; + this.interestPostedAmount = BigDecimal.ZERO; + this.lastInterestPostedDate = null; + this.nextInterestPostedDate = null; } public DepositAccountData(final DepositAccountData account, final List interestCompoundedEveryPeriodTypeOptions, @@ -176,11 +176,11 @@ public class DepositAccountData { this.lockinPeriod = account.getLockinPeriod(); this.lockinPeriodType = account.getLockinPeriodType(); this.isLockinPeriodAllowed = account.isLockinPeriodAllowed(); - + this.availableInterest = account.getAvailableInterest(); - this.interestPostedAmount = account.getInterestPostedAmount(); - this.lastInterestPostedDate = account.getLastInterestPostedDate(); - this.nextInterestPostedDate = account.getNextInterestPostedDate(); + this.interestPostedAmount = account.getInterestPostedAmount(); + this.lastInterestPostedDate = account.getLastInterestPostedDate(); + this.nextInterestPostedDate = account.getNextInterestPostedDate(); } public DepositAccountData(final DepositAccountData account, final DepositPermissionData permissions, @@ -228,11 +228,11 @@ public class DepositAccountData { this.lockinPeriod = account.getLockinPeriod(); this.lockinPeriodType = account.getLockinPeriodType(); this.isLockinPeriodAllowed = account.isLockinPeriodAllowed(); - + this.availableInterest = account.getAvailableInterest(); - this.interestPostedAmount = account.getInterestPostedAmount(); - this.lastInterestPostedDate = account.getLastInterestPostedDate(); - this.nextInterestPostedDate = account.getNextInterestPostedDate(); + this.interestPostedAmount = account.getInterestPostedAmount(); + this.lastInterestPostedDate = account.getLastInterestPostedDate(); + this.nextInterestPostedDate = account.getNextInterestPostedDate(); } public DepositAccountData(final Long id, final String externalId, final EnumOptionData status, final Long clientId, @@ -244,7 +244,7 @@ public class DepositAccountData { final boolean preClosureAllowed, final BigDecimal preClosureInterestRate, final LocalDate withdrawnonDate, final LocalDate rejectedonDate, final LocalDate closedonDate, final boolean isInterestWithdrawable, final BigDecimal interestPaid, final boolean interestCompoundingAllowed, final boolean isLockinPeriodAllowed, - final Integer lockinPeriod, final EnumOptionData lockinPeriodType,final BigDecimal availableInterest, + final Integer lockinPeriod, final EnumOptionData lockinPeriodType, final BigDecimal availableInterest, final BigDecimal interestPostedAmount, final LocalDate lastInterestPostedDate, final LocalDate nextInterestPostedDate) { this.id = id; this.externalId = externalId; @@ -290,11 +290,11 @@ public class DepositAccountData { this.isLockinPeriodAllowed = isLockinPeriodAllowed; this.lockinPeriod = lockinPeriod; this.lockinPeriodType = lockinPeriodType; - + this.availableInterest = availableInterest; - this.interestPostedAmount = interestPostedAmount; - this.lastInterestPostedDate = lastInterestPostedDate; - this.nextInterestPostedDate = nextInterestPostedDate; + this.interestPostedAmount = interestPostedAmount; + this.lastInterestPostedDate = lastInterestPostedDate; + this.nextInterestPostedDate = nextInterestPostedDate; } public DepositAccountData(final Long clientId, final String clientName, final Long productId, final String productName, @@ -345,11 +345,11 @@ public class DepositAccountData { this.lockinPeriod = Integer.valueOf(0); this.isLockinPeriodAllowed = true; this.lockinPeriodType = interestCompoundedEveryPeriodType; - + this.availableInterest = BigDecimal.ZERO; - this.interestPostedAmount = BigDecimal.ZERO; - this.lastInterestPostedDate = null; - this.nextInterestPostedDate = null; + this.interestPostedAmount = BigDecimal.ZERO; + this.lastInterestPostedDate = null; + this.nextInterestPostedDate = null; } public Long getId() { @@ -509,66 +509,77 @@ public class DepositAccountData { } public BigDecimal getAvailableInterest() { - return this.availableInterest; - } + return this.availableInterest; + } - public BigDecimal getInterestPostedAmount() { - return this.interestPostedAmount; - } + public BigDecimal getInterestPostedAmount() { + return this.interestPostedAmount; + } - public LocalDate getLastInterestPostedDate() { - return this.lastInterestPostedDate; - } + public LocalDate getLastInterestPostedDate() { + return this.lastInterestPostedDate; + } - public LocalDate getNextInterestPostedDate() { - return this.nextInterestPostedDate; - } - private BigDecimal determineAvailableInterestForWithdrawal(final DepositAccountData account) { - BigDecimal availableInterestForWithdrawal = BigDecimal.ZERO; - - if(this.status!=null){ - if (account.getStatus().getId() == 300) { - BigDecimal interestGettingForPeriod = BigDecimal.valueOf(account.getActualInterestAccrued().doubleValue()/ new Double(account.getTenureInMonths())); - LocalDate interestWithdrawingDate= new LocalDate().isBefore(getMaturedOn())?new LocalDate():getMaturedOn().plusDays(1); - Integer noOfMonthsforInterestCal = Months.monthsBetween(account.getActualCommencementDate(), interestWithdrawingDate).getMonths(); - Integer noOfPeriods = noOfMonthsforInterestCal/ account.getInterestCompoundedEvery(); + public LocalDate getNextInterestPostedDate() { + return this.nextInterestPostedDate; + } - availableInterestForWithdrawal = BigDecimal.valueOf(interestGettingForPeriod.multiply(new BigDecimal(noOfPeriods)).doubleValue()- account.getInterestPaid().doubleValue()); - }else { - return BigDecimal.ZERO; - } - }else return BigDecimal.ZERO; - - return availableInterestForWithdrawal; - } - - private BigDecimal determineAvalableWithdrawalAmount(final DepositAccountData account) { - - BigDecimal avalablePreclosureWithdrawalAmount = BigDecimal.ZERO; - if(this.status != null){ - if (account.getStatus().getId() == 300) { - // if(new LocalDate().isBefore(account.getMaturedOn()) || new LocalDate().isEqual(account.getMaturedOn())){ - Integer days = Days.daysBetween(account.getLastInterestPostedDate(), new LocalDate()).getDays(); - avalablePreclosureWithdrawalAmount=account.getAvailableInterest().add(account.getDeposit()).add(determineRemainInerestAmount(account.getDeposit(), account.getPreClosureInterestRate(), days)); - - // }else if(new LocalDate().isAfter(account.getMaturedOn())){ - // Integer days = Days.daysBetween(account.getLastInterestPostedDate(), new LocalDate()).getDays(); - // avalablePreclosureWithdrawalAmount=account.getAvailableInterest().add(account.getDeposit()).add(determineRemainInerestAmount(account.getDeposit(), account.getPreClosureInterestRate(), days)); - // } - }else{ - avalablePreclosureWithdrawalAmount=account.getDeposit(); - } - } - return avalablePreclosureWithdrawalAmount; - } - - private BigDecimal determineRemainInerestAmount(final BigDecimal depsoitAmount, final BigDecimal interstRateApplicable, final Integer days){ + private BigDecimal determineAvailableInterestForWithdrawal(final DepositAccountData account) { + BigDecimal availableInterestForWithdrawal = BigDecimal.ZERO; - MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); - Integer daysInYear = 365; - BigDecimal interestRateAsFraction = interstRateApplicable.divide(BigDecimal.valueOf(100), mc); - BigDecimal interestRateForOneDay = interestRateAsFraction.divide(BigDecimal.valueOf(daysInYear.doubleValue()), mc); - return BigDecimal.valueOf(depsoitAmount.doubleValue()*days.doubleValue()*interestRateForOneDay.doubleValue()); - - } + if (this.status != null) { + if (account.getStatus().getId() == 300) { + BigDecimal interestGettingForPeriod = BigDecimal.valueOf(account.getActualInterestAccrued().doubleValue() + / new Double(account.getTenureInMonths())); + LocalDate interestWithdrawingDate = new LocalDate().isBefore(getMaturedOn()) ? new LocalDate() : getMaturedOn().plusDays(1); + Integer noOfMonthsforInterestCal = Months.monthsBetween(account.getActualCommencementDate(), interestWithdrawingDate) + .getMonths(); + Integer noOfPeriods = noOfMonthsforInterestCal / account.getInterestCompoundedEvery(); + + availableInterestForWithdrawal = BigDecimal.valueOf(interestGettingForPeriod.multiply(new BigDecimal(noOfPeriods)) + .doubleValue() - account.getInterestPaid().doubleValue()); + } else { + return BigDecimal.ZERO; + } + } else + return BigDecimal.ZERO; + + return availableInterestForWithdrawal; + } + + private BigDecimal determineAvalableWithdrawalAmount(final DepositAccountData account) { + + BigDecimal avalablePreclosureWithdrawalAmount = BigDecimal.ZERO; + if (this.status != null) { + if (account.getStatus().getId() == 300) { + // if(new LocalDate().isBefore(account.getMaturedOn()) || new + // LocalDate().isEqual(account.getMaturedOn())){ + Integer days = Days.daysBetween(account.getLastInterestPostedDate(), new LocalDate()).getDays(); + avalablePreclosureWithdrawalAmount = account.getAvailableInterest().add(account.getDeposit()) + .add(determineRemainInerestAmount(account.getDeposit(), account.getPreClosureInterestRate(), days)); + + // }else if(new LocalDate().isAfter(account.getMaturedOn())){ + // Integer days = + // Days.daysBetween(account.getLastInterestPostedDate(), new + // LocalDate()).getDays(); + // avalablePreclosureWithdrawalAmount=account.getAvailableInterest().add(account.getDeposit()).add(determineRemainInerestAmount(account.getDeposit(), + // account.getPreClosureInterestRate(), days)); + // } + } else { + avalablePreclosureWithdrawalAmount = account.getDeposit(); + } + } + return avalablePreclosureWithdrawalAmount; + } + + private BigDecimal determineRemainInerestAmount(final BigDecimal depsoitAmount, final BigDecimal interstRateApplicable, + final Integer days) { + + MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); + Integer daysInYear = 365; + BigDecimal interestRateAsFraction = interstRateApplicable.divide(BigDecimal.valueOf(100), mc); + BigDecimal interestRateForOneDay = interestRateAsFraction.divide(BigDecimal.valueOf(daysInYear.doubleValue()), mc); + return BigDecimal.valueOf(depsoitAmount.doubleValue() * days.doubleValue() * interestRateForOneDay.doubleValue()); + + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountTransactionData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountTransactionData.java index 30c25306b..e71d20c9d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountTransactionData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountTransactionData.java @@ -9,52 +9,51 @@ import org.mifosplatform.infrastructure.core.data.EnumOptionData; * Immutable data object to represent transactions on a deposit account. */ public class DepositAccountTransactionData { - - private final Long transactionId; - private final EnumOptionData transactionType; - private final LocalDate transactionDate; - private final BigDecimal transactionAmount; - private final Long accountId; - private final BigDecimal interestAmount; - private final BigDecimal total; - - public DepositAccountTransactionData( - final Long transactionId, final Long accountId, final EnumOptionData transactionType, - final LocalDate transactionDate, final BigDecimal transactionAmount, final BigDecimal interstAmount, final BigDecimal total ) { - this.transactionId = transactionId; - this.accountId = accountId; - this.transactionType = transactionType; - this.transactionDate = transactionDate; - this.transactionAmount = transactionAmount; - this.interestAmount = interstAmount; - this.total = total; - } - public Long getAccountId() { - return accountId; - } + private final Long transactionId; + private final EnumOptionData transactionType; + private final LocalDate transactionDate; + private final BigDecimal transactionAmount; + private final Long accountId; + private final BigDecimal interestAmount; + private final BigDecimal total; - public Long getTransactionId() { - return transactionId; - } + public DepositAccountTransactionData(final Long transactionId, final Long accountId, final EnumOptionData transactionType, + final LocalDate transactionDate, final BigDecimal transactionAmount, final BigDecimal interstAmount, final BigDecimal total) { + this.transactionId = transactionId; + this.accountId = accountId; + this.transactionType = transactionType; + this.transactionDate = transactionDate; + this.transactionAmount = transactionAmount; + this.interestAmount = interstAmount; + this.total = total; + } - public EnumOptionData getTransactionType() { - return transactionType; - } + public Long getAccountId() { + return accountId; + } - public LocalDate getTransactionDate() { - return transactionDate; - } + public Long getTransactionId() { + return transactionId; + } - public BigDecimal getTransactionAmount() { - return transactionAmount; - } + public EnumOptionData getTransactionType() { + return transactionType; + } - public BigDecimal getInterestAmount() { - return interestAmount; - } + public LocalDate getTransactionDate() { + return transactionDate; + } - public BigDecimal getTotal() { - return total; - } + public BigDecimal getTransactionAmount() { + return transactionAmount; + } + + public BigDecimal getInterestAmount() { + return interestAmount; + } + + public BigDecimal getTotal() { + return total; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountsForLookup.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountsForLookup.java index 0d45086b0..c820594a4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountsForLookup.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositAccountsForLookup.java @@ -1,15 +1,15 @@ package org.mifosplatform.portfolio.savingsdepositaccount.data; public class DepositAccountsForLookup { - - private final Long id; - - public DepositAccountsForLookup(final Long id) { - this.id = id; - } - public Long getId() { - return id; - } + private final Long id; -} + public DepositAccountsForLookup(final Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositPermissionData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositPermissionData.java index 0f7e799e2..cf68a01af 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositPermissionData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/data/DepositPermissionData.java @@ -1,60 +1,60 @@ package org.mifosplatform.portfolio.savingsdepositaccount.data; public class DepositPermissionData { - - private final boolean rejectAllowed; - private final boolean withdrawnByApplicantAllowed; - private final boolean undoApprovalAllowed; - private final boolean pendingApproval; - private final boolean isInterestWithdrawalAllowed; - private final boolean renewelAllowed; - private final boolean isMaturedDepositAccount; - - private final boolean anyActionOnAccountAllowed; - - public DepositPermissionData(final boolean rejectAllowed,final boolean withdrawnByApplicantAllowed,final boolean undoApprovalAllowed, - final boolean pendingApproval,final boolean interestWithdrawalAllowed, final boolean renewelAllowed, final boolean isMaturedDepositAccount) { - this.rejectAllowed = rejectAllowed; - this.withdrawnByApplicantAllowed = withdrawnByApplicantAllowed; - this.undoApprovalAllowed = undoApprovalAllowed; - this.pendingApproval = pendingApproval; - this.isInterestWithdrawalAllowed = interestWithdrawalAllowed; - this.renewelAllowed = renewelAllowed; - this.isMaturedDepositAccount = isMaturedDepositAccount; - this.anyActionOnAccountAllowed = isRejectAllowed() || isPendingApproval() || isUndoApprovalAllowed() || isWithdrawnByApplicantAllowed() || - isInterestWithdrawalAllowed() || isRenewelAllowed() || isMaturedDepositAccount(); - } + private final boolean rejectAllowed; + private final boolean withdrawnByApplicantAllowed; + private final boolean undoApprovalAllowed; + private final boolean pendingApproval; + private final boolean isInterestWithdrawalAllowed; + private final boolean renewelAllowed; + private final boolean isMaturedDepositAccount; - public boolean isRejectAllowed() { - return rejectAllowed; - } + private final boolean anyActionOnAccountAllowed; - public boolean isWithdrawnByApplicantAllowed() { - return withdrawnByApplicantAllowed; - } + public DepositPermissionData(final boolean rejectAllowed, final boolean withdrawnByApplicantAllowed, final boolean undoApprovalAllowed, + final boolean pendingApproval, final boolean interestWithdrawalAllowed, final boolean renewelAllowed, + final boolean isMaturedDepositAccount) { + this.rejectAllowed = rejectAllowed; + this.withdrawnByApplicantAllowed = withdrawnByApplicantAllowed; + this.undoApprovalAllowed = undoApprovalAllowed; + this.pendingApproval = pendingApproval; + this.isInterestWithdrawalAllowed = interestWithdrawalAllowed; + this.renewelAllowed = renewelAllowed; + this.isMaturedDepositAccount = isMaturedDepositAccount; + this.anyActionOnAccountAllowed = isRejectAllowed() || isPendingApproval() || isUndoApprovalAllowed() + || isWithdrawnByApplicantAllowed() || isInterestWithdrawalAllowed() || isRenewelAllowed() || isMaturedDepositAccount(); + } - public boolean isUndoApprovalAllowed() { - return undoApprovalAllowed; - } + public boolean isRejectAllowed() { + return rejectAllowed; + } - public boolean isPendingApproval() { - return pendingApproval; - } - - public boolean isAnyActionOnAccountAllowed() { - return anyActionOnAccountAllowed; - } + public boolean isWithdrawnByApplicantAllowed() { + return withdrawnByApplicantAllowed; + } - public boolean isInterestWithdrawalAllowed() { - return isInterestWithdrawalAllowed; - } + public boolean isUndoApprovalAllowed() { + return undoApprovalAllowed; + } - public boolean isRenewelAllowed() { - return renewelAllowed; - } + public boolean isPendingApproval() { + return pendingApproval; + } - public boolean isMaturedDepositAccount() { - return isMaturedDepositAccount; - } + public boolean isAnyActionOnAccountAllowed() { + return anyActionOnAccountAllowed; + } + + public boolean isInterestWithdrawalAllowed() { + return isInterestWithdrawalAllowed; + } + + public boolean isRenewelAllowed() { + return renewelAllowed; + } + + public boolean isMaturedDepositAccount() { + return isMaturedDepositAccount; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java index 22da4e5da..a6714920b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java @@ -36,799 +36,799 @@ import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProduct; import org.mifosplatform.useradministration.domain.AppUser; @Entity -@Table(name = "m_deposit_account", uniqueConstraints = @UniqueConstraint(name="deposit_acc_external_id", columnNames = { "external_id" })) -public class DepositAccount extends AbstractAuditableCustom { - - @ManyToOne - @JoinColumn(name = "client_id", nullable = false) - private Client client; +@Table(name = "m_deposit_account", uniqueConstraints = @UniqueConstraint(name = "deposit_acc_external_id", columnNames = { "external_id" })) +public class DepositAccount extends AbstractAuditableCustom { - @ManyToOne - @JoinColumn(name = "product_id") - private DepositProduct product; - - @Column(name = "external_id") - private String externalId; - - @Embedded - private MonetaryCurrency currency; - - @Column(name = "deposit_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal depositAmount; - - @Column(name = "maturity_nominal_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal interestRate; - - @Column(name = "tenure_months", nullable=false) - private Integer tenureInMonths; - - @Column(name = "interest_compounded_every", nullable = false) - private Integer interestCompoundedEvery; + @ManyToOne + @JoinColumn(name = "client_id", nullable = false) + private Client client; - @Column(name = "interest_compounded_every_period_enum", nullable = false) - private Integer interestCompoundedFrequencyType; - - @Temporal(TemporalType.DATE) - @Column(name = "projected_commencement_date") - private Date projectedCommencementDate; - - @Temporal(TemporalType.DATE) - @Column(name = "actual_commencement_date") - private Date actualCommencementDate; - - @Temporal(TemporalType.DATE) - @Column(name = "matures_on_date") - private Date maturesOnDate; - - @Column(name = "projected_interest_accrued_on_maturity", scale = 6, precision = 19, nullable = false) - private BigDecimal projectedInterestAccruedOnMaturity; - - @Column(name = "actual_interest_accrued", scale = 6, precision = 19, nullable = false) - private BigDecimal interestAccrued; - - @Column(name = "projected_total_maturity_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal projectedTotalOnMaturity; - - @Column(name = "actual_total_amount", scale = 6, precision = 19, nullable = false) - private BigDecimal total; - - @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal preClosureInterestRate; - - @Column(name = "is_renewal_allowed", nullable = false) - private boolean renewalAllowed = false; - - @Column(name = "is_preclosure_allowed", nullable = false) - private boolean preClosureAllowed = false; - - @Column(name = "is_deleted", nullable=false) - private boolean deleted = false; - - @Column(name = "status_enum", nullable = false) - private Integer depositStatus; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "closedon_date") - private Date closedOnDate; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "rejectedon_date") - private Date rejectedOnDate; - - @SuppressWarnings("unused") - @Temporal(TemporalType.DATE) - @Column(name = "withdrawnon_date") - private Date withdrawnOnDate; - - @Column(name = "interest_paid", scale = 6, precision = 19, nullable = false) - private BigDecimal interstPaid; - - @Column(name = "is_interest_withdrawable", nullable = false) - private boolean isInterestWithdrawable = false; - - @Column(name = "is_compounding_interest_allowed", nullable = false) - private boolean interestCompoundingAllowed = false; - - // see - // http://stackoverflow.com/questions/4334970/hibernate-cannot-simultaneously-fetch-multiple-bags - @OrderBy(value = "id") - @LazyCollection(LazyCollectionOption.FALSE) - @OneToMany(cascade = CascadeType.ALL, mappedBy = "depositAccount", orphanRemoval = true) - private final List depositaccountTransactions = new ArrayList(); - - @SuppressWarnings("unused") - @OneToOne(optional=true, cascade={CascadeType.PERSIST}) - @JoinColumn(name = "renewed_account_id") - private DepositAccount renewdAccount; - - @Column(name = "is_lock_in_period_allowed", nullable=false) - private boolean isLockinPeriodAllowed = false; - - @Column(name = "lock_in_period", nullable=false) - private Integer lockinPeriod; - - @Column(name = "lock_in_period_type", nullable=false) - private PeriodFrequencyType lockinPeriodType; - - //for interest posting - @Column(name = "available_interest", scale = 6, precision = 19) - private BigDecimal availableInterest; - - @Column(name = "interest_posted_amount", scale = 6, precision = 19) - private BigDecimal interestPostedAmount; - - @Temporal(TemporalType.DATE) - @Column(name = "last_interest_posted_date") - private Date lastInterestPostedDate; - - @Temporal(TemporalType.DATE) - @Column(name = "next_interest_posting_date") - private Date nextInterestPostingDate; - - - public DepositAccount openNew( - final Client client, final DepositProduct product, - final String externalId, final Money deposit, final BigDecimal maturityInterestRate, final BigDecimal preClosureInterestRate, final Integer tenureInMonths, - final Integer interestCompoundedEvery, - final PeriodFrequencyType interestCompoundedFrequencyPeriodType, - final LocalDate commencementDate, - final boolean renewalAllowed, - final boolean preClosureAllowed, - final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, - final DepositLifecycleStateMachine depositLifecycleStateMachine, - final boolean isInterstWithdrawable,final boolean interestCompoundingAllowed, - final boolean isLockinPeriodAllowed, final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { - - Money futureValueOnMaturity =null; + @ManyToOne + @JoinColumn(name = "product_id") + private DepositProduct product; - if (interestCompoundingAllowed) { - futureValueOnMaturity = fixedTermDepositInterestCalculator - .calculateInterestOnMaturityFor(deposit, tenureInMonths, - maturityInterestRate, interestCompoundedEvery, - interestCompoundedFrequencyPeriodType); - } else { - futureValueOnMaturity = fixedTermDepositInterestCalculator - .calculateInterestOnMaturityForSimpleInterest(deposit, - tenureInMonths, maturityInterestRate, - interestCompoundedEvery, - interestCompoundedFrequencyPeriodType); - } - - DepositAccountStatus from = null; - if (depositStatus != null) { - from = DepositAccountStatus.fromInt(depositStatus); - } + @Column(name = "external_id") + private String externalId; - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CREATED, from); - depositStatus = statusEnum.getValue(); - - return new DepositAccount(client, product, externalId, deposit, maturityInterestRate, preClosureInterestRate, tenureInMonths, - interestCompoundedEvery, interestCompoundedFrequencyPeriodType, commencementDate, renewalAllowed, preClosureAllowed, - futureValueOnMaturity,depositStatus,isInterstWithdrawable, interestCompoundingAllowed,isLockinPeriodAllowed,lockinPeriod,lockinPeriodType); - } - - public DepositAccount() { - this.product = null; - } + @Embedded + private MonetaryCurrency currency; - public DepositAccount( - final Client client, final DepositProduct product, - final String externalId, final Money deposit, final BigDecimal interestRate, final BigDecimal preClosureInterestRate, final Integer termInMonths, - final Integer interestCompoundedEvery, - final PeriodFrequencyType interestCompoundedFrequencyPeriodType, - final LocalDate commencementDate, - final boolean renewalAllowed, - final boolean preClosureAllowed, - final Money futureValueOnMaturity, - final Integer depositStatus, - final boolean isInterestWithdrawable, - final boolean interestCompoundingAllowed, - final boolean isLockinPeriodAllowed, - final Integer lockinPeriod, - final PeriodFrequencyType lockinPeriodType) { - this.client = client; - this.product = product; - setExternalId(externalId); - - this.currency = deposit.getCurrency(); - this.depositAmount = deposit.getAmount(); - product.validateDepositInRange(this.depositAmount); - this.interestRate = interestRate; - product.validateInterestRateInRange(interestRate); - this.tenureInMonths = termInMonths; - - this.interestCompoundedEvery = interestCompoundedEvery; - this.interestCompoundedFrequencyType = interestCompoundedFrequencyPeriodType.getValue(); - if (commencementDate != null) { - this.projectedCommencementDate = commencementDate.toDate(); - this.maturesOnDate = commencementDate.plusMonths(this.tenureInMonths).minusDays(1).toDate(); - } - - this.renewalAllowed = renewalAllowed; - this.preClosureAllowed = preClosureAllowed; - - this.preClosureInterestRate = preClosureInterestRate; - this.isInterestWithdrawable = isInterestWithdrawable; - this.interestCompoundingAllowed = interestCompoundingAllowed; - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockinPeriod; - this.lockinPeriodType = lockinPeriodType; - - // derived fields - this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.minus(deposit).getAmount(); - this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); - this.depositStatus=depositStatus; - this.interestAccrued=BigDecimal.ZERO; - this.interstPaid=BigDecimal.ZERO; - this.total=BigDecimal.ZERO; - } - - private void setExternalId(final String externalId) { - if (StringUtils.isNotBlank(externalId)) { - this.externalId = externalId.trim(); - } else { - this.externalId = null; - } - } - - public boolean isDeleted() { - return deleted; - } - - /** - * Delete is a soft delete. Updates flag on account so it wont appear in query/report results. - * - * Any fields with unique constraints and prepended with id of record. - */ - public void delete() { - this.deleted = true; - this.externalId = this.getId() + "_" + this.externalId; - } + @Column(name = "deposit_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal depositAmount; - public void approve( - final LocalDate actualCommencementDate, - final DepositLifecycleStateMachine depositLifecycleStateMachine, - final DepositStateTransitionApprovalCommand command, - final FixedTermDepositInterestCalculator calculator) { + @Column(name = "maturity_nominal_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal interestRate; - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED, DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnum.getValue(); - - if (command.getTenureInMonths() != null) { - this.tenureInMonths = command.getTenureInMonths(); - } - - if(command.getMaturityInterestRate() != null){ - this.interestRate = command.getMaturityInterestRate(); - } - this.product.validateInterestRateInRange(this.interestRate); - - if (command.getDepositAmount() != null) { - this.depositAmount = command.getDepositAmount(); - } - this.product.validateDepositInRange(this.depositAmount); - - this.interestCompoundedEvery = command.getInterestCompoundedEvery(); - - if (command.getInterestCompoundedEveryPeriodType() != null) { - this.interestCompoundedFrequencyType = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()).getValue(); - } + @Column(name = "tenure_months", nullable = false) + private Integer tenureInMonths; - this.actualCommencementDate = actualCommencementDate.toDate(); - this.maturesOnDate = getActualCommencementDate().plusMonths(this.tenureInMonths).minusDays(1).toDate(); - - Money futureValueOnMaturity =null; - - if (this.interestCompoundingAllowed) { - futureValueOnMaturity = calculator.calculateInterestOnMaturityFor( - getDeposit(), this.tenureInMonths, this.interestRate, - this.interestCompoundedEvery, - getInterestCompoundedFrequencyType()); - } else { - futureValueOnMaturity = calculator - .calculateInterestOnMaturityForSimpleInterest(getDeposit(), - this.tenureInMonths, this.interestRate, - this.interestCompoundedEvery, - getInterestCompoundedFrequencyType()); - } - this.interestAccrued = futureValueOnMaturity.minus(getDeposit()).getAmount(); - this.total = futureValueOnMaturity.getAmount(); - - DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.deposit(getDeposit(), getActualCommencementDate(),getAccuredInterest()); - depositaccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositaccountTransaction); - - //for interest posting initializing - this.lastInterestPostedDate = this.actualCommencementDate; - this.nextInterestPostingDate = new LocalDate(this.lastInterestPostedDate).plusMonths(this.interestCompoundedEvery).toDate(); - this.availableInterest = BigDecimal.ZERO; - this.interestPostedAmount = BigDecimal.ZERO; - - LocalDate submittalDate = new LocalDate(this.projectedCommencementDate); - if (actualCommencementDate.isBefore(submittalDate)) { - final String errorMessage = "The date on which a deposit is approved cannot be before its submittal date: " + submittalDate.toString(); - throw new InvalidDepositStateTransitionException("approval", "cannot.be.before.submittal.date", errorMessage, getActualCommencementDate(), submittalDate); - } - - if (actualCommencementDate.isAfter(new LocalDate())) { - final String errorMessage = "The date on which a deposit is approved cannot be in the future."; - throw new InvalidDepositStateTransitionException("approval", "cannot.be.a.future.date", errorMessage, getActualCommencementDate()); - } - } + @Column(name = "interest_compounded_every", nullable = false) + private Integer interestCompoundedEvery; - public LocalDate getActualCommencementDate() { - LocalDate date = null; - if (this.actualCommencementDate != null) { - date = new LocalDate(this.actualCommencementDate); - } - return date; - } + @Column(name = "interest_compounded_every_period_enum", nullable = false) + private Integer interestCompoundedFrequencyType; - public LocalDate getProjectedCommencementDate() { - LocalDate date = null; - if (this.projectedCommencementDate != null) { - date = new LocalDate(this.projectedCommencementDate); - } - return date; - } - - public LocalDate getMaturityDate() { - LocalDate date = null; - if (this.maturesOnDate != null) { - date = new LocalDate(this.maturesOnDate); - } - return date; - } + @Temporal(TemporalType.DATE) + @Column(name = "projected_commencement_date") + private Date projectedCommencementDate; - public List getDepositaccountTransactions() { - return depositaccountTransactions; - } + @Temporal(TemporalType.DATE) + @Column(name = "actual_commencement_date") + private Date actualCommencementDate; - public BigDecimal getProjectedTotalOnMaturity() { - return projectedTotalOnMaturity; - } + @Temporal(TemporalType.DATE) + @Column(name = "matures_on_date") + private Date maturesOnDate; - public BigDecimal getTotal() { - return total; - } + @Column(name = "projected_interest_accrued_on_maturity", scale = 6, precision = 19, nullable = false) + private BigDecimal projectedInterestAccruedOnMaturity; - public boolean isInterestCompoundingAllowed() { - return interestCompoundingAllowed; - } - - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + @Column(name = "actual_interest_accrued", scale = 6, precision = 19, nullable = false) + private BigDecimal interestAccrued; - public Integer getLockinPeriod() { - return lockinPeriod; - } + @Column(name = "projected_total_maturity_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal projectedTotalOnMaturity; - public PeriodFrequencyType getLockinPeriodType() { - return lockinPeriodType; - } + @Column(name = "actual_total_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal total; - public void reject(final LocalDate rejectedOn, - final DepositLifecycleStateMachine depositLifecycleStateMachine) { + @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal preClosureInterestRate; - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition( - DepositAccountEvent.DEPOSIT_REJECTED, - DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnum.getValue(); + @Column(name = "is_renewal_allowed", nullable = false) + private boolean renewalAllowed = false; - this.maturesOnDate=null; - this.rejectedOnDate = rejectedOn.toDateTimeAtCurrentTime().toDate(); - this.closedOnDate = rejectedOn.toDateTimeAtCurrentTime().toDate(); + @Column(name = "is_preclosure_allowed", nullable = false) + private boolean preClosureAllowed = false; - if (rejectedOn.isBefore(getProjectedCommencementDate())) { + @Column(name = "is_deleted", nullable = false) + private boolean deleted = false; - final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: " - + getProjectedCommencementDate().toString(); - throw new InvalidDepositStateTransitionException("reject", - "cannot.be.before.submittal.date", errorMessage, - rejectedOn, getProjectedCommencementDate()); + @Column(name = "status_enum", nullable = false) + private Integer depositStatus; - } - if (rejectedOn.isAfter(new LocalDate())) { + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "closedon_date") + private Date closedOnDate; - final String errorMessage = "The date on which a deposit is rejected cannot be in the future."; - throw new InvalidDepositStateTransitionException("reject", - "cannot.be.a.future.date", errorMessage, rejectedOn); + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "rejectedon_date") + private Date rejectedOnDate; - } + @SuppressWarnings("unused") + @Temporal(TemporalType.DATE) + @Column(name = "withdrawnon_date") + private Date withdrawnOnDate; - } + @Column(name = "interest_paid", scale = 6, precision = 19, nullable = false) + private BigDecimal interstPaid; - public void withdrawnByApplicant(final LocalDate withdrawnOn, - final DepositLifecycleStateMachine depositLifecycleStateMachine) { + @Column(name = "is_interest_withdrawable", nullable = false) + private boolean isInterestWithdrawable = false; - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition( - DepositAccountEvent.DEPOSIT_WITHDRAWN, - DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnum.getValue(); + @Column(name = "is_compounding_interest_allowed", nullable = false) + private boolean interestCompoundingAllowed = false; - this.maturesOnDate = null; - this.withdrawnOnDate = withdrawnOn.toDateTimeAtCurrentTime().toDate(); - this.closedOnDate = withdrawnOn.toDateTimeAtCurrentTime().toDate(); + // see + // http://stackoverflow.com/questions/4334970/hibernate-cannot-simultaneously-fetch-multiple-bags + @OrderBy(value = "id") + @LazyCollection(LazyCollectionOption.FALSE) + @OneToMany(cascade = CascadeType.ALL, mappedBy = "depositAccount", orphanRemoval = true) + private final List depositaccountTransactions = new ArrayList(); - if (withdrawnOn.isBefore(getProjectedCommencementDate())) { + @SuppressWarnings("unused") + @OneToOne(optional = true, cascade = { CascadeType.PERSIST }) + @JoinColumn(name = "renewed_account_id") + private DepositAccount renewdAccount; - final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: " - + getProjectedCommencementDate().toString(); - throw new InvalidDepositStateTransitionException("reject", - "cannot.be.before.submittal.date", errorMessage, - withdrawnOn, getProjectedCommencementDate()); + @Column(name = "is_lock_in_period_allowed", nullable = false) + private boolean isLockinPeriodAllowed = false; - } - - if (withdrawnOn.isAfter(new LocalDate())) { - final String errorMessage = "The date on which a deposit is rejected cannot be in the future."; - throw new InvalidDepositStateTransitionException("reject", - "cannot.be.a.future.date", errorMessage, withdrawnOn); - } - } + @Column(name = "lock_in_period", nullable = false) + private Integer lockinPeriod; - public void undoDepositApproval(final DepositLifecycleStateMachine depositLifecycleStateMachine) { + @Column(name = "lock_in_period_type", nullable = false) + private PeriodFrequencyType lockinPeriodType; - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition( - DepositAccountEvent.DEPOSIT_APPROVAL_UNDO, - DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnum.getValue(); + // for interest posting + @Column(name = "available_interest", scale = 6, precision = 19) + private BigDecimal availableInterest; - this.actualCommencementDate = null; - this.projectedInterestAccruedOnMaturity=this.interestAccrued; - this.projectedTotalOnMaturity = this.depositAmount.add(this.projectedInterestAccruedOnMaturity); - this.maturesOnDate = getProjectedCommencementDate().plusMonths(this.tenureInMonths).minusDays(1).toDate(); - this.total=null; - this.interestAccrued=null; - this.depositaccountTransactions.clear(); - } + @Column(name = "interest_posted_amount", scale = 6, precision = 19) + private BigDecimal interestPostedAmount; - public PeriodFrequencyType getInterestCompoundedFrequencyType() { - return PeriodFrequencyType.fromInt(this.interestCompoundedFrequencyType); - } + @Temporal(TemporalType.DATE) + @Column(name = "last_interest_posted_date") + private Date lastInterestPostedDate; - public Money getDeposit() { - return Money.of(this.currency, this.depositAmount); - } - - public Money getAccuredInterest(){ - return Money.of(this.currency, this.interestAccrued); - } - - public Client client() { - return this.client; - } - - public DepositProduct product(){ - return this.product; - } - - public String getExternalId() { - return this.externalId; - } - - public boolean isRenewalAllowed() { - return this.renewalAllowed; - } - - public BigDecimal getInterstPaid() { - return this.interstPaid; - } + @Temporal(TemporalType.DATE) + @Column(name = "next_interest_posting_date") + private Date nextInterestPostingDate; - public boolean isInterestWithdrawable() { - return isInterestWithdrawable; - } + public DepositAccount openNew(final Client client, final DepositProduct product, final String externalId, final Money deposit, + final BigDecimal maturityInterestRate, final BigDecimal preClosureInterestRate, final Integer tenureInMonths, + final Integer interestCompoundedEvery, final PeriodFrequencyType interestCompoundedFrequencyPeriodType, + final LocalDate commencementDate, final boolean renewalAllowed, final boolean preClosureAllowed, + final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, + final DepositLifecycleStateMachine depositLifecycleStateMachine, final boolean isInterstWithdrawable, + final boolean interestCompoundingAllowed, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, + final PeriodFrequencyType lockinPeriodType) { - public Integer getTenureInMonths() { - return tenureInMonths; - } + Money futureValueOnMaturity = null; - public Integer getInterestCompoundedEvery() { - return this.interestCompoundedEvery; - } + if (interestCompoundingAllowed) { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, tenureInMonths, + maturityInterestRate, interestCompoundedEvery, interestCompoundedFrequencyPeriodType); + } else { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, + tenureInMonths, maturityInterestRate, interestCompoundedEvery, interestCompoundedFrequencyPeriodType); + } - public BigDecimal getInterestRate() { - return interestRate; - } + DepositAccountStatus from = null; + if (depositStatus != null) { + from = DepositAccountStatus.fromInt(depositStatus); + } - public Date getMaturesOnDate() { - return maturesOnDate; - } + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CREATED, from); + depositStatus = statusEnum.getValue(); - public BigDecimal getPreClosureInterestRate() { - return preClosureInterestRate; - } + return new DepositAccount(client, product, externalId, deposit, maturityInterestRate, preClosureInterestRate, tenureInMonths, + interestCompoundedEvery, interestCompoundedFrequencyPeriodType, commencementDate, renewalAllowed, preClosureAllowed, + futureValueOnMaturity, depositStatus, isInterstWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, + lockinPeriod, lockinPeriodType); + } - public boolean isPreClosureAllowed() { - return preClosureAllowed; - } + public DepositAccount() { + this.product = null; + } - public Integer getDepositStatus() { - return depositStatus; - } + public DepositAccount(final Client client, final DepositProduct product, final String externalId, final Money deposit, + final BigDecimal interestRate, final BigDecimal preClosureInterestRate, final Integer termInMonths, + final Integer interestCompoundedEvery, final PeriodFrequencyType interestCompoundedFrequencyPeriodType, + final LocalDate commencementDate, final boolean renewalAllowed, final boolean preClosureAllowed, + final Money futureValueOnMaturity, final Integer depositStatus, final boolean isInterestWithdrawable, + final boolean interestCompoundingAllowed, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, + final PeriodFrequencyType lockinPeriodType) { + this.client = client; + this.product = product; + setExternalId(externalId); - public LocalDate maturesOnDate() { - LocalDate date = null; - if (this.maturesOnDate != null) { - date = new LocalDate(this.maturesOnDate); - } - return date; - } + this.currency = deposit.getCurrency(); + this.depositAmount = deposit.getAmount(); + product.validateDepositInRange(this.depositAmount); + this.interestRate = interestRate; + product.validateInterestRateInRange(interestRate); + this.tenureInMonths = termInMonths; - public void updateAccount(DepositAccount account) { - - this.renewdAccount = account; - - } + this.interestCompoundedEvery = interestCompoundedEvery; + this.interestCompoundedFrequencyType = interestCompoundedFrequencyPeriodType.getValue(); + if (commencementDate != null) { + this.projectedCommencementDate = commencementDate.toDate(); + this.maturesOnDate = commencementDate.plusMonths(this.tenureInMonths).minusDays(1).toDate(); + } - public void withdrawDepositAccountMoney(DepositLifecycleStateMachine depositLifecycleStateMachine, FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator,LocalDate eventDate) { - - if (eventDate.isBefore(getLastInterestPostedDate())) { - final String errorMessage = "Deposit Account Preclosed date \"" +eventDate+ "\"cannot before last interest posted date \"" + getLastInterestPostedDate()+"\""; - throw new InvalidDepositStateTransitionException("withdraw", "event.date.cannot.before.last.interest.posted.date",errorMessage, getLastInterestPostedDate(), eventDate); - } - if (eventDate.isAfter(maturesOnDate()) || eventDate.equals(maturesOnDate())) { - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED, DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnum.getValue(); - } else if(eventDate.isBefore(maturesOnDate())){ - DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_PRECLOSED, DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnum.getValue(); - } - - Integer days = Days.daysBetween(getLastInterestPostedDate(), eventDate).getDays(); - Money accuredInterestAfterMaturityToTillDate = fixedTermDepositInterestCalculator.calculateRemainInterest(getDeposit(), days, preClosureInterestRate); - this.interestAccrued = this.interestAccrued.add(accuredInterestAfterMaturityToTillDate.getAmount()); - - DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(getDeposit(), eventDate,getAccuredInterest()); - depositaccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositaccountTransaction); - - this.closedOnDate = eventDate.toDate(); - this.withdrawnOnDate = null; - this.rejectedOnDate = null; - - } + this.renewalAllowed = renewalAllowed; + this.preClosureAllowed = preClosureAllowed; - /*public void adjustTotalAmountForPreclosureInterest(DepositAccount account, FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator,LocalDate eventDate) { - - LocalDate commnencementDate = getActualCommencementDate(); - LocalDate lastInterestPosedDate = getLastInterestPostedDate(); - LocalDate preClosedDate = eventDate; - - if (preClosedDate.isBefore(lastInterestPosedDate)) { - throw new DepositAccountTransactionsException("deposit.account.preclosed.date.should.be.after.last.interest.posted.date", null); - } - - Integer tenure = Months.monthsBetween(lastInterestPosedDate, preClosedDate).getMonths(); - LocalDate actualPrecloseCalculationDate = lastInterestPosedDate.plusMonths(tenure); - Integer missedDays = Days.daysBetween(actualPrecloseCalculationDate, preClosedDate).getDays(); - - Money deposit = Money.of(account.getDeposit().getCurrency(), account.getDeposit().getAmount()); - Money accuredtotalAmount = null; - Money remainDaysAmount = fixedTermDepositInterestCalculator.calculateRemainInterest(deposit, missedDays, preClosureInterestRate); - if (account.isInterestCompoundingAllowed()) { - accuredtotalAmount = fixedTermDepositInterestCalculator - .calculateInterestOnMaturityFor(deposit, tenure, - preClosureInterestRate, interestCompoundedEvery, - this.product.getInterestCompoundedEveryPeriodType()); - accuredtotalAmount = accuredtotalAmount.plus(remainDaysAmount); - } else { - accuredtotalAmount = fixedTermDepositInterestCalculator - .calculateInterestOnMaturityForSimpleInterest(deposit, - tenure, preClosureInterestRate, - interestCompoundedEvery, - this.product.getInterestCompoundedEveryPeriodType()); - accuredtotalAmount = accuredtotalAmount.plus(remainDaysAmount); - } - this.total = account.isInterestCompoundingAllowed()?accuredtotalAmount.getAmount():BigDecimal.valueOf(accuredtotalAmount.getAmount().doubleValue()-this.interstPaid.doubleValue()); - this.interestAccrued = accuredtotalAmount.minus(deposit).getAmount(); - - }*/ + this.preClosureInterestRate = preClosureInterestRate; + this.isInterestWithdrawable = isInterestWithdrawable; + this.interestCompoundingAllowed = interestCompoundingAllowed; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; - public void withdrawInterest(Money interest) { - @SuppressWarnings("unused") - boolean statustest = isActive(); - if(isActive()){ - DepositAccountTransaction depositAccountTransaction = DepositAccountTransaction.withdraw(null, new LocalDate(), interest); - depositAccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositAccountTransaction); - this.interstPaid = this.interstPaid.add(interest.getAmount()); - this.availableInterest = this.availableInterest.subtract(interest.getAmount()); - this.total = this.total.subtract(interest.getAmount()); - } - - } - public void closeDepositAccount(DepositLifecycleStateMachine depositLifecycleStateMachine){ - DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED, DepositAccountStatus.fromInt(this.depositStatus)); - this.depositStatus = statusEnumForClose.getValue(); - - DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(getDeposit(), new LocalDate(),Money.of(getDeposit().getCurrency(), getTotal()).minus(getDeposit())); - depositaccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositaccountTransaction); - - this.closedOnDate = new LocalDate().toDate(); - } + // derived fields + this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.minus(deposit).getAmount(); + this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); + this.depositStatus = depositStatus; + this.interestAccrued = BigDecimal.ZERO; + this.interstPaid = BigDecimal.ZERO; + this.total = BigDecimal.ZERO; + } - public void update(final DepositProduct product, final String externalId, - final LocalDate commencementDate, final Money deposit, - final Integer tenureInMonths, final BigDecimal maturityInterestRate, - final BigDecimal preClosureInterestRate, final Integer interestCompoundedEvery, - final PeriodFrequencyType compoundingInterestFrequency, - final boolean renewalAllowed, final boolean preClosureAllowed, - final boolean isInterestWithdrawable, final boolean isInterestCompoundingAllowed, - final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, - final boolean isLockinPeriodAllowed, - final Integer lockinPeriod, - final PeriodFrequencyType lockinPeriodType) { - - Money futureValueOnMaturity =null; + private void setExternalId(final String externalId) { + if (StringUtils.isNotBlank(externalId)) { + this.externalId = externalId.trim(); + } else { + this.externalId = null; + } + } - if (isInterestCompoundingAllowed) { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, tenureInMonths, - maturityInterestRate, interestCompoundedEvery, - compoundingInterestFrequency); - } else { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, - tenureInMonths, maturityInterestRate, - interestCompoundedEvery, - compoundingInterestFrequency); - } - - setExternalId(externalId); - if (commencementDate != null) { - this.projectedCommencementDate = commencementDate.toDate(); - this.maturesOnDate = commencementDate.plusMonths(this.tenureInMonths).minusDays(1).toDate(); - } - this.product = product; - this.depositAmount = deposit.getAmount(); - this.tenureInMonths = tenureInMonths; - this.interestRate = maturityInterestRate; - this.product.validateInterestRateInRange(maturityInterestRate); - this.preClosureInterestRate=preClosureInterestRate; - this.interestCompoundedEvery=interestCompoundedEvery; - this.interestCompoundedFrequencyType=compoundingInterestFrequency.getValue(); - this.renewalAllowed=renewalAllowed; - this.preClosureAllowed=preClosureAllowed; - this.isInterestWithdrawable=isInterestWithdrawable; - this.interestCompoundingAllowed=isInterestCompoundingAllowed; - this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.minus(deposit).getAmount(); - this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockinPeriod; - this.lockinPeriodType = lockinPeriodType; - this.interestAccrued=BigDecimal.ZERO; - - } + public boolean isDeleted() { + return deleted; + } - public void update(final boolean renewalAllowed, final boolean isInterestWithdrawable) { - this.renewalAllowed=renewalAllowed; - this.isInterestWithdrawable=isInterestWithdrawable; - } + /** + * Delete is a soft delete. Updates flag on account so it wont appear + * in query/report results. + * + * Any fields with unique constraints and prepended with id of record. + */ + public void delete() { + this.deleted = true; + this.externalId = this.getId() + "_" + this.externalId; + } - public boolean isSubmittedAndPendingApproval() { - return DepositAccountStatus.fromInt(this.depositStatus).isSubmittedAndPendingApproval(); - } + public void approve(final LocalDate actualCommencementDate, final DepositLifecycleStateMachine depositLifecycleStateMachine, + final DepositStateTransitionApprovalCommand command, final FixedTermDepositInterestCalculator calculator) { - public boolean isActive() { - return DepositAccountStatus.fromInt(this.depositStatus).isActive(); - } + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnum.getValue(); - public void postInterestForDepositAccount(DepositAccount account, FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { - - LocalDate lastInterestPostedDate = getLastInterestPostedDate(); - LocalDate nextInterestPostingDate = getNextInterestPostedDate(); - Integer monthsForInterestCalculation = Months.monthsBetween(lastInterestPostedDate, new LocalDate()).getMonths(); - Integer postInterestItereations = monthsForInterestCalculation/this.interestCompoundedEvery; - Money deposit = Money.of(this.currency, this.depositAmount); - - while (postInterestItereations > 0) { - - lastInterestPostedDate = getLastInterestPostedDate(); - nextInterestPostingDate = getNextInterestPostedDate(); - if (lastInterestPostedDate.isBefore(getMaturityDate())){ - if (nextInterestPostingDate.isAfter(getMaturityDate())){ - Integer noofRemainMonthsAfterMaturity = Months.monthsBetween(getMaturityDate(), nextInterestPostingDate).getMonths(); - Integer noOfMonthsBeforeMaturity = Months.monthsBetween(lastInterestPostedDate, getMaturityDate()).getMonths(); - Money futureValueOnMaturity =null; - if (noOfMonthsBeforeMaturity >0) { - - if (this.interestCompoundingAllowed) { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, noOfMonthsBeforeMaturity,this.interestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } else { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, noOfMonthsBeforeMaturity, this.interestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } - this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.lastInterestPostedDate = nextInterestPostingDate.toDate(); - this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); - - } - if (noofRemainMonthsAfterMaturity >0){ - - if (this.interestCompoundingAllowed) { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, noofRemainMonthsAfterMaturity, this.preClosureInterestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } else { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, noofRemainMonthsAfterMaturity, this.preClosureInterestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } - this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.lastInterestPostedDate = nextInterestPostingDate.toDate(); - this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); - } - - // add transaction entry for each interest posting - DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, nextInterestPostingDate,futureValueOnMaturity.minus(deposit)); - depositaccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositaccountTransaction); - } else { - Money futureValueOnMaturity =null; - if (this.interestCompoundingAllowed) { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, this.interestCompoundedEvery, this.interestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } else { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, this.interestCompoundedEvery, this.interestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } - this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.lastInterestPostedDate = nextInterestPostingDate.toDate(); - this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); - - // add transaction entry for each interest posting - DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, nextInterestPostingDate,futureValueOnMaturity.minus(deposit)); - depositaccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositaccountTransaction); - } - } else{ - Money futureValueOnMaturity =null; - if (this.interestCompoundingAllowed) { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, this.interestCompoundedEvery, this.preClosureInterestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } else { - futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, this.interestCompoundedEvery, this.preClosureInterestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); - } - this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); - this.lastInterestPostedDate = nextInterestPostingDate.toDate(); - this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); - - // add transaction entry for each interest posting - DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, nextInterestPostingDate,futureValueOnMaturity.minus(deposit)); - depositaccountTransaction.updateAccount(this); - this.depositaccountTransactions.add(depositaccountTransaction); - } - postInterestItereations--; - } - - } + if (command.getTenureInMonths() != null) { + this.tenureInMonths = command.getTenureInMonths(); + } - private final LocalDate getLastInterestPostedDate() { - LocalDate lastInterestPostedDate; - if (this.lastInterestPostedDate == null){ - lastInterestPostedDate = new LocalDate(this.actualCommencementDate); - } else { - lastInterestPostedDate = new LocalDate(this.lastInterestPostedDate); - } - return lastInterestPostedDate; - } - - private final LocalDate getNextInterestPostedDate() { - LocalDate nextInterestPostingDate; - if (this.nextInterestPostingDate == null){ - nextInterestPostingDate = new LocalDate(this.nextInterestPostingDate).plusMonths(this.interestCompoundedEvery); - } else { - nextInterestPostingDate = new LocalDate(this.nextInterestPostingDate); - } - return nextInterestPostingDate; - } + if (command.getMaturityInterestRate() != null) { + this.interestRate = command.getMaturityInterestRate(); + } + this.product.validateInterestRateInRange(this.interestRate); - public BigDecimal getAvailableInterest() { - return availableInterest; - } + if (command.getDepositAmount() != null) { + this.depositAmount = command.getDepositAmount(); + } + this.product.validateDepositInRange(this.depositAmount); + + this.interestCompoundedEvery = command.getInterestCompoundedEvery(); + + if (command.getInterestCompoundedEveryPeriodType() != null) { + this.interestCompoundedFrequencyType = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()).getValue(); + } + + this.actualCommencementDate = actualCommencementDate.toDate(); + this.maturesOnDate = getActualCommencementDate().plusMonths(this.tenureInMonths).minusDays(1).toDate(); + + Money futureValueOnMaturity = null; + + if (this.interestCompoundingAllowed) { + futureValueOnMaturity = calculator.calculateInterestOnMaturityFor(getDeposit(), this.tenureInMonths, this.interestRate, + this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); + } else { + futureValueOnMaturity = calculator.calculateInterestOnMaturityForSimpleInterest(getDeposit(), this.tenureInMonths, + this.interestRate, this.interestCompoundedEvery, getInterestCompoundedFrequencyType()); + } + this.interestAccrued = futureValueOnMaturity.minus(getDeposit()).getAmount(); + this.total = futureValueOnMaturity.getAmount(); + + DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.deposit(getDeposit(), getActualCommencementDate(), + getAccuredInterest()); + depositaccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositaccountTransaction); + + // for interest posting initializing + this.lastInterestPostedDate = this.actualCommencementDate; + this.nextInterestPostingDate = new LocalDate(this.lastInterestPostedDate).plusMonths(this.interestCompoundedEvery).toDate(); + this.availableInterest = BigDecimal.ZERO; + this.interestPostedAmount = BigDecimal.ZERO; + + LocalDate submittalDate = new LocalDate(this.projectedCommencementDate); + if (actualCommencementDate.isBefore(submittalDate)) { + final String errorMessage = "The date on which a deposit is approved cannot be before its submittal date: " + + submittalDate.toString(); + throw new InvalidDepositStateTransitionException("approval", "cannot.be.before.submittal.date", errorMessage, + getActualCommencementDate(), submittalDate); + } + + if (actualCommencementDate.isAfter(new LocalDate())) { + final String errorMessage = "The date on which a deposit is approved cannot be in the future."; + throw new InvalidDepositStateTransitionException("approval", "cannot.be.a.future.date", errorMessage, + getActualCommencementDate()); + } + } + + public LocalDate getActualCommencementDate() { + LocalDate date = null; + if (this.actualCommencementDate != null) { + date = new LocalDate(this.actualCommencementDate); + } + return date; + } + + public LocalDate getProjectedCommencementDate() { + LocalDate date = null; + if (this.projectedCommencementDate != null) { + date = new LocalDate(this.projectedCommencementDate); + } + return date; + } + + public LocalDate getMaturityDate() { + LocalDate date = null; + if (this.maturesOnDate != null) { + date = new LocalDate(this.maturesOnDate); + } + return date; + } + + public List getDepositaccountTransactions() { + return depositaccountTransactions; + } + + public BigDecimal getProjectedTotalOnMaturity() { + return projectedTotalOnMaturity; + } + + public BigDecimal getTotal() { + return total; + } + + public boolean isInterestCompoundingAllowed() { + return interestCompoundingAllowed; + } + + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } + + public Integer getLockinPeriod() { + return lockinPeriod; + } + + public PeriodFrequencyType getLockinPeriodType() { + return lockinPeriodType; + } + + public void reject(final LocalDate rejectedOn, final DepositLifecycleStateMachine depositLifecycleStateMachine) { + + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnum.getValue(); + + this.maturesOnDate = null; + this.rejectedOnDate = rejectedOn.toDateTimeAtCurrentTime().toDate(); + this.closedOnDate = rejectedOn.toDateTimeAtCurrentTime().toDate(); + + if (rejectedOn.isBefore(getProjectedCommencementDate())) { + + final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: " + + getProjectedCommencementDate().toString(); + throw new InvalidDepositStateTransitionException("reject", "cannot.be.before.submittal.date", errorMessage, rejectedOn, + getProjectedCommencementDate()); + + } + if (rejectedOn.isAfter(new LocalDate())) { + + final String errorMessage = "The date on which a deposit is rejected cannot be in the future."; + throw new InvalidDepositStateTransitionException("reject", "cannot.be.a.future.date", errorMessage, rejectedOn); + + } + + } + + public void withdrawnByApplicant(final LocalDate withdrawnOn, final DepositLifecycleStateMachine depositLifecycleStateMachine) { + + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_WITHDRAWN, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnum.getValue(); + + this.maturesOnDate = null; + this.withdrawnOnDate = withdrawnOn.toDateTimeAtCurrentTime().toDate(); + this.closedOnDate = withdrawnOn.toDateTimeAtCurrentTime().toDate(); + + if (withdrawnOn.isBefore(getProjectedCommencementDate())) { + + final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: " + + getProjectedCommencementDate().toString(); + throw new InvalidDepositStateTransitionException("reject", "cannot.be.before.submittal.date", errorMessage, withdrawnOn, + getProjectedCommencementDate()); + + } + + if (withdrawnOn.isAfter(new LocalDate())) { + final String errorMessage = "The date on which a deposit is rejected cannot be in the future."; + throw new InvalidDepositStateTransitionException("reject", "cannot.be.a.future.date", errorMessage, withdrawnOn); + } + } + + public void undoDepositApproval(final DepositLifecycleStateMachine depositLifecycleStateMachine) { + + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVAL_UNDO, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnum.getValue(); + + this.actualCommencementDate = null; + this.projectedInterestAccruedOnMaturity = this.interestAccrued; + this.projectedTotalOnMaturity = this.depositAmount.add(this.projectedInterestAccruedOnMaturity); + this.maturesOnDate = getProjectedCommencementDate().plusMonths(this.tenureInMonths).minusDays(1).toDate(); + this.total = null; + this.interestAccrued = null; + this.depositaccountTransactions.clear(); + } + + public PeriodFrequencyType getInterestCompoundedFrequencyType() { + return PeriodFrequencyType.fromInt(this.interestCompoundedFrequencyType); + } + + public Money getDeposit() { + return Money.of(this.currency, this.depositAmount); + } + + public Money getAccuredInterest() { + return Money.of(this.currency, this.interestAccrued); + } + + public Client client() { + return this.client; + } + + public DepositProduct product() { + return this.product; + } + + public String getExternalId() { + return this.externalId; + } + + public boolean isRenewalAllowed() { + return this.renewalAllowed; + } + + public BigDecimal getInterstPaid() { + return this.interstPaid; + } + + public boolean isInterestWithdrawable() { + return isInterestWithdrawable; + } + + public Integer getTenureInMonths() { + return tenureInMonths; + } + + public Integer getInterestCompoundedEvery() { + return this.interestCompoundedEvery; + } + + public BigDecimal getInterestRate() { + return interestRate; + } + + public Date getMaturesOnDate() { + return maturesOnDate; + } + + public BigDecimal getPreClosureInterestRate() { + return preClosureInterestRate; + } + + public boolean isPreClosureAllowed() { + return preClosureAllowed; + } + + public Integer getDepositStatus() { + return depositStatus; + } + + public LocalDate maturesOnDate() { + LocalDate date = null; + if (this.maturesOnDate != null) { + date = new LocalDate(this.maturesOnDate); + } + return date; + } + + public void updateAccount(DepositAccount account) { + + this.renewdAccount = account; + + } + + public void withdrawDepositAccountMoney(DepositLifecycleStateMachine depositLifecycleStateMachine, + FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, LocalDate eventDate) { + + if (eventDate.isBefore(getLastInterestPostedDate())) { + final String errorMessage = "Deposit Account Preclosed date \"" + eventDate + "\"cannot before last interest posted date \"" + + getLastInterestPostedDate() + "\""; + throw new InvalidDepositStateTransitionException("withdraw", "event.date.cannot.before.last.interest.posted.date", + errorMessage, getLastInterestPostedDate(), eventDate); + } + if (eventDate.isAfter(maturesOnDate()) || eventDate.equals(maturesOnDate())) { + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnum.getValue(); + } else if (eventDate.isBefore(maturesOnDate())) { + DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_PRECLOSED, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnum.getValue(); + } + + Integer days = Days.daysBetween(getLastInterestPostedDate(), eventDate).getDays(); + Money accuredInterestAfterMaturityToTillDate = fixedTermDepositInterestCalculator.calculateRemainInterest(getDeposit(), days, + preClosureInterestRate); + this.interestAccrued = this.interestAccrued.add(accuredInterestAfterMaturityToTillDate.getAmount()); + + DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(getDeposit(), eventDate, + getAccuredInterest()); + depositaccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositaccountTransaction); + + this.closedOnDate = eventDate.toDate(); + this.withdrawnOnDate = null; + this.rejectedOnDate = null; + + } + + /* + * public void adjustTotalAmountForPreclosureInterest(DepositAccount + * account, FixedTermDepositInterestCalculator + * fixedTermDepositInterestCalculator,LocalDate eventDate) { + * + * LocalDate commnencementDate = getActualCommencementDate(); LocalDate + * lastInterestPosedDate = getLastInterestPostedDate(); LocalDate + * preClosedDate = eventDate; + * + * if (preClosedDate.isBefore(lastInterestPosedDate)) { throw new + * DepositAccountTransactionsException + * ("deposit.account.preclosed.date.should.be.after.last.interest.posted.date" + * , null); } + * + * Integer tenure = Months.monthsBetween(lastInterestPosedDate, + * preClosedDate).getMonths(); LocalDate actualPrecloseCalculationDate = + * lastInterestPosedDate.plusMonths(tenure); Integer missedDays = + * Days.daysBetween(actualPrecloseCalculationDate, preClosedDate).getDays(); + * + * Money deposit = Money.of(account.getDeposit().getCurrency(), + * account.getDeposit().getAmount()); Money accuredtotalAmount = null; Money + * remainDaysAmount = + * fixedTermDepositInterestCalculator.calculateRemainInterest(deposit, + * missedDays, preClosureInterestRate); if + * (account.isInterestCompoundingAllowed()) { accuredtotalAmount = + * fixedTermDepositInterestCalculator + * .calculateInterestOnMaturityFor(deposit, tenure, preClosureInterestRate, + * interestCompoundedEvery, + * this.product.getInterestCompoundedEveryPeriodType()); accuredtotalAmount + * = accuredtotalAmount.plus(remainDaysAmount); } else { accuredtotalAmount + * = fixedTermDepositInterestCalculator + * .calculateInterestOnMaturityForSimpleInterest(deposit, tenure, + * preClosureInterestRate, interestCompoundedEvery, + * this.product.getInterestCompoundedEveryPeriodType()); accuredtotalAmount + * = accuredtotalAmount.plus(remainDaysAmount); } this.total = + * account.isInterestCompoundingAllowed + * ()?accuredtotalAmount.getAmount():BigDecimal + * .valueOf(accuredtotalAmount.getAmount + * ().doubleValue()-this.interstPaid.doubleValue()); this.interestAccrued = + * accuredtotalAmount.minus(deposit).getAmount(); + * + * } + */ + + public void withdrawInterest(Money interest) { + @SuppressWarnings("unused") + boolean statustest = isActive(); + if (isActive()) { + DepositAccountTransaction depositAccountTransaction = DepositAccountTransaction.withdraw(null, new LocalDate(), interest); + depositAccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositAccountTransaction); + this.interstPaid = this.interstPaid.add(interest.getAmount()); + this.availableInterest = this.availableInterest.subtract(interest.getAmount()); + this.total = this.total.subtract(interest.getAmount()); + } + + } + + public void closeDepositAccount(DepositLifecycleStateMachine depositLifecycleStateMachine) { + DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED, + DepositAccountStatus.fromInt(this.depositStatus)); + this.depositStatus = statusEnumForClose.getValue(); + + DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.withdraw(getDeposit(), new LocalDate(), + Money.of(getDeposit().getCurrency(), getTotal()).minus(getDeposit())); + depositaccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositaccountTransaction); + + this.closedOnDate = new LocalDate().toDate(); + } + + public void update(final DepositProduct product, final String externalId, final LocalDate commencementDate, final Money deposit, + final Integer tenureInMonths, final BigDecimal maturityInterestRate, final BigDecimal preClosureInterestRate, + final Integer interestCompoundedEvery, final PeriodFrequencyType compoundingInterestFrequency, final boolean renewalAllowed, + final boolean preClosureAllowed, final boolean isInterestWithdrawable, final boolean isInterestCompoundingAllowed, + final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, final boolean isLockinPeriodAllowed, + final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { + + Money futureValueOnMaturity = null; + + if (isInterestCompoundingAllowed) { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, tenureInMonths, + maturityInterestRate, interestCompoundedEvery, compoundingInterestFrequency); + } else { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, + tenureInMonths, maturityInterestRate, interestCompoundedEvery, compoundingInterestFrequency); + } + + setExternalId(externalId); + if (commencementDate != null) { + this.projectedCommencementDate = commencementDate.toDate(); + this.maturesOnDate = commencementDate.plusMonths(this.tenureInMonths).minusDays(1).toDate(); + } + this.product = product; + this.depositAmount = deposit.getAmount(); + this.tenureInMonths = tenureInMonths; + this.interestRate = maturityInterestRate; + this.product.validateInterestRateInRange(maturityInterestRate); + this.preClosureInterestRate = preClosureInterestRate; + this.interestCompoundedEvery = interestCompoundedEvery; + this.interestCompoundedFrequencyType = compoundingInterestFrequency.getValue(); + this.renewalAllowed = renewalAllowed; + this.preClosureAllowed = preClosureAllowed; + this.isInterestWithdrawable = isInterestWithdrawable; + this.interestCompoundingAllowed = isInterestCompoundingAllowed; + this.projectedInterestAccruedOnMaturity = futureValueOnMaturity.minus(deposit).getAmount(); + this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount(); + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; + this.interestAccrued = BigDecimal.ZERO; + + } + + public void update(final boolean renewalAllowed, final boolean isInterestWithdrawable) { + this.renewalAllowed = renewalAllowed; + this.isInterestWithdrawable = isInterestWithdrawable; + } + + public boolean isSubmittedAndPendingApproval() { + return DepositAccountStatus.fromInt(this.depositStatus).isSubmittedAndPendingApproval(); + } + + public boolean isActive() { + return DepositAccountStatus.fromInt(this.depositStatus).isActive(); + } + + public void postInterestForDepositAccount(DepositAccount account, FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { + + LocalDate lastInterestPostedDate = getLastInterestPostedDate(); + LocalDate nextInterestPostingDate = getNextInterestPostedDate(); + Integer monthsForInterestCalculation = Months.monthsBetween(lastInterestPostedDate, new LocalDate()).getMonths(); + Integer postInterestItereations = monthsForInterestCalculation / this.interestCompoundedEvery; + Money deposit = Money.of(this.currency, this.depositAmount); + + while (postInterestItereations > 0) { + + lastInterestPostedDate = getLastInterestPostedDate(); + nextInterestPostingDate = getNextInterestPostedDate(); + if (lastInterestPostedDate.isBefore(getMaturityDate())) { + if (nextInterestPostingDate.isAfter(getMaturityDate())) { + Integer noofRemainMonthsAfterMaturity = Months.monthsBetween(getMaturityDate(), nextInterestPostingDate).getMonths(); + Integer noOfMonthsBeforeMaturity = Months.monthsBetween(lastInterestPostedDate, getMaturityDate()).getMonths(); + Money futureValueOnMaturity = null; + if (noOfMonthsBeforeMaturity > 0) { + + if (this.interestCompoundingAllowed) { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, + noOfMonthsBeforeMaturity, this.interestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } else { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest( + deposit, noOfMonthsBeforeMaturity, this.interestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } + this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.lastInterestPostedDate = nextInterestPostingDate.toDate(); + this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); + + } + if (noofRemainMonthsAfterMaturity > 0) { + + if (this.interestCompoundingAllowed) { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, + noofRemainMonthsAfterMaturity, this.preClosureInterestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } else { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest( + deposit, noofRemainMonthsAfterMaturity, this.preClosureInterestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } + this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.lastInterestPostedDate = nextInterestPostingDate.toDate(); + this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); + } + + // add transaction entry for each interest posting + DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, + nextInterestPostingDate, futureValueOnMaturity.minus(deposit)); + depositaccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositaccountTransaction); + } else { + Money futureValueOnMaturity = null; + if (this.interestCompoundingAllowed) { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, + this.interestCompoundedEvery, this.interestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } else { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, + this.interestCompoundedEvery, this.interestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } + this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.lastInterestPostedDate = nextInterestPostingDate.toDate(); + this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); + + // add transaction entry for each interest posting + DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, + nextInterestPostingDate, futureValueOnMaturity.minus(deposit)); + depositaccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositaccountTransaction); + } + } else { + Money futureValueOnMaturity = null; + if (this.interestCompoundingAllowed) { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityFor(deposit, + this.interestCompoundedEvery, this.preClosureInterestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } else { + futureValueOnMaturity = fixedTermDepositInterestCalculator.calculateInterestOnMaturityForSimpleInterest(deposit, + this.interestCompoundedEvery, this.preClosureInterestRate, this.interestCompoundedEvery, + getInterestCompoundedFrequencyType()); + } + this.interestPostedAmount = this.interestPostedAmount.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.availableInterest = this.availableInterest.add(futureValueOnMaturity.minus(deposit).getAmount()); + this.lastInterestPostedDate = nextInterestPostingDate.toDate(); + this.nextInterestPostingDate = nextInterestPostingDate.plusMonths(this.interestCompoundedEvery).toDate(); + + // add transaction entry for each interest posting + DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, nextInterestPostingDate, + futureValueOnMaturity.minus(deposit)); + depositaccountTransaction.updateAccount(this); + this.depositaccountTransactions.add(depositaccountTransaction); + } + postInterestItereations--; + } + + } + + private final LocalDate getLastInterestPostedDate() { + LocalDate lastInterestPostedDate; + if (this.lastInterestPostedDate == null) { + lastInterestPostedDate = new LocalDate(this.actualCommencementDate); + } else { + lastInterestPostedDate = new LocalDate(this.lastInterestPostedDate); + } + return lastInterestPostedDate; + } + + private final LocalDate getNextInterestPostedDate() { + LocalDate nextInterestPostingDate; + if (this.nextInterestPostingDate == null) { + nextInterestPostingDate = new LocalDate(this.nextInterestPostingDate).plusMonths(this.interestCompoundedEvery); + } else { + nextInterestPostingDate = new LocalDate(this.nextInterestPostingDate); + } + return nextInterestPostingDate; + } + + public BigDecimal getAvailableInterest() { + return availableInterest; + } + + public BigDecimal getInterestPostedAmount() { + return interestPostedAmount; + } - public BigDecimal getInterestPostedAmount() { - return interestPostedAmount; - } - - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountEvent.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountEvent.java index 71ecb640e..76e7c0b33 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountEvent.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountEvent.java @@ -1,7 +1,6 @@ package org.mifosplatform.portfolio.savingsdepositaccount.domain; public enum DepositAccountEvent { - - DEPOSIT_CREATED, DEPOSIT_REJECTED, DEPOSIT_APPROVED, DEPOSIT_APPROVAL_UNDO, DEPOSIT_WITHDRAWN, DEPOSIT_MATURED, DEPOSIT_CLOSED, DEPOSIT_PRECLOSED; -} + DEPOSIT_CREATED, DEPOSIT_REJECTED, DEPOSIT_APPROVED, DEPOSIT_APPROVAL_UNDO, DEPOSIT_WITHDRAWN, DEPOSIT_MATURED, DEPOSIT_CLOSED, DEPOSIT_PRECLOSED; +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountRepository.java index 61baec5fb..612a92611 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountRepository.java @@ -3,8 +3,6 @@ package org.mifosplatform.portfolio.savingsdepositaccount.domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -public interface DepositAccountRepository extends - JpaRepository, - JpaSpecificationExecutor { - -} +public interface DepositAccountRepository extends JpaRepository, JpaSpecificationExecutor { + // +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountStatus.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountStatus.java index 4de350f32..a060d7f3b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountStatus.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountStatus.java @@ -1,94 +1,94 @@ package org.mifosplatform.portfolio.savingsdepositaccount.domain; public enum DepositAccountStatus { - - INVALID(0, "depositStatusType.invalid"), // - SUBMITED_AND_PENDING_APPROVAL(100, "depositStatusType.submitted.and.pending.approval"), // - //APPROVED(200, "depositStatusType.approved"), // - ACTIVE(300, "depositStatusType.active"), // - WITHDRAWN_BY_CLIENT(400, "depositStatusType.withdrawn.by.client"), // - REJECTED(500, "depositStatusType.rejected"), // - CLOSED(600, "depositStatusType.closed"), // - MATURED(700,"depositStatusType.matured"), - PRECLOSED(800,"depositStatusType.preclosed"); - + + INVALID(0, "depositStatusType.invalid"), // + SUBMITED_AND_PENDING_APPROVAL(100, "depositStatusType.submitted.and.pending.approval"), // + // APPROVED(200, "depositStatusType.approved"), // + ACTIVE(300, "depositStatusType.active"), // + WITHDRAWN_BY_CLIENT(400, "depositStatusType.withdrawn.by.client"), // + REJECTED(500, "depositStatusType.rejected"), // + CLOSED(600, "depositStatusType.closed"), // + MATURED(700, "depositStatusType.matured"), PRECLOSED(800, "depositStatusType.preclosed"); + private final Integer value; - private final String code; - - private DepositAccountStatus(final Integer value, final String code) { - this.value = value; - this.code = code; - } - + private final String code; + + private DepositAccountStatus(final Integer value, final String code) { + this.value = value; + this.code = code; + } + public boolean hasStateOf(final DepositAccountStatus state) { - return this.value.equals(state.getValue()); - } + return this.value.equals(state.getValue()); + } - public Integer getValue() { - return value; - } + public Integer getValue() { + return value; + } - public String getCode() { - return code; - } - - public boolean isSubmittedAndPendingApproval() { - return this.value.equals(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL.getValue()); - } - - /*public boolean isApproved() { - return this.value.equals(DepositAccountStatus.APPROVED.getValue()); - }*/ - - public boolean isActive() { - return this.value.equals(DepositAccountStatus.ACTIVE.getValue()); - } + public String getCode() { + return code; + } - public boolean isClosed() { - return this.value.equals(DepositAccountStatus.CLOSED.getValue()); - } + public boolean isSubmittedAndPendingApproval() { + return this.value.equals(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL.getValue()); + } - public boolean isWithdrawnByClient() { - return this.value.equals(DepositAccountStatus.WITHDRAWN_BY_CLIENT.getValue()); - } + /* + * public boolean isApproved() { return + * this.value.equals(DepositAccountStatus.APPROVED.getValue()); } + */ - public boolean isRejected() { - return this.value.equals(DepositAccountStatus.REJECTED.getValue()); - } - - public boolean isPreClosed(){ - return this.value.equals(DepositAccountStatus.PRECLOSED.getValue()); - } - - public static DepositAccountStatus fromInt(final Integer statusValue) { + public boolean isActive() { + return this.value.equals(DepositAccountStatus.ACTIVE.getValue()); + } - DepositAccountStatus enumeration = DepositAccountStatus.INVALID; - switch (statusValue) { - case 100: - enumeration = DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL; - break; - /*case 200: - enumeration = DepositAccountStatus.APPROVED; - break;*/ - case 300: - enumeration = DepositAccountStatus.ACTIVE; - break; - case 400: - enumeration = DepositAccountStatus.WITHDRAWN_BY_CLIENT; - break; - case 500: - enumeration = DepositAccountStatus.REJECTED; - break; - case 600: - enumeration = DepositAccountStatus.CLOSED; - break; - case 700: - enumeration = DepositAccountStatus.MATURED; - break; - case 800: - enumeration = DepositAccountStatus.PRECLOSED; - break; - } - return enumeration; - } + public boolean isClosed() { + return this.value.equals(DepositAccountStatus.CLOSED.getValue()); + } + + public boolean isWithdrawnByClient() { + return this.value.equals(DepositAccountStatus.WITHDRAWN_BY_CLIENT.getValue()); + } + + public boolean isRejected() { + return this.value.equals(DepositAccountStatus.REJECTED.getValue()); + } + + public boolean isPreClosed() { + return this.value.equals(DepositAccountStatus.PRECLOSED.getValue()); + } + + public static DepositAccountStatus fromInt(final Integer statusValue) { + + DepositAccountStatus enumeration = DepositAccountStatus.INVALID; + switch (statusValue) { + case 100: + enumeration = DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL; + break; + /* + * case 200: enumeration = DepositAccountStatus.APPROVED; break; + */ + case 300: + enumeration = DepositAccountStatus.ACTIVE; + break; + case 400: + enumeration = DepositAccountStatus.WITHDRAWN_BY_CLIENT; + break; + case 500: + enumeration = DepositAccountStatus.REJECTED; + break; + case 600: + enumeration = DepositAccountStatus.CLOSED; + break; + case 700: + enumeration = DepositAccountStatus.MATURED; + break; + case 800: + enumeration = DepositAccountStatus.PRECLOSED; + break; + } + return enumeration; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransaction.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransaction.java index 7962daed8..462cb1bb3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransaction.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransaction.java @@ -21,92 +21,97 @@ import org.mifosplatform.organisation.monetary.domain.Money; import org.springframework.data.jpa.domain.AbstractPersistable; @Entity -@Table(name="m_deposit_account_transaction") +@Table(name = "m_deposit_account_transaction") public class DepositAccountTransaction extends AbstractPersistable { - - @SuppressWarnings("unused") - @ManyToOne(optional = false) - @JoinColumn(name = "deposit_account_id", nullable=false) + + @SuppressWarnings("unused") + @ManyToOne(optional = false) + @JoinColumn(name = "deposit_account_id", nullable = false) private DepositAccount depositAccount; - - @Enumerated(EnumType.ORDINAL) - @Column(name = "transaction_type_enum", nullable = false) - private DepositAccountTransactionType typeOf; - - @SuppressWarnings("unused") - @OneToOne(optional=true, cascade={CascadeType.PERSIST}) - @JoinColumn(name="contra_id") - private DepositAccountTransaction contra; - - @Temporal(TemporalType.DATE) - @Column(name = "transaction_date", nullable=false) - private final Date dateOf; - - @Column(name = "amount", scale = 6, precision = 19, nullable = false) - private final BigDecimal amount; - - @SuppressWarnings("unused") - @Column(name = "interest", scale = 6, precision = 19, nullable = false) - private final BigDecimal interest; - - @SuppressWarnings("unused") - @Column(name = "total", scale = 6, precision = 19, nullable = false) - private final BigDecimal total; - - protected DepositAccountTransaction(){ - this.depositAccount=null; - this.typeOf=null; - this.amount=null; - this.dateOf=null; - this.interest=null; - this.total=null; - } - - private DepositAccountTransaction(DepositAccountTransactionType type, final BigDecimal amount, final LocalDate date, final BigDecimal interest) { - this.typeOf = type; + + @Enumerated(EnumType.ORDINAL) + @Column(name = "transaction_type_enum", nullable = false) + private DepositAccountTransactionType typeOf; + + @SuppressWarnings("unused") + @OneToOne(optional = true, cascade = { CascadeType.PERSIST }) + @JoinColumn(name = "contra_id") + private DepositAccountTransaction contra; + + @Temporal(TemporalType.DATE) + @Column(name = "transaction_date", nullable = false) + private final Date dateOf; + + @Column(name = "amount", scale = 6, precision = 19, nullable = false) + private final BigDecimal amount; + + @SuppressWarnings("unused") + @Column(name = "interest", scale = 6, precision = 19, nullable = false) + private final BigDecimal interest; + + @SuppressWarnings("unused") + @Column(name = "total", scale = 6, precision = 19, nullable = false) + private final BigDecimal total; + + protected DepositAccountTransaction() { + this.depositAccount = null; + this.typeOf = null; + this.amount = null; + this.dateOf = null; + this.interest = null; + this.total = null; + } + + private DepositAccountTransaction(DepositAccountTransactionType type, final BigDecimal amount, final LocalDate date, + final BigDecimal interest) { + this.typeOf = type; this.amount = amount; - this.dateOf = date.toDateMidnight().toDate(); - this.interest = interest; - this.total = amount.doubleValue()==0?new BigDecimal(0):amount.add(interest); - } + this.dateOf = date.toDateMidnight().toDate(); + this.interest = interest; + this.total = amount.doubleValue() == 0 ? new BigDecimal(0) : amount.add(interest); + } - public Date getDateOf() { - return dateOf; - } + public Date getDateOf() { + return dateOf; + } - public BigDecimal getAmount() { - return amount; - } + public BigDecimal getAmount() { + return amount; + } + + public DepositAccountTransactionType getTypeOf() { + return typeOf; + } + + public Money getAmount(MonetaryCurrency currency) { + return Money.of(currency, this.amount); + } - public DepositAccountTransactionType getTypeOf() { - return typeOf; - } - - public Money getAmount(MonetaryCurrency currency) { - return Money.of(currency, this.amount); - } - public LocalDate getTransactionDate() { return new LocalDate(this.dateOf); } - public boolean isDeposit(){ - return DepositAccountTransactionType.DEPOSIT.equals(typeOf); - } + public boolean isDeposit() { + return DepositAccountTransactionType.DEPOSIT.equals(typeOf); + } - public static DepositAccountTransaction deposit(Money amount, LocalDate paymentDate, Money interest) { - return new DepositAccountTransaction(DepositAccountTransactionType.DEPOSIT, amount == null ? new BigDecimal(0) : amount.getAmount(), paymentDate, interest==null ? new BigDecimal(0) : interest.getAmount()); - } - - public static DepositAccountTransaction withdraw(Money amount, LocalDate paymentDate, Money interest) { - return new DepositAccountTransaction(DepositAccountTransactionType.WITHDRAW, amount == null ? new BigDecimal(0) : amount.getAmount(), paymentDate, interest==null ? new BigDecimal(0) : interest.getAmount()); - } - - public static DepositAccountTransaction postInterest(Money depositAmount, LocalDate paymentDate, Money interest) { - return new DepositAccountTransaction(DepositAccountTransactionType.INTEREST_POSTING, depositAmount == null ? new BigDecimal(0) : depositAmount.getAmount(), paymentDate, interest==null ? new BigDecimal(0) : interest.getAmount()); - } - - public void updateAccount(DepositAccount depositAccount) { - this.depositAccount=depositAccount; - } + public static DepositAccountTransaction deposit(Money amount, LocalDate paymentDate, Money interest) { + return new DepositAccountTransaction(DepositAccountTransactionType.DEPOSIT, + amount == null ? new BigDecimal(0) : amount.getAmount(), paymentDate, interest == null ? new BigDecimal(0) + : interest.getAmount()); + } + + public static DepositAccountTransaction withdraw(Money amount, LocalDate paymentDate, Money interest) { + return new DepositAccountTransaction(DepositAccountTransactionType.WITHDRAW, amount == null ? new BigDecimal(0) + : amount.getAmount(), paymentDate, interest == null ? new BigDecimal(0) : interest.getAmount()); + } + + public static DepositAccountTransaction postInterest(Money depositAmount, LocalDate paymentDate, Money interest) { + return new DepositAccountTransaction(DepositAccountTransactionType.INTEREST_POSTING, depositAmount == null ? new BigDecimal(0) + : depositAmount.getAmount(), paymentDate, interest == null ? new BigDecimal(0) : interest.getAmount()); + } + + public void updateAccount(DepositAccount depositAccount) { + this.depositAccount = depositAccount; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransactionType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransactionType.java index e6ba7c5a2..5f0e0aab1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransactionType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccountTransactionType.java @@ -1,60 +1,57 @@ package org.mifosplatform.portfolio.savingsdepositaccount.domain; public enum DepositAccountTransactionType { - - INVALID(0, "depositTransactionType.invalid"), // - DEPOSIT(1, "depositTransactionType.deposit"), // - WITHDRAW(2, "depositTransactionType.withdraw"), // - REVERSAL(3, "depositTransactionType.reversal"), - INTEREST_POSTING(4,"depositTransactionType.interestPosting"); + + INVALID(0, "depositTransactionType.invalid"), // + DEPOSIT(1, "depositTransactionType.deposit"), // + WITHDRAW(2, "depositTransactionType.withdraw"), // + REVERSAL(3, "depositTransactionType.reversal"), INTEREST_POSTING(4, "depositTransactionType.interestPosting"); private final Integer value; private final String code; - + private DepositAccountTransactionType(final Integer value, final String code) { - this.value=value; - this.code=code; - } + this.value = value; + this.code = code; + } - public Integer getValue() { - return value; - } + public Integer getValue() { + return value; + } - public String getCode() { - return code; - } - - public static DepositAccountTransactionType fromInt(final Integer transactionType){ - - if (transactionType == null) { - return DepositAccountTransactionType.INVALID; - } - - DepositAccountTransactionType depositTransactionType=null; - switch (transactionType) { - case 1: - depositTransactionType=DepositAccountTransactionType.DEPOSIT; - break; - - case 2: - depositTransactionType=DepositAccountTransactionType.WITHDRAW; - break; - - case 3: - depositTransactionType=DepositAccountTransactionType.REVERSAL; - break; - - case 4: - depositTransactionType=DepositAccountTransactionType.INTEREST_POSTING; - break; - - default : - depositTransactionType=DepositAccountTransactionType.INVALID; - break; + public String getCode() { + return code; + } - } - - return depositTransactionType; + public static DepositAccountTransactionType fromInt(final Integer transactionType) { + + if (transactionType == null) { return DepositAccountTransactionType.INVALID; } + + DepositAccountTransactionType depositTransactionType = null; + switch (transactionType) { + case 1: + depositTransactionType = DepositAccountTransactionType.DEPOSIT; + break; + + case 2: + depositTransactionType = DepositAccountTransactionType.WITHDRAW; + break; + + case 3: + depositTransactionType = DepositAccountTransactionType.REVERSAL; + break; + + case 4: + depositTransactionType = DepositAccountTransactionType.INTEREST_POSTING; + break; + + default: + depositTransactionType = DepositAccountTransactionType.INVALID; + break; + + } + + return depositTransactionType; } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachine.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachine.java index 007ff8a6d..2cd7ea8a2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachine.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachine.java @@ -1,8 +1,6 @@ package org.mifosplatform.portfolio.savingsdepositaccount.domain; - public interface DepositLifecycleStateMachine { - - DepositAccountStatus transition(DepositAccountEvent loanEvent, DepositAccountStatus from); -} + DepositAccountStatus transition(DepositAccountEvent loanEvent, DepositAccountStatus from); +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachineImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachineImpl.java index d64be509e..18ec2bbfe 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachineImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositLifecycleStateMachineImpl.java @@ -4,119 +4,111 @@ import java.util.List; import org.mifosplatform.portfolio.savingsdepositaccount.exception.InvalidDepositStateTransitionException; -public class DepositLifecycleStateMachineImpl implements - DepositLifecycleStateMachine { - - private final List allowedDepositStatuses; - - public DepositLifecycleStateMachineImpl(List allowedDepositStatuses) { - this.allowedDepositStatuses=allowedDepositStatuses; - } +public class DepositLifecycleStateMachineImpl implements DepositLifecycleStateMachine { - @Override - public DepositAccountStatus transition(DepositAccountEvent depositEvent, DepositAccountStatus from) { - - DepositAccountStatus newState = null; - - switch (depositEvent) { - case DEPOSIT_CREATED: - if (from == null) { - newState = stateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL, allowedDepositStatuses); - } - break; - case DEPOSIT_REJECTED: - if (from.hasStateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL)) { - newState = stateOf(DepositAccountStatus.REJECTED, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be rejected from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("rejection", "failed", errorMessage,from); - } - break; - case DEPOSIT_APPROVED: - if (from.hasStateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL)) { - newState = stateOf(DepositAccountStatus.ACTIVE, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be approved from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("approve", "failed", errorMessage,from); - } - break; - case DEPOSIT_WITHDRAWN: - if (this.anyOfAllowedWhenComingFrom(from, DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL, DepositAccountStatus.ACTIVE)) { - newState = stateOf(DepositAccountStatus.WITHDRAWN_BY_CLIENT, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be withdrawn from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("withdrawbyclient", "failed", errorMessage,from); - } - break; - case DEPOSIT_APPROVAL_UNDO: - if (from.hasStateOf(DepositAccountStatus.ACTIVE)) { - newState = stateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be unapproved from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("unapprove", "failed", errorMessage,from); - } - break; - case DEPOSIT_MATURED: - if (from.hasStateOf(DepositAccountStatus.ACTIVE) ){ - newState = stateOf(DepositAccountStatus.MATURED, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be matured from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("mature", "failed", errorMessage,from); - } - break; - case DEPOSIT_CLOSED: - if (from.hasStateOf(DepositAccountStatus.ACTIVE) ){ - newState = stateOf(DepositAccountStatus.CLOSED, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be closed from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("closed", "failed", errorMessage,from); - } - break; - case DEPOSIT_PRECLOSED: - if (from.hasStateOf(DepositAccountStatus.ACTIVE) ){ - newState = stateOf(DepositAccountStatus.PRECLOSED, allowedDepositStatuses); - } - else{ - final String errorMessage = "The DepositApplication can not be matured from "+from.getCode() ; - throw new InvalidDepositStateTransitionException("preclosure", "failed", errorMessage,from); - } - break; - default: - break; - - } - - return newState; - } - - private DepositAccountStatus stateOf(DepositAccountStatus state, List allowedLoanStatuses) { - DepositAccountStatus match = null; - for (DepositAccountStatus depositStatus : allowedLoanStatuses) { - if (depositStatus.hasStateOf(state)) { - match = depositStatus; - break; - } - } - return match; - } + private final List allowedDepositStatuses; - private boolean anyOfAllowedWhenComingFrom(final DepositAccountStatus state, final DepositAccountStatus... allowedStates) { - boolean allowed = false; + public DepositLifecycleStateMachineImpl(List allowedDepositStatuses) { + this.allowedDepositStatuses = allowedDepositStatuses; + } - for (DepositAccountStatus allowedState : allowedStates) { - if (state.hasStateOf(allowedState)) { - allowed = true; - break; - } - } + @Override + public DepositAccountStatus transition(DepositAccountEvent depositEvent, DepositAccountStatus from) { - return allowed; - } + DepositAccountStatus newState = null; + + switch (depositEvent) { + case DEPOSIT_CREATED: + if (from == null) { + newState = stateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL, allowedDepositStatuses); + } + break; + case DEPOSIT_REJECTED: + if (from.hasStateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL)) { + newState = stateOf(DepositAccountStatus.REJECTED, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be rejected from " + from.getCode(); + throw new InvalidDepositStateTransitionException("rejection", "failed", errorMessage, from); + } + break; + case DEPOSIT_APPROVED: + if (from.hasStateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL)) { + newState = stateOf(DepositAccountStatus.ACTIVE, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be approved from " + from.getCode(); + throw new InvalidDepositStateTransitionException("approve", "failed", errorMessage, from); + } + break; + case DEPOSIT_WITHDRAWN: + if (this.anyOfAllowedWhenComingFrom(from, DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL, DepositAccountStatus.ACTIVE)) { + newState = stateOf(DepositAccountStatus.WITHDRAWN_BY_CLIENT, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be withdrawn from " + from.getCode(); + throw new InvalidDepositStateTransitionException("withdrawbyclient", "failed", errorMessage, from); + } + break; + case DEPOSIT_APPROVAL_UNDO: + if (from.hasStateOf(DepositAccountStatus.ACTIVE)) { + newState = stateOf(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be unapproved from " + from.getCode(); + throw new InvalidDepositStateTransitionException("unapprove", "failed", errorMessage, from); + } + break; + case DEPOSIT_MATURED: + if (from.hasStateOf(DepositAccountStatus.ACTIVE)) { + newState = stateOf(DepositAccountStatus.MATURED, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be matured from " + from.getCode(); + throw new InvalidDepositStateTransitionException("mature", "failed", errorMessage, from); + } + break; + case DEPOSIT_CLOSED: + if (from.hasStateOf(DepositAccountStatus.ACTIVE)) { + newState = stateOf(DepositAccountStatus.CLOSED, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be closed from " + from.getCode(); + throw new InvalidDepositStateTransitionException("closed", "failed", errorMessage, from); + } + break; + case DEPOSIT_PRECLOSED: + if (from.hasStateOf(DepositAccountStatus.ACTIVE)) { + newState = stateOf(DepositAccountStatus.PRECLOSED, allowedDepositStatuses); + } else { + final String errorMessage = "The DepositApplication can not be matured from " + from.getCode(); + throw new InvalidDepositStateTransitionException("preclosure", "failed", errorMessage, from); + } + break; + default: + break; + + } + + return newState; + } + + private DepositAccountStatus stateOf(DepositAccountStatus state, List allowedLoanStatuses) { + DepositAccountStatus match = null; + for (DepositAccountStatus depositStatus : allowedLoanStatuses) { + if (depositStatus.hasStateOf(state)) { + match = depositStatus; + break; + } + } + return match; + } + + private boolean anyOfAllowedWhenComingFrom(final DepositAccountStatus state, final DepositAccountStatus... allowedStates) { + boolean allowed = false; + + for (DepositAccountStatus allowedState : allowedStates) { + if (state.hasStateOf(allowedState)) { + allowed = true; + break; + } + } + + return allowed; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/FixedTermDepositInterestCalculator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/FixedTermDepositInterestCalculator.java index 47980b4b7..b75d9ff52 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/FixedTermDepositInterestCalculator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/FixedTermDepositInterestCalculator.java @@ -11,88 +11,91 @@ import org.springframework.stereotype.Service; @Service public class FixedTermDepositInterestCalculator { - // FIXME - MADHUKAR - Are the unused field here needed? - public Money calculateInterestOnMaturityFor( - final Money deposit, - final Integer tenureInMonths, - final BigDecimal maturityInterestRate, - final Integer interestCompoundedEvery, - final PeriodFrequencyType interestCompoundedFrequencyPeriodType) { + // FIXME - MADHUKAR - Are the unused field here needed? + public Money calculateInterestOnMaturityFor(final Money deposit, final Integer tenureInMonths, final BigDecimal maturityInterestRate, + final Integer interestCompoundedEvery, final PeriodFrequencyType interestCompoundedFrequencyPeriodType) { - // TODO - Can change 'interest compounding' fields into something simpler like interestCompoundedFrequency {None (Simple Interest), Monthly, Quarterly, Half-Yearly, Annually} - // - the 'interestCompoundedEvery' would then be inferred form the selected type. - // - the special case of 'simple interest' or 'no compounding' would use simple formula rather than 'future value' function. - - // FIXME - assuming only monthly compounding period for now - MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); - Integer monthsInYear = 12; - - BigDecimal interestRateAsFraction = maturityInterestRate.divide(BigDecimal.valueOf(100), mc); - BigDecimal interestRateForOneMonth = interestRateAsFraction.divide(BigDecimal.valueOf(monthsInYear.doubleValue()), mc); - - BigDecimal ratePerCompoundingPeriod = interestRateForOneMonth.multiply(BigDecimal.valueOf(interestCompoundedEvery.doubleValue()), mc); - - Integer numberOfPeriods = tenureInMonths / interestCompoundedEvery; - - return fv(ratePerCompoundingPeriod, numberOfPeriods, deposit); - } + // TODO - Can change 'interest compounding' fields into something + // simpler like interestCompoundedFrequency {None (Simple Interest), + // Monthly, Quarterly, Half-Yearly, Annually} + // - the 'interestCompoundedEvery' would then be inferred form the + // selected type. + // - the special case of 'simple interest' or 'no compounding' would use + // simple formula rather than 'future value' function. - private static Money fv(final BigDecimal ratePerCompoundingPeriod, final Integer numberOfPeriods, final Money presentValue) { - - double pmtPerPeriod = Double.valueOf("0.0"); - double pv = presentValue.negated().getAmount().doubleValue(); - - double futureValue = fv(ratePerCompoundingPeriod.doubleValue(), numberOfPeriods.doubleValue(), pmtPerPeriod, pv, false); - - return Money.of(presentValue.getCurrency(), BigDecimal.valueOf(futureValue)); - } - - /** - * Future value of an amount given the number of payments, rate, amount of - * individual payment, present value and boolean value indicating whether - * payments are due at the beginning of period (false => payments are due at - * end of period) - */ - private static double fv(double ratePeriodCompoundingPeriod, double numberOfCompoundingPeriods, double pmtPerPeriod, double presentValue, boolean type) { - double retval = 0; - if (ratePeriodCompoundingPeriod == 0) { - retval = -1 * (presentValue + (numberOfCompoundingPeriods * pmtPerPeriod)); - } else { - double r1 = ratePeriodCompoundingPeriod + 1; - retval = ((1 - Math.pow(r1, numberOfCompoundingPeriods)) * (type ? r1 : 1) * pmtPerPeriod) / ratePeriodCompoundingPeriod - presentValue - * Math.pow(r1, numberOfCompoundingPeriods); - } - return retval; - } + // FIXME - assuming only monthly compounding period for now + MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); + Integer monthsInYear = 12; - public Money calculateInterestOnMaturityForSimpleInterest(Money deposit, - Integer tenureInMonths, BigDecimal maturityInterestRate, - Integer interestCompoundedEvery, - PeriodFrequencyType interestCompoundedFrequencyPeriodType) { - - MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); - Integer monthsInYear = 12; - - BigDecimal interestRateAsFraction = maturityInterestRate.divide(BigDecimal.valueOf(100), mc); - BigDecimal interestRateForOneMonth = interestRateAsFraction.divide(BigDecimal.valueOf(monthsInYear.doubleValue()), mc); - BigDecimal ratePerCompoundingPeriod = interestRateForOneMonth.multiply(BigDecimal.valueOf(interestCompoundedEvery.doubleValue()), mc); - Integer numberOfPeriods = tenureInMonths / interestCompoundedEvery; - - BigDecimal interest = ratePerCompoundingPeriod.multiply(deposit.getAmount()).multiply(BigDecimal.valueOf(new Double(numberOfPeriods))); - BigDecimal totalAmount =deposit.getAmount().add(interest); - - return Money.of(deposit.getCurrency(), totalAmount); - } - - public Money calculateRemainInterest(Money deposit, Integer days, BigDecimal interestRate){ - - MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); - Integer daysInYear = 365; - - BigDecimal interestRateAsFraction = interestRate.divide(BigDecimal.valueOf(100), mc); - BigDecimal interestRateForOneDay = interestRateAsFraction.divide(BigDecimal.valueOf(daysInYear.doubleValue()), mc); - BigDecimal interest = BigDecimal.valueOf(deposit.getAmount().doubleValue()*days.doubleValue()*interestRateForOneDay.doubleValue()); - - return Money.of(deposit.getCurrency(), interest); - } + BigDecimal interestRateAsFraction = maturityInterestRate.divide(BigDecimal.valueOf(100), mc); + BigDecimal interestRateForOneMonth = interestRateAsFraction.divide(BigDecimal.valueOf(monthsInYear.doubleValue()), mc); + + BigDecimal ratePerCompoundingPeriod = interestRateForOneMonth.multiply(BigDecimal.valueOf(interestCompoundedEvery.doubleValue()), + mc); + + Integer numberOfPeriods = tenureInMonths / interestCompoundedEvery; + + return fv(ratePerCompoundingPeriod, numberOfPeriods, deposit); + } + + private static Money fv(final BigDecimal ratePerCompoundingPeriod, final Integer numberOfPeriods, final Money presentValue) { + + double pmtPerPeriod = Double.valueOf("0.0"); + double pv = presentValue.negated().getAmount().doubleValue(); + + double futureValue = fv(ratePerCompoundingPeriod.doubleValue(), numberOfPeriods.doubleValue(), pmtPerPeriod, pv, false); + + return Money.of(presentValue.getCurrency(), BigDecimal.valueOf(futureValue)); + } + + /** + * Future value of an amount given the number of payments, rate, amount of + * individual payment, present value and boolean value indicating whether + * payments are due at the beginning of period (false => payments are due at + * end of period) + */ + private static double fv(double ratePeriodCompoundingPeriod, double numberOfCompoundingPeriods, double pmtPerPeriod, + double presentValue, boolean type) { + double retval = 0; + if (ratePeriodCompoundingPeriod == 0) { + retval = -1 * (presentValue + (numberOfCompoundingPeriods * pmtPerPeriod)); + } else { + double r1 = ratePeriodCompoundingPeriod + 1; + retval = ((1 - Math.pow(r1, numberOfCompoundingPeriods)) * (type ? r1 : 1) * pmtPerPeriod) / ratePeriodCompoundingPeriod + - presentValue * Math.pow(r1, numberOfCompoundingPeriods); + } + return retval; + } + + public Money calculateInterestOnMaturityForSimpleInterest(Money deposit, Integer tenureInMonths, BigDecimal maturityInterestRate, + Integer interestCompoundedEvery, PeriodFrequencyType interestCompoundedFrequencyPeriodType) { + + MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); + Integer monthsInYear = 12; + + BigDecimal interestRateAsFraction = maturityInterestRate.divide(BigDecimal.valueOf(100), mc); + BigDecimal interestRateForOneMonth = interestRateAsFraction.divide(BigDecimal.valueOf(monthsInYear.doubleValue()), mc); + BigDecimal ratePerCompoundingPeriod = interestRateForOneMonth.multiply(BigDecimal.valueOf(interestCompoundedEvery.doubleValue()), + mc); + Integer numberOfPeriods = tenureInMonths / interestCompoundedEvery; + + BigDecimal interest = ratePerCompoundingPeriod.multiply(deposit.getAmount()).multiply( + BigDecimal.valueOf(new Double(numberOfPeriods))); + BigDecimal totalAmount = deposit.getAmount().add(interest); + + return Money.of(deposit.getCurrency(), totalAmount); + } + + public Money calculateRemainInterest(Money deposit, Integer days, BigDecimal interestRate) { + + MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); + Integer daysInYear = 365; + + BigDecimal interestRateAsFraction = interestRate.divide(BigDecimal.valueOf(100), mc); + BigDecimal interestRateForOneDay = interestRateAsFraction.divide(BigDecimal.valueOf(daysInYear.doubleValue()), mc); + BigDecimal interest = BigDecimal.valueOf(deposit.getAmount().doubleValue() * days.doubleValue() + * interestRateForOneDay.doubleValue()); + + return Money.of(deposit.getCurrency(), interest); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccounDataValidationtException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccounDataValidationtException.java index 01a7b915c..d2db69ee0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccounDataValidationtException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccounDataValidationtException.java @@ -4,11 +4,11 @@ import java.math.BigDecimal; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; -public class DepositAccounDataValidationtException extends - AbstractPlatformDomainRuleException { - - public DepositAccounDataValidationtException(BigDecimal preClosureInterestRate, BigDecimal maturityMinInterestRate) { - super("error.msg.deposit.account.preClosureInterestRate.should.lessthanOrEqualTo.maturityMinInterestRate", "PreClosureInterestRate : "+preClosureInterestRate+"should lessthan or equal to maturityMinInterestRate : "+maturityMinInterestRate, preClosureInterestRate,maturityMinInterestRate); - } +public class DepositAccounDataValidationtException extends AbstractPlatformDomainRuleException { + public DepositAccounDataValidationtException(BigDecimal preClosureInterestRate, BigDecimal maturityMinInterestRate) { + super("error.msg.deposit.account.preClosureInterestRate.should.lessthanOrEqualTo.maturityMinInterestRate", + "PreClosureInterestRate : " + preClosureInterestRate + "should lessthan or equal to maturityMinInterestRate : " + + maturityMinInterestRate, preClosureInterestRate, maturityMinInterestRate); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountNotFoundException.java index a30778fe1..027a86f8e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountNotFoundException.java @@ -4,8 +4,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN public class DepositAccountNotFoundException extends AbstractPlatformResourceNotFoundException { - public DepositAccountNotFoundException(final Long id) { - super("error.msg.deposit.account.id.invalid", "Deposit account with identifier " + id + " does not exist", id); - } - -} + public DepositAccountNotFoundException(final Long id) { + super("error.msg.deposit.account.id.invalid", "Deposit account with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountReopenException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountReopenException.java index 3f1854d46..dbd16a884 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountReopenException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountReopenException.java @@ -3,10 +3,9 @@ package org.mifosplatform.portfolio.savingsdepositaccount.exception; import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; -public class DepositAccountReopenException extends AbstractPlatformDomainRuleException{ - - public DepositAccountReopenException(LocalDate maturedDate) { - super("error.msg.depositaccount.cannot.reopen.before.mature", "You cannot renew the account that is not matured:"+maturedDate); - } +public class DepositAccountReopenException extends AbstractPlatformDomainRuleException { + public DepositAccountReopenException(LocalDate maturedDate) { + super("error.msg.depositaccount.cannot.reopen.before.mature", "You cannot renew the account that is not matured:" + maturedDate); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountTransactionsException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountTransactionsException.java index f8b882fdb..0e877efa4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountTransactionsException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/DepositAccountTransactionsException.java @@ -2,11 +2,9 @@ package org.mifosplatform.portfolio.savingsdepositaccount.exception; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; - public class DepositAccountTransactionsException extends AbstractPlatformDomainRuleException { - public DepositAccountTransactionsException(String errorcode, String remainInterestForWithdrawal) { - super(errorcode, "You can Withdraw "+remainInterestForWithdrawal+" only", remainInterestForWithdrawal); - } - + public DepositAccountTransactionsException(String errorcode, String remainInterestForWithdrawal) { + super(errorcode, "You can Withdraw " + remainInterestForWithdrawal + " only", remainInterestForWithdrawal); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/InvalidDepositStateTransitionException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/InvalidDepositStateTransitionException.java index e4ed5e775..d52d6d8dc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/InvalidDepositStateTransitionException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/exception/InvalidDepositStateTransitionException.java @@ -8,5 +8,4 @@ public class InvalidDepositStateTransitionException extends AbstractPlatformDoma Object... defaultUserMessageArgs) { super("error.msg.deposit." + action + "." + postFix, defaultUserMessage, defaultUserMessageArgs); } - -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java index 70e740d81..820b0c5cc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java @@ -24,324 +24,314 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** - * An assembler for turning {@link DepositAccountCommand} into {@link DepositAccount}'s. + * An assembler for turning {@link DepositAccountCommand} into + * {@link DepositAccount}'s. */ @Service public class DepositAccountAssembler { - private final ClientRepository clientRepository; - private final DepositProductRepository depositProductRepository; - private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator; + private final ClientRepository clientRepository; + private final DepositProductRepository depositProductRepository; + private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator; - @Autowired - public DepositAccountAssembler(final ClientRepository clientRepository, final DepositProductRepository depositProductRepository, - final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { - this.clientRepository = clientRepository; - this.depositProductRepository = depositProductRepository; - this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator; - } + @Autowired + public DepositAccountAssembler(final ClientRepository clientRepository, final DepositProductRepository depositProductRepository, + final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { + this.clientRepository = clientRepository; + this.depositProductRepository = depositProductRepository; + this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator; + } - public DepositAccount assembleFrom(final DepositAccountCommand command) { + public DepositAccount assembleFrom(final DepositAccountCommand command) { - Client client = this.clientRepository.findOne(command.getClientId()); - if (client == null || client.isDeleted()) { - throw new ClientNotFoundException(command.getClientId()); - } - - DepositProduct product = this.depositProductRepository.findOne(command.getProductId()); - if (product == null || product.isDeleted()) { - throw new DepositProductNotFoundException(command.getProductId()); - } - - boolean isInterestWithdrawable = command.isInterestWithdrawable(); - - // details inherited from product setting (unless allowed to be overridden through account creation api - Money deposit = Money.of(product.getCurrency(), command.getDepositAmount()); - - Integer tenureInMonths = product.getTenureInMonths(); - if (command.getTenureInMonths() != null) { - tenureInMonths = command.getTenureInMonths(); - } - - BigDecimal maturityInterestRate = product.getMaturityDefaultInterestRate(); - if (command.getMaturityInterestRate() != null) { - maturityInterestRate = command.getMaturityInterestRate(); - } - - BigDecimal preClosureInterestRate = product.getPreClosureInterestRate(); - if(command.getPreClosureInterestRate()!=null){ - preClosureInterestRate = command.getPreClosureInterestRate(); - } - - if(product.getMaturityMinInterestRate().compareTo(preClosureInterestRate)==-1){ - throw new DepositAccounDataValidationtException(preClosureInterestRate, product.getMaturityMinInterestRate()); - } - - Integer compoundingInterestEvery = product.getInterestCompoundedEvery(); - if (command.getInterestCompoundedEvery() != null) { - compoundingInterestEvery = command.getInterestCompoundedEvery(); - } - - PeriodFrequencyType compoundingInterestFrequency = product.getInterestCompoundedEveryPeriodType(); - if (command.getInterestCompoundedEveryPeriodType() != null) { - compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); - } - - boolean renewalAllowed = product.isRenewalAllowed(); - if (command.isRenewalAllowedChanged()) { - renewalAllowed = command.isRenewalAllowed(); - } - - boolean preClosureAllowed = product.isPreClosureAllowed(); - if (command.isPreClosureAllowedChanged()) { - preClosureAllowed = command.isPreClosureAllowed(); - } - - boolean interestCompoundingAllowed= product.isInterestCompoundingAllowed(); - if(command.isInterestCompoundingAllowedChanged()){ - interestCompoundingAllowed = command.isInterestCompoundingAllowed(); - } - - boolean isLockinPeriodAllowed = product.isLockinPeriodAllowed(); - if(command.isLockinPeriodChanged()){ - isLockinPeriodAllowed = command.isLockinPeriodAllowed(); - } - - Integer lockinPeriod = product.getLockinPeriod(); - if(command.getLockinPeriod() != null){ - lockinPeriod = command.getLockinPeriod(); - } - - PeriodFrequencyType lockinPeriodType = product.getLockinPeriodType(); - if(command.getLockinPeriodType() != null){ - lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - } - // end of details allowed to be overriden from product - - DepositAccount account =new DepositAccount().openNew(client, product, command.getExternalId(), - deposit, - maturityInterestRate, preClosureInterestRate, - tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, - command.getCommencementDate(), - renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, - defaultDepositLifecycleStateMachine(),isInterestWithdrawable,interestCompoundingAllowed, - isLockinPeriodAllowed,lockinPeriod,lockinPeriodType); - - return account; - } - - private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() { - List allowedDepositStatuses = Arrays.asList(DepositAccountStatus.values()); - return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); - } + Client client = this.clientRepository.findOne(command.getClientId()); + if (client == null || client.isDeleted()) { throw new ClientNotFoundException(command.getClientId()); } - public DepositAccount assembleFrom(DepositAccount account, DepositAccountCommand command) { - - Client client = account.client(); - - DepositProduct product = account.product(); - if(command.getProductId() != null){ - product = this.depositProductRepository.findOne(command.getProductId()); - if (product == null || product.isDeleted()) { - throw new DepositProductNotFoundException(command.getProductId()); - } - } - - Money deposit = account.getDeposit(); - if(command.getDepositAmount() != null){ - deposit = Money.of(account.getDeposit().getCurrency(), command.getDepositAmount()); - } - - Integer tenureInMonths = account.getTenureInMonths(); - if(command.getTenureInMonths() != null){ - tenureInMonths =command.getTenureInMonths(); - } - - BigDecimal maturityInterestRate = account.getInterestRate(); - if(command.getMaturityInterestRate() != null){ - maturityInterestRate = command.getMaturityInterestRate(); - } - - BigDecimal preClosureInterestRate = account.getPreClosureInterestRate(); - if(command.getPreClosureInterestRate() != null){ - preClosureInterestRate = command.getPreClosureInterestRate(); - } - - - if(product.getMaturityMinInterestRate().compareTo(preClosureInterestRate)==-1){ - throw new DepositAccounDataValidationtException(preClosureInterestRate, product.getMaturityMinInterestRate()); - } - - Integer compoundingInterestEvery = account.getInterestCompoundedEvery(); - if(command.getInterestCompoundedEvery() != null){ - compoundingInterestEvery = command.getInterestCompoundedEvery(); - } - - PeriodFrequencyType compoundingInterestFrequency = account.getInterestCompoundedFrequencyType(); - if(command.getInterestCompoundedEveryPeriodType() !=null){ - compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); - } - - boolean renewalAllowed = account.isRenewalAllowed(); - if(command.isRenewalAllowedChanged()){ - renewalAllowed = command.isRenewalAllowed(); - } - - boolean preClosureAllowed = account.isPreClosureAllowed(); - if(command.isPreClosureAllowedChanged()){ - preClosureAllowed = command.isPreClosureAllowed(); - } - - boolean isInterestWithdrawable = account.isInterestWithdrawable(); - if(command.isInterestWithdrawableChanged()){ - isInterestWithdrawable = command.isInterestWithdrawable(); - } - - boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); - if(command.isInterestCompoundingAllowedChanged()){ - isInterestCompoundingAllowed = command.isInterestCompoundingAllowed(); - } - - boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); - if(command.isLockinPeriodChanged()){ - isLockinPeriodAllowed = command.isLockinPeriodAllowed(); - } - - Integer lockinPeriod = account.getLockinPeriod(); - if(command.getLockinPeriod() != null){ - lockinPeriod = command.getLockinPeriod(); - } - - PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); - if(command.getLockinPeriodType() != null){ - lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - } - - DepositAccount newAccount =new DepositAccount().openNew(client, product, null, - deposit, - maturityInterestRate, preClosureInterestRate, - tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, - account.maturesOnDate().plusDays(1), - renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, defaultDepositLifecycleStateMachine(), - isInterestWithdrawable,isInterestCompoundingAllowed,isLockinPeriodAllowed,lockinPeriod,lockinPeriodType); - - newAccount.updateAccount(account); - - return newAccount; - } + DepositProduct product = this.depositProductRepository.findOne(command.getProductId()); + if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(command.getProductId()); } - /*public void adjustTotalAmountForPreclosureInterest(DepositAccount account,LocalDate eventDate) { - account.adjustTotalAmountForPreclosureInterest(account,this.fixedTermDepositInterestCalculator,eventDate); - }*/ + boolean isInterestWithdrawable = command.isInterestWithdrawable(); - public void assembleUpdatedDepositAccount(DepositAccount account,DepositAccountCommand command) { - - DepositProduct product = account.product(); - if(command.getProductId() != null){ - product = this.depositProductRepository.findOne(command.getProductId()); - if (product == null || product.isDeleted()) { - throw new DepositProductNotFoundException(command.getProductId()); - } - } - - String externalId = account.getExternalId(); - if(command.isExternalIdChanged()){ - externalId = command.getExternalId(); - } - - LocalDate commencementDate = account.getProjectedCommencementDate(); - if(command.isCommencementDateChanged()){ - commencementDate = new LocalDate(command.getCommencementDate()); - } - - Money deposit = account.getDeposit(); - if(command.isDepositAmountChanged()){ - deposit = Money.of(product.getCurrency(), command.getDepositAmount()); - } - - Integer tenureInMonths = account.getTenureInMonths(); - if(command.isTenureInMonthsChanged()){ - tenureInMonths =command.getTenureInMonths(); - } - - BigDecimal maturityInterestRate = account.getInterestRate(); - if(command.isMaturityActualInterestRateChanged()){ - maturityInterestRate = command.getMaturityInterestRate(); - } - - BigDecimal preClosureInterestRate = account.getPreClosureInterestRate(); - if(command.isPreClosureInterestRateChanged()){ - preClosureInterestRate = command.getPreClosureInterestRate(); - } - - if(product.getMaturityMinInterestRate().compareTo(preClosureInterestRate)==-1){ - throw new DepositAccounDataValidationtException(preClosureInterestRate, product.getMaturityMinInterestRate()); - } - - Integer compoundingInterestEvery = account.getInterestCompoundedEvery(); - if(command.isCompoundingInterestEveryChanged()){ - compoundingInterestEvery = command.getInterestCompoundedEvery(); - } - - PeriodFrequencyType compoundingInterestFrequency = account.getInterestCompoundedFrequencyType(); - if(command.getInterestCompoundedEveryPeriodType() !=null){ - compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); - } - - boolean renewalAllowed = account.isRenewalAllowed(); - if(command.isRenewalAllowedChanged()){ - renewalAllowed = command.isRenewalAllowed(); - } - - boolean preClosureAllowed = account.isPreClosureAllowed(); - if(command.isPreClosureAllowedChanged()){ - preClosureAllowed = command.isPreClosureAllowed(); - } - - boolean isInterestWithdrawable = account.isInterestWithdrawable(); - if(command.isInterestWithdrawableChanged()){ - isInterestWithdrawable = command.isInterestWithdrawable(); - } - - boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); - if(command.isInterestCompoundingAllowedChanged()){ - isInterestCompoundingAllowed = command.isInterestCompoundingAllowed(); - } - - boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); - if(command.isLockinPeriodChanged()){ - isLockinPeriodAllowed = command.isLockinPeriodAllowed(); - } - - Integer lockinPeriod = account.getLockinPeriod(); - if(command.getLockinPeriod() != null){ - lockinPeriod = command.getLockinPeriod(); - } - - PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); - if(command.getLockinPeriodType() != null){ - lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); - } - account.update(product,externalId,commencementDate,deposit,tenureInMonths,maturityInterestRate,preClosureInterestRate,compoundingInterestEvery,compoundingInterestFrequency,renewalAllowed, - preClosureAllowed,isInterestWithdrawable,isInterestCompoundingAllowed,this.fixedTermDepositInterestCalculator,isLockinPeriodAllowed,lockinPeriod,lockinPeriodType); - } + // details inherited from product setting (unless allowed to be + // overridden through account creation api + Money deposit = Money.of(product.getCurrency(), command.getDepositAmount()); - public void updateApprovedDepositAccount(DepositAccount account, DepositAccountCommand command) { - - boolean renewalAllowed = account.isRenewalAllowed(); - if(command.isRenewalAllowedChanged()){ - renewalAllowed = command.isRenewalAllowed(); - } - - boolean isInterestWithdrawable = account.isInterestWithdrawable(); - if(command.isInterestWithdrawableChanged()){ - isInterestWithdrawable = command.isInterestWithdrawable(); - } - account.update(renewalAllowed,isInterestWithdrawable); - - } + Integer tenureInMonths = product.getTenureInMonths(); + if (command.getTenureInMonths() != null) { + tenureInMonths = command.getTenureInMonths(); + } - public void postInterest(DepositAccount account) { - account.postInterestForDepositAccount(account,this.fixedTermDepositInterestCalculator); - } + BigDecimal maturityInterestRate = product.getMaturityDefaultInterestRate(); + if (command.getMaturityInterestRate() != null) { + maturityInterestRate = command.getMaturityInterestRate(); + } + + BigDecimal preClosureInterestRate = product.getPreClosureInterestRate(); + if (command.getPreClosureInterestRate() != null) { + preClosureInterestRate = command.getPreClosureInterestRate(); + } + + if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException( + preClosureInterestRate, product.getMaturityMinInterestRate()); } + + Integer compoundingInterestEvery = product.getInterestCompoundedEvery(); + if (command.getInterestCompoundedEvery() != null) { + compoundingInterestEvery = command.getInterestCompoundedEvery(); + } + + PeriodFrequencyType compoundingInterestFrequency = product.getInterestCompoundedEveryPeriodType(); + if (command.getInterestCompoundedEveryPeriodType() != null) { + compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); + } + + boolean renewalAllowed = product.isRenewalAllowed(); + if (command.isRenewalAllowedChanged()) { + renewalAllowed = command.isRenewalAllowed(); + } + + boolean preClosureAllowed = product.isPreClosureAllowed(); + if (command.isPreClosureAllowedChanged()) { + preClosureAllowed = command.isPreClosureAllowed(); + } + + boolean interestCompoundingAllowed = product.isInterestCompoundingAllowed(); + if (command.isInterestCompoundingAllowedChanged()) { + interestCompoundingAllowed = command.isInterestCompoundingAllowed(); + } + + boolean isLockinPeriodAllowed = product.isLockinPeriodAllowed(); + if (command.isLockinPeriodChanged()) { + isLockinPeriodAllowed = command.isLockinPeriodAllowed(); + } + + Integer lockinPeriod = product.getLockinPeriod(); + if (command.getLockinPeriod() != null) { + lockinPeriod = command.getLockinPeriod(); + } + + PeriodFrequencyType lockinPeriodType = product.getLockinPeriodType(); + if (command.getLockinPeriodType() != null) { + lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + } + // end of details allowed to be overriden from product + + DepositAccount account = new DepositAccount().openNew(client, product, command.getExternalId(), deposit, maturityInterestRate, + preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, + command.getCommencementDate(), renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, + defaultDepositLifecycleStateMachine(), isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, + lockinPeriod, lockinPeriodType); + + return account; + } + + private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() { + List allowedDepositStatuses = Arrays.asList(DepositAccountStatus.values()); + return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); + } + + public DepositAccount assembleFrom(DepositAccount account, DepositAccountCommand command) { + + Client client = account.client(); + + DepositProduct product = account.product(); + if (command.getProductId() != null) { + product = this.depositProductRepository.findOne(command.getProductId()); + if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(command.getProductId()); } + } + + Money deposit = account.getDeposit(); + if (command.getDepositAmount() != null) { + deposit = Money.of(account.getDeposit().getCurrency(), command.getDepositAmount()); + } + + Integer tenureInMonths = account.getTenureInMonths(); + if (command.getTenureInMonths() != null) { + tenureInMonths = command.getTenureInMonths(); + } + + BigDecimal maturityInterestRate = account.getInterestRate(); + if (command.getMaturityInterestRate() != null) { + maturityInterestRate = command.getMaturityInterestRate(); + } + + BigDecimal preClosureInterestRate = account.getPreClosureInterestRate(); + if (command.getPreClosureInterestRate() != null) { + preClosureInterestRate = command.getPreClosureInterestRate(); + } + + if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException( + preClosureInterestRate, product.getMaturityMinInterestRate()); } + + Integer compoundingInterestEvery = account.getInterestCompoundedEvery(); + if (command.getInterestCompoundedEvery() != null) { + compoundingInterestEvery = command.getInterestCompoundedEvery(); + } + + PeriodFrequencyType compoundingInterestFrequency = account.getInterestCompoundedFrequencyType(); + if (command.getInterestCompoundedEveryPeriodType() != null) { + compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); + } + + boolean renewalAllowed = account.isRenewalAllowed(); + if (command.isRenewalAllowedChanged()) { + renewalAllowed = command.isRenewalAllowed(); + } + + boolean preClosureAllowed = account.isPreClosureAllowed(); + if (command.isPreClosureAllowedChanged()) { + preClosureAllowed = command.isPreClosureAllowed(); + } + + boolean isInterestWithdrawable = account.isInterestWithdrawable(); + if (command.isInterestWithdrawableChanged()) { + isInterestWithdrawable = command.isInterestWithdrawable(); + } + + boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); + if (command.isInterestCompoundingAllowedChanged()) { + isInterestCompoundingAllowed = command.isInterestCompoundingAllowed(); + } + + boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); + if (command.isLockinPeriodChanged()) { + isLockinPeriodAllowed = command.isLockinPeriodAllowed(); + } + + Integer lockinPeriod = account.getLockinPeriod(); + if (command.getLockinPeriod() != null) { + lockinPeriod = command.getLockinPeriod(); + } + + PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); + if (command.getLockinPeriodType() != null) { + lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + } + + DepositAccount newAccount = new DepositAccount().openNew(client, product, null, deposit, maturityInterestRate, + preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, account.maturesOnDate() + .plusDays(1), renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, + defaultDepositLifecycleStateMachine(), isInterestWithdrawable, isInterestCompoundingAllowed, isLockinPeriodAllowed, + lockinPeriod, lockinPeriodType); + + newAccount.updateAccount(account); + + return newAccount; + } + + /* + * public void adjustTotalAmountForPreclosureInterest(DepositAccount + * account,LocalDate eventDate) { + * account.adjustTotalAmountForPreclosureInterest + * (account,this.fixedTermDepositInterestCalculator,eventDate); } + */ + + public void assembleUpdatedDepositAccount(DepositAccount account, DepositAccountCommand command) { + + DepositProduct product = account.product(); + if (command.getProductId() != null) { + product = this.depositProductRepository.findOne(command.getProductId()); + if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(command.getProductId()); } + } + + String externalId = account.getExternalId(); + if (command.isExternalIdChanged()) { + externalId = command.getExternalId(); + } + + LocalDate commencementDate = account.getProjectedCommencementDate(); + if (command.isCommencementDateChanged()) { + commencementDate = new LocalDate(command.getCommencementDate()); + } + + Money deposit = account.getDeposit(); + if (command.isDepositAmountChanged()) { + deposit = Money.of(product.getCurrency(), command.getDepositAmount()); + } + + Integer tenureInMonths = account.getTenureInMonths(); + if (command.isTenureInMonthsChanged()) { + tenureInMonths = command.getTenureInMonths(); + } + + BigDecimal maturityInterestRate = account.getInterestRate(); + if (command.isMaturityActualInterestRateChanged()) { + maturityInterestRate = command.getMaturityInterestRate(); + } + + BigDecimal preClosureInterestRate = account.getPreClosureInterestRate(); + if (command.isPreClosureInterestRateChanged()) { + preClosureInterestRate = command.getPreClosureInterestRate(); + } + + if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException( + preClosureInterestRate, product.getMaturityMinInterestRate()); } + + Integer compoundingInterestEvery = account.getInterestCompoundedEvery(); + if (command.isCompoundingInterestEveryChanged()) { + compoundingInterestEvery = command.getInterestCompoundedEvery(); + } + + PeriodFrequencyType compoundingInterestFrequency = account.getInterestCompoundedFrequencyType(); + if (command.getInterestCompoundedEveryPeriodType() != null) { + compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); + } + + boolean renewalAllowed = account.isRenewalAllowed(); + if (command.isRenewalAllowedChanged()) { + renewalAllowed = command.isRenewalAllowed(); + } + + boolean preClosureAllowed = account.isPreClosureAllowed(); + if (command.isPreClosureAllowedChanged()) { + preClosureAllowed = command.isPreClosureAllowed(); + } + + boolean isInterestWithdrawable = account.isInterestWithdrawable(); + if (command.isInterestWithdrawableChanged()) { + isInterestWithdrawable = command.isInterestWithdrawable(); + } + + boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); + if (command.isInterestCompoundingAllowedChanged()) { + isInterestCompoundingAllowed = command.isInterestCompoundingAllowed(); + } + + boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); + if (command.isLockinPeriodChanged()) { + isLockinPeriodAllowed = command.isLockinPeriodAllowed(); + } + + Integer lockinPeriod = account.getLockinPeriod(); + if (command.getLockinPeriod() != null) { + lockinPeriod = command.getLockinPeriod(); + } + + PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); + if (command.getLockinPeriodType() != null) { + lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType()); + } + account.update(product, externalId, commencementDate, deposit, tenureInMonths, maturityInterestRate, preClosureInterestRate, + compoundingInterestEvery, compoundingInterestFrequency, renewalAllowed, preClosureAllowed, isInterestWithdrawable, + isInterestCompoundingAllowed, this.fixedTermDepositInterestCalculator, isLockinPeriodAllowed, lockinPeriod, + lockinPeriodType); + } + + public void updateApprovedDepositAccount(DepositAccount account, DepositAccountCommand command) { + + boolean renewalAllowed = account.isRenewalAllowed(); + if (command.isRenewalAllowedChanged()) { + renewalAllowed = command.isRenewalAllowed(); + } + + boolean isInterestWithdrawable = account.isInterestWithdrawable(); + if (command.isInterestWithdrawableChanged()) { + isInterestWithdrawable = command.isInterestWithdrawable(); + } + account.update(renewalAllowed, isInterestWithdrawable); + + } + + public void postInterest(DepositAccount account) { + account.postInterestForDepositAccount(account, this.fixedTermDepositInterestCalculator); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountEnumerations.java index ba09f3983..61dc5c717 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountEnumerations.java @@ -5,41 +5,52 @@ import org.mifosplatform.portfolio.savingsdepositaccount.domain.DepositAccountSt public class DepositAccountEnumerations { - public static EnumOptionData status(final Integer statusId) { - return status(DepositAccountStatus.fromInt(statusId)); - } + public static EnumOptionData status(final Integer statusId) { + return status(DepositAccountStatus.fromInt(statusId)); + } - public static EnumOptionData status(final DepositAccountStatus status) { - EnumOptionData optionData = null; - switch (status) { - case SUBMITED_AND_PENDING_APPROVAL: - optionData = new EnumOptionData(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL.getValue().longValue(), DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL.getCode(), "Submitted and pending approval"); - break; - /*case APPROVED: - optionData = new EnumOptionData(DepositAccountStatus.APPROVED.getValue().longValue(), DepositAccountStatus.APPROVED.getCode(), "Approved"); - break;*/ - case ACTIVE: - optionData = new EnumOptionData(DepositAccountStatus.ACTIVE.getValue().longValue(), DepositAccountStatus.ACTIVE.getCode(), "Active"); - break; - case REJECTED: - optionData = new EnumOptionData(DepositAccountStatus.REJECTED.getValue().longValue(), DepositAccountStatus.REJECTED.getCode(), "Rejected"); - break; - case WITHDRAWN_BY_CLIENT: - optionData = new EnumOptionData(DepositAccountStatus.WITHDRAWN_BY_CLIENT.getValue().longValue(), DepositAccountStatus.WITHDRAWN_BY_CLIENT.getCode(), "Withdrawn by applicant"); - break; - case MATURED: - optionData = new EnumOptionData(DepositAccountStatus.MATURED.getValue().longValue(), DepositAccountStatus.MATURED.getCode(), "Matured"); - break; - case CLOSED: - optionData = new EnumOptionData(DepositAccountStatus.CLOSED.getValue().longValue(), DepositAccountStatus.CLOSED.getCode(), "Closed"); - break; - case PRECLOSED: - optionData = new EnumOptionData(DepositAccountStatus.PRECLOSED.getValue().longValue(), DepositAccountStatus.PRECLOSED.getCode(), "Preclosed"); - break; - default: - optionData = new EnumOptionData(DepositAccountStatus.INVALID.getValue().longValue(), DepositAccountStatus.INVALID.getCode(), "Invalid"); - break; - } - return optionData; - } + public static EnumOptionData status(final DepositAccountStatus status) { + EnumOptionData optionData = null; + switch (status) { + case SUBMITED_AND_PENDING_APPROVAL: + optionData = new EnumOptionData(DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL.getValue().longValue(), + DepositAccountStatus.SUBMITED_AND_PENDING_APPROVAL.getCode(), "Submitted and pending approval"); + break; + /* + * case APPROVED: optionData = new + * EnumOptionData(DepositAccountStatus + * .APPROVED.getValue().longValue(), + * DepositAccountStatus.APPROVED.getCode(), "Approved"); break; + */ + case ACTIVE: + optionData = new EnumOptionData(DepositAccountStatus.ACTIVE.getValue().longValue(), DepositAccountStatus.ACTIVE.getCode(), + "Active"); + break; + case REJECTED: + optionData = new EnumOptionData(DepositAccountStatus.REJECTED.getValue().longValue(), + DepositAccountStatus.REJECTED.getCode(), "Rejected"); + break; + case WITHDRAWN_BY_CLIENT: + optionData = new EnumOptionData(DepositAccountStatus.WITHDRAWN_BY_CLIENT.getValue().longValue(), + DepositAccountStatus.WITHDRAWN_BY_CLIENT.getCode(), "Withdrawn by applicant"); + break; + case MATURED: + optionData = new EnumOptionData(DepositAccountStatus.MATURED.getValue().longValue(), + DepositAccountStatus.MATURED.getCode(), "Matured"); + break; + case CLOSED: + optionData = new EnumOptionData(DepositAccountStatus.CLOSED.getValue().longValue(), DepositAccountStatus.CLOSED.getCode(), + "Closed"); + break; + case PRECLOSED: + optionData = new EnumOptionData(DepositAccountStatus.PRECLOSED.getValue().longValue(), + DepositAccountStatus.PRECLOSED.getCode(), "Preclosed"); + break; + default: + optionData = new EnumOptionData(DepositAccountStatus.INVALID.getValue().longValue(), + DepositAccountStatus.INVALID.getCode(), "Invalid"); + break; + } + return optionData; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformService.java index d862c8bc0..470db52ee 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformService.java @@ -18,6 +18,6 @@ public interface DepositAccountReadPlatformService { DepositPermissionData retrieveDepositAccountsPermissions(DepositAccountData depositAccountData); BigDecimal retrieveAvailableInterestForWithdrawal(DepositAccountData account); - + Collection retrieveDepositAccountForLookup(); -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformServiceImpl.java index bb0e00108..f8f296b6f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountReadPlatformServiceImpl.java @@ -208,18 +208,19 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead Integer lockinPeriod = JdbcSupport.getInteger(rs, "lockinPeriod"); Integer lockinPeriodTypeValue = JdbcSupport.getInteger(rs, "lockinPeriodType"); EnumOptionData lockinPeriodType = SavingsDepositEnumerations.interestCompoundingPeriodType(lockinPeriodTypeValue); - + BigDecimal availableInterest = rs.getBigDecimal("availableInterest"); - BigDecimal interestPostedAmount = rs.getBigDecimal("interestPostedAmount"); - LocalDate lastInterestPostedDate = JdbcSupport.getLocalDate(rs, "lastInterestPostedDate"); - LocalDate nextInterestPostedDate = JdbcSupport.getLocalDate(rs, "nextInterestPostedDate"); + BigDecimal interestPostedAmount = rs.getBigDecimal("interestPostedAmount"); + LocalDate lastInterestPostedDate = JdbcSupport.getLocalDate(rs, "lastInterestPostedDate"); + LocalDate nextInterestPostedDate = JdbcSupport.getLocalDate(rs, "nextInterestPostedDate"); return new DepositAccountData(id, externalId, status, clientId, clientName, productId, productName, currencyData, depositAmount, interestRate, termInMonths, projectedCommencementDate, actualCommencementDate, maturedOn, projectedInterestAccrued, actualInterestAccrued, projectedMaturityAmount, actualMaturityAmount, interestCompoundedEvery, interestCompoundedEveryPeriodType, renewalAllowed, preClosureAllowed, preClosureInterestRate, withdrawnonDate, rejectedonDate, closedonDate, isInterestWithdrawable, interestPaid, interestCompoundingAllowed, - isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, availableInterest, interestPostedAmount, lastInterestPostedDate, nextInterestPostedDate); + isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, availableInterest, interestPostedAmount, lastInterestPostedDate, + nextInterestPostedDate); } } @@ -254,7 +255,18 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead boolean undoApprovalAllowed = (depositAccountData.getStatus().getId().equals(300L)); boolean renewelAllowed = false; if (depositAccountData.getMaturedOn() != null) { - if (new LocalDate().isAfter(depositAccountData.getMaturedOn())/* || depositAccountData.getMaturedOn().isEqual(new LocalDate()) */) { + if (new LocalDate().isAfter(depositAccountData.getMaturedOn())/* + * || + * depositAccountData + * . + * getMaturedOn + * (). + * isEqual + * ( + * new + * LocalDate + * ()) + */) { renewelAllowed = depositAccountData.isRenewalAllowed(); } } @@ -276,28 +288,28 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead return BigDecimal.valueOf(interstGettingForPeriod.multiply(new BigDecimal(noOfPeriods)).doubleValue() - account.getInterestPaid().doubleValue()); } - + @Override - public Collection retrieveDepositAccountForLookup() { + public Collection retrieveDepositAccountForLookup() { - this.context.authenticatedUser(); - DepositAccountLookupMapper mapper = new DepositAccountLookupMapper(); - String sql = "select "+mapper.depositAccountLookupSchema(); - return this.jdbcTemplate.query(sql, mapper, new Object[]{}); - - } - - private static final class DepositAccountLookupMapper implements RowMapper { - - public String depositAccountLookupSchema(){ - return " da.id as id from m_deposit_account da where da.status_enum=300 and da.is_deleted=0"; - } + this.context.authenticatedUser(); + DepositAccountLookupMapper mapper = new DepositAccountLookupMapper(); + String sql = "select " + mapper.depositAccountLookupSchema(); + return this.jdbcTemplate.query(sql, mapper, new Object[] {}); - @Override - public DepositAccountsForLookup mapRow(ResultSet rs, int rowNum) throws SQLException { - Long id = rs.getLong("id"); - return new DepositAccountsForLookup(id); - } - - } + } + + private static final class DepositAccountLookupMapper implements RowMapper { + + public String depositAccountLookupSchema() { + return " da.id as id from m_deposit_account da where da.status_enum=300 and da.is_deleted=0"; + } + + @Override + public DepositAccountsForLookup mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + Long id = rs.getLong("id"); + return new DepositAccountsForLookup(id); + } + + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountTransactionEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountTransactionEnumerations.java index 2b84c2984..9ba124818 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountTransactionEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountTransactionEnumerations.java @@ -4,31 +4,35 @@ import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.portfolio.savingsdepositaccount.domain.DepositAccountTransactionType; public class DepositAccountTransactionEnumerations { - - public static EnumOptionData depositType(final Integer statusId) { - return depositType(DepositAccountTransactionType.fromInt(statusId)); - } - private static EnumOptionData depositType(DepositAccountTransactionType transactionType) { - - EnumOptionData optionData=null; - switch (transactionType) { - case DEPOSIT: - optionData=new EnumOptionData(DepositAccountTransactionType.DEPOSIT.getValue().longValue(), DepositAccountTransactionType.DEPOSIT.getCode(), "Deposit"); - break; - - case WITHDRAW: - optionData=new EnumOptionData(DepositAccountTransactionType.WITHDRAW.getValue().longValue(), DepositAccountTransactionType.WITHDRAW.getCode(), "Withdraw"); - break; - - case REVERSAL: - optionData=new EnumOptionData(DepositAccountTransactionType.REVERSAL.getValue().longValue(), DepositAccountTransactionType.REVERSAL.getCode(), "Revarsal"); - break; - default: - optionData=new EnumOptionData(DepositAccountTransactionType.INVALID.getValue().longValue(), DepositAccountTransactionType.INVALID.getCode(), "Invalid Transaction"); - break; - } - return optionData; - } + public static EnumOptionData depositType(final Integer statusId) { + return depositType(DepositAccountTransactionType.fromInt(statusId)); + } + + private static EnumOptionData depositType(DepositAccountTransactionType transactionType) { + + EnumOptionData optionData = null; + switch (transactionType) { + case DEPOSIT: + optionData = new EnumOptionData(DepositAccountTransactionType.DEPOSIT.getValue().longValue(), + DepositAccountTransactionType.DEPOSIT.getCode(), "Deposit"); + break; + + case WITHDRAW: + optionData = new EnumOptionData(DepositAccountTransactionType.WITHDRAW.getValue().longValue(), + DepositAccountTransactionType.WITHDRAW.getCode(), "Withdraw"); + break; + + case REVERSAL: + optionData = new EnumOptionData(DepositAccountTransactionType.REVERSAL.getValue().longValue(), + DepositAccountTransactionType.REVERSAL.getCode(), "Revarsal"); + break; + default: + optionData = new EnumOptionData(DepositAccountTransactionType.INVALID.getValue().longValue(), + DepositAccountTransactionType.INVALID.getCode(), "Invalid Transaction"); + break; + } + return optionData; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java index d2f77e405..2e9f17cc7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java @@ -52,7 +52,7 @@ public interface DepositAccountWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'RENEW_DEPOSITACCOUNT')") EntityIdentifier renewDepositAccount(DepositAccountCommand command); - + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER')") - EntityIdentifier postInterestToDepositAccount(Collection accounts); + EntityIdentifier postInterestToDepositAccount(Collection accounts); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index f95b3d8ee..e49462152 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -305,9 +305,10 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo "deposit.transaction.canot.withdraw.before.lockinperiod.reached", "You can not withdraw your application before maturity date reached"); } } - // if (eventDate.isBefore(account.maturesOnDate())) { - // this.depositAccountAssembler.adjustTotalAmountForPreclosureInterest(account, eventDate); - // } + // if (eventDate.isBefore(account.maturesOnDate())) { + // this.depositAccountAssembler.adjustTotalAmountForPreclosureInterest(account, + // eventDate); + // } account.withdrawDepositAccountMoney(defaultDepositLifecycleStateMachine(), fixedTermDepositInterestCalculator, eventDate); this.depositAccountRepository.save(account); String noteText = command.getNote(); @@ -421,26 +422,23 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo return new EntityIdentifier(Long.valueOf(-1)); } } - - @Transactional - @Override - public EntityIdentifier postInterestToDepositAccount(Collection accounts) { - - try { - - for (DepositAccountsForLookup accountData : accounts) - { - DepositAccount account = this.depositAccountRepository.findOne(accountData.getId()); - if (account == null || account.isDeleted()) { - throw new DepositAccountNotFoundException(accountData.getId()); - } - this.depositAccountAssembler.postInterest(account); - this.depositAccountRepository.save(account); - } - return new EntityIdentifier(new Long(accounts.size())); - } catch (Exception e) { - return new EntityIdentifier(Long.valueOf(-1)); - } - - } + + @Transactional + @Override + public EntityIdentifier postInterestToDepositAccount(Collection accounts) { + + try { + + for (DepositAccountsForLookup accountData : accounts) { + DepositAccount account = this.depositAccountRepository.findOne(accountData.getId()); + if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(accountData.getId()); } + this.depositAccountAssembler.postInterest(account); + this.depositAccountRepository.save(account); + } + return new EntityIdentifier(new Long(accounts.size())); + } catch (Exception e) { + return new EntityIdentifier(Long.valueOf(-1)); + } + + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositStateTransitionCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositStateTransitionCommandValidator.java index 39dbe2586..4024ca5b1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositStateTransitionCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositStateTransitionCommandValidator.java @@ -9,24 +9,22 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand; public class DepositStateTransitionCommandValidator { - - private final DepositStateTransitionCommand command; - - public DepositStateTransitionCommandValidator(final DepositStateTransitionCommand command) { - this.command=command; - } - - public void validate(){ - - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition"); - baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull(); - baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); - } - } + private final DepositStateTransitionCommand command; + + public DepositStateTransitionCommandValidator(final DepositStateTransitionCommand command) { + this.command = command; + } + + public void validate() { + + List dataValidationErrors = new ArrayList(); + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition"); + baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); + baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull(); + baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/RenewDepositAccountCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/RenewDepositAccountCommandValidator.java index bb75fe5a1..b7123054f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/RenewDepositAccountCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/RenewDepositAccountCommandValidator.java @@ -9,35 +9,38 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand; public class RenewDepositAccountCommandValidator { - - private final DepositAccountCommand command; - - public RenewDepositAccountCommandValidator(final DepositAccountCommand command) { - this.command=command; - } - - public void validateForCreate() { - - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account"); - - baseDataValidator.reset().parameter("clientId").value(command.getClientId()).ignoreIfNull(); - baseDataValidator.reset().parameter("productId").value(command.getProductId()).ignoreIfNull(); - baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100); - baseDataValidator.reset().parameter("deposit").value(command.getDepositAmount()).ignoreIfNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).ignoreIfNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("preClosureInterestRate").value(command.getPreClosureInterestRate()).ignoreIfNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero(); - - baseDataValidator.reset().parameter("interestCompoundedEvery").value(command.getInterestCompoundedEvery()).ignoreIfNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).ignoreIfNull().inMinMaxRange(2, 2); - baseDataValidator.reset().parameter("commencementDate").value(command.getCommencementDate()).ignoreIfNull(); - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); - } - } + private final DepositAccountCommand command; + + public RenewDepositAccountCommandValidator(final DepositAccountCommand command) { + this.command = command; + } + + public void validateForCreate() { + + List dataValidationErrors = new ArrayList(); + + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account"); + + baseDataValidator.reset().parameter("clientId").value(command.getClientId()).ignoreIfNull(); + baseDataValidator.reset().parameter("productId").value(command.getProductId()).ignoreIfNull(); + baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100); + + baseDataValidator.reset().parameter("deposit").value(command.getDepositAmount()).ignoreIfNull().zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).ignoreIfNull() + .zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("preClosureInterestRate").value(command.getPreClosureInterestRate()).ignoreIfNull() + .zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero(); + + baseDataValidator.reset().parameter("interestCompoundedEvery").value(command.getInterestCompoundedEvery()).ignoreIfNull() + .integerGreaterThanZero(); + baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()) + .ignoreIfNull().inMinMaxRange(2, 2); + baseDataValidator.reset().parameter("commencementDate").value(command.getCommencementDate()).ignoreIfNull(); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java index 5907d0a9f..ab5392e24 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java @@ -43,7 +43,7 @@ import org.springframework.stereotype.Component; public class DepositProductsApiResource { private final String entityType = "DEPOSITPRODUCT"; - + @Autowired private DepositProductReadPlatformService depositProductReadPlatformService;