Announcement

Collapse
No announcement yet.

Using VAT in a price calculation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using VAT in a price calculation

    I've written some PHP code to do some sorting on prices, and I've used the ProductPriceRaw variable so I can do calculations on a numeric value. It all works as intended but now I want to add VAT back on the price and display it.

    I know I can multiply the figure by 1.175, but I was hoping to future-proof it against January's vat rise so I'm looking to retrieve the tax-rate as a variable (if such a thing exists). I've tried using TaxRate1 within a pricelist block as per a post of Norman's I found, but it threw an error and wouldn't recognise the figure.

    Am I doing something wrong? Can anyone help? Is a VAT rate variable one for the wishlist?

    #2
    Why not create your own new variable and use that, I seem to recall that getting to the figure used in tax settings is not possible.

    Comment


      #3
      I thought about that, and while it improves things, it's still another potential point of failure for the end user. Ideally, they'd set the tax rate once, and that would be that.

      Actinic obviously uses a variable containing the tax rate - I just hoped it also exposed it for me to use. Disappointing.

      Comment


        #4
        Tax1 and Tax2 can be used in a product layout to show the actual value of the tax at rate 1 and 2. That might help you.
        ie...
        <actinic:variable name="Tax1" />
        <actinic:variable name="Tax2" />

        EDIT - no they won't - see post 7 below.

        Comment


          #5
          The tax rate isn't available as a variable. This lump of code will calculate it by comparing the tax TaxExclusivePrice and TaxInclusivePrice variables.
          Code:
          <actinic:block type="PriceList">
          	<actinic:block if="%3cactinic%3avariable%20name%3d%22ListIndex%22%20%2f%3e%20%3d%3d%201" >
          		<actinic:block php="true">
          			$taxrate = 0;
          			$exc = preg_replace('/[^0-9]/', '', '<actinic:variable name="TaxExclusivePrice" />');
          			$inc = preg_replace('/[^0-9]/', '', '<actinic:variable name="TaxInclusivePrice" />');
          			if ( ($exc != 0) && ($exc != $inc) ) 
          				{
          				$taxrate = ($inc - $exc) / $exc;
          				}
          			echo sprintf("%01.3f", $taxrate);	
          		</actinic:block>
          	</actinic:block>
          </actinic:block>
          Displays e.g. 0.175 or 0.000.

          NB Only lightly tested with 17.5 and zero rated items.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            That's genius! Such a simple idea.

            Cheers Norman.

            Comment


              #7
              Tax1 and Tax2 can be used ...
              Unfortunately, not.

              These variables are for use in the Cart and they always return dummy values of £3.84 and £0.00 when used in a Product Layout in Design Mode. On the uploaded site they display as NETQUOTEVAR:TAX1 NETQUOTEVAR:TAX2.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                I spoke too soon...

                Which layout can I use this code inside? Everywhere I put it I get an error saying:

                The 'TaxExclusivePrice' variable has been placed within the 'whatever' layout but it won't work here. Ditto for TaxInclusivePrice.

                The code I've been working on lives at section level.

                Comment


                  #9
                  You're working with Product level variables so they are only available within Product Layouts.

                  As is the ProductPriceRaw variable that you refer to in your OP.

                  Also note that I've just tweaked my post #5 so that it will work regardless of the currency the site uses.

                  If you're working at the Section level, then you would need to put something like

                  <actinic:block type="ProductList">
                  ...
                  </actinic:block>

                  Around this code (and maybe an inner blockif ListIndex == 1) if there's more than one product per Section.
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #10
                    and I've used the ProductPriceRaw variable
                    This won't work at the present if you use Duplicates. A bug involving ProductPriceRaw in Duplicates doesn't track changes you make to product prices.

                    See http://community.actinic.com/showthread.php?p=306621 for details and a workaround.
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      I seem to recall Gabriel posting some php that extracted values from the Actinic database - blowed if I can find it now though.

                      Comment


                        #12
                        Cheers Norman,

                        I was working within a Product List initially. Not sure what I was doing wrong, but I used your code in a different product list far away from what I was doing, and simply used your $taxrate variable where I needed it. Thank you.

                        Comment


                          #13
                          Originally posted by NormanRouxel View Post
                          This won't work at the present if you use Duplicates. A bug involving ProductPriceRaw in Duplicates doesn't track changes you make to product prices.

                          See http://community.actinic.com/showthread.php?p=306621 for details and a workaround.
                          Ouch!

                          I saw this while I was researching my issue and thought "That doesn't apply to me". It's now just occurred to me that yes, it will apply because my client is using quite a number of duplicates...

                          At least I found out about it now and not three weeks after delivery...

                          Comment


                            #14
                            Another gotcha, eh!

                            Note that I just amended my workaround for the ProductPriceRaw so that it (hopefully) works on all types of currencies.
                            Norman - www.drillpine.biz
                            Edinburgh, U K / Bitez, Turkey

                            Comment


                              #15
                              Got it. Thanks for all your help guys.

                              Comment

                              Working...
                              X