<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Personas</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />

</head>
<?php
include "../../conn.php";
include "../../general.php";
include "../../token.php";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$persona=$_POST["persona"];
$genero=$_POST["genero"];
$ciudad=$_POST["ciudad"];
$cargo=$_POST["cargo"];
$empleado=$_POST["empleado"];
$vende=$_POST["vende"];
$activo=$_POST["activo"];
$sucursal=$_POST["sucursal"];
$nacimiento=$_POST["nacimiento"];
$fechaini_nac=$_POST["fechaini_nac"];
$fechafin_nac=$_POST["fechafin_nac"];
$fechaini_cont=$_POST["fechaini_cont"];
$fechafin_cont=$_POST["fechafin_cont"];
$orden=$_POST["orden"];
//$usuario=$_POST["usuario"];

$cod_alt_ver=$_POST["cod_alt_ver"];
$ciudad_ver=$_POST["ciudad_ver"];
$genero_ver=$_POST["genero_ver"];
$web_ver=$_POST["web_ver"];
$casilla_ver=$_POST["casilla_ver"];
$nacimiento_ver=$_POST["nacimiento_ver"];
$fechanac_ver=$_POST["fechanac_ver"];
$fechacont_ver=$_POST["fechacont_ver"];
$estcivil_ver=$_POST["estcivil_ver"];
$contrato_ver=$_POST["contrato_ver"];
$tipoemp_ver=$_POST["tipoemp_ver"];
$salario_ver=$_POST["salario_ver"];
$tiempotrab_ver=$_POST["tiempotrab_ver"];
$codcaja_ver=$_POST["codcaja_ver"];
$nua_ver=$_POST["nua_ver"];
$edadjub_ver=$_POST["edadjub_ver"];
$descuentos_ver=$_POST["descuentos_ver"];
$cursos_ver=$_POST["cursos_ver"];
$dependientes_ver=$_POST["dependientes_ver"];
$documentos_ver=$_POST["documentos_ver"];
$idiomas_ver=$_POST["idiomas_ver"];
$direccion_ver=$_POST["direccion_ver"];
$email_ver=$_POST["email_ver"];
$telefono_ver=$_POST["telefono_ver"];
$comisiones_ver=$_POST["comisiones_ver"];
$conceptos_ver=$_POST["conceptos_ver"];

$nro_per = 5;

if($fechaini_nac == '0000-00-00') { $fechaini_nac = '1900-01-01'; }
if($fechafin_nac == '0000-00-00') { $fechafin_nac = '2999-12-31'; }

if($fechaini_cont == '0000-00-00') { $fechaini_cont = '1900-01-01'; }
if($fechafin_cont == '0000-00-00') { $fechafin_cont = '2999-12-31'; }
//$n_decimales = 6;
//echo $tipoventa;
?>
<body>
<?php


//Inicio reporte personas

if($rep == 13 && $tipo == 1) { // if 2

  	if ($persona == 0) { // if 2.0
		$nom_persona = 'Todos';
		$valor_persona= ' ';
	} else {
		//nombre persona
		$result2 = mysqli_query($link, "select pkyPerson as codigo, case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end as persona
								from
								agnPerson 
								where
								pkyPerson = '$persona' and
								sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result2)) {
			$nom_persona = $row['persona'];
		}
		mysqli_free_result($result2);
		$valor_persona = ' a.pkyPerson = ' .$persona. ' and ';
	} //fin if 2.0
	
	
	if ($genero == 0) { // if 2.2
		$nom_genero = 'Todos';
		$valor_genero = ' ';
	} else {
		//nombre genero
		$result3 = mysqli_query($link, "select pkyGender as cod_gen, fldName as genero
							    from 
							    agnGender
							    where
							    pkyGender = '$genero' and 
							    sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result3)) {
			$nom_genero = $row['genero'];
		}
		mysqli_free_result($result3);
		$valor_genero = ' a.codGender = ' .$genero. ' and ';
	} //fin if 2.2
	
	
	if ($ciudad == 0) { // if 2.4
		$nom_ciudad = 'Todos';
		$valor_ciudad = ' ';
	} else {
		//nombre ciudad
		$result4 = mysqli_query($link, "select a.pkyCity as cod_ciu, a.fldName as ciudad, b.fldName as pais
							    from 
								regCity a, regCountry b
								where
								a.pkyCity = '$ciudad' and 
								a.codCountry = b.pkyCountry and 
								a.sysEnabled = 1 and a.sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result4)) {
			$nom_ciudad = $row['ciudad'].' - '.$row['pais'];
		}
		mysqli_free_result($result4);
		$valor_ciudad = ' a.codCityLocation = ' .$ciudad. ' and ';
	} //fin if 2.4
	
	if ($cargo == 0) { // if 2.5
		$nom_cargo = 'Todos';
		$valor_cargo = ' ';
	} else {
		//nombre cargo
		$result5 = mysqli_query($link, "select pkyJob as cod_cargo, fldName as cargo
								from 
								hrsJob
								where
								pkyJob = '$cargo' and 
								sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result5)) {
			$nom_cargo = $row['cargo'];
		}
		mysqli_free_result($result5);
		$valor_cargo = ' a.codJob = ' .$cargo. ' and ';
	} //fin if 2.5
	
		
	if ($empleado == -1) { // if 2.7
		$nom_empleado = 'Todos';
		$valor_empleado = ' ';
	} //fin if 2.7
	if ($empleado == 1) { // if 2.8
		$nom_empleado = 'Si';
		$valor_empleado = ' a.fldIsEmployee = 1 and ';
	} //fin if 2.8
	if ($empleado == 0) { // if 2.9
		$nom_empleado = 'No';
		$valor_empleado = ' a.fldIsEmployee = 0 and ';
	} //fin if 2.9
	
	
	if ($vende == -1) { // if 2.10
		$nom_vende = 'Todos';
		$valor_vende = ' ';
	} //fin if 2.10
	if ($vende == 1) { // if 2.11
		$nom_vende = 'Si';
		$valor_vende = ' a.fldCanSell = 1 and ';
	} //fin if 2.11
	if ($vende == 0) { // if 2.12
		$nom_vende = 'No';
		$valor_vende = ' a.fldCanSell = 0 and ';
	} //fin if 2.12
	
	if ($activo == -1) { // if 2.133
		$nom_activo = 'Todos';
		$valor_activo = ' ';
	} //fin if 2.133
	if ($activo == 1) { // if 2.144
		$nom_activo = 'Si';
		$valor_activo = ' a.fldActive = 1 and ';
	} //fin if 2.144
	if ($activo == 0) { // if 2.155
		$nom_activo = 'No';
		$valor_activo = ' a.fldActive = 0 and ';
	} //fin if 2.155
	
	
	if ($sucursal == 0) { // if 2.133
		$nom_sucursal = 'Todos';
		$valor_sucursal = ' ';
	} else {
		//nombre sucursal
		$result4 = mysqli_query($link, "select a.pkyCompanyBranch as cod_suc, a.fldName as suc, a.fldID as id, b.fldName as ciudad
								from 
								agnCompanyBranch a, regCity b 
								where 
								a.pkyCompanyBranch = '$sucursal' and 
								a.codCompany = 2 and 
								a.codCity = b.pkyCity and 
								a.sysEnabled = 1 and a.sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result4)) {
			$nom_sucursal = $row['suc'].' - '.$row['id'].' - '.$row['ciudad'];
		}
		mysqli_free_result($result4);
		$valor_sucursal = ' a.codBranch = ' .$sucursal. ' and ';
	} //fin if 2.133
	
	
	if ($nacimiento == 0) { // if 2.13
		$nom_nacimiento = 'Todos';
		$valor_nacimiento = ' ';
	} else {
		//nombre ciudad de nacimiento
		$result4 = mysqli_query($link, "select a.pkyCity as cod_ciu, a.fldName as ciudad, b.fldName as pais
							    from 
								regCity a, regCountry b
								where
								a.pkyCity = '$nacimiento' and 
								a.codCountry = b.pkyCountry and 
								a.sysEnabled = 1 and a.sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result4)) {
			$nom_nacimiento = $row['ciudad'].' - '.$row['pais'];
		}
		mysqli_free_result($result4);
		$valor_nacimiento = ' a.codBirthCity = ' .$nacimiento. ' and ';
	} //fin if 2.13
	
	
	if ($orden == 0) { // if 2.11
		$nom_orden = 'Apellido';
		$valor_orden = ' order by a.fldLastName ';
	} //fin if 2.11
	if ($orden == 1) { // if 2.12
		$nom_orden = 'G&eacute;nero';
		$valor_orden = ' order by a.codGender, a.fldLastName ';
	} //fin if 2.12
	if ($orden == 2) { // if 2.13
		$nom_orden = 'Fecha de nacimiento';
		$valor_orden = ' order by a.fldBirthDate, a.fldLastName ';
	} //fin if 2.13
	if ($orden == 3) { // if 2.14
		$nom_orden = 'Fecha de contrataci&oacute;n';
		$valor_orden = ' order by a.fldHiringDate, a.fldLastName ';
	} //fin if 2.14
	
	
	
//listado personas
$result = mysqli_query($link, "select pkyPerson as codigo, case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end as persona, a.codGender as cod_genero, a.codCityLocation as cod_ciu, b.fldName as ciudad, a.fldWebSite as sitio_web, a.fldZipCode as casilla, a.fldAlternativeKey as cod_alt, a.fldIsEmployee as empleado, a.codJob as cod_job, a.codBirthCity as cod_ciu_nac, a.fldBirthDate as fecha_nac, a.fldHiringDate as fecha_cont, a.fldCanSell as vende, a.fldActive as activo, c.fldName as estado_civil, a.codDocumentNumber as cod_contrato, d.fldName as tipo_emp, a.fldBasicSalary as salario, a.fldMinimumUnit as tiempo_trab, a.fldHealthFundCode as cod_caja, a.fldRetirementPensionCode as nua, a.fldRetirementAge as edad_jub
from 
agnPerson a, regCity b, agnMaritalStatus c, agnEmployeeType d
where
$valor_persona
$valor_genero
$valor_ciudad
$valor_cargo 
$valor_empleado 
$valor_vende 
$valor_activo 
$valor_nacimiento 
$valor_sucursal 
a.fldBirthDate >= '$fechaini_nac' and 
a.fldBirthDate <= '$fechafin_nac' and
a.fldHiringDate >= '$fechaini_cont' and 
a.fldHiringDate <= '$fechafin_cont' and
a.codCityLocation = b.pkyCity and 
a.codMaritalStatus = c.pkyMaritalStatus and 
a.codEmployeeType = d.pkyEmployeeType  and 
a.sysEnabled = 1 and a.sysAuthorized = 1   
$valor_orden;");


//listado genero
$result2 = mysqli_query($link, "select pkyGender as cod_gen, fldName as genero
from
agnGender
where
sysEnabled = 1 and sysAuthorized = 1;");

$matriz_gen = array();
$i = 1;
while ($row = mysqli_fetch_array($result2)) {
	$matriz_gen [$i][1] = $row['cod_gen'];
	$matriz_gen [$i][2] = $row['genero'];
	$i++;
}
$fin_gen = $i - 1;
mysqli_free_result($result2);

//listado ciudad
$result3 = mysqli_query($link, "select a.pkyCity as cod_ciu, a.fldName as ciudad, b.fldName as pais
from 
regCity a, regCountry b
where 
a.codCountry = b.pkyCountry and 
a.sysEnabled = 1 and a.sysAuthorized = 1;");

$matriz_ciu = array();
$i = 1;
while ($row = mysqli_fetch_array($result3)) {
	$matriz_ciu [$i][1] = $row['cod_ciu'];
	$matriz_ciu [$i][2] = $row['ciudad'];
	$i++;
}
$fin_ciu = $i - 1;
mysqli_free_result($result3);

//listado cargo
$result4 = mysqli_query($link, "select pkyJob as cod_cargo, fldName as cargo
from 
hrsJob 
where
sysEnabled = 1 and sysAuthorized = 1;");

$matriz_cargo = array();
$i = 1;
while ($row = mysqli_fetch_array($result4)) {
	$matriz_cargo [$i][1] = $row['cod_cargo'];
	$matriz_cargo [$i][2] = $row['cargo'];
	$i++;
}
$fin_cargo = $i - 1;
mysqli_free_result($result4);

//listado comisiones
$result5 = mysqli_query($link, "select distinct codEmployee as comision 
from hrsSalesCommission 
where
sysEnabled = 1 and sysAuthorized = 1;");

$matriz_comisiones = array();
$i = 1;
while ($row = mysqli_fetch_array($result5)) {
	$matriz_comisiones [$i][1] = $row['comision'];
	$i++;
}
$fin_comisiones = $i - 1;
mysqli_free_result($result5);

$matriz_per = array();
$i = 1;
while ($row = mysqli_fetch_array($result)) {
	$matriz_per [$i][1] = $row['codigo'];
	$matriz_per [$i][2] = $row['persona'];
	//$matriz_per [$i][3] = $row['ap_mat'];
	//$matriz_per [$i][4] = $row['nombre'];
	$matriz_per [$i][5] = $row['cod_genero'];
	
	for($j = 1; $j <= $fin_gen; $j++) {
		if($row['cod_genero'] == $matriz_gen [$j][1]) {
			$matriz_per [$i][6] = $matriz_gen [$j][2];
		}
	}
	
	$matriz_per [$i][7] = $row['cod_ciu'];
	$matriz_per [$i][8] = $row['ciudad'];
	$matriz_per [$i][9] = $row['sitio_web'];
	$matriz_per [$i][10] = $row['casilla'];
	$matriz_per [$i][11] = $row['cod_alt'];
	$matriz_per [$i][12] = $row['empleado'];
	if($row['empleado'] == 0) {
		$matriz_per [$i][13] = 'No';
	} else {
		$matriz_per [$i][13] = 'Si';
	}
	$matriz_per [$i][14] = $row['cod_job'];
	
	for($j = 1; $j <= $fin_cargo; $j++) {
		if($row['cod_job'] == $matriz_cargo [$j][1]) {
			$matriz_per [$i][15] = $matriz_cargo [$j][2];
		}
	}
	
	$matriz_per [$i][16] = $row['cod_ciu_nac'];
	
	for($j = 1; $j <= $fin_ciu; $j++) {
		if($row['cod_ciu_nac'] == $matriz_ciu [$j][1]) {
			$matriz_per [$i][17] = $matriz_ciu [$j][2];
		}
	}
	
	$matriz_per [$i][18] = $row['fecha_nac'];
	$matriz_per [$i][19] = $row['fecha_cont'];
	$matriz_per [$i][20] = $row['vende'];
	
	if($row['vende'] == 0) {
		$matriz_per [$i][21] = 'No';
	} else {
		$matriz_per [$i][21] = 'Si';
	}
	
	for($j = 1; $j <= $fin_comisiones; $j++) {
		if($row['codigo'] == $matriz_comisiones [$j][1]) {
			$matriz_per [$i][22] = 'Si';
		}
	}
	
	$matriz_per [$i][23] = $row['estado_civil'];
	
	if($row['activo'] == 0) {
		$matriz_per [$i][24] = 'No';
	} else {
		$matriz_per [$i][24] = 'Si';
	}
	
	$matriz_per [$i][25] = $row['cod_contrato'];
	$matriz_per [$i][26] = $row['tipo_emp'];
	$matriz_per [$i][27] = $row['salario'];
	
	if($row['tiempo_trab'] == 0) {
		$matriz_per [$i][28] = 'D&iacute;a';
	} else {
		$matriz_per [$i][28] = 'Hora';
	}
	
	$matriz_per [$i][29] = $row['cod_caja'];
	$matriz_per [$i][30] = $row['nua'];
	$matriz_per [$i][31] = $row['edad_jub'];
	
	$i++;
}
$fin = $i - 1;
mysqli_free_result($result);


?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Listado de Personas</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="25%"><b>Persona: </b><?php echo $nom_persona; ?></TD>
        <TD width="25%"><b>G&eacute;nero: </b><?php echo $nom_genero; ?></TD>
        <TD width="25%"><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        <TD width="25%"><b>Ciudad: </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR>
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Autorizado a Vender: </b><?php echo $nom_vende; ?></TD>
        <TD><b>Activo: </b><?php echo $nom_activo; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        
        <TD colspan="2"><b>Lugar de Nacimiento: </b><?php echo $nom_nacimiento; ?></TD>
        <TD colspan="2"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TR>
        <TD><b>De Fecha de Nacimiento: </b><?php echo $fechaini_nac; ?></TD>
        <TD><b>A Fecha de Nacimiento: </b><?php echo $fechafin_nac; ?></TD>
        <TD><b>De Fecha de Contrataci&oacute;n: </b><?php echo $fechaini_cont; ?></TD>
        <TD><b>A Fecha de Contrataci&oacute;n: </b><?php echo $fechafin_cont; ?></TD>
        </TR>
    </table>

</td>
<!--
<td valign="top" width="150">

    <table border="1" align="center" cellpadding="2" width="100%">
    <tr>
    <TD><b>Tipo de Cambio:</b></TD>
    </tr><tr>
    <TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $ultimo_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $ultimo_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
        <table border="0" cellpadding="2" align="center">
            <?php
            for($m = 1; $m <= $fin_m; $m++) {
            printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
            printf("<td align='center'>%s</td>", ' = ');//letra a
            printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
            //printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
            }
            ?>
        </table>
    </TD>
    </tr>
	</table>
    
</td>
-->
</tr>
</table>
<br /> 
<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>Cod.</b></TD>
    <?php if($cod_alt_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Cod. Alt.</b></TD>
    <?php } ?>
    <TD align="center"><b>Persona</b></TD>
    <TD align="center"><b>Cargo</b></TD>
    <?php if($genero_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>G&eacute;nero</b></TD>
    <?php } ?>
    <TD align="center"><b>Empleado</b></TD>
    <TD align="center"><b>Vende</b></TD>
    <TD align="center"><b>Activo</b></TD>
    <?php if($ciudad_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Ciudad</b></TD>
    <?php } ?>
    <?php if($web_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Sitio Web</b></TD>
    <?php } ?>
    <?php if($casilla_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Casilla</b></TD>
    <?php } ?>
    <?php if($nacimiento_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Ciudad Nac.</b></TD>
    <?php } ?>
    <?php if($fechanac_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Fecha Nac.</b></TD>
    <?php } ?>
    <?php if($estcivil_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Estado Civil</b></TD>
    <?php } ?>
    <?php if($fechacont_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Fecha Cont.</b></TD>
    <?php } ?>
    <?php if($contrato_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Cod. Alta</b></TD>
    <?php } ?>
    <?php if($tipoemp_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Tipo Empleado</b></TD>
    <?php } ?>
    <?php if($salario_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Sueldo B&aacute;sico</b></TD>
    <?php } ?>
    <?php if($tiempotrab_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Tiempo Trabajo</b></TD>
    <?php } ?>
    <?php if($codcaja_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Cod. Caja Salud</b></TD>
    <?php } ?>
    <?php if($nua_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Cod. Fondo Pensiones</b></TD>
    <?php } ?>
    <?php if($edadjub_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Edad Jubilaci&oacute;n</b></TD>
    <?php } ?>
    <?php if($descuentos_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Dctos. Fijos AFP</b></TD>
    <?php } ?>
    <?php if($cursos_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Cursos</b></TD>
    <?php } ?>
    <?php if($dependientes_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Dependientes</b></TD>
    <?php } ?>
    <?php if($documentos_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Documentos</b></TD>
    <?php } ?>
    <?php if($idiomas_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Idiomas</b></TD>
    <?php } ?>
    <?php if($direccion_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Direcci&oacute;n</b></TD>
    <?php } ?>
    <?php if($email_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>E-Mail</b></TD>
    <?php } ?>
    <?php if($telefono_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Tel.</b></TD>
    <?php } ?>
    <?php if($comisiones_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Comisiones</b></TD>
    <?php } ?>
    <?php if($conceptos_ver == 1) { $nro_per++; ?>
    <TD align="center"><b>Conceptos Gasto</b></TD>
    <?php } ?>
    </TR>
	</thead>
    <tbody class="marcafila">
  <?php
  $color = 2;
     
  $j = 1;
  while ($j <= $fin) { //while
  	$cod_persona = $matriz_per [$j][1];
	$cod_contrato = $matriz_per [$j][25];
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_persona&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_per [$j][1]);//cod per
	} else {
	printf("<tr><td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_persona&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_per [$j][1]);//cod per
	}//fin if color
	if($cod_alt_ver == 1) {
	printf("<td align='center'>%s</td>", $matriz_per [$j][11]);//cod alt
	}
	printf("<td align='left'>%s</td>", $matriz_per [$j][2]);//persona
	printf("<td align='left'>%s</td>", $matriz_per [$j][15]);//cargo
	if($genero_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][6]);//genero
	}
	printf("<td align='center'>%s</td>", $matriz_per [$j][13]);//empleado
	printf("<td align='center'>%s</td>", $matriz_per [$j][21]);//vende
	printf("<td align='center'>%s</td>", $matriz_per [$j][24]);//activo
	if($ciudad_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][8]);//ciudad
	}
	if($web_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][9]);//sitio web
	}
	if($casilla_ver == 1) {
	printf("<td align='right'>%s</td>", $matriz_per [$j][10]);//casilla
	}
	if($nacimiento_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][17]);//ciudad de nacimiento
	}
	if($fechanac_ver == 1) {
	printf("<td align='center'>%s</td>", $matriz_per [$j][18]);//fecha nacimiento
	}
	if($estcivil_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][23]);//estado civil
	}
	if($fechacont_ver == 1) {
	printf("<td align='center'>%s</td>", $matriz_per [$j][19]);//fecha contrato
	}
	
	
	if($contrato_ver == 1) {//if alta contrato
	$contrato = NULL;
	//alta contrato
	$result5 = mysqli_query($link, "select a.pkyEmployeeMovement as cod_mov, a.fldDocumentNumber as contrato
	from 
	hrsEmployeeMovement a
	where 
	a.pkyEmployeeMovement = '$cod_contrato';");
	
	while ($row = mysqli_fetch_array($result5)) {
		$contrato = $row['contrato'];
	}
	mysqli_free_result($result5);
	printf("<td align='left'><a href='../../ModuleHumanResources/VoucherEmployeeMovement/index.php?pkyEmployeeMovement=$cod_contrato&user=$usuario&token=$token' title='Nota de Movimiento de Empleado'>%s</a>-%s</td>", $cod_contrato, $contrato);//alta contrato
	}//fin if alta contrato
	
	if($tipoemp_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][26]);//tipo empleado
	}
	if($salario_ver == 1) {
	printf("<td align='right'>%s</td>", number_format($matriz_per [$j][27], 2));//salario
	}
	if($tiempotrab_ver == 1) {
	printf("<td align='left'>%s</td>", $matriz_per [$j][28]);//tipo empleado
	}
	if($codcaja_ver == 1) {
	printf("<td align='right'>%s</td>", $matriz_per [$j][29]);//cod caja
	}
	if($nua_ver == 1) {
	printf("<td align='right'>%s</td>", $matriz_per [$j][30]);//nua
	}
	if($edadjub_ver == 1) {
	printf("<td align='right'>%s</td>", $matriz_per [$j][31]);//edad jubilacion
	}

		
	if($descuentos_ver == 1) {//if descuentos
	echo "<td>";
	//descuentos
	$result5 = mysqli_query($link, "select a.pkyDiscountException as cod_desc, a.codFixedDiscount as cod_df, b.fldName as descuento 
	from 
	hrsDiscountException a, hrsFixedDiscounts b
	where 
	a.codFixedDiscount = b.pkyFixedDiscounts and 
	a.codEmployee = '$cod_persona'  
	order by b.fldName;");
	
	echo "<table border='0' width='200'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td></tr>", $row['descuento']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if descuentos
	
	
	if($cursos_ver == 1) {//if cursos
	echo "<td>";
	//cursos
	$result5 = mysqli_query($link, "select a.pkyEmployeeCourse as cod_curso, a.fldCourse as curso
	from 
	hrsEmployeeCourse a
	where 
	a.codPerson = '$cod_persona'  
	order by a.fldCourse;");
	
	echo "<table border='0' width='200'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td></tr>", $row['curso']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if cursos
	
	
	if($dependientes_ver == 1) {//if dependientes
	echo "<td>";
	//dependientes
	$result5 = mysqli_query($link, "select a.pkyEmployeeDependent as cod_dep, case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName) end as dependiente 
	from 
	hrsEmployeeDependent a, agnPerson b
	where 
	a.codDependent = b.pkyPerson and 
	a.codPerson = '$cod_persona'  
	order by dependiente;");
	
	echo "<table border='0' width='200'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td></tr>", $row['dependiente']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if dependientes


	if($documentos_ver == 1) {//if documentos
	echo "<td>";
	//documentos
	$result5 = mysqli_query($link, "select a.pkyEmployeeDocument as cod_doc, b.fldName as documento, a.fldNumber as numero, c.fldName as ciudad 
	from 
	hrsEmployeeDocument a, agnIdentityDocumentType b, regCity c
	where 
	a.codIdentityDocumentType = b.pkyIdentityDocumentType and 
	a.codCity = c.pkyCity and 
	a.codPerson = '$cod_persona'  
	order by b.fldName, a.fldNumber, c.fldName;");
	
	echo "<table border='0' width='100%'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td>", $row['documento']);
		printf("<td align='right' valign='top'>%s</td>", $row['numero']);
		printf("<td align='right' valign='top'>(%s)</td></tr>", $row['ciudad']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if documentos
	
	
	if($idiomas_ver == 1) {//if idiomas
	echo "<td>";
	//idiomas
	$result5 = mysqli_query($link, "select a.pkyEmployeeLanguage as cod_idi, b.fldName as idioma
	from 
	hrsEmployeeLanguage a, regLanguage b
	where 
	a.codLanguage = b.pkyLanguage and 
	a.codPerson = '$cod_persona'  
	order by b.fldName;");
	
	echo "<table border='0' width='100%'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td></tr>", $row['idioma']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if idiomas
	
	
	if($direccion_ver == 1) {//if direccion
	echo "<td>";
	//direccion
	$result5 = mysqli_query($link, "select a.pkyPersonAddress as cod_dir, a.fldAddress as direccion, b.fldName as tipo 
	from 
	agnPersonAddress a, agnAddressType b
	where 
	a.codType = b.pkyAddressType and 
	a.codPerson = '$cod_persona'  
	order by a.fldDefault desc, a.fldAddress;");
	
	echo "<table border='0' width='100%'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td>", $row['direccion']);
		printf("<td align='right' valign='top'>(%s)</td></tr>", $row['tipo']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if direccion
	
	
	if($email_ver == 1) {//if email
	echo "<td>";
	//email
	$result5 = mysqli_query($link, "select a.pkyPersonMail as cod_mail, a.fldMail as mail, b.fldName as tipo 
	from 
	agnPersonMail a, agnMailType b
	where 
	a.codType = b.pkyMailType and 
	a.codPerson = '$cod_persona'  
	order by a.fldDefault desc, a.fldMail;");
	
	echo "<table border='0' width='100%'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td>", $row['mail']);
		printf("<td align='right' valign='top'>(%s)</td></tr>", $row['tipo']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if mail
	
	
	if($telefono_ver == 1) {//if telefono
	echo "<td>";
	//telefono
	$result5 = mysqli_query($link, "select a.pkyPersonPhone as cod_tel, a.fldPhone as telefono, b.fldName as tipo 
	from 
	agnPersonPhone a, agnPhoneType b
	where 
	a.codType = b.pkyPhoneType and 
	a.codPerson = '$cod_persona'  
	order by a.fldDefault desc, a.fldPhone;");
	
	echo "<table border='0' width='100%'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'>%s</td>", $row['telefono']);
		printf("<td align='right' valign='top'>(%s)</td></tr>", $row['tipo']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if telefono
	
	if($comisiones_ver == 1) {
	printf("<td align='center'>%s</td>", $matriz_per [$j][22]);//comisiones
	}
	
	if($conceptos_ver == 1) {//if conceptos gasto
	echo "<td>";
	//conceptos gasto
	$result5 = mysqli_query($link, "select h1.fldName as con_gastos_sueldos_x_pagar, h2.fldName as con_gasto_aguinaldo_2, h3.fldName as con_gasto_aguinaldo, h4.fldName as con_gasto_indem, h5.fldName as con_gasto_ap_pat, h6.fldName as con_gasto_reintegro, 
h7.fldName as con_gasto_hrs_extra, h8.fldName as con_gasto_hrs_recargo, h9.fldName as con_gasto_hrs_domingo, h10.fldName as con_gasto_hrs_extraor, h11.fldName as con_gasto_hrs_feriado, h12.fldName as con_gasto_bono_ant
from
agnPerson a, payExpensesConcept h1, payExpensesConcept h2, payExpensesConcept h3, payExpensesConcept h4, payExpensesConcept h5, payExpensesConcept h6, payExpensesConcept h7, payExpensesConcept h8, payExpensesConcept h9, payExpensesConcept h10, payExpensesConcept h11, payExpensesConcept h12
where
a.pkyPerson = '$cod_persona' and  
a.codWagesExpenseConcept = h1.pkyExpensesConcept and 
a.codSecondBonusExpenseConcept = h2.pkyExpensesConcept and  
a.codBonusExpenseConcept = h3.pkyExpensesConcept and  
a.codCompensationExpenseConcept = h4.pkyExpensesConcept and  
a.codEmployerContributionsExpenseConcept = h5.pkyExpensesConcept and  
a.codSalaryReimbursementExpenseConcept = h6.pkyExpensesConcept and 
a.codExtraHoursExpenseConcept = h7.pkyExpensesConcept and 
a.codChargeHoursExpenseConcept = h8.pkyExpensesConcept and 
a.codSundayHoursExpenseConcept = h9.pkyExpensesConcept and
a.codExtraordinaryHoursExpenseConcept = h10.pkyExpensesConcept and 
a.codHolidayHoursExpenseConcept = h11.pkyExpensesConcept and 
a.codSeniorityExpenseConcept = h12.pkyExpensesConcept;");
	
	echo "<table border='0' width='300'>";
	$i = 1;
	while ($row = mysqli_fetch_array($result5)) {
		printf("<tr><td align='left' valign='top'><b>Sueldos x Pagar:</b> %s</td></tr>", $row['con_gastos_sueldos_x_pagar']);
		printf("<tr><td align='left' valign='top'><b>Indemnizaci&oacute;n:</b> %s</td></tr>", $row['con_gasto_indem']);
		printf("<tr><td align='left' valign='top'><b>Reintegro:</b> %s</td></tr>", $row['con_gasto_reintegro']);
		printf("<tr><td align='left' valign='top'><b>Horas Extra:</b> %s</td></tr>", $row['con_gasto_hrs_extra']);
		printf("<tr><td align='left' valign='top'><b>Horas Dom.:</b> %s</td></tr>", $row['con_gasto_hrs_domingo']);
		printf("<tr><td align='left' valign='top'><b>Horas Feriado:</b> %s</td></tr>", $row['con_gasto_hrs_feriado']);
		printf("<tr><td align='left' valign='top'><b>Aguinaldo:</b> %s</td></tr>", $row['con_gasto_aguinaldo']);
		printf("<tr><td align='left' valign='top'><b>Ap. Patronales:</b> %s</td></tr>", $row['con_gasto_ap_pat']);
		printf("<tr><td align='left' valign='top'><b>2do. Aguinaldo:</b> %s</td></tr>", $row['con_gasto_aguinaldo_2']);
		printf("<tr><td align='left' valign='top'><b>Horas Recargo:</b> %s</td></tr>", $row['con_gasto_hrs_recargo']);
		printf("<tr><td align='left' valign='top'><b>Horas Extraor.:</b> %s</td></tr>", $row['con_gasto_hrs_extraor']);
		printf("<tr><td align='left' valign='top'><b>Bono Antig&uuml;edad:</b> %s</td></tr>", $row['con_gasto_bono_ant']);
	}
	echo "</table>";
	echo "</td>";
	mysqli_free_result($result5);
	
	}//fin if conceptos gasto
	
	echo "</tr>";
	
	$color++;
	$j++;
  }//fin while
?>
<tr BGCOLOR='#ffcccc'><td colspan="<?php echo $nro_per++; ?>"><b>Total Personas</b></td>
<td align="right"><?php printf("<b>%s</b>", $fin); ?></td></tr>
</tbody>
</table>
<?php
} //fin if 2

?>

</body>
</html>
