<?

require_once("comun/funciones.php");

$link_impo=con_impo();

$files = busquedaB($link_impo,"select files from datosexpint where referencia_interteam = '".$referencia_cliente."'","files");

$query=mysqli_query($link_impo,"select * from bookingexpint where `booking` <> '' and files like '".$files."%' ORDER BY booking_interteam");

if(mysqli_num_rows($query)==0 or trim($referencia)=='' or trim($referencia_cliente)=='') return;
 

?>
<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="1334" id="exportar" border="1" class="tablas_con_bordes_" style="font-size:11px" >

  
  <tr class="yellow" style="text-align:center">
    <TD width="42" style="border:none; background-color:transparent"></TD>
    <td width="22" style="border:none; background-color:transparent"> </td>
    <td width="40" style="border:none; background-color:transparent"></td>
    <td width="38" style="border:none; background-color:transparent"></td>
    <td width="278"  >Marcas</td>
    <td width="83"  >Gross weight</td>
    <td width="132" >Pedimento entregado</td>
    <td width="131" >Status</td>
    <td width="106" >Revisi&oacute;n</td>
    <td width="132" >Fecha Revisi&oacute;n</td>
    <td width="101" >Registro</td>
    <td width="177" >Comentarios</td>
  </tr>
  

   <? while($row=mysqli_fetch_array($query)){ ?>
     <tr class="yellow">
  	 <TD colspan="12" align="left" style="text-align:left"><?=$row[booking_interteam]?><br /> CLIENTE: <?=$row[customer]?>&nbsp;&nbsp;&nbsp; AA: <?=$row[customsagent]?>&nbsp;&nbsp;&nbsp; CONTACTO: <?=$row[customscontact]?>&nbsp;&nbsp;&nbsp; 
     EMAIL: <?=$row[customsemail]?> </td>
     </tr>
  
   <? 
   // cantidad de partidas por booking
   //$cant = busquedaB("select count(bookingno) as cant from detailcargaexpint where bookingno = '".$row[booking]."'","cant");
   //echo 'cantidad '.$cant;
  
   $query1= mysqli_query($link_impo,"select * from detailcargaexpint where bookingno = '".$row[booking]."'");
   
   $link_ver=con_ver();
   $query2= mysqli_query($link_ver,"select * from detailcargaexpint where bookingno = '".$row[booking_interteam]."'");
   ?>
   
   <? 
   $k = 1;
   while($row1=mysqli_fetch_array($query1)){
   ?>	   
   <tr class="comun" style="text-align:center">
    <TD align="center"><?=$k?><? $k++;?></TD>
    <TD align="center">HB dL</TD>
    <TD align="center">
    <img title="Modificar BL" src="https://<?=$_SERVER["SERVER_NAME"]?>/js/img/cambio.png" border="0" style="cursor:pointer" 
    onclick='dhtmlwindow.open("mblBox","iframe","../registro_manifiesto.php?files=<?=$files?>&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row2[id]?>&id_bl=<?=$row2[id_bl]?>&booking_interteam=<?=$row2[bookingno]?>", "Modificar BL", 
"width=950px,height=1000px,resize=1,scrolling=1,center=0", "recal");'/>
    </TD>
    <td></td>
    <td align="center" ><?=$row1[markandnos]?></td>
    <td align="center"><?=$row1[weight]?></td>
    <td ></td>
    <td ></td>
    <td ></td>
    <td ></td>
 	<td align="center">INTERTEAM</td>
    <td ></td>
  </tr>

  <? 
   
   } ?> 
   
    <? 
   
   while($row2=mysqli_fetch_array($query2)){
	   
	if($row2[tipo_bl]=='MBL'){
		$bl = data($link_ver,"select * from hblexpint where tipo='MBL' and booking = '".$row2[bookingno]."' and referencia = '".$referencia_cliente."'");
	}else{
		$bl = data($link_ver,"select * from hblexpint where idhbl = '".$row2[id_bl]."'");
	}
   ?>	   
   <tr class="comun" <?= $row2[tipo_bl]=='MBL' ? 'style="color:#F30"':''?> style="text-align:center">
     <TD align="center"><?=$k?><? $k++;?></TD>
     <TD align="center"><?=$row2[tipo_bl]?></TD>
  
    <TD align="center">
    <img title="Modificar BL" src="https://<?=$_SERVER["SERVER_NAME"]?>/js/img/cambio.png" border="0" style="cursor:pointer" 
    onclick='dhtmlwindow.open("mblBox","iframe","../registro_manifiesto.php?files=<?=$files?>&referencia=<?=$referencia?>&referencia_cliente=<?=$referencia_cliente?>&id=<?=$row2[id]?>&id_bl=<?=$row2[id_bl]?>&booking_interteam=<?=$row2[bookingno]?>", "Registrar BL", 
"width=950px,height=1000px,resize=1,scrolling=1,center=0", "recal");'/>
    </TD>
    <td><img title="Borrar BL" onclick="
    <? if($row2[tipo_bl]=='HBL') { ?>
    if(confirm('Borra este House BL?')){ 
    borrar_hbl('<?=$row2[id]?>','<?=$row2[bookingno]?>','<?=$row2[id_bl]?>');
    }
    <? } elseif($row2[tipo_bl]=='MBL') { ?>
    if(confirm('Borra este Master BL?')){ 
     borrar_mbl('<?=$row2[id]?>','<?=$row2[bookingno]?>','<?=$row2[id_bl]?>');
    }
    <? } ?>" src="https://<?=$_SERVER["SERVER_NAME"]?>/js/img/eliminar.png" border="0" style="cursor:pointer" /> 
</td>
 
 
    <td align="center"><?=$row2[markandnos]?></td>
    <td align="center"><?=$row2[weight]?></td>
    <td align="center"><?=$bl[pedimento_no]?></td>
    <td align="center"><?=$bl[status]?></td>
    <td align="center"><?=$bl[revision]?></td>
    <td align="center"><?=$bl[fecha_revision]?></td>
 	<td align="center">AA ALTAMIRA</td>
    <td align="center" ><?=$bl[comentarios]?></td>
  </tr>

  <? 
   
   } ?>  

  <? } ?>  
  </table>
<br />