-
Notifications
You must be signed in to change notification settings - Fork 0
/
storekeeper.php
103 lines (99 loc) · 2.61 KB
/
storekeeper.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
<?php
# check for a user session
if (!isset($_SESSION["user"])) {
header("location: login.php");
}
# initialize array of delivered but not stored products
# such array is implemented as the session variable
if (!isset($_SESSION["supplied_products"])) {
$_SESSION["supplied_products"] = array();
}
?>
<h3>Supplied products</h3>
<?php
# check for awaiting deliveries (is there any empty contracts)
$sql = "SELECT * FROM contract_supplier
WHERE contract_number NOT IN (SELECT contract_number FROM supplied)";
$result = mysqli_query($conn, $sql);
# if awaiting deliveries exist
# display a corresponding form
if (mysqli_num_rows($result) > 0) {
# chech session array of delivered but not stored products
# if there are any products - display the form used to store supplied products
if (sizeof($_SESSION["supplied_products"]) > 0) {
?>
<form method="post" action="index.php">
<p>
<b>by contract</b>
<select name="contract_number">
<?php
# display the combo box with awaiting orders
while ($row = mysqli_fetch_assoc($result)) {
?><option value="<?= $row["contract_number"] ?>">
<?= $row["contract_number"] . " - " . $row["Supplier"] .
" (" . $row["contract_date"] . ")" ?></option><?php
}
?>
</select>
</p>
<table border="1">
<tr>
<th>Product</th>
<th>Amount</th>
<th>Cost</th>
<th>Action</th>
</tr>
<?php
# display the session array of delivered products
foreach ($_SESSION["supplied_products"] as $key => $value) {
?>
<tr>
<td><?= $key ?></td>
<td><?= $value["amount"] ?></td>
<td><?= $value["cost"] ?></td>
<td><a href="index.php?supplied=remove&product=<?= $key ?>">Remove</a></td>
</tr>
<?php
}
?>
</table>
<p>
<input type="submit" name="save_products" value="Store products" />
</p>
</form>
<?php
} else {
echo "Add supplied products";
}
?>
<p>
<b>New product</b>
</p>
<form method="post" action="index.php">
<table border="1">
<tr>
<th>Product</th>
<th>Amount</th>
<th>Cost</th>
</tr>
<tr>
<td>
<input type="text" name="supplied_product" required />
</td>
<td>
<input type="number" name="supplied_amount" min="0.01" step="0.01" value="0.01" required />
</td>
<td>
<input type="number" name="supplied_cost" min="0.01" step="0.01" value="0.01" required />
</td>
</tr>
</table>
<p>
<input type="submit" name="add_product" value="Add product">
</p>
</form>
<?php
} else {
echo "There are no awaiting deliveries";
}
?>