<?

require_once("comun/funciones.php");
 
// BUSQUEDA DE BLS PARA LOS QUE NO SE HA ENCONTRADO REFERENCIA DE CLIENTE REGISTRADA
//echo 'ref cliente'.trim($referencia_cliente);where referencia='' 
if(trim($referencia_cliente)==''){
	$query = mysqli_query($link,"select distinct booking from hblexpint where  (status='NUEVO' or status = 'REVISANDO' ) and year(fechaRegistro)>=2016 order by fechaRegistro desc");
	$FINE = 1;
	//echo "1.select distinct booking from hblexpint where  (status='NUEVO' or status = 'REVISANDO' ) and year(fechaRegistro)>=2016 order by fechaRegistro desc";
}else{
	$query = mysqli_query($link,"select distinct booking from hblexpint where referencia like '".trim($referencia_cliente)."' and referencia<>''  order by booking");
	//echo "2.select distinct booking from hblexpint where referencia like '".trim($referencia_cliente)."' and referencia<>''  order by booking"; 
}
 
if( mysqli_num_rows($query)<1 ) {
	$query = mysqli_query($link,"select distinct booking from hblexpint  order by fechaRegistro desc limit 20");
	//echo "3.select distinct booking from hblexpint  order by fechaRegistro Desc limit 20";
	//echo mysqli_num_rows($query);
} 
if( mysqli_num_rows($query)==0 ) {echo '<br>No se encontraron resultados<br>';return;}

// echo '3';

 if(trim($referencia_cliente)!=''){
$refer = busquedaB($link,"select referencia from referencias_veracruz where referencia_cliente = '".trim($referencia_cliente)."'","referencia");
}

?>
<style>
table.tablas_con_bordes_ tr.yellow td {
	 
	background: #FFC;
	 
	font-weight:bold; 
	text-align:center;
	 border:1PX solid #333;
	vertical-align:middle;
	/*border-collapse:collapse*/
	
	}

	table.tablas_con_bordes_ tr.comun td {
	 border:1PX solid #333;
	text-align:left;
	
	vertical-align:middle;
	 
	/*background: #FFC;*/
	}
	
	table.tablas_con_bordes_{
		  border-collapse:collapse;
		 /* border-collapse:collapse;border-collapse:collapse; */
	}
	</style>
<br />
<table width="2000" id="exportar" border="1" class="tablas_con_bordes_" style="font-size:11px" >
 
  
  <tr class="yellow" style="text-align:center">

    <td width="36" style="border:none; background-color:transparent;text-align:left" colspan="2" ><B>
	<?=$FINE==1 ? 'HBL SIN REFERENCIA' : ''?>
    <b><?= $refer!='' ? 'REFERENCIA PUERTO:<br> '.$refer : ''?> 
    </B>
    <br /><a style="color:#039; text-decoration:underline"  onClick="todos(this);" >Seleccionar todos los bls</a>
    </td>
    <? if(strtoupper($_SESSION[user]) == "EHUERTA" || strtoupper($_SESSION[user]) == "SISTEMAS" || strtoupper($_SESSION[user]) == "CCARDENAS"){?>
    <td width="250"  align="center" >&nbsp;</td>
	<?}?>
    <td width="250"  align="center" >Booking</td>
    <td  nowrap="nowrap" >Pago MEI</td>
    <td  >Autorizar      </td>
    <td  nowrap="nowrap" >Fecha/Usuario Autorización</td>
    <td width="100"  >Carga Peligrosa</td>
    <td width="100"  >Fecha/Usuario IMO</td>
    <td width="100"  >IMO</td>
    <td width="100"  >Fotos</td>
    <td width="262"  >Marcas</td>
    <td width="79"  >Gross weight</td>
    <td width="75" ><div align="center">Quantity</div></td>
    <td width="87" ><div align="center">Volume</div></td>
    <td width="127" >Pedimento entregado</td>
    <td width="124" >Fecha documentaci&oacute;n</td>
    <td width="101" ><div align="center">Fecha de registro</div></td>
    <!--<td width="124" >Registr&oacute;</td>-->
    <td width="101" >Revisi&oacute;n</td>
    <td width="126" >Fecha Revisi&oacute;n</td>
   <td width="200" >Agencia Aduanal</td>
   <td width="176" >Registrado por</td>
   <td width="176" >Comentarios</td>
  </tr>
  

   <? $k = 1;
   
   while($row=mysqli_fetch_array($query)){ $esi=0;$sh='';
   if(trim($referencia_cliente)!=''){
   $queryA = mysqli_query($link,"select * from hblexpint where referencia like '".trim($referencia_cliente)."%' and booking = '".$row[booking]."'");
   }else{
	    $queryA = mysqli_query($link,"select * from hblexpint where booking = '".$row[booking]."' and (status='NUEVO' or status = 'REVISANDO')  and (year(fechaRegistro)='".date("Y")."' or year(fechaRegistro)='".(date("Y")-1)."') order by fechaRegistro DESC"); 
		
   }
   
   //Validar Carga IMO TOP CEHO
   $vmsgcarimo = "0";
   $qimo=mysqli_query($link ,"select * from booking_ssl where booking_ssl like '%".$row[booking]."%' ");
   if(mysqli_num_rows($qimo)>0){
	$nreg=mysqli_fetch_array($qimo);   
	$vcarga_imo=$nreg[carga_imo];
	if ($vcarga_imo == "1"){$vmsgcarimo = "1";}
	else{$vmsgcarimo = "0";}
   }
   $qimo2=mysqli_query($link ,"select * from detailcargaexpint where bookingno like '%".$row[booking]."%' ");
   $nreg2=mysqli_fetch_array($qimo2);   
   $vusuimo=$nreg2[usuario_imo];
   $vfecimo=$nreg2[fecha_registro];
   if($vfecimo == "0000-00-00 00:00:00"){$vfecimo = "";}
   $vusuimo = $vusuimo."<br>".$vfecimo;
   //Validar Carga IMO END
 
	$qry3=mysqli_query($link_impo,"select booking_interteam from booking_canceled where booking_interteam='".$row[booking]."'");
	$cancelado=0;
	
 
	if(mysqli_num_rows($qry3)>0){
	$cancelado=1;	
	mysqli_query($link,"update hblexpint set status='CANCELADO' where booking = '".$row[booking]."' and booking<>'' "); 
	}
	/* fin de cambio 25.1.2017 */ 
	
   $rowA=mysqli_fetch_array($queryA);
 
   if(trim($referencia_cliente)!=''){
   $query1= mysqli_query($link,"select D.*,H.* from detailcargaexpint D,hblexpint H where D.bookingno = '".$row[booking]."' and H.idhbl = D.id_bl and H.referencia = '".trim($referencia_cliente)."' order by H.idhbl");
   }else{
	   $query1= mysqli_query($link,"select D.*,H.* from detailcargaexpint D,hblexpint H where D.bookingno = '".$row[booking]."' and H.idhbl = D.id_bl and (H.status='NUEVO' or H.status = 'REVISANDO')  and (year(H.fechaRegistro)='".date("Y")."' or year(H.fechaRegistro)='".(date("Y")-1)."') order by H.fechaRegistro desc");
   }
   
   ?>
   
   <? 
   
   while($row1=mysqli_fetch_array($query1)){
 
	 $markandnos=$row1[markandnos];
	if($row1[markandnos]=='' and $row1[id_carga_esi_interteam]*1!=0){
		  
			$q1=mysqli_query($link_impo,"select markandnos from detailcargaexpint where id='".$row1[id_carga_esi_interteam]."'");
			 
			if(mysqli_num_rows($q1)>0){
				$rq1=mysqli_fetch_array($q1);
				$markandnos=$rq1[markandnos];
			 
				mysqli_query($link,"update detailcargaexpint  set markandnos='".$rq1[markandnos]."' where 
				id_carga_esi_interteam='".$row1[id_carga_esi_interteam]."'");
				 
			}
 	 
	}
	 
	//echo '3';
	if(trim($row1[status])=='ROLADO' or trim($row1[status])=='CANCELADO' or $cancelado==1){ 
		$style='style="color:red; text-decoration:line-through;text-align:center;  background-color:#CECE9D;"';

	}else{
		$style='style="text-align:center;  background-color:#CECE9D;"';
	}
	//echo trim($bl[status]).' '.$style;
	$array[]=$row1[bookingno];
	$array1[$row1[bookingno]]=$row1[referencia];
	
   ?>	   
   <tr class="comun" <?=$style?> >
    <TD align="center" style="text-align:center" width="40px"><?=$k?>
     <img align="absbottom" title="Borrar BL" onclick="
    <? if($row1[tipo_bl]=='HBL') { ?>
    if(confirm('Borra este House BL?')){ 
        document.getElementById('form1').action='../borra_hbl.php?idhbl=<?=$row1[id]?>&booking=<?=$row1[bookingno]?>&idpater=<?=$row1[id_bl]?>&referencia_cliente=<?=$referencia_cliente?>';
        document.getElementById('submit').click();
    }
    <? } elseif($row1[tipo_bl]=='MBL') { ?>
    if(confirm('Borra este Master BL?')){ 
       document.getElementById('form1').action='../borra_mbl.php?idhbl=<?=$row1[id]?>&booking=<?=$row1[bookingno]?>&idpater=<?=$row1[id_bl]?>&referencia_cliente=<?=$referencia_cliente?>';
       document.getElementById('submit').click();
    }
    <? } ?>" src="https://<?= $_SERVER["SERVER_NAME"]?>/images/eliminar.png" border="0" style="cursor:pointer" /> 
    </TD>
    
    <TD align="center" style="text-align:center" width="150px"> 
     <? if($row1[tipo_bl]=='MBL'){ ?>
      <input name="<?=$k?>" id="<?=$k?>" onclick="alert(this.id)" type="checkbox" value="../pdf/mbl_n.php?booking=<?=base64_encode($row1[bookingno])?>&idhbl=<?=base64_encode($row1[id_bl])?>" /> 
     <a target="_blank" href="../pdf/mbl_n.php?booking=<?=base64_encode($row1[bookingno])?>&idhbl=<?=base64_encode($row1[id_bl])?>" style="color:#039;text-align:center;text-decoration:underline; cursor:pointer;" title="Exportar a PDF" id="pdf">Recibase MBL ID <?=$row1[id_bl]?></A> 
     <? }else{ ?>
     <input name="<?=$k?>" id="<?=$k?>"  onclick="alert(this.id)" type="checkbox" value="../pdf/hbl_n.php?booking=<?=base64_encode($row1[bookingno])?>&idhbl=<?=base64_encode($row1[id_bl])?>" /> 
     <a  target="_blank" href="../pdf/hbl_n.php?booking=<?=base64_encode($row1[bookingno])?>&idhbl=<?=base64_encode($row1[id_bl])?>" style="color:#039;text-align:center;text-decoration:underline; cursor:pointer;" title="Exportar a PDF" id="pdf">Recibase HBL ID <?=$row1[id_bl]?></A> 
     <? } ?>
    </TD>
    <? if(strtoupper($_SESSION[user]) == "EHUERTA" || strtoupper($_SESSION[user]) == "SISTEMAS" || strtoupper($_SESSION[user]) == "CCARDENAS"){?>
    <td style="text-align:center"> <a href="../borra_hbl_carga.php?idcarga=<?=$row1[id]?>" target="_blank">Borrar carga <?=$row1[id]?></a> </td>
	<?}?>
    <input name="jid_bl[]" type="hidden" id="jid_bl[]" value="<?=$row1[id_bl]?>" />
    <input name="jbookingno[]" type="hidden"  id="jbookingno[]" value="<?=$row1[bookingno]?>" />
    <input name="jtipo[]" type="hidden" id="jtipo[]" value="<?=$row1[tipo_bl]?>"  />
   
    
    <!--<TD align="center" colspan="2" style="text-align:center">
 REVISION</a>
    </TD>-->
    <td style="text-align:center"><div style="width:170px">
      <? if($row1[status]=='REVISANDO'){?>
      <a style="background-color:#FFF; COLOR:GREEN; border:2PX SOLID GREEN;text-decoration:underline;text-align:center;cursor:POINTER" title="REVISION" href="../registro_manifiesto.php?referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>"/><?=$row1[bookingno]?></a>&nbsp;
      
      <? if((strpos($row1[registrado_por],'DHL')!==false or strpos($row1[registrado_por],'KUEHNE')!==false  or strpos($row1[registrado_por],'JAS')!==false) or strpos($row1[comentarios],'**ESI ON')!==false){ ?>
      
      <br><SPAN style="background-color:white; border:2PX SOLID blue; cursor:pointer;text-align:center;">
        <a  title="<?= $sh=='' ? '  ESI&nbsp;&nbsp;' : $sh  ?>" href="../registro_manifiesto.php?bkg=<?=$bkg?>&esi=1&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>#ancla_esi"/> <?= $sh=='' ? '  ESI&nbsp;&nbsp;' : $sh?>&nbsp;<?=$row1[CommunicationReference]=='' ? $row1[CustomerReference] : $row1[CommunicationReference]?></a> </SPAN>
      <? } ?>
      
      <? }else{?> 
      <a style="background-color:#FFF; COLOR:RED; border:2PX SOLID #F00;text-decoration:underline; text-align:center;cursor:POINTER" title="REVISION" href="../registro_manifiesto.php?bkg=<?=$bkg?>&esi=1&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>#ancla_esi"/><?=$row1[bookingno]?></a>&nbsp;
      <? if((strpos($row1[registrado_por],'DHL')!==false or strpos($row1[registrado_por],'KUEHNE')!==false  or strpos($row1[registrado_por],'JAS')!==false) or strpos($row1[comentarios],'**ESI ON')!==false){ ?>
      <br>
      <SPAN style="background-color:white; border:2PX SOLID blue; cursor:pointer;text-align:center;">
        <a  title="<?=$sh=='' ? '  ESI&nbsp;&nbsp;' : $sh?>" href="../registro_manifiesto.php?bkg=<?=$bkg?>&esi=1&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>#ancla_esi"/>&nbsp; <?= $sh=='' ? '  ESI&nbsp;&nbsp;' : $sh?><?=$row1[CommunicationReference]=='' ? $row1[CustomerReference] : $row1[CommunicationReference]?></a> </SPAN>
      <? } ?>
      
      <? } ?>
      </div>
    </td>
      <input name="TDBOK<?=$k?>" type="hidden"  id="TDBOK<?=$k?>" value="<?=$row1[booking]?>" />
	<input name="TDIDBOK<?=$k?>" type="hidden"  id="TDIDBOK<?=$k?>" value="<?=$row1[idhbl]?>" />
    <input name="TDREG_POR<?=$k?>" type="hidden"  id="TDREG_POR<?=$k?>" value="<?=$row1[registrado_por]?>" />
    <input name="TDPED<?=$k?>" type="hidden"  id="TDPED<?=$k?>" value="<?=$row1[pedimento]?>" />
    
    <td style="text-align:center"  id="divPagoMei<?=$k?>" <?=$row1[pago_mei]=='PENDIENTE' ?
	' bgcolor="red" ' : ($row1[pago_mei]=='PAGADO' ?  ' bgcolor="green" ' : "") ?>   >     
	<?= ($row1[autorizacion]!='Autorizar' and $row1[autorizacion]!='NO Autorizar' and $row1[autorizacion]!='')  ? 'NA' : $row1[pago_mei] ?>
</td>
    
    <td style="text-align:center"><select name="autorizar<?=$k?>" id="autorizar<?=$k?>"
    onchange="/*REG_POR='<?=$row1[registrado_por]?>';PED='<?=$row1[pedimento]?>';TBOK='<?=$row1[booking]?>';
 
    for(t=1;t<=document.getElementById('cantFilas').value;t++){ 
            if(document.getElementById('TDPED'+t).value!=''){
                if(document.getElementById('TDPED'+t).value==PED && document.getElementById('TDPED'+t).value!='' && document.getElementById('TDBOK'+t).value==TBOK){
                document.getElementById('autorizar'+t).value=this.value;   
                }
            } 
            if(document.getElementById('TDPED'+t).value==''){
                if(document.getElementById('TDREG_POR'+t).value==REG_POR && document.getElementById('TDBOK'+t).value==TBOK){ 
                document.getElementById('autorizar'+t).value=this.value;
                }
            }
    }*/ ">
      <option value=""  <?=$row1[autorizacion]=='' ? 'selected="selected"' : ''?>></option>
      <option value="Autorizar" <?=$row1[autorizacion]=="Autorizar" ? 'selected="selected"' : ''?>>Autorizar</option>
      <option value="NO Autorizar" <?=$row1[autorizacion]=="NO Autorizar" ? 'selected="selected"' : ''?>>NO Autorizar</option>
      
         <option value="MEI EXENTO // LESCHACO" <?=$row1[autorizacion]=="MEI EXENTO // LESCHACO" ? 'selected="selected"' : ''?>>MEI EXENTO // LESCHACO</option>
      <option value="MEI EXENTO // DHL" <?=$row1[autorizacion]=="MEI EXENTO // DHL" ? 'selected="selected"' : ''?>>MEI EXENTO // DHL</option>
  	  <option value="MEI EXENTO // DSV" <?=$row1[autorizacion]=="MEI EXENTO // DSV" ? 'selected="selected"' : ''?>>MEI EXENTO // DSV</option>
      <option value="MEI EXENTO // PAC" <?=$row1[autorizacion]=="MEI EXENTO // PAC" ? 'selected="selected"' : ''?>>MEI EXENTO // PAC</option>
 	  <option value="MEI EXENTO // EMERSON" <?=$row1[autorizacion]=="MEI EXENTO // EMERSON" ? 'selected="selected"' : ''?>>MEI EXENTO // EMERSON</option>
      <option value="MEI EXENTO // KN" <?=$row1[autorizacion]=="MEI EXENTO // KN" ? 'selected="selected"' : ''?>>MEI EXENTO // KN</option>
      <option value="MEI EXENTO // SOLIC. ITT" <?=$row1[autorizacion]=="MEI EXENTO // SOLIC. ITT" ? 'selected="selected"' : ''?>>MEI EXENTO // SOLIC. ITT</option>
      <option value="MEI EXENTO // DESP. ITT" <?=$row1[autorizacion]=="MEI EXENTO // DESP. ITT" ? 'selected="selected"' : ''?>>MEI EXENTO // DESP. ITT</option> 
    </select></td>
    <td style="text-align:center"><div id="divAutorizo<?=$k?>">
      <?=$row1[usuario_autorizo].' '.$row1[fecha_usuario_autorizo]?>
    </div></td>
    <td style="text-align:center">
    <select name="cargimo<?=$k?>" id="cargimo<?=$k?>" onchange="">
	<? if($vmsgcarimo == "1"){?>
      <option value="SI">SI</option>
	<?}else{?>  
      <option value="NO">NO</option>
      <option value="SI">SI</option>
	<?}?>  
    </select>
    </td>
    <td style="text-align:center">
      <?=$vusuimo?>
    </td>
    <?
				//$medidas='';
				$volumen='';$numero_bultos=''; 
				$dimen1 =	mysqli_query($link,"select D.* from dimensiones D where D.id_partida = '".$row1[id_bl]."'  ");
				
				if(mysqli_num_rows($dimen1)>0){ 
				   while($rd1=mysqli_fetch_array($dimen1)){
				   $volumen+=$rd1[largo]*$rd1[ancho]*$rd1[alto]*$rd1[numero_bultos]/1000000;
				   //$medidas.= $rd1[largo].'x'.$rd1[ancho].'x'.$rd1[alto].(mysqli_num_rows($dimen1)>0 ? '<br>' : '');
				   $numero_bultos+=$rd1[numero_bultos];
				   }
				}
				/*			if(mysqli_num_rows($dimen1)<1 and (strtoupper(strpos($row[registrado_por],'DHL'))!==false 
							or strtoupper(strpos($row[registrado_por],'KUEHNE'))!==false
							or strtoupper(strpos($row[registrado_por],'JAS'))!==false) ){
				$dimen1 =	mysqli_query($link,"select * from detailcargaexpint where bookingno='".$row1[bookingno]."' ");
				$rd1=mysqli_fetch_array($dimen1);
				$numero_bultos=$rd1[bulk];
				//$volumen=$rd1[measurement];
 $weight=$rd1[weight];
				}*/
				
				if(mysqli_num_rows($dimen1)<1 /*and (strtoupper(strpos($row[registrado_por],'DHL'))!==false 
				or strtoupper(strpos($row[registrado_por],'KUEHNE'))!==false
				or strtoupper(strpos($row[registrado_por],'JAS'))!==false)*/ ){
				$dimen1 =	mysqli_query($link,"select * from detailcargaexpint where  id_bl= '".$row1[id_bl]."'");
				//echo "select * from detailcargaexpint where bookingno='".$row1[bookingno]."' and id_bl= '".$row1[id_bl]."' ";
				$rd1=mysqli_fetch_array($dimen1);
				$numero_bultos=$rd1[bulk];
				//$volumen=$rd1[measurement];
 $weight=$rd1[weight];
				}
				
	?>
    <td style="text-align:center"><?=$row1[imo]?></td>
    <td style="text-align:center"><?= $row1[fotos]!='' ? '<a href="'.$row1[fotos].'" target="_blank">Fotos</a>' : ''?></td> 
    <td align="center" ><?=$markandnos?></td>
    <td align="center"><?=$row1[weight]?></td>

    
    <td ><div align="center">
     <?=($row1[ultimo_update_golmex]!='0000-00-00 00:00:00' and $row1[ultimo_update_golmex]!='') ? '<span style="color:green; font-style:italic">**' : ''?>
      <?=$numero_bultos?>
      <?=($row1[ultimo_update_golmex]!='0000-00-00 00:00:00' and $row1[ultimo_update_golmex]!='') ? '**</span>' : ''?>
    </div></td>
    <td ><div align="center">
    <?=($row1[ultimo_update_golmex]!='0000-00-00 00:00:00' and $row1[ultimo_update_golmex]!='') ? '<span style="color:green; font-style:italic">**' : ''?>
      
	<?=number_format($volumen*1,3)?>

      <?=($row1[ultimo_update_golmex]!='0000-00-00 00:00:00' and $row1[ultimo_update_golmex]!='') ? '**</span>' : ''?>
    </div></td>
    <td ><?=$row1[pedimento]?></td>
    <td width="150" style="text-align:center" ><?=($row1[status]=='' ? 'REVISANDO' : $row1[status])?>  </td>
    <td align="center"><div align="center">
      <?=$row1[fechaRegistro]?>
    </div></td>
    <!--<td ><?=$row1[registrado_por]?></td>-->
    <td ><?=$row1[revision]?></td>
    <td ><div align="center">
      <?=$row1[fecha_revision]?>
    </div></td>
    
         <?
		 
		$link_impo=con_impo();
	

		$datos_aa = data($link_impo,"SELECT A.*,C.nombre_contacto,C.telefono_contacto FROM `agentes_aduanales` A 
		INNER JOIN contactos_agentes_aduanales C
		on A.patente=C.patente and A.id=C.idaa and (A.registro = 'ALTAMIRA' or A.registro = 'INTERTEAM') and C.email_contacto LIKE '%".$row1["registrado_por"]."%' ");

		$agente_aduanal  = $datos_aa[nombre_agente_aduanal];
		$nombre_empresa  = $datos_aa[nombre_empresa];
		$nombre_contacto  = $datos_aa[nombre_contacto];
		$telefono_contacto  = $datos_aa[telefono_contacto];
		con_ver();
		?>
        
    <td style="font-size:10px" ><?=$nombre_empresa?></td>
    <td align="center" ><?=$row1[registrado_por]?></td>
    <td >
	<?=($row1[ultimo_update_golmex]!='0000-00-00 00:00:00' and $row1[ultimo_update_golmex]!='') ? 
	'<span style="color:green; font-style:italic">**Webservice Golmex** '.$row1[ultimo_update_golmex].'</span>' : ''?>
		<?=str_replace("\n","<br>",$row1[comentarios].' <span style="color:blue">'.$row1[ultima_actualizacion_esi].'</span>')?></td></td>
  </tr>

 
  <?   $k++; } } ?>  
   <input name="cantFilas" id="cantFilas" type="hidden" value="<?=$k-1?>" />
  
    <? 
if(trim($referencia_cliente)!=''){ 
 
	$qry3=mysqli_query($link_impo,"select files from datosexpint FORCE INDEX (i_referencia_interteam) where referencia_interteam like '".trim($referencia_cliente)."%'");
	//ECHO "select files from datosexpint where referencia_interteam like '".trim($referencia_cliente)."%'";
	$r8=mysqli_fetch_array($qry3);
	$files=$r8["files"];
	
	if(!isset($array)){
	$array = array();	
	}
	$unicos=array_unique($array);
	 
	$cantidad_bookings = count(array_unique($array));
	
	//$finales[]$customsagent[]
	if(trim($files)!=''){ 
			$qry3=mysqli_query($link_impo,"select booking_interteam,customsagent from bookingexpint  FORCE INDEX (i_files_b) where files='".$files."' order by booking_interteam");
			//ECHO "select booking_interteam,customsagent from bookingexpint where files='".$files."' order by booking_interteam";
			 
			if($cantidad_bookings<mysqli_num_rows($qry3)){
				while($r8=mysqli_fetch_array($qry3)){
					 
					if (! in_array($r8[booking_interteam], $unicos) and ($array1[$r8[booking_interteam]]==$referencia_cliente or !isset($array1[$r8[booking_interteam]]))) {
						$finales[]=$r8[booking_interteam];
						$customsagent[]=$r8[customsagent];
					}
				}
				
			}
	
	}

	$i=0;	
	if(count($finales)>0){
	while($i<count($finales)){
		?>
    <tr class="comun" <?=$style?>  >
    <TD align="center" style="text-align:center;" width="40px"><?=$k?></TD>
    
    <TD align="center" style="text-align:center" width="150px"></TD>
    
    <? $k++;?>
    
  
    <td style="text-align:center"> <SPAN style="background-color:#FFF; COLOR:blue; border:2PX SOLID blue">&nbsp;<a style="text-decoration:underline; color:#039;text-align:center;cursor:POINTER" title="REVISION" href="../registro_manifiesto3.php?referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&booking_interteam=<?=$finales[$i]?>"/><?=$finales[$i]?></a>&nbsp;</SPAN> </td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td> 
    <td style="text-align:center">&nbsp;</td> 
    <td style="text-align:center">&nbsp;</td> 
    <td align="center" > <SPAN style="background-color:#FFF; COLOR:blue; border:2PX SOLID blue">&nbsp;SIN DOCUMENTAR&nbsp;</SPAN></td>
    <td style="text-align:center">&nbsp;</td> 
    <td align="center"><?=$row1[weight]?></td>
         
    
    <td ><div align="center">
      <? //=$numero_bultos?>
    </div></td>
    <td ><div align="center">
      <? //=number_format($volumen,3)?>
    </div></td>
    <td > </td>
    <td width="150" style="text-align:center" ></td>
    <td align="center"><div align="center">
      <?=$row1[fechaRegistro]?>
    </div></td>
  
    <td ><div align="center">
     
    </div></td>
    <td ><div align="center">
      
    </div></td>
    <td style="font-size:10px"> <SPAN style="background-color:#FFF; COLOR:blue; border:2PX SOLID blue">&nbsp;<?=$customsagent[$i]?>&nbsp;</SPAN></td>
    <td align="center" > </td>
    <td > </td>
  </tr>
    <? $i++;
	} }
		con_ver();
	?>

     <? 
	 
	//%%%%%%%%%%%%%%%%%%%%%% BOOKINGS SIN DOCUMENTAR DE REFERENCIAS DE VERACRUZ %%%%%%%%%%%%%%%%%%%%%% 
 
 
	unset($finales);unset($customsagent);
	$unicos=array_unique($array);
	//echo $unicos;
	$cantidad_bookings = count(array_unique($array));

	$qry3=mysqli_query($link,"SELECT * FROM booking_ssl FORCE INDEX (i_referencia_cliente) where referencia_cliente = '".trim($referencia_cliente)."' order by booking_ssl");
	//echo "SELECT * FROM booking_ssl FORCE INDEX (i_referencia_cliente) where referencia_cliente = '".trim($referencia_cliente)."' order by booking_ssl";
	
 
		while($r8=mysqli_fetch_array($qry3)){
			if (! in_array($r8[booking_ssl], $unicos)) {
				$finales[]=$r8[booking_ssl];
				 
			}
		}
		
 

	$i=0;	
	//echo count($finales);
	if(count($finales)>0){
	while($i<count($finales)){
		?>
    <tr class="comun" <?=$style?>  >
    <TD align="center" style="text-align:center;" width="40px"><?=$k?></TD>
    
    <TD align="center" style="text-align:center" width="150px"></TD>
    
    <? $k++;?>
    
  
    <td style="text-align:center"> <SPAN style="background-color:#FFF; COLOR:blue; border:2PX SOLID blue">&nbsp;<a style="text-decoration:underline; color:#039;text-align:center;cursor:POINTER" title="REVISION" href="../registro_manifiesto3.php?referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&booking_interteam=<?=$finales[$i]?>"/><?=$finales[$i]?></a>&nbsp;</SPAN> </td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td>
    <td style="text-align:center">&nbsp;</td> 
    <td style="text-align:center">&nbsp;</td> 
    <td style="text-align:center">&nbsp;</td> 
    <td align="center" > <SPAN style="background-color:#FFF; COLOR:blue; border:2PX SOLID blue">&nbsp;SIN DOCUMENTAR&nbsp;</SPAN></td>
    <td style="text-align:center">&nbsp;</td> 
    <td align="center"><?=$row1[weight]?></td>
         
    
    <td ><div align="center">
      <? //=$numero_bultos?>
    </div></td>
    <td ><div align="center">
      <? //=number_format($volumen,3)?>
    </div></td>
    <td > </td>
    <td width="150" style="text-align:center" ></td>
    <td align="center"><div align="center">
      <?=$row1[fechaRegistro]?>
    </div></td>
  
    <td ><div align="center">
     
    </div></td>
    <td ><div align="center">
      
    </div></td>
    <td style="font-size:10px"></td>
    <td align="center" > </td>
    <td > </td>
  </tr>
    <? $i++;
} } }
		?>
  </table>
<div style="width:2000px" align="left">
  <input name="input" type="button" value="Guardar" 
    onclick="
    for(t=1;t<=document.getElementById('cantFilas').value;t++){
        realizaProceso(t,document.getElementById('cantFilas').value);
    } "/>
</div>
<br />