Added Account section

This commit is contained in:
2020-03-13 23:01:39 -04:00
parent dd1809473c
commit 396ca2366e
80 changed files with 5330 additions and 107 deletions

View File

@ -0,0 +1,68 @@
<!--
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 // View Invoice</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="invoice.css" />
<script src="invoice.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="invoice">
<table id="invoice-table" class="lmc-table">
<thead>
<tr>
<td colspan="8"><strong>Invoice #<span id="invoice-id"></span></strong></td>
</tr>
<tr>
<td>Description</td>
<td>From</td>
<td>To</td>
<td>Quantity</td>
<td>Unit Price</td>
<td>Subtotal</td>
<td>Tax</td>
<td>Total</td>
</tr>
</thead>
<tbody id="invoice-body"></tbody>
</table>
<table id="totals">
<tbody>
<tr>
<td>Subtotal:</td>
<td id="subtotal"></td>
</tr>
<tr>
<td>Tax:</td>
<td id="tax"></td>
</tr>
<tr>
<td>Invoice Total:</td>
<td id="total"></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,59 @@
/*
* 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');
#invoice {
padding: 15px 15px 15px;
}
#invoice-table td:nth-of-type(4) {
text-align: center;
}
#invoice-table td:nth-of-type(5) {
text-align: center;
}
#invoice-table td:nth-of-type(6) {
text-align: right;
}
#invoice-table td:nth-of-type(7) {
text-align: right;
}
#invoice-table td:nth-of-type(8) {
text-align: right;
}
.lmc-table tbody:not(.lmc-tbody-head) tr:last-of-type {
border-bottom: 1px solid #E8E8E8;
}
#totals {
margin: 20px 0 0 auto;
text-align: right;
}
#totals td {
padding: 5px;
}
#totals tr:last-of-type {
font-weight: bold;
}

151
account/invoice/invoice.js Normal file
View File

@ -0,0 +1,151 @@
/*
* 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.invoiceBody = "invoice-body";
elements.invoiceID = "invoice-id";
elements.lmcRow = "lmc-tr1";
elements.lmcRowAlt = "lmc-tr2";
elements.subnav = "subnav-link";
elements.subnavActive = "subnav-link-active";
elements.subtotal = "subtotal";
elements.tax = "tax";
elements.total = "total";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.invoiceBody = {};
ui.invoiceID = {};
ui.subtotal = {};
ui.tax = {};
ui.total = {};
// Generates an invoice item table row
var createItemRow = function(item, alt)
{
var row = document.createElement("tr");
if (alt)
row.className = elements.lmcRowAlt;
else
row.className = elements.lmcRow;
var description = document.createElement("td");
description.innerHTML = item.label;
row.appendChild(description);
var from = document.createElement("td");
var fromDate = new Date(item.from + "Z");
from.innerHTML = fromDate.toLocaleString();
row.appendChild(from);
var to = document.createElement("td");
var toDate = new Date(item.to + "Z");
to.innerHTML = toDate.toLocaleString();
row.appendChild(to);
var quantity = document.createElement("td");
quantity.innerHTML = item.quantity;
row.appendChild(quantity);
var unitPrice = document.createElement("td");
unitPrice.innerHTML = "$" + parseFloat(item.unit_price).toFixed(4);
row.appendChild(unitPrice);
var subtotal = document.createElement("td");
subtotal.innerHTML = "$" + item.amount.toFixed(2);
row.appendChild(subtotal);
var tax = document.createElement("td");
tax.innerHTML = "$" + item.tax.toFixed(2);
row.appendChild(tax);
var total = document.createElement("td");
total.innerHTML = "$" + item.total.toFixed(2);
row.appendChild(total);
return row;
};
// Callback for invoice API call
var displayInvoice = function(response)
{
ui.subtotal.innerHTML = "$" + response.subtotal.toFixed(2);
ui.tax.innerHTML = "$" + response.tax.toFixed(2);
ui.total.innerHTML = "$" + response.total.toFixed(2);
};
// Callback for invoice items API call
var displayItems = function(response)
{
// Insert invoice items into table
for (var i = 0; i < response.data.length; i++)
ui.invoiceBody.appendChild(createItemRow(response.data[i], ui.invoiceBody.children.length % 2));
// Request the next page if there are more
if (response.page != response.pages)
apiGet("/account/invoices/" + data.params.iid + "/items?page=" + (response.page + 1), displayItems, null);
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need an invoice ID, so die if we don't have it
if (!data.params.iid) {
alert("No invoice ID supplied!");
return;
}
setupHeader();
// Highlight the remote access subnav link
var subnavLinks = document.getElementsByClassName(elements.subnav);
for (var i = 0; i < subnavLinks.length; i++) {
if (subnavLinks[i].pathname == "/account/billing_history")
subnavLinks[i].className = elements.subnav + " " + elements.subnavActive;
else
subnavLinks[i].className = elements.subnav;
}
// Get element references
ui.invoiceBody = document.getElementById(elements.invoiceBody);
ui.invoiceID = document.getElementById(elements.invoiceID);
ui.subtotal = document.getElementById(elements.subtotal);
ui.tax = document.getElementById(elements.tax);
ui.total = document.getElementById(elements.total);
// Set title and table header
document.title += " " + data.params.iid;
ui.invoiceID.innerHTML = data.params.iid;
// Get data from API
apiGet("/account/invoices/" + data.params.iid, displayInvoice, null);
apiGet("/account/invoices/" + data.params.iid + "/items", displayItems, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();