use of org.mifos.accounts.util.helpers.AccountPaymentData in project head by mifos.
the class SavingsBO method makePayment.
/**
* @deprecated for deposits use {@link SavingsBO#deposit(AccountPaymentEntity, Integer)} and withdrawals use
* {@link SavingsBO#withdraw(AccountPaymentEntity)}
*/
@Deprecated
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
Money totalAmount = paymentData.getTotalAmount();
Money enteredAmount = totalAmount;
Date transactionDate = paymentData.getTransactionDate();
List<AccountPaymentData> accountPayments = paymentData.getAccountPayments();
if (paymentData.getCustomer() == null) {
throw new NullPointerException("Customer in payment data during payment should not be null");
}
CustomerBO customer = paymentData.getCustomer();
AccountPaymentEntity accountPayment = new AccountPaymentEntity(this, totalAmount, paymentData.getReceiptNum(), paymentData.getReceiptDate(), getPaymentTypeEntity(paymentData.getPaymentTypeId()), transactionDate);
accountPayment.setCreatedByUser(paymentData.getPersonnel());
accountPayment.setComment(paymentData.getComment());
// make savings account active if inactive
if (this.getState().getValue().equals(AccountState.SAVINGS_INACTIVE.getValue())) {
this.changeStatus(AccountState.SAVINGS_ACTIVE, null, "Account Made Active Due to Payment", paymentData.getPersonnel());
}
if (totalAmount.isGreaterThanZero() && paymentData.getAccountPayments().size() <= 0) {
SavingsTrxnDetailEntity accountTrxn = buildUnscheduledDeposit(accountPayment, totalAmount, paymentData.getPersonnel(), customer, transactionDate);
accountPayment.addAccountTrxn(accountTrxn);
addSavingsActivityDetails(buildSavingsActivity(totalAmount, getSavingsBalance(), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), transactionDate, paymentData.getPersonnel()));
return accountPayment;
}
for (AccountPaymentData accountPaymentData : accountPayments) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(accountPaymentData.getInstallmentId(), customer.getCustomerId());
if (accountAction != null && depositAmountIsInExcess(enteredAmount)) {
if (accountAction.isPaid()) {
throw new AccountException("errors.update", new String[] { getGlobalAccountNum() });
}
Money depositAmount = new Money(getCurrency());
PaymentStatus paymentStatus = PaymentStatus.UNPAID;
if (enteredAmount.isGreaterThanOrEqual(accountAction.getTotalDepositDue())) {
depositAmount = accountAction.getTotalDepositDue();
enteredAmount = enteredAmount.subtract(accountAction.getTotalDepositDue());
paymentStatus = PaymentStatus.PAID;
} else {
depositAmount = enteredAmount;
enteredAmount = new Money(getCurrency());
}
if (this.isVoluntary() && depositAmountIsInExcess(depositAmount)) {
paymentStatus = PaymentStatus.PAID;
}
savingsBalance = savingsBalance.add(depositAmount);
savingsPerformance.setPaymentDetails(depositAmount);
accountAction.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
Short installmentId = accountAction.getInstallmentId();
SavingsTrxnDetailEntity accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(accountPayment, customer, this.savingsBalance, depositAmount, paymentData.getPersonnel(), accountAction.getActionDate(), paymentData.getTransactionDate(), paymentData.getTransactionDate(), installmentId);
accountPayment.addAccountTrxn(accountTrxn);
}
}
if (depositAmountIsInExcess(enteredAmount)) {
SavingsTrxnDetailEntity accountTrxn = buildUnscheduledDeposit(accountPayment, enteredAmount, paymentData.getPersonnel(), customer, transactionDate);
accountPayment.addAccountTrxn(accountTrxn);
}
addSavingsActivityDetails(buildSavingsActivity(totalAmount, getSavingsBalance(), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), transactionDate, paymentData.getPersonnel()));
return accountPayment;
}
use of org.mifos.accounts.util.helpers.AccountPaymentData in project head by mifos.
the class SavingsServiceFacadeWebTier method deposit.
@Override
public PaymentDto deposit(SavingsDepositDto savingsDeposit, boolean inTransaction) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsDeposit.getSavingsId());
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
savingsAccount.updateDetails(userContext);
PersonnelBO createdBy = this.personnelDao.findPersonnelById(Short.valueOf((short) user.getUserId()));
CustomerBO customer = this.customerDao.findCustomerById(savingsDeposit.getCustomerId().intValue());
Money totalAmount = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsDeposit.getAmount()));
PaymentData payment = PaymentData.createPaymentData(totalAmount, createdBy, savingsDeposit.getModeOfPayment().shortValue(), savingsDeposit.getDateOfDeposit().toDateMidnight().toDate());
if (savingsDeposit.getDateOfReceipt() != null) {
payment.setReceiptDate(savingsDeposit.getDateOfReceipt().toDateMidnight().toDate());
}
payment.setReceiptNum(savingsDeposit.getReceiptId());
payment.setCustomer(customer);
for (AccountActionDateEntity installment : savingsAccount.getTotalInstallmentsDue(savingsDeposit.getCustomerId().intValue())) {
AccountPaymentData accountPaymentData = new SavingsPaymentData(installment);
payment.addAccountPaymentData(accountPaymentData);
}
try {
if (!inTransaction) {
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(savingsAccount);
}
AccountPaymentEntity newPaymentEntity = savingsAccount.applyPayment(payment);
this.savingsDao.save(savingsAccount);
Date lastIntPostDate = savingsAccount.getLastIntPostDate();
if (lastIntPostDate != null && DateUtils.dateFallsOnOrBeforeDate(payment.getTransactionDate(), lastIntPostDate)) {
this.recalculateInterestPostings(savingsAccount.getAccountId(), new LocalDate(payment.getTransactionDate()));
}
// commit
if (inTransaction) {
this.transactionHelper.flushSession();
} else {
this.transactionHelper.commitTransaction();
}
return newPaymentEntity.toDto();
} catch (AccountException e) {
if (!inTransaction) {
this.transactionHelper.rollbackTransaction();
}
throw new BusinessRuleException(e.getKey(), e);
} finally {
if (!inTransaction) {
this.transactionHelper.closeSession();
}
}
}
Aggregations