use of org.mifos.customers.business.CustomerBO 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.customers.business.CustomerBO in project head by mifos.
the class SavingsBO method createDepositTrxnsForMandatoryAccountsAfterAdjust.
private Set<AccountTrxnEntity> createDepositTrxnsForMandatoryAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO createdBy) {
Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
SavingsTrxnDetailEntity accountTrxn = null;
CustomerBO customer = null;
Date trxnDate = adjustmentDate.toDateMidnight().toDate();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
customer = oldAccntTrxn.getCustomer();
break;
}
List<AccountActionDateEntity> accountActionList = getAccountActions(lastAccountPayment.getPaymentDate(), customer.getCustomerId());
for (AccountActionDateEntity accountActionDateEntity : accountActionList) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) accountActionDateEntity;
if (newAmount.isZero()) {
break;
}
accountTrxn = null;
// if payment covers required deposit
if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
Short installmentId = accountAction.getInstallmentId();
Date dueDate = accountAction.getActionDate();
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(accountAction.getDeposit());
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.PAID);
} else {
this.savingsBalance = this.savingsBalance.add(newAmount);
Short installmentId = accountAction.getInstallmentId();
Date dueDate = accountAction.getActionDate();
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.UNPAID);
}
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
// add trxn for excess amount
if (newAmount.isGreaterThanZero()) {
this.savingsBalance = this.savingsBalance.add(newAmount);
Short installmentId = null;
Date dueDate = null;
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
return newTrxns;
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class SavingsBO method createDepositTrxnsForVolAccountsAfterAdjust.
/*
* FIXME - keithw - it doesnt make sense to be that voluntary account break up account payments into more than one account transaction
* just because the amount deposited is greater than the 'recommended' amount.
*
* As a result there is no need to make a distinction between the amount deposited (be it less or greater than recommended amount)
*/
private Set<AccountTrxnEntity> createDepositTrxnsForVolAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO loggedInUser) {
Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
SavingsTrxnDetailEntity accountTrxn = null;
CustomerBO customer = null;
Date trxnDate = adjustmentDate.toDateMidnight().toDate();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
customer = oldAccntTrxn.getCustomer();
break;
}
Short installmentId = null;
Date dueDate = null;
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
if (oldAccntTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
SavingsTrxnDetailEntity oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
if (oldAccntTrxn.getInstallmentId() != null) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(oldSavingsAccntTrxn.getInstallmentId(), oldSavingsAccntTrxn.getCustomer().getCustomerId());
installmentId = accountAction.getInstallmentId();
dueDate = accountAction.getActionDate();
// if recommended amount is covered by payment
if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(accountAction.getDeposit());
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.PAID);
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
} else if (newAmount.isNonZero()) {
// not zero and amount paid is less that recommended amount
this.savingsBalance = this.savingsBalance.add(newAmount);
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.UNPAID);
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
}
break;
}
}
}
if (accountTrxn != null) {
newTrxns.add(accountTrxn);
}
// Create a new transaction with remaining amount
if (newAmount.isGreaterThanZero()) {
this.savingsBalance = this.savingsBalance.add(newAmount);
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
return newTrxns;
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method transferClientTo.
@Override
public void transferClientTo(ClientBO client, OfficeBO receivingBranch) {
try {
this.hibernateTransactionHelper.startTransaction();
this.hibernateTransactionHelper.beginAuditLoggingFor(client);
client.transferToBranch(receivingBranch);
if (client.getParentCustomer() != null) {
CustomerBO parent = client.getParentCustomer();
parent.incrementChildCount();
}
this.hibernateTransactionHelper.flushSession();
client.generateSearchId();
this.customerDao.save(client);
if (client.getParentCustomer() != null) {
this.customerDao.save(client.getParentCustomer());
}
this.hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method updateCustomerStatus.
@Override
public final void updateCustomerStatus(UserContext userContext, CustomerStatusUpdate customerStatusUpdate) throws CustomerException {
CustomerBO customer = this.customerDao.findCustomerById(customerStatusUpdate.getCustomerId());
customer.validateVersion(customerStatusUpdate.getVersionNum());
customer.updateDetails(userContext);
checkPermission(customer, userContext, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag());
Short oldStatusId = customer.getCustomerStatus().getId();
CustomerStatus oldStatus = CustomerStatus.fromInt(oldStatusId);
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
CustomerNoteEntity customerNote = new CustomerNoteEntity(customerStatusUpdate.getNotes(), new Date(), loggedInUser, customer);
if (customer.isGroup()) {
GroupBO group = (GroupBO) customer;
updateGroupStatus(group, oldStatus, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
} else if (customer.isClient()) {
ClientBO client = (ClientBO) customer;
updateClientStatus(client, oldStatus, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
} else {
CenterBO center = (CenterBO) customer;
updateCenterStatus(center, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
}
}
Aggregations