<?php
 
session_start();
include("DMMYSQLG.php");
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" 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=DG23000_PR2.php"  HTTP-EQUIV="REFRESH">';
}else{
?>
  <input name="ver" type="hidden" value="1">
 <input name="tdis" type="hidden" 
	<?php
 
	if(isset($_POST['tncli'])){
		@$result = mysqli_query($con ,"SELECT * FROM dgcatcli WHERE cod_cli = '".$_POST['tncli']."'");
	}else{
		@$result = mysqli_query($con ,"SELECT * FROM dgcatcli WHERE cod_cli = '".$_POST['tdis']."'");
	}
	@$row = mysqli_fetch_array($result);
	echo 'value="'.$row['tip_cte'].'"';
	?>
 >
 
  <table width="876"  align="center">
<tr>
<td colspan="5" class="tdagre1">
    <?php
  
echo 'Numero de venta:'.$_POST['bot'];
@$result1 = mysqli_query($con ,"SELECT * FROM dgpemema WHERE fol_ven = '".$_POST['bot']."'");
while(@$row = mysqli_fetch_array($result1))
{
	$op1=$row["tip_ven"];
	$op2=$row["fec_ven"];
	$op3=$row["cod_cli"];
	$op4=$row["con_cre"];
	$op5=$row["alm_gen"];
	$op6=$row["sub_ven"];
	$op7=$row["iva_ven"];
	$op8=$row["tot_ven"];
	$op9=$row["iva_des"];
	$op10=$row["por_des"];
	$op11=$row["cod_ven"];
	$op12=$row["des_ven"];
	$op13=$row["nom_cli_alt"];
}
?>  </td>
  </tr>
  <tr>
    <th colspan="5" class=\"titulo\">Datos de la Venta </th>
  </tr>
  <tr>
    <td width="117">Tipo de Venta:</td>
    <td width="267">
	<?php
 
		@$resultado=mysqli_query($con ,"select * from dgtipven where tip_ven like '%$op1%'");
		if(isset($_POST['ver1']))
		{
			@$res=mysqli_query($con ,"select * from dgtipven where tip_ven like '%".$_POST['ver1']."%'");
			while(@$reg=mysqli_fetch_array($res))
			{
				echo '<input name="ver1" type="hidden" value="'.$reg['tip_ven'].'">';
				echo $reg['des_tipven'];
			}
		}else{
			while(@$registro=mysqli_fetch_array($resultado))
			{
				echo '<input name="ver1" type="hidden" value="'.$registro['tip_ven'].'">';
				echo $registro['des_tipven'];
			}		
		}	
	?>&nbsp;</td>
    <td>Fecha de Venta : 
	  <?php
 
		if(isset($_POST['ver2']))
		{
			echo '<input name="ver2" type="hidden" value="'.$_POST['ver2'].'">';
			echo $_POST['ver2'];
		}else{
			$fec1=$op2;
			include("DF20000.php");
			echo '<input name="ver2" type="hidden" value="'.$f_f.'">';
			echo $f_f;
		}
	?>	</td>
    <td colspan="2">Venta a:  	 
      <?php
 
	  	if(isset($_POST['ver3'])){
			echo '<input name="ver3" type="hidden" value="'.$_POST['ver3'].'">';
			echo $_POST['ver3'];
		}else{
			if($op4 == 1){
				echo '<input name="ver3" type="hidden" value="CONTADO">';
				echo "CONTADO";
			}else{
				echo '<input name="ver3" type="hidden" value="CREDITO">';
				echo "CREDITO";
			}
		}
	?></td>
    </tr>
  <tr>
    <td>Vendedor: </td>
    <td><?php
 
		@$resultado=mysqli_query($con ,"select * from dgcatven where cod_ven = '$op11'");
		if(isset($_POST['ver11']))
		{
			echo '<input name="ver11" type="hidden" value="'.$_POST['ver11'].'">';
			echo $_POST['ver11'];
		}else{
			while(@$registro=mysqli_fetch_array($resultado))
			{
				echo '<input name="ver11" type="hidden" value="'.$registro['nom_ven'] . ' ' . $registro['ap_pat_ven'].'">';
				echo $registro['nom_ven'] . ' ' . $registro['ap_pat_ven'];
			}		
		}	
	?></td>
    <td>Descuento de Venta :
      <?php
 
	  	if(isset($_POST['ver31'])){
			echo '<input name="ver31" type="hidden" value="'.$_POST['ver31'].'">';
			echo $_POST['ver31'];
		}else{
			echo '<input name="ver31" type="hidden" value="'.$op10.'">';
			echo $op10;
		}
		echo ' %';
	?></td>
    <td width="129">Iva Desglosado: </td>
    <td width="68"><?php
 
	
	  	if(isset($_POST['ver311'])){
			echo '<input name="ver311" type="hidden" value="'.$_POST['ver311'].'">';
			echo $_POST['ver311'];
		}else{
			if($op9 == 0){
				echo '<input name="ver311" type="hidden" value="NO">';
				echo "NO";
			}else{
				echo '<input name="ver311" type="hidden" value="SI">';
				echo "SI";
			}
		}
	?></td>
  </tr>
  <tr>
    <td>Cliente: </td>
    <td colspan="2"><?php
 
		if(isset($_POST['ver33']))
		{
			@$res=mysqli_query($con ,"select * from dgcatcli where cod_cli = '".$_POST['ver33']."'");
			while(@$reg=mysqli_fetch_array($res))
			{
				echo '<input name="ver33" type="hidden" value="'.$_POST['ver33'].'">';
				echo '<input name="verd" type="hidden" value="'.$reg['distribuidor'] .'">';
				echo $reg['nom_cli'] . ' ' . $reg['ap_pat_cli'];
			}	
		}else{
			@$resultado=mysqli_query($con ,"select * from dgcatcli where cod_cli = '$op3'");
			while(@$registro=mysqli_fetch_array($resultado))
			{
				echo '<input name="ver33" type="hidden" value="'.$op3.'">';
				echo '<input name="verd" type="hidden" value="'.$registro['distribuidor'] .'">';
				echo $registro['nom_cli'] . ' ' . $registro['ap_pat_cli'];
			}		
		}	
	?></td>
    <td>N&ordm; de Cliente </td>
    <td><?php
 
		if(isset($_POST['tnc']))
		{
			echo '<input name="tnc" type="hidden" value="'.$_POST['tnc'].'">';
			echo $_POST['tnc'];
		}else{
			echo '<input name="tnc" type="hidden" value="'.$op3.'">';
			echo $op3;
		}	
	?></td>
  </tr>
  <tr>
    <td>Nombre de Cliente Alterno: </td>
    <td colspan="2">
<?php
 
	if(isset($_POST['ver26']))
	{
		echo '<input name="ver26" type="hidden" value="'.$_POST['ver26'] .'">';
		echo $_POST['ver26'];
	}else{
		echo '<input name="ver26" type="hidden" value="'.$op13.'">';
		echo $op13;
	}	
?>&nbsp;</td>
    <td>Almacen</td>
    <td><?php
 
	if($al <> ""){
		$_SESSION['al']=$al;
	}
	@$re=mysqli_query($con ,"select * from dgalmacen where almacen = '".$_SESSION['al']."'");
	@$reg=mysqli_fetch_array($re);
	echo $reg['desc_almacen'];
	?>      &nbsp;&nbsp;</td>
  </tr>
</table>
  </div>
<table border='1' align="center">
    <tr>
      <th colspan="11"> </th>
    </tr>
    <tr>
      <th><div align="center">Clave Producto</div></th>
      <th><div align="center">Descripcion</div></th>
	  <th><div align="center">Precio Base</div></th>
	  <th><div align="center">Cantidad</div></th>
	  <th><div align="center">% Descuento</div></th>
	  <th><div align="center">Descuento</div></th>
      <th><div align="center">Precio Unitario</div></th>
	  <th><div align="center">Sub - total</div></th>
	  <th><div align="center">Iva</div></th>
	  <th><div align="center">Total</div></th>
    </tr>

<?php

	//saca el numero de producto
	@$res=mysqli_query($con ,"select * from dgpememd 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 dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 like '$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 dgpememd where cons_ven LIKE '".$_POST['bot']."' && nparte1 like '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			echo '<tr>';
			echo '<td><div align="center">' . $npr[$y] . '</div></td>';
			echo '<td><div align="center">' . $dpr[$y] . '</div></td>';
			$pbas=$row['pre_uni']/1.15;
			echo '<td><div align="center">$ ' . number_format($pbas, 2, '.', ',') . '</div></td>';
			$pbase =  $pbase + $pbas;
			echo '<td><div align="center">' . $row['can_ref'] . '</div></td>';
			$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, 2, '.', ',') . '</div></td>';
			$p = $p + $pre_u;
			//sacra el iva
			$sbt = $pre_u * $row['can_ref'];
			echo '<td><div align="center">$ ' . number_format($sbt, 2, '.', ',') . '</div></td>';
			$s = $s + $sbt;
			//$ti = $sbt
			$ivpp = $sbt * .15;
			echo '<td><div align="center">$ ' . number_format($ivpp, 2, '.', ',') . '</div></td>';
			$iv = $iv + $ivpp;
			$t = $ivpp + $sbt;
			echo '<td><div align="center">$ ' . number_format($t, 2, '.', ',') . '</div></td>';
			$tot = $tot + $t;
			echo '</tr>'; 
		}
	}
 mysqli_close($con);
?>
<th>Totales</th>
      <th>&nbsp;</th>
	<th>
	<?php
 
	echo '<input name="txt_pb" type="hidden" value="'.$pbase.'">';
	echo '$' . number_format($pbase, 4, '.', ',');
	?>	</th>
	<th>&nbsp;</th>
      <th>&nbsp;</th>
	<th>
	<?php
 
	echo '<input name="txt_d" type="hidden" value="'.$d.'">';
	echo '$' . number_format($d, 4, '.', ',');
	?>	</th>
	    <th>
	<?php
 
	echo '<input name="txt_p" type="hidden" value="'.$p.'">';
	echo '$' . number_format($p, 4, '.', ',');
	?>	</th>
	    <th>
	<?php
 
	echo '<input name="txt_s" type="hidden" value="'.$s.'">';
	echo '$' . number_format($s, 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="'.$tot.'">';
	echo '$' . number_format($tot, 2, '.', ',');
	?>	</th>
  </table>
  <div align="center">
    <input name="Submit5" type="Submit" value="Regresar" onClick="openpage('DG23000_PR2.php','_self')">
  </div>
  <?php
 } ?>
</form>
</body>
</html>
