Search in sources :

Example 6 with SavingsWithdrawalDto

use of org.mifos.dto.domain.SavingsWithdrawalDto in project head by mifos.

the class LoanBO method processFeesAtDisbursement.

@Transactional(readOnly = false)
public void processFeesAtDisbursement(final AccountPaymentEntity accountPayment, final Money feeAmountAtDisbursement, final Short paymentTypeIdForFees, Integer accountForTransferId) {
    try {
        loanSummary.updateFeePaid(feeAmountAtDisbursement);
        List<AccountFeesEntity> applicableAccountFees = new ArrayList<AccountFeesEntity>();
        for (AccountFeesEntity accountFeesEntity : getAccountFees()) {
            if (accountFeesEntity.isTimeOfDisbursement()) {
                applicableAccountFees.add(accountFeesEntity);
            }
        }
        LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.FEE_REPAYMENT, Short.valueOf("0"), accountPayment.getPaymentDate(), accountPayment.getCreatedByUser(), accountPayment.getPaymentDate(), feeAmountAtDisbursement, "-", null, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), applicableAccountFees, null);
        accountPayment.addAccountTrxn(loanTrxnDetailEntity);
        addLoanActivity(buildLoanActivity(accountPayment.getAccountTrxns(), accountPayment.getCreatedByUser(), AccountConstants.PAYMENT_RCVD, accountPayment.getPaymentDate()));
        Short transferFromSavingsPaymentType = legacyAcceptedPaymentTypeDao.getSavingsTransferId();
        if (paymentTypeIdForFees != null && accountForTransferId != null && paymentTypeIdForFees.equals(transferFromSavingsPaymentType)) {
            if (AccountingRules.isGroupLoanWithMembers() && (!this.isParentGroupLoanAccount() && this.isGroupLoanAccountMember())) {
                return;
            }
            if (this.getParentAccount() != null && this.getAccountType().getAccountTypeId().equals(AccountTypes.INDIVIDUAL_LOAN_ACCOUNT.getValue())) {
                return;
            }
            MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            Locale preferredLocale = Localization.getInstance().getLocaleById(user.getPreferredLocaleId());
            SavingsWithdrawalDto savingsWithdrawalDto = new SavingsWithdrawalDto(new Long(accountForTransferId), new Long(accountPayment.getAccount().getCustomer().getCustomerId()), new LocalDate(accountPayment.getPaymentDate().getTime()), Double.parseDouble(feeAmountAtDisbursement.getAmount().toString()), new Integer(paymentTypeIdForFees.toString()), accountPayment.getReceiptNumber(), new LocalDate(accountPayment.getReceiptDate().getTime()), preferredLocale);
            this.savingsServiceFacade.withdraw(savingsWithdrawalDto, true);
        }
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) Money(org.mifos.framework.util.helpers.Money) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with SavingsWithdrawalDto

use of org.mifos.dto.domain.SavingsWithdrawalDto in project head by mifos.

the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentFromSavings.

@Test
public void testMakeEarlyRepaymentFromSavings() throws AccountException, PersistenceException {
    final String savingsAccGlobalNum = "0001-00000009";
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    final java.sql.Date date = new java.sql.Date(new Date().getTime());
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    when(loanBO.getCurrency()).thenReturn(rupee);
    boolean waiveInterest = true;
    when(loanBO.isInterestWaived()).thenReturn(waiveInterest);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    when(savingsServiceFacade.retrieveSavingsAccountDetails(savingsAccGlobalNum)).thenReturn(savingsAccountDetailDto);
    when(savingsAccountDetailDto.getCustomerId()).thenReturn(2);
    when(savingsAccountDetailDto.getAccountId()).thenReturn(1);
    String paymentMethod = "4";
    String receiptNumber = "001";
    when(savingsServiceFacade.withdraw(any(SavingsWithdrawalDto.class), eq(true))).thenReturn(withdrawal);
    when(withdrawal.getPaymentId()).thenReturn(1);
    loanAccountServiceFacade.makeEarlyRepaymentFromSavings(new RepayLoanInfoDto("1", "100", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.TEN, BigDecimal.ZERO), savingsAccGlobalNum);
    ArgumentCaptor<SavingsWithdrawalDto> withdrawal = ArgumentCaptor.forClass(SavingsWithdrawalDto.class);
    verify(savingsServiceFacade).withdraw(withdrawal.capture(), eq(true));
    final Long savingsId = savingsAccountDetailDto.getAccountId().longValue();
    final Long customerId = savingsAccountDetailDto.getCustomerId().longValue();
    final LocalDate trxnDate = new LocalDate(date);
    final LocalDate receiptDate = new LocalDate(date);
    final Double amount = Double.parseDouble("100");
    final Integer modeOfPayment = 4;
    AccountPaymentDto paymentDto = new AccountPaymentDto(amount, date, receiptNumber, date, Short.valueOf((short) 1));
    assertEquals(withdrawal.getValue().getAmount(), amount);
    assertEquals(withdrawal.getValue().getSavingsId(), savingsId);
    assertEquals(withdrawal.getValue().getCustomerId(), customerId);
    assertEquals(withdrawal.getValue().getDateOfWithdrawal(), trxnDate);
    assertEquals(withdrawal.getValue().getDateOfReceipt(), receiptDate);
    assertEquals(withdrawal.getValue().getModeOfPayment(), modeOfPayment);
    assertEquals(withdrawal.getValue().getPreferredLocale(), userContext.getPreferredLocale());
    verify(loanBO).makeEarlyRepayment(paymentDto, (short) 1, waiveInterest, new Money(rupee, BigDecimal.ZERO), 1, null);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Test(org.junit.Test)

Example 8 with SavingsWithdrawalDto

use of org.mifos.dto.domain.SavingsWithdrawalDto in project head by mifos.

the class SavingsAccountRESTController method doSavingsTrxn.

private Map<String, String> doSavingsTrxn(String globalAccountNum, BigDecimal amount, String trxnDate, Short receiptId, String receiptDate, Short paymentTypeId, TrxnTypes trxnType) throws Exception {
    validateAmount(amount);
    String format = "dd-MM-yyyy";
    DateTime trnxDate = validateDateString(trxnDate, format);
    validateSavingsDate(trnxDate);
    DateTime receiptDateTime = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptDateTime = validateDateString(receiptDate, format);
        validateSavingsDate(receiptDateTime);
    } else {
        receiptDateTime = new DateTime(trnxDate);
    }
    SavingsBO savingsBO = savingsDao.findBySystemId(globalAccountNum);
    validateAccountState(savingsBO);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Integer accountId = savingsBO.getAccountId();
    DateTime today = new DateTime();
    String receiptIdString;
    if (receiptId == null) {
        receiptIdString = "";
    } else {
        receiptIdString = receiptId.toString();
    }
    CustomerBO client = savingsBO.getCustomer();
    CustomerDto customer = new CustomerDto();
    customer.setCustomerId(client.getCustomerId());
    Money balanceBeforePayment = savingsBO.getSavingsBalance();
    if (trxnType.equals(TrxnTypes.savings_deposit)) {
        validateSavingsPaymentTypeId(paymentTypeId, accountService.getSavingsPaymentTypes());
        SavingsDepositDto savingsDeposit = new SavingsDepositDto(accountId.longValue(), savingsBO.getCustomer().getCustomerId().longValue(), trnxDate.toLocalDate(), amount.doubleValue(), paymentTypeId.intValue(), receiptIdString, receiptDateTime.toLocalDate(), Locale.UK);
        this.savingsServiceFacade.deposit(savingsDeposit);
    } else {
        validateSavingsPaymentTypeId(paymentTypeId, accountService.getSavingsWithdrawalTypes());
        SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(accountId.longValue(), savingsBO.getCustomer().getCustomerId().longValue(), trnxDate.toLocalDate(), amount.doubleValue(), paymentTypeId.intValue(), receiptIdString, receiptDateTime.toLocalDate(), Locale.UK);
        this.savingsServiceFacade.withdraw(savingsWithdrawal);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("savingsDisplayName", savingsBO.getSavingsOffering().getPrdOfferingName());
    map.put("paymentDate", today.toLocalDate().toString());
    map.put("paymentTime", today.toLocalTime().toString());
    map.put("paymentAmount", savingsBO.getLastPmnt().getAmount().toString());
    map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("balanceBeforePayment", balanceBeforePayment.toString());
    map.put("balanceAfterPayment", savingsBO.getSavingsBalance().toString());
    return map;
}
Also used : Money(org.mifos.framework.util.helpers.Money) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) HashMap(java.util.HashMap) CustomerDto(org.mifos.dto.domain.CustomerDto) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosUser(org.mifos.security.MifosUser) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) DateTime(org.joda.time.DateTime)

Aggregations

SavingsWithdrawalDto (org.mifos.dto.domain.SavingsWithdrawalDto)8 LocalDate (org.joda.time.LocalDate)6 Locale (java.util.Locale)5 AccountException (org.mifos.accounts.exceptions.AccountException)5 MifosUser (org.mifos.security.MifosUser)5 BusinessRuleException (org.mifos.service.BusinessRuleException)5 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 PersistenceException (org.mifos.framework.exceptions.PersistenceException)4 UserContext (org.mifos.security.util.UserContext)4 PaymentDto (org.mifos.dto.domain.PaymentDto)3 SavingsDepositDto (org.mifos.dto.domain.SavingsDepositDto)3 ServiceException (org.mifos.framework.exceptions.ServiceException)3 Money (org.mifos.framework.util.helpers.Money)3 Date (java.util.Date)2 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)2 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)2 AccountPaymentDto (org.mifos.dto.domain.AccountPaymentDto)2 SavingsAccountDetailDto (org.mifos.dto.domain.SavingsAccountDetailDto)2