-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusages.php
More file actions
249 lines (181 loc) · 7.49 KB
/
usages.php
File metadata and controls
249 lines (181 loc) · 7.49 KB
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
<?php
$page_title = 'All Usages';
require_once('includes/load.php');
page_require_level(3);
$search = isset($_GET['search']) ? $_GET['search'] : '';
if ($search !== '') {
$usages = search_usages($search);
} else {
// If no search query, retrieve all usages
$query = "SELECT pu.id, pu.quantity, pu.date, p.specification, p.name, p.id as product_id, c.name as category_name ";
$query .= "FROM product_usage pu ";
$query .= "JOIN products p ON pu.product_id = p.id ";
$query .= "LEFT JOIN categories c ON p.categorie_id = c.id";
$usages = find_by_sql($query);
}
include_once('layouts/header.php');
?>
<div class="row">
<div class="col-md-6">
<?php echo display_msg($msg); ?>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading wrapper">
<div>
<img src="libs/logos/table-logo/active.png" alt="inventory-logo">
<span>All Active</span>
</div>
<!-- TABLE HEAD -->
<div class=" wrapper search-add">
<div class="allCategoryForm">
<form action="" method="get" class="allCategoryFormWrap">
<div class="allCategoryInput">
<input type="text" class="allCategoryInputWrap" name="search" placeholder="Search Active Items">
<button class="searchBtn" type="submit"><img src="libs/logos/table-logo/search.png" class="searchBtnImg" alt=""></button>
</div>
<span class="searchBtnClose">
<a href="usages.php">
<img src="libs/logos/table-logo/close.png"class="searchBtnCloseImg" alt="close">
</a>
</span>
</form>
</div>
<div class="table-add-btn-div">
<button class="btn btn-info pull-right btn-sm addNewGrp"> Add Active</button>
</div>
</div>
</div>
<!-- TABLE BODY -->
<div class="panel-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 50px;">#</th>
<th style="width: 40%;"> Item Name & Indent No</th>
<th style="width: 15%;"> Category </th>
<th style="width: 15%;"> Quantity</th>
<th style="width: 15%;"> Date Added </th>
<!-- <th> Specification </th> -->
<th class="text-center" style="width: 15%;"> Actions </th>
</tr>
</thead>
<tbody>
<?php foreach ($usages as $usage):?>
<tr>
<td ><?php echo count_id();?></td>
<td><?php echo get_product_name($usage['product_id']); ?></td>
<td><?php echo $usage['category_name']; ?></td> <!-- Display the category name -->
<td ><?php echo (int)$usage['quantity']; ?></td>
<td><?php echo date("M d, Y", strtotime($usage['date'])); ?></td>
<!-- <td style=""><?php echo remove_junk($usage['specification']); ?></td> -->
<td class="text-center">
<div class="btn-group edit-dlt-btn-group">
<!-- <button type="button" id="<?php echo (int)$usage['id']; ?>" class="btn btn-info pull-right btn-sm editNewGrp"> Edit Active</button> -->
<a href="edit_usage.php?id=<?php echo (int)$usage['id'];?>" class="editBtn" data-toggle="tooltip" title="Edit">
<p>Edit <img src="libs/logos/table-logo/edit.png" alt="edit-logo"></p>
</a>
<a href="#" class="categoryDeleteBtn" title="Delete" data-toggle="tooltip" onclick="confirmDelete(<?php echo $usage['id'];?>)">
<img src="libs/logos/table-logo/delete.png" alt="delete-logo">
</a>
</div>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- ADD -->
<div class="addNewgGroupPopUpWap display">
<div class="newgroupPopHeadWrap">
<div class="iconHeadGroup">
<img src="libs/logos/table-logo/inventory.png" alt="logo">
<div class="addPopGroupTitle">Add Active</div>
</div>
<div class="addNewGroupContent">
<div class="addNewForm">
<form method="post" action="add_usage.php">
<div class="inputGrup">
<label for="name">Select a Product</label>
<select class="form-control" name="product_id">
<option value="">Select a product</option>
<?php
$products = find_all('products');
foreach ($products as $product) :
?>
<option value="<?php echo $product['id']; ?>"><?php echo $product['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="inputGrup">
<label for="used_qty">Used Quantity</label>
<input type="text" class="form-control" name="used_qty">
</div>
<div class="inputGrup">
<label for="date">Date</label>
<input type="date" class="form-control datepicker" name="date" value="<?php echo date('d-m-Y'); ?>">
</div>
<div class="buttonGroup">
<div>
<div class="cancelBtn">
<button type="button">Cancel</button>
</div>
<div class="submitbtn">
<button type="submit" name="add_usage" class="btn btn-primary">Add Usage</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// Declare a variable to store the item ID
var selectedItemId = null;
// Add a click event handler to each "Edit" anchor
var editAnchors = document.querySelectorAll("a.edit-btn.addNewGrp");
editAnchors.forEach(function(anchor) {
anchor.addEventListener("click", function(event) {
event.preventDefault();
// Get the item's ID from the data attribute
selectedItemId = anchor.getAttribute("data-item-id");
// Open the edit popup
openEditPopup();
});
});
// Function to open the edit popup
function openEditPopup() {
// Get the edit popup element
var editPopup = document.querySelector(".editNewgGroupPopUpWap");
// Find the input field for the group ID in the form
var groupIdInput = editPopup.querySelector("#group-id");
// Set the value of the input field to the selected item's ID
groupIdInput.value = selectedItemId;
// Show the edit popup
editPopup.classList.add("display");
}
function confirmDelete(productId) {
if (confirm("Are you sure you want to delete this entry? This data may be lost.")) {
// Redirect to delete.products.php with the product ID
window.location.href = "delete_usage.php?id=" + productId;
}
}
function toggleQuantityField() {
var quantityField = document.querySelectorAll(".usedqnty");
var quantityTickbox = document.querySelectorAll(".quantity_tickboxes");
quantityTickbox.forEach((maindata,index)=>{
if(maindata.checked){
quantityField[index].readOnly = false;
}else{
quantityField[index].readOnly = true;
}
})
}
</script>
<?php include_once('layouts/footer.php'); ?>