{
  "$comment": "Machine-readable companion to https://valem.run/calculators/saudi-arabia/gratuity. Formula, inputs, outputs, engine-verified test vectors, cited sources and the re-runnable Valem ModelSpec behind the page.",
  "url": "https://valem.run/calculators/saudi-arabia/gratuity",
  "dataUrl": "https://valem.run/calculators/saudi-arabia/gratuity.json",
  "license": {
    "name": "CC BY 4.0",
    "url": "https://creativecommons.org/licenses/by/4.0/",
    "attribution": "Saudi Arabia end of service model by Valem (https://valem.run/calculators/saudi-arabia/gratuity), CC BY 4.0.",
    "note": "Covers the model — the expression of each rule and the arrangement of the catalog. The rates and thresholds themselves are law and are not licensed by anyone; the cited sources are where they come from."
  },
  "verificationUrl": "https://valem.run/calculators/saudi-arabia/gratuity/verify",
  "country": "saudi-arabia",
  "countryName": "Saudi Arabia",
  "formula": "gratuity",
  "formulaName": "End of service",
  "title": "End of Service Calculator — Saudi Arabia",
  "answer": "Saudi end-of-service is half a month's wage per year for the first five years, then a full month per year beyond, for a terminated contract.",
  "lang": "en",
  "currency": "SAR",
  "taxYear": "2026",
  "verification": {
    "claim": "internal-consistency",
    "statement": "The Valem engine reproduces this model's stated formula through 3 self-test cases (below, and re-runnable against the spec). That asserts internal consistency, NOT that the formula matches current law — the cited sources are the evidence for that, and carry the date each was last checked.",
    "selfTestCases": 3,
    "ratesAreIllustrative": false,
    "sourcesCheckedOn": "2026-08-02"
  },
  "sources": [
    {
      "label": "HRSD",
      "url": "https://www.hrsd.gov.sa",
      "checked": "2026-08-02"
    }
  ],
  "terminalOutput": "eos",
  "inputs": [
    {
      "name": "wageMonthly",
      "type": "number",
      "label": "Monthly wage (SAR)",
      "minimum": 0
    },
    {
      "name": "years",
      "type": "number",
      "label": "Years of service",
      "minimum": 0
    },
    {
      "name": "leaving",
      "type": "string",
      "label": "How the employment ended"
    }
  ],
  "outputs": [
    {
      "name": "eos",
      "type": "number",
      "label": "End-of-service award",
      "format": "currency",
      "formula": "$round(eosFull * resignFactor, 2)"
    },
    {
      "name": "eosFull",
      "type": "number",
      "formula": "($w := wageMonthly; $f := years < 5 ? years : 5; $b := years > 5 ? years - 5 : 0; $round($w * $const.firstFactor * $f + $w * $const.beyondFactor * $b, 2))"
    },
    {
      "name": "resignFactor",
      "type": "number",
      "formula": "(leaving = 'resigned' ? (years < 2 ? 0 : years < 5 ? 1/3 : years < 10 ? 2/3 : 1) : 1)"
    }
  ],
  "testCases": [
    {
      "description": "E1 wage 8,000 SAR, 4 years, terminated",
      "given": {
        "wageMonthly": 8000,
        "years": 4,
        "leaving": "terminated"
      },
      "expect": {
        "eos": 16000
      }
    },
    {
      "description": "E2 wage 8,000 SAR, 12 years",
      "given": {
        "wageMonthly": 8000,
        "years": 12,
        "leaving": "terminated"
      },
      "expect": {
        "eos": 76000
      }
    },
    {
      "description": "E3 same 4 years but resigned — Article 84 pays only one third",
      "given": {
        "wageMonthly": 8000,
        "years": 4,
        "leaving": "resigned"
      },
      "expect": {
        "eosFull": 16000,
        "eos": 5333.33
      }
    }
  ],
  "spec": {
    "id": "net-salary-saudi-arabia",
    "version": "1.0.0",
    "schema": {
      "type": "object",
      "properties": {
        "wageMonthly": {
          "type": "number",
          "minimum": 0
        },
        "years": {
          "type": "number",
          "minimum": 0
        },
        "leaving": {
          "type": "string"
        },
        "eos": {
          "type": "number",
          "readOnly": true
        },
        "eosFull": {
          "type": "number",
          "readOnly": true
        },
        "resignFactor": {
          "type": "number",
          "readOnly": true
        }
      }
    },
    "constants": {
      "firstFactor": 0.5,
      "beyondFactor": 1
    },
    "defaultValues": [
      {
        "path": "$",
        "expr": "{ 'wageMonthly': 8000, 'years': 4, 'leaving': 'terminated' }"
      }
    ],
    "derivations": [
      {
        "path": "$.eosFull",
        "expr": "($w := wageMonthly; $f := years < 5 ? years : 5; $b := years > 5 ? years - 5 : 0; $round($w * $const.firstFactor * $f + $w * $const.beyondFactor * $b, 2))"
      },
      {
        "path": "$.resignFactor",
        "expr": "(leaving = 'resigned' ? (years < 2 ? 0 : years < 5 ? 1/3 : years < 10 ? 2/3 : 1) : 1)"
      },
      {
        "path": "$.eos",
        "expr": "$round(eosFull * resignFactor, 2)"
      }
    ],
    "constraints": [],
    "metaDerivations": [],
    "viewDefinition": {
      "renderer": "builtin",
      "defaultView": "main",
      "views": [
        {
          "id": "main",
          "label": "End of service",
          "layout": "vertical",
          "components": [
            {
              "id": "wage",
              "type": "numericField",
              "label": "Monthly wage (SAR)",
              "bind": "$.wageMonthly"
            },
            {
              "id": "years",
              "type": "numericField",
              "label": "Years of service",
              "bind": "$.years"
            },
            {
              "id": "leaving",
              "type": "selectField",
              "label": "How the employment ended",
              "bind": "$.leaving",
              "helperText": "Article 84 pays the full award on termination, but reduces it steeply if you resign.",
              "options": [
                {
                  "value": "terminated",
                  "label": "Terminated or contract ended — full award"
                },
                {
                  "value": "resigned",
                  "label": "Resigned — reduced by length of service"
                }
              ]
            },
            {
              "id": "tiles",
              "type": "group",
              "layout": "horizontal",
              "components": [
                {
                  "id": "eosTile",
                  "type": "statTile",
                  "label": "End-of-service award",
                  "bind": "$.eos",
                  "format": "currency",
                  "currency": "SAR"
                }
              ]
            },
            {
              "id": "note",
              "type": "staticText",
              "text": "'Saudi Arabia has no personal income tax; net equals gross for expats. End-of-service (Art. 84, termination): half-month wage per year for the first 5 years, then a full month per year beyond. Resignation reduces the award by fractions (2-5 yrs one third, 5-10 two thirds, 10+ full). Estimate, not legal advice. On resignation the award is reduced: nothing under 2 years, one third from 2 to 5 years, two thirds from 5 to 10, and the full amount only after 10 years.'"
            },
            {
              "id": "sources",
              "type": "sourceList",
              "label": "Sources",
              "items": [
                {
                  "label": "HRSD",
                  "url": "https://www.hrsd.gov.sa",
                  "date": "2026-08-02"
                }
              ]
            }
          ]
        }
      ]
    },
    "tests": [
      {
        "description": "E1 wage 8,000 SAR, 4 years, terminated",
        "given": {
          "$.wageMonthly": 8000,
          "$.years": 4,
          "$.leaving": "terminated"
        },
        "expect": {
          "$.eos": 16000
        }
      },
      {
        "description": "E2 wage 8,000 SAR, 12 years",
        "given": {
          "$.wageMonthly": 8000,
          "$.years": 12,
          "$.leaving": "terminated"
        },
        "expect": {
          "$.eos": 76000
        }
      },
      {
        "description": "E3 same 4 years but resigned — Article 84 pays only one third",
        "given": {
          "$.wageMonthly": 8000,
          "$.years": 4,
          "$.leaving": "resigned"
        },
        "expect": {
          "$.eosFull": 16000,
          "$.eos": 5333.33
        }
      }
    ]
  }
}
