{
  "$defs": {
    "InvoiceLine": {
      "description": "One invoice line.",
      "properties": {
        "description": {
          "type": "string"
        },
        "gl_account_revenue": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "CoA revenue account."
        },
        "gl_account_vat": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "CoA VAT account."
        },
        "performance_obligation": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "IFRS 15 / ASC 606 performance-obligation PathRef (BDR 0078)."
        },
        "product": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef into BDR 0065 Product when applicable."
        },
        "quantity": {
          "format": "double",
          "type": "number"
        },
        "recognition_pattern": {
          "anyOf": [
            {
              "$ref": "#/$defs/InvoiceRecognitionPattern"
            },
            {
              "type": "null"
            }
          ],
          "description": "Revenue-recognition pattern for this line."
        },
        "segment": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef into BDR 0065 OperatingSegment when applicable."
        },
        "total_net": {
          "description": "Line total before VAT.",
          "format": "double",
          "type": "number"
        },
        "unit_price": {
          "format": "double",
          "type": "number"
        },
        "vat_amount": {
          "format": "double",
          "type": "number"
        },
        "vat_rate": {
          "description": "VAT rate (e.g. 0.19 for DE standard, 0.07 for DE reduced).",
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "description",
        "quantity",
        "unit_price",
        "vat_rate",
        "vat_amount",
        "total_net"
      ],
      "type": "object"
    },
    "InvoiceRecognitionPattern": {
      "description": "IFRS 15 / ASC 606 revenue-recognition pattern for an invoice line.",
      "oneOf": [
        {
          "const": "point_in_time",
          "description": "Revenue recognised at a point in time (transfer of control).",
          "type": "string"
        },
        {
          "const": "over_time",
          "description": "Revenue recognised over time (subscription, service contract).",
          "type": "string"
        }
      ]
    },
    "InvoiceStatus": {
      "description": "AR invoice status.",
      "enum": [
        "draft",
        "issued",
        "partially_paid",
        "paid",
        "overdue",
        "written_off",
        "credit_noted"
      ],
      "type": "string"
    },
    "IsoCurrency": {
      "description": "ISO 4217 currency code.",
      "pattern": "^[A-Z]{3}$",
      "type": "string"
    },
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "PathRef": {
      "description": "Path-based cross-reference relative to .corpospec/ root.\nPattern: `^[a-z0-9_-]+(/[a-z0-9_.-]+)+$`",
      "pattern": "^[a-z0-9_-]+(/[a-z0-9_.-]+)+$",
      "type": "string"
    },
    "PaymentApplication": {
      "description": "Application of a bank transaction to invoice settlement.",
      "properties": {
        "amount": {
          "format": "double",
          "type": "number"
        },
        "bank_transaction": {
          "$ref": "#/$defs/PathRef"
        },
        "fx_rate": {
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "bank_transaction",
        "amount"
      ],
      "type": "object"
    },
    "PaymentMethod": {
      "description": "Payment method on an outbound AP invoice.",
      "enum": [
        "sepa",
        "swift",
        "card",
        "cash",
        "direct_debit",
        "other"
      ],
      "type": "string"
    },
    "WithholdingTaxDecl": {
      "description": "Withholding-tax declaration on an AP line (US 1099 / DE Bauabzug).",
      "properties": {
        "amount": {
          "format": "double",
          "type": "number"
        },
        "kind": {
          "description": "E.g. `\"us_1099_nec\"`, `\"de_bauabzug_15\"`, `\"uk_cis_20\"`.",
          "type": "string"
        },
        "rate_pct": {
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "kind",
        "rate_pct",
        "amount"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/invoice-received.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "AP invoice received from a vendor.",
  "properties": {
    "currency": {
      "$ref": "#/$defs/IsoCurrency"
    },
    "document": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "due_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "is_1099_reportable": {
      "description": "US 1099 reportability flag.",
      "type": [
        "boolean",
        "null"
      ]
    },
    "journal_entries": {
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "lines": {
      "items": {
        "$ref": "#/$defs/InvoiceLine"
      },
      "type": "array"
    },
    "payment_method": {
      "anyOf": [
        {
          "$ref": "#/$defs/PaymentMethod"
        },
        {
          "type": "null"
        }
      ]
    },
    "payment_terms": {
      "type": "string"
    },
    "payments": {
      "items": {
        "$ref": "#/$defs/PaymentApplication"
      },
      "type": "array"
    },
    "received_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "status": {
      "$ref": "#/$defs/InvoiceStatus"
    },
    "supplier_invoice_number": {
      "description": "Vendor's invoice number (recorded as-given).",
      "type": "string"
    },
    "total_gross": {
      "format": "double",
      "type": "number"
    },
    "total_net": {
      "format": "double",
      "type": "number"
    },
    "total_vat": {
      "format": "double",
      "type": "number"
    },
    "vat_deductible": {
      "description": "Whether the input VAT on this invoice is deductible (DE\nVorsteuerabzug per §15 UStG).",
      "type": [
        "boolean",
        "null"
      ]
    },
    "vendor": {
      "$ref": "#/$defs/PathRef"
    },
    "withholding_tax": {
      "anyOf": [
        {
          "$ref": "#/$defs/WithholdingTaxDecl"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "entity",
    "vendor",
    "supplier_invoice_number",
    "received_at",
    "due_at",
    "currency",
    "lines",
    "total_net",
    "total_vat",
    "total_gross",
    "payment_terms",
    "status"
  ],
  "title": "InvoiceReceived",
  "type": "object",
  "x-corpospec-pillar": "financials"
}