use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsBOIntegrationTest method createSavingsAccountPayment.
private SavingsBO createSavingsAccountPayment() throws Exception {
AccountPaymentEntity payment;
createInitialObjects();
savingsOffering = helper.createSavingsOffering("2333dsf", "2132");
savings = helper.createSavingsAccount(savingsOffering, group, AccountState.SAVINGS_ACTIVE, userContext);
Money initialBal = new Money(currency, "5500");
payment = helper.createAccountPayment(savings, null, new Money(currency, "5500.0"), new Date(), createdBy);
SavingsTrxnDetailEntity adjustment = SavingsTrxnDetailEntity.savingsAdjustment(payment, group, initialBal, initialBal, createdBy, helper.getDate("04/01/2006"), helper.getDate("04/01/2006"), new DateTime().toDate(), "", null);
payment.addAccountTrxn(adjustment);
AccountTestUtils.addAccountPayment(payment, savings);
savings.update();
return TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsClosureActionStrutsTest method testSuccessfullPreview_withoutReceipt.
@Test
public void testSuccessfullPreview_withoutReceipt() throws Exception {
AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
addRequestParameter("receiptId", "");
addRequestParameter("receiptDate", "");
addRequestParameter("paymentTypeId", "1");
addRequestParameter("customerId", "1");
addRequestParameter("notes", "notes");
setRequestPathInfo("/savingsClosureAction.do");
addRequestParameter("method", "preview");
actionPerform();
verifyForward("preview_success");
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsClosureActionStrutsTest method testPreviewDateValidation.
@Test
public void testPreviewDateValidation() throws Exception {
AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
addRequestParameter("receiptId", "101");
// an invalid date
String badDate = "3/20/2005";
addRequestParameter("receiptDate", badDate);
addRequestParameter("paymentTypeId", "1");
addRequestParameter("customerId", "1");
addRequestParameter("notes", "notes");
setRequestPathInfo("/savingsClosureAction.do");
addRequestParameter("method", "preview");
actionPerform();
verifyActionErrors(new String[] { AccountConstants.ERROR_INVALIDDATE });
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsClosureActionStrutsTest method testSuccessfullPreviewWithNullPaymentId.
@Test
public void testSuccessfullPreviewWithNullPaymentId() throws Exception {
AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
addRequestParameter("receiptId", "101");
addRequestParameter("receiptDate", "");
// paymentTypeId is left null
addRequestParameter("customerId", "1");
addRequestParameter("notes", "notes");
setRequestPathInfo("/savingsClosureAction.do");
addRequestParameter("method", "preview");
actionPerform();
verifyNoActionErrors();
verifyForward("preview_success");
}
use of org.mifos.accounts.business.AccountPaymentEntity 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);
}
}
}
Aggregations