Added Account section
This commit is contained in:
44
account/billing_history/billing_history.css
Normal file
44
account/billing_history/billing_history.css
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@import url('/global.css');
|
||||
|
||||
.balance-negative {
|
||||
color: #F00;
|
||||
}
|
||||
|
||||
.balance-positive {
|
||||
color: #008000;
|
||||
}
|
||||
|
||||
#billing-history {
|
||||
padding: 15px 15px 15px;
|
||||
}
|
||||
|
||||
#current {
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
td:nth-of-type(3) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
tr {
|
||||
border-bottom: 1px solid #E8E8E8;
|
||||
}
|
210
account/billing_history/billing_history.js
Normal file
210
account/billing_history/billing_history.js
Normal file
@ -0,0 +1,210 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.balance = "balance";
|
||||
elements.balanceNegative = "balance-negative";
|
||||
elements.billingTable = "billing-table";
|
||||
elements.lmcRow = "lmc-tr1";
|
||||
elements.lmcRowAlt = "lmc-tr2";
|
||||
elements.loading = "loading";
|
||||
|
||||
// Data received from API calls
|
||||
var data = {};
|
||||
data.invoices = [];
|
||||
data.payments = [];
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.balance = {};
|
||||
ui.billingTable = {};
|
||||
ui.loading = {};
|
||||
|
||||
// Temporary state
|
||||
var state = {};
|
||||
state.haveInvoices = false;
|
||||
state.havePayments = false;
|
||||
|
||||
// Creates a row for the billing table
|
||||
var createBillingRow = function(item, alt)
|
||||
{
|
||||
var row = document.createElement("tr");
|
||||
if (alt)
|
||||
row.className = elements.lmcRowAlt;
|
||||
else
|
||||
row.className = elements.lmcRow;
|
||||
|
||||
var dateCell = document.createElement("td");
|
||||
var date = new Date(item.date + "Z");
|
||||
dateCell.innerHTML = date.toLocaleDateString();
|
||||
row.appendChild(dateCell);
|
||||
|
||||
var description = document.createElement("td");
|
||||
var amount = document.createElement("td");
|
||||
|
||||
if (item.year) {
|
||||
// Yearly payment report
|
||||
var span1 = document.createElement("span");
|
||||
span1.innerHTML = "Yearly Payments Report (";
|
||||
var link = document.createElement("a");
|
||||
link.href = "/account/paymentreceiptyear?year=" + item.year;
|
||||
link.innerHTML = item.year;
|
||||
var span2 = document.createElement("span");
|
||||
span2.innerHTML = ")";
|
||||
description.appendChild(span1);
|
||||
description.appendChild(link);
|
||||
description.appendChild(span2);
|
||||
} else if (item.label) {
|
||||
// Invoice
|
||||
var link = document.createElement("a");
|
||||
link.href = "/account/invoice?iid=" + item.id;
|
||||
link.innerHTML = item.label;
|
||||
description.appendChild(link);
|
||||
|
||||
if (item.total < 0)
|
||||
amount.innerHTML = "($" + (-item.total).toFixed(2) + ")";
|
||||
else
|
||||
amount.innerHTML = "$" + item.total.toFixed(2);
|
||||
} else {
|
||||
// Payment
|
||||
var link = document.createElement("a");
|
||||
link.href = "/account/paymentreceipt?pid=" + item.id;
|
||||
link.innerHTML = "Payment";
|
||||
var thanks = document.createElement("span");
|
||||
thanks.innerHTML = " - Thank you";
|
||||
description.appendChild(link);
|
||||
description.appendChild(thanks);
|
||||
|
||||
if (item.usd > 0)
|
||||
amount.innerHTML = "($" + item.usd.toFixed(2) + ")";
|
||||
else
|
||||
amount.innerHTML = "$" + (-item.usd).toFixed(2);
|
||||
}
|
||||
|
||||
row.appendChild(description);
|
||||
row.appendChild(amount);
|
||||
|
||||
return row;
|
||||
};
|
||||
|
||||
// Populate billing table with invoices and payments
|
||||
var displayAll = function()
|
||||
{
|
||||
// Remove loading row
|
||||
ui.loading.remove();
|
||||
|
||||
// Combine to single array
|
||||
var combined = data.invoices.concat(data.payments);
|
||||
|
||||
// Insert yearly payment reports
|
||||
var now = new Date();
|
||||
var lowestYear = now.getFullYear();
|
||||
for (var i = 0; i < combined.length; i++) {
|
||||
var date = new Date(combined[i].date + "Z");
|
||||
if (date.getFullYear() < lowestYear)
|
||||
lowestYear = date.getFullYear();
|
||||
}
|
||||
for (var i = now.getFullYear(); i >= lowestYear; i--) {
|
||||
combined.push({
|
||||
"date": i + "-01-01T12:00:00",
|
||||
"year": i
|
||||
});
|
||||
}
|
||||
|
||||
// Sort
|
||||
combined.sort(function(a, b)
|
||||
{
|
||||
var aDate = new Date(a.date + "Z");
|
||||
var bDate = new Date(b.date + "Z");
|
||||
return bDate - aDate;
|
||||
});
|
||||
|
||||
// Insert
|
||||
for (var i = 0; i < combined.length; i++)
|
||||
ui.billingTable.appendChild(createBillingRow(combined[i], ui.billingTable.children.length % 2));
|
||||
};
|
||||
|
||||
// Callback for account details API call
|
||||
var displayBalance = function(response)
|
||||
{
|
||||
ui.balance.innerHTML = "$" + response.balance.toFixed(2);
|
||||
if (response.balance < 0) {
|
||||
ui.balance.innerHTML += " credit";
|
||||
} else if (response.balance > 0) {
|
||||
ui.balance.innerHTML += " outstanding";
|
||||
ui.balance.className = elements.balanceNegative;
|
||||
}
|
||||
};
|
||||
|
||||
// Callback for invoices API call
|
||||
var displayInvoices = function(response)
|
||||
{
|
||||
data.invoices = data.invoices.concat(response.data);
|
||||
|
||||
// Request the next page if there are more
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/account/invoices?page=" + (response.page + 1), displayInvoices, null);
|
||||
return;
|
||||
}
|
||||
|
||||
state.haveInvoices = true;
|
||||
if (state.havePayments)
|
||||
displayAll();
|
||||
};
|
||||
|
||||
// Callback for payments API call
|
||||
var displayPayments = function(response)
|
||||
{
|
||||
data.payments = data.payments.concat(response.data);
|
||||
|
||||
// Request the next page if there are more
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/account/payments?page=" + (response.page + 1), displayPayments, null);
|
||||
return;
|
||||
}
|
||||
|
||||
state.havePayments = true;
|
||||
if (state.haveInvoices)
|
||||
displayAll();
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
setupHeader();
|
||||
|
||||
// Get element references
|
||||
ui.balance = document.getElementById(elements.balance);
|
||||
ui.billingTable = document.getElementById(elements.billingTable);
|
||||
ui.loading = document.getElementById(elements.loading);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/account", displayBalance, null);
|
||||
apiGet("/account/invoices", displayInvoices, null);
|
||||
apiGet("/account/payments", displayPayments, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
52
account/billing_history/index.shtml
Normal file
52
account/billing_history/index.shtml
Normal file
@ -0,0 +1,52 @@
|
||||
<!--
|
||||
This file is part of Linode Manager Classic.
|
||||
|
||||
Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>LMC - Account // Billing History</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="billing_history.css" />
|
||||
<script src="billing_history.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<!--#include virtual="/include/account_subnav.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="billing-history">
|
||||
<table class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="3">Billing History</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Date</td>
|
||||
<td>Description</td>
|
||||
<td>Amount</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="billing-table">
|
||||
<tr id="loading" class="lmc-tr1">
|
||||
<td colspan="3">Loading...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p id="current">Current Balance <span id="balance" class="balance-positive"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user