removed unused warnings and code and format of code.

This commit is contained in:
Keith Woodlock
2013-01-22 10:54:14 +00:00
parent e8cc870f21
commit 9b85e9b274
5 changed files with 627 additions and 772 deletions
@@ -28,7 +28,6 @@ import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerServi
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData;
@@ -95,16 +94,14 @@ public class SavingsAccountApiResource {
@Autowired
private ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer;
@Autowired
private FromJsonHelper fromJsonHelper;
private static final Set<String> typicalResponseParameters = new HashSet<String>(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","outstandingAmount","savingScheduleData","transactions","interestPostEvery","interestPostFrequency"));
"lockinPeriod", "lockinPeriodType", "outstandingAmount", "savingScheduleData", "transactions", "interestPostEvery",
"interestPostFrequency"));
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@@ -193,20 +190,20 @@ public class SavingsAccountApiResource {
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
if (!associationParameters.isEmpty()) {
if (associationParameters.contains("all")) {
associationParameters.addAll(Arrays.asList("savingScheduleData","transactions"));
responseParameters.addAll(Arrays.asList("permissions","savingScheduleData","transactions"));
associationParameters.addAll(Arrays.asList("savingScheduleData", "transactions"));
responseParameters.addAll(Arrays.asList("permissions", "savingScheduleData", "transactions"));
} else {
responseParameters.addAll(associationParameters);
}
if (associationParameters.contains("savingScheduleData")) {
CurrencyData currencyData = account.getCurrencyData();
savingScheduleData = this.savingAccountReadPlatformService.retrieveSavingsAccountSchedule(accountId,currencyData);
account = new SavingAccountData(account,savingScheduleData);
savingScheduleData = this.savingAccountReadPlatformService.retrieveSavingsAccountSchedule(accountId, currencyData);
account = new SavingAccountData(account, savingScheduleData);
}
if (associationParameters.contains("transactions")) {
transactions = this.savingAccountReadPlatformService.retrieveSavingsAccountTransactions(accountId);
account = new SavingAccountData(account,transactions);
account = new SavingAccountData(account, transactions);
}
permissions = this.savingAccountReadPlatformService.retrieveSavingAccountPermissions(account);
account = new SavingAccountData(account, permissions);
@@ -217,12 +214,10 @@ public class SavingsAccountApiResource {
@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) {
@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);
@@ -233,14 +228,15 @@ public class SavingsAccountApiResource {
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
SavingAccountData account = this.savingAccountReadPlatformService.retrieveNewSavingsAccountDetails(clientId, productId);
account = handleTemplateRelatedData(responseParameters,account);
account = handleTemplateRelatedData(responseParameters, account);
return this.apiJsonSerializerService.serializeSavingAccountsDataToJson(prettyPrint, responseParameters, account);
}
private SavingAccountData handleTemplateRelatedData(Set<String> responseParameters, SavingAccountData account) {
responseParameters.addAll(Arrays.asList("productOptions", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions",
"savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions", "dueAmount"));
"savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions",
"dueAmount"));
Collection<SavingProductLookup> productOptions = savingProductReadPlatformService.retrieveAllSavingProductsForLookup();
List<CurrencyData> currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies();
@@ -264,13 +260,14 @@ public class SavingsAccountApiResource {
List<EnumOptionData> lockinPeriodTypeOptions = Arrays.asList(months);
EnumOptionData averagebal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.AVERAGEBAL);
// EnumOptionData minbal = SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MINBAL);
// EnumOptionData minbal =
// SavingProductEnumerations.savingInterestCalculationMethod(SavingInterestCalculationMethod.MINBAL);
EnumOptionData monthlyCollection = SavingProductEnumerations
.savingInterestCalculationMethod(SavingInterestCalculationMethod.MONTHLYCOLLECTION);
List<EnumOptionData> interestCalculationOptions = Arrays.asList(averagebal, monthlyCollection);
BigDecimal dueAmount = this.savingAccountReadPlatformService.deriveSavingDueAmount(account);
return new SavingAccountData(account, productOptions, currencyOptions, savingsProductTypeOptions,tenureTypeOptions,savingFrequencyOptions,
savingsInterestTypeOptions,lockinPeriodTypeOptions,interestCalculationOptions, dueAmount);
return new SavingAccountData(account, productOptions, currencyOptions, savingsProductTypeOptions, tenureTypeOptions,
savingFrequencyOptions, savingsInterestTypeOptions, lockinPeriodTypeOptions, interestCalculationOptions, dueAmount);
}
private boolean is(final String commandParam, final String commandValue) {
@@ -281,22 +278,27 @@ public class SavingsAccountApiResource {
@Path("{accountId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam, final String jsonRequestBody) {
public Response savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam,
final String jsonRequestBody) {
Response response = null;
if (is(commandParam, "approve")) {
SavingAccountApprovalCommand command = this.apiDataConversionService.convertJsonToSavingApprovalCommand(accountId, jsonRequestBody);
SavingAccountApprovalCommand command = this.apiDataConversionService.convertJsonToSavingApprovalCommand(accountId,
jsonRequestBody);
CommandProcessingResult identifier = this.savingAccountWritePlatformService.approveSavingAccount(command);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "depositmoney")) {
SavingAccountDepositCommand command = this.apiDataConversionService.convertJsonToSavingAccountDepositCommand(accountId, jsonRequestBody);
SavingAccountDepositCommand command = this.apiDataConversionService.convertJsonToSavingAccountDepositCommand(accountId,
jsonRequestBody);
CommandProcessingResult identifier = this.savingAccountWritePlatformService.depositMoney(command);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "withdraw")) {
SavingAccountWithdrawalCommand command = this.apiDataConversionService.convertJsonToSavingAccountWithdrawalCommand(accountId, jsonRequestBody);
SavingAccountWithdrawalCommand command = this.apiDataConversionService.convertJsonToSavingAccountWithdrawalCommand(accountId,
jsonRequestBody);
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingAmount(command);
response = Response.ok().entity(identifier).build();
} else {
SavingStateTransitionsCommand command = this.apiDataConversionService.convertJsonToSavingStateTransitionCommand(accountId, jsonRequestBody);
SavingStateTransitionsCommand command = this.apiDataConversionService.convertJsonToSavingStateTransitionCommand(accountId,
jsonRequestBody);
if (is(commandParam, "reject")) {
CommandProcessingResult identifier = this.savingAccountWritePlatformService.rejectSavingApplication(command);
response = Response.ok().entity(identifier).build();
@@ -336,5 +338,4 @@ public class SavingsAccountApiResource {
return Response.ok().entity(entityIdentifier).build();
}
}
@@ -11,7 +11,7 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductLookup;
/**
* Immutable data object reprsenting a savings account.
* Immutable data object representing a savings account.
*/
public class SavingAccountData {
@@ -50,21 +50,13 @@ public class SavingAccountData {
private final EnumOptionData lockinPeriodType;
private final Integer depositEvery;
@SuppressWarnings("unused")
private final List<SavingProductLookup> productOptions;
@SuppressWarnings("unused")
private final List<CurrencyData> currencyOptions;
@SuppressWarnings("unused")
private final List<EnumOptionData> savingsProductTypeOptions;
@SuppressWarnings("unused")
private final List<EnumOptionData> tenureTypeOptions;
@SuppressWarnings("unused")
private final List<EnumOptionData> savingFrequencyOptions;
@SuppressWarnings("unused")
private final List<EnumOptionData> savingsInterestTypeOptions;
@SuppressWarnings("unused")
private final List<EnumOptionData> lockinPeriodTypeOptions;
@SuppressWarnings("unused")
private final List<EnumOptionData> interestCalculationOptions;
private final Collection<SavingScheduleData> savingScheduleDatas;
@@ -89,7 +81,8 @@ public class SavingAccountData {
BigDecimal projectedInterestAccuredOnMaturity, BigDecimal actualInterestAccured, BigDecimal projectedMaturityAmount,
BigDecimal actualMaturityAmount, boolean preClosureAllowed, BigDecimal preClosureInterestRate, LocalDate withdrawnonDate,
LocalDate rejectedonDate, LocalDate closedonDate, boolean isLockinPeriodAllowed, Integer lockinPeriod,
EnumOptionData lockinPeriodType, Integer depositEvery, BigDecimal outstandingAmount, Integer interestPostEvery, EnumOptionData interestPostFrequency) {
EnumOptionData lockinPeriodType, Integer depositEvery, BigDecimal outstandingAmount, Integer interestPostEvery,
EnumOptionData interestPostFrequency) {
this.id = id;
this.status = status;
this.externalId = externalId;
@@ -188,17 +181,17 @@ public class SavingAccountData {
this.savingScheduleDatas = null;
this.permissions = null;
this.outstandingAmount = BigDecimal.ZERO;
this.dueAmount =BigDecimal.ZERO;
this.dueAmount = BigDecimal.ZERO;
this.savingScheduleData = null;
this.transactions = null;
this.interestPostEvery =null;
this.interestPostEvery = null;
this.interestPostFrequency = null;
}
public SavingAccountData(SavingAccountData account, Collection<SavingProductLookup> productOptions, List<CurrencyData> currencyOptions,
List<EnumOptionData> savingsProductTypeOptions, List<EnumOptionData> tenureTypeOptions,
List<EnumOptionData> savingFrequencyOptions, List<EnumOptionData> savingsInterestTypeOptions,
List<EnumOptionData> lockinPeriodTypeOptions, List<EnumOptionData> interestCalculationOptions,BigDecimal dueAmount) {
List<EnumOptionData> lockinPeriodTypeOptions, List<EnumOptionData> interestCalculationOptions, BigDecimal dueAmount) {
this.id = account.id;
this.status = account.status;
this.externalId = account.externalId;
@@ -259,7 +252,6 @@ public class SavingAccountData {
Integer tenure, EnumOptionData savingsFrequencyType, EnumOptionData interestType, EnumOptionData interestCalculationMethod,
BigDecimal minimumBalanceForWithdrawal, boolean partialDepositAllowed, boolean lockinPeriodAllowed, Integer lockinPeriod,
EnumOptionData lockinPeriodType, Integer depositEvery) {
this.id = null;
this.status = null;
this.externalId = null;
@@ -308,7 +300,7 @@ public class SavingAccountData {
this.dueAmount = BigDecimal.ZERO;
this.savingScheduleData = null;
this.transactions = null;
this.interestPostEvery =3;
this.interestPostEvery = 3;
this.interestPostFrequency = savingsFrequencyType;
}
@@ -474,38 +466,10 @@ public class SavingAccountData {
this.interestPostFrequency = account.interestPostFrequency;
}
public Long getId() {
return this.id;
}
public EnumOptionData getStatus() {
return this.status;
}
public String getExternalId() {
return this.externalId;
}
public Long getClientId() {
return this.clientId;
}
public String getClientName() {
return this.clientName;
}
public Long getProductId() {
return this.productId;
}
public String getProductName() {
return this.productName;
}
public EnumOptionData getProductType() {
return this.productType;
}
public CurrencyData getCurrencyData() {
return this.currencyData;
}
@@ -514,30 +478,6 @@ public class SavingAccountData {
return this.savingsDepositAmountPerPeriod;
}
public EnumOptionData getSavingsFrequencyType() {
return this.savingsFrequencyType;
}
public BigDecimal getTotalDepositAmount() {
return this.totalDepositAmount;
}
public BigDecimal getReccuringInterestRate() {
return this.recurringInterestRate;
}
public BigDecimal getSavingInterestRate() {
return this.savingInterestRate;
}
public EnumOptionData getInterestType() {
return this.interestType;
}
public EnumOptionData getInterestCalculationMethod() {
return this.interestCalculationMethod;
}
public Integer getTenure() {
return this.tenure;
}
@@ -546,10 +486,6 @@ public class SavingAccountData {
return this.tenureType;
}
public LocalDate getProjectedCommencementDate() {
return this.projectedCommencementDate;
}
public LocalDate getActualCommencementDate() {
return this.actualCommencementDate;
}
@@ -558,100 +494,11 @@ public class SavingAccountData {
return this.maturesOnDate;
}
public BigDecimal getProjectedInterestAccuredOnMaturity() {
return this.projectedInterestAccuredOnMaturity;
}
public BigDecimal getActualInterestAccured() {
return this.actualInterestAccured;
}
public BigDecimal getProjectedMaturityAmount() {
return this.projectedMaturityAmount;
}
public BigDecimal getActualMaturityAmount() {
return this.actualMaturityAmount;
}
public boolean isPreClosureAllowed() {
return this.preClosureAllowed;
}
public BigDecimal getPreClosureInterestRate() {
return this.preClosureInterestRate;
}
public LocalDate getWithdrawnonDate() {
return this.withdrawnonDate;
}
public LocalDate getRejectedonDate() {
return this.rejectedonDate;
}
public LocalDate getClosedonDate() {
return this.closedonDate;
}
public boolean isLockinPeriodAllowed() {
return this.isLockinPeriodAllowed;
}
public Integer getLockinPeriod() {
return this.lockinPeriod;
}
public EnumOptionData getLockinPeriodType() {
return this.lockinPeriodType;
}
public Integer getDepositEvery() {
return this.depositEvery;
}
public List<SavingProductLookup> getProductOptions() {
return this.productOptions;
}
public List<CurrencyData> getCurrencyOptions() {
return this.currencyOptions;
}
public List<EnumOptionData> getSavingsProductTypeOptions() {
return this.savingsProductTypeOptions;
}
public List<EnumOptionData> getTenureTypeOptions() {
return this.tenureTypeOptions;
}
public List<EnumOptionData> getSavingFrequencyOptions() {
return this.savingFrequencyOptions;
}
public List<EnumOptionData> getSavingsInterestTypeOptions() {
return this.savingsInterestTypeOptions;
}
public List<EnumOptionData> getLockinPeriodTypeOptions() {
return this.lockinPeriodTypeOptions;
}
public List<EnumOptionData> getInterestCalculationOptions() {
return this.interestCalculationOptions;
}
public BigDecimal getOutstandingAmount() {
return this.outstandingAmount;
}
public Integer getInterestPostEvery() {
return this.interestPostEvery;
}
public EnumOptionData getInterestPostFrequency() {
return this.interestPostFrequency;
}
}
@@ -43,7 +43,7 @@ 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<AppUser, Long> {
@ManyToOne
@@ -60,14 +60,12 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
@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;
@@ -96,7 +94,6 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "projected_commencement_date")
private Date projectedCommencementDate;
@SuppressWarnings("unused")
@Temporal(TemporalType.DATE)
@Column(name = "actual_commencement_date")
private Date actualCommencementDate;
@@ -191,8 +188,8 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "savingAccount", orphanRemoval = true)
private final List<SavingAccountTransaction> savingAccountTransactions = new ArrayList<SavingAccountTransaction>();
public SavingAccount() {
// TODO Auto-generated constructor stub
protected SavingAccount() {
//
}
public static SavingAccount openNew(Client client, SavingProduct product, String externalId, Money savingsDeposit,
@@ -200,13 +197,15 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
TenureTypeEnum tenureTypeEnum, SavingProductType savingProductType, SavingFrequencyType savingFrequencyType,
SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod,
boolean isLockinPeriodAllowed, Integer lockinPeriod, PeriodFrequencyType lockinPeriodType,
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final DepositLifecycleStateMachine lifecycleStateMachine,
Integer depositEvery, Integer interestPostEvery, Integer interestPostFrequency) {
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,
final DepositLifecycleStateMachine lifecycleStateMachine, Integer depositEvery, Integer interestPostEvery,
Integer interestPostFrequency) {
Money futureValueOnMaturity = null;
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod,depositEvery);
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod,
depositEvery);
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
futureValueOnMaturity = savingsDeposit;
} else {
@@ -215,15 +214,16 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
return new SavingAccount(client, externalId, product, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure,
commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, interestType, savingInterestCalculationMethod,
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, futureValueOnMaturity, lifecycleStateMachine,depositEvery,interestPostEvery, interestPostFrequency);
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, futureValueOnMaturity, lifecycleStateMachine, depositEvery,
interestPostEvery, interestPostFrequency);
}
public SavingAccount(Client client, String externalId, SavingProduct product, Money savingsDeposit, BigDecimal reccuringInterestRate,
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,Integer payEvery,
Integer interestPostEvery, Integer interestPostFrequency) {
PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, final DepositLifecycleStateMachine lifecycleStateMachine,
Integer payEvery, Integer interestPostEvery, Integer interestPostFrequency) {
DepositAccountStatus from = null;
if (accountStatus != null) {
@@ -256,25 +256,31 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.lockinPeriod = lockinPeriod;
this.lockinPeriodType = lockinPeriodType.getValue();
this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount();
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); //presently only for months
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring : BigDecimal.ZERO;
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(
BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); // presently
// only
// for
// months
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring
: BigDecimal.ZERO;
this.payEvery = payEvery;
this.outstandingAmount = BigDecimal.ZERO;
this.interestPostEvery = interestPostEvery;
this.interestPostFrequency=interestPostFrequency;
this.interestPostFrequency = interestPostFrequency;
}
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,Integer payEvery,
PeriodFrequencyType lockinPeriodType, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer payEvery,
SavingsInterestType interestType, Integer interestPostEvery, Integer interestPostFrequency) {
Money futureValueOnMaturity = null;
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod,payEvery);
futureValueOnMaturity = reccuringDepositInterestCalculator
.calculateInterestOnMaturityFor(savingsDeposit, tenure, reccuringInterestRate, commencementDate, tenureTypeEnum,
savingFrequencyType, savingInterestCalculationMethod, payEvery);
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
futureValueOnMaturity = savingsDeposit;
} else {
@@ -299,12 +305,17 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.payEvery = payEvery;
this.outstandingAmount = BigDecimal.ZERO;
this.interestPostEvery = interestPostEvery;
this.interestPostFrequency=interestPostFrequency;
this.interestPostFrequency = interestPostFrequency;
this.savingScheduleInstallments.clear();
this.projectedTotalOnMaturity = futureValueOnMaturity.getAmount();
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); //presently only for months
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring : BigDecimal.ZERO;
BigDecimal projectedInterestForReccuring = futureValueOnMaturity.getAmount().subtract(
BigDecimal.valueOf(savingsDeposit.getAmount().doubleValue() * tenure.doubleValue() / payEvery)); // presently
// only
// for
// months
this.projectedInterestAccruedOnMaturity = savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod() ? projectedInterestForReccuring
: BigDecimal.ZERO;
}
public boolean isDeleted() {
@@ -418,7 +429,6 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
public void reject(LocalDate rejectedOn, DepositLifecycleStateMachine depositLifecycleStateMachine) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED,
DepositAccountStatus.fromInt(this.accountStatus));
this.accountStatus = statusEnum.getValue();
@@ -442,7 +452,6 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
}
}
public LocalDate projectedCommencementDate() {
@@ -468,8 +477,8 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
final String errorMessage = "The date on which a deposit is rejected cannot be before its submittal date: "
+ projectedCommencementDate().toString();
throw new InvalidDepositStateTransitionException("withdrawnbyclient", "cannot.be.before.submittal.date", errorMessage, withdrawnOn,
projectedCommencementDate());
throw new InvalidDepositStateTransitionException("withdrawnbyclient", "cannot.be.before.submittal.date", errorMessage,
withdrawnOn, projectedCommencementDate());
}
@@ -489,8 +498,8 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
public void approveSavingAccount(LocalDate approvalDate, BigDecimal savingsDepositAmountPerPeriod, BigDecimal recurringInterestRate,
BigDecimal savingInterestRate, Integer interestType, Integer tenure, Integer tenureType, Integer frequency, Integer payEvery,
DepositLifecycleStateMachine depositLifecycleStateMachine, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,
Integer interestPostEvery, Integer interestPostFrequency) {
DepositLifecycleStateMachine depositLifecycleStateMachine,
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer interestPostEvery, Integer interestPostFrequency) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED,
DepositAccountStatus.fromInt(this.accountStatus));
@@ -504,7 +513,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
Money futureValueOnMaturity = null;
if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod()) {
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsAmountPerPeriod, tenure,
recurringInterestRate, approvalDate, tenureTypeEnum, savingFrequencyType, interestCalculationMethod,payEvery);
recurringInterestRate, approvalDate, tenureTypeEnum, savingFrequencyType, interestCalculationMethod, payEvery);
} else if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isPerpetual()) {
futureValueOnMaturity = savingsAmountPerPeriod;
} else {
@@ -521,9 +530,14 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.frequency = frequency;
this.payEvery = payEvery;
this.savingScheduleInstallments.clear();
this.total=futureValueOnMaturity.getAmount();
BigDecimal interestForReccuring = futureValueOnMaturity.getAmount().subtract(BigDecimal.valueOf(savingsDepositAmountPerPeriod.doubleValue() * tenure.doubleValue()/payEvery.doubleValue())); //presently only for months
this.interestAccrued = SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod() ? interestForReccuring : BigDecimal.ZERO;
this.total = futureValueOnMaturity.getAmount();
BigDecimal interestForReccuring = futureValueOnMaturity.getAmount().subtract(
BigDecimal.valueOf(savingsDepositAmountPerPeriod.doubleValue() * tenure.doubleValue() / payEvery.doubleValue())); // presently
// only
// for
// months
this.interestAccrued = SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod() ? interestForReccuring
: BigDecimal.ZERO;
this.interestPostEvery = interestPostEvery;
this.interestPostFrequency = interestPostFrequency;
@@ -539,26 +553,29 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
BigDecimal remainAmountToBePaid = BigDecimal.ZERO;
BigDecimal commandRemainDepositAmount = command.getSavingsDepostiAmountPerPeriod();
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.deposit(command.getSavingsDepostiAmountPerPeriod(),command.getDepositDate());
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.deposit(command.getSavingsDepostiAmountPerPeriod(),
command.getDepositDate());
savingAccountTransaction.updateAccount(this);
this.savingAccountTransactions.add(savingAccountTransaction);
this.outstandingAmount = this.outstandingAmount.add(command.getSavingsDepostiAmountPerPeriod());
this.totalSavingsAmount = this.totalSavingsAmount.add(command.getSavingsDepostiAmountPerPeriod());
if(SavingProductType.fromInt(this.savingProductType).isReccuring() && TenureTypeEnum.fromInt(tenureType).isFixedPeriod()) {
for(SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments){
if(!savingScheduleInstallment.isCompleted()){
if (SavingProductType.fromInt(this.savingProductType).isReccuring() && TenureTypeEnum.fromInt(tenureType).isFixedPeriod()) {
for (SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments) {
if (!savingScheduleInstallment.isCompleted()) {
depositAmount = savingScheduleInstallment.getDeposit();
remainAmountToBePaid = depositAmount.subtract(savingScheduleInstallment.getDepositPaid());
if (remainAmountToBePaid.doubleValue() > 0) {
if (commandRemainDepositAmount.doubleValue() > 0) {
if (commandRemainDepositAmount.doubleValue() >= remainAmountToBePaid.doubleValue()) {
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment.getDepositPaid()));
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment
.getDepositPaid()));
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
savingScheduleInstallment.setCompleted(true);
commandRemainDepositAmount = commandRemainDepositAmount.subtract(remainAmountToBePaid);
} else if(commandRemainDepositAmount.doubleValue() < remainAmountToBePaid.doubleValue()){
savingScheduleInstallment.setDepositPaid(commandRemainDepositAmount.add(savingScheduleInstallment.getDepositPaid()));
} else if (commandRemainDepositAmount.doubleValue() < remainAmountToBePaid.doubleValue()) {
savingScheduleInstallment.setDepositPaid(commandRemainDepositAmount.add(savingScheduleInstallment
.getDepositPaid()));
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
commandRemainDepositAmount = BigDecimal.ZERO;
}
@@ -567,7 +584,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
}
}
} else {
for(SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments){
for (SavingScheduleInstallments savingScheduleInstallment : this.savingScheduleInstallments) {
savingScheduleInstallment.setDepositPaid(remainAmountToBePaid.add(savingScheduleInstallment.getDepositPaid()));
savingScheduleInstallment.setPaymentDate(command.getDepositDate().toDate());
}
@@ -580,12 +597,11 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
public void withdrawAmount(BigDecimal amount, LocalDate transactionDate) {
this.outstandingAmount = this.outstandingAmount.subtract(amount);
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount,transactionDate);
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount, transactionDate);
savingAccountTransaction.updateAccount(this);
this.savingAccountTransactions.add(savingAccountTransaction);
}
/**
* Delete is a <i>soft delete</i>. Updates flag on account so it wont appear
* in query/report results.
@@ -603,7 +619,8 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
@SuppressWarnings("unused")
LocalDate nextInterestPostingDate = getNextInterestPostedDate();
@SuppressWarnings("unused")
SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(this.interestCalculationMethod);
SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod
.fromInt(this.interestCalculationMethod);
Integer monthsForInterestCalculation = Months.monthsBetween(lastInterestPostedDate, new LocalDate()).getMonths();
Integer postInterestItereations = monthsForInterestCalculation / this.interestPostEvery;
@@ -616,7 +633,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
BigDecimal totalOutstandingAmount = BigDecimal.ZERO;
boolean isOutstandingAmountCalculated = false;
while (postInterestItereations > 0 ) {
while (postInterestItereations > 0) {
lastInterestPostedDate = getLastInterestPostedDate();
nextInterestPostingDate = getNextInterestPostedDate();
LocalDate transactionStartDate = lastInterestPostedDate;
@@ -624,26 +641,27 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
BigDecimal termTotalAmount = BigDecimal.ZERO;
BigDecimal averageBalanceForTerm = BigDecimal.ZERO;
for (int i=0; i< interestPostEvery; i++){
//default for months here
for (int i = 0; i < interestPostEvery; i++) {
// default for months here
LocalDate transactionEndDate = transactionStartDate.plusMonths(1);
BigDecimal depositedAmount = BigDecimal.ZERO;
BigDecimal withdrawableAmount = BigDecimal.ZERO;
BigDecimal outstandingAmount = BigDecimal.ZERO;
for(SavingAccountTransaction savingAccountTransaction : this.savingAccountTransactions){
for (SavingAccountTransaction savingAccountTransaction : this.savingAccountTransactions) {
LocalDate actualTransactionDate = savingAccountTransaction.getTransactionDate();
if (actualTransactionDate != null && (actualTransactionDate.isAfter(transactionStartDate) || actualTransactionDate.isEqual(transactionStartDate))) {
if (actualTransactionDate != null
&& (actualTransactionDate.isAfter(transactionStartDate) || actualTransactionDate.isEqual(transactionStartDate))) {
if (actualTransactionDate.isBefore(transactionEndDate)) {
if(savingAccountTransaction.getTypeOf().isDeposit()){
if (savingAccountTransaction.getTypeOf().isDeposit()) {
depositedAmount = depositedAmount.add(savingAccountTransaction.getAmount());
} else if (savingAccountTransaction.getTypeOf().isWithdraw()) {
withdrawableAmount = withdrawableAmount.add(savingAccountTransaction.getAmount());
}
}
} else if (actualTransactionDate != null && (actualTransactionDate.isBefore(transactionStartDate))) {
if(!isOutstandingAmountCalculated){
if(savingAccountTransaction.getTypeOf().isDeposit()){
if (!isOutstandingAmountCalculated) {
if (savingAccountTransaction.getTypeOf().isDeposit()) {
depositedAmount = depositedAmount.add(savingAccountTransaction.getAmount());
} else if (savingAccountTransaction.getTypeOf().isWithdraw()) {
withdrawableAmount = withdrawableAmount.add(savingAccountTransaction.getAmount());
@@ -663,15 +681,16 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
// TODO- calculate interest on calculation method
// if (savingInterestCalculationMethod.isAverageBalance()) {
averageBalanceForTerm =BigDecimal.valueOf(termTotalAmount.doubleValue()/this.interestPostEvery);
BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue()/monthsInYear.doubleValue()*this.interestPostEvery.doubleValue());
averageBalanceForTerm = BigDecimal.valueOf(termTotalAmount.doubleValue() / this.interestPostEvery);
BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue() / monthsInYear.doubleValue()
* this.interestPostEvery.doubleValue());
BigDecimal interestPerTerm = averageBalanceForTerm.multiply(interestRatePerTerm);
this.interestPostedAmount = this.interestPostedAmount.add(interestPerTerm);
totalOutstandingAmount = totalOutstandingAmount.add(interestPerTerm);
// } else if(savingInterestCalculationMethod.isMonthlyCollection()){
//}
this.outstandingAmount = this.outstandingAmount . add(interestPerTerm);
// }
this.outstandingAmount = this.outstandingAmount.add(interestPerTerm);
this.lastInterestPostedDate = getNextInterestPostedDate().toDate();
this.nextInterestPostingDate = getNextInterestPostedDate().plusMonths(this.interestPostEvery).toDate();
postInterestItereations--;
@@ -697,14 +716,4 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
}
return nextInterestPostingDate;
}
private final LocalDate getMaturityDate(){
LocalDate commencementDate;
if (this.actualCommencementDate == null) {
commencementDate = new LocalDate(this.projectedCommencementDate).plusMonths(this.tenure);
} else {
commencementDate = new LocalDate(this.actualCommencementDate).plusMonths(this.tenure);
}
return commencementDate;
}
}
@@ -23,7 +23,6 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
@JoinColumn(name = "saving_account_id", nullable = false)
private SavingAccount savingAccount;
@SuppressWarnings("unused")
@Temporal(TemporalType.DATE)
@Column(name = "duedate", nullable = false)
private final Date dueDate;
@@ -32,16 +31,13 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
@Column(name = "installment", nullable = false)
private final Integer installmentNumber;
@SuppressWarnings("unused")
@Column(name = "deposit", scale = 6, precision = 19, nullable = false)
private BigDecimal deposit;
@SuppressWarnings("unused")
@Temporal(TemporalType.DATE)
@Column(name = "payment_date", nullable = true)
private Date paymentDate;
@SuppressWarnings("unused")
@Column(name = "deposit_paid", scale = 6, precision = 19, nullable = true)
private BigDecimal depositPaid;
@@ -49,7 +45,6 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
@Column(name = "interest_accured", scale = 6, precision = 19, nullable = true)
private BigDecimal interstAccured;
@SuppressWarnings("unused")
@Column(name = "completed_derived", nullable = false)
private boolean completed;
@@ -59,7 +54,8 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
this.paymentDate = null;
}
public SavingScheduleInstallments(SavingAccount account, Date dueDate, Integer installmentNumber, BigDecimal deposit, BigDecimal interstAccured) {
public SavingScheduleInstallments(SavingAccount account, Date dueDate, Integer installmentNumber, BigDecimal deposit,
BigDecimal interstAccured) {
this.savingAccount = account;
this.dueDate = dueDate;
this.installmentNumber = installmentNumber;
@@ -105,6 +101,4 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
public void setCompleted(boolean completed) {
this.completed = completed;
}
}
@@ -47,7 +47,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
this.context = context;
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.clientReadPlatformService = clientReadPlatformService;
this.savingProductReadPlatformService=savingProductReadPlatformService;
this.savingProductReadPlatformService = savingProductReadPlatformService;
}
@Override
@@ -155,15 +155,16 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
Integer depositEvery = JdbcSupport.getInteger(rs, "depositEvery");
Integer interestPostEvery = JdbcSupport.getInteger(rs, "interestPostEvery");
EnumOptionData interestPostFrequency = SavingProductEnumerations.interestFrequencyType(JdbcSupport.getInteger(rs, "interestPostFrequency"));
EnumOptionData interestPostFrequency = SavingProductEnumerations.interestFrequencyType(JdbcSupport.getInteger(rs,
"interestPostFrequency"));
return new SavingAccountData(id, status, externalId, clientId, clientName, productId, productName, productType, currencyData,
savingsDepostiAmountPerPeriod, savingsFrequencyType, totalDepositAmount, reccuringInterestRate, savingInterestRate,
interestType, interestCalculationMethod, tenure, tenureType, projectedCommencementDate, actualCommencementDate,
maturesOnDate, projectedInterestAccuredOnMaturity, actualInterestAccured, projectedMaturityAmount,
actualMaturityAmount, preClosureAllowed, preClosureInterestRate, withdrawnonDate, rejectedonDate, closedonDate,
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType,depositEvery,outstandingAmount, interestPostEvery, interestPostFrequency);
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, depositEvery, outstandingAmount, interestPostEvery,
interestPostFrequency);
}
}
@@ -182,10 +183,11 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
accountData = new SavingAccountData(clientAccount.id(), clientAccount.displayName(), selectedProduct.getId(),
selectedProduct.getName(), currency, selectedProduct.getInterestRate(), selectedProduct.getSavingsDepositAmount(),
selectedProduct.getSavingProductType(), selectedProduct.getTenureType(), selectedProduct.getTenure(), selectedProduct.getSavingFrequencyType(),
selectedProduct.getInterestType(), selectedProduct.getInterestCalculationMethod(),selectedProduct.getMinimumBalanceForWithdrawal(),
selectedProduct.isPartialDepositAllowed(), selectedProduct.isLockinPeriodAllowed(),selectedProduct.getLockinPeriod(),
selectedProduct.getLockinPeriodType(),selectedProduct.getDepositEvery());
selectedProduct.getSavingProductType(), selectedProduct.getTenureType(), selectedProduct.getTenure(),
selectedProduct.getSavingFrequencyType(), selectedProduct.getInterestType(),
selectedProduct.getInterestCalculationMethod(), selectedProduct.getMinimumBalanceForWithdrawal(),
selectedProduct.isPartialDepositAllowed(), selectedProduct.isLockinPeriodAllowed(), selectedProduct.getLockinPeriod(),
selectedProduct.getLockinPeriodType(), selectedProduct.getDepositEvery());
} else {
accountData = SavingAccountData.createFrom(clientAccount.id(), clientAccount.displayName());
@@ -193,7 +195,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
return accountData;
}
private SavingProductData findSavingProductById( Collection<SavingProductLookup> savingProducts, Long productId) {
private SavingProductData findSavingProductById(Collection<SavingProductLookup> savingProducts, Long productId) {
SavingProductData match = this.savingProductReadPlatformService.retrieveNewSavingProductDetails();
for (SavingProductLookup savingProductLookup : savingProducts) {
if (savingProductLookup.hasId(productId)) {
@@ -217,7 +219,8 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
boolean rejectAllowed = pendingApproval;
boolean withdrawnByApplicantAllowed = pendingApproval;
boolean isMaturedDepositAccount = (savingAccountData.getStatus().getId().equals(700L));
return new SavingPermissionData(rejectAllowed, withdrawnByApplicantAllowed, undoApprovalAllowed, pendingApproval, renewelAllowed, isMaturedDepositAccount);
return new SavingPermissionData(rejectAllowed, withdrawnByApplicantAllowed, undoApprovalAllowed, pendingApproval, renewelAllowed,
isMaturedDepositAccount);
}
@SuppressWarnings("unused")
@@ -232,11 +235,13 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
BigDecimal amountPerPeriod = account.getSavingsDepostiAmountPerPeriod();
Integer tenure = account.getTenure();
Integer depositEvery = account.getDepositEvery();
Integer noOfPeriods = tenure/depositEvery ;
Integer noOfPeriods = tenure / depositEvery;
Integer noOfMonths = Months.monthsBetween(date, new LocalDate()).getMonths();
Integer noOfPeriodsExistedTillDate = noOfMonths/depositEvery;
BigDecimal totalAmountToBePaidTillDate = BigDecimal.valueOf(noOfPeriodsExistedTillDate.doubleValue()*amountPerPeriod.doubleValue());
dueAmount = dueAmount.add(BigDecimal.valueOf(totalAmountToBePaidTillDate.doubleValue() - account.getOutstandingAmount().doubleValue()));
Integer noOfPeriodsExistedTillDate = noOfMonths / depositEvery;
BigDecimal totalAmountToBePaidTillDate = BigDecimal.valueOf(noOfPeriodsExistedTillDate.doubleValue()
* amountPerPeriod.doubleValue());
dueAmount = dueAmount.add(BigDecimal.valueOf(totalAmountToBePaidTillDate.doubleValue()
- account.getOutstandingAmount().doubleValue()));
}
dueAmount = dueAmount.doubleValue() < 0 ? BigDecimal.ZERO : dueAmount;
@@ -247,23 +252,24 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
public SavingScheduleData retrieveSavingsAccountSchedule(Long accountId, CurrencyData currency) {
this.context.authenticatedUser();
SavingAccountScheduleMapper mapper = new SavingAccountScheduleMapper();
String sql = "Select " + mapper.savingScheduleSchema() +" where ss.saving_account_id =? order by ss.installment";
List<SavingSchedulePeriodData> periods = this.jdbcTemplate.query(sql, mapper, new Object[]{accountId});
String sql = "Select " + mapper.savingScheduleSchema() + " where ss.saving_account_id =? order by ss.installment";
List<SavingSchedulePeriodData> periods = this.jdbcTemplate.query(sql, mapper, new Object[] { accountId });
BigDecimal cumulativeDepositDue = BigDecimal.ZERO;
BigDecimal cumulativeDepositPaid = BigDecimal.ZERO;
BigDecimal cummulativeInterestAccured = BigDecimal.ZERO;
for(SavingSchedulePeriodData data : periods){
cumulativeDepositDue = cumulativeDepositDue.add(data.getDepositDue())/*.subtract(data.getDepositPaid())*/;
for (SavingSchedulePeriodData data : periods) {
cumulativeDepositDue = cumulativeDepositDue.add(data.getDepositDue());
cumulativeDepositPaid = cumulativeDepositPaid.add(data.getDepositPaid());
cummulativeInterestAccured = cummulativeInterestAccured.add(data.getInterestAccured());
}
SavingScheduleData scheduleData = new SavingScheduleData(currency, cumulativeDepositDue, cumulativeDepositPaid, cummulativeInterestAccured, periods);
SavingScheduleData scheduleData = new SavingScheduleData(currency, cumulativeDepositDue, cumulativeDepositPaid,
cummulativeInterestAccured, periods);
return scheduleData;
}
public static final class SavingAccountScheduleMapper implements RowMapper<SavingSchedulePeriodData> {
public String savingScheduleSchema(){
public String savingScheduleSchema() {
return "ss.id as id, ss.saving_account_id as savingAccountId, ss.duedate as dueDate, ss.installment as installment, "
+ " ss.deposit as deposit, ss.payment_date as paymentDate, ss.deposit_paid as depositPaid, "
+ " ss.completed_derived as completedDerived, ss.interest_accured AS interestAccured FROM m_saving_schedule ss";
@@ -286,13 +292,13 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
@Override
public Collection<SavingAccountForLookup> retrieveSavingAccountsForLookUp() {
SavingAccountLookupMapper mapper = new SavingAccountLookupMapper();
String sql = "select "+ mapper.schema();
String sql = "select " + mapper.schema();
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
}
private static final class SavingAccountLookupMapper implements RowMapper<SavingAccountForLookup> {
public String schema(){
public String schema() {
return " sa.id as id from m_saving_account sa where sa.is_deleted=0 and sa.status_enum=300";
}
@@ -308,8 +314,8 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
public Collection<SavingAccountTransactionsData> retrieveSavingsAccountTransactions(Long accountId) {
this.context.authenticatedUser();
SavingAccountTransactionMapper savingAccountTransactionMapper = new SavingAccountTransactionMapper();
String sql = "select "+ savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? ";
return jdbcTemplate.query(sql, savingAccountTransactionMapper, new Object[] {accountId});
String sql = "select " + savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? ";
return jdbcTemplate.query(sql, savingAccountTransactionMapper, new Object[] { accountId });
}
private static final class SavingAccountTransactionMapper implements RowMapper<SavingAccountTransactionsData> {
@@ -327,7 +333,5 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
BigDecimal amount = rs.getBigDecimal("amount");
return new SavingAccountTransactionsData(id, transactionDate, transactionType, amount);
}
}
}