A microscopic theory of quantum well photovoltaics