<? 
 
$booking = str_replace('\"','"',base64_decode($booking));
$booking = str_replace("\'","'",$booking);
$txtbooking=$booking;
$idhbl = base64_decode($_GET[idhbl]);  

include("../comun/conexion3.php");
include("../comun/conex_ver.php");
include("../comun/funciones.php");
$link_impo=con_impo();$link=con_ver();
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;
 
$referencia_cliente = busquedaB($link,"select referencia from hblexpint where booking = '".$txtbooking."' and idhbl = '$idhbl' ","referencia");
if($referencia_cliente!=''){
		DATOSBOOKING($link,$link_impo,$referencia_cliente);
 
		fpeso_bruto($link,$link_impo,'',0,$referencia_cliente);
 
		$peso_neto_con_tara=$tara+$tweight;
}
$ref = busquedaB($link,"select referencia_lpv from datosbooking where referencia_cliente = '".$referencia_cliente."' ","referencia_lpv");
$datos_shipping = data($link,"select * from hblexpint where idhbl like '$idhbl%'");
//echo "select * from hblexpint where idhbl like '$idhbl%'";
//2316 HBL
//2334
?>
<page backtop="5mm" backbottom="10mm" backleft="10mm" backright="10mm">
    <page_header>
<table style="width: 100%; ">
            <tr>
                <td style="text-align: left;    width: 5%"><img  width="150" height="76.5"  src="<?="https://".$_SERVER["SERVER_NAME"]?>/images/logolpa_revalidacion.jpg" /></td>
                <td style="text-align: center;    width: 70%"><span style="text-align:center;font-size: 20px; font-weight: bold">RECIBASE HOUSE</span>
                
</td>
                <td style="text-align: center;    width: 15%"><?php echo date('m/d/Y'); ?></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: left;    width: 50%">PAGE [[page_cu]]/[[page_nb]]</td>
            </tr>
      </table>
    </page_footer>
 <br /> <br />  <br /><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>SHIPPER</B><br />
            <? echo $datos_shipping["shipper"].'<br>'.$datos_shipping["shipper2"].'<br>'.$datos_shipping["shipper3"].'<br>'.$datos_shipping["shipper4"].'<br>'.$datos_shipping["shipper5"].'<br>'.($datos_shipping["shipper6"]=='0' ? '' : $datos_shipping["shipper6"]).'<br>'.$datos_shipping["PhoneSH"].'<br>'.$datos_shipping["FaxSH"].'<br>'.$datos_shipping["EmailSH"];
	 ?>
       
          </div>
        </td>
        <td   style="text-align: left; border: solid 1px #55DD44;">
          <div style="width:350px">
            <b>BOOKING:</b>&nbsp;<?=$txtbooking?><BR /><BR />
            <b>EXPORT REFERENCE:</b>&nbsp;<?=$datos_shipping[export_reference]?><BR />
          </div>
        </td>
    </tr>
    
      <tr>
        <td  style="text-align: left; border: solid 1px #55DD44;">
          <div style="width:370px">
          <b>CONSIGNEE</b><br />
          <? echo $datos_shipping["consignee"].'<br>'.$datos_shipping["consignee2"].'<br>'.$datos_shipping["consignee3"].'<br>'.$datos_shipping["consignee4"].'<br>'.$datos_shipping["consignee5"].'<br>'.($datos_shipping["consignee6"]=='0' ? '' : $datos_shipping["consignee6"]).'<br>'.$datos_shipping["PhoneCN"].'<br>'.$datos_shipping["FaxCN"].'<br>'.$datos_shipping["EmailCN"];
	 ?>
     	  </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_shipping["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 />
          <?=$nombre_empresa?><br />
          AA <?=$agente_aduanal?><br />
          AT'N: <?=$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_shipping["notify"].'<br>'.$datos_shipping["notify2"].'<br>'.$datos_shipping["notify3"].'<br>'.$datos_shipping["notify4"].'<br>'.$datos_shipping["notify5"].'<br>'.($datos_shipping["notify6"]=='0' ? '' : $datos_shipping["notify6"]).'<br>'.$datos_shipping["PhoneN1"].'<br>'.$datos_shipping["FaxN1"].'<br>'.$datos_shipping["EmailN1"];
	 ?>
        </div>
        </td>
        <td  style="text-align: left; border: solid 1px #55DD44;">
        <div style="width:350px"></div>
        </td>
      </tr>
      <tr>
        <td  style="text-align: left; border: solid 1px #55DD44;">
        <div style="width:370px">
                <b>PORT OF LOADING</b><br />
                <? echo 'ALTAMIRA, TAMAULIPAS' ?><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 />

                        <?=($datos_shipping[finaldestination]=='' ? $destino_final : $datos_shipping[finaldestination])?> <? //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>
    

    
 


<table style="width: 100%; border: solid 1px #5544DD;border-collapse:collapse; font-size:10px" align="left" ><!---714-->
   <tr>
    <td  colspan="7" style="text-align: left; border: solid 1px #55DD44;">
 
    <B>CONTENEDOR:</B>&nbsp;<span style="width:716px">
    <?=$contenedor?>
    </span><br />
    <b>SELLO:</B>&nbsp;<span style="width:714px">
    <?=$sello?>
    </span><br />
    <b>TARA:</b> <span style="width:714px">
    <?= $tara!='' ? number_format($tara,2) : '';?>
    </span><br />
    <b>PESO CON TARA:
    </B> 
    <span style="width:714px">
    <?= $peso_neto_con_tara!='' ? number_format($peso_neto_con_tara,2) : '';?>
    </span></td>
  </tr>

<?   
$datos = mysqli_query($link,"select * from detailcargaexpint where id_bl like '$idhbl'");
?>
  
   <tr>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:101px;max-width:101px"><B>MARKS AND NOS</B></div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:103px;max-width:103px"><b>QUANTITY OF BULKS</b></div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:101px;max-width:101px"><b>NUMBER OF PIECES</b></div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:180px; max-width:180px"><B>DESCRIPTION</B></div> </td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:70px"><B>NET WEIGHT KGS</B> </div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:70px"><b>GROSS WEIGHT KGS</b></div></td>
    <td  style="text-align: left; border: solid 1px #55DD44;background:#CCFFCC"><div style="width:80px"><B>MEASUREMENT CBM</B> </div></td>
  </tr>

<? 
$tw=0;$tm=0;$tb=0;$ntm=0;
while($r=mysqli_fetch_array($datos)){
	$HARMONIZED_CODE=$r[harmonized_code];
	?>
  <tr>
    <td  style="text-align: left; border: solid 1px #55DD44;"><div style="width:100px;max-width:100px"><?=$r[markandnos]?></div><br /></td>
    <td   style="text-align: left; border: solid 1px #55DD44;"><div style="width:103px;max-width:103px"><?=$r[bulk].' '.$r[type_of_bulks]?></div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;"><div style="width:101px;max-width:101px"><?=$r[number_of_pieces]?></div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;"><div style="width:180px; max-width:180px; font-size:9px"><?=$r[cargo]?></div></td>
    <td  style="text-align:right; border: solid 1px #55DD44;"><?= ($r[netweight]!='' ? number_format($r[netweight],2) :'')?></td>
    <td   style="text-align:right; border: solid 1px #55DD44;"><?=($r[weight]!='' ? number_format($r[weight],2) :'') ?></td>
<?
  $dimensiones = mysqli_query($link,"select DISTINCT id_partida,numero_bultos,largo,ancho,alto,hora_registro_ingreso,fecha_recepcion from dimensiones where id_partida = '".$idhbl."' ");
 
  $total=0;
  //echo "total 1 : ".$total;
  while($rd=mysqli_fetch_array($dimensiones)){
		$hora_registro_ingreso=$rd[hora_registro_ingreso];
		$fecha_recepcion=$rd[fecha_recepcion];
		$numero_bultos[]=$rd[numero_bultos];
		$largo[]=$rd[largo];
		$ancho[]=$rd[ancho];
		$alto[]=$rd[alto];
		$volumen[]=number_format(($rd[largo]/100) * ($rd[alto]/100) * ($rd[ancho]/100) * $rd[numero_bultos],3);
		$total+=($rd[largo]/100) * ($rd[alto]/100) * ($rd[ancho]/100) * $rd[numero_bultos];
		//echo "total 2 : ".$total;
  }
  if($total > 0){
	  $ntm = number_format($total,2);
  }else{
	  if($r[measurement]!=''){
	      $ntm = number_format($r[measurement],2);
	  }else{
		  $ntm = 0.00;
	  }
  }
?>
    <td  style="text-align:right;border: solid 1px #55DD44;"><?= $ntm;?></td>
  </tr>
  <tr>
    <td colspan="7"  style="text-align: left; border: solid 1px #55DD44;">SCAC CODE:&nbsp; 
    	<?
	if(trim($r[ams])==''){
		
		$sc=data($link_impo,"select scac from bookingexpint where booking_interteam like '$txtbooking'");
		$scac=$sc[scac];
		
	}else{
		$scac=$r[ams];
	}
	?>
	<?=$scac?>
    </td>
    </tr>
<? 
$tw+=$r[weight];
$tm+=$ntm;
$tb+=$r[bulk];
} ?>
  
</table>

<table style="width: 100%;" align="left" ><!---714-->
  <tr>
  	<td  style="text-align: left;">
    <div style="width:724px"><BR /><BR />
    <B>TOTAL OF BULKS:</B>&nbsp;<?=number_format($tb,2)?><b>&nbsp;&nbsp;&nbsp;&nbsp;TOTAL GROSS WEIGHT:</b>&nbsp;&nbsp;&nbsp;&nbsp;<?=number_format($tw,2)?>&nbsp;&nbsp;&nbsp;&nbsp;<b>TOTAL MEASUREMENT:</b>&nbsp;<?=number_format($tm,2)?>
    <BR /><BR />
    </div>
    </td>
 
  </tr>
 </table>
 
 <table style="width: 100%;" align="left" >
  <tr>
  	 <td  style="text-align: left; "><div style="width:724px">
     <B>HARMONIZED CODE:</B>&nbsp;<?=$HARMONIZED_CODE?><br />
     <B>FREIGHT PREPAID</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>CLEAN ON BOARD</B></div></td>
  </tr>
 </table>
</page>
 
