Praise be to Allah, the Lord of the World; and blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
An amount of money that is deducted from basic salary and retained for a fixed time, is subject to Zakah every lunar year provided that such a sum is controlled by someone who can pay at anytime. In other words, such an amount of money is considered as a delayed debt.
As for gratuity given by some companies, if you are sure that amount will be retained on your behalf and given to you at death, retirement or resignation, then it also becomes subject to Zakah.
As for paying Zakah in these two or similar cases, one can pay Zakah at a fixed time every year or delay payment until he/she receives that sum of money and then pay for the entire period.
But, if an employee will not receive such a gratuity, or must meet some conditions, then there is no Zakah.
Allah knows best.