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/wallet.js
$(document).on('ready', function (e) {
    if (document.getElementById("btn-edit-fan"))
        document.getElementById("btn-edit-fan").disabled = true;
    $("#all_coins").on('keyup', function () {
        if ($(" #editCoin input[name='current_coins']").val() != $(" #editCoin input[name='all_coins']").val()) {
            document.getElementById("btn-edit-fan").disabled = false;
        } else {
            document.getElementById("btn-edit-fan").disabled = true;
        }
    });
    $("#credit_coins").on('keyup', function () {
        if ($(" #editCoin input[name='current_credit_coins']").val() != $(" #editCoin input[name='credit_coins']").val()) {
            document.getElementById("btn-edit-fan").disabled = false;
        } else {
            document.getElementById("btn-edit-fan").disabled = true;
        }
    });
});

/** Bloquear/Desbloquear credito hinchas switch */
function chkLocked(value) {
    var info = {
        id: value,
        state: !$("#checkLocked" + value).is(":checked"),
    };

    $.ajax({
        url: "/credit-coins/locked",
        type: "POST",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        data: JSON.stringify(info),
        success: function (r) {
            if (r.r) {
                swal("Ok", r.m);
            } else {
                swal("Error", Lang.get("messagesClient.wallet_coins_tag4"), "error");
            }
        },
    });
}

/** Visualizar transacciones de uso de las monedas del hincha */
function clickCreditDetail(value) {
    var info = {
        id: value,
    };

    $.ajax({
        url: "credit-coins/info",
        type: "POST",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        data: JSON.stringify(info),
        success: function (r) {
            coins = r.u;
            $("#coins").html(coins.all_coins + ' <i class="fa fa-money">');
            $("#locked").text(coins.locked ? 'Inactiva' : 'Activa');
            $("#lastdate").text(new Date(coins.updated_at).toLocaleString());

            $("#transfer_row").css("display", "none");
            $("#list_transactions").html('');
            transactions = coins.transactions;
            var table = `<table style="width: max-content;">
                <tr style="background-color: #ececec;">
                  <th style="padding: 5px 15px;">Tipo</th>
                  <th style="padding: 5px 15px;">Fecha</th>
                  <th style="padding: 5px 15px;">Referencia</th>
                  <th style="padding: 5px 15px;">Monedas</th>
                  <th style="padding: 5px 15px;">Detalle</th>
                  <th style="padding: 5px 15px;">Transacción cancelada</th>
                </tr>`;
            if (transactions.length > 0) {
                for (let i = 0; i < transactions.length; i++) {
                    table += `<tr>
                        <td style="padding: 5px 15px;">`+ (transactions[i].cancelled == 1 ? '<i class="fa fa-minus" style="color: orange;">' : (transactions[i].sign == 1 ? '<i class="fa fa-location-arrow" style="color: green;">' : '<i class="fa fa-location-arrow" style="color: red; transform: rotate(180deg);">')) + `</i></td>
                        <td style="padding: 5px 15px;">`+ toJSONLocal(transactions[i].created_at) + `</td>
                        <td style="padding: 5px 15px;">`+ transactions[i].reference + `</td>
                        <td style="padding: 5px 15px;  `+ (transactions[i].cancelled == 1 ? 'color: orange;' : (transactions[i].sign == 1 ? 'color: green;' : 'color: red;')) + `">` + (transactions[i].sign == 1 ? '' : '-') + transactions[i].coins + ` <i class="fa fa-money"></i></td>
                        <td style="padding: 5px 15px;">`+ transactions[i].detail + `</td>
                        <td style="padding: 5px 15px;">`+ (transactions[i].cancelled ? 'SI' : 'NO') + `</td>
                    </tr > `;
                }
            } else {
                table += `<tr>
                        <td style="padding: 5px 15px;">Ningún dato disponible en esta tabla</td>
                    </tr >`;
            }
            table += `</table > `;
            $("#list_transactions").append(table);
            $("#transfer_row").css("display", "block");
            $("#modal-info-coin").modal();
        }
    });
}

function clickCoinDetail(value) {
    var info = {
        id: value,
    };

    $.ajax({
        url: "coins/info",
        type: "POST",
        contentType: "application/json",
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        data: JSON.stringify(info),
        success: function (r) {
            coins = r.u;
            $("#coins").html(coins.all_coins + ' <i class="fa fa-money">');
            $("#locked").text(coins.locked ? 'Inactiva' : 'Activa');
            $("#lastdate").text(new Date(coins.updated_at).toLocaleString());

            $("#transfer_row").css("display", "none");
            $("#list_transactions").html('');
            transactions = coins.transactions;
            var table = `<table style="width: max-content;">
                <tr style="background-color: #ececec;">
                  <th style="padding: 5px 15px;">Tipo</th>
                  <th style="padding: 5px 15px;">Fecha</th>
                  <th style="padding: 5px 15px;">Referencia</th>
                  <th style="padding: 5px 15px;">Monedas</th>
                  <th style="padding: 5px 15px;">Detalle</th>
                  <th style="padding: 5px 15px;">Transacción cancelada</th>
                </tr>`;
            if (transactions.length > 0) {
                for (let i = 0; i < transactions.length; i++) {
                    table += `<tr>
                        <td style="padding: 5px 15px;">`+ (transactions[i].cancelled == 1 ? '<i class="fa fa-minus" style="color: orange;">' : (transactions[i].sign == 1 ? '<i class="fa fa-location-arrow" style="color: green;">' : '<i class="fa fa-location-arrow" style="color: red; transform: rotate(180deg);">')) + `</i></td>
                        <td style="padding: 5px 15px;">`+ toJSONLocal(transactions[i].created_at) + `</td>
                        <td style="padding: 5px 15px;">`+ transactions[i].reference + `</td>
                        <td style="padding: 5px 15px;  `+ (transactions[i].cancelled == 1 ? 'color: orange;' : (transactions[i].sign == 1 ? 'color: green;' : 'color: red;')) + `">` + (transactions[i].sign == 1 ? '' : '-') + transactions[i].coins + ` <i class="fa fa-money"></i></td>
                        <td style="padding: 5px 15px;">`+ transactions[i].detail + `</td>
                        <td style="padding: 5px 15px;">`+ (transactions[i].cancelled ? 'SI' : 'NO') + `</td>
                    </tr > `;
                }
            } else {
                table += `<tr>
                        <td style="padding: 5px 15px;">Ningún dato disponible en esta tabla</td>
                    </tr >`;
            }
            table += `</table > `;
            $("#list_transactions").append(table);
            $("#transfer_row").css("display", "block");
            $("#modal-info-coin").modal();
        }
    });
}

/** Abrir formulario para editar saldo de monedas del hincha */
function clickUpdateCreditCoins(value) {
    _table = $("#example2").DataTable();
    index = _table.page();
    localStorage.setItem("productsTableIndex", index);
    $(location).attr("href", "/credit-coins/edit/" + value);
}

function clickUpdateCoins(value) {
    _table = $("#example2").DataTable();
    index = _table.page();
    localStorage.setItem("productsTableIndex", index);
    $(location).attr("href", "/coins/edit/" + value);
}

/** Actualizar saldo de monedas del hincha */
function updateUserCreditCoins() {
    $("#editCoin").validator("update");
    $("#editCoin")
        .validator("update")
        .on("submit", function (e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();
                var info = {
                    id: $("#btn-edit-fan").attr("data-id"),
                    all_coins: $(" #editCoin input[name='all_coins']").val(),
                    credit_coins: $(" #editCoin input[name='credit_coins']").val()
                };
                swal(Lang.get("messagesClient.wallet_coins_tag2"), {
                    buttons: {
                        cancel: "No",
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $.ajax({
                            url: "/credit-coins/update",
                            type: "POST",
                            contentType: "application/json",
                            headers: {
                                "X-CSRF-TOKEN": $(
                                    'meta[name="csrf-token"]'
                                ).attr("content"),
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(info),
                            success: function (r) {
                                if (r.r) {
                                    swal(r.m, {
                                        icon: "success",
                                        buttons: {
                                            Ok: true,
                                        },
                                    }).then((val) => {
                                        if (val == "Ok") {
                                            localStorage.setItem(
                                                "setPageTable",
                                                true
                                            );
                                            $(location).attr("href", "/credit-coins");
                                        }
                                    });
                                } else {
                                    swal("Error", r.m, "error");
                                }
                            },
                            error: function (e) {
                                swal(
                                    "Error", Lang.get("messagesClient.wallet_coins_tag3"), "error"
                                );
                            },
                        });
                    }
                });
            }
        });
}

function updateUserCoins() {
    $("#editCoin").validator("update");
    $("#editCoin")
        .validator("update")
        .on("submit", function (e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();
                var info = {
                    id: $("#btn-edit-fan").attr("data-id"),
                    all_coins: $(" #editCoin input[name='all_coins']").val()
                };
                swal(Lang.get("messagesClient.wallet_coins_tag2"), {
                    buttons: {
                        cancel: "No",
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $.ajax({
                            url: "/coins/update",
                            type: "POST",
                            contentType: "application/json",
                            headers: {
                                "X-CSRF-TOKEN": $(
                                    'meta[name="csrf-token"]'
                                ).attr("content"),
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(info),
                            success: function (r) {
                                if (r.r) {
                                    swal(r.m, {
                                        icon: "success",
                                        buttons: {
                                            Ok: true,
                                        },
                                    }).then((val) => {
                                        if (val == "Ok") {
                                            localStorage.setItem("setPageTable", true);
                                            $(location).attr("href", "/coins");
                                        }
                                    });
                                } else {
                                    swal("Error", r.m, "error");
                                }
                            },
                            error: function (e) {
                                swal(
                                    "Error", Lang.get("messagesClient.wallet_coins_tag3"), "error"
                                );
                            },
                        });
                    }
                });
            }
        });
}

/** Abrir panel de transacciones */
function clickTransactionCancellationCredit(value) {
    _table = $("#example2").DataTable();
    index = _table.page();
    localStorage.setItem("productsTableIndex", index);
    $(location).attr("href", "/credit-coins/transactions/" + value);
}

function clickTransactionCancellation(value) {
    _table = $("#example2").DataTable();
    index = _table.page();
    localStorage.setItem("productsTableIndex", index);
    $(location).attr("href", "/coins/transactions/" + value);
}

function clickCancelTransaction(value) {
    var info = {
        id: value
    };
    swal(Lang.get("messagesClient.wallet_coins_tag5"), {
        buttons: {
            cancel: "No",
            Ok: true,
        },
    }).then((val) => {
        if (val == "Ok") {
            $.ajax({
                url: "/credit-coins/cancel",
                type: "POST",
                contentType: "application/json",
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                    "Content-Type": "application/json",
                },
                data: JSON.stringify(info),
                success: function (r) {
                    if (r.r) {
                        swal(r.m, {
                            icon: "success",
                            buttons: {
                                Ok: true,
                            },
                        }).then((val) => {
                            if (val == "Ok") {
                                localStorage.setItem(
                                    "setPageTable",
                                    true
                                );
                                location.reload();
                            }
                        });
                    } else {
                        swal("Error", Lang.get("messagesClient.wallet_coins_tag4"), "error");
                    }
                },
            });
        }
    });
}

function toJSONLocal(date) {
    let local = new Date(date);
    return local.toJSON().slice(0, 10) + ' ' + local.toLocaleTimeString();
}

/** Actualizar saldo de monedas del hincha */
function createUserCreditCoins() {
    $("#addCoin").validator("update");
    $("#addCoin")
        .validator("update")
        .on("submit", function (e) {
            if (e.isDefaultPrevented()) {
            } else {
                e.preventDefault();
                var info = {
                    email: $(" #addCoin input[name='email']").val().trim(),
                    credit_coins: $(" #addCoin input[name='credit_coins']").val()
                };
                swal(Lang.get("messagesClient.wallet_coins_tag6"), {
                    buttons: {
                        cancel: "No",
                        Ok: true,
                    },
                }).then((val) => {
                    if (val == "Ok") {
                        $.ajax({
                            url: "/credit-coins/create",
                            type: "POST",
                            contentType: "application/json",
                            headers: {
                                "X-CSRF-TOKEN": $(
                                    'meta[name="csrf-token"]'
                                ).attr("content"),
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(info),
                            success: function (r) {
                                if (r.r) {
                                    swal(r.m, {
                                        icon: "success",
                                        buttons: {
                                            Ok: true,
                                        },
                                    }).then((val) => {
                                        if (val == "Ok") {
                                            localStorage.setItem("setPageTable", true);
                                            $(location).attr("href", "/credit-coins");
                                        }
                                    });
                                } else {
                                    swal("Error", r.m, "error");
                                }
                            },
                            error: function (e) {
                                swal(
                                    "Error", Lang.get("messagesClient.wallet_coins_tag3"), "error"
                                );
                            },
                        });
                    }
                });
            }
        });
}

function importCreditCoins() {
    var archivo = document.getElementById("archivo");
    var t = $("#example22").DataTable();
    var state;
    archivo = archivo.files[0];
    t.clear().draw();
    if (archivo) {
        var formData = new FormData();
        formData.append("archivo", archivo);

        $("#buttonImportCreditCoins").addClass("displayNone");
        $("#spinnerImportCreditCoins").removeClass("displayNone");
        $.ajax({
            type: "POST",
            dataType: "json",
            processData: false,
            contentType: false,
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            },
            data: formData,
            url: "/credit-coins/import",
            success: function (r) {
                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,
                            });

                            message = r.d[i].message;
                            state = r.d[i].state;
                        }

                        if (state == false) {
                            $('#modalImportCreditCoins').modal('hide');
                            $('#logModal').modal("show");
                            t.draw();
                        }
                    } else if (r.r) {
                        swal(r.m, {
                            icon: "success",
                            buttons: {
                                Ok: true,
                            },
                        }).then((val) => {
                            if (val == "Ok") {
                                $(location).attr("href", "/credit-coins");
                            }
                        });
                    }
                } else {
                    swal("Error", "¡Error al subir el archivo!", "error");
                    $("#buttonImportCreditCoins").removeClass("displayNone");
                    $("#spinnerImportCreditCoins").addClass("displayNone");
                }
            },
        });
    } else {
        swal("Ok", "¡No hay archivo!", "warning");
    }
}

function closeLogCreditCoins() {
    $(location).attr("href", "/credit-coins");
}