<?

require_once("comun/funciones.php");
 
$qr=mysqli_query($link,"select * from datosbooking FORCE INDEX (i_contenedor) where contenedor ='$contenedor' and contenedor<>'' order by id desc limit 1");
$rqr=mysqli_fetch_array($qr);

if( mysqli_num_rows($qr)==0 ) {echo '<br>No se encontraron resultados<br>';return;}
$referencia_cliente=$rqr[referencia_cliente];

$query = mysqli_query($link,"select distinct booking from hblexpint FORCE INDEX (i_referencia) 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 FORCE INDEX (i_fechaRegistro) order by fechaRegistro Desc limit 20");
}
if( mysqli_num_rows($query)==0 ) {echo '<br>No se encontraron resultados x<br>';return;}

if(trim($referencia_cliente)!=''){
	$refer = busquedaB($link,"select referencia from referencias_veracruz FORCE INDEX (i_referencia_cliente) 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="2050" id="exportar" border="1" class="tablas_con_bordes_" style="font-size:11px" >
 
  
  <tr class="yellow" style="text-align:center">

    <td 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>
    <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="154"  >IMO</td>
    <td width="154"  >Fotos</td>
    <td width="253"  >Marcas</td>
    <td width="99"  ><div align="center">Gross weight</div></td>
    <td width="71" ><div align="center">Quantity</div></td>
    <td width="67" ><div align="center">Volume</div></td>
    <td width="131" >Pedimento entregado</td>
    <td width="93" >Fecha documentaci&oacute;n</td>
    <td width="99" ><div align="center">Fecha de registro</div></td>
    <!--<td width="124" >Registr&oacute;</td>-->
    <td width="115" >Revisi&oacute;n</td>
    <td width="100" ><div align="center">Fecha Revisi&oacute;n</div></td>
   <td width="150" >Agencia Aduanal</td>
   <td width="176" >Registrado por</td>
   <td width="206" >Comentarios</td>
  </tr>
  

   <? $k = 1;
   
   while($row=mysqli_fetch_array($query)){ $esi=0;
    $array[]=$row[booking];
	$array1[$row[bookingno]]=$row[referencia];
	
   //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

   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') order by fechaRegistro DESC"); 
		
		
   }
   
   $rowA=mysqli_fetch_array($queryA);
 
$qry3=mysqli_query($link_impo,"select booking_interteam from booking_canceled where booking_interteam='".$row[booking]."'");
$cancelado=0;
/* esis dhl 25.6.2018 */ 
	if(strpos($row[booking],'EXIT')!==false){
	$queryInt=mysqli_query($link_impo,"SELECT booking FROM `bookingexpint` WHERE booking_interteam LIKE '".$row[booking]."'");
	 if(mysqli_num_rows($queryInt)>0){
		 $rqueryInt=mysqli_fetch_array($queryInt);
		 $bkg=$rqueryInt[0];
		 $sql = mysqli_query($link_impo,"SELECT *  FROM hblexpint_actualizaciones where booking= '$bkg' order by id desc limit 1"); 
		
		if(mysqli_num_rows($sql)>0){
			$rs=mysqli_fetch_array($sql);
			$sh=$rs[shipper];
			$sh1=explode(' ',$rs[shipper]);
			$cn=$rs[consignee];
			$n1=$rs[notify];
			$sh='';
			if(strpos($sh,'DHL')!==false or strpos($sh,'DHL')!==false or strpos($sh,'DHL')!==false){
			$sh='DHL';	
			}
			if(strpos($sh,'KUEHNE')!==false or strpos($sh,'KUEHNE')!==false or strpos($sh,'KUEHNE')!==false){
			$sh='KUEHNE';	
			}
			if(strpos($sh,'JAS')!==false or strpos($sh,'JAS')!==false or strpos($sh,'JAS')!==false){
			$sh='JAS';	
			}
			if(strpos($sh,'PANALPINA')!==false or strpos($sh,'PANALPINA')!==false or strpos($sh,'PANALPINA')!==false){
			$sh='PANALPINA';	
			}
			if(strpos($sh,'AGILITY')!==false or strpos($sh,'AGILITY')!==false or strpos($sh,'AGILITY')!==false){
			$sh='AGILITY';	
			}
			if($sh==''){
				$sh=$sh1[0];
			}
			$esi=1;
		}
	 }
	}
 
if(mysqli_num_rows($qry3)>0){
$cancelado=1;	
mysqli_query($link,"update hblexpint set status='CANCELADO' where booking = '".$row[booking]."' and booking<>'' "); 
}
 
 
   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' ) 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;
   ?>	   
   <tr class="comun" <?=$style?> >
    <TD align="center" style="text-align:center" width="32"><?=$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="117"> 
     <? if($row1[tipo_bl]=='MBL'){ ?>
      <input name="<?=$k?>" id="<?=$k?>"  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?>"  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>
        <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]?>"  />
    <? $k++;?>
    
    <!--<TD align="center" colspan="2" style="text-align:center">
 REVISION</a>
    </TD>-->
    <td style="text-align:center">
      <? if($row1[status]=='REVISANDO'){?>
      <SPAN style="background-color:#FFF; COLOR:GREEN; border:2PX SOLID GREEN;text-decoration:underline; cursor:pointer">&nbsp;<a style="text-decoration:underline; color:#039;text-align:center;cursor:auto" title="REVISION" href="../registro_manifiesto.php?contenedor=<?=$contenedor?>&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>"/><?=$row1[bookingno]?></a>&nbsp;</SPAN>&nbsp;
      
      <? if(strpos($row1[registrado_por],'DHL')!==false or strpos($row1[registrado_por],'KUEHNE')!==false or strpos($row1[registrado_por],'JAS')!==false){ ?>
      &nbsp; 
      <SPAN style="background-color:white; border:2PX SOLID blue; cursor:pointer;text-align:center;">
      <a  title="<?=  $sh //$sh!='DHL' ? $sh : 'DHL'?>" href="../registro_manifiesto.php?contenedor=<?=$contenedor?>&bkg=<?=$bkg?>&esi=1&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>#ancla_esi"/>&nbsp;ESI <?= $sh//$sh=='DHL' ? 'DHL' : ''?>&nbsp;</a> </SPAN>
      <? } ?>
      
      <? }elseif($row1[status]=='NUEVO'){?> 
      <SPAN style="background-color:#FFF; COLOR:RED; border:2PX SOLID #F00;text-decoration:underline; cursor:pointer">&nbsp;<a style="text-decoration:underline; color:#039;text-align:center;cursor:auto" title="REVISION" href="../registro_manifiesto.php?contenedor=<?=$contenedor?>&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>"/><?=$row1[bookingno]?></a>&nbsp;</SPAN>&nbsp;
      
      <? if(strpos($row1[registrado_por],'DHL')!==false or strpos($row1[registrado_por],'KUEHNE')!==false or strpos($row1[registrado_por],'JAS')!==false){ ?>
      &nbsp; 
      <SPAN style="background-color:white; border:2PX SOLID blue; cursor:pointer;text-align:center;">
      <a  title="<?= $sh //$sh!='DHL' ? $sh : 'DHL'?>" href="../registro_manifiesto.php?contenedor=<?=$contenedor?>&bkg=<?=$bkg?>&esi=1&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>#ancla_esi"/>&nbsp;ESI <?= $sh //$sh=='DHL' ? 'DHL' : ''?>&nbsp;</a> </SPAN>
      <? } ?>
      
      <? }else{ ?> 
      <A style="text-decoration:underline; color:#039;text-align:center;cursor:POINTER" title="REVISION" href="../registro_manifiesto.php?contenedor=<?=$contenedor?>&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){ ?>
      &nbsp; 
      <SPAN style="background-color:white; border:2PX SOLID blue; cursor:pointer;text-align:center;">
      <a  title="<?=$sh //$sh!='DHL' ? $sh : 'DHL'?>" href="../registro_manifiesto.php?contenedor=<?=$contenedor?>&bkg=<?=$bkg?>&esi=1&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row1[id_bl]?>&id_bl=<?=$row1[id_bl]?>#ancla_esi"/>&nbsp;ESI <?=$sh //$sh=='DHL' ? 'DHL' : ''?>&nbsp;</a> </SPAN>
      <? } ?>
      <? } ?>
      
    </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="">
      <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];
				}
				
	?>
    <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"><div align="center">
      <?=$row1[weight]?>
    </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">**' : ''?>
      <?=$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="93" 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 ><div align="center">
      <?=$row1[revision]?>
    </div></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])?></td>
  </tr>

 
  <? } }
  
  $z=$k; ?> 
  
   
    <? 
 
	$qry3=mysqli_query($link_impo,"select files from datosexpint where referencia_interteam like '".trim($referencia_cliente)."%'");
	$r8=mysqli_fetch_array($qry3);
	$files=$r8["files"];
	$unicos=array_unique($array);
	$cantidad_bookings = count(array_unique($array));
	
 
	$qry3=mysqli_query($link_impo,"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)){
			 //echo $r8[booking_interteam].'  ---> r i '.$array1[$r8[booking_interteam]]. ' rc v '.$referencia_cliente.'<br>';
			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?contenedor=<?=$contenedor?>&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*1,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 %%%%%%%%%%%%%%%%%%%%%% 
	con_ver();
 
	unset($finales);unset($customsagent);
	$unicos=array_unique($array);
	$cantidad_bookings = count(array_unique($array));
 
	$qry3=mysqli_query($link,"SELECT * FROM booking_ssl where referencia_cliente like '".trim($referencia_cliente)."' order by booking_ssl");
	 
 		while($r8=mysqli_fetch_array($qry3)){
			if (! in_array($r8[booking_ssl], $unicos)) {
				$finales[]=$r8[booking_ssl];
				//$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?contenedor=<?=$contenedor?>&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*1,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>
    <input name="cantFilas" id="cantFilas" type="hidden" value="<?=$z-1?>" />
<div align="left"><span style="width:2000px">
  <input name="input" type="button" value="Guardar" 
    onclick="
    for(t=1;t<=document.getElementById('cantFilas').value;t++){
        realizaProceso(t,document.getElementById('cantFilas').value);
    } "/>
</span></div>
<br />

