<?php

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

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


Yii::app()->clientScript->registerScript('re-install-date-picker', "
$.datepicker(jQuery.extend());
$.datepicker.setDefaults($.datepicker.regional['es']);

");
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
    $('#desde').datepicker(jQuery.extend({showMonthAfterYear:true},jQuery.datepicker.regional['es']));

}
");

 
    $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('pagos-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-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('pagos/comision') . '"; ',
                 '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('_comision',array('model'=>$model,)); 
        ?>
        </div>
</div>

<div class='table-responsive'>   
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'pagos-grid',
	'dataProvider'=>$model->comision(),
        'pager' => array('cssFile' => Yii::app()->baseUrl.'/public/css/tablas.css'),
	'afterAjaxUpdate' => 'reinstallDatePicker',  
        'filter'=>$model,
	'columns'=>array(
            
            array(   
			'name' => 'fecha_operacion',
                        'value'=>  'Utility::fecha4($data->fecha)',
                        'filter'=>false,
                     'htmlOptions' => array('class' => 'text-center'),
		),

            
                array(
                'header'=>'DIA',
                'filter'=> FALSE,
                'value' => '$data->dia',
                'type' => 'text',
                'name' => 'dia', 
                  'htmlOptions' => array('class' => 'text-center'),
                ),
                
           
         
              array(
                    'filter'=>false,
                    'value' => '$data->cuota',
                    'type' => 'text',
                    'name' => 'cuota',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            
            
            array(
                    'filter'=>false,
                    'header'=>'Porcentaje',
                    'value' => '$data->porcentaje',
                    'type' => 'text',
                    'name' => 'porcentaje',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
             array(
                    'filter'=>false,
                    'value' => 'number_format($data->comision, 2); ',
                    'type' => 'text',
                    'name' => 'comision',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
    
            array(
                    'filter'=>false,
                    'value' => '$data->estatus',
                    'type' => 'text',
                    'name' => 'estatus',
                    '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'),
                ),
            
            

	),
)); ?>
</div> 


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


if(isset($session['pago'])){
    $d = $session['pago'];
    $num=0;
    $cuota=0;
    $mora=0;
    $total=0;
    foreach($d->data as $item)
    {
    $num=$num+1;
    $cuota=$cuota+$item->cuota;
    $mora=$mora+$item->comision;
    $total=$total+$cuota+$mora;
    }
?>
    
    <div class="row justify-content-center">
     <fieldset class="col-12 px-3" id="total">
    <legend>RESUMEN GENERAL:</legend>
    
    
    <div class="row justify-content-center">
        <div class="col-12 col-sm-12 col-md-3 text-center">
            TOTAL REGISTROS
        </div>
        <div class="col-12 col-sm-12 col-md-3 text-center">
            COBRANZA
        </div>
        <div class="col-12 col-sm-12 col-md-3 text-center">
            COMISION
        </div>

    </div>
    <div class="row  justify-content-center ">
        <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  number_format($cuota, 2, ',', '.')  ; ?> 
        </div>
        <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php echo number_format($mora, 2, ',', '.')    ; ?> 
        </div>
 
    </div>
    
    
  </fieldset>
       </div>
             
             
 <?php
}
 ?>
            