<?php
$this->breadcrumbs=array(
	'Ajuste Haberes'=>array('index'),
	$model->id,
);

$this->menu=array(
	array('label'=>'List AjusteHaberes', 'url'=>array('index')),
	array('label'=>'Create AjusteHaberes', 'url'=>array('create')),
	array('label'=>'Update AjusteHaberes', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Delete AjusteHaberes', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'Manage AjusteHaberes', 'url'=>array('admin')),
);
?>
<h3 style="text-align: center">Vista del ajuste de haberes masivo</h3><hr>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 93%;display: block;margin-left:-46%;">
      <div class="modal-dialog modal-lg">
    <div class="progress progress-striped active" >
      <div class="bar" style="width: 100%;"></div>
    </div>
  </div>
</div>
    <?= CHtml::link('Ir a la bandeja de ajuste', ['admin'], ['class'=>'btn btn-inverse']);?>
	<?php if($model->id_estatus==4){ ?>
        <a role="button" class="btn btn-primary btn-lg" data-toggle="modal" onclick="mostrarFormularioAprobarAjuste();">Aprobar ajuste masivo</a>
    <?php } ?>
    <?= ($model->id_estatus==4 || $model->id_estatus==5)?CHtml::link('Rechazar archivo','#',array('submit'=>['denegar','id'=>$model->id],'confirm' => '¿Seguro que desea denegar el archivo de aportes extraordinarios?','class'=>'btn btn-danger')):"";?>


  <br><br>
<?php $this->widget('bootstrap.widgets.TbAlert', array(
		'block' => true, // display a larger alert block?
		'fade' => true, // use transitions?
		'closeText' => '×', // close link text - if set to false, no close link is displayed
		'alerts' => array(// configurations per alert type
            'error' => array('block' => true, 'fade' => true, 'closeText' => '×'), // success, info, warning, error or danger
			'success' => array('block' => true, 'fade' => true, 'closeText' => '×'), // success, info, warning, error or danger
		),
	))?>
<fieldset>
    <legend style=" font-size: 17px;"><b>Datos del encabezado la n&oacute;mina de ajustes</b></legend>
    <table class="table table-bordered table-striped table-hover items table table-striped table-bordered table-condensed" >
      <tr>
        <td style="text-align: justify; width: 20%;"><b><?= $model->getAttributeLabel('nombre_archivo'); ?></b></td>
        <td style="text-align: justify;"><?= $model->nombre_archivo; ?></td>
        <td style="text-align: justify; width: 20%;""><b><?= $model->getAttributeLabel('descripcion'); ?></b></td>
        <td style="text-align: justify"><?= $model->descripcion; ?></td>
      </tr>
      <tr >
        <td style="text-align: justify; width: 20%;"><b><?= $model->getAttributeLabel('total_asociado'); ?></b></td>
        <td style="text-align: justify"><?= $model->total_asociado ?></td>
        <td style="text-align: justify; width: 20%;""><b><?= $model->getAttributeLabel('total_asociado'); ?></b></td>
        <td style="text-align: justify">Bs. <?= number_format($model->total_ajuste,2,",", ".") ?></td>
      </tr>
      <tr >
        <td style="text-align: justify; width: 20%;"><b><?= $model->getAttributeLabel('fecha_registro'); ?></b></td>
        <td style="text-align: justify"><?= date('d-m-Y',strtotime($model->fecha_registro)); ?></td>
        <td style="text-align: justify; width: 20%;""><b>Estatus</b></td>
        <td style="text-align: justify"><?= $model->nombre_estatus; ?></td>
      </tr>
      <tr>
        <td style="text-align: justify; width: 20%;"><b><?= $model->getAttributeLabel('id_concepto_ajuste'); ?></b></td>
        <td style="text-align: justify"><?= $model->idConceptoAjuste->descripcion; ?></td>
        <td style="text-align: justify; width: 20%;"><b><?= $model->getAttributeLabel('fecha_ajuste'); ?></b></td>
        <td style="text-align: center"><?=  date('d-m-Y', strtotime($model->fecha_ajuste))?></td>
      </tr>
    </table>
</fieldset>

<div class="panel-heading" data-toggle="collapse" data-target="#collapse-faq-3" style="background-color: #3C85C4; padding: 0.1%;margin-top: 0.3%;" onclick="seleccionTabs(3)">
            <h5 class="panel-title" style="padding-left: 1.5%;">
              <a data-toggle="collapse" href="#collapse3" style="color: white">
                    <div style = "display: ruby-base;">
                        <i id="indicator-3" class="icon-chevron-<?=(isset($mantenerSessionAjuste) && isset($mantenerSessionAjuste['collapse-faq-3'])&& $mantenerSessionAjuste['collapse-faq-3']==1)?'up':'down'?> "></i>&nbsp;&nbsp;Informaci&oacute;n de la n&oacute;mina ajustes cargados
                    </div>
                </a>
            </h5>
    </div>
    <div id="collapse-faq-3" class="<?=(isset($mantenerSessionAjuste) && isset($mantenerSessionAjuste['collapse-faq-3'])&& $mantenerSessionAjuste['collapse-faq-3']==1)?'in':''?> collapse"><br>
        <table class="table table-bordered table-striped table-hover items table table-striped table-bordered table-condensed" >
          <tr class="info">
            <td style="text-align: center; width: 20%;"><b>Descripci&oacute;n</b></td>
            <td style="text-align: center; width: 20%;"><b>Cantidad de asociados</b></td>
            <td style="text-align: center; width: 20%;"><b>Total monto asociado </b></td>
            <td style="text-align: center; width: 20%;"><b>Total monto patrono </b></td>
          </tr>
          <?php
            $totalAsociado = $montoAsociado = $montoPatrono = 0;
            foreach ($data1 as $key => $value) {
                 $totalAsociado += $value['total'];
                 $montoAsociado += $value['monto_asociado'];
                 $montoPatrono += $value['monto_patrono'];
            ?>
              <tr>
                <td style="text-align: justify; width: 20%;"><?= $value['descripcion']?></td>
                <td style="text-align: center; width: 20%;"><?= $value['total']?></td>
                <td style="text-align: right; width: 20%;"><?= Yii::app()->format->number($value['monto_asociado']) ?></td>
                <td style="text-align: right; width: 20%;"><?= Yii::app()->format->number($value['monto_patrono']) ?></td>
              </tr>
          <?php }?>
          <tr >
            <td style="text-align: center; width: 20%;"><b>Total</b></td>
            <td style="text-align: center; width: 20%;"><b><?= $totalAsociado?></b></td>
            <td style="text-align: right;"><b><?= number_format($montoAsociado,2,",", ".") ?></b></td>
            <td style="text-align: right"><b><?= number_format($montoPatrono,2,",", ".") ?></b></td>
          </tr>
        </table>
    </div>

<div id="VistaAjusteMasivo" style="display: <?= ($operacion ==0 )?"block":"none"?>">
    <div class="panel-heading" data-toggle="collapse" data-target="#collapse-faq-1" style="background-color: #3C85C4; padding: 0.1%;margin-top: 0.3%;" onclick="seleccionTabs(1)">
                <h5 class="panel-title" style="padding-left: 1.5%;">
                  <a data-toggle="collapse" href="#collapse1" style="color: white">
                        <div style = "display: ruby-base;">
                            <i id="indicator-1" class="icon-chevron-<?=(isset($mantenerSessionAjuste) && isset($mantenerSessionAjuste['collapse-faq-1'])&& $mantenerSessionAjuste['collapse-faq-1']==1)?'up':'down'?> "></i>&nbsp;&nbsp;Informaci&oacute;n de los ajustes cargados
                        </div>
                    </a>
                </h5>
        </div>
        <div id="collapse-faq-1" class="<?=(isset($mantenerSessionAjuste) && isset($mantenerSessionAjuste['collapse-faq-1'])&& $mantenerSessionAjuste['collapse-faq-1']==1)?'in':''?> collapse"><br>
            <?php $this->widget('bootstrap.widgets.TbGridView',array(
                'id'=>'ajuste-haberes-grid',
                'dataProvider'=>$modelAjustes->searchAjusteMasivo($model->id),
                'filter'=>$modelAjustes,
                'columns'=>array(
                    [
                        'name'=>'cedula',
                        'value'=>'($data->idAsociado)?$data->idAsociado->cedula:""',
                    ],
                    [
                        'header'=>'Nombres y apellidos',
                        'name'=>'nombre',
                        'value'=>'(isset($data->idAsociado->nombre))?$data->idAsociado->nombre." ".$data->idAsociado->apellidos:""',
                    ],
                    [
                        'name'=>'idUnidad',
                        'value'=>'($data->idAsociado)?$data->idAsociado->unidad->descripcion:""',
                        'filter'=>CHtml::listData(Unidad::model()->findAll('blnborrado= false'), 'idunidad', 'descripcion'),
                    ],
                    [
                        'name'=>'id_tipo_ajuste',
                        'value'=>'($data->idTipoAjuste)?$data->idTipoAjuste->descripcion:""',
                        'filter'=>CHtml::listData(TipoAjuste::model()->findAll(), 'id', 'descripcion'),
                    ],
                    [
                        'name'=>'monto_asociado',
                        'value'=>'number_format($data->monto_asociado,2,",",".")',
                         'filter'=>false
                    ],
                    [
                        'name'=>'monto_patrono',
                        'value'=>'number_format($data->monto_patrono,2,",",".")',
                         'filter'=>false
                    ],
                ),
            ));?>
        </div>


    <div class="panel-heading" data-toggle="collapse" data-target="#collapse-faq-2" style="background-color: #3C85C4; padding: 0.1%;margin-top: 0.3%;" onclick="seleccionTabs(2)">
                <h5 class="panel-title" style="padding-left: 1.5%;">
                  <a data-toggle="collapse" href="#collapse2" style="color: white">
                        <div style = "display: ruby-base;">
                            <i id="indicator-2" class="icon-chevron-<?=(isset($mantenerSessionAjuste) && isset($mantenerSessionAjuste['collapse-faq-2'])&& $mantenerSessionAjuste['collapse-faq-2']==1)?'up':'down'?> "></i>&nbsp;&nbsp;Informaci&oacute;n de los ajustes no definidos
                        </div>
                    </a>
                </h5>
        </div>
        <div id="collapse-faq-2" class="<?=(isset($mantenerSessionAjuste) && isset($mantenerSessionAjuste['collapse-faq-2'])&& $mantenerSessionAjuste['collapse-faq-2']==1)?'in':''?> collapse"><br>
            <div id="ajuste_haberes_no_definidos">
                <div id="mensajeAHND"></div>
                    <?php $this->widget('bootstrap.widgets.TbGridView',array(
                        'id'=>'ajuste-haberes-diferido-grid',
                        'dataProvider'=>$modelAjustesDiferido->search($model->id),
                        'filter'=>$modelAjustesDiferido,
                        'columns'=>array(
                            [
                                'name'=>'cedula',
                                'value'=>'$data->cedula',
                            ],
                            [
                                'name'=>'id_tipo_ajuste',
                                'value'=>'($data->idTipoAjuste)?$data->idTipoAjuste->descripcion:""',
                                'filter'=>CHtml::listData(TipoAjuste::model()->findAll(), 'id', 'descripcion'),
                            ],
                            [
                                'name'=>'monto_asociado',
                                'value'=>'number_format($data->monto_asociado,2,",",".")',
                                'filter'=>false
                            ],
                            [
                                'name'=>'monto_patrono',
                                'value'=>'number_format($data->monto_patrono,2,",",".")',
                                'filter'=>false
                            ],
                            [
                                'name'=>'id_estatus_ajuste_diferido',
                                'value'=>'($data->idEstatusAjusteHaberes)?$data->idEstatusAjusteHaberes->descripcion:""',
                                'filter'=>CHtml::listData(EstatusAjusteHaberesDiferido::model()->findAll(), 'id', 'descripcion'),
                            ],
                            'observacion',
                            [
                                'class'=>'bootstrap.widgets.TbButtonColumn',
                                'header'=>"Acción",
                                'template' => '{update}',
                                'buttons'=>[
                                    'update' => [
                                                'label' =>'actualizar',
                                                // 'urlExpression'=>'"javascript:change();"',
                                               'url'=>'$data->id',
                                                'click'=>'js:function() { monstarFormularioDefinicionAjuste($(this).attr("href"));return false; }',
                                    ],
                                ]

                            ]
                        ),
                    ));?>
                    </div>
            <div id="definicion_AHND" style="display: none">
                <?= $this->renderPartial('viewDefinicionAjusteHaber', array(
                                    'model'=>$model,
                                    'modelAjustesDiferido'=>$modelAjustesDiferido,
                                )); ?>


                </div>
        </div>


     <?php $this->widget('bootstrap.widgets.TbGridView',array(
    	'id'=>'conf-retiro-parcial-grid',
    	'dataProvider'=> $modelSeguimiento->searchSeguimiento($model->id),
    	//'filter'=>$model,
    	'columns'=>array(
    		array(
                        'name'=>'fecha_registro',
                        'value'=>'date("d-m-Y h:m:s",strtotime($data->fecha_registro))',
                    ),
    		array(
                        'name'=>'id_estatus_ajuste_haberes',
                        'value'=>'$data->idEstatusAjusteHaberes->descripcion',
                    ),
    		array(
                        'name'=>'observacion',
                        'value'=>'$data->observacion',
                    ),
    		array(
                        'header'=>'Usuario',
                        'name'=>'id_usuario',
                        'value'=>'$data->datosUsuario',
                    ),
    	),
    )); ?>
</div>
<div id="formularioAprobarAjusteHaberes" style="display: <?= ($operacion !=0 )?"block":"none"?>">
    <?= $this->renderPartial('formularioAprobarAjusteHaberes', array(
                                    'model'=>$model,
                                    'modelSeguimiento'=>$modelSeguimiento,
                                )); ?>
</div>
    <br/>

    <?php Yii::app()->clientScript->registerScript('busqueda', '

        var idDefinicionCuota=0;


         function seleccionTabs(id){
                let estado = (($("#collapse-faq-"+id).hasClass(\'in\'))?0:1);
                let idCollapse ="collapse-faq-"+id;
                if(estado ==1){
                    $(`#indicator-${id}`).removeClass("icon-chevron-down");
                    $(`#indicator-${id}`).addClass("icon-chevron-up");
                }
                else{
                    $(`#indicator-${id}`).removeClass("icon-chevron-up");
                    $(`#indicator-${id}`).addClass("icon-chevron-down");
                }
                $.ajax({
                    url:"'.CController::createUrl('/Comun/EstadoTabsNominaAjusteHaberes').'",
                    cache: false,
                    type: "POST",
                    data: ({id:idCollapse,estado:estado}),
                });
            }

        function monstarFormularioDefinicionAjuste(id){
            $.ajax({
                    url:"'.CController::createUrl('/Comun/BuscarAjusteHaberesNoDefinido').'",
                    cache: false,
                    type: "POST",
                    dataType: "json",
                    data: ({id:id}),
                    beforeSend: function(xkr){
                        $("#formulario").hide("slow");
                        $(".datos").html("");
                    },
                    success: function(data){
                        idDefinicionCuota = id;
                        if(data.error ==0){
                             $("#cedula").html(data.cedula);
                             $("#nombre").html(data.nombre);
                             $("#apellido").html(data.apellido);
                             $("#unidad").html(data.unidad);
                             $("#estatus").html(data.estatus);
                             $("#fechaingreso").html(data.fechaingreso);

                             $("#id_tipo_ajuste").html(data.id_tipo_ajuste);
                             $("#monto_asociado").html(data.monto_asociado);
                             $("#monto_patrono").html(data.monto_patrono);
                             $("#id_estatus_ajuste_diferido").html(data.id_estatus_ajuste_diferido);
                             $("#observacion").html(data.observacion);
                        }
                    }
                });

            $("#ajuste_haberes_no_definidos ").hide("slow");
            $("#definicion_AHND").show("slow");
            $("#mensaje").html("");
            $("#mensajeAHND").html("");
        }

        function cerrarDefinicioAjuste(){
            idDefinicionCuota = 0;
            $("#ajuste_haberes_no_definidos").show("slow");
            $("#definicion_AHND").hide("slow");
            $("#CorreccionClave").hide("slow");
            $("#CorreccionPeriodo").hide("slow");
            $("#mensajeAHND").html("");
            $(".datos").html("");
            $("#'.CHtml::activeId($modelAjustesDiferido,'id_estatus_ajuste_diferido').'.span6").val("").change();
            $("#'.CHtml::activeId($modelAjustesDiferido,'observacion').'").val(\'\');
        }

        function definirAjuste(){
            var data=$("#definicion_AHND :input").serialize()+ \'&AjusteHaberesDiferido[id]=\' + idDefinicionCuota;
            $.ajax({
                type: \'POST\',
                url:\''.Yii::app()->createAbsoluteUrl("ajustehaberes/datosNominaAjusteHaberes/updateDefinicionAjusteAjax").'\',
                data:data,
                beforeSend: function(xkr){
                    $("#mensaje").html("");
                },
                success:function(data){
                    $(".load").css("display","none");
                    try{
                        var d=jQuery.parseJSON(data)
                        if(Object.keys(d).length>0){
                            if(d.error==0){
                                cerrarDefinicioAjuste();
                                if(d.estatusTxt!=0){
                                    $(\'#myModal\').modal();
                                    window.location.reload(false); //firefox
                                    window.location = self.location; //chrome
                                }
                                else{
                                    $.fn.yiiGridView.update("ajuste-haberes-diferido-grid");
                                }
                                $("#mensajeAHND").html("<div class=\"alert in alert-block fade alert-success\">El registro han sido actualizado exitosamente</div>");

                            }
                            else if(d.error==1){
                                $("#mensaje").html(d.mensajes_error);
                            }
                        }
                    }
                    catch(err){
                        alert("Lo sentimos, ha ocurrido un error!");
                    }
                },
                error: function(data) {
                    alert("Lo sentimos, ha ocurrido un error!");
                },
                dataType:\'html\'
            });
        }



        function mostrarFormularioAprobarAjuste(){
            $("#formularioAprobarAjusteHaberes").show("slow");
            $("#VistaAjusteMasivo").hide("slow");
        }
        function cerrarAprobarAjusteHaberes(){
            $("#formularioAprobarAjusteHaberes").hide("slow");
            $("#VistaAjusteMasivo").show("slow");
        }

        function aprobarDenegarAjusteHaberes(id){
            var data=$("#formularioAprobarAjusteHaberes :input").serialize()+ \'&DatosNominaHaberesSeguimiento[id_estatus_ajuste_haberes]=\' + id + \'&DatosNominaHaberesSeguimiento[id_datos_nomina_ajuste_haberes]='.$model->id.'\';
            $.ajax({
                type: \'POST\',
                url:\''.Yii::app()->createAbsoluteUrl("ajustehaberes/datosNominaAjusteHaberes/aprobarDenegarAjusteHaberes").'\',
                data:data,
                beforeSend: function(xkr){
                    $("#mensaje").html("");
                    $(".btn_formulario").prop("disabled", true);
                    $("#myModal").modal({backdrop: \'static\', keyboard: false});
                },
                success:function(data){
                    $(".load").css("display","none");
                    try{
                        var d=jQuery.parseJSON(data)
                        if(Object.keys(d).length>0){
                            if(d.error==0){
                                cerrarAprobarAjusteHaberes();
                                window.location.replace("'.CController::createUrl('/ajustehaberes/datosNominaAjusteHaberes/view', ['id' => $model->id]).'");
                                $("#mensajeAHND").html("<div class=\"alert in alert-block fade alert-success\">El registro han sido actualizado exitosamente</div>");
                            }
                            else if(d.error==1){
                                $("#myModal").modal(\'hide\');
                                $(".btn_formulario").prop("disabled", false);
                                $("#mensajeAprobarDenegarAjusteHaberes").html(d.mensajes_error);
                            }
                        }
                    }
                    catch(err){
                        $("#myModal").modal(\'hide\');
                        $(".btn_formulario").prop("disabled", false);
                        alert("Lo sentimos, ha ocurrido un error!");
                    }
                },
                error: function(data) {
                    $("#myModal").modal(\'hide\');
                    $("#btn_formulario").prop("disabled", false);
                    alert("Lo sentimos, ha ocurrido un error!");
                },
                dataType:\'html\'
            });
        }


        ',CClientScript::POS_HEAD);

?>
