<style>
    span.required {
	color: #eee!important;
    }

    .red-star {
	color: #eee!important;
	display: none;
    }
</style>
<?php
/* @var $this TidController */
/* @var $model Tid */
$this->breadcrumbs = array(
    yii::t('default', 'TIDs Management') => array('dashboardLayout/tids'),
    yii::t('default', 'TIDs') => array('index'),
);


Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#tid-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php
if (!Yii::app()->user->isGuest)
    echo CHtml::link(Yii::t('default', 'Add'), array('create'), array('class' => 'btn btn-primary', 'data-dismiss' => 'modal')); ?>
&nbsp;
<?php
echo TbHtml::buttonDropdown('Export', array(
    array('label' => 'TIDs Summary', 'url' => array('summaryExportToExcel')),
    array('label' => 'TIDs Detailed', 'url' => array('detailExportToExcel')),
    array('label' => 'TI Statuses', 'url' => array('/tid/ExportToExcelStatusInfo')),
    array('label' => 'Assets', 'url' => array('/asset/exportToExcel')),
	), array('class' => 'btn btn-success')
);
?>
&nbsp;
<?php echo CHtml::link('Advanced Search', '#', array('class' => 'search-button btn')); ?>
<div class="search-form" style="display:none">
    <?php
    $this->renderPartial('_search', array(
	'model' => $model,
    ));
    ?>
</div><!-- search-form -->


<div id="flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>


<?php
    $this->widget('yiiwheels.widgets.grid.WhGridView', array(
	'id' => 'tid-grid',
	'dataProvider' => $model->search(),
	'filter' => $model,
	'columns' => array(
	    'number',
	    array(
		'name' => 'tid_no',
		'type' => 'html',
		'value' => 'CHtml::link($data->tid_no, array("/tid/view", "id" => $data->id))',
	    ),
//	    'value',
//	    'customs_letter_no',
//	    'customs_letter_date',
	    'shipment_ref',
	    'segment_name',
	    array(
		'name' => 'point_of_entry_id',
		'value' => '$data->point_of_entry_name',
		'filter' => PointOfEntry::getNamesForView(),
		'htmlOptions' => array('width' => '100'),
	    ),
	    array(
		'name' => 'last_status_ti_status',
		'value' => '$data->last_status_ti_status',
		'filter' => TidStatus::getStatusOptions()
	    ),
	    array(
		'name' => 'last_status_ti_type_id',
		'value' => '$data->ti_type_name',
		'filter' => TiType::getNamesForView()
	    ),
	    array(
		'name' => 'last_status_ti_expiry_date',
		'value' => '($data->last_status_ti_expiry_date != "0000-00-00") ?$data->last_status_ti_expiry_date: ""',
	    ),
	    array(
		'name' => 'last_status_contract_id',
		'value' => '$data->contract_reference',
		'filter' => Contract::getNamesForView()
	    ),
	    array(
		'name' => 'last_status_under_processing',
		'value' => '($data->last_status_under_processing == null) ? "" : $data->last_status_under_processing',
		'filter' => array('Yes' => Yii::t('default', 'Yes'), 'No' => Yii::t('default', 'No'))
	    ),
	    array(
		'name' => 'last_status_renewal_stage_id',
		'value' => '($data->last_status_renewal_stage_id != null) ? $data->renewal_stage_name : ""',
		'filter' => RenewalStage::getNamesForView()
	    ),
	    array(
		'class' => 'CButtonColumn',
		'htmlOptions' => array('width' => '120'),
		'template' => '{update} {delete} {renew} {add_invoice} {add_asset}',
		'afterDelete' => 'function(link,success,data){ if(success) $("#flash-msg").html(data); }',
		'buttons' => array(
		    'delete' => array
			(
			'visible' => 'Yii::app()->user->checkAccess(User::SYSTEM_ADMIN_ROLE)',
		    ),
		    'update' => array
			(
			'visible' => '!Yii::app()->user->isGuest'
		    ),
		    'renew' => array
			(
			'label' => Yii::t('default', 'Renew'),
			'url' => 'array("tid/renew","id"=>$data->id)',
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/renew.png',
			'visible' => '!Yii::app()->user->isGuest && (($data->getLastStatus() != null) ? ($data->getLastStatus()->tiType->validity_mode == "Permanent" ?  false : true) : true)',
		    ),
		    'add_invoice' => array(
			'label' => Yii::t('default', 'Add New Invoice'),
			'url' => 'array("invoice/create","tid_id"=>$data->id)',
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/add_invoice.png',
			'visible' => '!Yii::app()->user->isGuest'
		    ),
		    'add_asset' => array(
			'label' => Yii::t('default', 'Add New Asset'),
			'url' => 'array("asset/create","tid_id"=>$data->id)',
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/add_asset.png',
			'visible' => '!Yii::app()->user->isGuest'
		    ),
		),
	    ),
	),
    ));
?>
