<?php
require_once ('../../autoload.php');
$Enrutamiento = new Enrutamiento();
require_once $Enrutamiento->session;
require_once $Enrutamiento->funciones;
require_once ('funciones_visaciones.php');

//	globales
$id_funcionario = $_SESSION['id_funcionario'];
$nivel = $_SESSION['nivel'];

//	Clases
$Funcionario = new Funcionario();


$Visacion = new Visa();

 if($id_funcionario==380 || $id_funcionario==365 || $id_funcionario==2839 || $id_funcionario==3011) {
 //	$AsignacionDecretos = $Decreto->getAllAsignacionesPendientes($etapa);
 	$AsignacionDecretos=$Visacion->VisaEtapa4();
 } else {
 	$AsignacionDecretos = $Visacion->VisacionFuncionarios4($id_funcionario);
 }

$num = (!is_null($AsignacionDecretos))? count($AsignacionDecretos): 0;

$anio = date('Y');
$anio21= 2021;


if($AsignacionDecretos){

?>

<h2 class="text-center text-info"># Registros: <?=$num?> finalizados</h2>
<div class="table-responsive text-wrap">
	<table class="table table-bordered table-hover" id="t1">
		<thead>
			<tr class="text-center">
				<th width="10%"># Seguimiento / Fecha Solicitud</th>
				<th width="15%">#Decreto / #Exento</th>
				<th width="15%">Decreto</th>
				<th>Materia</th>
				<th>Origen / Solicitante</th>
				<th width="10%">Acciones</th>
			</tr>
		</thead>
		<tbody  id="myScrollspy" class="text-left">
			<?php
			foreach ($AsignacionDecretos as $ElDecreto) { 
				$FuncionarioAsigna = $Funcionario->getPerfilGlobalFuncionario($ElDecreto->envia);

				?>
				<tr>
					<td class="text-center">

						<h5 class="text-success"><b>ID-<?=$ElDecreto->id?></b></h5>
						<h6 class="text-success"><?=date("d-m-Y", strtotime($ElDecreto->fecha_hora))?></h6>
					</td>
					<td class="text-center">

				<h5 class='text-muted'><b>#ID_Simge: <?$ElDecreto->id_simge?></b></h5>
						

						<hr>

						<?php
						//	verifica si tiene # decreto
						if(!is_null($ElDecreto->num_decreto)) 
						{ 
							//	Cuando hay un # Decreto
							if(is_null($ElDecreto->num_exento)) {
								echo "<h6 class='text-muted'><b># Exento: No</b></h6>";
							} else {
								$numExento = $ElDecreto->num_exento;
								echo "<h6 class='text-muted'># Exento: ".$numExento."</h6>";
							} 
						} else {
							if($ElDecreto->exento) 
							{
								echo "<h6 class='text-muted'><b># Exento: Si</b></h6>";
							} else {
								$numExento = $ElDecreto->num_exento;
								echo "<h6 class='text-muted'><b># Exento: No</b></h6>";
							} 
						} ?>

						<hr>
						<h6 class="text-muted"># Ordinario: <?=$ElDecreto->num_ordinario?></h6>
					</td>

					<!-- Decreto Firmado: Etapa==7 -->
					<td class="text-center">
						<?php

						if($ElDecreto->ext!="pdf"){ 
							echo "<h5 data-toggle='tooltip' title='Decreto No Firmado'><img src='../assets/icons/decreto-no-firmado.svg' style='width: 1.7em'></h5></a>";
						} else if(!is_null($ElDecreto->num_decreto)) { 
							echo "<a href='../../documentos/decretos/$ElDecreto->anio/$ElDecreto->id/$ElDecreto->archivo' target='_blank'>
							
								<h5 data-toggle='tooltip' title='Ver Decreto Firmado 1 '><img src='../assets/icons/decreto-firmado.svg' style='width: 1.7em'></h5>
							</a>
							
							
							
							
							";
							
							echo "<a href='../../documentos/decretos/2022/$ElDecreto->id/$ElDecreto->archivo' target='_blank'>
							
								<h5 data-toggle='tooltip' title='Ver Decreto Firmado 2 '><img src='../assets/icons/decreto-firmado-ojo.svg' style='width: 1.7em'></h5>
							</a>
							";
						} 
						else { 
							echo "<h5>---</h5>";
						} ?>
						<hr>


					</td>

					<td>
	
						<h6 class="text-primary txt-materia"><?=$ElDecreto->materia?></h6>
					</td>

					<td>
						<h6 class="text-primary"><b><?=$ElDecreto->oficina?></b></h6>
						<hr>
						<h6 class="text-success"><?=$FuncionarioAsigna->nombres?><br><?=$FuncionarioAsigna->apellidos?></h6>
					</td>

					<!-- Botones -->
					<td class="text-center">
						<!-- Modal ver Expediente -->
						<button type="button" class="btn" name="btnModalVerArchivos" value="<?=$ElDecreto->id_simge?>" target="_blank" data-bs-toggle="modal" data-target="#mainModal" style="float:left; all:unset;">
							<h5 data-toggle="tooltip" title="Ver archivos expediente"><img src="../assets/icons/expediente.svg" style="width: 1.7em"></h5>
						</button>

                <?if (!empty($rectifiquese)) {
    echo "<ul>";
    foreach ($rectifiquese as $r) {
        echo "<li>Rectificatorio</li>
        <a href='../../documentos/decretos/$ElDecreto->anio/$r->id_decreto/$r->rectifiquese' target='_blank'>
		<h5 data-toggle='tooltip' title='Ver Decreto Firmado 1 '><img src='../assets/icons/decreto-firmado.svg' style='width: 1.7em'></h5>";
    }
    echo "</ul>";
} 
?>
            <hr>
						<!-- Funcionario asignado -->
						<?php
							echo ($nivel==1)? "<div class='text-muted'><h6 class='text-primary'>Funcionario asignado:</h6><h6>$ElDecreto->nombres $ElDecreto->apellidos</h6></div>" : NULL;
						?>
					</td>

				</tr>
			<?php
			} ?>
		</tbody>
	</table>
</div>

<?php
} else { ?>
	<h2 class="text-danger text-center">No hay Decretos Pendientes.</h2>
<?php
} ?>


<?php require_once "../mainModal.php"; ?>

<script type="text/javascript" src="<?=$Enrutamiento->jsDataTableMin;?>"></script>
<script type="text/javascript" src="<?=$Enrutamiento->jsDataTableBootstrap4Min;?>"></script>
<script type="text/javascript" src="<?=$Enrutamiento->jsNatural;?>"></script>
<script type="text/javascript" src="<?=$Enrutamiento->jsGlobal;?>"></script>


<script type="text/javascript">

$('[data-toggle="tooltip"]').tooltip();


$(document).ready(function(){


  //  Modal Ver archivos recibidos
	$('#t1 tbody').on( 'click', 'button[name=btnModalVerArchivos]', function() {
		var id = $(this).val();
		var btn = 1;
		$('[data-toggle="tooltip"]').tooltip("hide");
		$("#showMainModal").load("municipalidad/solicitudesDecreto/modalVerDocumentos.php",{id:id, btn:btn});
	});






});

</script>
