DH
Asked
Hi,
I need to display the exclusive price (without vat, tax) in the "List Products" (we already have 'Cost' and 'Price'), how can I achieve this ?
I need to link the tax table (->join('tax_rates', 'tax_rates.id=products.tax_rate', 'left');) in **getProducts($warehouse_id = null)** in Products.php but have no idea where to place the calculation and to return the result as a new column
Thanks for your suggestions,
Domi.
I need to display the exclusive price (without vat, tax) in the "List Products" (we already have 'Cost' and 'Price'), how can I achieve this ?
I need to link the tax table (->join('tax_rates', 'tax_rates.id=products.tax_rate', 'left');) in **getProducts($warehouse_id = null)** in Products.php but have no idea where to place the calculation and to return the result as a new column
Thanks for your suggestions,
Domi.
- MSAnsweredHello,
You can update the `select` on database in the same `getProducts ` method. You can do all in select with sql or select the `tax_rates` .`rate` and do it in the view. The documentation.pdf has the general guide on adding/removing column, that would be helpful to understand.
Thank you - DHAnsweredHi,
thanks for this but the documentation show how to add a field from the database but in my case I need to perform some calculations, I need to get the price without tax so I need to divide the sale price by removing the percent of vat from another table - in our countries, there is no sense to display the price including vat as the vat is for the government.
I can I perform this ?
regards,
Domi. - DHAnsweredHave found the solution,
in the select, I have added the following : **(price * 100 / (100 + {$this->db->dbprefix('tax_rates')}.rate)) as exclprice** and, of course, a join with the tax_rate table.
but how to do if I need a more complex formula with if..then for example ? as **$this->datatables->generate();** generates rows based on fields ?
Tkx,
Domi. - MSAnsweredHello,
Yes, you should be able to manage with select. If it's not possible then you can select the columns and do calculation with render function in datatables same as price & quantity is being formatted.
Thank you - DHAnsweredSorry, not clear your answer.
can you, please, provide a small example with an if/then/else in select or in a "render function" ?
tkx in advance,
Domi. - DHAnsweredMeanwhile, I has solved like this :
```php
->select($this->db->dbprefix('products') . ".id as productid, {$this->db->dbprefix('products')}.image as image, {$this->db->dbprefix('products')}.tax_method as tax_method, {$this->db->dbprefix('products')}.code as code, {$this->db->dbprefix('products')}.name as name, {$this->db->dbprefix('brands')}.name as brand, {$this->db->dbprefix('categories')}.name as cname, cost as cost, CASE WHEN tax_method = 0 THEN (price * 100 / (100 + {$this->db->dbprefix('tax_rates')}.rate)) ELSE price END as exclprice, price as price, COALESCE(wp.quantity, 0) as quantity, {$this->db->dbprefix('units')}.code as unit, wp.rack as rack, alert_quantity", false)
```
see the CASE/IF/ELSE ...
maybe you could put this in a future release as it is more interresting to display the price with exclusive taxes as taxes go to the government
sincerly,
Domi. - MSAnsweredHello,
You can have select statement as you need. No one before asked about this but I will check in future updates.
Thank you - DHAnsweredStrange because in our countries (Belgium, ...) this kind of lists have always prices with vat exclusive ...
btw : thanks for your reply and help,
Domi. - Login to Reply