{
  "$defs": {
    "DunningStage": {
      "description": "AR dunning stage.",
      "enum": [
        "none",
        "friendly",
        "firm",
        "collection",
        "legal"
      ],
      "type": "string"
    },
    "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"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/invoice-issued.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "AR invoice issued to a customer.",
  "properties": {
    "currency": {
      "$ref": "#/$defs/IsoCurrency"
    },
    "customer": {
      "$ref": "#/$defs/PathRef"
    },
    "document": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "due_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "dunning_stage": {
      "anyOf": [
        {
          "$ref": "#/$defs/DunningStage"
        },
        {
          "type": "null"
        }
      ]
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "invoice_number": {
      "description": "Unique per entity per §14 UStG.",
      "type": "string"
    },
    "issued_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "journal_entries": {
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "lines": {
      "items": {
        "$ref": "#/$defs/InvoiceLine"
      },
      "type": "array"
    },
    "payment_terms": {
      "description": "E.g. `\"30 days net\"`, `\"due on receipt\"`.",
      "type": "string"
    },
    "payments": {
      "items": {
        "$ref": "#/$defs/PaymentApplication"
      },
      "type": "array"
    },
    "status": {
      "$ref": "#/$defs/InvoiceStatus"
    },
    "total_gross": {
      "format": "double",
      "type": "number"
    },
    "total_net": {
      "format": "double",
      "type": "number"
    },
    "total_vat": {
      "format": "double",
      "type": "number"
    }
  },
  "required": [
    "id",
    "entity",
    "customer",
    "invoice_number",
    "issued_at",
    "due_at",
    "currency",
    "lines",
    "total_net",
    "total_vat",
    "total_gross",
    "payment_terms",
    "status"
  ],
  "title": "InvoiceIssued",
  "type": "object",
  "x-corpospec-pillar": "financials"
}