<? session_start();
//RESTRICCION DE ACCESO A TRABAJADOR (ACCESO INDIVIDUAL)
if (isset($_SESSION['tipousuario'])) {
	if ($_SESSION['tipousuario'] == '1')
		header('location:menu_personal.php');
}
if (trim($_SESSION['nombre_validar']) == '') header('location:index.php');
include("fphp.php");
$enlace = cargar_conexion();
$accion = $_REQUEST["accion"];
$cedula = $_REQUEST["cedula"];
$fdesde = $_REQUEST["fdesde"];
$periodo = $_REQUEST["periodo"];
$fechahoy = date('Y-m-d');
$aprobacionVacacion = $_REQUEST["aprobacionVacacion"];
$usuario = $_SESSION['usuario_validar'];

?>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="autocompletar/js/bootstrap3-typeahead.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<?


//calculo de vacaciones SAIREH Vzla.

$consulta = mysqli_query($enlace,"select * from periodo where id='" . $_SESSION['id_validar'] . "' order by nomina,periodo desc limit 1");
if (mysqli_num_rows($consulta) != 0) {
	$row = mysqli_fetch_array($consulta);
	$per = mostrar_fecha($row['desde']) . ' al ' . mostrar_fecha($row['hasta']) . " (Nom:" . $row['nomina'] . ")";
} else $per = '';
menu();
set_time_limit(3000);


///////////////////////////////////////////////// eliminar vacaciones ////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////MOSTRAR SOLICITUD DE CEDULA ////////////////////////////////////////////////////////////////
if ((!$_POST || $_POST['busca'] == 1) && ($accion != 5) && ($accion != 2) && ($_POST['grabar'] != 1)) {

	echo "<hr><h2> <center> VACACIONES PENDIENTES POR PAGAR </center> </h2>";

	echo "<form name = 'entrada' action = '" . $_SERVER['PHP_SELF'] . "' method = 'POST'  enctype='multipart/form-data'>";
	echo "<input type = 'hidden' name = 'busca' value = '1'>";
	echo "<table cellpadding=2 cellspacing=0 width='500' align='center'>";
	echo "<tr>";
	echo "<td align=right> C&eacute;dula/Nombre/Apellido:</td>";
	echo "<td> <input name='cedula' size = '30' maxlength = '8'></td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td align=right> Ordenado por:</td>";
	echo "<td colspan = 3>";
	echo "	<input type = 'radio' name = 'orden' value = 'ced' checked> cedula";
	echo "	<input type = 'radio' name = 'orden' value = 'nom'> nombre";
	echo "	<input type = 'radio' name = 'orden' value = 'ape'> apellido";
	echo "	<input type = 'radio' name = 'orden' value = 'fechai'> Fecha Ingreso";
	echo "</tr>";
	echo "</table>";
	echo "	<script language='javascript' type='text/javascript'>";
	echo "		document.entrada.cedula.focus()";
	echo "	</script>";
	echo "<table border=0  align = 'center'><tr>";
	echo "<td><input type = 'submit' class='boton' value = 'Buscar Registros'></td>";
	echo "</tr></table></form>";

	$query1 = "";
	if ($_POST['cedula'] != "") {
		$query1 = " and (codigo like '%" . $_POST['cedula'] . "%' or nombres like '%" . $_POST['cedula'] . "%' or apellidos like '%" . $_POST['cedula'] . "%') ";
	}
	if ($_POST['orden'] == "fechai") $query2 = " order by fechai";
	else if ($_POST['orden'] == "nom") $query2 = " order by nombres";
	else if ($_POST['orden'] == "ape") $query2 = " order by apellidos";
	else if ($_POST['orden'] == "ced") $query2 = " order by codigo";
	else $query2 = " order by nombres";

	$consulta = "select * from personal, vacacion where personal.id='" . $_SESSION['id_validar'] . "' and personal.status<>'I' AND personal.codigo=vacacion.cedula AND	vacacion.aprobacion_rrhh='Aprobado'  AND	vacacion.aprobacion_nomina='Aprobado' AND vacacion.aprobacion_contabilidad='Aprobado' AND	envio_banesco!='Si' " . $query1 . " order by nomina,fdesde,nombres";
	$resultado = mysqli_query($enlace,$consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
	$num_rows = mysqli_num_rows($resultado);
if ($num_rows != 0) {
    // Agrupar registros por nómina
    $gruposNomina = [];
    while ($row = mysqli_fetch_array($resultado)) {
        $gruposNomina[$row['nomina']][] = $row;
    }

    // Recorrer cada grupo de nómina
    foreach ($gruposNomina as $tipoNomina => $registros) {
		$detalle_nomina = ( $tipoNomina == 100 ? 'DIARIA' : 'MENSUAL' );

		echo "<br><table border=0 cellpadding=2 cellspacing=0 align='center'>";
		 echo "<tr align='center' bgcolor='#7dbe2c'>";
		echo "<th  colspan=13 ali = center><font face='verdana' size=2> nomina: $detalle_nomina</font></th>";
		echo "</tr>";
		echo "<tr bgcolor='#43bced' height='35'>";
        //echo "<table rules=none border=0 cellpadding=2 cellspacing=0 align='center'>";
        //echo "<tr style='background:#43bced; height:28px; font-size:12px;'>";
		echo "<th style='color:white; text-align:center;'>Nº</th>";
        //echo "<th style='color:white; text-align:center;'>Foto</th>";
        echo "<th style='color:white; text-align:left;'>Cédula</th>";
        echo "<th style='color:white; text-align:left;'>Nombres</th>";
        echo "<th style='color:white; text-align:left;'>Apellidos</th>";
        echo "<th style='color:white; text-align:center;'>Nómina</th>";
        echo "<th style='color:white; text-align:center;'>Fecha Ingreso</th>";
        echo "<th style='color:white; text-align:center;'>Fecha Inicio Vacac.</th>";
        echo "<th style='color:white; text-align:center;'>Monto a pagar (Bs.)</th>";
        echo "<th colspan=4 style='color:white; text-align:center;'>Consultar</th>";

        $color = true;
		$totalNomina = 0; // acumulador por grupo
		$contador = 1; // inicializar contador


        foreach ($registros as $row) {
            $cedula = $row['codigo'];
            $tcolor = $color ? "#CFE7DE" : "white";
            $imagen = file_exists('fotos/' . $cedula . '.jpg') ? 'fotos/' . $cedula . '.jpg' : 'img2/nohay.jpg';

            echo "<tr bgcolor='$tcolor'>";
			echo "<td align='center'>$contador</td>"; // mostrar número de fila
           // echo "<td align='center'><img src='$imagen' height='64' width='64'></td>";
            echo "<td width='100'><a href='" . $_SERVER['PHP_SELF'] . "?accion=5&cedula=$cedula'>" . $row['codigo'] . "</a></td>";
            echo "<td width='200'>" . trim($row['nombres']) . " " . $row['nombres1'] . "</td>";
            echo "<td width='200'>" . trim($row['apellidos']) . " " . $row['apellidos1'] . "</td>";
            echo "<td width='50' align=center>" . $row['nomina'] . "</td>";
            echo "<td width='120' align=center>" . mostrar_fecha($row['fechai']) . "</td>";
            echo "<td width='120' align=center>" . mostrar_fecha($row['fdesde']) . "</td>";
            echo "<td width='120' align=center>" . $row['neto_pagar_vacacion'] . "</td>";
            echo "<td width='30' align='center'><a href='" . $_SERVER['PHP_SELF'] . "?accion=5&cedula=$cedula'><img border=0 src='img2/deduccion.png' alt='Seleccionar este registro'></a></td>";
            echo "</tr>";

			// acumular total
            $totalNomina += $row['neto_pagar_vacacion'];
			 $contador++; // incrementar contador


            $color = !$color;
        }
		// Fila de total al final
        echo "<tr style='background:#e0e0e0; font-weight:bold;'>";
        echo "<td colspan='7' align='right'>TOTAL $tipoNomina:</td>";
        echo "<td align='center'>" . number_format($totalNomina, 2, ',', '.') . "</td>";
        echo "<td colspan='4'></td>";
        echo "</tr>";

        echo "</table><br>";
    }
} else {
    echo "<hr>";
}
	
	mysqli_free_result($resultado);
}

///////////////////////////////////////////////// MOSTRAR DATA A INGRESAR ////////////////////////////////////////////////////////////////
if ($accion == 2 || $accion == 5 || $_POST['grabar'] == 1) {
	include("calendario/calendario.php");

	echo "<b>Opciones:</b> &nbsp;&nbsp;
      <a href='" . $_SERVER['PHP_SELF'] . "'>
          <img border='0' src='img2/regresa.png' alt='Regresar'>
          Regresar
      </a>";


	echo"<h2><center>APROBACIÓN DE VACACIONES DE TRABAJADOR <center></h2>";


	if ($resultado_aprobacion != '') {
		echo "<div id='response_sucess'>";
		echo $resultado_aprobacion;
		echo "</div>";
	}

	echo "<form name = 'fentrada' action = '" . $_SERVER['PHP_SELF'] . "' method = 'POST'  enctype='multipart/form-data'>";
	echo "<input type = 'hidden' name = 'grabar' value = '1'>";

	$consulta = "select * from personal where id='" . $_SESSION['id_validar'] . "' and codigo='" . $cedula . "' ";
	$resultado = mysqli_query($enlace,$consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
	$num_rows = mysqli_num_rows($resultado);
	if ($num_rows != 0) {
		$row = mysqli_fetch_array($resultado);

		//====================== buscar tipo de nomina
		$tipoNom = 1;
		$multiplo = 0;
		$consulta1 = "select tipo from nomina where id='" . $_SESSION['id_validar'] . "' and codigo='" . $row['nomina'] . "'";
		$resultado1 = mysqli_query($enlace,$consulta1) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
		while ($row1 = mysqli_fetch_array($resultado1)) $tipoNom = $row1['tipo'];
		if ($tipoNom == 1) $multiplo = 12;
		else if ($tipoNom == 2) $multiplo = 6;
		else $multiplo = 3;
		//if ($icomi==1) $multiplo=$multiplo/2;

		//====================== buscar monto constante
		$mon01 = 0;
		$mon02 = 0;
		$mon03 = 0;
		$mon04 = 0;

		if ($con01 != '') {
			$consultax = "select monto from constante_individual where id='" . $_SESSION['id_validar'] . "' and codigo='" . $con01 . "' and cedula='" . $cedula . "' and nomina='" . $row['nomina'] . "'";
			$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
			if (mysqli_num_rows($resultadox) != 0) {
				$rowx = mysqli_fetch_array($resultadox);
				if ($tipoNom == 1) $mon01 = $rowx['monto'] / 7 * 30;
				else if ($tipoNom == 2) $mon01 = $rowx['monto'] * 2;
				else $mon01 = $rowx['monto'];
			}
		}
		if ($con02 != '') {
			$consultax = "select monto from constante_individual where id='" . $_SESSION['id_validar'] . "' and codigo='" . $con02 . "' and cedula='" . $cedula . "' and nomina='" . $row['nomina'] . "'";
			$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
			if (mysqli_num_rows($resultadox) != 0) {
				$rowx = mysqli_fetch_array($resultadox);
				if ($tipoNom == 1) $mon02 = $rowx['monto'] / 7 * 30;
				else if ($tipoNom == 2) $mon02 = $rowx['monto'] * 2;
				else $mon02 = $rowx['monto'];
			}
		}

		//====================== buscar monto conceptos
		//if ($con03!='') {
		//$consultax="select monto from historico where id='".$_SESSION['id_validar']."' and concepto='".$con03."' and cedula='".$cedula."' and nomina='".$row['nomina']."' order by xxx desc limit ".$multiplo;
		/*$consultax="select monto from historico where id='".$_SESSION['id_validar']."' and (substring(concepto,1,3)='109' OR substring(concepto,1,1)='7') and cedula='".$cedula."' and nomina='".$row['nomina']."' order by xxx desc limit ".$multiplo;
			$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
			$mpaty=0; $cpaty=0;
			while ($rowx=mysqli_fetch_array($resultadox)) {
				$mpaty +=$rowx['monto'];
				$cpaty ++;
			}
			if ($cpaty>0) {
				if ($cpaty==1) {
					$mon03=$mpaty;
				} else {
					$mon03= $mpaty / $cpaty;
				}
			}*/

		$consultax = "select round(avg(monto),2) as monto from  (select sum(sueldo) as monto from personal_sueldo where id='" . $_SESSION['id_validar'] . "' and codigo='" . $cedula . "' and fec<'" . substr($fechahoy, 0, -2) . "01' group by fec order by fec desc limit " . $multiplo . ") as prueba";

		$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
		$mpaty = 0;
		$cpaty = 0;
		if ($rowx = mysqli_fetch_array($resultadox)) {

			if ($tipoNom == 1) {
				$mon03 = $rowx['monto'];
				$monMes = $mon03 / 7 * 30;
				$monDia = $mon03 / 7;
			} else {
				$mon03 = $rowx['monto'];
				$monMes = $mon03 / 15 * 30;
				$monDia = $mon03 / 15;
			}
		}

		//}
		/*
		if ($con04!='') {
			$consultax="select monto from historico where id='".$_SESSION['id_validar']."' and substring(concepto,1,".strlen($con04).")='".$con04."' and cedula='".$cedula."' and nomina='".$row['nomina']."' group by periodo order by xxx desc limit ".$multiplo;
			$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
			$mpaty=0; $cpaty=0;
			while ($rowx=mysqli_fetch_array($resultadox)) {
				$mpaty +=$rowx['monto'];
				$cpaty ++;
			}
			if ($cpaty>0) {
				$mon04= $mpaty / $cpaty;
			}
		}
		*/
		$smes = ($row['smes']/30+$row['bono1']+$row['bono2'])*30;

		echo "<br><center><img src='img2/administrator.png'><font color=black size=5>&nbsp;" . trim($row['nombres']) . " " . trim($row['nombres1']) . ' ' . trim($row['apellidos']) . " " . trim($row['apellidos1']) . "</font></center><br>";

		//echo "Tipo de Nómina: ".$tipoNom;
		//echo "Multiplo: ".$multiplo;
		echo "<table width = '100%' align ='center'>";
		echo "<tr><td width = '20%' align = 'right'> C&eacute;dula: </td>";
		echo "<td width = '36%' align = 'left'> <input type = 'text' name = 'cedula' size = '30' maxlength = '8' value = '" . $row['codigo'] . "' readonly> * </td>";
		echo "</tr>";

		//Echo substr($fechahoy, 0, -2)."01";

		echo "<tr><td width = '15%' align = 'right'> Nombres: </td>";
		echo "<td width = '29%' align = 'left'> <input type = 'text' name = 'nombres' size = '30' maxlength = '50' value = '" . trim($row['nombres']) . " " . $row['nombres1'] . "' readonly> * </td>";
		echo "</tr>";

		echo "<tr><td align = 'right'> Apellidos: </td>";
		echo "<td align = 'left'> <input type = 'text' name = 'apellidos' size = '30' maxlength = '50' value = '" . trim($row['apellidos']) . " " . $row['apellidos1'] . "' readonly> * </td>";
		echo "</tr>";

		echo "<tr><td align = 'right' > Fecha de Ingreso: </td>";
		echo "<td align = 'left' > <input type = 'text' name = 'fec' size = '10' maxlength = '50' value = '" . $row['fechai'] . "' readonly></td>";
		echo "</tr>";

		//echo "<tr><td align = 'right' > Fecha de Hoy: </td>";
		//echo "<td align = 'left' >" .$fechahoy."</td>";
		//echo "</tr>";

		/////////////////////////////
		/*
		echo "<tr><td align = 'right' > Tipo de N&oacute;mina : </td>";
		if ($tipoNom == 1)
			echo "<td align = 'left' >  <input type = 'text' name = 'tip' size = '10' maxlength = '50' value = '1' readonly></td>";
		elseif ($tipoNom == 2) {
			echo "<td align = 'left' >  <input type = 'text' name = 'tip' size = '10' maxlength = '50' value = '2' readonly></td>";
		} else "<td align = 'left' >  <input type = 'text' name = 'tip' size = '10' maxlength = '50' value = '3' readonly></td>";

		echo "</tr>";

		*/
		///////////////////////////////////////////

		/*
		echo "<tr>";
		echo "<td  width = '200' align = 'right' > <font color=red>Salario B&aacute;sico Mensual: </font></td>";
		echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'smesx' size = '10' maxlength = '50' value = '" .$smes. "' ></td>";
		echo "</tr>";
		$smesDiario = $smes/30;
		echo "<tr>";
		echo "<td  width = '200' align = 'right' > <font color=red>Sueldo B&aacute;sico Diario: </font></td>";
		echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'smesdia' size = '10' maxlength = '50' value = '" . round($smesDiario, 2) . "' ></td>";
		//number_format($row['antiguedad'],0)
		echo "</tr>";
		*/
		///////////////////////////////////////////

		/*
		//echo "<tr>";
		//echo "<td  width = '200' align = 'right' > <font color=red>Complemento de Sueldo: </font></td>";
		//echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'smesx' size = '10' maxlength = '50' //value = '".($mon01+$mon02)."' ></td>";
		//echo "</tr>";

		//echo "<tr>";
		//echo "<td  width = '200' align = 'right' > <font color=red>Promedio Asignaciones (prom. 3 meses): </font></td>";
		//echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'smesx' size = '10' maxlength = '50' value = '".($mon03+$mon04)."' ></td>";
		//echo "</tr>";

		if ($smes > $monMes) {
			$sueldo_vac = $smesDiario;
		} else {
			$sueldo_vac = $monDia;
		}

		echo "<tr>";
		echo "<td  width = '200' align = 'right' > <font color=red>Salario Promedio Diario </font></td>";
		echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'sueldoDia' size = '10' maxlength = '50' value = '" . round($monDia, 2) . "' ></td>";
		echo "</tr>";

		echo "<tr>";
		echo "<td  width = '200' align = 'right' > <font color=red>Salario para vacaciones </font></td>";
		echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'sueldo' size = '10' maxlength = '50' value = '" . round($sueldo_vac, 2) . "' ></td>";
		echo "</tr>";
		*/

		//////////////////////////////////

		/*
		$ano1 = date("Y");
		$mes1 = date("m");
		$dia1 = date("d");
		$ano2 = $ano1 - 1;
		$ano3 = substr($row['fechai'], 0, 4);
		$mes3 = substr($row['fechai'], 5, 2);
		$dia3 = substr($row['fechai'], 8, 2);

		///////Encontar el próximo periodo de vacacaciones a pagar
		if ($ultimoPer != '') {

			$ano4 = substr($ultimoPer, 5, 4);
			$ano5 = $ano4 + 1;
			$periodoPagar = $ano4 . '-' . $ano5;
		} else {
			$ano4 = substr($row['fechai'], 0, 4);
			$ano5 = $ano4 + 1;
			$periodoPagar = $ano4 . '-' . $ano5;
		}

		/////Antiguedad para vacaciones a pagar
		$antigPagarVaca = $antiguedadVac < '1' ? 1 : $antiguedadVac + 1;
		//$antigPagarVaca = $antiguedadVac+1;



		if ($antiguedadVac < "1") {
			echo "<tr><td align = 'right' > A&ntilde;os de Antiguedad para Vacaciones? </td>";
			echo "<td align = 'left' > <input type = 'text' name = 'antiguedad' size = '10' maxlength = '10' value = '" . ($antiguedadVac + 1) . "'></td>";
			echo "</tr>";

			echo "<tr><td align = 'right' > Per&iacute;odo de Vacaciones a Pagar </td>";
			echo "<td align = 'left' > <input type = 'text' name = 'periodo' size = '10' maxlength = '9' value = '" . $periodoPagar . "'></td>";
			echo "</tr>";
		} else {

			echo "<tr><td align = 'right' > A&ntilde;os de Antiguedad para Vacaciones? </td>";
			echo "<td align = 'left' > <input type = 'text' name = 'antiguedad' size = '10' maxlength = '10' value = '" . ($diasVacaPagados >= "15" ? $antigPagarVaca : $antiguedadVac) . "'></td>";
			echo "</tr>";

			echo "<tr><td align = 'right' > ULTIMO PERIODO PAGADO</td>";
			echo "<td align = 'left' > <input type = 'text' name = 'ultper' size = '10' maxlength = '10' value = '" . $ultimoPer . "'></td>";
			echo "</tr>";

			echo "<tr><td align = 'right' > Per&iacute;odo de Vacaciones a Pagar </td>";
			echo "<td align = 'left' > <input type = 'text' name = 'periodo' size = '10' maxlength = '9' value = '" . ($diasVacaPagados >= "15" ? $periodoPagar : $ultimoPer) . "'></td>";
			echo "</tr>";
		}
			*/

			////////////////////////////////////////


		/*
		echo "<tr><td align = 'right' > Per&iacute;odo de Vacaciones? </td>";
		echo "<td align = 'left' > <input type = 'text' name = 'periodo' size = '10' maxlength = '9' value = '".($ano2.'-'.$ano1)."'></td>";
		echo "</tr>";
		*/


		if ($diasVacaPagados > 0 && $diasVacaPagados < 15) {
			echo "<tr><td align = 'right' > D&iacute;as Pagados en Fracci&oacute;n " . $ultimoPer . "</td>";
			echo "<td align = 'left' > <input type = 'text' name = 'diaspag' size = '10' maxlength = '10' value = '" . $diasVacaPagados . "'></td>";
			echo "</tr>";
		}
			/*
		echo "<tr><td align = 'right' > D&iacute;as H&aacute;biles para Vacaciones (Art. 190) </td>";
		echo "<td align = 'left' > <input type = 'text' name = 'dvac' size = '10' maxlength = '10' value = '" . ($diasVacaPagados >= 15 ? $dvac : $dvac - $diasVacaPagados) . "'></td>";
		echo "</tr>";

		echo "<tr><td align = 'right' > D&iacute;as Adicionales para Vacaciones (Art. 190) </td>";
		echo "<td align = 'left' > <input type = 'text' name = 'diext' size = '10' maxlength = '10' value = '" . ($diasVacaPagados >= 15 ? $dias_ext : 0) . "'></td>";
		echo "</tr>";

		if ($antiguedadVac < 1) {
			echo "<tr><td align = 'right' > D&iacute;as para Bono Vacacional (Cla&uacutes. 14) </td>";
			echo "<td align = 'left' > <input type = 'text' name = 'dbon' size = '10' maxlength = '10' value = '" . $dbon . "'></td>";
			echo "</tr>";
		} else {
			echo "<tr><td align = 'right' > D&iacute;as para Bono Vacacional (Cla&uacutes. 14) </td>";
			echo "<td align = 'left' > <input type = 'text' name = 'dbon' size = '10' maxlength = '10' value = '" . ($diasVacaPagados >= 15 ? $dbon : 0) . "'></td>";
			echo "</tr>";
		}
		*/

		/*

		echo "<tr><td align = 'right' > Descontar SSO? </td>";
		echo "<td align = 'left' > <select name = 'des1'>
			<option value='0'>Si
			<option value='1'>No
			</select></td>";
		echo "</tr>";

		echo "<tr>";
		echo "<td width = '200' align = 'right' > <font color=red>Nro. Semanas del SSO: </font></td>";
		echo "<td width = '400' align = 'left' > <select name = 'semana'>
			<option>0
			<option>1
			<option>2
			<option>3
			<option>4
			<option>5
			<option>6
			<option>7
				</select></td>";
		echo "</tr>";

		*/

		/*

		echo "<tr><td align = 'right' > Descontar RPVH? </td>";
		echo "<td align = 'left' > <select name = 'des2'>
			<option value='0'>Si
			<option value='1'>No
			</select></td>";
		echo "</tr>";

		//		echo "<tr><td align = 'right' > La Vacaci&oacute;n es Colectiva? </td>";
		//		echo "<td align = 'left' > <select name = 'icol'>
		//			<option value='0'>NO
		//			<option value='1'>SI
		//			</select><font color=red>&nbsp;&nbsp;(Solo se Calcular&aacute; meses fraccionados)</font></td>";
		//		echo "</tr>";

		*/

		/*

		echo "<tr><td align = 'right' > Fecha Inicial de Vacaciones(ddmmaaaa): </td>";
		echo "<td align = 'left'>";
		escribe_formulario_fecha_vacio("fecha1", "fentrada");
		echo "</td></tr>";
		*/

		//====================================== si no es automatico
		//		echo "<tr><td align = 'right' > </td>";
		//		echo "<td align = 'left'><font color=red>(Si no es Autom&aacute;tica agregar estos valores)</font>";
		//		echo "</td></tr>";

		//		echo "<tr><td align = 'right' > Fecha Final de Vacaciones(ddmmaaaa): </td>";
		//		echo "<td align = 'left'>";
		//		escribe_formulario_fecha_vacio("fecha2","fentrada");
		//		echo "</td></tr>";

		//		echo "<tr><td align = 'right' > Fecha de Reintegro (ddmmaaaa): </td>";
		//		echo "<td align = 'left'>";
		//		escribe_formulario_fecha_vacio("fecha3","fentrada");
		//		echo "</td></tr>";

		/* echo "<tr><td align = 'right' > </td>";
		echo "<td align = 'left'>";
		echo "<input type = 'submit' value = 'Grabar Liquidaci&oacute;n de Vacaciones'>";
		echo "</td></tr>"; */

		echo "</tr>";
		echo "</table>";
	}
	echo "	<script language='javascript' type='text/javascript'>";
	echo "		document.fentrada.dias.focus()";
	echo "	</script>";
	echo "</form>";



	if ($cedula != '') {
		$consulta = "select vacacion.*, personal.nombres, personal.nombres1, personal.apellidos, personal.apellidos1 from vacacion,personal where personal.id='" . $_SESSION['id_validar'] . "' and vacacion.cedula=personal.codigo and vacacion.cedula= '" . $cedula . "' order by fdesde";
		$resultado = mysqli_query($enlace,$consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
		$num_rows = mysqli_num_rows($resultado);

		//if ($num_rows != 0){
		echo "<table style='width:80%' rules=none border=0 cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr bgcolor='#43bced' height='35' align='center'>";
		echo "<th style='width:9%' rowspan = 2 align = left><font color='white'> Per&iacute;odo </font></th>";
		echo "<th style='width:6%' rowspan = 2 align = left><font color='white'> Dias Vac. </font></th>";
		echo "<th style='width:6%' rowspan = 2 align = left><font color='white'> Dias Adic Vac. </font></th>";
		echo "<th style='width:6%' rowspan = 2 align = left><font color='white'> Dias/Bono </font></th>";
		//echo "<th align = left><font color='white'> Tip/Nomina </font></th>";
		echo "<th style='width:12%' rowspan = 2 align = left><font color='white'> Desde </font></th>";
		echo "<th style='width:12%' rowspan = 2 align = center><font color='white'> Hasta </font></th>";
		echo "<th style='width:9%' rowspan = 2 align = center><font color='white'> Reintegro </font></th>";
		echo "<th style='width:9%' rowspan = 2 align = center><font color='white'> A&ntilde;o/Ant. </font></th>";
		//echo "<th align = center><font color='white'> Mes/Ant. </font></th>";
		echo "<th style='width:7%' rowspan = 2 align = center><font color='white'> Salario </font></th>";
		echo "<th style='width:9%; text-align: center;' colspan = 4 style='text-align: center;' ><font color='white'> Aprobaciones </font></th>";
		echo "<th style='width:7%; text-align: center;' rowspan = 2 colspan = 3 align = center><font color='white'> Acci&oacute;n </font></th>";

		echo "<tr bgcolor='#43bced' style='color: #fff;'>";
		echo "<th style='text-align: center;' width='100'>RRHH</td>";
		echo "<th style='text-align: center;' width='100'>SERV. MEDICO</td>";
		echo "<th style='text-align: center;' width='100'>Nomina</td>";
		echo "<th style='text-align: center;' width='100'>Contab</td>";
		echo "</tr>";

		$sum_vaca_ot = 0;
		for ($cont = 0; $cont < $num_rows; $cont++) {
			$row = mysqli_fetch_array($resultado);
			//sumatoria de vacaciones otorgadas
			$sum_vaca_ot += $row['dvac'];
			$cedula = $row['cedula'];
			if ($color) {
				$tcolor = "#dfdfd0";
			} else {
				$tcolor = "white";
			}
			echo '<tr bgcolor=' . $tcolor . ' >';
			echo "<td width='100'>" . $row['periodo'] . "</td>";
			echo "<td width='20'>" . $row['dvac'] . "</td>";
			echo "<td width='20'>" . $row['dias_ext'] . "</td>";
			echo "<td width='20'>" . $row['dbon'] . "</td>";
			//echo "<td width='100'>".$row['tip']."</td>";
			echo "<td width='100'>" . mostrar_fecha($row['fdesde']) . "</td>";
			echo "<td width='100'>" . mostrar_fecha($row['fhasta']) . "</td>";
			echo "<td width='100'>" . mostrar_fecha($row['reintegro']) . "</td>";
			echo "<td width='50' align='center'>" . number_format($row['antiguedad'], 0) . "</td>";
			//echo "<td width='100' align='center'>".number_format($row['imes'],0)."</td>";
			echo "<td width='100' align='right'>" . number_format($row['sueldo'], 2) . "</td>";

			//RRHH
			echo "<td width='30' align='center'>";
			if ($row['aprobacion_rrhh'] == 'Aprobado') {
				echo "<img src='img2/status_ver.png'>";
			}
			echo "</td>";

			//SERVICIO MEDICO
			echo "<td width='30' align='center'>";
			if ($row['aprobacion_medico'] == 'Aprobado') {
			echo "<img src='img2/status_ver.png'>";
			}
			echo "</td>";

			//NOMINA
			echo "<td width='30' align='center'>";
			if ($row['aprobacion_nomina'] == 'Aprobado') {
				echo "<img src='img2/status_ver.png'>";
			}
			echo "</td>";

			//CONTABILIDAD
			echo "<td width='30' align='center'>";
			if ($row['aprobacion_contabilidad'] == 'Aprobado') {
				echo "<img src='img2/status_ver.png'>";
			}
			echo "</td>";
			if (substr($_SESSION['acceso_validar'], 18, 1) == '1') {
				echo "<td width='30' align='center'><a onclick='return validar_elimina()' href='" . $_SERVER['PHP_SELF'] . "?accion=2&cedula=" . $cedula . "&periodo=" . $row['periodo'] . "&fdesde=" . $row['fdesde'] . "'><img  border = 0  src='img2/borrar.png'alt='eliminar éste registro' ></a></td>";
			}

			echo "<td width='30' align='center'><a target='_blank' href='calculo_vacaciones_recibo.php?periodo=" . $row['periodo'] . "&fdesde=" . $row['fdesde'] . "&cedula=" . $cedula . "'><img border = 0 src='img2/icono_imprimo.png' alt='Imprimir éste registro'></a></td>";



			echo '</tr>';
			$color = !$color;
		}
		////////////////////////////////////////////

		//Variables para días de vacaciones pendientes


		/*
			Calc days between two dates using the financial calendar
			30/360 (usa) or 30E/360(european)<-default
			$fec1 and $fecha2 in format: aaaa-mm-dd
			return days  or -1 in case of error.

			based on cost_analysis.py module Ver. 0.1 public domain, no license required by Harm Kirchhoff
			*/


		///////////////////////////////////////////////// oculto hasta lanzar actualización V 4.5


		function days_360($fec1, $fec2, $europeo = true)
		{
			//try switch dates: min to max
			if ($fec1 > $fec2) {
				$temf = $fec1;
				$fec1 = $fec2;
				$fec2 = $temf;
			}

			// get day month year...
			list($yy1, $mm1, $dd1) = explode('-', $fec1);
			list($yy2, $mm2, $dd2) = explode('-', $fec2);

			if ($dd1 == 31) {
				$dd1 = 30;
			}

			//checks according standars: 30E/360 or 30/360.
			if (!$europeo) {
				if (($dd1 == 30) and ($dd2 == 31)) {
					$dd2 = 30;
				} else {
					if ($dd2 == 31) {
						$dd2 = 30;
					}
				}
			}

			//check for invalid date
			if (($dd1 < 1) or ($dd2 < 1) or ($dd1 > 30) or ($dd2 > 31) or
				($mm1 < 1) or ($mm2 < 1) or ($mm1 > 12) or ($mm2 > 12) or
				($yy1 > $yy2)
			) {
				return (-1);
			}
			if (($yy1 == $yy2) and ($mm1 > $mm2)) {
				return (-1);
			}
			if (($yy1 == $yy2) and ($mm1 == $mm2) and ($dd1 > $dd2)) {
				return (-1);
			}

			//Calc
			$yy = $yy2 - $yy1;
			$mm = $mm2 - $mm1;
			$dd = $dd2 - $dd1;

			return (($yy * 360) + ($mm * 30) + $dd);
		}
		$fec1 = date("Y-m-d");
		$fec2 = date('Y-m-d', mktime(0, 0, 0, $mes3, $dia3, $ano3));
		$tdias = days_360($fec1, $fec2) + 1;
		$antiguedad_dias = number_format(($tdias), 0, '.', '');
		$antiguedad_mese_enteros = number_format(($antiguedad_dias / 30), 2);
		$dias_vacaciones_total = $antiguedad_mese_enteros * 15 / 12;
		$cant_vaca_favor = $dias_vacaciones_total - $sum_vaca_ot;
		$dias_disponibles_vac = (intval($dias_vacaciones_total / 15) * 15) - $sum_vaca_ot;


		echo "<td></td>";


		//ELIMINAR LOS COMENTADO SI SE QUIEREN MOSTRAR ESTOS DATOS // Miguelangel

		/*
			echo "<tr><td></td>";
			//echo $fec1;
			echo "</br>";
			//echo $fec2;
			echo "<td colspan=2 bgcolor='white'><font color='black'>Total d&iacute;as acumulados vacaciones al " .date('d-m-Y')." </font></td>";
			echo "<td bgcolor='white'><font color='black'>".number_format($antiguedad_mese_enteros,0)." </font></td>";
			echo "</tr>";

				echo"<td></td>";

			echo "<tr><td></td>";
			echo "<td colspan=2 bgcolor='white'><font color='black'>Total d&iacute;as vacaciones otorgados</font></td>";
			echo "<td bgcolor='white'><font color='black'>".number_format($dvac,0)." </font></td>";
			echo "</tr>";

				echo"<td></td>";

			*/

		///////////////////////////////////////////////// oculto hasta lanzar actualización V 4.5


		//echo "<tr><td></td>";
		//echo "<td colspan=3 bgcolor='#dfdfd0'><font color='black'>D&iacute;as pagados/disfrutados:</font></td>";
		//echo "<td bgcolor='#dfdfd0'><font color='black'>" . number_format($sum_vaca_ot, 2) . " </font></td>";
		//echo "</tr>";

		//echo "<tr><td></td>";
		//echo "<td colspan=3 bgcolor='white'><font color='black'>Fracci&oacute;n D&iacute;as &Uacute;ltimo a&ntilde;o:</font></td>";
		//echo "<td bgcolor='white'><font color='black'>" . number_format($dias_vacaciones_total - $sum_vaca_ot, 2) . " </font></td>";
		//echo "</tr>";


		//echo "<td></td>";


		//echo "<tr><td></td>";
		//echo "<td colspan=3 bgcolor='#43bced'><font color='black'>D&iacute;as disponibles vacaciones al " . date('d-m-Y') . " </font></td>";

		/*
		if ($dias_disponibles_vac > 0) {
			echo "<td bgcolor='#C1F592'><font color='black'>" . number_format($dias_disponibles_vac, 0) . " </font></td>";
		} else
			echo "<td bgcolor='red'><font color='white'>" . number_format($dias_disponibles_vac, 0) . " </font></td>";

		echo "</tr>";
		*/


		/////////////////////////////////////////
		echo '</table>';
		//} else echo "<hr>";
		mysqli_free_result($resultado);
	}
}


echo "<br><br><br><br></body>";
?>


<style>
	.boton {
    border-radius: 8px;      /* Bordes redondeados */
    padding: 8px 16px;       /* Más espacio interno */
    border: none;            /* Quita el borde feo por defecto */
    cursor: pointer;         /* Mano al pasar */
    transition: 0.2s ease;   /* Animación suave */
	}

	.boton:hover {
	transform: scale(1.03);  /* Efecto sutil al pasar el mouse */
	}
	
	.boton {
		/* width: 100%; */
		color: #FFFFFF;
		/* font-size: 0.8725em; */
		padding: 7px;
		margin-bottom: 5px;
		margin-top: 6px;
		outline: none;
		/* margin: 5px 0; */
		font-family: 'Open Sans', sans-serif;
		font-size: 16px;
		font-weight: bold;
		text-transform: uppercase;
		background: #36C1E2;
		border: 0px solid #DFDFDF;
	}

	.label_status_aprobar {
		background-color: #36C1E2 !important;
		color: #fff;
		display: inline;
		padding: .2em .6em .3em;
		font-size: 90%;
		font-weight: 700;
		line-height: 1;
		text-align: center;
		white-space: nowrap;
		vertical-align: baseline;
	}

	#response_sucess {
		background: #7dbe2c;
		padding: 10px;
		width: auto;
		color: #fff;
		text-align: left;
		line-height: 25px;
	}
</style>

<script>
	setTimeout(function() {
		$('#response_sucess').fadeOut('slow');
	}, 1000);
</script>

<?
echo "</html>";
mysqli_close($enlace);
?>
