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

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

?>
<body>

<?php
	
// Inicio impresion proyeccion de produccion

$result3 = mysqli_query($link, "select a.pkyProductionProjection as cod_proy, a.fldDocumentNumber as nro_doc, a.fldInitDate as fecha_ini, a.fldEndDate as fecha_fin, a.fldUsed 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 prdProductionProjection a, accGroup g, srvContext s
where 
a.sysAuthorizationGroup = g.pkyGroup and 
a.sysContext = s.pkyContext and 
a.pkyProductionProjection = '$cod_proyprod';");
	while ($row = mysqli_fetch_array($result3)) {
	$nro_doc = $row['nro_doc'];
	$fecha_ini = $row['fecha_ini'];
	$fecha_fin = $row['fecha_fin'];
	$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';
}

//items
	$result2 = mysqli_query($link, "select a.pkyProductionProjectionItem as cod_proyitem, a.codItem as cod_item, b.fldName as item, a.fldAmount as cantidad, a.fldPercent as ponderacion
from prdProductionProjectionItem a, invItem b
where 
a.codItem = b.pkyItem and 
a.codProductionProjection = '$cod_proyprod'
order by b.fldName;");

//costos indirectos
	$result4 = mysqli_query($link, "select a.pkyProductionProjectionItemExpense as cod_cosind, b.fldName as concepto, c.fldName as gasto, a.fldAmount as monto
from prdProductionProjectionItemExpense a, prdProductionConcept b, payExpensesConcept c
where 
a.codProductionConcept = b.pkyProductionConcept and 
a.codExpensesConcept = c.pkyExpensesConcept and  
a.codProductionProjection = '$cod_proyprod'
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>Proyecci&oacute;n de Producci&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_proyprod; ?></TD>
        <TD width="33%"><b>Nro. Doc.: </b><?php echo $nro_doc; ?></TD>
        <TD width="33%"><b>Usada: </b><?php echo $nom_usado; ?></TD>
        </TR>
        <TR>
        <TD><b>Fecha Inicial: </b><?php echo $fecha_ini; ?></TD>
        <TD><b>Fecha Final: </b><?php echo $fecha_fin; ?></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 />
<b>Items:</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>Cant.</b></TD>
    <TD align="center" width="100"><b>Ponderaci&oacute;n</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_cantidad = 0;
	$suma_pond = 0;
	$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_proyitem']);//cod proyeccion detalle
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_proyitem']);//cod proyeccion 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='right'>%s</td>", number_format($row['cantidad'], $n_cantidad));//cantidad
		printf("<td align='right'>%s</td></tr>", number_format($row['ponderacion'], $n_decimales));//ponderacion

		$suma_cantidad = $suma_cantidad + $row['cantidad'];
		$suma_pond = $suma_pond + $row['ponderacion'];
		$color++;
	}//fin while
	mysqli_free_result($result2);
	
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="3"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_cantidad, $n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_pond, $n_decimales); ?></b></td>
    </tr>
</tbody>    
</table>
<br />
<b>Costos Indirectos:</b>
<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center" width="100"><b>Cod.</b></TD>
    <TD align="center"><b>Concepto Producci&oacute;n</b></TD>
    <TD align="center"><b>Concepto Gasto</b></TD>
    <TD align="center" width="100"><b>Monto</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_monto = 0;
	$i = 1;
		
	while ($row = mysqli_fetch_array($result4)) { //while
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_cosind']);//cod costo ind detalle
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_cosind']);//cod costo ind detalle
		} //cierra if color
		printf("<td align='left'>%s</td>", $row['concepto']);//concepto produccion
		printf("<td align='left'>%s</td>", $row['gasto']);//concepto gasto
		printf("<td align='right'>%s</td></tr>", number_format($row['monto'], $n_decimales));//monto

		$suma_monto = $suma_monto + $row['monto'];
		$color++;
	}//fin while
	mysqli_free_result($result4);
	
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="3"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_monto, $n_decimales); ?></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>
