Use of the Green's function formalism in resonant two-photon ionisation of alkali-metal atoms: I. Formal theory