use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.
the class FeeServiceImpl method createOneTimeFee.
private FeeBO createOneTimeFee(FeeCreateRequest feeCreateRequest, FeeFrequencyTypeEntity feeFrequencyType, CategoryTypeEntity feeCategoryType, GLCodeEntity glCodeEntity, UserContext userContext) throws FeeException {
FeePaymentEntity feePaymentEntity = this.feeDao.findFeePaymentEntityByType(feeCreateRequest.getFeePaymentType());
FeeBO feeBO = null;
if (feeCreateRequest.isRateFee()) {
FeeFormulaEntity feeFormulaEntity = this.feeDao.findFeeFormulaEntityByType(feeCreateRequest.getFeeFormula());
feeBO = new RateFeeBO(userContext, feeCreateRequest.getFeeName(), feeCategoryType, feeFrequencyType, glCodeEntity, feeCreateRequest.getRate(), feeFormulaEntity, feeCreateRequest.isCustomerDefaultFee(), feePaymentEntity);
} else {
Money feeMoney = new Money(getCurrency(feeCreateRequest.getCurrencyId()), feeCreateRequest.getAmount());
feeBO = new AmountFeeBO(userContext, feeCreateRequest.getFeeName(), feeCategoryType, feeFrequencyType, glCodeEntity, feeMoney, feeCreateRequest.isCustomerDefaultFee(), feePaymentEntity);
}
return feeBO;
}
use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.
the class FeeServiceImpl method createPeriodicFee.
private FeeBO createPeriodicFee(FeeCreateRequest feeCreateRequest, FeeFrequencyTypeEntity feeFrequencyType, CategoryTypeEntity feeCategoryType, GLCodeEntity glCodeEntity, UserContext userContext) throws FeeException, MeetingException {
MeetingBO feeMeeting = feeCreateRequest.getFeeRecurrenceType().equals(RecurrenceType.MONTHLY) ? new MeetingBO(feeCreateRequest.getFeeRecurrenceType(), feeCreateRequest.getMonthRecurAfter(), new DateTimeService().getCurrentJavaDateTime(), MeetingType.PERIODIC_FEE) : new MeetingBO(feeCreateRequest.getFeeRecurrenceType(), feeCreateRequest.getWeekRecurAfter(), new DateTimeService().getCurrentJavaDateTime(), MeetingType.PERIODIC_FEE);
FeeBO feeBO = null;
if (feeCreateRequest.isRateFee()) {
FeeFormulaEntity feeFormulaEntity = this.feeDao.findFeeFormulaEntityByType(feeCreateRequest.getFeeFormula());
feeBO = new RateFeeBO(userContext, feeCreateRequest.getFeeName(), feeCategoryType, feeFrequencyType, glCodeEntity, feeCreateRequest.getRate(), feeFormulaEntity, feeCreateRequest.isCustomerDefaultFee(), feeMeeting);
} else {
Money feeMoney = new Money(getCurrency(feeCreateRequest.getCurrencyId()), feeCreateRequest.getAmount());
feeBO = new AmountFeeBO(userContext, feeCreateRequest.getFeeName(), feeCategoryType, feeFrequencyType, glCodeEntity, feeMoney, feeCreateRequest.isCustomerDefaultFee(), feeMeeting);
}
return feeBO;
}
use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.
the class FeeServiceImpl method update.
@Override
public void update(FeeUpdateRequest feeUpdateRequest, UserContext userContext) throws ApplicationException {
FeeBO feeBo = this.feeDao.findById(feeUpdateRequest.getFeeId());
feeBo.updateDetails(userContext);
FeeChangeType feeChangeType;
FeeStatus feeStatus = null;
if (feeUpdateRequest.getFeeStatusValue() != null) {
feeStatus = FeeStatus.getFeeStatus(feeUpdateRequest.getFeeStatusValue());
}
FeeStatusEntity feeStatusEntity = new FeeStatusEntity(feeStatus);
if (feeBo.getFeeType().equals(RateAmountFlag.AMOUNT)) {
AmountFeeBO amountFee = ((AmountFeeBO) feeBo);
feeChangeType = amountFee.calculateNewFeeChangeType(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()), feeStatusEntity);
amountFee.setFeeAmount(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()));
} else {
RateFeeBO rateFee = ((RateFeeBO) feeBo);
feeChangeType = rateFee.calculateNewFeeChangeType(feeUpdateRequest.getRateValue(), feeStatusEntity);
rateFee.setRate(feeUpdateRequest.getRateValue());
}
try {
hibernateTransactionHelper.startTransaction();
feeBo.updateStatus(feeStatus);
feeBo.updateFeeChangeType(feeChangeType);
this.feeDao.save(feeBo);
hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.accounts.fees.business.AmountFeeBO in project head by mifos.
the class AccountBusinessService method populaleApplicableCharge.
private void populaleApplicableCharge(List<ApplicableCharge> applicableChargeList, List<FeeBO> feeList, UserContext userContext) {
for (FeeBO fee : feeList) {
ApplicableCharge applicableCharge = new ApplicableCharge();
applicableCharge.setFeeId(fee.getFeeId().toString());
applicableCharge.setFeeName(fee.getFeeName());
applicableCharge.setIsPenaltyType(false);
if (fee.getFeeType().getValue().equals(RateAmountFlag.RATE.getValue())) {
applicableCharge.setAmountOrRate(new LocalizationConverter().getDoubleStringForInterest(((RateFeeBO) fee).getRate()));
applicableCharge.setFormula(((RateFeeBO) fee).getFeeFormula().getFormulaStringThatHasName());
applicableCharge.setIsRateType(true);
} else {
applicableCharge.setAmountOrRate(((AmountFeeBO) fee).getFeeAmount().toString());
applicableCharge.setIsRateType(false);
}
MeetingBO meeting = fee.getFeeFrequency().getFeeMeetingFrequency();
if (meeting != null) {
applicableCharge.setPeriodicity(new MeetingHelper().getDetailMessageWithFrequency(meeting, userContext));
} else {
applicableCharge.setPaymentType(fee.getFeeFrequency().getFeePayment().getName());
}
applicableChargeList.add(applicableCharge);
}
}
use of org.mifos.accounts.fees.business.AmountFeeBO 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;
}
Aggregations