Magento Forum

   
Unable to save the invoice after change
 
steefking
Member
 
Total Posts:  46
Joined:  2012-01-22
 

I did a change to the website like below founded on this forum:

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.

What have i done wrong and how can i put it back in de database?

Steven

 
Magento Community Magento Community
Magento Community
Magento Community
 
steefking
Member
 
Total Posts:  46
Joined:  2012-01-22
 

Can someone help because i can’t finish my orders because i can’t save the invoice.

 
Magento Community Magento Community
Magento Community
Magento Community
 
GloriaGrayson
Jr. Member
 
Total Posts:  3
Joined:  2011-10-18
 

This is an ongoing issue ... does anybody have the solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
thesmartdude
Jr. Member
 
Total Posts:  4
Joined:  2012-03-02
 

Did you ever find a solution? Just started happening to one of my clients.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top