create order invoice programmatically in Magento

In this article we can generate invoice programmatically.
$yourorder have your order, get invoice ID of your order and save with the help capture() function.
With this code your invoice for the order is created.


Here is code....
<?php
if($yourorder->canInvoice()) {

$yourinvoiceId = Mage::getModel('sales/order_invoice_api')
->create($yourorder->getIncrementId(), array());

$createInvoice = Mage::getModel('sales/order_invoice')
->loadByIncrementId($yourinvoiceId);

$createInvoice->capture()->save();
}
?>

Labels: