-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.html
386 lines (331 loc) · 11.1 KB
/
report.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title> Admin dashboard </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/report.css">
<link rel="stylesheet" href="css/color.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/table.css">
<!-- Boxicons CDN Link -->
<link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!--sidebar begins here-->
<div class="sidebar">
<div class="logo-details">
<i class='bx bxl-t-plus-plus'></i>
<!--type of icon-->
<span class="logo_name">TrackMe</span>
</div>
<ul class="nav-links">
<li>
<a href="index.html">
<i class='bx bx-grid-alt'></i>
<span class="links_name">Dashboard</span>
</a>
</li>
<li>
<a href="#" class="active">
<i class='bx bx-edit'></i>
<span class="links_name">Info Reports</span>
</a>
</li>
<li>
<a href="barcode.html">
<i class='bx bx-barcode'></i>
<span class="links_name">Generate QR</span>
</a>
</li>
<li>
<a href="scan.html">
<i class='bx bx-scan'></i>
<span class="links_name">Scan QR</span>
</a>
</li>
<li>
<a href="workers.html">
<i class='bx bx-user'></i>
<span class="links_name">Employees</span>
</a>
</li>
<li class="log_out">
<a href="#">
<i class='bx bx-log-out'></i>
<span class="links_name">Log out</span>
</a>
</li>
</ul>
</div>
<!-- sidebar ends here -->
<section class="home-section">
<!-- navbar starts here -->
<nav>
<div class="sidebar-button">
<i class='bx bx-menu sidebarBtn'></i>
<span class="dashboard">Dashboard</span>
</div>
</nav>
<!-- navbar ends here -->
<div class="report-body">
<div class="grid-container">
<section class="grid-item1">
<div id="prod-statistics">
<div class="chart-header">
<h1>Statistics (Employee / Statistics)</h1>
</div>
<div class="prodStat show-graph">
<canvas id="productionChart" style="width:100%;max-width:100%"></canvas>
</div>
<div class="empStat hide-graph">
<canvas id="ffbChart" style="width:100%;max-width:100%"></canvas>
</div>
</div>
<div id="loss-gain" class="report-table">
<h1>Loss /Gain statistics</h1>
<table id="myTable">
<thead>
<tr>
<th class="topic">Month</th>
<th class="topic">Total FFB Produce</th>
<th class="topic">% Loss/Gain</th>
</tr>
</thead>
<tbody id="report-table-data"></tbody>
</table>
</div>
</section>
<section class="grid-item2">
<div class="sub-nav">
<h3>Sections</h3>
<hr />
<div class="sub-menu prodTrigger">
Monthly Production
</div>
<div class="sub-menu empTrigger">
Employee Performance
</div>
<div class="sub-menu">
<a href="#loss-gain">Loss / Gain</a>
</div>
</div>
</section>
</div>
</div>
</section>
<!-- <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.min.js"></script> -->
<script src="./js/date.js"></script>
<script src="./js/generate_dashboard_table.js"></script>
<script src="./js/utils.js"></script>
<script src="./js/firebase.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.min.js"></script>
<script src="./js/print.min.js"></script>
<!-- Firebase sdk setup -->
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp, } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-app.js";
import {
getFirestore,
getDocs,
collection,
addDoc,
updateDoc,
deleteDoc,
doc,
query,
where,
} from "https://www.gstatic.com/firebasejs/9.6.10/firebase-firestore.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
import { getAuth, signOut } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-auth.js";
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: config.apiKey,
authDomain: config.authDomain,
projectId: config.projectId,
storageBucket: config.storageBucket,
messagingSenderId: config.messagingSenderId,
appId: config.appId
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
//Firestore connection
const database = getFirestore();
const auth = getAuth();
const prodBtn = document.querySelector(".prodStat");
const empBtn = document.querySelector(".empStat");
const productionTrigger = document.querySelector(".prodTrigger");
const FFBTrigger = document.querySelector(".empTrigger");
function toggleChart() {
prodBtn.classList.toggle("show-graph");
empBtn.classList.toggle("show-graph");
prodBtn.classList.toggle("hide-graph");
empBtn.classList.toggle("hide-graph");
}
productionTrigger.addEventListener("click", toggleChart);
FFBTrigger.addEventListener("click", toggleChart);
// function to get scanned barcode data
const getReportGraphQuery = (daysOfMonth) => {
const q = query(collection(database, BARCODE),
where("date", "in", daysOfMonth),
where("checked_in", "==", true),
where("checked_out", "==", true),
);
return getDocs(q);
}
const getReportGraphData = async () => {
let finalData = [];
for (const monthDates of get12MonthsDates()) { //monthDates = is used to label the names of the month
let monthResult = [];
for (const days of monthDates ){ //days = 3 arrays of 10 items
const querySnapshot = await getReportGraphQuery(days);
querySnapshot.forEach((doc) => {
monthResult.push({...doc.data()});
});
};
console.log(monthResult);
finalData.push(monthResult.length);
};
console.log(finalData);
return finalData;
}
const getBarcodesQuery = () => {
const q = query(collection(database, BARCODE));
return getDocs(q);
};
const getBarcodes = async () => {
const querySnapshot = await getBarcodesQuery();
let barcodes = [];
querySnapshot.forEach((doc) => {
barcodes.push({ ...doc.data() });
});
console.log(barcodes);
return barcodes;
}
// function to get weight of FFB tons
const getWeightGraphQuery = (daysOfMonth) => {
const q = query(collection(database, COUNTER), where("day", "in", daysOfMonth));
return getDocs(q);
}
const getWeightGraphData = async () => {
let secondFinalData = [];
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for (const [index, monthDates] of get12LastMonthsDates().entries()) { //monthDates = is used to label the names of the month
let secondMonthResult = {
mon: months[index],
val: 0,
percentage: 0
};
for (const days of monthDates ){ //days = 3 arrays of 10 items
const querySnapshot = await getWeightGraphQuery(days);
querySnapshot.forEach((doc) => {
secondMonthResult.val += doc.data().tons;
secondMonthResult.percentage = percentageValue(50, secondMonthResult.val);
});
};
console.log(secondMonthResult);
secondFinalData.push(secondMonthResult);
};
return secondFinalData;
}
function percentageValue(defaultValue, currentValue) {
return ((currentValue/defaultValue)*100)-100;
}
window.addEventListener("DOMContentLoaded", async (e) => {
let [
barcodes,
weights,
] = await Promise.all(
[
getReportGraphData(),
// getWeightGraphData(),
]
);
//generate table for ffb report
let tableBody = document.getElementById("report-table-data").innerHTML + generate_weight_table(weights);
document.getElementById("report-table-data").innerHTML = tableBody;
//function to hide and display graph
var xValues = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var yValues = barcodes;
// var zValues = weightLine;
new Chart("productionChart", {
type: "line",
data: {
labels: xValues,
datasets: [
{
// data: [1600, 1700, 1700, 1900, 2000, 2700, 4000, 5000, 6000, 7000, 5000, 7000],
data: yValues,
borderColor: "green",
fill: false,
legendText: "Employees",
legendText: "QR used"
},
{
// data: [16, 17, 10, 9, 2, 7, 0, 5, 6, 7, 5, 7],
// data: zValues,
borderColor: "blue",
fill: false,
legendText: "Tons",
showInLegend: true,
}]
},
options: {
legend: { display: false },
title: {
display: true,
text: "Report"
}
}
});
var iValues = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
// var yValues = barcodes;
var zValues = weightLine;
new Chart("ffbChart", {
type: "line",
data: {
labels: xValues,
datasets: [
{
// data: [1600, 1700, 1700, 1900, 2000, 2700, 4000, 5000, 6000, 7000, 5000, 7000],
// data: yValues,
borderColor: "green",
fill: false,
legendText: "Employees",
legendText: "QR used"
},
{
// data: [16, 17, 10, 9, 2, 7, 0, 5, 6, 7, 5, 7],
data: zValues,
borderColor: "blue",
fill: false,
legendText: "Tons",
showInLegend: true,
}]
},
options: {
legend: { display: false },
title: {
display: true,
text: "Report"
}
}
});
});
</script>
<script>
let sidebar = document.querySelector(".sidebar");
let sidebarBtn = document.querySelector(".sidebarBtn");
sidebarBtn.onclick = function () {
sidebar.classList.toggle("active");
if (sidebar.classList.contains("active")) {
sidebarBtn.classList.replace("bx-menu", "bx-menu-alt-right");
} else
sidebarBtn.classList.replace("bx-menu-alt-right", "bx-menu");
}
</script>
</body>
</html>