<?php
include("../conexion/conex.php");
include ('class.ezpdf.php');
$pdf =& new Cezpdf();
$pdf->selectFont('./fonts/Helvetica.afm');
$fecha=date('Y-m-d');
$rut=$_GET['ruta'];
$tabla=$_GET['tabla'];
$plani=$_GET['planilla'];
$link = conn_mysql();

$pdf->addJpegFromFile($rut,35,780,70,30);
$pdf->addText(230,790,8,'Reporte Detallado - Planilla No '.$plani);
$pdf->ezStartPageNumbers(552,800,8,'','Pagina: {PAGENUM} de {TOTALPAGENUM}',1);
$pdf->addText(492,785,8,'Fecha: '.$fecha);
/*Cuadro 1*/
$pdf->line(32,810,110,810);//Horizontal Superior
$pdf->line(32,780,110,780);//Horizontal Inferior
$pdf->line(32,810,32,780);//1era. Linea Vertical
$pdf->line(110,780,110,810);//2da. Linea Vertical
/*Cuadro Titulo*/
$pdf->line(120,810,470,810);//Horizontal Superior
$pdf->line(120,780,470,780);//Horizontal Inferior
$pdf->line(120,810,120,780);//1era. Linea Vertical
$pdf->line(470,780,470,810);//2da. Linea Vertical
/*Cuadro Arriba*/
$pdf->line(480,810,573,810);//Horizontal Superior
$pdf->line(480,780,573,780);//Horizontal Inferior
$pdf->line(480,810,480,780);//1era. Linea Vertical
$pdf->line(573,780,573,810);//2da. Linea Vertical
$pdf->ezSetMargins(80,20,40,20);

$sql_rep="SELECT g.orden, g.guia, c.cod_cliente, c.nombre as nom_cli,  o.producto, g.destinatario, g.direccion, 
					 g.ciudad, o.peso, o.valor, g.telefono, g.id_estado, m.nombre, m.id_mensajero, m.id_sucursal,
                     eg.nombre as nom_est
			from $tabla as g 
				 inner join mensajeros as m on (g.id_mensajero=m.id_mensajero)
				 inner join ordenes as o on (g.orden=o.orden)
				 inner join clientes as c on(g.id_cliente=c.id_cliente)
				 inner join estados_gestion as eg on (eg.id_estado=g.id_estado)
			where g.id_planilla='".$planilla."' order by g.orden, g.guia"; 

		$rs_val=mysql_query($sql_rep, $link);	
		
		while ($row_rep=mysql_fetch_array($rs_val)){
			$dato['CLIENTE']=trim($row_rep['nom_cli']);
			$dato['ORDEN']=trim($row_rep['orden']);
			$dato['PRODUCTO']=trim($row_rep['producto']);
			$dato['GUIA']=trim($row_rep['guia']);
			$dato['DESTINATARIO']=trim($row_rep['destinatario']);
			$dato['DIRECCION']=trim($row_rep['direccion']);
			$dato['CIUDAD']=trim($row_rep['ciudad']);
			$dato['PESO']=trim($row_rep['peso']);
			$dato['VALOR']=$row_rep['valor'];
			$dato['ESTADO']=$row_rep['nom_est'];
			$datos[]=$dato;
		}
	
		
		$pdf->ezTable($datos,'','',array('fontSize' => 6,'showHeadings' => 1,'shaded'=> 1,
	   'shadeCol' => array(0.96,0.96,0.96),'shadeCol2' => array(0.9,0.9,0.9), 'cols'=>array(
	  											'CLIENTE'=>array('justification'=>'left','width'=>60), 
												'ORDEN'=>array('justification'=>'left','width'=>40), 
										  		'PRODUCTO'=>array('justification'=>'left','width'=>60), 
										  		'GUIA'=>array('justification'=>'left','width'=>30), 
										  		'DESTINATARIO'=>array('justification'=>'left','width'=>100), 
										  		'DIRECCION'=>array('justification'=>'left','width'=>90),
										  		'CIUDAD'=>array('justification'=>'left','width'=>60), 
										  		'PESO'=>array('justification'=>'right','width'=>30), 
										  		'VALOR'=>array('justification'=>'right','width'=>35),
												'ESTADO'=>array('justification'=>'left','width'=>65)
	
	)));

	
$pdf->ezStream();
?>