I am running Magento 1.5.1.0 and used to have problems with the tax calculation on invoice totals. While the calculation would be correct for all totals in my store, the backend invoice view and pdf invoices would display incorrect totals.

The difference between the wrong, displayed value and the correct value can be seen on this picture:
*(The short version: the subtotal will include shipping tax, although shipping tax is already icluded in shipping)*
<http://i731.photobucket.com/albums/ww318/vitamin6/orderview_fixed.jpg>

So I posted this issue on freelancer.com and someone managed to fix it. BUT as I found out later, the fix doesn't cover every scenario - if the order has free shipping, the invoice subtotal will still be incorrect. Here is a screenshot to show the difference:
<http://i731.photobucket.com/albums/ww318/vitamin6/orderview_freeship.jpg>

The freelancer edited the following file to fix the wrong tax calculation:
**app\code\local\Mage\Sales\Model\Order\Invoice\Total\Subtotal.php**

In there the following code:

```
    if ($invoice->isLast()) {
        $subtotal = $allowedSubtotal;
        $baseSubtotal = $baseAllowedSubtotal;
        $subtotalInclTax = $allowedSubtotalInclTax;
        $baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;

```

was replaced with this one:

```
    if ($invoice->isLast()) {
        $subtotal = $allowedSubtotal;
        $baseSubtotal = $baseAllowedSubtotal;
        //$subtotalInclTax = $allowedSubtotalInclTax;
        //$baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;
        $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
        $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);

```

Could somebody point me into the right direction, how I would have to further alter the file to make the fix work for orders with free shipping? 
More details about tax settings, etc can be given if needed - thank you in advance!