File: /var/www/vhost/disk-apps/demo.sports-crowd.com/public/abonados/abonados.js
let total_price = 0;
let abonos_array = [];
let user_document;
let presuscription = false;
var formatter = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: 0,
});
function validateUser() {
total_price = 0;
$('#user_info').attr('hidden', true);
$('#total_price').attr('hidden', true);
$('#name_user').empty();
$('#documento_user').empty();
$('#user_mail').empty();
$('#subscriber_table').empty();
$('#price_total').empty();
$('#price_total').append(formatter.format(total_price));
document_user = $('#user_document').val();
user_document = document_user;
if (!document_user) {
swal('¡Atención!', 'Ingresa tu documento de identidad', 'warning');
return;
}
$("#button_send").addClass("hide");
$("#button_loading").removeClass("hide");
$.ajax({
url: "/abonados/validate/" + document_user,
type: "GET",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json",
},
success: function (r) {
$("#button_loading").addClass("hide");
$("#button_send").removeClass("hide");
if (r.r) {
$('#user_document').val('');
$('#user_info').attr('hidden', false);
$('#name_user').append(r.user.first_name + ' ' + r.user.last_name);
$('#documento_user').append(r.user.document);
$('#user_mail').append(r.user.email);
r.pre_subscriber.forEach(rep => {
if (rep.payment === 0) {
$('#subscriber_table').append(
'<tr><td>' + rep.seat.zone.zone.name + ' - ' + rep.seat.zone.name + ' - ' + rep.seat.letter.name + ' - ' + rep.seat.code + '</td><td>' + formatter.format(rep.price) + '</td><td><input type="checkbox" onChange="checkAbono(' + rep.id + ',' + rep.price + ')" data-id="' + rep.id + '" id="checkactive' + rep.id + '" /></td></tr>'
);
} else {
$('#subscriber_table').append(
'<tr><td>' + rep.seat.zone.zone.name + ' - ' + rep.seat.zone.name + ' - ' + rep.seat.letter.name + ' - ' + rep.seat.code + '</td><td>' + formatter.format(rep.price) + '</td><td>Comprado</td></tr>'
);
}
});
$('#total_price').attr('hidden', false);
} else {
swal('¡Atención!', r.message, 'warning').then((val) => {
if (val) {
$('#user_document').val('');
}
});
}
},
error: function (e) {
$("#button_loading").addClass("hide");
$("#button_send").removeClass("hide");
swal("Error", e.responseJSON.message, "error");
},
});
}
function checkAbono(id_silla, price) {
$('#price_total').empty();
if ($('#checkactive' + id_silla).prop('checked')) {
total_price = total_price + price;
$('#price_total').append(formatter.format(total_price));
abonos_array.push(id_silla);
} else {
total_price = total_price - price;
$('#price_total').append(formatter.format(total_price));
abonos_array = abonos_array.filter((i) => i !== id_silla);
}
}
function makePayment() {
if (abonos_array.length == 0) {
swal('¡Atención!', 'Por favor selecciona un abono', 'warning');
return;
}
var info = {
user_abonado: user_document,
abonados_array: abonos_array
};
$("#button_send_sell").addClass("hide");
$("#button_loading_sell").removeClass("hide");
$.ajax({
url: "/abonados/payment",
type: "PUT",
contentType: "application/json",
data: JSON.stringify(info),
success: function (response) {
$("#button_loading_sell").addClass("hide");
$("#button_send_sell").removeClass("hide");
if (response.r) {
window.open('/abonados/purchase/' + response.data, "_self");
} else {
swal('¡Atención!', response.m, 'warning');
return;
}
},
error: function (e) {
$("#button_loading_sell").addClass("hide");
$("#button_send_sell").removeClass("hide");
swal("Error", e.responseJSON.message, "error");
},
});
}