Search in sources :

Example 16 with AccountPenaltiesEntity

use of org.mifos.accounts.business.AccountPenaltiesEntity in project head by mifos.

the class LoanBO method updateAccountPenaltiesEntity.

private void updateAccountPenaltiesEntity(final Short penaltyId) {
    AccountPenaltiesEntity accountPenalties = getAccountPenalty(penaltyId);
    if (accountPenalties != null) {
        accountPenalties.changePenaltyStatus(PenaltyStatus.INACTIVE, getDateTimeService().getCurrentJavaDateTime());
        accountPenalties.setLastAppliedDate(null);
    }
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity)

Example 17 with AccountPenaltiesEntity

use of org.mifos.accounts.business.AccountPenaltiesEntity 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);
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) LocalDate(org.joda.time.LocalDate) LoanScheduleConfiguration(org.mifos.clientportfolio.newloan.domain.LoanScheduleConfiguration) Money(org.mifos.framework.util.helpers.Money) CustomerBO(org.mifos.customers.business.CustomerBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) CreateLoanSchedule(org.mifos.clientportfolio.loan.service.CreateLoanSchedule) LoanSchedule(org.mifos.clientportfolio.newloan.domain.LoanSchedule) UserContext(org.mifos.security.util.UserContext) LoanScheduleDto(org.mifos.dto.screen.LoanScheduleDto) MifosUser(org.mifos.security.MifosUser) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) LoanProductOverridenDetail(org.mifos.clientportfolio.newloan.domain.LoanProductOverridenDetail) MeetingDto(org.mifos.dto.domain.MeetingDto) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO)

Aggregations

AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)17 ArrayList (java.util.ArrayList)11 UserContext (org.mifos.security.util.UserContext)11 MifosUser (org.mifos.security.MifosUser)10 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)9 LoanBO (org.mifos.accounts.loan.business.LoanBO)9 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)7 LocalDate (org.joda.time.LocalDate)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 MeetingBO (org.mifos.application.meeting.business.MeetingBO)6 LoanProductOverridenDetail (org.mifos.clientportfolio.newloan.domain.LoanProductOverridenDetail)6 LoanSchedule (org.mifos.clientportfolio.newloan.domain.LoanSchedule)6 LoanScheduleConfiguration (org.mifos.clientportfolio.newloan.domain.LoanScheduleConfiguration)6 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 Money (org.mifos.framework.util.helpers.Money)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 BigDecimal (java.math.BigDecimal)5 AmountPenaltyBO (org.mifos.accounts.penalties.business.AmountPenaltyBO)5 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5