WHICH/THAT and WHO/M ... 01 see also WHICH 04
'qui' is generally used for 'who' or 'which' when it denotes the *subject* of a following verb.
| The man who sweeps the street is tired. |
L'homme qui balaie la rue est fatigué. |
| The door which is open is blue. | La porte qui est ouverte est bleue. |
'que' is generally used for 'whom' or 'which'/'that' when it denotes the *object* of a following verb.
| I had recognised the man whom I had seen at the market. |
J'avais reconnu l'homme que j'avais vu au marché. |
| I have spent all the money that you have given me. | J'ai dépensé tout l'argent que vous m'avez donné. |
However 'qui' is also used for 'who/m' (ie a person) when it follows a preposition (even if it is not the *subject* of a following verb).
| I have written to the girl with whom I worked. |
J'ai écrit à la fille avec qui j'ai travaillé. |