Search in sources :

Example 86 with CustomerBO

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 87 with CustomerBO

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();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerBO(org.mifos.customers.business.CustomerBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 88 with CustomerBO

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);
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) CenterBO(org.mifos.customers.center.business.CenterBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 89 with CustomerBO

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();
        }
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CustomerBO(org.mifos.customers.business.CustomerBO)

Example 90 with CustomerBO

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);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) DateTime(org.joda.time.DateTime) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

CustomerBO (org.mifos.customers.business.CustomerBO)138 ArrayList (java.util.ArrayList)39 Money (org.mifos.framework.util.helpers.Money)38 MifosUser (org.mifos.security.MifosUser)38 UserContext (org.mifos.security.util.UserContext)37 LocalDate (org.joda.time.LocalDate)35 MifosRuntimeException (org.mifos.core.MifosRuntimeException)31 AccountException (org.mifos.accounts.exceptions.AccountException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)27 BusinessRuleException (org.mifos.service.BusinessRuleException)27 MeetingBO (org.mifos.application.meeting.business.MeetingBO)23 ClientBO (org.mifos.customers.client.business.ClientBO)23 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 DateTime (org.joda.time.DateTime)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)20 Date (java.util.Date)19 Test (org.junit.Test)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 HashMap (java.util.HashMap)15