<?
include("../conexion/class-sb-conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Libro Remuneracion</title>
<link href="../style/joda-estilo.css" rel="stylesheet" type="text/css" />
</head>
<style>
.linea{
font-size:12px;

}
</style>
<body>
<?
		$db = new sb_mysql();
		$db->proceso($empresa_global);
		$sql_empresa="
  select 
   	rut_empresa,
   	nombre,
	rut_representante,
	nombre_representante,
	ciudad,
	direccion
  from empresa
  where id='".$empresa_global."'
	  ";
		$consulta_empresa = $db->consulta_free($sql_empresa);
		$res_empresa = $db->sb_array($consulta_empresa);

		?>
<table width="100%" border="0" cellpadding="0" cellspacing="0"> 
		<tr class="titulos2">
	<td colspan="8">
		<span style="font-weight:bold">
		<?=$res_empresa['nombre']?>
        </span>
    </td>
    <td align="right">Fecha :<?=date("d/m/Y")?></td>
</tr>
<tr class="titulos2">
	<td colspan="8">
		<span style="font-weight:bold">
		<?=$res_empresa['direccion']?>
        </span>
    </td>

</tr>
<tr class="titulos2">
    <td >
    	R.U.T.&nbsp;:&nbsp;
        <span style="font-weight:bold">
		<?=$res_empresa['rut_empresa']?>
        </span>
    </td>

</tr>
</table>
<?




	  $sql="select 
	  		Rut_Func,
			concat(Apellido_Paterno_Func,' ',Apellido_Materno_Func,' ',Nombre_Func) as Nombre,
			Total_Liquido_Liq,
			Total_Imponible_Liq,
			Total_Haberes_Liq,
			Total_Descuentos_Liq,
			Ajuste_Liq,
			Total_Beneficios_Liq,
			Codigo_Liq,
			Codigo_Liq,
			Sueldo_Base_Liq
	  	FROM sb_contratos_lista
	  	INNER JOIN  sb_funcionarios_lista 
		  		on sb_contratos_lista.Codigo_Func_cont = sb_funcionarios_lista.Codigo_Func
		INNER JOIN  sb_datos_liquidacion 
		  		on sb_contratos_lista.Codigo_Cont = sb_datos_liquidacion.Codigo_Cont_Liq		
	   where sb_contratos_lista.Codigo_Sucu_Cont='".$sucursal_global."' and
	   		 sb_contratos_lista.Codigo_Empresa_Cont='".$empresa_global."' AND
		 sb_datos_liquidacion.Activo_Liq=1	 and Codigo_Proceso='".$db->id_proceso."'
	   order  by Apellido_Paterno_Func,Apellido_Materno_Func,Nombre_Func asc	 ";   
	
     //echo $sql;
	$consulta = $db->consulta_free($sql);
	$num_reg=mysqli_num_rows($consulta);
	$registros=0;
	//echo "....".$num_reg."----";
	?><table border="0" width="100%" style="border:1px solid #CCCCCC"  cellpadding="0" cellspacing="0">
    	<caption>Libro de Remuneracion Haberes <br />
        Periodo : <?=$db->mes_actual." - ".$db->ano_actual?>
        </caption>
		<tr valign="top" class="linea" align="center">
        	<td style="border:1px solid #CCCCCC">N&deg;</td>
            <td style="border:1px solid #CCCCCC">Nombre</td>
            <td style="border:1px solid #CCCCCC">Rut</td>
            <td style="border:1px solid #CCCCCC">Sueldo<br />base</td>
            <td style="border:1px solid #CCCCCC">Dias</td>
            <td style="border:1px solid #CCCCCC">Sueldo<br />Mes</td>
            <td style="border:1px solid #CCCCCC">Cant<br />Hrs</td>
            <td style="border:1px solid #CCCCCC">Extra</td>
            <td style="border:1px solid #CCCCCC">Gratif.</td>
            <td style="border:1px solid #CCCCCC">Tratos</td>
            <td style="border:1px solid #CCCCCC">Bonos</td>
            <td style="border:1px solid #CCCCCC">Total<br />Imp</td>
            <td style="border:1px solid #CCCCCC">N&deg;<br />Cargas</td>
            <td style="border:1px solid #CCCCCC">ASig.<br />Fami.</td>
            <td style="border:1px solid #CCCCCC">ASig.<br />Caja.</td>
            <td style="border:1px solid #CCCCCC">Movili.</td>
            <td style="border:1px solid #CCCCCC">Colaci.</td>
            <td style="border:1px solid #CCCCCC">Viati.</td>
            <td style="border:1px solid #CCCCCC">Feriado<br />Prop.</td>
            <td style="border:1px solid #CCCCCC">Indem-<br />nizacion</td>
            <td style="border:1px solid #CCCCCC">Desahu-<br />cio</td>
            <td style="border:1px solid #CCCCCC">Total<br />Beneficios</td>
            
        </tr>
	<?
	while($Reg = $db->sb_array($consulta))
	{   
	$registros++;
	?>
	<tr class="linea" style="border:1px solid #CCCCCC"><td><?=$registros?></td><td><?=$Reg['Nombre']?></td>
	<?
	$sql="select 
		  	Codigo_HabDes_Plantilla,
		  	Nombre_HabDes,
		  	Valor_Plantilla
		  FROM sb_plantilla_haberes_descuentos
		  INNER JOIN  sb_haberes_descuentos_lista 
		  	on sb_plantilla_haberes_descuentos.Codigo_HabDes_Plantilla = sb_haberes_descuentos_lista.Codigo_HabDes
		  where Codigo_Liq_Plantilla='".$Reg['Codigo_Liq']."'
		  order  by Tipo_HabDes asc,Imponible_HabDes asc,Codigo_HabDes asc  ";   
	//echo $sql;
	$consulta2 = $db->consulta_free($sql);
	while($resultados = $db->sb_array($consulta2)){   
		 //echo ;
		 $indice=$resultados['Codigo_HabDes_Plantilla'];
		 $campos[$indice]=$resultados['Valor_Plantilla'];
		 //echo $indice."-"."-".$campos['$indice']."<br>";
	}
	?><td><?=$Reg['Rut_Func']?></td><?
	?><td align="right"><?=number_format($Reg['Sueldo_Base_Liq'],0,0,'.')?></td><?
	?><td align="right"><?=number_format($campos['1'],0,0,'.')?></td><?
	?><td align="right"><?=number_format($campos['2'],0,0,'.')?></td><? $c2+=$campos['2'];
	?><td align="right"><?=number_format($campos['4'],0,0,'.')?></td><?
	?><td align="right"><?=number_format($campos['5'],0,0,'.')?></td><? $c5+=$campos['5'];
	?><td align="right"><?=number_format($campos['3'],0,0,'.')?></td><? $c3+=$campos['3'];
	?><td align="right"><?=number_format($campos['6'],0,0,'.')?></td><? $c6+=$campos['6'];
	?><td align="right"><?=number_format($campos['7'],0,0,'.')?></td><? $c7+=$campos['7'];
	?><td align="right"><?=number_format($Reg['Total_Imponible_Liq'],0,0,'.')?></td><?  $TRI=$Reg['Total_Imponible_Liq'];
	?><td align="right"><?=number_format($campos['8'],0,0,'.')?></td><?
	?><td align="right"><?=number_format($campos['9'],0,0,'.')?></td><?  $c9+=$campos['9'];
	?><td align="right"><?=number_format($campos['10'],0,0,'.')?></td><? $c10+=$campos['10'];
	?><td align="right"><?=number_format($campos['11'],0,0,'.')?></td><? $c11+=$campos['11'];
	?><td align="right"><?=number_format($campos['12'],0,0,'.')?></td><? $c12+=$campos['12'];
	?><td align="right"><?=number_format($campos['13'],0,0,'.')?></td><? $c13+=$campos['13'];
	?><td align="right"><?=number_format($campos['14'],0,0,'.')?></td><? $c14+=$campos['14'];
	?><td align="right"><?=number_format($campos['15'],0,0,'.')?></td><? $c15+=$campos['15'];
	?><td align="right"><?=number_format($campos['16'],0,0,'.')?></td><? $c16+=$campos['16'];
	?><td align="right"><?=number_format($Reg['Total_Beneficios_Liq'],0,0,'.')?></td><?  $TBE=$Reg['Total_Beneficios_Liq'];
	
	?></tr>
    
    <?
	
	}

   ?>
   <td></td>
   <td>Totales</td>
   <td></td>
   <?
	?><td align="right"></td><?
	?><td align="right"></td><?
	?><td align="right"><?=number_format($c2,0,0,'.')?></td><? 
	?><td align="right"> </td><?
	?><td align="right"><?=number_format($c5,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c3,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c6,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c7,0,0,'.')?></td><?
	?><td align="right"><?=number_format($TRI,0,0,'.')?></td><?
	?><td align="right">&nbsp;</td>
   <?
	?><td align="right"><?=number_format($c9,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c10,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c11,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c12,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c13,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c14,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c15,0,0,'.')?></td><?
	?><td align="right"><?=number_format($c16,0,0,'.')?></td><?
	?><td align="right"><?=number_format($TBE,0,0,'.')?></td><?
	
	?></tr>

   
   
    </table>
 
 
    <br />    
    <br />        

    
    <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
		<tr class="titulos2">
	<td colspan="8">
		<span style="font-weight:bold">
		<?=$res_empresa['nombre']?>
        </span>
    </td>
    <td align="right">Fecha :<?=date("d/m/Y")?></td>
</tr>
<tr class="titulos2">
	<td colspan="8">
		<span style="font-weight:bold">
		<?=$res_empresa['direccion']?>
        </span>
    </td>

</tr>
<tr class="titulos2">
    <td >
    	R.U.T.&nbsp;:&nbsp;
        <span style="font-weight:bold">
		<?=$res_empresa['rut_empresa']?>
        </span>
    </td>

</tr>
</table>
   <table border="0" width="100%" style="border:1px solid #CCCCCC"  cellpadding="0" cellspacing="0">
    		<caption>Libro de Remuneracion Descuentos<br />
        Periodo : <?=$db->mes_actual." - ".$db->ano_actual?></caption>
		<tr valign="top" class="linea" align="center">
        	<td style="border:1px solid #CCCCCC">N&deg;</td>
            <td style="border:1px solid #CCCCCC">Nombre</td>
            <td style="border:1px solid #CCCCCC">Rut</td>
            <td style="border:1px solid #CCCCCC">Anticipo</td>
            <td style="border:1px solid #CCCCCC">Prest.<br />Medico</td>
            <td style="border:1px solid #CCCCCC">Prest.<br />Caja</td>
            <td style="border:1px solid #CCCCCC">Prest.<br />Empresa</td>
            <td style="border:1px solid #CCCCCC">Seguro<br />Vida</td>
            <td style="border:1px solid #CCCCCC">Sindicato.</td>
            <td style="border:1px solid #CCCCCC">Desc.<br />Varios</td>
            <td style="border:1px solid #CCCCCC">Bienestar</td>
            <td style="border:1px solid #CCCCCC">Reten.<br />Judicial</td>
            <td style="border:1px solid #CCCCCC">Ahorro<br />Afp</td>
            <td style="border:1px solid #CCCCCC">Desc.<br />Vol.</td>
            <td style="border:1px solid #CCCCCC">Desc.<br />Afp</td>
            <td style="border:1px solid #CCCCCC">Desc<br />Isapre</td>
            <td style="border:1px solid #CCCCCC">Imp.<br />Renta</td>
            <td style="border:1px solid #CCCCCC">Seguro<br />Vida</td>
            <td style="border:1px solid #CCCCCC">Apv</td>
            <td style="border:1px solid #CCCCCC">Total<br />Haberes</td>
            <td style="border:1px solid #CCCCCC">Total<br />Desc.</td>
            <td style="border:1px solid #CCCCCC">Ajuste</td>
            <td style="border:1px solid #CCCCCC">Total<br />Liquido</td>
            
        </tr>
<?




	  $sql="select 
	  		Rut_Func,
			concat(Apellido_Paterno_Func,' ',Apellido_Materno_Func,' ',Nombre_Func) as Nombre,
			Total_Liquido_Liq,
			Total_Imponible_Liq,
			Total_Haberes_Liq,
			Total_Descuentos_Liq,
			Ajuste_Liq,
			Total_Beneficios_Liq,
			Codigo_Liq,
			Codigo_Liq,
			Sueldo_Base_Liq
	  	FROM sb_contratos_lista
	  	INNER JOIN  sb_funcionarios_lista 
		  		on sb_contratos_lista.Codigo_Func_cont = sb_funcionarios_lista.Codigo_Func
		INNER JOIN  sb_datos_liquidacion 
		  		on sb_contratos_lista.Codigo_Cont = sb_datos_liquidacion.Codigo_Cont_Liq		
	   where sb_contratos_lista.Codigo_Sucu_Cont='".$sucursal_global."' and
	   		 sb_contratos_lista.Codigo_Empresa_Cont='".$empresa_global."' AND
		 sb_datos_liquidacion.Activo_Liq=1	 and Codigo_Proceso='".$db->id_proceso."'
	   order  by Apellido_Paterno_Func,Apellido_Materno_Func,Nombre_Func desc
		  	 ";   
	
     //echo $sql;
	$consulta = $db->consulta_free($sql);
	$num_reg=mysqli_num_rows($consulta);
	$registros=0;
	//echo "....".$num_reg."----";
	
	while($Reg = $db->sb_array($consulta))
	{   
	$registros++;
	?>
	<tr class="linea" style="border:1px solid #CCCCCC"><td><?=$registros?></td><td><?=$Reg['Nombre']?></td>
	<?
	$sql="select 
		  	Codigo_HabDes_Plantilla,
		  	Nombre_HabDes,
		  	Valor_Plantilla
		  FROM sb_plantilla_haberes_descuentos
		  INNER JOIN  sb_haberes_descuentos_lista 
		  	on sb_plantilla_haberes_descuentos.Codigo_HabDes_Plantilla = sb_haberes_descuentos_lista.Codigo_HabDes
		  where Codigo_Liq_Plantilla='".$Reg['Codigo_Liq']."'
		  order  by Tipo_HabDes asc,Imponible_HabDes asc,Codigo_HabDes asc  ";   
	//echo $sql;
	$consulta2 = $db->consulta_free($sql);
	while($resultados = $db->sb_array($consulta2))
	{   
		 //echo ;
		 $indice=$resultados['Codigo_HabDes_Plantilla'];
		 $campos[$indice]=$resultados['Valor_Plantilla'];
		 //echo $indice."-"."-".$campos['$indice']."<br>";
	 }     
 


	
     ?><td><?=$Reg['Rut_Func']?></td><?
      
		?><td align="right"><?=number_format($campos['18'],0,0,'.')?></td><? $c18+=$campos['18'];
		?><td align="right"><?=number_format($campos['19'],0,0,'.')?></td><? $c19+=$campos['19'];
		?><td align="right"><?=number_format($campos['20'],0,0,'.')?></td><? $c20+=$campos['20'];
		?><td align="right"><?=number_format($campos['21'],0,0,'.')?></td><? $c21+=$campos['21'];
		?><td align="right"><?=number_format($campos['22'],0,0,'.')?></td><? $c22+=$campos['22'];
		?><td align="right"><?=number_format($campos['23'],0,0,'.')?></td><? $c23+=$campos['23'];
		?><td align="right"><?=number_format($campos['24'],0,0,'.')?></td><? $c24+=$campos['24'];
		?><td align="right"><?=number_format($campos['25'],0,0,'.')?></td><? $c25+=$campos['25'];
		
		?><td align="right"><?=number_format($campos['26'],0,0,'.')?></td><? $c26+=$campos['26'];
		?><td align="right"><?=number_format($campos['27'],0,0,'.')?></td><? $c27+=$campos['27'];
		?><td align="right"><?=number_format($campos['28'],0,0,'.')?></td><? $c28+=$campos['28'];
		?><td align="right"><?=number_format($campos['29'],0,0,'.')?></td><? $c29+=$campos['29'];
		?><td align="right"><?=number_format(($campos['30']+$campos['31']),0,0,'.')?></td><? $c30+=$campos['30'];
		 $c31+=$campos['31'];
		
		?><td align="right"><?=number_format($campos['32'],0,0,'.')?></td><? $c32+=$campos['32'];
		?><td align="right"><?=number_format($campos['33'],0,0,'.')?></td><? $c33+=$campos['33'];
		?><td align="right"><?=number_format($campos['34'],0,0,'.')?></td><? $c34+=$campos['34'];
		?><td align="right"><?=number_format($Reg['Total_Haberes_Liq'],0,0,'.')?></td><?  $THA+= $Reg['Total_Haberes_Liq'];
		?><td align="right"><?=number_format($Reg['Total_Descuentos_Liq'],0,0,'.')?></td><? $THA+= $Reg['Total_Descuentos_Liq'];
		?><td align="right"><?=number_format($Reg['Ajuste_Liq'],0,0,'.')?></td><?   $Aju+= $Reg['Ajuste_Liq'];
		?><td align="right"><?=number_format($Reg['Total_Liquido_Liq'],0,0,'.')?></td> <? $TLI+= $Reg['Total_Liquido_Liq']; ?>
		</tr>
		<?
	
	
	}

?>
 <td>&nbsp;</td>
 <td>Totales</td>
 <td>&nbsp;</td>
 <?
      
		?><td align="right"><?=number_format($c18,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c19,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c20,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c21,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c22,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c23,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c24,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c25,0,0,'.')?></td><?
		
		?><td align="right"><?=number_format($c26,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c27,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c28,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c29,0,0,'.')?></td><?
		?><td align="right"><?=number_format(($c30+$c31),0,0,'.')?></td><?
		
		?><td align="right"><?=number_format($c32,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c33,0,0,'.')?></td><?
		?><td align="right"><?=number_format($c34,0,0,'.')?></td><?
		?><td align="right"><?=number_format($THA,0,0,'.')?></td><?
		?><td align="right"><?=number_format($TDE,0,0,'.')?></td><?
		?><td align="right"><?=number_format($Aju,0,0,'.')?></td><?
		?><td align="right"><?=number_format($TLI,0,0,'.')?></td>
		</tr>
		</table>

		
		


</body>
</html>
