General treatment of junction potentials in solids using irreversible thermodynamics