<?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';
    }




?>


<script>
    
    function app(elem){
        
        var url = $(elem).attr("href");
        var div = url.split("/");
        url = url + '?apk=' + div[3];
        $(elem).attr("href",url);
        return false;
    }
    
</script>

<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
    
    if(Yii::app()->user->name!='jacky' ){
    
    
    echo CHtml::link('<i class="fa fa-plus fa-lg"></i>  AGREGAR PAGO', 
             Yii::app()->createUrl('pagos/create'), 
             array('class'=>'btn btn-primary',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'AGREGAR PAGO',
                 )); 
     ?> 
  
         <?php echo CHtml::link('<i class="fa fa-file-pdf fa-lg"></i>  COBRANZA', 
             Yii::app()->createUrl('pagos/reporte'), 
             array('class'=>'btn btn-danger',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'COBRANZA',
                 )); 
    }
     ?> 
        
        
        

        
       
        
             <?php echo CHtml::link('<i class="fa fa-eye fa-lg"></i>  COBRANZA', 
             Yii::app()->createUrl('pagos/reportever'), 
             array('class'=>'btn btn-primary',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'COBRANZA',
                 )); 
     ?> 
        
   
        
        
        
 <?php
 if(empty($_SESSION['perfil']) and empty($_SESSION['gestor'])  and ($_SESSION['id_perfil']!=3) and (Yii::app()->user->name!='jacky' ) ){
?> 
        
         <?php echo CHtml::link('<i class="fa fa-plus fa-lg"></i>  MORA', 
             Yii::app()->createUrl('pagos/cancelarmora'), 
             array('class'=>'btn btn-info',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'CANCELAR MORA',
                 'style'=>'background-color:#D26FF7;'
                 )); 
     ?>    
    <?php echo CHtml::link('<i class="fa fa-plus fa-lg"></i>  CANCELAR CUOTA', 
             Yii::app()->createUrl('pagos/cancelarp'), 
             array('class'=>'btn btn-danger',
                 'data-toggle' => "tooltip",
                 'data-original-title' => 'CANCELAR CUOTA',
                 
                 )); 
     ?>     
   <?php
 }
   
   ?>
      
        
        
        
    <?php 
    if(Yii::app()->user->name!='jacky' ){
    
    
    echo CHtml::link('<i class="fa fa-file-pdf fa-lg"></i> EXCEL', 
             Yii::app()->createUrl('pagos/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-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('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>



<?php
if(!empty($_SESSION['id_perfil']) and ($_SESSION['id_perfil']=='1') ){

?>


<div class='table-responsive'>   
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'pagos-grid',
	'dataProvider'=>$model->search(),
        'pager' => array('cssFile' => Yii::app()->baseUrl.'/public/css/tablas.css'),
	'afterAjaxUpdate' => 'reinstallDatePicker',  
        'filter'=>$model,
	'columns'=>array(
               array(
                    'header'=>'ID',
                    'name' => 'id_pago',
                    'value' => '$data->id_pago',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
             array(
                    'header'=>'NUM.OPE',
                    'name' => 'num_operacion',
                    'value' => '$data->num_operacion',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
           
                'filter'=> ModalidadPago::lista(),
                'value' => 'ModalidadPago::Descripcion($data->id_modalidad_pago)',
                'type' => 'text',
                'name' => 'id_modalidad_pago',
                '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(
                   'header' =>'FOTO',
                    'filter' =>false,
                    'value' => 'CHtml::link(CHtml::image(Yii::app()->request->baseUrl."/upload/".$data->imagen,"", array("width" =>"25")),Yii::app()->request->baseUrl."/upload/".$data->imagen, array("target"=>"_blank"))  ',
                    'type' => 'raw',
                    'name' => 'imagen',
                    'htmlOptions' => array( 'class' => 'text-center'),
                ),
               array(
                'header' => 'IMPRIMIR',
                'class' => 'CButtonColumn',
                'htmlOptions' => array('width' => '100', 'class' => 'text-center'),
                    'template' => '{pdf}',
                    'buttons' => array(
                       'pdf' => array(
                            'label' => '',
                            'url' => 'Yii::app()->controller->createUrl("Recibo",array("id"=>$data->id_pago))',
                            'options' => array(
                                'data-toggle' => 'tooltip',
                                'class' => ' fa fa-file-pdf fa-lg mr-3 text-danger',
                                'data-original-title' => 'IMPRIMIR RECIBO',
                                'target'=>'_black',
                            ),
                            'visible' => 'true',
                        ),
                    ),
                ),
            
            array( 
            'header' => 'IMPRIMIR POR ANDROID',
            'class' => 'CButtonColumn',
            'htmlOptions' => array('width' => '100', 'class' => 'text-center'),
            'template' => '{pdf}',
            'buttons' => array(
               'pdf' => array(
                    'label' => '',
                    'url' => 'Yii::app()->controller->createUrl("Recibo",array("id"=>$data->id_pago))',
                    'options' => array(
                        'data-toggle' => 'tooltip',
                        'class' => ' fa fa-file-pdf fa-lg mr-3',
                        'data-original-title' => 'IMPRIMIR PDF ANDROID',
                        'onclick' => 'app(this)',
                    ),
                    'visible' => 'true',
                    ),
                    ),
                ),
            
                                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(
                    'value' => '$data->capital',
                    'type' => 'text',
                    'name' => 'capital',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            
                array(
                    'value' => '$data->interes',
                    'type' => 'text',
                    'name' => 'interes',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            
            
               array(
                    'value' => '$data->cuota',
                    'type' => 'text',
                    'name' => 'cuota',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            
          
                 array(
			'name' => 'fecha',
                        'value'=>  'Utility::fecha($data->fecha)',
			'filter' => $this->widget(
                                'zii.widgets.jui.CJuiDatePicker', array(
				'model'=>$model, 
				'attribute'=>'fecha', 
				'language' => 'es',
				'htmlOptions' => array(
					'id' => 'desde',
					'size' => '10',
                                  'autocomplete'=>"off" 
				),
				'defaultOptions' => array(  
					'showOn' => 'focus', 
					'dateFormat'=>'yy-mm-dd',
					'showOtherMonths' => true,
					'selectOtherMonths' => true,
					'changeMonth' => true,
					'changeYear' => true,
					'showButtonPanel' => true,
				)
			), 
			true), 
		),
       
               
            
         
            
            
              array('filter'=> Gestor::lista(),
                        'header'=>'GESTOR',
                        'value' => '$data->gestor',
                        'type' => 'text',
                        'name' => 'gestor',
                        'htmlOptions' => array('class' => 'text-center'),
                ),
            

                array(
                    'filter'=> Prestamo::listaEstatus(),
                    'type' => 'html',
                    'value' => 'Prestamo::estatusClass2($data->estatus,$data->id_prestamo)',
                    'name' => 'estatus',
                  
                    'htmlOptions' => array('class' => 'text-center'),
                    
                ),
            
            

	),
)); ?>
</div> 

<?php

}else{
?>

<div class='table-responsive'>   
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'pagos-grid',
	'dataProvider'=>$model->search(),
        'pager' => array('cssFile' => Yii::app()->baseUrl.'/public/css/tablas.css'),
	'afterAjaxUpdate' => 'reinstallDatePicker',  
        'filter'=>$model,
	'columns'=>array(
               array(
                    'header'=>'ID',
                    'name' => 'id_pago',
                    'value' => '$data->id_pago',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
             array(
                    'header'=>'NUM.OPE',
                    'name' => 'num_operacion',
                    'value' => '$data->num_operacion',
                    'type' => 'text',
                    'htmlOptions' => array('class' => 'text-center'),
                ),
                array(
           
                'filter'=> ModalidadPago::lista(),
                'value' => 'ModalidadPago::Descripcion($data->id_modalidad_pago)',
                'type' => 'text',
                'name' => 'id_modalidad_pago',
                '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(
                   'header' =>'FOTO',
                    'filter' =>false,
                    'value' => 'CHtml::link(CHtml::image(Yii::app()->request->baseUrl."/upload/".$data->imagen,"", array("width" =>"25")),Yii::app()->request->baseUrl."/upload/".$data->imagen, array("target"=>"_blank"))  ',
                    'type' => 'raw',
                    'name' => 'imagen',
                    'htmlOptions' => array( 'class' => 'text-center'),
                ),
               array(
                'header' => 'IMPRIMIR',
                'class' => 'CButtonColumn',
                'htmlOptions' => array('width' => '100', 'class' => 'text-center'),
                    'template' => '{pdf}',
                    'buttons' => array(
                       'pdf' => array(
                            'label' => '',
                            'url' => 'Yii::app()->controller->createUrl("Recibo",array("id"=>$data->id_pago))',
                            'options' => array(
                                'data-toggle' => 'tooltip',
                                'class' => ' fa fa-file-pdf fa-lg mr-3 text-danger',
                                'data-original-title' => 'IMPRIMIR RECIBO',
                                'target'=>'_black',
                            ),
                            'visible' => 'true',
                        ),
                    ),
                ),
                
                            array( 
            'header' => 'IMPRIMIR POR ANDROID',
            'class' => 'CButtonColumn',
            'htmlOptions' => array('width' => '100', 'class' => 'text-center'),
            'template' => '{pdf}',
            'buttons' => array(
               'pdf' => array(
                    'label' => '',
                    'url' => 'Yii::app()->controller->createUrl("Recibo",array("id"=>$data->id_pago))',
                    'options' => array(
                        'data-toggle' => 'tooltip',
                        'class' => ' fa fa-file-pdf fa-lg mr-3',
                        'data-original-title' => 'IMPRIMIR PDF ANDROID',
                        'onclick' => 'app(this)',
                    ),
                    'visible' => 'true',
                    ),
                    ),
                ),
            
            
                                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(
                    'value' => '$data->capital',
                    'type' => 'text',
                    'name' => 'capital',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            
                array(
                    'value' => '$data->interes',
                    'type' => 'text',
                    'name' => 'interes',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            */
            
               array(
                    'value' => '$data->cuota',
                    'type' => 'text',
                    'name' => 'cuota',
                    'htmlOptions' => array('class' => 'text-center'),
             
                ),
            
          
                 array(
			'name' => 'fecha',
                        'value'=>  'Utility::fecha($data->fecha)',
			'filter' => $this->widget(
                                'zii.widgets.jui.CJuiDatePicker', array(
				'model'=>$model, 
				'attribute'=>'fecha', 
				'language' => 'es',
				'htmlOptions' => array(
					'id' => 'desde',
					'size' => '10',
                                  'autocomplete'=>"off" 
				),
				'defaultOptions' => array(  
					'showOn' => 'focus', 
					'dateFormat'=>'yy-mm-dd',
					'showOtherMonths' => true,
					'selectOtherMonths' => true,
					'changeMonth' => true,
					'changeYear' => true,
					'showButtonPanel' => true,
				)
			), 
			true), 
		),
       
               
            
         
            
            
              array('filter'=> Gestor::lista(),
                        'header'=>'GESTOR',
                        'value' => '$data->gestor',
                        'type' => 'text',
                        'name' => 'gestor',
                        'htmlOptions' => array('class' => 'text-center'),
                ),
            

                array(
                    'filter'=> Prestamo::listaEstatus(),
                    'type' => 'html',
                    'value' => 'Prestamo::estatusClass2($data->estatus,$data->id_prestamo)',
                    'name' => 'estatus',
                  
                    'htmlOptions' => array('class' => 'text-center'),
                    
                ),
            
            

	),
)); ?>
</div> 


<?php

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


if(isset($session['pago'])){
    $d = $session['pago'];
    $num=0;
    $cuota=0;
    $capital=0;
    $interes=0;
    foreach($d->data as $item)
    {
    $num=$num+1;
    $cuota=$cuota+$item->cuota;
    $capital=$capital+$item->capital;
    $interes=$interes+$item->interes;
    }
?>
    
    <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">
            TOTAL REGISTROS
        </div>
        
        <?php
        if(!empty($_SESSION['id_perfil']) and ($_SESSION['id_perfil']=='1') ){
        ?>
        
        <div class="col-12 col-sm-12 col-md-3 text-center">
            CAPITAL
        </div>
        <div class="col-12 col-sm-12 col-md-3 text-center">
            INTERES
        </div>
        <?php
        
        }
        ?>
        
        <div class="col-12 col-sm-12 col-md-3 text-center">
            CUOTA
        </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 $num; ?>
        </div>
        <?php
        if(!empty($_SESSION['id_perfil']) and ($_SESSION['id_perfil']=='1') ){
        ?>
        
        <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php echo $capital; ?> 
        </div>
        <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php echo $interes; ?> 
        </div>
        
         <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php  echo $capital+$interes; ?> 
        </div>
        
          <?php
        
        }else{
        ?>
        <div class="col-12 col-sm-12 col-md-3 text-center" style="font-weight: 600;font-size: 20px;">
            <?php  echo $cuota; ?> 
        </div>
       <?php }?>
    </div>
    
    
  </fieldset>
       </div>
             
             
 <?php
}
 ?>
            