<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nota de Tiempo Trabajado</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?pkyWorkedTime=1&user=Luigi&token=123456
$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

$cod_tiempo = $_GET["pkyWorkedTime"];
//$usuario = $_GET["user"];

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

<?php

// Inicio impresion Tiempo trabajado

$result = mysqli_query($link, "select a.pkyWorkedTime as cod_tiempo, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.fldPeriod as periodo, a.codExchangeRate as cod_tc, a.fldUsed as usada, 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 hrsWorkedTime a, accGroup g, srvContext s
where 
a.sysAuthorizationGroup = g.pkyGroup and
a.sysContext = s.pkyContext and 
a.pkyWorkedTime = '$cod_tiempo';");
	while ($row = mysqli_fetch_array($result)) {
		$nro_doc = $row['nro_doc'];
		$fecha = $row['fecha'];
		$periodo = $row['periodo'];
		$cod_tc = $row['cod_tc'];
		$usada = $row['usada'];
		$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.pkyWorkedTimeDetail as cod_tiempo_det, a.codWorkedTime as cod_tiempo, 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.fldMinimumUnit as hora_dia, a.fldQuantity as cantidad, a.fldAbsences as faltas, a.fldSundayAbsences as faltas_dom, a.fldSick as enfermedad, a.fldOther as otros, a.fldVacation as vacaciones, a.fldExtraHours as horas_extra, a.fldChargeHours as horas_recargo, a.fldSundayHours as horas_domingo, a.fldExtraordinaryHours as horas_extraor, a.fldHolidayHours as horas_feriado
from hrsWorkedTimeDetail a, agnPerson b
where 
a.codEmployee = b.pkyPerson and 
a.codWorkedTime = '$cod_tiempo' 
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><br/>
<p><br /><center><font color="#000099" size="+1"><b>Nota de Tiempo Trabajado</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_tiempo; ?></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>Usada: </b><?php echo $usada_txt; ?></TD>
        <TD><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
        <TD><b>Periodo: </b><?php echo substr($periodo, 0,-3); ?></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>Cantidad</b></TD>
    <TD align="center"><b>Faltas (D&iacute;as)</b></TD>
    <TD align="center"><b>Faltas Dom. (D&iacute;as)</b></TD>
    <TD align="center"><b>Enfermedad (D&iacute;as)</b></TD>
    <TD align="center"><b>Otros (D&iacute;as)</b></TD>
    <TD align="center"><b>Vacaciones</b></TD>
    <TD align="center"><b>Horas Extra</b></TD>
    <TD align="center"><b>Horas Recargo</b></TD>
    <TD align="center"><b>Horas Domingos</b></TD>
    <TD align="center"><b>Horas Extraordinarias</b></TD>
    <TD align="center"><b>Horas Feriados</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_cant = 0;
	$suma_falt = 0;
	$suma_falt_dom = 0;
	$suma_enf = 0;
	$suma_otros = 0;
	$suma_vaca = 0;
	$suma_he = 0;
	$suma_hr = 0;
	$suma_hd = 0;
	$suma_hx = 0;
	$suma_hf = 0;
	
	while ($row = mysqli_fetch_array($result2)) { //while
	
		$cod_persona = $row['cod_empleado'];
		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['cantidad'],$n_cantidad));//cantidad
		printf("<td align='right'>%s</td>", number_format($row['faltas'],$n_cantidad));//faltas
		printf("<td align='right'>%s</td>", number_format($row['faltas_dom'],$n_cantidad));//faltas domingo
		printf("<td align='right'>%s</td>", number_format($row['enfermedad'],$n_cantidad));//enfermedad
		printf("<td align='right'>%s</td>", number_format($row['otros'],$n_cantidad));//otros
		printf("<td align='right'>%s</td>", number_format($row['vacaciones'],$n_cantidad));//vacaciones
		printf("<td align='right'>%s</td>", number_format($row['horas_extra'],$n_cantidad));//horas extra
		printf("<td align='right'>%s</td>", number_format($row['horas_recargo'],$n_cantidad));//horas recargo
		printf("<td align='right'>%s</td>", number_format($row['horas_domingo'],$n_cantidad));//horas domingo
		printf("<td align='right'>%s</td>", number_format($row['horas_extraor'],$n_cantidad));//horas extraordinarias
		printf("<td align='right'>%s</td></tr>", number_format($row['horas_feriado'],$n_cantidad));//horas feriado
		
		$suma_cant = $suma_cant + $row['cantidad'];
		$suma_falt = $suma_falt + $row['faltas'];
		$suma_falt_dom = $suma_falt_dom + $row['faltas_dom'];
		$suma_enf = $suma_enf + $row['enfermedad'];
		$suma_otros = $suma_otros + $row['otros'];
		$suma_vaca = $suma_vaca + $row['vacaciones'];
		$suma_he = $suma_he + $row['horas_extra'];	
		$suma_hr = $suma_hr + $row['horas_recargo'];
		$suma_hd = $suma_hd + $row['horas_domingo'];
		$suma_hx = $suma_hx + $row['horas_extraor'];
		$suma_hf = $suma_hf + $row['horas_feriado'];						
		$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_cant,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_falt,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_falt_dom,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_enf,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_otros,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_vaca,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_he,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hr,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hd,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hx,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hf,$n_cantidad); ?></b></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>
