-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddpurchase.php
352 lines (340 loc) · 14.6 KB
/
addpurchase.php
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
<?php
session_start();
include_once "php/config.php";
$usersql=mysqli_query($conn,"SELECT * FROM users WHERE user_id={$_SESSION['unique_id']}");
$user=mysqli_fetch_assoc($usersql);
if($user['role']!=1)
{
header("location: mainpage.php");
}
include_once("navigation.php");
?>
<div class="container-fluid">
<center><h2>NEW PURCHASE ENTRY</h2></center>
<center><form action="" class="form-horizontal" method="post" name="myForm" id="formpurchase">
<br>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="systemcheck" value="Add System">
<input type="text" value="uncheck" id="check" hidden>
<label class="form-check-label" for="exampleCheck1">Add System</label>
</div>
<br>
<div class="form-group pt-2">
<label for="inputEmail3" class="col-md-5 control-label">Invoice Number</label>
<div class="col-md-2">
<input type="text" class="form-control" id="invoice" name="invoice" placeholder="Invoice Number" required>
</div>
</div>
<div class="form-group pt-2">
<label for="inputEmail3" class="col-md-5 control-label">Invoice Date</label>
<div class="col-md-2">
<input type="date" class="form-control" id="date" name="date" placeholder="Invoice Date" required>
</div>
</div>
<div class="form-group" id="inputcompcheck">
</div>
<div class="form-group">
<h4 class="text-center"> Add Components</h4>
<br>
<div class="row">
<div class="col-md-2">
<select id="compcat" class="dropdown" name="compcat" style="width:130px;height:30px">
<?php
$categorysql=mysqli_query($conn,"SELECT * FROM category WHERE category_code NOT IN ('CPU','SRV','LAP','MAC')");
$output ="";
while($category=mysqli_fetch_assoc($categorysql))
{
$output.='<option value="'.$category['category'].'">'.$category['category'].'</option>
';
}
echo $output;
?>
</select>
<!-- </ul> -->
<!-- </div> -->
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="brand" name="brand" placeholder="Brand">
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="type" name="type" placeholder="Type">
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="compdesc" name="compdesc" placeholder="Description">
</div>
<div class="col-md-1">
<input type="text" class="form-control" id="compquant" name="compquant" placeholder="Quantity">
</div>
<div class="col-md-1">
<button type="submit" class="btn btn-primary" id="addcomponent" name="add">Add to List</button>
</div>
</div>
</div>
<br>
<div class="form-group mt-2">
<h4 class="text-center"> Add CPU/Server/Laptop</h4>
<br>
<div class="row">
<div class="col-md-2">
<select id="cpucat" name="cpucat" class="dropdown" style="width:130px;height:30px">
<?php
$categorysql=mysqli_query($conn,"SELECT * FROM category WHERE category_code IN ('CPU','SRV','LAP','MAC')");
$output ="";
while($category=mysqli_fetch_assoc($categorysql))
{
$output.='<option value="'.$category['category'].'">'.$category['category'].'</option>
';
}
echo $output;
?>
</select>
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="ram" name="ram" placeholder="RAM" >
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="procseries" name="procseries" placeholder="Processor Series">
</div>
<div class="col-md-1">
<input type="text" class="form-control" id="storage" name="storage" placeholder="Storage(GB): Example 1000">
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="cpudesc" name="cpudesc" placeholder="Description">
</div>
<div class="col-md-1">
<input type="text" class="form-control" id="cpuquant" name="cpuquant" placeholder="Quantity">
</div>
<div class="col-md-1">
<button type="submit" class="btn btn-primary" id="addcpu" name="addcpu">Add to List</button>
</div>
</div>
<div class="row" id="assemblesystemdiv">
</div>
<div class="row">
<div class="col-sm-offset-2 col-md-9 text-center" id="assemblesystem">
</div>
</div>
<br>
<br>
<div class="row" id="finish" style="margin-bot:10px">
<center><button type="submit" class="btn btn-primary" id="finishbtn" name="finish">Finish Purchase Details</button></center>
</div>
</div>
<br>
<br>
</form></center><br><br><br>
</div>
<?php
include_once("footer.php");
?>
<script>
const form=document.querySelector("#formpurchase"),
continueBtn1=form.querySelector("#addcomponent"),
continueBtn2=form.querySelector("#addcpu");
continuebtn3=form.querySelector("#assignsystem");
var count=0;
var comp=["CPU","MNT","MOU","KBD"];
// errorText = form.querySelector(".error-text");
$('#finishbtn').prop("disabled",true);
document.getElementById("systemcheck").onclick=()=>{
if(document.getElementById("check").value=="uncheck")
{
count=0;
document.getElementById("check").value="check";
document.getElementById("ram").value="";
document.getElementById("procseries").value="";
document.getElementById("storage").value="";
document.getElementById("cpudesc").value="";
document.getElementById("cpuquant").value="";
if(count==0)
{
document.getElementById("inputcompcheck").innerHTML='<div class="alert alert-info"><strong>Component 1: Enter Mouse details of the Systems Puchased.</strong></div>';
document.getElementById("compcat").value="Mouse";
document.getElementById("cpucat").value="";
$('#addcpu').prop("disabled",true);
}
}
else if(document.getElementById("check").value=="check" && count>0 && count<4)
{
alert('System details must be finished before entering other components');
document.getElementById("systemcheck").checked=true;
}
else{
$('#addcpu').prop("disabled",false);
$('#addcomponent').prop("disabled",false);
document.getElementById("inputcompcheck").innerHTML='';
document.getElementById("check").value="uncheck";
document.getElementById("ram").value="";
document.getElementById("procseries").value="";
document.getElementById("storage").value="";
document.getElementById("cpudesc").value="";
document.getElementById("cpuquant").value="";
count=0;
}
}
continueBtn1.onclick = (e)=>{
e.preventDefault();
console.log(document.getElementById("compcat").value);
document.getElementById("assemblesystemdiv").innerHTML="";
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/addcomponent.php", true);
console.log(xhr.response);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
if(parseInt(data.slice(-1))>=0 && parseInt(data.slice(-1))<=9)
{
alert(data);
document.getElementById("assemblesystemdiv").innerHTML="";
document.getElementById("brand").value="";
document.getElementById("type").value="";
document.getElementById("compdesc").value="";
document.getElementById("type").value="";
if(document.getElementById("check").value!="check")
{
document.getElementById("compquant").value="";
$('#addcpu').prop("disabled",false);
$('#addcomponent').prop("disabled",false);
$('#finishbtn').prop("disabled",false);
}
else
{
$('#finishbtn').prop("disabled",true);
$('#addcpu').prop("disabled",true);
count=count+1;
if(count==1)
{
document.getElementById("inputcompcheck").innerHTML='<div class="alert alert-info"><strong>Component 2: Enter Monitor details of the Systems Puchased.</strong></div>';
document.getElementById("compcat").value="Monitor";
}
else if(count==2)
{
document.getElementById("inputcompcheck").innerHTML='<div class="alert alert-info"><strong>Component 3: Enter KeyBoard details of the Systems Puchased.</strong></div>';
document.getElementById("compcat").value="Keyboard";
}
else if(count==3)
{
document.getElementById("inputcompcheck").innerHTML='<div class="alert alert-info"><strong>Component 4: Enter CPU details of the Systems Puchased.</strong></div>';
document.getElementById("compcat").value="";
document.getElementById("cpucat").value="CPU";
document.getElementById("cpuquant").value=document.getElementById("compquant").value;
document.getElementById("compquant").value="";
$('#addcpu').prop("disabled",false);
$('#addcomponent').prop("disabled",true);
}
}
}
else
{
alert(data);
}
}
}
}
let formData = new FormData(form);
xhr.send(formData);
}
continueBtn2.onclick = (e)=>{
e.preventDefault();
console.log(document.getElementById("cpucat").value);
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/addcpu.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
if(parseInt(data.slice(-1))>=0 && parseInt(data.slice(-1))<=9)
{
alert(data);
if(document.getElementById("check").value=="check" && count==3)
{
count=count+1;
document.getElementById("ram").value="";
document.getElementById("procseries").value="";
document.getElementById("storage").value="";
document.getElementById("cpudesc").value="";
if(count==4)
{
document.getElementById("compquant").value="";
document.getElementById("assemblesystem").style.display="block";
document.getElementById("inputcompcheck").innerHTML='<div class="alert alert-info"><strong>Great All Details of System submitted. Click Assemble System to Assign Components.</strong></div>';
document.getElementById("assemblesystem").innerHTML='<br><center><button type="submit" class="btn btn-primary" id="assignsystem" name="assignsystem">Assemble System</button><center>';
document.getElementById("finish").style.display="none";
$('#addcpu').prop("disabled",false);
$('#addcomponent').prop("disabled",false);
count=0;
$('#finishbtn').prop("disabled",false);
}
}
else
{
$('#addcpu').prop("disabled",false);
$('#addcomponent').prop("disabled",false);
$('#finishbtn').prop("disabled",false);
}
}
else
{
alert(data);
}
}
}
}
let formData = new FormData(form);
xhr.send(formData);
}
$(document).on('click','#assignsystem',function(e){
e.preventDefault();
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/assemblesystem.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
document.getElementById("assemblesystemdiv").innerHTML=data;
document.getElementById("inputcompcheck").innerHTML='';
document.getElementById("assignsystem").style.display="none";
document.getElementById("cpuquant").value="";
document.getElementById("compcat").value="mouse";
document.getElementById("systemcheck").checked=false;
document.getElementById("check").value="uncheck";
}
}
}
let formData = new FormData();
formData.append("invoice_id",document.getElementById("invoice").value);
formData.append("date",document.getElementById("date").value);
formData.append("quantity",document.getElementById("cpuquant").value);
formData.append("date",document.getElementById("date").value);
xhr.send(formData);
});
document.getElementById("finishbtn").onclick=(e)=>{
e.preventDefault();
window.onbeforeunload = null;
let xhr=new XMLHttpRequest();
xhr.open("POST", "php/insertinvoice.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
console.log(data);
location.href="addpurchase.php";
}
}
}
let formData = new FormData();
formData.append("invoice_id",document.getElementById("invoice").value);
xhr.send(formData);
}
$(document).on('click','#okaybtn',function(e){
e.preventDefault();
document.getElementById("assemblesystemdiv").innerHTML="";
document.getElementById("finish").style.display="block";
});
window.onbeforeunload = function(){
return 'Are you sure you want to leave?';
};
</script>
</body>
</html>