Ejemplo n.º 1
0
        public async Task <FilterPiDetailDto> GetPiesByFiltersList(FilterPiDetailDto filterPiDetailDto)
        {
            var asQueryable = piDetailRepository
                              .GetEntities()
                              .Where(x => x.PeroformaInvoiceId == filterPiDetailDto.PiId)
                              .AsQueryable();
            //if (filterPiDetailDto.SearchText != null || !(string.IsNullOrWhiteSpace(filterPiDetailDto.SearchText)))
            //{
            //    asQueryable = asQueryable.Where(x => x.PiCode.Contains(filterPiDto.SearchText.Trim()));
            //}

            var count = (int)Math.Ceiling(asQueryable.Count() / (double)filterPiDetailDto.TakeEntity);
            var pager = Pager.Builder(count, filterPiDetailDto.PageId, filterPiDetailDto.TakeEntity);
            var list  = asQueryable.Paging(pager).ToList();

            filterPiDetailDto.PiDetailDtos = new List <PiDetailDto>();
            foreach (var item in list)
            {
                filterPiDetailDto.PiDetailDtos.Add(new PiDetailDto()
                {
                    BrokerId     = item.BrokerId,
                    PiId         = item.PeroformaInvoiceId,
                    DepositDate  = item.DepositDate,
                    DepositPrice = item.DepositPrice,
                    Id           = item.Id,
                    IsSold       = item.IsSold
                });
            }
            return(filterPiDetailDto.SetPiDetails(filterPiDetailDto.PiDetailDtos).SetPaging(pager));
        }
Ejemplo n.º 2
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));
        }
        public async Task <FilterCurrSalePiDto> GetListExDecSalesByPiDetailId(FilterCurrSalePiDto filterDto)
        {
            var piDetailIdList = _piDetailRepository
                                 .GetEntities()
                                 .Where(x => x.PeroformaInvoiceId == filterDto.Id)
                                 .Select(x => x.Id);
            var asQueryable = _currPiDetailRepository
                              .GetEntities()
                              .Include(X => X.CurrencySale)
                              .Where(x => piDetailIdList.Contains((long)x.PeroformaInvoiceDetailId))
                              .AsQueryable();

            //var listOfRoleId = user.Roles.Select(r => r.RoleId);
            //var roles = db.Roles.Where(r => listOfRoleId.Contains(r.RoleId));
            var count = (int)Math.Ceiling(asQueryable.Count() / (double)filterDto.TakeEntity);
            var pager = Pager.Builder(count, filterDto.PageId, filterDto.TakeEntity);
            var list  = await asQueryable.Paging(pager).ToListAsync();

            filterDto.CurrencySaleDetailPi = new List <CurrencySaleDetailPiDto>();
            foreach (var item in list)
            {
                var currencySaleItem = await _currencySaleRepository.GetCurrencyByIdIncludesCustomerAndBroker(item.CurrencySaleId);

                var peroformaInvoice = await _piRepository.GetEntityById(filterDto.Id);

                filterDto.CurrencySaleDetailPi.Add(new CurrencySaleDetailPiDto()
                {
                    Id                 = item.Id,
                    BrokerName         = currencySaleItem.Broker.Name + " (" + currencySaleItem.Broker.Title + ") ",
                    CurrSaleDate       = currencySaleItem.SaleDate,
                    CustomerName       = currencySaleItem.Customer.Name,
                    Price              = item.Price,
                    ProfitLossAmount   = item.ProfitLossAmount,
                    PiCode             = peroformaInvoice.PiCode,
                    SellPriceCurrency  = item.CurrencySale.SalePricePerUnit,
                    SellPriceCommodity = peroformaInvoice.BasePrice
                });
            }
            return(filterDto.SetCurrencySaleExDec(filterDto.CurrencySaleDetailPi).SetPaging(pager));
        }