Gratuity is a-l-w-a-y-s calculated on basic salary. As per the regulations you can come back on a new visa and work with another employer without the need for NOC since you have completed five years with the same employer. However, my advice to you is to leave peacefully with a smile on your face and do make a-b-s-o-l-u-t-e-l-y sure your current employer cancels your visa before you exit Qatar. They should give you a paper from the ministry stating your visa stands cancelled.