<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Receta</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?pkyRecipe=101&user=Luigi&token=123456
$cod_receta = $_GET["pkyRecipe"];

//$usuario = $_GET["user"];
//$n_decimales = 6;

?>
<body>

<?php
	
// Inicio impresion receta

$result3 = mysqli_query($link, "select a.pkyRecipe as cod_receta, a.fldName as receta, a.codItem as cod_item, b.fldName as item, a.fldVersion as revision, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg
from prdRecipe a, invItem b, accGroup g 
where 
a.codItem = b.pkyItem and 
a.sysAuthorizationGroup = g.pkyGroup and 
a.pkyRecipe = '$cod_receta';");
	while ($row = mysqli_fetch_array($result3)) {
	$receta = $row['receta'];
	$cod_item = $row['cod_item'];
	$item = $row['item'];
	$revision = $row['revision'];
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	$usuario_reg = $row['usuario_reg'];
	$enabled = $row['enabled'];
	$authorized = $row['authorized'];
	}
	mysqli_free_result($result3);

//detalle
	$result2 = mysqli_query($link, "select a.pkyRecipeDetail as cod_recetadet, a.codItem as cod_item, b.fldName as item, a.fldQuantity as cantidad, c.fldName as unidad_men
from prdRecipeDetail a, invItem b, invStorageUnit c 
where 
a.codItem = b.pkyItem and 
b.codMinimumStorageUnit = c.pkyStorageUnit and 
a.codRecipe = '$cod_receta'
order by b.fldName;");


?>
<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>Receta</b></font></center></p>
	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="25%"><b>Cod. Reg.: </b><?php echo $cod_receta; ?></TD>
        <TD width="25%"><b>Nombre: </b><?php echo $receta; ?></TD>
        <TD width="25%"><b>Revisi&oacute;n: </b><?php echo $revision; ?></TD>
        <TD width="25%"><b>Producto: </b><?php echo $cod_item; ?> - <?php echo $item; ?></TD>
        </TR>
        <TR> 
        <TD colspan="4"><b>Descripci&oacute;n: </b><?php echo $glosa; ?></TD>
        </TR>
    </table>
<br />
<b>Detalle</b>
<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center" width="100"><b>Cod.</b></TD>
    <TD align="center" width="100"><b>Cod. Item</b></TD>
    <TD align="center"><b>Item</b></TD>
    <TD align="center" width="100"><b>Unidad</b></TD>
    <TD align="center" width="100"><b>Cant.</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_cantidad = 0;
	$uni = array();
	$i = 1;
		
	while ($row = mysqli_fetch_array($result2)) { //while
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_recetadet']);//cod receta detalle
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_recetadet']);//cod receta detalle
		} //cierra if color
		printf("<td align='center'>%s</td>", $row['cod_item']);//cod item
		printf("<td align='left'>%s</td>", $row['item']);//item
		printf("<td align='left'>%s</td>", $row['unidad_men']);//unidad menor
		printf("<td align='right'>%s</td></tr>", number_format($row['cantidad'], $n_receta));//total
				
		$suma_cantidad = $suma_cantidad + $row['cantidad'];
		$color++;
	}//fin while
	mysqli_free_result($result2);
	
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="4"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_cantidad, $n_receta); ?></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>

</body>
</html>
