<?php
 
session_start();
include("DMMYSQLG.php");
?>
<html>
<link rel="stylesheet" href="css/estilo1.csss" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<body>
<form name="frm1" id="frm1" method="post" action="">

<?php
 
if ($_POST['bot']==""){
	echo '<h2>!!! Selecciona un Registro !!!</h2>';
	echo '<meta content="1; url=AL21000_PR.php"  HTTP-EQUIV="REFRESH">';
}else{
?>
  <input name="ver" type="hidden" value="1">
 <table   align="center">
   <tr>
     <td colspan="3" class="men">
<?php
  
	@$result = mysqli_query($con ,"SELECT * FROM dgreqdev WHERE fol_ven = '".$_POST['bot']."'");	
	@$row = mysqli_fetch_array($result);
	$op3=$row["alm_gen"];
	$op1=$row["tip_ven"];
	$op14=$row["folio_control"];
	$op15=$row["trefe"];

?>     </td>
   </tr>
   <tr>
     <th colspan="3" class=\"titulo\">DATOS DE ENTRADA. </th>
   </tr>
   <tr>
     <td>ORDEN DE COMPRA. </td>
     <td width="254"><input name="numero_folio" type="text" id="numero_folio" tabindex="4" size="40" readonly=""
 <?php
 
  if(isset($_POST['bot'])){
	  	echo 'value = "'.$op14.'"';
	  }
	  ?>
 ></td>
     <td width="101">FECHA.
      <?php
 
			$fec1=$row["fec_ven"];
			include("DF20000.php");
			echo $f_f;
		}
	?></td>
   </tr>
   <tr>
     <td>PROVEEDOR.</td>
     <td>&nbsp;
      <?php
 
		//echo $op1.'<br>';
		@$resultado=mysqli_query($con ,"select * from fproveedores where nparte1 = '".$row['tip_ven']."'");
		@$registro=mysqli_fetch_array($resultado);
		echo $registro['np_desc1'];
		
	?></td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td width="117">FACTURA.</td>
     <td><?php
 
		//echo $op1.'<br>';
		@$resultado=mysqli_query($con ,"select * from dgreqdev where trefe = '$op15'");
		@$registro=mysqli_fetch_array($resultado);
		echo $registro['trefe'];
		
	?></td>
     <td>&nbsp;</td>
    </tr>
 </table>
 </div>
<table border='1' align="center">
    <tr>
      <th><div align="center">SEL.</div></th>
      <th><div align="center">CLAVE.</div></th>
      <th><div align="center">DESCRIPCION.</div></th>
      <th><div align="center">PRECIO.</div></th>
      <th><div align="center">% DESC.</div></th>
      <th><div align="center">DESCUENTO.</div></th>
      <th><div align="center">CANTIDAD.</div></th>
      <th><div align="center">IMPORTE.</div></th>
      <th><div align="center">I.V.A.</div></th>
      <th><div align="center">TOTAL</div></th>
    </tr>
    <?php

	//saca el numero de producto
	@$res=mysqli_query($con ,"select * from dgreqded where cons_ven = '".$_POST['bot']."'");
	while($row = mysqli_fetch_array($res))
	{
		$npr[]=$row["nparte1"];	
		$nrx[]=$row["fol_ven1"];	
	}
	//contar cuantos registros
	$num_elementos=count($npr);
	//saca la descripcion del producto
	for($j=0;$j<=$num_elementos-1;$j++)
	{
		@$res=mysqli_query($con ,"SELECT * FROM farticulos WHERE farticulos.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '$npr[$j]'");
		while($row = mysqli_fetch_array($res))
		{
			$dpr[]=$row["np_desc1"];	
		}
	}
	$num_elementos1=count($npr);
	for($y=0;$y<=$num_elementos1-1;$y++)
	{	
		//mostrar datos encontrados en dgrefodd
		@$res=mysqli_query($con ,"select * from dgreqded where cons_ven = '".$_POST['bot']."' and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res)){
			echo '<tr><td>';
			echo '<div align="center"><input name="r5" type="radio" value="'.$row['fol_ven1'].'"/></div></td>';
			echo '<input name="nu_re1'.$y.'" type="hidden" value="'.$nrx[$y].'">';
			echo '<input name="nu_re2'.$y.'" type="hidden" value="'. $npr[$y].'">';
			echo '<td><div align="center">' . $npr[$y] . '</div></td>';
			echo '<td><div align="center">' . $dpr[$y] . '</div></td>';
			$pbas=$row['pre_uni'];
			echo '<td><div align="center">$ ' . number_format($row['pre_uni'], 2, '.', ',') . '</div></td>';
			$pbase =  $pbase + $pbas;
			$c = $c + $row['can_ref'];
			echo '<td><div align="center">' . number_format($row['por_des'], 2, '.', ',') . '  %</div></td>';
			echo '<td><div align="center">$ ' . number_format($row['des'], 2, '.', ',') . '</div></td>';
			$d = $d + $row['des'];
			$pre_u = $pbas - $row['des'];
			$vgf = $vgf + $row['des'];
			//echo '<td><div align="center">$ ' . number_format($pre_u, 4, '.', ',') . '</div></td>';
			$p = $p + $pre_u;
			//sacra el iva
			$sbt = $pre_u * $row['can_ref'];
			echo '<td><div align="center">' . $row['can_ref'] . '</div></td>';
			echo '<td><div align="center">$ ' . number_format($row['subtotal'], 2, '.', ',') . '</div></td>';
			$s = $s + $sbt;
			$jsh = $jsh + $row['subtotal'];
			//$ti = $sbt
			$ivpp = $row['iva_pre'] ;
			echo '<td><div align="center">$ ' . number_format($ivpp, 2, '.', ',') . '</div></td>';
			$iv = $iv + $ivpp;
			$t = $ivpp + $sbt;
			$juy= $juy + $row['total_cd'];
			echo '<td><div align="center">$ ' . number_format($row['total_cd'], 2, '.', ',') . '</div></td>';
			$tot = $tot + $t;
			echo '</tr>'; 
		}
	}
 
 mysqli_close($con);
?>
  <th colspan="2">Totales</th>
      <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th><?php
 
	echo '<input name="txt_s" type="hidden" value="'.$vgf.'">';
	echo '$' . number_format($vgf, 2, '.', ',');
	?></th>
    <th>&nbsp;</th>
    <th> <?php
 
	echo '<input name="txt_s" type="hidden" value="'.$jsh.'">';
	echo '$' . number_format($jsh, 2, '.', ',');
	?>      </th>
    <th> <?php
 
	echo '<input name="txt_iv" type="hidden" value="'.$iv.'">';
	echo '$' . number_format($iv, 2, '.', ',');
	?>      </th>
    <th> <?php
 
	echo '<input name="txt_to" type="hidden" value="'.$juy.'">';
	echo '$' . number_format($juy, 2, '.', ',');
	?>      </th>
  </table>
  <div align="center">
    <input name="Submit5" type="Submit" value="Regresar" onClick="cargapag('AL21000_PR.php','_self')">
  </div>
</form>
</body>
</html>
