Mache OTC-Produktliste dynamisch
This commit is contained in:
1 parent
ee03fd70b9
commit
4ccc0c528f
2 files changed
+27
-17
No files matched your search
@@ -27,15 +27,14 @@ function get_otc_order_form_products(PDO $pdo): array
|
||||
p.name,
|
||||
COALESCE(SUM(v.qty_net), 0) AS available_qty
|
||||
FROM product p
|
||||
INNER JOIN stock_lot sl
|
||||
LEFT JOIN stock_lot sl
|
||||
ON sl.product_id = p.id
|
||||
AND sl.status = 'current'
|
||||
INNER JOIN v_stock_lot_balance v
|
||||
LEFT JOIN v_stock_lot_balance v
|
||||
ON v.stock_lot_id = sl.id
|
||||
WHERE p.status = 'active'
|
||||
GROUP BY p.id, p.name
|
||||
HAVING COALESCE(SUM(v.qty_net), 0) > 0
|
||||
ORDER BY p.id ASC"
|
||||
GROUP BY p.id, p.name, p.sku, p.uom
|
||||
ORDER BY p.name ASC, p.id ASC"
|
||||
);
|
||||
|
||||
$products = [];
|
||||
@@ -43,10 +42,23 @@ function get_otc_order_form_products(PDO $pdo): array
|
||||
$products[] = [
|
||||
'id' => (int) $row['id'],
|
||||
'name' => (string) $row['name'],
|
||||
'sku' => (string) $row['sku'],
|
||||
'uom' => (string) $row['uom'],
|
||||
'available_qty' => (float) $row['available_qty'],
|
||||
'has_sellable_mapping' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$mappingStmt = $pdo->query(
|
||||
'SELECT DISTINCT product_id
|
||||
FROM sellable_item_component'
|
||||
);
|
||||
$mappedProductIds = array_fill_keys(array_map('intval', $mappingStmt->fetchAll(PDO::FETCH_COLUMN)), true);
|
||||
foreach ($products as &$product) {
|
||||
$product['has_sellable_mapping'] = isset($mappedProductIds[$product['id']]);
|
||||
}
|
||||
unset($product);
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user