Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David 3 posts 74 karma points
    May 04, 2017 @ 21:18
    David
    0

    Merchello discount coupon and tax

    Hello,

    I am working on a site with Merchello and have a problem with discount coupons and tax.

    I have a discount coupon which applies a 75% discount. This discount is taken off the pre-tax price, but not the tax on the full price. My tax is set to 20%

    This is what is currently happening:

    Product £40.00 ex tax

    Sub Total: £40.00

    Discount: (£30.00)

    Tax: £8.00 - [20% of £40] (wrong ?)

    Total: £18.00 inc Tax

    This is what I think should be happening:

    Product £40.00 ex tax

    Sub Total: £40.00

    Discount: (£30.00)

    Tax: £2.00 = [ 20% of (£40 - £30) ]

    Total: £12.00 inc Tax

    Does anyone know of a setting or change I can make to get the behaviour I am after? Or I am misunderstanding how it is supposed to work?

    Many thanks, David

  • David 3 posts 74 karma points
    May 05, 2017 @ 14:00
    David
    0

    Any thoughts?

    This seems to be to be really fundamental flaw in the way discounts are applied.

    I don't understand why tax would be calculated on the full (un-discounted) amount?

    But hopefully I'm being stupid there is an easy way round it.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    May 09, 2017 @ 03:50
    Rusty Swayne
    1

    Hey David,

    You can override the tax application by replacing this task with your own version: https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.FastTrack.Ui/App_Plugins/Merchello/config/merchello.config#L161

    From what you described, I agree does seem like a bug (assuming you are taxing by invoice and not including taxes in the product pricing ... correct). The fix for this will need to be done in the tax provider - which I think will be a really quick tweak as what is probably happening is the discount line items are not being included in the tax calculation.

    We would need to create an issue on http://issues.merchello.com for that.

  • David 3 posts 74 karma points
    May 22, 2017 @ 21:39
    David
    1

    Hi Rusty,

    Thanks a lot for getting back to to me. What I did (before I saw you message) was to override the FixedRateTaxCalculationStrategy as below.

    Which got me out of the hole I was in, but didn't feel like I was doing it the right way.

    public override Attempt<ITaxCalculationResult> CalculateTaxesForInvoice()
        {
            var extendedData = new ExtendedDataCollection();
    
            try
            {
                var baseTaxRate = _taxMethod.PercentageTaxRate;
    
                var BaseTaxRate = "merchBaseTaxRate";
                extendedData.SetValue(BaseTaxRate, baseTaxRate.ToString(CultureInfo.InvariantCulture));
    
                if (_taxMethod.HasProvinces)
                {
                    baseTaxRate = AdjustedRate(baseTaxRate, _taxMethod.Provinces.FirstOrDefault(x => x.Code == TaxAddress.Region), extendedData);
                }
    
                var visitor = new TaxableLineItemVisitor(baseTaxRate / 100);
    
                Invoice.Items.Accept(visitor);
    
                decimal taxDeduction = 0;
                ///
                foreach (var lineItem in Invoice.Items)
                {
                    if (lineItem.LineItemType != Merchello.Core.LineItemType.Discount)
                        continue;
    
                    var json = lineItem.ExtendedData["merchCouponReward"];
                    var offerSettings = JsonConvert.DeserializeObject<OfferSettingsDisplay>(json);
    
                    string discount = null;
                    List<string> productKeys = new List<string>();
                    decimal decDiscount = 0;
                    string adjustment = "Percent";
                    foreach (var m in offerSettings.ComponentDefinitions)
                    {
                        if (m.ComponentType == Merchello.Core.Marketing.Offer.OfferComponentType.Reward)
                        {
                            foreach (var e in m.ExtendedData)
                            {
                                if (e.Key == "amount")
                                {
                                    discount = e.Value;
                                    decDiscount = decimal.Parse(discount) / 100M;
                                }
                                if (e.Key == "adjustment")
                                {
                                    adjustment = e.Value;
                                }
                            }
                        }
                        if (m.ComponentType == Merchello.Core.Marketing.Offer.OfferComponentType.Constraint)
                        {
    
                            foreach (var c in m.ExtendedData)
                            {
                                if (c.Key == "productConstraints" )
                                {
                                    dynamic dataarry = JsonConvert.DeserializeObject(c.Value);
    
                                    foreach (dynamic d in dataarry)
                                    {
                                        if (d.productKey != null)
                                            productKeys.Add(d.productKey.ToString());
    
                                    }
                                }
                            }
                        }
                    }
    
                    foreach (var productItem in Invoice.Items)
                    {
                        if (productItem.LineItemType == Merchello.Core.LineItemType.Product)
                        {
                            if (productKeys.Contains(productItem.ExtendedData.GetProductKey().ToString()))// == productKey)
                            {
                                if (adjustment == "Percent")
                                {
                                    var itemTax = productItem.Price * baseTaxRate/100M;
                                    var itemTaxDiscount = itemTax * (decDiscount) * productItem.Quantity;
                                    taxDeduction += itemTaxDiscount;
                                }
                                else
                                {
                                    // TO DO
                                }
                            }
                        }
                    }
                }
                ///
    
    
                var merchLineItemTaxAmount = "merchLineItemTaxAmount";
                var totalTax = visitor.TaxableLineItems.Sum(x => decimal.Parse(x.ExtendedData.GetValue(merchLineItemTaxAmount), CultureInfo.InvariantCulture));
    
                totalTax -= taxDeduction;
    
                return Attempt<ITaxCalculationResult>.Succeed(
                    new TaxCalculationResult(_taxMethod.Name, baseTaxRate, totalTax, extendedData));
            }
            catch (Exception ex)
            {
                return Attempt<ITaxCalculationResult>.Fail(ex);
            }
        }
    

    I'll take a look at the way you suggest.

    Thanks again for getting back to me, and for Merchello - it is excellent!

  • Geoff Beaumont 75 posts 104 karma points
    Apr 30, 2018 @ 10:11
    Geoff Beaumont
    0

    Okay, having also run into this issue I've been doing some digging - the issue goes somewhat deeper than the taxation task, or even the taxation gateway provider.

    On line 50 of the TaxableLineItemVisitor, it tests whether the line item has an extended data item marking it as taxable:

    if (!lineItem.ExtendedData.GetTaxableValue()) return;
    

    But discount line items (at least those created by the standard Coupon discounts) do not have this extended data item and so are incorrectly deemed not taxable by the visitor and not included in the tax calculation.

    This wasn't fixed in 2.6 even though it seems like a show stopper (surely any store that's apply tax and using coupons is affected by this?). Does that mean that this issue is only triggered by a specific configuration?

    As far as I can see no issue was ever opened for this, so I'll create one.

  • Geoff Beaumont 75 posts 104 karma points
    Apr 30, 2018 @ 10:56
  • Barry Fogarty 493 posts 1129 karma points
    Jun 01, 2018 @ 12:59
    Barry Fogarty
    0

    FYI For anyone else suffering from this problem, please see my workaround posted on the issue tracker here:

    https://github.com/Merchello/Merchello/issues/2153#issuecomment-393848144

Please Sign in or register to post replies

Write your reply to:

Draft