Written by Giles Bennett
Whilst a number of third party modules allow you to adjust the columns and totals shown in the PDF invoice print-outs in Magento, there's not much control over the default PDF invoices - a recent request from a client was to remove all reference to tax in the PDF invoices, so here's how to go about it.
There are three files which need to be copied over from the core directory as follows before being edited. They are :
app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php to app/code/local/Mage/Sales/Model/Order/Pdf/Invoice.php
app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php to app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php to app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php
The first of these files, Invoice.php, controls the product grid into which Invoice/Default.php then renders each individual product. It's simple enough to remove the Tax heading column by finding and removing the following lines :
$lines[0][] = array(
'text' => Mage::helper('sales')->__('Tax'),
'feed' => 495,
'align' => 'right'
);
The second of the files, Default.php, renders each individual item, and again it's simple enough to track down and remove the tax entry for each item by finding and removing the following lines :
// draw Tax
$lines[0][] = array(
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 495,
'font' => 'bold',
'align' => 'right'
);
The third and final file, Abstract.php, is a little more complicated. The function in question is called 'insertTotals' and this runs through each total (subtotal, tax, shipping, grand total, etc.) and renders it. Within that function is a foreach block which looks like this :
foreach ($total->getTotalsForDisplay() as $totalData) {
$lineBlock['lines'][] = array(
array(
'text' => $totalData['label'],
'feed' => 475,
'align' => 'right',
'font_size' => $totalData['font_size'],
'font' => 'bold'
),
array(
'text' => $totalData['amount'],
'feed' => 565,
'align' => 'right',
'font_size' => $totalData['font_size'],
'font' => 'bold'
),
);
}
This code is what generates the actual line shown on the invoice, and adds it to an array for rendering. Because of this, we know that
$totalData['label']
must correspond to the title of the tax line on the totals - in our case 'VAT:'. We can therefore adjust this code with an if clause to only render the line if the total's title is not 'VAT:' as follows :
foreach ($total->getTotalsForDisplay() as $totalData) {
if($totalData['label'] != "VAT:") {
$lineBlock['lines'][] = array(
array(
'text' => $totalData['label'],
'feed' => 475,
'align' => 'right',
'font_size' => $totalData['font_size'],
'font' => 'bold'
),
array(
'text' => $totalData['amount'],
'feed' => 565,
'align' => 'right',
'font_size' => $totalData['font_size'],
'font' => 'bold'
),
);
}
}
And hey presto, your invoices generate without any reference to VAT. It's not fool-proof - multi-language setups would need to adjust the logic to take into account the possible variants of 'VAT:' that their store may output, but it's a short hack that gets the job done.