forked from justinpavatte/pmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoldscrap.html
157 lines (151 loc) · 5.06 KB
/
goldscrap.html
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PMC</title>
<!-- https://favicon.io/favicon-converter/ -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png">
<link rel="manifest" href="site.webmanifest">
<link rel="stylesheet" type="text/css" href="styles.css">
<style>
label {
color: gold;
}
</style>
</head>
<body>
<div>
<label for="grams">Grams:</label>
</div>
<div>
<input id="grams" inputmode="numeric" autofocus />
</div>
<div>
<label for="karat">Karat:</label>
</div>
<div>
<select id="karat">
<option value="10K">10K</option>
<option value="14K">14K</option>
<option value="18K">18K</option>
</select>
</div>
<div>
<button id="calcPriceBtn" onclick="calcPrice()">Calculate</button>
</div>
<div>
<label for="tradeValue">Trade:</label>
</div>
<div>
<input readonly id="tradeValue" />
</div>
<div>
<label for="scrapValue">Scrap:</label>
</div>
<div>
<input readonly id="scrapValue" />
</div>
<div>
<br>
<label><i>Details...</i></label>
</div>
<div>
<label for="gldSptPrc">gold spot price:</label>
</div>
<div>
<input readonly id="gldSptPrc" />
</div>
<div>
<label for="spotFluc">spot fluc subtrahend:</label>
</div>
<div>
<input readonly id="spotFluc" />
</div>
<div>
<label for="prsdGrmInpt">parsed gram input:</label>
</div>
<div>
<input readonly id="prsdGrmInpt" />
</div>
<div>
<label for="troyOzToGrmsFctr">toz to grm factor:</label>
</div>
<div>
<input readonly id="troyOzToGrmsFctr" />
</div>
<div>
<label for="krtFct">karat factor:</label>
</div>
<div>
<input readonly id="krtFct" />
</div>
<div>
<label for="rfDrt">refine/dirt factor:</label>
</div>
<div>
<input readonly id="rfDrt" />
</div>
<div>
<br>
<label><i>Notes...</i></label>
</div>
<div>The spot price is set by calling a web service to get the current bid price at the moment. This price is in dollars per troy ounce. The bid price shows what buyers are currently willing to pay. Therefore, this is the foundation for what we are willing to pay the customer.</div>
<script src="metalprices.js"></script>
<script src="todoist.js"></script>
<script>
async function calcPrice() {
const troyOuncesToGramsFactor = 0.0322;
const fluctuatingPriceFactor = 100.0;
const refineryFeeAndDirtFactor = 0.9175;
let gramValue = document.getElementById('grams').value;
let karatValue = document.getElementById('karat').value;
let gramNumber = parseFloat(gramValue);
let karatFactor = 0.0;
if (karatValue == "10K") {
karatFactor = 10.0 / 24.0;
}
else if (karatValue == "14K") {
karatFactor = 14.0 / 24.0;
}
else if (karatValue == "18K") {
karatFactor = 18.0 / 24.0;
}
let curSpt = await fetchBidPrice("gold");
let fullValueForTrade = gramNumber * (curSpt - fluctuatingPriceFactor) * troyOuncesToGramsFactor * karatFactor * refineryFeeAndDirtFactor;
let halfValueForScrap = fullValueForTrade / 2.0;
let tradePriceDisp = fullValueForTrade.toFixed(2);
let scrapPriceDisp = halfValueForScrap.toFixed(2);
let curSptDisp = curSpt.toFixed(2);
document.getElementById('tradeValue').value = "$" + tradePriceDisp;
document.getElementById('scrapValue').value = "$" + scrapPriceDisp;
document.getElementById('gldSptPrc').value = "$" + curSptDisp;
document.getElementById('spotFluc').value = fluctuatingPriceFactor;
document.getElementById('prsdGrmInpt').value = gramNumber;
document.getElementById('troyOzToGrmsFctr').value = troyOuncesToGramsFactor;
document.getElementById('krtFct').value = karatFactor;
document.getElementById('rfDrt').value = refineryFeeAndDirtFactor;
writeToLog(`
GOLD SCRAP
Trade: ${tradePriceDisp}
Scrap: ${scrapPriceDisp}
Spot: ${curSptDisp}
Fluc: ${fluctuatingPriceFactor}
Grams: ${gramNumber}
Gram Factor: ${troyOuncesToGramsFactor}
Karat Factor: ${karatFactor}
Refine/Dirt Factor: ${refineryFeeAndDirtFactor}
`);
}
//make enter the accept button
document.getElementById('grams').onkeydown = function (event) {
if (event.key === 'Enter') {
event.preventDefault();
calcPrice();
}
};
</script>
</body>
</html>