use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.
the class IntegrationTestObjectMother method createAccountChecklist.
public static AccountCheckListBO createAccountChecklist(Short prdTypeId, AccountState accountState, Short checklistStatus, List<String> details) {
try {
StaticHibernateUtil.startTransaction();
ProductTypeEntity productTypeEntity = (ProductTypeEntity) StaticHibernateUtil.getSessionTL().get(ProductTypeEntity.class, prdTypeId);
AccountStateEntity accountStateEntity = new AccountStateEntity(accountState);
AccountCheckListBO accountChecklist = new AccountCheckListBO(productTypeEntity, accountStateEntity, "productchecklist", checklistStatus, details, Short.valueOf("1"), PersonnelConstants.SYSTEM_USER);
customerDao.save(accountChecklist);
StaticHibernateUtil.commitTransaction();
return accountChecklist;
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new RuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.
the class LoanBO method handleArrears.
public void handleArrears() throws AccountException {
AccountStateEntity stateEntity;
try {
stateEntity = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_BADSTANDING);
} catch (PersistenceException e) {
throw new AccountException(e);
}
AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), stateEntity, this.getPersonnel(), this);
this.addAccountStatusChangeHistory(historyEntity);
this.setAccountState(stateEntity);
try {
String systemDate = DateUtils.getCurrentDate();
Date currrentDate = DateUtils.getLocaleDate(systemDate);
this.setUpdatedDate(currrentDate);
} catch (InvalidDateException ide) {
throw new AccountException(ide);
}
try {
getlegacyLoanDao().createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.business.AccountStateEntity 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.accounts.business.AccountStateEntity in project head by mifos.
the class LoanBO method makeEarlyRepayment.
public void makeEarlyRepayment(final AccountPaymentDto paymentDto, final Short personnelId, boolean waiveInterest, Money interestDue, Integer savingsPaymentId, AccountPaymentEntity parentPayment) throws AccountException {
try {
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
this.setUpdatedBy(personnelId);
this.setUpdatedDate(paymentDto.getTransactionDate());
AccountPaymentEntity accountPaymentEntity;
if (this.isGroupLoanAccount() && null != this.getParentAccount()) {
accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate(), parentPayment);
} else {
accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate());
}
if (savingsPaymentId != null) {
AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
accountPaymentEntity.setOtherTransferPayment(withdrawal);
}
addAccountPayment(accountPaymentEntity);
makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
makeEarlyRepaymentForNextInstallment(currentUser, accountPaymentEntity, waiveInterest, interestDue);
makeEarlyRepaymentForFutureInstallments(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setNoOfPayments(getPerformanceHistory().getNoOfPayments() + 1);
}
LoanActivityEntity loanActivity = buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_REPAYMENT, paymentDto.getTransactionDate());
addLoanActivity(loanActivity);
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
AccountStateEntity newAccountState = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET);
addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newAccountState, legacyPersonnelDao.getPersonnel(personnelId), this));
setAccountState(legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET));
changeStateForAllFees(FeeStatus.INACTIVE);
setClosedDate(paymentDto.getTransactionDate());
// Client performance entry
updateCustomerHistoryOnRepayment();
this.delete(loanArrearsAgingEntity);
loanArrearsAgingEntity = null;
// GLIM
if (this.isGroupLoanAccountParent()) {
for (Entry<String, AmountWithInterest> entry : paymentDto.getMemberNumWithAmount().entrySet()) {
AccountPaymentDto memberPayment = new AccountPaymentDto(entry.getValue().getAmount(), paymentDto.getTransactionDate(), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), paymentDto.getPaymentTypeId());
legacyLoanDao.getAccount(Integer.valueOf(entry.getKey())).makeEarlyRepayment(memberPayment, personnelId, waiveInterest, new Money(this.getCurrency(), entry.getValue().getInterest()), null, accountPaymentEntity);
}
} else if (hasMemberAccounts() && !this.isGroupLoanAccount()) {
for (LoanBO memberAccount : this.memberAccounts) {
BigDecimal fraction = memberAccount.calcFactorOfEntireLoan();
paymentDto.setTotalAmount(new BigDecimal(paymentDto.getTotalAmount()).divide(fraction, RoundingMode.HALF_UP).doubleValue());
memberAccount.makeEarlyRepayment(paymentDto, personnelId, waiveInterest, interestDue, null, null);
}
}
this.legacyAccountDao.createOrUpdate(accountPaymentEntity);
this.legacyAccountDao.createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.
the class BirtAdminDocumentUploadAction method editThenUpload.
@SuppressWarnings("unchecked")
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward editThenUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
BirtAdminDocumentUploadActionForm uploadForm = (BirtAdminDocumentUploadActionForm) form;
FormFile formFile = uploadForm.getFile();
boolean newFile = false;
if (StringUtils.isEmpty(formFile.getFileName())) {
formFile.destroy();
} else {
uploadFile(formFile);
newFile = true;
}
AdminDocumentBO admindoc = legacyAdminDocumentDao.getAdminDocumentById(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
admindoc.setAdminDocumentName(uploadForm.getAdminiDocumentTitle());
admindoc.setIsActive(Short.valueOf(uploadForm.getIsActive()));
if (newFile) {
admindoc.setAdminDocumentIdentifier(formFile.getFileName());
}
legacyAdminDocumentDao.createOrUpdate(admindoc);
if (Short.valueOf(uploadForm.getAccountTypeId()).shortValue() <= 2) {
List<AccountStateEntity> masterList = (List<AccountStateEntity>) SessionUtils.getAttribute("SelectedStatus", request);
List<AdminDocAccStateMixBO> admindoclist = legacyAdminDocAccStateMixDao.getMixByAdminDocuments(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
for (AdminDocAccStateMixBO temp : admindoclist) {
legacyAdminDocAccStateMixDao.delete(temp);
}
AdminDocAccStateMixBO admindocaccstatemixBO = new AdminDocAccStateMixBO();
for (AccountStateEntity acc : masterList) {
admindocaccstatemixBO = new AdminDocAccStateMixBO();
admindocaccstatemixBO.setAccountStateID(acc);
admindocaccstatemixBO.setAdminDocumentID(admindoc);
legacyAdminDocAccStateMixDao.createOrUpdate(admindocaccstatemixBO);
}
} else {
List<AccountActionEntity> masterList = (List<AccountActionEntity>) SessionUtils.getAttribute("SelectedStatus", request);
List<AdminDocAccActionMixBO> admindoclist = legacyAdminDocAccStateMixDao.getAccActionMixByAdminDocument(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
for (AdminDocAccActionMixBO temp : admindoclist) {
legacyAdminDocAccStateMixDao.delete(temp);
}
AdminDocAccActionMixBO adminDocAccActionMixBO = new AdminDocAccActionMixBO();
for (AccountActionEntity acc : masterList) {
adminDocAccActionMixBO = new AdminDocAccActionMixBO();
adminDocAccActionMixBO.setAccountAction(acc);
adminDocAccActionMixBO.setAdminDocument(admindoc);
legacyAdminDocAccStateMixDao.createOrUpdate(adminDocAccActionMixBO);
}
}
return getViewBirtAdminDocumentPage(mapping, form, request, response);
}
Aggregations