use of org.mifos.dto.domain.PenaltyDto in project head by mifos.
the class LoanControllerHelper method populateFormBeanFromDto.
public void populateFormBeanFromDto(int customerId, int productId, LoanAccountFormBean formBean, BackdatedPaymentable loanScheduleFormBean, LocalDate disbursementDate, LoanScheduleDto loanSchedule, boolean resetActualPaymentDatesAndAmountsForRedoLoan) {
List<DateTime> installments = new ArrayList<DateTime>();
List<DateTime> actualPaymentDates = new ArrayList<DateTime>();
List<Number> installmentAmounts = new ArrayList<Number>();
List<Number> actualPaymentAmounts = new ArrayList<Number>();
List<Short> actualPaymentTypes = new ArrayList<Short>();
BigDecimal totalLoanInterest = BigDecimal.ZERO;
BigDecimal totalLoanFees = BigDecimal.ZERO;
for (LoanCreationInstallmentDto installment : loanSchedule.getInstallments()) {
totalLoanInterest = totalLoanInterest.add(BigDecimal.valueOf(installment.getInterest()));
totalLoanFees = totalLoanFees.add(BigDecimal.valueOf(installment.getFees()));
installments.add(new DateTime(installment.getDueDate()));
actualPaymentDates.add(new DateTime(installment.getDueDate()));
installmentAmounts.add(installment.getTotal());
if (new LocalDate(installment.getDueDate()).isBefore(new LocalDate().plusDays(1))) {
actualPaymentAmounts.add(installment.getTotal());
} else {
actualPaymentAmounts.add(Double.valueOf("0.0"));
}
actualPaymentTypes.add(null);
}
loanScheduleFormBean.setInstallments(installments);
loanScheduleFormBean.setVariableInstallments(loanSchedule.getInstallments());
loanScheduleFormBean.setInstallmentAmounts(installmentAmounts);
if (resetActualPaymentDatesAndAmountsForRedoLoan) {
loanScheduleFormBean.setActualPaymentDates(actualPaymentDates);
loanScheduleFormBean.setActualPaymentAmounts(actualPaymentAmounts);
loanScheduleFormBean.setActualPaymentTypes(actualPaymentTypes);
}
loanScheduleFormBean.setLoanPrincipal(BigDecimal.valueOf(formBean.getAmount().doubleValue()));
loanScheduleFormBean.setTotalLoanInterest(totalLoanInterest);
loanScheduleFormBean.setTotalLoanFees(totalLoanFees);
loanScheduleFormBean.setRepaymentInstallments(loanSchedule.getInstallments());
if (disbursementDate != null) {
loanScheduleFormBean.setDisbursementDate(disbursementDate.toDateMidnight().toDate());
}
// variable installments related
loanScheduleFormBean.setVariableInstallmentsAllowed(formBean.isVariableInstallmentsAllowed());
if (loanScheduleFormBean.isVariableInstallmentsAllowed()) {
loanScheduleFormBean.setMinGapInDays(formBean.getMinGapInDays());
loanScheduleFormBean.setMaxGapInDays(formBean.getMaxGapInDays());
loanScheduleFormBean.setMinInstallmentAmount(formBean.getMinInstallmentAmount());
loanScheduleFormBean.setCustomerId(formBean.getCustomerId());
loanScheduleFormBean.setLoanAccountFormBean(formBean);
}
List<FeeDto> applicableFees = new ArrayList<FeeDto>();
LoanCreationLoanDetailsDto dto = this.loanAccountServiceFacade.retrieveLoanDetailsForLoanAccountCreation(customerId, Integer.valueOf(productId).shortValue(), formBean.isRedoLoanAccount());
int feeIndex = 0;
for (Boolean defaultFeeSelectedForRemoval : formBean.getDefaultFeeSelected()) {
if (defaultFeeSelectedForRemoval == null || !defaultFeeSelectedForRemoval) {
Integer feeId = formBean.getDefaultFeeId()[feeIndex].intValue();
BigDecimal amountOrRate = BigDecimal.valueOf(formBean.getDefaultFeeAmountOrRate()[feeIndex].doubleValue());
applicableFees.add(findFeeById(dto.getDefaultFees(), feeId, amountOrRate));
}
feeIndex++;
}
List<PenaltyDto> applicablePenalties = new ArrayList<PenaltyDto>();
int penaltyIndex = 0;
for (Boolean defaultPenaltySelectedForRemoval : formBean.getDefaultPenaltySelected()) {
if (defaultPenaltySelectedForRemoval == null || !defaultPenaltySelectedForRemoval) {
Integer penaltyId = formBean.getDefaultPenaltyId()[penaltyIndex].intValue();
BigDecimal amountOrRate = BigDecimal.valueOf(formBean.getDefaultPenaltyAmountOrRate()[penaltyIndex].doubleValue());
applicablePenalties.add(findPenaltyById(dto.getDefaultPenalties(), penaltyId, amountOrRate));
}
penaltyIndex++;
}
feeIndex = 0;
Number[] additionalFeesSelected = formBean.getSelectedFeeId();
if (additionalFeesSelected != null) {
for (Number additionalFee : additionalFeesSelected) {
if (additionalFee != null) {
BigDecimal amountOrRate = BigDecimal.valueOf(formBean.getSelectedFeeAmount()[feeIndex].doubleValue());
applicableFees.add(findFeeById(dto.getAdditionalFees(), additionalFee.intValue(), amountOrRate));
}
feeIndex++;
}
}
loanScheduleFormBean.setApplicableFees(applicableFees);
loanScheduleFormBean.setApplicablePenalties(applicablePenalties);
}
use of org.mifos.dto.domain.PenaltyDto in project head by mifos.
the class LoanPrdActionForm method setSelectedFeesPenaltiesAndFundsAndValidateForFrequency.
private void setSelectedFeesPenaltiesAndFundsAndValidateForFrequency(HttpServletRequest request, ActionErrors errors) {
logger.debug("start setSelectedFeesPenaltiesAndFundsAndValidateForFrequency method " + "of Loan Product Action form method :");
request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
List<FeeDto> feeDtos = new ArrayList<FeeDto>();
try {
if (getPrdOfferinFees() != null && getPrdOfferinFees().length > 0) {
List<FeeBO> fees = getAllLoanPrdFee(request);
for (String selectedFee : getPrdOfferinFees()) {
FeeBO fee = getFeeFromList(fees, selectedFee);
if (fee != null) {
isFrequencyMatchingOfferingFrequency(fee, errors);
if (AccountingRules.isMultiCurrencyEnabled()) {
isValidForCurrency(fee, errors, request);
}
feeDtos.add(getFeeDto(request, fee));
}
}
}
setSelectedFeeDtoOnSession(request, feeDtos);
} catch (PageExpiredException e) {
}
List<FundBO> selectedFunds = new ArrayList<FundBO>();
try {
if (getLoanOfferingFunds() != null && getLoanOfferingFunds().length > 0) {
List<FundBO> funds = (List<FundBO>) SessionUtils.getAttribute(ProductDefinitionConstants.SRCFUNDSLIST, request);
for (String selectedFund : getLoanOfferingFunds()) {
FundBO fund = getFundFromList(funds, selectedFund);
if (fund != null) {
selectedFunds.add(fund);
}
}
}
SessionUtils.setCollectionAttribute(ProductDefinitionConstants.LOANPRDFUNDSELECTEDLIST, selectedFunds, request);
} catch (PageExpiredException e) {
}
List<PenaltyDto> selectedPenalties = new ArrayList<PenaltyDto>();
try {
if (getPrdOfferinPenalties() != null && getPrdOfferinPenalties().length > 0) {
List<PenaltyBO> penalties = getAllLoanPrdPenalty(request);
for (String selectedPenalty : getPrdOfferinPenalties()) {
PenaltyBO penalty = getPenaltyFromList(penalties, selectedPenalty);
if (penalty != null) {
selectedPenalties.add(penalty.toDto());
}
}
}
setSelectedPenaltyDtoOnSession(request, selectedPenalties);
} catch (PageExpiredException e) {
}
logger.debug("setSelectedFeesPenaltiesAndFundsAndValidateForFrequency method " + "of Loan Product Action form method called :");
}
use of org.mifos.dto.domain.PenaltyDto in project head by mifos.
the class LoanPrdAction method getPenaltiesSelected.
private List<PenaltyDto> getPenaltiesSelected(LoanOfferingBO loanOffering) {
List<PenaltyDto> penaltySelected = new ArrayList<PenaltyDto>();
for (PrdOfferingPenaltiesEntity prdOfferingPenalties : loanOffering.getLoanOfferingPenalties()) {
PenaltyBO penalty = prdOfferingPenalties.getPenalty();
penalty = penaltyDao.findPenaltyById(penalty.getPenaltyId());
penaltySelected.add(penalty.toDto());
}
return penaltySelected;
}
use of org.mifos.dto.domain.PenaltyDto in project head by mifos.
the class LoanControllerHelper method findPenaltyById.
public PenaltyDto findPenaltyById(final List<PenaltyDto> defaultPenalties, final Integer penaltyId, final BigDecimal amountOrRate) {
PenaltyDto found = null;
for (PenaltyDto penaltyDto : defaultPenalties) {
if (Integer.valueOf(penaltyDto.getPenaltyId()).equals(penaltyId)) {
penaltyDto.setAmount(amountOrRate.toPlainString());
if (penaltyDto.isRateBasedPenalty()) {
penaltyDto.setRate(amountOrRate.doubleValue());
}
found = penaltyDto;
}
}
return found;
}
Aggregations