{
  "schemaVersion": 1,
  "name": "Orders with items",
  "unit": "mm",
  "page": {
    "size": "A4",
    "orientation": "portrait",
    "margins": {
      "top": 12,
      "right": 12,
      "bottom": 12,
      "left": 12
    }
  },
  "dataSources": [
    {
      "name": "orders"
    }
  ],
  "styles": {
    "title": {
      "fontSize": 18,
      "fontWeight": "bold",
      "color": "#0f172a"
    },
    "muted": {
      "fontSize": 9,
      "color": "#64748b"
    },
    "th": {
      "fontSize": 9,
      "fontWeight": "bold",
      "color": "#ffffff",
      "backgroundColor": "#334155",
      "padding": 1.5
    },
    "td": {
      "fontSize": 9,
      "padding": 1.5,
      "border": {
        "width": 0.4,
        "color": "#e2e8f0",
        "style": "solid",
        "sides": [
          "bottom"
        ]
      }
    },
    "num": {
      "textAlign": "right"
    },
    "sub": {
      "fontSize": 9,
      "fontWeight": "bold",
      "backgroundColor": "#e2e8f0",
      "padding": 1.5
    }
  },
  "reportHeader": {
    "id": "rh",
    "height": 14,
    "components": [
      {
        "id": "title",
        "type": "text",
        "x": 0,
        "y": 0,
        "width": 186,
        "height": 9,
        "text": "Orders with items",
        "styleName": "title"
      }
    ]
  },
  "pageFooter": {
    "id": "pf",
    "height": 8,
    "components": [
      {
        "id": "pf_n",
        "type": "text",
        "x": 0,
        "y": 2,
        "width": 186,
        "height": 5,
        "text": "Page {{ page.number }} of {{ page.count }}",
        "style": {
          "fontSize": 8,
          "color": "#64748b",
          "textAlign": "right"
        }
      }
    ]
  },
  "body": [
    {
      "kind": "dataRegion",
      "id": "orders_region",
      "dataSource": "orders",
      "detail": {
        "id": "order",
        "height": 9,
        "components": [
          {
            "id": "o1",
            "type": "text",
            "x": 0,
            "y": 2,
            "width": 40,
            "height": 6,
            "text": "Order {{ row.id }}",
            "style": {
              "fontSize": 11,
              "fontWeight": "bold",
              "color": "#1d4ed8"
            }
          },
          {
            "id": "o2",
            "type": "text",
            "x": 40,
            "y": 2,
            "width": 80,
            "height": 6,
            "text": "{{ row.customer }}",
            "style": {
              "fontSize": 11,
              "fontWeight": "bold"
            }
          },
          {
            "id": "o3",
            "type": "text",
            "x": 120,
            "y": 2,
            "width": 66,
            "height": 6,
            "text": "{{ row.date }}",
            "style": {
              "fontSize": 9,
              "color": "#64748b",
              "textAlign": "right"
            },
            "format": {
              "type": "date",
              "pattern": "d MMMM yyyy"
            }
          }
        ]
      },
      "children": [
        {
          "kind": "dataRegion",
          "id": "items_region",
          "relation": "items",
          "detail": {
            "id": "item",
            "height": 6,
            "components": [
              {
                "id": "i1",
                "type": "text",
                "x": 6,
                "y": 0,
                "width": 26,
                "height": 6,
                "text": "{{ row.sku }}",
                "styleName": "td"
              },
              {
                "id": "i2",
                "type": "text",
                "x": 32,
                "y": 0,
                "width": 84,
                "height": 6,
                "text": "{{ row.name }}",
                "styleName": "td"
              },
              {
                "id": "i3",
                "type": "text",
                "x": 116,
                "y": 0,
                "width": 20,
                "height": 6,
                "text": "{{ row.qty }}",
                "styleName": "td",
                "style": {
                  "textAlign": "right"
                }
              },
              {
                "id": "i4",
                "type": "text",
                "x": 136,
                "y": 0,
                "width": 25,
                "height": 6,
                "text": "{{ row.price }}",
                "styleName": "td",
                "style": {
                  "textAlign": "right"
                },
                "format": {
                  "type": "currency",
                  "currency": "USD"
                }
              },
              {
                "id": "i5",
                "type": "text",
                "x": 161,
                "y": 0,
                "width": 25,
                "height": 6,
                "text": "{{ row.qty * row.price }}",
                "styleName": "td",
                "style": {
                  "textAlign": "right"
                },
                "format": {
                  "type": "currency",
                  "currency": "USD"
                }
              }
            ]
          },
          "footer": {
            "id": "items_total",
            "height": 9,
            "components": [
              {
                "id": "t1",
                "type": "text",
                "x": 116,
                "y": 1.5,
                "width": 45,
                "height": 6,
                "text": "Order total",
                "styleName": "sub",
                "style": {
                  "textAlign": "right"
                }
              },
              {
                "id": "t2",
                "type": "text",
                "x": 161,
                "y": 1.5,
                "width": 25,
                "height": 6,
                "text": "{{ sum(rows, r => r.qty * r.price) }}",
                "styleName": "sub",
                "style": {
                  "textAlign": "right"
                },
                "format": {
                  "type": "currency",
                  "currency": "USD"
                }
              }
            ]
          }
        }
      ]
    }
  ]
}