No misfortune can happen on earth or in your souls but is recorded in a decree before We bring it into existence: That is truly easy for Allah:

In order that ye may not despair over matters that pass you by, nor exult over favours bestowed upon you. For Allah loveth not any vainglorious boaster,-

Such persons as are covetous and commend covetousness to men. And if any turn back (from Allah’s Way), verily Allah is Free of all Needs, Worthy of all Praise.

-Surat al-Hadid (the Iron). Qur’an, 57:22-24. Yusuf Ali translation