<?php
 
session_start();
include("DMMYSQLG.php");
?>
<html>
<head>
<title>Orden de compra</title>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
</head>
<body>
<form name="frm1" id="frm1" method="post" action="">
<?php
 
//echo "hola";
if(isset($_REQUEST['Submit3'])){
	echo '<input name="r6" type="text" value="'.$_POST['r5'].'">';
	$sqlyy = mysqli_query($con ,"SELECT * FROM dgrefodd WHERE cons = '".$_POST['r5']."'");
	$regyy = mysqli_fetch_array($sqlyy);
	//echo $regyy['cons'];
}
?>
<input name="ver" type="hidden" value="11">
<table width="876"  align="center">
<tr>
<td colspan="6" class="tdagre1">
<?php
  
if(isset($_POST['tnum']) || isset($_POST['boton_car'])){
	echo '<input name="tnum" type="hidden" value="'.$_POST['tnum'].'">';
	echo 'ORDEN NUMERO:'.$_POST['tnum']; 
	$result = mysqli_query($con ,"SELECT * FROM dgreford WHERE num_ord = '".$_POST['tnum']."'");
}
if(isset($_POST['bot'])){
	//$ultimo_id = mysqli_insert_id($con);
	echo '<input name="tnum" type="hidden" value="'.$_POST['bot'].'">';
	echo 'ORDEN NUMERO:'.$_POST['bot']; 
	$result = mysqli_query($con ,"SELECT * FROM dgreford WHERE num_ord = '".$_POST['bot']."'");
}	
while($row = mysqli_fetch_array($result)){
	$tc=$row["tip_com"];
	$pr=$row["codigo"];
	$al=$row["almacen"];
	$fp=$row["fec_pro"];
	$pd=$row["por_des"];
	$tm=$row["tip_mon"];
	$cp=$row["cve_pais"];
	$cm=$row["cve_mon"];
	$ti=$row["tip_cam"];
	
}
?>  </td>
  </tr>
  <tr>
    <th colspan="6" class=\"titulo\">Datos de la Orden de Compra </th>
  </tr>
  <tr>
    <td width="127">Tipo de compra:</td>
    <td width="257">
	<?php
 
		@$resultado=mysqli_query($con ,"select * from dgtipcom where tip_com = '$tc'");
		if(isset($_POST['ver1']))
		{
			echo '<input name="ver1" type="hidden" value="'.$_POST['ver1'].'">';
			echo $_POST['ver1'];
		}else{
			while(@$registro=mysqli_fetch_array($resultado))
			{
				echo '<input name="ver1" type="hidden" value="'.$registro['des_tipcom'].'">';
				echo $registro['des_tipcom'];
			}		
		}	
	?>	</td>
    <td colspan="2">Proveedor: 
	  <?php
 
		if(isset($_POST['ver2']))
		{
			@$resultado=mysqli_query($con ,"select * from dgcatpro where cod_pro = '".$_POST['ver2']."'");
			while(@$registro=mysqli_fetch_array($resultado))
			{
				echo '<input name="ver2" type="hidden" value="'.$_POST['ver2'].'">';
				echo $registro['nom_pro'];
			}
		}else{
			@$resultado=mysqli_query($con ,"select * from dgcatpro where cod_pro = $pr");
			while($registro=mysqli_fetch_array($resultado)){
				echo '<input name="ver2" type="hidden" value="'.$pr.'">';
				echo $registro['nom_pro'];
			}			
		}
	?>	</td>
    <td colspan="2">Almacen:
	  <?php
 
	  	if(isset($_POST['ver3'])){
			@$resultado=mysqli_query($con ,"select * from dgalmacen where almacen = '".$_POST['ver3']."'");
			while(@$registro=mysqli_fetch_array($resultado)){
				echo '<input name="ver3" type="hidden" value="'.$_POST['ver3'].'">';
				echo $registro['desc_almacen'];
			}
		}else{
			@$resultado=mysqli_query($con ,"select * from dgalmacen where almacen = '$al'");
			while($registro=mysqli_fetch_array($resultado)){
				echo '<input name="ver3" type="hidden" value="'.$al.'">';
				echo $registro['desc_almacen'];
			}			
		}
	?>	</td>
    </tr>
  <tr>
    <td>Tipo de Moneda: </td>
    <td><?php
 
		if(isset($_POST['tp_des']))
		{
			echo '<input name="tp_mon" type="hidden" value="'.$_POST['tp_mon'].'">';
			$tm = $_POST['tp_des'];
		}else{
			echo '<input name="tp_mon" type="hidden" value="'.$_POST['ttmon'].'">';
			$tm = $_POST['ttmon'];
		}	
		if(isset($_POST['bot2'])){
			$tm = $tm;
		}
		if($tm == 1){
			echo "NACIONAL";
		}else{
			echo "EXTRANJERA";
		}
	?></td>
    <td colspan="2">Pais:
      <?php
 
	  include("DMMYSQLG.php");
	  	if(isset($_POST['p'])){
			@$re=mysqli_query($con ,"select * from dxpaises where cve_pais = '".$_POST['p']."'");
			$registo=mysqli_fetch_array($re);
			echo '<input name="ver3p" type="hidden" value="'.$_POST['p'].'">';
			echo $registo['des_pais'];
		}else{
			if(isset($_POST['bot2'])){
				$vaa = $cp;
			}else{
				$vaa = $_POST['tpai'];
			}
			@$resulto=mysqli_query($con ,"select * from dxpaises where cve_pais = '$vaa'");
			$regiso=mysqli_fetch_array($resulto);
			echo $regiso['des_pais'];
			echo '<input name="ver3p" type="hidden" value="'.$vaa.'">';		
		}
	?></td>
    <td width="91">Moneda: </td>
    <td width="106"><?php
 
	  	if(isset($_POST['pm'])){
			$resulta=mysqli_query($con ,"select * from dxpaimon where cve_mon = '".$_POST['pm']."'");
			$regis=mysqli_fetch_array($resulta);
			echo '<input name="ver3pm" type="hidden" value="'.$regis['cve_mon'].'">';
			echo $regis['des_moneda'];
		}else{
			if(isset($_POST['bot2'])){
				$vaa = $cm;
			}else{
				$vaa = $_POST['select33'];
			}
			$resulta=mysqli_query($con ,"select * from dxpaimon where cve_mon = '$vaa'");
			$regis=mysqli_fetch_array($resulta);
			echo $regis['des_moneda'];
			echo '<input name="ver3pm" type="hidden" value="'.$vaa.'">';		
		}
			  include("DMMYSQLG.php");
	?>
      &nbsp;</td>
  </tr>
  <tr>
    <td>Fecha promesa: </td>
    <td>
	<?php
 
	$fec1=$fp;
	include("DF20000.php");
	if(isset($_POST['ver4']))
	{
		echo '<input name="ver4" type="hidden" value="'.$_POST['ver4'].'">';
		echo $_POST['ver4'];
	}else{
		echo '<input name="ver4" type="hidden" value="'.$f_f.'">';
		echo $f_f;
	}
	?>	</td>
    <td width="121">% Des/Gral</td>
    <td width="134"><?php
 
		if(isset($_POST['tp_des']))
		{
			echo '<input name="tp_des" type="hidden" value="'.$_POST['tp_des'].'">';
			echo $_POST['tp_des'];
		}else{
			if(isset($_POST['bot2'])){
				$vaa = $pd;
			}else{
				$vaa = $_POST['tdesgr'];
			}
			echo '<input name="tp_des" type="hidden" value="'.$vaa.'">';
			echo $vaa;
		}	
	?>      &nbsp;</td>
    <td>Tipo de cambio: </td>
    <td><?php
 
		if(isset($_POST['t_cam']))
		{
			echo '<input name="t_cam" type="hidden" value="'.$_POST['t_cam'].'">';
			echo $_POST['t_cam'];
		}else{
			if(isset($_POST['bot2'])){
				$vaa = $ti;
			}else{
				$vaa = $_POST['ttc'];
			}
			echo '<input name="t_cam" type="hidden" value="'.$vaa.'">';
			echo $vaa;
		}	
	?>
  &nbsp;</td>
  </tr>
</table>
<?php
 

//si eprecionan el boton de eliminar
if (isset($_POST['Submit2']))
{
	@$res=mysqli_query($con ,"select * from dgrefodd where cons = '".$_POST['r5']."'");
	$row = mysqli_fetch_array($res);
	$cant=$row['can_ord'];	
	$npa =$row['nparte1'];	
	

	$sql="DELETE FROM dgrefodd WHERE cons = '".$_POST['r5']."'";
	if (!mysqli_query($con ,$sql)){
	  	die('Error 1: ' . mysqli_error($con));
		exit();
	 } 
	 @$res=mysqli_query($con ,"select * from dgrefodd where num_ord = $_POST['tnum']");
	//sacra la cantidad de registros encontrados en la cosnulta anterior
	$num_salidas=mysqli_num_rows($res); 
	//si no hay datos ya para la dgreford entonces limpiar la actualizacion
	if($num_salidas==0){
		$sql="UPDATE dgreford SET actualiza = 0, sub_ord = 0, iva_ord = 0, total_ord = 0, acc_fec = '".date('Y-m-d')."', acc_hor =  '".date('H:i:s')."', usuario = '".$_SESSION['num_usu']."' WHERE num_ord = $_POST['tnum']";
		if (!mysqli_query($con ,$sql))
		{
		  	die('Error 2: ' . mysqli_error($con));
			exit();
		 }
	}else{
		//calcular valor del iva sub-total y total
		//buscar todos los registros 
		@$result = mysqli_query($con ,"SELECT * FROM dgrefodd WHERE num_ord = $_POST['tnum']");
		while($dato = mysqli_fetch_array ($result))
		{ 
			$su_to=$su_to + $dato['pre_uni'];
			$iv_to=$iv_to + $dato['iva_tot'];
			$to_to=$to_to + $dato['subtotal'];
		}
		//agregar registro a la orden de actualizada
		 $sql="UPDATE dgreford SET sub_ord = $su_to, iva_ord = $iv_to, total_ord = $to_to, acc_fec = '".date('Y-m-d')."', acc_hor =  '".date('H:i:s')."', usuario = '".$_SESSION['num_usu']."' WHERE num_ord = $_POST['tnum']";
		if (!mysqli_query($con ,$sql))
		{
		  	die('Error 3: ' . mysqli_error($con));
			exit();
		 }
	}
	 //sacar back order
	@$res=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '$npa'");
	while($row = mysqli_fetch_array($res))
	{
		//saca el back order
		$ncbo=$row['bck_ord'] - $cant;	
	}
	//convertir fecha
	$fec= $_POST['ver4'];
	include("DF20000.php");
	//agregar back order y fecha
	 @$sql="UPDATE dginvent SET bck_ord = '$ncbo', fec_bck_ord = '$f_m', acc_fec = '".date('Y-m-d')."', acc_hor =  '".date('H:i:s')."', usuario = '".$_SESSION['num_usu']."' WHERE nparte1 = '$npa'";
	if (!mysqli_query($con ,$sql))
	{
		die('Error: ' . mysqli_error($con));
	} 
}
if (isset($_POST['boton_car']))
{
	@$res=mysqli_query($con ,"select * from dgrefodd where nparte1 LIKE '".$_POST['producto']."' && num_ord = $_POST['tnum']");
	$num_salidas=mysqli_num_rows($res); 
	if($num_salidas==0){
		//calcular el iva
	 	@$result = mysqli_query($con ,"SELECT * FROM dxtasiva WHERE cve_iva = $_POST['select3']");
		while($dato = mysqli_fetch_array ($result) )
		{ 
			$iva23[1]=$dato['porc_iva'];
		}
		 //consultar el registro  y sacar datos
		@$res=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 like '".$_POST['producto']."'");
		while($row = mysqli_fetch_array($res))
		{
			$pro1[]=$row["np_desc1"];		
		}
		//
		$x = $_POST['tpre'] * $_POST['tcan'];
		//sacar el porcentaje de descuento
		$p_d = $_POST['tpor_des'];
		//calcular descuento
		$des = ($_POST['tpre'] * ($p_d/100));
		//calcular total con descuent
		$tc1= $_POST['tpre'] - $des;
		//subtotal
		$sub_t =  $tc1 * $_POST['tcan'];
		//calcular el iva del total con descuento
		$iva = $sub_t * ($iva23[1]/100);
		//sumar el iva calculado al//subtotal final//iva_total final//totoal final 
		$pt = $sub_t + $iva;
		//fin
		@$result = mysqli_query($con ,"SELECT * FROM dgrefodd WHERE num_ord = $_POST['tnum']");
		while($dato = mysqli_fetch_array ($result) )
		{ 
			$su_to=$su_to + $dato['subtotal'];
			$iv_to=$iv_to + $dato['iva_tot'];
			$to_to=$to_to + $dato['total_fin'];
		}
		$su_to=$su_to + $sub_t;
		$iv_to=$iv_to + $iva;
		$to_to=$to_to + $pt;
		//agregar registro a la orden de actualizada
	   $sql="UPDATE dgreford SET actualiza = 1, sub_ord = $su_to, iva_ord = $iv_to, total_ord = $to_to, acc_fec = '".date('Y-m-d')."', acc_hor =  '".date('H:i:s')."', usuario = '".$_SESSION['num_usu']."' WHERE num_ord = $_POST['tnum']";
		if (!mysqli_query($con ,$sql))
		{
		  	die('Error: ' . mysqli_error($con));
			exit();
		 }
		//insertar datos en dgrefodd
		$sql="INSERT INTO dgrefodd (tip_com, cod_pro, fec_ord, num_ord, nparte1, can_ord, pre_uni, total, por_des, total_cd, almacen,cve_iva, iva_tot, subtotal, total_fin, des, acc_fec, acc_hor, usuario, tip_mon, cve_pais, cve_mon, tip_cam) VALUES ('$tc', '$pr', '$fp', '".$_POST['tnum']."', '".$_POST['producto']."', '".$_POST['tcan']."', '".$_POST['tpre']."', '$x', '".$_POST['tpor_des']."', '$tc1', '$al', '".$_POST['select3']."','$iva','$sub_t','$pt', '$des', '".date('Y-m-d')."', '".date('H:i:s')."','".$_SESSION['num_usu']."', '".$_POST['tp_mon']."', '".$_POST['p']."', '".$_POST['pm']."', '".$_POST['t_cam']."')";
		if (!mysqli_query($con ,$sql))
		{
			die('Error x1: ' . mysqli_error($con));
		} 
		//sacar back order
		@$res=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 like '".$_POST['producto']."'");
		while($row = mysqli_fetch_array($res))
		{
			//saca el back order
			$nbo=$row['bck_ord'] + $_POST['tcan'];	
		}
		//convertir fecha
		$fec= $_POST['ver4'];
		include("DF20000.php");
		//agregar back order y fecha
		 @$sql="UPDATE dginvent SET bck_ord = '$nbo', fec_bck_ord = '$f_m', acc_fec = '".date('Y-m-d')."', acc_hor =  '".date('H:i:s')."', usuario = '".$_SESSION['num_usu']."' WHERE nparte1 LIKE '".$_POST['producto']."'";
		if (!mysqli_query($con ,$sql))
		{
			die('Error: ' . mysqli_error($con));
		} 
		//si boton de cargar o boton de buscar entonces o modificar o eliminar
	}else{
		echo 'ĦĦĦEse registro ya esta cargado en la Solicitud!!!';
	}
}

?>
    <table width="876"  align="center">
  <tr>
    <th colspan="6" class=\"titulo\">Productos de la Orden de Compra </th>
    </tr>
  <tr>
    <td width="237"> 
        <input name="tbus" type="text" id="tbus" tabindex="1">
          <input type="submit" name="Submit" value="Buscar"></td>
    <td colspan="5"><input name="r1" type="radio" value="clave" checked tabindex="2">
Clave del producto
   &nbsp;&nbsp;&nbsp;
   <input name="r1" type="radio" value="des" tabindex="3">
Descripcion</td>
    </tr>
  
  <tr>
    <td colspan="6">Producto:
      <select name="producto" tabindex="5">
        <?php
 
	$bus = $_POST['r1'];
	//echo $bus;
	//exit();
	if($bus=="clave")
	{
		//busca si encuentra la clave
  		@$resultado=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$_POST['tbus']."'");
		//numero de registros encontrados
		$num_salidas=mysqli_num_rows($resultado); 
		//no encontro clave si no la encuentra buscar semejanzas
		if($num_salidas <> 1)
		{
			//echo '<input name="pp" type="text" value="'.$num_salidas.'">';
			//exit();
			@$resultado=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 like '$_POST['tbus']%'");
		}
	  }elseif($bus=="des"){
	  	//en caso de buscar por descripcion
	  	@$resultado=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   np_desc1 like '%".$_POST['tbus']."%'");
	  }//else{
	  	//mostrar todo
		//@$resultado=mysqli_query($con ,"select * from dginvent");
	  //}
	  $b = $_POST['tbus'];
	  if($b=="")
	  {
	  	@$resultado=mysqli_query($con ,"select * from dginvent");
	  }
  while($registro=mysqli_fetch_array($resultado))
  {
	echo '<option value="' . $registro['nparte1'] . '">' . $registro['nparte1'] . '--' .$registro['np_desc1'] . '</option>';
  }			
  ?>
      </select></td>
    </tr>
  <tr>
    <td>Precio $      
      <input name="tpre" type="text" size="15" maxlength="15"  tabindex="5"
	  <?php
 
	  	if(isset($_REQUEST['Submit3'])){
			echo 'value = "'.$regyy['pre_uni'].'"';
		}
	  ?>
	  
	  ></td>
    <td width="277">Cantidad de producto:      
      <input name="tcan" type="text" size="15" maxlength="15" onKeyPress="return soloNumeros(event)" tabindex="6"
	  <?php
 
	  	if(isset($_REQUEST['Submit3'])){
			echo 'value = "'.$regyy['can_ord'].'"';
		}
	  ?>
	  ></td>
    <td colspan="2">Descuento:
      <?php
 
if(isset($_REQUEST['Submit3'])){
	echo '<input name="tpor_des" type="text" size="10" value="'.$regyy['por_des'].'" tabindex="7">';
}else{

	if(isset($_POST['boton_car'])){
		echo '<input name="tpor_des" type="text" size="10" value="'.$_POST['tp_des'].'" tabindex="7">';
	}else{
		if(isset($_POST['tpor_des']) && !isset($_POST['boton_car']))
		{
			echo '<input name="tpor_des" type="text" size="10" value="'.$_POST['tpor_des'].'" tabindex="7">';
		}else{
			echo '<input name="tpor_des" type="text" size="10" value="'.$_POST['tdesgr'].'" tabindex="7">';
		}
	}	
}
	?></td>
    <td width="122" colspan="2"> Iva: 
        <select name="select3" tabindex="8">
          <?php

		if(isset($_POST['select3']))
		{
		@$resultado2=mysqli_query($con ,"select * from dxtasiva where tip_com=$_POST['select3']");
			while($registro2=mysqli_fetch_array($resultado2))
			{
				echo '<option value="'. $registro2['cve_iva'] .'">'.$registro2['conc_iva'] . '</option>';
			}
		}
			@$resultado=mysqli_query($con ,"select * from dxtasiva");
			while($registro=mysqli_fetch_array($resultado))
			{
	  			if(isset($_REQUEST['Submit3']) and $regyy['cve_iva'] == $registro['cve_iva']){
					echo '<option value="' . $registro['cve_iva'] . '" selected>' . $registro['conc_iva'] . '</option>';
				}else{
					echo '<option value="' . $registro['cve_iva'] . '">' . $registro['conc_iva'] . '</option>';
				}
			}			
		?>
        </select>
    </td>
  </tr>
</table>
<div align="center"><br>
    <?php
 
if(isset($_REQUEST['Submit3'])){
?>
    <input type="submit" name="submit7" value="Modificar" onClick="openpage('DH22000_AG1.php','_self')" tabindex="9">
    <?php

}else{
?>
    <input type="submit" name="boton_car" value="Agregar producto" onClick="openpage('DH22000_AG1.php','_self')" tabindex="8">
    <?php

}
if(isset($_POST['submit7'])){
	$sqlyxy = mysqli_query($con ,"update dgrefodd set can_ord = '".$_REQUEST['tcan']."', pre_uni = '".$_REQUEST['tpre']."', por_des = '".$_REQUEST['tpor_des']."', cve_iva = '".$_REQUEST['select3']."' WHERE cons = '".$_REQUEST['r6']."'");
}
?>
    <br>
</div>
<table border='1' align="center">
    <tr>
      <th> 
        <input type="submit" name="Submit2" value="Eliminar" tabindex="9">
      </th>
      <th> 
        <input type="submit" name="Submit3" value="Modificar">
      </th>
      <th colspan="9">&nbsp;</th>
    </tr>
    <tr>
	  <th><div align="center">Seleccion</div></th>
      <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">% Descuento</div></th>
	  <th><div align="center">Descuento</div></th>
      <th><div align="center">Precio Unitario</div></th>
	  <th><div align="center">Cantidad</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

if (isset($_POST['boton_car']) || isset($_POST['Submit5']) or isset($_POST['bot']) or isset($_POST['bot2']) || isset($_POST['producto'])){
	//saca el numero de producto
		if(isset($_POST['bot']) or isset($_POST['bot2'])){
			$nnn = $_POST['bot'];
			//echo $nnn;
		}else{
			$nnn = $_POST['tnum'];
		}
	@$res=mysqli_query($con ,"select * from dgrefodd where num_ord = '$nnn'");
	while($row = mysqli_fetch_array($res))
	{
		$npr[]=$row["nparte1"];	
	}
	//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);
	//echo $num_elementos1;
	for($y=0;$y<=$num_elementos1-1;$y++)
	{	
		//mostrar datos encontrados en dgrefodd
		@$res=mysqli_query($con ,"select * from dgrefodd where num_ord LIKE '$nnn' && nparte1 like '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			echo '<tr>';
			echo '<td><input name="r5" type="radio" value="'.$row['cons'].'"/></td>';
			echo '<td>' . $npr[$y] . '</td>';
			echo '<td>' . $dpr[$y] . '</td>';
			$c = $c + $row['can_ord'];
			echo '<td>$ ' . number_format($row['pre_uni'], 4, '.', ',') . '</td>';
			$pbase =  $pbase + $row['pre_uni'];
			echo '<td>' . number_format($row['por_des'], 4, '.', ',') . '  %</td>';
			echo '<td>$ ' . number_format($row['des'], 4, '.', ',') . '</td>';
			$d = $d + $row['des'];
			$pre_u = $row['pre_uni'] - $row['des'];
			echo '<td>$ ' . number_format($pre_u, 4, '.', ',') . '</td>';
			$p = $p + $pre_u;
			echo '<td>' . $row['can_ord'] . '</td>';
			echo '<td>$ ' . number_format($row['subtotal'], 2, '.', ',') . '</td>';
			$s = $s + $row['subtotal'];
			echo '<td>$ ' . number_format($row['iva_tot'], 2, '.', ',') . '</td>';
			$iv = $iv + $row['iva_tot'];
			echo '<td>$ ' . number_format($row['total_fin'], 2, '.', ',') . '</td>';
			$tot = $tot + $row['total_fin'];
			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>&nbsp;</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="Terminar Captura" tabindex="10" onClick="openpage('DH22000_AG2.php','_self')">
  </div>
</form>
</body>
</html>
