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);
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method handleChangeOfClientStatusToClosedOrCancelled.
private void handleChangeOfClientStatusToClosedOrCancelled(ClientBO client, CustomerStatusFlag customerStatusFlag, CustomerNoteEntity customerNote, PersonnelBO loggedInUser) throws AccountException {
if (client.isClosedOrCancelled()) {
if (client.isClientUnderGroup()) {
CustomerBO parentCustomer = client.getParentCustomer();
client.resetPositions(parentCustomer);
parentCustomer.setUserContext(client.getUserContext());
CustomerBO center = parentCustomer.getParentCustomer();
if (center != null) {
parentCustomer.resetPositions(center);
center.setUserContext(client.getUserContext());
}
}
CustomerAccountBO customerAccount = client.getCustomerAccount();
if (customerAccount.isOpen()) {
customerAccount.setUserContext(client.getUserContext());
customerAccount.changeStatus(AccountState.CUSTOMER_ACCOUNT_INACTIVE, customerStatusFlag.getValue(), customerNote.getComment(), loggedInUser);
customerAccount.update();
}
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method generateSavingSchedulesForGroupAndCenterSavingAccounts.
private void generateSavingSchedulesForGroupAndCenterSavingAccounts(ClientBO client) {
try {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> holidays = new ArrayList<Holiday>();
UserContext userContext = client.getUserContext();
CustomerBO group = client.getParentCustomer();
if (group != null) {
List<SavingsBO> groupSavingAccounts = new CustomerPersistence().retrieveSavingsAccountForCustomer(group.getCustomerId());
CustomerBO center = group.getParentCustomer();
if (center != null) {
List<SavingsBO> centerSavingAccounts = new CustomerPersistence().retrieveSavingsAccountForCustomer(center.getCustomerId());
groupSavingAccounts.addAll(centerSavingAccounts);
}
for (SavingsBO savings : groupSavingAccounts) {
savings.setUserContext(userContext);
if (client.getCustomerMeetingValue() != null) {
if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
DateTime today = new DateTime().toDateMidnight().toDateTime();
savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), workingDays, holidays, today);
}
}
}
}
} catch (PersistenceException pe) {
throw new MifosRuntimeException(pe);
}
}
Aggregations