<?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();
	$cedula=str_repeat('0',8-strlen(trim($_REQUEST["cedula"]))).trim($_REQUEST["cedula"]);


	//============ datos de empresa
	$consulta=mysqli_query($enlace,"select * from empresa where id='".$_SESSION['id_validar']."' ");
	$row=mysqli_fetch_array($consulta);
	$ince=$row['ince'];
	$dvac=$row['dvac'];
	$dbon=$row['dbon'];
	$duti=$row['duti'];
	$icon=$row['icon'];
	$con01=$row['constante01'];
	$con02=$row['constante02'];
	$con03=$row['constante03'];
	$con04=$row['constante04'];
	$sueldominimo=$row['sueldominimo'];

	//===========egresado o no
	$egresado=true;

	//=========== datos de liquidación
	$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));
	$rowx=mysqli_fetch_array($resultadox);
	$status_liq = $rowx['estado_liquidacion'];
	$fec1 = $rowx['fechai'];
	$fec2 = $rowx['fecha_retiro'];
	$fecha_pago = $rowx['fecha_pago'];
	$tipoe = $rowx['tipoe'];
	$tipo_salario = $rowx['tipo_salario'];
	$smes = $rowx['sueldo_liq'];
	$salar_integral = $rowx['salar_integral'];
	$diaspagar = $rowx['dias'];
	$valor_dias_pagar = $rowx['valor_dias_pagar'];
	$sueldos_pagar = $rowx['sueldos_pagar'];
	$diasticket = $rowx['diast'];
	$valor_dia_cestatic = $rowx['valor_dia_cestatic'];
	$valor_ct_total = $rowx['valor_ct_total'];
	$vac = $rowx['vacacion'];
	$dias_vac_venc = $rowx['dias_vac_venc'];
	$valor_vaca_venc = $rowx['valor_vaca_venc'];
	$dias_bonovac_venc = $rowx['dias_bonovac_venc'];
	$valor_bonovac_venc = $rowx['valor_bonovac_venc'];
	$dias_vac_fraccion = $rowx['dias_vac_fraccion'];
	$valor_dias_vac_fraccion = $rowx['valor_dias_vac_fraccion'];
	$dias_bonovac_fraccion = $rowx['dias_bonovac_fraccion'];
	$valor_bonovac_fraccion = $rowx['valor_bonovac_fraccion'];
	$dias_bono_postvaca = $rowx['dias_bono_postvaca'];
	$valor_bono_postvaca = $rowx['bono_post_vaca'];
	$dias_descanso_vaca = $rowx['dias_descans_vacac'];
	$valor_dias_descanso_vaca = $rowx['valor_dias_desc_vacac'];
	$ccon01 = $rowx['ccon01'];
	$ncon01 = $rowx['ncon01'];
	$pago_fondo_ahor = $rowx['pago_fondo_ahor'];
	$dias_util_pagar = $rowx['dias_util_pagar'];
	$valor_utilid_pagar = $rowx['valor_utilid_pagar'];
	$dias_prestac_garant = $rowx['dias_prestac_garant'];
	$valor_prestaciones_gant = $rowx['valor_prestaciones_gant'];
	$dias_prest_adic = $rowx['dias_prest_adic'];
	$valor_prestac_adic = $rowx['valor_prestac_adic'];
	$valor_indemniza = $rowx['valor_indem'];
	$valor_metodoC = $rowx['valor_metodo_c'];
	$intereses_prestac = $rowx['intereses_prestac'];
	$semana = $rowx['semana'];
	$valor_sso = $rowx['valor_sso'];
	$valor_rpe = $rowx['valor_rpe'];
	$faov = $rowx['faov'];
	$islr = $rowx['islr'];
	$valor_islr = $rowx['valor_islr'];
	$dpnl = $rowx['dpnl'];
	$valor_dpnlabor = $rowx['valor_dpnlabor'];
	$inces = $rowx['inces'];
	$fideicomiso = $rowx['fideicomiso'];
	$adelanto_prestaciones = $rowx['anticipo_prestac'];
	$adeuti=$rowx['adeuti'];
	$adevac=$rowx['adevac'];
	$ccon02 = $rowx['ccon02'];
	$ncon02 = $rowx['ncon02'];
	$cuantosdias=calcular_dias($fec1,$fec2);
	$saldoprestamo = $rowx['saldo_prestamo'];

	$hoy=substr($fec2,0,4).'-01-01';
	if ($fec1>$hoy) $hoy = $fec1;

	$mesutilidad = mostrar_antiguedad(2,$hoy, $fec2);
	$utilidad = $duti/12*$mesutilidad*($smes/30);

	$a=mostrar_antiguedad(1,$fec1,$fec2);
	$diasvac = $dvac + ($a-1<=0?0:$a-1);
	$diasbon = $dbon + ($a-1<=0?0:$a-1);

	/*
	//============ 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'];
	*/
	//============ datos de adelantos
	$consulta=mysqli_query($enlace,"select sum(monto) as total from prestacion_adelanto where cedula='".$cedula."' and id='".$_SESSION['id_validar']."' ");
	$row=mysqli_fetch_array($consulta);
	$saldoadelanto=$row['total'];

	//============ datos de intereses
	$consulta=mysqli_query($enlace,"select sum(monto) as total from prestacion_interes where cedula='".$cedula."' and id='".$_SESSION['id_validar']."' ");
	$row=mysqli_fetch_array($consulta);
	$saldointeres=$row['total'];


	//====================================== SALIDA DE CALCULO
	//====================================== SALIDA DE CALCULO
	
	$consulta="select nomina,nombres,nombres1,apellidos,apellidos1, fechai, fechae from personal where codigo='".$cedula."' and id='".$_SESSION['id_validar']."' ";
	$resultado = mysqli_query($enlace,$consulta) or die($consulta . mysqli_error($enlace));
	$row=mysqli_fetch_array($resultado);
	$tiponomina=$row['nomina'];

	//====================== buscar tipo de nomina
	$tipoclase=1;
	$consulta1="select tipo from nomina where id='".$_SESSION['id_validar']."' and codigo='".$tiponomina."'";
	$resultado1 = mysqli_query($enlace,$consulta1) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
	while ($row1 = mysqli_fetch_array($resultado1)) $tipoclase=$row1['tipo'];

echo "<div class='factura-container'>";

echo "<div class='factura-header'>
        <div class='titulo'>Cálculo de Liquidación por Retiro</div>
        <div class='trabajador'>".$row['nombres']." ".$row['nombres1']." ".$row['apellidos']." ".$row['apellidos1']." Cédula: ".$cedula." </div>
		<div class='trabajador'>Fecha Ing: ".$row['fechai']." - Fecha Fin: ".$row['fechae']."</div>
      </div>";

echo "<table class='tabla-factura' rules='none' border='0'>";

	echo "<tr bgcolor='#43bced' height='25'>";
		echo "<th width='400' align = left><font face='arial' font color='black' > Conceptos </font></th>";
		echo "<th width='80' align = left><font face='arial' font color='black'> Desde </font></th>";
		echo "<th width='80' align = left><font face='arial' font color='black'> Hasta </font></th>";
		echo "<th width='80' align = left><font face='arial' font color='black'> Unidad </font></th>";
		echo "<th width='60' align = left><font face='arial' font color='black'> Cantidad </font></th>";
		echo "<th width='60' align = right><font face='arial' font color='black'> Diario </font></th>";
		echo "<th width='100' align = right><font face='arial' font color='black'> Sub-Total </font></th>";
	echo "</tr>";

	$totaldev=0; $totalded=0;
	///=====================================  dias a pagar
	///=====================================  dias a pagar
	if ($diaspagar>0) {
		echo '<tr>';
			echo "<td><font color='black' font face='Verdana' font size=2>Sueldo / Salario</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font color='black' font face='Verdana' font size=2>D&iacute;as</font></td>";
			echo "<td align=left><font color='black' font face='Verdana' font size=2>".number_format($diaspagar ,0)."</font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($smes/30 ,2)."</font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($valor_dias_pagar,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $valor_dias_pagar;
	}

	///===================================== sueldos y recargos a pagar

	if ($sueldos_pagar>0) {
		
		echo '<tr>';
			echo "<td><font color='black' font face='Verdana' font size=2>Salarios y recargos trabajados</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font color='black' font face='Verdana' font size=2> </font></td>";
			echo "<td align=left><font color='black' font face='Verdana' font size=2> </font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2> </font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($sueldos_pagar,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $sueldos_pagar;
	}
	///===================================== cesta ticket dias a pagar
	///===================================== cesta ticket dias a pagar
	if ($diasticket>0) {
		
		echo '<tr>';
			echo "<td><font color='black' font face='Verdana' font size=2>Cesta Tickets a Pagar</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font color='black' font face='Verdana' font size=2>D&iacute;as</font></td>";
			echo "<td align=left><font color='black' font face='Verdana' font size=2>".number_format($diasticket ,0)."</font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($valor_dia_cestatic ,2)."</font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($valor_ct_total,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $valor_ct_total;
	}

	///===================================== vacaciones vencidas
	if ($vac>0) {
		echo '<tr>';
			echo "<td ><font color='black' font face='Verdana' font size=2>Vacaciones Anuales Vencidas (".$vac.")</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font color='black' font face='Verdana' font size=2>D&iacute;as</font></td>";
			echo "<td align=left><font color='black' font face='Verdana' font size=2>".number_format($dias_vac_venc,0)."</font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
			echo "<td align=right><font color='black' font face='Verdana' font size=2>".number_format($valor_vaca_venc,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $valor_vaca_venc;

		///==================== Bono vacacional vencido
		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>Bono Vacacional Vencido (".$vac.")</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font face='Verdana' font size=2>D&iacute;as</td></font>";
			echo "<td align=left><font face='Verdana' font size=2>".number_format($dias_bonovac_venc,0)."</font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_bonovac_venc,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $valor_bonovac_venc;

		///==================== Bono POST vacacional vencido
		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>Bono Post Vacacional (".$vac.")</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font face='Verdana' font size=2>D&iacute;as</td></font>";
			echo "<td align=left><font face='Verdana' font size=2>".$dias_bono_postvaca. "</font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_bono_postvaca,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $valor_bono_postvaca;

		/*if ($color) $tcolor="#dfdfd0";///==================== Dias de descanso de vacaciones vencidas

		else $tcolor="white";
		echo '<tr bgcolor='.$tcolor.' >';
			echo "<td ><font face='Verdana' font size=2>Dias de descanso en vacaciones no disfrutados (".$vac.")</font></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td><font face='Verdana' font size=2>D&iacute;as</td></font>";
			echo "<td align=left><font face='Verdana' font size=2>".$dias_descanso_vaca. "</font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_dias_descanso_vaca,2)."</font></td>";
		echo "</tr>";
		$color=!$color;
		$totaldev += $valor_dias_descanso_vaca;
		*/




	}

	$a=mostrar_antiguedad(1,$fec1,$fec2);
	$mesvacacion = mostrar_antiguedad(2,$fec1,$fec2);
	$diasvac = $dvac + ($a<=0?0:$a);
	$diasbon = $dbon + ($a<=0?0:$a);

	//=============================== Vacaciones Fraccionadas
	echo '<tr>';
		echo "<td width='300'><font face='Verdana' font size=2>Vacaciones Fraccionadas</td>";
		echo "<td></td>";
		echo "<td></td>";
		echo "<td ><font face='Verdana' font size=2> Dias</font></td>";
		echo "<td align=left><font face='Verdana' font size=2>".number_format($dias_vac_fraccion,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_dias_vac_fraccion,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$totaldev += $valor_dias_vac_fraccion;

	//=============================== Bono Vacacional Fraccionado
	echo '<tr>';
		echo "<td width='300'><font face='Verdana' font size=2>Bono Vacacional Fraccionado</td>";
		echo "<td></td>";
		echo "<td></td>";
		echo "<td ><font face='Verdana' font size=2> Dias</font></td>";
		echo "<td align=left><font face='Verdana' font size=2>".number_format($dias_bonovac_fraccion,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_bonovac_fraccion,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$totaldev += $valor_bonovac_fraccion;




	//=============================== UTILIDADES
	//=============================== UTILIDADES
	$hoy=substr($fec2,0,4).'-01-01';
	if ($fec1>$hoy) $hoy = $fec1;

	$mesutilidad = mostrar_antiguedad(2,$hoy, $fec2);
	$utilidad = $duti/12*$mesutilidad*($smes/30);
	echo '<tr>';
		echo "<td ><font face='Verdana' font size=2>Utilidades del Per&iacute;odo</font></td>";
		echo "<td ><font face='Verdana' font size=2>".mostrar_fecha($hoy)."</font></td>";
		echo "<td ><font face='Verdana' font size=2>".mostrar_fecha($fec2)."</font></td>";
		echo "<td ><font face='Verdana' font size=2> Dias</font></td>";
		echo "<td width='100' align=left><font face='Verdana' font size=2>".number_format($dias_util_pagar,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($smes/30,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_utilid_pagar,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$totaldev += $valor_utilid_pagar;


	//=============================== otras asignaciones
	//=============================== otras asignaciones
	if ($ncon01>0) {
		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>".$ccon01."</font></td>";
			echo "<td ></td>";
			echo "<td ></td>";
			echo "<td ></td>";
			echo "<td align=right></td>";
			echo "<td align=right></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($ncon01,2)."</font></td>";
		echo '</tr>';
		$color=!$color;
		$totaldev += $ncon01;
	}
	///Pago de Haberes del FONDO DE AHORROS
	if ($pago_fondo_ahor>0) {
		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>Haberes Fondo Ahorros</font></td>";
			echo "<td ></td>";
			echo "<td ></td>";
			echo "<td ></td>";
			echo "<td align=right></td>";
			echo "<td align=right></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($pago_fondo_ahor,2)."</font></td>";
		echo '</tr>';
		$color=!$color;
		$totaldev += $pago_fondo_ahor;
	}

	//============ datos inicializando
	$fec11 = substr($rowx['fechai'],0,7);
	$fec22 = substr($rowx['egreso'],0,7);
	$fec11x = $rowx['fechai'];
	$fec22x = $rowx['egreso'];
	$inicio=0; $tri=0; $salto=0; $anosx=0; $anos=0; $entrosueldo=0;
	$acumulado=0; $intereses=0; $tdias=0; $prestaciones=0;$interesganados=0;
	$cuantosmeses=0;

	//============ datos de sueldo
	$consulta=mysqli_query($enlace,"select sueldo from personal_sueldo where id='".$_SESSION['id_validar']."' and substring(fec,1,7)='".$fec11."' and codigo='".$cedula."'") or die (mysqli_error($enlace));
	$row=mysqli_fetch_array($consulta);
	if (mysqli_num_rows($consulta)!=0) $sueldo=$row['sueldo'];


	///////////////Nuevo proceso de Prestaciones- solo consulta a la tabla [liqudiaciones] en la BD
	/////////prestaciones en Garantia 142
	
	if(($valor_metodoC < ($valor_prestaciones_gant+$valor_prestac_adic)) || $valor_metodoC==0)
	{

	echo '<tr>';
		echo "<td ><font face='Verdana' font size=2>Prestaciones en Garantia (Art. 142)</font></td>";
		echo "<td><font face='Verdana' font size=2>".mostrar_fecha($fec1)."</font></td>";
		echo "<td><font face='Verdana' font size=2>".mostrar_fecha($fec2)."</font></td>";
		echo "<td ><font face='Verdana' font size=2> Dias</font></td>";
		echo "<td width='100' align=left><font face='Verdana' font size=2>".number_format($dias_prestac_garant,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2></font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_prestaciones_gant,2)."</font></td>";

	echo '</tr>';
	$color=!$color;
	$totaldev += $valor_prestaciones_gant;

	/////////prestaciones Adicionales 142

	echo '<tr>';
		echo "<td ><font face='Verdana' font size=2>Depósito Ultimo Trimestre(Art. 142)</font></td>";
		echo "<td><font face='Verdana' font size=2> </font></td>";
		echo "<td><font face='Verdana' font size=2> </font></td>";
		echo "<td ><font face='Verdana' font size=2> Dias</font></td>";
		echo "<td width='100' align=left><font face='Verdana' font size=2>".number_format($dias_prest_adic,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2></font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_prestac_adic,2)."</font></td>";

		echo '</tr>';
		$color=!$color;
		$totaldev += $valor_prestac_adic;
	}else {
	echo '<tr>';
		echo "<td ><font face='Verdana' font size=2>Prestaciones Por Antig. (Art. 142 lit C)</font></td>";
		echo "<td><font face='Verdana' font size=2> </font></td>";
		echo "<td><font face='Verdana' font size=2> </font></td>";
		echo "<td ><font face='Verdana' font size=2> Dias</font></td>";
		echo "<td width='100' align=left><font face='Verdana' font size=2>".number_format($dias_prest_adic,2)."</font></td>";
		echo "<td align=right><font face='Verdana' font size=2></font></td>";
		echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_metodoC,2)."</font></td>";

		echo '</tr>';
		$color=!$color;
		$totaldev += $valor_metodoC;
		}
		///////////////Intereses sobre prestaciones_pagar
		if($intereses_prestac>0){
		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>Intereses sobre prestaciones Sociales</font></td>";
			echo "<td><font face='Verdana' font size=2> </font></td>";
			echo "<td><font face='Verdana' font size=2> </font></td>";
			echo "<td ><font face='Verdana' font size=2> </font></td>";
			echo "<td width='100' align=left><font face='Verdana' font size=2></font></td>";
			echo "<td align=right><font face='Verdana' font size=2></font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($intereses_prestac,2)."</font></td>";
			echo '</tr>';
			$color=!$color;
			$totaldev += $intereses_prestac;
		}


		/////////Indemnizacion

		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>Indemnizacion (Art. 92)</font></td>";
			echo "<td><font face='Verdana' font size=2> </font></td>";
			echo "<td><font face='Verdana' font size=2> </font></td>";
			echo "<td ><font face='Verdana' font size=2></font></td>";
			echo "<td width='100' align=left><font face='Verdana' font size=2></font></td>";
			echo "<td align=right><font face='Verdana' font size=2></font></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($valor_indemniza,2)."</font></td>";


	echo '</tr>';
	$color=!$color;
	$totaldev += $valor_indemniza;




	 	//===========Agregado para calcular el trimestre
	$fec11 = $fec1;
	$fec22 = $fec2;
	$ultdias=false;

	//=============================== total devengo
	//=============================== total devengo
	echo "<tr bgcolor='#CEF2F6' height='25'>";
		echo "<td align = right colspan=6><font color='black' font face='Verdana' font size=3> Total Devengado Bs. </font></td>";

		echo "<td align='right'><font color='black' font face='Verdana' font size=4><b>".number_format($totaldev,2)."</font></td>";
	echo "</tr>";



	//=============================== total DEDUCCIONES
	//=============================== total DEDUCCIONES

	//=============================== total dias pagado no laborados
	$total=0;
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>D&iacute;as Pagados No Laborados</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".$dpnl." D&iacute;as</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($valor_dpnlabor,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total += $valor_dpnlabor;

	//=============================== total PRESTACIONES
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Adelantos de Prestaciones Sociales</font></td>";
		echo "<td align='right'></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($adelanto_prestaciones,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$adelanto_prestaciones;

	//=============================== total INTERESES
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Intereses de Prestaciones Sociales Pagadas</font></td>";
		echo "<td align='right'></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($saldointeres,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$saldointeres;

	//=============================== total PRESTAMOS
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Prestamos Personales</font></td>";
		echo "<td align='right'></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($saldoprestamo,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$saldoprestamo;

	//=============================== total UTILIDADES
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Adelantos de Utilidades</font></td>";
		echo "<td align='right'></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($adeuti,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$adeuti;

	//=============================== total VACACIONES
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Adelantos de Vacaciones</font></td>";
		echo "<td align='right'></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($adevac,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$adevac;

	//=============================== total FIDEICOMISO
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Deposito en FIDEICOMISO</font></td>";
		echo "<td align='right'></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($fideicomiso,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$fideicomiso;

	//=============================== total ISLR
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Impuesto Sobre La Renta (I.S.L.R.)</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($islr,2)."</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($valor_islr,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$valor_islr;

	//=============================== total S.S.O.
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Seguro Social Obligatorio (S.S.O.)</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($semana,2)."</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($valor_sso,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$valor_sso;

	//=============================== total RPE
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>Regimen de Prestaci&oacute;n de Empleo (R.P.E.)</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($semana,2)."</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($valor_rpe,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$valor_rpe;

	//=============================== total FAOV
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>F.A.O.V</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2> 1%</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($faov,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$faov;

	//=============================== total INCES
	echo '<tr>';
		echo "<td colspan=5><font face='Verdana' font size=2>I.N.C.E.S.</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($ince,2)."</font></td>";
		echo "<td align='right'><font face='Verdana' font size=2>".number_format($inces,2)."</font></td>";
	echo '</tr>';
	$color=!$color;
	$total +=$inces;

	//=============================== otras deducciones
	if ($ncon02>0) {
		echo '<tr>';
			echo "<td ><font face='Verdana' font size=2>".$ccon02."</font></td>";
			echo "<td ></td>";
			echo "<td ></td>";
			echo "<td ></td>";
			echo "<td align=right></td>";
			echo "<td align=right></td>";
			echo "<td align=right><font face='Verdana' font size=2>".number_format($ncon02,2)."</font></td>";
		echo '</tr>';
		$color=!$color;
		$total += $ncon02;
	}

	//=============================== total Deducciones
	echo "<tr bgcolor='#1a69a9'>";
		echo "<td colspan=6 align=right><font color='black' font face='Verdana' font size=3>Total Deducciones Bs.</font></td>";
		
		echo "<td align='right'><font color='black' font face='Verdana' font size=3>".number_format($total,2)."</font></td>";
	echo "</tr>";
	echo "<br>";

	echo '<tr bgcolor="#43BCED">';
		echo "<td colspan=6 align=right class='fila-total'><b><font color='black' font face='Verdana' font size=4>Total Neto a Pagar Bs.  :</b></font></td>";
		echo "<td align='right'><font color='black' font face='Verdana' font size=4><b>".number_format($totaldev-$total,2)."</b></font></td>";
	echo '</tr>';
	echo "</table>";
echo "<div class='factura-footer'>Reporte generado por SAIREH</div>";
echo "</div>";
	mysqli_free_result($resultado);


	echo '</table>';
	mysqli_close($enlace);
?>

	<style>
/* ============================================
   REPORTE TIPO FACTURA – ESTILO SAIREH
   ============================================ */

/* Tipografía general */
body, table, td, th {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    color: #333;
}

/* Contenedor general */
.factura-container {
    width: 900px;
    margin: 0 auto;
    padding: 25px;
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}

/* Encabezado */
.factura-header {
    text-align: center;
    margin-bottom: 25px;
}

.factura-header .titulo {
    font-size: 22px;
    font-weight: 700;
    color: #000000;
    margin-bottom: 5px;
}

.factura-header .trabajador {
    font-size: 18px;
    font-weight: 500;
    color: #000;
}

/* Tabla principal */
.tabla-factura {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

/* Encabezados */
.tabla-factura th {
    background: #43bced;
    color: #000;
    padding: 10px;
    font-weight: 600;
    text-align: left;
    border-bottom: 2px solid #2fa3c9;
}

/* Filas */
.tabla-factura td {
    padding: 8px 10px;
    border-bottom: 1px solid #eaeaea;
    vertical-align: middle;
}

/* Filas alternadas */
.tabla-factura tr:nth-child(even) {
    background: #f9f9f9;
}

/* Totales */
.fila-total {
    background: #43bced !important;
    font-weight: bold;
    color: #000;
}

.fila-total td, .fila-total th {
    padding: 12px;
    font-size: 15px;
}

/* Alineaciones */
.text-right { text-align: right; }
.text-left { text-align: left; }

/* Evitar saltos de línea */
td, th {
    white-space: nowrap;
}

/* Secciones */
.seccion-titulo {
    margin-top: 30px;
    font-size: 16px;
    font-weight: 600;
    color: #75263C;
    border-left: 4px solid #43bced;
    padding-left: 10px;
}

/* Resaltado de números */
.numero {
    font-weight: 600;
}

/* Footer */
.factura-footer {
    margin-top: 30px;
    text-align: right;
    font-size: 13px;
    color: #666;
}
	</style>
