-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.js
90 lines (69 loc) · 3.31 KB
/
javascript.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
function calculate() {
var cost = parseFloat(document.getElementById("cost").value);
var yieldPercent = parseFloat(document.getElementById("yield").value) / 100;
var processingCost = parseFloat(document.getElementById("processing_cost").value);
var processor = parseFloat(document.getElementById("processor").value);
var coldStorage = parseFloat(document.getElementById("cold_storage").value);
var shipping = parseFloat(document.getElementById("shipping").value);
var packaging = parseFloat(document.getElementById("packaging").value);
var weightType = document.getElementById("weight_type").value;
var result = cost / yieldPercent + processingCost + processor + coldStorage + shipping + packaging;
if (weightType === "incoming") {
result += processingCost;
} else {
result += processingCost / yieldPercent;
}
document.getElementById("result").innerHTML = "Cost per Sellable Pound: $" + result.toFixed(2);
}
function addToTable() {
var table = document.getElementById("resultsTable").getElementsByTagName('tbody')[0];
var newRow = table.insertRow(table.rows.length);
newRow.insertCell(0).innerHTML = document.getElementById("species").value;
newRow.insertCell(1).innerHTML = document.getElementById("product").value;
newRow.insertCell(2).innerHTML = document.getElementById("cost").value;
newRow.insertCell(3).innerHTML = document.getElementById("yield").value;
newRow.insertCell(4).innerHTML = document.getElementById("processing_cost").value;
newRow.insertCell(5).innerHTML = document.getElementById("processor").value;
newRow.insertCell(6).innerHTML = document.getElementById("cold_storage").value;
newRow.insertCell(7).innerHTML = document.getElementById("shipping").value;
newRow.insertCell(8).innerHTML = document.getElementById("packaging").value;
newRow.insertCell(9).innerHTML = document.getElementById("result").innerText.split('$')[1];
}
function exportToCSV() {
var table = document.getElementById("resultsTable");
var csv = [];
var rows = table.querySelectorAll("tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
row.push(cols[j].innerText);
}
csv.push(row.join(","));
}
var csvFile = new Blob([csv.join("\n")], { type: "text/csv" });
var downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(csvFile);
downloadLink.download = 'results.csv';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
function copyToClipboard() {
var table = document.getElementById("resultsTable");
var csv = [];
var rows = table.querySelectorAll("tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
row.push(cols[j].innerText);
}
csv.push(row.join(","));
}
var textArea = document.createElement("textarea");
textArea.value = csv.join("\n");
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
alert("Table data copied to clipboard!");
}