<? session_start();
//RESTRICCIÓN 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"]==''?$_POST["cedula"]:$_REQUEST["cedula"]);
$curso=$_REQUEST["curso"];
$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();
echo '<script language="JavaScript" type="text/javascript" src="ajax.js"></script>';
set_time_limit(3000); 

///////////////////////////////////////////////// ELIMINAR LIQUIDACION ////////////////////////////////////////////////////////////////
if ($accion==2) {
		$consulta="delete from liquidaciones where id='".$_SESSION['id_validar']."' and cedula= '".$cedula."' ";
		$resultado = mysqli_query($enlace,$consulta) or die($consulta . mysqli_error($enlace));
}	

/////////////////////////////////////////////////GRABAR DATOS INICIALES ////////////////////////////////////////////////////////////////
if ( $_POST['grabar']==1){
	//if ($_POST['egreso']=='') $mensaje = "Debe ingresar una Fecha de Egreso Valido.....";
	 
		$fec1 = crear_fecha( unir_fecha(fecha_mysql($_POST['fechai'])) );
		$fec2 = crear_fecha( unir_fecha(fecha_mysql($_POST['fechae'])) );
		$fec3 = crear_fecha($_POST['fecha_pago']); //Fecha de pago
		if ($_POST['semana']=='') {
			$dias=$_POST['dias'];
			if ($dias>1 && $dias<=7) $semana=1;
			if ($dias>7) $semana=2;		
		} else $semana=$_POST['semana'];
		if ($_POST['ncon1']=='') $_POST['ncon1']=0; 	
		if ($_POST['ncon2']=='') $_POST['ncon2']=0;
	///////////////// calculo dias de vacaciones 
	$consultaxx=mysqli_query($enlace,"select * from empresa where id='".$_SESSION['id_validar']."' ");
	$rowxx=mysqli_fetch_array($consultaxx);
	
		//=======Dias vacaciones vencidas a pagar
	$dvac=$rowxx['dvac'];
	$dbon=$rowxx['dbon'];
	
		$a=mostrar_antiguedad(1,$fec1,$fec2);
		$diasvac = $dvac + ($a-1<=0?0:$a-1);
		$diasbon = $dbon + ($a-1<=0?0:$a-1);
		
	$dias_vac_venc = $_POST['vacacion']*$diasvac;
	$valor_vaca_venc = $_POST['vacacion']*$diasvac/30*$_POST['smes'];
	$dias_bonovac_venc = $_POST['vacacion']*$diasbon;
	$valor_bonovac_venc = $dias_bonovac_venc/30*$_POST['smes'];
	
	//=====================================
	
				//=======Dias vacaciones fraccionadas a pagar
	$b=mostrar_antiguedad(1,$fec1,$fec2);
	$mesvacacion = mostrar_antiguedad(2,$fec1,$fec2);
	$diasVac = $dvac + ($b<=0?0:$b);
	$diasBon = $dbon + ($b<=0?0:$b);
	$diasVacFracc = number_format($diasVac/12*$mesvacacion,2);
	$diasBonFracc = number_format($diasBon/12*$mesvacacion,2);
	
	$valor_dias_vac_fraccion = $diasVacFracc/30*$_POST['smes'];
	$valor_bonovac_fraccion = $diasBonFracc/30*$_POST['smes'];
	//========= Retenciones 
	$porcentajeFaov=0.01;
	$faov = $_POST['dias']/30*$_POST['smes']*$porcentajeFaov;
	$islr = $_POST['islr'];
	$retenislr = $_POST['dias']*$_POST['smes']/30*$islr/100;
	$sso = $_POST['smes']*12/52*0.04*$semana;
	$rpe = $_POST['smes']*12/52*0.005*$semana;
	$inces = $_POST['valordutipagar']*0.005;
	
	//=========Dias a pagar
	$valorDiasPagar = $_POST['dias']/30*$_POST['smes'];
	
	//Cestaticket a pagar
	$valorDiaCestatic = $_POST['valor_dia_cestatic']*$_POST['diast'];
	
	//Dias pagados a descontar
	$valor_dpnlabor = $_POST['dpnl']/30*$_POST['smes'];
	
	//================================================
		$consultax="select * from liquidaciones where cedula='".$cedula."' and id='".$_SESSION['id_validar']."' ";
		$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
		if (mysqli_num_rows($resultadox)==0) {
			
			//Traigo los nombres y apellidos para insertarlos en la tabla "Liquidacion"
			
			
			$consulta_nombres="select * from personal where id='".$_SESSION['id_validar']."' and codigo='".$cedula."' ";
			$resultado_nombres = mysqli_query($enlace,$consulta_nombres) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
			$row=mysqli_fetch_array($resultado_nombres);
			$nombres=$row['nombres'];
			$nombres1=$row['nombres1'];
			$apellidos=$row['apellidos'];
			$apellidos1=$row['apellidos1'];
			
			$consultax="insert into liquidaciones (id,cedula,nombres,nombres1,apellidos,apellidos1,fechai,egreso,fecha_pago,tipoe,tipo_salario,sueldo_liq,dias,valor_dias_pagar,valor_dia_cestatic,diast,valor_ct_total,vacacion,dias_vac_venc,valor_vaca_venc,dias_bonovac_venc,valor_bonovac_venc,dias_vac_fraccion,valor_dias_vac_fraccion,dias_bonovac_fraccion,valor_bonovac_fraccion,ccon01,ncon01,dias_util_pagar,valor_utilid_pagar,semana,valor_sso,valor_rpe,faov,islr,valor_islr,dpnl,valor_dpnlabor,inces,fideicomiso,adeuti,adevac,ccon02,ncon02,icon)";
			
			$consultax .="values ('".$_SESSION['id_validar']."','".$cedula."','".$nombres."','".$nombres1."','".$apellidos."','".$apellidos1."','".$fec1."','".$fec2."','".$fec3."','".$_POST['tipoe']."','".$_POST['sector']."','".$_POST['smes']."','".$_POST['dias']."','".$valorDiasPagar."','".$_POST['valor_dia_cestatic']."','".$_POST['diast']."','".$valorDiaCestatic."','".$_POST['vacacion']."','".$dias_vac_venc."','".$valor_vaca_venc."','".$dias_bonovac_venc."','".$valor_bonovac_venc."','".number_format($diasVacFracc,2,'.','')."','".$valor_dias_vac_fraccion."','".$diasBonFracc."','".$valor_bonovac_fraccion."','".$_POST['ccon01']."','".$_POST['ncon01']."','".$_POST['dutipagar']."','".$_POST['valordutipagar']."','".$semana."','".$sso."','".$rpe."','".$faov."','".$islr."','".$retenislr."','".$_POST['dpnl']."','".$valor_dpnlabor."','".$inces."','".$_POST['fideicomiso']."','".$_POST['adeuti']."','".$_POST['adevac']."','".$_POST['ccon02']."','".$_POST['ncon02']."','".$_POST['icon']."') ";
			$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
	
		} else {
			$consultax="update liquidaciones set fechai='".$fec1."',egreso='".$fec2."',fecha_pago='".$fec3."',tipoe='".$_POST['tipoe']."',tipo_salario='".$_POST['sector']."',sueldo_liq='".$_POST['smes']."',dias='".$_POST['dias']."',valor_dias_pagar='".$valorDiasPagar."', valor_dia_cestatic='".$_POST['valor_dia_cestatic']."', diast='".$_POST['diast']."',valor_ct_total='".$valorDiaCestatic."',vacacion='".$_POST['vacacion']."',dias_vac_venc='".$dias_vac_venc."',valor_vaca_venc='".$valor_vaca_venc."', dias_bonovac_venc='".$dias_bonovac_venc."',valor_bonovac_venc='".$valor_bonovac_venc."', dias_vac_fraccion='".number_format($diasVacFracc,2)."',valor_dias_vac_fraccion='".$diasVacFracc/30*$_POST['smes']."', dias_bonovac_fraccion='".$diasBonFracc."',valor_bonovac_fraccion='".$valor_bonovac_fraccion."',ccon01='".$_POST['ccon01']."',ncon01='".$_POST['ncon01']."',dias_util_pagar='".$_POST['dutipagar']."',valor_utilid_pagar='".$_POST['valordutipagar']."',semana='".$semana."',valor_sso='".$sso."',valor_rpe='".$rpe."',faov='".$faov."',islr='".$islr."',valor_islr='".$retenislr."',dpnl='".$_POST['dpnl']."',valor_dpnlabor='".$valor_dpnlabor."',fideicomiso='".$_POST['fideicomiso']."',adeuti='".$_POST['adeuti']."',adevac='".$_POST['adevac']."',ccon02='".$_POST['ccon02']."',ncon02='".$_POST['ncon02']."',icon='".$_POST['icon']."' where id='".$_SESSION['id_validar']."' and cedula='".$cedula."'  ";
			$resultadox = mysqli_query($enlace,$consultax) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
		}	
		
}

/////////////////////////////////////////////////MOSTRAR SOLICITUD DEL TRABAJADOR ////////////////////////////////////////////////////////////////
if ( (!$_POST && $accion!=1 && $_POST['grabar']!=1) || $_POST['busca']==1){
	echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='img2/icono_01.png' alt='Seleccionar'>&nbsp;Seleccionar Trabajador";
	echo "<hr><h2>Actualizaci&oacute;n de Prestaciones Sociales LOTTT</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 = 'fechae'> Fecha Egreso";
	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' 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'] == "fechae") $query2 = " order by fechae DESC";
	else if ($_POST['orden'] == "ced") $query2 = " order by codigo";
	else if ($_POST['orden'] == "ape") $query2 = " order by apellidos";
	else if ($_POST['orden'] == "nom") $query2 = " order by nombres";

	else $query2 = " order by fechae DESC"; 

		
	if ($_SESSION['modo_validar']==1)$consulta="select * from personal as p join liquidaciones as l on l.cedula=p.codigo where p.status='A' and p.id='".$_SESSION['id_validar']."' ".$query1.$query2;
	else $consulta="SELECT
   	p.codigo,
    p.nombres,
    p.nombres1,
    p.apellidos,
    p.apellidos1,
    p.clave,
    p.dir,
    p.telefono,
    p.sexo,
    p.hijo,
    p.gsanguineo,
    p.gerencia,
    p.empresa,
    p.cargo,
    p.unidad,
    p.nomina,
    p.turno,
    p.banco,
    p.fechan,
    p.fechai,
    p.fechae,
    p.fechac,
    p.cuenta,
    p.mensaje,
    p.sdia,
    p.smes,
    p.division,
    p.sector,
    p.estado,
    p.pago,
    p.parroquia,
    p.nacionalidad,
    p.municipio,
    p.area,
    p.edocivil,
    p.tipo,
    p.profesion,
    p.direccion,
    p.sso,
    p.status,
    p.fechalic,
    p.fechacar,
    p.fechasal,
    p.fechaman,
    p.pasaporte,
    p.pais,
    p.contrato,
    p.nrocontrato,
    p.id,
    p.justicontrato,
    l.estado_liquidacion
    from personal as p 
    LEFT JOIN liquidaciones as l on l.cedula=p.codigo
    WHERE p.status='I' and p.id='".$_SESSION['id_validar']."' ".$query1.$query2;
	$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 rules=none border=0 cellpadding=2 cellspacing=0 align='center'>";
			echo "<tr bgcolor='#43bced' height='35'>";
			echo "<th align = center><font color='white'> Foto </font></th>";
			echo "<th align = left><font color='white'> C&eacute;dula </font></th>";
			echo "<th align = left><font color='white'> Nombres </font></th>";
			echo "<th align = left><font color='white'> Apellidos </font></th>";
			echo "<th align = center><font color='white'> Status </font></th>";
			echo "<th align = center><font color='white'> Fec. Ingreso </font></th>";
			echo "<th align = left><font color='white'> Fec. Retiro </font></th>";
			echo "<th align = center><font color='white'> Status Liquidac. </font></th>";
			
			echo "<th align = center><font color='white'> Acci&oacute;n </font></th>";

			for ($cont=0;$cont<$num_rows;$cont++) {
				$row = mysqli_fetch_array($resultado);
				$cedula = $row['codigo'];
				if ($color) {
					$tcolor="#dfdfd0";
					if (file_exists('fotos/'.$cedula.'.jpg')) $imagen='fotos/'.$cedula.'.jpg';
					else $imagen = 'img2/nohay2.jpg';
				} else { 
					$tcolor="white";
					if (file_exists('fotos/'.$cedula.'.jpg')) $imagen='fotos/'.$cedula.'.jpg';
					else $imagen = 'img2/nohay.jpg';
				}	
				echo '<tr bgcolor='.$tcolor.' >';
				echo "<td align'center'><img src='".$imagen."' height='64' width='64'></td>";
				echo "<td width='100'><a href='".$_SERVER['PHP_SELF']."?accion=1&cedula=".$cedula."'>".$row['codigo']."</a></td>";
				echo "<td width='250'>".trim($row['nombres'])." ".$row['nombres1']."</td>";
				echo "<td width='250'>".trim($row['apellidos'])." ".$row['apellidos1']."</td>";
				echo "<td width='50' align='center'>".($row['status']=='A'?'<img src="img2/status_ver.png">':'<img src="img2/status_fal.png">')."</td>";
				echo "<td width='120' align=center>".mostrar_fecha($row['fechai'])."</td>";
				echo "<td width='120' align=center>".mostrar_fecha($row['fechae'])."</td>";
				echo "<td width='80' align=center>";	
			   
			   	if (($row['estado_liquidacion']=="Procesado")||($row['estado_liquidacion']=="procesado"))
				{
				    $row['estado_liquidacion']="Procesado"; 
				    echo "<span style=\"background-color:green; color:white;\">".stripslashes($row['estado_liquidacion'])."</span>";
				}
				elseif(!$row['estado_liquidacion'])
				{
				$row['estado_liquidacion']="Sin procesar";
				echo "<span style=\"background-color:red;\">".stripslashes($row['estado_liquidacion'])."</span>";
				}
				else
				{
				$row['estado_liquidacion']="Sin procesar";
				echo "<span style=\"background-color:red;\">".stripslashes($row['estado_liquidacion'])."</span>";
				}
				
				echo "</td>";
				
				echo "<td width='30' align='center'><a href='".$_SERVER['PHP_SELF']."?accion=1&cedula=".$cedula."'><img border = 0 src='img2/icono_01.png' alt='Seleccionar éste registro'></a></td>";
				
				echo '</tr>';
				$color=!$color;
			}
			echo '</table>';
	} else echo "<hr>"; 		
	mysqli_free_result($resultado);
}	

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

	//============ datos de empresa
	$consulta=mysqli_query($enlace,"select * from empresa where id='".$_SESSION['id_validar']."' ");
	$row=mysqli_fetch_array($consulta);
	$con01=$row['constante01'];
	$con02=$row['constante02'];
	$con03=$row['constante03'];
	$con04=$row['constante04'];
	$icomi=$row['comision'];
	$valor_actual_cestatic=$row['ticket'];
	$duti_empresa=$row['duti'];


	//========================================= datos personales ========================================================///
	$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));
	$row=mysqli_fetch_array($resultado);
		$nombres=$row['nombres'];
		$nombres1=$row['nombres1'];
		$apellidos=$row['apellidos'];
		$apellidos1=$row['apellidos1'];
		
		$fecha1=$row['fechai'];
		$fecha2=$row['fechae'];
		$sector=$row['sector'];
			//=============================== UTILIDADES 
	//=============================== UTILIDADES 
	$hoy=substr($fecha2,0,4).'-01-01';
	if ($fecha1>$hoy) $hoy = $fecha1;
	
	$mesutilidad = mostrar_antiguedad(2,$hoy, $fecha2);
	$dias_util_pagar = $duti_empresa/12*$mesutilidad;
		/*Se puede eliminar lo comentado, se imprimió para hacer pruebas de verificacion-Miguelangel
	echo $fecha1;
	echo "<br>";
	echo $fecha2;
	echo "<br>";
	echo $hoy;
	echo "<br>";
	echo $mesutilidad;
	echo "<br>";
	echo $dias_util_pagar;
		*/
	//====================== buscar tipo de nomina	
	$tipo=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)) $tipo=$row1['tipo'];
	if ($tipo==1) $multiplo=24;
		else if ($tipo==2) $multiplo=6;
			else $multiplo=6;
	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 ($tipo==1) $mon01=$rowx['monto']/7*30;
			else if ($tipo==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 ($tipo==1) $mon02=$rowx['monto']/7*30;
			else if ($tipo==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;
			$consultax="select monto from historico where id='".$_SESSION['id_validar']."' and (substring(concepto,1,2) like '10%' OR substring(concepto,1,1)='7') and cedula='".$cedula."' and nomina='".$row['nomina']."' order by xxx desc limit ".$multiplo;
			$consultax="select sum(monto) as monto from historico where id='".$_SESSION['id_validar']."' and ((concepto between '1005' and '1999') OR substring(concepto,1,1)='7') 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 ++;
				//echo $rowx['monto']."</br>";
			}
			
			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($row['fechae'], 0, -2)."01' group by fec order by xxx desc limit ".$multiplo.") as prueba";
			//echo $consultax;
			$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)) {
				$mon03 =$rowx['monto'];	
			}
			$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($row['fechae'], 0, -2)."01' group by fec order by xxx desc limit 1) as prueba";
			//echo $consultax;
			$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)) {
				$mon04 =$rowx['monto'];	
			}
			
	//}	
	
	/*
	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;
			}	
	}	
	*/
	if($row['sector']!='1000'&&$row['sector']!='') {
	$consultax="select SUM(monto) AS valor from historico where tipo='A' and id='".$_SESSION['id_validar']."' 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['valor'];	
				$cpaty ++;
	  }
	 $mon04= $mpaty / $cpaty;
	 	$smes=$row['smes'];
	}
		///Defino el salario que se va a tomar para la liquidacion
	
	$sueldo_liq_antes=0;
	
	if($mon03<$row['smes'])
		{
		$sueldo_liq_antes=$row['smes'];
		}
	else 
		$sueldo_liq_antes=$mon03;
	//$mon03<$row['smes']?$row['smes']:$mon03 se puede quitar
	
	$noentro=0;
	$consultax="select * from liquidaciones where id='".$_SESSION['id_validar']."' and cedula='".$cedula."' ";
	$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);
		$semana=0;
		$sueldo_liq = $rowx['sueldo_liq'];
		$valor_dia_cestatic = $rowx['valor_dia_cestatic'];
		$status_liq = $rowx['estado_liquidacion'];
	} else $noentro=1;
	
	echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='images/b_regresa.png' alt='Regresar'>:<a href='".$_SERVER['PHP_SELF']."'>Regresar</a>";
	echo "&nbsp;&nbsp;<img border = 0 src='img2/icono_07.png' alt='Eliminar'>:Eliminar Liquidaci&oacute;n</a>";
	echo "&nbsp;&nbsp;<a target='_blank' href='prestaciones_informe_imprimir.php?accion=".($noentro==0?1:2)."&cedula=".$cedula."'><img border = 0 src='img2/archivo.png' alt='Informe'>&nbsp;Informe de liquidaciones Sociales</a>";
	
	/*
	echo "<hr><h1><font color=#DD0044>Por favor espere, estamos trabajando en este modulo para instalar actualizaciones. Disculpe las molestias </font></h1>";	
	*/

	echo "<hr><h2><font color=#DD0044>C&aacute;lculo de Liquidaciones de por retiro de trabajador </font></h2>";	
	
	echo "</br></br>";
	

	echo "<h4> DATOS DEL TRABAJADOR </h4>";	

	
	if (file_exists('fotos/'.$cedula.'.jpg')) $imagen='fotos/'.$cedula.'.jpg';
	else $imagen = 'img2/nohay2.jpg';			
	echo "<center><img style='border-width: 1px; border-color: 75263C;border-style: solid;' src='".$imagen."' height='30' width='30'>&nbsp;<font color=black size=5>&nbsp;".trim($row['nombres'])." ".trim($row['nombres1']).' '.trim($row['apellidos'])." ".trim($row['apellidos1'])."</font></center>";
	echo "<center> <font color=black size=4>C.I.: ".$cedula."</font></center>";
	
	If ($status_liq=="procesado"){
	echo "<center> <font color=black size=4>Estatus de liquidaci&oacute;n: <font color=blue>".$status_liq."</font></center>";
	}
	else 
		echo "<center> <font color=black size=4>Estatus de liquidaci&oacute;n: <font color=red>Sin Procesar</font></center>";

	
	//=================================================================================================///
	if ($noentro==0) {	 
		echo "<br><table border=0 cellpadding=0 cellspacing=0 width='700' align=center style='border-width: 0px; border-color: 75263C;border-style: solid;'>";	
		?>
		<tr bgcolor='#43bced'>
			<td width='300' align=left><a target='_blank' style='color:black;text-decoration:none' href='prestaciones_calcular.php?cedula=<?echo $cedula;?>'>
				&nbsp;<img src='img2/calcular.png'>&nbsp;&nbsp;<font size=4>Mostrar Liquidaci&oacute;n</a></font></td>
				
			<td width='300' align=right><a target='_blank' style='color:black;text-decoration:none' href='prestaciones_imprimir.php?cedula=<?echo $cedula;?>'>
				<font size=4 >Imprimir Liquidaci&oacute;n&nbsp;<img src='img2/icono_02.png'>&nbsp;</a></font></td>
				<?
				if (substr($_SESSION['acceso_validar'],18,1)=='1')
				echo "<td width='100' align='center'><a onclick='return validar_elimina()' href='".$_SERVER['PHP_SELF']."?accion=2&cedula=".$cedula."'><img  border = 0  src='img2/icono_07.png'alt='eliminar éste registro' ></a></td>";
				?>				
		</tr>
		<?			
		echo "</table>";
	}
	
	echo "<form name = 'entrada' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data'>";
	echo "<input type = 'hidden' name = 'grabar' value = '1'>";
	echo "<input type = 'hidden' name = 'cedula' value = '".$cedula."'>";
	

	//COMIENZO DE TODA LA TABLA
						echo "<td width = '200' align = 'center' > <h4>DATOS B&Aacute;SICOS</h4></td>";

	echo "<div style='display: inline-flex; width: 50%;'>";
	
			 ////////////columna 1

		echo "<table rules border=2 cellpadding=2 cellspacing=0 align='center' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";

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

		echo "<tr>";

			echo "<td width = '100' align = 'right' > Fecha/Retiro: </td>";
			echo "<td width = '200' align = 'left' ><input type = 'text' name = 'fechae' size = '10' maxlength = '50' value = '".mostrar_fecha($row['fechae'])."' readonly></td>";

		echo "</tr>";
		echo "<tr>";
			$fec1=$row['fechai'];
			$fec2=$row['fechae'];	
				$cdias  = calcular_dias($fec1,$fec2);
				$tdias  = calcular_dias($fec1,$fec2);
				$cmeses =0;
				$canos  =0;
				if ($cdias>=30) {
					$cmeses = ($cdias - ($cdias % 30>0 ? $cdias % 30 : 0) ) / 30;
					$cdias = $cdias - ($cmeses * 30); 
					
					if ($cmeses>=12) {
						$canos = ($cmeses - ($cmeses % 12>0 ? $cmeses % 12 : 0) ) / 12;
						$cmeses = $cmeses - ($canos * 12); 
					}		
				}
				$antiguedad  =(mostrar_antiguedad(1,$fec1,$fec2))." Años, ";
	            $antiguedad .=(mostrar_antiguedad(2,$fec1,$fec2))." Meses, ";
	            $antiguedad .=(mostrar_antiguedad(3,$fec1,$fec2))." Días ";
				//$prueba=calculodiasNueva($fec1,$fec2);
				//$antiguedad ="($tdias Dias)-> ".($canos==0?'':"$canos Año(s), "). ($cmeses==0?'':"$cmeses Mes(es), "). ($cdias==0?'':"$cdias Día{s} ");
				//print_r($prueba);
			
			echo "<td width = '100' align = 'right' > &nbsp;Antiguedad:&nbsp: </td>";

			echo "<td>".utf8_encode($antiguedad)."</td>";				
		echo "</tr>";
		
		echo "<tr>";
					echo "<td width = '100' align = 'right' > Tipo de Salario: </td>";

		echo "<td width = '200' align = 'left' ><input type = 'text' name = 'sector' size = '10' maxlength = '50' value = '".($row['sector']=='2000'?'VARIABLE':'FIJO')."' readonly></td>";
		echo "</tr>";
		
		echo "</table>";
	echo "</div>";
	
		   ////////////columna 2
		   
	echo "<div style='display: inline-flex; width: 50%;'>";
		echo "<table rules border=2 cellpadding=2 cellspacing=0 align='left' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";

		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=blue> Sueldo B&aacute;sico Mensual: </font></td>";
			echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'smesx' size = '10' maxlength = '50' value = '".($row['smes'])."' ></td>";
		echo "</tr>";
		
		//echo "<tr>";
			//echo "<td  width = '200' align = 'right' > <font color= blue>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= blue>Salario Promedio Mensual: </font></td>";
			echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'smesx' size = '10' maxlength = '50' value = '".($row['sector']=='2000'?number_format(($mon03),2,'.',''):$mon04)."' ></td>";
		echo "</tr>";
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color= blue>Salario Mensual para prestaciones: </font></td>";
			
			if($noentro==0) /////////CONDICION PARA TRAER SALARIO CUANDO YA ESTA GUARDADO-Miguelangel

			{
				
				echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'smes' size = '10' maxlength = '50' value = '".$sueldo_liq."' ></td>";
			}
			else{
					//////////////Condiciones para calcular el salario promedio si es Sarario VARIABLE o si es FIJO
			if($row['sector']=='2000')
				{
				echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'smes' size = '10' maxlength = '50' value = '".$sueldo_liq_antes."' ></td>";
				}
				elseif($row['sector']=='1000' & $mon04>=$row['smes'])
				{
				echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'smes' size = '10' maxlength = '50' value = '".$mon04."' ></td>";
				}
				elseif($row['sector']=='1000' & $mon04<$row['smes'])
				{
				echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'smes' size = '10' maxlength = '50' value = '".$row['smes']."' ></td>";
				}
				else 
				{
				echo "<td  width = '200' align = 'left' ><font color=red> DEBE ASIGNAR UN TIPO DE SALARIO DESDE LA FICHA DEL TRABAJADOR PARA CALCULAR LA LIQUIDACION</font></td>";
				}
			}
					///////////////////////////////////////////////////////////////////////
				
		echo "</tr>";
		
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color= blue>Valor diario Cestaticket: </font></td>";
			
			if($noentro==0) /////////CONDICION PARA TRAER EL VALOR DEL CESTATICKET CUANDO YA ESTA GUARDADO-Miguelangel
			{
				
			echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'valor_dia_cestatic' size = '10' maxlength = '50' value = '".$valor_dia_cestatic."' ></td>";
			}
			else{
			echo "<td  width = '200' align = 'left' > <input type = 'text' name = 'valor_dia_cestatic' size = '10' maxlength = '50' value = '".$valor_actual_cestatic."' readonly></td>";
			}
						////////////////////////////////////////////////////////////////////////////
		echo "</tr>";


		echo "</table>";
	echo "</div>";
	echo "</br></br>";
		//=========================================================================================================	

		echo "<div style='display: inline-flex; width: 50%;'>";
		echo "<table rules border=2 cellpadding=2 cellspacing=0 align='center' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";

		echo "<tr>";
			echo "<td width = '100' align = 'right'><font color=blue> Intereses/Prestaciones en Contabilidad? </font></td>";
			echo "<td width = '10' align = 'left' > 
			<select name = 'icon' >
				<option value='1' ".($rowx['icon']==0||$rowx['icon']==1?'selected':'').">SI 
				<option value='2' ".($rowx['icon']==2?'selected':'').">NO 
			</select></td>";
		echo "</tr>";
		
		echo "<tr>";
			echo "<td width = '100' align = 'right' > <font color=blue>Tipo de Egreso </font></td>";
			echo "<td width = '200' align = 'left' > <select name = 'tipoe'>
				<option value='0' ".($rowx['tipoe']==0?'selected':'').">Renuncia
				<option value='1' ".($rowx['tipoe']==1?'selected':'').">Renuncia Doble
				<option value='2' ".($rowx['tipoe']==2?'selected':'').">Finalizaci&oacute;n de Contrato
				<option value='3' ".($rowx['tipoe']==3?'selected':'').">Despido Justificado
				<option value='4' ".($rowx['tipoe']==4?'selected':'').">Despido Injustificado
				</select></td>";
		echo "</tr>";
		
		echo "</table>";

		echo "</div>";
		
		echo "<div style='display: inline-flex; width: 50%;'>";
		echo "<table rules border=2 cellpadding=2 cellspacing=0 align='left' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";
		
	
		echo "<tr>";
			echo "<td  width = '100' align = 'right' > <font color=blue>Fecha de Pago (ddmmaaaa): </font></td>";
			echo "<td  width = '200' align = 'left'>";
				$valor = (unir_fecha($rowx['fecha_pago'])=='00000000'?'':unir_fecha($rowx['fecha_pago']));//Fecha de pago
				escribe_formulario_fecha_modifica("fecha_pago","entrada",$valor);
			echo "</td>";
		echo "</tr>";
		
				/*
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=blue>Fecha de Egreso (ddmmaaaa): </font></td>";
			echo "<td  width = '400' align = 'left'>";
				$valor = (unir_fecha($rowx['egreso'])=='00000000'?unir_fecha($row['fechae']):unir_fecha($rowx['egreso']));
				escribe_formulario_fecha_modifica("egreso","entrada",$valor);
			echo "</td>";
		echo "</tr>";
		*/
		
		echo "</table>";

		echo "</div>";
		
		echo "<br><br><br>";

		//=======================================ASIGNACIONES A PAGAR===========================================
		//=======================================ASIGNACIONES A PAGAR===========================================
		//=======================================ASIGNACIONES A PAGAR===========================================		

		echo "<table rules border=2 cellpadding=2 cellspacing=0 align='center' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";



		echo "<tr>";
			echo "<td width = '200' align = 'right' > <h4>ASIGNACIONES</h4></td>";
		echo "</tr>";
		
		echo "<tr>";  /////////////////PERIODOS DE VACACIONES VENCIDOS
			echo "<td width = '100' align = 'right' > <font color= blue>Vacaciones Vencidas </font></td>";
			echo "<td width = '10' align = 'left' > <select name = 'vacacion'>
				<option ".($rowx['vacacion']==0?'selected':'').">0
				<option ".($rowx['vacacion']==1?'selected':'').">1
				<option ".($rowx['vacacion']==2?'selected':'').">2
				<option ".($rowx['vacacion']==3?'selected':'').">3
				<option ".($rowx['vacacion']==4?'selected':'').">4
				<option ".($rowx['vacacion']==5?'selected':'').">5
				
				</select><font color= blue><width=100>     Monto Vac. Venc(Bs) </font><input type = 'text' name = 'valor_vaca_venc' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_vaca_venc']:$diasvac)."' readonly></td>";
			
		echo "</tr>";
		
		
					/////////////////////////////////////////////////////////

		echo "<tr>";////////////DIAS DE SALARIO PENDIENTES A PAGAR EN LIQUIDACION
			echo "<td width = '100' align = 'right' > <font color= blue>D&iacute;as Pendientes a Pagar </font></td>";
			echo "<td width = '10' align = 'left' > <select name = 'dias'>
				<option ".($rowx['dias']==0?'selected':'').">0<option ".($rowx['dias']==1?'selected':'').">1<option ".($rowx['dias']==2?'selected':'').">2<option ".($rowx['dias']==3?'selected':'').">3
				<option ".($rowx['dias']==4?'selected':'').">4<option ".($rowx['dias']==5?'selected':'').">5<option ".($rowx['dias']==6?'selected':'').">6<option ".($rowx['dias']==7?'selected':'').">7
				<option ".($rowx['dias']==8?'selected':'').">8<option ".($rowx['dias']==9?'selected':'').">9<option ".($rowx['dias']==10?'selected':'').">10<option ".($rowx['dias']==11?'selected':'').">11
				<option ".($rowx['dias']==12?'selected':'').">12<option ".($rowx['dias']==13?'selected':'').">13<option ".($rowx['dias']==14?'selected':'').">14<option ".($rowx['dias']==15?'selected':'').">15
				<option ".($rowx['dias']==16?'selected':'').">16
				</select> <font color= blue><width=100>  Monto Dias pend.(Bs) </font><input type = 'text' name = 'valordiaspagar' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_dias_pagar']:($_POST['dias']))."' readonly></td>";
		echo "</tr>";
		
					//////////////////////////////////////////////////////////////////////
					
					######################################################################################
					
		echo "<tr>"; ////////////////DIAS DE CESTATICKET A PAGAR
			echo "<td width = '100' align = 'right' > <font color= blue>D&iacute;as Cesta Ticket a Pagar </font></td>";
			echo "<td width = '10' align = 'left' > <select name = 'diast'>
				<option ".($rowx['diast']==0?'selected':'').">0<option ".($rowx['diast']==1?'selected':'').">1
				<option ".($rowx['diast']==2?'selected':'').">2<option ".($rowx['diast']==3?'selected':'').">3
				<option ".($rowx['diast']==4?'selected':'').">4<option ".($rowx['diast']==5?'selected':'').">5
				<option ".($rowx['diast']==6?'selected':'').">6<option ".($rowx['diast']==7?'selected':'').">7
				<option ".($rowx['diast']==8?'selected':'').">8<option ".($rowx['diast']==9?'selected':'').">9
				<option ".($rowx['diast']==10?'selected':'').">10<option ".($rowx['diast']==11?'selected':'').">11
				<option ".($rowx['diast']==12?'selected':'').">12<option ".($rowx['diast']==13?'selected':'').">13
				<option ".($rowx['diast']==14?'selected':'').">14<option ".($rowx['diast']==15?'selected':'').">15
				<option ".($rowx['diast']==16?'selected':'').">16<option ".($rowx['diast']==17?'selected':'').">17
				<option ".($rowx['diast']==18?'selected':'').">18<option ".($rowx['diast']==19?'selected':'').">19
				<option ".($rowx['diast']==20?'selected':'').">20<option ".($rowx['diast']==21?'selected':'').">21
				<option ".($rowx['diast']==22?'selected':'').">22<option ".($rowx['diast']==23?'selected':'').">23
				<option ".($rowx['diast']==24?'selected':'').">24<option ".($rowx['diast']==25?'selected':'').">25
				<option ".($rowx['diast']==26?'selected':'').">26<option ".($rowx['diast']==27?'selected':'').">27
				<option ".($rowx['diast']==28?'selected':'').">28<option ".($rowx['diast']==29?'selected':'').">29
				<option ".($rowx['diast']==30?'selected':'').">30
				</select> <font color= blue><width=100>  Monto CT a pagar(Bs) </font> <input type = 'text' name = 'valorctpagar' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_ct_total']:($_POST['diast']))."' readonly></td>";
		echo "</tr>";		
		
		
		
		//////////////////////////////////////////////////////////////////////////////////////
		
			echo "<tr>"; ////Dias de utilidades a Pagar
			echo "<td width = '100' align = 'right' > <font color= blue>D&iacute;as Utilidades a Pagar </font></td>";
			echo "<td  width = '3' align = 'left' > <input type = 'text' name = 'dutipagar' size = '3' maxlength = '50' value = '".($noentro==0?$rowx['dias_util_pagar']:$dias_util_pagar)."' readonly><font color= blue>Valor Util a Pagar (Bs) </font> <input type = 'text' name = 'valordutipagar' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_utilid_pagar']:($dias_util_pagar*$sueldo_liq_antes/30))."' readonly></td>"; /////No eliminar esta vista, funciona el insert con este Post- Miguelangel 21-01-20
		echo "</tr>";
		
		////////////////////////////////////////////////////////////////////////////////////
		
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <input type='text' name='ccon01' size = '20' maxlength = '50' value='".($noentro==0?$rowx['ccon01']:'Otras Asignaciones')."'> </td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'ncon01' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['ncon01']:0)."' ></td>";
		echo "</tr>";


		
		echo "</table>";
		
		echo "<br><br>";
		//=========================================================================================================	
		//=======================================DEDUCCIONES A DESCONTAR===========================================
		//=======================================DEDUCCIONES A DESCONTAR===========================================
		//=======================================DEDUCCIONES A DESCONTAR===========================================

		
		echo "<table rules border=2 cellpadding=2 cellspacing=0 align='center' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";

		echo "<tr>";
			echo "<td width = '200' align = 'right' > <h4>DEDUCCIONES</h4></td>";
		echo "</tr>";
		
		echo "<tr>";
			echo "<td width = '200' align = 'right' > <font color=#DD0044>Nro. Semanas del SSO: </font> <select name = 'semana'>
				<option ".($rowx['semana']==0?'selected':'').">0<option ".($rowx['semana']==1?'selected':'').">1<option ".($rowx['semana']==2?'selected':'').">2<option ".($rowx['semana']==3?'selected':'').">3
				<option ".($rowx['semana']==4?'selected':'').">4<option ".($rowx['semana']==5?'selected':'').">5
				</select> </td>";
				echo "<td width=100>Monto SSO(Bs)<input type = 'text' name = 'rentensso' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_sso']:($_POST['semana']))."' readonly><br>Monto RPE(Bs)<input type = 'text' name = 'rentensso' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_rpe']:($_POST['semana']))."' readonly></td>";

				
		echo "</tr>";
		
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>% ISLR: </font></td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'islr' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['islr']:($_POST['islr']))."' >  Monto ISLR (Bs): <input type = 'text' name = 'rentenislr' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_islr']:($_POST['islr']))."' readonly></td>";
		echo "</tr>";
		
		if($noentro==0){
			echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>% FAOV: </font></td>";
			echo "<td  width = '400' align = 'left' >Monto FAOV (Bs) <input type = 'text' name = 'faov' size = '10' maxlength = '50' value = '".($rowx['faov'])."' ></td>";
		echo "</tr>";


		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>% INCES: </font></td>";
			echo "<td  width = '400' align = 'left' > Monto (Bs) <input type = 'text' name = 'inces' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['inces']:($_POST['inces']))."' readonly></td>";
		echo "</tr>";
		
		}
		
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>D&iacute;as pagados no laborados: </font></td>";
			echo "<td width = '400' align = 'left' > <select name = 'dpnl'>
				<option ".($rowx['dpnl']==0?'selected':'').">0<option ".($rowx['dpnl']==1?'selected':'').">1<option ".($rowx['dpnl']==2?'selected':'').">2<option ".($rowx['dpnl']==3?'selected':'').">3
				<option ".($rowx['dpnl']==4?'selected':'').">4<option ".($rowx['dpnl']==5?'selected':'').">5<option ".($rowx['dpnl']==6?'selected':'').">6<option ".($rowx['dpnl']==7?'selected':'').">7
				<option ".($rowx['dpnl']==8?'selected':'').">8<option ".($rowx['dpnl']==9?'selected':'').">9<option ".($rowx['dpnl']==10?'selected':'').">10<option ".($rowx['dpnl']==11?'selected':'').">11
				<option ".($rowx['dpnl']==12?'selected':'').">12<option ".($rowx['dpnl']==13?'selected':'').">13<option ".($rowx['dpnl']==14?'selected':'').">14<option ".($rowx['dpnl']==15?'selected':'').">15
				</select>  Monto Dias Pagad No Lab(Bs) <input type = 'text' name = 'valordpnl' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['valor_dpnlabor']:($_POST['dpnl']))."' readonly></td>";
		echo "</tr>";
				
		
		echo "</tr>";
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>Deposito en FIDEICOMISO: </font></td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'fideicomiso' size = '10' maxlength = '50' value = '".($rowx['fideicomiso'])."' ></td>";
		echo "</tr>";
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>Adelanto de Utilidades Pagado: </font></td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'adeuti' size = '10' maxlength = '50' value = '".($rowx['adeuti'])."' ></td>";
		echo "</tr>";

		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>Adelanto de Vacaciones Pagado: </font></td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'adevac' size = '10' maxlength = '50' value = '".($rowx['adevac'])."' ></td>";
		echo "</tr>";
		
	
	//============ datos de prestamos
	$consulta=mysqli_query($enlace,"select sum(saldo) as total from prestamo where cedula='".$cedula."' and id='".$_SESSION['id_validar']."' ");
	$row=mysqli_fetch_array($consulta);
	$saldoprestamo=$row['total'];

		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <font color=#DD0044>Saldo Pr&eacute;stamo pendiente (Bs): </font></td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'prestamo' size = '10' maxlength = '50' value = '".number_format($saldoprestamo,2,'.','')."' readonly></td>";
		echo "</tr>";
		
	
		echo "<tr>";
			echo "<td  width = '200' align = 'right' > <input type='text' name='ccon02' size = '20' maxlength = '50' value='".($noentro==0?$rowx['ccon02']:'Otras Deducciones')."'></td>";
			echo "<td  width = '400' align = 'left' > <input type = 'text' name = 'ncon02' size = '10' maxlength = '50' value = '".($noentro==0?$rowx['ncon02']:0)."' ></td>";
		echo "</tr>";

		echo "</table>";
	echo "</br></br>";

		//=========================================================================================================	


		
		echo "<table rules=none border=0 cellpadding=2 cellspacing=0 align='center' style='border-width: 0px; border-color: 75263C;border-style: solid;'>";

		echo "<tr>";
			echo "<td align = 'center'>";
				echo "<input type = 'submit' value = 'Grabar Datos de Liquidaci&oacute;n'>";
			echo "</td>";
		echo "</tr>";
		echo "</table>";

	echo "</form>";
	//FIN DE TODA LA TABLA
	if ($mensaje!='') echo "<br><center><font style='color:RED; font-size:1em;' face='Verdana' ><b>".$mensaje."</b></font></center>";	

	if ($noentro==0) {
		echo "<br><center><font color=#DD0044><b>NOTA:</b> Debe ingresar las <u>Asignaciones y deducciones</u> y Grabar para calcular la Liquidaci&oacute;n.</font></center>";	
	}	
	
echo "<br><br><div id='resultado'></div>";

	
echo "<br><br><br><br></body>";
echo "</html>";
}

mysqli_close($enlace);
?>