Bug: item_subtotal does not include item discount

Expected Behaviour:
In line items, $item->item_subtotal should contain the final cost of the item, taking into account any taxes and discounts for the item.


Actual Behaviour:
$item->item_subtotal does not include the item discount.


Example:


Workaround:
This is possible to fix in the template by changing:
<?php echo format_currency($item->item_subtotal); ?>
to:
<?php echo format_currency($item->item_subtotal - $item->item_discount); ?>
but that won’t actually solve the real problem: that $item->item_subtotal is wrong.

Cheers

Geoff.

2 Likes

And…
The calculation of the tax is not right on the invoice screen and the invoice template when you have a discount applied.

I think in the file application/modules/invoices/models/mdt_items_amounts.php the order of the calculation is not right.
And a extra calcutation has to be added.

line 35: (public function calculate($item_id))

$item_subtotal = $item->item_quantity * $item->item_price;
$item_tax_total = $item_subtotal * ($item->item_tax_rate_percent / 100);
$item_discount_total = $item->item_discount_amount * $item->item_quantity;
$item_total = $item_subtotal + $item_tax_total - $item_discount_total;

It should be:

$item_subtotal = $item->item_quantity * $item->item_price;
$item_discount_total = $item->item_discount_amount * $item->item_quantity;
$item_tax_total = ($item_subtotal - $item_discount_total) * ($item->item_tax_rate_percent / 100);
$item_total = $item_subtotal + $item_tax_total - $item_discount_total;

With this code the invoice screen and the template are showing the correct data.
EDIT: for the standard InvoicePlane invoice template to work correct, you have to change the itemtotal to:

     <?php echo format_currency($item->item_subtotal - $item->item_discount); ?>

Don’t forget to save a “pending” invoice after that the change is visible.

1 Like