use of org.mifos.clientportfolio.loan.service.RecurringSchedule in project head by mifos.
the class LoanAccountController method submitLoanApplication.
private LoanCreationResultDto submitLoanApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
accountFees.addAll(additionalAccountFees);
BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
CreateLoanAccount loanAccountDetails = new CreateLoanAccount(formBean.getCustomerId(), formBean.getProductId(), accountState, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, formBean.getInterestRate().doubleValue(), disbursementDate, null, formBean.getNumberOfInstallments().intValue(), formBean.getMinNumberOfInstallments().intValue(), formBean.getMaxNumberOfInstallments().intValue(), formBean.getGraceDuration().intValue(), formBean.getFundId(), formBean.getLoanPurposeId(), formBean.getCollateralTypeId(), formBean.getCollateralNotes(), formBean.getExternalId(), formBean.isRepaymentScheduleIndependentOfCustomerMeeting(), recurringSchedule, accountFees, accountPenalties);
LoanCreationResultDto loanCreationResultDto = null;
if (formBean.isGlimApplicable()) {
List<GroupMemberAccountDto> memberAccounts = createGroupMemberAccounts(formBean);
BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
loanCreationResultDto = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
} else {
if (formBean.isVariableInstallmentsAllowed()) {
List<DateTime> installmentDates = cashFlowSummaryFormBean.getInstallments();
List<Number> totalInstallmentAmounts = cashFlowSummaryFormBean.getInstallmentAmounts();
if (installmentDates.isEmpty()) {
installmentDates = loanScheduleFormBean.getInstallments();
totalInstallmentAmounts = loanScheduleFormBean.getInstallmentAmounts();
}
// api for creating loan with premade loan schedule
loanCreationResultDto = loanAccountServiceFacade.createLoan(loanAccountDetails, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow, installmentDates, totalInstallmentAmounts);
} else {
loanCreationResultDto = loanAccountServiceFacade.createLoan(loanAccountDetails, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
}
}
List<CommonsMultipartFile> formFiles = formBean.getFiles();
List<UploadedFileDto> filesMetadata = formBean.getFilesMetadata();
for (int i = 0; i < formFiles.size(); i++) {
if (formFiles.get(i).getSize() != 0) {
InputStream inputStream;
try {
inputStream = formFiles.get(i).getInputStream();
} catch (IOException e) {
throw new MifosRuntimeException();
}
UploadedFileDto fileMetadata = filesMetadata.get(i);
loanAccountServiceFacade.uploadFile(loanCreationResultDto.getAccountId(), inputStream, fileMetadata);
}
}
return loanCreationResultDto;
}
use of org.mifos.clientportfolio.loan.service.RecurringSchedule in project head by mifos.
the class LoanAccountController method retrieveLoanSchedule.
public LoanScheduleDto retrieveLoanSchedule(int customerId, int productId, LoanAccountFormBean formBean, BackdatedPaymentable loanScheduleFormBean, boolean resetRedoLoanAccountDetails) {
LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
accountFees.addAll(additionalAccountFees);
CreateLoanSchedule createLoanAccount = new CreateLoanSchedule(customerId, productId, BigDecimal.valueOf(formBean.getAmount().doubleValue()), formBean.getInterestRate().doubleValue(), disbursementDate, formBean.getNumberOfInstallments().intValue(), formBean.getGraceDuration().intValue(), formBean.isRepaymentScheduleIndependentOfCustomerMeeting(), recurringSchedule, accountFees);
LoanScheduleDto loanSchedule = null;
if (formBean.isVariableInstallmentsAllowed() && !loanScheduleFormBean.getInstallments().isEmpty()) {
loanSchedule = loanAccountServiceFacade.createLoanSchedule(createLoanAccount, loanScheduleFormBean.getInstallments(), loanScheduleFormBean.getInstallmentAmounts());
} else {
loanSchedule = loanAccountServiceFacade.createLoanSchedule(createLoanAccount);
}
loanControllerHelper.populateFormBeanFromDto(customerId, productId, formBean, loanScheduleFormBean, disbursementDate, loanSchedule, resetRedoLoanAccountDetails);
return loanSchedule;
}
use of org.mifos.clientportfolio.loan.service.RecurringSchedule in project head by mifos.
the class LoanAccountController method submitLoanWithBackdatedPaymentsApplication.
private LoanCreationResultDto submitLoanWithBackdatedPaymentsApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
accountFees.addAll(additionalAccountFees);
BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
CreateLoanAccount loanAccountDetails = new CreateLoanAccount(formBean.getCustomerId(), formBean.getProductId(), accountState, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, formBean.getInterestRate().doubleValue(), disbursementDate, formBean.getDisbursalPaymentTypeId(), formBean.getNumberOfInstallments().intValue(), formBean.getMinNumberOfInstallments().intValue(), formBean.getMaxNumberOfInstallments().intValue(), formBean.getGraceDuration().intValue(), formBean.getFundId(), formBean.getLoanPurposeId(), formBean.getCollateralTypeId(), formBean.getCollateralNotes(), formBean.getExternalId(), formBean.isRepaymentScheduleIndependentOfCustomerMeeting(), recurringSchedule, accountFees, accountPenalties);
List<LoanPaymentDto> backdatedLoanPayments = new ArrayList<LoanPaymentDto>();
int index = 0;
List<Number> actualPaymentAmountDetails = cashFlowSummaryFormBean.getActualPaymentAmounts();
if (actualPaymentAmountDetails.isEmpty()) {
actualPaymentAmountDetails = loanScheduleFormBean.getActualPaymentAmounts();
}
for (Number actualPaymentAmount : actualPaymentAmountDetails) {
if (actualPaymentAmount.doubleValue() > 0) {
LocalDate transactionDate = new LocalDate(loanScheduleFormBean.getActualPaymentDates().get(index));
backdatedLoanPayments.add(new LoanPaymentDto(actualPaymentAmount.toString(), transactionDate, loanScheduleFormBean.getActualPaymentTypes().get(index), null));
}
index++;
}
LoanCreationResultDto loanCreationResultDto = null;
if (formBean.isGlimApplicable()) {
List<GroupMemberAccountDto> memberAccounts = createGroupMemberAccounts(formBean);
BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
loanCreationResultDto = loanAccountServiceFacade.createBackdatedGroupLoanWithIndividualMonitoring(createGroupLoanAccount, backdatedLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
} else if (formBean.isVariableInstallmentsAllowed()) {
List<DateTime> installmentDates = cashFlowSummaryFormBean.getInstallments();
List<Number> installmentPrincipalAmounts = cashFlowSummaryFormBean.getInstallmentAmounts();
if (installmentDates.isEmpty()) {
installmentDates = loanScheduleFormBean.getInstallments();
installmentPrincipalAmounts = loanScheduleFormBean.getInstallmentAmounts();
}
// api for creating loan with premade loan schedule
loanCreationResultDto = loanAccountServiceFacade.createBackdatedLoan(loanAccountDetails, backdatedLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow, installmentDates, installmentPrincipalAmounts);
} else {
loanCreationResultDto = loanAccountServiceFacade.createBackdatedLoan(loanAccountDetails, backdatedLoanPayments, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
}
return loanCreationResultDto;
}
use of org.mifos.clientportfolio.loan.service.RecurringSchedule 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.clientportfolio.loan.service.RecurringSchedule in project head by mifos.
the class LoanAdjustmentsIntegrationTest method createLoan.
private LoanBO createLoan() throws Exception {
MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday().build();
IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
IntegrationTestObjectMother.createCenter(center, weeklyMeeting);
group = new GroupBuilder().withMeeting(weeklyMeeting).withName("Group").withOffice(sampleBranchOffice()).withLoanOfficer(testUser()).withParentCustomer(center).build();
IntegrationTestObjectMother.createGroup(group, weeklyMeeting);
client = new ClientBuilder().withMeeting(weeklyMeeting).withName("Client").withOffice(sampleBranchOffice()).withLoanOfficer(testUser()).withParentCustomer(group).buildForIntegrationTests();
IntegrationTestObjectMother.createClient(client, weeklyMeeting);
LoanOfferingBO loanOffering = new LoanProductBuilder().withName("Adjust Loan Product").withMeeting(weeklyMeeting).buildForIntegrationTests();
IntegrationTestObjectMother.createProduct(loanOffering);
AmountFeeBO periodicFee = new FeeBuilder().appliesToLoans().periodic().withFeeAmount("10.0").withName("Periodic Fee").with(sampleBranchOffice()).build();
IntegrationTestObjectMother.saveFee(periodicFee);
BigDecimal loanAmount = BigDecimal.valueOf(Double.valueOf("1000.0"));
BigDecimal minAllowedLoanAmount = loanAmount;
BigDecimal maxAllowedLoanAmount = loanAmount;
Double interestRate = loanOffering.getDefInterestRate();
LocalDate disbursementDate = new LocalDate();
int numberOfInstallments = 10;
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(periodicFee.getFeeId().intValue(), periodicFee.getFeeAmount().toString()));
CreateLoanAccount createLoanAccount = new CreateLoanAccount(client.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
return IntegrationTestObjectMother.createClientLoan(createLoanAccount);
}
Aggregations