-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
131 lines (108 loc) · 4.19 KB
/
ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Assign some default values so I don't have to type as much.
*/
function assign_defaults() {
/* fixed defaults */
var shipping_rate = 5800;
var airfare = 1400;
var tax_rate = 9;
var insurance_rate = 0.65;
var everything_else = 1000;
var cash = 10000;
var loan1 = 20000;
var loan_rate1 = 4.5;
var price_point = 100;
var markup = 100;
var item_count = 200;
/* projection defaults */
document.getElementById('price_point').value = price_point;
document.getElementById('markup').value = markup;
document.getElementById('item_count').value = item_count;
document.getElementById('shipping_rate').value = shipping_rate;
document.getElementById('airfare').value = airfare;
document.getElementById('tax_rate').value = tax_rate;
document.getElementById('insurance_rate').value = insurance_rate;
document.getElementById('everything_else').value = everything_else;
document.getElementById('cash').value = cash;
document.getElementById('loan1').value = loan1;
document.getElementById('loan_rate1').value = loan_rate1;
}
function expenseTable(data) {
//create and return a table of expenses
var table = document.createElement('table');
var tbody = document.createElement('tbody');
var items = listFixedCosts(data);
items.unshift( [ 'Expense', 'Amount' ] );
items.push( [ 'Total: ', getFixedCost(data) ]);
var firstRow = true;
items.forEach(function (item) {
var tr = document.createElement('tr');
item.forEach(function (cell) {
if(firstRow) {
var tdh = document.createElement('th');
} else {
var tdh = document.createElement('td');
}
tdh.appendChild(document.createTextNode(cell));
tr.appendChild(tdh);
});
firstRow = false;
tbody.appendChild(tr);
});
table.appendChild(tbody);
return table;
}
function inventoryTable(data) {
var items = []
items.push(
[ 'item_count', "Item Count", data['item_count']],
[ 'price_point', "Price Point", "$" + data['price_point']],
[ 'markup', "Markup", data['markup'] + "%" ],
[ 'stock_cost', "Stock Cost", "$" + getStockCost(data)],
[ 'tax', "Import Tax", "$" + getTax(data)],
[ 'insurance', "Freight Insurance", "$" + getInsurance(data)],
[ 'gross_cad', "Gross CAD", "$" + getGross(data)]
);
var table = document.createElement('table');
var tbody = document.createElement('tbody');
var headingRow = document.createElement('tr');
var bodyRow = document.createElement('tr');
items.forEach(function (cell) {
var th = document.createElement('th');
var td = document.createElement('td');
th.appendChild(document.createTextNode(cell[1]));
td.appendChild(document.createTextNode(cell[2]));
headingRow.appendChild(th);
bodyRow.appendChild(td);
});
tbody.appendChild(headingRow);
tbody.appendChild(bodyRow);
table.appendChild(tbody);
return table;
}
function summary(data) {
console.log(data);
var summary = document.createElement('div') ;
var heading = document.createElement('h2');
heading.appendChild(document.createTextNode("Summary"));
summary.appendChild(heading);
var paragraphs = [];
paragraphs.push(
"Total cost: fixed + stock",
nf(getFixedCost(data)) + " + " + nf(getStockCost(data)) + " = " + nf(getTotalCost(data)) + " of " + nf(getCapital(data)),
"Net: gross = ( stock + fixed ) - tax - insurance",
"" + nf(getGross(data))+ " - (" + nf(getStockCost(data)) + " + " + nf(getFixedCost(data)) +") - " + nf(getTax(data)) + " - " + nf(getInsurance(data)),
"I want a 1/3 return on my investment, so " + nf(getCapital(data)) + " / 3 = " + nf(getRequiredNet(data)),
"Net: " + nf(getProfit(data)) + " of " + nf(getRequiredNet(data))
);
paragraphs.forEach(function(para) {
var p = document.createElement('p');
p.appendChild(document.createTextNode(para));
summary.appendChild(p);
});
return summary;
}
function nf(n){
n = new Intl.NumberFormat().format(n);
return "$" + n;
}