Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        //public async Task<FilterGenericDto<PiRemaindDto>> GetPiesByFiltersList(FilterGenericDto<PiRemaindDto> filterPiDto)
        //{
        //    var asQueryable = piRepository
        //        .GetEntities()
        //        .Where(x => !x.IsSold)
        //        .AsQueryable();

        //    if (filterPiDto.SearchText != null || !(string.IsNullOrWhiteSpace(filterPiDto.SearchText)))
        //    {
        //        asQueryable = asQueryable.Where(x => x.PiCode.Contains(filterPiDto.SearchText.Trim()));
        //    }

        //    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.Entities = new List<PiRemaindDto>();
        //    foreach (var item in peroformaInvoices)
        //    {
        //        var payDetails = await piDetailService.GetTotalAamountReceivedFromTheCustomer(item.Id);
        //        //if (PayDetails < item.TotalPrice)
        //        //{
        //        filterPiDto.Entities.Add(new PiRemaindDto()
        //        {
        //            BasePrice = item.BasePrice,
        //            PiCode = item.PiCode,
        //            TotalPrice = item.TotalPrice,
        //            PiDate = item.PiDate,
        //            RemaindPrice = item.TotalPrice - payDetails,
        //            SoldPrice = payDetails,
        //            Id = item.Id
        //        });
        //        //}

        //    }

        //    return filterPiDto.SetEntitiesDto(filterPiDto.Entities).SetPaging(pager);
        //}

        #region GetAll
        public async Task <FilterPiDto> GetPiesByFiltersIsSold(FilterPiDto filterPiDto)
        {
            var asQueryable = piRepository
                              .GetEntities()
                              .AsQueryable();

            if (filterPiDto.SearchText != null || !(string.IsNullOrWhiteSpace(filterPiDto.SearchText)))
            {
                asQueryable = asQueryable.Where(x => x.PiCode.Contains(filterPiDto.SearchText.Trim()));
            }
            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);

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

            return(filterPiDto.SetPies(filterPiDto.PiRemaind).SetPaging(pager));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetPiAll([FromQuery] FilterPiDto filterPiDto)
        {
            var pi = await _piService.GetPiesByFiltersIsSold(filterPiDto);

            return(JsonResponseStatus.Success(pi));
        }