Gratuity is the End of Service Benefit stipulated by the Qatar Labour Law. The best place to read is the Qatar Labour Law itself, which is very clear.

The calculation is 3 weeks latest basic salary times the no. of completed years.