<? 
 
$booking = str_replace('\"','"',$booking);
$booking = str_replace("\'","'",$booking);
$txtbooking=$booking;
 

$referencia = $_GET[referencia]; 
$referencia = str_replace("\'","'",$referencia);
$referencia_cliente = $_GET[referencia_cliente]; 
$referencia_cliente = str_replace("\'","'",$referencia_cliente);

include("../comun/conexion3.php");
include("../comun/conex_ver.php");
include("../comun/funciones.php");
$link_impo=con_impo();$link=con_ver();

$tmp= explode('/', dirname(__FILE__)) ; 
$directorio_principal= $tmp[4];	
include("constantes.php"); 


global $tbulk,$tweight,$tnetweight;
global $tipos_de_imo;
global $buque,$viaje,$ets,$cliente,$booking_naviera,$pod,$naviera,$almacen,$procedencia_vacio,$almacen_consolidacion,$desde,$hacia,$tipo_mercancia,$pedimento,$linea,$contenedor,$dimension,$sello,$tipo,$tara,$destino_final,$comentarios;
 
$idhbl = $_GET[idhbl];
$datos_shipping = data($link,"select * from hblexpint where idhbl like '$idhbl%'");

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

if(trim($referencia)==''){
 
$referencia = busquedaB($link,"select referencia_lpv from datosbooking where referencia_cliente = '".trim($referencia_cliente)."'","referencia_lpv");

}
 
if($referencia_cliente!=''){
	DATOSBOOKING($link,$link_impo,$referencia_cliente);
 
 	$freightcode="FREIGHT PREPAID";
 	$Tbulk=0;
	$Tnetweight=0;
	$Tcu=0;

$queryDetalle=mysqli_query($link,"select * from detallebooking where `referencia_cliente` = '".$referencia_cliente."' ORDER BY id");
//echo "select * from detallebooking where `referencia_cliente` = '".$referencia_cliente."' ORDER BY id";
while($rQD=mysqli_fetch_array($queryDetalle)){
	$imo.=($rQD[imo]!='' ? ', '.$rQD[imo] : '');
	$un.= ($rQD[un]!='' ? ', '.$rQD[un] : '');
	$packing_group.=($rQD[packing_group]!='' ? ', '.$rQD[packing_group] : '');
}
$imo = substr($imo,2,strlen($imo));
$un = substr($un,2,strlen($un));
$packing_group = substr($packing_group,2,strlen($packing_group));
}
 
$datos_shipping2 = data($link,"select * from mbl_naviera where referencia_cliente like '$referencia_cliente%'");
//VER4813-CTG
//echo 're cliente '.$referencia_cliente.' referencia '.$referencia; 
//echo $datos_shipping2[1];
//echo $datos_shipping2[shipper];
$suma_pza_mbl = "";
$suma_peso_mbl = "";
$suma_pza_mblt = "";
$suma_peso_mblt = "";
?>
<page backtop="5mm" backbottom="10mm" backleft="10mm" backright="10mm">
    <page_header>
<table style="width: 100%;">
            <tr>
                <td style="text-align: left;    width: 15%">&nbsp;</td>
                <td style="text-align: center;    width: 75%"><span style="text-align:center;font-size: 14px; font-weight: bold">
                RECIBASE MASTER&nbsp;<?=$referencia_cliente?>&nbsp;
                 <span style="text-align:center;font-weight: bold;font-size: 14px;">
                <?=$cliente?> / <?=$pod?>
                </span></span>
                <br />
               
</td>
                <td style="text-align: right;    width: 15%">&nbsp;</td>
            </tr>
             
      </table>
    </page_header>
    
    <page_footer>
<table style="width: 100%; border: solid 1px black;">
            <tr>
        <td align="left" style="text-align: left;    width: 50%"></td>
                <td style="text-align: left;    width: 50%"></td>
                <td style="text-align: right;    width: 50%">PAGE [[page_cu]]/[[page_nb]]</td>
            </tr>
      </table>
    </page_footer>
<BR />
 <div align="center">
      <span style="text-align: left;"><img src="<?="https://".$_SERVER["SERVER_NAME"]?>/<?=$directorio_principal?>/images/logo_lpv.jpg" />
      </span> 
 </div>

 <table style="width: 100%;border: solid 1px #5544DD;border-collapse:collapse;" align="left" >
   <tr>
     <td  style="text-align: left; border: solid 1px #55DD44;"><? ?><div style="width:370px"> <b>SHIPPER</b><br />
       <? echo $datos_shipping2[shipper].'<br>'.$datos_shipping2["shipper2"].'<br>'.$datos_shipping2["shipper3"].'<br>'.$datos_shipping2["shipper4"].'<br>'.$datos_shipping2["shipper5"].'<br>'.$datos_shipping2["shipper6"];
	 ?> </div></td>
     <td   style="text-align: left; border: solid 1px #55DD44;"><div style="width:350px"> <b>BOOKING:</b>&nbsp;
       <?=$booking_naviera?>
       <br />
       <br />
       <b>EXPORT REFERENCE:</b> <?=$referencia?><br />
     </div></td>
   </tr>
   <tr>
     <td  style="text-align: left; border: solid 1px #55DD44;"><div style="width:370px"> <b>CONSIGNEE</b><br />
       <? echo $datos_shipping2["consignee"].'<br>'.$datos_shipping2["consignee2"].'<br>'.$datos_shipping2["consignee3"].'<br>'.$datos_shipping2["consignee4"].'<br>'.$datos_shipping2["consignee5"].'<br>'.$datos_shipping2["consignee6"];
	 ?> </div></td>
     <td  style="text-align: left; border: solid 1px #55DD44;"><?
		 
	 
		$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 C.email_contacto LIKE '%".$datos_shipping2["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];
		?>
           <div style="width:350px"><b>FORWARDING AGENT:</b><br />
          <br />
          <?=$DIRECCION4[$directorio_principal]?><br />
          <b>AT'N:</b> <?=$nombre_contacto?> TEL: <?=$telefono_contacto?>
          </div>
      </td>
   </tr>
   <tr>
     <td  style="text-align: left; border: solid 1px #55DD44;"><div style="width:370px"> <b>NOTIFY</b><br />
       <? echo ''.$datos_shipping2["notify"].'<br>'.$datos_shipping2["notify2"].'<br>'.$datos_shipping2["notify3"].'<br>'.$datos_shipping2["notify4"].'<br>'.$datos_shipping2["notify5"].'<br>'.$datos_shipping2["notify6"];
	 ?> </div></td>
     <td valign="top"  style="text-align: left; border: solid 1px #55DD44;"><div  style="vertical-align:top;width:350px"><b>COMENTARIOS</b><BR />
     <?=$comentarios?>
     </div></td>
   </tr>
   <tr>
     <td  style="text-align: left; border: solid 1px #55DD44;"><div style="width:370px"> <b>PORT OF LOADING</b><br />
       <? echo strtoupper($CIUDAD[$directorio_principal])?> ?><br />
       <br />
       <b>PORT OF DISCHARGE</b><br />
       <? echo $pod;?> </div></td>
     <td  style="text-align: left; border: solid 1px #55DD44;"><table>
       <tr>
         <td><div style="width:150px"> <b>OCEAN VESSEL</b><br />
           <? echo $buque;
                     ?><br />
           <br />
           <b>FINAL DESTINATION</b><br />
           <? echo $destino_final;
                     ?> </div></td>
         <td valign="top"><div style="width:100px"> <b>VOYAGE</b><br />
           <? echo $viaje;
                     ?> </div></td>
       </tr>
     </table></td>
   </tr>
 </table>
 <br />
 <table style="width: 100%;border: solid 1px #5544DD;border-collapse:collapse;" align="left" >
     
    <tr>
        <td  style="text-align: left; border: solid 1px #55DD44;">
        <div style="width:370px">
                <!--<b>BUQUE:</b> <? //echo $buque; ?> <br />
                
                <b>SSL BOOKING:</b> <? //=$booking_naviera?><br />
                
                <b>PUERTO:</b>       <? //echo $pod;?> <br />
                <b>ETS:</b> 
                <? //echo $ets;?>-->
                <b>TARA:</b> <? echo $tara; ?> <br />
                <? if(trim($imo)!=''){ ?>
                <b>IMO:</b> <? echo $imo; ?> <br />
                <? } ?>
                <? if(trim($un)!=''){ ?>
                <b>UN:</b> <? echo $un; ?> <br />
                <? } ?>
                <? if(trim($packing_group)!=''){ ?>
                <b>PACKING GROUP:</b> <? echo $packing_group; ?> <br />
                <? } ?>
        </div> 
      </td>
        
        <td   style="text-align: left; border: solid 1px #55DD44;">
          <div style="width:350px">
          			 <b>CONTENEDOR:</b> &nbsp;
                            <?=$contenedor?>
                            <br />
                            <b>SELLO: </b> &nbsp;
                            <?=$sello?>
                            <br />
                            <b>TAMA&Ntilde;O / TIPO:</b> <?=$dimension?>&nbsp;<?=$tipo?>
                            <!--<br /><b>REFERENCIA: </b> &nbsp;<? //=$referencia?> -->
              
                   
          </div>
        </td>
    </tr>
     
     
  </table>
    

    
<?
$x=0;$z=0;
con_ver();
$bls = mysqli_query($link,"select distinct booking from hblexpint where referencia = '$referencia_cliente' and status = 'OK' order by booking");
//echo "select distinct booking from hblexpint where referencia = '$referencia_cliente' and status = 'OK' order by booking";
//echo mysqli_num_rows($bls);
while($rbl = mysqli_fetch_array($bls) and mysqli_num_rows($bls)>0){
		$booking = $rbl[0];
		
		$datos = mysqli_query($link,"select * from detailcargaexpint where bookingno = '$booking' and cargo <> '' and id_bl in (select idhbl from hblexpint where status = 'OK' and booking =  '$booking') order by bookingno"); 


if(mysqli_num_rows($datos)>0){
	
 $HBL=data($link,"select * from hblexpint where booking like '$booking%' and status = 'OK'"); //idhbl = '".$id_bl."' and tipo = 'MBL'	

$kilos = mysqli_query($link,"select * from detailcargaexpint where bookingno = '$booking' and cargo <> '' and id_bl in (select idhbl from hblexpint where status = 'OK' and booking =  '$booking') order by bookingno"); 
$rk = mysqli_fetch_array($kilos);

?><br />


<!----------------------------------------- un solo bl registrado ------------------------------------>
<? if(mysqli_num_rows($datos)==1){ ?>

<?
while($rbooking=mysqli_fetch_array($datos) and mysqli_num_rows($datos)>0){
	$x++;$z++;
	$id_bl = $rbooking[id_bl];
	
	// kilos de este bl 22.4
	$kilos1 = mysqli_query($link,"select * from detailcargaexpint where  id_bl ='".$id_bl."' "); 
	$rk1 = mysqli_fetch_array($kilos1);

	$HBL=data($link,"select * from hblexpint where booking like '$booking%' and idhbl = '".$id_bl."' and status = 'OK' ");
	$consignee = $HBL[consignee];
	$shipper = $HBL[shipper];
	$tarja = $HBL[tarja];
	?>
    <table style="width: 100%; border: solid 1px #5544DD;border-collapse:collapse; font-size:10px; font-family:Arial, Helvetica, sans-serif" align="left" >
  <tr>
  <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:25px; max-width:25px"><B>NO</B></div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:270px; max-width:270px"><B>MARCAS Y NUMEROS</B></div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:325px; max-width:325px"><B>CONTENIDO (DICE CONTENER)</B></div> </td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:47px; max-width:47px"><B>PESO</B> </div></td>
    <td style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:45px; max-width:45px"><B>CBM</B> </div></td>
    <? 
	$Tbulk+=$rk[bulk];
	$Tnetweight+=$rk[weight];
	$suma_pza_mbl  = doubleval($rk[bulk])+doubleval($rk[no_piezasimoh]);
	$suma_peso_mbl = doubleval($rk[weight])+doubleval($rk[gross_weightimoh]);
	$suma_pza_mblt+= doubleval($rk[bulk])+doubleval($rk[no_piezasimoh]);
	$suma_peso_mblt+= doubleval($rk[weight])+doubleval($rk[gross_weightimoh]);

	?>
  </tr>
  
  <tr>
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:25px; max-width:25px">
      <?=$z?>
    </div></td>
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:270px; max-width:270px"><?=$rbooking[markandnos]?><br /> </div></td>
    
    <td style="text-align: left; border: solid 1px #55DD44;">
      <div style="width:325px; max-width:325px">
        <span style="width:89px; max-width:89px">
        <?=$suma_pza_mbl.' '.$rbooking[type_of_bulks]?>
        </span>
        <?='WITH '.$rbooking[number_of_pieces].' OF '.$rbooking[cargo].' // H.S. '.$rbooking[harmonized_code]?>
        </div> 
    </td>
    
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:47px; max-width:47px"><?=($suma_peso_mbl!='' ?  number_format($suma_peso_mbl,2):'')?></div></td>
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:45px;max-width:45px">
  <? 
            $tt=0;
            $dimen = mysqli_query($link,"select * from dimensiones where id_partida =  '".$id_bl."'");
            while($rd=mysqli_fetch_array($dimen)){
                    $tt +=$rd[largo]*$rd[ancho]*$rd[alto]*$rd[numero_bultos]/1000000;
                    $Tcu+=$rd[largo]*$rd[ancho]*$rd[alto]*$rd[numero_bultos]/1000000;
            } 
            ?>
              <?=($tt!='' ? number_format($tt,3) :'')?>
    </div></td>
    </tr>
  <tr>
    <td colspan="5" style="text-align: left; border: solid 1px #55DD44;">SCAC CODE:&nbsp;	
	<?
	if(trim($rbooking[ams])==''){
		con_impo();
		$sc=data($link_impo,"select scac from bookingexpint where booking_interteam like '$booking%'");
		$scac=$sc[scac];
		con_ver();
	}else{
		$scac=$rbooking[ams];
	}
	?>
	<?=$scac?></td>
    </tr>
  <? } ?>
  
  
  
  </table>
  

<? } ?>


<!---------------------------------------- 1 mbl y un hbl ------------------------------------------------>

<? if(mysqli_num_rows($datos)==2){ ?>
<? $datos1 = mysqli_query($link,"select * from detailcargaexpint where bookingno = '$booking' and cargo <> '' and tipo_bl = 'HBL' and id_bl in (select idhbl from hblexpint where status = 'OK' and booking =  '$booking') order by bookingno"); ?>
<?
while($rbooking=mysqli_fetch_array($datos1) and mysqli_num_rows($datos1)>0){
	$x++;$z++;
	$id_bl = $rbooking[id_bl];
	// kilos de este bl 22.4
	$kilos1 = mysqli_query($link,"select * from detailcargaexpint where  id_bl ='".$id_bl."' "); 
	$rk1 = mysqli_fetch_array($kilos1);
	
	$HBL=data($link,"select * from hblexpint where booking like '$booking%' and idhbl = '".$id_bl."' and tipo = 'HBL' and status = 'OK' ");
	$consignee = $HBL[consignee];
	$shipper = $HBL[shipper];
	$tarja = $HBL[tarja];
	

	?>
    <table style="width: 100%; border: solid 1px #5544DD;border-collapse:collapse; font-size:10px; font-family:Arial, Helvetica, sans-serif" align="left" >
  <tr>
  <td  style="text-align: left; border: solid 1px #55DD44; background:#FF6"><div style="width:25px; max-width:25px"><B>NO</B></div></td>
  <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:270px; max-width:270px"><B>MARCAS Y NUMEROS</B></div></td>
        
     <td   style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:325px; max-width:325px"><B>CONTENIDO (DICE CONTENER)</B></div> </td>

    <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:47px; max-width:47px"><B>PESO</B> </div></td>
    <? $cu = $rbooking[largo]*$rbooking[ancho]*$rbooking[alto]*$rbooking[bulk]/1000000;?>
     
    <td style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:45px; max-width:45px"><B>CBM</B> </div></td>
    <? 
	$Tbulk+=$rbooking[bulk];
	$Tnetweight+=$rbooking[weight];
	//$Tcu+= $cu;
	$suma_pza_mbl  = doubleval($rbooking[bulk])+doubleval($rbooking[no_piezasimoh]);
	$suma_peso_mbl = doubleval($rbooking[weight])+doubleval($rbooking[gross_weightimoh]);
	$suma_pza_mblt+= doubleval($rbooking[bulk])+doubleval($rbooking[no_piezasimoh]);
	$suma_peso_mblt+= doubleval($rbooking[weight])+doubleval($rbooking[gross_weightimoh]);
	?>
    
  </tr>
  
  <tr>
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:25px; max-width:25px"><?=$z?></div></td>
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:270px; max-width:270px"><?=$rbooking[markandnos]?><br /> </div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;"><div style="width:325px; max-width:325px">
      <span style="width:89px; max-width:89px">
      <?=($suma_pza_mbl!='' ? $suma_pza_mbl : $suma_pza_mbl).' '.($rk1[type_of_bulks]!='' ? $rk1[type_of_bulks] : $rk[type_of_bulks])?>
      </span>
      <?='WITH '.$rbooking[number_of_pieces].' OF '.$rbooking[cargo].' // H.S. '.$rbooking[harmonized_code]?>
    </div> </td>
    
    <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:47px; max-width:47px"><?=($suma_peso_mbl!='' ? number_format($suma_peso_mbl,2) : '')?></div></td>
            <td style="text-align: left; border: solid 1px #55DD44;"><div style="width:45px;max-width:45px">
            <? 
            $tt=0;
            $dimen = mysqli_query($link,"select * from dimensiones where id_partida =  '".$id_bl."'");
            while($rd=mysqli_fetch_array($dimen)){
                    $tt +=$rd[largo]*$rd[ancho]*$rd[alto]*$rd[numero_bultos]/1000000;
                    $Tcu+=$rd[largo]*$rd[ancho]*$rd[alto]*$rd[numero_bultos]/1000000;
            } 
            ?>
              <?=($tt!='' ? number_format($tt,3) : ($rk1[measurement]*1!='' ? number_format($rk1[measurement]*1,3) : ''))?>
            </div></td>
      </tr>
  <tr>
    <td colspan="5" style="text-align: left; border: solid 1px #55DD44;">SCAC CODE:&nbsp;
	<?
	if(trim($rbooking[ams])==''){
		con_impo();
		$sc=data($link_impo,"select scac from bookingexpint where booking_interteam like '$booking%'");
		$scac=$sc[scac];
		con_ver();
	}else{
		$scac=$rbooking[ams];
	}
	?>
	<?=$scac?>
    
    </td>
    </tr>

  
 
  
  </table>
 <? } ?>

<? } ?>

<!------------------------------------------ 1 MBL Y VARIOS HBLS ----------------------------------------------------->

<? if(mysqli_num_rows($datos)>2){ ?>
<? 
$datos2 = mysqli_query($link,"SELECT *
FROM hblexpint
WHERE booking LIKE '$booking%' AND tipo='HBL' and status = 'OK'
GROUP BY shipper, shipper2, shipper3, shipper4, shipper5, shipper6, consignee, consignee2, consignee3, consignee4, consignee5, consignee6, notify, notify2, notify3, notify4, notify5, notify6"); 

?>
<?
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// cada grupo que ha sido agrupado segun distinto sh cn y n1
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

while($rs=mysqli_fetch_array($datos2) and mysqli_num_rows($datos2)>0){
	$x++;
	$datos3 = mysqli_query($link,"SELECT *
	FROM hblexpint
	WHERE booking LIKE '$booking%' AND tipo='HBL' and shipper='".ret($rs[shipper])."' and shipper2='".ret($rs[shipper2])."' and shipper3='".ret($rs[shipper3])."' 
	and shipper4='".ret($rs[shipper4])."' and shipper5='".ret($rs[shipper5])."' and shipper6='".ret($rs[shipper6])."' and consignee='".ret($rs[consignee])."' 
	and consignee2='".ret($rs[consignee2])."' and consignee3='".ret($rs[consignee3])."' and consignee4='".ret($rs[consignee4])."' 
	and consignee5='".ret($rs[consignee5])."' and consignee6='".ret($rs[consignee6])."' and notify='".ret($rs[notify])."' and notify2='".ret($rs[notify2])."' 
	and notify3='".ret($rs[notify3])."' and notify4='".ret($rs[notify4])."' and notify5='".ret($rs[notify5])."' and notify6='".ret($rs[notify6])."' and status = 'OK'");
 
	?>
    
  <?
	//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	// todos los hbls de este grupo
	//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	$j=1;
	while($rx=mysqli_fetch_array($datos3) and mysqli_num_rows($datos3)>0){
		$x++;
		$z++;
				$id_bl = $rx[idhbl]; 
				$consignee = $rx[consignee];
				$shipper = $rx[shipper];
				$tarja = $rx[tarja];
				
				$datos4 = mysqli_query($link,"SELECT * FROM detailcargaexpint WHERE id_bl ='".$id_bl."'");
				$rbooking = mysqli_fetch_array($datos4);
				
			     $cu = $rbooking[largo]*$rbooking[ancho]*$rbooking[alto]*$rbooking[bulk]/1000000;?>
  <table style="width: 100%; border: solid 1px #5544DD;border-collapse:collapse; font-size:10px; font-family:Arial, Helvetica, sans-serif" align="left" >
  <tr>
  <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:25px; max-width:25px"><B>NO</B></div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:270px; max-width:270px"><B>MARCAS Y NUMEROS</B> </div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:325px; max-width:325px"><B>CONTENIDO (DICE CONTENER)</B></div> </td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:47px; max-width:47px"><B>PESO</B> </div></td>
    <td style="text-align: left; border: solid 1px #55DD44;background:#FF6"><div style="width:45px; max-width:45px"><B>CBM</B> </div></td>
    <? 
	$Tbulk+=$rbooking[bulk];
	$Tnetweight+=$rbooking[weight];
	//$Tcu+= $cu;
	$suma_pza_mbl  = doubleval($rbooking[bulk])+doubleval($rbooking[no_piezasimoh]);
	$suma_peso_mbl = doubleval($rbooking[weight])+doubleval($rbooking[gross_weightimoh]);
	$suma_pza_mblt+= doubleval($rbooking[bulk])+doubleval($rbooking[no_piezasimoh]);
	$suma_peso_mblt+= doubleval($rbooking[weight])+doubleval($rbooking[gross_weightimoh]);
	?>
    
  </tr>
  
     
			  <tr>
				<td style="text-align: left; border: solid 1px #55DD44;"><div style="width:25px; max-width:25px"><?=$z?> </div></td>
				<td style="text-align: left; border: solid 1px #55DD44;"><div style="width:270px; max-width:270px">
				<?=$rbooking[markandnos]?><br /> </div></td>
				<td style="text-align: left; border: solid 1px #55DD44;"><div style="width:325px; max-width:325px">
				<?=$suma_pza_mbl.' '.$rbooking[type_of_bulks]?>&nbsp;<?='WITH '.$rbooking[number_of_pieces].' OF '.$rbooking[cargo].' // H.S. '.$rbooking[harmonized_code]?>
				<span style="width:89px; max-width:89px">
				
				</span></div> </td>
				<td style="text-align: left; border: solid 1px #55DD44;"><div style="width:47px; max-width:47px"><?=$suma_peso_mbl!='' ? number_format($suma_peso_mbl,2):''?></div></td>
				<td style="text-align: left; border: solid 1px #55DD44;"><div style="width:45px;max-width:45px">
                   <? 
	$tt=0;
	$dimen = mysqli_query($link,"select * from dimensiones where id_partida =  '".$id_bl."'");
	while($rd=mysqli_fetch_array($dimen)){
			$tt +=$rd[largo]*$rd[ancho]*$rd[alto]*$rd[numero_bultos]/1000000;
			$Tcu+=$rd[largo]*$rd[ancho]*$rd[alto]*$rd[numero_bultos]/1000000;
	} 
	?>
      <?=($tt!='' ? number_format($tt,3) :'')?>
                </div></td>
			  </tr>
			  <tr>
			    <td colspan="5" style="text-align: left; border: solid 1px #55DD44;">SCAC CODE:&nbsp;
					<?
					if(trim($rbooking[ams])==''){
						con_impo();
						$sc=data($link_impo,"select scac from bookingexpint where booking_interteam like '$booking%'");
						$scac=$sc[scac];
						con_ver();
					}else{
						$scac=$rbooking[ams];
					}
					?>
					<?=$scac?>
				</td>
    </tr> 
              
              
              
              
             </table>  
    <? $j++; }
	//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	// fin de todos los hbls de este grupo
	//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	?>
  
 
 
    		
  
  <? } ?>
  

  <?  
  }
  ?>

<? 

} ?>
<?  
}
?>
<BR /> 
  <table style="width: 100%; border-collapse:collapse; font-size:10px; font-family:Arial, Helvetica, sans-serif" align="left" >
  <tr>
  <td  style="text-align: left; "><div style="width:25px; max-width:25px"><B></B></div></td>
    <td  style="text-align: left;"><div style="width:130px; max-width:130px"><B></B></div></td>
    <td   style="text-align: left;"><div style="width:220px; max-width:220px"><B></B></div> </td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#C1C1FF"><div style="width:53px; max-width:55px"><B>BULTOS TOTALES</B> </div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#C1C1FF"><div style="width:99px; max-width:99px"><?=$suma_pza_mblt?></div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#C1C1FF"><div style="width:35px; max-width:35px"><B>TOTAL PESO</B> </div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#C1C1FF"><div style="width:57px; max-width:57px"><?=($suma_peso_mblt!='' ? number_format($suma_peso_mblt,2):'')?></div></td>
    
    
     
    <td bgcolor="#C1C1FF"  style="text-align: left; border: solid 1px #55DD44;"><div style="width:30px; max-width:30px"><B>TOTAL CBM</B> </div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#C1C1FF"><div style="width:53px; max-width:53px"><?=($Tcu!='' ? number_format($Tcu,3):'')?></div></td>
  </tr>
  </table>
<BR />
<DIV align="center">
FREIGHT PREPAID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLEAN ON BOARD
</DIV>
</page>
 