use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LegacyLoanDao method getLastPaymentAction.
@SuppressWarnings("unchecked")
public Short getLastPaymentAction(final Integer accountId) throws PersistenceException {
Map<String, Integer> queryParameters = new HashMap<String, Integer>();
queryParameters.put("accountId", accountId);
List<AccountPaymentEntity> accountPaymentList = executeNamedQuery(NamedQueryConstants.RETRIEVE_MAX_ACCPAYMENT, queryParameters);
if (accountPaymentList != null && accountPaymentList.size() > 0) {
AccountPaymentEntity accountPayment = accountPaymentList.get(0);
Set<AccountTrxnEntity> accountTrxnSet = accountPayment.getAccountTrxns();
for (AccountTrxnEntity accountTrxn : accountTrxnSet) {
if (accountTrxn.getAccountActionEntity().getId().shortValue() == AccountActionTypes.DISBURSAL.getValue()) {
return accountTrxn.getAccountActionEntity().getId();
}
}
}
return null;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LoanBO method makePayment.
/*
* PaymentData is the payment information entered in the UI An AccountPaymentEntity is created from the PaymentData
* passed in.
*/
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
AccountPaymentEntity accountPaymentEntity = prePayment(paymentData);
LoanPaymentTypes loanPaymentType = getLoanPaymentType(paymentData.getTotalAmount());
ApplicationContextProvider.getBean(LoanBusinessService.class).applyPayment(paymentData, this, accountPaymentEntity);
postPayment(paymentData, accountPaymentEntity, loanPaymentType);
if (paymentData.getOverpaymentAmount() != null) {
AccountOverpaymentEntity overpaymentEntity = new AccountOverpaymentEntity(this, accountPaymentEntity, paymentData.getOverpaymentAmount(), OverpaymentStatus.UNCLEARED.getValue());
addAccountOverpayment(overpaymentEntity);
}
// GLIM
BigDecimal installmentsPaid = findNumberOfPaidInstallments();
applyPaymentToMemberAccounts(paymentData, installmentsPaid);
return accountPaymentEntity;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LoanBO method disburse.
public void disburse(PersonnelBO createdBy, AccountPaymentEntity disbursalPayment) throws AccountException {
Date transactionDate = disbursalPayment.getPaymentDate();
addLoanActivity(buildLoanActivity(getLoanAmount(), createdBy, AccountConstants.LOAN_DISBURSAL, transactionDate));
final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newState, createdBy, this));
setAccountState(newState);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
}
// build up account payment related data
AccountPaymentEntity accountPayment = null;
// Disbursal process has to create its own accountPayment taking into account any disbursement fees
Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
accountPayment = new AccountPaymentEntity(this, getLoanAmount().subtract(feeAmountAtDisbursement), disbursalPayment.getReceiptNumber(), disbursalPayment.getReceiptDate(), getPaymentTypeEntity(disbursalPayment.getPaymentType().getId()), transactionDate);
accountPayment.setCreatedByUser(createdBy);
if (feeAmountAtDisbursement.isGreaterThanZero()) {
processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, disbursalPayment.getOtherTransferPaymentDto().getPaymentTypeId(), disbursalPayment.getOtherTransferPayment().getAccount().getAccountId());
}
// create trxn entry for disbursal
final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, createdBy, transactionDate, getLoanAmount(), "-", null, getLoanAmount(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
accountPayment.addAccountTrxn(loanTrxnDetailEntity);
addAccountPayment(accountPayment);
buildFinancialEntries(accountPayment.getAccountTrxns());
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LoanBO method applyMifos4948FixPayment.
/*
* Mifos-4948 specific code
*/
public void applyMifos4948FixPayment(Money totalMissedPayment) throws AccountException {
String comment = "MIFOS-4948 - Loan: " + this.getGlobalAccountNum() + " - Adding payment: " + totalMissedPayment;
try {
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel((short) 1);
Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, totalMissedPayment, null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
addAccountPayment(accountPaymentEntity);
accountPaymentEntity.setComment(comment);
AccountActionTypes accountActionTypes;
String accountConstants;
if (this.getAccountState().getId().equals(AccountState.LOAN_CLOSED_WRITTEN_OFF.getValue())) {
accountActionTypes = AccountActionTypes.WRITEOFF;
accountConstants = AccountConstants.LOAN_WRITTEN_OFF;
} else {
accountActionTypes = AccountActionTypes.LOAN_RESCHEDULED;
accountConstants = AccountConstants.LOAN_RESCHEDULED;
}
makeWriteOffOrReschedulePaymentForMifos4948(accountPaymentEntity, accountConstants, accountActionTypes, currentUser);
addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, accountConstants, transactionDate));
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class LoanBO method postPayment.
private void postPayment(PaymentData paymentData, AccountPaymentEntity accountPaymentEntity, LoanPaymentTypes loanPaymentType) throws AccountException {
closeLoanIfRequired(paymentData);
updateLoanStatus(paymentData, loanPaymentType);
handleLoanArrearsAging(loanPaymentType);
AccountPaymentEntity otherTransferPayment = paymentData.getOtherTransferPayment();
if (otherTransferPayment != null) {
otherTransferPayment.setOtherTransferPayment(accountPaymentEntity);
}
addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), paymentData.getPersonnel(), AccountConstants.PAYMENT_RCVD, paymentData.getTransactionDate()));
}
Aggregations