Menu

#23 Add retail price tax inclusive option

v2.3.1
closed
jekkos
None
1
2015-05-04
2014-09-12
jekkos
No

Tax inclusion option should be added to the configuration screen. For Europe (Belgium at least) most of the time prices are always tax inclusive. this means that a user will enter tax inclusive prices in the system and the receipt should only mention prices in which a tax has already been incorporated.

This means on one hand that if the option is enabled, no extra tax should be added to the subtotal, as is done now the American way.

This is only different when you make 'invoices', which means that you don't charge any tax to the customer you're selling to. In this case the is_taxable flag would be set to false.

in that case behavior of the receipt should change to calculate the totals with the following formula (use price and substract the included tax value)

price * quantity (1 - discount / 100) * (100 / 100 + taxrate)

  1. so in the first place the get_taxes method should be changed with code below
  2. secondly, if a customer is taxable and prices are tax inclusive, get_taxes shouldn't be added to the subtotal at the end of the receipt (but can be mentioned separately to avoid confusion)
  3. if a user is not taxable and prices are tax inclusive, all price calculations should be done with aformentioned formulae
  4. if anyone has more input on this, post away.
// get_taxes from libaries/Sales_lib.php
function get_taxes()
{
$customer_id = $this->get_customer();
$customer = $this->CI->Customer->get_info($customer_id);
$tax_included = $this->CI->config->config['tax_included'];

    //Do not charge sales tax if we have a customer that is not taxable
    if (!$customer->taxable and $customer_id!=-1)
    {
       return array();
    }

    $taxes = array();
    foreach($this->get_cart() as $line=>$item)
    {
        $tax_info = $this->CI->Item_taxes->get_info($item['item_id']);

        foreach($tax_info as $tax)
        {
            $name = $tax['percent'].'% ' . $tax['name'];

            if ( $tax_included )
            {
                $tax_amount=($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100)*($tax['percent'])/(($tax['percent']+100));
            }
            else
            {
                $tax_amount=($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100)*(($tax['percent'])/100);
            }

            if (!isset($taxes[$name]))
            {
                $taxes[$name] = 0;
            }
            $taxes[$name] += $tax_amount;
        }
    }

    return $taxes;
}

Discussion

  • jekkos

    jekkos - 2014-09-12
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -13,7 +13,6 @@
     3. if anyone has more thoughts or input on this, post away.
    
     ~~~~~~
    -
     // get_taxes from libaries/Sales_lib.php
     function get_taxes()
     {
    @@ -55,6 +54,4 @@
    
         return $taxes;
     }
    -
    -
     ~~~~~~
    
    • Group: Unstable_(example) --> v2.3.1
     
  • jekkos

    jekkos - 2014-09-12
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -10,7 +10,8 @@
    
     1. so in the first place the get_taxes method should be changed with code below
     2. secondly, if a customer is taxable and prices are tax inclusive, get_taxes shouldn't be added to the subtotal at the end of the receipt (but can be mentioned separately to avoid confusion)
    -3. if anyone has more thoughts or input on this, post away.
    +3. if a user is not taxable and prices are tax inclusive, all price calculations should be done with aformentioned formulae
    +4. if anyone has more input on this, post away.
    
     ~~~~~~
     // get_taxes from libaries/Sales_lib.php
    
     
  • jekkos

    jekkos - 2014-09-15

    Ok I commit a patch to my github for this feature.. Could someone give this a try and provide some feedback??

    latest version can be found at https://github.com/jekkos/opensourcepos

    just check tax inclusive pricing in the configuration and then all entered prices will be tax inclusive (no added taxes upon checkout).

    tax exclusive prices are calculated by substracting all present taxes from the entered item price. If desired I could add a cumulative tax option as well here.

     
  • Anonymous

    Anonymous - 2014-11-23

    regarding the tax inclusive.
    is there anyway to have the line totals and sub totals exclusive of tax.
    so for example we can have
    2 items at selling price $5 with tax of 15%
    the subtotal will be $8.69
    the tax will be $1.31
    the total $ 10.00

     
  • jekkos

    jekkos - 2014-11-24

    there is certainly a way. But I chose to show the prices all tax inclusive, as I found that showing it exclusive taxes will confuse the customers.

    subtotal method will need to be adapted so that the tax is substracted again after summing up the totals. send me a pm if you urgently need this feature.

     
    • Anonymous

      Anonymous - 2014-11-24

      I live in a country where the tax dept is quite strict, they more concerned about the slip, which prints through a fiscal printer that SMSs the figures to them.
      Before I(or get you to) do anything further changes, let me see if I can modify the slip to suit their needs

       
  • Jerome

    Jerome - 2014-12-02

    That's my working line :)
    just change tax_amount calculation by:

    $tax_amount=-1(($item['price']$item['quantity']-$item['price']$item['quantity']$item['discount']/100)/(($tax['percent'])/100+1)-($item['price']$item['quantity']-$item['price']$item['quantity']*$item['discount']/100));

     
  • Jerome

    Jerome - 2014-12-02

    To be changed in application/models/reports/summary_taxes.php:
    replace:
    FROM (SELECT name, CONCAT( percent, '%' ) AS percent, (
    item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100
    ) AS subtotal, ROUND( (
    item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100
    ) * ( 1 + ( percent /100 ) ) , 2 ) AS total, ROUND( (
    item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100
    ) * ( percent /100 ) , 2 ) AS tax

    by:
    FROM (SELECT name, CONCAT( percent, '%' ) AS percent, (

        (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100)
        / ( 1 + ( percent /100 ) )
    
        ) AS subtotal, ROUND( (
        item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100
        ) 
        , 2 ) AS total, ROUND(
    
        ((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100)/
        (1 + percent /100 ) -
        (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100))*-1
    
        , 2 ) AS tax
    
     
  • Jerome

    Jerome - 2014-12-02

    and the last one, application/models/sale.php in order to get correct value for the summary
    change this:

    (item_unit_pricequantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)(1-(SUM(percent)/100)) as subtotal,
    ".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description,
    (item_unit_pricequantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100) as total,
    (item_unit_price
    quantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)(SUM(percent)/100) as tax,
    (item_unit_price
    quantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)(1-(SUM(percent)/100)) - (item_cost_pricequantity_purchased) as profit

    by:
    (item_unit_pricequantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)/(1+SUM(percent)/100)
    as subtotal,
    ".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description,
    (item_unit_price
    quantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)
    as total,
    ((item_unit_pricequantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)/(1+SUM(percent)/100)-(item_unit_pricequantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100))-1
    as tax,
    (item_unit_price
    quantity_purchased-item_unit_pricequantity_purchaseddiscount_percent/100)/(1+SUM(percent)/100) - (item_cost_price*quantity_purchased)
    as profit

     

    Last edit: Jerome 2014-12-02
  • jekkos

    jekkos - 2014-12-04

    Think you will experience rounding errors with this approach. There is no guaranteed precision when using the regular math operators. Check the latest commits on github to see how it works. (github.com/jekkos/opensourcepos)

     
  • jekkos

    jekkos - 2014-12-04
    • status: open --> closed
     
  • jekkos

    jekkos - 2014-12-04

    implementation done and will be included in 2.3.1 (see github)

     
  • Jerome

    Jerome - 2014-12-04

    Thanks for the update, I will keep an eye on 2.3.1 :)

     
  • Anonymous

    Anonymous - 2015-05-04
    Post awaiting moderation.