<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nota de Movimiento de Empleado</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";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

//index.php?pkyEmployeeMovement=1&user=Luigi&token=123456
$cod_mov = $_GET["pkyEmployeeMovement"];
//$usuario = $_GET["user"];
//$n_decimales = 6;

?>
<body>

<?php
	
// Inicio impresion Nota de Movimiento de Empleado

$result = mysqli_query($link, "select a.pkyEmployeeMovement as cod_mov_emp, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codType as cod_tipo, b.fldName as tipo, a.codPerson as cod_persona, case when c.fldOtherNames is NULL then case when c.fldMiddleName is NULL then concat(c.fldLastName,', ',c.fldFirstName) else concat(c.fldLastName,' ',c.fldMiddleName,', ',c.fldFirstName) end else case when c.fldMiddleName is NULL then concat(c.fldLastName,', ',c.fldFirstName,' ',c.fldOtherNames) else concat(c.fldLastName,' ',c.fldMiddleName,', ',c.fldFirstName,' ',c.fldOtherNames) end end as persona, a.codPreviousBranch as cod_ant_suc, a.codBranch as cod_suc, a.codPreviousJob as cod_ant_cargo, a.codJob as cod_cargo, a.fldPreviousSalary as salario_ant, a.fldBasicSalary as salario_basico, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg, a.fldParentComponent as papa, a.cosComponentKey as cod_papa, a.sysContext as cod_contexto, s.fldName as contexto, a.fldAccumulatedVacation as vacaciones_acum, a.fldAccumulatedVAT as iva_acum
from 
hrsEmployeeMovement a, hrsEmployeeMovementType b, agnPerson c, accGroup g, srvContext s
where 
a.pkyEmployeeMovement = '$cod_mov' and 
a.codType = b.pkyEmployeeMovementType and 
a.codPerson = c.pkyPerson and 
a.sysContext = s.pkyContext and 
a.sysAuthorizationGroup = g.pkyGroup;");

	while ($row = mysqli_fetch_array($result)) {//while principal
		$cod_mov = $row['cod_mov_emp'];
		$nro_doc = $row['nro_doc'];
		$fecha_mov = $row['fecha'];
		$cod_tipo_mov = $row['cod_tipo'];
		$tipo_mov = $row['tipo'];
		$cod_persona_mov = $row['cod_persona'];
		$persona_mov = $row['persona'];
		$cod_ant_suc = $row['cod_ant_suc'];
		$cod_suc = $row['cod_suc'];
		$cod_ant_cargo = $row['cod_ant_cargo'];
		$cod_cargo = $row['cod_cargo'];
		$salario_ant = $row['salario_ant'];
		$salario_basico = $row['salario_basico'];
		$glosa = $row['glosa'];
		$glosa = nl2br($glosa);//quita salto de linea 
		$glosa = str_replace('\n','<br />',$glosa);//reemplaza para salto de linea
		$enabled = $row['enabled'];
		$authorized = $row['authorized'];
		$cod_empresa = $row['cod_empresa'];
		$usuario_reg = $row['usuario_reg'];
		$cod_contexto = $row['cod_contexto'];
		$contexto = $row['contexto'];
		$vacaciones_acum = $row['vacaciones_acum'];
		$iva_acum = $row['iva_acum'];
		//para enlazar al que genero el asiento
		$papa_componente = $row['papa'];
		$papa_codigo = $row['cod_papa'];
		//$usuario = $usuario_det;
		include "../../generadopor.php";
		
		if($cod_ant_suc != NULL) {//if cod antigua sucursal
			$resultantsuc = mysqli_query($link, "select fldName as ant_suc
							from agnCompanyBranch
							where
							pkyCompanyBranch = '$cod_ant_suc';");
			while ($row = mysqli_fetch_array($resultantsuc)) {
				$ant_suc = $row['ant_suc'];
			}
			mysqli_free_result($resultantsuc);
		} else {
			$ant_suc = NULL;
		}//fin if antigua sucursal
		
		if($cod_suc != NULL) {//if cod sucursal
			$resultsuc = mysqli_query($link, "select fldName as sucursal
							from agnCompanyBranch
							where
							pkyCompanyBranch = '$cod_suc';");
			while ($row = mysqli_fetch_array($resultsuc)) {
				$sucursal = $row['sucursal'];
			}
			mysqli_free_result($resultsuc);
		} else {
			$sucursal = NULL;
		}//fin if sucursal
		
		if($cod_ant_cargo != NULL) {//if cod antiguo cargo
			$resultantcargo = mysqli_query($link, "select fldName as ant_cargo
							from hrsJob
							where
							pkyJob = '$cod_ant_cargo';");
			while ($row = mysqli_fetch_array($resultantcargo)) {
				$ant_cargo = $row['ant_cargo'];
			}
			mysqli_free_result($resultantcargo);
		} else {
			$ant_cargo = NULL;
		}//fin if antiguo cargo
		
		if($cod_cargo != NULL) {//if cod cargo
			$resultcargo = mysqli_query($link, "select fldName as cargo
							from hrsJob
							where
							pkyJob = '$cod_cargo';");
			while ($row = mysqli_fetch_array($resultcargo)) {
				$cargo = $row['cargo'];
			}
			mysqli_free_result($resultcargo);
		} else {
			$cargo = NULL;
		}//fin if cargo
	}//fin while principal
	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>Nota de Movimiento de Empleado (<?php echo $tipo_mov; ?>)</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_mov; ?></TD>
        <TD width="33%"><b>Nro. Doc.: </b><?php echo $nro_doc; ?></TD>
        <TD width="33%"><b>Fecha de Reg.: </b><?php echo $fecha_mov; ?></TD>
        </TR>
        <TR>
        <TD><b>Persona: </b><a href="../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=<?php echo $cod_persona_mov; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Activo Fijo"><?php echo $cod_persona_mov; ?></a> - <?php echo $persona_mov; ?></TD>
        <TD><b>Cargo: </b><?php echo $cargo; ?></TD>
        <TD><b>Salario B&aacute;sico: </b><?php echo number_format($salario_basico, $n_decimales); ?></TD>
        </TR>
        <tr>
        <TD><b>Sucursal: </b><?php echo $sucursal; ?></TD>
        <TD><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
        <TD><b>Generado Por: </b><?php echo $papa_enlace; ?></TD>
        </TR>
        <?php if($cod_tipo_mov == 1) { ?>
        <TR>
        <TD colspan="2"><b>Vacaciones Acum.: </b><?php echo number_format($vacaciones_acum, $n_decimales); ?></TD>
        <TD><b>IVA Acum.: </b><?php echo number_format($iva_acum, $n_decimales); ?></TD>
        </tr>
        <?php } ?>
        <?php if($cod_tipo_mov == 3) { ?>
        <TR>
        <TD><b>Cargo Anterior: </b><?php echo $ant_cargo; ?></TD>
        <TD><b>Sucursal Anterior: </b><?php echo $ant_suc; ?></TD>
        <TD><b>Salario Anterior: </b><?php echo number_format($salario_ant, $n_decimales); ?></TD>
        </tr>
        <?php } ?>
        <tr>
        <TD colspan="3"><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 />

<?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>

</body>
</html>
