use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsBO method createNewAccountPaymentWithAdjustedAmount.
private Set<AccountTrxnEntity> createNewAccountPaymentWithAdjustedAmount(Money amountAdjustedTo, PersonnelBO updatedBy, AccountPaymentEntity payment, AccountActionTypes savingsTransactionType, Date adjustedOn, LocalDate adjustmentDate) {
AccountPaymentEntity newAccountPayment = new AccountPaymentEntity(this, amountAdjustedTo, payment.getReceiptNumber(), payment.getReceiptDate(), payment.getPaymentType(), adjustmentDate.toDateMidnight().toDate());
newAccountPayment.setCreatedByUser(updatedBy);
newAccountPayment.setAmount(amountAdjustedTo);
Set<AccountTrxnEntity> accountTrxns = new HashSet<AccountTrxnEntity>();
if (isMandatory() && savingsTransactionType.equals(AccountActionTypes.SAVINGS_DEPOSIT)) {
accountTrxns = createDepositTrxnsForMandatoryAccountsAfterAdjust(newAccountPayment, payment, amountAdjustedTo, adjustmentDate, updatedBy);
} else if (isVoluntary() && savingsTransactionType.equals(AccountActionTypes.SAVINGS_DEPOSIT)) {
accountTrxns = createDepositTrxnsForVolAccountsAfterAdjust(newAccountPayment, payment, amountAdjustedTo, adjustmentDate, updatedBy);
} else {
accountTrxns = createWithdrawalTrxnsAfterAdjust(newAccountPayment, payment, amountAdjustedTo, adjustmentDate, updatedBy);
}
for (AccountTrxnEntity accountTrxn : accountTrxns) {
newAccountPayment.addAccountTrxn(accountTrxn);
}
this.addAccountPayment(newAccountPayment);
AccountActionEntity depositOrWithdrawalTransactionType = new AccountActionEntity(savingsTransactionType);
SavingsActivityEntity depositOrWithdrawalActivity = new SavingsActivityEntity(updatedBy, depositOrWithdrawalTransactionType, amountAdjustedTo, this.savingsBalance, adjustedOn, this);
this.savingsActivityDetails.add(depositOrWithdrawalActivity);
return newAccountPayment.getAccountTrxns();
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsBO method createWithdrawalTrxnsAfterAdjust.
private Set<AccountTrxnEntity> createWithdrawalTrxnsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, final Money newAmount, final LocalDate adjustmentDate, PersonnelBO loggedInUser) {
Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
SavingsTrxnDetailEntity accountTrxn = null;
// create transaction for withdrawal
SavingsTrxnDetailEntity oldSavingsAccntTrxn = null;
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
break;
}
this.savingsBalance = this.savingsBalance.subtract(newAmount);
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsWithdrawal(newAccountPayment, oldSavingsAccntTrxn.getCustomer(), newAmount, newAmount, loggedInUser, oldSavingsAccntTrxn.getDueDate(), adjustmentDate.toDateMidnight().toDate(), transactionCreatedDate);
this.savingsPerformance.setTotalWithdrawals(this.savingsPerformance.getTotalWithdrawals().add(accountTrxn.getWithdrawlAmount()));
newTrxns.add(accountTrxn);
return newTrxns;
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsBO method withdrawalAdjustmentDoesNotMakeBalanceNegative.
private boolean withdrawalAdjustmentDoesNotMakeBalanceNegative(final AccountPaymentEntity accountPayment, final Money amountAdjustedTo) {
boolean balanceIsPositive = true;
Money balanceAfterAdjust = this.savingsBalance;
for (AccountTrxnEntity accntTrxn : accountPayment.getAccountTrxns()) {
SavingsTrxnDetailEntity savingsTrxn = (SavingsTrxnDetailEntity) accntTrxn;
if (accountPayment.isSavingsWithdrawal() && amountAdjustedTo.isGreaterThan(savingsTrxn.getWithdrawlAmount())) {
balanceAfterAdjust = balanceAfterAdjust.subtract(amountAdjustedTo.subtract(savingsTrxn.getWithdrawlAmount()));
if (balanceAfterAdjust.isLessThanZero()) {
balanceIsPositive = false;
}
}
}
return balanceIsPositive;
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class SavingsBO method adjustUserAction.
private AccountPaymentEntity adjustUserAction(Money amountAdjustedTo, String adjustmentNote, LocalDate adjustmentDate, PersonnelBO updatedBy, AccountPaymentEntity payment) {
AccountPaymentEntity newPayment = null;
try {
if (!isAdjustPossibleOnTrxn(amountAdjustedTo, payment)) {
throw new BusinessRuleException(AccountExceptionConstants.CANNOTADJUST);
}
AccountActionTypes savingsTransactionType = findFirstDepositOrWithdrawalTransaction(payment);
Date adjustedOn = new DateTimeService().getCurrentJavaDateTime();
List<AccountTrxnEntity> reversedTransactions = reverseTransaction(adjustmentNote, updatedBy, payment, savingsTransactionType, adjustedOn);
buildFinancialEntries(new LinkedHashSet<AccountTrxnEntity>(reversedTransactions));
if (amountAdjustedTo.isGreaterThanZero()) {
Set<AccountTrxnEntity> adjustedPaymentTransactions = createNewAccountPaymentWithAdjustedAmount(amountAdjustedTo, updatedBy, payment, savingsTransactionType, adjustedOn, adjustmentDate);
buildFinancialEntries(adjustedPaymentTransactions);
newPayment = adjustedPaymentTransactions.toArray(new AccountTrxnEntity[adjustedPaymentTransactions.size()])[0].getAccountPayment();
}
} catch (AccountException e) {
throw new BusinessRuleException(e.getKey(), e);
}
goActiveDueToDepositOrWithdrawalOnAccount(updatedBy);
return newPayment;
}
use of org.mifos.accounts.business.AccountTrxnEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getApplicablePayments.
private List<LoanActivityDto> getApplicablePayments(LoanBO loan) {
List<LoanActivityDto> payments = new ArrayList<LoanActivityDto>();
List<AccountPaymentEntity> accountPayments = loan.getAccountPayments();
int i = accountPayments.size() - 1;
if (accountPayments.size() > 0) {
for (AccountPaymentEntity accountPayment : accountPayments) {
if (accountPayment.getAmount().isGreaterThanZero()) {
Money amount = new Money(accountPayment.getAmount().getCurrency());
if (i == 0) {
for (AccountTrxnEntity accountTrxn : accountPayment.getAccountTrxns()) {
short accountActionTypeId = accountTrxn.getAccountActionEntity().getId().shortValue();
boolean isLoanRepayment = accountActionTypeId == AccountActionTypes.LOAN_REPAYMENT.getValue();
boolean isFeeRepayment = accountActionTypeId == AccountActionTypes.FEE_REPAYMENT.getValue();
if (isLoanRepayment || isFeeRepayment) {
amount = amount.add(accountTrxn.getAmount());
}
}
} else {
amount = accountPayment.getAmount();
}
if (amount.isGreaterThanZero()) {
LoanActivityDto loanActivityDto = new LoanActivityDto();
loanActivityDto.setActionDate(accountPayment.getPaymentDate());
loanActivityDto.setTotal(amount.toString());
loanActivityDto.setTotalValue(amount.getAmount().doubleValue());
payments.add(0, loanActivityDto);
}
}
i--;
}
}
return payments;
}
Aggregations