<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'monte-pio-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="help-block">Campos con<span class="required">*</span> son obligatorios.</p>

	<?php echo $form->errorSummary($model); ?>

	<?php 
        if($model->isNewRecord==false){
            $id=$model->idtrabajador;            
        }else{        
            $id_a= Asociado::model()->findAll('"cedula"=:cedula  ', array(':cedula'=>$cedula));
		if($id_a != null){  
		$id= $id_a[0]['idasociado'];
		$model->idtrabajador=$id;
                }
                $user=Yii::app()->user->id;
        	$sql = "select * from cruge_user where iduser= $user and state= 1";
		$resp = Yii::app()->db->createCommand($sql)->queryAll();
        	$cedula= $resp[0]['cedula'];
        	
		$id_a= Asociado::model()->findAll('"cedula"=:cedula  ', array(':cedula'=>$cedula));
		if($id_a != null){  
		$id= $id_a[0]['idasociado'];
		$model->idtrabajador=$id;                
                }
        }
        echo $form->hiddenField($model,'idtrabajador',array('class'=>'span5'));
        
	   $dataProvider=new CActiveDataProvider('Asociado', array(
            'criteria'=>array(
                'condition'=>'"idasociado"='.$id.'' ,
    ),       
    'pagination'=>array(
        'pageSize'=>10,
    ),
));	
	$this->widget('bootstrap.widgets.TbGridView',array(
	'type'=>'bordered',
	'id'=>'asociado-grid',
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		'nombre',
		'apellidos',
		'cedula',

	),
));?>
	<?php echo $form->textFieldRow($model,'cedula',array('class'=>'span2')); ?>

	<?php echo $form->textFieldRow($model,'nombre',array('class'=>'span4','maxlength'=>100)); ?>

	<?php echo $form->textFieldRow($model,'apellido',array('class'=>'span4','maxlength'=>100)); ?>
       <?php echo $form->labelEx($model,'parentesco'); ?>
       <?php echo $form->dropDownList($model,'parentesco', CHtml::listData(Parentesco::model()->findAll(), 'idparentesco', 'descripcion')); ?>
       <?php echo $form->error($model,'parentesco'); ?>
        <?php echo $form->textFieldRow($model,'lugar',array('class'=>'span4','maxlength'=>100)); ?>

      <?php echo $form->labelEx($model,'fecha_siniestro'); ?>
     
      <?php
      if ($model->fecha_siniestro!='') {       
      $model->fecha_siniestro=date('d-m-Y',strtotime($model->fecha_siniestro));
      }
      $fecha=date('Y-m-d');
      $this->widget('zii.widgets.jui.CJuiDatePicker', array(
              'model'=>$model,
              'attribute'=>'fecha_siniestro',
              'value'=>$model->fecha_siniestro,
      'language' => 'es',
      'htmlOptions' => array('readonly'=>"readonly"),
                //additional javascript options for the date picker plugin
              'options'=>array(
                      'autoSize'=>true,
                      'defaultDate'=>$model->fecha_siniestro,
          //'dateFormat'=>'yy-m-d',
          'dateFormat'=>'dd-mm-yy',
          'buttonImage'=>Yii::app()->baseUrl.'/images/calendar.png',
                      'buttonImageOnly'=>true,
                      'buttonText'=>'Fecha',
                      'selectOtherMonths'=>true,
                      'showAnim'=>'slide',
                      'showButtonPanel'=>true,
                      'showOn'=>'button',
                      'showOtherMonths'=>true,
               'changeMonth' => 'true',
                  'changeYear' => 'true',
                  'maxDate' => $fecha,
                  ),
          
          
          
      )); ?>
      <?php echo $form->error($model,'fecha_siniestro'); ?>
	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'submit',
			'type'=>'primary',
			'label'=>$model->isNewRecord ? 'Aceptar' : 'Aceptar',
		)); ?>
	</div>

<?php $this->endWidget(); ?>
