Skip to content

Commit 445668f

Browse files
Fix negative quantity validation and update stock
calculation
1 parent ec1ef92 commit 445668f

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

functions/stock-in.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$id = $_POST['data_id'];
55
$qty = $_POST['qty'];
66

7-
if ($qty < 0) {
7+
if ($qty < 0) {
88
header('Location: ../supply.php?type=error&message=Invalid quantity!');
99
exit();
1010
}

functions/stock-out.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
exit();
2121
}
2222

23-
$stock = $qty - $row['stock'];
23+
$stock = $row['stock'] - $qty;
2424

2525
$sql = "UPDATE items SET stock = :stock WHERE id = :id";
2626
$statement = $db->prepare($sql);

reciept.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2+
include_once 'functions/connection.php';
23
session_start();
34
if (!isset($_SESSION['username'])) {
45
header('location:login.php');
56
}
6-
77
$id = $_GET['id'];
88
$kilo = $_GET['kilo'];
99
$type = $_GET['type'];
@@ -12,6 +12,16 @@
1212
$total = $_GET['total'];
1313
$get_tracking_url = getHostByName(getHostName()) . dirname($_SERVER['PHP_SELF']) . '/tracking.php?id=' . $id;
1414

15+
$sql = 'SELECT Transactions.id, customers.fullname AS fullname
16+
FROM Transactions
17+
JOIN users ON Transactions.user_id = users.id
18+
JOIN customers ON Transactions.customer_id = customers.id
19+
WHERE Transactions.id = :id';
20+
$stmt = $db->prepare($sql);
21+
$stmt->execute(['id' => $id]);
22+
$result = $stmt->fetch();
23+
24+
1525
?>
1626
<!DOCTYPE html>
1727
<html data-bs-theme="light" lang="en">
@@ -36,29 +46,33 @@
3646
<div class="card-body text-center p-4">
3747
<span class="badge rounded-pill bg-primary position-absolute top-0 start-50 translate-middle text-uppercase">Reciept</span>
3848
<h6 class="text-uppercase text-muted card-subtitle">Total</h6>
39-
<h4 class="display-4 fw-bold card-title">₱<?php echo $total; ?></h4>
49+
<h4 class="display-4 fw-bold card-title">₱<?php echo number_format($total, 2); ?></h4>
4050
<canvas id="qr-code"></canvas>
4151
</div>
4252
<div class="card-footer p-4">
4353
<div id="receipt">
4454

4555
<ul class="list-unstyled">
4656
<li class="d-flex mb-2"><span class="bs-icon-xs bs-icon-rounded bs-icon-primary-light bs-icon me-2"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-check2-circle">
47-
<path d="M2.5 8a5.5 5.5 0 0 1 8.25-4.764.5.5 0 0 0 .5-.866A6.5 6.5 0 1 0 14.5 8a.5.5 0 0 0-1 0 5.5 5.5 0 1 1-11 0z"></path>
48-
<path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z"></path>
57+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
58+
<path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"></path>
59+
</svg></span><span><strong>Customer : <?php echo $result['fullname']; ?></strong></span></li>
60+
<li class="d-flex mb-2"><span class="bs-icon-xs bs-icon-rounded bs-icon-primary-light bs-icon me-2"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-check2-circle">
61+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
62+
<path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"></path>
4963
</svg></span><span><strong>Kg/Kilo : <?php echo $kilo; ?></strong></span></li>
5064
<li class="d-flex mb-2"><span class="bs-icon-xs bs-icon-rounded bs-icon-primary-light bs-icon me-2"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-check2-circle">
51-
<path d="M2.5 8a5.5 5.5 0 0 1 8.25-4.764.5.5 0 0 0 .5-.866A6.5 6.5 0 1 0 14.5 8a.5.5 0 0 0-1 0 5.5 5.5 0 1 1-11 0z"></path>
52-
<path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z"></path>
53-
</svg></span><span><strong>Type : <?php echo $type; ?> -&nbsp;₱<?php echo $type_price; ?></strong></span></li>
65+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
66+
<path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"></path>
67+
</svg></span><span><strong>Type : <?php echo $type; ?> -&nbsp;₱<?php echo number_format($type_price, 2); ?></strong></span></li>
5468
<li class="d-flex mb-2"><span class="bs-icon-xs bs-icon-rounded bs-icon-primary-light bs-icon me-2"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-check2-circle">
55-
<path d="M2.5 8a5.5 5.5 0 0 1 8.25-4.764.5.5 0 0 0 .5-.866A6.5 6.5 0 1 0 14.5 8a.5.5 0 0 0-1 0 5.5 5.5 0 1 1-11 0z"></path>
56-
<path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z"></path>
57-
</svg></span><span><strong>Products</strong>&nbsp;: <strong>₱<?php echo $products; ?></strong></span></li>
69+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
70+
<path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"></path>
71+
</svg></span><span><strong>Products</strong>&nbsp;: <strong>₱<?php echo number_format($products, 2); ?></strong></span></li>
5872
<li class="d-flex mb-2"><span class="bs-icon-xs bs-icon-rounded bs-icon-primary-light bs-icon me-2"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-check-circle">
5973
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
6074
<path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"></path>
61-
</svg></span><span><strong>Total :&nbsp;₱<?php echo $total; ?></strong></span></li>
75+
</svg></span><span><strong>Total :&nbsp;₱<?php echo number_format($total, 2); ?></strong></span></li>
6276
</ul>
6377
</div>
6478
<a class="btn btn-primary d-block w-100" role="button" onclick="printReceipt()">Print</a>

0 commit comments

Comments
 (0)