In this case, the payment is made when the taxpayer is Spanish tax resident. However, taking into account that the bonus has been generated outside of Spain and for the benefit of a non-resident entity, the exemption for work performed outside of Spain (article 7.p) of the law) is applicable, with a maximum annual amount of 60,100 euros.
Same exemption is applicable to the part of income related to the stocks and which was generated before the move to Spain. If your employer has not applied this exemption or you have not considered it on your tax return, you will be paying more taxes. A claim of taxes could always be made, if necessary, during the following 4 years.