Showing posts with label Transaction table. Show all posts
Showing posts with label Transaction table. Show all posts

December 15, 2013

Magento create invoice programmatically

How to create invoice for order in magento


$order = Mage::getModel('sales/order')->loadByIncrementId([order_id]);

if(!$order->canInvoice())
{
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}

$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

$invoice->setTransactionId([last_trans_id]);

$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);

$invoice->register();

$transactionSave = Mage::getModel('core/resource_transaction')
                                              ->addObject($invoice)
                                              ->addObject($invoice->getOrder());

$transactionSave->save();