private async Task <double?> GetIncreasePercent(QuotationReportParams queryParams) { if (!queryParams.IsApplySaleRate) { return(null); } var weight = queryParams.WeightInKg; var saleRateRepo = this.UnitOfWork.GetRepository <SaleQuotationRate>(); var saleRate = await saleRateRepo.GetQueryable().OrderBy(sr => sr.FromWeight) .FirstOrDefaultAsync(sr => weight >= sr.FromWeight && (weight <= sr.ToWeight || sr.ToWeight == null)); return(saleRate?.Percent); }
public async Task <List <QuotationReport> > GetQuotationReport(QuotationReportParams queryParams) { var vendorRepository = this.UnitOfWork.GetRepository <Vendor>(); var availableVendors = await vendorRepository.GetQueryable() .Include(v => v.Zones) .Where(v => !v.IsStopped && v.Zones != null && v.Zones.Any()) .ToListAsync(); var vendorHasQuotations = availableVendors.Where(v => v.VendorQuotations != null && v.VendorQuotations.Any() && v.Zones.Any(z => z.Countries.Contains(queryParams.DestinationCountry))).ToList(); var increasePercent = await this.GetIncreasePercent(queryParams); var result = new List <QuotationReport>(); foreach (var vendor in vendorHasQuotations) { var report = new QuotationReport { VendorName = vendor.Name, OtherFeeInUsd = vendor.OtherFeeInUsd, FuelChargePercent = vendor.FuelChargePercent, }; var reportDetail = new List <QuotationReportDetail>(); var zonesByCountry = vendor.Zones.Where(z => z.Countries.Contains(queryParams.DestinationCountry)) .ToList(); foreach (var zone in zonesByCountry) { var zoneSplit = this.SplitZoneName(zone.Name); var countingParams = new PurchasePriceCountingParams { Vat = queryParams.Vat, UsdExchangeRate = queryParams.UsdExchangeRate, WeightInKg = queryParams.WeightInKg, DestinationCountry = queryParams.DestinationCountry, FuelChargePercent = vendor.FuelChargePercent ?? 0, OtherFeeInUsd = vendor.OtherFeeInUsd ?? 0 }; var price = this.billService.CountVendorNetPriceInUsd(vendor, countingParams, zone, increasePercent); if (price.PurchasePriceInUsd > 0) { reportDetail.Add(new QuotationReportDetail { Service = zoneSplit.serviceName, Zone = zoneSplit.zoneName, PurchasePriceInUsd = price.PurchasePriceInUsd, PurchasePriceInVnd = price.PurchasePriceInVnd, PurchasePriceAfterVatInUsd = price.PurchasePriceAfterVatInUsd, PurchasePriceAfterVatInVnd = price.PurchasePriceAfterVatInVnd, QuotationPriceInUsd = price.QuotationPriceInUsd, VendorNetPriceInUsd = price.VendorNetPriceInUsd }); } } if (reportDetail.Any()) { report.Quotation.AddRange(reportDetail.OrderBy(rd => rd.PurchasePriceAfterVatInVnd)); } if (report.Quotation.Any()) { result.Add(report); } } return(result.OrderBy(r => r.Quotation, new QuotationReportComparer()).ToList()); }