home · contact · privacy
Add "mirror" button to /edit_structured.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 26 Feb 2025 16:37:37 +0000 (17:37 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 26 Feb 2025 16:37:37 +0000 (17:37 +0100)
src/templates/edit_structured.tmpl

index de2a2264e91829508c572487fb7dd4b9d40bd1e2..c3431d3be4b870c0ded8b3e3502289cffeb05135 100644 (file)
@@ -175,6 +175,26 @@ function replace() {
   update_form();
 }
 
+function mirror() {
+  dat_lines.slice(1).forEach((dat_line) => {
+      let inverted_amount = `-${dat_line.booking_line.amount}`;
+      if (inverted_amount.startsWith('--')) {
+          inverted_amount = inverted_amount.slice(2);
+      }
+      dat_lines.push({
+          error: '',
+          comment: '',
+          booking_line: {
+              account: '?',
+              amount: inverted_amount,
+              currency: dat_line.booking_line.currency
+          }
+      });
+  })
+  taint();
+  update_form();
+}
+
 window.onload = update_form;
 {% endblock %}
 
@@ -182,6 +202,8 @@ window.onload = update_form;
 {% block content %}
 <form action="/edit_structured/{{id}}" method="POST">
 {{ macros.edit_bar("raw", id) }}
+<input type="button" onclick="mirror()" value="mirror" class="disable_on_change">
+|
 <input type="button" onclick="replace()" value="replace string" class="disable_on_change">
 from
 <input id="replace_from" />