use of org.mifos.dto.domain.DueOnDateDto in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveDepositDueDetails.
@Override
public SavingsAccountDepositDueDto retrieveDepositDueDetails(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
List<DueOnDateDto> previousDueDates = new ArrayList<DueOnDateDto>();
SavingsScheduleEntity nextInstallment = (SavingsScheduleEntity) savingsAccount.getDetailsOfNextInstallment();
Money totalDepositDue = Money.zero(savingsAccount.getCurrency());
LocalDate nextDueDate = new LocalDate();
if (nextInstallment != null) {
nextDueDate = new LocalDate(nextInstallment.getActionDate());
totalDepositDue = nextInstallment.getTotalDepositDue();
}
List<AccountActionDateEntity> scheduledDeposits = savingsAccount.getAccountActionDatesSortedByInstallmentId();
for (AccountActionDateEntity scheduledDeposit : scheduledDeposits) {
if (!scheduledDeposit.isPaid() && scheduledDeposit.isBefore(nextDueDate)) {
SavingsScheduleEntity savingsScheduledDeposit = (SavingsScheduleEntity) scheduledDeposit;
previousDueDates.add(new DueOnDateDto(scheduledDeposit.getActionDate(), MoneyUtils.currencyRound(savingsScheduledDeposit.getTotalDepositDue()).toString()));
}
}
DueOnDateDto nextDueDetail = new DueOnDateDto(new java.sql.Date(nextDueDate.toDateMidnight().toDate().getTime()), MoneyUtils.currencyRound(totalDepositDue).toString());
AccountStateEntity accountStateEntity = savingsAccount.getAccountState();
return new SavingsAccountDepositDueDto(nextDueDetail, previousDueDates, accountStateEntity.getId(), accountStateEntity.getName());
}
Aggregations