Search in sources :

Example 1 with ClientAttendanceBO

use of org.mifos.customers.client.business.ClientAttendanceBO in project head by mifos.

the class SaveCollectionSheetAssembler method clientAttendanceAssemblerfromDto.

public List<ClientAttendanceBO> clientAttendanceAssemblerfromDto(final List<SaveCollectionSheetCustomerDto> saveCollectionSheetCustomers, final LocalDate transactionDate, final Short branchId, final String searchId) {
    List<ClientAttendanceBO> clientAttendanceList = null;
    try {
        clientAttendanceList = clientAttendanceDao.findClientAttendance(branchId, searchId, transactionDate);
        for (SaveCollectionSheetCustomerDto saveCollectionSheetCustomer : saveCollectionSheetCustomers) {
            ClientBO client = customerDao.findClientById(saveCollectionSheetCustomer.getCustomerId());
            if (null != client) {
                ClientAttendanceBO clientAttendance = findClientAttendance(clientAttendanceList, client);
                if (clientAttendance == null) {
                    clientAttendance = new ClientAttendanceBO();
                    clientAttendance.setCustomer(client);
                    clientAttendance.setMeetingDate(DateUtils.getDateFromLocalDate(transactionDate));
                }
                clientAttendance.setAttendance(saveCollectionSheetCustomer.getAttendanceId());
                clientAttendanceList.add(clientAttendance);
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException("Failure assembling client attendance list.", e);
    }
    return clientAttendanceList;
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ClientAttendanceBO(org.mifos.customers.client.business.ClientAttendanceBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with ClientAttendanceBO

use of org.mifos.customers.client.business.ClientAttendanceBO in project head by mifos.

the class CollectionSheetServiceImpl method saveCollectionSheet.

/**
     * The method saves a collection sheet.
     *
     * @throws SaveCollectionSheetException
     * */
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) throws SaveCollectionSheetException {
    Long totalTime;
    Long totalTimeStart = System.currentTimeMillis();
    Long readTime;
    Long saveTime = null;
    Long saveTimeStart;
    Integer topCustomerId = saveCollectionSheet.getSaveCollectionSheetCustomers().get(0).getCustomerId();
    CollectionSheetCustomerDto collectionSheetTopCustomer = new CustomerPersistence().findCustomerWithNoAssocationsLoaded(topCustomerId);
    if (collectionSheetTopCustomer == null) {
        List<InvalidSaveCollectionSheetReason> invalidSaveCollectionSheetReasons = new ArrayList<InvalidSaveCollectionSheetReason>();
        List<String> invalidSaveCollectionSheetReasonsExtended = new ArrayList<String>();
        invalidSaveCollectionSheetReasons.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER);
        invalidSaveCollectionSheetReasonsExtended.add(InvalidSaveCollectionSheetReason.INVALID_TOP_CUSTOMER.toString() + ": Customer Id: " + topCustomerId);
        throw new SaveCollectionSheetException(invalidSaveCollectionSheetReasons, invalidSaveCollectionSheetReasonsExtended);
    }
    Short branchId = collectionSheetTopCustomer.getBranchId();
    String searchId = collectionSheetTopCustomer.getSearchId();
    // session caching: prefetch collection sheet data
    // done prior to structure validation because it loads
    // the customers and accounts to be validated into the session
    SaveCollectionSheetSessionCache saveCollectionSheetSessionCache = new SaveCollectionSheetSessionCache();
    saveCollectionSheetSessionCache.loadSessionCacheWithCollectionSheetData(saveCollectionSheet, branchId, searchId);
    try {
        new SaveCollectionSheetStructureValidator().execute(saveCollectionSheet);
    } catch (SaveCollectionSheetException e) {
        System.out.println(e.printInvalidSaveCollectionSheetReasons());
        throw e;
    }
    /*
         * With preprocessing complete...
         *
         * only errors and warnings from the business model remain
         */
    final List<String> failedSavingsDepositAccountNums = new ArrayList<String>();
    final List<String> failedSavingsWithdrawalNums = new ArrayList<String>();
    final List<String> failedLoanDisbursementAccountNumbers = new ArrayList<String>();
    final List<String> failedLoanRepaymentAccountNumbers = new ArrayList<String>();
    final List<String> failedCustomerAccountPaymentNums = new ArrayList<String>();
    final List<ClientAttendanceBO> clientAttendances = saveCollectionSheetAssembler.clientAttendanceAssemblerfromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), saveCollectionSheet.getTransactionDate(), branchId, searchId);
    final AccountPaymentEntity payment = saveCollectionSheetAssembler.accountPaymentAssemblerFromDto(saveCollectionSheet.getTransactionDate(), saveCollectionSheet.getPaymentType(), saveCollectionSheet.getReceiptId(), saveCollectionSheet.getReceiptDate(), saveCollectionSheet.getUserId());
    final List<SavingsBO> savingsAccounts = saveCollectionSheetAssembler.savingsAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedSavingsDepositAccountNums, failedSavingsWithdrawalNums);
    Short paymentTypeId = (payment.getPaymentType() == null || payment.getPaymentType().getId() == null) ? null : payment.getPaymentType().getId();
    final List<LoanBO> loanAccounts = saveCollectionSheetAssembler.loanAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, paymentTypeId);
    final List<AccountBO> customerAccounts = saveCollectionSheetAssembler.customerAccountAssemblerFromDto(saveCollectionSheet.getSaveCollectionSheetCustomers(), payment, failedCustomerAccountPaymentNums);
    boolean databaseErrorOccurred = false;
    Throwable databaseError = null;
    readTime = System.currentTimeMillis() - totalTimeStart;
    try {
        saveTimeStart = System.currentTimeMillis();
        persistCollectionSheet(clientAttendances, loanAccounts, customerAccounts, savingsAccounts);
        saveTime = System.currentTimeMillis() - saveTimeStart;
    } catch (HibernateException e) {
        logger.error("database error saving collection sheet", e);
        databaseErrorOccurred = true;
        databaseError = e;
    }
    totalTime = System.currentTimeMillis() - totalTimeStart;
    printTiming(saveCollectionSheet.printSummary(), totalTime, saveTime, readTime, saveCollectionSheetSessionCache);
    return new CollectionSheetErrorsDto(failedSavingsDepositAccountNums, failedSavingsWithdrawalNums, failedLoanDisbursementAccountNumbers, failedLoanRepaymentAccountNumbers, failedCustomerAccountPaymentNums, databaseErrorOccurred, databaseError);
}
Also used : ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountBO(org.mifos.accounts.business.AccountBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) ClientAttendanceBO(org.mifos.customers.client.business.ClientAttendanceBO) HibernateException(org.hibernate.HibernateException) LoanBO(org.mifos.accounts.loan.business.LoanBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Aggregations

ClientAttendanceBO (org.mifos.customers.client.business.ClientAttendanceBO)2 ArrayList (java.util.ArrayList)1 HibernateException (org.hibernate.HibernateException)1 AccountBO (org.mifos.accounts.business.AccountBO)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1