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/public/js/complimentary_tickets.js
function viewComplimentaryTickets(ticketMainId, userId) {
    $(location).attr("href", "/complimentary_tickets/details/" + ticketMainId + "/" + userId);
}

function changeSeats(ticketMainId, userId, zoneId, element, showModal = true) {
    if (showModal) {
        showZoneModal(zoneId, function (selectedZoneId) {
            $("#zoneId").val(selectedZoneId);
            changeSeats(ticketMainId, userId, zoneId, element, false);
        });
        return;
    }

    var dataLog = $(element).attr("data-log");
    $.ajax({
        url: "/complimentary_tickets/changeSeats",
        type: "POST",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        data: JSON.stringify({
            ticketMainId: ticketMainId,
            userId: userId,
            zoneId: parseInt($("#zoneId").val()),
            dataLog: dataLog,
        }),
        success: function (response) {
            if (response.success) {
                swal(response.message, {
                    icon: "success",
                    buttons: {
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $(location).attr("href", "/complimentary_tickets");
                    }
                });
            } else {
                swal("Error", response.message, "error");
            }
        },
        error: function (xhr, status, error) {
            swal("Error", xhr.responseJSON.message, "error");
        }
    });
}

function showZoneModal(zoneId, callback) {
    $.get('/tickets/childZones/' + zoneId, function (response) {
        if (!response.r) {
            swal("Error", response.m, "error");
            return;
        }
        let zones = response.data;
        let $select = $('#modalZoneSelect');
        $select.empty().append('<option value="">Selecciona una zona</option>');
        zones.forEach(function (zone) {
            $select.append(`<option value="${zone.id}">${zone.name}</option>`);
        });
    });

    $('#zoneModal').modal('show');

    $('#confirmZoneBtn').off('click').on('click', function () {
        let selectedZoneId = $('#modalZoneSelect').val();
        if (selectedZoneId) {
            $('#zoneModal').modal('hide');
            callback(selectedZoneId);
        } else {
            swal("Warning", "Debes seleccionar una zona", "warning");
        }
    });
}

function changeEmail(ticketMainId, userId, element, email = null) {
    if (!email) {
        swal({
            text: "Por favor ingresa el nuevo correo electrónico:",
            content: "input",
            buttons: {
                cancel: {
                    text: "Cancelar",
                    visible: true,
                    className: "",
                    closeModal: true,
                },
                confirm: {
                    text: "Enviar",
                    closeModal: false,
                },
            },
        }).then(inputEmail => {
            if (inputEmail === null) {
                return;
            }

            if (!inputEmail) {
                swal("Warning", "No se ingresó ningún correo", "warning");
                return;
            }

            if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inputEmail)) {
                swal("Error", "Correo electrónico no válido", "error");
                return;
            }

            changeEmail(ticketMainId, userId, element, inputEmail);
        });
        return;
    }

    var dataLog = $(element).attr("data-log");
    $.ajax({
        url: "/complimentary_tickets/changeEmail",
        type: "POST",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        data: JSON.stringify({
            ticketMainId: ticketMainId,
            userId: userId,
            email: email,
            dataLog: dataLog,
        }),
        success: function (response) {
            if (response.success) {
                swal(response.message, {
                    icon: "success",
                    buttons: {
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $(location).attr("href", "/complimentary_tickets");
                    }
                });
            } else {
                swal("Error", response.message, "error");
            }
        },
        error: function (xhr, status, error) {
            swal("Error", xhr.responseJSON.message, "error");
        }
    });
}

function sendEmailNotification(ticketMainId, userId, element) {
    swal({
        text: "¿Estás seguro de que deseas reenviar la notificación de cortesias por correo electrónico?",
        buttons: {
            cancel: {
                text: "Cancelar",
                visible: true,
                className: "",
                closeModal: true,
            },
            confirm: {
                text: "Enviar",
                closeModal: false,
            },
        },
    }).then((val) => {
        if (val === null) {
            return;
        }

        var dataLog = $(element).attr("data-log");
        $.ajax({
            url: "/complimentary_tickets/sendEmailNotification",
            type: "POST",
            contentType: "application/json",
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                "Content-Type": "application/json",
            },
            data: JSON.stringify({
                ticketMainId: ticketMainId,
                userId: userId,
                dataLog: dataLog,
            }),
            success: function (response) {
                if (response.success) {
                    swal(response.message, {
                        icon: "success",
                        buttons: {
                            Ok: true,
                        },
                    }).then((val) => {
                        if (val == "Ok") {
                            $(location).attr("href", "/complimentary_tickets");
                        }
                    });
                } else {
                    swal("Error", response.message, "error");
                }
            },
            error: function (xhr, status, error) {
                swal("Error", xhr.responseJSON.message, "error");
            }
        });
    });
}

function cancelComplimentaryTickets(ticketMainId, userId, element) {
    swal({
        text: "¿Estás seguro de anular todas las cortesias de este usuario?",
        buttons: {
            cancel: {
                text: "Cancelar",
                visible: true,
                className: "",
                closeModal: true,
            },
            confirm: {
                text: "Enviar",
                closeModal: false,
            },
        },
    }).then((val) => {
        if (val === null) {
            return;
        }

        var dataLog = $(element).attr("data-log");
        $.ajax({
            url: "/complimentary_tickets/cancelComplimentaryTickets",
            type: "POST",
            contentType: "application/json",
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                "Content-Type": "application/json",
            },
            data: JSON.stringify({
                ticketMainId: ticketMainId,
                userId: userId,
                dataLog: dataLog,
            }),
            success: function (response) {
                if (response.success) {
                    swal(response.message, {
                        icon: "success",
                        buttons: {
                            Ok: true,
                        },
                    }).then((val) => {
                        if (val == "Ok") {
                            $(location).attr("href", "/complimentary_tickets");
                        }
                    });
                } else {
                    swal("Error", response.message, "error");
                }
            },
            error: function (xhr, status, error) {
                swal("Error", xhr.responseJSON.message, "error");
            }
        });
    });
}