Phase-matching effect on the second harmonic and terahertz generations in β-barium borate