coupon discount amount incorrect


  • Default avatar
    rick26    
     10 years ago
    0

    When I apply a 5% discount with AWO the actual discount taken is a little higher. When I do the same thing through Virtuemart discount the discount is correct. I beleive I have tried to switch on/off every setting to fix this but it is still an issue. Please can someone tell me how to correct this issue

    Virtuemart 2.6
    AWO 2.2.7.1
    Joomla 2.5.19
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    Can you give an example of the exact numbers in the cart?

    Also what tax rules do you have set up in Virtuemart?
  • Default avatar
    rick26    
     10 years ago
    0

    I have observed that it is when I pick a shipping method that the discount which is initially correct changes to an incorrect amount. My shipping method has a $.00 value

    Numbers in cart before picking shipping method (correct)

    Total - $117.61
    Discount - ($5.88)
    HST tax - 14.52

    After picking shipping method (Discount incorrect)

    Total - $117.61
    Discount - ($6.65)
    HST tax - $14.52

    The tax stays the same and is correct. The tax rule I have is 13% HST tax
  • Your avatar
    seyi    
     10 years ago
    0

    Ok, so what seems to be happening is the discount is shown before tax:
    117.61*0.05 = 5.88

    And after picking shipping the discount is shown after tax:
    (117.61*1.13)*.05 = 6.65

    Is HST tax set up as TaxBill?

    If you complete the order and go to awocoupon->history of uses->coupons, what discount do you see?

    And how do you have discount setup in awocoupon->configuration, before or after tax?
  • Default avatar
    rick26    
     10 years ago
    0

    - I want the discount before tax so this is okay

    - HST is set up as TAXBill

    - Coupon history shows the correct discount of $5.88 (setting set before taxes)

    - I tried setting "after tax" and coupon history shows correct amount of $6.65

    - Interesting......!

    Hope you have a easy solution
  • Your avatar
    seyi    
     10 years ago
    0

    Ok, so the discount is correct, its just displaying the coupon with tax, and you want it to display without tax?
  • Default avatar
    rick26    
     10 years ago
    0

    I want the discount to remain the same after picking shipping please
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    Ok, so you want the discount displayed without tax. Is the overall total correct? If so then it is just a matter of updating your template to show discounts without tax.
  • Default avatar
    rick26    
     10 years ago
    0


    The overall total in the cart is not correct due to the higher discount, therefore on each transaction I am losing this additional amount!
  • Your avatar
    seyi    
     10 years ago
    0

    Ok, in
    www/administrator/components/com_awocoupon/views/config/tmpl/default.php, around line 62 is this:
        <!--<tr><td class="key"><label><?php echo JText::_'Use Injection Mode' ); ?></label></td>
            <td><?php echo $this->lists['virtuemart_inject_totals']; ?></td>
        </tr>-->


    Uncomment it, like this:
        <tr><td class="key"><label><?php echo JText::_'Use Injection Mode' ); ?></label></td>
            <td><?php echo $this->lists['virtuemart_inject_totals']; ?></td>
        </tr>


    Then go to the configuration page set 'Use injection mode' to yes, and try it again. This should fix the order total.

  • Default avatar
    rick26    
     10 years ago
    0

    Okay, uncommented as you described; set injection to yes

    Result = discount is correct until I select a shipping method, then it is the same as initially described to you
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    Can yoiu send a private message temporary admin access to have a look?
  • Your avatar
    seyi    
     10 years ago
    0

    Ok, so we have established that the overall discount is correct. In your example, these are the numbers:

    Product: 117.61
    Discount: 6.65
    Tax: 15.29
    Total: 126.25

    The discount has also tax included.
    Discount no tax: 117.61*.05=5.88
    Discount including tax: 5.88*1.13 = 6.65

    What you want is to remove the tax amount from the discount and subtract it to the Tax total


    Product: 117.61
    Discount: 5.88
    Tax: 14.52
    Total: 126.25

    In order to do that you would have to make modifications to the template.

    Using the default virtuemart template, in
    www/components/com_virtuemart/views/cart/tmpl/default_pricelist.php, you have these lines of code:

    <?php
    echo $this->currencyDisplay->createPriceDiv ('salesPriceCoupon'''$this->cart->pricesUnformatted['salesPriceCoupon'], FALSE)

    // can be altered to 
    echo $this->currencyDisplay->createPriceDiv ('salesPriceCoupon'''$this->cart->pricesUnformatted['salesPriceCoupon']-$this->cart->pricesUnformatted['couponTax'], FALSE)
    ?>



    And for tax, since you are using taxbill, you would look in the foreach loop
    <?php
    foreach ($this->cart->cartData['taxRulesBill'] as $rule) {
    ?>


    Where you will find
    <?php
    echo $this->currencyDisplay->createPriceDiv ($rule['virtuemart_calc_id'] . 'Diff'''$this->cart->pricesUnformatted[$rule['virtuemart_calc_id'] . 'Diff'], FALSE);

    // which can be altered to
    echo $this->currencyDisplay->createPriceDiv ($rule['virtuemart_calc_id'] . 'Diff'''$this->cart->pricesUnformatted[$rule['virtuemart_calc_id'] . 'Diff']+$this->cart->pricesUnformatted['couponTax'], FALSE);
    ?>


    That should do it. You would probably have to make the modifications in your template file
    www/templats/[your-template]/html/com_virtuemart/cart/default_pricelist.php
  • Default avatar
    rick26    
     10 years ago
    0

    Thanks for all your help so far.

    Why when I use the default Virtuemart coupon it works without modification? Everything works as it should! I have just tested it again by disabling your coupon

    I really prefer not to make changes to templates, can you look into this a little further please

  • Your avatar
    seyi    
     10 years ago
    0

    That is because Virtuemart deals with discounts on a discount before tax level for everything. AwoCoupon has to take a lot more into account.
  • Default avatar
    rick26    
     10 years ago
    0

    Seyi,

    Thanks for all your help

    FYI, my figures are exported to an external accounting system so that is why the individual number totals are important.

    I will try to make the modifications and let you know

    Thank you
  • Default avatar
    rick26    
     10 years ago
    0

    Seyi,

    DONE! - looking good so far!

    Not to be picky but rather; accurate.

    It is rounding the discount as per my example above from $5.8805 to $5.89; of course then it also affects the final tax

    Must be a simple solution?

    Thanks


  • Default avatar
    rick26    
     10 years ago
    0

    Seyi,

    Dont bother with my last post, it is working okay, not too sure why in the above example it was off.

    Thank you so much for your help and support

    Best regards

    Rick
  • Your avatar
    seyi    
     10 years ago
    0

    You are welcome. Glad it all came together and is working well.
  • Default avatar
    rick26    
     10 years ago
    0

    Seyi,

    Well, its never that easy is it!

    Everything on screen while the order is placed is perfect now BUT in the Virtuemart admin and the customer account details where they can look up their order we have the same issue original issue with discount off tax

    Of course I didn't notice till a week later

    What can be done?

    Rick
  • Your avatar
    seyi    
     10 years ago
    0

    Hi Rick,

    ok, here is a whole new approach that should fix all views, which modifies AwoCoupon instead of virtuemart. In
    www/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php, around line 384 is this

    <?php
            
    // update cart objects
            
    $this->vmcartPrices['couponTax'] = round($coupon_session['product_discount_tax'] + $coupon_session['shipping_discount_tax'] + $coupon_taxbill,2) * $negative_multiplier;
            
    $this->vmcartPrices['couponValue'] = round($coupon_session['product_discount_notax'] + $coupon_session['shipping_discount_notax'],2) * $negative_multiplier;
            
    $this->vmcartPrices['salesPriceCoupon'] = round($coupon_session['product_discount'] + $coupon_session['shipping_discount'] + $coupon_taxbill,2) * $negative_multiplier;
            
    $this->vmcartPrices['billSub'] -= $this->vmcartPrices['couponValue']*$negative_multiplier;
            
    $this->vmcartPrices['billTaxAmount'] -= $this->vmcartPrices['couponTax']*$negative_multiplier;
            
    $this->vmcartPrices['billTotal'] -= $this->vmcartPrices['salesPriceCoupon']*$negative_multiplier;
    ?>


    Change it to this
    <?php
            
    if(!empty($this->vmcartData['taxRulesBill']) && count($this->vmcartData['taxRulesBill'])==1) {
                
    reset($this->vmcartData['taxRulesBill']);
                
    $key key($this->vmcartData['taxRulesBill']);
                if(empty(
    $this->vmcartPrices[$key.'Diff'])) $this->vmcartPrices[$key.'Diff'] = 0;
                
                
    $coupon_tax $coupon_value $coupon_subtotal 0;
                foreach(
    $coupon_session['processed_coupons'] as $item) {
                    if(!empty(
    $item['product_discount_tax'])) {
                        
    $coupon_tax += $item['product_discount_tax'];
                        
    $coupon_value += $item['product_discount_notax'];
                        
    $coupon_subtotal += $item['product_discount_notax'];
                    }
                    else {
                        
    $coupon_value += $item['product_discount'];
                    }
                }
                
    $coupon_tax round($coupon_tax,2) * $negative_multiplier;
                
    $coupon_value round($coupon_value,2) * $negative_multiplier;
                
    $coupon_subtotal round($coupon_subtotal,2) * $negative_multiplier;
                
                if(!empty(
    $coupon_subtotal)) {
                    
    $this->vmcartData['taxRulesBill'][$key]['subTotal'] += $coupon_subtotal;
                }

                
    $this->vmcartPrices[$key.'Diff'] += $coupon_tax;
                
    $this->vmcartPrices['couponTax'] = 0;
                
    $this->vmcartPrices['couponValue'] = $coupon_value;
                
    $this->vmcartPrices['salesPriceCoupon'] = $coupon_value;
                
    $this->vmcartPrices['billSub'] += $coupon_value;
                
    $this->vmcartPrices['billTaxAmount'] += $coupon_tax;
                
    $this->vmcartPrices['billTotal'] += $coupon_value+$coupon_tax;
            }
            else {
                
    // update cart objects
                
    $this->vmcartPrices['couponTax'] = round($coupon_session['product_discount_tax'] + $coupon_session['shipping_discount_tax'] + $coupon_taxbill,2) * $negative_multiplier;
                
    $this->vmcartPrices['couponValue'] = round($coupon_session['product_discount_notax'] + $coupon_session['shipping_discount_notax'],2) * $negative_multiplier;
                
    $this->vmcartPrices['salesPriceCoupon'] = round($coupon_session['product_discount'] + $coupon_session['shipping_discount'] + $coupon_taxbill,2) * $negative_multiplier;
                
    $this->vmcartPrices['billSub'] -= $this->vmcartPrices['couponValue']*$negative_multiplier;
                
    $this->vmcartPrices['billTaxAmount'] -= $this->vmcartPrices['couponTax']*$negative_multiplier;
                
    $this->vmcartPrices['billTotal'] -= $this->vmcartPrices['salesPriceCoupon']*$negative_multiplier;
            }
    ?>


    Some notes about this code
    - please remove the original template modification we added to default_pricelist
    - this approach will work for all future orders, not previous ones, as it actually modifies the taxbill rule line
    - this assumes you only have one taxbill rule in an order. if for some reason you have multiple, then the coupon tax defaults to the coupon line
  • Default avatar
    rick26    
     10 years ago
    0

    Seyi,

    Cool! if this would work it would be the perfect solution.

    Unfortunately I have followed your instructions; removed modifications to default_pricelist.php and made the change as you noted. The result is a total blank web page screen.........nothing, the whole site goes away

    As a super fast remedy i disabled all AWO plug ins and the site came back.......phew!

    For now I will leave them disabled to I hear back from you

    Guess we need to look at it some more

    Rick
  • Your avatar
    seyi    
     10 years ago
    0

    Hi Rick

    The code is copy and paste from a test server where it works. Did you also add the beginning and end tags <\?php and ?>

    Those are just there to beautify the code and if added would cause an error, causing a blank screen.
  • Default avatar
    rick26    
     10 years ago
    0

    Seyi,

    Just to make double sure I checked the copy and paste and it is okay.

    Please note that if a user is not logged in the website works fine but as you might remember when you worked on it before it is then just a catalogue

    Rick
  • Your avatar
    seyi    
     10 years ago
    0

    Hi Rick,

    Thanks for the access. I took a look at the code, and you were missing the closing bracket on the function. I have added it, enabled AwoCoupon and tested on your site, and it works, no more white screen.