false, 'ERROR' => 'no_business_selected']); } $beaconId = (int) ($data['BeaconID'] ?? 0); if ($beaconId <= 0) { apiAbort(['OK' => false, 'ERROR' => 'missing_beacon_id', 'MESSAGE' => 'BeaconID is required']); } $q = queryOne(" SELECT ID, BusinessID, ServicePointID FROM BeaconHardware WHERE ID = ? AND BusinessID = ? LIMIT 1 ", [$beaconId, $bizId]); if (!$q) { apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Beacon not found or does not belong to this business']); } $servicePointId = (int) ($q['ServicePointID'] ?? 0); // Clear the minor from the service point so it can be re-provisioned if ($servicePointId > 0) { queryTimed("UPDATE ServicePoints SET BeaconMinor = NULL WHERE ID = ? AND BusinessID = ?", [$servicePointId, $bizId]); } // Mark hardware as unassigned queryTimed(" UPDATE BeaconHardware SET Status = 'unassigned', BusinessID = NULL, ServicePointID = NULL, ShardUUID = NULL, Major = NULL, Minor = NULL, UpdatedAt = NOW() WHERE ID = ? ", [$beaconId]); jsonResponse(['OK' => true, 'ERROR' => '', 'BeaconID' => $beaconId]);