Promotion and Tax calculation issue v1.40

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 年 前
Does anyone have a workaround or correction which we can already apply on the existing v1.40 version?

Thanks in advance.

Kind Regards,
Ludo
14 年 前
The problem seems also to be existing in the v1.50 release:

Example: 10% promotion on the Total Order; both Items and Shipping Costs are including a 21% VAT, this is the result on the Shopping Cart:

Sub-Total  9,99
Discount  -0,83
Shipping  3,99
Tax  2,42
Total  13,15


For me to be correct is that it should be as follows: the customer want's to have the discount of the Total of the items including the tax.  Values should be rounded to 2 decimals (note: 0.555 will become 0.56 and not 0.55).

Sub-Total  9,99
Discount  -1,00
Shipping  3,99
Tax  2,25
Total  12,98

Kind Regards,
Ludo
14 年 前
1. These discounts (discount type "Assigned to whole order]") are not taxable
2. Discounted amount of these discounts (discount type "Assigned to whole order]") are based on order subtotal excluding tax. If you need to override this behavior, then modify OrderManager.GetShoppingCartSubTotal() method.
14 年 前
Thank you, this was a great help for me.

Kind Regards,
Ludo


These are the changes in case someone is interested:

NopCommerceStore\Modules\OrderTotals.ascx.cs

BindData()

                    // **LV**100329**START
                    // Take into account a possible Order % Discount when calculating the Tax.
                    // decimal shoppingCartTaxBase = TaxManager.GetTaxTotal(Cart, paymentMethodID, NopContext.Current.User, ref TaxError);
                    decimal shoppingCartTaxBase = TaxManager.GetTaxTotal(Cart, paymentMethodID, NopContext.Current.User, ref TaxError, appliedDiscount);
                    // **LV**100329**END


Libraries\Nop.BusinessLogic\Tax\TaxManager.cs

using NopSolutions.NopCommerce.BusinessLogic.Promo.Discounts;  // **LV**100329

        // **LV**100329**START
        //public static decimal GetTaxTotal(ShoppingCart Cart, Customer customer, ref string Error)
        public static decimal GetTaxTotal(ShoppingCart Cart, Customer customer, ref string Error, Discount orderDiscount)
        // **LV**100329**END
        {
            // **LV**100329**START
            // return GetTaxTotal(Cart, 0, customer, ref Error);
            return GetTaxTotal(Cart, 0, customer, ref Error, orderDiscount);
            // **LV**100329**END
        }


        // **LV**100329**START
        //public static decimal GetTaxTotal(ShoppingCart Cart, int PaymentMethodID,
        //    Customer customer, ref string Error)
        public static decimal GetTaxTotal(ShoppingCart Cart, int PaymentMethodID,
            Customer customer, ref string Error, Discount orderDiscount)
        // **LV**100329**END
        {
            decimal taxTotal = decimal.Zero;

            // **LV**100329**START
            // Check if there was a % percentage discount for the order.
            decimal orderDiscountPercentage;
            if (orderDiscount != null && orderDiscount.UsePercentage && orderDiscount.DiscountPercentage > 0)
                orderDiscountPercentage = orderDiscount.DiscountPercentage;
            else
                orderDiscountPercentage = 0;
            // **LV**100329**END

            //items
            decimal itemsTaxTotal = decimal.Zero;
            foreach (var shoppingCartItem in Cart)
            {
                decimal subTotalWithoutDiscountExclTax = decimal.Zero;
                decimal subTotalWithoutDiscountInclTax = decimal.Zero;

                string Error1 = string.Empty;
                string Error2 = string.Empty;
                // **LV**100329**START
                //subTotalWithoutDiscountExclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), false, customer, ref Error1);
                //subTotalWithoutDiscountInclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), true, customer, ref Error2);
                decimal itemPrice = PriceHelper.GetSubTotal(shoppingCartItem, customer, true);
                if (orderDiscountPercentage > 0)
                    itemPrice = itemPrice * ((100 - orderDiscountPercentage) / 100);
                subTotalWithoutDiscountExclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, itemPrice, false, customer, ref Error1);
                subTotalWithoutDiscountInclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, itemPrice, true, customer, ref Error2);
                // **LV**100329**END



Libraries\Nop.BusinessLogic\Orders\OrderManager.cs

        public static string PlaceOrder(PaymentInfo paymentInfo, Customer customer,
            Guid OrderGuid, out int OrderID)
        {

                //tax total
                decimal orderTaxTotal = decimal.Zero;
                decimal orderTaxInCustomerCurrency = decimal.Zero;
                if (!paymentInfo.IsRecurringPayment)
                {
                    string TaxError = string.Empty;
                    // **LV**100329**START
                    // Take into account a possible Order % Discount when calculating the Tax.
                    //orderTaxTotal = TaxManager.GetTaxTotal(cart, paymentInfo.PaymentMethodID, customer, ref TaxError);
                    Discount orderDiscount = appliedDiscounts.Count > 0 ? appliedDiscounts[0] : null;
                    orderTaxTotal = TaxManager.GetTaxTotal(cart, paymentInfo.PaymentMethodID, customer, ref TaxError, orderDiscount);
                    // **LV**100329**END
                    if (!String.IsNullOrEmpty(TaxError))
                        throw new NopException("Tax total couldn't be calculated");



Libraries\Nop.BusinessLogic\Orders\ShoppingCartManager.cs

        public static decimal? GetShoppingCartTotal(ShoppingCart Cart, int PaymentMethodID, Customer customer)

            //tax
            // **LV**100329**START
            // Take into account a possible Order % Discount when calculating the Tax.
            // decimal shoppingCartTax = TaxManager.GetTaxTotal(Cart, PaymentMethodID, customer, ref TaxError);
            decimal shoppingCartTax = TaxManager.GetTaxTotal(Cart, PaymentMethodID, customer, ref TaxError, appliedDiscount);
            // **LV**100329**START
            if (!String.IsNullOrEmpty(TaxError))
                return null;



        public static string GetShoppingCartSubTotal(ShoppingCart Cart, Customer customer,
            out decimal discountAmount, out Discount appliedDiscount,
            out List<AppliedGiftCard> appliedGiftCards, bool includingTax,
            out decimal subtotalWithoutPromo, out decimal subtotalWithPromo)

            #region Discounts
            //Discount amount (excl tax)
            //We calculate discount amount on subtotal excl tax
            //This type of discounts [Assigned to whole order] is not taxable
            // **LV**100329**START
            // Calculate the Order Discount on the Order Total including the Tax.
            if (includingTax) {
                discountAmount = GetOrderDiscount(customer, subTotalInclTaxWithoutDiscount, out appliedDiscount);

                // If the appliedDiscount is not a percentage then recalc it without tax.
                if (appliedDiscount != null && !appliedDiscount.UsePercentage)
                    discountAmount = GetOrderDiscount(customer, subTotalExclTaxWithoutDiscount, out appliedDiscount);
            }
            else
                // **LV**100329**END
                discountAmount = GetOrderDiscount(customer, subTotalExclTaxWithoutDiscount, out appliedDiscount);

            //sub totals with discount
            decimal subTotalWithDiscount = decimal.Zero;
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.