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

use simitsdk\phpjasperxml\PHPJasperXML;

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

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

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


SELECT
    pro.nombre AS promocion,
    COUNT(DETP.id_premio) AS Premios_entregados,
    pro_premio.precio_unitario,
    pro_premio.premio,
    pro_premio.detalle,
    (COUNT(DETP.id_premio) * pro_premio.precio_unitario) AS TOTAL_bs,
    MONTH(gan.fecha) AS mes,
    UPPER(CONCAT(MONTHNAME(gan.fecha), ' ', YEAR(gan.fecha))) AS mes_ano,
    0.00 AS Variable_1
FROM
    promocion AS pro
    INNER JOIN pro_ganador AS gan ON pro.id_promocion = gan.id_promocion
    INNER JOIN pro_det_premio AS DETP ON gan.premio = DETP.id_det_premio
    INNER JOIN pro_premio ON DETP.id_premio = pro_premio.id_premio 
	
	WHERE
	( pro.estado = 1 ) 
	
GROUP BY
    pro.nombre,
    pro_premio.premio,
    pro_premio.detalle,
    pro_premio.cantidad,
    pro_premio.precio_unitario,
    gan.fecha
    
ORDER BY
gan.fecha ASC
  ,
   
    TOTAL_bs 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);

?>
