-
Notifications
You must be signed in to change notification settings - Fork 5
/
IssueFertilizer.php
310 lines (208 loc) · 11.1 KB
/
IssueFertilizer.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
<?php require_once('includes/connection.php'); ?>
<?php
session_start();
$officerID = $_SESSION['userID'];
$query = "SELECT OfficerID, CenterID, FName, LName FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}' LIMIT 1";
$result = mysqli_query($conn, $query);
if ($recordRow = mysqli_fetch_assoc($result)) {
$userOfficerID = $recordRow['OfficerID'];
$userCenterID = $recordRow['CenterID'];
$userFName = $recordRow['FName'];
$userLName = $recordRow['LName'];
$msgViewUser = "Login as {$userOfficerID} - {$userFName} {$userLName} under Center - {$userCenterID}";
}
if (isset($_POST['txtFarmerID'])) {
$farmerID = $_POST['txtFarmerID'];
$query1 = "SELECT FName, LName FROM FARMER WHERE FarmerID = '{$farmerID}' LIMIT 1";
$query2 = "SELECT LandID FROM CULTIVATION WHERE FarmerID = '{$farmerID}' and OfficerID = '{$officerID}'";
$result1 = mysqli_query($conn, $query1);
if ($record = mysqli_fetch_assoc($result1)) {
$msg1 = $record['FName'] . " " . $record['LName'];
$result2 = mysqli_query($conn, $query2);
} else {
$msg1 = "No such FarmerID exists";
}
}
if (isset($_POST['btnBrowseLand'])) {
$LandID = $_POST['listLandIDs'];
$query1 = "SELECT * FROM CULTIVATION WHERE LandID = '{$LandID}' LIMIT 1";
$result3 = mysqli_query($conn, $query1);
if ($recordCult = mysqli_fetch_assoc($result3)) {
$landID = $recordCult['LandID'];
$cropName = $recordCult['CropName'];
$landArea = $recordCult['LandArea'];
$month = $recordCult['Month'];
}
}
if (isset($_POST['txtLandID'])) {
$chsLandID = $_POST['txtLandID'];
$query1 = "SELECT * FROM CULTIVATION WHERE LandID = '{$chsLandID}' LIMIT 1";
$query2 = "SELECT * FROM FERTILIZER WHERE FertilizerID = ANY (SELECT FertilizerID FROM STORES WHERE CenterID = (SELECT CenterID FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}'))";
$result3 = mysqli_query($conn, $query1);
$result4 = mysqli_query($conn, $query2);
if ($recordCult = mysqli_fetch_assoc($result3)) {
$chsLandID = $recordCult['LandID'];
$chsCropName = $recordCult['CropName'];
$chsLandArea = $recordCult['LandArea'];
$chsMonth = $recordCult['Month'];
}
}
if (isset($_POST['btnBrowseFertilizer'])) {
$fertilizerName = $_POST['listFertilizers'];
$query = "SELECT a.FertilizerID, a.Description, b.QtyOnHand, b.ExpireDate FROM FERTILIZER a, STORES b WHERE a.FertilizerID = b.FertilizerID and a.FertilizerID = (SELECT FertilizerID FROM FERTILIZER WHERE Description = '{$fertilizerName}') and CenterID = (SELECT CenterID FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}')";
$result5 = mysqli_query($conn, $query);
if ($record = mysqli_fetch_assoc($result5)) {
$fertilizerID = $record['FertilizerID'];
$description = $record['Description'];
$expireDate = $record['ExpireDate'];
$qtyOnHand = $record['QtyOnHand'];
}
}
/////////////////////////////////////////////////
if (isset($_POST['txtFerilizerID'])) {
$chsFertilizerID = $_POST['txtFerilizerID'];
$query = "SELECT a.FertilizerID, a.Description, b.QtyOnHand, b.ExpireDate FROM FERTILIZER a, STORES b WHERE a.FertilizerID = b.FertilizerID and a.FertilizerID = '{$chsFertilizerID}' and CenterID = (SELECT CenterID FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}')";
$result6 = mysqli_query($conn, $query);
if ($record = mysqli_fetch_assoc($result6)) {
$chsFertilizerID = $record['FertilizerID'];
$chsDescription = $record['Description'];
$chsExpireDate = $record['ExpireDate'];
$chsQtyOnHand = $record['QtyOnHand'];
}
}
//////////////////////////////////////////////////////////////////////////
if (isset($_POST['btnSave'])) {
$farmerID = $_POST['txtFarmerID'];
$landID = $_POST['txtLandID'];
$fertilizerID = $_POST['txtFerilizerID'];
$amount = $_POST['txtAmount'];
$currentDate = date('Y-m-d');
$query1 = "SELECT QtyOnHand FROM STORES WHERE FertilizerID = '{$fertilizerID}' and CenterID = (SELECT CenterID FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}')";
$result7 = mysqli_query($conn, $query1);
$qtyOnHand = mysqli_fetch_assoc($result7)['QtyOnHand'];
$query2 = "INSERT INTO RECEIVES VALUES ('{$landID}', '{$fertilizerID}', '{$currentDate}', {$amount})";
$query3 = "UPDATE STORES SET QtyOnHand = ({$qtyOnHand} - {$amount}) WHERE FertilizerID = '{$fertilizerID}' and CenterID = (SELECT CenterID FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}')";
$result8 = mysqli_query($conn, $query2);
if ($result8) {
$result9 = mysqli_query($conn, $query3);
if ($result9) {
$msg2 = "Fertilizer Issued Successfully";
}
} else {
$msg2 = "Process Failure";
}
}
?>
<?php include('includes/header.php'); ?>
<form action="IssueFertilizer.php" method = "post">
<h1>Fertilizer Issuing</h1>
<h4><?php echo $msgViewUser ?></h4><hr>
<table>
<tr>
<td>Farmer ID : </td>
<td>
<input type="text" name = "txtFarmerID" value = "<?php echo (isset($farmerID)) ? $farmerID : ''; ?>"></input>
<button name="btnSearchID" type="submit" value="HTML">SEARCH</button>
<label for="lblMsg"><b><?php echo (isset($msg1)) ? $msg1 : ''; ?></b></label>
</td>
</tr>
<tr>
<td>Browse what Land to be Selected : </td>
<td>
<select name = "listLandIDs" style="width: 150px;">
<?php
// Iterating through the product array
while($recordLands = mysqli_fetch_assoc($result2)){
?>
<option value="<?php echo $recordLands['LandID']; ?>"><?php echo $recordLands['LandID']; ?></option>
<?php
}
?>
</select>
<button name="btnBrowseLand" type="submit" value="HTML">BROWSE</button>
<label for="lblLandID"><b><?php echo (isset($landID)) ? $landID : ''; ?></b></label>
<label for="lblCropName"><b><?php echo (isset($cropName)) ? $cropName : ''; ?></b></label>
<label for="lblLandArea"><b><?php echo (isset($landArea)) ? $landArea . " ha" : ''; ?></b></label>
<label for="lblMonth"><b><?php echo (isset($month)) ? $month : ''; ?></b></label>
</td>
</tr>
<tr>
<td>Enter Land ID: </td>
<td>
<input type="text" name = "txtLandID" value = "<?php echo (isset($chsLandID)) ? $chsLandID : ''; ?>"></input>
<button name="btnSubmitLandID" type="submit" value="HTML">SUBMIT</button>
</td>
</tr>
<tr>
<td>Land ID : </td>
<td><label for="lblChsLandID"><b><?php echo (isset($chsLandID)) ? $chsLandID : ''; ?></b></label></td>
</tr>
<tr>
<td>Crop Name : </td>
<td><label for="lblChsCropName"><b><?php echo (isset($chsCropName)) ? $chsCropName : ''; ?></b></label></td>
</tr>
<tr>
<td>Land Area : </td>
<td><label for="lblChsLandArea"><b><?php echo (isset($chsLandArea)) ? $chsLandArea . " ha" : ''; ?></b></label></td>
</tr>
<tr>
<td>Month : </td>
<td><label for="lblChsMonth"><b><?php echo (isset($chsMonth)) ? $chsMonth : ''; ?></b></label></td>
</tr>
<tr>
<td>Browse what Fertilizer to be selected : </td>
<td>
<select name = "listFertilizers" style="width: 150px;">
<?php
// Iterating through the product array
while($recFertilizer = mysqli_fetch_assoc($result4)){
?>
<option value="<?php echo $recFertilizer['Description']; ?>"><?php echo $recFertilizer['Description']; ?></option>
<?php
}
?>
</select>
<button name="btnBrowseFertilizer" type="submit" value="HTML">BROWSE</button>
<label for="lblFertilizerID"><b><?php echo (isset($fertilizerID)) ? $fertilizerID : ''; ?></label>
<label for="lblDescription"><b><?php echo (isset($description)) ? $description : ''; ?></label>
<label for="lblExpireDate"><b><?php echo (isset($expireDate)) ? $expireDate : ''; ?></label>
<label for="lblQtyOnHand"><b><?php echo (isset($qtyOnHand)) ? $qtyOnHand . " kgs" : ''; ?></label>
</td>
</tr>
<tr>
<td>Fertilizer ID : </td>
<td>
<input type="text" name = "txtFerilizerID" value = "<?php echo (isset($chsFertilizerID)) ? $chsFertilizerID : ''; ?>"></input>
<button name="btnSubmitFertilizerID" type="submit" value="HTML">SUBMIT</button>
</td>
</tr>
<tr>
<td>Fertilizer ID : </td>
<td><label for="lblChsFertilizerID"><b><?php echo (isset($chsFertilizerID)) ? $chsFertilizerID : ''; ?></b></label></td>
</tr>
<tr>
<td>Description : </td>
<td><label for="lblChsDescription"><b><?php echo (isset($chsDescription)) ? $chsDescription : ''; ?></b></label></td>
</tr>
<tr>
<td>Date of Expiry : </td>
<td><label for="lblChsExpireDate"><b><?php echo (isset($chsExpireDate)) ? $chsExpireDate : ''; ?></b></label></td>
</tr>
<tr>
<td>Qty on Hand : </td>
<td><label for="lblChsQtyOnHand"><b><?php echo (isset($chsQtyOnHand)) ? $chsQtyOnHand . " kgs": ''; ?></b></label></td>
</tr>
<tr>
<td>Amount : </td>
<td>
<input type="text" name = "txtAmount" value = "<?php echo (isset($amount)) ? $amount : ''; ?>"></input>
<button name="btnSave" type="submit" value="HTML">SAVE</button>
<label for="lblSaveMsg"><b><?php echo (isset($msg2)) ? $msg2 : ''; ?></b></label>
</td>
</tr>
</table>
</form>
<?php include('includes/footer.php'); ?>
</body>
</html>
<?php mysqli_close($conn); ?>