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;
}
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);
}
Aggregations