<script>
function eliminar_linea(codproformatmp,numlinea,importe)
{
	if (confirm(" Desea eliminar esta linea ? "))
		parent.document.formulario_lineas.baseimponible.value=parseFloat(parent.document.formulario_lineas.baseimponible.value) - parseFloat(importe);
		var original=parseFloat(parent.document.formulario_lineas.baseimponible.value);
		var result=Math.round(original*100)/100 ;
		parent.document.formulario_lineas.baseimponible.value=result;

		parent.document.formulario_lineas.baseimpuestos.value=parseFloat(result * parseFloat(parent.document.formulario.cob_iv.value / 100));
		var original1=parseFloat(parent.document.formulario_lineas.baseimpuestos.value);
		var result1=Math.round(original1*100)/100 ;
		parent.document.formulario_lineas.baseimpuestos.value=result1;
		var original2=parseFloat(result + result1);
		var result2=Math.round(original2*100)/100 ;
		parent.document.formulario_lineas.preciototal.value=result2;
		
		document.getElementById("frame_datos").src="eliminar_linea.php?codproformatmp="+codproformatmp+"&numlinea=" + numlinea;
}

function pon_prefijo(filas,preciotot) {
	parent.document.formulario_lineas.filas.value=filas;
	parent.document.formulario_lineas.preciotot.value=preciotot;
	parent.document.formulario_lineas.numlin.value="";
	parent.document.formulario_lineas.cdgbar.value="";
	parent.document.formulario_lineas.aplica.value="";
    
}

function nobackbutton(){	
   window.location.hash="no-back-button";	
   window.location.hash="Again-No-back-button" //chrome	
   window.onhashchange=function(){window.location.hash="no-back-button";}	
}


function chk_aplicacion(cdgbar,aplica,numlin)
			{
   	
   	parent.document.formulario_lineas.cdgbar.value=cdgbar; 
	parent.document.formulario_lineas.aplica.value=aplica;
  	parent.document.formulario_lineas.numlin.value=numlin;

	parent.document.getElementById("formulario_lineas").submit();

 
		}
		
		
</script>

<html>
<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
<body onLoad="nobackbutton();">
<?php 
include ("../conexion.php");
     $cdghac = "0";
	$codfactura=$_POST["codfactura2"];
	$cdgpro=$_POST["cdgpro"];
	
	     ///////////////////   aplica el ck de modificar precio al aticulo   /////////////////////
	 
	 
	 
	$aplica=$_POST["aplica"];
		
	 	if ($aplica<>"")  { 
	
		$cdgbar=$_POST["cdgbar"];
		$numlin=$_POST["numlin"];
		
	    $query="UPDATE factulinea_compra SET modpre='$aplica'  WHERE codigo='$cdgbar' AND numlinea='$numlin' AND codfactura='$codfactura' ";
	  	$mysqli->query($query);

	 } 

?>
<div id="xdetalleAW">
  <iframe id="frame_datos" name="frame_datos" width="0%" height="0" frameborder="0">
  <ilayer width="0" height="0" id="frame_datos" name="frame_datos"></ilayer>
  </iframe>
  <table class="fuente9" width="100%" cellspacing=0 cellpadding=0 border=0 ID="Table1">
<?php

 	$baseimp = 0;
	$baseiva = 0;
	$basedes = 0;
		
	$consulta ="SELECT * FROM factulinea_compra WHERE codfactura='$codfactura'  ORDER BY numlinea ASC";
$contador=0;
if ($resultado = $mysqli->query($consulta)) 


    while ($fila2 = $resultado->fetch_assoc()) {

	
	            $numlinea = $fila2["numlinea"];
				$cdgbar  = $fila2["codigo"];
				$dscart  = $fila2["dscart"];
				$cdglin  = $fila2["cdglin"];
				$cdgfam  = $fila2["cdgfam"];
				$canart  = $fila2["canart"];
				$cosart  = $fila2["cosart"];
				$utiart1 = $fila2["utiart1"];
				$utiart2 = $fila2["utiart1"];  ///// aplica la misma utilidad 1 a utilidad 2  /////////
				$PRE001  = $fila2["PRE001"];
				$PRE002  = $fila2["PRE002"];
				$importe = $fila2["importe"];
				$desfac  = $fila2["desfac"];
				$despro  = $fila2["despro"];  
				$impart  = $fila2["impart"];
				$fleart  = $fila2["fleart"];
				$implin  = $fila2["implin"];
				$deslin  = $fila2["deslin"];
				$flelin  = $fila2["flelin"];
				$PREANT  = $fila2["PREANT"];
				$modpre  = $fila2["modpre"];
			


	
	$baseimp=$importe+$baseimp;
	$baseiva=$implin+$baseiva;
	$basedes=$deslin+$basedes;
	
	if ($result = $mysqli->query("SELECT * FROM web_1001 WHERE cdgbar='$cdgbar' ")) {
    $fila = $result->fetch_array(); 
   $filas2 = $result->num_rows;
 
}
	

	if ($filas2 > 0) { 
	
	
$consulta2 = "SELECT COB_IV, cdghac,ESTART FROM web_1001 WHERE cdgbar='$cdgbar'";
$resultado2 = $mysqli->query($consulta2);
$row = $resultado2->fetch_array();
$cdghac   = $row["cdghac"];
$COB_IV   = $row["COB_IV"];
$ESTART  = $row["ESTART"];

	if  ($COB_IV == 1)  { 
		$exento="(G)";
	
	} else  { 

	$exento="(E)";
    } 
	
	 } else  { 

	$exento="";
	 }
	 




	if ($contador % 2) { $fondolinea="itemParTabla"; } else { $fondolinea="itemImparTabla"; } 
	
		// if ($cdghac == "" ) {   $fondolinea="no_existe";  } 
		
		if ($ESTART <> 1 ) {   $fondolinea="no_existe";  } 
		
		      ?>
		 
			<tr class="<?php echo $fondolinea?>">
				<td width="6%"><div align="left"><?php echo $cdgbar?></td>
			  <td width="6%" class=""><div align="center"><?php echo $canart?></div></td>
              	<?php	   $dscart = substr($dscart." ", 0, 33); ?>
				<td width="25%"><div align="left"><?php echo $dscart?></div></td>
                   <td width="2%"><div align="left"><?php echo $exento?></div></td>
				
			  <td width="9%"><div align="right"><?php echo number_format($cosart,2,".",",")?></div></td>
			   <td width="7%"><div align="right"><?php echo number_format($fleart,2,".",",")?></div></td>
			  <td width="6%"><div align="right"><?php echo number_format($utiart1,2,".",",")?></div></td>
			  <td width="7%"><div align="right"><?php echo number_format($despro,2,".",",")?></div></td>
        
               <td width="9%"><div align="center"><?php echo number_format($PREANT,2,".",",")?></div></td>
			  <td width="8%"><div align="right"><?php echo number_format($PRE001,2,".",",")?></div></td>

				<td width="8%"><div align="center"><?php echo number_format($desfac,2,".",",")?></div></td>
          
			  <td width="8%"><div align="right"><?php echo number_format($importe,2,".",",")?></div></td>
			  <td width="9%"><div align="right"><a href="javascript:eliminar_linea(<?php echo $codfacturatmp?>,<?php echo $numlinea?>,<?php echo $importe ?>)"></a></div></td>
			    <?php if ($modpre==1){ ?>
                <td width="2%"><input type="checkbox" value="otro" name="valores"   onkeypress="return tabE(this,event)"  checked onClick="chk_aplicacion('<?php echo $cdgbar ?>',<?php echo 0 ?>,<?php echo $numlinea?>)" /> </td>
		       <?php } else { ?>
                <td width="2%"><input type="checkbox" value="otro" name="valores"    onkeypress="return tabE(this,event)" onClick="chk_aplicacion('<?php echo $cdgbar ?>',<?php echo 1 ?>,<?php echo $numlinea?>)" /> </td>
                <?php }  ?> 
			</tr>
<?php 

$preciotot=$baseimp+$baseiva-$basedes;


$contador++;
}


?>

					<script languaje="javascript">
	pon_prefijo("<?php echo $filas ?>","<?php echo $preciotot ?>");
	
		</script>


</table>

</table>
<blockquote>&nbsp;	</blockquote>
</div>

<div id="ztotalesaw" align="right">
			<table width="98%" border=0 align="right" cellpadding=0 cellspacing=0 class="fuente8">
			  <tr>
			    <td width="70%" class="busqueda"><b>Sub-total</b></td>
					<td width="30%" align="right"><div align="right">
			      <input class="cajaTotales" name="baseimponible" type="text" id="baseimponible" size="12" value="<?php echo number_format($baseimp,2,",",".");?>" align="right" readonly> 
		        </div></td>																					 
	

			  </tr>
			  <tr>
			    <td class="busqueda"><b>Descuento</b></td>
			    <td align="right"><div align="right">
			      <input class="cajaTotales" name="basedescuento2" type="text" id="basedescuento2" size="12" value="<?php echo number_format($basedes,2,",",".");?>" align="right" readonly>
		        </div></td>
		      </tr>
			  <tr>
				<td class="busqueda"><b>IVA</b></td>
				<td align="right"><div align="right">
			      <input class="cajaTotales" name="baseimpuestos" type="text" id="baseimpuestos" size="12" align="right" value="<?php echo number_format($baseiva,2,",",".");?>" readonly> 
		        </div></td>
			  </tr>
			  <tr>
				<td class="busqueda"><b>Precio Total</b></td>
			
				<td align="right"><div align="right">
			      <input class="cajaTotales" name="preciototal" type="text" id="preciototal" size="12" align="right" value="<?php echo number_format($preciotot,2,",",".");?>" readonly> 
							  

		        </div></td>
			  </tr>
			</table>
</div>

</body>
</html>