-
Notifications
You must be signed in to change notification settings - Fork 0
/
addProdAmount.js
101 lines (85 loc) · 3.38 KB
/
addProdAmount.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
91
92
93
94
95
96
97
98
99
100
101
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);
var presentAmount, totalBuyAmount, totalSelAmount;
function Ready(){
idV = document.getElementById('id').value;
//nameV = document.getElementById('name').value
// dateV = document.getElementById('date').value;
amountV = document.getElementById('amount').value;
buyCostV = document.getElementById('buyCost').value;
sellCostV = document.getElementById('sellCost').value;
mobNoV = document.getElementById('mobNo').value;
}
function tap() {
Ready();
if ( idV == "" || idV == null || amountV == "" || amountV == null || buyCostV == "" || buyCostV == null || sellCostV == "" || sellCostV == null || mobNoV == "" || mobNoV == null) {
alert("All field Must be filled out");
return false;
}
else{
if(idV.length >= 4){
var test = false;
ref = firebase.database().ref('inventory');
ref.once('value', (snapshot) => {
//var childSnapshot = 'customer';
snapshot.forEach(childSnapshot => {
var id = childSnapshot.key;
//console.log(childSnapshot.val());
var childData = childSnapshot.val();
//console.log(childKey);
presentAmount = childData['amount'];
presentAmount = parseInt(presentAmount);
totalBuyAmount = childData['totalbuy'];
totalBuyAmount = parseInt(totalBuyAmount);
totalSelAmount = childData['totalsel'];
totalSelAmount = parseInt(totalSelAmount);
if(id == idV){
insert();
}
else{
test = true;
}
});
if(test == true){
alert("Prod-ID not exists");
}
});
}
else {
alert("Product ID must be Length 4 or more!");
return false;
}
}
}
function insert(){
var div = document.getElementById('classId');
div.style.visibility = "visible";
presentAmount = parseInt(presentAmount);
amountV = parseInt(amountV);
totalBuyAmount = parseInt(totalBuyAmount);
totalSelAmount = parseInt(totalSelAmount);
buyCostV = parseInt(buyCostV);
sellCostV = parseInt(sellCostV);
presentAmount = presentAmount + amountV;
totalBuyAmount = totalBuyAmount + amountV;
firebase.database().ref('inventory/' + idV).update({
amount: presentAmount,
buycost: buyCostV,
unitcost: sellCostV,
totalbuy: totalBuyAmount
});
setTimeout(swith, 5000);
}
function swith() {
window.location.assign("inventoryPage.html");
//console.log("Hellllo2");
}