|
|
@@ -8,6 +8,8 @@ export default class Home extends Page{
|
|
|
constructor(){
|
|
|
super("Home", ["addMenu", "viewMenu", "logout"]);
|
|
|
|
|
|
+ this.incomeTotal = user.account.incomeTotal();
|
|
|
+
|
|
|
const date = new Date();
|
|
|
const month = date.toLocaleString("en-US", {month: "long"});
|
|
|
|
|
|
@@ -22,6 +24,7 @@ export default class Home extends Page{
|
|
|
.then((transactions)=>{
|
|
|
if(transactions.length > 0) user.account.addManyTransactions(transactions);
|
|
|
user.account.isPopulated = true;
|
|
|
+ this.renderData();
|
|
|
})
|
|
|
.catch((err)=>{
|
|
|
new Notifier("error", "Unable to retrieve transactions");
|
|
|
@@ -31,6 +34,26 @@ export default class Home extends Page{
|
|
|
this.render(month);
|
|
|
}
|
|
|
|
|
|
+ renderData(){
|
|
|
+ for(let i = 0; i < user.account.allowances.length; i++){
|
|
|
+ const a = user.account.allowances[i];
|
|
|
+ const spent = Format.currency(user.account.categorySpent(a));
|
|
|
+ new Elem(this.container.querySelector(`[class="${a.id}"] dd`))
|
|
|
+ .text(`${spent} / ${Format.currency(a.currencyAmount(this.incomeTotal))}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ const discretionary = user.account.getDiscretionary();
|
|
|
+ const remaining = discretionary - user.account.getDiscretionarySpent();
|
|
|
+ new Elem(this.container.querySelector(".discretionary dd"))
|
|
|
+ .text("")
|
|
|
+ .append(new Elem("span")
|
|
|
+ .text(Format.currency(remaining))
|
|
|
+ )
|
|
|
+ .append(new Elem("span")
|
|
|
+ .text(` / ${Format.currency(discretionary)}`)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
render(month){
|
|
|
new Elem("h1")
|
|
|
.text(month)
|
|
|
@@ -50,7 +73,7 @@ export default class Home extends Page{
|
|
|
.text("Income: ")
|
|
|
)
|
|
|
.append(new Elem("dd")
|
|
|
- .text(Format.currency(user.account.incomeTotal()))
|
|
|
+ .text(Format.currency(this.incomeTotal))
|
|
|
)
|
|
|
.appendTo(this.container);
|
|
|
|
|
|
@@ -62,5 +85,36 @@ export default class Home extends Page{
|
|
|
.text(Format.currency(user.account.billsTotal()))
|
|
|
)
|
|
|
.appendTo(this.container);
|
|
|
+
|
|
|
+ const discretionary = Format.currency(user.account.getDiscretionary());
|
|
|
+ new Elem("dl")
|
|
|
+ .addClass("discretionary")
|
|
|
+ .append(new Elem("dt")
|
|
|
+ .text("Remaining Discretionary:")
|
|
|
+ )
|
|
|
+ .append(new Elem("dd")
|
|
|
+ .text(`${discretionary} / ${discretionary}`)
|
|
|
+ )
|
|
|
+ .appendTo(this.container);
|
|
|
+
|
|
|
+ let allowances;
|
|
|
+ new Elem("h3").text("Allowances:").appendTo(this.container);
|
|
|
+ new Elem("div")
|
|
|
+ .addClass("allowances")
|
|
|
+ .toVar((e)=>{allowances = e})
|
|
|
+ .appendTo(this.container);
|
|
|
+
|
|
|
+ for(let i = 0; i < user.account.allowances.length; i++){
|
|
|
+ const a = user.account.allowances[i];
|
|
|
+ new Elem("dl")
|
|
|
+ .addClass(a.id)
|
|
|
+ .append(new Elem("dt")
|
|
|
+ .text(`${a.name}: `)
|
|
|
+ )
|
|
|
+ .append(new Elem("dd")
|
|
|
+ .text(`$0.00 / ${Format.currency(a.currencyAmount(this.incomeTotal))}`)
|
|
|
+ )
|
|
|
+ .appendTo(this.container);
|
|
|
+ }
|
|
|
}
|
|
|
}
|