public static TaxRate ToTaxRate(this coreDto.TaxRate taxRateDto, Currency currency)
        {
            var result = new TaxRate(currency)
            {
                Rate        = new Money(taxRateDto.Rate.Value, currency),
                PercentRate = (decimal)(taxRateDto.PercentRate ?? 0)
            };

            if (taxRateDto.Line != null)
            {
                result.Line = new TaxLine(currency)
                {
                    Code     = taxRateDto.Line.Code,
                    Id       = taxRateDto.Line.Id,
                    Name     = taxRateDto.Line.Name,
                    Quantity = taxRateDto.Line.Quantity ?? 1,
                    TaxType  = taxRateDto.Line.TaxType,
                    TypeName = taxRateDto.Line.TypeName,

                    Amount = new Money(taxRateDto.Line.Amount.Value, currency),
                    Price  = new Money(taxRateDto.Line.Price.Value, currency)
                };
                if (taxRateDto.TaxDetails != null)
                {
                    result.Line.TaxDetails = taxRateDto.TaxDetails.Select(x => x.ToTaxDetail(currency)).ToList();
                }
            }

            return(result);
        }
        public virtual TaxRate ToTaxRate(coreDto.TaxRate taxRateDto, Currency currency)
        {
            var result = new TaxRate(currency)
            {
                Rate = new Money(taxRateDto.Rate.Value, currency)
            };

            if (taxRateDto.Line != null)
            {
                result.Line = new TaxLine(currency);
                result.Line.InjectFrom(taxRateDto.Line);
                result.Line.Amount = new Money(taxRateDto.Line.Amount.Value, currency);
                result.Line.Price  = new Money(taxRateDto.Line.Price.Value, currency);
            }

            return(result);
        }
        public virtual async Task EvaluateTaxesAsync(TaxEvaluationContext context, IEnumerable <ITaxable> owners)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (owners == null)
            {
                throw new ArgumentNullException(nameof(owners));
            }
            IList <coreService.TaxRate> taxRates = new List <coreService.TaxRate>();

            if (context.StoreTaxCalculationEnabled)
            {
                //Do not execute platform API for tax evaluation if fixed tax rate is used
                if (context.FixedTaxRate != 0)
                {
                    foreach (var line in context.Lines ?? Enumerable.Empty <TaxLine>())
                    {
                        var rate = new coreService.TaxRate()
                        {
                            Rate     = (double)(line.Amount * context.FixedTaxRate * 0.01m).Amount,
                            Currency = context.Currency.Code,
                            Line     = line.ToTaxLineDto()
                        };
                        taxRates.Add(rate);
                    }
                }
                else
                {
                    var cacheKey = CacheKey.With(GetType(), context.GetCacheKey());
                    taxRates = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, (cacheEntry) =>
                    {
                        cacheEntry.AddExpirationToken(TaxCacheRegion.CreateChangeToken());
                        return(_commerceApi.EvaluateTaxesAsync(context.StoreId, context.ToTaxEvaluationContextDto()));
                    });
                }
            }
            ApplyTaxRates(taxRates, owners);
        }
Exemplo n.º 4
0
        public virtual TaxRate ToTaxRate(coreDto.TaxRate taxRateDto, Currency currency)
        {
            var result = new TaxRate(currency)
            {
                Rate = new Money(taxRateDto.Rate.Value, currency)
            };

            if (taxRateDto.Line != null)
            {
                result.Line          = new TaxLine(currency);
                result.Line.Code     = taxRateDto.Line.Code;
                result.Line.Id       = taxRateDto.Line.Id;
                result.Line.Name     = taxRateDto.Line.Name;
                result.Line.Quantity = taxRateDto.Line.Quantity ?? 1;
                result.Line.TaxType  = taxRateDto.Line.TaxType;

                result.Line.Amount = new Money(taxRateDto.Line.Amount.Value, currency);
                result.Line.Price  = new Money(taxRateDto.Line.Price.Value, currency);
            }

            return(result);
        }
Exemplo n.º 5
0
        public static TaxRate ToTaxRate(this coreDto.TaxRate taxRateDto, Currency currency)
        {
            var result = new TaxRate(currency)
            {
                Rate = new Money(taxRateDto.Rate.Value, currency)
            };

            if (taxRateDto.Line != null)
            {
                result.Line = new TaxLine(currency)
                {
                    Code     = taxRateDto.Line.Code,
                    Id       = taxRateDto.Line.Id,
                    Name     = taxRateDto.Line.Name,
                    Quantity = taxRateDto.Line.Quantity ?? 1,
                    TaxType  = taxRateDto.Line.TaxType,

                    Amount = new Money(taxRateDto.Line.Amount.Value, currency),
                    Price  = new Money(taxRateDto.Line.Price.Value, currency)
                };
            }

            return(result);
        }
Exemplo n.º 6
0
 public static TaxRate ToTaxRate(this coreDto.TaxRate taxRateDto, Currency currency)
 {
     return(TaxConverterInstance.ToTaxRate(taxRateDto, currency));
 }