forked from vishesharya/Inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkits_issue_data.php
More file actions
331 lines (288 loc) · 13.2 KB
/
Copy pathkits_issue_data.php
File metadata and controls
331 lines (288 loc) · 13.2 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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
session_start();
include_once 'include/connection.php';
include_once 'include/admin-main.php';
// Fetch stitcher names from the database
$stitcher_query = "SELECT DISTINCT stitcher_name FROM kits_issue ORDER BY stitcher_name ASC";
$stitcher_result = mysqli_query($con, $stitcher_query);
// Check if 'challan_no' is set in session
if (isset($_SESSION['challan_no'])) {
$challan_no = $_SESSION['challan_no'];
}
// Initialize $result variable
$result = null;
// Check if 'View' button is clicked
if (isset($_POST['view_entries'])) {
// Get selected stitcher
$stitcher_name = isset($_POST['stitcher_name']) ? mysqli_real_escape_string($con, $_POST['stitcher_name']) : '';
// Initialize conditions
$conditions = "";
// Add stitcher condition
if (!empty($stitcher_name)) {
$conditions .= " WHERE stitcher_name = '$stitcher_name'";
}
// Add date range condition
if (!empty($_POST['from_date']) && !empty($_POST['to_date'])) {
// Get selected date range
$start_date = mysqli_real_escape_string($con, $_POST['from_date']);
$end_date = mysqli_real_escape_string($con, $_POST['to_date']);
// Add AND or WHERE depending on whether previous conditions exist
$conditions .= ($conditions == "") ? " WHERE" : " AND";
$conditions .= " date_and_time BETWEEN '$start_date' AND '$end_date'";
}
// Add challan number condition
if (!empty($_POST['challan_no'])) {
// Get selected challan number
$challan_no = mysqli_real_escape_string($con, $_POST['challan_no']);
// Add AND or WHERE depending on whether previous conditions exist
$conditions .= ($conditions == "") ? " WHERE" : " AND";
$conditions .= " challan_no = '$challan_no'";
}
// Construct the final query
$query = "SELECT * FROM kits_issue $conditions";
$result = mysqli_query($con, $query);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KITS ISSUE DETAILS</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fc;
font-family: Arial, sans-serif;
overflow-y: scroll; /* Enable scrollbar on body */
}
.card {
border-radius: 1rem;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 1.5rem;
}
.btn-group {
margin-top: 1.5rem;
justify-content: center;
}
.table-container {
max-height: 500px;
overflow-y: auto;
margin-top: 2rem;
}
.table {
border-collapse: collapse;
width: 100%;
}
.table th, .table td {
text-align: center;
padding: 8px;
}
#printbtn {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.error-input {
border: 1px solid red;
}
.date_input {
display: flex;
}
#input_field {
margin: 0.1rem;
}
@media print {
#form {
display: none;
}
}
/* Custom scrollbar styles */
.table-container::-webkit-scrollbar {
width: 12px;
}
.table-container::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 10px;
}
.table-container::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
.table-container::-webkit-scrollbar-thumb:hover {
background: #555;
}
</style>
</head>
<body>
<?php include('include/kits_nav.php'); ?>
<div class="container-fluid mt-5">
<h1 class="h4 text-center mb-4">KITS ISSUE DETAILS </h1> <!-- Changed container to container-fluid -->
<div id="form" class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<?php if (!empty($errors)) : ?>
<div class="alert alert-danger" role="alert">
<?php foreach ($errors as $error) : ?>
<?php echo $error; ?><br>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- New form to select stitcher, associated challan number, and product details -->
<form method="post" action="">
<div class="date_input">
<!-- From date -->
<div class="col-md-6">
<div class="form-group">
<label for="from_date">From Date:</label>
<input type="date" class="form-control" id="from_date" name="from_date">
</div>
</div>
<!-- To date -->
<div class="col-md-6">
<div class="form-group">
<label for="to_date">To Date:</label>
<input type="date" class="form-control" id="to_date" name="to_date">
</div>
</div>
</div>
<div id="input_field" class="row">
<div class="col-md-6">
<div class="form-group">
<label for="select_stitcher">Select Stitcher:</label>
<select class="form-select" id="select_stitcher" name="stitcher_name">
<option value="">Select Stitcher</option>
<?php while ($row = mysqli_fetch_assoc($stitcher_result)) : ?>
<option value="<?php echo $row['stitcher_name']; ?>"><?php echo $row['stitcher_name']; ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="select_challan">Select Issue Challan No:</label>
<select class="form-select" id="select_challan" name="challan_no">
<option value="" selected disabled>Select Issue Challan No</option>
<?php if (isset($challan_result_issue)) : ?>
<?php while ($row = mysqli_fetch_assoc($challan_result_issue)) : ?>
<option value="<?php echo $row['challan_no']; ?>"><?php echo $row['challan_no']; ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</div>
</div>
</div>
<div id="printbtn" class="btn-group">
<div>
<button type="submit" class="btn btn-primary" name="view_entries">View</button>
<button type="button" class="btn btn-primary" onclick="window.print()">Print</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php if (isset($_POST['view_entries']) && mysqli_num_rows($result) > 0): ?>
<table class="table datatable-multi-sorting">
<thead>
<tr>
<th>Sn.</th>
<th>Challan No.</th>
<th>Stitcher Name</th>
<th>Product Name</th>
<th>Product Base</th>
<th>Product Color</th>
<th>Issue Quantity</th>
<th>Bladder Name</th>
<th>Bladder Quantity</th>
<th>Thread Name</th>
<th>Thread Quantity</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
// Initialize variables to hold totals
$total_issue_quantity = 0;
$total_bladder_quantity = 0;
$total_thread_quantity = 0;
?>
<?php $sn = 1; ?>
<?php while ($data = mysqli_fetch_array($result)): ?>
<tr>
<td><?php echo $sn; ?>.</td>
<td><?php echo $data['challan_no']; ?></td>
<td><?php echo $data['stitcher_name']; ?></td>
<td><?php echo $data['product_name']; ?></td>
<td><?php echo ucfirst($data['product_base']); ?></td>
<td><?php echo ucfirst($data['product_color']); ?></td>
<td><?php echo $data['issue_quantity']; ?></td>
<td><?php echo $data['bladder_name']; ?></td>
<td><?php echo $data['bladder_quantity']; ?></td>
<td><?php echo $data['thread_name']; ?></td>
<td><?php echo $data['thread_quantity']; ?></td>
<td><?php echo date('d/m/Y', strtotime($data['date_and_time'])); ?></td>
</tr>
<?php $sn++; ?>
<?php
$total_issue_quantity += $data['issue_quantity'];
$total_bladder_quantity += $data['bladder_quantity'];
$total_thread_quantity += $data['thread_quantity'];
?>
<?php endwhile; ?>
<tr>
<td colspan="5"></td> <!-- Colspan to span across columns -->
<td><b>Total : </b></td>
<td><?php echo $total_issue_quantity; ?></td>
<td></td> <!-- Empty cell for bladder name -->
<td><?php echo $total_bladder_quantity; ?></td>
<td></td> <!-- Empty cell for thread name -->
<td><?php echo $total_thread_quantity; ?></td>
<td colspan="1"></td> <!-- Colspan to span across date column -->
</tr>
</tbody>
</table>
<?php elseif (isset($_POST['view_entries'])): ?>
<p>No entries found.</p>
<?php endif; ?>
<!-- JavaScript code for fetching challan numbers based on selected stitcher and date range -->
<script>
function fetchChallanNumbers(selectedStitcher, fromDate, toDate) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var challanSelect = document.getElementById("select_challan");
var challanNumbers = JSON.parse(this.responseText);
challanSelect.innerHTML = "<option value='' selected disabled>Select Issue Challan No</option>";
challanNumbers.forEach(function(challan) {
var option = document.createElement("option");
option.value = challan;
option.text = challan;
challanSelect.appendChild(option);
});
}
};
xhttp.open("GET", "fatch_challan_no_for_kits_issue.php?stitcher=" + selectedStitcher + "&from_date=" + fromDate + "&to_date=" + toDate, true);
xhttp.send();
}
function handleDateRangeChange() {
var selectedStitcher = document.getElementById("select_stitcher").value;
var fromDate = document.getElementById("from_date").value;
var toDate = document.getElementById("to_date").value;
if (selectedStitcher && fromDate && toDate) {
fetchChallanNumbers(selectedStitcher, fromDate, toDate);
}
}
document.getElementById("from_date").addEventListener("change", handleDateRangeChange);
document.getElementById("to_date").addEventListener("change", handleDateRangeChange);
document.getElementById("select_stitcher").addEventListener("change", function() {
handleDateRangeChange();
});
</script>
</body>
</html>