Search in sources :

Example 26 with CustomerAccountBO

use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.

the class AccountGetFeeDatesIntegrationTest method getScheduledDatesForFeesForGivenCustomerForWeeklySchedules.

@Test
public void getScheduledDatesForFeesForGivenCustomerForWeeklySchedules() throws Exception {
    // setup
    DateTime firstTuesdayInstallmentDate = new DateMidnight().toDateTime().withDate(2010, 4, 20);
    weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).withStartDate(firstTuesdayInstallmentDate).build();
    IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
    MeetingBuilder weeklyMeetingForFees = new MeetingBuilder().periodicFeeMeeting().weekly().every(1).withStartDate(firstTuesdayInstallmentDate);
    weeklyPeriodicFeeForCenterOnly = new FeeBuilder().appliesToCenterOnly().withFeeAmount("100.0").withName("Center Weekly Periodic Fee").with(weeklyMeetingForFees).with(sampleBranchOffice()).build();
    IntegrationTestObjectMother.saveFee(weeklyPeriodicFeeForCenterOnly);
    center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
    IntegrationTestObjectMother.createCenter(center, weeklyMeeting, weeklyPeriodicFeeForCenterOnly);
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    DateTime meetingStartDate = firstTuesdayInstallmentDate.minusDays(7);
    MeetingBO feeMeetingFrequency = new MeetingBuilder().periodicFeeMeeting().weekly().every(1).occuringOnA(WeekDay.MONDAY).startingFrom(meetingStartDate.toDate()).build();
    InstallmentDate installment1 = new InstallmentDate(Short.valueOf("1"), firstTuesdayInstallmentDate.toDate());
    InstallmentDate installment2 = new InstallmentDate(Short.valueOf("2"), firstTuesdayInstallmentDate.plusWeeks(1).toDate());
    InstallmentDate installment3 = new InstallmentDate(Short.valueOf("3"), firstTuesdayInstallmentDate.plusWeeks(2).toDate());
    InstallmentDate installment4 = new InstallmentDate(Short.valueOf("4"), firstTuesdayInstallmentDate.plusWeeks(3).toDate());
    List<InstallmentDate> installmentDates = Arrays.asList(installment1, installment2, installment3, installment4);
    // exercise test
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    List<Date> feeDates = customerAccount.getFeeDates(feeMeetingFrequency, installmentDates);
    // verification
    assertThat(feeDates.get(0), is(firstTuesdayInstallmentDate.toDate()));
    assertThat(feeDates.get(1), is(firstTuesdayInstallmentDate.plusWeeks(1).toDate()));
    assertThat(feeDates.get(2), is(firstTuesdayInstallmentDate.plusWeeks(2).toDate()));
    assertThat(feeDates.get(3), is(firstTuesdayInstallmentDate.plusWeeks(3).toDate()));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) FeeBuilder(org.mifos.domain.builders.FeeBuilder) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) Test(org.junit.Test)

Example 27 with CustomerAccountBO

use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.

the class AccountPaymentEntityIntegrationTest method testReversalAdjustment.

@Test
public void testReversalAdjustment() throws Exception {
    userContext = TestObjectFactory.getContext();
    createInitialObjects();
    accountBO = client.getCustomerAccount();
    Date currentDate = new Date(System.currentTimeMillis());
    CustomerAccountBO customerAccountBO = (CustomerAccountBO) accountBO;
    customerAccountBO.setUserContext(userContext);
    CustomerScheduleEntity accountAction = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
    CustomerAccountBOTestUtils.setMiscFeePaid(accountAction, TestUtils.createMoney(100));
    CustomerAccountBOTestUtils.setMiscPenaltyPaid(accountAction, TestUtils.createMoney(100));
    CustomerAccountBOTestUtils.setPaymentDate(accountAction, currentDate);
    accountAction.setPaymentStatus(PaymentStatus.PAID);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(customerAccountBO, TestUtils.createMoney(100), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    CustomerTrxnDetailEntity accountTrxnEntity = new CustomerTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.PAYMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(userContext.getId()), currentDate, TestUtils.createMoney(200), "payment done", null, TestUtils.createMoney(100), TestUtils.createMoney(100));
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
        accountFeesActionDetailEntity.setFeeAmountPaid(TestUtils.createMoney(100));
        FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
        CustomerBOTestUtils.addFeesTrxnDetail(accountTrxnEntity, feeTrxn);
    // TODO: is there anything to assert on here?
    // totalFees = accountFeesActionDetailEntity.getFeeAmountPaid();
    }
    accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
    customerAccountBO.addAccountPayment(accountPaymentEntity);
    TestObjectFactory.updateObject(customerAccountBO);
    StaticHibernateUtil.flushSession();
    customerAccountBO = TestObjectFactory.getObject(CustomerAccountBO.class, customerAccountBO.getAccountId());
    client = customerAccountBO.getCustomer();
    PersonnelBO loggedInUser = legacyPersonnelDao.getPersonnel(userContext.getId());
    List<AccountTrxnEntity> reversedTrxns = customerAccountBO.findMostRecentPaymentByPaymentDate().reversalAdjustment(loggedInUser, "adjustment");
    for (AccountTrxnEntity accntTrxn : reversedTrxns) {
        CustomerTrxnDetailEntity custTrxn = (CustomerTrxnDetailEntity) accntTrxn;
        CustomerScheduleEntity accntActionDate = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(custTrxn.getInstallmentId());
        Assert.assertEquals(custTrxn.getMiscFeeAmount(), accntActionDate.getMiscFeePaid().negate());
        Assert.assertEquals(custTrxn.getMiscPenaltyAmount(), accntActionDate.getMiscPenaltyPaid().negate());
        Assert.assertEquals(loggedInUser.getPersonnelId(), custTrxn.getPersonnel().getPersonnelId());
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CustomerTrxnDetailEntity(org.mifos.customers.business.CustomerTrxnDetailEntity) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Date(java.sql.Date) Test(org.junit.Test)

Example 28 with CustomerAccountBO

use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.

the class AccountServiceIntegrationTest method getCustomerAccountWithAllTypesOfFees.

private CustomerAccountBO getCustomerAccountWithAllTypesOfFees() {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    CustomerAccountBO customerAccountBO = center.getCustomerAccount();
    CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.CENTER, Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT, null);
    AccountFeesEntity accountUpfrontFee = new AccountFeesEntity(customerAccountBO, upfrontFee, new Double("20.0"), FeeStatus.ACTIVE.getValue(), null, customerScheduleEntity.getActionDate());
    AccountTestUtils.addAccountFees(accountUpfrontFee, customerAccountBO);
    AccountFeesActionDetailEntity accountUpfrontFeesaction = new CustomerFeeScheduleEntity(customerScheduleEntity, upfrontFee, accountUpfrontFee, new Money(getCurrency(), "20.0"));
    customerScheduleEntity.addAccountFeesAction(accountUpfrontFeesaction);
    TestObjectFactory.updateObject(center);
    customerAccountBO = center.getCustomerAccount();
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.ALLCUSTOMERS, "200", RecurrenceType.WEEKLY, Short.valueOf("1"));
    AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(customerAccountBO, periodicFee, new Double("200.0"), FeeStatus.INACTIVE.getValue(), null, null);
    AccountTestUtils.addAccountFees(accountPeriodicFee, customerAccountBO);
    TestObjectFactory.updateObject(center);
    return customerAccountBO;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) FeeBO(org.mifos.accounts.fees.business.FeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) CustomerFeeScheduleEntity(org.mifos.customers.business.CustomerFeeScheduleEntity)

Example 29 with CustomerAccountBO

use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.

the class CenterServiceFacadeWebTier method retrieveChargesDetails.

@Override
public CustomerChargesDetailsDto retrieveChargesDetails(Integer customerId) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    CustomerAccountBO customerAccount = customerBO.getCustomerAccount();
    try {
        personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    List<AccountFeesDto> accountFeesDtos = new ArrayList<AccountFeesDto>();
    if (!customerAccount.getAccountFees().isEmpty()) {
        for (AccountFeesEntity accountFeesEntity : customerAccount.getAccountFees()) {
            AccountFeesDto accountFeesDto = new AccountFeesDto(accountFeesEntity.getFees().getFeeFrequency().getFeeFrequencyType().getId(), (accountFeesEntity.getFees().getFeeFrequency().getFeePayment() != null ? accountFeesEntity.getFees().getFeeFrequency().getFeePayment().getId() : null), accountFeesEntity.getFeeStatus(), accountFeesEntity.getFees().getFeeName(), accountFeesEntity.getAccountFeeAmount().toString(), getMeetingRecurrence(accountFeesEntity.getFees().getFeeFrequency().getFeeMeetingFrequency(), userContext), accountFeesEntity.getFees().getFeeId());
            accountFeesDtos.add(accountFeesDto);
        }
    }
    CustomerScheduleDto customerSchedule = null;
    CustomerScheduleEntity scheduleEntity = (CustomerScheduleEntity) customerAccount.getUpcomingInstallment();
    if (scheduleEntity != null) {
        Set<AccountFeesActionDetailEntity> feeEntities = scheduleEntity.getAccountFeesActionDetails();
        List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
        for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
            feeDtos.add(convertToDto(feeEntity));
        }
        customerSchedule = new CustomerScheduleDto(scheduleEntity.getMiscFee().toString(), scheduleEntity.getMiscFeePaid().toString(), scheduleEntity.getMiscPenalty().toString(), scheduleEntity.getMiscPenaltyPaid().toString(), feeDtos);
    }
    return new CustomerChargesDetailsDto(customerAccount.getNextDueAmount().toString(), customerAccount.getTotalAmountInArrears().toString(), customerAccount.getTotalAmountDue().toString(), customerAccount.getUpcomingChargesDate(), customerSchedule, accountFeesDtos);
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountFeesDto(org.mifos.dto.screen.AccountFeesDto) AccountFeeScheduleDto(org.mifos.dto.domain.AccountFeeScheduleDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) CustomerChargesDetailsDto(org.mifos.dto.domain.CustomerChargesDetailsDto) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerScheduleDto(org.mifos.dto.domain.CustomerScheduleDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 30 with CustomerAccountBO

use of org.mifos.customers.business.CustomerAccountBO in project head by mifos.

the class CustomerPersistence method getCustomerAccountWithAccountActionsInitialized.

public CustomerAccountBO getCustomerAccountWithAccountActionsInitialized(final Integer accountId) throws PersistenceException {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("accountId", accountId);
    List obj = executeNamedQuery("accounts.retrieveCustomerAccountWithAccountActions", queryParameters);
    Object[] obj1 = (Object[]) obj.get(0);
    return (CustomerAccountBO) obj1[0];
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)36 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)15 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 DateTime (org.joda.time.DateTime)11 LocalDate (org.joda.time.LocalDate)11 AccountBO (org.mifos.accounts.business.AccountBO)10 CenterBuilder (org.mifos.domain.builders.CenterBuilder)10 MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)10 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)9 CenterBO (org.mifos.customers.center.business.CenterBO)8 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 GroupBO (org.mifos.customers.group.business.GroupBO)7 GroupBuilder (org.mifos.domain.builders.GroupBuilder)7 AccountException (org.mifos.accounts.exceptions.AccountException)6 LoanBO (org.mifos.accounts.loan.business.LoanBO)6 UserContext (org.mifos.security.util.UserContext)6 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)5