private GetTaxRequest BuildTaxRequest(Customer cust, Avalara.AvaTax.Adapter.AddressService.Address originAddress, DocumentType docType) { // Instantiate a new GetTaxRequest GetTaxRequest avalaraTaxRequest = new GetTaxRequest { OriginAddress = originAddress, CompanyCode = CompanyCode, CustomerCode = cust.CustomerID.ToString(), DetailLevel = DetailLevel.Tax, CurrencyCode = Localization.StoreCurrency(), DocCode = ("DocDate" + System.DateTime.Now.ToString()), DocDate = System.DateTime.Today, DocType = docType, Discount = System.Decimal.Zero, }; avalaraTaxRequest.TaxOverride.TaxDate = System.DateTime.Today; if (cust.LevelHasNoTax) { avalaraTaxRequest.ExemptionNo = (cust.CustomerLevelName.Length > 25 ? cust.CustomerLevelName.Substring(0, 25) : cust.CustomerLevelName) ?? "Customer Level Tax Exempt"; //Avalara can't handle more than 25 chars here } return(avalaraTaxRequest); }
private static AvaAddress.Address FromAddress(IAddressBase address) { AvaAddress.Address result = new AvaAddress.Address(); result.City = address.City; result.Country = address.CountryID; result.Line1 = address.AddressLine1; result.Line2 = address.AddressLine2; result.Line3 = address.AddressLine3; result.PostalCode = address.PostalCode; result.Region = address.State; return(result); }
private Line CreateLineItem(CartItem cartItem, Avalara.AvaTax.Adapter.AddressService.Address destinationAddress) { decimal extendedPrice; if (cartItem.ThisShoppingCart == null) { // Order line items using (var promotionsDataContext = new AspDotNetStorefront.Promotions.Data.EntityContextDataContext()) { // Sum the discount for every PromotionLineItem that applies to the current cart item. // A gift product's line item price is already discounted, so don't include the discount when IsAGift is true. var lineItemDiscountAmount = promotionsDataContext.PromotionLineItems .Where(pli => !pli.isAGift) .Where(pli => pli.shoppingCartRecordId == cartItem.ShoppingCartRecordID) .Sum(pli => (decimal?)pli.discountAmount); extendedPrice = cartItem.Price + (lineItemDiscountAmount ?? 0); } } else { // Shopping cart items CartItemCollection cartItems = cartItem.ThisShoppingCart.CartItems; extendedPrice = Prices.LineItemPrice(cartItem, cartItems.CouponList, cartItems.QuantityDiscountList, cartItem.ThisCustomer); } Line lineItem = new Line { ItemCode = cartItem.SKU, Description = cartItem.ProductName, Amount = extendedPrice, Qty = (double)cartItem.Quantity, Discounted = true, DestinationAddress = destinationAddress, }; if (cartItem.IsTaxable) { var lineItemTaxClass = new TaxClass(cartItem.TaxClassID); lineItem.TaxCode = lineItemTaxClass.TaxCode; } else { lineItem.TaxCode = "NT"; } lineItem.TaxOverride.TaxDate = System.DateTime.Today; return(lineItem); }
private IEnumerable <Line> CreateCartShippingLineItem(Avalara.AvaTax.Adapter.AddressService.Address destinationAddress, Customer customer, IEnumerable <CartItem> cartItems, IEnumerable <OrderOption> orderOptions) { var lineItemTaxClass = new TaxClass(AppLogic.AppConfigUSInt("ShippingTaxClassID")); Line lineItem = new Line { ItemCode = ShippingItemSku, Description = String.Empty, Amount = Prices.ShippingTotal(true, true, new CartItemCollection(cartItems), customer, orderOptions), Qty = 1, Discounted = false, DestinationAddress = destinationAddress, TaxCode = lineItemTaxClass.TaxCode, }; lineItem.TaxOverride.TaxDate = System.DateTime.Today; yield return(lineItem); }
private IEnumerable <Line> CreateOrderShippingLineItem(Avalara.AvaTax.Adapter.AddressService.Address destinationAddress, IEnumerable <CartItem> cartItems, Order order, int adnsfShippingAddressId) { var lineItemTaxClass = new TaxClass(AppLogic.AppConfigUSInt("ShippingTaxClassID")); var shippingAmount = new OrderShipmentCollection(order.OrderNumber) .Where(os => os.AddressID == adnsfShippingAddressId) .Select(os => os.ShippingTotal) .FirstOrDefault(); Line lineItem = new Line { ItemCode = ShippingItemSku, Description = String.Empty, Amount = shippingAmount, Qty = 1, Discounted = false, DestinationAddress = destinationAddress, TaxCode = lineItemTaxClass.TaxCode, }; lineItem.TaxOverride.TaxDate = System.DateTime.Today; yield return(lineItem); }
private IEnumerable <Line> CreateOrderOptionLineItems(IEnumerable <OrderOption> orderOptions, Avalara.AvaTax.Adapter.AddressService.Address destinationAddress) { return(orderOptions.Select(oo => new { OrderOption = oo, TaxClass = new TaxClass(oo.TaxClassID), }) .Select(o => new Line { ItemCode = OrderOptionItemSku + o.OrderOption.Name.Replace(" ", "_"), Description = o.OrderOption.Name, Amount = o.OrderOption.Cost, Qty = 1, Discounted = true, DestinationAddress = destinationAddress, } )); }