update and remove global stock portfolio positions

This commit is contained in:
Justin 2023-09-26 15:43:27 +08:00 committed by GitHub
parent 12cf1fa1bc
commit 934026d6ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3586,7 +3586,6 @@ function removeStockPorftolio() {
}
// update stock portfolio position with new values
function updateStockPorftolio() {
@ -3651,6 +3650,102 @@ function updateStockPorftolio() {
}
// remove global stock portfolio position
function removeGlobalStockPorftolio() {
let remove_globalstock_symbol = document.getElementById('globalstocks_symbol').value;
if (remove_globalstock_symbol !== '') {
document.getElementById('globalstocks_port_cost').value = '';
document.getElementById('globalstocks_port_shares').value = '';
document.getElementById('globalstocks_port_date').value = '';
fetch("/deleteGlobalPortfolioPosition", {
method: "POST",
body: JSON.stringify(remove_globalstock_symbol),
});
document.getElementById('globalstockremoved-p').innerHTML = 'Global stock Position Removed!';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
else {
document.getElementById('globalstockremoved-p').innerHTML = 'No symbol selected.';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
}
// update global stock portfolio position with new values
function updateGlobalStockPorftolio() {
let update_globalstock_cost = document.getElementById('globalstocks_port_cost').value;
let update_globalstock_shares = document.getElementById('globalstocks_port_shares').value;
let update_globalsymbol = document.getElementById('globalstocks_symbol').value;
let update_globalstock_days = document.getElementById('globalstocks_port_date').value;
let update_globalstock_settings = {
shares:update_globalstock_shares,
cost:update_globalstock_cost,
symbol:update_globalsymbol,
days:update_globalstock_days,
};
if ((update_globalsymbol === '') || (update_globalsymbol === ' ')) {
document.getElementById('globalstockremoved-p').innerHTML = 'No symbol selected.';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
else if ((update_globalstock_cost === ' ') || (update_globalstock_shares === ' ') || (update_globalstock_days === ' ')) {
document.getElementById('globalstockremoved-p').innerHTML = 'No spaces.';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
else if ((isNaN(update_globalstock_cost)) || (isNaN(update_globalstock_shares))) {
document.getElementById('globalstockremoved-p').innerHTML = 'No text characters, only numbers.';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
else if ((!update_globalstock_days.includes('-')) && (update_globalstock_days !== '')) {
document.getElementById('globalstockremoved-p').innerHTML = 'Incorrect date format, it should be YYYY-MM-DD';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
else if (((update_globalstock_shares !== '') || (update_globalstock_cost !== '') || (update_globalstock_days !== '')) && ((update_globalstock_shares === '') || (update_globalstock_cost === '') || (update_globalstock_days === ''))) {
document.getElementById('globalstockremoved-p').innerHTML = 'Some fields are empty.';
document.getElementById('removed-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-globalstock-p').style.display = "none";
}, 5000);
}
else {
fetch("/saveGlobalPortfolioSettings", {
method: "POST",
body: JSON.stringify(update_globalstock_settings),
});
document.getElementById('updated-globalstock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('updated-globalstock-p').style.display = "none";
}, 5000);
}
}
// remove crypto portfolio position
function removeCryptoPorftolio() {