Example #1
0
            /// <summary>
            /// Given all relevant transaction info, this method will calculate the charges
            /// which should be put on the given transaction.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="customerId">The customer account number to search for transaction charges by.</param>
            /// <param name="customerGroup">The customer charge group id to search for transaction charges by.</param>
            /// <param name="deliveryMode">The delivery mode code to search transaction charges by.</param>
            /// <param name="deliveryModeGroup">The delivery mode charge group id to search transactions charges by.</param>
            /// <param name="transaction">The transaction which will potentially have charges.</param>
            /// <returns>Collection of charges which apply to this transaction.</returns>
            private static IEnumerable <ChargeLine> CalculateTransactionCharges(RequestContext context, string customerId, string customerGroup, string deliveryMode, string deliveryModeGroup, SalesTransaction transaction)
            {
                GetSalesParametersDataRequest getSalesParametersDataRequest = new GetSalesParametersDataRequest(QueryResultSettings.SingleRecord);
                var salesParameters = context.Execute <SingleEntityDataServiceResponse <SalesParameters> >(getSalesParametersDataRequest).Entity;

                // return empty if we're not calculating transaction charges
                if (!salesParameters.UseHeaderCharges)
                {
                    return(new Collection <ChargeLine>());
                }

                // generate all applicable combinations of account, item, and delivery type for header auto-charges
                //   we'll iterate through these to create the header filters for finding auto-charge configurations
                var allCombinations = GetAllHeaderChargeCombinations();

                var processorArgs = new ChargeProcessorArguments
                {
                    CombinationsToTry   = allCombinations,
                    ChargeType          = ChargeLevel.Header,
                    CustomerId          = customerId,
                    CustomerChargeGroup = customerGroup,
                    ItemId                  = string.Empty,
                    ItemChargeGroup         = string.Empty,
                    DeliveryModeId          = deliveryMode,
                    DeliveryModeChargeGroup = deliveryModeGroup,
                };

                return(ApplyAutoCharges(context, transaction, processorArgs));
            }
Example #2
0
            /// <summary>
            /// Given all relevant transaction/line info, this will calculate the charges
            /// which should be put on the given sales line.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="customerId">The customer account number to use for searching.</param>
            /// <param name="customerGroup">The customer charge group id to use for searching.</param>
            /// <param name="deliveryMode">The delivery mode code to use for searching.</param>
            /// <param name="deliveryModeGroup">The delivery mode charge group id to use for searching.</param>
            /// <param name="line">The sales line that would get the charge. Null if not applying to sales line.</param>
            /// <param name="transaction">The sales transaction that will have this charge.</param>
            /// <returns>Collection of charges which apply to this line.</returns>
            private static IEnumerable <ChargeLine> CalculateLineCharges(RequestContext context, string customerId, string customerGroup, string deliveryMode, string deliveryModeGroup, SalesLine line, SalesTransaction transaction)
            {
                GetSalesParametersDataRequest getSalesParametersDataRequest = new GetSalesParametersDataRequest(QueryResultSettings.SingleRecord);
                var salesParameters = context.Execute <SingleEntityDataServiceResponse <SalesParameters> >(getSalesParametersDataRequest).Entity;

                // return empty if we're not calculating line charges
                if (!salesParameters.UseLineCharges)
                {
                    return(new Collection <ChargeLine>());
                }

                var getItemsRequest = new GetItemsDataRequest(new string[] { line.ItemId });

                getItemsRequest.QueryResultSettings = new QueryResultSettings(new ColumnSet("ITEMID", "MARKUPGROUPID"), PagingInfo.AllRecords);
                var getItemsResponse = context.Execute <GetItemsDataResponse>(getItemsRequest);

                Item item = getItemsResponse.Items.SingleOrDefault();

                if (item == null)
                {
                    return(new Collection <ChargeLine>());
                }

                // generate all applicable combinations of account, item, and delivery type for line auto-charges
                //   we'll iterate through these below to create the header filters for finding auto-charge configurations
                var allCombinations = GetAllLineChargeCombinations();
                var processorArgs   = new ChargeProcessorArguments
                {
                    CombinationsToTry   = allCombinations,
                    ChargeType          = ChargeLevel.Line,
                    CustomerId          = customerId,
                    CustomerChargeGroup = customerGroup,
                    ItemId                  = item.ItemId,
                    ItemChargeGroup         = item.ChargeGroup,
                    DeliveryModeId          = deliveryMode,
                    DeliveryModeChargeGroup = deliveryModeGroup,
                };

                return(ApplyAutoCharges(context, transaction, processorArgs));
            }
Example #3
0
            /// <summary>
            /// This method will find all auto-charge configurations which match the combinations
            /// and info given in the ChargeProcessorArguments parameters.
            /// Then it will apply the charge calculation rules and return a collection of
            /// ChargeLines which should be applied to the transaction or line.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="transaction">Transaction we will populate with charges.</param>
            /// <param name="args">Defines which combinations to look for, whether header/line charges, and transaction/line info.</param>
            /// <returns>The collection of charge lines.</returns>
            private static IEnumerable <ChargeLine> ApplyAutoCharges(RequestContext context, SalesTransaction transaction, ChargeProcessorArguments args)
            {
                // for all combinations to try, search for any matches in the data base
                var chargeConfigurations = new List <ChargeConfiguration>();

                foreach (var combo in args.CombinationsToTry)
                {
                    var header = BuildConfigurationHeader(
                        combo.Item1,
                        combo.Item2,
                        combo.Item3,
                        args.CustomerId,
                        args.CustomerChargeGroup,
                        args.ItemId,
                        args.ItemChargeGroup,
                        args.DeliveryModeId,
                        args.DeliveryModeChargeGroup);

                    GetChargeConfigurationsByHeaderDataRequest getChargeConfigurationsByHeaderDataRequest = new GetChargeConfigurationsByHeaderDataRequest(args.ChargeType, header, QueryResultSettings.AllRecords);
                    var configs = context.Execute <EntityDataServiceResponse <ChargeConfiguration> >(getChargeConfigurationsByHeaderDataRequest).PagedEntityCollection;
                    chargeConfigurations.AddRange(GetValidChargeConfigurations(configs.Results));
                }

                // try to apply all the charge configurations found above
                var orderAmount    = transaction.NetAmountWithNoTax;
                var appliedCharges = ApplyChargeConfigurations(chargeConfigurations, orderAmount);

                return(appliedCharges);
            }