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

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


?>
<body>

<?php
	
// Inicio impresion nota de preproduccion

$result3 = mysqli_query($link, "select a.pkyPreproductionNote as cod_preprod, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, b.fldName as linea_prod, a.fldIsUsed as sino, 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 prdPreproductionNote a, prdProductionLine b, accGroup g, srvContext s  
where 
a.codProductionLine = b.pkyProductionLine and 
a.sysAuthorizationGroup = g.pkyGroup and 
a.sysContext = s.pkyContext and 
a.pkyPreproductionNote = '$cod_preprod';");
	while ($row = mysqli_fetch_array($result3)) {
	$nro_doc = $row['nro_doc'];
	$fecha = $row['fecha'];
	$linea_prod = $row['linea_prod'];
	$usado = $row['sino'];
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	$usuario_reg = $row['usuario_reg'];
	$enabled = $row['enabled'];
	$authorized = $row['authorized'];
	$cod_contexto = $row['cod_contexto'];
	$contexto = $row['contexto'];
	}
	mysqli_free_result($result3);

if($usado == 0) {
	$nom_usado = 'No';
} else {
	$nom_usado = 'Si';
}


$result2 = mysqli_query($link, "select a.pkyPreproductionNoteDetail as cod_preprod_det, a.codItem as cod_item, b.fldName as item, a.fldQuantity as cantidad, b.codMinimumStorageUnit as cod_unidad, c.fldName as unidad, d.pkyRecipe as cod_receta
from prdPreproductionNoteDetail a, invItem b, invStorageUnit c, prdRecipe d  
where 
a.codItem = b.pkyItem and 
b.codMinimumStorageUnit = c.pkyStorageUnit and 
a.codItem = d.codItem and 
a.codPreproductionNote = '$cod_preprod'
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>Nota de Preproducci&oacute;n</b></font></center></p>
	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Cod. Reg.: </b><?php echo $cod_preprod; ?></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>Linea de Producci&oacute;n: </b><?php echo $linea_prod; ?></TD>
        <TD><b>Usada: </b><?php echo $nom_usado; ?></TD>
        <TD><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
        </TR>
        <TR> 
        <TD colspan="3"><b>Glosa: </b><?php echo $glosa; ?></TD>
        </TR>
    </table>
<br />
<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
		
		$uni[$i] = $row['cod_unidad'];
		$total_unidad = $row['unidad'];
		$cod_receta = $row['cod_receta'];
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_preprod_det']);//cod preproduccion detalle
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_preprod_det']);//cod preproduccion detalle
		} //cierra if color
		printf("<td align='center'><a href='../../ModuleProduction/VoucherRecipe/index.php?pkyRecipe=$cod_receta&user=$usuario&token=$token' title='Receta'>%s</a></td>", $row['cod_item']);//cod item
		printf("<td align='left'>%s</td>", $row['item']);//item
		printf("<td align='left'>%s</td>", $row['unidad']);//unidad
		printf("<td align='right'>%s</td></tr>", number_format($row['cantidad'], $n_cantidad));//total
				
		$suma_cantidad = $suma_cantidad + $row['cantidad'];
		$color++;
	}//fin while
	mysqli_free_result($result2);
	
	$fin_i = $i;
	$valor_uni = 0;
	$uni_ini = $uni[1];
	for($i = 2; $i < $fin_i; $i++) {
		if($uni_ini != $uni[$i]) { $valor_uni = 1; }
	}
	
	if($valor_uni == 1) { $total_unidad = '(El total en cantidad es solo referencial, las unidades de los items no son iguales)'; }
	if($valor_uni == 0) { $total_unidad = ' '; }
/*	
	//convierte el total en literal
	$letras=new NroEnLetra($suma_cantidad,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;
	}
*/	
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="4"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php //echo $mostrar_letras; ?> <?php echo $total_unidad; ?></b></td>
    <td align="right"><b><?php echo number_format($suma_cantidad, $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>

</body>
</html>
