use of org.mifos.accounts.business.AccountFeesEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method createLoanSchedule.
@Override
public LoanScheduleDto createLoanSchedule(CreateLoanSchedule createLoanSchedule, List<DateTime> loanScheduleDates, List<Number> totalInstallmentAmounts) {
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 = customer.getCustomerMeetingValue();
if (loanScheduleIndependentOfCustomerMeetingEnabled) {
loanMeeting = this.createNewMeetingForRepaymentDay(createLoanSchedule.getDisbursementDate(), createLoanSchedule, customer);
if (loanProduct.isVariableInstallmentsAllowed()) {
loanMeeting.setMeetingStartDate(createLoanSchedule.getDisbursementDate().toDateMidnight().toDate());
}
}
LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
LoanSchedule loanSchedule = this.loanScheduleService.generate(loanProduct, customer, loanMeeting, overridenDetail, configuration, accountFeeEntities, createLoanSchedule.getDisbursementDate(), loanScheduleDates, totalInstallmentAmounts);
// 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.business.AccountFeesEntity in project head by mifos.
the class LoanBOTestUtils method createLoanAccount.
/**
* Like
* <b>createLoanAccountWithDisbursement(String, CustomerBO, AccountState, Date, LoanOfferingBO, int, Short)</b>
* but differs in various ways.
* <p/>
* This test code needs to be refactored! By creating the loan with a
* set of terms, then directly manipulating instance variables to completely
* change the repayment schedule, it leaves the loan in an inconsistent
* state, which leads one to suspect the validity of any of the 67 unit
* tests that use it.
*
* It has been verified that setActionDate method calls in the loop below
* will set the dates of the installments incorrectly for some if not all
* cases. For certain classes of tests this doesn't matter, but for others
* (involving verifying dates) it does. So BEWARE if you call down through
* this method.
*
* @param globalNum
*/
public static LoanBO createLoanAccount(final String globalNum, final CustomerBO customer, final AccountState state, final Date startDate, final LoanOfferingBO loanOffering) {
Calendar calendar = new GregorianCalendar();
calendar.setTime(startDate);
MeetingBO meeting = TestObjectFactory.createLoanMeeting(customer.getCustomerMeeting().getMeeting());
List<Date> meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), meeting, 6);
MifosCurrency currency = loanOffering.getCurrency();
AmountFeeBO maintanenceFee = (AmountFeeBO) TestObjectFactory.createPeriodicAmountFee("Mainatnence Fee", FeeCategory.LOAN, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
IntegrationTestObjectMother.saveFee(maintanenceFee);
BigDecimal loanAmount = BigDecimal.valueOf(DEFAULT_LOAN_AMOUNT);
BigDecimal minAllowedLoanAmount = loanAmount;
BigDecimal maxAllowedLoanAmount = loanAmount;
Double interestRate = loanOffering.getDefInterestRate();
LocalDate disbursementDate = new LocalDate(meetingDates.get(0));
int numberOfInstallments = 6;
int minAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
int maxAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
int graceDuration = 0;
Integer sourceOfFundId = null;
Integer loanPurposeId = null;
Integer collateralTypeId = null;
String collateralNotes = null;
String externalId = null;
boolean repaymentScheduleIndependentOfCustomerMeeting = false;
RecurringSchedule recurringSchedule = null;
List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
accountFees.add(new CreateAccountFeeDto(maintanenceFee.getFeeId().intValue(), maintanenceFee.getFeeAmount().toString()));
CreateLoanAccount createLoanAccount = new CreateLoanAccount(customer.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), state.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
SecurityContext securityContext = new SecurityContextImpl();
MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
Authentication authentication = new TestingAuthenticationToken(principal, principal);
securityContext.setAuthentication(authentication);
SecurityContextHolder.setContext(securityContext);
LoanBO loan = IntegrationTestObjectMother.createClientLoan(createLoanAccount);
loan.updateDetails(TestUtils.makeUser());
AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(loan, maintanenceFee, (maintanenceFee).getFeeAmount().getAmountDoubleValue());
AccountTestUtils.addAccountFees(accountPeriodicFee, loan);
loan.setLoanMeeting(meeting);
short i = 0;
for (Date date : meetingDates) {
LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(++i);
actionDate.setPrincipal(new Money(currency, "100.0"));
actionDate.setInterest(new Money(currency, "12.0"));
// the following line overwrites the correct loan schedule dates
// with dates that are not correct!
actionDate.setActionDate(new java.sql.Date(date.getTime()));
actionDate.setPaymentStatus(PaymentStatus.UNPAID);
AccountTestUtils.addAccountActionDate(actionDate, loan);
AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
actionDate.addAccountFeesAction(accountFeesaction);
}
loan.setCreatedBy(Short.valueOf("1"));
loan.setCreatedDate(new Date(System.currentTimeMillis()));
setLoanSummary(loan, currency);
return loan;
}
use of org.mifos.accounts.business.AccountFeesEntity in project head by mifos.
the class LoanScheduleEntityIntegrationTest method testSuccessRemoveFees.
@Test
public void testSuccessRemoveFees() {
Short feeId = null;
Set<AccountFeesEntity> accountFeesSet = groupLoan.getAccountFees();
for (AccountFeesEntity accountFeesEntity : accountFeesSet) {
feeId = accountFeesEntity.getFees().getFeeId();
break;
}
Set<AccountActionDateEntity> accountActionDateEntitySet = groupLoan.getAccountActionDates();
Iterator<AccountActionDateEntity> itr = accountActionDateEntitySet.iterator();
while (itr.hasNext()) {
LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) itr.next();
accountActionDateEntity.removeFees(feeId);
Assert.assertTrue(true);
}
}
use of org.mifos.accounts.business.AccountFeesEntity in project head by mifos.
the class CenterBO method validateMeetingAndFees.
public void validateMeetingAndFees(List<AccountFeesEntity> accountFees) throws CustomerException {
if (this.getCustomerMeeting() == null || this.getCustomerMeetingValue() == null) {
if (accountFees.size() > 0) {
throw new CustomerException(CustomerConstants.MEETING_REQUIRED_EXCEPTION);
}
throw new CustomerException(CustomerConstants.ERRORS_SPECIFY_MEETING);
}
for (AccountFeesEntity accountFee : accountFees) {
if (accountFee.getFees().isPeriodic()) {
MeetingBO feeMeeting = accountFee.getFees().getFeeFrequency().getFeeMeetingFrequency();
if (!feeMeeting.hasSameRecurrenceAs(this.getCustomerMeetingValue())) {
throw new CustomerException(CustomerConstants.ERRORS_FEE_FREQUENCY_MISMATCH);
}
FeeBO fee = accountFee.getFees();
if (AccountFeesEntity.isPeriodicFeeDuplicated(accountFees, fee)) {
throw new CustomerException(CustomerConstants.ERRORS_DUPLICATE_PERIODIC_FEE);
}
}
}
}
use of org.mifos.accounts.business.AccountFeesEntity 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;
}
Aggregations