/// <summary>
            /// Gets the setting that shows whether to apply inter-state tax for India or not.
            /// </summary>
            /// <param name="request">The get apply interstate tax India data request.</param>
            /// <returns>The setting that shows whether to apply inter-state tax for India or not.</returns>
            private SingleEntityDataServiceResponse <ApplyInterStateTaxIndia> GetApplyInterstateTaxIndia(GetApplyInterstateTaxIndiaDataRequest request)
            {
                ThrowIf.Null(request, "request");

                IndiaTaxL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetIndiaTaxL2CacheDataStoreAccessor(request.RequestContext);

                bool found;
                bool updateL2Cache;
                ApplyInterStateTaxIndia result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetApplyInterStateTaxIndia(request.QueryResultSettings.ColumnSet), out found, out updateL2Cache);

                if (!found)
                {
                    // Fetches it from database if no setting was cached.
                    // Input parameters
                    ParameterSet parameters = new ParameterSet();
                    parameters["@bi_ChannelId"] = request.RequestContext.GetPrincipal().ChannelId;

                    using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                    {
                        result = sqlServerDatabaseContext.ExecuteStoredProcedure <ApplyInterStateTaxIndia>(GetApplyInterStateTaxIndiaName, parameters).SingleOrDefault();
                    }

                    updateL2Cache &= result != null;
                }

                if (updateL2Cache)
                {
                    // Caches the result if it is fetched from database.
                    level2CacheDataAccessor.PutApplyInterStateTaxIndia(request.QueryResultSettings.ColumnSet, result);
                }

                return(new SingleEntityDataServiceResponse <ApplyInterStateTaxIndia>(result));
            }
Exemplo n.º 2
0
            /// <summary>
            /// Gets the tax group for India inter-state transaction.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="inventLocationId">Inventory location id.</param>
            /// <param name="shippingAddress">Shipping address.</param>
            /// <param name="isInterState">The flag indicates whether it's inter state.</param>
            /// <returns>
            /// The sales tax group information.
            /// </returns>
            internal static string GetInterStateTaxRegimeIndia(RequestContext context, string inventLocationId, Address shippingAddress, out bool isInterState)
            {
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }

                if (context.Runtime == null)
                {
                    throw new ArgumentException("context.Runtime cannot be null.");
                }

                if (shippingAddress == null)
                {
                    throw new ArgumentNullException("shippingAddress");
                }

                if (string.IsNullOrWhiteSpace(shippingAddress.ThreeLetterISORegionName) &&
                    string.IsNullOrWhiteSpace(shippingAddress.TwoLetterISORegionName))
                {
                    throw new ArgumentNullException("shippingAddress", "shippingAddress ISORegionName");
                }

                string taxRegime = string.Empty;

                isInterState = false;
                bool isApplyInterStateTax = false;

                if (!string.IsNullOrWhiteSpace(inventLocationId))
                {
                    GetApplyInterstateTaxIndiaDataRequest getApplyInterstateTaxIndiaDataRequest = new GetApplyInterstateTaxIndiaDataRequest(QueryResultSettings.SingleRecord);
                    ApplyInterStateTaxIndia interStateTaxSetting = context.Runtime.Execute <SingleEntityDataServiceResponse <ApplyInterStateTaxIndia> >(getApplyInterstateTaxIndiaDataRequest, context).Entity;

                    if (interStateTaxSetting != null)
                    {
                        isApplyInterStateTax = interStateTaxSetting.IsApplyInterStateTaxIndia;
                    }

                    if (isApplyInterStateTax)
                    {
                        GetWarehouseAddressIndiaDataRequest getWarehouseAddressIndiaDataRequest = new GetWarehouseAddressIndiaDataRequest(inventLocationId, QueryResultSettings.SingleRecord);
                        Address shippingFromAddress = context.Runtime.Execute <SingleEntityDataServiceResponse <Address> >(getWarehouseAddressIndiaDataRequest, context).Entity;

                        if (shippingFromAddress != null &&
                            (shippingFromAddress.ThreeLetterISORegionName == shippingAddress.ThreeLetterISORegionName) &&
                            !string.IsNullOrWhiteSpace(shippingFromAddress.State) &&
                            !string.IsNullOrWhiteSpace(shippingAddress.State) &&
                            (shippingFromAddress.State != shippingAddress.State))
                        {
                            isInterState = true;
                        }

                        if (isInterState)
                        {
                            GetTaxRegimeIndiaDataRequest getTaxRegimeIndiaDataRequest = new GetTaxRegimeIndiaDataRequest(QueryResultSettings.SingleRecord);
                            taxRegime = context.Runtime.Execute <SingleEntityDataServiceResponse <string> >(getTaxRegimeIndiaDataRequest, context).Entity;

                            if (string.IsNullOrWhiteSpace(taxRegime))
                            {
                                InvalidTaxGroupNotification notification = new InvalidTaxGroupNotification(shippingFromAddress);
                                context.Notify(notification);
                            }
                        }
                    }
                }

                return(taxRegime);
            }