use of org.mifos.dto.domain.SavingsDepositDto in project head by mifos.
the class SavingsDepositWithdrawalAction method makePayment.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward makePayment(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
SavingsBO savedAccount = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
SavingsBO savings = savingsDao.findById(savedAccount.getAccountId());
checkVersionMismatch(savedAccount.getVersionNo(), savings.getVersionNo());
savings.setVersionNo(savedAccount.getVersionNo());
SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
Date trxnDate = getDateFromString(actionForm.getTrxnDate(), uc.getPreferredLocale());
monthClosingServiceFacade.validateTransactionDate(trxnDate);
Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (!savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled)) {
throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
}
Long savingsId = Long.valueOf(savings.getAccountId());
Long customerId = Long.valueOf(savings.getCustomer().getCustomerId());
if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
customerId = Long.valueOf(actionForm.getCustomerId());
}
Locale preferredLocale = uc.getPreferredLocale();
LocalDate dateOfDepositOrWithdrawalTransaction = new LocalDate(trxnDate);
Double amount = Double.valueOf(actionForm.getAmount());
Integer modeOfPayment = Integer.valueOf(actionForm.getPaymentTypeId());
String receiptId = actionForm.getReceiptId();
LocalDate dateOfReceipt = null;
if (StringUtils.isNotBlank(actionForm.getReceiptDate())) {
dateOfReceipt = new LocalDate(getDateFromString(actionForm.getReceiptDate(), preferredLocale));
}
try {
Short trxnTypeId = Short.valueOf(actionForm.getTrxnTypeId());
if (trxnTypeId.equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
SavingsDepositDto savingsDeposit = new SavingsDepositDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
this.savingsServiceFacade.deposit(savingsDeposit);
} else if (trxnTypeId.equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue())) {
SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
this.savingsServiceFacade.withdraw(savingsWithdrawal);
}
} catch (BusinessRuleException e) {
throw new AccountException(e.getMessageKey(), e);
}
return mapping.findForward(ActionForwards.account_details_page.toString());
}
use of org.mifos.dto.domain.SavingsDepositDto in project head by mifos.
the class SavingsServiceFacadeWebTier method fundTransfer.
@Override
public void fundTransfer(FundTransferDto fundTransferDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO targetAcc = this.savingsDao.findBySystemId(fundTransferDto.getTargetGlobalAccountNum());
SavingsBO sourceAcc = this.savingsDao.findBySystemId(fundTransferDto.getSourceGlobalAccountNum());
SavingsDepositDto depositDto;
SavingsWithdrawalDto withdrawalDto;
// prepare data
try {
depositDto = new SavingsDepositDto(targetAcc.getAccountId().longValue(), targetAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
withdrawalDto = new SavingsWithdrawalDto(sourceAcc.getAccountId().longValue(), sourceAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
} catch (PersistenceException ex) {
throw new MifosRuntimeException(ex);
}
// transaction
try {
this.transactionHelper.startTransaction();
PaymentDto deposit = deposit(depositDto, true);
PaymentDto withdrawal = withdraw(withdrawalDto, true);
// connect the two payments
AccountPaymentEntity sourcePayment = sourceAcc.findPaymentById(withdrawal.getPaymentId());
AccountPaymentEntity targetPayment = targetAcc.findPaymentById(deposit.getPaymentId());
sourcePayment.setOtherTransferPayment(targetPayment);
targetPayment.setOtherTransferPayment(sourcePayment);
this.savingsDao.save(sourceAcc);
this.savingsDao.save(targetAcc);
this.transactionHelper.commitTransaction();
} catch (BusinessRuleException ex) {
this.transactionHelper.rollbackTransaction();
throw ex;
} catch (Exception ex) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(ex);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.dto.domain.SavingsDepositDto in project head by mifos.
the class K2RESTController method processSavingsDeposit.
private Map<String, String> processSavingsDeposit(SavingsBO savingsBO, String k2TransactionId, String mmSystemId, LocalDate transactionDate, BigDecimal amount, String currency) throws Exception {
Integer paymentTypeId = null;
List<PaymentTypeDto> savingsPaymentTypes = accountService.getSavingsPaymentTypes();
for (PaymentTypeDto paymentTypeDtoIterator : savingsPaymentTypes) {
if (paymentTypeDtoIterator.getName().equals(mmSystemId)) {
paymentTypeId = paymentTypeDtoIterator.getValue().intValue();
}
}
if (paymentTypeId == null || !savingsBO.getCurrency().getCurrencyCode().equals(currency)) {
return invalidPayment();
}
Long accountId = savingsBO.getAccountId().longValue();
Long customerId = savingsBO.getCustomer().getCustomerId().longValue();
String receiptIdString = k2TransactionId;
SavingsDepositDto savingsDeposit = new SavingsDepositDto(accountId, customerId, transactionDate, amount.doubleValue(), paymentTypeId, receiptIdString, transactionDate, Locale.UK);
this.savingsServiceFacade.deposit(savingsDeposit);
return accepted();
}
use of org.mifos.dto.domain.SavingsDepositDto 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