{
  "version": "1.0",
  "name": "Aerospace material readiness exception report",
  "description": "Transforms a site-part master export into a controlled daily exception queue. Rules are deterministic and intentionally exclude technical approval decisions.",
  "source": {
    "sheet": "ERP Export",
    "headerRow": 1,
    "requiredColumns": [
      "as_of_date",
      "site_id",
      "part_id",
      "part_family",
      "criticality_class",
      "unit_cost",
      "lead_time_days",
      "supplier_id_primary",
      "supplier_risk_class",
      "on_hand_qty",
      "backorder_qty",
      "blocked_qty",
      "forecast_qty"
    ],
    "maxRows": 10000
  },
  "template": {
    "sheet": "Daily Material Report",
    "headerRow": 8,
    "tableStartRow": 9,
    "tableStartColumn": 1,
    "styleRow": 9,
    "clearThroughRow": 2000,
    "auditSheet": "Transformation Audit"
  },
  "derived": [
    {
      "name": "available_qty",
      "logic": {
        "-": [
          { "var": "on_hand_qty" },
          { "var": "blocked_qty" }
        ]
      }
    },
    {
      "name": "required_qty",
      "logic": {
        "+": [
          { "var": "forecast_qty" },
          { "var": "backorder_qty" }
        ]
      }
    },
    {
      "name": "coverage_weeks",
      "logic": {
        "if": [
          { "<=": [{ "var": "forecast_qty" }, 0] },
          99,
          { "/": [{ "var": "available_qty" }, { "var": "forecast_qty" }] }
        ]
      }
    },
    {
      "name": "inventory_value",
      "logic": {
        "*": [
          { "var": "on_hand_qty" },
          { "var": "unit_cost" }
        ]
      }
    },
    {
      "name": "status",
      "cases": [
        {
          "when": {
            "and": [
              { "==": [{ "var": "criticality_class" }, "A"] },
              { ">": [{ "var": "backorder_qty" }, 0] }
            ]
          },
          "value": "CRITICAL BACKORDER"
        },
        {
          "when": {
            "and": [
              { "==": [{ "var": "criticality_class" }, "A"] },
              { ">": [{ "var": "blocked_qty" }, 0] }
            ]
          },
          "value": "CRITICAL QUALITY HOLD"
        },
        {
          "when": {
            "<": [
              { "var": "available_qty" },
              { "var": "required_qty" }
            ]
          },
          "value": "SHORTAGE"
        },
        {
          "when": { ">": [{ "var": "blocked_qty" }, 0] },
          "value": "QUALITY HOLD"
        },
        {
          "when": {
            "and": [
              { "==": [{ "var": "supplier_risk_class" }, "High"] },
              { "<": [{ "var": "coverage_weeks" }, 4] }
            ]
          },
          "value": "SUPPLIER RISK"
        },
        {
          "when": { "<": [{ "var": "coverage_weeks" }, 2] },
          "value": "WATCH"
        }
      ],
      "else": "READY"
    },
    {
      "name": "priority",
      "cases": [
        {
          "when": { "==": [{ "var": "status" }, "CRITICAL BACKORDER"] },
          "value": 1
        },
        {
          "when": { "==": [{ "var": "status" }, "CRITICAL QUALITY HOLD"] },
          "value": 2
        },
        {
          "when": { "==": [{ "var": "status" }, "SHORTAGE"] },
          "value": 3
        },
        {
          "when": { "==": [{ "var": "status" }, "QUALITY HOLD"] },
          "value": 4
        },
        {
          "when": { "==": [{ "var": "status" }, "SUPPLIER RISK"] },
          "value": 5
        },
        {
          "when": { "==": [{ "var": "status" }, "WATCH"] },
          "value": 6
        }
      ],
      "else": 9
    },
    {
      "name": "planner_action",
      "cases": [
        {
          "when": { "==": [{ "var": "status" }, "CRITICAL BACKORDER"] },
          "value": "Planner: confirm recovery owner and next checkpoint"
        },
        {
          "when": { "==": [{ "var": "status" }, "CRITICAL QUALITY HOLD"] },
          "value": "Quality + Planning: confirm approved disposition path"
        },
        {
          "when": { "==": [{ "var": "status" }, "SHORTAGE"] },
          "value": "Planning + Purchasing: validate supply recovery"
        },
        {
          "when": { "==": [{ "var": "status" }, "QUALITY HOLD"] },
          "value": "Quality: review blocked stock and release status"
        },
        {
          "when": { "==": [{ "var": "status" }, "SUPPLIER RISK"] },
          "value": "Purchasing: verify next receipt against demand"
        },
        {
          "when": { "==": [{ "var": "status" }, "WATCH"] },
          "value": "Planner: monitor against next forecast"
        }
      ],
      "else": "No action"
    }
  ],
  "filter": {
    "!=": [
      { "var": "status" },
      "READY"
    ]
  },
  "sort": [
    { "field": "priority", "direction": "asc" },
    { "field": "criticality_class", "direction": "asc" },
    { "field": "site_id", "direction": "asc" },
    { "field": "part_id", "direction": "asc" }
  ],
  "columns": [
    { "header": "Priority", "field": "priority", "format": "integer" },
    { "header": "Status", "field": "status", "format": "text" },
    { "header": "Site", "field": "site_id", "format": "text" },
    { "header": "Part", "field": "part_id", "format": "text" },
    { "header": "Family", "field": "part_family", "format": "text" },
    { "header": "Crit.", "field": "criticality_class", "format": "text" },
    { "header": "Supplier", "field": "supplier_id_primary", "format": "text" },
    { "header": "Supplier risk", "field": "supplier_risk_class", "format": "text" },
    { "header": "Forecast", "field": "forecast_qty", "format": "integer" },
    { "header": "On hand", "field": "on_hand_qty", "format": "integer" },
    { "header": "Blocked", "field": "blocked_qty", "format": "integer" },
    { "header": "Backorder", "field": "backorder_qty", "format": "integer" },
    { "header": "Available", "field": "available_qty", "format": "integer" },
    { "header": "Coverage (wk)", "field": "coverage_weeks", "format": "decimal" },
    { "header": "Inventory value", "field": "inventory_value", "format": "currency" },
    { "header": "Planner action", "field": "planner_action", "format": "text" }
  ],
  "summaryCells": [
    { "cell": "B4", "operation": "max", "field": "as_of_date" },
    { "cell": "B6", "operation": "sourceCount" },
    { "cell": "D6", "operation": "outputCount" },
    {
      "cell": "F6",
      "operation": "countWhere",
      "where": {
        "in": [
          { "var": "status" },
          ["CRITICAL BACKORDER", "CRITICAL QUALITY HOLD"]
        ]
      }
    },
    {
      "cell": "H6",
      "operation": "countWhere",
      "where": {
        "in": [
          { "var": "status" },
          ["QUALITY HOLD", "CRITICAL QUALITY HOLD"]
        ]
      }
    },
    {
      "cell": "J6",
      "operation": "countWhere",
      "where": { "==": [{ "var": "status" }, "SHORTAGE"] }
    },
    { "cell": "L6", "operation": "suppressedCount" }
  ],
  "statusField": "status",
  "statusColors": {
    "CRITICAL BACKORDER": "FFFFD9DD",
    "CRITICAL QUALITY HOLD": "FFFFE6C7",
    "SHORTAGE": "FFFFF0D5",
    "QUALITY HOLD": "FFFFF7DC",
    "SUPPLIER RISK": "FFE9F1F8",
    "WATCH": "FFF0F4F6"
  },
  "outputFileName": "Daily_Material_Readiness_Report.xlsx"
}
