<?php
 
session_start();
include("DMMYSQLG.php");
include("JQUERY.inc");
$pbase=0;
$c=0;
$d=0;
$vgf=0;
$p=0;
$s=0;
$jsh=0;
$iv=0;
$juy=0;
$tot=0;
?>
<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:#000000; scrollbar-highlight-color:#9B0F1A; scrollbar-shadow-color:#9B0F1A; scrollbar-3dlight-color:#000000;
scrollbar-arrow-color:#9B0F1A; scrollbar-track-color:#9B0F1A; scrollbar-darkshadow-color:#000000;
}

.Estilo1 {color: #000;
font-weight:bold}
</style>
<body>
<form name="frm1" id="frm1" method="post" action="">
<input name="ver" type="hidden" value="1">
<input name="bot" type="hidden" value="<?php
 echo $_POST['bot']?>">
   <div id="width_titulos" align="center">
  <table width="476" align="center" >
<tr>
<td colspan="4">
    <?php 
    if(isset($_POST['Submit5'])){ 
          
	include('AL10700_CL.php');
		$varible_clase = new clase_entrada_varia();
		//$varible_clase->folio_control=strtoupper($_POST["numero_folio"]);	
                $fec=$_POST['ver2'];
			include("DF20000.php");
                       
		$varible_clase->fec_ven=$f_m;	
		$varible_clase->tip_ven=$_POST['ver1'];	
                $varible_clase->trefe=$_POST['ver6'];	
		$varible_clase->modificarf($_POST['bot']);
                
                        echo "<script>location.href='AL10700_AG2.php'</script>";
                        exit();
	}
	if(isset($_POST['+[a-z_]+'])){
           
	include('AL10700_CL.php');
		$varible_clase = new clase_entrada_varia();
		$varible_clase->folio_control=strtoupper($_POST["numero_folio"]);	
                
		$varible_clase->modificar($_POST['bot']);
	}

	if(isset($_POST['bot2'])){
		@$ultimo_id = mysqli_insert_id($con);
		echo '<input name="tnum" type="hidden" value="'.$_POST['bot'].'">';

		@$result = mysqli_query($con ,"SELECT * FROM dgreqdev WHERE fol_ven = '".$_POST['bot']."'");
	}else{
		echo '<input name="tnum" type="hidden" value="'.$_POST['tnum'].'">';

		@$result = mysqli_query($con ,"SELECT * FROM dgreqdev WHERE fol_ven = '".$_POST['tnum']."'");
	}	
	@$row = mysqli_fetch_array($result);
	$fol_ven=$row["fol_ven"];
	$op1=$row["tip_ven"];
	$op2=$row["fec_ven"];
	$op3=$row["cod_cli"];
	
	$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"];
	
	
	$op14=$row["folio_control"];
	$op15=$row["trefe"];


?>  </td>
  </tr>
  <tr>
    <td colspan="4" class="titulo">DATOS DE ENTRADA </td>
  </tr>
  <tr>
    <th style="#FFCC00"><strong>ORDEN DE COMPRA</strong></th>
    <td width="115"><span class="Estilo1">
      <input name="numero_folio" type="hidden" id="numero_folio" tabindex="4" size="40"
 <?php
 
  if(isset($_POST['bot'])){
	  	echo 'value = "'.$op14.'"';
	  }
	  ?>
 >
      <?php
 echo str_pad($op14,5,'0',STR_PAD_LEFT); ?> </span></td>
    <th><span class="Estilo1">FECHA :</span></th>
    <td width="70"><span class="Estilo1">
      <?php
		if(isset($_POST['ver2'])){
			echo '<input name="ver2" type="hidden" value="'.$_POST['ver2'].'">';
			echo $_POST['ver2'];
		}else{
			$fec1=$op2;
			include("DF20000.php");
			$entradas = mysqli_fetch_array(mysqli_query($con ,"select count(*) as cantidad from dgreqded where cons_ven = '".$_POST['tnum']."' or cons_ven = '".$_POST['bot']."'"));
			if ($entradas['cantidad'] == 0)
				echo '<input name="ver2" class="date" type="text" value="'.$f_f.'">';
			else
				echo '<input name="ver2" type="hidden" value="'.$f_f.'">';
			echo $f_f;
		}
	?>
    </span></td>
  </tr>
  <tr>
    <th style="#FFCC00"><strong>PROVEEDOR</strong></th>
    <td colspan="3"><span class="Estilo1">
		<select name="ver1" id="ver1">
			<option value="">---------SELECCIONE---------</option>
			<?php
			$sql = mysqli_query($con ,"SELECT * FROM fproveedores where t1='ACTIVO' order by np_desc1 ");
			if(isset($_POST['ver1']))
				$prov = $_POST['ver1'];
			else
				$prov = $op1;
			while($reg=mysqli_fetch_array($sql)){
				if($prov == $reg['nparte1'] ){
					echo '<option value="' . $reg['nparte1'] . '" selected>' . $reg['np_desc1'] . '</option>';
				}else{
					echo '<option value="' . $reg['nparte1'] . '">' . $reg['np_desc1'] . '</option>';
				}
			}			
			?>       
		</select>
    </span></td>
    </tr>
  <tr>
    <th width="153" style="#FFCC00"><strong>FACTURA</strong></th>
    <td colspan="3"><span class="Estilo1">
      <?php
 
		
		if(isset($_POST['ver6']))
		{
			@$res=mysqli_query($con ,"select * from dgreqdev where trefe = '".$_POST['ver6']."'");
			@$reg=mysqli_fetch_array($res);
			echo '<input name="ver6" type="text" value="'.$reg['trefe'].'">';
			//echo str_pad($reg['trefe'],5,'0',STR_PAD_LEFT);
		}else{
			@$res=mysqli_query($con ,"select * from dgreqdev where trefe = '$op15'");
			@$reg=mysqli_fetch_array($res);
			echo '<input name="ver6" type="text" value="'.$reg['trefe'].'">';
			//echo str_pad($reg['trefe'],5,'0',STR_PAD_LEFT);
		}	
	?>
    </span></td>
    </tr>
	</table>
  </div>


 <?php

/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////si eprecionan el boton de eliminar/
/////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['Submit2'])){
	include('AL10700_AC7.php');	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////Si se agrega un producto para la venta
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//if (isset($_POST['boton_car'])){
	//include('AL10700_AC6.php');
//}
if (isset($_POST['boton_car'])){  //AGREGA LOS ARTICULOS 
//				include('AL10700_AC6.php');
}


?>
<div id="width_factura" align="center">
<table border='1' align="center" bordercolor="#9B0F1A" bordercolordark="#9B0F1A">
    <tr>
      <td colspan="7" class="titulo"><div align="left">
        <input type="submit" name="Submit2" value="CAMBIAR" class="bot_RjR" onClick="<?php
 if ($op14==0){?>openpage('AL10700_AC.php?sub=<?php
 echo $juy;?>','_self'); <?php
 }else {?>openpage('AL10700_AC.php?sub=<?php
 echo $juy?>','_self');<?php
 }?>">
    
      </div></td>
      <td colspan="2" class="titulo"><input name="Submit5" type="Submit" value="Terminar Captura" class="bot_WsW"></td>
    </tr>
    <tr>
	  
      <th width="52"><div align="center">CLAVE</div></th>
      <th width="132"><div align="center">DESCRIPCION</div></th>
	  <th width="76"><div align="center">PRECIO</div></th>
	  <th width="78"><div align="center">% DESC</div></th>
	  <th width="99"><div align="center">DESCUENTO</div></th>
      <th width="82"><div align="center">CANTIDAD</div></th>
	  <th width="77"><div align="center">IMPORTE</div></th>
	  <th width="78"><div align="center">I.V.A.</div></th>
	  <th width="88"><div align="center">TOTAL</div></th>
    </tr>

<?php

if (isset($_POST['boton_car']) || isset($_POST['producto']) || isset($_POST['Submit2']) || isset($_POST['Submit'])  || isset($_POST['bot2'])){
	//saca el numero de producto
	@$res=mysqli_query($con ,"select * from dgreqded where cons_ven = '".$_POST['tnum']."' or 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['tnum']."' or cons_ven = '".$_POST['bot']."')and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			echo '<tr>';
			//echo '<td><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;
			//$ti = $sbt
			$jsh = $jsh + $row['subtotal'];
			$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><?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>
  <div align="center"></div>
</form>
</body>
</html>

