This is my class for add some custom totals to invoice:
class Devpassion_Rowtotal_Model_Order_Invoice_Total_Totalpopust extends Mage_Sales_Model_Order_Invoice_Total_Abstract{
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
$items = $invoice->getAllItems();
foreach ($items as $item){
$subtotaldisc = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount() - $item->getDiscountAmount();
}
$invoice->setTotalpopustAmount($subtotaldisc);
return $this;
}
public function fetch(Mage_Sales_Model_Quote_Address $invoice)
{
if ($invoice->getTotalpopust() > 0)
{
$invoice->addTotal(array(
'code' => $this->getCode(),
'title' => Mage::helper('rowtotal')->__('Test tekst'),
'value' => $invoice->getTotalpopust()
));
}
return $this;
}
}
And this is my inittotals() function:
class Devpassion_Rowtotal_Block_Sales_Total_Totalpopust
extends Mage_Core_Block_Abstract{
public function initTotals()
{
$parent = $this->getParentBlock();
$value = $parent->getSource()->getTotalpopust();
// if ($value > 0)
// {
$total = new Varien_Object(array(
'code' => 'totalpopust',
'value' => $parent->getSource()->getResult(),
'base_value' => $parent->getSource()->getResult(),
'label' => $this->__('Cijena sa popustom'),
'field' => 'totalpopust'
));
$parent->addTotal($total, 'totalpopust');
// }
return $this;
}
}
Please can someone advice what is wrong in definition of this classes, because nothing shows up on Invoice, neither on print pdf (I have defined in config.xml to show in pdf), neither on adminhtml (I have defined layout for adminhtml).