use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class LoanAccountServiceFacadeWebTier method createLoanSchedule.
@Override
public LoanScheduleDto createLoanSchedule(CreateLoanSchedule createLoanSchedule, List<DateTime> loanScheduleDates, List<Number> totalInstallmentAmounts) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
// assemble into domain entities
LoanOfferingBO loanProduct = this.loanProductDao.findById(createLoanSchedule.getProductId());
CustomerBO customer = this.customerDao.findCustomerById(createLoanSchedule.getCustomerId());
Money loanAmountDisbursed = new Money(loanProduct.getCurrency(), createLoanSchedule.getLoanAmount());
List<AccountFeesEntity> accountFeeEntities = assembleAccountFees(createLoanSchedule.getAccountFeeEntities());
LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(loanAmountDisbursed, createLoanSchedule.getDisbursementDate(), createLoanSchedule.getInterestRate(), createLoanSchedule.getNumberOfInstallments(), createLoanSchedule.getGraceDuration(), accountFeeEntities, new ArrayList<AccountPenaltiesEntity>());
Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
boolean loanScheduleIndependentOfCustomerMeetingEnabled = createLoanSchedule.isRepaymentIndependentOfCustomerMeetingSchedule();
MeetingBO loanMeeting = customer.getCustomerMeetingValue();
if (loanScheduleIndependentOfCustomerMeetingEnabled) {
loanMeeting = this.createNewMeetingForRepaymentDay(createLoanSchedule.getDisbursementDate(), createLoanSchedule, customer);
if (loanProduct.isVariableInstallmentsAllowed()) {
loanMeeting.setMeetingStartDate(createLoanSchedule.getDisbursementDate().toDateMidnight().toDate());
}
}
LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
LoanSchedule loanSchedule = this.loanScheduleService.generate(loanProduct, customer, loanMeeting, overridenDetail, configuration, accountFeeEntities, createLoanSchedule.getDisbursementDate(), loanScheduleDates, totalInstallmentAmounts);
// translate to DTO form
List<LoanCreationInstallmentDto> installments = new ArrayList<LoanCreationInstallmentDto>();
Short digitsAfterDecimal = AccountingRules.getDigitsAfterDecimal();
for (LoanScheduleEntity loanScheduleEntity : loanSchedule.getRoundedLoanSchedules()) {
Integer installmentNumber = loanScheduleEntity.getInstallmentId().intValue();
LocalDate dueDate = new LocalDate(loanScheduleEntity.getActionDate());
String principal = loanScheduleEntity.getPrincipal().toString(digitsAfterDecimal);
String interest = loanScheduleEntity.getInterest().toString(digitsAfterDecimal);
String fees = loanScheduleEntity.getTotalFees().toString(digitsAfterDecimal);
String penalty = "0.0";
String total = loanScheduleEntity.getPrincipal().add(loanScheduleEntity.getInterest()).add(loanScheduleEntity.getTotalFees()).toString(digitsAfterDecimal);
LoanCreationInstallmentDto installment = new LoanCreationInstallmentDto(installmentNumber, dueDate, Double.valueOf(principal), Double.valueOf(interest), Double.valueOf(fees), Double.valueOf(penalty), Double.valueOf(total));
installments.add(installment);
}
return new LoanScheduleDto(customer.getDisplayName(), Double.valueOf(createLoanSchedule.getLoanAmount().doubleValue()), createLoanSchedule.getDisbursementDate(), loanProduct.getGraceType().getValue().intValue(), installments);
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CenterServiceFacadeWebTier method createCustomerNote.
@Override
public void createCustomerNote(CustomerNoteFormDto customerNoteForm) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
CustomerBO customer = this.customerDao.findCustomerBySystemId(customerNoteForm.getGlobalNum());
customer.updateDetails(userContext);
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
CustomerNoteEntity customerNote = new CustomerNoteEntity(customerNoteForm.getComment(), new DateTimeService().getCurrentJavaSqlDate(), loggedInUser, customer);
customer.addCustomerNotes(customerNote);
try {
this.transactionHelper.startTransaction();
this.customerDao.save(customer);
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(customer.getCustomerAccount().getAccountId().toString(), e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CenterServiceFacadeWebTier method retrieveAccountTransactionHistory.
@Override
public List<TransactionHistoryDto> retrieveAccountTransactionHistory(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
AccountBO account = new AccountBusinessService().findBySystemId(globalAccountNum);
CustomerBO customerBO = account.getCustomer();
account.updateDetails(userContext);
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
List<TransactionHistoryDto> transactionHistories = account.getTransactionHistoryView();
for (TransactionHistoryDto transactionHistoryDto : transactionHistories) {
transactionHistoryDto.setUserPrefferedPostedDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), transactionHistoryDto.getPostedDate().toString()));
transactionHistoryDto.setUserPrefferedTransactionDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), transactionHistoryDto.getTransactionDate().toString()));
}
return transactionHistories;
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class LoanAccountServiceFacadeWebTier method linkGuarantor.
public void linkGuarantor(Integer guarantorId, Integer loanId) {
CustomerBO customerBO = this.customerDao.findCustomerById(guarantorId);
if (customerBO == loanDao.findById(loanId).getCustomer()) {
return;
}
transactionHelper.startTransaction();
GuarantyEntity guaranty = new GuarantyEntity();
guaranty.setGuarantorId(guarantorId);
guaranty.setLoanId(loanId);
guaranty.setState(true);
genericDao.getSession().save(guaranty);
try {
transactionHelper.commitTransaction();
} catch (Exception e) {
transactionHelper.rollbackTransaction();
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class MeetingAction method edit.
@TransactionDemarcate(conditionToken = true)
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
MeetingActionForm actionForm = (MeetingActionForm) form;
clearActionForm(actionForm);
CustomerBO customerInSession = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
CustomerBO customer = this.customerDao.findCustomerById(customerInSession.getCustomerId());
SessionUtils.setAttribute(Constants.BUSINESS_KEY, customer, request);
List<WeekDay> workingDays = getLocalizedWorkingDays();
SessionUtils.setCollectionAttribute(MeetingConstants.WEEKDAYSLIST, workingDays, request);
SessionUtils.setCollectionAttribute(MeetingConstants.WEEKRANKLIST, RankOfDay.getRankOfDayList(), request);
ActionForward forward = null;
if (customer.getCustomerMeeting() != null) {
MeetingBO meeting = customer.getCustomerMeeting().getMeeting();
setValuesInActionForm(actionForm, meeting);
forward = mapping.findForward(ActionForwards.edit_success.toString());
actionForm.setInput(MeetingConstants.INPUT_EDIT);
} else {
actionForm.setInput(MeetingConstants.INPUT_CREATE);
forward = mapping.findForward(ActionForwards.createMeeting_success.toString());
}
return forward;
}
Aggregations