File: /var/www/vhost/disk-apps/agile-selling-wpb/app/Http/Controllers/ReportStateController.php
<?php
namespace App\Http\Controllers;
use App\MatchEvent;
use App\Ticket;
use Carbon\Carbon;
use Illuminate\Http\Request;
use ExcelReport;
use DB;
// Libreria: https://github.com/Jimmy-JS/laravel-report-generator
class ReportStateController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$events = MatchEvent::all();
return view("reports_state.reports_state", compact('events'));
}
public function generateReport($type, $event_id){
switch($type){
case 'anulada':
return $this->reportReversedAndReject($event_id);
break;
case 'cortesia':
return $this->reportCourtesy($event_id);
break;
case 'vendida':
return $this->reportTicketsSold($event_id);
break;
}
}
public function reportTicketsSold($event_id){
$title = "Ticket vendidos";
$event = MatchEvent::find($event_id);
$meta = [ // For displaying filters description on header
'Evento' => $title. ' - '. $event->name,
'Fecha impresión reporte' => Carbon::now()->format('d/m/Y H:i:s'),
'Tipo' => 'Tickets vendidos'
];
// Query a mostrar en el reporte
$queryBuilder = DB::table('tickets')
->select(['tickets.id', 'match_events.name', 'match_events.code', 'tickets.zone', 'tickets.code_ticket', 'tickets.price', 'tickets.created_at AS fecha_compra'])
->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
->where('tickets.match_event_id', $event_id) // Del evento
->where(function($query){
$query->where('tickets.ticket_status_id', 1) // Comprado
->orWhere('tickets.ticket_status_id', 2); // Ingresado
}) //
->where(function ($query) {
$query->where('tickets.ticket_type_id', 1) // Venta libre
->orWhere('tickets.ticket_type_id', 2); // Abonados
});
$columns = [
'ID' => 'id',
'Nombre Evento' => 'name',
'Codigo evento' => 'code',
'Zona' => 'zone',
'Código ticket' => 'code_ticket',
'Precio' => 'price',
'Fecha compra' => 'fecha_compra'
];
return ExcelReport::of($title, $meta, $queryBuilder, $columns)
->download($event->name . ' - Vendidas');
}
public function reportReversedAndReject($event_id){
$title = "Ticket reversados y anulados";
$event = MatchEvent::find($event_id);
$meta = [ // For displaying filters description on header
'Evento' => $title. ' - '. $event->name,
'Fecha impresión reporte' => Carbon::now()->format('d/m/Y H:i:s'),
'Tipo' => 'Tickets Reversados y anulados'
];
// Query a mostrar en el reporte
$queryBuilder = DB::table('tickets')
->select(['tickets.id', 'match_events.name', 'match_events.code', 'tickets.zone', 'tickets.code_ticket', 'tickets.price', 'tickets.created_at AS fecha_compra'])
->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
->where('tickets.match_event_id', $event_id) // Del evento
->where(function($query){
$query->where('tickets.ticket_status_id', 3) // Comprado
->orWhere('tickets.ticket_status_id', 4); // Ingresado
});
$columns = [
'ID' => 'id',
'Nombre Evento' => 'name',
'Codigo evento' => 'code',
'Zona' => 'zone',
'Código ticket' => 'code_ticket',
'Precio' => 'price',
'Fecha compra' => 'fecha_compra'
];
return ExcelReport::of($title, $meta, $queryBuilder, $columns)
->download($event->name . ' - Reversados y anulados');
}
public function reportCourtesy($event_id){
$title = "Tickets de cortesía";
$event = MatchEvent::find($event_id);
$meta = [ // For displaying filters description on header
'Evento' => $title. ' - '. $event->name,
'Fecha impresión reporte' => Carbon::now()->format('d/m/Y H:i:s'),
'Tipo' => 'Tickets cortesia'
];
// Query a mostrar en el reporte
$queryBuilder = DB::table('tickets')
->select(['tickets.id', 'match_events.name', 'match_events.code', 'tickets.zone', 'tickets.code_ticket', 'tickets.price', 'tickets.created_at AS fecha_compra'])
->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
->where('tickets.match_event_id', $event_id) // Del evento
->where(function($query){
$query->where('tickets.ticket_status_id', 1) // Comprado
->orWhere('tickets.ticket_status_id', 2); // Ingresado
}) //
->where(function ($query) {
$query->where('tickets.ticket_type_id', 3); // Cortesia
});
$columns = [
'ID' => 'id',
'Nombre Evento' => 'name',
'Codigo evento' => 'code',
'Zona' => 'zone',
'Código ticket' => 'code_ticket',
'Precio' => 'price',
'Fecha compra' => 'fecha_compra'
];
return ExcelReport::of($title, $meta, $queryBuilder, $columns)
->download($event->name . ' - Cortesias');
}
}