<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>

<script src="assets/js/funciones.js"></script>


<style type="text/css">
<!--
.Estilo16 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.Estilo20 {color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 14px; }
-->
</style>
</head>



<body onload="calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value);">
<table width="978" border="0" cellpadding="1" cellspacing="1">
  <tr>
    <td width="17" bgcolor="#FF6600">&nbsp;</td>
    <td width="20" height="31" bgcolor="#FF6600"><div align="center"></div></td>
    <td width="20" bgcolor="#FF6600"><div align="center">
      <div align="center"><span class="Estilo20">C&oacute;d. </span></div>
    </div></td>
    <td width="288" bgcolor="#FF6600"><div align="center">
      <div align="center"><span class="Estilo20">Producto </span></div>
    </div></td>
    <td width="110" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Unidad medida </span></div></td>
    <td width="66" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Cant. </span></div></td>
    <td width="66" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Devol. N.C.</span></div></td>
    <td width="80" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Precio</span></div></td>
    <td width="5" bgcolor="#FF6600"><div align="center"><span class="Estilo20">EXO</span></div></td>
    <td width="10" bgcolor="#FF6600"><div align="center"><span class="Estilo20">IGV</span></div></td>
    <td width="10" bgcolor="#FF6600"><div align="center"><span class="Estilo20">ISC</span></div></td>
    <td width="79" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Desct. N.C.</span></div></td>
    <td width="48" bgcolor="#FF6600"><div align="center"><span class="Estilo20">ISC PRORRAT </span></div></td>
    <td width="90" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Monto</span></div></td>
    <td width="10" bgcolor="#FF6600">&nbsp;</td>
  </tr>
  
  
  <form name="form_compras_detalle" id="form_compras_detalle" method="post" target="frame_compras_detalle_guarda" action="procesos/comprasdetalle.php">
	<?
	@$xid=$_REQUEST['xid'];
	@$xidtrans=$_REQUEST['xidtrans'];	
	@$xidtrans_temporal=$_REQUEST['xidtrans_temporal'];		
	
	include("conexion.php");
	
	
	//echo "SELECT * FROM orden_compra o WHERE idtrans='$xidtrans';";
	
	$xordcom_igv_porcentaje = 0;
	
	$xordcom_percepcion = 0;
	$xordcom_isc = 0;
	$r_compra = mysqli_query($conexion,"SELECT * FROM orden_compra o WHERE idtrans='$xidtrans';");
	$nn=0;
	while($row_compra  = mysqli_fetch_array($r_compra)){
		$xordcom_percepcion = $row_compra['ordcom_percepcion'];
		$xordcom_isc = $row_compra['ordcom_isc'];
		$xordcom_igv_porcentaje = $row_compra['ordcom_igv_porcentaje'];		
		
		?>
		<script language="javascript">
		parent.document.getElementById('xisc_total').value = '<?php echo number_format($xordcom_isc,2,'.','') ;  ?>';
		parent.document.getElementById('xpercepcion_total').value = '<?php echo number_format($xordcom_percepcion,2,'.','') ;  ?>';		
		</script>
		<?php
		
		 
	}
	if($xordcom_igv_porcentaje == 0){
		$xordcom_igv_porcentaje = $_SESSION['s_igv'];
	}
	
	/*
	echo "SELECT * FROM temporal_orden_compra_detalle o 
									LEFT JOIN productos p ON  o.prd_codi_fk=p.prd_codi 
									LEFT JOIN unidades_medida u ON o.unimed_codi_fk=u.unimed_codi 
									WHERE o.idtrans='$xidtrans' 
									AND o.idtrans_temporal='$xidtrans_temporal';";
	*/
	
	$result1=mysqli_query($conexion,"SELECT * 
									FROM temporal_orden_compra_detalle o 
									LEFT JOIN productos p ON  o.prd_codi_fk=p.prd_codi 
									LEFT JOIN unidades_medida u ON o.unimed_codi_fk=u.unimed_codi 
									WHERE o.idtrans='$xidtrans' 
									AND o.idtrans_temporal='$xidtrans_temporal'
									ORDER BY ordcomdet_codi;");
	$nn=0;
	$nisc=0;
	while($row1=mysqli_fetch_array($result1)){
		$nn=$nn+1;
				
		$xordcomdet_igv_afectado = $row1['ordcomdet_igv_afectado'];
		
		//echo $row1['ordcomdet_isc_afectado'];
		//echo $xordcom_igv_porcentaje;
		//echo "xordcom_igv_porcentaje: " . $xordcom_igv_porcentaje;
		//echo "<br>";
						
		if($xordcomdet_igv_afectado == 0){
			$wigv = $row1['ordcomdet_precio'] - ($row1['ordcomdet_precio'] / (($xordcom_igv_porcentaje / 100) + 1));			
		}else{
			$wigv = 0;					
		}
		
		if($row1['ordcomdet_isc_afectado']==1){  
			$nisc = $nisc + 1;
			?>  	
			<script language="javascript">
			document.getElementById('xmonto_isc').disabled = false;
			</script>		
			<?php 
		} 
							
	?>
   
  
  <tr id="tr<?php echo $nn;?>" style="background-color:#FFFFFF;" onMouseOver="resaltar('#F9F38A',this.id);" onMouseOut="resaltar('#FFFFFF',this.id);" >
    <td class="Estilo16"><div align="center"><?php echo $nn; ?></div></td>
    <td class="Estilo16"><a href="#" onclick="enviar_compras_detalle_item('eliminar',<?php echo $row1['ordcomdet_codi'];?>); return false;"><img src="images/icono_eliminar.png" width="20" height="22" border="0" /></a></td>
    <td width="20" class="Estilo16"><input readonly="readonly"  name="xcodigo_<?php echo $nn;//$row1['ordcomdet_codi'];?>" id="xcodigo_<?php echo $nn;?>" type="text" style="width:35px; text-align:left; color:#999999;letter-spacing:-1px;"  value="<?php echo $row1['prd_codigo']; ?>" size="8" /></td>
    <td class="Estilo16"><input readonly="readonly"  name="xproducto_<?php echo $nn;?>" type="text" id="xproducto_<?php echo $nn;?>" style="width:280px; text-align:left;  color:#999999; letter-spacing:-1px;"  value="<?php echo $row1['prd_nombre']; ?>" title="<?php echo $row1['prd_nombre']; ?>" size="8" /></td>
	
	
    <td class="Estilo16"><select class="input_texto" onchange="parent.hay_cambios(); enviar_compras_detalle_item('guardar_unidad',<?php echo $row1['ordcomdet_codi'];?>,this.value); return false;" name="xunidad_<?php echo $nn;?>" id="xunidad_<?php echo $nn;?>" style="width:110px; text-align:left; letter-spacing:-1px;" requiered="requiered" disabled="disabled" >
        <option value=""></option>
        <?				
									$r_unidades=mysqli_query($conexion,"SELECT * FROM unidades_medida u order by unimed_nombre;");												
									
									while($row_unidades=mysqli_fetch_array($r_unidades)){
									
									?>
        <option value="<?php echo $row_unidades['unimed_codi']; ?>" <?php if($row_unidades['unimed_codi']==$row1['unimed_codi_fk']){ ?> selected="selected" <?php	} ?> ><?php echo $row_unidades['unimed_nombre']; ?></option>
        <?
									}
									?>
          </select></td>
		  
		  
    <td class="Estilo16"><input  onchange="parent.hay_cambios(); enviar_compras_detalle_item('guardar_cantidad',<?php echo $row1['ordcomdet_codi'];?>,this.value); calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value); return false;"  name="xcantidad_<?php echo $nn;?>" autocomplete="off" type="number" id="xcantidad_<?php echo $nn;?>" style="width:50px; text-align:right; "  value="<?php echo $row1['ordcomdet_cantidad']; ?>" size="8" /></td>
    <td class="Estilo16"><div align="center"><?php echo $row1['ordcomdet_cantidad_devolver']; ?></div></td>
    <td class="Estilo16"><div align="right">
      <input type="number"  onchange="parent.hay_cambios(); enviar_compras_detalle_item('guardar_precio',
	  														<?php echo $row1['ordcomdet_codi'];?>,
															this.value,
															<?php echo $nn;?>,
															parent.document.getElementById('xigv').value); calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value); return false;"  name="xprecio_<?php echo $nn;?>" autocomplete="off" id="xprecio_<?php echo $nn;?>"  value="<?php echo number_format($row1['ordcomdet_precio'],3,'.','') ; ?>" style="width:80px; text-align:right; " />
    </div></td>
    <td width="5" class="Estilo16"><strong>
      <input name="xigv_chk_<?php echo $nn;?>" id="xigv_chk_<?php echo $nn;?>" type="checkbox" value="1" disabled="disabled"   
			<?php if($row1['ordcomdet_igv_afectado']==1){  ?>  checked="checked" <?php }  ?>
			onclick="cambiar_estado_compra_igv(<?php echo $nn; ?>, 
												this.checked, 
												parent.document.getElementById('xigv').value,
												'<?php echo $row1['ordcomdet_codi'];?>');" />
    </strong></td>
    <td width="10" class="Estilo16"><div align="left" style="display:block;">
      <table width="61" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="61"><input type="number" readonly="readonly" disabled="disabled" onchange="parent.hay_cambios(); calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value); return false;"  name="xigv_<?php echo $nn;?>" autocomplete="off" id="xigv_<?php echo $nn;?>"  value="<?php echo number_format($wigv,3,'.',''); //number_format($row1['ordcomdet_igv'],3,'.','') ; ?>" style="width:60px; text-align:right; " /></td>
        </tr>
      </table>
    </div>	</td>
    <td width="10" class="Estilo16"><strong>
      <input name="xisc_chk_<?php echo $nn;?>" id="xisc_chk_<?php echo $nn;?>" type="checkbox" value="1" disabled="disabled"   
			<?php if($row1['ordcomdet_isc_afectado']==1){  ?>  checked="checked" <?php }  ?>
			onclick="cambiar_estado_compra_isc(<?php echo $nn; ?>, 
												this.checked, 
												parent.document.getElementById('xigv').value,
												'<?php echo $row1['ordcomdet_codi'];?>');" />
    </strong></td>
    <td class="Estilo16"><div align="left" style="display:none;">
      <input type="number"  onchange="parent.hay_cambios(); 
	  						enviar_compras_detalle_item('guardar_descuento',
														<?php echo $row1['ordcomdet_codi'];?>,
														this.value); 
							calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value); return false;"  
							name="xdescuento_<?php echo $nn;?>" autocomplete="off" id="xdescuento_<?php echo $nn;?>2"  value="<?php echo number_format($row1['ordcomdet_isc'],3,'.','') ; ?>" style="width:60px; text-align:right; " />
    </div>
      <div align="right"><?php echo number_format($row1['ordcomdet_precio_descuento'],2,'.','') ; ?></div></td>
	
	
    <td class="Estilo16"><div align="left" style="display:block;" >
      <input type="number"  readonly="readonly" disabled="disabled" onchange="parent.hay_cambios(); enviar_compras_detalle_item('guardar_isc',<?php echo $row1['ordcomdet_codi'];?>,this.value); calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value); return false;"  name="xisc_<?php echo $nn;?>" autocomplete="off" id="xisc_<?php echo $nn;?>"  value="<?php echo number_format($row1['ordcomdet_isc'],3,'.','') ; ?>" style="width:60px; text-align:right; " />
    </div></td>
    <td class="Estilo16"><div align="right">
      <input type="text"  readonly="readonly" disabled="disabled" name="xmonto_<?php echo $nn;?>" id="xmonto_<?php echo $nn;?>"  value="" style="width:70px; text-align:right;  color:#999999; " />
    </div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  
	<?
	}
	?> 

  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div align="right"><strong>Op. Grabadas:</strong></div></td>
    <td class="Estilo16"><div id="d_xsubtotal" align="right"><strong></strong></div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div align="right"><strong>Op. Exoneradas: </strong></div></td>
    <td class="Estilo16"><div id="d_exoneradas" align="right"><strong></strong></div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16"><a name="anclaje_detalle_pedido" id="anclaje_detalle_pedido"></a></td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div align="right"><strong>
      IGV: 
            <input  style="display:none;"  type="checkbox" name="checkbox" value="checkbox" />
    </strong></div></td>
    <td class="Estilo16"><div id="d_xigv" align="right"><strong></strong></div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div  style="display:block;"  align="right"><strong> <input style="display:none;" type="checkbox" name="checkbox3" value="checkbox" /> ISC:
          
    </strong></div></td>
    <td class="Estilo16"><div align="right">
      <input onchange="calcular_isc(this.value); calcular_totales_detalle_orden_compra(parent.document.getElementById('xigv').value);" autocomplete="off"  type="text"  name="xmonto_isc" id="xmonto_isc"  value="" disabled="disabled" style="width:70px; text-align:right;  color:#000000; " />
    </div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div align="right"><strong>Total:</strong></div></td>
    <td class="Estilo16"><div id="d_xtotal" align="right"><strong></strong></div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div  style="display:block;"  align="right"><strong>
      Percepci&oacute;n: 
      <input style="display:none;" type="checkbox" name="checkbox2" value="checkbox" />
    </strong></div></td>
    <td class="Estilo16"><div align="right">
      <input onchange="calcular_percepcion(this.value);" name="xpercepcion" id="xpercepcion" type="text" value="<?php echo number_format($xordcom_percepcion,2,'.',''); ?>" style="  display:block; width:70px; text-align:right; " />
    </div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td width="20" class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="8" class="Estilo16"><div  style="display:none;"  align="right"><strong>Total compra:</strong></div></td>
    <td class="Estilo16"><div  style="display:none;"  id="d_xtotal_con_percepcion" align="right"><strong></strong></div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>


	<input name="xid" id="xid" type="hidden" value="<?php echo $xid;?>" />
	<input name="xaccion" id="xaccion" type="hidden" value="adicionar">
	<input name="xordcomdet_codi" id="xordcomdet_codi" type="hidden" value="" />	
	<input name="xcantidad_reg" id="xcantidad_reg" type="hidden" value="<?php echo $nn;?>" />	
	
	<input name="xproveedor" id="xproveedor" type="hidden" value="" />	
	<input name="xpagotipo" id="xpagotipo" type="hidden" value="" />	
	<input name="xfecha" id="xfecha" type="hidden" value="" />
	<input name="xidtrans" id="xidtrans" type="hidden" value="" />
	<input name="xidtrans_temporal" id="xidtrans_temporal" type="hidden" value="" />
	
	<input name="xpedido_recuperado" id="xpedido_recuperado" type="hidden">	
					
	<input name="xanotaciones" id="xanotaciones" type="hidden" value="" />
	<input name="xpagodocumento" id="xpagodocumento" type="hidden" value="" />				
	<input name="xndocumento" id="xndocumento" type="hidden" value="" />
	
	<input name="xfecha_vencimiento" id="xfecha_vencimiento" type="hidden" value="" />
	
	<input  name="xordcom_tipo" id="xordcom_tipo" type="hidden" value="">
	<input  name="xcuentacontable" id="xcuentacontable" type="hidden" value="">
 </form>	
</table>

<div align="left">
<iframe id="frame_compras_detalle_guarda" name="frame_compras_detalle_guarda" width="10" height="10" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" allowtransparency="AllowTransparency"></iframe>
</div>
</body>

<?php
if($nisc > 0){ 
	?>  	
	<script language="javascript">
	document.getElementById('xmonto_isc').disabled = false;
	</script>		
	<?php 
}
?>

<script language="javascript">
parent.document.getElementById('d_img_espera').style.display = "none";
parent.document.getElementById('bt_enviar_formulario_compras').disabled = false;

location.href="#anclaje_detalle_pedido";

document.getElementById('xmonto_isc').value = parent.document.getElementById('xisc_total').value;
document.getElementById('xpercepcion').value = parent.document.getElementById('xpercepcion_total').value;

function calcular_isc(xvalor){
	//alert("xvalor: "+xvalor);
	parent.document.getElementById('xisc_total').value = xvalor;
}

function calcular_percepcion(xvalor){
	//alert("xvalor: "+xvalor);
	parent.document.getElementById('xpercepcion_total').value = xvalor;
}

</script>			


</html>
