Support for custom template - If > 0 then do not display

Hi community,

I am trying to create an Invoice PDF template according to my wishes and have been stuck for a few days, I hope you can help me?

I am trying to get the values that are 0 or empty not to be displayed in the PDF.
I am currently having problems with discount and mulltiple tax (see screenshot).

As soon as I have finalized the template, I would like to share the template and everything about it with the community.

Many thanks in advance.

<?php
        $taxarray2 = array();
        $linecounter = 0;
        foreach ($items as $item) { ?>
        <?php
                      // load all tax_rates/mdl_tax_rates and calc subtotal per rate
                      //$this->load->model('tax_rates/mdl_tax_rates');
                      //$taxarray1 = $this->mdl_tax_rates->where('tax_rate_id', $item->item_tax_rate_id)->get()->row();                                 
                      //$taxarray2[$item->item_tax_rate_id]->taxcode = $taxarray1->tax_rate_code;
                      if (!isset($taxarray2[$item->item_tax_rate_id]))
                            $taxarray2[$item->item_tax_rate_id]=array();
                      $taxarray2[$item->item_tax_rate_id]['taxdescr'] = $item->item_tax_rate_name;
                      $taxarray2[$item->item_tax_rate_id]['taxperc'] = $item->item_tax_rate_percent;
                      if (isset($taxarray2[$item->item_tax_rate_id]['netamount']))
                            $taxarray2[$item->item_tax_rate_id]['netamount'] += ($item->item_subtotal - $item->item_discount);
                      else
                            $taxarray2[$item->item_tax_rate_id]['netamount'] = ($item->item_subtotal - $item->item_discount);
                      if (isset($taxarray2[$item->item_tax_rate_id]['taxamount'])) 
                            $taxarray2[$item->item_tax_rate_id]['taxamount'] += $item->item_tax_total;
                      else
                            $taxarray2[$item->item_tax_rate_id]['taxamount'] = $item->item_tax_total;
                ?>
            <tr>
                <td><?php _htmlsc($item->item_name); ?></td>
                <td><?php echo nl2br(htmlsc($item->item_description)); ?></td>
                <td class="text-right">
				<?php if ($item->item_quantity > 0) : ?>
                    <?php echo format_amount($item->item_quantity); ?>
                    <?php if ($item->item_product_unit) : ?>
                        <br>
                        <small><?php _htmlsc($item->item_product_unit); ?></small>
                    <?php endif; ?>
				<?php endif; ?>
                </td>
                <td class="text-right">
				<?php if ($item->item_price > 0) : ?>
                    <?php echo format_currency($item->item_price); ?>
				<?php endif; ?>
                </td>
                <td class="text-right">
				<?php if ($item->item_tax_rate_percent > 0) : ?>
                    <?php echo format_amount($item->item_tax_rate_percent) . '%'; ?>
				<?php endif; ?>
                </td>
                <?php if ($show_item_discounts) : ?>
                    <td class="text-right">
                        <?php echo format_currency($item->item_discount); ?>
                    </td>
                <?php endif; ?>
                <td class="text-right">
				<?php if ($item->item_subtotal> 0) : ?>
                    <?php echo format_currency($item->item_subtotal); ?>
				<?php endif; ?>
                </td>
            </tr>
        <?php } ?>


        </tbody>
        <tbody class="invoice-sums">

        <tr>
            <td class="text-right"></td>
            <td <?php echo($show_item_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
                <?php _trans('subtotal'); ?>
            </td>
            <td class="text-right"><?php echo format_currency($invoice->invoice_item_subtotal); ?></td>
        </tr>
       
        <?php if ($invoice->invoice_item_tax_total > 0) {
            foreach($taxarray2 as $key => $value) :?>
                <tr>
                    <td <?php echo($show_item_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right"></td>
                    <td class="text-right"><?php echo 'USt.('. format_amount($value['taxperc']).'%)'; ?></>
                    </td>
                    <td class="text-right"><?php echo format_currency($value['taxamount']); ?></td>
                </tr>
        <?php endforeach ?>
        <!--<tr> Steuer Summe
                <td class="text-right"></td>
                <td <?php echo($show_item_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
                    <?php _trans('item_tax'); ?>
                </td>
                <td class="text-right">
                    <?php echo format_currency($invoice->invoice_item_tax_total);?>
                </td>
            </tr>-->
       <?php } ?>
1 Like

Your problem might be with the format_currency function, but let’s focus on 1 thing first.
See this:

$invoice->invoice_item_tax_total);

In all those places where you see those zeroes as amounts, make it this:

($invoice->invoice_item_tax_total != 0) ? $invoice->invoice_item_tax_total : null;

Try it out with one of those items, see what it looks Iike.

As soon as I have finalized the template, I would like to share the template and everything about it with the community

That’s really appreciated.
I’ve created a branch for you on the InvoicePlane repository: feature/custom-template-with-discount-and-multiple-tax

If you check out that branch and apply your customizations there, it’s also a little bit easier to see.

Your second tax part probably needs a database change.
And the name for your tax … Mwst? That needs a translation in ip_lang.php in application/language/

Hi UnderDog,

many thanks for your reply.
I have tested this, unfortunately the lines are still shown on the pdf. (screenshot below)

<?php if ($invoice->invoice_item_tax_total > 0) {
            foreach($taxarray2 as $key => $value) :?>
                <tr>
                    <td <?php echo($show_item_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right"></td>
                    <td class="text-right"><?php echo 'USt.('. format_amount($value['taxperc']).'%)'; ?></>
                    </td>
                    <td class="text-right"><?php echo format_currency($value['taxamount']); ?></td>
                </tr>
        <?php endforeach ?>
        <!--<tr> Steuer Summe
                <td class="text-right"></td>
                <td <?php echo($show_item_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
                    <?php _trans('item_tax'); ?>
                </td>
                <td class="text-right">
                    <?php echo format_currency($invoice->invoice_item_tax_total != 0) ? $invoice->invoice_item_tax_total : null;?>
                </td>
            </tr>-->

image

many thanks
mctiger