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/flash_ticket_selling.js
var matchEvent;
var total;

function selectEvent(sel) {
    matchEvent = JSON.parse(sel.value);
    if (matchEvent.web_price != null) {
        $('#web_price_container').show();
        $('#web_price').val(matchEvent.web_price);
        $('#web_amount_label').html('Boletas (' + matchEvent.maximum_user_ticket_sales_box_office + ' Max)');
    }

    if (matchEvent.special_price != null) {
        $('#special_price_container').show();
        $('#special_price').val(matchEvent.special_price);
    }

    if (matchEvent.courtesy_price != null) {
        $('#courtesy_price_container').show();
        $('#courtesy_price').val(matchEvent.courtesy_price);
    }

    clearData();
    $('#total_container').show();
}

function getSoldTicketsCount() {
    $.ajax({
        url: "/flash_ticket/getSoldCount/" + matchEvent.match_event_id + "/" + matchEvent.zone_id,
        type: "GET",
        contentType: "application/json",
        async: false,
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
            "Content-Type": "application/json",
        },
        success: function (r) {
            if (r.r) {
                let detail = (r.d + ' Boletas vendidas') + ' / ' + (matchEvent.salable_capacity + ' Max. capacidad boletas');
                $('#available_tickets').html(detail);
            }
        },
    });
}

function calculateRelativeTotal(id) {
    switch (id) {
        case 'web_amount':
            if ($('#web_amount').val() > matchEvent.maximum_user_ticket_sales_box_office) {
                $('#web_amount').val(matchEvent.maximum_user_ticket_sales_box_office);
            }
            $('#web_total_price').val($('#web_amount').val() * matchEvent.web_price);
            break;
        case 'special_amount':
            especialAmount = $('#special_amount').val();
            $('#special_total_price').val(especialAmount * matchEvent.special_price);
            if (!especialAmount || especialAmount == 0) {
                $('#special_text').val('');
            }
            break;
        case 'courtesy_amount':
            courtesyAmount = $('#courtesy_amount').val();
            $('#courtesy_total_price').val(courtesyAmount * matchEvent.courtesy_price);
            if (!courtesyAmount || courtesyAmount == 0) {
                $('#courtesy_text').val('');
            }
            break;
    }
    calculateTotal();
    showPaymentButton();
}

function calculateTotal() {
    total =
        Number($('#web_total_price').val()) +
        Number($('#special_total_price').val()) +
        Number($('#courtesy_total_price').val());

    $('#total').html('Total: $' + total);
}

function showPaymentButton() {
    tickets =
        Number($('#web_amount').val()) +
        Number($('#special_amount').val()) +
        Number($('#courtesy_amount').val());

    if (tickets > 0) {
        $('#div_footer').show();
    } else {
        $('#div_footer').hide();
    }
}

function buyTickets(parameters) {
    specialAmount = $('#special_amount').val();
    specialText = $('#special_text').val();
    courtesyAmount = $('#courtesy_amount').val();
    courtesyText = $('#courtesy_text').val();

    if (courtesyAmount && courtesyAmount > 0 && !courtesyText) {
        swal(Lang.get("messagesClient.flash_ticket.tag_4"), {
            text: Lang.get("messagesClient.flash_ticket.tag_4"),
            icon: 'warning',
            showCancelButton: true,
            cancelButtonColor: '#d33',
        });
        return;
    }

    if (!tickets) {
        swal(Lang.get("messagesClient.flash_ticket.tag_2"), {
            text: "",
            icon: 'warning',
            showCancelButton: true,
            cancelButtonColor: '#d33',
        });
    }


    showActionsAlert = parameters.flash_ticket_selling_confirmation;
    if (showActionsAlert) {
        swal(Lang.get("messagesClient.flash_ticket.tag_1"), {
            buttons: {
                cancel: "No",
                Ok: true,
            },
        }).then((val) => {
            if (val == "Ok") {
                sendDataToApi(showActionsAlert);
            }
        });
    } else {
        sendDataToApi(showActionsAlert);
    }
}


function sendDataToApi(showActionsAlert) {
    var info = {
        total: total,
        web_amount: $('#web_amount').val(),
        special_amount: specialAmount,
        courtesy_amount: courtesyAmount,
        flash_ticket_configuration_id: matchEvent.id,
        special_text: specialText,
        courtesy_text: courtesyText,
    };

    $('#loading').show();
    $.ajax({
        url: "/flash_ticket/buy",
        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) {
            $('#loading').hide();
            if (r.r) {
                tickets = r.d.join();
                if (showActionsAlert) {
                    swal(r.m, {
                        icon: "success",
                        buttons: {
                            cancel: "Seguir vendiendo",
                            Ok: "Imprimir",
                        },
                    }).then((val) => {
                        if (val == "Ok") {
                            print(tickets);
                        } else {
                            $(location).attr("href", window.location.pathname);
                        }
                    });
                } else {
                    print(tickets);
                }
            } else {
                if (r.r == false) {
                    swal("Error", r.m, "error");
                } else {
                    swal("Error", Lang.get("messagesClient.user_client_tag3"), "error");
                }
            }
        },
    });
}

function clearData() {
    $('#web_amount').val('');
    $('#special_amount').val('');
    $('#courtesy_amount').val('');
    $('#web_total_price').val('');
    $('#special_total_price').val('');
    $('#courtesy_total_price').val('');
    $('#special_text').val('');
    $('#courtesy_text').val('');
    calculateTotal();
    showPaymentButton();
    getSoldTicketsCount();
}

function print(tickets) {
    clearData
    window.open(window.location.origin + '/tickets/pdf/' + tickets);
}