Scope stock table access by company warehouses
This commit is contained in:
@@ -31,7 +31,7 @@ class ProductManager {
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Scan all td_stock_* warehouse tables for any active stock row
|
||||
* Scan this company's td_stock_* warehouse tables for any active stock row
|
||||
* that references the given SKU.
|
||||
*
|
||||
* Used as a pre-delete guard on products: a product cannot be removed
|
||||
@@ -45,11 +45,14 @@ class ProductManager {
|
||||
private function findActiveStock(string $sku): ?string {
|
||||
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT table_name FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name LIKE 'td_stock_%'"
|
||||
"SELECT t.table_name
|
||||
FROM md_warehouse w
|
||||
JOIN information_schema.tables t
|
||||
ON t.table_schema = DATABASE()
|
||||
AND t.table_name = CONCAT('td_stock_', w.id)
|
||||
WHERE w.company_id = :company_id"
|
||||
);
|
||||
$sth->execute();
|
||||
$sth->execute([':company_id' => $this->company_id]);
|
||||
$tables = $sth->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
foreach ($tables as $table) {
|
||||
|
||||
Reference in New Issue
Block a user