<? include("../header_subnivel1.php");date_default_timezone_set('America/Mexico_City');ini_set("display_errors",1);
//include("../funciones.php");
/*global $tbulk,$tweight,$tnetweight;
global $buque;*/
$Z=con_impo();
/*mysqli_query("INSERT INTO accesos (`fecha`, `hora`, `usuario`, `ip`, `script`, `tipo`,critico) Values ('" . date("Y-m-d")  . "','" . date("H:i:s")  . "','".strtoupper($_SESSION[user])."','" . getRealIP() . "','REPORTE WS GOLMEX','EXPORTACION VERACRUZ',1)");
mysqli_close($Z);*/
$ll=con_ver();

?>	
 <style type="text/css">
 <!--
@import url("../css_tables/foggy_country.css");
@import url("../css_tables/foggy_country1.css");
@import url("../css_tables/foggy_country4.css");
-->
.botonExcel{
	cursor:pointer;
	text-decoration:underline;
	color:#00AF4B;
}
.link{
	cursor:pointer;
	text-decoration:underline;
	color:#00AF4B;
}
</style>

<script language="javascript">
 
$(document).ready(function() {
	$(".botonExcel").click(function(event) {
		$("#datos_a_enviar").val( $("<div>").append( $("#exportar").eq(0).clone()).html());
		$("#FormularioExportacion").submit();
});
});
 
</script>   
<div align="justify" style="line-height:18px;margin-top:-20px; position:absolute;width: 960px; height:100%;">



<span style="color:#00AF4B">Dashboard WS Golmex &raquo;</span><br />

 
<br />
<form name="form1" id="form1" method="post" action="reporte_ws_golmex.php">
  <table width="563" style="line-height:22px"  >
    <tr>
      <td width="209">Booking</td>
      <td width="342"><input type="text" class="aa" name="booking" id="booking" size="40" value="<?=$_POST[booking]?>"   /></td>
    </tr>
   
    <tr>
      <td>Ultimo update desde</td>
      <td align="left"><input type="text" class="aa" name="ultimo_update_golmex_desde" id="ultimo_update_golmex_desde" size="40" value="<?=$_POST[ultimo_update_golmex_desde]?>"  onclick="displayCalendar(document.getElementById('ultimo_update_golmex_desde'),'yyyy-mm-dd',this)" ondblclick="this.value=''" /></td>
    </tr>
    <tr>
      <td>Ultimo update hasta</td>
      <td align="left"><input type="text" class="aa" name="ultimo_update_golmex_hasta" id="ultimo_update_golmex_hasta" size="40" value="<?=$_POST[ultimo_update_golmex_hasta]?>"  onclick="displayCalendar(document.getElementById('ultimo_update_golmex_hasta'),'yyyy-mm-dd',this)" ondblclick="this.value=''" /></td>
    </tr>
    <tr>
      <td>Cantidad de registros</td>
      <td><input type="text" class="aa" name="cant_registros" id="cant_registros" size="40" value="<?=($_POST[cant_registros]=='' ? 100 : $_POST[cant_registros])?>"   /></td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" id="submit" name="submit" value="Buscar"/>&nbsp;
      </td>
    </tr>
 </table>
 

</form>

 
<br />

 <?php
 
con_ver();
$referencia_puerto = trim($_POST[referencia_puerto]);
$ultimo_update_golmex_desde = trim($_POST[ultimo_update_golmex_desde]);
$ultimo_update_golmex_hasta = trim($_POST[ultimo_update_golmex_hasta]);
$booking = $_POST[booking];

if(trim($_POST[cant_registros])=='') $cant_registros=100; else $cant_registros=$_POST[cant_registros];

if($ultimo_update_golmex_desde=='' and $ultimo_update_golmex_hasta=='' and $booking==''){
	$lista_referencias=mysqli_query($ll,"select  distinct HH.booking,db.*,db.tipo as tipo_cont,db.comentarios as comentarios_booking from hblexpint HH 
	inner join datosbooking db on
	HH.referencia = db.referencia_cliente and ultimo_update_golmex<>'0000-00-00 00:00:00'
	order by HH.ultimo_update_golmex desc limit $cant_registros");
}else{
	$lista_referencias=mysqli_query($ll,"select  distinct HH.booking,db.*,db.tipo as tipo_cont,db.comentarios as comentarios_booking from hblexpint HH 
	inner join datosbooking db on
	HH.referencia = db.referencia_cliente and ultimo_update_golmex<>'0000-00-00 00:00:00'
	".($booking!='' ? " and HH.booking = '$booking' " : '')."
	".(($ultimo_update_golmex_desde!='' and $ultimo_update_golmex_hasta!='') ? 
	" and cast(HH.ultimo_update_golmex as date) between '$ultimo_update_golmex_desde' and '$ultimo_update_golmex_hasta' " : '')." 
	".($referencia_puerto!='' ? " and db.referencia_lpv like '%$referencia_puerto%' " : '')." 
	order by HH.ultimo_update_golmex desc limit $cant_registros");
	
}
	
if(mysqli_num_rows($lista_referencias)<1 ){  
	echo 'No se encontraron registros para su busqueda';
	return;
} 
if(mysqli_num_rows($lista_referencias)>0){ 



?>
<span class="botonExcel">Exportar a Excel</span>
<form action="reporte_dashboard_bookings.php" method="post" target="_blank" id="FormularioExportacion">
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
<input type="hidden" id="titulo" name="titulo" value="REPORTE DE CONTENEDORES <?= '<br>FECHA DE IMPRESION: ' .date("Y/m/d")?>" />
</form>
<br />

<table border = "1" class="frog4" align="left" width="180%" id="exportar"  style="font-family:Arial, Helvetica, sans-serif; font-size:10px">
 <tr>
    <td bgcolor="#C0C0C0">FILA</td>
    <td bgcolor="#C0C0C0">ULTIMO UPDATE GOLMEX</td>
    <td bgcolor="#C0C0C0">TARJA DE RECEPCION</td>
    <td bgcolor="#C0C0C0">NUM AVERIA</td>
    <td bgcolor="#C0C0C0">FECHA DE RECEPCION</td>
    <td bgcolor="#C0C0C0">BOOKING</td>
    <td bgcolor="#C0C0C0">PUERTO (POD)</td>
    <td bgcolor="#C0C0C0"><div align="right">LARGO</div></td>
    <td bgcolor="#C0C0C0"><div align="right">ANCHO</div></td>
    <td bgcolor="#C0C0C0"><div align="right">ALTO</div></td>
    <td bgcolor="#C0C0C0"><div align="right">CUBICAJE</div></td>
    <td bgcolor="#C0C0C0">EMBALAJE</td>
    <td bgcolor="#C0C0C0">MARCAS</td>
    <td bgcolor="#C0C0C0">HORA RECEPCION</td>
    <td bgcolor="#C0C0C0">POSICION</td>
    <td bgcolor="#C0C0C0">FECHA CONSOLIDACION</td>
    <!-- <td bgcolor="#C0C0C0"><div align="center">SOL ICITUD DE VACIO</div></td>
    <td bgcolor="#C0C0C0"><div align="center">DOCUMENTADO</div></td>
    <td bgcolor="#C0C0C0"><div align="center">PROG RAMADO</div></td>
    <td bgcolor="#C0C0C0"><div align="center">LI BERADO</div></td>-->
  </tr>
  
 <div align="center">
   <?
$gt=0;
$x=1;
while ($row = mysqli_fetch_array($lista_referencias)){
	
	
				$markandnos='';$type_of_bulks='';
				$harmonized_code='';
				$cantidad='';$peso='';$volumen='';
				$partida = mysqli_query($ll,"SELECT DISTINCT * FROM `detailcargaexpint` WHERE `bookingno` LIKE '".$row[booking]."' AND cargo <> '' 
				AND (tipo_bl = 'HBL' 
				or (tipo_bl = 'MBL' 
				and NOT EXISTS (SELECT * FROM `detailcargaexpint` WHERE `bookingno` LIKE '".$row[booking]."' and tipo_bl='HBL')))
				");
				
 
 				while($rA=mysqli_fetch_array($partida)){
					$markandnos= $rA[markandnos];
					$type_of_bulks= $rA[type_of_bulks];
					$harmonized_code=$rA[harmonized_code];
					$cantidad=$rA[bulk];
					$peso=$rA[weight];
					$id_bl=$rA[id_bl];
				
				
				$hbl=mysqli_query($ll,"select *,cast(ultimo_update_golmex as date) as ultimo_update_golmex_fecha from hblexpint where idhbl = '".$id_bl."' ");  
				
				
				$pedimentoz='';
				$tarja='';
				$tarja_recepcion='';
				$fecha_recepcion='';
				$hora_registro_ingreso='';
				$tarja_averia='';
				$shipper='';
				$consignee='';
				$status='';
				$agencia_aduanal='';$posicion_almacen='';
				while($rHBL=mysqli_fetch_array($hbl)){
					$pedimentoz=($rHBL[pedimento]!='' ? $rHBL[pedimento] : $pedimentoz);
					$tarja=($rHBL[tarja]!='' ? $rHBL[tarja] : $tarja);
					$posicion_almacen=$rHBL[posicion_almacen];
					$fecha_salida=$rHBL[fecha_salida];
					$ultimo_update_golmex_fecha=$rHBL[ultimo_update_golmex_fecha];
					$ultimo_update_golmex=$rHBL[ultimo_update_golmex];
					$tarja_recepcion=($rHBL[tarja_recepcion]!='' ? $rHBL[tarja_recepcion] : $tarja_recepcion);
					$fecha_recepcion=($rHBL[fecha_recepcion]!='0000-00-00' ? $rHBL[fecha_recepcion] : $fecha_recepcion);
					$hora_registro_ingreso=($rHBL[hora_registro_ingreso]!='' ? $rHBL[hora_registro_ingreso] : $hora_registro_ingreso);
					$tarja_averia=($rHBL[tarja_averia]!='' ? $rHBL[tarja_averia] : $tarja_averia);
					$shipper=($rHBL[shipper]!='' ? $rHBL[shipper] : $shipper);
					$consignee=($rHBL[consignee]!='' ? $rHBL[consignee] : $consignee);
					$status=($rHBL[status]!='' ? $rHBL[status] : $status);
					/* DATOS DE IMO Y AGENCIA ADUANAL QUE DOCUMENTO LOS HBLS, SEGUN SEA EL HBL O MBL DEL BOOKING 
					$IMOs.=$rHBL[imo].', ';
					$IMOs=substr($IMOs,0,strlen($IMOs)-2);
					
					if($rHBL[registrado_por]!=''){
						con_impo();
						$datos_aaq = mysqli_query("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 A.registro = 'VERACRUZ' and C.email_contacto LIKE '%".trim($rHBL[registrado_por])."%' ");
						$raa=mysqli_fetch_array($datos_aaq);
						$agencia_aduanal=$raa[nombre_empresa];
						con_ver();
					}
					%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
				}
		 
				
				
				$medidas='';
				$volumen=''; 
				$dimen1 =	mysqli_query($ll,"select D.* from dimensiones D where D.id_partida = '".$id_bl."' order by id desc  ");
				$largo='';$ancho='';$alto='';$cubicaje='';
				if(mysqli_num_rows($dimen1)>0){ 
				   while($rd1=mysqli_fetch_array($dimen1)){
				   $largo.=$rd1[largo].(mysqli_num_rows($dimen1)>1 ? '<br>' : '');
				   $ancho.=$rd1[ancho].(mysqli_num_rows($dimen1)>1 ? '<br>' : '');
				   $alto.=$rd1[alto].(mysqli_num_rows($dimen1)>1 ? '<br>' : '');
				   $cubicaje.=number_format($rd1[largo]*1/100*$rd1[ancho]*1/100*$rd1[alto]*1/100*$rd1[numero_bultos],3).(mysqli_num_rows($dimen1)>1 ? '<br>' : '');
				 
				   }
				}
				
			//	$QIMO =	mysqli_query("select * from detallebooking where referencia_cliente = '".$row[referencia_cliente]."' and imo<>'' and and imo<>'0'");

/*if((compararFechas($fecha_recepcion_hasta,$fecha_recepcion)>=0 and compararFechas($fecha_recepcion_desde,$fecha_recepcion)<=0 and $fecha_recepcion<>'' and $fecha_recepcion<>'0000-00-00') or ($fecha_recepcion_desde=='' and $fecha_recepcion_hasta=='')){*/
				?>
   
 </div>
 <tr>
    <td><span><div align="left"><?=$x?><? $x++;?></div></span></td>
    <td <?=$ultimo_update_golmex_fecha==date("Y-m-d") ? 'bgcolor="#00FFFF" ' : ''?>><div align="left">
      <?=$ultimo_update_golmex?>
    </div></td>
    <td><div align="left">
      <?=$tarja_recepcion?>
    </div></td>
    <td><div align="left">
      <?=$tarja_averia?>
    </div></td>
    <td align="right"><div align="left">
      <?=$fecha_recepcion?>
    </div></td>
    <td><div align="left">
      <?=$row[booking]?>
    </div></td>
    <td align="right">
      <div align="left">
        <?=$row[pod]?>
      </div>
    </td>
    <td align="right"><div align="right"><?=$largo?></div></td>
    <td align="right"><div align="right"><?=$ancho?></div></td>
    <td align="right"><div align="right"><?=$alto?></div></td>
    <td align="right"><div align="right"><?=$cubicaje?></div></td>
    <td align="right"><div align="left"><?=$type_of_bulks?></div></td>
    <td align="right"><div align="left">
      <?=$markandnos?>
    </div></td>
    <td align="center"><div align="left">
      <?=$hora_registro_ingreso?>
    </div></td>
    <td align="right"><div align="left">
      <?=$posicion_almacen?>
    </div></td>
    <td align="right"><div align="left">
      <?=$fecha_salida?>
    </div></td>
     
  </tr>
  <?  } 
				 
}
  
?>
 
  <tr>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <!--<td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>
    <td align="right" bgcolor="#C0C0C0">&nbsp;</td>-->
  </tr>
</table>
<? } mysqli_close($ll);?>