Electronic structure of V4O7: charge ordering, metal-insulator transition and magnetism