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

?>
<body>

<?php
	
// Inicio impresion Nota de Item

$result = mysqli_query($link, "select a.pkyItem as cod_item, a.fldName as item, a.codType as cod_tipo, b.fldName as tipo, a.codFamily as cod_familia, c.fldName as familia, a.codSubFamily as cod_subfamilia, a.codGroup as cod_grupo, a.codSubGroup as cod_subgrupo, a.codMaximumStorageUnit as cod_max_uni, 
d.fldName as max_uni, a.codMinimumStorageUnit as cod_min_uni, e.fldName as min_uni,a.fldStorageUnitCoefficient as conversion, a.codBrand as cod_marca, a.codSource as cod_origen, f.fldName as origen, a.fldFactoryKey as cod_fabrica, a.fldAlternativeKey as cod_alternativo, a.fldBarcode as cod_barra, a.fldMaximumStock as stock_max, a.fldMinimumStock as stock_min, a.fldWarranty as garantia,
a.fldPackagedItemWeight as peso_embalaje, a.fldItemWeight as peso_neto, a.codWeightMeasureUnit as cod_peso, h.fldName as peso, a.fldPackagedItemVolume as volumen_embalaje, a.fldItemVolume as volumen_neto, a.codVolumeMeasureUnit as cod_volumen, i.fldName as volumen, a.codBrandModel as cod_modelo, a.fldInUse as en_uso, a.fldMaintenance as en_mant, a.fldMaintenanceStartDate as fecha_ini_mant, a.fldMaintenanceEndDate as fecha_fin_mant, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg
from invItem a, invItemType b, invItemCategory c, invStorageUnit d, invStorageUnit e, regCountry f, accGroup g, srvMeasureUnit h, srvMeasureUnit i
where 
a.codType = b.pkyItemType and 
a.codFamily = c.pkyItemCategory and 
a.codMaximumStorageUnit = d.pkyStorageUnit and 
a.codMinimumStorageUnit = e.pkyStorageUnit and
a.codSource = f.pkyCountry and 
a.codWeightMeasureUnit = h.pkyMeasureUnit and 
a.codVolumeMeasureUnit = i.pkyMeasureUnit and 
a.sysAuthorizationGroup = g.pkyGroup and 
a.pkyItem = '$cod_item';");

	while ($row = mysqli_fetch_array($result)) {
		$cod_item = $row['cod_item'];
		$item = $row['item'];
		$cod_tipo = $row['cod_tipo'];
		$tipo = $row['tipo'];
		$cod_familia = $row['cod_familia'];
		$familia = $row['familia'];
		$cod_subfamilia = $row['cod_subfamilia'];
		$cod_grupo = $row['cod_grupo'];
		$cod_subgrupo = $row['cod_subgrupo'];
		$cod_max_uni = $row['cod_max_uni'];
		$max_uni = $row['max_uni'];
		$cod_min_uni = $row['cod_min_uni'];
		$min_uni = $row['min_uni'];
		$conversion = $row['conversion'];
		$cod_marca = $row['cod_marca'];
		$cod_origen = $row['cod_origen'];
		$origen = $row['origen'];
		$cod_fabrica = $row['cod_fabrica'];
		$cod_alternativo = $row['cod_alternativo'];
		$cod_barra = $row['cod_barra'];
		$stock_max = $row['stock_max'];
		$stock_min = $row['stock_min'];
		$garantia = $row['garantia'];
		$peso_embalaje = $row['peso_embalaje'];
		$peso_neto = $row['peso_neto'];
		$cod_peso = $row['cod_peso'];
		$peso = $row['peso'];
		$volumen_embalaje = $row['volumen_embalaje'];
		$volumen_neto = $row['volumen_neto'];
		$cod_volumen = $row['cod_volumen'];
		$volumen = $row['volumen'];
		$cod_modelo = $row['cod_modelo'];
		$en_uso = $row['en_uso'];
		if($en_uso == 0) {
			$uso = 'NO';
		} else {
			$uso = 'SI';
		}
		$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'];
		$glosa = $row['glosa'];
		//$glosa = nl2br($glosa);
		//$glosa = str_replace("a","XXX",$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 invItemCategory
where pkyItemCategory = '$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 invItemCategory
where pkyItemCategory = '$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 invItemCategory
where pkyItemCategory = '$cod_subgrupo' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultsubgrupo)) {
	$subgrupo = $row['sub_grupo'];
}
mysqli_free_result($resultsubgrupo);

//solo si es vehiculo
if($cod_tipo == 4) {//if codtipo 4
//datos del vehiculo
$resultvehi = mysqli_query($link, "select a.fldCarPlate as placa, a.fldYear as ano, a.fldChassis as chasis, a.fldEngine as motor, a.codFuelType as cod_combus, b.fldName as combus, a.fldCategory as categoria, a.fldTankCapacity as tanque, a.codOwner as cod_propietario, c.fldName as propietario, a.fldPersonCapacity as capacidad, a.fldBaggageCapacity as maletas, a.fldWeightCapacity as carga, a.fldColor as color
from vhcVehicleDetail a, vhcFuelType b, agnCompany c
where 
a.codFuelType = b.pkyFuelType and 
a.codOwner = c.pkyCompany and 
a.codItem = '$cod_item' and 
a.sysEnabled = 1 and a.sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultvehi)) {
	$placa = $row['placa'];
	$ano = $row['ano'];
	$chasis = $row['chasis'];
	$motor = $row['motor'];
	$combus = $row['combus'];
	$categoria = $row['categoria'];
	$tanque = $row['tanque'];
	$propietario = $row['propietario'];
	$capacidad = $row['capacidad'];
	$maletas = $row['maletas'];
	$carga = $row['carga'];
	$color = $row['color'];
}
mysqli_free_result($resultvehi);

//equipamiento
$resultequip = mysqli_query($link, "select a.codVehicleEquipment as cod_equipo, b.fldName as equipo, a.fldChecked as contiene
from vhcVehicleEquipmentDetail a, vhcVehicleEquipment b
where 
a.codVehicleEquipment = b.pkyVehicleEquipment and 
a.codItem = '$cod_item' and 
a.sysEnabled = 1 and a.sysAuthorized = 1;");
$mat_equip = array ();
$i = 1;
while ($row = mysqli_fetch_array($resultequip)) {
	$mat_equip[$i][1] = $row['cod_equipo'];
	$mat_equip[$i][2] = $row['equipo'];
	if($row['contiene'] == 0) {
		$mat_equip[$i][3] = 'No';
	} else {
		$mat_equip[$i][3] = 'Si';
	}
	$i++;
}
$hay_equipamiento = mysqli_num_rows($resultequip);
mysqli_free_result($resultequip);
$fin_i = $i - 1;
}//fin if codtipo 4
/*
$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>
<p><br /><center><font color="#000099" size="+1"><b>Nota de Item</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_item; ?></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 $item; ?></TD>
        <TD><b>Marca: </b><?php echo $marca; ?></TD>
        <TD><b>Modelo: </b><?php echo $modelo; ?></TD>
        <TD><b>Tipo: </b><?php echo $tipo; ?></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>Peso Embalaje: </b><?php echo number_format($peso_embalaje,$n_decimales); ?> <?php echo $peso; ?></TD>
        <TD><b>Peso Neto: </b><?php echo number_format($peso_neto,$n_decimales); ?> <?php echo $peso; ?></TD>
        <TD><b>Vol&uacute;men Embalaje: </b><?php echo number_format($volumen_embalaje,$n_decimales); ?> <?php echo $volumen; ?></TD>
        <TD><b>Vol&uacute;men Neto: </b><?php echo number_format($volumen_neto,$n_decimales); ?> <?php echo $volumen; ?></TD>
        </TR>
        <TR>
        <TD><b>Unidad Max.(x): </b><?php echo $max_uni; ?></TD>
        <TD><b>Unidad Min.(y): </b><?php echo $min_uni; ?></TD>
        <TD><b>Conversi&oacute;n: </b><?php echo $conversion; ?></TD>
        <TD><b>Garant&iacute;a (D&iacute;as): </b><?php echo $garantia; ?></TD>
        </TR>
        <TR>
        <TD><b>Min. Stock: </b><?php echo $stock_min; ?></TD>
        <TD><b>Max. Stock: </b><?php echo $stock_max; ?></TD>
        <TD colspan="2"><b>Origen: </b><?php echo $origen; ?></TD>
        </TR>
        <?php if($cod_tipo == 4) { //if cod_tipo 1 ?>
        <TR>
        <TD><b>¿En Uso?: </b><?php echo $uso; ?></TD>
        <TD><b>¿En Mantenimiento?: </b><?php echo $mantenimiento; ?></TD>
        <TD><b>Fecha Inicial de Mantenimiento: </b><?php echo $fecha_ini_mant; ?></TD>
        <TD><b>Fecha Final de Mantenimiento: </b><?php echo $fecha_fin_mant; ?></TD>
        </TR>
        <?php } //fin if cod_tipo 1 ?>
        <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($cod_tipo == 4) { //if cod_tipo 2 ?>
    <table border="0" align="left" cellpadding="2" width="80%">
    <tr><td>
    <b>Datos del Veh&iacute;culo</b>
    </td></tr>
    </table>
    <table border="1" align="left" cellpadding="2" width="50%">
        <thead>
        <TR> 
        <TD align="center"><b>Concepto</b></TD>
        <TD align="center"><b>Valor</b></TD>
        </TR>
        </thead>
        <tbody class="marcafila">
        
    <?php
        printf("<tr BGCOLOR='#e2e7fa'><td>Placa</td>");//placa
        printf("<td>%s</td></tr>", $placa);//placa
        printf("<tr><td>A&ntilde;o</td>");//modelo
        printf("<td>%s</td></tr>", $ano);//modelo
        printf("<tr BGCOLOR='#e2e7fa'><td>Chasis</td>");//chasis
        printf("<td>%s</td></tr>", $chasis);//chasis
        printf("<tr><td>Motor</td>");//motor
        printf("<td>%s</td></tr>", $motor);//motor
        printf("<tr BGCOLOR='#e2e7fa'><td>Tipo de Combustible</td>");//combustible
        printf("<td>%s</td></tr>", $combus);//combustible
        printf("<tr><td>Categor&iacute;a</td>");//categoria
        printf("<td>%s</td></tr>", $categoria);//categoria
        printf("<tr BGCOLOR='#e2e7fa'><td>Tanque (Litros)</td>");//tanque
        printf("<td>%s</td></tr>", $tanque);//tanque
        printf("<tr><td>Propietario</td>");//propietario
        printf("<td>%s</td></tr>", $propietario);//propietario
        printf("<tr BGCOLOR='#e2e7fa'><td>Capacidad (Personas)</td>");//capacidad
        printf("<td>%s</td></tr>", $capacidad);//capacidad
        printf("<tr><td>Capacidad (Maletas)</td>");//maletas
        printf("<td>%s</td></tr>", $maletas);//maletas
        printf("<tr BGCOLOR='#e2e7fa'><td>Capacidad (Kilogramos)</td>");//carga
        printf("<td>%s</td></tr>", $carga);//carga
        printf("<tr><td>Color</td>");//color
        printf("<td>%s</td></tr>", $color);//color
    ?>
    </tbody>    
    </table>
    <table border="0" align="left" cellpadding="2" width="80%">
    <tr><td>&nbsp;
    
    </td></tr>
    </table>
    <?php if($hay_equipamiento != 0) { //if hay_equipamiento ?>
    <table border="0" align="left" cellpadding="2" width="80%">
    <tr><td>
    <b>Equipamiento</b>
    </td></tr>
    </table>
    <table border="1" align="left" cellpadding="2" width="50%">
        <thead>
        <TR> 
        <TD align="center"><b>Equipo</b></TD>
        <TD align="center"><b>¿Contiene?</b></TD>
        </TR>
        </thead>
        <tbody class="marcafila">
        
    <?php
    $color = 2;
    for ($i = 1; $i <= $fin_i; $i++) { //for i
        if($color % 2 == 0) { //if color
            printf("<tr BGCOLOR='#e2e7fa'><td>%s</td>", $mat_equip[$i][2]);//equipo
        } else {
            printf("<tr><td>%s</td>", $mat_equip[$i][2]);//equipo
        } //cierra if color
            
        printf("<td>%s</td></tr>", $mat_equip[$i][3]);//contiene
        $color++;
    }//fin for i
    ?>	
    </tbody>    
    </table>
    <?php } //fin if hay_equipamiento ?>
    <br />
    <table border="0" align="left" cellpadding="2" width="80%">
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    </table>
<?php } //fin if cod_tipo 2 ?>

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