<style>
    table.detail-view th {
	width: 215px !important;
    }

</style>
<?php
/* @var $this AssetController */
/* @var $model Asset */

$this->breadcrumbs = array(
    yii::t('default', 'TIDs Management') => array('dashboardLayout/tids'),
    yii::t('default', 'Assets') => array('index'),
    $model->asset_number,
);


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

<?php
    $this->widget('bootstrap.widgets.TbDetailView', array(
	'data' => $model,
	'type' => 'striped',
	'cssFile' => Yii::app()->request->baseUrl . '/css/general/CDetailView/' . Yii::app()->language . '/styles.css',
	'attributes' => array(
	    array(
		'type' => 'raw',
		'name' => 'tid_no',
		'value' => CHtml::link($model->tid_no, array('tid/view', 'id' => $model->tid_id))
	    ),
	    array(
		'type' => 'raw',
		'name' => 'invoice_number',
		'value' => CHtml::link($model->invoice_number, array('invoice/view', 'id' => $model->invoice_id))
	    ),
	    'po_number',
	    array(
		'type' => 'raw',
		'name' => 'segment_name',
		'value' => $model->segment_name
	    ),
	    'serial_number',
	    'asset_number',
	    'part_number',
	    'description',
	    'asset_status',
	    array(
		'type' => 'raw',
		'name' => 'type_of_asset_name',
		'value' => $model->type_of_asset_name
	    ),
	    array(
		'type' => 'raw',
		'name' => 'chassis_number',
		'value' => $model->chassis_number,
		'visible' => $model->type_of_asset_id == Setting::getVehicleTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'plate_number',
		'value' => $model->plate_number,
		'visible' => $model->type_of_asset_id == Setting::getVehicleTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'vehicle_book_expiry_date',
		'value' => $model->vehicle_book_expiry_date,
		'visible' => $model->type_of_asset_id == Setting::getVehicleTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'vehicle_book_status',
		'value' => $model->vehicle_book_status,
		'visible' => $model->type_of_asset_id == Setting::getVehicleTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'radioactive_license_number',
		'value' => $model->radioactive_license_number,
		'visible' => $model->type_of_asset_id == Setting::getRadioActiveTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'radioactive_license_expiry_date',
		'value' => $model->radioactive_license_expiry_date,
		'visible' => $model->type_of_asset_id == Setting::getRadioActiveTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'radioactive_license_status',
		'value' => $model->radioactive_license_status,
		'visible' => $model->type_of_asset_id == Setting::getRadioActiveTypeOfAsset()
	    ),
	    array(
		'type' => 'raw',
		'name' => 'username',
		'value' => ($model->last_edited_date > $model->asset_status_last_edited_date) ? $model->username : (($model->asset_status_last_edited_by == 0) ? "System" :  User::getUsernameById($model->asset_status_last_edited_by)) ,
	    ),
	    
	),
    ));


    Yii::app()->controller->renderPartial('/asset/_modal', array('from_view' => null));
?>

    <br/>

<?php echo CHtml::link(Yii::t('default', 'View TID'), array('/tid/view', 'id' => $model->tid_id), array('class' => 'btn primary')); ?>
    &nbsp;
<?php echo CHtml::link(Yii::t('default', 'View Invoice'), array('/invoice/view', 'id' => $model->invoice_id), array('class' => 'btn primary')); ?>
    &nbsp;
<?php
    if (!Yii::app()->user->isGuest) {
	echo CHtml::link(Yii::t('default', 'Add New Asset'), array('/asset/create'), array('class' => 'btn primary'));
	echo "&nbsp;";
    }
?>

<?php
    if (!Yii::app()->user->isGuest) {
	echo CHtml::link(Yii::t('default', 'Renew'), '#', array('class' => 'btn primary', 'onClick' => 'renew();'));
	echo "&nbsp;";
    }
?>

<?php
    if (!Yii::app()->user->isGuest) {
	echo CHtml::link(Yii::t('default', 'Edit'), array('update', 'id' => $model->id), array('class' => 'btn primary'));
	echo "&nbsp;";
    }
?>

<?php
    if (!Yii::app()->user->isGuest) {
	echo CHtml::link(Yii::t('default', 'Delete'), array('/asset/delete', 'id' => $model->id), array(
	    'class' => 'btn primary', 'id' => 'delete_btn',
	    'onclick' => 'return confirm("' . yii::t("zii", 'Are you sure you want to delete this item?') . '");'));
	echo "&nbsp;";
    }
?>



<?php echo CHtml::link(Yii::t('default', 'Back'), array('index'), array('class' => 'btn primary')); ?>


    <script type="text/javascript">
        var model_id =  '<?php echo $model->id ?>';
        function renew(){

    	var type_of_asset = '<?php echo $model->type_of_asset_id ?>';
    	checkTypeOfAssetModal(type_of_asset);
    	$("#renew-form").addClass("in");
        }

        $('#cancel_button').click(function(){
    	$('#renew-form').removeClass('in');
        });

        function save_changes() {
    	var vehicle_expiry_date = $("#Asset_vehicle_book_expiry_date").val();
    	var radioactive_expiry_date = $("#Asset_radioactive_license_expiry_date").val();
    	$.ajax({
    	    type: "POST",
    	    data: {
    		'model_id': model_id,
    		'vehicle_expiry_date': vehicle_expiry_date,
    		'radioactive_expiry_date': radioactive_expiry_date

    	    },
    	    url: "<?php echo Yii::app()->createAbsoluteUrl("asset/renew"); ?>",
	    success: function(data) {
		if (data.indexOf("error") != -1) {
		    $("#renew-flash-msg").html(data);
		}
		else {
		    $("#flash-msg").html(data);
		    window.location.reload();
		    $("#flash-msg").html(data);
		    $('#renew-form').removeClass('in');
		    $("#Asset_vehicle_book_expiry_date").val("");
		    $("#Asset_radioactive_license_expiry_date").val("");
		}
	    },
	    error: function(data) { // if error occured
		$("#renew-flash-msg").html(data);
	    }
	});
    }


</script>