<?php

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

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

	return false;
});
");


 



?>

<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('prestamo-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-file-pdf fa-lg"></i> EXCEL', 
             Yii::app()->createUrl('prestamo/excelnuevo'), 
             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-info 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('prestamo/nuevo') . '"; ',
                 '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('_search2',array('model'=>$model,)); 
        ?>
        </div>
</div>

<div class='table-responsive'>   
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'prestamo-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(
                 'filter'=> FALSE,
                'header'=> 'Fecha',
                'value'=> 'Utility::fecha($data->fecha_inicio)',
                'type' => 'text',
                'name' => 'fecha_inicio',
                'htmlOptions' => array('class' => 'text-center'),
                ),
            
        
		array('filter'=> FALSE,
                    'name' => 'dni',
                    'value' => '$data->dni',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array('filter'=> FALSE,
                    'name' => 'nombre',
                    'value' => '$data->nombre',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
                    'filter'=> FALSE,
                    'name' => 'apellido',
                    'value' => '$data->apellido',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                
              array(
                    'filter'=> FALSE,
                    'name' => 'gestor',
                    'value' => '$data->gestor',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
            
             
           
            
            
	),
)); ?>
</div> 


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


if(isset($session['prestamo'])){
    $d = $session['prestamo'];
    $num=0;
    
    foreach($d->data as $item)
    {
    $num=$num+1;

    }
?>
    
    <div class="row justify-content-center">
     <fieldset class="col-12 px-3" id="total">
    <legend>RESUMEN GENERAL:</legend>
    
    
    <div class="row">
        
        <div class="col-12 col-sm-12 col-md-3 text-center">
            TIPO
        </div>
        
        <div class="col-12 col-sm-12 col-md-3 text-center">
            CANTIDAD
        </div>

        <div class="col-12 col-sm-12 col-md-3 text-center">
            COMISION
        </div>
        
        
    </div>
    <div class="row">
         <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php echo 'NUEVO'; ?>
        </div>
        
        <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php echo $num; ?>
        </div>
        
        <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php echo Prestamo::NuevoComision($num); ?> 
        </div>
    </div>
    
    
  </fieldset>
       </div>
             
             
 <?php
}
 ?>

