|
2 | 2 | include_once 'connection.php'; |
3 | 3 |
|
4 | 4 | $id = $_POST['data_id']; |
| 5 | + |
| 6 | +$total_qty = $_POST['total_qty']; |
5 | 7 | $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 | +} |
6 | 12 | $penalty = $_POST['penalty']; |
7 | 13 |
|
8 | 14 | $sql = "SELECT * FROM rentals WHERE id = :id"; |
|
11 | 17 | $stmt->execute(); |
12 | 18 | $item = $stmt->fetch(PDO::FETCH_ASSOC); |
13 | 19 |
|
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(); |
26 | 20 |
|
27 | 21 | $sql = "SELECT * FROM inventory WHERE id = :id"; |
28 | 22 | $stmt = $db->prepare($sql); |
29 | 23 | $stmt->bindParam(':id', $item['item_id']); |
30 | 24 | $stmt->execute(); |
31 | 25 | $row = $stmt->fetch(PDO::FETCH_ASSOC); |
32 | 26 |
|
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 | | -// } |
39 | 27 |
|
40 | 28 |
|
41 | 29 | if ($_POST['conditions'] > 1) { |
|
45 | 33 | $stmt->bindParam(':qty', $qty); |
46 | 34 | $stmt->bindParam(':penalty', $penalty); |
47 | 35 | $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(); |
56 | 36 |
|
57 | 37 | generate_logs('Item Returned Damage', $row['name'].' '.$qty.' Stock was deducted'); |
58 | 38 | header('Location: ../rents.php?type=success&message=Item Returned!'); |
|
0 commit comments