コード例 #1
0
        public static TaxRuleCollection LoadForBasket(int basketId, TaxAddress address, User user)
        {
            List <TaxRule> potentialTaxRules = new List <TaxRule>();
            //GET ALL TAX CODES THAT ARE PRESENT IN THE BASKET
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT DISTINCT TaxCodeId FROM ac_BasketItems");
            selectQuery.Append(" WHERE BI.BasketId = @basketId AND TaxCodeId > 0");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@basketId", System.Data.DbType.Int32, basketId);
            List <int> taxCodes = new List <int>();

            //EXECUTE THE COMMAND
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    taxCodes.Add(dr.GetInt32(0));
                }
                dr.Close();
            }
            //THIS WILL RETURN ALL TAX RULES THAT COULD APPLY TO PRODUCT IN THE BASKET
            //FOR THE GIVEN ADDRESS AND USER
            return(LoadForTaxCodes(taxCodes.ToArray(), address, user));
        }
コード例 #2
0
 /// <summary>
 /// Determines in a tax applies based on the given addresses.
 /// </summary>
 /// <param name="billingAddress">The billing address</param>
 /// <param name="shippingAddress">The shipping address</param>
 /// <returns>True if the tax applies to the given addresses</returns>
 /// <remarks>This method determines which address to use based on nexus, and indicates whether the tax applies for the given set.</remarks>
 public bool AppliesToAddress(TaxAddress billingAddress, TaxAddress shippingAddress)
 {
     //SHORTCUT IF THERE IS NO ZONE FILTER
     if (this.TaxRuleShipZones.Count == 0)
     {
         return(true);
     }
     if (this.UseBillingAddress)
     {
         return(AppliesToAddress(billingAddress));
     }
     return(AppliesToAddress(shippingAddress));
 }
コード例 #3
0
        /// <summary>
        /// Determines in a tax applies based on the given address.
        /// </summary>
        /// <param name="address">The address used to determine tax liability</param>
        /// <returns>True if the tax applies to the given address</returns>
        /// <remarks>This method does not check nexus, it only decides whether the shipzone filter is met by the given address.</remarks>
        public bool AppliesToAddress(TaxAddress address)
        {
            if (this.TaxRuleShipZones.Count == 0)
            {
                return(true);
            }
            ShipZoneCollection shipZones = address.ShipZones;

            foreach (ShipZone zone in shipZones)
            {
                if (this.TaxRuleShipZones.IndexOf(this.TaxRuleId, zone.ShipZoneId) > -1)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
 /// <summary>
 /// Loads rules that may apply for the given tax code and address information
 /// </summary>
 /// <param name="taxCodeId">Tax code Id</param>
 /// <param name="taxAddress">Address for which to load the tax rules</param>
 /// <param name="user">User for which to load the tax rules</param>
 /// <returns>Collection of rules that apply</returns>
 public static TaxRuleCollection LoadForTaxCode(int taxCodeId, TaxAddress taxAddress, User user)
 {
     int[] taxCodeIds = { taxCodeId };
     return(LoadForTaxCodes(taxCodeIds, taxAddress, user));
 }
コード例 #5
0
        public static TaxRuleCollection LoadForTaxCodes(int[] taxCodeIds, TaxAddress taxAddress, User user)
        {
            //IF WE DO NOT HAVE VALID TAX CODES THERE ARE NO RULES
            if ((taxCodeIds == null) || (taxCodeIds.Length == 0))
            {
                return(new TaxRuleCollection());
            }
            TaxRuleCollection potentialTaxRules = new TaxRuleCollection();

            //FIRST DETERMINE THE ZONE(S) FOR THE Tax Address
            ShipZoneCollection shipmentZoneCollection = taxAddress.ShipZones;

            //BUILD A LIST OF ZONEIDS FOR QUERY CRITERIA
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT DISTINCT " + TaxRule.GetColumnNames("TR"));
            selectQuery.Append(" FROM (ac_TaxRules TR INNER JOIN ac_TaxRuleTaxCodes TRTC ON TR.TaxRuleId = TRTC.TaxRuleId)");
            selectQuery.Append(" LEFT JOIN ac_TaxRuleShipZones TRSZ ON TR.TaxRuleId = TRSZ.TaxRuleId");
            selectQuery.Append(" WHERE StoreId = @storeId ");
            if (taxCodeIds.Length == 1)
            {
                selectQuery.Append(" AND TRTC.TaxCodeId = " + taxCodeIds[0].ToString());
            }
            else
            {
                selectQuery.Append(" AND TRTC.TaxCodeId IN (" + AlwaysConvert.ToList(",", taxCodeIds) + ")");
            }

            //PROCESS SHIPZONE EXCLUSION
            selectQuery.Append(" AND (TRSZ.ShipZoneId IS NULL");
            for (int i = 0; i < shipmentZoneCollection.Count; i++)
            {
                selectQuery.Append(" OR TRSZ.ShipZoneId = @shipZoneId" + i.ToString());
            }
            selectQuery.Append(") ORDER BY TR.Priority");

            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            //ADD IN NUMBERED ZONE PARAMETERS
            for (int i = 0; i < shipmentZoneCollection.Count; i++)
            {
                database.AddInParameter(selectCommand, "@shipZoneId" + i.ToString(), System.Data.DbType.Int32, shipmentZoneCollection[i].ShipZoneId);
            }
            //EXECUTE THE COMMAND
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    TaxRule taxRule = new TaxRule();
                    TaxRule.LoadDataReader(taxRule, dr);
                    potentialTaxRules.Add(taxRule);
                }
                dr.Close();
            }

            //PROCESS GROUP EXCLUSIONS
            TaxRuleCollection potentialTaxRulesWithGroupFilter = new TaxRuleCollection();

            foreach (TaxRule taxRule in potentialTaxRules)
            {
                if (taxRule.AppliesToUser(user))
                {
                    potentialTaxRulesWithGroupFilter.Add(taxRule);
                }
            }

            //RETURN POTENTIAL TAXES
            return(potentialTaxRulesWithGroupFilter);
        }