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/qas.sports-crowd.com/app/Http/Controllers/ReportStateController.php
<?php

namespace App\Http\Controllers;

use App\Core\Ticket\TicketStatusEnum;
use App\Core\Ticket\TicketTypesEnum;
use App\MatchEvent;
use Carbon\Carbon;
use CSVReport;
use PdfReport;
use DB;

class ReportStateController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $events = MatchEvent::select('id', 'name', 'event_start', 'active')->orderBy('active', 'desc')->orderBy('created_at', 'desc')->get();
        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;
            case 'consolidado':
                return $this->reportTicketsConsolidated($event_id);
                break;
        }
    }

    public static function clean($string)
    {
        if (!$string) {
            return "";
        }
        $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

        return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
    }

    public function reportTicketsConsolidated($event_id)
    {
        $title = "Reporte consolidado";
        $event = MatchEvent::find($event_id);

        $meta = [ // For displaying filters description on header
            'Evento' => $title . ' - ' . $event->name . '(' . $event->id . ')',
            'Fecha evento' => $event->event_start,
            'Código evento' => $event->code,
            'Fecha impresión reporte' => Carbon::now()->format('d/m/Y H:i:s'),
            'Tipo' => 'Tickets vendidos'
        ];

        $queryBuilder = DB::table('tickets')
            ->select('match_events.name', 'match_events.code', 'zsub.name as zone',  DB::raw('sum(tickets.price) as total'), DB::raw('count(tickets.id) as t_tickets'))
            ->join('ticket_mains', 'tickets.ticket_main_id', '=', 'ticket_mains.id')
            ->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
            ->join('seats as s', 'tickets.seat_id', '=', 's.id')
            ->join('zones as z', 's.zone_id', '=', 'z.id')
            ->join('zones as zsub', 'z.zone_id', '=', 'zsub.id')
            ->where('tickets.match_event_id', $event_id)
            ->whereIn('tickets.ticket_status_id', [TicketStatusEnum::PURCHASED, TicketStatusEnum::CREATED])
            ->whereIn('tickets.ticket_type_id', [TicketTypesEnum::FREE_SALE, TicketTypesEnum::SUBSCRIBER, TicketTypesEnum::CREDIT])
            ->groupBy('zsub.id', 'match_events.name', 'match_events.code', 'zsub.name');

        $columns = [
            'Nombre Evento' => 'name',
            'Codigo evento' => 'code',
            'Tribuna' => 'zone',
            'Cant. Tickets' => 't_tickets',
            'Total' => 'total'
        ];

        return PdfReport::of($title, $meta, $queryBuilder, $columns)
            ->editColumns(['Total'], [ // Mass edit column
                'class' => 'right bold'
            ])
            ->editColumns(['Cant. Tickets'], [ // Mass edit column
                'class' => 'right bold'
            ])
            ->showTotal([ // Used to sum all value on specified column on the last table (except using groupBy method). 'point' is a type for displaying total with a thousand separator
                'Total' => 'point', // if you want to show dollar sign ($) then use 'Total Balance' => '$'
                'Cant. Tickets' => 'point'
            ])
            ->download('Reporte consolidado - ' . $event->name);
    }

    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.code_seat',
                'tickets.price',
                'tickets.created_at AS fecha_compra',
                'users.first_name',
                'users.last_name',
                'users.document',
                'ticket_types.name AS type_ticket',
                's.zone_id',
                'tickets.letter_seat as letter',
                'z.zone_id as id_sub_zone',
                'zsub.name as tribune'
            ])
            ->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
            ->join('users', 'tickets.user_id', '=', 'users.id')
            ->join('ticket_types', 'tickets.ticket_type_id', '=', 'ticket_types.id')
            ->join('seats as s', 'tickets.seat_id', '=', 's.id')
            ->join('zones as z', 's.zone_id', '=', 'z.id')
            ->join('zones as zsub', 'z.zone_id', '=', 'zsub.id')
            ->where('tickets.match_event_id', $event_id)
            ->whereIn('tickets.ticket_status_id', [TicketStatusEnum::PURCHASED, TicketStatusEnum::CREATED])
            ->whereIn('tickets.ticket_type_id', [TicketTypesEnum::FREE_SALE, TicketTypesEnum::SUBSCRIBER, TicketTypesEnum::CREDIT]);

        $columns = [
            'ID' => 'id',
            'Nombre Evento' => 'name',
            'Codigo evento' => 'code',
            'Tribuna' => 'tribune',
            'Sector' => 'zone',
            'Silla' => 'code_seat',
            'Fila' => 'letter',
            'Tipo de boleta' => 'type_ticket',
            'Precio' => 'price',
            'Fecha compra' => 'fecha_compra',
        ];

        $name = stripslashes(str_replace('/', '', $event->name));
        return CSVReport::of($title, $meta, $queryBuilder, $columns)->download($name . ' - Hacienda - 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.code_seat',
                'tickets.price',
                'tickets.created_at AS fecha_compra',
                'users.first_name',
                'users.last_name',
                'users.document',
                'ticket_types.name AS type_ticket',
                's.zone_id',
                'tickets.letter_seat as letter',
                'z.zone_id as id_sub_zone',
                'zsub.name as tribune'
            ])
            ->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
            ->join('users', 'tickets.user_id', '=', 'users.id')
            ->join('ticket_types', 'tickets.ticket_type_id', '=', 'ticket_types.id')
            ->join('seats as s', 'tickets.seat_id', '=', 's.id')
            ->join('zones as z', 's.zone_id', '=', 'z.id')
            ->join('zones as zsub', 'z.zone_id', '=', 'zsub.id')
            ->where('tickets.match_event_id', $event_id)
            ->whereIn('tickets.ticket_status_id', [TicketStatusEnum::CANCELLED, TicketStatusEnum::REVERSED]);

        $columns = [
            'ID' => 'id',
            'Nombre Evento' => 'name',
            'Codigo evento' => 'code',
            'Tribuna' => 'tribune',
            'Sector' => 'zone',
            'Silla' => 'code_seat',
            'Fila' => 'letter',
            'Tipo de boleta' => 'type_ticket',
            'Precio' => 'price',
            'Fecha compra' => 'fecha_compra',
        ];

        $name = stripslashes(str_replace('/', '', $event->name));
        return CSVReport::of($title, $meta, $queryBuilder, $columns)->download($name . ' - Hacienda - 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.code_seat',
                'tickets.price',
                'tickets.created_at AS fecha_compra',
                'users.first_name',
                'users.last_name',
                'users.document',
                'ticket_types.name AS type_ticket',
                's.zone_id',
                'tickets.letter_seat as letter',
                'z.zone_id as id_sub_zone',
                'zsub.name as tribune'
            ])
            ->join('match_events', 'tickets.match_event_id', '=', 'match_events.id')
            ->join('users', 'tickets.user_id', '=', 'users.id')
            ->join('ticket_types', 'tickets.ticket_type_id', '=', 'ticket_types.id')
            ->join('seats as s', 'tickets.seat_id', '=', 's.id')
            ->join('zones as z', 's.zone_id', '=', 'z.id')
            ->join('zones as zsub', 'z.zone_id', '=', 'zsub.id')
            ->where('tickets.match_event_id', $event_id)
            ->whereIn('tickets.ticket_status_id', [TicketStatusEnum::PURCHASED, TicketStatusEnum::CREATED])
            ->whereIn('tickets.ticket_type_id', [TicketTypesEnum::COMPLIMENTARY]);

        $columns = [
            'ID' => 'id',
            'Nombre Evento' => 'name',
            'Codigo evento' => 'code',
            'Tribuna' => 'tribune',
            'Sector' => 'zone',
            'Silla' => 'code_seat',
            'Fila' => 'letter',
            'Tipo de boleta' => 'type_ticket',
            'Precio' => 'price',
            'Fecha compra' => 'fecha_compra',
        ];

        $name = stripslashes(str_replace('/', '', $event->name));
        return CSVReport::of($title, $meta, $queryBuilder, $columns)->download($name . ' - Hacienda - Cortesias');
    }
}