Skip to content

Commit 5a7959f

Browse files
Fix bug in item-return.php preventing invalid quantity input
1 parent 08b2209 commit 5a7959f

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

assets/js/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ VANTA.WAVES({
141141
$('input[name="data_id"]').val(id);
142142
$('input[name="qty"]').val(qty - item_return);
143143
$('input[name="qty"]').attr('max', qty - item_return);
144+
$('input[name="total_qty"]').val(qty - item_return);
144145
console.log(id, qty);
145146
});
146147

functions/item-return.php

+6-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
include_once 'connection.php';
33

44
$id = $_POST['data_id'];
5+
6+
$total_qty = $_POST['total_qty'];
57
$qty = $_POST['qty'];
8+
if ($qty <= 0 || $qty > $total_qty) {
9+
header('Location: ../rents.php?type=error&message=Quantity is not valid!');
10+
exit();
11+
}
612
$penalty = $_POST['penalty'];
713

814
$sql = "SELECT * FROM rentals WHERE id = :id";
@@ -11,31 +17,13 @@
1117
$stmt->execute();
1218
$item = $stmt->fetch(PDO::FETCH_ASSOC);
1319

14-
// $sql = "UPDATE rentals SET penalty = penalty + :penalty, conditions = :conditions WHERE id = :id";
15-
// $statement = $db->prepare($sql);
16-
// $statement->bindParam(':penalty', $_POST['penalty']);
17-
// $statement->bindParam(':conditions', $_POST['conditions']);
18-
// $statement->bindParam(':id', $id);
19-
// $statement->execute();
20-
21-
// $sql = "SELECT COUNT(*) FROM rentals WHERE transact_id = :id";
22-
// $stmt = $db->prepare($sql);
23-
// $stmt->bindParam(':id', $item['transact_id']);
24-
// $stmt->execute();
25-
// $count = $stmt->fetchColumn();
2620

2721
$sql = "SELECT * FROM inventory WHERE id = :id";
2822
$stmt = $db->prepare($sql);
2923
$stmt->bindParam(':id', $item['item_id']);
3024
$stmt->execute();
3125
$row = $stmt->fetch(PDO::FETCH_ASSOC);
3226

33-
// if ($count > 0){
34-
// $sql = "UPDATE transactions SET status = 'Returned' WHERE id = :id";
35-
// $statement = $db->prepare($sql);
36-
// $statement->bindParam(':id', $item['transact_id']);
37-
// $statement->execute();
38-
// }
3927

4028

4129
if ($_POST['conditions'] > 1) {
@@ -45,14 +33,6 @@
4533
$stmt->bindParam(':qty', $qty);
4634
$stmt->bindParam(':penalty', $penalty);
4735
$stmt->execute();
48-
49-
// $stock = $row['qty'] - $qty;
50-
51-
// $sql = "UPDATE inventory SET qty = :stock WHERE id = :id";
52-
// $statement = $db->prepare($sql);
53-
// $statement->bindParam(':stock', $stock);
54-
// $statement->bindParam(':id', $item['item_id']);
55-
// $statement->execute();
5636

5737
generate_logs('Item Returned Damage', $row['name'].' '.$qty.' Stock was deducted');
5838
header('Location: ../rents.php?type=success&message=Item Returned!');

rents.php

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<div class="modal-body">
170170
<form action="functions/item-return.php" method="post">
171171
<input type="hidden" name="data_id">
172+
<input type="hidden" name="total_qty">
172173
<div class="mb-2" style="margin-top: 5px;">
173174
<label class="form-label">Item Condition</label>
174175
<select class="form-select" required="" name="conditions">

0 commit comments

Comments
 (0)