<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nota Planilla de Reintegro</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 "../../class.nroenletraver2.php";
include "../../general.php";
include "../../token.php";

//index.php?pkySalaryReimbursement=1&user=Luigi&token=123456
$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

$cod_reint = $_GET["pkySalaryReimbursement"];
//$usuario = $_GET["user"];

//$n_cantidad = 6;
?>
<body>

<?php

// Inicio impresion Planilla Reintegro

$result = mysqli_query($link, "select a.pkySalaryReimbursement as cod_reint, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.fldInitMonth as mes_ini, a.fldEndMonth as mes_fin, a.codExchangeRate as cod_tc, a.fldIsBasicPercent as porcentaje_basico, a.fldIsSeniorityPercent as porcentaje_antiguedad, a.fldIsProductionPercent as porcentaje_prod, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg, a.sysContext as cod_contexto, s.fldName as contexto
from hrsSalaryReimbursement a, accGroup g, srvContext s
where 
a.sysAuthorizationGroup = g.pkyGroup and
a.sysContext = s.pkyContext and 
a.pkySalaryReimbursement = '$cod_reint';");
	while ($row = mysqli_fetch_array($result)) {
		$nro_doc = $row['nro_doc'];
		$fecha = $row['fecha'];
		$mes_ini = $row['mes_ini'];
		$mes_fin = $row['mes_fin'];
		$cod_tc = $row['cod_tc'];
		//$usada = $row['usada'];
		$porcentaje_basico = $row['porcentaje_basico'];
		$porcentaje_antiguedad = $row['porcentaje_antiguedad'];
		$porcentaje_prod = $row['porcentaje_prod'];
		$glosa = $row['glosa'];
		$glosa = nl2br($glosa);//quita salto de linea 
		$glosa = str_replace('\n','<br />',$glosa);//reemplaza para salto de linea
		$usuario_reg = $row['usuario_reg'];
		$enabled = $row['enabled'];
		$authorized = $row['authorized'];
		$cod_contexto = $row['cod_contexto'];
		$contexto = $row['contexto'];
	}
	mysqli_free_result($result);
	

$resulttc = mysqli_query($link, "select pkyExchangeRate as cod_tc, fldDate as fecha, fldTime as hora
from
actExchangeRate
where
pkyExchangeRate = '$cod_tc';");
while ($row = mysqli_fetch_array($resulttc)) {
	$tc_fecha = $row['fecha'];
	$tc_hora = $row['hora'];
}
mysqli_free_result($resulttc);

$resulttcdet = mysqli_query($link, "select a.pkyExchangeRateDetail as cod_tc_det, a.codBaseCurrency as cod_mon_target, b.fldName as mon_target, b.txtDescription as nom_mon_target, a.codTargetCurrency as cod_mon_base, c.fldName as mon_base, c.txtDescription as nom_mon_base, a.fldRate as tasa
from
actExchangeRateDetail a, actCurrency b, actCurrency c
where
a.codExchangeRate = '$cod_tc' and 
a.codBaseCurrency = '$cod_moneda_principal' and 
a.codBaseCurrency = b.pkyCurrency and 
a.codTargetCurrency = c.pkyCurrency 
order by cod_mon_target, cod_mon_base;");
$ma_tc = array();
$m = 1;
while ($row = mysqli_fetch_array($resulttcdet)) {
	$ma_tc [$m][1] = $row['mon_base'];
	$ma_tc [$m][2] = $row['mon_target'];
	$ma_tc [$m][3] = $row['tasa'];
	$m++;
}
mysqli_free_result($resulttcdet);
$fin_m = $m - 1;

//if($usada == 0) { $usada_txt = 'NO';}
//if($usada == 1) { $usada_txt = 'SI';}

$result2 = mysqli_query($link, "select a.pkySalaryReimbursementDetail as cod_reint_det, a.codSalaryReimbursement as cod_reint, a.codEmployee as cod_empleado, case when b.fldOtherNames is NULL then case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName) end else case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName,' ',b.fldOtherNames) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName,' ',b.fldOtherNames) end end as empleado, a.fldBasicAmount as basico, a.fldSeniorityAmount as antiguedad, a.fldProductionAmount as produccion, a.codEmployeeMovement as cod_mov_emp, c.fldDocumentNumber as nro_mov_emp
from hrsSalaryReimbursementDetail a, agnPerson b, hrsEmployeeMovement c
where 
a.codEmployee = b.pkyPerson and
a.codEmployeeMovement = c.pkyEmployeeMovement and 
a.codSalaryReimbursement = '$cod_reint' 
order by empleado;");


?>
<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>Nota Planilla de Reintegro</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="33%"><b>Cod. Reg.: </b><?php echo $cod_reint; ?></TD>
        <TD width="33%"><b>Nro. Doc.: </b><?php echo $nro_doc; ?></TD>
        <TD width="33%"><b>Fecha de Reg.: </b><?php echo $fecha; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes Inicial: </b><?php echo substr($mes_ini, 0,-3); ?></TD>
        <TD><b>Mes Final: </b><?php echo substr($mes_fin, 0,-3); ?></TD>
		<TD><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
        </TR>
        <!--
        <TR>
        <TD><b>Basico: </b><?php echo $porcentaje_basico; ?></TD>
        <TD><b>Antig&uuml;edad: </b><?php echo $porcentaje_antiguedad; ?></TD>
        <TD><b>Producci&oacute;n: </b><?php echo $porcentaje_prod; ?></TD>
        </TR>
        -->
        <TR>
        <TD colspan="4"><b>Glosa: </b><?php echo $glosa; ?></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 $cod_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $cod_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></tr>", 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. Empleado</b></TD>
    <TD align="center"><b>Empleado</b></TD>
    <TD align="center"><b>B&aacute;sico</b></TD>
    <TD align="center"><b>Antig&uuml;edad</b></TD>
    <TD align="center"><b>Producci&oacute;n</b></TD>
    <TD align="center"><b>Mov. Empleado</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_bas = 0;
	$suma_ant = 0;
	$suma_prod = 0;
	
	while ($row = mysqli_fetch_array($result2)) { //while
		
		$cod_persona = $row['cod_empleado'];
		$cod_mov_emp = $row['cod_mov_emp'];
		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>", $row['cod_empleado']);//cod empleado
		} else {
		printf("<tr><td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_persona&user=$usuario&token=$token' title='Persona'>%s</a></td>", $row['cod_empleado']);//cod empleado
		} //cierra if color
		printf("<td align='left'>%s</td>", $row['empleado']);//empleado
		
		printf("<td align='right'>%s</td>", number_format($row['basico'],$n_decimales));//basico
		printf("<td align='right'>%s</td>", number_format($row['antiguedad'],$n_decimales));//antiguedad
		printf("<td align='right'>%s</td>", number_format($row['produccion'],$n_decimales));//produccion
		printf("<td align='left'><a href='../../ModuleHumanResources/VoucherEmployeeMovement/index.php?pkyEmployeeMovement=$cod_mov_emp&user=$usuario&token=$token' title='Mov. Empleado'>%s</a></td></tr>", $row['nro_mov_emp']);//nro. mov. empleado
		
		$suma_bas = $suma_bas + $row['basico'];
		$suma_ant = $suma_ant + $row['antiguedad'];
		$suma_prod = $suma_prod + $row['produccion'];	
		$color++;
	}//fin while
	mysqli_free_result($result2);
	
	//convierte el total en literal
	/*
	$letras=new NroEnLetra($suma_total,2);
	
	$mostrar_letras = ucfirst($letras->getLetra());
	
	$busca_espacio = substr($mostrar_letras,-6,1);
	if($busca_espacio == ' ') {
		$fin_letras = substr($mostrar_letras,-5);
		$mostrar_letras = substr($mostrar_letras,0,-5);
		$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
	}
	$resultmoneda = mysqli_query($link, "select txtDescription as nom_moneda
	from actCurrency
	where
	pkyCurrency = '$cod_moneda';");
	while ($row = mysqli_fetch_array($resultmoneda)) {
		$nom_moneda_letras_tot = $row['nom_moneda'];
	}
	mysqli_free_result($resultmoneda);
	*/
	?>
	<tr BGCOLOR='#ffcccc'>
    <!--
    <td colspan="8"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $nom_moneda_letras_tot; ?></b></td>
    -->
    <td colspan="2"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_bas,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_ant,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_prod,$n_cantidad); ?></b></td>
    <td>&nbsp;</td>
    </tr>
</tbody>    
</table>
<br />
<?php
    if($enabled == 0){
				printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO ANULADO</font></td></tr></table>");
			}
	if($authorized == 0){
				printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
			}

?>

<br /><br /><br /><br /><br />
<table border="0" align="center" cellpadding="2" width="90%">
<tr>
<td align="center">----------------------------------------</td>
<td align="center">----------------------------------------</td>
<td align="center">----------------------------------------</td>
<td align="center">----------------------------------------</td>
</tr><tr>
<td align="center">Elaborado por: <?php echo $usuario_reg; ?></td>
<td align="center"><?php echo $firma_contabilidad; ?></td>
<td align="center"><?php echo $firma_gerencia; ?></td>
<td align="center"><?php echo $firma_interesado; ?></td>
</tr><tr>
<td align="left">Nombre:__________________________</td>
<td align="left">Nombre:__________________________</td>
<td align="left">Nombre:__________________________</td>
<td align="left">Nombre:__________________________</td>
</tr><tr>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
</tr>
</table>

<?php


?>
</body>
</html>
