use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.
the class LoanTrxnDetailEntityIntegrationTest method testSuccessSetRunningBalance.
@Test
public void testSuccessSetRunningBalance() throws Exception {
MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
center = TestObjectFactory.createWeeklyFeeCenter("Center_Active", meeting);
group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
Date sampleDate = new Date(System.currentTimeMillis());
LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(sampleDate, meeting);
account = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, sampleDate, loanOffering);
StaticHibernateUtil.flushSession();
account = legacyAccountDao.getAccount(account.getAccountId());
Assert.assertEquals(((LoanBO) account).getLoanOffering().getPrdOfferingName(), "Loan");
List<AccountActionDateEntity> accountActionsToBeUpdated = new ArrayList<AccountActionDateEntity>();
accountActionsToBeUpdated.add(account.getAccountActionDates().iterator().next());
PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accountActionsToBeUpdated, TestUtils.createMoney("700.0"), null, account.getPersonnel(), "423423", Short.valueOf("1"), sampleDate, sampleDate);
IntegrationTestObjectMother.applyAccountPayment(account, paymentData);
Assert.assertEquals(1, account.getAccountPayments().size());
// AccountPaymentEntity payment = account.getAccountPayments().iterator().next();
// Assert.assertEquals(4, payment.getAccountTrxns().size());
// Should we assert something about each of those transactions?
LoanSummaryEntity loanSummaryEntity = ((LoanBO) account).getLoanSummary();
Assert.assertEquals(loanSummaryEntity.getOriginalPrincipal().subtract(loanSummaryEntity.getPrincipalPaid()), ((LoanBO) account).getLoanActivityDetails().iterator().next().getPrincipalOutstanding());
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.
the class AdminServiceFacadeWebTier method updateLoanProduct.
@Override
public PrdOfferingDto updateLoanProduct(LoanProductRequest loanProductRequest) {
LoanOfferingBO loanProductForUpdate = this.loanProductDao.findById(loanProductRequest.getProductDetails().getId());
// enforced by integrity constraints on table also.
if (loanProductForUpdate.isDifferentName(loanProductRequest.getProductDetails().getName())) {
this.savingsProductDao.validateProductWithSameNameDoesNotExist(loanProductRequest.getProductDetails().getName());
}
if (loanProductForUpdate.isDifferentShortName(loanProductRequest.getProductDetails().getShortName())) {
this.savingsProductDao.validateProductWithSameShortNameDoesNotExist(loanProductRequest.getProductDetails().getShortName());
}
// domain rule validation - put on domain entity
if (loanProductForUpdate.isDifferentStartDate(loanProductRequest.getProductDetails().getStartDate())) {
validateStartDateIsNotBeforeToday(loanProductRequest.getProductDetails().getStartDate());
validateStartDateIsNotOverOneYearFromToday(loanProductRequest.getProductDetails().getStartDate());
validateEndDateIsPastStartDate(loanProductRequest.getProductDetails().getStartDate(), loanProductRequest.getProductDetails().getEndDate());
}
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
LoanOfferingBO newLoanProductDetails = this.loanProductAssembler.fromDto(user, loanProductRequest);
loanProductForUpdate.updateDetails(userContext);
HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
try {
transactionHelper.startTransaction();
transactionHelper.beginAuditLoggingFor(loanProductForUpdate);
loanProductForUpdate.updateDetailsOfProductNotInUse(newLoanProductDetails.getPrdOfferingName(), newLoanProductDetails.getPrdOfferingShortName(), newLoanProductDetails.getDescription(), newLoanProductDetails.getPrdCategory(), newLoanProductDetails.getStartDate(), newLoanProductDetails.getEndDate(), newLoanProductDetails.getPrdApplicableMaster(), newLoanProductDetails.getPrdStatus());
loanProductForUpdate.update(newLoanProductDetails.isIncludeInLoanCounter(), newLoanProductDetails.isInterestWaived());
if (newLoanProductDetails.isLoanAmountTypeSameForAllLoan()) {
loanProductForUpdate.updateLoanAmountDetails(newLoanProductDetails.getEligibleLoanAmountSameForAllLoan());
} else if (newLoanProductDetails.isLoanAmountTypeAsOfLastLoanAmount()) {
loanProductForUpdate.updateLoanAmountByLastLoanDetails(newLoanProductDetails.getLoanAmountFromLastLoan());
} else if (newLoanProductDetails.isLoanAmountTypeFromLoanCycle()) {
loanProductForUpdate.updateLoanAmountLoanCycleDetails(newLoanProductDetails.getLoanAmountFromLoanCycle());
}
loanProductForUpdate.updateInterestRateDetails(newLoanProductDetails.getMinInterestRate(), newLoanProductDetails.getMaxInterestRate(), newLoanProductDetails.getDefInterestRate());
PrdOfferingMeetingEntity entity = newLoanProductDetails.getLoanOfferingMeeting();
MeetingBO meeting = new MeetingBO(entity.getMeeting().getRecurrenceType(), entity.getMeeting().getRecurAfter(), entity.getMeeting().getStartDate(), MeetingType.LOAN_INSTALLMENT);
loanProductForUpdate.updateRepaymentDetails(meeting, newLoanProductDetails.getGracePeriodType(), newLoanProductDetails.getGracePeriodDuration());
if (newLoanProductDetails.isNoOfInstallTypeSameForAllLoan()) {
loanProductForUpdate.updateInstallmentDetails(newLoanProductDetails.getNoOfInstallSameForAllLoan());
} else if (newLoanProductDetails.isNoOfInstallTypeFromLastLoan()) {
loanProductForUpdate.updateInstallmentByLastLoanDetails(newLoanProductDetails.getNoOfInstallFromLastLoan());
} else if (newLoanProductDetails.isNoOfInstallTypeFromLoanCycle()) {
loanProductForUpdate.updateInstallmentLoanCycleDetails(newLoanProductDetails.getNoOfInstallFromLoanCycle());
}
loanProductForUpdate.updateFees(newLoanProductDetails.getLoanOfferingFees());
loanProductForUpdate.updateFunds(newLoanProductDetails.getLoanOfferingFunds());
loanProductForUpdate.updatePenalties(newLoanProductDetails.getLoanOfferingPenalties());
this.loanProductDao.save(loanProductForUpdate);
transactionHelper.commitTransaction();
return loanProductForUpdate.toDto();
} catch (Exception e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.
the class XlsLoansAccountImporter method validateProductName.
private LoanOfferingBO validateProductName(String productName, CustomerBO customerBO, HSSFRow row, int currentCell) throws XlsParsingException {
// check if blank
if (StringUtils.isBlank(productName)) {
throw new XlsParsingException(getCellError(XlsMessageConstants.MISSING_PRODUCT_NAME, row, currentCell, null));
}
// check if product is definied
List<LoanOfferingBO> products = loanProductDao.findActiveLoanProductsApplicableToCustomerLevel(customerBO.getCustomerLevel());
LoanOfferingBO foundProduct = null;
for (LoanOfferingBO loanOfferingBO : products) {
if (loanOfferingBO.getPrdOfferingName().equals(productName) && loanOfferingBO.isActive()) {
foundProduct = loanOfferingBO;
break;
}
}
if (foundProduct == null) {
List<Object> params = new ArrayList<Object>();
params.add(productName);
throw new XlsParsingException(getCellError(XlsMessageConstants.PRODUCT_NOT_FOUND, row, currentCell, params));
}
// check if installments date is synchronized with meetings
boolean meetingOk = (foundProduct.getLoanOfferingMeeting().getMeeting().hasSameRecurrenceAs(customerBO.getCustomerMeetingValue()) || configurationPersistence.isRepaymentIndepOfMeetingEnabled());
if (!meetingOk) {
throw new XlsParsingException(getCellError(XlsMessageConstants.DIFFERENT_MEETING_FREQUENCY, row, currentCell, null));
}
return foundProduct;
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.
the class QGFlowsServiceImpl method applyToAllLoanProducts.
@Override
public void applyToAllLoanProducts(Integer questionGroupId) throws SystemException {
LoanPrdBusinessService loanPrdBusinessService = new LoanPrdBusinessService();
try {
List<LoanOfferingBO> offerings = loanPrdBusinessService.getAllLoanOfferings((short) 1);
if (offerings.size() > 0) {
QuestionGroupReference questionGroupReference = new QuestionGroupReference();
questionGroupReference.setQuestionGroupId(questionGroupId);
for (LoanOfferingBO offering : offerings) {
offering.getQuestionGroups().add(questionGroupReference);
offering.save();
}
StaticHibernateUtil.commitTransaction();
}
} catch (ServiceException e) {
throw new SystemException(e);
} catch (ProductDefinitionException e) {
throw new SystemException(e);
}
}
use of org.mifos.accounts.productdefinition.business.LoanOfferingBO in project head by mifos.
the class LoanDisbursementActionStrutsTest method getLoanAccount.
private LoanBO getLoanAccount(AccountState state, Date startDate, int disbursalType) {
MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
return TestObjectFactory.createLoanAccountWithDisbursement("99999999999", group, state, startDate, loanOffering, disbursalType);
}
Aggregations