Esempio n. 1
0
        public async Task <PiDetailDto> GetPiDetailById(long id)
        {
            var piDetail = await piDetailRepository.GetEntityById(id);

            if (piDetail == null)
            {
                return(null);
            }

            return(new PiDetailDto()
            {
                Id = piDetail.Id,
                DepositPrice = piDetail.DepositPrice,
                DepositDate = piDetail.DepositDate,
                BrokerId = piDetail.BrokerId,
                PiId = piDetail.PeroformaInvoiceId,
                IsSold = piDetail.IsSold
            });
        }
        public async Task <FilterCurrSalePiDto> GetListPiSalesByCurrencyId(FilterCurrSalePiDto filterDto)
        {
            var asQueryable = _currPiDetailRepository
                              .GetEntities()
                              .Include(X => X.CurrencySale)
                              .Where(x => x.CurrencySaleId == filterDto.Id)
                              .AsQueryable();

            if (filterDto.SearchText != null || !(string.IsNullOrEmpty(filterDto.SearchText)))
            {
                asQueryable = asQueryable.Include(x => x.PeroformaInvoiceDetails)
                              .Include(c => c.PeroformaInvoiceDetails.PeroformaInvoice)
                              .Where(d =>
                                     d.PeroformaInvoiceDetails.PeroformaInvoice.PiCode.Contains(filterDto.SearchText.Trim()));
            }

            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 piDetail = await _piDetailRepository.GetEntityById(item.PeroformaInvoiceDetailId ?? 1);

                var pi = await _piRepository.GetEntityById(piDetail.PeroformaInvoiceId);

                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             = pi.PiCode,
                    PiDetailPrice      = piDetail.DepositPrice,
                    SellPriceCurrency  = item.CurrencySale.SalePricePerUnit,
                    SellPriceCommodity = pi.BasePrice
                });
            }
            return(filterDto.SetCurrencySaleExDec(filterDto.CurrencySaleDetailPi).SetPaging(pager));
        }