-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfeedConsumption.php
152 lines (150 loc) · 8.08 KB
/
feedConsumption.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
<?php
session_start();
if (!isset($_SESSION['Username'])) {
header("Location: index.php");
exit();
}
include 'includes/database.php';
include 'includes/action.php';
?>
<!DOCTYPE html>
<html lang="en">
<!-- head -->
<?php include "{$_SERVER['DOCUMENT_ROOT']}/epms/partials/_head.php";?>
<body id="body">
<div class="container">
<!-- top navbar -->
<?php include "{$_SERVER['DOCUMENT_ROOT']}/epms/partials/_top_navbar.php";?>
<main>
<div class="main__container">
<table>
<thead>
<th>Consumed On</th>
<th>Quantity Consumed</th>
<th>Equivalent Price</th>
<th>Employee Responsible</th>
<th colspan="2">Action</th>
</thead>
<tbody>
<?php
// calling viewMethod() method
$myrow = $feedConsumptionObject->viewMethod("FeedConsumption");
foreach($myrow as $row){
// breaking point
?>
<tr>
<td><?php echo $row['ConsDate'];?></td>
<td><?php echo $row['Quantity'];?></td>
<td><?php echo $row['Price'];?></td>
<td>
<?php
$employee = $row['Employee'];
$sql = "select FirstName, LastName from Employee, FeedConsumption where Employee.Employee_ID = $employee";
$query = new Database();
$result = $query->connect()->query($sql);
$result = mysqli_fetch_assoc($result);
// print_r($result);
echo $result['FirstName'].' '.$result['LastName'];
?>
</td>
<td>
<a class="edit_btn" href="feedConsumption.php?feedconsupdate=1&id=<?php echo $row["FeedConsumption_ID"]; ?>">Edit</a>
</td>
<td>
<a class="del_btn" href="includes/action.php?feedconsdelete=1&id=<?php echo $row["FeedConsumption_ID"]; ?>">Delete</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
if(isset($_GET["feedconsupdate"])){
// Get the Employee_ID for the employee record to be edited
$id = $_GET["id"] ?? null;
$where = array("FeedConsumption_ID" => $id);
// Call the selectEmployee method that displays the record to be edited
$row = $feedConsumptionObject->selectMethod("FeedConsumption", $where);
?>
<form action="includes/action.php" method="post">
<div class="input-group">
<input type="hidden" name="id" value="<?php echo $id; ?>">
</div>
<div class="input-group">
<label for="">Date</label>
<input type="date" name="ConsDate" value="<?php echo $row["ConsDate"]; ?>" required>
</div>
<div class="input-group">
<label for="">Quantity</label>
<input type="number" step="any" name="Quantity" value="<?php echo $row["Quantity"]; ?>" required>
</div>
<div class="input-group">
<label for="">Price</label>
<input type="number" step="any" name="Price" value="<?php echo $row["Price"]; ?>" required>
</div>
<div class="input-group">
<label for="">Employee Assigned</label>
<select name="Employee" id="" required>
<?php
$myrow = $employeeObject->viewMethod("Employee");
foreach($myrow as $row){
$foreignID = $row["Employee_ID"];
?>
<option class="selectoptions" value="<?php echo $foreignID; ?>"><?php echo $row["FirstName"] ?></option>
<?php
}
?>
</select>
</div>
<div class="input-group">
<button type="submit" name="feedconsedit" class="btn" value="">Update</button>
</div>
</form>
<?php
}else{
?>
<form action="includes/action.php" method="post">
<div class="input-group">
<label for="">Date</label>
<input type="date" name="ConsDate" value="" required>
</div>
<div class="input-group">
<label for="">Quantity</label>
<input type="number" step="any" name="Quantity" value="" required>
</div>
<div class="input-group">
<label for="">Price</label>
<input type="number" step="any" name="Price" value="" required>
</div>
<div class="input-group">
<!-- <label for="">Employee Assigned</label>
<input type="text" name="Employee" value=""> -->
<label for="">Employee Assigned</label>
<select name="Employee" id="" required>
<?php
$myrow = $feedConsumptionObject->viewMethod("Employee");
foreach($myrow as $row){
$foreignID = $row["Employee_ID"];
?>
<option class="selectoptions" value="<?php echo $foreignID; ?>"><?php echo $row["FirstName"] ?></option>
<?php
}
?>
</select>
</div>
<div class="input-group">
<button type="submit" name="feedconssave" class="btn">Save</button>
</div>
</form>
<?php
}
?>
</div>
</main>
<!-- sidebar nav -->
<?php include "{$_SERVER['DOCUMENT_ROOT']}/epms/partials/_side_bar.php";?>
</div>
<script src="script.js"></script>
</body>
</html>