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/comfama.sports-crowd.com/public/js/fans.js
$(document).ready(function () {
    let div_price = $("#div_price");
    let div_file = $("#div_file");
    let div_user = $("#div_user");

    div_price.hide();
    div_user.hide();
    div_file.hide();

    _table = $("#example2").DataTable({
        responsive: true,
        processing: true,
        serverSide: false,
        order: [],
        language: {
            url: "https://cdn.datatables.net/plug-ins/1.10.19/i18n/Spanish.json",
        },
        columns: [
            { data: "line", name: "line", width: "10%" },
            { data: "message", name: "message", width: "90%" },
        ],
    });
});

function validateTicketTypeFields() {
    let name_ticket_type_id = $("#name_ticket_type_id").val();
    let div_price = $("#div_price");
    // Tipo credito
    if (name_ticket_type_id == 4) {
        div_price.show();
        $("#zone_id").empty();
        // Tipo cortesia
    } else if (name_ticket_type_id == 3) {
        div_price.val(0);
        div_price.hide();
    }
}

function searchUser() {
    let user_document = $("#user_document").val();
    let ticket_type_id = $("#name_ticket_type_id").val();
    let name_ticket_type = $("#name_ticket_type_id option:selected").text();
    let match_event_id = $("#name_match_event_id").val();

    if (!ticket_type_id || !match_event_id) {
        swal("Por favor indique el evento y tipo de boleta");
        return;
    }

    $("#user_data").val("");

    if (user_document && user_document != "") {
        $.ajax({
            url: `/tickets/user/${user_document}/${match_event_id}/${ticket_type_id}`,
            type: "GET",
            contentType: "application/json",
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                "Content-Type": "application/json",
            },
            success: function (r) {
                if (r.r) {
                    var current_user = r.data;
                    if (!current_user) {
                        swal(
                            "Advertencia",
                            "¡Documento no encontrado!",
                            "warning"
                        );

                        return;
                    }

                    $("#user_data").val(
                        user_document +
                        " - " +
                        current_user.first_name +
                        " " +
                        current_user.last_name +
                        " - " +
                        current_user.email
                    );
                    $("#document").val(user_document);
                    if (current_user) {
                        $("#user_id").val(current_user.id);
                    }

                    if (r.tickets > 0) {
                        swal({
                            title: "",
                            icon: "info",
                            text:
                                "Este usuario ya cuenta con " +
                                r.tickets +
                                " boletas de " +
                                name_ticket_type +
                                ", desea reenviar el email ?",
                            buttons: {
                                cancel: "Cancelar",
                                Ok: "Continuar",
                            },
                        }).then((result) => {
                            if (result == "Ok") {
                                resendEmail(
                                    current_user.id,
                                    match_event_id,
                                    ticket_type_id
                                );
                            }
                        });
                    }
                }
            },
        });
    } else {
        swal("Advertencia", "¡Debes ingresar un documento valido!", "warning");
    }
}

function resendEmail(user_id, match_event_id, ticket_type_id) {
    let formData = new FormData();
    formData.append("user_id", user_id);
    formData.append("match_event_id", match_event_id);
    formData.append("ticket_type_id", ticket_type_id);

    $.ajax({
        url: "/tickets/resend/list",
        method: "POST",
        dataType: "json",
        processData: false,
        contentType: false,
        data: formData,
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
        },
        success: (r) => {
            if (r.s) {
                swal("", r.m, "success");
            } else {
                swal("", r.m, "error");
            }
        },
        error: (e) => { },
    });
}

function loadSubZones() {
    let main_zone_id = $("#main_zone_id").val();
    let match_event_id = $("#name_match_event_id").val();
    $("#zone_id").empty();
    if (!main_zone_id) {
        return;
    }

    $.ajax({
        url: "/get_sub_zones/" + main_zone_id + '/' + match_event_id,
        method: "GET",
        success: (r) => {
            fillSubZones(r);
        },
        error: (r) => { },
    });
}

function loadPriceForZone() {
    let zone_id = $("#zone_id").val();
    let match_event_id = $("#name_match_event_id").val();
    let price = $("#price");
    let name_ticket_type_id = $("#name_ticket_type_id").val();

    // Si es cortesia precio = 0.
    if (name_ticket_type_id == 3) {
        price.val(0);
    }

    // Soloobtiene precio para tipo crédito.
    if (name_ticket_type_id != 4) {
        return;
    }
    $.ajax({
        url: "/get_price_zone/" + zone_id + "/" + match_event_id,
        method: "GET",
        success: (r) => {
            if (r) {
                price.val(r.price);
            } else {
                price.val(0);
            }
        },
        error: (r) => { },
    });
}

function fillSubZones(subzones) {
    let zone_id = $("#zone_id").empty();
    zone_id.append(
        `<option value="" disabled required selected>-- Seleccione</option>`
    );
    subzones.forEach((s) => {
        zone_id.append(`<option value="${s.id}">${s.name}</option>`);
    });
}

function validateGenerationTypeFields() {
    let generation_type_id = $("#generation_type_id").val();

    let div_price = $("#div_price");
    let div_file = $("#div_file");
    let div_location = $("#div_location");
    let div_user = $("#div_user");

    // Tipo aleatoria
    if (generation_type_id == "random") {
        div_price.val(0);
        div_file.hide();
        div_location.show();
        div_user.show();
    } else if (generation_type_id == "template") {
        div_price.val(0);
        div_file.show();
        div_location.hide();
        div_user.hide();
    }
}

function beginProcessImport() {
    let generation_type_id = $("#generation_type_id").val();
    let generation_type_text = $("#generation_type_id option:selected").text();
    let user_name = $("#user_document").val();

    if (!generation_type_id) {
        swal("Completa los datos");
        return;
    }

    swal({
        title: "Confirmación",
        icon: "info",
        text:
            "Desea generar el proceso: \n Tipo: " +
            generation_type_text +
            "\n Para el usuario: " +
            user_name,
        buttons: {
            cancel: "Cancelar",
            Ok: "Continuar",
        },
    }).then((result) => {
        if (result == "Ok") {
            if (generation_type_id == "template") {
                importFile();
            } else if (generation_type_id == "random") {
                importRandom();
            } else {
                swal(
                    "",
                    "Por favor indique el proceso que desea realizar",
                    "error"
                );
            }
        }
    });
}

function importRandom() {
    var t = $("#example2").DataTable();
    t.clear().draw();

    let ticket_type_id = $("#name_ticket_type_id").val();
    var match_event_id = $("#name_match_event_id").val();
    var price = $("#price").val();
    var user_id = $("#user_id").val();
    var zone_id = $("#zone_id").val();
    var quantity = $("#quantity").val();

    if (
        !ticket_type_id ||
        !match_event_id ||
        !user_id ||
        !zone_id ||
        !quantity
    ) {
        swal("", "Por favor complete todos los datos!", "error");
        return;
    }

    if (!price) {
        price = 0;
    }

    var formData = new FormData();
    formData.append("ticket_type_id", ticket_type_id);
    formData.append("match_event_id", match_event_id);
    formData.append("price", price);
    formData.append("user_id", user_id);
    formData.append("zone_id", zone_id);
    formData.append("quantity", quantity);

    $("#button-import-product").addClass("displayNone");
    $("#spinnerButtonProduct").removeClass("displayNone");

    $.ajax({
        url: "/massive_fans/import_random",
        method: "POST",
        dataType: "json",
        processData: false,
        contentType: false,
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
        },
        data: formData,
        success: (r) => {
            $("#button-import-product").removeClass("displayNone");
            $("#spinnerButtonProduct").addClass("displayNone");

            if (r.r) {
                swal("", r.m, "success");
            } else {
                swal("Error", r.m + "\n" + r.d, "error");
            }
        },
        error: (e) => {
            $("#button-import-product").removeClass("displayNone");
            $("#spinnerButtonProduct").addClass("displayNone");
        },
    });
}

function importFile() {
    var t = $("#example2").DataTable();
    var fExcel = document.getElementById("importFans");
    var state;
    var items = [];
    fExcel = fExcel.files[0];

    t.clear().draw();
    if (fExcel) {
        var nameFile = document.getElementById("importFans").files[0].name;
        var name_ticket_type_id = $("#name_ticket_type_id").val();
        var match_event_id = $("#name_match_event_id").val();
        var price = $("#price").val();

        if (name_ticket_type_id === null) {
            swal("", "Debes seleccionar el tipo de boleta.!", "error");
        }

        if (!price) {
            price = 0;
        }

        var formData = new FormData();
        formData.append("importFans", fExcel);

        if (name_ticket_type_id) {
            formData.append("name_file", nameFile);
            formData.append("name_ticket_type_id", name_ticket_type_id);
        }
        if (match_event_id) {
            formData.append("name_match_event_id", match_event_id);
        }

        if (price) {
            formData.append("price", price);
        }

        $("#button-import-product").addClass("displayNone");
        $("#spinnerButtonProduct").removeClass("displayNone");
        $.ajax({
            type: "POST",
            dataType: "json",
            processData: false,
            contentType: false,
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            },
            data: formData,
            url: "/massive_fans/import",
            success: function (r) {
                $("#button-import-product").removeClass("displayNone");
                $("#spinnerButtonProduct").addClass("displayNone");

                if (r.d != null) {
                    if (r.d.length > 0) {
                        for (var i = 0; i < r.d.length; i++) {
                            t.row.add({
                                message: r.d[i].message,
                                line: r.d[i].line,
                            });
                            items.push(r.d[i].message);
                            state = r.d[i].state;
                        }
                        t.draw();
                        var message = `(${items.join('","')})`;
                        console.log(message);
                        if (state == false) {
                            swal("Existen errores por favor revise el log", {
                                icon: "error",
                                timer: 3700,
                                showConfirmButton: false,
                                buttons: false,
                            });
                        }
                    } else if (r.r) {
                        swal(r.m, {
                            icon: "success",
                            buttons: {
                                Ok: true,
                            },
                        }).then((val) => {
                            if (val == "Ok") {
                                $(location).attr("href", "/massive_fans");
                            }
                        });
                    }
                } else {
                    swal("Error", r.m, "error");
                }
            },
            error: function (err) {
                $("#button-import-product").removeClass("displayNone");
                $("#spinnerButtonProduct").addClass("displayNone");
            },
        });
    } else {
        swal("", "No hay archivo", "error");
    }
}