Theory of Carrier Transport From First Principles: Applications in Photovoltaic and Thermoelectric Materials