
<script type="text/javascript">
    var invoice_id = '<?php echo $invoice_id; ?>';
   

    function hideViewColumn(){
	var page_name = '<?php echo $page_name; ?>';
	grid = $('#asset-grid');
	if(page_name == 'saveAndAdd'){
	    $('tr', grid).each(function() {
		$('td:eq(10), th:eq(10)', this).hide();
	    });
	}
    }
    $(document).ready(function(){
	hideViewColumn();
    });
    
</script>
<?php if ($page_name == 'view_invoice') {
?>
    <div id="asset-flash-msg">
        <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>
<?php } ?>
<div id="content-innner"></div>
<?php
$this->widget('yiiwheels.widgets.grid.WhGridView', array(
    'id' => 'asset-grid',
    'ajaxUrl' => Yii::app()->createUrl('asset/index', array('from' => 'invoice_view', 'rendered_from' => $page_name)),
    'beforeAjaxUpdate' => 'function(id,options) {
                var url=options.url;
		options.url = options.url+ "&VAsset%5Binvoice_id%5D="+invoice_id;
	    }',
    'afterAjaxUpdate' => 'function(id,options) {
                hide_column();
		hideViewColumn();
		$("td.empty").show();
	    }',
    'dataProvider' => $model->search($invoice_id),
    'template' => ($page_name == 'view_invoice') ? '{summary}{items}{pager}' : "{items}{pager}",
    'filter' => $model,
    'columns' => array(
	'type_of_asset_id',
	'po_number',
	array(
	    'name' => 'segment_name',
	    'value' => '$data->segment_name',
	    'filter' => Segment::getNamesForView()
	),
	'serial_number',
	array(
	    'type' => 'html',
	    'name' => 'asset_number',
	    'value' => 'CHtml::link($data->asset_number, array("/asset/view", "id" => $data->id))',
	),
	'part_number',
	array(
	    'name' => 'type_of_asset_name',
	    'value' => '$data->type_of_asset_name',
	    'filter' => TypeOfAsset::getNamesForView()
	),
	array(
	    'name' => 'asset_status',
	    'value' => '$data->asset_status',
	    'filter' => Asset::getAssetStatusOptions()
	),
//	    'chassis_number',
//	    'plate_number',
//	    'radioactive_license_number',
	array(
	    'name' => 'status',
	    'value' => '$data->status',
	    'filter' => Asset::getStatusOptions()
	),
	array(
	    'name' => 'expiry_date',
	    'value' => '$data->expiry_date',
	),
	array(
	    'class' => 'CButtonColumn',
	    'htmlOptions' => array('width' => '60'),
	    'template' => ($page_name != 'view_invoice') ? '' : '{update} {delete} {renew}',
	    'afterDelete' => 'function(link,success,data){ if(success) $("#asset-flash-msg").html(data); }',
	    'buttons' => array(
		'delete' => array
		    (
		    'url' => 'Yii::app()->createAbsoluteUrl("asset/delete", array("id" => $data->id))',
		    'visible' => 'Yii::app()->user->checkAccess(User::SYSTEM_ADMIN_ROLE)',
		),
		'update' => array
		    (
		    'url' => 'Yii::app()->createAbsoluteUrl("asset/update", array("id" => $data->id))',
		    'visible' => '!Yii::app()->user->isGuest'
		),
		'renew' => array
		    (
		    'label' => Yii::t('default', 'Renew'),
		    'url' => '"#"',
		    'click' => 'function(){
                             var rowIndex = $(this).closest("tr").index();
                             var rowId = $("#"+$(this).closest("div.grid-view").attr("id")+" > div.keys > span:eq("+rowIndex+")").text();
                              model_id = rowId;
			     var type_of_asset = $(this).parent().parent().children(":nth-child(1)").text();			     
			     checkTypeOfAssetModal(type_of_asset);
			     $("#renew-form").addClass("in");   
                             return false;}',
		    'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/renew.png',
		    'visible' => '!Yii::app()->user->isGuest && ($data->type_of_asset_id == Setting::getRadioActiveTypeOfAsset() || $data->type_of_asset_id == Setting::getVehicleTypeOfAsset())',
		),
	    ),
	),
    ),
));
if (($page_name == 'view_invoice'))
    Yii::app()->controller->renderPartial('/asset/_modal', array('from_view' => null));
?>

<script type="text/javascript">
    var model_id =  '';
    var expiry_date =  '';
    
    $('#cancel_button').click(function(){
	$('#renew-form').removeClass('in');
    });

    function hide_column() {
        grid = $('#asset-grid');
        $('tr', grid).each(function() {
            $('td:eq(0), th:eq(0)', this).hide();
        });
    }
    hide_column() ;
    
</script>
