protected internal virtual VatRegion GetVatRegion([NotNull] Order order) { Assert.ArgumentNotNull(order, "order"); VatRegion result = null; if (order.TaxTotal != null) { if (order.TaxTotal.TaxSubtotal.Count > 0) { TaxSubTotal taxSubTotal = order.TaxTotal.TaxSubtotal.FirstOrDefault(); Assert.IsNotNull(taxSubTotal, "taxSubTotal cannot be null."); TaxCategory taxCategory = taxSubTotal.TaxCategory; Assert.IsNotNull(taxCategory, "taxCategory cannot be null."); string code = taxCategory.Name; if (string.IsNullOrEmpty(code)) { return(null); } result = this.GetVatRegion(code); } } return(result); }
/// <summary> /// Resolves the preconditions: product and totals. /// </summary> /// <param name="order">The order.</param> /// <param name="productCode">The product code.</param> protected internal virtual void ResolvePreConditions([NotNull] Order order, [NotNull] string productCode) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(productCode, "productCode"); this.needResolvePreConditions = false; this.product = this.ProductRepository.Get <Product>(productCode); Assert.IsNotNull(this.product, "Product cannot be resolved"); this.currency = this.CurrencyProvider.Get(order.PricingCurrencyCode); Assert.IsNotNull(this.currency, "Currency cannot be resolved"); this.totals = this.ProductPriceManager.GetProductTotals <DomainModel.Prices.Totals, Product, Currency>(this.product, this.currency); Assert.IsNotNull(this.totals, "Totals cannot be resolved"); VatRegion vatRegion = this.GetVatRegion(order); this.vat = vatRegion != null ? ((ProductPriceManager)this.ProductPriceManager).GetVat(this.product, vatRegion) : this.totals.VAT; }
/// <summary> /// Gets the value-added tax. /// </summary> /// <typeparam name="TProduct">The type of the product.</typeparam> /// <param name="product">The product.</param> /// <param name="vatRegion">The vat region.</param> /// <returns> /// The value-added tax. /// </returns> public virtual decimal GetVat <TProduct>(TProduct product, VatRegion vatRegion = null) where TProduct : Product { Assert.ArgumentNotNull(product, "product"); if (string.IsNullOrEmpty(product.VatType)) { Log.Warn(string.Format("Value-added tax field of product '{0}' is null or empty", product.Title), this); return(decimal.Zero); } Item vatTypeItem = this.Database.GetItem(product.VatType); if (vatTypeItem == null) { Log.Warn("Value-added tax item is null", this); return(decimal.Zero); } Item vatValueItem = null; if (vatRegion is IEntity) { vatValueItem = vatTypeItem.Axes.SelectSingleItem(string.Format("./*[@VAT Region ='{0}']", (vatRegion as IEntity).Alias)); } if (vatValueItem == null) { vatValueItem = vatTypeItem.Axes.SelectSingleItem(string.Format("./*[@VAT Region ='{0}']", this.GeneralSettings.DefaultVatRegion)); } string vatValue = vatValueItem != null ? vatValueItem["VAT Value"] : "0"; decimal vat; decimal.TryParse(vatValue, NumberStyles.Float, CultureInfo.InvariantCulture, out vat); return(vat); }