<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	if ($_GET['id'] == 1)			// 4 X 4
	{
		if (!empty($_POST['lista']))
		{
			require('code128.php');
			$pdf = new PDF_Code128('P','mm',array(102,102));
			// Ciclo para mostrar las casillas checked checkbox.
			foreach($_POST['lista'] as $selected)
			{
				$pdf -> AddPage();
				$pdf -> SetFont('Arial','',35);
			
				$code = $selected;
				$pdf -> Cell(0,10,'GRUPO MAMPA',0,1,'C');
				$pdf -> Code128(10,22,$code,80,20);
				$pdf -> Cell(0,61,$code,0,1,'C');
			}
			$pdf -> Output();
		}
	}
	if ($_GET['id'] == 2)			// 2 X 3
	{
		if (!empty($_POST['lista']))
		{
			require('code128.php');
			$pdf = new PDF_Code128('L','mm',array(75,45));
			// Ciclo para mostrar las casillas checked checkbox.
			foreach($_POST['lista'] as $selected)
			{
				// conexión
				$servername = $svr_servidor;
				$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
				$conexion = sqlsrv_connect($servername, $conectioninfo);
				if ($conexion == false)
				{
					$mensaje = "Existe un error al intentar conectarse con el servidor...";
				}
				else
				{
					// CONSULTA SQL
					$sql = "SELECT * FROM JOIN_UBICACIONES WHERE (IDUBICACION = ".$selected.")";
					$pa1 = array();
					$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
					// Lanzar la consulta
					$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
					while($fila = sqlsrv_fetch_array($re1))
					{
						$cV01 = $fila['CODUBICACION'];
					}
					sqlsrv_free_stmt($re1);
				}
				sqlsrv_close($conexion);
		
				$pdf -> AddPage();
				$pdf -> SetFont('Arial','',14);
			
				$code = $selected;
				$pdf -> Text(15,8,'GRUPO MAMPA '.$code);
				$pdf -> Code128(10,10,$code,65,18);
				$pdf -> Text(15,40,$cV01);
			}
			$pdf -> Output();
		}
	}
	if ($_GET['id'] == 3)			// 5 X 8
	{
		if (!empty($_POST['lista']))
		{
			require('code128.php');
			$pdf = new PDF_Code128('L','mm',array(75,45));
			// Ciclo para mostrar las casillas checked checkbox.
			foreach($_POST['lista'] as $selected)
			{
				$code = $selected;
				$fecha = date('Y-m-d');
				$pdf -> AddPage();
				$pdf -> SetFont('Arial','',24);
				$pdf -> Text(16,10,$fecha);
				$pdf -> SetFont('Arial','',35);
				$pdf -> Code128(5,11,$code,65,20);
				$pdf -> Text(10,42,$code);
			}
			$pdf -> Output();
		}
	}
	if ($_GET['id'] == 4)			// 2 X 1
	{
		if (!empty($_POST['lista']))
		{
			require('code128.php');
			$pdf = new PDF_Code128('L','mm',array(50,25));
			// Ciclo para mostrar las casillas checked checkbox.
			foreach($_POST['lista'] as $selected)
			{
				// conexión
				$servername = $svr_servidor;
				$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
				$conexion = sqlsrv_connect($servername, $conectioninfo);
				if ($conexion == false)
				{
					$mensaje = "Existe un error al intentar conectarse con el servidor...";
				}
				else
				{
					// CONSULTA SQL
					$sql = "SELECT PL.CODARTICULO, PL.REFERENCIA, A.DESCRIPCION, PL.TALLA, PL.COLOR, PL.NUMLINEA, L.CODBARRAS \n"
						  ."FROM PEDCOMPRACAB AS PC \n"
						  ."INNER JOIN PEDCOMPRALIN AS PL ON (PC.NUMSERIE = PL.NUMSERIE) AND (PC.NUMPEDIDO = PL.NUMPEDIDO) \n"
						  ."INNER JOIN ARTICULOS AS A ON (PL.CODARTICULO = A.CODARTICULO) \n"
						  ."INNER JOIN ARTICULOSLIN AS L ON (A.CODARTICULO = L.CODARTICULO) \n"
						  ."WHERE (PL.NUMSERIE = '".$_POST['serie']."') AND (PL.NUMPEDIDO = ".$_POST['numero'].") AND (PL.NUMLINEA = ".$selected.")";
					$pa1 = array();
					$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
					// Lanzar la consulta
					$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
					while($fila = sqlsrv_fetch_array($re1))
					{
						$cV01 = $fila['REFERENCIA'];
						$cV02 = $fila['DESCRIPCION'];
						$cV03 = $fila['TALLA'];
						$cV04 = $fila['COLOR'];
						$cV05 = $fila['CODBARRAS'];
					}
					sqlsrv_free_stmt($re1);
				}
				sqlsrv_close($conexion);
		
				$pdf -> AddPage();
				$pdf -> SetFont('Arial','',8);
			
				$pdf -> Code128(2,1,$cV05,47,8);
				$pdf -> Text(2,12,$cV05);
				$pdf -> Text(2,15.5,$cV02);
				$pdf -> Text(2,19.5,'Referencia: '.$cV01);
				$pdf -> Text(2,23,'Talla: '.$cV03.' Color: '.$cV04);
			}
			$pdf -> Output();
		}
	}
	if ($_GET['id'] == 5)			// ETIQUETA PICKING
	{
		require('code128.php');
		$pdf = new PDF_Code128('L','mm',array(75,45));
		$variable = explode('|',$_POST['cETQ']);
		$auxiliar = "";
		for ($i = 0; $i <= substr_count($_POST['cETQ'],"|"); $i++){
			if (($i % 4) == 0 && $i > 0){
				if ($variable[$i-1] != ''){
					$pdf -> AddPage();
					$pdf -> SetFont('Arial','',18);
					$pdf -> Text(15,6,$variable[$i-4]."-".$variable[$i-3]);
					$pdf -> SetFont('Arial','',18);
					$pdf -> Text(15,12,$variable[$i-2]);
					$pdf -> SetFont('Arial','',35);
					$pdf -> Code128(5,13,$variable[$i-1],65,22);
					$pdf -> SetFont('Arial','',28);
					$pdf -> Text(10,43,$variable[$i-1]);
				}
			}
		}
		$pdf -> Output();
	}
?>