Mossavvir Khan
Mossavvir Khan

Reputation: 21

Get invoice creation date in Invoice PDF

I am using this code to get invoice date of order in PDF, and putting this code in this file "app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php" But it is showing current date instead of invoice creation date.

$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId);
$createdDate = strtotime( $invoice->getCreatedAt() );
$page->drawText(
    Mage::helper('sales')->__('Invoice Creation Date: ') . Mage::helper('core')->formatDate(
        $createdDate, 'medium', false
    ),
    35,
    ($top -= 15),
    'UTF-8'
);

Upvotes: 1

Views: 1272

Answers (2)

Mossavvir Khan
Mossavvir Khan

Reputation: 21

I have solved it with this code.

$order_increment_idd = $order->getRealOrderId();
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$query      = "Select * from `sales_flat_invoice_grid` WHERE `order_increment_id` ='$order_increment_idd' LIMIT 1";
$rows       = $connection->fetchAll($query);

foreach ($rows as $values) {
    $createdDate = $values['created_at'];


    $page->drawText(
        Mage::helper('sales')->__('Date: ') . Mage::helper('core')->formatDate(
            $createdDate, 'medium', false
        ),
        35,
        ($top -= 15),
        'UTF-8'
    );
}

Upvotes: 1

Ranjit Shinde
Ranjit Shinde

Reputation: 1130

don't use strtotime(),magento itself handles it. Try using this

$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId);
$createdDate = $invoice->getCreatedAt();
$page->drawText(
        Mage::helper('sales')->__('Invoice Creation Date: ') . Mage::helper('core')->formatDate(
            $createdDate, 'medium', false
        ),
        35,
        ($top -= 15),
        'UTF-8'
    );

Upvotes: 1

Related Questions