{
  "schemaVersion": 1,
  "slug": "layaway-payment-calculator",
  "category": "shopping",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "f68cc427f55ad4a43f3a81c3bceeba90483e91f7acba41438fb9d83c065c0439",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/layaway-payment-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": "n = ceil(weeks ÷ frequency factor); installment = (price − deposit + fees) ÷ n; fees = serviceFee + price × feePercent ÷ 100",
    "vars": [
      [
        "P",
        "Payment per period"
      ],
      [
        "n",
        "Number of payments"
      ],
      [
        "price",
        "Item price"
      ],
      [
        "down",
        "Down payment"
      ],
      [
        "weeks",
        "Total weeks"
      ],
      [
        "f",
        "Period divisor: weekly 1, biweekly 2, monthly 4.345"
      ]
    ],
    "note": "Deposit must not exceed price. Installment = (price − deposit + fees) ÷ number of periods; fees = service fee + price × fee percent. Total paid includes the deposit and fees."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(downPayment>itemPrice)return{balance:null,paymentPerPeriod:null,paymentsCount:null,totalFees:null,totalPaid:null,extraVsCash:null,__error:'inputError'};const balance=itemPrice-downPayment;const periods=payFrequency==='weekly'?weeks:payFrequency==='biweekly'?Math.ceil(weeks/2):Math.ceil(weeks/4.345);const totalFees=serviceFee+itemPrice*feePercent/100;const totalPaid=itemPrice+totalFees;return{balance,paymentPerPeriod:periods>0?(balance+totalFees)/periods:0,paymentsCount:periods,totalFees,totalPaid,extraVsCash:totalFees};",
    "inputs": [
      {
        "name": "itemPrice",
        "type": "number",
        "default": 600,
        "min": 0,
        "max": 100000,
        "step": 0.01
      },
      {
        "name": "downPayment",
        "type": "number",
        "default": 60,
        "min": 0,
        "max": 100000,
        "step": 0.01
      },
      {
        "name": "weeks",
        "type": "number",
        "default": 10,
        "min": 1,
        "max": 104,
        "step": 1,
        "slider": true
      },
      {
        "name": "serviceFee",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 1000,
        "step": 1,
        "slider": true
      },
      {
        "name": "feePercent",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 20,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "payFrequency",
        "type": "select",
        "default": "weekly",
        "options": [
          {
            "value": "weekly"
          },
          {
            "value": "biweekly"
          },
          {
            "value": "monthly"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "balance",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "paymentPerPeriod",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "paymentsCount",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "totalFees",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "totalPaid",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "extraVsCash",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
