false, 'ERROR' => 'no_business_selected']); } $qBiz = queryOne("SELECT BeaconShardID, BeaconMajor FROM Businesses WHERE ID = ? LIMIT 1", [$businessId]); $usesSharding = $qBiz && ((int) ($qBiz['BeaconShardID'] ?? 0)) > 0; $assignments = []; if ($usesSharding) { $qShard = queryOne("SELECT UUID FROM BeaconShards WHERE ID = ?", [(int) $qBiz['BeaconShardID']]); $shardUUID = $qShard ? $qShard['UUID'] : ''; $rows = queryTimed(" SELECT sp.ID AS ServicePointID, sp.BeaconMinor, sp.Name AS ServicePointName FROM ServicePoints sp WHERE sp.BusinessID = ? AND sp.BeaconMinor IS NOT NULL AND sp.IsActive = 1 ORDER BY sp.BeaconMinor, sp.Name ", [$businessId]); foreach ($rows as $r) { $assignments[] = [ 'ServicePointID' => (int) $r['ServicePointID'], 'BeaconID' => 0, 'BusinessID' => $businessId, 'BeaconName' => $r['ServicePointName'] . ' (Minor ' . $r['BeaconMinor'] . ')', 'UUID' => $shardUUID, 'Major' => (int) $qBiz['BeaconMajor'], 'Minor' => (int) $r['BeaconMinor'], 'ServicePointName' => $r['ServicePointName'], 'IsSharding' => true, ]; } } else { $rows = queryTimed(" SELECT sp.ID AS ServicePointID, sp.BeaconID, sp.BusinessID, b.Name AS BeaconName, b.UUID, sp.Name AS ServicePointName FROM ServicePoints sp JOIN Beacons b ON b.ID = sp.BeaconID WHERE sp.BusinessID = ? AND sp.BeaconID IS NOT NULL ORDER BY b.Name, sp.Name ", [$businessId]); foreach ($rows as $r) { $assignments[] = [ 'ServicePointID' => (int) $r['ServicePointID'], 'BeaconID' => (int) $r['BeaconID'], 'BusinessID' => (int) $r['BusinessID'], 'BeaconName' => $r['BeaconName'], 'UUID' => $r['UUID'], 'ServicePointName' => $r['ServicePointName'], 'IsSharding' => false, ]; } } jsonResponse([ 'OK' => true, 'ERROR' => '', 'COUNT' => count($assignments), 'ASSIGNMENTS' => $assignments, 'USES_SHARDING' => $usesSharding, ]);