Search in sources :

Example 1 with SavingsInterestPostingFinancialActivity

use of org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity in project head by mifos.

the class SavingsBO method doPostInterest.

private void doPostInterest(LocalDate currentPostingDate, Money actualInterestToBePosted, PersonnelBO loggedInUser) {
    this.savingsBalance = this.savingsBalance.add(actualInterestToBePosted);
    this.savingsPerformance.setTotalInterestDetails(actualInterestToBePosted);
    SavingsActivityEntity savingsActivity = SavingsActivityEntity.savingsInterestPosting(this, personnel, this.savingsBalance, actualInterestToBePosted, currentPostingDate.toDateMidnight().toDate());
    savingsActivityDetails.add(savingsActivity);
    AccountPaymentEntity interestPayment = AccountPaymentEntity.savingsInterestPosting(this, actualInterestToBePosted, currentPostingDate.toDateMidnight().toDate(), loggedInUser);
    DateTime dueDate = new DateTime();
    SavingsTrxnDetailEntity interestPostingTransaction = SavingsTrxnDetailEntity.savingsInterestPosting(interestPayment, this.customer, this.savingsBalance, currentPostingDate.toDateMidnight().toDate(), dueDate, loggedInUser);
    interestPayment.addAccountTrxn(interestPostingTransaction);
    this.addAccountPayment(interestPayment);
    // NOTE: financial Transaction Processing should be decoupled from application domain model.
    try {
        BaseFinancialActivity baseFinancialActivity = new SavingsInterestPostingFinancialActivity(interestPostingTransaction);
        baseFinancialActivity.buildAccountEntries();
    } catch (FinancialException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : BaseFinancialActivity(org.mifos.accounts.financial.business.service.activity.BaseFinancialActivity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsInterestPostingFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) DateTime(org.joda.time.DateTime) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with SavingsInterestPostingFinancialActivity

use of org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity in project head by mifos.

the class InterestPostingAccountingEntryTest method testBuildAccountEntryForAction.

@Test
public void testBuildAccountEntryForAction() throws FinancialException {
    // setup
    DateMidnight savingsTrxnDetailActionDate = new DateMidnight(2009, 9, 9);
    DateMidnight savingsTrxnDetailCreationDate = new DateMidnight(2009, 1, 1);
    MifosCurrency currency = TestUtils.RUPEE;
    // stubbing
    when(savingsTrxnDetail.getAccount()).thenReturn(savingsBO);
    when(savingsTrxnDetail.getInterestAmount()).thenReturn(new Money(currency, interestAmount));
    when(savingsTrxnDetail.getActionDate()).thenReturn(savingsTrxnDetailActionDate.toDate());
    when(savingsTrxnDetail.getTrxnCreatedDate()).thenReturn(new Timestamp(savingsTrxnDetailCreationDate.getMillis()));
    when(savingsTrxnDetail.getPersonnel()).thenReturn(transactionCreator);
    when(savingsBO.getSavingsOffering()).thenReturn(savingsOffering);
    when(savingsOffering.getInterestGLCode()).thenReturn(coaSavingsInterestPayable.getAssociatedGlcode());
    when(savingsOffering.getDepositGLCode()).thenReturn(coaClientsSavings.getAssociatedGlcode());
    SavingsInterestPostingFinancialActivity financialActivity = new SavingsInterestPostingFinancialActivity(savingsTrxnDetail);
    // exercise test
    interestPostingAccountingEntry.buildAccountEntryForAction(financialActivity);
    // verification
    List<FinancialTransactionBO> transactions = financialActivity.getFinanacialTransaction();
    assertThat(transactions.size(), is(2));
    /*
         * Sort by GLCode strings so "22100" (interest payable tran) should be first, followed by "22200" (client
         * savings tran)
         */
    Collections.sort(transactions, new GLCodeComparator());
    Iterator<FinancialTransactionBO> it = transactions.iterator();
    FinancialTransactionBO interestPostingTrans = it.next();
    assertThat(interestPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
    assertThat(interestPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
    assertThat(interestPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
    assertThat(interestPostingTrans.getGlcode().getGlcode(), is(coaSavingsInterestPayable.getGlCode()));
    assertThat(interestPostingTrans.getDebitCreditFlag(), is(FinancialConstants.DEBIT.getValue()));
    assertThat(interestPostingTrans.getPostedBy(), is(transactionCreator));
    FinancialTransactionBO savingsPostingTrans = it.next();
    assertThat(savingsPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
    assertThat(savingsPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
    assertThat(savingsPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
    assertThat(savingsPostingTrans.getGlcode().getGlcode(), is(coaClientsSavings.getGlCode()));
    assertThat(savingsPostingTrans.getDebitCreditFlag(), is(FinancialConstants.CREDIT.getValue()));
    assertThat(savingsPostingTrans.getPostedBy(), is(transactionCreator));
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) DateMidnight(org.joda.time.DateMidnight) SavingsInterestPostingFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity) Timestamp(java.sql.Timestamp) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Aggregations

SavingsInterestPostingFinancialActivity (org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity)2 Timestamp (java.sql.Timestamp)1 DateMidnight (org.joda.time.DateMidnight)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 FinancialTransactionBO (org.mifos.accounts.financial.business.FinancialTransactionBO)1 BaseFinancialActivity (org.mifos.accounts.financial.business.service.activity.BaseFinancialActivity)1 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)1 MifosCurrency (org.mifos.application.master.business.MifosCurrency)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 Money (org.mifos.framework.util.helpers.Money)1