Reply to comment

How-To:
Add Invoice Date onto the various invoices in magento.
Based on Magento ver. 1.3.2.4

The only way I found i could add the invoice date onto invoices was to modify the core magento code.
Before you modify any core magento files please make sure you duplicated the core file (including path) from “app\code\core” to “app\code\local”. Otherwise your future upgraded path will be limited.
I found there were 4 different (code paths) that a user could end up with an invoice:

1)New Invoice email
2)Update invoice email
3)User Account – Print Html
4)Pdf – though admin, or an extension that attaches to invoice emails.
_____________________________
1) New Invoice email

---Info: This will make a new variable available to use on the invoice template ("invoiced_date").

---Core File: \app\code\core\Mage\Sales\Model\Order\Invoice.php

---Inside Function: sendEmail($notifyCustomer=true, $comment='')

-- What to do:

Find

foreach ($sendTo as $recipient) {
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId()))
->sendTransactional(
$template,
Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $order->getStoreId()),
$recipient['email'],
$recipient['name'],
array(
'order' => $order,
'invoice' => $this,
'comment' => $comment,
'billing' => $order->getBillingAddress(),
'payment_html'=> $paymentBlock->toHtml()
)
);
}

Replace with

foreach ($sendTo as $recipient) {
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId()))
->sendTransactional(
$template,
Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $order->getStoreId()),
$recipient['email'],
$recipient['name'],
array(
'order' => $order,
'invoice' => $this,
'comment' => $comment,
'billing' => $order->getBillingAddress(),
'payment_html'=> $paymentBlock->toHtml(),
'invoiced_date' => Mage::helper('core')->formatDate($this->getCreatedAt(), 'medium', false)
)
);
}

Add this to your invoice templates

{{var invoiced_date}}
______________________________
2) Update invoice email

Same as New Invoice email, except you do it inside the fucntion sendUpdateEmail, instead of sendEmail
______________________________
4) User Account – Print Html

---Info: This will simply add the invoice date to the html printable invoice from within a web users login.

---File: app\design\frontend\default\default\template\sales\order\print\invoice.phtml (not this is not a core file, but under a template, if this file is not in your active template copy it into it first).

---What to do:

Find
<?php echo $this->__('Invoice #%s', $_invoice->getIncrementId()) ?>

Insert the below somewhere after (you may need add some inline styling to postion how you want it).

<?php echo $this->__('Invoice Date: %s', $this->formatDate($_invoice->getCreatedAt(), 'long')) ?>
______________________________

4) Add Invoice Date to PDF

---Info: This will simply add the invoice date only on the same line as invoice #.

---Core File: \app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php

---Inside Function: getPdf($invoices = array())

-- What to do:

Find on line 68
$page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
Insert this after the line above
$page->drawText(Mage::helper('sales')->__('Invoice Date: ') . Mage::helper('core')->formatDate($invoice->getCreatedAt(), 'medium', false), 285, 780, 'UTF-8');
______________________________

This is only a basic guide and only adds the invoice date. Once I worked out how to do this I also procedeed to add/alter other information, like adding "TAX INVOICE" in large letters to right corners of invoices.

One thing to note about Magento's PDF's, magento first draws the order to the page, then draws the extra invoice information to the page, so if you want to change the postion of something on the order, like the order date position, you can find the code for this: \app\code\core\Mage\Sales\Model\Order\Pdf\Abstract.php, function “insertOrder(&$page, $order, $putOrderId = true)”. So as to only change the invoice and not all orders, I copied this function to the \app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php file and renamed it “insertInvoiceOrder(&$page, $order, $putOrderId = true)”, and from within the function “getPdf($invoices = array())” on \app\code\core\Mage\Sales\Model\Order\Pdf\Invoice.php, change the reference to the new function. You are then free to change what you want without changing how orders will show.

How this helps others..

Cheers,

Sim

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <perl>, <php>, <python>, <ruby>, <xml>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.