Magento get order increment id

How can you get order increment id/last order id in magento? You can get magento order increment id/last order id into the success.phtml page by this method.Also you can get magento order increment id/last order id into admin panel as following methods.

Magento get order increment id into the success.phtml page

$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
Following method is not working sometimes….
$orderId = $this->getOrderId();
This is another method
$_orderID = Mage::getModel('sales/order')
            ->loadByIncrementId($this->getOrderId());

Magento get order increment id into admin panel

// Getting last id from all orders
$orders = Mage::getModel('sales/order')->getCollection()
          ->setOrder('increment_id','DESC')
          ->setPageSize(1)
          ->setCurPage(1);
$orderId = $orders->getFirstItem()->getEntityId();

Above method will not work, if there are multi store in a single magento setup.Try to this one.

$orders = Mage::getModel('sales/order')->getCollection()
          ->setOrder('created_at','DESC')
          ->setPageSize(1)
          ->setCurPage(1);
$orderId = $orders->getFirstItem()->getEntityId();

Note there is a different of ->setOrder('created_at','DESC').

Magento get order details by order id

$order = Mage::getModel('sales/order')->load($orderId);
$_grand = $order->getGrandTotal();
$customerName = $order->getCustomerName(); // or $order->getBillingAddress()->getName();
foreach ($order->getAllItems() as $itemId => $item)
{
  // display details here
}