{
  "schemaVersion": 1,
  "slug": "sale-price-calculator",
  "category": "shopping",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "54da9530b33dbb324fa81e258d78b2804f4042ab6b27e533ee3feabee262def5",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/sale-price-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "S = P(1 - d1 ÷ 100)(1 - d2 ÷ 100) - c; total = max(0,S) × (1 + t ÷ 100) + ship",
    "vars": [
      [
        "P",
        "Original price"
      ],
      [
        "d1/d2",
        "First and stacked discount (%)"
      ],
      [
        "c",
        "Coupon amount"
      ],
      [
        "t",
        "Sales tax (%)"
      ],
      [
        "ship",
        "Shipping"
      ]
    ],
    "note": "Discounts are applied sequentially, then the coupon is subtracted (not below zero); tax is applied to the discounted amount and shipping is added afterward. Effective discount is undefined when the original price is zero. Local tax treatment of shipping may differ."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const afterFirst=originalPrice*(1-discount1/100);const salePrice=afterFirst*(1-discount2/100);const afterCoupon=Math.max(0,salePrice-coupon);const effectiveDiscount=originalPrice>0?(1-afterCoupon/originalPrice)*100:null;const finalTotal=afterCoupon*(1+taxPercent/100)+shipping;return{afterFirst,salePrice,effectiveDiscount,totalSaving:originalPrice-afterCoupon,finalTotal};",
    "inputs": [
      {
        "name": "originalPrice",
        "type": "number",
        "default": 120,
        "min": 0,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "discount1",
        "type": "number",
        "default": 20,
        "min": 0,
        "max": 95,
        "step": 1,
        "slider": true
      },
      {
        "name": "discount2",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 95,
        "step": 1,
        "slider": true
      },
      {
        "name": "taxPercent",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 30,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "shipping",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 10000,
        "step": 1
      },
      {
        "name": "coupon",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 10000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "afterFirst",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "salePrice",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "effectiveDiscount",
        "precision": 2,
        "unit": "%",
        "optional": true
      },
      {
        "name": "totalSaving",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "finalTotal",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
