-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrestock.php
185 lines (151 loc) · 5.1 KB
/
restock.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
<?php
session_start();
if(!isset($_SESSION['Eid']))
header('location:login.php');
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "supermarket";
?>
<?php include "head.php"; ?>
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class = "container-fluid row padding" >
<div class="col-lg-4 col-md-6 col-sm-6" >
<h1 style = "padding-left: 15%"><br>Restock : </h1>
</div>
<div class="col-lg-8 col-md-6 col-sm-6" >
<form method="post">
<label><h5>Showroom ID</h5></label>
<br>
<select name="Sid">
<?php
$mysqli = new mysqli($servername, $username, $password, $dbname);
$sqlSelect="SELECT * FROM showroom";
$result = $mysqli-> query ($sqlSelect);
while ($row = mysqli_fetch_array($result)) {
$rows[] = $row;
}
foreach ($rows as $row) {
print "<option value='" . $row['Showroom_ID'] . "'>" .$row['Showroom_ID']."(". $row['Showroom_Name'] . ")</option>";
}
?>
</select>
<br><br>
<label><h5>Godown ID</h5></label>
<br>
<select name="Gid">
<?php
$mysqli = new mysqli($servername, $username, $password, $dbname);
$sqlSelect="SELECT * FROM godown";
$result = $mysqli-> query ($sqlSelect);
while ($row = mysqli_fetch_array($result)) {
$rows1[] = $row;
}
foreach ($rows1 as $row) {
print "<option value='" . $row['Godown_ID'] . "'>" .$row['Godown_ID']."(". $row['Godown_Location'] . ")</option>";
}
?>
</select>
<br><br>
<label><h5>Date of Restock</h5></label>
<br>
<input type="Date" name="date">
<br><br>
<button type="submit" name="button1">Add</button>
</form>
</div>
</div>
<?php
function isGodownManager($mid, $gid)
{
$q = "select * from godown where Godown_ID = $gid and Manager_ID = $mid";
$con = mysqli_connect("127.0.0.1","root","");
mysqli_select_db($con, "supermarket");
$result = mysqli_query($con, $q);
$n = mysqli_num_rows($result);
return $n > 0;
}
function isShowroomManager($mid, $sid)
{
$q = "select * from showroom where Showroom_ID = $sid and Manager_ID = $mid";
$con = mysqli_connect("127.0.0.1","root","");
mysqli_select_db($con, "supermarket");
$result = mysqli_query($con, $q);
$n = mysqli_num_rows($result);
return $n > 0;
}
if(isset($_POST['button1']))
{
$Gid = $_POST['Gid'];
$Sid = $_POST['Sid'];
$input_date = $_POST['date'];
$date=date("Y-m-d",strtotime($input_date));
if(isGodownManager($_SESSION['Eid'], $Gid) || isShowroomManager($_SESSION['Eid'], $Sid))
{
$q = "select * from restock where Godown_ID = '$Gid' and Showroom_ID = '$Sid' and DOR = '$date'";
$con = mysqli_connect("127.0.0.1","root","");
mysqli_select_db($con, "supermarket");
$result = mysqli_query($con, $q);
$n = mysqli_num_rows($result);
// echo $n."<br><br>";
if($n != 0)
{
$q = "select Restock_ID from restock where Godown_ID = '$Gid' and Showroom_ID = '$Sid' and DOR = '$date' limit 1";
$result = mysqli_query($con, $q);
$Pid = mysqli_fetch_row($result)[0];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "supermarket";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM restock_item_details natural join item where Restock_ID = $Pid";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class = 'table table-hover table-striped'><tr><th>Item ID</th><th>Item Name</th><th>Quantity</th><th>Price per unit</th><th>Total price</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["Item_ID"]. "</td><td>" . $row["Item_Name"]. "</td><td>" . $row["Quantity"] . "</td><td>Rs." . $row["Item_Unit_Price"] . " per " . $row["Item_Units"] ."</td><td>" . $row["Item_Unit_Price"] * $row["Quantity"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}
else
{
$q = "INSERT INTO `restock`(`Godown_ID`, `Showroom_ID`, `DOR`) VALUES ($Gid, $Sid, '$date')";
// echo $q;
if(mysqli_query($con, $q))
{
echo "Restock Added Successfully!!";
}
else
{
echo "Restock cannot be added!! Check Details again";
}
}
$q = "select Restock_ID from restock where Godown_ID = '$Gid' and Showroom_ID = '$Sid' and DOR = '$date' limit 1";
$result = mysqli_query($con, $q);
$Rid = mysqli_fetch_row($result)[0];
echo "<br><br<b><center>Restock exists!! Restock id is : $Rid</center></b><br><br>";
echo "<a href='editrestock.php?Rid=".$Rid."&Gid=".$Gid."&dor=".$date."&Sid=".$Sid."''>Edit this restock</a><br><br>";
}
else
{
echo "<center>You are not permitted to add Restock!!</center>";
}
}
?>
<br>
<center><h3><a href='home.php' style = "color : white; font-weight : bold; padding-left : 50px; text-decoration: underline">Back</a></h3></center>
<br><br><br>
</body>
</html>