<?php
 
session_start();
include("DMMYSQLG.php");
include("JQUERY.inc");
?>
<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="">
<input name="ver" type="hidden" value="1">

<input name="bot" type="hidden" value="<?php
 echo $_POST['bot']?>">
  <table   align="center">
<tr>
<td colspan="4" class="men">
    <?php
@$req=mysqli_query($con ,"SELECT * FROM dgrequie WHERE fol_ven = '".$_POST['bot']."'");
$rqeui=mysqli_fetch_array($req);
$isdir=($rqeui['aseg']!='')?'disabled="disabled"':'';

	if(isset($_POST['+[a-z_]+'])){
	include('AL10800_CL.php');
		$varible_clase = new clase_salida_varia();
		$varible_clase->folio_control=strtoupper($_POST["numero_folio"]);
		$varible_clase->modificar($_POST['bot']);
	}
	if(isset($_POST['modEnc'])){
		$articulos = array();
		$sql = mysqli_query($con ,"SELECT nparte1 FROM dgrequid where cons_ven = ".$_POST['bot']);
		while($reg = mysqli_fetch_array($sql)){
			$articulos[] = $reg ['nparte1'];
		}
		$fec=$_POST['ver2'];
		include("DF20000.php");
		include('AL10800_CL.php');
		$varible_clase = new clase_salida_varia();
		$varible_clase->folio_control=strtoupper($_POST["numero_folio"]);
		$varible_clase->fec_ven=$f_m;
		$varible_clase->tip_ven = $_POST['ver1'];
		//$sql = mysqli_query($con ,"SELECT fec_ven FROM dgrequid d WHERE d.fec_ven >= '".$f_m."' AND d.nparte1 IN (".implode(",", $articulos).") ORDER BY d.fec_ven DESC LIMIT 1");
		$entrada = mysqli_fetch_array($sql);
$entrada = null;
		if($entrada == null){
			$varible_clase->modificar($_POST['bot']);
			$varible_clase->modificardetalle($_POST['bot']);	
		}else
			@$mensaje = '<br>Si desea cambiar la fecha de la salida debe ser mayor a '.$entrada['fec_ven'];
	}
	if(isset($_POST['bot2'])){
		@$ultimo_id = mysqli_insert_id($con);
		echo '<input name="tnum" type="hidden" value="'.$_POST['bot'].'">';
		echo 'NUMERO DE FOLIO:'.$_POST['bot']; 
		@$result = mysqli_query($con ,"SELECT * FROM dgrequie WHERE fol_ven = '".$_POST['bot']."'");
	}else{
		echo '<input name="tnum" type="hidden" value="'.$_POST['tnum'].'">';
		echo 'NUMERO DE FOLIO:'.$_POST['tnum']; 
		@$result = mysqli_query($con ,"SELECT * FROM dgrequie 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"];
	
	//-->se verifica si afecta a produccion 
/*	$sq_material_con=mysqli_query($con ,"select * from dpmaterial_con where tip_requ='S' and noreg_requ='$fol_ven'");
	if(mysqli_num_rows($sq_material_con)>0){
		$dt_material_con=mysqli_fetch_array($sq_material_con);
		echo '<input name="s1" type="hidden" value="PT">';
		echo '<input name="s2" type="hidden" value="'.$dt_material_con["cve_ord"].'">';
		echo '<input name="s3" type="hidden" value="'.$dt_material_con["noreg_maquilero"].'">';
	}*/
?>  </td>
  </tr>
  <tr>
    <th colspan="4" class=\"titulo\">DATOS DE SALIDA. </th>
  </tr>
  <tr>
    <td>DEPARTAMENTO.</td>
    <td width="288">
		<select name="ver1" id="ver1">
		<option value="">---------SELECCIONE---------</option>
        <?php
		$sql = mysqli_query($con ,"SELECT * FROM fdepartamento where t1='ACTIVO' order by np_desc1 ");
		if(isset($_POST['ver1']))
			$depto = $_POST['ver1'];
		else
			$depto = $op1;
		while($reg=mysqli_fetch_array($sql)){
			if($depto == $reg['nparte1']) {
				echo '<option value="' . $reg['nparte1'] . '" selected>' . $reg['np_desc1'] . '</option>';
			}else{
				echo '<option value="' . $reg['nparte1'] . '">' . $reg['np_desc1'] . '</option>';
			}
		}			
		?>       
		</select>
	</td>
    <td width="169" colspan="2">FECHA.
      <?php
 
		if(isset($_POST['ver2'])){
			echo '<input name="ver2" type="text" class="date" value="'.$_POST['ver2'].'">';
			echo $_POST['ver2'];
		}else{
			$fec1=$op2;
			include("DF20000.php");
			$entradas = mysqli_fetch_array(mysqli_query($con ,"select count(*) as cantidad from dgrequid 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;
			
		}  
		echo @$mensaje;
	?></td>
  </tr>
  <tr>
    <td width="117">REQUISICION. </td>
    <td colspan="3"><input name="numero_folio" <?php echo $isdir; ?> type="text" id="numero_folio" tabindex="4" size="40"
 <?php
 
  if(isset($_POST['bot'])){
	  	echo 'value = "'.$op14.'"';
	  }
	  ?>
 >
      <input name="modEnc" type="submit" id="modEnc" <?php echo $isdir; ?> value="Modificar Requisicion."></td>
    </tr>
</table>
 <?php

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

?>

    <table  align="center">
  <tr>
    <th nowrap class=\"titulo\">PRODUCTOS DE LA SALIDA. </th>
    </tr>
  <tr>
    <td nowrap><div align="center">
      <input type="submit" name="Submit"  <?php echo $isdir; ?> value="Buscar" onClick="openpage('AL10800_AC.php','_self')">
    </div></td>
    <?php
 
@$resultado2=mysqli_query($con ,"SELECT * FROM farticulos WHERE farticulos.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$_POST['producto']."'");
$regist2=mysqli_fetch_array($resultado2);
/* 	$a1 = $registro2['nparte1']; 
	$a2 = $registro2['np_desc1']; 
	$a3 = $registro2['exi_min']; 
	$a4 = $registro2['exi_max']; 
	$a5 = $registro2['linea']; 
	$a6 = $registro2['gpo_basico']; 
	$a7 = $registro2['cve_marca']; */
	$pp8 = $regist2['lim_vta1']; 
	$pp9 = $regist2['lim_vta2']; 
	$pp10 = $regist2['lim_vta3'];  
	$pp1 = $regist2['lim_1']; 
	$pp2 = $regist2['lim_2']; 
	$pp3 = $regist2['lim_3']; 
	/* $a14 = $registro2['tip_mon']; 
	
	$a16 = $registro2['uc_num_doc']; 
	$a17 = $registro2['uc_pre_com']; 
	$a18 = $registro2['cos_prom']; 
	$a19 = $registro2['cos_prom_ant']; 
	$a20 = $registro2['exi_fis']; 
	$a21 = $registro2['t5']; 
	$a22 = $registro2['fec_bck_ord']; 
	$a23 = $registro2['bck_ord']; 
	$a24 = $registro2['cve_uni_com']; */
	$a25 = $regist2['ven_esp1']; 
/* 	$a26 = $registro2['cve_uni_vta']; 
	*/ 
?>
    </tr>
</table>
    <div align="center"><br>
    <input type="submit" name="boton_car" <?php echo $isdir; ?> value="Agregar Porducto" onClick="openpage('AL10800_AC.php','_self')">
    <br>
</div>
<table border='1' align="center">
    <tr>
      <th> 
        <input type="submit" name="Submit2" <?php echo $isdir; ?> value="Eliminar" onClick="openpage('AL10800_AC.php','_self')">      </th>
      <th colspan="7"></th>
    </tr>
    <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">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

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 dgrequid 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
         $vnp=(isset($npr))?$npr:"";
	$num_elementos=count($vnp);
	//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[$j]=$row["np_desc1"];	

			$direc[$j]=$row["directo"];	
		}
	}
        
	$num_elementos1=count($vnp);
	for($y=0;$y<=$num_elementos1-1;$y++)
	{	
		//mostrar datos encontrados en dgrefodd
		@$res=mysqli_query($con ,"select * from dgrequid where (cons_ven = '".$_POST['tnum']."' or cons_ven = '".$_POST['bot']."')and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
		$disabled=($direc[$y]==1)?'disabled="disabled"':'';
		//echo $disabled;
			echo '<tr><td>';
			echo '<div align="center"><input name="r5" '.$disabled.'  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'], 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 = $ivpp + $sbt;
			echo '<td><div align="center">$ ' . number_format($t, 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
 $vs=(isset($s))?$s:0;
	echo '<input name="txt_s" type="hidden" value="'.$vs.'">';
	echo '$' . number_format($vs, 2, '.', ',');
	?>	</th>
	    <th>
	<?php
  $vi=(isset($iv))?$iv:0;
	echo '<input name="txt_iv" type="hidden" value="'.$vi.'">';
	echo '$' . number_format($vi, 2, '.', ',');
	?>	</th>
	    <th>
	<?php
        $vt=(isset($tot))?$tot:0;
	echo '<input name="txt_to" type="hidden" value="'.$vt.'">';
	echo '$' . number_format($vt, 2, '.', ',');
	?>	</th>
  </table>
  <div align="center">
    <input name="Submit5" type="Submit" value="Terminar Captura" onClick="openpage('AL10800_AG2.php','_self')">
  </div>
</form>
</body>
</html>
