-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
166 lines (142 loc) · 4.21 KB
/
index.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
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
.myButton {
background:linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
background-color:#ffffff;
border-radius:10px;
border:3px solid #dcdcdc;
display:inline-block;
cursor:pointer;
color:#666666;
font-family:Verdana;
font-size:12px;
font-weight:bold;
padding:5px 8px;
text-decoration:none;
}
</style>
<title>Inventory</title>
</head>
<body>
<form name="list" id="list">
<table>
<tr>
<td>
<label for="BatCH">Batch:</label>
</td>
<td>
<input id="BatCH" name="BatCH" inputmode="numeric" size="28" />
<a onclick='validate()' class="myButton">+</a>
</td>
</tr>
<tr>
<td>
<label for="Barcode">Barcode:</label>
</td>
<td>
<input id="Barcode" name="Barcode" type="tel" pattern='\d*' size="28" disabled/>
</td>
</tr>
<tr>
<td>
<input id="Qtty" type="hidden" name="Qtty" value="1" size="28" />
</td>
</tr>
</table>
</form>
<br>
<button>Generate Import File (CSV)</button>
<table id="results" width="360">
<thead>
<tr>
<th scope="col" width="120">Batch</th>
<th scope="col" width="120">Barcode</th>
<th scope="col" width="120">Qtty</th>
</tr>
</thead>
</table>
<script>
var input = document.getElementById("BatCH");
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
validate();
}
});
function validate() {
if (document.getElementById("BatCH").value != "" ){
document.getElementById("BatCH").disabled = true;
document.getElementById("Barcode").disabled = false;
document.getElementById("Barcode").focus();
}
}
var input1 = document.getElementById("Barcode");
input1.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
if (input1.value != "" ){
updateForm ();
input1.value =""
}
}
});
function updateForm() {
var product = document.getElementById("BatCH").value;
var qty = document.getElementById("Barcode").value;
var price = document.getElementById("Qtty").value;
var table=document.getElementById("results");
var row=table.insertRow(-1);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
var cell3=row.insertCell(2);
cell1.innerHTML=product;
cell2.innerHTML=qty;
cell3.innerHTML=price;
}
function download_csv(csv, filename) {
var csvFile;
var downloadLink;
// CSV FILE
csvFile = new Blob([csv], {type: "text/csv"});
// Download link
downloadLink = document.createElement("a");
// File name
downloadLink.download = filename;
// We have to create a link to the file
downloadLink.href = window.URL.createObjectURL(csvFile);
// Make sure that the link is not displayed
downloadLink.style.display = "none";
// Add the link to your DOM
document.body.appendChild(downloadLink);
// Lanzamos
downloadLink.click();
}
function export_table_to_csv(html, filename) {
var csv = [];
var table = document.getElementById("results")
var rows = table.querySelectorAll("table tr");
if (rows.length>1) {
for (var i = 1; 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(","));
}
// Download CSV
download_csv(csv.join("\n"), filename);
}
else{
window.alert("No records");
}
}
document.querySelector("button").addEventListener("click", function () {
var d = new Date();
var html = document.querySelector("table").outerHTML;
export_table_to_csv(html,d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate()+"-"+d.getHours()+"-"+d.getMinutes()+".csv" );
});
</script>
</body>
</html>