<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nota de Activo Fijo</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?pkyFixedAsset=1&user=Luigi&token=123456
$cod_af = $_GET["pkyFixedAsset"];
//$usuario = $_GET["user"];
//$n_decimales = 6;

?>
<body>

<?php
	
// Inicio impresion Nota de Activo Fijo

$result = mysqli_query($link, "select a.pkyFixedAsset as cod_af, a.fldName as nom_af, a.codFamily as cod_familia, b.fldName as familia, a.codSubFamily as cod_subfamilia, a.codGroup as cod_grupo, a.codSubGroup as cod_subgrupo, a.codBrand as cod_marca, a.codEmployeeResponsible as cod_responsable, case when c.fldMiddleName is NULL then concat(c.fldLastName,', ',c.fldFirstName) else concat(c.fldLastName,' ',c.fldMiddleName,', ',c.fldFirstName) end as responsable, a.fldFactoryKey as cod_fabrica, a.fldAlternativeKey as cod_alternativo, a.fldBarcode as cod_barra, a.fldWarranty as garantia, a.codBrandModel as cod_modelo, a.fldMaintenance as en_mant, a.fldMaintenanceStartDate as fecha_ini_mant, a.fldMaintenanceEndDate as fecha_fin_mant, a.codCompanyBranch as cod_sucursal, d.fldName as sucursal, a.codExchangeRate as cod_tc, a.fldValue as valor, e.fldDate as fecha_alta, a.fldRevaluationCurrencyValue as valor_moneda_revalu, a.fldAccumulatedRevaluationValue as acumulado_revalu, a.fldAccumulatedDepreciationValue as depreciacion_acum, a.fldYearDepreciationValue as depreciacion_anual, a.fldUpdatedAccumulatedDepreciationValue as valor_actualizacion_depreciacion_acum, a.fldOriginalValue as valor_compra, a.fldIncomingDate as fecha_compra, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg
from fasFixedAsset a, fasFixedAssetCategory b, agnPerson c, agnCompanyBranch d, fasFixedAssetMovement e, accGroup g
where 
a.codFamily = b.pkyFixedAssetCategory and 
a.codEmployeeResponsible = c.pkyPerson and 
a.codCompanyBranch = d.pkyCompanyBranch and  
a.pkyFixedAsset = e.codFixedAsset and 
e.codType = 1 and 
a.sysAuthorizationGroup = g.pkyGroup and 
a.pkyFixedAsset = '$cod_af';");

	while ($row = mysqli_fetch_array($result)) {
		$cod_af = $row['cod_af'];
		$activo_fijo = $row['nom_af'];
		$cod_familia = $row['cod_familia'];
		$familia = $row['familia'];
		$cod_subfamilia = $row['cod_subfamilia'];
		$cod_grupo = $row['cod_grupo'];
		$cod_subgrupo = $row['cod_subgrupo'];
		$cod_marca = $row['cod_marca'];
		$cod_responsable = $row['cod_responsable'];
		$responsable = $row['responsable'];
		$cod_fabrica = $row['cod_fabrica'];
		$cod_alternativo = $row['cod_alternativo'];
		$cod_barra = $row['cod_barra'];
		$garantia = $row['garantia'];
		$cod_modelo = $row['cod_modelo'];
		$en_mant = $row['en_mant'];
		if($en_mant == 0) {
			$mantenimiento = 'NO';
		} else {
			$mantenimiento = 'SI';
		}
		$fecha_ini_mant = $row['fecha_ini_mant'];
		$fecha_fin_mant = $row['fecha_fin_mant'];
		$cod_sucursal = $row['cod_sucursal'];
		$sucursal = $row['sucursal'];
		$cod_tc = $row['cod_tc'];
		$valor = $row['valor'];
		$fecha_alta = $row['fecha_alta'];
		$valor_moneda_revalu = $row['valor_moneda_revalu'];
		$acumulado_revalu = $row['acumulado_revalu'];
		$depreciacion_acum = $row['depreciacion_acum'];
		$depreciacion_anual = $row['depreciacion_anual'];
		$valor_actualizacion_depreciacion_acum = $row['valor_actualizacion_depreciacion_acum'];
		$valor_compra = $row['valor_compra'];
		$fecha_compra = $row['fecha_compra'];
		$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'];
	}
	mysqli_free_result($result);

$resultmarca = mysqli_query($link, "select fldName as marca
from invBrand
where pkyBrand = '$cod_marca' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultmarca)) {
	$marca = $row['marca'];
}
mysqli_free_result($resultmarca);

$resultmodelo = mysqli_query($link, "select fldName as modelo
from invBrandModel
where pkyBrandModel = '$cod_modelo' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultmodelo)) {
	$modelo = $row['modelo'];
}
mysqli_free_result($resultmodelo);

$resultsubfam = mysqli_query($link, "select fldName as sub_familia
from fasFixedAssetCategory
where pkyFixedAssetCategory = '$cod_subfamilia' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultsubfam)) {
	$subfamilia = $row['sub_familia'];
}
mysqli_free_result($resultsubfam);

$resultgrupo = mysqli_query($link, "select fldName as grupo
from fasFixedAssetCategory
where pkyFixedAssetCategory = '$cod_grupo' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultgrupo)) {
	$grupo = $row['grupo'];
}
mysqli_free_result($resultgrupo);

$resultsubgrupo = mysqli_query($link, "select fldName as sub_grupo
from fasFixedAssetCategory
where pkyFixedAssetCategory = '$cod_subgrupo' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultsubgrupo)) {
	$subgrupo = $row['sub_grupo'];
}
mysqli_free_result($resultsubgrupo);

$resulttc = mysqli_query($link, "select pkyExchangeRate as cod_tc, fldDate as fecha, fldTime as hora
from
actExchangeRate
where
pkyExchangeRate = '$cod_tc' and 
sysEnabled = 1 and sysAuthorized = 1;");
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;

	
?>
<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 Activo Fijo</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>Cod. Reg.: </b><?php echo $cod_af; ?></TD>
        <TD width="25%"><b>Cod. Alt.: </b><?php echo $cod_alternativo; ?></TD>
        <TD width="25%"><b>Cod. Fab.: </b><?php echo $cod_fabrica; ?></TD>
        <TD width="25%"><b>Cod. Barra: </b><?php echo $cod_barra; ?></TD>
        </TR>
        <TR>
        <TD><b>Nombre: </b><?php echo $activo_fijo; ?></TD>
        <TD><b>Marca: </b><?php echo $marca; ?></TD>
        <TD><b>Modelo: </b><?php echo $modelo; ?></TD>
        <TD><b>Garant&iacute;a (D&iacute;as): </b><?php echo $garantia; ?></TD>
        </TR>
        <TR>
        <TD><b>Familia: </b><?php echo $cod_familia; ?> - <?php echo $familia; ?></TD>
        <TD><b>Sub Familia: </b><?php echo $cod_subfamilia; ?> - <?php echo $subfamilia; ?></TD>
        <TD><b>Grupo: </b><?php echo $cod_grupo; ?> - <?php echo $grupo; ?></TD>
        <TD><b>Sub Grupo: </b><?php echo $cod_subgrupo; ?> - <?php echo $subgrupo; ?></TD>
        </TR>
        <TR>
        <TD><b>Empleado: </b><?php echo $cod_responsable; ?> - <?php echo $responsable; ?></TD>
        <TD><b>Sucursal: </b><?php echo $cod_sucursal; ?> - <?php echo $sucursal; ?></TD>
        <TD><b>Valor de Compra: </b><?php echo number_format($valor_compra,$n_decimales); ?></TD>
        <TD><b>Fecha de Compra: </b><?php echo $fecha_compra; ?></TD>
        </TR>
        <TR>
        <TD><b>Valor de Ingreso: </b><?php echo number_format($valor,$n_decimales); ?></TD>
        <TD><b>Fecha de Ingreso: </b><?php echo $fecha_alta; ?></TD>
        <TD><b>Valor Moneda Revaluaci&oacute;n: </b><?php echo number_format($valor_moneda_revalu,$n_decimales); ?></TD>
        <TD><b>Acumulado Revaluaci&oacute;n: </b><?php echo number_format($acumulado_revalu,$n_decimales); ?></TD>
        </TR>
        <TR>
        <TD><b>Depreciaci&oacute;n Anual: </b><?php echo number_format($depreciacion_anual,$n_decimales); ?></TD>
        <TD><b>Depreciaci&oacute;n Acumulada: </b><?php echo number_format($depreciacion_acum,$n_decimales); ?></TD>
        <TD colspan="2"><b>¿En Mantenimiento?: </b><?php echo $mantenimiento; ?></TD>
        </TR>
        <TR>
        <TD colspan="2"><b>Fecha Inicial de Mantenimiento: </b><?php echo $fecha_ini_mant; ?></TD>
        <TD colspan="2"><b>Fecha Final de Mantenimiento: </b><?php echo $fecha_fin_mant; ?></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 />


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