cancel
Showing results for 
Search instead for 
Did you mean: 

How to show VAT number on all invoices

How to show VAT number on all invoices

Hi,

 

I have searched this forum but unable to locate the answer.

 

We are running Magento 2.4.4, we need to show our VAT number at the bottom of all invoices. Currently, when you print these as a PDF, tax calculations are shown but not VAT number so it can't be used as a VAT invoice and there is no other way to generate a VAT invoice in Magento.

 

Is there a way to enable this on all invoices in the footer / anywhere?

 

Kind Regards,
Chris.

3 REPLIES 3

Re: How to show VAT number on all invoices

Would adding the VAT number in Stores > Configuration > Sales > Sales > Invoice and Packing Slip Design > Address suffice for your needs?

 

That would add it to the top right corner of your print invoice PDF

Founder at https://agency418.com

Re: How to show VAT number on all invoices

Spot on, that's all I need.

 

Appreciate the help!

Re: How to show VAT number on all invoices

Hi @salesurmst8ade,

To show Vat number In all the invoices PDF you have to perform following steps:

 

Step 1: Create a custom module,
assuming the module is named Custom_InvoiceVatNum

 

Step 2: Create a new ‘invoice.php’ file
Copy the Invoice.php file from vendor/magento/module-sales/Model/Order/Pdf/ to app/code/Custom/InvoiceVat/Model/Order/Pdf/.

 

Your file structure should look like this:
app
|_ code
|_ Custom
|_ InvoiceVatNum
|_ Model
|_ Order
|_ Pdf
|_ Invoice.php

 

Step 3: Modify the Invoice.php file
Edit the Invoice.php file in your custom module to include the VAT number. Here is a simplified example:

 

<?php
namespace Custom\ InvoiceVatNum \Model\Order\Pdf;
class Invoice extends \Magento\Sales\Model\Order\Pdf\Invoice
{
    protected function insertVat($page, $source){
        $order = $source->getOrder();
        $customerId = $order->getCustomerId();
        if ($customerId) {
            $vatNumber = $order->getCustomerTaxvat();
            if ($vatNumber) {
                $page->drawText(__('VAT number:'), 470, 450, 'UTF-8');
                $page->drawText(__($vatNumber),535, 450, 'UTF-8');
            }
        }
    }
}

 

Step 4: Register the Override in di.xml

 

Create a di.xml file to tell Magento to use your custom Invoice.php file instead of the core one.
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:frameworkSmiley SurprisedbjectManager/etc/config.xsd">
<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Custom\ InvoiceVatNum \Model\Order\Pdf\Invoice" />
</config>

Step 5: run all the commands11.jpg

 

If the issue will be resolved, Click Kudos & Accept as a Solution.