Search in sources :

Example 56 with AccountActionDateEntity

use of org.mifos.accounts.business.AccountActionDateEntity 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());
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) LocalDate(org.joda.time.LocalDate) SavingsAccountDepositDueDto(org.mifos.dto.screen.SavingsAccountDepositDueDto) DueOnDateDto(org.mifos.dto.domain.DueOnDateDto) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 57 with AccountActionDateEntity

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

the class ApplicationInitializer method applyMifos4948Fix.

@SuppressWarnings("unchecked")
private void applyMifos4948Fix() throws AccountException {
    Session session = StaticHibernateUtil.getSessionTL();
    List<LoanBO> fixLoans;
    Query query = session.getNamedQuery("fetchMissingInstalmentsForWriteOffsAndReschedules");
    fixLoans = query.list();
    if (fixLoans != null && fixLoans.size() > 0) {
        for (LoanBO fixLoan : fixLoans) {
            Set<AccountActionDateEntity> fixLoanSchedules = fixLoan.getAccountActionDates();
            Money totalMissedPayment = new Money(fixLoan.getCurrency());
            if (fixLoanSchedules != null && fixLoanSchedules.size() > 0) {
                for (AccountActionDateEntity fixLoanSchedule : fixLoanSchedules) {
                    LoanScheduleEntity loanInstallment = (LoanScheduleEntity) fixLoanSchedule;
                    totalMissedPayment = totalMissedPayment.add(loanInstallment.getPrincipalDue());
                }
            }
            logger.info("MIFOS-4948 - Loan: " + fixLoan.getGlobalAccountNum() + " - Adding payment: " + totalMissedPayment + " to fix instalments that should have been written-off or rescheduled.");
            fixLoan.applyMifos4948FixPayment(totalMissedPayment);
        }
        logger.info(fixLoans.size() + " Account Payments created to fix data related to MIFOS-4948");
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) Query(org.hibernate.Query) LoanBO(org.mifos.accounts.loan.business.LoanBO) Session(org.hibernate.Session)

Example 58 with AccountActionDateEntity

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

the class LoanBOForReversalIntegrationTest method applyPaymentForLoan.

private void applyPaymentForLoan() throws AccountException {
    loan = retrieveLoanAccount();
    loan.setUserContext(userContext);
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.addAll(loan.getAccountActionDates());
    Date currentDate = new Date(System.currentTimeMillis());
    PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(200), null, loan.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(loan, paymentData);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 59 with AccountActionDateEntity

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

the class LoanBOTestUtils method getSortedAccountActionDateEntity.

public static LoanScheduleEntity[] getSortedAccountActionDateEntity(final Set<AccountActionDateEntity> actionDateCollection, final int expectedCount) {
    LoanScheduleEntity[] sortedList = new LoanScheduleEntity[actionDateCollection.size()];
    Assert.assertEquals(expectedCount, actionDateCollection.size());
    for (AccountActionDateEntity actionDateEntity : actionDateCollection) {
        sortedList[actionDateEntity.getInstallmentId().intValue() - 1] = (LoanScheduleEntity) actionDateEntity;
    }
    return sortedList;
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity)

Example 60 with AccountActionDateEntity

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

the class FinancialBusinessServiceIntegrationTest method testLoanWriteOffAccountingEntries.

@Test
public void testLoanWriteOffAccountingEntries() throws Exception {
    loan = getLoanAccount();
    loan.setUserContext(TestUtils.makeUser());
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), null, null, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    FinancialBusinessService financialBusinessService = new FinancialBusinessService();
    AccountActionDateEntity accountActionDateEntity = loan.getAccountActionDate(Short.valueOf("1"));
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(loan.getUserContext().getId());
    LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.WRITEOFF, accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate(), personnel, new Date(System.currentTimeMillis()), ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), "Loan Written Off", null, ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
    accountPaymentEntity.addAccountTrxn(loanTrxnDetailEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
    financialBusinessService.buildAccountingEntries(loanTrxnDetailEntity);
    TestObjectFactory.updateObject(loan);
    Set<FinancialTransactionBO> finTrxnSet = loanTrxnDetailEntity.getFinancialTransactions();
    Assert.assertEquals(finTrxnSet.size(), 2);
    for (FinancialTransactionBO finTrxn : finTrxnSet) {
        if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("22")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("22")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("24"));
        } else {
        //--fail("There should not be any other entry");
        }
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)211 Money (org.mifos.framework.util.helpers.Money)80 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)58 LocalDate (org.joda.time.LocalDate)42 Date (java.util.Date)39 DateTime (org.joda.time.DateTime)33 MeetingBO (org.mifos.application.meeting.business.MeetingBO)33 AccountException (org.mifos.accounts.exceptions.AccountException)24 PaymentData (org.mifos.accounts.util.helpers.PaymentData)24 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)21 Date (java.sql.Date)19 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)15 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)14 UserContext (org.mifos.security.util.UserContext)14 Calendar (java.util.Calendar)13 GregorianCalendar (java.util.GregorianCalendar)13 CenterBuilder (org.mifos.domain.builders.CenterBuilder)13