<?php
session_start();
$com = "A";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DF80000.php");
include ("varfun.php");

?>

<html>

<script language="javascript">

function openWindow(dataGen,valores){

	var objDate=new Date();

	var getVars,getVarsAux,distPage;

	var idVentana;

	for(getVarsAux in valores){

		getVars +='&'+getVarsAux+'='+valores['getVarsAux'];

	}

	if(typeof dataGen.width=='undefined') dataGen.width='800';

	if(typeof dataGen.height=='undefined') dataGen.height='600';

	distPage='?tmr='+objDate.getHours()+objDate.getMinutes()+objDate.getSeconds()+objDate.getDay()+objDate.getMonth()+objDate.getFullYear();

	idVentana=window.open(dataGen.action+distPage+getVars,dataGen.name,'width='+dataGen.width+',height='+dataGen.height+',top=100,left=50,scrollbars=yes,menubar=no,status=no');

	return idVentana;

}


</script>
<body>
<?php 
/*Verifica que exista Variable contenedora del Id del Encabezado*/	
if (!isset($_REQUEST['bot'])){
	echo '<h2>!!! SELECCIONA UN REGISTRO... ACTUALIZANDO !!!</h2>';
	echo '<meta content="1; url=caj_checkout_PR.php"  HTTP-EQUIV="REFRESH">';
	exit();
}	
$his=mysqli_query($con ,"select * from valeryus19 where n_reg='".$_REQUEST['bot']."'");
$h1=mysqli_fetch_array($his);
if ($h1['status'] == 'HISTORICO'){
	echo '<h2>!!! ESTE FOLIO YA ESTA SALDADO... ACTUALIZANDO !!!</h2>';
	echo '<meta content="1; url=caj_checkout_PR.php"  HTTP-EQUIV="REFRESH">';
	exit();
	}
/****************************************************************/
/*Llena Variable para verificar si esta en modo Update*/
if(!isset($_POST['block_mod'])){
	$bMod=false;			//Bandera de modificar, bloquea pagina en modo Modificar esperando el evento que la cambie de estado
	$bSel='';				//Id registro a modificar
}
else{
	$bMod=$_POST['block_mod'];
	$bSel=$_POST['reg_mod'];
}

/****************************************************/
$bModPri=false;				//Bandera de Modificar(True solo En el Primer Bloqueo o recarga de pagina en modo Modificar)
$id_enc=$_REQUEST["bot"]; 	//Id de Encabezado
$id_det=$_POST['bot_det'];	//Id de Detalle (si se selecciono alguno)
/*Crear Objetos Necesarios para Manipular Encabezado y Detalle*/
include('DI21100_CL.php');
$dataEnc['idInvent']=$id_enc;
$dataDet['idInvent']=$id_enc;
$dataDet['idInvend']=$id_det;
//echo "DETALLE: $dataDet['idInvend']";$reg_cuenta = $_GET['n_reg'];
//$encInv = new EncFac($dataEnc);
//$detInv = new DetFac($dataDet);
/************************************************************/
/*Recuperar Informacin de Encabezado y la coloca en los objetos HTML*/
//$res=$encInv->busReg();
$dt_encinv=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM valeryus19 WHERE n_reg='$id_enc'"));
$_REQUEST['id_prod']=$dt_encinv['fnombre'];
$_REQUEST['des_prod']=$dt_encinv['fnumcto'];
$_REQUEST['fec_prod']=chfecha($dt_encinv['ffecsalida'],'Y-m-d','d/m/Y');
$_REQUEST['fac_prod']=$dt_encinv['fapellido'];
$_REQUEST['tip_prod']=$dt_encinv['almacen'];
$_REQUEST['n_reg']=$dt_encinv['n_reg'];
$_REQUEST['invmin']=$dt_encinv['ftipocto'];
$_REQUEST['invmax']=$dt_encinv['fnumctos'];
$_REQUEST['codigo']=$dt_encinv['n_reg'];
$_REQUEST['fnorasvip']=$dt_encinv['fnorasvip'];
$_REQUEST['fcodgrupo']=$dt_encinv['fcodgrupo'];
$_REQUEST['fcodmeca']=$dt_encinv['fcodmeca'];
$_REQUEST['fcodagen']=$dt_encinv['fcodagen'];
$_REQUEST['codseg']=$dt_encinv['codseg'];
$_REQUEST['ffecllegada']=chfecha($dt_encinv['ffecllegada'],'Y-m-d','d/m/Y');
$_REQUEST['fformpago']=$dt_encinv['fformpago'];
$_REQUEST['tex']=$dt_encinv['tex'];
$_REQUEST['tex4']=$dt_encinv['tex4'];
$_REQUEST['text1']=$dt_encinv['text1'];
$_REQUEST['text4']=$dt_encinv['text4'];
$_REQUEST['fmonmen']=$dt_encinv['fmonmen'];
$_REQUEST['fmonadu']=$dt_encinv['fmonadu'];
	
/******************************************************************/
/*Verificamos Si es la Primer Carga de La Pagina por si es necesario realizar alguna accion*/
if(!isset($_POST['DI21100_AGDET'])){
	$_REQUEST['id_iva']  =$dt_encinv['idTasIva'];
}
/************************************************/
/*Bloque de condiciones para Realizar las distintas operaciones sobre el detalle*/

/****************************************************************/
/*Busca los Registros pertenecientes al encabezado en cuestion*/
$sq_detfac=mysqli_query($con ,"SELECT * FROM valeryus030 WHERE nparte1='".$dataEnc['idInvent']."' order by acc_fec");

/*************************************************************/
?>
<!--form name="formulario" action="cualquiera.html" method="post">
Acepto las condiciones <input type="checkbox" value="acepto" onclick="document.formulario.enviar.disabled=!document.formulario.enviar.disabled"><br>
<input type="submit" name="enviar" value="Enviar" disabled>
</form-->
<form name="frm1" id="frm1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="DI21100_AGDET" id="DI21100_AGDET" value="DI21100_AGDET.php">
<input type="hidden" name="bot" id="bot" value="<?php echo $_REQUEST['bot'];?>">
<input type="hidden" name="reg_mod" id="reg_mod" value="<?php echo $bSel;?>">
<input type="hidden" name="block_mod" id="block_mod" value="<?php echo $bMod;?>">
 
  <p>&nbsp;</p>
  <table width="644" border="0" align="center" cellspacing="4" id="tableDetail">
    <tr>
      <th colspan="19"><div align="center">
        
      </div></th>
    </tr>
    <tr>
      <th width="23" nowrap>SEL</span></th>
      <th width="41" nowrap>FECHA</th>
      <th width="37" nowrap>HORA</th>
	  <th width="61" nowrap># RECIBO </th>
      <th width="135" nowrap>DESCRIPCON /CARGO</th>
	  <th width="54" nowrap>CARGOS</th>
      <th width="55" nowrap>ABONOS</th>
	  <th width="60" nowrap>NOTAS</th>
	  <th width="100" nowrap>GRUPO</th>
	  <th width="100" nowrap>AGENCIA</th>
	  <th width="100" nowrap>SEGMENTO</th>
	  <th width="100" nowrap>MERCADO</th>
	    </tr>
    <?php
		//Codigo Mostrar
                // Detalle
		$subTotDoc=0.00;
		$ivaTotDoc=0.00;
		$totDoc=0.00;
		$subTotPar=0.00;
		$ivaTotPar=0.00;
		$totPar=0.00;
		$tipCar='-1';
		$contador=0;
		while($dt_invend=mysqli_fetch_array($sq_detfac)){
			$contador++;
			$auxInvent=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM valeryus09 WHERE n_reg='".$dt_invend['nparte1_det']."'"));			
			if($dt_invend['id_invend']!=$bSel){// nparte1, np_desc son de la table farticulos
    				if($dt_invend['cancelado'] == 0){
					echo'<tr>
					<td><div align="center">
						<input type="radio" name="bot_det" id="bot_det" value="'.$dt_invend['id_invend'].'">
					</div></td>
					<td><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$auxInvent['pclave'].'-'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$dt_invend['grupo'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$dt_invend['agencia'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$dt_invend['segmento'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$dt_invend['mercado'].'&nbsp;
					</div></td>
					
					</tr>';
					}if ($dt_invend['cancelado'] == 1){
				    echo'<tr>
					<td style="background:#FF3300"><div align="center">
						<input type="radio" name="bot_det" disabled id="bot_det" value="'.$dt_invend['id_invend'].'">
					</div></td>
					<td style="background:#FF3300"><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td style="background:#FF3300" class="detailRowTable" ><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td style="background:#FF3300" class="detailRowTable" ><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td style="background:#FF3300" class="detailRowTable" ><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td style="background:#FF3300" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td style="background:#FF3300" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td style="background:#FF3300" class="detailRowTable" ><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td style="background:#FF3300"><div align="left">
							'.$dt_invend['grupo'].'&nbsp;
					</div></td>
					<td style="background:#FF3300"><div align="left">
							'.$dt_invend['agencia'].'&nbsp;
					</div></td>
					<td style="background:#FF3300"><div align="left">
							'.$dt_invend['segmento'].'&nbsp;
					</div></td>
					<td style="background:#FF3300"><div align="left">
							'.$dt_invend['mercado'].'&nbsp;
					</div></td>
					
					</tr>';
					}if ($dt_invend['cancelado'] == 2){
				    echo'<tr>
					<td style="background:#7970F1"><div align="center">
						<input type="radio" name="bot_det" id="bot_det" value="'.$dt_invend['id_invend'].'">
					</div></td>
					<td style="background:#7970F1"><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td style="background:#7970F1"><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td style="background:#7970F1" class="detailRowTable" ><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td style="background:#7970F1" class="detailRowTable" ><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td style="background:#7970F1" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td style="background:#7970F1" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td style="background:#7970F1" class="detailRowTable" ><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td style="background:#7970F1"><div align="left">
							'.$dt_invend['grupo'].'&nbsp;
					</div></td>
					<td style="background:#7970F1"><div align="left">
							'.$dt_invend['agencia'].'&nbsp;
					</div></td>
					<td style="background:#7970F1"><div align="left">
							'.$dt_invend['segmento'].'&nbsp;
					</div></td>
					<td style="background:#7970F1"><div align="left">
							'.$dt_invend['mercado'].'&nbsp;
					</div></td>
					
					</tr>';
					}if ($dt_invend['cancelado'] == 3){
				    echo'<tr>
					<td style="background:#CC3399"><div align="center"
						<input type="radio" name="bot_det" disabled id="bot_det" value="'.$dt_invend['id_invend'].'">
					</div></td>
					<td style="background:#CC3399"><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td style="background:#CC3399"><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td style="background:#CC3399" class="detailRowTable" ><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td style="background:#CC3399" class="detailRowTable" ><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td style="background:#CC3399" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td style="background:#CC3399" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td style="background:#CC3399"><div align="left">
							'.$dt_invend['grupo'].'&nbsp;
					</div></td>
					<td style="background:#CC3399"><div align="left">
							'.$dt_invend['agencia'].'&nbsp;
					</div></td>
					<td style="background:#CC3399"><div align="left">
							'.$dt_invend['segmento'].'&nbsp;
					</div></td>
					<td style="background:#CC3399"><div align="left">
							'.$dt_invend['mercado'].'&nbsp;
					</div></td>
					
					</tr>';
					}
					$numPun +=$auxInvent['num_pun'];
					$sbt = $sbt + $dt_invend['toldes'];
					$p = $p + $dt_invend['total'];
					$q = $q + $dt_invend['ivatotal'];
					$jiu = ($q +$p)-$sbt;
					$nk = $nk + $dt_invend['proteina'];
		$sqo = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(costo) AS tot FROM valeryus030 WHERE cancelado=0 AND nparte1 = '".$_REQUEST['bot']."'"));
		$sqk = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(costo) AS tat FROM valeryus030 WHERE cancelado=2 AND nparte1 = '".$_REQUEST['bot']."'"));
		$sqf = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(total) AS sos FROM valeryus030 WHERE cancelado=0 AND nparte1 = '".$_REQUEST['bot']."'"));
		$sqs = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(total) AS sas FROM valeryus030 WHERE cancelado=2 AND nparte1 = '".$_REQUEST['bot']."'"));
					$uij = $sqo['tot'] + $sqk['tat'];
				    $pol = $sqf['sos'] + $sqs['sas'];
					$asd = $uij - $pol;
				}
		}
		echo '
			<tr>
			<td colspan="5" class="inputcodigo"><div align="right">TOTAL: &nbsp;</div></td>
			<td colspan="1" class="inputcodigo"><div align="right">'.number_format($uij,2,'.',',').'</div></td>
			<td colspan="1" class="inputcodigo"><div align="right">'.number_format($pol,2,'.',',').'</div></td>
			<td colspan="2" class="inputcodigo"><div align="right">=======>>>>>> &nbsp;</div></td>
			<td colspan="1" class="inputcodigo"><div align="right">'.number_format($asd,2,'.',',').'</div></td>
			</tr>';	
	?>
    <tr>
      <td colspan="15"><div align="center">
             </div></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
 mysqli_close($con);
//932--->700 ultima actualizacion 29/abril/2011
?>
