<?
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" />
<link href="../style/joda-estilo.css" rel="stylesheet" type="text/css" />
<title>Documento sin t&iacute;tulo</title>
</head>
<body>
<BR />
<BR />
<BR />
<table align="center">

<caption>REGISTRO ARCHIVO PREVIRED INDIVIDUAL</caption>
<BR />
<BR />
<BR />

<?

	$dbx = new sb_mysql();
	$dbx->proceso($empresa_global);
	
	$wsql = "select 
   		Codigo_Empresa_Datos,
  		Proceso_Datos,
  		Tope_Gratificacion_Datos,
		Tope_Imponible_Ips_Datos,
		Tope_Imponible_Salud_Datos,
		Tramo1_Asig_Datos,
  		Tramo2_Asig_Datos,
  		Tramo3_Asig_Datos,
  		Tramo4_Asig_Datos,
  		Tope_Imponible_Datos,
  		Tope_Imponible_Cesantia_Datos,
  		Factor_Horas_Extras_Datos,
  		Caja_Comp_Datos,
  		Por_Caja_Comp_Datos,
  		Mutual_Datos,
  		Por_Mutual_Datos,
		Uf_Datos,
		Utm_Datos,
		Por_Gratificacion_Datos,
		Sis_datos
		from sb_datos_empresa_proceso 
		Where Codigo_Empresa_Datos='".$empresa_global."' ";
		
		//echo $wsql;
    	$consulta_free = $dbx->consulta_free($wsql);
		$fijos = $dbx->sb_array($consulta_free);   
	
	$sql="select * from sb_datos_liquidacion
	inner join sb_contratos_lista
	on sb_datos_liquidacion.Codigo_Cont_Liq = sb_contratos_lista.Codigo_Cont
	  where Activo_Liq=1
	and Codigo_Proceso='".$dbx->id_proceso."'
	and Codigo_Empresa_Cont = '".$empresa_global."'
	and Codigo_Func_Liq = '".$Codigo_Func."'
	";
	
	//echo $sql;
	$consultatotal = $dbx->consulta_free($sql);
	
    //$num_reg=mysqli_num_rows($consulta_total);
	
	
	
	while($registrototal = $dbx->sb_array($consultatotal))
	{
	//echo "ndndndn<br>";
	
	$sql="select 
	SUBSTR(
    	REPLACE(REPLACE(Rut_Func,'.',''),'-',''),
     	1,
     	LENGTH(
        		REPLACE(REPLACE(Rut_Func,'.',''),'-','')
            )-1                                     
	) AS Rut,	
	SUBSTR(Rut_Func,LENGTH(Rut_Func),1) AS DV,
    SUBSTR(Apellido_Paterno_Func,1,30) as Apellido_Paterno_Func,
    SUBSTR(Apellido_Materno_Func,1,30) AS Apellido_Materno_Func,
    SUBSTR(Nombre_Func,1,30) AS Nombre_Func,
    if(Sexo_Func=1,'F','M') as Sexo,
    1 as Nacionalidad,
    1 as Tipo_Pago,
    CONCAT(SUBSTR(Mes_Proceso,5,2),SUBSTR(Mes_Proceso,1,4)) AS Periodo_Desde,
    '' as 'N10',
	if(Regimen_Antiguo=0,'AFP',
       if(Regimen_Antiguo=1,'INP',
          if(Regimen_Antiguo=2,'SIP','SIP')
       )
     ) as  Regimen,
	if(Regimen_Antiguo=0,'0',
       if(Regimen_Antiguo=2,'0','')
     )  as Tipo_Trab,  
	round(t1.Valor_Plantilla) as Dias,	
    '00' as Tipo_Linea, 
    Codigo_Mov_Liq,
    Fecha_Inicio_Mov_Liq,
    Fecha_Termino_Mov_Liq, 
    IF(Tramo_Asig_Liq='0','',Tramo_Asig_Liq) as Tramo_Asig_Liq,
    Cargas_Norm_Liq,
    Cargas_Mate_Liq,
    Cargas_Inva_Liq,
    round(t2.Valor_Plantilla) as Valor_Cargas, 
    round(t6.Valor_Plantilla) as Asignacion_retroactiva,
    '' as 'N24',
    '' as 'N25', 
    if(Regimen_Antiguo=0,Equivalencia_pr_Afp,'') as Codigo_Afp,
    if(Regimen_Antiguo=0,
		if(Total_Imponible_Liq>(".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf)."),
		".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	,'') as Total_Imponible_Liq,
    if(Regimen_Antiguo=0,round(t3.Valor_Plantilla),'') as Desc_Afp,
    if(Regimen_Antiguo=0,round(Total_Imponible_Liq*0.0115),'') as Sis,
    if(Regimen_Antiguo=0,round(t4.Valor_Plantilla),'') as Desc_Vol_Afp,
    '' as 'N31',
	'00,00' as 'N32',
    '' as 'N33',
    '' as 'N34',
    '' as 'N35',
    '' as 'N36',
    '' as 'N37',
    '00,00' as 'N38',
    '' as 'N39',
    if(Codigo_Recaudadora_Apv_Func!=0,Codigo_Recaudadora_Apv_Func,'000') as Codigo_Ins_Apv,
    '' as 'N41',
    if(Codigo_Recaudadora_Apv_Func!=0,'2','0') as Forma_pago_Apv,
    if(Codigo_Recaudadora_Apv_Func!=0,round(t5.Valor_Plantilla),'') as Apv,
    '' as 'N44',
	'' as 'N45',
	'' as 'N46',
	'' as 'N47',
	'' as 'N48',
	'' as 'N49',
	'' as 'N50',
	'' as 'N51',
	'' as 'N52',
	'' as 'N53',
	'' as 'N54',
	'' as 'N55',
	'' as 'N56',
	'' as 'N57',
	'' as 'N58',
	'' as 'N59',
	'' as 'N60',
	'' as 'N61',
	if(Regimen_Antiguo=1,Equivalencia_pr_Afp,'') as Codigo_Ex_caja,
	if(Regimen_Antiguo=1,Porc_Afp,'00,00') as Por_Ex_caja,
	if(Regimen_Antiguo=1 or (Codigo_Isapre_Liq=1 ) or ".$fijos["Mutual_Datos"]."=0 or
	(".$fijos["Caja_Comp_Datos"]."=0 and round(t2.Valor_Plantilla)>0)
	 ,
		if(Regimen_Antiguo=0,
			if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",
			".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
			)
		,
		   if(Regimen_Antiguo=1 or Codigo_Isapre_Liq=1,
			 if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Ips_Datos"]."*".$dbx->uf).",
			    ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
			   )
	       ,'')
	    )
	,'') as Total_Imponible_Ips,
	if(Regimen_Antiguo=1,round(t3.Valor_Plantilla),'') as Desc_Ips,
	'' as 'N66',
	'' as 'N67',
	'00,00' as 'N68',
	'' as 'N69',
	if(Codigo_Isapre_Liq=1,
	if(".$fijos["Caja_Comp_Datos"]."!=0,
	round((7-".$fijos["Por_Caja_Comp_Datos"].")*7/round(t7.Valor_Plantilla))
	,round(t7.Valor_Plantilla)) 	
	,'') as Desc_Salud_Fonsa,
	round(
	if(".$fijos["Mutual_Datos"]."=0,
	    (".$fijos["Por_Mutual_Datos"]."/100)*
		if(Regimen_Antiguo=0,
		  if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",
		  ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
		  )
	    ,
	     if(Regimen_Antiguo=1 or Codigo_Isapre_Liq=1,
		   if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Ips_Datos"]."*".$dbx->uf).",
		    ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
			)
	     ,'')
		)
	,'')
	) as  'Acc',
	
	'' as 'N72',
	if(".$fijos["Caja_Comp_Datos"]."=0,round(t2.Valor_Plantilla),'')  as Valor_Cargas_ISL,
	'' as 'N74',
	if(Codigo_Isapre_Liq!=1,Codigo_Isapre_Liq,'') as Codigo_Isapre,
	'' as 'N76',
	if(Codigo_Isapre_Liq!=1,
	  if(Regimen_Antiguo=0,
		if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",
		".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
		)
	  ,
	   if(Regimen_Antiguo=1 or Regimen_Antiguo=2,
		 if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Ips_Datos"]."*".$dbx->uf).",
		 ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
		 )
	   ,'')
	  )
	,'') as Total_Imponible_Salud,
	if(Codigo_Isapre_Liq!=1,Tipo_Pactado_Liq,'') as Tipo_Pactado_Liq,
	if(Codigo_Isapre_Liq!=1,Valor_Pactado_Liq,'') as Valor_Pactado_Liq,
	if(Codigo_Isapre_Liq!=1,round(t7.Valor_Plantilla),'') as Desc_Salud2,
	if(Codigo_Isapre_Liq!=1,round(t8.Valor_Plantilla),'') as Desc_Adic_Isapre,
	'' as 'N82',
	if(".$fijos["Caja_Comp_Datos"]."!=0,".$fijos["Caja_Comp_Datos"].",'')
	as 'Codigo_caja',
	if(".$fijos["Caja_Comp_Datos"]."!=0,
	  if(Regimen_Antiguo=0,
		if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",
		".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	  ,
	   if(Regimen_Antiguo=1 or Regimen_Antiguo=2,
		 if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Ips_Datos"]."*".$dbx->uf).",
		 ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq
		 )
	   ,'')
	   )
	,'') as 'Renta_Imp_Cccaf',
	'' as 'N85',
	'' as 'N86',
	'' as 'N87',
	if(".$fijos["Caja_Comp_Datos"]."!=0,round(t10.Valor_Plantilla),'') as 'Seguro_Vida_CCAF',
	'' as 'N89',
	if(".$fijos["Caja_Comp_Datos"]."!=0,
	if(Codigo_Isapre_Liq=1,
	round((".$fijos["Por_Caja_Comp_Datos"].")*7/round(t7.Valor_Plantilla))
	,'')
	,'') as 'Cotizacion_Ccaf',
	if(".$fijos["Caja_Comp_Datos"]."!=0,
	(round(t2.Valor_Plantilla) +round(t6.Valor_Plantilla))
	,'') as 'Desc_Ccaf',
	'' as 'N92',
	'' as 'N93',
	'' as 'N94',
	'' as 'N95',
	if(".$fijos["Mutual_Datos"]."!=0,".$fijos["Mutual_Datos"].",'') as 'codigo_mutual',
	if(".$fijos["Mutual_Datos"]."!=0,
	  if(Regimen_Antiguo=0,
		if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",
		".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	   ,
	    if(Regimen_Antiguo=1 or Regimen_Antiguo=2,
		  if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Ips_Datos"]."*".$dbx->uf).",
		   ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	    ,'')
		)
	,'') as 'Renta_Imp_Mutual',
	round(
	if(".$fijos["Mutual_Datos"]."!=0,(".$fijos["Por_Mutual_Datos"]."/100)*
	  if(Regimen_Antiguo=0,
		if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",
		".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	  ,
	    if(Regimen_Antiguo=1 or Codigo_Isapre_Liq=1 ,
		  if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Ips_Datos"]."*".$dbx->uf).",
		  ".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	    ,'')
	  )
	,'')
	) as 'Coti_Acc_Mutual',
	'' as 'N99',
	if(Total_Imponible_Liq>".($fijos["Tope_Imponible_Cesantia_Datos"]."*".$dbx->uf).",
		".($fijos["Tope_Imponible_Datos"]."*".$dbx->uf).",Total_Imponible_Liq)
	 as 'Imp_SC',
	round(Total_Imponible_Liq*0.006) as 'Aporte_Trab',
	round(Total_Imponible_Liq*0.024) as 'Aporte_Empre',
	'' as 'N103',
	'' as 'N104',
	'' as 'N105'

	
	from sb_datos_liquidacion
	inner join sb_contratos_lista
		on sb_datos_liquidacion.Codigo_Cont_Liq = sb_contratos_lista.Codigo_Cont
	inner join sb_funcionarios_lista 
		on Codigo_Func_Liq = Codigo_Func
	inner join sb_plantilla_haberes_descuentos  as t1  
      on Codigo_Liq = t1.Codigo_Liq_Plantilla && t1.Codigo_HabDes_Plantilla=1
    inner join sb_plantilla_haberes_descuentos  as t2  
      on Codigo_Liq = t2.Codigo_Liq_Plantilla && t2.Codigo_HabDes_Plantilla=9	
    inner join sb_plantilla_haberes_descuentos  as t3  
      on Codigo_Liq = t3.Codigo_Liq_Plantilla && t3.Codigo_HabDes_Plantilla=29
    inner join sb_plantilla_haberes_descuentos  as t4  
      on Codigo_Liq = t4.Codigo_Liq_Plantilla && t4.Codigo_HabDes_Plantilla=28	    	  
    inner join sb_plantilla_haberes_descuentos  as t5  
      on Codigo_Liq = t5.Codigo_Liq_Plantilla && t5.Codigo_HabDes_Plantilla=24
	inner join sb_plantilla_haberes_descuentos  as t6  
      on Codigo_Liq = t6.Codigo_Liq_Plantilla && t6.Codigo_HabDes_Plantilla=27
	inner join sb_plantilla_haberes_descuentos  as t7  
      on Codigo_Liq = t7.Codigo_Liq_Plantilla && t7.Codigo_HabDes_Plantilla=30
	inner join sb_plantilla_haberes_descuentos  as t8  
      on Codigo_Liq = t8.Codigo_Liq_Plantilla && t8.Codigo_HabDes_Plantilla=31            		
	inner join sb_plantilla_haberes_descuentos  as t9  
      on Codigo_Liq = t9.Codigo_Liq_Plantilla && t9.Codigo_HabDes_Plantilla=33
	inner join sb_plantilla_haberes_descuentos  as t10  
      on Codigo_Liq = t10.Codigo_Liq_Plantilla && t10.Codigo_HabDes_Plantilla=22                
	inner join sb_afp_lista    
      on sb_afp_lista.Codigo_Afp = Codigo_Afp_Liq 	  
	inner join sb_isapre_lista    
      on sb_isapre_lista.Codigo_Isapre = Codigo_Isapre_Liq 	    
    WHERE Codigo_Empresa_Cont = '".$empresa_global."' and
		  sb_datos_liquidacion.Codigo_Proceso = '".$dbx->id_proceso."' and
          Codigo_Liq= '".$registrototal['Codigo_Liq']."'  ";
	//echo $sql;	    
	
	//and Codigo_Proceso='".$dbx->id_proceso."
	//and Codigo_Empresa_Cont = '".$empresa_global."' ";
	//$consulta_total = $dbx->consulta_free($sql);
	
	
	//exit();
	$consulta = $dbx->consulta_free($sql);
	$registro = $dbx->sb_array($consulta);
   $num_reg=mysqli_num_rows($consulta);
    $texto='';  
    ?>
	<tr>
    	<td>Campo N&deg;&nbsp;1</td>
    	<td>Rut</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Rut'],11, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Rut'],11, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
	<tr>
    	<td>Campo N&deg;&nbsp;2</td>
    	<td>DV</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['DV'],1," ");
			$texto.=str_pad($registro['DV'],1, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;3</td>
    	<td>Apellido Paterno</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Apellido_Paterno_Func'],30," ");
			$texto.=str_pad($registro['Apellido_Paterno_Func'],30, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;4</td>
    	<td>Apellido Paterno</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Apellido_Materno_Func'],30," ");
			$texto.=str_pad($registro['Apellido_Materno_Func'],30, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;5</td>
    	<td>Nombres</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Nombre_Func'],30," ");
			$texto.=str_pad($registro['Nombre_Func'],30, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;6</td>
    	<td>Sexo</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Sexo'],1," ");
			$texto.=str_pad($registro['Sexo'],1, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;7</td>
    	<td>Nacionalidad</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Nacionalidad'],1," ");
			$texto.=str_pad($registro['Nacionalidad'],1, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;8</td>
    	<td>Tipo Pago</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Tipo_Pago'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Tipo_Pago'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;9</td>
    	<td>Periodo Desde</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Periodo_Desde'],6, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Periodo_Desde'],6, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <? 
		//echo str_pad($registro['N10'],6, "0",STR_PAD_LEFT);
		$texto.=str_pad($registro['N10'],6, "0",STR_PAD_LEFT);
	?>
    <tr>
    	<td>Campo N&deg;&nbsp;11</td>
    	<td>Regimen</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Regimen'],3," ");
			$texto.=str_pad($registro['Regimen'],3, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;12</td>
    	<td>Tipo Trabajador</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Tipo_Trab'],1, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Tipo_Trab'],1, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;13</td>
    	<td>Dias</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Dias'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Dias'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;14</td>
    	<td>Tipo Linea</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Tipo_Linea'],2, " ");
			$texto.=str_pad($registro['Tipo_Linea'],2, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;15</td>
    	<td>Cod. Movimiento Personal</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Codigo_Mov_Liq'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Codigo_Mov_Liq'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;16</td>
    	<td>Fecha Desde</td>
        <td>&nbsp;:&nbsp;
			<?
			list($ano, $mes, $dia) = split("[/-]",$registro['Fecha_Inicio_Mov_Liq']); 
			echo str_pad($dia."-".$mes."-".$ano,10," ");
			$texto.=str_pad($dia."-".$mes."-".$ano,10," ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;17</td>
    	<td>Fecha Desde</td>
        <td>&nbsp;:&nbsp;
			<?
			list($ano, $mes, $dia) = split("[/-]",$registro['Fecha_Termino_Mov_Liq']);  
			echo str_pad($dia."-".$mes."-".$ano,10," ");
			$texto.=str_pad($dia."-".$mes."-".$ano,10," ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;18</td>
    	<td>Tramo Asignacion Familiar</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Tramo_Asig_Liq'],1, " ");
			$texto.=str_pad($registro['Tramo_Asig_Liq'],1, " ");
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;19</td>
    	<td>N&deg; Cargas Simples</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Cargas_Norm_Liq'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Cargas_Norm_Liq'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;20</td>
    	<td>N&deg; Cargas Maternas</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Cargas_Mate_Liq'],1, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Cargas_Mate_Liq'],1, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;21</td>
    	<td>N&deg; Cargas Invalidas</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Cargas_Inva_Liq'],1, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Cargas_Inva_Liq'],1, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;22</td>
    	<td>Asignacion Familiar</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Valor_Cargas'],6, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Valor_Cargas'],6, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;23</td>
    	<td>Asignacion Familiar Retroctiva</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Asignacion_retroactiva'],6, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Asignacion_retroactiva'],6, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    	<? 
			//echo str_pad($registro['24'],6, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N24'],6, "0",STR_PAD_LEFT);
		
			//echo str_pad($registro['joven'],1, " ");
			$texto.=str_pad($registro['N25'],1," ");
		?>
    <tr>
    	<td>Campo N&deg;&nbsp;26</td>
    	<td>Codigo de la AFP</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Codigo_Afp'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Codigo_Afp'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;27</td>
    	<td>Renta Imponible</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Total_Imponible_Liq'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Total_Imponible_Liq'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;28</td>
    	<td>Cotizacion Obligatoria AFP</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Afp'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Afp'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;29</td>
    	<td>Cotizacion SIS</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Sis'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Sis'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;30</td>
    	<td>Cuenta de Ahorro Voluntario AFP</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Vol_Afp'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Vol_Afp'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    	<?  
			//echo str_pad($registro['N31'],8,"0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N31'],8,"0",STR_PAD_LEFT);
	 
			//echo str_pad($registro['N32'],5, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N32'],5, "0",STR_PAD_LEFT);
	
			//echo str_pad($registro['N33'],9, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N33'],9, "0",STR_PAD_LEFT);
	
			//echo str_pad($registro['N34'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N34'],2, "0",STR_PAD_LEFT);
		        
			//echo str_pad($registro['N35'],10, " ");
			$texto.=str_pad($registro['N35'],10," ");
		
			//echo str_pad($registro['N36'],10, " ");
			$texto.=str_pad($registro['N36'],10," ");
		
			//echo str_pad($registro['N36'],40, " ");
			$texto.=str_pad($registro['N37'],40," ");
		
			//echo str_pad($registro['N36'],5, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N38'],5, "0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N39'],6, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N39'],6, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
       	<td>Campo N&deg;&nbsp;40</td>
    	<td> Codigo de la Institucion APVI (FALTA)</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Codigo_Ins_Apv'],3, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Codigo_Ins_Apv'],3, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    		<? 
			//echo str_pad($registro['Codigo_Cont_Apv'],20, " ");
			$texto.=str_pad($registro['N41'],20, " ");
			?>
       </td>
    </tr>  
    <tr>
    	<td>Campo N&deg;&nbsp;42</td>
    	<td> Forma de Pago APVI</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Forma_pago_Apv'],1, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Forma_pago_Apv'],1, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;43</td>
    	<td>Cotizacion APVI </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Apv'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Apv'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
			<? 
			//echo str_pad($registro['N44'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N44'],8, "0",STR_PAD_LEFT);
	
			//echo str_pad($registro['N45'],3, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N45'],3, "0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N46'],20, " ");
			$texto.=str_pad($registro['N46'],20," ");
			 
			//echo str_pad($registro['N47'],1, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N47'],1, "0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N48'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N48'],8,"0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N49'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N49'],8, "0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N50'],11, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N50'],11, "0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N51'],1, " ");
			$texto.=str_pad($registro['N51'],1," ");
			 
			//echo str_pad($registro['N52'],30," ");
			$texto.=str_pad($registro['N52'],30," ");
			 
			//echo str_pad($registro['N53'],30," ");
			$texto.=str_pad($registro['N53'],30," ");
			 
			//echo str_pad($registro['N54'],30, " ");
			$texto.=str_pad($registro['N54'],30," ");
			 
			//echo str_pad($registro['N55'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N55'],2, "0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N56'],10, " ");
			$texto.=str_pad($registro['N56'],10," ");
			 
			//echo str_pad($registro['N57'],10, " ");
			$texto.=str_pad($registro['N57'],10," ");
			 
			//echo str_pad($registro['N58'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N58'],2,"0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N59'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N59'],8,"0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N60'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N60'],8,"0",STR_PAD_LEFT);
			 
			//echo str_pad($registro['N61'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N61'],2,"0",STR_PAD_LEFT);
			?>
    <tr>
    	<td>Campo N&deg;&nbsp;62</td>
    	<td>Codigo Ex-Caja Regimen </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Codigo_Ex_caja'],4, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Codigo_Ex_caja'],4, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;63</td>
    	<td>Tasa Cotizacion Ex-Caja Prevision </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Por_Ex_caja'],5, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Por_Ex_caja'],5, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;64</td>
    	<td>Renta Imponible IPS </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Total_Imponible_Ips'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Total_Imponible_Ips'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;65</td>
    	<td>Cotizacion IPS </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Ips'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Ips'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    	<? 
			$texto.=str_pad($registro['N66'],8, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N67'],4, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N68'],5, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N69'],8, "0",STR_PAD_LEFT);
		?>
	<tr>
    	<td>Campo N&deg;&nbsp;70</td>
    	<td>Cotizacion Fonasa </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Salud_Fonsa'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Salud_Fonsa'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;71</td>
    	<td>Cotizacion Acc Trabajo (ILS) </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Acc'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Acc'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
   			<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
			?>
    <tr>
    	<td>Campo N&deg;&nbsp;73</td>
    	<td>Descuento por cargas familiares de ISL </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Valor_Cargas_ISL'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Valor_Cargas_ISL'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
			<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N74'],8, "0",STR_PAD_LEFT);
			?>
	<tr>
    	<td>Campo N&deg;&nbsp;75</td>
    	<td>Codigo Institucion de Salud </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Codigo_Isapre'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Codigo_Isapre'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
			<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N76'],16, " ");
			?>
	<tr>
    	<td>Campo N&deg;&nbsp;77</td>
    	<td>Renta Imponible Isapre </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Total_Imponible_Salud'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Total_Imponible_Salud'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;78</td>
    	<td>Moneda del plan pactado Isapre </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Tipo_Pactado_Liq'],1, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Tipo_Pactado_Liq'],1, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;79</td>
    	<td>Cotizacion Pactada </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Valor_Pactado_Liq'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Valor_Pactado_Liq'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;80</td>
    	<td>Cotizacion Obligatoria Isapre </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Salud2'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Salud2'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;81</td>
    	<td>Cotizacion Adicional Voluntaria </td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Adic_Isapre'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Adic_Isapre'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
		<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N82'],8, "0",STR_PAD_LEFT);
		?>
    <tr>
    	<td>Campo N&deg;&nbsp;83</td>
    	<td>Codigo CCAF</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Codigo_caja'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Codigo_caja'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;84</td>
    	<td>Renta Imponible CCAF</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Renta_Imp_Cccaf'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Renta_Imp_Cccaf'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>        
		<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['N85'],8, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N86'],8, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N87'],8, "0",STR_PAD_LEFT);
		?>
	<tr>
    	<td>Campo N&deg;&nbsp;88</td>
    	<td>Descuento Seguro de Vida CCAF</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Seguro_Vida_CCAF'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Seguro_Vida_CCAF'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>        
		<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
		
			$texto.=str_pad($registro['N89'],8, "0",STR_PAD_LEFT);
		?>
	<tr>
    	<td>Campo N&deg;&nbsp;90</td>
    	<td>Cotizacion a CCAF no afliados a isapres</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Cotizacion_Ccaf'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Cotizacion_Ccaf'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;91</td>
    	<td>Descuento Cargas Familiares CCAF</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Desc_Ccaf'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Desc_Ccaf'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>                
		<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
		
			$texto.=str_pad($registro['N92'],8, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N93'],8, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N94'],8, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N95'],20, " ");
		?>
	<tr>
    	<td>Campo N&deg;&nbsp;96</td>
    	<td>Codigo Mutualidad</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['codigo_mutual'],2, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['codigo_mutual'],2, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>                
	<tr>
    	<td>Campo N&deg;&nbsp;97</td>
    	<td>Renta Imponible Mutual</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Renta_Imp_Mutual'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Renta_Imp_Mutual'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>
    <tr>
    	<td>Campo N&deg;&nbsp;98</td>
    	<td>Cotizacion Accidente de Trabajo Mutual</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Renta_Imp_Mutual'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Renta_Imp_Mutual'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>                                
		<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
		
			$texto.=str_pad($registro['N99'],3, "0",STR_PAD_LEFT);
		?>
    <tr>
    	<td>Campo N&deg;&nbsp;100</td>
    	<td>Renta Imponible Seguro Cesntia</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Imp_SC'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Imp_SC'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>                                    
	<tr>
    	<td>Campo N&deg;&nbsp;101</td>
    	<td>Aporte Trabajador Seguro Cesantia</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Aporte_Trab'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Aporte_Trab'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>                                    
    <tr>
    	<td>Campo N&deg;&nbsp;102</td>
    	<td>Aporte Empleador Seguro Cesantia</td>
        <td>&nbsp;:&nbsp;
			<? 
			echo str_pad($registro['Aporte_Empre'],8, "0",STR_PAD_LEFT);
			$texto.=str_pad($registro['Aporte_Empre'],8, "0",STR_PAD_LEFT);
			?>
       </td>
    </tr>                                    
		<? 
			//echo str_pad($registro['N72'],8, "0",STR_PAD_LEFT);
		
			$texto.=str_pad($registro['N103'],11, "0",STR_PAD_LEFT);
			
			$texto.=str_pad($registro['N104'],1, " ");
			
			$texto.=str_pad($registro['N105'],20, " ");
		
		?>
	
	
	
    
    
</table>
<?  
    //echo strlen($texto).":".$texto;

}
//$cadena="00013155612|8|TORRES                        |TRONCOSO                      |MAURICIO IVAN                 |M|1|01|072010|000000|AFP|0|30|00|00|00-00-0000|00-00-0000| |00|0|0|000000|000000|000000| |08|00215000|00029305|00000000|00000000|00000000|00,00|000000000|00|          |          |                                        |00,00|000000|000|                    |0|00000000|00000000|000|                    |0|00000000|00000000|00000000000| |                              |                              |                              |00|          |          |00|00000000|00000000|00|0000|00,00|00215000|00000000|00000000|0000|00,00|00000000|00015050|00002042|00000000|00000000|00000000|00|                |00000000|0|00000000|00000000|00000000|00000000|00|00000000|00000000|00000000|00000000|00000000|00000000|00000000|00000000|00000000|00000000|00000000|                    |00|00000000|00000000|000|00215000|00001290|00005160|00000000000| |                    ";

//$archivo = split('[|]', $cadena);//explode('|',$cadena);
//echo count($archivo)."------";
//for($i=0;$i<count($archivo);$i++){
//echo "campo ".($i+1)." numero :".strlen($archivo[$i])." valor :".$archivo[$i]."<br>";
//}

?>
</body>
</html>
