-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfootball_received.php
685 lines (592 loc) · 38.8 KB
/
football_received.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<?php
include './include/check_login.php';
include './include/connection.php';
include_once 'include/admin-main.php';
include('access_control.php');
// Function to fetch current number from the database
function getCurrentNumber($con) {
$result = mysqli_query($con, "SELECT football_received_temp FROM challan_temp LIMIT 1");
$row = mysqli_fetch_assoc($result);
return $row['football_received_temp'];
}
// Function to update the current number in the database
function updateCurrentNumber($con, $newNumber) {
mysqli_query($con, "UPDATE challan_temp SET football_received_temp = $newNumber");
}
// Function to generate the code prefix
function generateCodePrefix($number) {
return "KSI-FR-" . $number;
}
// Function to generate the Challan number
function generateChallanNumber($con) {
$currentNumber = getCurrentNumber($con);
$codePrefix = generateCodePrefix($currentNumber);
// Increment current number for the next time
updateCurrentNumber($con, $currentNumber + 1);
return $codePrefix;
}
function viewChallanNumber($con) {
$currentNumber = getCurrentNumber($con);
$codePrefix = generateCodePrefix($currentNumber);
return $codePrefix;
}
$challan_no = viewChallanNumber($con);
// Fetch stitcher names from the database
$stitcher_query = "SELECT DISTINCT stitcher_name FROM kits_job_work WHERE status = 0 ORDER BY stitcher_name ASC";
$stitcher_result = mysqli_query($con, $stitcher_query);
// Fetch associated challan numbers for selected stitcher
if (isset($_POST['stitcher_name'])) {
$selected_stitcher = mysqli_real_escape_string($con, $_POST['stitcher_name']);
$challan_query_issue = "SELECT DISTINCT challan_no_issue FROM kits_job_work WHERE stitcher_name = '$selected_stitcher' AND status = 0";
$challan_result_issue = mysqli_query($con, $challan_query_issue);
}
// Fetch product names based on selected stitcher and challan number
if (isset($_POST['challan_no_issue'])) {
$selected_challan = mysqli_real_escape_string($con, $_POST['challan_no_issue']);
$selected_stitcher = mysqli_real_escape_string($con, $_POST['stitcher_name']); // Added this line
// Query to fetch products based on selected stitcher, challan number, and status = 0
$product_query = "SELECT DISTINCT product_name,product_base,product_color FROM kits_job_work WHERE stitcher_name = '$selected_stitcher' AND challan_no_issue = '$selected_challan' AND status = 0";
$product_result = mysqli_query($con, $product_query);
}
if (isset($_POST['add_product'])) {
// Validate input
if (empty($_POST['product_name']) || empty($_POST['product_base']) || empty($_POST['product_color']) || empty($_POST['date_and_time'])) {
$errors[] = "Please fill in all fields.";
} else {
$stitcher_name = isset($_POST['stitcher_name']) ? mysqli_real_escape_string($con, $_POST['stitcher_name']) : "";
$product_name = mysqli_real_escape_string($con, $_POST['product_name']);
$product_base = mysqli_real_escape_string($con, $_POST['product_base']);
$product_color = mysqli_real_escape_string($con, $_POST['product_color']);
$stitcher_ist_company_ist = mysqli_real_escape_string($con, $_POST['stitcher_ist_company_ist']);
$stitcher_iind_company_iind = mysqli_real_escape_string($con, $_POST['stitcher_iind_company_iind']);
$stitcher_iind_company_ist = mysqli_real_escape_string($con, $_POST['stitcher_iind_company_ist']);
$stitcher_ist_company_iind = mysqli_real_escape_string($con, $_POST['stitcher_ist_company_iind']);
$stitcher_ist_company_ist = isset($_POST['stitcher_ist_company_ist']) ? intval($_POST['stitcher_ist_company_ist']) : 0;
$stitcher_iind_company_iind = isset($_POST['stitcher_iind_company_iind']) ? intval($_POST['stitcher_iind_company_iind']) : 0;
$stitcher_iind_company_ist = isset($_POST['stitcher_iind_company_ist']) ? intval($_POST['stitcher_iind_company_ist']) : 0;
$stitcher_ist_company_iind = isset($_POST['stitcher_ist_company_iind']) ? intval($_POST['stitcher_ist_company_iind']) : 0;
// Calculate total
$total = $stitcher_ist_company_ist + $stitcher_iind_company_iind + $stitcher_iind_company_ist + $stitcher_ist_company_iind;
// If input is empty, default to zero
if ($_POST['stitcher_ist_company_ist'] === '' && isset($_POST['stitcher_ist_company_ist'])) {
$stitcher_ist_company_ist = 0;
}
if ($_POST['stitcher_iind_company_iind'] === '' && isset($_POST['stitcher_iind_company_iind'])) {
$stitcher_iind_company_iind = 0;
}
if ($_POST['stitcher_iind_company_ist'] === '' && isset($_POST['stitcher_iind_company_ist'])) {
$stitcher_iind_company_ist = 0;
}
if ($_POST['stitcher_ist_company_iind'] === '' && isset($_POST['stitcher_ist_company_iind'])) {
$stitcher_ist_company_iind = 0;
}
// Fetch existing issue quantity
$issue_quantity_query = "SELECT issue_quantity FROM kits_job_work WHERE challan_no_issue = '$selected_challan' AND stitcher_name = '$stitcher_name' AND product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$issue_quantity_result = mysqli_query($con, $issue_quantity_query);
if ($issue_quantity_result && mysqli_num_rows($issue_quantity_result) > 0) {
$issue_quantity_row = mysqli_fetch_assoc($issue_quantity_result);
$existing_issue_quantity = $issue_quantity_row['issue_quantity'];
// Check if total exceeds existing issue quantity
if ($total > $existing_issue_quantity) {
$errors[] = "The entered quantity exceeds the balance quantity.";
} else {
// Fetch existing remaining quantity for Ist Company Ist
$existing_remaining_quantity_ist_company_ist_query = "SELECT remaining_quantity FROM products WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$existing_remaining_quantity_ist_company_ist_result = mysqli_query($con, $existing_remaining_quantity_ist_company_ist_query);
$row_ist_company_ist = mysqli_fetch_assoc($existing_remaining_quantity_ist_company_ist_result);
$existing_remaining_quantity_ist_company_ist = $row_ist_company_ist['remaining_quantity'];
// Fetch existing remaining quantity for IInd Company IInd
$existing_remaining_quantity_iind_company_iind_query = "SELECT remaining_quantity FROM products WHERE product_name = '$product_name IIND' AND product_base = 'MIX COLOR' AND product_color = 'MIX COLOR'";
$existing_remaining_quantity_iind_company_iind_result = mysqli_query($con, $existing_remaining_quantity_iind_company_iind_query);
$row_iind_company_iind = mysqli_fetch_assoc($existing_remaining_quantity_iind_company_iind_result);
$existing_remaining_quantity_iind_company_iind = $row_iind_company_iind['remaining_quantity'];
// Calculate new remaining quantity
$new_remaining_quantity_ist_company_ist = $existing_remaining_quantity_ist_company_ist + $stitcher_ist_company_ist + $stitcher_iind_company_ist;
$new_remaining_quantity_iind_company_iind = $existing_remaining_quantity_iind_company_iind + $stitcher_iind_company_iind + $stitcher_ist_company_iind ;
// Update remaining quantity in products table for Ist Company Ist
$update_remaining_quantity_ist_company_ist_query = "UPDATE products SET remaining_quantity = '$new_remaining_quantity_ist_company_ist' WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$update_remaining_quantity_ist_company_ist_result = mysqli_query($con, $update_remaining_quantity_ist_company_ist_query);
// Update remaining quantity in products table for IInd Company IInd
$update_remaining_quantity_iind_company_iind_query = "UPDATE products SET remaining_quantity = '$new_remaining_quantity_iind_company_iind' WHERE product_name = '$product_name IIND' AND product_base = 'MIX COLOR' AND product_color = 'MIX COLOR'";
$update_remaining_quantity_iind_company_iind_result = mysqli_query($con, $update_remaining_quantity_iind_company_iind_query);
// Update issue quantity in the database
$updated_issue_quantity = max(0, $existing_issue_quantity - $total); // Ensure issue quantity doesn't go negative
$update_issue_quantity_query = "UPDATE kits_job_work SET issue_quantity = '$updated_issue_quantity' WHERE challan_no_issue = '$selected_challan' AND stitcher_name = '$stitcher_name' AND product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$update_issue_quantity_result = mysqli_query($con, $update_issue_quantity_query);
if ($update_issue_quantity_result) {
// Check if issue quantity became 0 and update status accordingly
if ($updated_issue_quantity == 0) {
$update_status_query = "UPDATE kits_job_work SET status = 1 WHERE challan_no_issue = '$selected_challan' AND stitcher_name = '$stitcher_name' AND product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$update_status_result = mysqli_query($con, $update_status_query);
if (!$update_status_result) {
$errors[] = "Failed to update status in the database.";
}
}
if (!$update_remaining_quantity_ist_company_ist_result || !$update_remaining_quantity_iind_company_iind_result) {
$errors[] = "Failed to update remaining quantity in the database.";
}
// Insert data into temporary session storage
$temp_product = array(
'challan_no' => $challan_no,
'stitcher_name' => $stitcher_name,
'challan_no_issue' => $selected_challan,
'product_name' => $product_name,
'product_base' => $product_base,
'product_color' => $product_color,
'stitcher_ist_company_ist' => $stitcher_ist_company_ist,
'stitcher_iind_company_iind' => $stitcher_iind_company_iind,
'stitcher_iind_company_ist' => $stitcher_iind_company_ist,
'stitcher_ist_company_iind' => $stitcher_ist_company_iind,
'total' => $total,
'date_and_time' => isset($_POST['date_and_time']) ? $_POST['date_and_time'] : date('Y-m-d H:i:s')
);
$_SESSION['temp_products'][] = $temp_product;
// Redirect to the same page to reset form fields
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
} else {
$errors[] = "Failed to update issue quantity in the database.";
}
}
}
}
}
if (isset($_POST['delete_product'])) {
$delete_index = $_POST['delete_index'];
if (isset($_SESSION['temp_products'][$delete_index])) {
$temp_product = $_SESSION['temp_products'][$delete_index];
$stitcher_name = mysqli_real_escape_string($con, $temp_product['stitcher_name']);
$product_name = mysqli_real_escape_string($con, $temp_product['product_name']);
$product_base = mysqli_real_escape_string($con, $temp_product['product_base']);
$product_color = mysqli_real_escape_string($con, $temp_product['product_color']);
$stitcher_ist_company_ist = intval($temp_product['stitcher_ist_company_ist']);
$stitcher_iind_company_iind = intval($temp_product['stitcher_iind_company_iind']);
$stitcher_iind_company_ist = intval($temp_product['stitcher_iind_company_ist']);
$stitcher_ist_company_iind = intval($temp_product['stitcher_ist_company_iind']);
$total = intval($temp_product['total']);
// Revert remaining quantities in the products table
// Fetch existing remaining quantity for Ist Company Ist
$existing_remaining_quantity_ist_company_ist_query = "SELECT remaining_quantity FROM products WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$existing_remaining_quantity_ist_company_ist_result = mysqli_query($con, $existing_remaining_quantity_ist_company_ist_query);
$row_ist_company_ist = mysqli_fetch_assoc($existing_remaining_quantity_ist_company_ist_result);
$existing_remaining_quantity_ist_company_ist = $row_ist_company_ist['remaining_quantity'];
// Fetch existing remaining quantity for IInd Company IInd
$existing_remaining_quantity_iind_company_iind_query = "SELECT remaining_quantity FROM products WHERE product_name = '$product_name IIND' AND product_base = 'MIX COLOR' AND product_color = 'MIX COLOR'";
$existing_remaining_quantity_iind_company_iind_result = mysqli_query($con, $existing_remaining_quantity_iind_company_iind_query);
$row_iind_company_iind = mysqli_fetch_assoc($existing_remaining_quantity_iind_company_iind_result);
$existing_remaining_quantity_iind_company_iind = $row_iind_company_iind['remaining_quantity'];
// Calculate new remaining quantity
$new_remaining_quantity_ist_company_ist = max(0, $existing_remaining_quantity_ist_company_ist - ($stitcher_ist_company_ist + $stitcher_iind_company_ist));
$new_remaining_quantity_iind_company_iind = max(0, $existing_remaining_quantity_iind_company_iind - ($stitcher_iind_company_iind + $stitcher_ist_company_iind));
// Update remaining quantity in products table for Ist Company Ist
$update_remaining_quantity_ist_company_ist_query = "UPDATE products SET remaining_quantity = '$new_remaining_quantity_ist_company_ist' WHERE product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$update_remaining_quantity_ist_company_ist_result = mysqli_query($con, $update_remaining_quantity_ist_company_ist_query);
// Update remaining quantity in products table for IInd Company IInd
$update_remaining_quantity_iind_company_iind_query = "UPDATE products SET remaining_quantity = '$new_remaining_quantity_iind_company_iind' WHERE product_name = '$product_name IIND' AND product_base = 'MIX COLOR' AND product_color = 'MIX COLOR'";
$update_remaining_quantity_iind_company_iind_result = mysqli_query($con, $update_remaining_quantity_iind_company_iind_query);
if ($update_remaining_quantity_ist_company_ist_result && $update_remaining_quantity_iind_company_iind_result) {
// Fetch existing issue quantity
$issue_quantity_query = "SELECT issue_quantity FROM kits_job_work WHERE challan_no_issue = '{$temp_product['challan_no_issue']}' AND stitcher_name = '$stitcher_name' AND product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$issue_quantity_result = mysqli_query($con, $issue_quantity_query);
if ($issue_quantity_result && mysqli_num_rows($issue_quantity_result) > 0) {
$issue_quantity_row = mysqli_fetch_assoc($issue_quantity_result);
$existing_issue_quantity = $issue_quantity_row['issue_quantity'];
// Update issue quantity in the database
$updated_issue_quantity = $existing_issue_quantity + $total;
$update_issue_quantity_query = "UPDATE kits_job_work SET issue_quantity = '$updated_issue_quantity' WHERE challan_no_issue = '{$temp_product['challan_no_issue']}' AND stitcher_name = '$stitcher_name' AND product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$update_issue_quantity_result = mysqli_query($con, $update_issue_quantity_query);
if ($update_issue_quantity_result) {
// Check if issue quantity is now more than 0 and update status accordingly
if ($updated_issue_quantity > 0) {
$update_status_query = "UPDATE kits_job_work SET status = 0 WHERE challan_no_issue = '{$temp_product['challan_no_issue']}' AND stitcher_name = '$stitcher_name' AND product_name = '$product_name' AND product_base = '$product_base' AND product_color = '$product_color'";
$update_status_result = mysqli_query($con, $update_status_query);
if (!$update_status_result) {
$errors[] = "Failed to update status in the database.";
}
}
// Remove the product from the session
unset($_SESSION['temp_products'][$delete_index]);
// Reset array keys to maintain consecutive numbering
$_SESSION['temp_products'] = array_values($_SESSION['temp_products']);
// Redirect to prevent form resubmission
header("Location: {$_SERVER['REQUEST_URI']}");
exit();
} else {
$errors[] = "Failed to update issue quantity in the database.";
}
}
} else {
$errors[] = "Failed to update remaining quantity in the database.";
}
}
}
// Store added products in the database when "Submit" button is clicked
if (isset($_POST['submit_form'])) {
$temp_products = isset($_SESSION['temp_products']) ? $_SESSION['temp_products'] : [];
if (empty($temp_products)) {
$errors[] = "Please add at least one product.";
} else {
foreach ($temp_products as $product) {
$stitcher_name = mysqli_real_escape_string($con, $product['stitcher_name']);
$product_name = mysqli_real_escape_string($con, $product['product_name']);
$product_base = mysqli_real_escape_string($con, $product['product_base']);
$product_color = mysqli_real_escape_string($con, $product['product_color']);
$stitcher_ist_company_ist = mysqli_real_escape_string($con, $product['stitcher_ist_company_ist']);
$total = mysqli_real_escape_string($con, $product['total']);
$stitcher_iind_company_iind = mysqli_real_escape_string($con, $product['stitcher_iind_company_iind']);
$stitcher_iind_company_ist = mysqli_real_escape_string($con, $product['stitcher_iind_company_ist']);
$stitcher_ist_company_ist = mysqli_real_escape_string($con, $product['stitcher_ist_company_ist']);
$stitcher_ist_company_iind = mysqli_real_escape_string($con, $product['stitcher_ist_company_iind']);
$date_and_time = mysqli_real_escape_string($con, $product['date_and_time']);
// Insert product into the database
$insert_query = "INSERT INTO football_received ( challan_no, stitcher_name, product_name, product_base, product_color, S_Ist_C_Ist, S_IInd_C_IInd, S_IInd_C_Ist, S_Ist_C_IInd, total, date_and_time)
VALUES ( '$challan_no', '$stitcher_name', '$product_name', '$product_base', '$product_color', '$stitcher_ist_company_ist', '$stitcher_iind_company_iind', '$stitcher_iind_company_ist', '$stitcher_ist_company_iind', '$total', '$date_and_time')";
$insert_result = mysqli_query($con, $insert_query);
if (!$insert_result) {
$errors[] = "Failed to store data in the database.";
}
}
// If no errors, update the Challan Number and clear session storage
if (empty($errors)) {
// Update Challan Number
$challan_no = generateChallanNumber($con);
// Clear session storage after insertion
unset($_SESSION['temp_products']);
// Redirect to the same page to prevent form resubmission
header("Location: {$_SERVER['REQUEST_URI']}");
exit();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Football Receiving Form</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fc;
font-family: Arial, sans-serif;
}
.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 {
margin-top: 2rem;
}
#printbtn{
display:flex;
justify-content:space-between;
align-items: flex-end;
}
.error-input {
border: 1px solid red;
}
#btn_grp{
display: flex;
gap: 15px;
}
.btn-group{
display: flex;
gap: 1rem;
}
</style>
</head>
<body>
<?php include('include/football_nav.php'); ?>
<div class="container-fluid mt-5"> <!-- Changed container to container-fluid -->
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<h1 class="h4 text-center mb-4">Football Receiving Form</h1>
<?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="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_issue">
<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_issue']; ?>"><?php echo $row['challan_no_issue']; ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="product_name">Product Name:</label>
<select class="form-select" id="product_name" name="product_name">
<option value="" selected disabled>Select Product Name</option>
<?php if (isset($product_result)) : ?>
<?php while ($row = mysqli_fetch_assoc($product_result)) : ?>
<option value="<?php echo $row['product_name']; ?>"><?php echo $row['product_name']; ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="product_base">Product Base:</label>
<select class="form-select" id="product_base" name="product_base" >
<option value="" selected disabled>Select Product Base</option>
<?php if (isset($product_base_result)) : ?>
<?php while ($row = mysqli_fetch_assoc($product_base_result)) : ?>
<option value="<?php echo $row['product_base']; ?>"><?php echo $row['product_base']; ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="product_color">Product Color:</label>
<select class="form-select" id="product_color" name="product_color" >
<option value="" selected disabled>Select Product Color</option>
<?php if (isset($product_color_result)) : ?>
<?php while ($row = mysqli_fetch_assoc($product_color_result)) : ?>
<option value="<?php echo $row['product_color']; ?>"><?php echo $row['product_color']; ?></option>
<?php endwhile; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="stitcher_ist_company_ist">Stitcher Ist Company Ist:</label>
<input type="number" class="form-control" id="stitcher_ist_company_ist" name="stitcher_ist_company_ist" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="stitcher_ist_company_iind">Stitcher Ist Company IInd:</label>
<input type="number" class="form-control" id="stitcher_ist_company_iind" name="stitcher_ist_company_iind" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="stitcher_iind_company_ist">Stitcher IInd Company Ist:</label>
<input type="number" class="form-control" id="stitcher_iind_company_ist" name="stitcher_iind_company_ist" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="stitcher_iind_company_iind">Stitcher IInd Company IInd:</label>
<input type="number" class="form-control" id="stitcher_iind_company_iind" name="stitcher_iind_company_iind" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="date_and_time">Date and Time:</label>
<input type="datetime-local" class="form-control" id="date_and_time" name="date_and_time">
</div>
</div>
</div>
<div id="printbtn" class="btn-group">
<div>
<button type="submit" class="btn btn-primary" name="add_product">Add Product</button>
<button type="submit" class="btn btn-primary" name="submit_form">Submit</button>
</div>
<div>
<a href="print_football_receive_slip.php" >Print Issue Slip </a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Display table with added products -->
<div class="row justify-content-center">
<div class="col-lg-10">
<div class="card mt-5">
<div class="added-products">
<h2 class="text-center mb-3">Added Products:</h2>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Challan No</th>
<th>Stitcher Name</th>
<th>Issue Challan No</th>
<th>Product Name</th>
<th>Product Base</th>
<th>Product Color</th>
<th>Stitcher Ist Company Ist</th>
<th>Stitcher IInd Company IInd</th>
<th>Stitcher IInd Company Ist</th>
<th>Stitcher Ist Company IInd</th>
<th>Total</th>
<th>Date</th>
<th>Delete Product</th>
</tr>
</thead>
<tbody>
<?php if (isset($_SESSION['temp_products'])) : ?>
<?php foreach ($_SESSION['temp_products'] as $key => $product) : ?>
<tr>
<td><?php echo $product['challan_no']; ?></td>
<td><?php echo $product['stitcher_name']; ?></td>
<td><?php echo $product['challan_no_issue']; ?></td>
<td><?php echo $product['product_name']; ?></td>
<td><?php echo $product['product_base']; ?></td>
<td><?php echo $product['product_color']; ?></td>
<td><?php echo $product['stitcher_ist_company_ist']; ?></td>
<td><?php echo $product['stitcher_iind_company_iind']; ?></td>
<td><?php echo $product['stitcher_iind_company_ist']; ?></td>
<td><?php echo $product['stitcher_ist_company_iind']; ?></td>
<td><?php echo $product['stitcher_ist_company_ist'] + $product['stitcher_iind_company_iind'] + $product['stitcher_iind_company_ist'] + $product['stitcher_ist_company_iind']; ?></td>
<td><?php echo $product['date_and_time']; ?></td>
<td>
<form method="post" action="">
<input type="hidden" name="delete_index" value="<?php echo $key; ?>">
<button type="submit" class="btn btn-danger" name="delete_product">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
document.getElementById("select_stitcher").addEventListener("change", function() {
var selectedStitcher = this.value;
fetchChallanNumbers(selectedStitcher);
});
function fetchChallanNumbers(selectedStitcher) {
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 Challan No</option>";
challanNumbers.forEach(function(challan) {
var option = document.createElement("option");
option.value = challan;
option.text = challan;
challanSelect.appendChild(option);
});
}
};
xhttp.open("GET", "fetch_challan_numbers.php?stitcher=" + selectedStitcher, true);
xhttp.send();
}
</script>
<script>
document.getElementById("select_challan").addEventListener("change", function() {
var selectedChallan = this.value;
fetchProductNames(selectedChallan);
});
function fetchProductNames(selectedChallan) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var productSelect = document.getElementById("product_name");
var productNames = JSON.parse(this.responseText);
productSelect.innerHTML = "<option value='' selected disabled>Select Product Name</option>";
productNames.forEach(function(product) {
var option = document.createElement("option");
option.value = product;
option.text = product;
productSelect.appendChild(option);
});
}
};
xhttp.open("GET", "fetch_product_name_football.php?challan_no=" + selectedChallan, true);
xhttp.send();
}
</script>
<script>
document.getElementById("product_name").addEventListener("change", function() {
var productName = this.value;
var selectedChallan = document.getElementById("select_challan").value;
fetchProductBase(productName, selectedChallan);
});
function fetchProductBase(productName, selectedChallan) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var productBaseSelect = document.getElementById("product_base");
productBaseSelect.innerHTML = "<option value='' selected disabled>Select Product Base</option>"; // Clear previous options
var productBaseData = JSON.parse(this.responseText);
productBaseData.forEach(function(productBase) {
var option = document.createElement("option");
option.value = productBase;
option.text = productBase;
productBaseSelect.appendChild(option);
});
}
};
xhttp.open("GET", "fetch-product_base_football.php?product_name=" + encodeURIComponent(productName) + "&challan_no_issue=" + encodeURIComponent(selectedChallan), true);
xhttp.send();
}
</script>
<script>
document.getElementById("product_base").addEventListener("change", function() {
var selectedChallan = document.getElementById("select_challan").value;
var productName = document.getElementById("product_name").value;
var productBase = this.value;
fetchProductColor(selectedChallan, productName, productBase);
});
function fetchProductColor(selectedChallan, productName, productBase) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var productColorSelect = document.getElementById("product_color");
productColorSelect.innerHTML = "<option value='' selected disabled>Select Product Color</option>"; // Clear previous options
var productColorData = JSON.parse(this.responseText);
productColorData.forEach(function(productColor) {
var option = document.createElement("option");
option.value = productColor;
option.text = productColor;
productColorSelect.appendChild(option);
});
}
};
xhttp.open("GET", "fetch_product_color_football.php?challan_no_issue=" + encodeURIComponent(selectedChallan) + "&product_name=" + encodeURIComponent(productName) + "&product_base=" + encodeURIComponent(productBase), true);
xhttp.send();
}
</script>
</body>
</html>