-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_homepage.js
83 lines (67 loc) · 2.91 KB
/
admin_homepage.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
//Firebase config start
const firebaseConfig = {
apiKey: "AIzaSyAO_ml9bYT2k8rSC_TFheB4-55zqx2qU-A",
authDomain: "test-web-tutorial.firebaseapp.com",
databaseURL: "https://test-web-tutorial.firebaseio.com",
projectId: "test-web-tutorial",
storageBucket: "test-web-tutorial.appspot.com",
messagingSenderId: "477439235921",
appId: "1:477439235921:web:c27e1569025872d10d2570",
measurementId: "G-6DDKTQT9WW"
};
firebase.initializeApp(firebaseConfig);
//console.log("hellohi");
//Firebase config end
// Table Load Start
document.getElementById("body").onload = function () {
//console.log("hellohi22");
var createRowElem = function(value) {
var td = document.createElement('td');
td.appendChild(document.createTextNode(value));
return td;
}
let sum = 0;
let sumTempProfit = 0;
var ref = firebase.database().ref('inventory');
ref.once('value', (snapshot) => {
// console.log('Hello');
var table = document.getElementById('inventory-table');
let temp = 0;
let tempProfit = 0;
snapshot.forEach(childSnapshot => {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
tempProfit = childData['totalbuy'] * childData['buycost'];
sumTempProfit += tempProfit;
temp = childData['totalsel'] * childData['unitcost'];
sum += temp;
console.log("TempPro: ", temp);
//console.log(childKey);
//console.log(childData['name']);
var trBody = document.createElement('tr');
trBody.appendChild(createRowElem(childData['name'].toUpperCase()));
trBody.appendChild(createRowElem(childData['amount']));
trBody.appendChild(createRowElem(childData['totalbuy']));
trBody.appendChild(createRowElem(childData['totalsel']));
trBody.appendChild(createRowElem(childData['unitcost']));
//}
table.appendChild(trBody);
});
let str = sum.toString() + " Taka";
document.getElementById("totalsel").innerHTML = str;
let str2 = sumTempProfit.toString() + " Taka";
document.getElementById("totalInvest").innerHTML = str2;
});
refTwo = firebase.database().ref('tokenRecord/totalProfit');
refTwo.once('value',(snapshot) => {
totalProfit = snapshot.val();
let str = totalProfit.toString() + " Taka";
document.getElementById("totalProfit").innerHTML = str;
});
}
// Table load end
//Log out btn
function log(){
window.location.assign("index.html");
}
// Total Sell Info