Change the pay() function in app\\\\code\\\\core\\\\mage\\\\sales\\\\model\\\\order\\\\invoice.php like shown below.
It’s better to make a new invoice.php in your local or community environment of course
/**
* Pay invoice
*
* @return Mage_Sales_Model_Order_Invoice
*/
public function pay()
{
if ($this->_wasPayCalled) {
return $this;
}
$this->_wasPayCalled = true;
$invoiceState = self::STATE_PAID;
if ($this->getOrder()->getPayment()->hasForcedState()) {
$invoiceState = $this->getOrder()->getPayment()->getForcedState();
}
$this->setState($invoiceState);
$this->getOrder()->getPayment()->pay($this);
// Check if order is already paid for. If so, it was paid for with an external payment provider
// so do not add Grandtotal to TotalPaid. This is a bugfix for a bug in the payment registration in Magento imho
// Fixed by Ed de Tollenaer http://www.deictuitgever.nl
if ($this->getOrder()->getTotalPaid() == $this->getOrder()->getGrandTotal()) {
$this->getOrder()->setTotalPaid($this->getOrder()->getTotalPaid());
$this->getOrder()->setBaseTotalPaid($this->getOrder()->getBaseTotalPaid());
} else {
$this->getOrder()->setTotalPaid($this->getOrder()->getTotalPaid()+$this->getGrandTotal());
$this->getOrder()->setBaseTotalPaid($this->getOrder()->getBaseTotalPaid()+$this->getBaseGrandTotal());
}
Mage::dispatchEvent(\\\’sales_order_invoice_pay\\\’, array($this->_eventObject=>$this));
return $this;
}
After this, run the following SQL statements on your database in PHPMyAdmin:
UPDATE sales_flat_order SET total_paid = total_invoiced WHERE total_paid > total_invoiced
UPDATE sales_flat_order SET base_total_paid = base_total_invoiced WHERE base_total_paid > base_total_invoiced
UPDATE sales_flat_order_grid SET base_total_paid = base_grand_total WHERE base_total_paid > base_grand_total
UPDATE sales_flat_order_grid SET total_paid = grand_total WHERE total_paid > grand_total
Then, go to Magento->Reports->Refresh statistics and refresh the lifetime statistics.
You can also reindex the database, but I am not sure if this is necessary.
When you go to the Reports->Sales->Total invoiced report you’ll see that the totals are up-to-date.
Everything works als planned but when i try to make the invoice it says: Unable to save the invoice.