public async Task <FilterPiDto> GetPiesByFiltersList(FilterPiDto filterPiDto) { IQueryable <PeroformaInvoice> asQueryable; if (filterPiDto.IsRemaindPriceZero == "1") { asQueryable = piRepository .GetEntities() .Where(x => x.TotalPrice != (piDetailRepository.GetEntities() .Where(d => d.PeroformaInvoiceId == x.Id && !d.IsDelete) .Sum(x => x.DepositPrice))) .AsQueryable(); } else { asQueryable = piRepository .GetEntities() .AsQueryable(); } asQueryable = asQueryable.OrderByDescending(x => x.PiDate); var count = (int)Math.Ceiling(asQueryable.Count() / (double)filterPiDto.TakeEntity); var pager = Pager.Builder(count, filterPiDto.PageId, filterPiDto.TakeEntity); var peroformaInvoices = await asQueryable.Paging(pager).ToListAsync(); filterPiDto.PiRemaind = new List <PiRemaindDto>(); foreach (var item in peroformaInvoices) { var payDetails = await piDetailService.GetTotalAamountReceivedFromTheCustomer(item.Id); var customer = item.CommodityCustomerId != null ? await customerRepository.GetEntityById((long)item.CommodityCustomerId) : null; var customerName = customer == null ? null : customer.Name; //if (PayDetails < item.TotalPrice) //{ filterPiDto.PiRemaind.Add(new PiRemaindDto() { BasePrice = item.BasePrice, PiCode = item.PiCode, TotalPrice = item.TotalPrice, PiDate = item.PiDate, RemaindPrice = item.TotalPrice - payDetails, SoldPrice = payDetails, Id = item.Id, CustomerName = customerName }); //} } if (filterPiDto.SearchText != null || !(string.IsNullOrWhiteSpace(filterPiDto.SearchText))) { filterPiDto.PiRemaind = filterPiDto.PiRemaind.Where(x => x.PiCode.Contains(filterPiDto.SearchText.Trim()) || x.TotalPrice.ToString().Contains(filterPiDto.SearchText.Trim()) || x.RemaindPrice.ToString().Contains(filterPiDto.SearchText.Trim())).ToList(); } return(filterPiDto.SetPies(filterPiDto.PiRemaind).SetPaging(pager)); }