-
Notifications
You must be signed in to change notification settings - Fork 1
/
boothSalesController.php
81 lines (62 loc) · 2.08 KB
/
boothSalesController.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
<?php
include "db_connect.php";
$requires = "admin";
include "menu.php";
foreach($_POST as $key => $value)
{
$key = $value;
}
$year = $_POST["year"];
$month = $_POST["month"];
$day = $_POST["day"];
$date = "20".$year."-".$month."-".$day;
//this time is just to enter a random time
$time = date();
$name = "Booth Sale";
$description = "Booth Sale";
$location = $_POST["location"];
//enter booth sale into event based on date to help admin keep track of location and date of booth sale
$query ="INSERT INTO events (dateOfEvent,timeOfEvent,name,description,location) VALUES ('$date','$time','$name','$description','$location');";
mysqli_query($db,$query);
//get the event id
$query ="SELECT MAX(eventId) FROM events;";
$eid = mysqli_query($db,$query);
//Add a new transaction and new sales
$query = "INSERT INTO transactions (girlId) VALUES ('0');";
mysqli_query($db, $query);
//Select max
$query = "SELECT MAX(TID) AS 'transId'FROM transactions;";
$tranId = mysqli_query($db, $query);
$total = 0;
$attendees = 0;
while(isset($_POST['pname'])){
$product = $_POST['pname'];
$query = "select productId from products where name = '$product';";
$pid = mysqli_query($db,$query);
$qty = $_POST[$quantity];
//create new sale
$query = "INSERT INTO sales (transactionId, quantity, productId, customer) VALUES ('$tranId', '$qty', '$pid', 'Booth Sale');";
mysqli_query($db, $query);
$query = "select quantity from products where productId = '$pid';";
$currentQty = mysqli_query($db,$query);
//can't substract from quantity if not available in inventory
echo "$currentQty";
if($currentQty >= $qty){
$newQty = $currentQty - $qty;
$query = "UPDATE products SET quantity = '$newQty' WHERE productId = '$pid';";
mysqli_query($db,$query);
}else {
echo "The quantity available isn't enough.";
}
$total = $total + $qty;
//Add Girls
foreach($_GET as $key => $value)
{
$query = "INSERT INTO attending (eventId, girlId) VALUES ('$eid', '$key');";
echo $query."<br>";
mysqli_query($db,$query);
$attendees++;
}
}
Header("Location: main.php");
?>