use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanScheduleEntity method getTotalFeeAmountPaidWithMiscFee.
public Money getTotalFeeAmountPaidWithMiscFee() {
Money totalFees = new Money(getCurrency());
for (AccountFeesActionDetailEntity obj : accountFeesActionDetails) {
totalFees = totalFees.add(obj.getFeeAmountPaid());
}
totalFees = totalFees.add(getMiscFeePaid());
return totalFees;
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanScheduleEntity method removeFees.
Money removeFees(Short feeId) {
Money feeAmount = null;
AccountFeesActionDetailEntity objectToRemove = null;
Set<AccountFeesActionDetailEntity> accountFeesActionDetailSet = this.getAccountFeesActionDetails();
for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountFeesActionDetailSet) {
if (accountFeesActionDetailEntity.getFee().getFeeId().equals(feeId) && (accountFeesActionDetailEntity.getFeeAmountPaid() == null || accountFeesActionDetailEntity.getFeeAmountPaid().isZero())) {
objectToRemove = accountFeesActionDetailEntity;
feeAmount = objectToRemove.getFeeAmount();
break;
} else if (accountFeesActionDetailEntity.getFee().getFeeId().equals(feeId) && accountFeesActionDetailEntity.getFeeAmountPaid() != null && accountFeesActionDetailEntity.getFeeAmountPaid().isGreaterThanZero()) {
feeAmount = accountFeesActionDetailEntity.getFeeAmount().subtract(accountFeesActionDetailEntity.getFeeAmountPaid());
((LoanFeeScheduleEntity) accountFeesActionDetailEntity).setFeeAmount(accountFeesActionDetailEntity.getFeeAmountPaid());
break;
}
}
if (objectToRemove != null) {
this.removeAccountFeesActionDetailEntity(objectToRemove);
}
return feeAmount;
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentSchedule.
@Override
public List<LoanRepaymentScheduleItemDto> retrieveLoanRepaymentSchedule(String globalAccountNum, Date viewDate) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
try {
personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
Errors errors = loanBusinessService.computeExtraInterest(loanBO, viewDate);
if (errors.hasErrors()) {
throw new MifosRuntimeException(errors.getErrorEntries().get(0).getDefaultMessage());
}
List<LoanRepaymentScheduleItemDto> loanSchedule = new ArrayList<LoanRepaymentScheduleItemDto>();
for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) {
LoanScheduleEntity loanAccountAction = (LoanScheduleEntity) accountAction;
Set<AccountFeesActionDetailEntity> feeEntities = loanAccountAction.getAccountFeesActionDetails();
List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
feeDtos.add(convertToDto(feeEntity));
}
loanSchedule.add(new LoanRepaymentScheduleItemDto(loanAccountAction.getInstallmentId(), loanAccountAction.getActionDate(), loanAccountAction.getPaymentStatus(), loanAccountAction.getPaymentDate(), loanAccountAction.getPrincipal().toString(), loanAccountAction.getPrincipalPaid().toString(), loanAccountAction.getInterest().toString(), loanAccountAction.getInterestPaid().toString(), loanAccountAction.getPenalty().toString(), loanAccountAction.getPenaltyPaid().toString(), loanAccountAction.getExtraInterest().toString(), loanAccountAction.getExtraInterestPaid().toString(), loanAccountAction.getMiscFee().toString(), loanAccountAction.getMiscFeePaid().toString(), loanAccountAction.getMiscPenalty().toString(), loanAccountAction.getMiscPenaltyPaid().toString(), feeDtos));
}
return loanSchedule;
}
use of org.mifos.accounts.business.AccountFeesActionDetailEntity 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.AccountFeesActionDetailEntity in project head by mifos.
the class CustomerAccountBO method applyFeeToInstallments.
private Money applyFeeToInstallments(final List<FeeInstallment> feeInstallmentList, final List<AccountActionDateEntity> accountActionDateList) {
Date lastAppliedDate = null;
Money totalFeeAmountApplied = new Money(getCurrency());
AccountFeesEntity accountFeesEntity = null;
for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
for (FeeInstallment feeInstallment : feeInstallmentList) {
if (feeInstallment.getInstallmentId().equals(customerScheduleEntity.getInstallmentId())) {
lastAppliedDate = customerScheduleEntity.getActionDate();
totalFeeAmountApplied = totalFeeAmountApplied.add(feeInstallment.getAccountFee());
AccountFeesActionDetailEntity accountFeesActionDetailEntity = new CustomerFeeScheduleEntity(customerScheduleEntity, feeInstallment.getAccountFeesEntity().getFees(), feeInstallment.getAccountFeesEntity(), feeInstallment.getAccountFee());
customerScheduleEntity.addAccountFeesAction(accountFeesActionDetailEntity);
accountFeesEntity = feeInstallment.getAccountFeesEntity();
}
}
}
if (accountFeesEntity != null) {
accountFeesEntity.setLastAppliedDate(lastAppliedDate);
addAccountFees(accountFeesEntity);
}
return totalFeeAmountApplied;
}
Aggregations