-
Notifications
You must be signed in to change notification settings - Fork 0
/
addCustomer.js
89 lines (77 loc) · 2.7 KB
/
addCustomer.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
//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);
function Ready(){
nameV = document.getElementById('name').value
idV = document.getElementById('id').value;
dateV = document.getElementById('date').value;
emailV = document.getElementById('email').value;
numV = document.getElementById('num').value;
addV = document.getElementById('address').value;
}
document.getElementById('addbutton').onclick = function () {
Ready();
if (nameV == "" || nameV == null || idV == "" || idV == null || emailV == "" || emailV == null || numV == "" || numV == null || addV == "" || addV == null) {
alert("All field Must be filled out");
return false;
}
else if(dateV == "" || dateV == null){
alert("Date field Must be filled out");
// Start
return false;
}
else {
var test = false;
ref = firebase.database().ref('customer');
ref.once('value', (snapshot) => {
//var childSnapshot = 'customer';
snapshot.forEach(childSnapshot => {
var id = childSnapshot.key;
//console.log(childSnapshot.val());
if(id == idV){
console.log(1);
test = true;
alert("Customer ID must be unique!");
console.log(2);
return false;
}
});
if(test == false){
console.log('Insert');
console.log(3);
insert();
console.log(4);
}
});
}
function insert(){
var div = document.getElementById('classId');
div.style.visibility = "visible";
firebase.database().ref('customer/' + idV).set({
address: addV,
id: idV,
email: emailV,
name: nameV,
phone: numV,
regDate: dateV,
totalDue: 0,
totalPaid: 0
});
// console.log('Tapp Tapp');
setTimeout(swith, 5000);
// console.log('Tapp Tapp2');
}
}
function swith() {
window.location.assign("customer.html");
//console.log("Hellllo2");
}