<?
require_once("comun/conex_ver.php");
//require_once("comun/funciones.php")
function valorate($valor){
	$valor = str_replace("'","\'",$valor);
	return $valor;
}

$link=con_ver();
//echo 'hola0';

$booking = $_GET[booking];
//echo 'booking 0.'.$booking ;
$query=mysqli_query($link,"select * from detailcargaexpint where `bookingno` = '".$booking."' ORDER BY id,tipo_bl");
//echo mysqli_error();

//echo "select * from detailcargaexpint where `bookingno` = '".$booking."' ORDER BY id,tipo_bl";

if(mysqli_num_rows($query)==0 or trim($booking)=='') return;
//echo "select * from detailcargaexpint where `bookingno` = '".$booking."' ORDER BY tipo_bl,id";

?>
<br />
<? echo $booking;?>
<table width="1562" class="cargas" id="dataTable" >
  <tr>
  <TD>ID</TD>
    <td width="149"> </td>
    <td width="64">Modificar </td>
    <td width="49">Borrar</td>
    <td width="57">Type</td>
    <td width="137">Marks</td>
    <td width="47">Length</td>
    <td width="43">Width</td>
    <td width="39">Height</td>
    <td width="109">Quantity of bulks</td>
    <td width="89">Type of bulks</td>
    <td width="217">Description of goods</td>
    <td width="113">Number of pieces</td>
    <td width="83">Gross weight</td>
    <td width="74">Net weight</td>
    <td width="53">Volume</td>
    <td width="120">Harmonized code</td>
    <td width="47">AMS</td>
  </tr>
  

   <? while($row=mysqli_fetch_array($query)){
	   $qry = mysqli_query($link,"select * from hblexpint where idhbl = '".$row[id_bl]."'");
	   //echo "select * from hblexpint where idhbl = '".$row[id_bl]."'";
	   $rQ=mysqli_fetch_array($qry);
	   $shipper=$rQ[shipper];$shipper2=$rQ[shipper2];$shipper3=$rQ[shipper3];$shipper4=$rQ[shipper4];$shipper5=$rQ[shipper5];$shipper6=$rQ[shipper6];
	   $consignee=$rQ[consignee];$consignee2=$rQ[consignee2];$consignee3=$rQ[consignee3];$consignee4=$rQ[consignee4];$consignee5=$rQ[consignee5];$consignee6=$rQ[consignee6];
	   $notify=$rQ[notify];$notify2=$rQ[notify2];$notify4=$rQ[notify4];$notify3=$rQ[notify3];$notify5=$rQ[notify5];$notify6=$rQ[notify6];
	   $referencia = $rQ[referencia];
	   
	   $tarja=$rQ[tarja];$status=$rQ[status];$registrado_por=$rQ[registrado_por];
	   
	   $ID = $rQ[idhbl];
	   // DATOS DEL MBL
	   
$qry1 = mysqli_query($link,"select * from hblexpint where booking = '".$booking."' and tipo = 'MBL'");
	   $rQ1=mysqli_fetch_array($qry1);
	    $shipperM=$rQ1[shipper];$shipper2M=$rQ1[shipper2];$shipper3M=$rQ1[shipper3];$shipper4M=$rQ1[shipper4];$shipper5M=$rQ1[shipper5];$shipper6M=$rQ1[shipper6];
	   $consigneeM=$rQ1[consignee];$consignee2M=$rQ1[consignee2];$consignee3M=$rQ1[consignee3];$consignee4M=$rQ1[consignee4];$consignee5M=$rQ1[consignee5];$consignee6M=$rQ1[consignee6];
	   $notifyM=$rQ1[notify];$notify2M=$rQ1[notify2];$notify4M=$rQ1[notify4];$notify3M=$rQ1[notify3];$notify5M=$rQ1[notify5];$notify6M=$rQ1[notify6];
	   $tarjaM=$rQ1[tarja];$statusM=$rQ1[status];$registrado_porM=$rQ1[registrado_por];$idhblM=$rQ1[idhbl];
	   
	   $qry2 = mysqli_query($link,"select * from detailcargaexpint where id_bl ='".$idhblM."'");
	   $rQ2=mysqli_fetch_array($qry2);
	   $largoM=$rQ2[largo];
	   $anchoM=$rQ2[ancho];
	   $altoM=$rQ2[alto];
	   $marksM=$rQ2[markandnos];
	   $quantityM=$rQ2[bulk];
	   $descriptionM=$rQ2[cargo];
  	   $number_of_piecesM=$rQ2[number_of_pieces];
	   $weightM=$rQ2[weight];
	   $netweightM=$rQ2[netweight];
	   $measurementM=$rQ2[measurement];
	   $harmonized_codeM=$rQ2[harmonized_code];
	   $amsM=$rQ2[ams];
  
  	   $idEM=$rQ2[id_bl];
	   $type_of_bulksM=$rQ2[type_of_bulks];
	   $referenciaM=$rQ2[referencia];
	   $bookingnoM=$rQ2[bookingno];


	
	   ?>
   <tr <?= $row[tipo_bl]=='MBL' ? 'style="color:#F30"':''?>>
     <TD><?=$ID?></TD>
     <TD>
      <? if($row[tipo_bl]=='MBL'){ ?>
      <a  target="_blank" href="pdf/mbl_n.php?booking=<?=$row[bookingno]?>&idhbl=<?=$row[id_bl]?>" style="color:#00AF4B; text-decoration:underline; cursor:pointer;" title="Exportar a PDF" id="pdf">Recibase MBL</span> 
      <? }else{ ?>
     <a target="_blank" href="pdf/hbl_n.php?booking=<?=$row[bookingno]?>&idhbl=<?=$row[id_bl]?>" style="color:#00AF4B; text-decoration:underline; cursor:pointer;" title="Exportar a PDF" id="pdf">Recibase HBL</span> 
     <? } ?>
     <!--<a href="../pdf/manifiesto.php" target="_blank">Manifiesto</a><br /><br />
     -->
     </TD>
  
    <TD>
    <img title="Modificar BL" onclick="
    <? if($row[tipo_bl]=='HBL') { ?>
    document.getElementById('h_marks').value='<?=valorate($row[markandnos])?>';
    document.getElementById('h_quantity').value='<?=valorate($row[bulk])?>';
    document.getElementById('h_description').value='<?=valorate($row[cargo])?>';
    document.getElementById('h_largo').value='<?=valorate($row[largo])?>';
    document.getElementById('h_ancho').value='<?=valorate($row[ancho])?>';
    document.getElementById('h_alto').value='<?=valorate($row[alto])?>';
    document.getElementById('h_status').value='<?=$status?>';
    document.getElementById('h_status_cambiado').value='<?=$status?>';
    
    document.getElementById('h_no_piezas').value='<?=valorate($row[number_of_pieces])?>';
    document.getElementById('h_gross_weight').value='<?=valorate($row[weight])?>';
    document.getElementById('h_net_weight').value='<?=valorate($row[netweight])?>';
    document.getElementById('h_volume').value='<?=valorate($row[measurement])?>';
    document.getElementById('h_harmonized_code').value='<?=valorate($row[harmonized_code])?>';
    
    document.getElementById('h_tarja').value='<?=valorate($tarja)?>';
    
    document.getElementById('h_ams').value='<?=valorate($row[ams])?>';
    document.getElementById('h_id').value='<?=valorate($row[id])?>';
    document.getElementById('h_booking').value='<?=valorate($row[bookingno])?>';
    document.getElementById('h_referencia').value='<?=valorate($referencia)?>';
    document.getElementById('h_type_of_bulks').value='<?=valorate($row[type_of_bulks])?>';
    
    
    document.getElementById('h_shipper1').value='<?=valorate($shipper)?>';
    document.getElementById('h_shipper2').value='<?=valorate($shipper2)?>';
    document.getElementById('h_shipper3').value='<?=valorate($shipper3)?>';
    document.getElementById('h_shipper4').value='<?=valorate($shipper4)?>';
    document.getElementById('h_shipper5').value='<?=valorate($shipper5)?>';
    document.getElementById('h_shipper6').value='<?=valorate($shipper6)?>';
    
    document.getElementById('h_consignee1').value='<?=valorate($consignee)?>';
    document.getElementById('h_consignee2').value='<?=valorate($consignee2)?>';
    document.getElementById('h_consignee3').value='<?=valorate($consignee3)?>';
    document.getElementById('h_consignee4').value='<?=valorate($consignee4)?>';
    document.getElementById('h_consignee5').value='<?=valorate($consignee5)?>';
    document.getElementById('h_consignee6').value='<?=valorate($consignee6)?>';
    
    document.getElementById('h_notify1').value='<?=valorate($notify)?>';
    document.getElementById('h_notify2').value='<?=valorate($notify2)?>';
    document.getElementById('h_notify3').value='<?=valorate($notify3)?>';
    document.getElementById('h_notify4').value='<?=valorate($notify4)?>';
    document.getElementById('h_notify5').value='<?=valorate($notify5)?>';
    document.getElementById('h_notify6').value='<?=valorate($notify6)?>';
    limpiar_mbl();
    
    document.getElementById('largo').value='<?=valorate($largoM)?>';
    document.getElementById('ancho').value='<?=valorate($anchoM)?>';
    document.getElementById('alto').value='<?=valorate($altoM)?>';
    document.getElementById('tarja').value='<?=valorate($tarjaM)?>';
    document.getElementById('status').value='<?=valorate($statusM)?>';
    document.getElementById('status_cambiado').value='<?=valorate($statusM)?>';
    document.getElementById('registrado_por').value='<?=valorate($registrado_porM)?>';
  
    document.getElementById('marks').value='<?=valorate($marksM)?>';
    document.getElementById('quantity').value='<?=valorate($quantityM)?>';
    document.getElementById('description').value='<?=valorate($descriptionM)?>';
    document.getElementById('no_piezas').value='<?=valorate($number_of_piecesM)?>';
    document.getElementById('gross_weight').value='<?=valorate($weightM)?>';
    document.getElementById('net_weight').value='<?=valorate($netweightM)?>';
    document.getElementById('volume').value='<?=valorate($measurementM)?>';
    document.getElementById('harmonized_code').value='<?=valorate($harmonized_codeM)?>';
    document.getElementById('ams').value='<?=valorate($amsM)?>';
    document.getElementById('idE').value='<?=valorate($idEM)?>';
    document.getElementById('booking').value='<?=valorate($bookingnoM)?>';
    
    document.getElementById('referencia').value='<?=valorate($referenciaM)?>';
    document.getElementById('type_of_bulks').value='<?=valorate($type_of_bulksM)?>';
        
    document.getElementById('shipper1').value='<?=valorate($shipperM)?>';
    document.getElementById('shipper2').value='<?=valorate($shipper2M)?>';
    document.getElementById('shipper3').value='<?=valorate($shipper3M)?>';
    document.getElementById('shipper4').value='<?=valorate($shipper4M)?>';
    document.getElementById('shipper5').value='<?=valorate($shipper5M)?>';
    document.getElementById('shipper6').value='<?=valorate($shipper6M)?>';
    
    document.getElementById('consignee1').value='<?=valorate($consigneeM)?>';
    document.getElementById('consignee2').value='<?=valorate($consignee2M)?>';
    document.getElementById('consignee3').value='<?=valorate($consignee3M)?>';
    document.getElementById('consignee4').value='<?=valorate($consignee4M)?>';
    document.getElementById('consignee5').value='<?=valorate($consignee5M)?>';
    document.getElementById('consignee6').value='<?=valorate($consignee6M)?>';
    
    document.getElementById('notify1').value='<?=valorate($notifyM)?>';
    document.getElementById('notify2').value='<?=valorate($notify2M)?>';
    document.getElementById('notify3').value='<?=valorate($notify3M)?>';
    document.getElementById('notify4').value='<?=valorate($notify4M)?>';
    document.getElementById('notify5').value='<?=valorate($notify5M)?>';
    document.getElementById('notify6').value='<?=valorate($notify6M)?>';

    //document.getElementById('booking').blur();
    parent.document.location='registro_bl.php#hbl'
    <? } elseif($row[tipo_bl]=='MBL') { ?>
    document.getElementById('largo').value='<?=valorate($row[largo])?>';
    document.getElementById('ancho').value='<?=valorate($row[ancho])?>';
    document.getElementById('alto').value='<?=valorate($row[alto])?>';
    document.getElementById('tarja').value='<?=valorate($tarja)?>';
    document.getElementById('status').value='<?=valorate($status)?>';
    document.getElementById('registrado_por').value='<?=valorate($registrado_por)?>';
        
    document.getElementById('marks').value='<?=valorate($row[markandnos])?>';
    document.getElementById('quantity').value='<?=valorate($row[bulk])?>';
    document.getElementById('description').value='<?=valorate($row[cargo])?>';
    document.getElementById('no_piezas').value='<?=valorate($row[number_of_pieces])?>';
    document.getElementById('gross_weight').value='<?=valorate($row[weight])?>';
    document.getElementById('net_weight').value='<?=valorate($row[netweight])?>';
    document.getElementById('volume').value='<?=valorate($row[measurement])?>';
    document.getElementById('harmonized_code').value='<?=valorate($row[harmonized_code])?>';
    document.getElementById('ams').value='<?=valorate($row[ams])?>';
    document.getElementById('idE').value='<?=valorate($row[id_bl])?>';
    document.getElementById('booking').value='<?=valorate($row[bookingno])?>';
    
    document.getElementById('referencia').value='<?=valorate($referencia)?>';
    document.getElementById('type_of_bulks').value='<?=valorate($row[type_of_bulks])?>';
        
    document.getElementById('shipper1').value='<?=valorate($shipper)?>';
    document.getElementById('shipper2').value='<?=valorate($shipper2)?>';
    document.getElementById('shipper3').value='<?=valorate($shipper3)?>';
    document.getElementById('shipper4').value='<?=valorate($shipper4)?>';
    document.getElementById('shipper5').value='<?=valorate($shipper5)?>';
    document.getElementById('shipper6').value='<?=valorate($shipper6)?>';
    
    document.getElementById('consignee1').value='<?=valorate($consignee)?>';
    document.getElementById('consignee2').value='<?=valorate($consignee2)?>';
    document.getElementById('consignee3').value='<?=valorate($consignee3)?>';
    document.getElementById('consignee4').value='<?=valorate($consignee4)?>';
    document.getElementById('consignee5').value='<?=valorate($consignee5)?>';
    document.getElementById('consignee6').value='<?=valorate($consignee6)?>';
    
    document.getElementById('notify1').value='<?=valorate($notify)?>';
    document.getElementById('notify2').value='<?=valorate($notify2)?>';
    document.getElementById('notify3').value='<?=valorate($notify3)?>';
    document.getElementById('notify4').value='<?=valorate($notify4)?>';
    document.getElementById('notify5').value='<?=valorate($notify5)?>';
    document.getElementById('notify6').value='<?=valorate($notify6)?>';
    limpiar_hbl();
    parent.document.location='registro_bl.php#mbl'
    <? } ?>" src="https://<?=$_SERVER["SERVER_NAME"]?>/js/img/cambio.png" border="0" style="cursor:pointer" />
    </TD>
    <td><img title="Borrar BL" onclick="
    <? if($row[tipo_bl]=='HBL') { ?>
    if(confirm('Borra este House BL?')){ 
    borrar_hbl('<?=$row[id]?>','<?=$row[bookingno]?>','<?=$row[id_bl]?>');
    }
    <? } elseif($row[tipo_bl]=='MBL') { ?>
    if(confirm('Borra este Master BL?')){ 
     borrar_mbl('<?=$row[id]?>','<?=$row[bookingno]?>','<?=$row[id_bl]?>');
    //borrar_mbl('<?=$row[bookingno]?>');
    }
    <? } ?>" src="https://<?=$_SERVER["SERVER_NAME"]?>/js/img/eliminar.png" border="0" style="cursor:pointer" /> 
    <TD><?=$row[tipo_bl]?></TD> 
    <td><?=$row[markandnos]?></td>
    <td><?=$row[largo]?></td>
    <td><?=$row[ancho]?></td>
    <td><?=$row[alto]?></td>
    <td><?=$row[bulk]?></td>
    <td><?=$row[type_of_bulks]?></td>
    <td><?=$row[cargo]?></td>
    <td><?=$row[number_of_pieces]?></td>
    <td><?=$row[weight]?></td>
    <td><?=$row[netweight]?></td>
    <td><?=$row[measurement]?></td>
    <td><?=$row[harmonized_code]?></td>
    <td><?=$row[ams]?></td>
  </tr>

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