use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class TestObjectFactory method getDueActionDatesForAccount.
public static List<AccountActionDateEntity> getDueActionDatesForAccount(final Integer accountId, final java.sql.Date transactionDate) throws Exception {
List<AccountActionDateEntity> dueActionDates = new CustomerPersistence().retrieveCustomerAccountActionDetails(accountId, transactionDate);
for (AccountActionDateEntity accountActionDate : dueActionDates) {
Hibernate.initialize(accountActionDate);
if (accountActionDate instanceof LoanScheduleEntity) {
LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDate;
for (AccountFeesActionDetailEntity accountFeesActionDetail : loanScheduleEntity.getAccountFeesActionDetails()) {
Hibernate.initialize(accountFeesActionDetail);
}
}
if (accountActionDate instanceof CustomerScheduleEntity) {
CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDate;
for (AccountFeesActionDetailEntity accountFeesActionDetail : customerScheduleEntity.getAccountFeesActionDetails()) {
Hibernate.initialize(accountFeesActionDetail);
}
}
}
StaticHibernateUtil.flushSession();
return dueActionDates;
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getUpcomingInstallmentDetails.
private InstallmentDetailsDto getUpcomingInstallmentDetails(final AccountActionDateEntity upcomingAccountActionDate, final MifosCurrency currency) {
if (upcomingAccountActionDate != null) {
LoanScheduleEntity upcomingInstallment = (LoanScheduleEntity) upcomingAccountActionDate;
Money subTotal = upcomingInstallment.getPrincipalDue().add(upcomingInstallment.getInterestDue()).add(upcomingInstallment.getTotalFeesDueWithMiscFee()).add(upcomingInstallment.getPenaltyDue());
return new InstallmentDetailsDto(upcomingInstallment.getPrincipalDue().toString(), upcomingInstallment.getInterestDue().toString(), upcomingInstallment.getTotalFeeDueWithMiscFeeDue().toString(), upcomingInstallment.getPenaltyDue().toString(), subTotal.toString());
}
String zero = new Money(currency).toString();
return new InstallmentDetailsDto(zero, zero, zero, zero, zero);
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method createLoanSchedule.
@Override
public LoanScheduleDto createLoanSchedule(CreateLoanSchedule createLoanSchedule) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
// assemble into domain entities
LoanOfferingBO loanProduct = this.loanProductDao.findById(createLoanSchedule.getProductId());
CustomerBO customer = this.customerDao.findCustomerById(createLoanSchedule.getCustomerId());
Money loanAmountDisbursed = new Money(loanProduct.getCurrency(), createLoanSchedule.getLoanAmount());
List<AccountFeesEntity> accountFeeEntities = assembleAccountFees(createLoanSchedule.getAccountFeeEntities());
LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(loanAmountDisbursed, createLoanSchedule.getDisbursementDate(), createLoanSchedule.getInterestRate(), createLoanSchedule.getNumberOfInstallments(), createLoanSchedule.getGraceDuration(), accountFeeEntities, new ArrayList<AccountPenaltiesEntity>());
Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
boolean loanScheduleIndependentOfCustomerMeetingEnabled = createLoanSchedule.isRepaymentIndependentOfCustomerMeetingSchedule();
MeetingBO loanMeeting = null;
if (loanScheduleIndependentOfCustomerMeetingEnabled) {
loanMeeting = this.createNewMeetingForRepaymentDay(createLoanSchedule.getDisbursementDate(), createLoanSchedule, customer);
if (loanProduct.isVariableInstallmentsAllowed()) {
loanMeeting.setMeetingStartDate(createLoanSchedule.getDisbursementDate().toDateMidnight().toDate());
}
} else {
MeetingDto customerMeetingDto = customer.getCustomerMeetingValue().toDto();
loanMeeting = new MeetingFactory().create(customerMeetingDto);
Short recurAfter = loanProduct.getLoanOfferingMeeting().getMeeting().getRecurAfter();
loanMeeting.getMeetingDetails().setRecurAfter(recurAfter);
}
LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
LoanSchedule loanSchedule = this.loanScheduleService.generate(loanProduct, customer, loanMeeting, overridenDetail, configuration, userContext.getBranchId(), accountFeeEntities, createLoanSchedule.getDisbursementDate());
// translate to DTO form
List<LoanCreationInstallmentDto> installments = new ArrayList<LoanCreationInstallmentDto>();
Short digitsAfterDecimal = AccountingRules.getDigitsAfterDecimal();
for (LoanScheduleEntity loanScheduleEntity : loanSchedule.getRoundedLoanSchedules()) {
Integer installmentNumber = loanScheduleEntity.getInstallmentId().intValue();
LocalDate dueDate = new LocalDate(loanScheduleEntity.getActionDate());
String principal = loanScheduleEntity.getPrincipal().toString(digitsAfterDecimal);
String interest = loanScheduleEntity.getInterest().toString(digitsAfterDecimal);
String fees = loanScheduleEntity.getTotalFees().toString(digitsAfterDecimal);
String penalty = "0.0";
String total = loanScheduleEntity.getPrincipal().add(loanScheduleEntity.getInterest()).add(loanScheduleEntity.getTotalFees()).toString(digitsAfterDecimal);
LoanCreationInstallmentDto installment = new LoanCreationInstallmentDto(installmentNumber, dueDate, Double.valueOf(principal), Double.valueOf(interest), Double.valueOf(fees), Double.valueOf(penalty), Double.valueOf(total));
installments.add(installment);
}
return new LoanScheduleDto(customer.getDisplayName(), Double.valueOf(createLoanSchedule.getLoanAmount().doubleValue()), createLoanSchedule.getDisbursementDate(), loanProduct.getGraceType().getValue().intValue(), installments);
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getOverDueInstallmentDetailsForGroupLoan.
//TODO
private InstallmentDetailsDto getOverDueInstallmentDetailsForGroupLoan(final List<List<AccountActionDateEntity>> overDueInstallmentList, final MifosCurrency currency) {
Money principalDue = new Money(currency);
Money interestDue = new Money(currency);
Money feesDue = new Money(currency);
Money penaltyDue = new Money(currency);
for (List<AccountActionDateEntity> member : overDueInstallmentList) {
for (AccountActionDateEntity accountActionDate : member) {
LoanScheduleEntity installment = (LoanScheduleEntity) accountActionDate;
principalDue = principalDue.add(installment.getPrincipalDue());
interestDue = interestDue.add(installment.getInterestDue());
feesDue = feesDue.add(installment.getTotalFeeDueWithMiscFeeDue());
penaltyDue = penaltyDue.add(installment.getPenaltyDue());
}
}
Money subTotal = principalDue.add(interestDue).add(feesDue).add(penaltyDue);
return new InstallmentDetailsDto(principalDue.toString(), interestDue.toString(), feesDue.toString(), penaltyDue.toString(), subTotal.toString());
}
use of org.mifos.accounts.loan.business.LoanScheduleEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentSchedule.
@Override
public List<LoanRepaymentScheduleItemDto> retrieveLoanRepaymentSchedule(String globalAccountNum, Date viewDate) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
try {
personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
Errors errors = loanBusinessService.computeExtraInterest(loanBO, viewDate);
if (errors.hasErrors()) {
throw new MifosRuntimeException(errors.getErrorEntries().get(0).getDefaultMessage());
}
List<LoanRepaymentScheduleItemDto> loanSchedule = new ArrayList<LoanRepaymentScheduleItemDto>();
for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) {
LoanScheduleEntity loanAccountAction = (LoanScheduleEntity) accountAction;
Set<AccountFeesActionDetailEntity> feeEntities = loanAccountAction.getAccountFeesActionDetails();
List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
feeDtos.add(convertToDto(feeEntity));
}
loanSchedule.add(new LoanRepaymentScheduleItemDto(loanAccountAction.getInstallmentId(), loanAccountAction.getActionDate(), loanAccountAction.getPaymentStatus(), loanAccountAction.getPaymentDate(), loanAccountAction.getPrincipal().toString(), loanAccountAction.getPrincipalPaid().toString(), loanAccountAction.getInterest().toString(), loanAccountAction.getInterestPaid().toString(), loanAccountAction.getPenalty().toString(), loanAccountAction.getPenaltyPaid().toString(), loanAccountAction.getExtraInterest().toString(), loanAccountAction.getExtraInterestPaid().toString(), loanAccountAction.getMiscFee().toString(), loanAccountAction.getMiscFeePaid().toString(), loanAccountAction.getMiscPenalty().toString(), loanAccountAction.getMiscPenaltyPaid().toString(), feeDtos));
}
return loanSchedule;
}
Aggregations