use of org.mifos.framework.exceptions.ServiceException in project head by mifos.
the class LoanBO method disburseLoan.
private void disburseLoan(final String receiptNum, final Date transactionDate, final Short paymentTypeId, final PersonnelBO loggedInUser, final Date receiptDate, final Short rcvdPaymentTypeId, final boolean persistChange, final Short paymentTypeIdForFees, Integer accountForTransferId) throws AccountException, PersistenceException {
if ((this.getState().compareTo(AccountState.LOAN_APPROVED) != 0) && (this.getState().compareTo(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) != 0)) {
throw new AccountException("Loan not in a State to be Disbursed: " + this.getState().toString());
}
if (this.getCustomer().isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(this.getLoanOffering())) {
throw new AccountException("errors.cannotDisburseLoan.because.otherLoansAreActive");
}
try {
new ProductMixValidator().checkIfProductsOfferingCanCoexist(this);
} catch (ServiceException e1) {
throw new AccountException(e1.getMessage());
}
addLoanActivity(buildLoanActivity(this.loanAmount, loggedInUser, AccountConstants.LOAN_DISBURSAL, transactionDate));
// regenerate the installments
if (!isFixedRepaymentSchedule() && !DateUtils.getDateWithoutTimeStamp(disbursementDate.getTime()).equals(DateUtils.getDateWithoutTimeStamp(transactionDate.getTime()))) {
final boolean lsimEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (lsimEnabled) {
// QUESTION: does minDays
final int minDaysInterval = new ConfigurationPersistence().getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY);
this.disbursementDate = new DateTime(transactionDate).plusDays(minDaysInterval - 1).toDate();
} else {
this.disbursementDate = transactionDate;
}
regeneratePaymentSchedule(lsimEnabled, null);
if (this.isParentGroupLoanAccount()) {
groupLoanAccountServiceFacade.fixMemberAndParentInstallmentDetails(this.getAccountId());
}
}
this.disbursementDate = transactionDate;
final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), newState, loggedInUser, this));
this.setAccountState(newState);
//
// Client performance entry
updateCustomerHistoryOnDisbursement(this.loanAmount);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
}
//
//
// build up account payment related data
AccountPaymentEntity accountPayment = null;
if (this.isInterestDeductedAtDisbursement()) {
// the 1st payment is made and creates an initial accountPaymentEntity.
// This disbursal process carries on with that accountPaymentEntity by updating the 'amount' to the actual
// disbursed amount.
accountPayment = payInterestAtDisbursement(receiptNum, transactionDate, rcvdPaymentTypeId, loggedInUser, receiptDate);
accountPayment.setAmount(this.loanAmount.subtract(accountPayment.getAmount()));
} else {
// Disbursal process has to create its own accountPayment taking into account any disbursement fees
Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
accountPayment = new AccountPaymentEntity(this, this.loanAmount.subtract(feeAmountAtDisbursement), receiptNum, receiptDate, getPaymentTypeEntity(paymentTypeId), transactionDate);
accountPayment.setCreatedByUser(loggedInUser);
if (feeAmountAtDisbursement.isGreaterThanZero()) {
processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, paymentTypeIdForFees, accountForTransferId);
}
}
// create trxn entry for disbursal
final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, loggedInUser, transactionDate, this.loanAmount, "-", null, this.loanAmount, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
accountPayment.addAccountTrxn(loanTrxnDetailEntity);
this.addAccountPayment(accountPayment);
this.buildFinancialEntries(accountPayment.getAccountTrxns());
if (persistChange) {
try {
ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
}
use of org.mifos.framework.exceptions.ServiceException in project head by mifos.
the class PersonnelServiceFacadeWebTier method createPersonnelInformation.
@Override
public UserDetailDto createPersonnelInformation(CreateOrUpdatePersonnelInformation personnel) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
try {
PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
List<RoleBO> roles = new ArrayList<RoleBO>();
for (ListElement element : personnel.getRoles()) {
RoleBO role = personnelBusinessService.getRoleById(new Short(element.getId().shortValue()));
roles.add(role);
}
AddressDto addressDto = personnel.getAddress();
Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
OfficeBO office = officeDao.findOfficeById(personnel.getOfficeId());
Name name = new Name(personnel.getFirstName(), personnel.getMiddleName(), personnel.getSecondLastName(), personnel.getLastName());
verifyFields(personnel.getUserName(), personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), name.getDisplayName());
PersonnelBO newPersonnel = new PersonnelBO(PersonnelLevel.fromInt(personnel.getPersonnelLevelId().intValue()), office, personnel.getTitle(), personnel.getPreferredLocale(), personnel.getPassword(), personnel.getUserName(), personnel.getEmailId(), roles, personnel.getCustomFields(), name, personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), personnel.getMaritalStatus(), personnel.getGender(), personnel.getDateOfJoiningMFI().toDate(), personnel.getDateOfJoiningBranch().toDate(), address, Integer.valueOf(user.getUserId()).shortValue(), personnel.getPasswordExpirationDate().toDate(), null);
transactionHelper.startTransaction();
this.personnelDao.save(newPersonnel);
transactionHelper.flushSession();
newPersonnel.generateGlobalPersonnelNum();
this.personnelDao.save(newPersonnel);
transactionHelper.commitTransaction();
return newPersonnel.toDto();
} catch (PersistenceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (ValidationException e) {
transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e.getValues(), e);
} catch (ServiceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
use of org.mifos.framework.exceptions.ServiceException in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method retrieveAllRoles.
@Override
public List<ListElement> retrieveAllRoles() {
try {
List<RoleBO> roles = new RolesPermissionsBusinessService().getRoles();
if (!roles.isEmpty()) {
List<ListElement> roleList = new ArrayList<ListElement>();
for (RoleBO role : roles) {
ListElement element = new ListElement(new Integer(role.getId()), role.getName());
roleList.add(element);
}
return roleList;
}
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
return null;
}
use of org.mifos.framework.exceptions.ServiceException in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getApplicablePenalties.
@Override
public List<ApplicableCharge> getApplicablePenalties(Integer accountId) {
try {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
LoanBO loan = this.loanDao.findById(accountId);
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
return loanBusinessService.getAppllicablePenalties(accountId, userContext);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.framework.exceptions.ServiceException in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveSavingsAccountAuditLogs.
@Override
public List<AuditLogDto> retrieveSavingsAccountAuditLogs(Long savingsId) {
List<AuditLogDto> auditLogDtos = new ArrayList<AuditLogDto>();
AuditBusinessService auditBusinessService = new AuditBusinessService();
try {
List<AuditLogView> auditLogs = auditBusinessService.getAuditLogRecords(EntityType.SAVINGS.getValue(), savingsId.intValue());
for (AuditLogView auditLogView : auditLogs) {
auditLogDtos.add(auditLogView.toDto());
}
return auditLogDtos;
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
}
Aggregations