> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Plantilla HTML

> Crea un informe financiero analítico en HTML con Reporter: detalles de la organización, desgloses por cuenta y listas detalladas de operaciones.

Este ejemplo muestra cómo estructurar un **informe financiero analítico** enfocado en el análisis de transacciones a nivel de cuenta, en formato HTML. El informe incluye:

* Información de la organización y del ledger.
* Desglose por cuenta.
* Lista detallada de operaciones.

## Código de la plantilla

***

<CodeGroup>
  ```html HTML expandable theme={null}
  <!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Analytical Financial Report</title>
    <style>
      body {
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        background-color: #f4f6f9;
        color: #333;
        padding: 40px;
      }

      .container {
        max-width: 900px;
        margin: auto;
        background: #ffffff;
        padding: 30px 40px;
        border-radius: 8px;
        box-shadow: 0 0 10px rgba(0,0,0,0.1);
      }

      h1 {
        text-align: center;
        font-size: 24px;
        color: #004080;
        margin-bottom: 10px;
      }

      .subtitle {
        text-align: center;
        font-size: 14px;
        color: #777;
        margin-bottom: 30px;
      }

      .section-title {
        font-weight: bold;
        font-size: 16px;
        margin-top: 30px;
        margin-bottom: 10px;
        color: #004080;
        border-bottom: 1px solid #ccc;
        padding-bottom: 4px;
      }

      table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 15px;
      }

      th, td {
        padding: 10px;
        text-align: left;
        border: 1px solid #ccc;
      }

      th {
        background-color: #e8f0fe;
        font-weight: bold;
        color: #003366;
      }

      .info p {
        margin: 4px 0;
      }

      .footer {
        margin-top: 40px;
        text-align: center;
        font-size: 12px;
        color: #999;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>Analytical Financial Report</h1>
      <div class="subtitle">Detailed analysis of movements by linked accounts.</div>

      <div class="info">
        <p><strong>Generation Date:</strong> {% date_time "dd/MM/YYYY HH:mm" %}</p>
        <p><strong>Organization:</strong> {{ midaz_onboarding.organization.0.legal_name }}</p>
        <p><strong>Ledger:</strong> {{ midaz_onboarding.ledger.0.name }}</p>
      </div>

      {% for account in midaz_onboarding.account %}
        {% with balance = filter(midaz_transaction.balance, "account_id", account.id)[0] %}
          <div class="section-title">Account: {{ account.alias }}</div>
          <div class="info">
            <p><strong>ID:</strong> {{ account.id }}</p>
            <p><strong>Currency:</strong> {{ balance.asset_code }}</p>
            <p><strong>Current Balance:</strong> {{ balance.available }}</p>
          </div>

          <table>
            <thead>
              <tr>
                <th>Operation ID</th>
                <th>Type</th>
                <th>Original Amount</th>
                <th>Discount (3%)</th>
                <th>Final Amount</th>
                <th>Description</th>
              </tr>
            </thead>
            <tbody>
              {% for operation in midaz_transaction.operation %}
                {% if operation.account_id == account.id %}
                  {% set original_amount = operation.amount %}
                  {% set discount_amount = original_amount * 0.03  %}
                  {% set final_amount = original_amount - discount_amount %}
                  <tr>
                    <td>{{ operation.id }}</td>
                    <td>{{ operation.type }}</td>
                    <td>{{ original_amount|floatformat:2 }}</td>
                    <td>{{ discount_amount|floatformat:2 }}</td>
                    <td>{{ final_amount|floatformat:2 }}</td>
                    <td>{{ operation.description }}</td>
                  </tr>
                {% endif %}
              {% endfor %}
            </tbody>
          </table>
        {% endwith %}
      {% endfor %}

      <div class="footer">
        Document generated automatically via Reporter - Lerian · {{ midaz_onboarding.organization.0.legal_document }}
      </div>
    </div>
  </body>
  </html>
  ```
</CodeGroup>

## Desglose del código

***

### Información de la organización y del ledger

<CodeGroup>
  ```html HTML theme={null}
      <div class="info">
        <p><strong>Generation Date:</strong> {% date_time "dd/MM/YYYY HH:mm" %}</p>
        <p><strong>Organization:</strong> {{ midaz_onboarding.organization.0.legal_name }}</p>
        <p><strong>Ledger:</strong> {{ midaz_onboarding.ledger.0.name }}</p>
      </div>
  ```
</CodeGroup>

**`<p><strong>Generation Date:</strong> {% date_time "dd/MM/YYYY HH:mm" %}</p>`**

Esta función aplica la fecha y la hora en el momento del renderizado, en el formato `dd/MM/YYYY HH:mm`.

**`<p><strong>Organization:</strong> {{ midaz_onboarding.organization.0.legal_name }}</p>`**

Esta línea renderiza el nombre legal de la primera organización asociada con los datos de onboarding.

* `midaz_onboarding.organization`: la lista de organizaciones en el sistema.
* `0`: obtiene el primer elemento de la lista.
* `legal_name`: obtiene el valor del campo `legal_name`.

**`<p><strong>Ledger:</strong> {{ midaz_onboarding.ledger.0.name }}</p>`**

Esta línea renderiza el nombre del primer ledger asociado con los datos de onboarding.

* `midaz_onboarding.ledger`: la lista de ledgers en el sistema.
* `0`: obtiene el primer elemento de la lista.
* `name`: obtiene el valor del campo `name`.

### Iteración sobre las cuentas

<CodeGroup>
  ```html HTML theme={null}
      {% for account in midaz_onboarding.account %}
        {% with balance = filter(midaz_transaction.balance, "account_id", account.id)[0] %}  
  ```
</CodeGroup>

**`{% for account in midaz_onboarding.account %}`**

Este bucle recorre cada cuenta en la lista `midaz_onboardTing.account`.

* Esta lista representa todas las cuentas vinculadas a un cliente o asociadas con un flujo de onboarding.
* En cada iteración, crea un nuevo scope donde `account` hace referencia a un elemento específico de esa lista.

**`{% with balance = filter(midaz_transaction.balance, "account_id", account.id)[0] %}`**

Dentro del bucle, esta línea:

* Usa la función filter para buscar un saldo en la lista `midaz_transaction.balance` donde `account_id` coincide con el ID de la cuenta actual.
* El `[0]` toma el primer saldo coincidente (asumiendo que hay solo uno por cuenta).
* El resultado se guarda en una variable temporal llamada `balance`, con scope limitado a este bloque.

### Información de la cuenta

<CodeGroup>
  ```html HTML theme={null}
          <div class="section-title">Account: {{ account.alias }}</div>
          <div class="info">
            <p><strong>ID:</strong> {{ account.id }}</p>
            <p><strong>Currency:</strong> {{ balance.asset_code }}</p>
            <p><strong>Current Balance:</strong> {{ balance.available }}</p>
          </div>
  ```
</CodeGroup>

**`<div class="section-title">Account: {{ account.alias }}</div>`**

Muestra un título de sección con el alias de la cuenta (un nombre amigable o legible para la cuenta).

**`<p><strong>ID:</strong> {{ account.id }}</p>`**

Muestra el identificador único de la cuenta.

**`<p><strong>Currency:</strong> {{ balance.asset_code }}</p>`**

Muestra el código de moneda (como "BRL" o "USD") asociado con el saldo de la cuenta.

**`<p><strong>Current Balance:</strong> {{ balance.available }}`**

Muestra el saldo disponible actual.

### Información de las operaciones

<CodeGroup>
  ```html HTML theme={null}
              {% for operation in midaz_transaction.operation %}
                {% if operation.account_id == account.id %}
                  {% set original_amount = operation.amount %}
                  {% set discount_amount = original_amount * 0.03  %}
                  {% set final_amount = original_amount - discount_amount %}
  ```
</CodeGroup>

**`{% for operation in midaz_transaction.operation %}`**

Esto recorre todas las operaciones de la lista `midaz_transaction.operation`.

**`{% if operation.account_id == account.id %}`**

Esta línea verifica si la operación actual está relacionada con la cuenta actual del bucle externo (del bloque anterior). Continúa solo si:

* El `account_id` de la operación coincide con el `account.id` en foco.

**`{% set original_amount = operation.amount %}`**

Esta línea define una variable temporal llamada `original_amount` y le asigna el valor del campo `amount` del objeto de la operación.

**`{% set discount_amount = original_amount * 0.03 %}`**

Esta línea calcula un descuento del 3% sobre el monto original.

* La línea guarda el resultado como `discount_amount`.

**`{% set final_amount = original_amount - discount_amount %}`**

Esta línea resta el descuento del monto original.

* La línea almacena el resultado final en `final_amount`, que puedes renderizar más adelante.

### Columnas de la tabla

<CodeGroup>
  ```html HTML theme={null}
                  <tr>
                    <td>{{ operation.id }}</td>
                    <td>{{ operation.type }}</td>
                    <td>{{ original_amount|floatformat:2 }}</td>
                    <td>{{ discount_amount|floatformat:2 }}</td>
                    <td>{{ final_amount|floatformat:2 }}</td>
                    <td>{{ operation.description }}</td>
                  </tr>
  ```
</CodeGroup>

Este bloque genera una fila de tabla para cada operación, con la siguiente información:

**`<td>{{ operation.id }}</td>`**

Identificador único de la operación.

**`<td>{{ operation.type }}</td>`**

Tipo de operación, como `credit` o `debit`.

**`<td>{{ original_amount|floatformat:2 }}</td>`**

Muestra el monto original (sin ajustar), con formato de 2 decimales.

**`<td>{{ discount_amount|floatformat:2 }}</td>`**

Muestra el descuento calculado, también con 2 decimales.

**`<td>{{ final_amount|floatformat:2 }}</td>`**

Muestra el monto final después de aplicar el descuento del 3%.

**`<td>{{ operation.description }}</td>`**

Renderiza la descripción o etiqueta de la operación, como "Transfer to savings".

### Pie del informe

<CodeGroup>
  ```html HTML theme={null}
      <div class="footer">
        Document generated automatically via Reporter - Lerian · {{ midaz_onboarding.organization.0.legal_document }}
      </div>
  ```
</CodeGroup>

Esta línea renderiza un pie de página en la parte inferior del documento. El pie de página indica que Reporter de Lerian generó el contenido automáticamente.

* También incluye el número de documento legal de la primera organización vinculada a los datos de onboarding, obtenido dinámicamente mediante el placeholder `{{ midaz_onboarding.organization.0.legal_document }}`.

## Salida de la plantilla

***

<CodeGroup>
  ```html HTML expandable theme={null}
  <!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Analytical Financial Report</title>
    <style>
      body {
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        background-color: #f4f6f9;
        color: #333;
        padding: 40px;
      }

      .container {
        max-width: 900px;
        margin: auto;
        background: #ffffff;
        padding: 30px 40px;
        border-radius: 8px;
        box-shadow: 0 0 10px rgba(0,0,0,0.1);
      }

      h1 {
        text-align: center;
        font-size: 24px;
        color: #004080;
        margin-bottom: 10px;
      }

      .subtitle {
        text-align: center;
        font-size: 14px;
        color: #777;
        margin-bottom: 30px;
      }

      .section-title {
        font-weight: bold;
        font-size: 16px;
        margin-top: 30px;
        margin-bottom: 10px;
        color: #004080;
        border-bottom: 1px solid #ccc;
        padding-bottom: 4px;
      }

      table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 15px;
      }

      th, td {
        padding: 10px;
        text-align: left;
        border: 1px solid #ccc;
      }

      th {
        background-color: #e8f0fe;
        font-weight: bold;
        color: #003366;
      }

      .info p {
        margin: 4px 0;
      }

      .footer {
        margin-top: 40px;
        text-align: center;
        font-size: 12px;
        color: #999;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>Analytical Financial Report</h1>
      <div class="subtitle">Detailed analysis of movements by linked accounts.</div>

      <div class="info">
        <p><strong>Generation Date:</strong> 23/05/2025 14:08</p>
        <p><strong>Organization:</strong> Mante - Pfannerstill</p>
        <p><strong>Ledger:</strong> Rice, Rowe and O'Hara</p>
      </div>    
          <div class="section-title">Account: @external/USD</div>
          <div class="info">
            <p><strong>ID:</strong> 0196d97e-a58d-7814-8eb3-e510b818f6a5</p>
            <p><strong>Currency:</strong> USD</p>
            <p><strong>Current Balance:</strong> 499950.00</p>
          </div>

          <table>
            <thead>
              <tr>
                <th>Operation ID</th>
                <th>Type</th>
                <th>Original Amount</th>
                <th>Discount (3%)</th>
                <th>Final Amount</th>
                <th>Description</th>
              </tr>
            </thead>
            <tbody>            
                  <tr>
                    <td>0196d982-4085-7e1d-b698-3aad306df721</td>
                    <td>CREDIT</td>
                    <td>500000.00</td>
                    <td>15000.00</td>
                    <td>485000.00</td>
                    <td>Duplicated account test</td>
                  </tr>
                  <tr>
                    <td>0196d983-a2c2-7dce-ad14-78eb36d9f2d1</td>
                    <td>DEBIT</td>
                    <td>20.00</td>
                    <td>0.60</td>
                    <td>19.40</td>
                    <td>Loan payment person1</td>
                  </tr>
                  <tr>
                    <td>0196d983-a2c2-7e0d-a246-45d5234138e3</td>
                    <td>DEBIT</td>
                    <td>30.00</td>
                    <td>0.90</td>
                    <td>29.10</td>
                    <td>Loan payment person1</td>
                  </tr>
            </tbody>
          </table>      
      <div class="footer">
        Document generated automatically via Reporter - Lerian · 123.456.789-0001/00
      </div>
    </div>
  </body>
  </html>
  ```
</CodeGroup>

## Resultado renderizado

***

<Frame caption="Figura 1. Un ejemplo de informe financiero renderizado a partir del código HTML del ejemplo.">
  <img src="https://mintcdn.com/lerian-49cb71fc/uUQdWFdbYtzFLYzd/images/en/docs/html_template.jpg?fit=max&auto=format&n=uUQdWFdbYtzFLYzd&q=85&s=da9d3540b0a8b7b1122b38f24c2715cc" alt="Ejemplo de informe financiero renderizado a partir del código de la plantilla HTML mostrado arriba" width="976" height="739" data-path="images/en/docs/html_template.jpg" />
</Frame>
