From ae09b6a8aae561c75b12f0189618c711e94d4e0b Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Tue, 28 Jan 2025 19:51:44 +0100
Subject: [PATCH] Improve ledger layout.

---
 ledger.py                        |  8 +++++---
 templates/_macros.tmpl           | 16 +++++++++++-----
 templates/ledger_raw.tmpl        |  1 +
 templates/ledger_structured.tmpl |  3 +++
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/ledger.py b/ledger.py
index d7ebad6..098c6f6 100755
--- a/ledger.py
+++ b/ledger.py
@@ -136,6 +136,7 @@ class BookingLine:
     def __init__(self, booking: 'Booking') -> None:
         self.errors: list[str] = []
         self.booking = booking
+        self.idx = 0
 
 
 class IntroLine(BookingLine):
@@ -170,8 +171,9 @@ class IntroLine(BookingLine):
 class TransferLine(BookingLine):
     """Non-first Booking line, expected to carry value movement."""
 
-    def __init__(self, booking: 'Booking', code: str) -> None:
+    def __init__(self, booking: 'Booking', code: str, idx: int) -> None:
         super().__init__(booking)
+        self.idx = idx
         self.currency = ''
         self.amount: Optional[Decimal] = None
         if not code[0].isspace():
@@ -211,8 +213,8 @@ class Booking:
         self.intro_line = IntroLine(self, dat_lines[0].code)
         dat_lines[0].booking_line = self.intro_line
         self._transfer_lines = []
-        for dat_line in dat_lines[1:]:
-            dat_line.booking_line = TransferLine(self, dat_line.code)
+        for i, dat_line in enumerate(dat_lines[1:]):
+            dat_line.booking_line = TransferLine(self, dat_line.code, i + 1)
             self._transfer_lines += [dat_line.booking_line]
         changes = Wealth()
         sink_account = None
diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl
index a899699..c88bce6 100644
--- a/templates/_macros.tmpl
+++ b/templates/_macros.tmpl
@@ -7,15 +7,21 @@ td.amt, td.curr { font-family: monospace; font-size: 1.3em; }
 td.invalid, tr.warning td.invalid { background-color: #ff0000; }
 {% endmacro %}
 
+{% macro css_ledger_index_col() %}
+table.ledger tr > td:first-child { background-color: white; }
+{% endmacro %}
+
 {% macro table_dat_lines(dat_lines, raw) %}
-<table>
+<table class="ledger">
 {% for dat_line in dat_lines %}
   {% if (not raw) and dat_line.is_intro and loop.index > 1 %}
-    <tr class="alternating"><td colspan=5>&nbsp;</td></tr>
+    <tr class="alternating"><td><td colspan=4>&nbsp;</td></tr>
   {% endif %}
   <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}">
   {% if dat_line.is_intro %}
-    <td id="{{dat_line.booking_id}}"><a href="#{{dat_line.booking_id}}">#</a>/<a href="/balance?up_incl={{dat_line.booking_id}}">b</a></td>
+    <td id="{{dat_line.booking_id}}"><a href="#{{dat_line.booking_id}}">[#]</a></td>
+  {% elif dat_line.booking_line.idx == 1 %}
+    <td><a href="/balance?up_incl={{dat_line.booking_id}}">[b]</a></td>
   {% else %}
     <td></td>
   {% endif %}
@@ -29,8 +35,8 @@ td.invalid, tr.warning td.invalid { background-color: #ff0000; }
     </td>
   {% else %}
     {% if dat_line.is_intro %}
-      <td{% if dat_line.error %} class="invalid"{% endif %}><a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking_line.date}}</a></td>
-      <td{% if dat_line.error %} class="invalid"{% endif %} colspan=2>{{dat_line.booking_line.target}}</td>
+      <td class="date {% if dat_line.error %} invalid{% endif %}" colspan=2><a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking_line.date}}</a></td>
+      <td{% if dat_line.error %} class="invalid"{% endif %}>{{dat_line.booking_line.target}}</td>
     {% elif not dat_line.error %}
       <td class="amt">{{dat_line.booking_line.amount_short}}</td>
       <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"…")}}</td>
diff --git a/templates/ledger_raw.tmpl b/templates/ledger_raw.tmpl
index d09e722..d11e192 100644
--- a/templates/ledger_raw.tmpl
+++ b/templates/ledger_raw.tmpl
@@ -4,6 +4,7 @@
 {% block css %}
 table { font-family: monospace; }
 {{ macros.css_errors() }}
+{{ macros.css_ledger_index_col() }}
 {% endblock %}
 
 {% block content %}
diff --git a/templates/ledger_structured.tmpl b/templates/ledger_structured.tmpl
index 1669ce9..654cf80 100644
--- a/templates/ledger_structured.tmpl
+++ b/templates/ledger_structured.tmpl
@@ -4,6 +4,9 @@
 {% block css %}
 {{ macros.css_td_money() }}
 {{ macros.css_errors() }}
+{{ macros.css_ledger_index_col() }}
+table.ledger > tbody > tr > td.date, table.ledger > tbody > tr > td:first-child { font-family: monospace; font-size: 1.3em; text-align: center; }
+table.ledger > tbody > tr > td { vertical-align: middle; }
 {% endblock %}
 
 {% block content %}
-- 
2.30.2