Update: 2026-05-03 22:15:40
This commit is contained in:
@@ -13,14 +13,21 @@ $db = Database::getInstance();
|
||||
// 1. Super Admin sees ALL companies
|
||||
if ($decoded['role'] === 'super_admin') {
|
||||
$stmt = $db->query("SELECT * FROM companies WHERE deleted_at IS NULL");
|
||||
} else {
|
||||
// 2. Others see only linked companies
|
||||
$stmt = $db->prepare("
|
||||
SELECT c.* FROM companies c
|
||||
JOIN user_companies uc ON c.id = uc.company_id
|
||||
WHERE uc.user_id = ? AND c.deleted_at IS NULL
|
||||
");
|
||||
$stmt->execute([$decoded['user_id']]);
|
||||
}
|
||||
// 2. Admin sees all companies in their tenant
|
||||
else if ($decoded['role'] === 'admin') {
|
||||
$stmt = $db->prepare("SELECT * FROM companies WHERE tenant_id = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$decoded['tenant_id']]);
|
||||
}
|
||||
// 3. Others (accountant, etc) see only their assigned company
|
||||
else {
|
||||
// Need to get their assigned company_id from users table first
|
||||
$stmtUser = $db->prepare("SELECT company_id FROM users WHERE id = ?");
|
||||
$stmtUser->execute([$decoded['user_id']]);
|
||||
$assignedCompanyId = $stmtUser->fetchColumn();
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM companies WHERE id = ? AND deleted_at IS NULL");
|
||||
$stmt->execute([$assignedCompanyId]);
|
||||
}
|
||||
|
||||
$companies = $stmt->fetchAll();
|
||||
|
||||
Reference in New Issue
Block a user