Carlos Alcaraz will play Novak Djokovic in the last four of the ATP Finals after he beat Daniil Medvedev to top the group.