I have a range of products that do or do not include VAT. I always want to show the price including VAT to the customer so I have a flag that states whether the price includes VAT or not. Currently I add VAT in PHP which means the sorting is something off as MySQL sorts on the base price and sometimes VAT can make the results out of order.
What I would like then is to automatically add VAT to prices, where it is needed, within the MySQL query. How can I achieve this?
My products table look like this:
product_id, product_dayprice, product_weekprice, product_includevat
product_includevat is simply a bool i.e. 1 or 0… VAT is stored as a PHP variable
My sort code looks like this which is designed to put products with a price of 0 at the end
CASE product_daypriceWHEN 0 then 40000 ELSE product_dayprice END
if that
product_include_vatis a bool field, then it’d be as simple asif the includevat field is false, it’ll evaluate to an integer 0, and your vat gets zeroed out in the multiplication.