use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.
the class TestObjectFactory method createLoanOffering.
public static LoanOfferingBO createLoanOffering(final String name, final String shortName, final ApplicableTo applicableTo, final Date startDate, final PrdStatus offeringStatus, final Double defLnAmnt, final Double defIntRate, final Short defInstallments, final InterestType interestType, final boolean interestDeductedAtDisbursement, final boolean principalDueInLastInstallment, final MeetingBO meeting, final GraceType graceType, final short gracePeriodDuration, final String loanAmountCalcType, final String noOfInstallCalcType, final MifosCurrency currency, VariableInstallmentDetailsBO variableInstallmentDetails) {
PrdApplicableMasterEntity prdApplicableMaster = new PrdApplicableMasterEntity(applicableTo);
ProductCategoryBO productCategory = TestObjectFactory.getLoanPrdCategory();
GracePeriodTypeEntity gracePeriodType = new GracePeriodTypeEntity(graceType);
InterestTypesEntity interestTypes = new InterestTypesEntity(interestType);
GLCodeEntity glCodePrincipal = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, TestGeneralLedgerCode.LOANS_TO_CLIENTS);
GLCodeEntity glCodeInterest = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, TestGeneralLedgerCode.INTEREST_ON_LOANS);
LoanOfferingBO loanOffering;
boolean loanCounter = true;
boolean waiverInterest = true;
try {
loanOffering = new LoanOfferingBO(getContext(), name, shortName, productCategory, prdApplicableMaster, startDate, null, null, gracePeriodType, gracePeriodDuration, interestTypes, new Money(currency, defLnAmnt.toString()), new Money(currency, defLnAmnt.toString()), new Money(currency, defLnAmnt.toString()), defIntRate, defIntRate, defIntRate, defInstallments, defInstallments, defInstallments, loanCounter, interestDeductedAtDisbursement, principalDueInLastInstallment, new ArrayList<FundBO>(), new ArrayList<FeeBO>(), new ArrayList<PenaltyBO>(), meeting, glCodePrincipal, glCodeInterest, loanAmountCalcType, noOfInstallCalcType, waiverInterest);
} catch (ProductDefinitionException e) {
throw new RuntimeException(e);
}
loanOffering.setCurrency(currency);
PrdStatusEntity prdStatus = testObjectPersistence.retrievePrdStatus(offeringStatus);
LoanOfferingTestUtils.setStatus(loanOffering, prdStatus);
LoanOfferingTestUtils.setGracePeriodType(loanOffering, gracePeriodType, gracePeriodDuration);
if (variableInstallmentDetails != null) {
loanOffering.setVariableInstallmentsAllowed(true);
loanOffering.setVariableInstallmentDetails(variableInstallmentDetails);
}
IntegrationTestObjectMother.saveLoanProducts(loanOffering);
return IntegrationTestObjectMother.findLoanProductBySystemId(loanOffering.getGlobalPrdOfferingNum());
}
use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.
the class TestObjectFactory method createLoanOffering.
/**
* @param defLnAmnt - Loan Amount same would be set as min and max amounts
* @param defIntRate - Interest Rate same would be set as min and max amounts
* @param defInstallments Number of installments set as min and max amounts
*/
public static LoanOfferingBO createLoanOffering(final String name, final String shortName, final ApplicableTo applicableTo, final Date startDate, final PrdStatus offeringStatus, final Double defLnAmnt, final Double defIntRate, final Short defInstallments, final InterestType interestType, final boolean interestDeductedAtDisbursement, final boolean principalDueInLastInstallment, final MeetingBO meeting, final GraceType graceType) {
PrdApplicableMasterEntity prdApplicableMaster = new PrdApplicableMasterEntity(applicableTo);
ProductCategoryBO productCategory = TestObjectFactory.getLoanPrdCategory();
GracePeriodTypeEntity gracePeriodType = new GracePeriodTypeEntity(graceType);
InterestTypesEntity interestTypes = new InterestTypesEntity(interestType);
GLCodeEntity glCodePrincipal = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, Short.valueOf("11"));
GLCodeEntity glCodeInterest = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, Short.valueOf("21"));
LoanOfferingBO loanOffering;
short gracePeriodDuration = (short) 0;
boolean loanCounter = true;
boolean waiverInterest = true;
try {
loanOffering = new LoanOfferingBO(getContext(), name, shortName, productCategory, prdApplicableMaster, startDate, null, null, gracePeriodType, gracePeriodDuration, interestTypes, TestUtils.createMoney(defLnAmnt), TestUtils.createMoney(defLnAmnt), TestUtils.createMoney(defLnAmnt), defIntRate, defIntRate, defIntRate, defInstallments, defInstallments, defInstallments, loanCounter, interestDeductedAtDisbursement, principalDueInLastInstallment, new ArrayList<FundBO>(), new ArrayList<FeeBO>(), new ArrayList<PenaltyBO>(), meeting, glCodePrincipal, glCodeInterest, waiverInterest);
} catch (ProductDefinitionException e) {
throw new RuntimeException(e);
}
PrdStatusEntity prdStatus = testObjectPersistence.retrievePrdStatus(offeringStatus);
LoanOfferingTestUtils.setStatus(loanOffering, prdStatus);
LoanOfferingTestUtils.setGracePeriodType(loanOffering, gracePeriodType, gracePeriodDuration);
return (LoanOfferingBO) testObjectPersistence.persist(loanOffering);
}
use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.
the class AdminServiceFacadeWebTier method retrieveSavingsProductFormReferenceData.
@Override
public SavingsProductFormDto retrieveSavingsProductFormReferenceData() {
try {
SavingsPrdBusinessService service = new SavingsPrdBusinessService();
List<ListElement> statusOptions = new ArrayList<ListElement>();
List<PrdStatusEntity> applicableStatuses = service.getApplicablePrdStatus(Short.valueOf("1"));
for (PrdStatusEntity entity : applicableStatuses) {
statusOptions.add(new ListElement(entity.getOfferingStatusId().intValue(), entity.getPrdState().getName()));
}
List<ListElement> penaltiesOptions = new ArrayList<ListElement>();
List<PenaltyBO> applicablePenalties = this.penaltyDao.findAllSavingPenalties();
for (PenaltyBO entity : applicablePenalties) {
penaltiesOptions.add(new ListElement(entity.getPenaltyId().intValue(), entity.getPenaltyName()));
}
List<ListElement> productCategoryOptions = new ArrayList<ListElement>();
List<ProductCategoryBO> productCategories = service.getActiveSavingsProductCategories();
for (ProductCategoryBO category : productCategories) {
productCategoryOptions.add(new ListElement(category.getProductCategoryID().intValue(), category.getProductCategoryName()));
}
List<ListElement> applicableForOptions = new ArrayList<ListElement>();
List<PrdApplicableMasterEntity> applicableCustomerTypes = this.loanProductDao.retrieveSavingsApplicableProductCategories();
for (PrdApplicableMasterEntity entity : applicableCustomerTypes) {
applicableForOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
}
List<ListElement> savingsTypeOptions = new ArrayList<ListElement>();
List<SavingsTypeEntity> savingsTypes = this.loanProductDao.retrieveSavingsTypes();
for (SavingsTypeEntity entity : savingsTypes) {
savingsTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
}
List<ListElement> recommendedAmountTypeOptions = new ArrayList<ListElement>();
List<RecommendedAmntUnitEntity> recommendedAmountTypes = this.loanProductDao.retrieveRecommendedAmountTypes();
for (RecommendedAmntUnitEntity entity : recommendedAmountTypes) {
recommendedAmountTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
}
List<ListElement> interestCalcTypeOptions = new ArrayList<ListElement>();
List<InterestCalcTypeEntity> interestCalcTypes = this.savingsProductDao.retrieveInterestCalculationTypes();
for (InterestCalcTypeEntity entity : interestCalcTypes) {
interestCalcTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
}
List<ListElement> timePeriodOptions = new ArrayList<ListElement>();
List<RecurrenceTypeEntity> applicableRecurrences = savingsProductDao.getSavingsApplicableRecurrenceTypes();
for (RecurrenceTypeEntity entity : applicableRecurrences) {
timePeriodOptions.add(new ListElement(entity.getRecurrenceId().intValue(), entity.getRecurrenceName()));
}
List<GLCodeEntity> depositGlCodeList = new ArrayList<GLCodeEntity>();
depositGlCodeList.addAll(new FinancialBusinessService().getGLCodes(FinancialActionConstants.MANDATORYDEPOSIT, FinancialConstants.CREDIT));
depositGlCodeList.addAll(new FinancialBusinessService().getGLCodes(FinancialActionConstants.VOLUNTARYDEPOSIT, FinancialConstants.CREDIT));
List<ListElement> depositGlCodeOptions = new ArrayList<ListElement>();
for (GLCodeEntity glCode : depositGlCodeList) {
depositGlCodeOptions.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode(), glCode.getAssociatedCOA().getAccountName()));
}
List<GLCodeEntity> interestGlCodeList = new FinancialBusinessService().getGLCodes(FinancialActionConstants.SAVINGS_INTERESTPOSTING, FinancialConstants.DEBIT);
List<ListElement> interestGlCodes = new ArrayList<ListElement>();
for (GLCodeEntity glCode : interestGlCodeList) {
interestGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode(), glCode.getAssociatedCOA().getAccountName()));
}
return new SavingsProductFormDto(productCategoryOptions, applicableForOptions, savingsTypeOptions, recommendedAmountTypeOptions, interestCalcTypeOptions, timePeriodOptions, depositGlCodeOptions, interestGlCodes, statusOptions);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
} catch (SystemException e) {
throw new MifosRuntimeException(e);
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.
the class InterceptHelper method readFurtherMeta.
private void readFurtherMeta(Object obj, String firstName, String state) {
Class clazz = getClazz(obj);
ClassMetadata customMeta = StaticHibernateUtil.getSessionFactory().getClassMetadata(clazz);
Object[] propertyValues = customMeta.getPropertyValues(obj, EntityMode.POJO);
String[] propertyNames = customMeta.getPropertyNames();
Type[] propertyTypes = customMeta.getPropertyTypes();
String prdStatusName = AuditConstants.PRDSTATUSPATH;
if (obj.getClass().getName().startsWith(prdStatusName)) {
Short id = ((PrdStatusEntity) obj).getOfferingStatusId();
setPrimaryKeyValues(id, firstName.concat(customMeta.getIdentifierPropertyName()), state);
} else {
setPrimaryKeyValues(customMeta, obj, firstName.concat(customMeta.getIdentifierPropertyName()), state);
}
for (int i = 0; i < propertyNames.length; i++) {
logger.debug("readFurtherMeta property : " + propertyNames[i]);
setColumnValues(propertyTypes[i], propertyNames[i], firstName, state, propertyValues[i]);
// Reading masterdata Types
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && propertyValues[i] instanceof MasterDataEntity && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
populateValueForObjectsOfTypeMasterDataEntity(propertyValues[i], state, firstName.concat(propertyNames[i]));
}
// Reading Collection Types
if (propertyTypes[i].isCollectionType() && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName) && !AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], firstName)) {
Iterator iterator = ((Set) propertyValues[i]).iterator();
while (iterator.hasNext()) {
Object valueFromSet = iterator.next();
readFurtherMetaForCollectionType(valueFromSet, propertyNames[i], state);
}
}
// Reading Collection Types
if (propertyTypes[i].isCollectionType() && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName) && AuditConfiguration.isObjectPropertiesToBeMerged(entityName, propertyNames[i], firstName)) {
populateAndMergeCollectionTypes(state, propertyValues[i], propertyNames[i], firstName);
}
// Reading further entity type
if (propertyTypes[i].isEntityType() && !propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
if (obj1 instanceof MeetingBO) {
MeetingBO meeting = (MeetingBO) obj1;
if (propertyNames[i].equalsIgnoreCase("meeting") && meeting.getMeetingId() != null) {
readMeetingEntity(meeting, propertyNames[i], state);
} else {
readFurtherMeta(obj1, propertyNames[i], state);
}
} else {
readFurtherMeta(obj1, propertyNames[i], state);
}
}
}
// Reading further component type
if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && AuditConfiguration.isObjectToBeLogged(entityName, propertyNames[i], firstName)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
readFurtherComponenetMeta(obj1, propertyNames[i], state, propertyTypes[i]);
}
}
// Reading further Money type
if (!propertyTypes[i].isEntityType() && propertyTypes[i].isComponentType() && !(propertyValues[i] instanceof MasterDataEntity) && (propertyValues[i] instanceof Money)) {
Object obj1 = propertyValues[i];
if (obj1 != null) {
readFurtherMoneyType(obj1, firstName.concat(propertyNames[i]), state);
}
}
}
}
use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.
the class LoanProductAssembler method fromDto.
public LoanOfferingBO fromDto(MifosUser user, LoanProductRequest loanProductRequest) {
try {
Integer userId = user.getUserId();
ProductDetailsDto productDetails = loanProductRequest.getProductDetails();
String name = productDetails.getName();
String shortName = productDetails.getShortName();
String description = productDetails.getDescription();
Integer category = productDetails.getCategory();
boolean loanCycleCounter = loanProductRequest.isIncludeInLoanCycleCounter();
boolean waiverInterest = loanProductRequest.isWaiverInterest();
PrdStatusEntity activeStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.LOAN_ACTIVE);
PrdStatusEntity inActiveStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.LOAN_INACTIVE);
PrdStatusEntity selectedStatus = activeStatus;
if (productDetails.getStatus() != null && inActiveStatus.getOfferingStatusId().equals(productDetails.getStatus().shortValue())) {
selectedStatus = inActiveStatus;
}
MifosCurrency currency = Money.getDefaultCurrency();
if (AccountingRules.isMultiCurrencyEnabled()) {
currency = AccountingRules.getCurrencyByCurrencyId(loanProductRequest.getCurrencyId().shortValue());
}
ProductCategoryBO productCategory = this.loanProductDao.findActiveProductCategoryById(category);
DateTime startDate = productDetails.getStartDate();
DateTime endDate = productDetails.getEndDate();
ApplicableTo applicableTo = ApplicableTo.fromInt(productDetails.getApplicableFor());
PrdApplicableMasterEntity applicableToEntity = this.loanProductDao.findApplicableProductType(applicableTo);
LoanAmountCalculation loanAmountCalculation = this.loanProductCaluclationTypeAssembler.assembleLoanAmountCalculationFromDto(loanProductRequest.getLoanAmountDetails());
InterestType interestType = InterestType.fromInt(loanProductRequest.getInterestRateType());
Double minRate = loanProductRequest.getInterestRateRange().getMin().doubleValue();
Double maxRate = loanProductRequest.getInterestRateRange().getMax().doubleValue();
Double defaultRate = loanProductRequest.getInterestRateRange().getTheDefault().doubleValue();
InterestTypesEntity interestTypeEntity = this.loanProductDao.findInterestType(interestType);
RecurrenceType recurrence = RecurrenceType.fromInt(loanProductRequest.getRepaymentDetails().getFrequencyType().shortValue());
Integer recurEvery = loanProductRequest.getRepaymentDetails().getRecurs();
LoanInstallmentCalculation loanInstallmentCalculation = this.loanProductCaluclationTypeAssembler.assembleLoanInstallmentCalculationFromDto(loanProductRequest.getRepaymentDetails().getInstallmentCalculationDetails());
GraceType gracePeriodType = GraceType.fromInt(loanProductRequest.getRepaymentDetails().getGracePeriodType());
GracePeriodTypeEntity gracePeriodTypeEntity = this.loanProductDao.findGracePeriodType(gracePeriodType);
Integer gracePeriodDuration = loanProductRequest.getRepaymentDetails().getGracePeriodDuration();
List<FeeBO> applicableFees = new ArrayList<FeeBO>();
List<Integer> applicableFeeIds = loanProductRequest.getApplicableFees();
for (Integer feeId : applicableFeeIds) {
FeeBO fee = ApplicationContextProvider.getBean(FeeDao.class).findById(feeId.shortValue());
applicableFees.add(fee);
}
List<FundBO> applicableFunds = new ArrayList<FundBO>();
List<Integer> applicableFundIds = loanProductRequest.getAccountDetails().getApplicableFunds();
for (Integer fundId : applicableFundIds) {
FundBO fund = this.fundDao.findById(fundId.shortValue());
applicableFunds.add(fund);
}
List<PenaltyBO> applicablePenalties = new ArrayList<PenaltyBO>();
List<Integer> applicablePenaltyIds = loanProductRequest.getApplicablePenalties();
for (Integer penaltyId : applicablePenaltyIds) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(penaltyId);
applicablePenalties.add(penalty);
}
GLCodeEntity interestGlCode = this.generalLedgerDao.findGlCodeById(loanProductRequest.getAccountDetails().getInterestGlCodeId().shortValue());
GLCodeEntity principalGlCode = this.generalLedgerDao.findGlCodeById(loanProductRequest.getAccountDetails().getPrincipalClCodeId().shortValue());
String globalProductId = generateProductGlobalNum(user);
LoanOfferingBO loanProduct = LoanOfferingBO.createNew(userId, globalProductId, name, shortName, description, productCategory, startDate, endDate, applicableToEntity, currency, interestTypeEntity, minRate, maxRate, defaultRate, recurrence, recurEvery, interestGlCode, principalGlCode, activeStatus, inActiveStatus, gracePeriodTypeEntity, gracePeriodDuration, waiverInterest, loanCycleCounter, loanAmountCalculation, loanInstallmentCalculation, applicableFees, applicableFunds, applicablePenalties);
loanProduct.updateStatus(selectedStatus);
return loanProduct;
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
}
Aggregations