use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class GroupLoanAccountServiceFacadeWebTier method fixMemberAndParentInstallmentDetails.
// fix installment details in order to match sum of interest of member accounts to interest of parent account
// update member fee amounts in order to match parent fee amount
private void fixMemberAndParentInstallmentDetails(LoanBO loan, List<LoanBO> memberLoans) {
Map<Integer, LoanScheduleEntity> parentScheduleEntities = loan.getLoanScheduleEntityMap();
List<RepaymentScheduleInstallment> correctedInstallments = new ArrayList<RepaymentScheduleInstallment>();
for (Integer installmentId : parentScheduleEntities.keySet()) {
LoanScheduleEntity parentEntity = parentScheduleEntities.get(installmentId);
Map<Short, BigDecimal> feeAmountsForInstallment = new HashMap<Short, BigDecimal>();
for (AccountFeesActionDetailEntity feesActionDetailEntity : parentEntity.getAccountFeesActionDetails()) {
feeAmountsForInstallment.put(feesActionDetailEntity.getFee().getFeeId(), feesActionDetailEntity.getFeeAmount().getAmount());
}
RepaymentScheduleInstallment correctedInstallment = new RepaymentScheduleInstallment();
correctedInstallment.setInstallment(installmentId);
correctedInstallment.setDueDateValue(parentEntity.getActionDate());
BigDecimal principal = BigDecimal.ZERO;
BigDecimal interest = BigDecimal.ZERO;
for (LoanBO memberLoan : memberLoans) {
LoanScheduleEntity memberEntity = memberLoan.getLoanScheduleEntityMap().get(installmentId);
principal = principal.add(memberEntity.getPrincipal().getAmount());
interest = interest.add(memberEntity.getInterest().getAmount());
for (AccountFeesActionDetailEntity feesActionDetailEntity : memberEntity.getAccountFeesActionDetails()) {
if (feesActionDetailEntity.getFee().getFeeType().equals(RateAmountFlag.RATE)) {
continue;
}
BigDecimal currentAmount = feeAmountsForInstallment.get(feesActionDetailEntity.getFee().getFeeId());
currentAmount = currentAmount.subtract(feesActionDetailEntity.getFeeAmount().getAmount());
if (currentAmount.compareTo(BigDecimal.ZERO) == -1) {
BigDecimal toUpdate = feesActionDetailEntity.getFeeAmount().getAmount().add(currentAmount);
feesActionDetailEntity.updateFeeAmount(toUpdate);
currentAmount = BigDecimal.ZERO;
}
feeAmountsForInstallment.put(feesActionDetailEntity.getFee().getFeeId(), currentAmount);
}
}
correctedInstallment.setPrincipal(new Money(parentEntity.getPrincipal().getCurrency(), principal));
correctedInstallment.setInterest(new Money(parentEntity.getInterest().getCurrency(), interest));
correctedInstallments.add(correctedInstallment);
}
loan.updateInstallmentSchedule(correctedInstallments);
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity 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.AccountFeesActionDetailEntity in project head by mifos.
the class CustomerScheduleEntity method waiveCharges.
Money waiveCharges() {
Money chargeWaived = new Money(getAccount().getCurrency());
chargeWaived = chargeWaived.add((getMiscFee().subtract(getMiscFeePaid())).add(getMiscPenalty().subtract(getMiscPenaltyPaid())));
setMiscFee(getMiscFeePaid());
setMiscPenalty(getMiscPenaltyPaid());
for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : getAccountFeesActionDetails()) {
chargeWaived = chargeWaived.add(((CustomerFeeScheduleEntity) accountFeesActionDetailEntity).waiveCharges());
}
return chargeWaived;
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class CustomerScheduleEntity method waiveFeeCharges.
Money waiveFeeCharges() {
Money chargeWaived = new Money(getAccount().getCurrency());
chargeWaived = chargeWaived.add(getMiscFee());
setMiscFee(new Money(getAccount().getCurrency()));
for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : getAccountFeesActionDetails()) {
chargeWaived = chargeWaived.add(((CustomerFeeScheduleEntity) accountFeesActionDetailEntity).waiveCharges());
}
return chargeWaived;
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class FinancialBusinessServiceIntegrationTest method getAccountTrxnObj.
private AccountTrxnEntity getAccountTrxnObj(AccountPaymentEntity accountPaymentEntity) throws Exception {
Date currentDate = new Date(System.currentTimeMillis());
LoanScheduleEntity accountAction = (LoanScheduleEntity) loan.getAccountActionDate(Short.valueOf("1"));
LoanTrxnDetailEntity accountTrxnEntity = new LoanTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.LOAN_ADJUSTMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(PersonnelConstants.SYSTEM_USER), currentDate, TestUtils.createMoney(630), "test for loan adjustment", null, TestUtils.createMoney(200), TestUtils.createMoney(300), TestUtils.createMoney(), TestUtils.createMoney(10), TestUtils.createMoney(20), null, null);
for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
LoanBOTestUtils.setFeeAmountPaid(accountFeesActionDetailEntity, TestUtils.createMoney(100));
FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
accountTrxnEntity.addFeesTrxnDetail(feeTrxn);
}
return accountTrxnEntity;
}
Aggregations