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);
}
}
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);
}
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;
}
Aggregations