<?php
//require __DIR__."./../phpJasperXML_2.0.1/autoload.php";
require_once("./../phpJasperXML_2.0.1/autoload.php");

use simitsdk\phpjasperxml\PHPJasperXML;

$filename = __DIR__."/lista_p.jrxml";

// read parameters
//$no_placa = $_SESSION['no_placa'] ; 	// invoice identification to obtain

// Read record
$data = array();
$rs = DB::Query("

SELECT
	
ga.id_ganador as id,

	ga.fecha,


ROW_NUMBER() OVER (
		ORDER BY ga.id_ganador
	) id_ganador,
	
	
	
	
	
	CONCAT( ga.nombres, ' ', ga.apellido_paterno, ' ', ga.apellido_materno ) AS Ganador,
	ga.ci,
	pr.detalle AS premio_detalle,
	ga.telefono,
	ga.placa,
	pre.cantidad_max AS M3_GNV,
	tv.nombre AS tipo_vehiculo,
	pro.nombre AS promocion,
	pr.premio,
	l.alias AS procedencia 
FROM  
	pro_ganador AS ga
	INNER JOIN pro_participante AS par ON ga.placa = par.placa
	INNER JOIN pro_det_premio AS pre ON ga.premio = pre.id_det_premio
	INNER JOIN pro_premio AS pr ON pre.id_premio = pr.id_premio
	INNER JOIN aux AS tv ON par.tipo_vehiculo = tv.id_aux
	INNER JOIN promocion AS pro ON ga.id_promocion = pro.id_promocion
	LEFT JOIN aux AS l ON ga.procedencia = l.id_aux
	INNER JOIN promocion AS pro2 ON par.id_promocion = pro2.id_promocion
WHERE
	( pro2.estado = 1 AND pro.estado = 1 ) 
ORDER BY
ga.id_ganador ASC


");
while( $row= $rs->fetchAssoc() )
{
$data[] = $row;
}
$config = [
    'driver'=>'array',
    'data'=> $data
];
$parameters = [];


$type = 'Pdf';
$fileOutput= '';
$creator = 'bi-softnet';
$author = 'xbi-softnet@gmail.com';
$title = 'Consumo';
$keywords = 'PHP';
$format_intl = 'es_ES';

// $temp_file = tempnam(sys_get_temp_dir(), 'pdf');  // Create file temporal
// $fileOutput = $temp_file;

$report = new PHPJasperXML();
$report->load_xml_file($filename)    
    ->setParameter($parameters)
    ->setDataSource($config)
    ->export($type,$fileOutput,$title,$creator,$author,$keywords,$format_intl);

?>
