use of org.mifos.accounts.exceptions.AccountException 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.exceptions.AccountException in project head by mifos.
the class SavingsBO method withdraw.
public void withdraw(final AccountPaymentEntity payment, final CustomerBO payingCustomer) throws AccountException {
final Money amountToWithdraw = payment.getAmount();
if (amountToWithdraw.isGreaterThan(savingsBalance)) {
throw new AccountException("errors.insufficentbalance", new String[] { getGlobalAccountNum() });
}
final Money maxWithdrawAmount = getSavingsOffering().getMaxAmntWithdrawl();
if (maxWithdrawAmount != null && maxWithdrawAmount.isNonZero() && amountToWithdraw.isGreaterThan(maxWithdrawAmount)) {
throw new AccountException("errors.exceedmaxwithdrawal", new String[] { getGlobalAccountNum() });
}
// 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", payment.getCreatedByUser());
}
this.addAccountPayment(payment);
savingsBalance = savingsBalance.subtract(amountToWithdraw);
savingsPerformance.setWithdrawDetails(amountToWithdraw);
final SavingsActivityEntity savingsActivity = this.savingsTransactionActivityHelper.createSavingsActivityForWithdrawal(payment, this.savingsBalance, this);
addSavingsActivityDetails(savingsActivity);
final SavingsTrxnDetailEntity accountTrxnBO = this.savingsTransactionActivityHelper.createSavingsTrxnForWithdrawal(payment, amountToWithdraw, payingCustomer, this.savingsBalance);
payment.addAccountTrxn(accountTrxnBO);
buildFinancialEntries(payment.getAccountTrxns());
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class CustomerServiceImpl method createSavingsAccountsForActiveSavingProducts.
private void createSavingsAccountsForActiveSavingProducts(ClientBO client, List<SavingsOfferingBO> savingProducts) {
UserContext userContext = client.getUserContext();
List<SavingsBO> savingsAccounts = new ArrayList<SavingsBO>();
for (SavingsOfferingBO clientSavingsProduct : savingProducts) {
try {
if (clientSavingsProduct.isActive()) {
List<CustomFieldDto> savingCustomFieldViews = new ArrayList<CustomFieldDto>();
SavingsBO savingsAccount = new SavingsBO(userContext, clientSavingsProduct, client, AccountState.SAVINGS_ACTIVE, clientSavingsProduct.getRecommendedAmount(), savingCustomFieldViews);
savingsAccounts.add(savingsAccount);
}
} catch (AccountException pe) {
throw new MifosRuntimeException(pe);
}
}
client.addSavingsAccounts(savingsAccounts);
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class CustomerServiceImpl method updateCustomerMeetingSchedule.
@Override
public void updateCustomerMeetingSchedule(MeetingBO updatedMeeting, CustomerBO customer) {
try {
customer.validateIsTopOfHierarchy();
customerDao.checkPermissionForEditMeetingSchedule(updatedMeeting.getUserContext(), customer);
CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
this.hibernateTransactionHelper.startTransaction();
boolean scheduleUpdateRequired = false;
CustomerMeetingEntity meetingEntity = customer.getCustomerMeeting();
if (meetingEntity != null) {
MeetingBO meeting = customer.getCustomerMeetingValue();
scheduleUpdateRequired = updateMeeting(meeting, updatedMeeting);
} else {
CustomerMeetingEntity newMeetingEntity = customer.createCustomerMeeting(updatedMeeting);
customer.setCustomerMeeting(newMeetingEntity);
}
customerDao.save(customer);
if (scheduleUpdateRequired) {
handleChangeInMeetingSchedule(customer, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
}
this.hibernateTransactionHelper.commitTransaction();
} catch (CustomerException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (AccountException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class GroupBO method updatePerformanceHistoryOnReversal.
@Override
public void updatePerformanceHistoryOnReversal(final LoanBO loan, final Money lastLoanAmount) throws CustomerException {
try {
GroupPerformanceHistoryEntity groupPerformanceHistoryEntity = (GroupPerformanceHistoryEntity) getPerformanceHistory();
groupPerformanceHistoryEntity.updateOnReversal(loan, lastLoanAmount);
} catch (AccountException e) {
throw new CustomerException(e);
}
}
Aggregations