mirror of
https://github.com/itflow-org/itflow
synced 2026-03-23 05:55:38 +00:00
Show Name Description Tax Price and Stock in Product Auto Complete in Invoice
This commit is contained in:
@@ -161,7 +161,22 @@ if (isset($_GET['invoice_id'])) {
|
|||||||
$invoice_badge_color = getInvoiceBadgeColor($invoice_status);
|
$invoice_badge_color = getInvoiceBadgeColor($invoice_status);
|
||||||
|
|
||||||
//Product autocomplete
|
//Product autocomplete
|
||||||
$products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price, product_tax_id AS tax, product_id AS prod_id FROM products WHERE product_archived_at IS NULL");
|
$products_sql = mysqli_query($mysqli, "
|
||||||
|
SELECT
|
||||||
|
product_name AS label,
|
||||||
|
product_type AS type,
|
||||||
|
product_description AS description,
|
||||||
|
product_price AS price,
|
||||||
|
product_tax_id AS tax,
|
||||||
|
tax_percent,
|
||||||
|
product_id AS prod_id,
|
||||||
|
COALESCE(SUM(product_stock.stock_qty), 0) AS available_stock
|
||||||
|
FROM products
|
||||||
|
LEFT JOIN product_stock ON product_id = stock_product_id
|
||||||
|
LEFT JOIN taxes ON product_tax_id = tax_id
|
||||||
|
WHERE product_archived_at IS NULL
|
||||||
|
GROUP BY product_id
|
||||||
|
");
|
||||||
|
|
||||||
if (mysqli_num_rows($products_sql) > 0) {
|
if (mysqli_num_rows($products_sql) > 0) {
|
||||||
while ($row = mysqli_fetch_array($products_sql)) {
|
while ($row = mysqli_fetch_array($products_sql)) {
|
||||||
@@ -769,22 +784,56 @@ require_once "../includes/footer.php";
|
|||||||
<link rel="stylesheet" href="../plugins/jquery-ui/jquery-ui.min.css">
|
<link rel="stylesheet" href="../plugins/jquery-ui/jquery-ui.min.css">
|
||||||
<script src="../plugins/jquery-ui/jquery-ui.min.js"></script>
|
<script src="../plugins/jquery-ui/jquery-ui.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
var availableProducts = <?php echo $json_products ?? '""'?>;
|
var availableProducts = <?php echo $json_products ?? '[]'?>;
|
||||||
|
|
||||||
$("#name").autocomplete({
|
$("#name").autocomplete({
|
||||||
source: availableProducts,
|
source: availableProducts,
|
||||||
select: function (event, ui) {
|
minLength: 1,
|
||||||
$("#name").val(ui.item.label); // Product name field - this seemingly has to referenced as label
|
delay: 0,
|
||||||
$("#desc").val(ui.item.description); // Product description field
|
select: function (event, ui) {
|
||||||
$("#qty").val(1); // Product quantity field automatically make it a 1
|
$("#name").val(ui.item.label);
|
||||||
$("#price").val(ui.item.price); // Product price field
|
$("#desc").val(ui.item.description);
|
||||||
$("#tax").val(ui.item.tax); // Product tax field
|
$("#qty").val(1);
|
||||||
$("#product_id").val(ui.item.prod_id); // Product ID field
|
$("#price").val(ui.item.price);
|
||||||
return false;
|
$("#tax").val(ui.item.tax);
|
||||||
}
|
$("#product_id").val(ui.item.prod_id);
|
||||||
});
|
return false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Keep it simple: default jQuery UI look, just richer content
|
||||||
|
$("#name").autocomplete("instance")._renderItem = function(ul, item) {
|
||||||
|
var typeText = item.type ? item.type.charAt(0).toUpperCase() + item.type.slice(1).toLowerCase() : "";
|
||||||
|
var showStock = (typeText.toLowerCase() !== "service");
|
||||||
|
|
||||||
|
var taxText = (item.tax_percent != null) ? (parseFloat(item.tax_percent) + "%") : "No tax";
|
||||||
|
var priceText = (item.price != null && item.price !== "") ? String(item.price) : "";
|
||||||
|
|
||||||
|
var infoLeft =
|
||||||
|
"<div class='d-flex justify-content-between align-items-start'>" +
|
||||||
|
"<div class='flex-fill pr-2'>" +
|
||||||
|
"<div class='font-weight-bold'>" + (item.label || "") +
|
||||||
|
(typeText ? " <small class='text-muted'>(" + typeText + ")</small>" : "") +
|
||||||
|
"</div>" +
|
||||||
|
"<div class='small text-muted'>" + (item.description || "") + "</div>" +
|
||||||
|
"<div class='mt-1'>" +
|
||||||
|
"<span class='badge badge-secondary mr-1'>Tax: " + taxText + "</span>" +
|
||||||
|
(showStock ? "<span class='badge " + ((item.available_stock ?? 0) > 0 ? "badge-success" : "badge-danger") + "'>Stock: " + (item.available_stock ?? 0) + "</span>" : "") +
|
||||||
|
"</div>" +
|
||||||
|
"</div>" +
|
||||||
|
"<div class='text-right'>" +
|
||||||
|
"<div class='font-weight-bold'>" + priceText + "</div>" +
|
||||||
|
"</div>" +
|
||||||
|
"</div>";
|
||||||
|
|
||||||
|
// Use the jQuery UI wrapper so default hover/focus styles apply
|
||||||
|
return $("<li>")
|
||||||
|
.append($("<div class='ui-menu-item-wrapper'>").append(infoLeft))
|
||||||
|
.appendTo(ul);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="../plugins/SortableJS/Sortable.min.js"></script>
|
<script src="../plugins/SortableJS/Sortable.min.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user