+ def ledger2_as_html(self, db):
+ single_c_tmpl = jinja2.Template('<span class="comment">{{c|e}}</span><br />')
+ booking_tmpl = jinja2.Template("""
+<p>{{date}} {{desc}} <span class="comment">{{head_comment|e}}</span>
+[edit: <a href="/add_structured?start={{start}}&end={{end}}">structured</a>
+/ <a href="/add_free?start={{start}}&end={{end}}">free</a>
+| copy:<a href="/copy_structured?start={{start}}&end={{end}}">structured</a>
+/ <a href="/copy_free?start={{start}}&end={{end}}">free</a>]
+<table>
+{% for l in booking_lines %}
+<tr><td>{{l.acc|e}}</td><td class="money">{{l.money|e}}</td><td class="money">{{l.balance|e}}</td></tr>
+{% endfor %}
+</table></p>
+""")
+ elements_to_write = []
+ account_sums = {}
+ for booking in db.bookings:
+ i = booking.start_line
+ booking_end = booking.start_line + len(booking.lines)
+ booking_lines = []
+ for booking_line in booking.lines[1:]:
+ if booking_line == '':
+ continue
+ account = booking_line[0]
+ account_toks = account.split(':')
+ path = ''
+ for tok in account_toks:
+ path += tok
+ if not path in account_sums.keys():
+ account_sums[path] = {}
+ path += ':'
+ moneys = []
+ money = ''
+ if booking_line[1] is not None:
+ moneys += [(booking_line[1], booking_line[2])]
+ money = f'{moneys[0][0]} {moneys[0][1]}'
+ else:
+ for currency, amount in booking.sink.items():
+ moneys += {(amount, currency)}
+ money = '['
+ for m in moneys:
+ money += f'{m[0]} {m[1]} '
+ money += ']'
+ balance = ''
+ for amount, currency in moneys:
+ path = ''
+ for tok in account_toks:
+ path += tok
+ if not currency in account_sums[path].keys():
+ account_sums[path][currency] = 0
+ account_sums[path][currency] += amount
+ path += ':'
+ balance += f'{account_sums[account][currency]} {currency}'
+ booking_lines += [{'acc': booking_line[0], 'money':money, 'balance':balance}]
+ elements_to_write += [booking_tmpl.render(
+ start=booking.start_line,
+ end=booking_end,
+ date=booking.date_string,
+ desc=booking.description,
+ head_comment=db.comments[booking.start_line],
+ booking_lines = booking_lines)]
+ return '\n'.join(elements_to_write)
+