use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method transferGroupTo.
@Override
public final String transferGroupTo(GroupBO group, OfficeBO transferToOffice) throws CustomerException {
group.validateNewOffice(transferToOffice);
group.validateNoActiveAccountsExist();
customerDao.validateGroupNameIsNotTakenForOffice(group.getDisplayName(), transferToOffice.getOfficeId());
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(group);
group.makeCustomerMovementEntries(transferToOffice);
group.setPersonnel(null);
if (group.isActive()) {
group.setCustomerStatus(new CustomerStatusEntity(CustomerStatus.GROUP_HOLD));
}
CustomerBO oldParentOfGroup = group.getParentCustomer();
if (oldParentOfGroup != null) {
oldParentOfGroup.incrementChildCount();
customerDao.save(oldParentOfGroup);
}
this.hibernateTransactionHelper.flushSession();
group.generateSearchId();
group.setUpdateDetails();
customerDao.save(group);
Set<CustomerBO> clients = group.getChildren();
if (clients != null) {
for (CustomerBO client : clients) {
client.setUserContext(group.getUserContext());
((ClientBO) client).handleGroupTransfer();
client.setUpdateDetails();
customerDao.save(client);
}
}
hibernateTransactionHelper.commitTransaction();
return group.getGlobalCustNum();
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CustomerServiceImpl method assembleCustomerPostionsFromDto.
private void assembleCustomerPostionsFromDto(List<CustomerPositionDto> customerPositions, CustomerBO customer) {
for (CustomerPositionDto positionView : customerPositions) {
boolean isPositionFound = false;
for (CustomerPositionEntity positionEntity : customer.getCustomerPositions()) {
if (positionView.getPositionId().equals(positionEntity.getPosition().getId())) {
CustomerBO customerInPosition = null;
if (positionView.getCustomerId() != null) {
customerInPosition = customerDao.findCustomerById(positionView.getCustomerId());
}
positionEntity.setCustomer(customerInPosition);
isPositionFound = true;
break;
}
}
if (!isPositionFound) {
CustomerBO customerInPosition = null;
if (positionView.getCustomerId() != null) {
customerInPosition = customerDao.findCustomerById(positionView.getCustomerId());
}
CustomerPositionEntity customerPosition = new CustomerPositionEntity(new PositionEntity(positionView.getPositionId()), customerInPosition, customer);
customer.addCustomerPosition(customerPosition);
}
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class GroupBO method updateSearchId.
/*
* This methed is used to regenerate the searchId for a group
* which has a bad searchId due to previous bugs (such as MIFOS-2737)
*/
public void updateSearchId() throws CustomerException {
generateSearchId();
update();
if (getChildren() != null) {
for (CustomerBO client : getChildren()) {
client.setUserContext(getUserContext());
((ClientBO) client).handleGroupTransfer();
}
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class GroupPerformanceHistoryEntity method getTotalSavingsAmount.
public Money getTotalSavingsAmount() throws CustomerException {
Money amount = group.getSavingsBalance(getCurrency());
List<CustomerBO> clients = getChildren();
if (clients != null) {
for (CustomerBO client : clients) {
Money savingsBalance = client.getSavingsBalance(getCurrency());
if (amount.getAmount().equals(BigDecimal.ZERO)) {
amount = savingsBalance;
} else {
amount = amount.add(savingsBalance);
}
}
}
return amount;
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class GroupPerformanceHistoryEntity method generatePortfolioAtRisk.
// this method calculates the PAR using the method
// LoanBO.hasPortfolioAtRisk() to determine if a loan is in arrears
public void generatePortfolioAtRisk() throws CustomerException {
Money amount = getBalanceForAccountsAtRisk(group);
List<CustomerBO> clients = getChildren();
if (clients != null) {
for (CustomerBO client : clients) {
Money balanceAtRisk = getBalanceForAccountsAtRisk(client);
if (amount.getAmount().equals(BigDecimal.ZERO)) {
amount = balanceAtRisk;
} else {
amount = amount.add(balanceAtRisk);
}
}
}
Money totalOutstandingLoanAmount = getTotalOutStandingLoanAmount();
if (!totalOutstandingLoanAmount.getAmount().equals(BigDecimal.ZERO)) {
setPortfolioAtRisk(new Money(amount.getCurrency(), amount.divide(totalOutstandingLoanAmount)));
}
}
Aggregations