<?php

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});

$('.search-form form').submit(function(){
	$('#renovacion-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
        
        $('#total').yiiGridView('update', {
		data: $(this).serialize()
	});

	return false;
});
");


    $v='FALSE';
    if(!empty($_SESSION['id_perfil']) and ($_SESSION['id_perfil']=='1') ){
        $v='TRUE';
    }



?>

<div class="row">
  
    <div class="col-12  col-sm-12 col-md-3"  style="margin-left: 23px;">
        <?php
        $pageSize = Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);
        echo
        'Ver ' .
         CHtml::dropDownList('pageSize', $pageSize, Utility::listaPageSize(), array(
            'class'=>'p-2 border-primary text-primary',
            'onchange' => "$.fn.yiiGridView.update('renovacion-grid',{ data:{pageSize: $(this).val() }})",
        ))
         . ' Registros';
        ?>
    </div> 
    
    
    <div class="col-12  col-sm-12 col-md-8 text-right"  style="margin-right: 25px;" >
         
 <?php echo CHtml::link('<i class="fa fa-plus fa-lg"></i>  AGREGAR', 
             Yii::app()->createUrl('renovacion/create'), 
             array('class'=>'btn btn-primary',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'AGREGAR',
                 )); 
     ?>     

    <?php echo CHtml::link('<i class="fa fa-file-pdf fa-lg"></i> EXCEL', 
             Yii::app()->createUrl('renovacion/excel'), 
             array('class'=>'btn btn-success',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'EXPORTAR A EXCEL',
                 'style'=>'background-color:#066100;'
                 )); 
     ?> 
   <?php echo CHtml::link('<i class="fa fa-search fa-lg"></i> BUSCAR', 
             '#', 
             array('class'=>'btn btn-secondary search-button',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'BUSCAR',
                  'style'=>'background-color:#6F9AF7 ;'
                 )); 
     ?> 
     <?php echo CHtml::link('<i class="fas fa-sync fa-lg"></i>', 
             '#', 
             array('class'=>'btn btn-danger',
                 'onClick' => 'window.location="' . Yii::app()->createUrl('cliente') . '"; ',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'REFRESCAR LISTA'
                 )); 
     ?>   
    </div>
</div>

<div class="col-12 p-4">
        <div class="search-form" style="display:none">
        <?php 
        $this->renderPartial('_search',array('model'=>$model,)); 
        ?>
        </div>
</div>

<div class='table-responsive'>   

<?php if($_SESSION['login'] == "antonio"){ ?>

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'renovacion-grid',
	'dataProvider'=>$model->search(),
        'pager' => array('cssFile' => Yii::app()->baseUrl.'/public/css/tablas.css'),
	'filter'=>$model,
	'columns'=>array(
                array(
                    'filter'=> FALSE,
                    'header'=>'ID',
                    'name' => 'id_prestamo',
                    'value' => '$data->id_prestamo',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
		
            
                   	  array(
                  'header' => '',
                  'class' => 'CButtonColumn',
                  'viewButtonImageUrl' => false,
                  'htmlOptions' => array( 'class' => 'text-center'),
                  'template' => '{view}',
                  'buttons' => array(
                      'view' => array(
                          'label' => ' ',
                          'options' => array(
                              'class' => 'mdi mdi-18px mdi-eye text-primary',
                              'title' => 'VER',
                          ),
                          'visible' =>'true',
                      ),
     
                  )
              ),
            
                      	  array(
                  'header' => '',
                  'class' => 'CButtonColumn',
                  'updateButtonImageUrl' => false,
                  'htmlOptions' => array( 'class' => 'text-center '),
                  'template' => '{update}',
                  'buttons' => array(
                 
                        'update' => array(
                          'label' => ' ',
                          'options' => array(
                              'class' => 'mdi mdi-18px mdi-pencil text-primary',
                              'title' => 'MODIFICAR',
                          ),
                          'visible' =>$v,
                      ),
                   
                  )
              ),
            
             array(
                  'header' => '',
                  'class' => 'CButtonColumn',
                  'deleteButtonImageUrl' => false,
               
                  'htmlOptions' => array( 'class' => 'text-center'),
                  'template' => '{delete}',
                  'buttons' => array(
                  
                        'delete' => array(
                            'label' => ' ',
                            'options' => array(
                                'class' => 'mdi mdi-18px mdi-trash-can-outline text-primary',
                                'title' => 'ELIMINAR',
                          ),
                            'visible' =>$v,
                      ),
                  )
              ),
            
    array(
                    'name' => 'gestor',
                    'value' => '$data->gestor',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
		array(
                    'name' => 'dni',
                    'value' => '$data->dni',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
                    'name' => 'nombre',
                    'value' => '$data->nombre',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
       
                    'name' => 'apellido',
                    'value' => '$data->apellido',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
               array(
                    'filter'=>Zona::lista(),
                    'name' => 'zona',
                    'value' => '$data->zona',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
                array(
                    'name' => 'id_monto',
                    'value' => '$data->id_monto',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
            array(
                'header'=> 'monto cuota',
                'value' => '$data->monto_cuota_renovacion',
                'type' => 'text',
                'name' => 'monto_cuota_renovacion',
                'htmlOptions' => array('class' => 'text-danger text-center',),  
                ),
              array(
                'header'=> 'monto mora',
                'value' => '$data->monto_mora_renovacion',
                'type' => 'text',
                'name' => 'monto_mora_renovacion',
                'htmlOptions' => array('class' => 'text-danger text-center'),  
                ),
            
             array(
                'header'=> 'monto entrega',
                'value' => '$data->monto_entrega',
                'type' => 'text',
                'name' => 'monto_entrega',
                'htmlOptions' => array('class' => 'text-danger text-center'),  
                ),
                 array(
                'filter'=>array(
                            'TRANSFERENCIA'=>'TRANSFERENCIA',
                            'EFECTIVO'=>'EFECTIVO'
                            ),
                'header'=> 'forma entrega',
                'value' => '$data->forma_entrega',
                'type' => 'text',
                'name' => 'forma_entrega',
                'htmlOptions' => array('class' => 'text-danger text-center'),  
                ),
            
            
            array(
                    'filter'=> Prestamo::listaEstatus(),
                    'type' => 'html',
                    'value' => 'Prestamo::estatusClass(Pagos::estatusPrestamo($data->id_prestamo))',
                    'name' => 'estatus',
                    'htmlOptions' => array('class' => 'text-center'),
                    
                ),
            
              array(
                'header'=> 'Num.Renovacion',
                'value' => '$data->num',
                'type' => 'text',
                'name' => 'num',
                'htmlOptions' => array('class' => 'text-center'), 
                ),
              
               array(
                'header'=> 'Fecha/Inicio',
                'value'=> 'Utility::fecha($data->fecha_inicio)',
                'type' => 'text',
                'name' => 'fecha_inicio',
                'htmlOptions' => array('class' => 'text-center'),
                ),
            
            
	
            
            
	),
)); ?>

<?php }else{ ?>

<?php


$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'renovacion-grid',
	'dataProvider'=>$model->search(),
        'pager' => array('cssFile' => Yii::app()->baseUrl.'/public/css/tablas.css'),
	'filter'=>$model,
	'columns'=>array(
                array(
                    'filter'=> FALSE,
                    'header'=>'ID',
                    'name' => 'id_prestamo',
                    'value' => '$data->id_prestamo',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
    array(
                    'name' => 'gestor',
                    'value' => '$data->gestor',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
		array(
                    'name' => 'dni',
                    'value' => '$data->dni',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
                    'name' => 'nombre',
                    'value' => '$data->nombre',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
       
                    'name' => 'apellido',
                    'value' => '$data->apellido',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
               array(
                    'filter'=>Zona::lista(),
                    'name' => 'zona',
                    'value' => '$data->zona',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
                array(
                    'name' => 'id_monto',
                    'value' => '$data->id_monto',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
            array(
                'header'=> 'monto cuota',
                'value' => '$data->monto_cuota_renovacion',
                'type' => 'text',
                'name' => 'monto_cuota_renovacion',
                'htmlOptions' => array('class' => 'text-danger text-center',),  
                ),
              array(
                'header'=> 'monto mora',
                'value' => '$data->monto_mora_renovacion',
                'type' => 'text',
                'name' => 'monto_mora_renovacion',
                'htmlOptions' => array('class' => 'text-danger text-center'),  
                ),
            
             array(
                'header'=> 'monto entrega',
                'value' => '$data->monto_entrega',
                'type' => 'text',
                'name' => 'monto_entrega',
                'htmlOptions' => array('class' => 'text-danger text-center'),  
                ),
                 array(
                'filter'=>array(
                            'TRANSFERENCIA'=>'TRANSFERENCIA',
                            'EFECTIVO'=>'EFECTIVO'
                            ),
                'header'=> 'forma entrega',
                'value' => '$data->forma_entrega',
                'type' => 'text',
                'name' => 'forma_entrega',
                'htmlOptions' => array('class' => 'text-danger text-center'),  
                ),
            
            
            array(
                    'filter'=> Prestamo::listaEstatus(),
                    'type' => 'html',
                    'value' => 'Prestamo::estatusClass(Pagos::estatusPrestamo($data->id_prestamo))',
                    'name' => 'estatus',
                    'htmlOptions' => array('class' => 'text-center'),
                    
                ),
            
              array(
                'header'=> 'Num.Renovacion',
                'value' => '$data->num',
                'type' => 'text',
                'name' => 'num',
                'htmlOptions' => array('class' => 'text-center'), 
                ),
              
               array(
                'header'=> 'Fecha/Inicio',
                'value'=> 'Utility::fecha($data->fecha_inicio)',
                'type' => 'text',
                'name' => 'fecha_inicio',
                'htmlOptions' => array('class' => 'text-center'),
                ),
            
            
	
            
            
	),
));


?>



<?php } ?>


</div> 



<?php
$session=new CHttpSession;
$session->open();

if(isset($session['renovacion'])){
$d = $session['renovacion'];

$id_monto=0;
$monto_cuota_renovacion=0;
$monto_mora_renovacion=0;
$monto_entrega=0;
$total=0;
foreach($d->data as $item)
    {
    

        
    $id_monto=$id_monto+$item->id_monto;
    $monto_cuota_renovacion=$monto_cuota_renovacion+$item->monto_cuota_renovacion;
    $monto_mora_renovacion=$monto_mora_renovacion+$item->monto_mora_renovacion;
    $monto_entrega=$monto_entrega+$item->monto_entrega;
    $total=$total+1;
    }
?>
    
  <div class="row justify-content-center"   >
      <fieldset class="col-12 px-3" id="total">
    <legend>TOTAL:</legend>
    <div class="row">
        <div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3 mt-3">
            CREDITO: <?php echo $id_monto; ?>
        </div>
        <div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3 mt-3">
            CUOTA:  <?php echo $monto_cuota_renovacion; ?> 
        </div>
        <div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3 mt-3 ">
            MORA: <?php echo $monto_mora_renovacion; ?> 
        </div>
        <div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3 mt-3">
            ENTREGO:  <?php echo $monto_entrega; ?> 
        </div>
        
         <div class="col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3 mt-3">
            TOTAL:  <?php echo $total; ?> 
        </div>
        
    </div>
  </fieldset>
       </div>
             
             
 <?php
}
 ?>
       