{
  "schemaVersion": 1,
  "name": "Order confirmation",
  "description": "Reference template: header/footer, flowing table across pages, totals kept together, page numbers, datasheets appended per product.",
  "locale": "nb-NO",
  "page": {
    "size": "A4",
    "margin": { "top": 40, "right": 40, "bottom": 40, "left": 40 }
  },
  "fonts": [
    { "family": "Inter", "weight": 400, "source": { "builtin": "Inter" } },
    { "family": "Inter", "weight": 600, "source": { "builtin": "Inter" } }
  ],
  "styles": {
    "base": { "fontFamily": "Inter", "fontSize": 9, "color": "#1F2328", "lineHeight": 1.3 },
    "muted": { "extends": "base", "color": "#6E7781" },
    "h1": { "extends": "base", "fontSize": 18, "fontWeight": 600 },
    "label": { "extends": "base", "fontSize": 7.5, "color": "#6E7781" },
    "th": { "extends": "base", "fontSize": 8, "fontWeight": 600 },
    "total": { "extends": "base", "fontSize": 11, "fontWeight": 600, "align": "right" }
  },
  "parts": [
    {
      "type": "flow",
      "id": "main",
      "tocTitle": "Ordrebekreftelse",
      "pageTemplates": {
        "default": {
          "header": {
            "height": 36,
            "elements": [
              { "id": "hdrCompany", "type": "text", "x": 0, "y": 0, "w": 300, "h": 14, "content": "{{ seller.name }}", "style": { "ref": "base", "fontWeight": 600 } },
              { "id": "hdrOrder", "type": "text", "x": 315, "y": 0, "w": 200, "h": 14, "content": "Ordre {{ order.no }}", "style": { "ref": "muted", "align": "right" } },
              { "id": "hdrRule", "type": "line", "x": 0, "y": 24, "w": 515, "h": 0, "stroke": "#D0D7DE", "strokeWidth": 0.5 }
            ]
          },
          "footer": {
            "height": 24,
            "elements": [
              { "id": "ftrRule", "type": "line", "x": 0, "y": 0, "w": 515, "h": 0, "stroke": "#D0D7DE", "strokeWidth": 0.5 },
              { "id": "ftrSeller", "type": "text", "x": 0, "y": 8, "w": 360, "h": 12, "content": "{{ seller.name }} · Org.nr. {{ seller.orgNo }}", "style": "muted" },
              { "id": "ftrPage", "type": "text", "x": 375, "y": 8, "w": 140, "h": 12, "content": "Side {{ @page }} av {{ @pageCount }}", "style": { "ref": "muted", "align": "right" } }
            ]
          }
        },
        "first": {
          "header": {
            "height": 96,
            "elements": [
              { "id": "logo", "type": "image", "x": 0, "y": 0, "w": 120, "h": 40, "source": { "binding": "seller.logo" }, "fit": "contain", "align": "left", "visibleIf": "seller.logo != null" },
              { "id": "title", "type": "text", "x": 255, "y": 0, "w": 260, "h": 24, "content": "Ordrebekreftelse", "style": { "ref": "h1", "align": "right" } },
              { "id": "orderNo", "type": "text", "x": 255, "y": 28, "w": 260, "h": 14, "content": "Ordre {{ order.no }} · {{ order.date | date('d. MMMM yyyy') }}", "style": { "ref": "muted", "align": "right" } },
              { "id": "qr", "type": "barcode", "x": 459, "y": 46, "w": 44, "h": 44, "format": "qr", "value": "{{ order.trackingUrl }}", "visibleIf": "order.trackingUrl != null" }
            ]
          },
          "footer": {
            "height": 24,
            "elements": [
              { "id": "ftrSeller1", "type": "text", "x": 0, "y": 8, "w": 360, "h": 12, "content": "{{ seller.name }} · Org.nr. {{ seller.orgNo }}", "style": "muted" },
              { "id": "ftrPage1", "type": "text", "x": 375, "y": 8, "w": 140, "h": 12, "content": "Side {{ @page }} av {{ @pageCount }}", "style": { "ref": "muted", "align": "right" } }
            ]
          }
        }
      },
      "sections": [
        {
          "id": "parties",
          "name": "Customer and delivery",
          "height": 88,
          "elements": [
            { "id": "custLabel", "type": "text", "x": 0, "y": 0, "w": 240, "h": 10, "content": "KUNDE", "style": "label" },
            { "id": "custAddr", "type": "text", "x": 0, "y": 12, "w": 240, "h": 60, "fit": "shrink", "content": "{{ customer.name }}\n{{ customer.address.street }}\n{{ customer.address.zip }} {{ customer.address.city }}", "style": "base" },
            { "id": "delivLabel", "type": "text", "x": 275, "y": 0, "w": 240, "h": 10, "content": "LEVERING", "style": "label" },
            { "id": "delivAddr", "type": "text", "x": 275, "y": 12, "w": 240, "h": 60, "fit": "shrink", "content": "{{ delivery.method }}\n{{ delivery.address.street }}\n{{ delivery.address.zip }} {{ delivery.address.city }}\nØnsket levering: {{ delivery.date | date('d.M.yyyy') | default('Snarest') }}", "style": "base" }
          ]
        },
        {
          "id": "lines",
          "name": "Order lines",
          "height": 40,
          "keepTogether": false,
          "elements": [
            {
              "id": "linesTable",
              "type": "table",
              "x": 0, "y": 0, "w": 515, "h": 40,
              "rows": { "over": "order.lines", "as": "line" },
              "headerStyle": "th",
              "cellStyle": "base",
              "repeatHeader": true,
              "minRowHeight": 16,
              "padding": { "top": 4, "right": 4, "bottom": 4, "left": 4 },
              "borders": { "color": "#D0D7DE", "width": 0.5, "horizontal": true },
              "zebra": "#F6F8FA",
              "carryOver": { "label": "Overføres", "broughtForwardLabel": "Overført", "columns": ["amount"] },
              "columns": [
                { "id": "sku", "width": 70, "header": "Varenr.", "cell": "{{ line.sku }}" },
                { "id": "desc", "width": "1fr", "header": "Beskrivelse", "cell": "{{ line.description }}" },
                { "id": "qty", "width": 50, "header": "Antall", "cell": "{{ line.qty | number(0) }} {{ line.unit }}", "style": { "ref": "base", "align": "right" } },
                { "id": "price", "width": 70, "header": "Pris", "cell": "{{ line.price | currency('NOK') }}", "style": { "ref": "base", "align": "right" } },
                { "id": "amount", "width": 80, "header": "Beløp", "cell": "{{ line.qty * line.price | currency('NOK') }}", "footer": "{{ sum(order.lines, 'qty * price') | currency('NOK') }}", "style": { "ref": "base", "align": "right" } }
              ]
            }
          ]
        },
        {
          "id": "totals",
          "name": "Totals",
          "height": 64,
          "keepTogether": true,
          "elements": [
            { "id": "netLabel", "type": "text", "x": 315, "y": 8, "w": 110, "h": 12, "content": "Sum eks. mva", "style": "muted" },
            { "id": "net", "type": "text", "x": 425, "y": 8, "w": 90, "h": 12, "content": "{{ order.totals.net | currency('NOK') }}", "style": { "ref": "base", "align": "right" } },
            { "id": "vatLabel", "type": "text", "x": 315, "y": 22, "w": 110, "h": 12, "content": "Mva 25 %", "style": "muted" },
            { "id": "vat", "type": "text", "x": 425, "y": 22, "w": 90, "h": 12, "content": "{{ order.totals.vat | currency('NOK') }}", "style": { "ref": "base", "align": "right" } },
            { "id": "totalRule", "type": "line", "x": 315, "y": 38, "w": 200, "h": 0, "stroke": "#1F2328", "strokeWidth": 0.75 },
            { "id": "grossLabel", "type": "text", "x": 315, "y": 44, "w": 110, "h": 16, "content": "Totalt", "style": { "ref": "base", "fontWeight": 600 } },
            { "id": "gross", "type": "text", "x": 425, "y": 44, "w": 90, "h": 16, "content": "{{ order.totals.gross | currency('NOK') }}", "style": "total" }
          ]
        },
        {
          "id": "terms",
          "name": "Terms",
          "height": 30,
          "visibleIf": "order.terms != null",
          "elements": [
            { "id": "termsText", "type": "text", "x": 0, "y": 12, "w": 515, "h": 18, "fit": "grow", "content": "{{ order.terms }}", "style": "muted" }
          ]
        }
      ]
    },
    {
      "type": "pdf",
      "id": "datasheets",
      "repeat": { "over": "order.datasheets", "as": "sheet" },
      "source": { "binding": "sheet.pdf" },
      "fit": "scaleToPage",
      "countPages": true,
      "tocTitle": "Datablad: {{ sheet.title }}",
      "overlay": {
        "footer": {
          "height": 24,
          "elements": [
            { "id": "dsPage", "type": "text", "x": 375, "y": 8, "w": 140, "h": 12, "content": "Side {{ @page }} av {{ @pageCount }}", "style": { "ref": "muted", "align": "right" } }
          ]
        }
      }
    }
  ]
}
