HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
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');
    }

}