自动提交的工作原理是根据使用条形码扫描仪输入的条形码将产品添加到从列表中输入的销售中,但是如果在数据库中找不到产品,它会添加以该产品相同的第一位数字开头的产品,因此我需要解决这个问题。 我尝试检查产品代码并从该脚本内的 JavaScript 访问它,但它不起作用,我认为问题是因为自动提交机制,但我不知道如何修复它。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>POS</title>
<!-- CSS -->
<link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<link href="vendors/uniform.default.css" rel="stylesheet" media="screen">
<link href="css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link href="../style.css" media="screen" rel="stylesheet" type="text/css" />
<!-- JavaScript -->
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="vendors/jquery-1.7.2.min.js"></script> <!-- Remove this line, as jQuery is already loaded above -->
<script src="src/facebox.js" type="text/javascript"></script>
<script src="vendors/bootstrap.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox({
loadingImage : 'src/loading.gif',
closeImage : 'src/closelabel.png'
});
});
</script>
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
</head>
<body>
<?php include('navfixed.php'); ?>
<?php
$position = isset($_SESSION['SESS_LAST_NAME']) ? $_SESSION['SESS_LAST_NAME'] : '';
if ($position == 'cashier') {
?>
<a href="sales.php?id=cash&invoice=<?php echo $finalcode ?>">Cash</a>
<a href="../index.php">Logout</a>
<?php
}
if ($position == 'admin') {
?>
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li><a href="index.php"><i class="icon-dashboard icon-2x"></i> Dashboard </a></li>
<li class="active"><a href="sales.php?id=cash&invoice=<?php echo $finalcode ?>"><i class="icon-shopping-cart icon-2x"></i> Sales</a></li>
<li><a href="products.php"><i class="icon-list-alt icon-2x"></i> Products</a></li>
<li><a href="customer.php"><i class="icon-group icon-2x"></i> Customers</a></li>
<li><a href="supplier.php"><i class="icon-group icon-2x"></i> Suppliers</a></li>
<li><a href="salesreport.php?d1=0&d2=0"><i class="icon-bar-chart icon-2x"></i> Sales Report</a></li>
<br><br><br><br><br><br>
<li>
<div class="hero-unit-clock">
<form name="clock">
<font color="white">Time: <br></font> <input style="width:150px;" type="text" class="trans" name="face" value="" disabled>
</form>
</div>
</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span10">
<div class="contentheader">
<i class="icon-money"></i> Sales
</div>
<ul class="breadcrumb">
<a href="index.php"><li>Dashboard</li></a> /
<li class="active">Sales</li>
</ul>
<div style="margin-top: -19px; margin-bottom: 21px;">
<a href="index.php">
<button class="btn btn-default btn-large" style="float: none;">
<i class="icon icon-circle-arrow-left icon-large"></i> Back
</button>
</a>
</div>
<form action="incoming.php" method="post" id="barcodeForm">
<input type="hidden" name="pt" value="<?php echo $_GET['id']; ?>" />
<input type="hidden" name="invoice" value="<?php echo $_GET['invoice']; ?>" />
<select name="product" style="width: 650px;" class="chzn-select" required autofocus>
<?php
include('../connect.php');
$sql = "SELECT * FROM products";
$result = $db->query($sql);
if ($result->rowCount() > 0) {
while ($row = $result->fetch()) {
?>
<option value="<?php echo $row['product_id']; ?>">
<?php echo $row['product_code'] . ' - ' . $row['product_name']; ?>
</option>
<?php
}
} else {
?>
<option value="" disabled>No products found</option>
<?php
}
?>
</select>
<input type="number" name="qty" value="1" min="1" placeholder="Qty" autocomplete="off" style="width: 68px; height:30px; padding-top:6px; padding-bottom: 4px; margin-right: 4px; font-size:15px;" required>
<Button type="submit" class="btn btn-info" style="width: 123px; height:35px; margin-top:-5px;" /><i class="icon-plus-sign icon-large"></i> Add</button>
</form>
<table class="table table-bordered" id="resultTable" data-responsive="table">
<thead>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Qty</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$id = $_GET['invoice'];
include('../connect.php');
$result = $db->prepare("SELECT * FROM sales_order WHERE invoice= :userid");
$result->bindParam(':userid', $id);
$result->execute();
for ($i = 1; $row = $result->fetch(); $i++) {
?>
<tr class="record">
<td hidden><?php echo $row['product']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>
<?php
$ppp = $row['price'];
echo $ppp;
?>
</td>
<td><?php echo $row['qty']; ?></td>
<td width="90">
<a href="delete.php?id=<?php echo $row['transaction_id']; ?>&invoice=<?php echo $_GET['invoice']; ?>&dle=<?php echo $_GET['id']; ?>&qty=<?php echo $row['qty']; ?>&code=<?php echo $row['product']; ?>">
<button class="btn btn-mini btn-warning"><i class="icon icon-remove"></i> Cancel</button>
</a>
</td>
</tr>
<?php
}
?>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th colspan="3">
<strong style="font-size: 12px; color: #222222;">Total:</strong>
</th>
<td colspan="1">
<strong style="font-size: 12px; color: #222222;">
<?php
function formatMoney($number, $fractional = false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
$sdsd = $_GET['invoice'];
$resultas = $db->prepare("SELECT price, qty FROM sales_order WHERE invoice= :a");
$resultas->bindParam(':a', $sdsd);
$resultas->execute();
$totalprice = 0;
for ($i = 0; $rowas = $resultas->fetch(); $i++) {
$gg = $rowas['price'];
$dd = $rowas['qty'];
$total = (float)$gg * (float)$dd;
$totalprice += $total;
}
echo '$' . number_format($totalprice, 2);
?>
</strong>
</td>
<td colspan="1">
<strong style="font-size: 12px; color: #222222;">
<?php
$resulta = $db->prepare("SELECT sum(profit) FROM sales_order WHERE invoice= :b");
$resulta->bindParam(':b', $sdsd);
$resulta->execute();
for ($i = 0; $qwe = $resulta->fetch(); $i++) {
$asd = $qwe['sum(profit)'];
}
?>
</strong>
</td>
<th></th>
</tr>
</tbody>
</table><br>
<form action="checkout.php" method="get">
<input type="hidden" name="invoice" value="<?php echo $_GET['invoice']; ?>" />
<input type="hidden" name="total" value="<?php echo $totalprice; ?>" /> <!-- Use $totalprice here -->
<input type="hidden" name="pt" value="<?php echo $_GET['id']; ?>" />
<input type="hidden" name="cashier" value="<?php echo $_SESSION['SESS_FIRST_NAME']; ?>" />
<input type="hidden" name="totalprof" value="<?php echo $asd; ?>" />
<button class="btn btn-success btn-large btn-block" type="submit">
<i class="icon icon-save icon-large"></i> SAVE
</button>
</form>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php } ?>
<?php include('footer.php'); ?>
<script>
const barcodeForm = document.getElementById('barcodeForm');
let submissionTimeout;
document.addEventListener('input', () => {
clearTimeout(submissionTimeout); // Clear any existing timeout
submissionTimeout = setTimeout(() => {
barcodeForm.submit();
}, 500); // Set a delay of 500 milliseconds
});
</script>
</body>
</html>
条形码查找发生在代码中的哪个位置?