use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveAdjustmentReferenceData.
@Override
public SavingsAdjustmentReferenceDto retrieveAdjustmentReferenceData(Long savingsId) {
SavingsBO savings = savingsDao.findById(savingsId);
AccountPaymentEntity lastPayment = savings.findMostRecentPaymentByPaymentDate();
Integer paymentId = (lastPayment == null) ? null : lastPayment.getPaymentId();
return retrieveAdjustmentReferenceData(savingsId, paymentId);
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveTransactionHistory.
@Override
public List<SavingsTransactionHistoryDto> retrieveTransactionHistory(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
CustomerBO customerBO = savingsAccount.getCustomer();
savingsAccount.updateDetails(userContext);
try {
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
List<SavingsTransactionHistoryDto> savingsTransactionHistoryViewList = new ArrayList<SavingsTransactionHistoryDto>();
// Check for order-by clause in AccountBO.hbm.xml,
// AccountPayment.hbm.xml and AccountTrxnEntity.hbm.xml for
// accountPaymentSet ,
// accountTrxnSet and financialBoSet. They all should be set for their
// primay key column desc in both. If stated is not there, the code
// below will behave abnormally.
List<AccountPaymentEntity> accountPaymentSet = savingsAccount.getAccountPayments();
for (AccountPaymentEntity accountPaymentEntity : accountPaymentSet) {
Set<AccountTrxnEntity> accountTrxnEntitySet = accountPaymentEntity.getAccountTrxns();
for (AccountTrxnEntity accountTrxnEntity : accountTrxnEntitySet) {
Set<FinancialTransactionBO> financialTransactionBOSet = accountTrxnEntity.getFinancialTransactions();
for (FinancialTransactionBO financialTransactionBO : financialTransactionBOSet) {
SavingsTransactionHistoryDto savingsTransactionHistoryDto = new SavingsTransactionHistoryDto();
savingsTransactionHistoryDto.setTransactionDate(financialTransactionBO.getActionDate());
String preferredTransactionDate = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), financialTransactionBO.getActionDate().toString());
savingsTransactionHistoryDto.setUserPrefferedTransactionDate(preferredTransactionDate);
savingsTransactionHistoryDto.setPaymentId(accountTrxnEntity.getAccountPayment().getPaymentId());
savingsTransactionHistoryDto.setAccountTrxnId(accountTrxnEntity.getAccountTrxnId());
savingsTransactionHistoryDto.setType(financialTransactionBO.getFinancialAction().getName());
savingsTransactionHistoryDto.setGlcode(financialTransactionBO.getGlcode().getGlcode());
savingsTransactionHistoryDto.setGlname(financialTransactionBO.getGlcode().getAssociatedCOA().getAccountName());
if (financialTransactionBO.isDebitEntry()) {
savingsTransactionHistoryDto.setDebit(String.valueOf(removeSign(financialTransactionBO.getPostedAmount())));
} else if (financialTransactionBO.isCreditEntry()) {
savingsTransactionHistoryDto.setCredit(String.valueOf(removeSign(financialTransactionBO.getPostedAmount())));
}
savingsTransactionHistoryDto.setBalance(String.valueOf(removeSign(((SavingsTrxnDetailEntity) accountTrxnEntity).getBalance())));
savingsTransactionHistoryDto.setClientName(accountTrxnEntity.getCustomer().getDisplayName());
savingsTransactionHistoryDto.setPostedDate(financialTransactionBO.getPostedDate());
String preferredDate = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), financialTransactionBO.getPostedDate().toString());
savingsTransactionHistoryDto.setUserPrefferedPostedDate(preferredDate);
if (accountTrxnEntity.getPersonnel() != null) {
savingsTransactionHistoryDto.setPostedBy(accountTrxnEntity.getPersonnel().getDisplayName());
}
if (financialTransactionBO.getNotes() != null && !financialTransactionBO.getNotes().equals("")) {
savingsTransactionHistoryDto.setNotes(financialTransactionBO.getNotes());
}
savingsTransactionHistoryViewList.add(savingsTransactionHistoryDto);
}
}
}
return savingsTransactionHistoryViewList;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsServiceFacadeWebTier method retrievePaymentsForAdjustment.
@Override
public List<AdjustableSavingsPaymentDto> retrievePaymentsForAdjustment(Integer accountId) {
SavingsBO savingsAccount = this.savingsDao.findById(accountId);
List<AdjustableSavingsPaymentDto> adjustablePayments = new ArrayList<AdjustableSavingsPaymentDto>();
for (AccountPaymentEntity payment : savingsAccount.getAccountPayments()) {
if (payment.isSavingsDepositOrWithdrawal() && payment.getAmount().isGreaterThan(Money.zero())) {
AdjustableSavingsPaymentDto adjustableSavingsPaymentDto = new AdjustableSavingsPaymentDto(payment.getPaymentId(), payment.getReceiptNumber(), payment.getAmount().getAmount(), new LocalDate(payment.getPaymentDate()), (payment.getReceiptDate() == null) ? null : new LocalDate(payment.getReceiptDate()), payment.getPaymentType().getName(), payment.isSavingsDeposit());
adjustablePayments.add(adjustableSavingsPaymentDto);
}
}
Collections.sort(adjustablePayments, new Comparator<AdjustableSavingsPaymentDto>() {
@Override
public int compare(AdjustableSavingsPaymentDto o1, AdjustableSavingsPaymentDto o2) {
int result;
LocalDate firstDate = o1.getPaymentDate();
LocalDate secondDate = o2.getPaymentDate();
// sort by date
if (firstDate.isAfter(secondDate)) {
result = -1;
} else if (firstDate.isBefore(secondDate)) {
result = 1;
} else {
// withdrawal comes after deposit
if (o1.isWithdrawal() && !o2.isWithdrawal()) {
result = -1;
} else if (!o1.isWithdrawal() && o2.isWithdrawal()) {
result = 1;
} else {
result = 0;
}
}
return result;
}
});
return adjustablePayments;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class CustomerAccountBO method makePayment.
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
Money totalPaid = paymentData.getTotalAmount();
if (totalPaid.isZero()) {
throw new AccountException("errors.update", new String[] { "Attempting to pay a customer account balance of zero for customer: " + paymentData.getCustomer().getGlobalCustNum() });
}
final List<CustomerScheduleEntity> customerAccountPayments = findAllUnpaidInstallmentsUpToDatePlusNextMeeting(paymentData.getTransactionDate());
if (customerAccountPayments.isEmpty()) {
throw new AccountException(AccountConstants.NO_TRANSACTION_POSSIBLE, new String[] { "Trying to pay account charges before the due date." });
}
Money totalAllUnpaidInstallments = new Money(totalPaid.getCurrency(), "0.0");
for (CustomerScheduleEntity customerSchedule : customerAccountPayments) {
totalAllUnpaidInstallments = totalAllUnpaidInstallments.add(new Money(totalPaid.getCurrency(), dueAmountForCustomerSchedule(customerSchedule)));
}
if (totalAllUnpaidInstallments.compareTo(totalPaid) < 0) {
throw new AccountException(AccountConstants.NO_TRANSACTION_POSSIBLE, new String[] { "Overpayments are not supported" });
}
final AccountPaymentEntity accountPayment = new AccountPaymentEntity(this, paymentData.getTotalAmount(), paymentData.getReceiptNum(), paymentData.getReceiptDate(), getPaymentTypeEntity(paymentData.getPaymentTypeId()), paymentData.getTransactionDate());
BigDecimal leftFromPaidIn = totalPaid.getAmount();
for (CustomerScheduleEntity customerSchedule : customerAccountPayments) {
if (leftFromPaidIn.compareTo(BigDecimal.ZERO) == 0) {
break;
}
final List<FeesTrxnDetailEntity> feeTrxns = new ArrayList<FeesTrxnDetailEntity>();
for (AccountFeesActionDetailEntity accountFeesActionDetail : customerSchedule.getAccountFeesActionDetails()) {
if (leftFromPaidIn.compareTo(BigDecimal.ZERO) > 0) {
CustomerFeeScheduleEntity customerFeeSchedule = (CustomerFeeScheduleEntity) accountFeesActionDetail;
BigDecimal feeFromScheduleToPay = leftFromPaidIn.min(customerFeeSchedule.getFeeDue().getAmount());
customerFeeSchedule.makePayment(new Money(totalPaid.getCurrency(), feeFromScheduleToPay));
final FeesTrxnDetailEntity feesTrxnDetailBO = new FeesTrxnDetailEntity(null, customerFeeSchedule.getAccountFee(), new Money(totalPaid.getCurrency(), feeFromScheduleToPay));
feeTrxns.add(feesTrxnDetailBO);
leftFromPaidIn = leftFromPaidIn.subtract(feeFromScheduleToPay);
}
}
BigDecimal miscPenaltyToPay = leftFromPaidIn.min(customerSchedule.getMiscPenaltyDue().getAmount());
if (miscPenaltyToPay.compareTo(BigDecimal.ZERO) > 0) {
customerSchedule.payMiscPenalty(new Money(totalPaid.getCurrency(), miscPenaltyToPay));
customerSchedule.setPaymentDate(new java.sql.Date(paymentData.getTransactionDate().getTime()));
leftFromPaidIn = leftFromPaidIn.subtract(miscPenaltyToPay);
}
BigDecimal miscFeeToPay = BigDecimal.ZERO;
if (leftFromPaidIn.compareTo(BigDecimal.ZERO) > 0) {
miscFeeToPay = leftFromPaidIn.min(customerSchedule.getMiscFeeDue().getAmount());
if (miscFeeToPay.compareTo(BigDecimal.ZERO) > 0) {
customerSchedule.payMiscFee(new Money(totalPaid.getCurrency(), miscFeeToPay));
customerSchedule.setPaymentDate(new java.sql.Date(paymentData.getTransactionDate().getTime()));
leftFromPaidIn = leftFromPaidIn.subtract(miscFeeToPay);
}
}
if (dueAmountForCustomerSchedule(customerSchedule).compareTo(BigDecimal.ZERO) == 0) {
customerSchedule.setPaymentStatus(PaymentStatus.PAID);
}
Money customerScheduleAmountPaid = new Money(totalPaid.getCurrency(), miscFeeToPay.add(miscPenaltyToPay));
final CustomerTrxnDetailEntity accountTrxn = new CustomerTrxnDetailEntity(accountPayment, AccountActionTypes.CUSTOMER_ACCOUNT_REPAYMENT, customerSchedule.getInstallmentId(), customerSchedule.getActionDate(), paymentData.getPersonnel(), paymentData.getTransactionDate(), customerScheduleAmountPaid, AccountConstants.PAYMENT_RCVD, null, new Money(totalPaid.getCurrency(), miscFeeToPay), new Money(totalPaid.getCurrency(), miscPenaltyToPay));
for (FeesTrxnDetailEntity feesTrxnDetailEntity : feeTrxns) {
accountTrxn.addFeesTrxnDetail(feesTrxnDetailEntity);
feesTrxnDetailEntity.setAccountTrxn(accountTrxn);
}
accountPayment.addAccountTrxn(accountTrxn);
}
addCustomerActivity(new CustomerActivityEntity(this, paymentData.getPersonnel(), paymentData.getTotalAmount(), AccountConstants.PAYMENT_RCVD, paymentData.getTransactionDate()));
return accountPayment;
}
use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.
the class SavingsTestHelper method createAccountPaymentToPersist.
public AccountPaymentEntity createAccountPaymentToPersist(AccountBO account, Money amount, Money balance, Date trxnDate, Short accountAction, SavingsBO savingsObj, PersonnelBO createdBy, CustomerBO customer) throws Exception {
AccountPaymentEntity payment = createAccountPayment(account, amount, new Date(), createdBy);
SavingsTrxnDetailEntity savingsTrxnDetail = SavingsTrxnDetailEntity.savingsAdjustment(payment, customer, balance, amount, createdBy, trxnDate, trxnDate, new DateTime().toDate(), "", null);
payment.addAccountTrxn(savingsTrxnDetail);
return payment;
}
Aggregations