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

$suma_pza_mbl = "";
$suma_peso_mbl = "";

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;

$partida = data($link,"select * from detailcargaexpint where  bookingno like '".$txtbooking."'  ORDER BY ultima_actualizacion_esi desc limit 1"); 
$suma_pza_mbl  = doubleval($partida[number_of_pieces])+doubleval($partida[no_piezasimoh]);
$suma_peso_mbl = doubleval($partida[weight])+doubleval($partida[gross_weightimoh]);
 
$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;
}

$freightcode="FREIGHT PREPAID";

$datos_shipping = data($link,"select * from hblexpint where idhbl like '$idhbl%'");
$ref = busquedaB($link,"select referencia_lpv from datosbooking where referencia_cliente = '".$referencia_cliente."' ","referencia_lpv");
//echo "select referencia_lpv from datosbooking where referencia_cliente = '".$referencia_cliente."' ";
?>
<page backtop="5mm" backbottom="10mm" backleft="10mm" backright="10mm">
    <page_header>
<table style="width: 100%; ">
            <tr>
                <td style="text-align: left;    width: 15%"><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 MASTER</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: right;    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;<? echo $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])?>
                     
                </div>
                </td>
                
                <td valign="top">
                 <div style="width:100px">
                        <b>VOYAGE</b><br />
                        <? echo $viaje;
                     ?>
                </div>
                </td>
                </tr>
                </table>
        </td>
      </tr>
     
     
    </table>
    

    
 
<? //echo "select * from detailcargaexpint where bookingno like '$txtbooking' and tipo_bl = 'MBL' order by id<br><br>";?>

<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;">
    <div style="width:714px">
    <B>CONTENEDOR:</B> &nbsp;<?=$contenedor?><br />
    <b>SELLO: </B> &nbsp;<?=$sello?><br />
    <b>TARA:</b> &nbsp;<?= $tara!='' ? number_format($tara,2) : '';?><br />
    <b>PESO CON TARA:</B>&nbsp;<?= $peso_neto_con_tara!='' ? number_format($peso_neto_con_tara,2) : '';?> </div>
    </td>
  </tr>

<?   
$buscar =  mysqli_query($link,"select * from detailcargaexpint where bookingno like '$txtbooking' order by id");

if(mysqli_num_rows($buscar)==1){
$datos = mysqli_query($link,"select * from detailcargaexpint where bookingno like '$txtbooking' and tipo_bl = 'MBL' order by id");
$har = mysqli_query($link,"select distinct harmonized_code from detailcargaexpint where bookingno like '$txtbooking' order by id");
$rHar=mysqli_fetch_array($har);
$HARMONIZED_CODE=$rHar[0];
}

if(mysqli_num_rows($buscar)==2){
$datos = mysqli_query($link,"select * from detailcargaexpint where bookingno like '$txtbooking' and tipo_bl = 'MBL' order by id");
$har = mysqli_query($link,"select distinct harmonized_code from detailcargaexpint where bookingno like '$txtbooking' and tipo_bl = 'MBL' order by id");
$rHar=mysqli_fetch_array($har);
$HARMONIZED_CODE=$rHar[0];
}

if(mysqli_num_rows($buscar)>2){
$datos = mysqli_query($link,"select * from detailcargaexpint where bookingno like '$txtbooking' and tipo_bl = 'HBL' order by id");
$har = mysqli_query($link,"select distinct harmonized_code from detailcargaexpint where bookingno like '$txtbooking' and tipo_bl = 'HBL' order by id");
		$HARMONIZED_CODE='';
		if(mysqli_num_rows($har)>0){
			while($rHar=mysqli_fetch_array($har)){
				$HARMONIZED_CODE=$HARMONIZED_CODE.', '.$rHar[0];
			}
			//$HARMONIZED_CODE=substr($HARMONIZED_CODE,0,strlen($HARMONIZED_CODE)-2);
		}
}
 
?>
  
  <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:101px;max-width:101px"><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:150px; max-width:150px"><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:82px"><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]?><br /> </div></td>
    <td   style="text-align: left; border: solid 1px #55DD44;"><span style="width:101px; max-width:101px"><?=$r[bulk].' '.$r[type_of_bulks]?></span></td>
    <td   style="text-align: left; border: solid 1px #55DD44;"><DIV style="width:101px; max-width:101px">
       <?=$suma_pza_mbl?>
    </DIV></td>
    <td   style="text-align: left; border: solid 1px #55DD44;"><div style="width:150px; max-width:150px"><?=$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;"><?=$suma_peso_mbl ?></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+=doubleval($r[weight])+doubleval($r[gross_weightimoh]);
$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;<?=$tb?><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>
 
