Display discount in template

Hello,

I added a code to display the discount (percentage and amount) in the default quote template in “public”, I’ll try to add this function in all other templates (invoice, pdf, etc.), but I’m not an expert, so I hope this is a correct way.

Code:

<?php 
// YEU Display percentage and amount of the discount
if ($quote->quote_discount_percent != floatval(0)) { ?>
    <tr>
        <td class="no-bottom-border" colspan="3"></td>
        <?php $display_discount_percent = ($quote->quote_discount_percent); ?>
        <td><?php echo lang('discount') . ' ' . $display_discount_percent; ?>%</td>
        <?php $get_subtotal = ($quote->quote_item_subtotal); ?>
        <?php $display_discount_amount = ($display_discount_percent / 100) * $get_subtotal; ?>
        <td><?php echo format_currency($display_discount_amount); ?></td>
    </tr>
<?php } elseif ($quote->quote_discount_amount != 0 ) { ?>
    <tr>
        <td class="no-bottom-border" colspan="3"></td>
        <?php $display_discount_amount = ($quote->quote_discount_amount); ?>
        <?php $get_subtotal = ($quote->quote_item_subtotal); ?>
        <?php $display_discount_percent = ($display_discount_amount / $get_subtotal) * 100; ?>
        <td><?php echo lang('discount') . ' ' . $display_discount_percent; ?>%</td>
        <td><?php echo format_currency($display_discount_amount); ?></td>
    </tr>
<?php } ?>

Any suggestions? If it’s ok and if you want, I can upload my edit files “default_with_discount.php” in github.

Thanks.

Could you share a screenshot of what it would look like?

Hi,

now I can’t do it (I’m reading with a smartphone), but I’ll post the screenshot as soon as possible.

Just a question, please. I read your thread about the release 2.

Well, do you think it’s possible to add a discounts adminis totration in the same mode of adding tax?
In this case the item in menu will be a generic “Add Item” and a user can add tax or discount or coupon or everything…

The options would be only:

  • plus or minus sign;
  • amount or percentage choise:
  • order to apply (e.g. discount before than tax, etc.)

In this way the management should be more flexible and easy…

Maybe. :smile:

Screenshot public template quote with discount:

There is a little problem with this solution. If I add a discount amount of €100 per subtotal €300, it results this percentage: 33,333333333%. How can I fix this? I’d like to view only 33,33%.

Many thanks.

<?php echo round($discount_amount, 2); ?>
1 Like

Thank you, but…

Ehm…

Where do I put this code in my code? :disappointed_relieved:

Where the discount should be displayed

1 Like

If anyone’s interested, I’ve hacked together some code that will display a per-item discount column, but only if one or more items have a discount (the column is hidden if no items have a discount:

First, add the following in the thead section of the invoice-items table between the price and total entries:

<?php
    $discount = false;
    foreach ($items as $item) {
        if ($item->item_discount != 0) {
            $discount = true;
        }
    }
    echo $discount ? '<th class="text-right color-d">' . lang('discount') . '</th>' : '';
?>

Then add the following inside the table’s foreach loop between the $item->item_price and the $item->item_subtotal

<?php echo $discount ? '<td  style="vertical-align:top" class="text-right">' . format_currency($item->item_discount) . '</td>' : ''  ?>

Finally, change the $item->item_subtotal entry to $item->item_total, and everything should be working. There’s probably a more elegant way to achieve the same thing, but this one is working for me.

(Incidentally, many thanks to the developers for creating such a flexible and easy-to-edit invoice template system. For me, it’s what really makes this software work for me.)

1 Like

Thank you Kovah and thank you rault!

Can this be added in InvoicePlane next version? :smiley:

Btw. in Invoice and Quote section there is an option to add discount per item and also add discount on a total amount. Will this show discount per item and also discount per total amount?

Hi,

with my code you can display the general discount, with rault’s code you can display each item discount per product.

I’ll upload all these templates with view discount as soon as possible. I need to work on them…

yes, definately much needed disply basic items like discount and notes in quotes and invoices.
please upload your template so we can use.
thanks for hard work

Hello to all.

There is a little problem with the discount option. The discount should be calculated before all taxes, or an user should be able to choose whether to apply it before or after.

How can I fix this?

Thank you in advance!

it should be calculated before tax only.

based on this I added some code to change colspan from 3 to 4 if discount is active:

replace:

<td colspan="3">

with:

<?php echo $discount ? '<td colspan="4"></td>' : '<td colspan="3">'  ?>

replace all the occurrences of:

<td class="no-bottom-border" colspan="3">

with:

<?php echo $discount ? '<td class="no-bottom-border" colspan="4"></td>' : '<td class="no-bottom-border" colspan="3"></td>'  ?>
1 Like

So, can someone post what to add and where? :smile:

Also, can this be added in the main tree in next version?

Anyone? Kovah? The invoice and quote pdf have full price of items and the final price that has the amount with discount. It is not with the tax law, at least in my country, to have that kind of a invoice where there is a discount included but is not seen from paper (pdf) The discount function has no meaning in this way…

EDIT: you should include raults post in invoice and quote templates and that is it!

have you tried this modifications?

https://community2.invoiceplane.com/t/display-discount-in-template/1179/8?u=foolab
https://community2.invoiceplane.com/t/display-discount-in-template/1179/15?u=foolab

Where is your code, I need this despartly, and where do i put it in the default quote template? I just need a general discount not a per item discount…Thank you

Hi, can this be added by default. Just realised that when I add a discount it just deducts it “silently” so the invoice looks really odd!