Showing posts with label Magento 1.9. Show all posts
Showing posts with label Magento 1.9. Show all posts

Tuesday 10 September 2019

How to get null attribute product value in magento 1 addAttributeToFilter Filter Query | Where condition

$collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect(['entity_id'])
        ->addAttributeToFilter(
        array(
            array('attribute'=> 'pricegroup','null' => true),
            array('attribute'=> 'pricegroup','eq' => ''),
            array('attribute'=> 'pricegroup','eq' => 'NO FIELD')
        ),
        '',
        'left')
        ->addAttributeToFilter('status', ['eq' => 1]);
echo $collection->getSelect();
echo '<pre>';print_r($collection->getData());exit;

Saturday 24 November 2018

How to get only one record in Join Query in Magento

$orders->getSelect()->join(["Category" => "catalog_category_product"], "Category.category_id=(
    select category_id from catalog_category_product AS p1 where SFOI.product_id = p1.product_id limit 1
    ) AND SFOI.product_id=Category.product_id", []);

Friday 5 October 2018

How to get list of all categories array tree view in Magento 1

Call Category function

$categories = $this->getTreeCategories(2, false);
print_r($categories);
Get All categories array tree view

function getTreeCategories($parentId, $isChild) {
     
        $allCats = Mage::getModel('catalog/category')->getCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('is_active', '1')
                ->addAttributeToFilter('include_in_menu', '1')
                ->addAttributeToFilter('parent_id', array('eq' => $parentId));
        $subcat = ($isChild) ? "&nbsp;&nbsp;-- " : "";
        foreach ($allCats as $category) {
            $options[] = array(
                'label' => Mage::helper('jaydip_attrfiltercount')->__($subcat.iconv(mb_detect_encoding($category->getName(), mb_detect_order(), true), "UTF-8", $category->getName())),
                'value' => $category->getId()
            );
            $subcats = $category->getChildren();
            if ($subcats != '') {
                $options[] = $this->getTreeCategories($category->getId(), true);
            }
        }
        $optiondata = array();
        foreach ($options as $option):
            if(isset($option[0])){
             
                foreach ($option as $value):
                    $optiondata[] = array(
                        'label' => $value['label'],
                        'value' => $value['value']
                    );
                endforeach;
             
            }else{
                $optiondata[] = array(
                    'label' => $option['label'],
                    'value' => $option['value']
                );
            }
        endforeach;
     
        return $optiondata;
    }

Saturday 22 September 2018

How to Skip | Hide shipping address in checkout Magento 1.9

Step 1 :

Create config.xml file : app/code/local/Jaydip/Kansagra/etc/config.xml

<config>
   <global>
        <blocks>
            <jaydip_kansagra>
                <class>Jaydip_Kansagra_Block</class>
            </jaydip_kansagra>
            <!-- For Hide Shipping address-->
            <checkout>
                <rewrite>
                    <onepage>Jaydip_kansagra_Block_Kansagra_Checkout_Onepage</onepage>
                </rewrite>
            </checkout>
            <!-- For Hide Shipping address-->
       </blocks>
       ...........
       ...........
       ...........
       <!-- For Hide Shipping address-->
        <rewrite>
            <hideshippingadd> <!--This can be any unique id -->
                <from><![CDATA[#^/checkout/onepage/#]]></from>  <!-- the URL which u want to override-->
                <to>/kansagra/onepage/</to>  <!-- destination url -->
            </hideshippingadd>
        </rewrite>
        <!-- For Hide Shipping address-->
       ...........
       ...........
       ...........
   </global>
</config>


Step 2 : 

Create OnepageController.php file : app/code/local/Jaydip/Kansagra/controllers/OnepageController.php

<?php
require_once Mage::getModuleDir('controllers', "Mage_Checkout") . DS . "OnepageController.php";
class Jaydip_Kansagra_OnepageController extends Mage_Checkout_OnepageController {
    public function saveBillingAction() {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('billing', array());
            $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
            if (isset($data['email'])) {
                $data['email'] = trim($data['email']);
            }
            $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
            if (!isset($result['error'])) {
                if ($this->getOnepage()->getQuote()->isVirtual()) {
                    $result['goto_section'] = 'payment';
                    $result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
                    );
                } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                    $result['goto_section'] = 'shipping_method';
                    $result['update_section'] = array(
                        'name' => 'shipping-method',
                        'html' => $this->_getShippingMethodsHtml()
                    );
                 
                } else {
                    $result['goto_section'] = 'shipping';
                }
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }
}

Step 3 :

Create Onepage.php file : app/code/local/Jaydip/Kansagra/Block/Kansagra/Checkout/Onepage.php

<?php
class Jaydip_Kansagra_Block_Kansagra_Checkout_Onepage extends Mage_Checkout_Block_Onepage {
    protected function _getStepCodes() {
        return array('login', 'billing', 'shipping_method', 'payment', 'review');
    }
}

Step 4 : 

And now you need to copy billing.phtml from app/design/frontend/base/default/checkout/onepage

folder into app/design/frontend/rwd/default/template/newgenray/checkout folder.

Find following code

<li class="control">
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"<?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo Mage::helper('core')->quoteEscape($this->__('Ship to this address')) ?>" onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo  $this->__('Ship to this address') ?></label>
</li>
<li class="control">
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0"<?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo Mage::helper('core')->quoteEscape($this->__('Ship to different address')) ?>" onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
</li>

and replace this by

<li class="control">
   <input type="hidden" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"  />
</li>

Friday 3 August 2018

How to add | update Shipping Price on existing order in Magento 1.9

$shippingamount = 10.00;
        try {
            $order = Mage::getModel('sales/order')->load(37881)
                    ->setShippingMethod('cstoreshipping_cstoreshipping')
                    ->setShippingAmount($shippingamount)
                    ->setBaseShippingAmount($shippingamount)
                    ->setShippingDescription('Shipping by third party');
            $order->setGrandTotal($order->getGrandTotal() + $shippingamount);
            $order->setBaseGrandTotal($order->getBaseGrandTotal() + $shippingamount);
            $order->save();
            pre($order->getData());
        } catch (Exception $e) {
            pre($e->getMessage());
        }

Thursday 3 May 2018

How to get the final sql / mysql query from the grid includes filters and pagination in Magento


Open Following file
Open MagentoRoot/lib/Varien/Db/Adapter/Pdo/Mysql.php
Update false to true
protected $_debug = true
protected $_logAllQueries  = true

Thursday 19 April 2018

Calendar.setup Calendar popup not display proper on Magento admin panel


HTML Code

<td class="label"><label for="tran_date">Date</label></td>
<td class="value">
    <input name="deposit[created_at]" id="tran_date" type="text" class="input-text" value="<?php echo Mage::getModel('core/date')->gmtDate('m/d/Y'); ?>"/>
    <img src="<?php echo $this->getSkinUrl('images/grid-cal.gif') ?>" class=""
        id="tran_date_trig"/>
    <div id="calendar--flat"></div>
</td>
</tr>
SCRIPT
 <script type="text/javascript">
// <![CDATA[
Calendar.setup({
flat: 'calendar--flat',
ifFormat: '%m/%e/%Y',
button: 'tran_date_trig',
align: 'Bl',
singleClick: true,
onSelect: function(dateText,selectedDate) {
    jQuery('#tran_date').val(selectedDate);
    jQuery('#calendar--flat').hide();
}
});
// ]]>
</script>

CSS

#calendar--flat {
    position: absolute;


Monday 16 April 2018

Remove / Disable checkbox Checked / unChecked when click on click row in magento 1.9

Need to change code in grid.js (magento\js\mage\adminhtml\grid.js)

Replace code from

rowMouseClick : function(event){
        if(this.rowClickCallback){
            try{
                this.rowClickCallback(this, event);
            }
            catch(e){}
        }
        varienGlobalEvents.fireEvent('gridRowClick', event);
    },
TO

rowMouseClick : function(event){
        var element = Event.findElement(event, 'table');
        if(element.id!='depositGrid_table') {
            if(this.rowClickCallback){
                try{
                    this.rowClickCallback(this, event);
                }
                catch(e){}
            }
        }
        varienGlobalEvents.fireEvent('gridRowClick', event);
    },

Tuesday 27 February 2018

How to create simple and custom order report in magento 1.9


Step 1 : Add Menu on adminhtml.xml file : app/code/local/Jaydip/Kansagra/etc/adminhtml.xml

<config>
    <menu>
        <report>
            <children>
                <jobber translate="title">
                    <title>Jobber</title>
                    <children>
                        <jaydip_kansagra_summary translate="title">
                            <title>Jobber Summary</title>
                            <action>adminhtml/kansagra_reports/summary</action>
                            <sort_order>10</sort_order>
                        </jaydip_kansagra_summary>
                    </children>
                </jobber>
            </children>
        </report>
    </menu>
    <acl>
        ....
        ....
        ....
    </acl>
</config>
Step 2 : Create Report Controller on your model controller file : app/code/local/Jaydip/Kansagra/controllers/Adminhtml/Kansagra/ReportsController.php

<?php
class Jaydip_Kansagra_Adminhtml_Kansagra_ReportsController extends Mage_Adminhtml_Controller_Action {
       
    /**
     * Initialize titles and navigation breadcrumbs
     * @return Jaydip_Reports_Adminhtml_ReportsController
     */
    protected function _initAction() {
        $this->_title($this->__('Reports'))->_title($this->__('Sales'))->_title($this->__('Summary'));
        $this->loadLayout()
                ->_setActiveMenu('report/sales')
                ->_addBreadcrumb(Mage::helper('jaydip_kansagra')->__('Reports'), Mage::helper('jaydip_kansagra')->__('Reports'))
                ->_addBreadcrumb(Mage::helper('jaydip_kansagra')->__('Jobber'), Mage::helper('jaydip_kansagra')->__('Jobber'));
        return $this;
    }
    /**
     * Prepare blocks with request data from our filter form
     * @return Jaydip_Reports_Adminhtml_ReportsController
     */
    protected function _initReportAction($blocks) {
        if (!is_array($blocks)) {
            $blocks = array($blocks);
        }
        $requestData = Mage::helper('adminhtml')->prepareFilterString($this->getRequest()->getParam('filter'));
        $requestData = $this->_filterDates($requestData, array('fromdate', 'todate'));
        $params = $this->_getDefaultFilterData();
        foreach ($requestData as $key => $value) {
            if (!empty($value)) {
                $params->setData($key, $value);
            }
        }
        foreach ($blocks as $block) {
            if ($block) {
                $block->setFilterData($params);
            }
        }
        return $this;
    }
    protected function _getDefaultFilterData() {
        return new Varien_Object(array(
            'fromdate' => '',
            'todate' => '',
            'salesperson' => 0,
        ));
    } 
   
    public function summaryAction() {
        $this->_initAction();
        $this->_title($this->__('Summary'));
        $gridBlock = $this->getLayout()->getBlock('adminhtml_reports_summary.grid');
        $filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
        $this->_initReportAction(array(
            $gridBlock,
            $filterFormBlock
        ));
        $this->renderLayout();
    }
   
    public function detailAction() {
        $this->_initAction();
        $this->_title($this->__('Detail'));
        $gridBlock = $this->getLayout()->getBlock('adminhtml_detail.grid');
        $filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
        $this->_initReportAction(array(
            $gridBlock,
            $filterFormBlock
        ));
        $this->renderLayout();
    }
}
Step 3 : Create admin layout xml file : app/design/adminhtml/default/default/layout/jaydip_kansagra.xml

<layout>
.....
.....
.....
<adminhtml_kansagra_reports_summary>
        <reference name="content">
            <block type="jaydip_kansagra/adminhtml_reports_summary" template="report/grid/container.phtml" name="jaydip_kansagra_reports_summary_grid_container">
                <block type="jaydip_kansagra/adminhtml_reports_filter_formsummary" name="grid.filter.form" />
            </block>
        </reference>
    </adminhtml_kansagra_reports_summary>
</layout> 
Step 4 : Create block file : app/code/local/Jaydip/Kansagra/Block/Adminhtml/Reports/Summary.php

class Jaydip_Kansagra_Block_Adminhtml_Reports_Summary extends Mage_Adminhtml_Block_Widget_Grid_Container {
    /**
     * This is your module alias
     */
    protected $_blockGroup = 'jaydip_kansagra';
    /**
     * This is the controller's name (this block)
     */
    protected $_controller = 'adminhtml_reports_summary';
    /*
      Note: the grid block's name would prepare from $_blockGroup and $_controller with the suffix '_grid'.
      So the complete block would called jaydip_kansagra/adminhtml_report_grid . As you already guessed it,
      this will resolve to the class Jaydip_Reports_Adminhtml_Report_Grid .
     */
    /**
     * Prepare grid container, add and remove additional buttons
     */
    public function __construct() {
        // The head title of the grid
        $this->_headerText = Mage::helper('jaydip_kansagra')->__('Summary');
        $this->setTemplate('report/grid/container.phtml');
        parent::__construct();
        $this->_removeButton('add');
        $this->addButton('filter_form_submit', array(
            'label' => Mage::helper('jaydip_kansagra')->__('Show Report'),
            'onclick' => 'filterFormSubmit()'
        ));
    }
    /**
     * This function will prepare our filter URL
     * @return string
     */
    public function getFilterUrl() {
        $this->getRequest()->setParam('filter', null);
        return $this->getUrl('*/*/summary', array('_current' => true));
    }
}
Step 5 : Create Grid file : app/code/local/Jaydip/Kansagra/Block/Adminhtml/Reports/Summary/Grid.php

<?php
class Jaydip_Kansagra_Block_Adminhtml_Reports_Summary_Grid extends Mage_Adminhtml_Block_Widget_Grid {
    /**
     * Basic setup of our grid
     */
    public function __construct() {
        parent::__construct();
        $this->setPagerVisibility(false);
        $this->setUseAjax(false);
        $this->setFilterVisibility(false);
        $this->setDefaultLimit(50);
        $this->setEmptyCellLabel(Mage::helper('jaydip_kansagra')->__('No records found.'));
        $this->setId('mxReportsGrid');
        // set our grid to obtain totals
        $this->setCountTotals(true);
    }
    /**
     * Return totals data
     * Count totals if it's not previously counted and set to retrieve
     * @return Varien_Object
     */
    public function getTotals() {
        $totals = new Varien_Object();
        $fields = array(
            'jobberprofit' => '',
            'jobberamount' => '',
            'invoiceamount' => '',
        );
        foreach ($this->getCollection() as $item) {
            foreach ($fields as $field => $value) {
                $fields[$field] += $item->getData($field);
            }
        }
        //First column in the grid
        $fields['sortorder'] = 'Totals';
        $totals->setData($fields);
        return $totals;
    }
    // prepare columns and collection   
    /**
     * Prepare our grid's columns to display
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Summary_Grid
     */
    protected function _prepareColumns() {
       
        $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
       
        $this->addColumn('created_at', array(
            'header' => Mage::helper('sales')->__('Date'),
            'index' => 'created_at',
            'type' => 'datetime',
            'width' => '120'
        ));
       
        $this->addColumn('company', array(
            'header' => Mage::helper('sales')->__('Company name'),
            'index' => 'company',
            'align' => 'right',
            'width' => '50'
        ));
        $this->addColumn('address', array(
            'header' => Mage::helper('sales')->__("Full Address"),
            'index' => 'street',
            'width' => '210'
        ));
        // add export types
        //$this->addExportType('*/*/exportCSV', Mage::helper('jaydip_kansagra')->__('CSV'));
        return parent::_prepareColumns();
    }
    /**
     * Prepare our collection which we'll display in the grid
     * First, get the resource collection we're dealing with, with our custom filters applied.
     * In case of an export, we're done, otherwise calculate the totals
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Summary_Grid
     */
    protected function _prepareCollection() {
       
        $data = $this->getFilterData();
       
        $datefrom = Mage::getModel('core/date')->gmtDate('Y-m-d',strtotime($data->fromdate));
        $dateto = Mage::getModel('core/date')->gmtDate('Y-m-d',strtotime($data->todate));
        $salesperson = $data->salesperson;
        $orders = Mage::getModel('sales/order')->getCollection()
                    ->addFieldToFilter('entity_id', array('eq' => 0));
        $this->setCollection($orders);
        //echo $this->showExtraCounts($collection);
        return parent::_prepareCollection();
    }
}
Step 6 : Create Filter Form file : app/code/local/Jaydip/Kansagra/Block/Adminhtml/Reports/Filter/Formsummary.php

<?php
class Jaydip_Kansagra_Block_Adminhtml_Reports_Filter_Formsummary extends Mage_Adminhtml_Block_Widget_Form {
    /**
     * This will contain our form element's visibility
     * @var array
     */
    protected $_fieldVisibility = array();
    /**
     * Field options
     * @var array
     */
    protected $_fieldOptions = array();
    /**
     * Sets a form element to be visible or not
     * @param string $fieldId
     * @param bool $visibility
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Filter_Form
     */
    public function setFieldVisibility($fieldId, $visibility) {
        $this->_fieldVisibility[$fieldId] = $visibility ? true : false;
        return $this;
    }
    /**
     * Returns the field is visible or not. If we hadn't set a value
     * for the field previously, it will return the value defined in the
     * defaultVisibility parameter (it's true by default)
     * @param string $fieldId
     * @param bool $defaultVisibility
     * @return bool
     */
    public function getFieldVisibility($fieldId, $defaultVisibility = true) {
        if (isset($this->_fieldVisibility[$fieldId])) {
            return $this->_fieldVisibility[$fieldId];
        }
        return $defaultVisibility;
    }
    /**
     * Set field option(s)
     * @param string $fieldId
     * @param string|array $option if option is an array, loop through it's keys and values
     * @param mixed $value if option is an array this option is meaningless
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Filter_Form
     */
    public function setFieldOption($fieldId, $option, $value = null) {
        if (is_array($option)) {
            $options = $option;
        } else {
            $options = array($option => $value);
        }
        if (!isset($this->_fieldOptions[$fieldId])) {
            $this->_fieldOptions[$fieldId] = array();
        }
        foreach ($options as $key => $value) {
            $this->_fieldOptions[$fieldId][$key] = $value;
        }
        return $this;
    }
    /**
     * Prepare our form elements
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Filter_Form
     */
    protected function _prepareForm() {
        // inicialise our form
        $actionUrl = $this->getCurrentUrl();
        $form = new Varien_Data_Form(array(
            'id' => 'filter_form',
            'action' => $actionUrl,
            'method' => 'get'
        ));
        // set ID prefix for all elements in our form
        $htmlIdPrefix = 'jaydip_kansagra_jobber_';
        $form->setHtmlIdPrefix($htmlIdPrefix);
        // create a fieldset to add elements to
        $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('jaydip_kansagra')->__('Filter')));
        // prepare our filter fields and add each to the fieldset
        // date filter
        $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
       
        $fieldset->addField('fromdate', 'date', array(
            'name' => 'fromdate',
            'format' => $dateFormatIso,
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'label' => Mage::helper('jaydip_kansagra')->__('From Date'),
            'title' => Mage::helper('jaydip_kansagra')->__('From Date'),
            'required' => true
        ));
       
        $fieldset->addField('todate', 'date', array(
            'name' => 'todate',
            'format' => $dateFormatIso,
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'label' => Mage::helper('jaydip_kansagra')->__('To Date'),
            'title' => Mage::helper('jaydip_kansagra')->__('To Date'),
            'required' => true
        ));
       
        $fieldset->addField('salesperson', 'select', array(
            'name' => 'salesperson',
            'values' => Mage::getModel('admin/user')->getAdminUsersArrByRole('Sales Person'),
            'label' => Mage::helper('jaydip_kansagra')->__('Jobbers'),
            'required' => true,
        ));
        $form->setUseContainer(true);
        $this->setForm($form);
        return $this;
    }
    /**
     * Inicialise form values
     * Called after prepareForm, we apply the previously set values from filter on the form
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Filter_Form
     */
    protected function _initFormValues() {
        $filterData = $this->getFilterData();
        $this->getForm()->addValues($filterData->getData());
        return parent::_initFormValues();
    }
    /**
     * Apply field visibility and field options on our form fields before rendering
     * @return Jaydip_Kansagra_Block_Adminhtml_Report_Filter_Form
     */
    protected function _beforeHtml() {
        $result = parent::_beforeHtml();
        $elements = $this->getForm()->getElements();
        // iterate on our elements and select fieldsets
        foreach ($elements as $element) {
            $this->_applyFieldVisibiltyAndOptions($element);
        }
        return $result;
    }
    /**
     * Apply field visibility and options on fieldset element
     * Recursive
     * @param Varien_Data_Form_Element_Fieldset $element
     * @return Varien_Data_Form_Element_Fieldset
     */
    protected function _applyFieldVisibiltyAndOptions($element) {
        if ($element instanceof Varien_Data_Form_Element_Fieldset) {
            foreach ($element->getElements() as $fieldElement) {
                // apply recursively
                if ($fieldElement instanceof Varien_Data_Form_Element_Fieldset) {
                    $this->_applyFieldVisibiltyAndOptions($fieldElement);
                    continue;
                }
                $fieldId = $fieldElement->getId();
                // apply field visibility
                if (!$this->getFieldVisibility($fieldId)) {
                    $element->removeField($fieldId);
                    continue;
                }
                // apply field options
                if (isset($this->_fieldOptions[$fieldId])) {
                    $fieldOptions = $this->_fieldOptions[$fieldId];
                    foreach ($fieldOptions as $k => $v) {
                        $fieldElement->setDataUsingMethod($k, $v);
                    }
                }
            }
        }
        return $element;
    }
}

Friday 9 February 2018

How to add / create grid Tab in custom module in magento admin panel

Step1 :
open : /app/code/local/Namespace/Modulename/Block/Adminhtml/Employee/Edit/Tabs.php
Add following lines

protected function _beforeToHtml()
{
.........
.........
.........
$this->addTab(
    'form_advancepayment',
    array(
'label'   => Mage::helper('namespace_modulename')->__('Advance Payment'),
'title'   => Mage::helper('namespace_modulename')->__('Advance Payment'),
'content' => $this->getLayout()->createBlock(
    'namespace_modulename/adminhtml_employee_edit_tab_advancepayment'
)
->toHtml(),
    )
);
return parent::_beforeToHtml();
}
Step2 :
Create new file (Advancepayment.php) : /app/code/local/Namespace/Modulename/Block/Adminhtml/Employee/Edit/Tab/Advancepayment.php
<?php
class Namespace_Modulename_Block_Adminhtml_Employee_Edit_Tab_Advancepayment extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('advancepymt_grid');
        $this->setDefaultSort('entity_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
        //$this->setFilterVisibility(false);
    }
   
    protected function _prepareCollection()
    {
        $id = $this->getRequest()->getParam('id');
        $collection = Mage::getModel('namespace_modulename/advancepymt')
            ->getCollection()
            ->addFieldToFilter('employee_id', $id);
       
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
   
    protected function _prepareColumns()
    {
        $this->addColumn(
            'entity_id',
            array(
                'header' => Mage::helper('namespace_modulename')->__('Id'),
                'index'  => 'entity_id',
                'filter' => false,
                'type'   => 'number'
            )
        );
        $this->addColumn(
            'payment',
            array(
                'header'    => Mage::helper('namespace_modulename')->__('Payment'),
                'align'     => 'left',
                'type'   => 'number',
                'index'     => 'payment',
            )
        );
       
        $this->addColumn(
            'created_at',
            array(
                'header' => Mage::helper('namespace_modulename')->__('Created at'),
                'index'  => 'created_at',
                'width'  => '120px',
                'type'   => 'datetime',
            )
        );
        return parent::_prepareColumns();
    }
   
    public function getGridUrl()
    {
        return $this->getUrl('*/*/advancepymt', array('_current'=>true));
    }
   
    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }
Step3 :
Create function in current controller : /app/code/local/Namespace/Modulename/controllers/Adminhtml/Payroll/EmployeeController.php
class Namespace_Modulename_Adminhtml_Payroll_EmployeeController extends Namespace_Modulename_Controller_Adminhtml_Payroll
{
.............
.............
.............
public function advancepymtAction() {
        $this->loadLayout();
        $this->getLayout()->getBlock('edit.tab.advancepayment');
        $this->renderLayout(); 
    }
Step4 :
Add view in admin layout xml file : /app/design/adminhtml/default/default/layout/namespace_modulename.xml
Add following code into file

...........
...........
<adminhtml_modulename_employee_advancepymt>
<block type="core/text_list" name="root" output="toHtml">
    <block type="namespace_modulename/adminhtml_employee_edit_tab_advancepayment" name="edit.tab.advancepayment"/>
</block>
</adminhtml_modulename_employee_advancepymt>
...........
...........