use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.
the class NotesAction method create.
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
NotesActionForm notesActionForm = (NotesActionForm) form;
UserContext uc = getUserContext(request);
CreateAccountNote accountNote = (CreateAccountNote) SessionUtils.getAttribute("model.accountNote", request);
AccountBO accountBO = new AccountBusinessService().getAccount(accountNote.getAccountId());
if (accountBO.getPersonnel() != null) {
checkPermissionForAddingNotes(accountBO.getType(), null, uc, accountBO.getOffice().getOfficeId(), accountBO.getPersonnel().getPersonnelId());
} else {
checkPermissionForAddingNotes(accountBO.getType(), null, uc, accountBO.getOffice().getOfficeId(), uc.getId());
}
if (accountBO.isSavingsAccount()) {
this.savingsServiceFacade.addNote(accountNote);
} else {
this.loanAccountServiceFacade.addNote(accountNote);
}
return mapping.findForward(chooseForward(Short.valueOf(notesActionForm.getAccountTypeId())));
}
use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.
the class NotesAction method getSearchResult.
@Override
protected QueryResult getSearchResult(ActionForm form) throws Exception {
Integer accountId = Integer.valueOf(((NotesActionForm) form).getAccountId());
AccountBO account = new AccountBusinessService().getAccount(accountId);
if (account.isSavingsAccount()) {
NoteSearchDto noteSearchDto = new NoteSearchDto(accountId, Integer.valueOf(1), Integer.valueOf(10));
NotesSearchResultsDto noteResults = this.savingsServiceFacade.retrievePagedNotesDto(noteSearchDto);
}
return legacyAccountDao.getAllAccountNotes(accountId);
}
use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.
the class AccountApplyPaymentActionForm method validateModeOfPaymentSecurity.
private void validateModeOfPaymentSecurity(HttpServletRequest request, ActionErrors errors) {
UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
AccountBO account = null;
Short personnelId = userContext.getId();
try {
if (accountId != null) {
account = new AccountBusinessService().getAccount(Integer.valueOf(accountId));
if (account.getPersonnel() != null) {
personnelId = account.getPersonnel().getPersonnelId();
}
}
} catch (NumberFormatException e) {
throw new MifosRuntimeException(e);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
if (getPaymentTypeId().equals("4") && !ActivityMapper.getInstance().isModeOfPaymentSecurity(userContext, personnelId)) {
errors.add(AccountConstants.LOAN_TRANSFER_PERMISSION, new ActionMessage(AccountConstants.LOAN_TRANSFER_PERMISSION, getLocalizedMessage("accounts.mode_of_payment_permission")));
}
}
use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.
the class WebTierAccountServiceFacade method applyGroupCharge.
@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);
try {
AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId())).getParentAccount();
BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
BigDecimal membersAmount = BigDecimal.ZERO;
for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
LoanBO individual = loanDao.findById(entry.getKey());
Double chargeAmount = Double.valueOf(entry.getValue());
if (chargeAmount.equals(0.0)) {
continue;
}
membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
individual.updateDetails(userContext);
if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
} else {
individual.applyCharge(chargeId, chargeAmount);
}
}
boolean isRateCharge = false;
if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES)) && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
if (isPenaltyType) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
if (penalty instanceof RatePenaltyBO) {
isRateCharge = true;
}
} else {
FeeBO fee = feeDao.findById(chargeId);
if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
isRateCharge = true;
}
}
}
Double chargeAmount = null;
if (!isRateCharge) {
chargeAmount = sumCharge(idsAndValues);
} else {
chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
membersAmount = membersAmount.multiply(chargeAmountBig);
int scale = Money.getInternalPrecision();
chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
chargeAmount = chargeAmountBig.doubleValue();
}
parentAccount.updateDetails(userContext);
CustomerLevel customerLevel = null;
if (parentAccount.isCustomerAccount()) {
customerLevel = parentAccount.getCustomer().getLevel();
}
if (parentAccount.getPersonnel() != null) {
checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
} else {
checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), userContext.getId());
}
this.transactionHelper.startTransaction();
if (isPenaltyType && parentAccount instanceof LoanBO) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
((LoanBO) parentAccount).addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
} else {
parentAccount.applyCharge(chargeId, chargeAmount);
}
this.transactionHelper.commitTransaction();
} catch (ServiceException e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.
the class LoanDisbursementAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
UserContext uc = getUserContext(request);
Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
try {
String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
final String comment = "";
final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
CustomerDto customerDto = null;
PaymentTypeDto paymentType = null;
AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
monthClosingServiceFacade.validateTransactionDate(trxnDate);
// GLIM
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
for (LoanBO individual : individualLoans) {
if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
}
}
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
for (LoanBO individual : individualLoans) {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
}
if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
}
} catch (BusinessRuleException e) {
throw new AccountException(e.getMessage());
} catch (MifosRuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof AccountException) {
throw new AccountException(e.getCause().getMessage());
}
String msg = "errors.cannotDisburseLoan.because.disburseFailed";
logger.error(msg, e);
throw new AccountException(msg);
} catch (Exception e) {
String msg = "errors.cannotDisburseLoan.because.disburseFailed";
logger.error(msg, e);
throw new AccountException(msg);
}
return mapping.findForward(Constants.UPDATE_SUCCESS);
}
Aggregations