use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.
the class LoanBO method applyPaymentToMemberAccounts.
@SuppressWarnings("unused")
@Deprecated
private void applyPaymentToMemberAccounts(PaymentData paymentData) throws AccountException {
Money totalPaymentAmount = paymentData.getTotalAmount();
for (LoanBO memberAccount : this.memberAccounts) {
BigDecimal factor = memberAccount.calcFactorOfEntireLoan();
Money memberPaymentAmount = totalPaymentAmount.divide(factor);
memberPaymentAmount = MoneyUtils.currencyRound(memberPaymentAmount);
PaymentData memberPayment;
if (getState().getValue() == (short) 6) {
memberPayment = new PaymentData(memberAccount.getTotalRepayableAmount(), paymentData.getPersonnel(), paymentData.getPaymentTypeId(), paymentData.getTransactionDate());
} else {
memberPayment = new PaymentData(memberPaymentAmount, paymentData.getPersonnel(), paymentData.getPaymentTypeId(), paymentData.getTransactionDate());
}
memberAccount.applyPayment(memberPayment);
}
}
use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.
the class LoanBO method adjustLastPayment.
@Override
public void adjustLastPayment(final String adjustmentComment, PersonnelBO loggedInUser) throws AccountException {
if (isAdjustPossibleOnLastTrxn()) {
logger.debug("Adjustment is possible hence attempting to adjust.");
AccountPaymentEntity lastPmntToBeAdjusted = getLastPmntToBeAdjusted();
Money equalizingPaymentAmount = lastPmntToBeAdjusted.getAmount();
short equalizingPaymentTypeId = lastPmntToBeAdjusted.getPaymentType().getId();
Date equalizingPaymentDate = lastPmntToBeAdjusted.getPaymentDate();
adjustPayment(lastPmntToBeAdjusted, loggedInUser, adjustmentComment);
if (hasMemberAccounts()) {
for (LoanBO memberAccount : this.memberAccounts) {
memberAccount.setUserContext(this.userContext);
if (memberAccount.isGroupLoanAccountMember()) {
memberAccount.adjustLastPaymentForMember(lastPmntToBeAdjusted, adjustmentComment, loggedInUser);
} else {
memberAccount.adjustLastPayment(adjustmentComment, loggedInUser);
}
}
//MIFOS-5742: equalizing payment made to solve the problem with adjusting very small payment on GLIM account
PaymentData equalizingPaymentData = new PaymentData(equalizingPaymentAmount, loggedInUser, equalizingPaymentTypeId, equalizingPaymentDate);
BigDecimal installmentsPaid = findNumberOfPaidInstallments();
applyPaymentToMemberAccounts(equalizingPaymentData, installmentsPaid);
}
} else if (this.parentAccount == null) {
//MIFOS-5694: if member account has no payments it could mean that payment was made before 2.4.0, remove this condition when MIFOS-5692 is done
throw new AccountException(AccountExceptionConstants.CANNOTADJUST);
}
}
use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.
the class LoanBO method applyNewPaymentMechanism.
public Money applyNewPaymentMechanism(LocalDate paymentDate, BigDecimal repaymentAmount, PersonnelBO user, String receiptId, LocalDate receiptDate, Short modeOfPayment) throws AccountException {
Money totalAmount = new Money(getCurrency(), repaymentAmount);
Date transactionDate = paymentDate.toDateMidnight().toDate();
PaymentData paymentData = new PaymentData(totalAmount, user, modeOfPayment, transactionDate);
if (receiptId != null) {
paymentData.setReceiptNum(receiptId);
}
if (receiptDate != null) {
paymentData.setReceiptDate(receiptDate.toDateMidnight().toDate());
}
AccountPaymentEntity accountPaymentEntity = prePayment(paymentData);
Money balance = totalAmount;
LoanPaymentTypes loanPaymentType = getLoanPaymentType(paymentData.getTotalAmount());
// 1. pay off installments in arrears
List<AccountActionDateEntity> inArrears = getDetailsOfInstallmentsInArrearsOn(paymentDate);
for (AccountActionDateEntity accountActionDate : inArrears) {
balance = ((LoanScheduleEntity) accountActionDate).applyPayment(accountPaymentEntity, balance, user, transactionDate);
}
// 2. pay off due installment (normal way)
if (balance.isGreaterThanZero()) {
AccountActionDateEntity upcomingInstallment = getDetailsOfNextInstallmentOn(paymentDate);
balance = ((LoanScheduleEntity) upcomingInstallment).applyPayment(accountPaymentEntity, balance, user, transactionDate);
}
if (!accountPaymentEntity.getAccountTrxns().isEmpty()) {
postPayment(paymentData, accountPaymentEntity, loanPaymentType);
addAccountPayment(accountPaymentEntity);
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
}
return balance;
}
use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.
the class LoanBO method applyMifos5722Fix.
public void applyMifos5722Fix() throws AccountException, PersistenceException {
if (!validateNoOfInstallments(getMemberAccounts().iterator().next()))
return;
PersonnelBO personnel = legacyPersonnelDao.getPersonnel((short) 1);
UserContext userContext = new UserContext();
userContext.setId(PersonnelConstants.SYSTEM_USER);
String comment = "Mifos-5722";
//clear accounts from previous payments
for (LoanBO memberAccount : getMemberAccounts()) {
memberAccount.setUserContext(userContext);
memberAccount.setAccountState(getAccountState());
for (AccountPaymentEntity payment : memberAccount.getAccountPayments()) {
memberAccount.adjustPayment(payment, personnel, comment);
}
}
List<LoanScheduleEntity> parentInstallments = getLoanInstallments();
for (LoanBO memberAccount : getMemberAccounts()) {
List<LoanScheduleEntity> memberInstallments = memberAccount.getLoanInstallments();
for (int i = 0; i < parentInstallments.size(); i++) {
LoanScheduleEntity parentInstallment = parentInstallments.get(i);
LoanScheduleEntity memberInstallment = memberInstallments.get(i);
//remove fees and penalties from installment
memberInstallment.removeAllFees();
memberInstallment.removeAllPenalties();
equalizeMiscFeesAndPenaltiesOnInstallments(parentInstallment, memberInstallment, memberAccount.calcFactorOfEntireLoan());
}
//remove fees and penalties from account
while (memberAccount.getAccountFeesIncludingInactiveFees().iterator().hasNext()) {
AccountFeesEntity fee = memberAccount.getAccountFeesIncludingInactiveFees().iterator().next();
memberAccount.getAccountFeesIncludingInactiveFees().remove(fee);
}
while (memberAccount.getAccountPenaltiesIncludingInactivePenalties().iterator().hasNext()) {
AccountPenaltiesEntity penalty = memberAccount.getAccountPenaltiesIncludingInactivePenalties().iterator().next();
memberAccount.getAccountPenaltiesIncludingInactivePenalties().remove(penalty);
}
}
//apply fees and penalties
Set<AccountFeesEntity> fees = getAccountFees();
Set<AccountPenaltiesEntity> penalties = getAccountPenalties();
for (LoanBO memberAccount : getMemberAccounts()) {
for (AccountFeesEntity fee : fees) {
try {
if (fee.getFees().getFeeType() == RateAmountFlag.RATE) {
RateFeeBO fbo = getFeeDao().findRateFeeById(fee.getFees().getFeeId());
if (fbo != null) {
memberAccount.applyChargeMifos5722(fee.getFees().getFeeId(), fbo.getRate());
}
} else {
memberAccount.applyChargeMifos5722(fee.getFees().getFeeId(), fee.getFeeAmount() / memberAccount.calcFactorOfEntireLoan().doubleValue());
}
} catch (AccountException e) {
e.printStackTrace();
}
for (AccountPenaltiesEntity penalty : penalties) {
memberAccount.addAccountPenalty(penalty);
}
}
}
applyAllPenaltiesToMemberAccounts();
List<AccountPaymentEntity> parentPayments = getAccountPayments();
BigDecimal currentAmount = BigDecimal.ZERO;
for (int i = parentPayments.size() - 2; i >= 0; i--) {
AccountPaymentEntity currentPayment = parentPayments.get(i);
currentAmount = currentAmount.add(currentPayment.getAmount().getAmount());
BigDecimal currentProportion = findNumberOfInstallmentsPaidByAmount(currentAmount);
PaymentData paymentData = new PaymentData(currentPayment.getAmount(), personnel, currentPayment.getPaymentType().getId(), currentPayment.getPaymentDate());
applyPaymentToMemberAccounts(paymentData, currentProportion);
}
}
use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.
the class LoanBO method applyPaymentToMemberAccounts.
/** Makes payments for member accounts that will equalize number of paid installments to installmentsPaid parameter
* Example: member accounts have currently paid 2.5 installments,
* after calling this method with installmentsPaid = 5.3,
* it will make payments for member accounts that pays 2.8 installments,
* so after all member accounts will have 5,3 installments paid.
*
* @param installmentsPaid - number of installments that are currently paid on parent account.
*
*/
private void applyPaymentToMemberAccounts(PaymentData paymentData, BigDecimal installmentsPaid) throws AccountException {
if (!isGroupLoanAccount()) {
for (LoanBO memberAccount : getMemberAccounts()) {
if (validateNoOfInstallments(memberAccount)) {
BigDecimal memberPaid = memberAccount.findNumberOfPaidInstallments();
List<LoanScheduleEntity> memberInstallments = memberAccount.getLoanInstallments();
Money memberPaymentAmount = new Money(getCurrency());
int currentPayment;
//Full payments for installments that are expected to be paid fully
for (currentPayment = memberPaid.intValue(); currentPayment < installmentsPaid.intValue(); currentPayment++) {
memberPaymentAmount = memberPaymentAmount.add(memberInstallments.get(currentPayment).getAmountToBePaidToGetExpectedProportion(BigDecimal.ONE));
}
BigDecimal afterComa = installmentsPaid.subtract(new BigDecimal(installmentsPaid.intValue()));
//If there is fraction in number of installments to be paid
if (afterComa.compareTo(BigDecimal.ZERO) == 1) {
memberPaymentAmount = memberPaymentAmount.add(memberInstallments.get(currentPayment).getAmountToBePaidToGetExpectedProportion(afterComa));
}
//It prevents member account to be closed before parent due to small last payments in parent account. Member accounts will remain in minimalPayment unpaid until last payment for parent account will be submitted
if (getState().compareTo(AccountState.LOAN_CLOSED_OBLIGATIONS_MET) != 0 && memberPaymentAmount.subtract((memberAccount.getTotalRepayableAmount())).isTinyAmount()) {
Double minimalPayment = Math.pow(10.0, (double) -AccountingRules.getDigitsAfterDecimal());
memberPaymentAmount = memberPaymentAmount.subtract(new Money(getCurrency(), minimalPayment));
}
memberPaymentAmount = MoneyUtils.currencyRound(memberPaymentAmount);
PaymentData memberPayment = new PaymentData(memberPaymentAmount, paymentData.getPersonnel(), paymentData.getPaymentTypeId(), paymentData.getTransactionDate());
if (!memberPaymentAmount.isTinyAmount() && !memberPaymentAmount.isLessThanZero()) {
memberAccount.applyPayment(memberPayment);
}
}
}
}
}
Aggregations