public PagedResults<CustomerBalanceDTO> CustomerGridSearchResults(String firstName, String lastName, Pagination pagination) { var results = new List<CustomerBalanceDTO>(); var customers = CustomerRepository.GetCustomers(firstName, lastName); var customerIds = customers.Select(c => c.Id).ToList(); var customerLedgers = CustomerLedgerRepository.GetLedgerByCustomerIds(customerIds); foreach (var customer in customers) { var customerLedger = customerLedgers.Where(cl => cl.CustomerId == customer.Id).ToList(); var currentBalance = CustomerLedgerService.GetCurrentBalance(customerLedger); var dto = new CustomerBalanceDTO() { Customer = customer, CurrentBalance = currentBalance }; results.Add(dto); } return pagination.ApplyPaging(results); }
public PagedResults<CustomerPaymentHistoryDTO> PaymentHistoryGridResults(Int32 customerId, Pagination pagination) { var results = new List<CustomerPaymentHistoryDTO>(); var customerLedger = CustomerLedgerRepository.GetLedgerByCustomerId(customerId); var value = 0M; foreach (var entry in customerLedger) { value -= entry.Credit; value += entry.Debit; var result = new CustomerPaymentHistoryDTO() { Credit = entry.Credit, Debit = entry.Debit, Balance = value, PaymentDate = entry.DatePosted }; results.Add(result); } return pagination.ApplyPaging(results); }