<?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['thh']=="22"){//Imprimir
	include('DG24000_RE.php');
	exit();
}
if (isset($_POST['Cancelar'])){//si CANCELAR
	include('DG24000_AC9.php');
}
if (isset($_POST['th']) and $_POST['th']<>""){//si elimina producto 
	//echo 'hola';
	include('DG24000_AC7.php');
}elseif (isset($_POST['producto'])){//si agrega producto 
	include('DG24000_AC6.php');
}

//fin
if (isset($_REQUEST['venta'])){
	include('DG24000_AC8.php');
	$nr = mysqli_insert_id($con);
	echo '<input name="tnum" type="hidden" value="'.$nr.'">';	
	$pedido = $nr;
}else{
	echo '<input name="tnum" type="hidden" value="'.$_REQUEST['tnum'].'">';	
	$pedido = $_REQUEST['tnum'];
}
$datos = mysqli_fetch_array(mysqli_query($con ,"select * from dgpemema where fol_ven = '$pedido'"));
?>
  <table  align="center">
    <tr>
      <tH colspan="12">PUNTO DE VENTA </TH>
    </tr>
    <tr>
      <td colspan="12" class="estilotabla">PEDIDO N&deg;<?php
 echo $pedido ?> </td>
    </tr>
    <tr>
      <td class="tragre">Cajero:</td>
      <td class="tragre">
<?php
 
	@$reg=mysqli_fetch_array(mysqli_query($con ,"select * from dgcatven where cod_ven = '".$datos['cod_ven']."'"));
	echo $reg['nom_ven'].' '.$registro['ap_pat_ven'].' '.$registro['ap_mat_ven'].' '.'&nbsp;';
?>	  </td>
      <td class="tragre">tipo de venta: </td>
      <td class="tragre">
<?php
 
	@$reg=mysqli_fetch_array(mysqli_query($con ,"select * from dgtipven where tip_ven = '".$datos['tip_ven']."'"));
	echo $reg['des_tipven'].'&nbsp;';
?>	  </td>
      <td class="tragre">Almacen</td>
      <td class="tragre">
<?php
 
	@$reg=mysqli_fetch_array(mysqli_query($con ,"select * from dgalmacen where almacen = '".$datos['alm_gen']."'"));
	echo $reg['desc_almacen'].'&nbsp;';
?>	  </td>
	  <td class="tragre">Cliente</td>
      <td class="tragre">
<?php
 
	@$reg=mysqli_fetch_array(mysqli_query($con ,"select * from dgcatcli where cod_cli = '".$datos['cod_cli']."'"));
	echo $reg['nom_cli'].' ' .$registro['ap_pat_cli'].' ' .$registro['ap_mat_cli'].' ' . '&nbsp;';
?>	  </td>
      <td class="tragre">Fecha</td>
      <td class="tragre"><?php
 echo date("d/m/Y") ?></td>
	  <td class="tragre">Hora</td>
      <td class="tragre"><?php
 echo date("H:i:s") ?></td>
    </tr>
  </table>
  <table border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>CANTIDAD</td>
      <td>
        <input name="tcan" type="text" id="tcan" value="1" tabindex="1">
    </td>
      <td>PRODUCTO</td>
      <td>
        <input name="producto" type="text" id="producto" tabindex="2">
     </td>
      <td>
        <input name="Submit" type="submit" value="" class="chico">
		<?php
 
		@$dtparame=mysqli_fetch_array(mysqli_query($con ,"select * from dgparame"));
		$dt_dgpememd = mysqli_fetch_array(mysqli_query($con ,"select sum(total_cd) as suma_t from dgpememd where cons_ven = '".$_REQUEST['tnum']."'"));
		?>
		<input name="tvalida" type="hidden" value="">
		<script language="javascript1.2">
			function valida_pago(){
				if (document.frm1.tvalida.value==""){
					if (confirm("¿Seguro que Terminar el Pedido?")) {
						document.frm1.tvalida.value="1"; 
					}
				}else{
					if (document.frm1.ttotal.value==0 || document.frm1.ttotal.value==""){
						alert ("Agrega x lo menos un artuiculo");
					}
				}
			}
		</script>
        <input name="Terminar" type="button" class="agrega" value="Terminar" onMouseMove="valida_pago()" onClick="window.open('DG24000_AG4.php?select=<?php
 echo $datos['cod_ven'] ?>&tip_venx=<?php
 echo $_SESSION['tipven'] ?>&select2=<?php
 echo $_SESSION['tipven'] ?>&tncli=<?php
 echo $dtparame['cod_pubgral'] ?>&importe=<?php
 echo $dt_dgpememd['suma_t'] ?>&select4=<?php
 echo $_REQUEST['tnum'] ?>', 'cobro<?php
 echo date("His") ?>', 'width=800,height=300,top=100,left=50,scrollbars=yes,menubar=no,status=no')">
        <input name="Cancelar" type="submit" class="agrega" value="Cancelar">
  </td>
    </tr>
  </table>
  <table border='1' align="center">
    <tr>
      <th><div align="center">Sel</div></th>
      <th><div align="center">Clave Producto</div></th>
      <th><div align="center">Descripcion</div></th>
      <th><div align="center">Precio Unitario</div></th>
      <th><div align="center">Cantidad</div></th>
      <th><div align="center">Total</div></th>
    </tr>
    <?php

if (isset($_POST['boton_car']) || isset($_POST['producto']) || isset($_POST['Submit'])){
	//saca el numero de producto
	@$res=mysqli_query($con ,"select * from dgpememd where cons_ven = '".$_POST['tnum']."'");
	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 = '".$_POST['tnum']."' and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			echo '<tr><td>';
			
			echo '<div align="center">';
			?>
			<input name="beliminar" id="beliminar" value="<?php
 echo $y ?>" type="image" src="logos/cerrar.gif" onClick="mandar('<?php
 echo $y ?>')"/>
			<?php

			echo '</div>';
			echo '<input name="nu_re1'.$y.'" type="hidden" value="'.$nrx[$y].'">';
			echo '<input name="nu_re2'.$y.'" type="hidden" value="'. $npr[$y].'">';
			echo '</td><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'], 4, '.', ',') . '</div></td>';
			$pbase =  $pbase + $pbas;
			$c = $c + $row['can_ref'];
			//echo '<td><div align="center">' . number_format($row['por_des'], 4, '.', ',') . '  %</div></td>';
			//echo '<td><div align="center">$ ' . number_format($row['des'], 4, '.', ',') . '</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($sbt, 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 = $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="5"><div align="right">Total</div></th>
    <th> <?php
 
	echo '<input name="txt_to" type="hidden" value="'.$tot.'">';
	echo '$' . number_format($tot, 2, '.', ',');
	?>      </th>
  </table>
  <input type="hidden" name="ttotal" id="ttotal" value="<?php
 echo $tot ?>">
  <input type="hidden" name="th" id="th">
  <input name="thh" type="text" id="thh" onFocus="javascript: document.getElementById('frm1').submit()" size="1">
</form>
</body>
</html>
<script language="javascript1.2">
	document.frm1.producto.focus();
	function mandar(va){
		document.frm1.th.value=va; 
		document.getElementById('frm1').submit();
	}
</script>