<?php
require('code128.php');
//require('../fpdf.php');

include ("../../Conexion.php");

$UsuEn=$_POST['USUkp'] or $UsuEn=$_GET['USUkp'];
$UsuAImp=strtoupper($_POST['USUkp']) or $UsuAImp=strtoupper($_GET['USUkp']);
$NoDocSEn=$_POST['txt_NODOC'] or $NoDocSEn=$_GET['txt_NODOC'];

if ($UsuEn=="")
		{
		echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=../../../RedireccionDeCierre.php' target='_parent'>";
		}

/////////IDENTIFICAR DATOS DE NIVEL///////
		$sql = mysql_query("select * from tabla_usuarios where USUARION='$UsuEn'");
						
	if (mysql_numrows($sql)==0) echo "";
		else{
		$registro=mysql_fetch_array($sql);
		}
		if (mysql_numrows($sql)>0)
		{
		$CNiv=$registro["NIVEL"];
		}
			
	if ($CNiv<>"01" and $CNiv<>"02" and $CNiv<>"04" and $CNiv<>"05")
		{
		echo "<script>alert('No estas autorizado para acceder a este módulo del WMS');</script>";
		echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=../../../RedireccionDeCierre.php'>";
		}

class MiPDF extends FPDF {

		public function Header(){
		
		
			$this -> Image ("../../../WMS_Resources/Imagenes/Logo_Rectangu_Transp.png" , 10 , 10 , 30 ,15);
			$this -> SetFont ( 'Arial' , 'B', '12');
			$this -> Cell ( 180, 10 , '|| Guia de Tracking ||' , 0 , 0 , 'C');
			$this -> Ln ( 2 );
			$this -> SetFont ( 'Arial' , 'I', '10');
			$this -> Cell ( 180, 20 , 'www.logsyswms.com' , 0 , 0 , 'C');
			$this -> Ln ( 4 );
			$this -> SetTextColor (0 , 136 , 29);
			$this -> SetFont ( 'Arial' , '', '10');
			$this -> Cell ( 180, 20 , '_______________________________________________________________________________________________' , 0 , 0 , 'C');
			$this -> Ln ( 3 );
			$this -> SetFont ( 'Arial' , '', '10');
			$this -> Cell ( 180, 20 , '_____________________________________________' , 0 , 0 , 'C');
			$this -> Ln ( 20 );
		}
		
	    function Footer(){
    		// Posición: a 2,0 cm del final
    		$this->SetY(-20);
    		// Arial italic 8
    		$this->SetFont('Arial','I',8);
    		// Número de página
    		$this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C');
		}
}

	$mipdf = new MiPDF();
	$mipdf = new PDF_Code128();
	$mipdf -> AliasNbPages();
	$mipdf -> addPage();
	
	//$pdf=new PDF_Code128();
	//$pdf->AddPage();
	
//////////////////////////////////CONSULTAR LA TABLA DEL CONTRATANTE////////////////////////////////////////////
		$sql = mysql_query("select * from tabla_contratante");
						
	if (mysql_numrows($sql)==0) echo "";
		else{
		$registro=mysql_fetch_array($sql);
		}
		if (mysql_numrows($sql)>0)
		{
		$CNomContra=$registro["NOMBRE_FISCAL"];
		$CNomCuenta=$registro["CUENTA"];
		}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////CONSULTAR LA tabla_consetrack////////////////////////////////////////////
		$sql = mysql_query("select * from tabla_consetrack WHERE NO_TRACKING='$NoDocSEn'");
						
		if (mysql_numrows($sql)==0) 
		{
		echo "<script>alert('El no. de Tracking ingresado no existe.\\n\\nFavor de corroborarlo.');</script>";
		echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=../../../RedireccionDeCierre.php'>";
		}
		else
		{
		$registro=mysql_fetch_array($sql);

		if (mysql_numrows($sql)>0)
		{
		$FeCTrack=$registro["FECHA"];
		
		//////////////FORATEADO LA FECHA DE CADUCIDAD///////////////////////////
			$ExtAno = substr($FeCTrack, -8,4);    // devuelve el año
			$ExtMes = substr($FeCTrack, -4, 2);    // devuelve el mes
			$ExtDia = substr($FeCTrack, -2,2);    // devuelve el día
			
			$FechaFIN=$ExtDia."/".$ExtMes."/".$ExtAno;
		}
		
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////CONSULTAR EL NOMBRE DEL DESTINO////////////////////////////////////////////
		$sql = mysql_query("select * from tabla_destinosclientes WHERE CVE_DESTINO='$CDesti'");
						
	if (mysql_numrows($sql)==0) echo "";
		else{
		$registro=mysql_fetch_array($sql);
		}
		if (mysql_numrows($sql)>0)
		{
		$CDestiNom=$registro["NOMBRE"];
		}

//////////////////////////INFORMACIÓN PRINCIPAL////////////////////////////////////////////////////////////////
	
	$CInfPrin_Contra = "P. LOGISTICO:";
	$CInfPrin_Cuen = "CUENTA:";
	$CInfPrin_Fecha = "FECHA:";
	$CInfPrin_Usu = "USUARIO:";
	
	$mipdf -> SetFont ( 'Courier' , 'B', '12');
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor (208 , 72 , 69 );
	$mipdf -> Cell ( 178 , 7 , '.:: GUÍA DE TRACKING ::.' , 1 , 0 , 'C' , true );
	$mipdf -> Ln ( 10 );////////////////////////////////////////////////////////
	$mipdf -> SetFont ( 'Courier' , '', '8');
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor ( 76 , 100 , 191 );
	$mipdf -> Cell ( 30 , 3 , $CInfPrin_Contra, 1 , 0 , 'L' , true );
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf -> SetFillColor ( 255 , 255 , 255 );
	$mipdf -> Cell ( 90 , 3 , $CNomContra, 1 , 0 , 'L' , true );
	$mipdf -> Ln ( 3 );////////////////////////////////////////////////////////
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor ( 76 , 100 , 191 );
	$mipdf -> Cell ( 30 , 3 , $CInfPrin_Cuen, 1 , 0 , 'L' , true );
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf -> SetFillColor ( 255 , 255 , 255 );
	$mipdf -> Cell ( 90 , 3 , $CNomCuenta, 1 , 0 , 'L' , true );
	$mipdf -> Ln ( 3 );////////////////////////////////////////////////////////
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor ( 76 , 100 , 191 );
	$mipdf -> Cell ( 30 , 3 ,$CInfPrin_Fecha, 1 , 0 , 'L' , true );
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf -> SetFillColor ( 255 , 255 , 255 );
	$mipdf -> Cell ( 90 , 3 , $FechaFIN, 1 , 0 , 'L' , true );
	$mipdf -> Ln ( 3 );////////////////////////////////////////////////////////
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor ( 76 , 100 , 191 );
	$mipdf -> Cell ( 30 , 3 ,$CInfPrin_Usu, 1 , 0 , 'L' , true );
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf -> SetFillColor ( 255 , 255 , 255 );
	$mipdf -> Cell ( 90 , 3 , $UsuAImp, 1 , 0 , 'L' , true );
	$mipdf -> Ln ( 6 );////////////////////////////////////////////////////////
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor ( 76 , 100 , 191 );
	$mipdf -> Cell ( 30 , 3 , 'TRACKING' , 1 , 0 , 'L' , true );
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf -> SetFillColor ( 255 , 255 , 255 );
	$mipdf -> Cell ( 86 , 15 , '' , 1 , 0 , 'L' , true );
	
//////////////////////////FIN INFORMACIÓN PRINCIPAL///////////////////////////////////////////////////////////	

	$cabeceraID = "ID";
	$cabeceraDOCU = "DOCUMENTO";
	$cabeceraDEST = "DESTINO";
	$cabeceraCALT = "CVE. ALTERNA";
	$cabeceraBARC = "DOCUMENTO - BARCODE";

	$mipdf -> Ln ( 18 );
	$mipdf -> SetFont ( 'Courier' , '', '6');
	$mipdf -> SetTextColor (255 , 255 , 255);
	$mipdf -> SetFillColor ( 76 , 100 , 191 );

	$mipdf -> Cell ( 6 , 3 , $cabeceraID, 1 , 0 , 'C' , true );
	$mipdf -> Cell ( 24 , 3 , $cabeceraDOCU, 1 , 0 , 'C' , true );
	$mipdf -> Cell ( 23 , 3 , $cabeceraDEST, 1 , 0 , 'C' , true );
	$mipdf -> Cell ( 40 , 3 , $cabeceraCALT, 1 , 0 , 'C' , true );
	$mipdf -> Cell ( 85 , 3 , $cabeceraBARC, 1 , 0 , 'C' , true );
	
	$mipdf -> Ln ( 3 );

$consulta = mysql_query ("SELECT  * from tabla_trcarga WHERE NO_RUTA='$NoDocSEn' ORDER BY ID  ASC");

$ID = "0";
while ($datos = mysql_fetch_array($consulta))
{
	$ID = $ID + 1;
	$DOCU = $datos [ 'DOCUMENTO' ];
	$DEST = $datos [ 'CVE_DESTINO' ];
	$CALTE = $datos [ 'CVE_SINCROALTE' ];
	
	//////////////////////////////////CONSULTAR EL NOMBRE DEL DESTINO////////////////////////////////////////////
		$sqlDD = mysql_query("select * from tabla_destinosclientes WHERE CVE_DESTINO='$DEST'");
		if (mysql_numrows($sqlDD)==0) echo "";
		else{
		$registroDD=mysql_fetch_array($sqlDD);
		}
		if (mysql_numrows($sqlDD)>0)
		{
		$CalleDD=$registroDD["CALLE"];
		$NoDD=$registroDD["NO"];
		$ColoDD=$registroDD["COLONIA"];
		$CpDD=$registroDD["CP"];
		$CiuDD=$registroDD["CIUDAD"];
		$EdoDD=$registroDD["ESTADO"];
		$PaiDD=$registroDD["PAIS"];
		
		$DirDes = $CalleDD.", ".$NoDD.", ".$ColoDD.", ".$CpDD.", ".$CiuDD.", ".$EdoDD.", ".$PaiDD;
		}
	
	$mipdf -> SetFont ( 'Courier' , '', '7');
	$mipdf -> SetTextColor (0 , 0 , 0 );
	$mipdf -> SetFillColor ( 255 , 255 , 255 );
	
	$mipdf -> Cell ( 6 , 14 , $ID , 1 , 0 , 'C' , true );
	$mipdf -> Cell ( 24 , 14 , $DOCU , 1 , 0 , 'L' , true );
	$mipdf -> Cell ( 23 , 14 , $DEST , 1 , 0 , 'L' , true );
	$mipdf -> Cell ( 40 , 14 , $CALTE , 1 , 0 , 'L' , true );
	$mipdf -> Cell ( 85 , 14 , ' ' , 1 , 0 , 'C' , true );
	
	$mipdf -> Ln ( 14 );
	
	$mipdf -> Cell ( 30 , 3 , ' DIRECCIÓN:' , 1 , 0 , 'L' , true );
	$mipdf -> Cell ( 148 , 3 , $DirDes , 1 , 0 , 'L' , true );
	
	$mipdf -> Ln ( 4 );
}

	$mipdf -> Ln ( 0 );
	$mipdf -> SetFont ( 'Courier' , 'B', '8');
	$mipdf -> SetFillColor ( 208 , 72 , 69 );
	$mipdf -> SetTextColor (255 , 255 , 255);
	$TDC= "Total: ".$ID;
	$mipdf -> Cell ( 93 , 3 , '' , 0 , 0 , 'C' , true );
	$mipdf -> Cell ( 85 , 3 , $TDC , 0 , 0 , 'R' , true );

$consulta2 = mysql_query ("SELECT  * from tabla_trcarga WHERE NO_RUTA='$NoDocSEn' ORDER BY ID  ASC");	
$EscaY="38";
$EscaYN="40";
while ($datos2 = mysql_fetch_array($consulta2))
{
	$EscaY = $EscaY + 18;
	$EscaYN = $EscaY + 10;
	
	$DOCU2 = $datos2 [ 'DOCUMENTO' ];
		
	$mipdf -> SetFillColor ( 0 , 0 , 0 );
	$code=$DOCU2;
	//$mipdf->Code128(100,$EscaY,$code,80,20);
	$mipdf->Code128(105,$EscaY,$code,80,10);
	$mipdf->SetXY(130,$EscaYN);
	$mipdf->SetFont('Arial','',10);
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf->Write(5, "$code");
	
	$mipdf -> Ln ( 6 );
}
	
	$mipdf -> SetFillColor ( 0 , 0 , 0 );
	$code=$NoDocSEn;
	//$mipdf->Code128(100,$EscaY,$code,80,20);
	$mipdf->Code128(43,35,$code,80,10);
	$mipdf->SetXY(63,45);
	$mipdf->SetFont('Arial','',10);
	$mipdf -> SetTextColor (0 , 0 , 0);
	$mipdf->Write(5, "$code");
	
	
	$mipdf -> SetTextColor (0 , 0 , 0);

$mipdf -> Output();

}
?>