File: /var/www/vhost/disk-apps/teamdemo.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");
archivo = archivo.files[0];
if (!archivo) {
swal("Advertencia", "¡No hay archivo!", "warning");
return;
}
var t = $("#example22").DataTable();
t.clear().draw();
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) {
$("#buttonImportCreditCoins").removeClass("displayNone");
$("#spinnerImportCreditCoins").addClass("displayNone");
if (r.r) {
if (r.d != null && r.d.length > 0) {
for (var i = 0; i < r.d.length; i++) {
t.row.add([
r.d[i].message,
r.d[i].line,
]);
}
$('#modalImportCreditCoins').modal("hide");
$('#logModal').modal("show");
t.draw();
} else {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/credit-coins");
}
});
}
} else {
swal("Error", r.m, "error");
}
},
error: function (err) {
$("#buttonImportCreditCoins").removeClass("displayNone");
$("#spinnerImportCreditCoins").addClass("displayNone");
swal("Error", err.responseJSON.message, "error");
}
});
}
function closeLogCreditCoins() {
$(location).attr("href", "/credit-coins");
}