Beispiel #1
0
        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);
        }
Beispiel #2
0
 public TaxClass this[string TaxClassName]
 {
     get
     {
         for (int i = 0; i < m_TaxClasses.Count; i++)
         {
             TaxClass t = (TaxClass)m_TaxClasses.GetByIndex(i);
             if (t.Name == TaxClassName)
             {
                 return(t);
             }
         }
         return(null);
     }
 }
Beispiel #3
0
        static public TaxClass Create(string Name, string TaxCode, int DisplayOrder)
        {
            int           TaxClassID = 0;
            string        err        = String.Empty;
            SqlConnection cn         = new SqlConnection(DB.GetDBConn());

            cn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "dbo.aspdnsf_insTaxclass";

            cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 800));
            cmd.Parameters.Add(new SqlParameter("@TaxCode", SqlDbType.NVarChar, 800));
            cmd.Parameters.Add(new SqlParameter("@DisplayOrder", SqlDbType.Int, 4));
            cmd.Parameters.Add(new SqlParameter("@TaxClassID", SqlDbType.Int, 4)).Direction = ParameterDirection.Output;

            cmd.Parameters["@Name"].Value         = Name;
            cmd.Parameters["@TaxCode"].Value      = TaxCode;
            cmd.Parameters["@DisplayOrder"].Value = DisplayOrder;


            try
            {
                cmd.ExecuteNonQuery();
                TaxClassID = Int32.Parse(cmd.Parameters["@TaxClassID"].Value.ToString());
            }
            catch (Exception ex)
            {
                err = ex.Message;
            }

            if (TaxClassID > 0)
            {
                TaxClass t = new TaxClass(TaxClassID);
                return(t);
            }

            cn.Close();
            cmd.Dispose();
            cn.Dispose();

            return(null);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 /// <summary>
 /// Creates a new TaxClass record and adds it to the collection
 /// </summary>
 public void Add(string Name, string TaxCode, int DisplayOrder)
 {
     this.Add(TaxClass.Create(Name, TaxCode, DisplayOrder));
 }
Beispiel #7
0
 /// <summary>
 /// Adds an existing TaxClass object to the collection
 /// </summary>
 public void Add(TaxClass taxclass)
 {
     m_TaxClasses.Add(taxclass.TaxClassID, taxclass);
 }