Simple Invoices logo
    • CommentAuthormichaeld
    • CommentTimeJan 13th 2010 edited
     permalink
    I want to enable PRE-TAX discounts. For example, if a product costs $100 and I give a 25% discount, the new price should be $75.

    I want to be able to tax ONLY the DISCOUNTED price of $75.

    As it is, I've set up TWO tax items per invoice item. One column is meant to be the DISCOUNT, and the other is used for TAX....however....this doesn't work because it taxes the item on its original price.

    I'm very capable and culpable as a programmer, but I cannot for the life of me figure out how to set up a proper EXTENSION that will allow me to do this. The documentation I'm finding doesn't seem to match up with current versions.

    Does anyone have a solution for this?



    What I WANT: $100(item price) - 25%(discount) = $75(post discount price) x 9.75%(tax) = $82.31

    What its doing: $100(item price) - 25%(tax item 1) x 9.75%(tax item 2) = $84.75 (how is it getting this #???)
    • CommentAuthorjustin
    • CommentTimeJan 13th 2010
     permalink
    hey michael

    i just looked at the code - invoice save and tax calc is the most confusing section of the code :)

    re $84.75
    $100 + (-25% of $100) + (9.57% of $100) = $84.75

    re code
    - from include/sql_queries.php

    /*
    Function: getTaxesPerLineItem
    Purpose: get the total tax for the line item
    */
    function getTaxesPerLineItem($line_item_tax_id,$quantity, $unit_price)
    {
    global $logger;

    foreach($line_item_tax_id as $key => $value)
    {
    $logger->log("Key: ".$key." Value: ".$value, Zend_Log::INFO);
    $tax = getTaxRate($value);
    $logger->log('tax rate: '.$tax['tax_percentage'], Zend_Log::INFO);

    $tax_amount = lineItemTaxCalc($tax,$unit_price,$quantity);
    //get Total tax for line item
    $tax_total = $tax_total + $tax_amount;

    //$logger->log('Qty: '.$quantity.' Unit price: '.$unit_price, Zend_Log::INFO);
    //$logger->log('Tax rate: '.$tax[tax_percentage].' Tax type: '.$tax['tax_type'].' Tax $: '.$tax_amount, Zend_Log::INFO);

    }
    return $tax_total;
    }

    /*
    Function: lineItemTaxCalc
    Purpose: do the calc for the tax for tax x on line item y
    */
    function lineItemTaxCalc($tax,$unit_price,$quantity)
    {
    if($tax['type'] == "%")
    {
    $tax_amount = ( ($tax['tax_percentage'] / 100) * $unit_price ) * $quantity;
    }
    if($tax['type'] == "$")
    {
    $tax_amount = $tax['tax_percentage'] * $quantity;
    }

    return $tax_amount;
    }


    if you want to change how total tax is calculated review the above functions aswell as the main insertInvoiceItem function

    post if you have queries - im sure we can make this work for you

    cheers

    justinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
    • CommentAuthormichaeld
    • CommentTimeJan 14th 2010
     permalink
    blerg! I must be dumb... I've tried for 2 days to figure this out but I just can't seem to get it to work.

    I tried creating my own extension, adjusting the way tax is calculated, added a PRE-tax dollar amount and tried to have UNIT_PRICE auto calculate
    Example: PRE_PRICE - DISCOUNT (% or $) = UNIT_PRICE

    but I just can't get it to work.
    Thanks for your reply though.
    Please let me know if you get it to work. I'd really be interested in using that function.
    • CommentAuthorame
    • CommentTimeFeb 3rd 2010
     permalink
    hi, did you find a way to get this functionality done? i'm really interested too.

    i talked to my tax advisor and it is preferable ("the correct way") to calculate a discount before the vat applies. e.g.
    100€ - 10% DIS = 90€
    + 20% VAT = 18€
    TOTAL: 118€

    the only time (according to my tax advisor) you are allowed to apply a discount after the vat calculation is, if you give discounts on "cash in the moment" payments. e.g.
    100€ + 20% VAT = 120€
    -10% DIS of 100€ = -10€
    TOTAL: 110€

    i hope i could explain my point (sorry for my english, i'm not a native speaker)

    it would be interesting to see an additional input field in the invoice creation page, something like:
    1st Product - Description - Unit Price - Qty. - Disc. - VAT - Product Total
    2nd Product - Description - Unit Price - Qty. - Disc. - VAT - Product Total
    ----------------------------------------------------------------------------------
    Sub Total:
    VAT:
    Total:

    thanks, andreas
    • CommentAuthorReallyNA
    • CommentTimeJun 16th 2010 edited
     permalink
    Any news on this field?

    I also need the discount to work pre-tax, the legal way, as michael and ame write here.

    Can't we create some kind of a new tax (discount) and give that tax a custom id. Imagine tax_id=100 Then in the formula, make the product subtract that amout on tax_id if existed if not the formula will be the same. Just a thought, making this in coding is another question that I don't know yet how to do. Really need to have some coding classes :p
    • CommentAuthorifara
    • CommentTimeJun 17th 2010
     permalink
    hello Justin and partners of the forum, I also would need this area, since in Spain is used a lot the discount, although on the other hand, see that it would be complicated when having that to modify several forms. Good to see what says Justin thereof.
    Greetingscheers from Canary Islands
  1.  permalink
    Hi

    I think the most logical way to create such a functionality is by introducing a new extension for discounts all together. I think we should have an extra field on all te invoices for discount the same way we have VAT/TAX field. This was we can easily adjust tax and discount in one invoice item line and also be able to manage discounts. I think the discounts can use almost the same structure as the tax extension, the only difference would be when applying discount it will be considered before the tax is applied to the item. Thus saving a lot of time for interface development for discount management.

    I believe this way would be most simplest and logical for the users/clients as well i.e. create invoice -> select product -> apply discount -> apply tax -> save, simple as that. Ofcourse this would require updating invoice interfaces and maybe some reports as well, but it is not a big change though.

    Let me see what I can do, although it may take some time but I think my clients would need this as well. I am happy to share my work if and when I develop it.

    Thanks
    Harvinder Singh
    • CommentAuthorReallyNA
    • CommentTimeJun 18th 2010
     permalink
    Hi Harvinder

    Thats a great idea. Please tell me in what I can help (and by I, I think I can say all of us here at SI).

    Regards
  2.  permalink
    We have a meeting tomorrow and will need to decide whether this module be of any use to us or not, at this point in time we do not know if our client's would decide on buying our service just on the factor of this feature. However I do think that this is a good feature to be present in the system at least.

    I will post the outcome of our meeting tomorrow and see where we go after that. If the outcome is yes we need it, than the development will start straight away and I am sure within a few days it should be finished, but if we decide not to go ahead with this at this point in time then it will have to be delayed foe possibly atleast a month or so.

    Thanks
    Harvinder Singh
    • CommentAuthorReallyNA
    • CommentTimeJun 22nd 2010
     permalink
    Hi Harvinder Singh,

    So, what's the outcome of the meeting?

    If you start to develop this feature please tell me in what I can help since this is a must-have feature for me.

    Regards
  3.  permalink
    Hi

    Unfortunately our requirements list does not have this feature ticked currently and there is a good chance that it will not be implemented by myself. However you never know if a few of our clients request this feature we might go ahead with the development, but there are no requests so far.

    Our simple solution is to insert the discounted price while creating the invoice.

    Sorry, I couldn't be much help.

    Thanks
    Harvinder SIngh
    • CommentAuthorReallyNA
    • CommentTimeJun 22nd 2010 edited
     permalink
    Hi

    Sad to read that you can't help with this. I'm not a coder but if have some time, can you please point the "directions" to where should we change the code?In what files assuming that we can have something similar to tax extension.

    If someone else can help on this, my thanks in advance.

    Justin, we must add discount option to SI todo. Is a must for European users.
    • CommentAuthorjustin
    • CommentTimeJun 23rd 2010
     permalink
    hey reallyNA

    can the discount be just another line item/product - with a negative value?

    cheers

    justinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
  4.  permalink
    I think if you create another line of item lets say with a product = Discount and put a negative price and the same amount of TAX, it should have exactly the same impact in the price:

    Item 1 - qty=1, Toothbruch, price=10, tax=17.5%, total=11.75
    Item 2 - qty=1, Discount, price=-1(10 percent discount), tax=17.5%, total=-1.175

    Grand total = 10.575

    And if we do it the way you want = price (10) - discount (1) = 9 => 9 * Tax (17.5%) = 10.575

    So you get the same effect, apparently I have just checked by creating a test invoice. That when you follow the above steps by creating a negative item (discount) it gets negated before any tax is applied. Thus achieveing the same level of adjustments as mentioned in your requirements.

    Hope this help, although you will end up with 2 rows for one invoice item (1=item and 2=discount) you do not need to do any changes in the codebase to get this working. Possibly just create a new product called Discount for your convenience.

    Thanks
    Harvinder Singh
    • CommentAuthorReallyNA
    • CommentTimeJun 23rd 2010
     permalink
    Hey Justin and Harvinder

    Thats a way we can do it, and the result yes, it's the same.

    But the problem is that the presentation of the invoice (the printed one for example) will be incorrect besides all the "liquid" values. Only the Total will be correct.

    As @ame write above, the current display should be:


    1st Product - Description - Unit Price - Qty. - Disc. - VAT - Product Total
    2nd Product - Description - Unit Price - Qty. - Disc. - VAT - Product Total
    ----------------------------------------------------------------------------------
    Sub Total:
    VAT:
    Total:

    If we have two products, one real product and other as discount, we will always have an increase of the VAT, the invoice will display a wrong value for sub-total (because again, it will make product +(-discount)) and VAT total.

    I really need this to work this way. My invoices have always big quantities, and with big quantities we need to make discounts (example: 1000 of product 1 will have 5% discount, less than 1000 no discount, 2000 will have 7%, and something like that.

    Again, if someone can help will this it will be much aprecciated and a good feature for SI - In europe this is a must have feature, so to me its a little odd that SI dont have it yet.

    Thanks
    • CommentAuthorReallyNA
    • CommentTimeJun 28th 2010
     permalink
    Any new idea to help making this done to SI?
  5.  permalink
    Hi

    Discounts is a completely new field for SI and I think if this is done in SI why not do it properly i.e. different type of discount i.e. % or value etc. However I think it will take some time for anyone to do some work on this. If you know PHP and know a little bit of inner workings of SI, you can possibly create something similar to the tax extension. It will involve working with the invoice calculation and other operations i.e. reports maybe and possibly you may need to change the view in the invoices grid to have a column to discount as well. It is not impossible to do but requires some knowledge of PHP and SI to be able to do it yourself, otherwise you will have to wait for it and I don't think that this even exists on Justin's todo list.

    Thanks
    • CommentAuthorReallyNA
    • CommentTimeJun 30th 2010
     permalink
    I think that this dont exist on Justin's todo list but since I don't think I'm the only one that nead this, maybe it could be an idea to add this so that anyone that can help, start creating this.

    I just know a little bit of PHP so alone I'm sure that I can't have this done. I do know that this will be a huge work, but is strange for me is that SI dont have this function yet.

    Let's keep this discussion live, maybe someone can help and Justin put this on todo list.
    • CommentAuthorjmruas
    • CommentTimeJun 30th 2010 edited
     permalink
    In Portugal (and I presume in Europe) we need to discriminate sum VAT. So we have to show:

    Sub Total:
    VAT 20%:
    VAT 5%:
    VAT x%:
    Total tax:
    Retention:
    Total:

    Retention is like a discount. Discount can't be applied after the VAT but over the amount before tax.

    It's hard when we have a specific need (will it be so specific or people use invoices out of the law? :)

    Cheers,
    José
    • CommentAuthorjustin
    • CommentTimeJul 1st 2010
     permalink
    hey guys

    thanks for all the posts and info!!

    have added it to our ideas list http://code.google.com/p/simpleinvoices/wiki/ideas

    there have been request for 'cumulative' taxes - which is used in some parts of Canada - given that pre-tax discount and cumulative taxes are the same - just opposite directions - i should be able to add support for this

    main reason i was not in favour of discounts was the need for yet another field in the new invoice display ... but on further thinking - now that i can merge pre-tax discounts with cumulative taxes a new field is not needed - just an optional tax cal method to be added

    this should happen - no time frame just yet

    cheers

    justinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
    • CommentAuthorReallyNA
    • CommentTimeJul 2nd 2010
     permalink
    Hey Justin,

    Happy to know that you added this to the ideas.

    No time frame, but let us know what we can do to make this done...

    Cheers,

    NA
    • CommentAuthorjustin
    • CommentTimeJul 2nd 2010
     permalink
    thanks NA

    will ask you guys to test once development starts

    cheers

    justinSmarterInvoices.com Simple Invoices hosting | SixHQ.com Simple Invoices custom development | Me
  6.  permalink
    Hi Guys

    Jut an update, we have not gone to this route to provide discount features to our clients yet. I think our requirements will be covered by using to tax lines per product. The first tax line could be used as discount i.e -10% and the second tax line could be used for the actual tax. Thiis way the first tax line which will be the discount is applied on the pre-taxed price of the product.

    Hope this helps, because we wont be having two lines per product but two tax lines per product instead (discount and tax).

    Thanks
    Harvinder Singh