<?php
session_start();
include "verifica.php";
?>
<!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();">
<table width="765" border="0" cellpadding="1" cellspacing="1">
  <tr>
    <td width="24" height="31" bgcolor="#FF6600"><div align="center"></div></td>
    <td width="24" bgcolor="#FF6600">&nbsp;</td>
    <td width="52" bgcolor="#FF6600"><div align="center">
      <div align="center"><span class="Estilo20">Estado </span></div>
    </div></td>
    <td width="90" bgcolor="#FF6600"><div align="center">
      <div align="center"><span class="Estilo20">Operaci&oacute;n de caja </span></div>
    </div></td>
    <td width="70" bgcolor="#FF6600"><div align="center">
      <div align="center"><span class="Estilo20">Fecha  </span></div>
    </div></td>
    <td width="110" bgcolor="#FF6600"><div align="center">
      <div align="center"><span class="Estilo20">Fecha registro </span></div>
    </div></td>
    <td bgcolor="#FF6600"><div align="center"><span class="Estilo20">Medio de pago </span></div></td>
    <td bgcolor="#FF6600"><div align="center"><span class="Estilo20">Anotaciones</span></div></td>
    <td width="80" bgcolor="#FF6600"><div align="center"><span class="Estilo20">Monto</span></div></td>
    <td width="12" bgcolor="#FF6600">&nbsp;</td>
  </tr>
  
  
  <form name="form_pedidos_detalle" id="form_pedidos_detalle" method="post" target="frame_pedidos_detalle_guarda" action="procesos/pedidosdetalle.php">
	<?
	@$xid=$_REQUEST['xid'];
	@$xidtrans=$_REQUEST['xidtrans'];
	@$xordcom_codi=$_REQUEST['xordcom_codi'];
	
	include("conexion.php");
	
	$xtotal_pagado = 0;
		$xtotal_compra = 0;
		$xtotal_pagado = 0;		
	
	//$result2=mysqli_query($conexion,"SELECT sum(ordpeddet_precio * ordpeddet_cantidad) as total FROM orden_pedido_detalle o WHERE o.ordped_codi_fk=$xordped_codi;");
	
	$result2=mysqli_query($conexion,"SELECT sum(ROUND(ordcomdet_precio * ordcomdet_cantidad,2)) as total, oc.* 
									FROM orden_compra_detalle ocd 
									INNER JOIN orden_compra oc ON oc.ordcom_codi=ocd.ordcom_codi_fk 
									WHERE ocd.ordcom_codi_fk=$xordcom_codi;");
	
	//SELECT sum(ordpeddet_precio * ordpeddet_cantidad) as total FROM orden_pedido_detalle o WHERE o.ordped_codi_fk=$xordped_codi;
			
	while($row2=mysqli_fetch_array($result2)){
		$xtotal_compra = $row2['total'];
		$xper_codi = $row2['per_codi_fk'];
	}
	
	$result1=mysqli_query($conexion,"SELECT * FROM operacion_caja o 
									LEFT JOIN personas p ON o.per_codi_fk=p.per_codi 
									LEFT JOIN operacion_caja_tipo ot ON o.opecajtip_codi_fk=ot.opecajtip_codi 
									INNER JOIN orden_compra_caja occ ON occ.opecaj_codi_fk=o.opecaj_codi 
									LEFT JOIN medios_pago mp ON mp.medpag_codi=o.medpag_codi_fk 
									WHERE occ.ordcom_codi_fk=$xordcom_codi 
									ORDER BY o.opecaj_fecha desc, o.opecaj_codi desc;");
	
	$nn=0;
	while($row1=mysqli_fetch_array($result1)){
		$nn=$nn+1;
		
		if($row1['opecaj_estado']==1){ 	
			$xtotal_pagado = $xtotal_pagado + $row1['opecaj_monto'];
		}	
	
	?>
   
  
  <tr id="tr<?php echo $nn;?>" style="background-color:#FFFFFF;" onMouseOver="resaltar('#F9F38A',this.id);" onMouseOut="resaltar('#FFFFFF',this.id);" >
    <td class="Estilo16"><a href="#" onclick="parent.modificar_pago_compras('modificar',
																			<?php echo $row1['opecaj_codi']; ?>,
																			<?php echo $row1['opecaj_monto']; ?>,
																			'<?php echo $row1['opecaj_anotaciones']; ?>',
																			'<?php echo $row1['opecaj_fecha']; ?>',
																			'<?php echo $row1['medpag_codi']; ?>',
																			'<?php echo $row1['cc_codi_fk']; ?>'); return false;"><img src="images/icono_editar.png" width="20" border="0" /></a></td>
    <td class="Estilo16"><a href="#"><img src="images/impresora.png" width="25" height="25" border="0" /></a></td>
    <td ><div align="center"><span style=" padding:2px;">
      
      <input name="checkbox" type="checkbox" id="chk_<?php echo $row1['opecaj_codi']; ?>" onclick="cambiar_estado_caja_compra(<?php echo $row1['opecaj_codi']; ?>, this.checked,<?php echo $xordcom_codi; ?>);" value="checkbox"  <?php if($row1['opecaj_estado']==1){ ?> checked="checked" <?php }	 ?>>
      
    </span></div></td>
    <td class="Estilo16"><input readonly="readonly"  name="xcodigo_<?php echo $nn;//$row1['ordpeddet_codi'];?>" id="xcodigo_<?php echo $nn;?>" type="text" style="width:90px; text-align:left; color:#999999;letter-spacing:-1px;" value="<?php echo $row1['opecaj_numero']; ?>" size="8" /></td>
    <td class="Estilo16"><input readonly="readonly"  name="xproducto_<?php echo $nn;?>" type="text" id="xproducto_<?php echo $nn;?>" style="width:65px; text-align:left;  color:#999999; letter-spacing:-1px;"  value="<?php echo date("d/m/Y",strtotime($row1['opecaj_fecha'])); ?>" size="8" /></td>
	
	
    <td class="Estilo16"><input readonly="readonly"  name="xproducto_<?php echo $nn;?>2" type="text" id="xproducto_<?php echo $nn;?>2" style="width:105px; text-align:left;  color:#999999; letter-spacing:-1px;"  value="<?php echo date("d/m/Y H:i:s",strtotime($row1['opecaj_fechahora'])); ?>" size="8" /></td>
    <td class="Estilo16"><input readonly="readonly"  name="xproducto_<?php echo $nn;?>23" type="text" id="xproducto_<?php echo $nn;?>23" style="width:110px; text-align:left;  color:#999999; letter-spacing:-1px;"  value="<?php echo $row1['medpag_nombre']; ?>" size="8" /></td>
		  
    <td class="Estilo16"><textarea name="xproducto_<?php echo $nn;?>22" cols="8" rows="1" readonly="readonly" id="xproducto_<?php echo $nn;?>22" style="width:200px; height:16px; text-align:left;  color:#999999; letter-spacing:-1px;"><?php echo $row1['opecaj_anotaciones']; ?></textarea></td>
    <td class="Estilo16"><input type="text"  readonly="readonly"  name="xmonto_<?php echo $nn;?>" id="xmonto_<?php echo $nn;?>"  value="<?php echo number_format($row1['opecaj_monto'],2,'.',','); ?>" style="width:80px; text-align:right;  color:#999999; " /></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  
	<?
	}
	?> 

  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="2" class="Estilo16">&nbsp;</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 class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16"><input type="hidden" name="xdiferencia" id="xdiferencia" value="<?php echo $xtotal_compra - $xtotal_pagado; ?>" /></td>
    <td class="Estilo16"><div align="right">Pendiente: </div></td>
    <td width="77" class="Estilo16"><div align="right"><B><?php echo number_format($xtotal_compra - $xtotal_pagado,2,'.',','); ?></B></div></td>
    <td width="222" class="Estilo16"><div align="right">Total: </div></td>
    <td class="Estilo16"><div id="d_xigv" align="right"><strong><?php echo number_format($xtotal_pagado,2,'.',','); ?></strong></div></td>
    <td class="Estilo16">&nbsp;</td>
  </tr>
  <tr >
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td class="Estilo16">&nbsp;</td>
    <td colspan="2" class="Estilo16">&nbsp;</td>
    <td class="Estilo16"><div id="d_xtotal" 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="xordpeddet_codi" id="xordpeddet_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="<?php echo $xper_codi;?>" />
	<input name="xordped_codi" id="xordped_codi" type="hidden" value="<?php echo $xordped_codi;?>" />
	
	<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="xanotaciones" id="xanotaciones" type="hidden" value="" />		
 </form>	
</table>


<script language="javascript">
parent.document.getElementById('xproveedor_caja').value = document.getElementById('xproveedor').value;
parent.document.getElementById('xpagotipo_caja').value = <?php echo $_SESSION['s_pagocompra']; ?>;

parent.document.getElementById('xproveedor_caja_vista').value = document.getElementById('xproveedor').value;
parent.document.getElementById('xpagotipo_caja_vista').value = <?php echo $_SESSION['s_pagocompra']; ?>;

parent.document.getElementById('xordcom_codi_fk').value = document.getElementById('xordcom_codi').value;



</script>


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

</body>

</html>
