<?php
 
session_start();
include("DMMYSQLG.php");
include("JQUERY.inc");
$npr=array();
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<style type="text/css">BODY {
SCROLLBAR-FACE-COLOR:#0000CC; SCROLLBAR-HIGHLIGHT-COLOR:#00CCFF; SCROLLBAR-SHADOW-COLOR:#0000CC; SCROLLBAR-3DLIGHT-COLOR:#0000CC; SCROLLBAR-ARROW-COLOR:#FFFFFF; SCROLLBAR-TRACK-COLOR:#FFFFFF; SCROLLBAR-DARKSHADOW-COLOR: #330000
}
</style>
<body>
<form name="frm1" id="frm1" method="post" action="">

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

?>     </td>
   </tr>
   <tr>
     <th colspan="4" class=\"titulo\">DATOS DE ENTRADA. </th>
   </tr>
   <tr>
     <td>ORDEN DE COMPRA. </td>
     <td><input name="numero_folio" type="text" id="numero_folio" tabindex="4" size="40" readonly=""
 <?php
 
  if(isset($_POST['bot'])){
	  	echo 'value = "'.$op14.'"';
	  }
	  ?>
 ></td>
     <td colspan="2">FECHA.
      <?php
 
			$fec1=$row["fec_ven"];
			include("DF20000.php");
			echo $f_f;
		}
	?></td>
   </tr>
   <tr>
     <td>PROVEEDOR.</td>
     <td><?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 colspan="2">&nbsp;</td>
   </tr>
   <tr>
     <td width="117">FACTURA.</td>
     <td width="267"><?php
 
			@$res=mysqli_query($con ,"select * from dgreqdev where trefe = '".$row['trefe']."'");
			@$reg=mysqli_fetch_array($res);
			//echo '<input name="ver6" type="hidden" value="'.$reg['trefe'].'">';
			echo $reg['trefe'];
	?></td>
     <td colspan="2">&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>        <div align="center"></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'];
			//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;
			//$ti = $sbt
			$ivpp = $row['iva_pre'] ;
			echo '<td><div align="center">$ ' . number_format($ivpp, 2, '.', ',') . '</div></td>';
			$iv = $iv + $ivpp;
			$t = $ivpp + $sbt;
			echo '<td><div align="center">$ ' . number_format($row['total_cd'], 2, '.', ',') . '</div></td>';
			$tot = $tot + $t;
			$jsh = $jsh + $row['subtotal'];
			$vgf = $vgf + $row['des'];
            $iv = $iv + $ivpp;
			echo '</tr>'; 
		}
	}
 
 mysqli_close($con);
?>
  <th colspan="2">Totales</th>
      <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th> <?php
    $vg=(isset($vgf))?$vgf:0;
	echo '<input name="txt_s" type="hidden" value="'.$vg.'">';
	echo '$' . number_format($vg, 2, '.', ',');
	?>      </th>
    <th> <?php
    $vj=(isset($jsh))?$jsh:0;
	echo '<input name="txt_iv" type="hidden" value="'.$vj.'">';
	echo '$' . number_format($vj, 2, '.', ',');
	?>      </th>
    <th> <?php
 $vi=(isset($iv))?$iv:0;
	echo '<input name="txt_to" type="hidden" value="'.$vi.'">';
	echo '$' . number_format($vi, 2, '.', ',');
	?>      </th>
  </table>
  <div align="center">
	<?php 
	if($num_elementos == 0){ ?>
		<input type="button" name="Submit" value="Cancelar" onClick="openpage('AL10700_EC.php','_self')">
	<?php
	}else
		echo "PARA PODER CANCELAR, DEBE ELIMINAR PRIMERO TODAS LAS ENTRADAS DE LA FACTURA";
	?>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="Submit5" type="button" value="Regresar" onClick="openpage('AL10700_PR.php','_self')">
  </div>
</form>
</body>
</html>
