Monday, 16 March 2015

Custom Invoice number extension for magento backend

Custom Invoice number extension for magento backend

Folder Structure :-

Local/Wits/Custom/Model/Observer.php

Local/Wits/Custom/etc/config.xml

App/etc/modules/Wits_Custom.xml

1.Create wits_custom.xml file in

app/etc/modules/Wits_Custom.xml

<?xml version="1.0"?>

<config>

<modules>

<Wits_Custom>

<active>true</active>

<codePool>local</codePool>

</Wits_Custom>

</modules>

</config>

2. Create Obserber.php file in

app/code/local/Wits/Custom/Model/Observer.php

<?php



class Wits_Custom_Model_Observer

{

public function saveInvoiceAfter(Varien_Event_Observer $observer) {



$postdata = Mage::app()->getFrontController()->getRequest()->getParams();

//echo "<pre>";print_r($postdata);die;

$orderid = $postdata['order_id'];

$witscustomnumber = $postdata['wits_invoice_number'];

$write = Mage::getSingleton('core/resource')->getConnection('core_write');

$data = array("custom_invoice_number" => $witscustomnumber);

$where = 'order_id = '.$orderid;

$write->update("ex_sales_flat_invoice", $data, $where);



}

}

3. Create config.xml file in

app/code/local/Wits/Custom/etc/config.xml

<?xml version="1.0" ?>

<config>

<modules>

<Wits_Custom>

<version>0.1.0</version>

</Wits_Custom>

</modules>

<adminhtml>

<events>

<sales_order_invoice_save_after>

<observers>

<Wits_Custom_Model_Observer>

<type>singleton</type>

<class>Wits_Custom_Model_Observer</class>

<method>saveInvoiceAfter</method>

</Wits_Custom_Model_Observer>

</observers>

</sales_order_invoice_save_after>

</events>

</adminhtml>

</config>

4. Create text filed input box for input by admin

Path : /public_html/app/design/adminhtml/default/default/template/sales/order/invoice/create/items.phtml

<div class="box-right entry-edit">

<div class="entry-edit-head"><h4><?php echo $this->__('Custom Invoice Number') ?></h4></div>

<fieldset>

<div id="history_form" class="order-history-form">

<span class="field-row">

<label class="normal" for="custom_invoice_number" style="width:200px;"><?php echo Mage::helper('sales')->__('Enter Your Custom Invoice Number') ?></label>

<input id="wits_invoice_number" name="wits_invoice_number" value="" class="input-text" type="text">

</span>

<div class="clear"></div>

</div>

</fieldset>

</div>

5. Create view box for display custom invoice number

Path : /public_html/app/design/adminhtml/default/default/template/sales/order/invoice/view/form.phtml

<div class="box-right entry-edit">

<div class="entry-edit-head"><h4><?php echo $this->__('Custom Invoice Number') ?></h4></div>

<fieldset>

<?php if($_invoice->getCustomInvoiceNumber()): ?>

<label><?php echo Mage::helper('sales')->__('Invoice Number') ?> : </label>

<strong><?php echo $_invoice->getCustomInvoiceNumber() ?></strong>

<?php endif; ?>

</fieldset>

</div>

6. Create custom invoice number filed for listing in invoice listing

Path : /public_html/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php

protected function _prepareColumns()

{

$this->addColumn('custom_invoice_number', array(

'header' => Mage::helper('sales')->__('Custom Invoice Number #'),

'index' => 'custom_invoice_number',

'type' => 'text',


));

No comments:

Post a Comment