<?php
if($_POST["buscar"] != ''){
$cont = $_POST["cont-oculto"];
// for($i = 1; $i <= $cont; $i++){
// $variable = $_POST["campo".$i];
// $variable1 = $_POST["campo1".$i];
// echo "<br />";
// echo $cont;
$sql ="SELECT profolio,(prodescuadria||'x'||prodlargo) as escuadria, ".
"prodvolumen, ".
"prodpzas, ".
"simtrozosconsumo, ".
"split_part(prodescuadria,'x',1) as part1, ".
"split_part(prodescuadria,'x',2) as part2, ".
"prodlargo ".
"FROM (SELECT a.profolio,a.esqcodigo,a.patcodigo,b.simcodigo, ".
"b.simtrozosconsumo ".
"FROM (SELECT profolio,esqcodigo,patcodigo,simcodigo, ".
"simtrozosconsumo ".
"FROM simulaciones ".
"WHERE profolio IN (";
//Para cada elemento agrego el valor al la cadena $sql
for($i = 1; $i <= $cont; $i++){
$variable = $_POST["campo".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable."'";
}
//A partir de aqui creo que debes corregir mas cosas...
$sql .=") AND patcodigo IN (";
for($i = 1; $i <= $cont; $i++){
$variable1 = $_POST["campo1".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable1."'";
}
$sql .=")) b,esquemaprograma a ".
" WHERE a.profolio IN (";
for($i = 1; $i <= $cont; $i++){
$variable = $_POST["campo".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable."'";
}
$sql .=") AND a.patcodigo IN (";
for($i = 1; $i <= $cont; $i++){
$variable1 = $_POST["campo1".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable1."'";
}
$sql .=") AND a.profolio=b.profolio AND a.esqcodigo=b.esqcodigo AND a.patcodigo=b.patcodigo ".
"GROUP BY a.profolio,a.esqcodigo,a.patcodigo,b.simcodigo,b.simtrozosconsumo) c,produccionsimulada a ".
"WHERE a.simcodigo=c.simcodigo AND prodtipo!='C' ".
"ORDER BY prodvolumen DESC";
//echo $sql."<br />";
$result = pg_query ( $dbconn, $sql ) or
die ("ERROR EN CONSULTA");
$suma = 0;
//echo number_format( ($row["prodvolumen"]), 3,',','');
//echo "<br />";
$total = $total + $row["prodvolumen"];
}
//echo number_format($total, 3,',','');
}
//}
}
if($_POST["buscar"] != ''){
$cont = $_POST["cont-oculto"];
for($i = 1; $i <= $cont; $i++){
// $variable = $_POST["campo".$i];
$variable2 = $_POST["campo2".$i];
}
// echo "<br />";
// echo $cont;
$sql ="SELECT profolio,(prodescuadria||'x'||prodlargo) as escuadria, ".
"prodvolumen, ".
"prodpzas, ".
"simtrozosconsumo, ".
"split_part(prodescuadria,'x',1) as part1, ".
"split_part(prodescuadria,'x',2) as part2, ".
"prodlargo ".
"FROM (SELECT a.profolio,a.esqcodigo,a.patcodigo,b.simcodigo, ".
"b.simtrozosconsumo ".
"FROM (SELECT profolio,esqcodigo,patcodigo,simcodigo, ".
"simtrozosconsumo ".
"FROM simulaciones ".
"WHERE profolio IN (";
//Para cada elemento agrego el valor al la cadena $sql
for($i = 1; $i <= $cont; $i++){
$variable = $_POST["campo".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable."'";
}
//A partir de aqui creo que debes corregir mas cosas...
$sql .=") AND patcodigo IN (";
for($i = 1; $i <= $cont; $i++){
$variable1 = $_POST["campo1".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable1."'";
}
$sql .=")) b,esquemaprograma a ".
" WHERE a.profolio IN (";
for($i = 1; $i <= $cont; $i++){
$variable = $_POST["campo".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable."'";
}
$sql .=") AND a.patcodigo IN (";
for($i = 1; $i <= $cont; $i++){
$variable1 = $_POST["campo1".$i];
if($i!=1) $sql .=",";
$sql .="'".$variable1."'";
}
$sql .=") AND a.profolio=b.profolio AND a.esqcodigo=b.esqcodigo AND a.patcodigo=b.patcodigo ".
"GROUP BY a.profolio,a.esqcodigo,a.patcodigo,b.simcodigo,b.simtrozosconsumo) c,produccionsimulada a ".
"WHERE a.simcodigo=c.simcodigo AND prodtipo!='C' ".
"ORDER BY prodvolumen DESC";
//echo $sql."<br />";
$result = pg_query ( $dbconn, $sql ) or
die ("ERROR EN CONSULTA"); //Contador de Enumeracion
$numeracion = 1;
$suma = 0;
$suma = $suma + $row["prodvolumen"];
?>
<tr>
<th background="imag/bg_menuon.gif"><?php echo $numeracion++; ?></th>
<td align="center"><?php echo $row["escuadria"]; ?></td>
<td align="center"><?php echo $row["simtrozosconsumo"]; ?></td>
<td align="center"><?php echo $row["prodpzas"];
$suma_pzas = $suma_pzas + $row["prodpzas"];
?></td>
<td align="center">
<?php echo number_format($row["prodvolumen"], 2,',',''); ?></td>
<td align="center"><?php $porcent = ( $row["prodvolumen"] / $total ) * 100;
//echo "<br />";
$suma_porcent = $suma_porcent + $porcent;
?></td>
<td align="right"><?php //echo $variable2;
//echo "<br />";
$real = (($variable2 * $row["prodpzas"])/$row["simtrozosconsumo"]);
$real_total = $real_total + $real;
?></td>
<?php $largo = (($row["prodlargo"])*1000);
$vol = (($row["part1"])/1000) * (($row["part2"])/1000) * (($largo)/1000);
//echo number_format($vol, 3,',',''); ?>
<td align="right" background="imag/bg_menuon.gif">
<?php
//echo $row["part1"];
//echo "<br />";
//echo $row["part2"];
//echo "<br />";
//echo $largo;
//echo "<br />";
//echo $vol;
//echo "<br />";
$volumen_real = $real * $vol;
$volumen_real_total = $volumen_real_total + $volumen_real;
?></td>
<?php
}
}
//}
}
?>