General journal transaction editor: Automatically fill in other posting when only 2 postings
This commit is contained in:
parent
371e7f39c4
commit
7bbbce7a65
@ -57,7 +57,7 @@
|
||||
<td class="amount-dr has-amount">
|
||||
<div class="input-group">
|
||||
<div class="input-group-text">$</div>
|
||||
<input type="text" name="amount" value="{{ posting.amount().quantity_string() }}" class="form-control">
|
||||
<input type="text" name="amount" value="{{ posting.amount().quantity_string() }}" class="form-control" oninput="changeAmount(this)">
|
||||
</div>
|
||||
</td>
|
||||
<td class="amount-cr"></td>
|
||||
@ -66,7 +66,7 @@
|
||||
<td class="amount-cr has-amount">
|
||||
<div class="input-group">
|
||||
<div class="input-group-text">$</div>
|
||||
<input type="text" name="amount" value="{{ (posting.amount()|abs).quantity_string() }}" class="form-control">
|
||||
<input type="text" name="amount" value="{{ (posting.amount()|abs).quantity_string() }}" class="form-control" oninput="changeAmount(this)">
|
||||
</div>
|
||||
</td>
|
||||
{% endif %}
|
||||
@ -89,7 +89,7 @@
|
||||
<td class="amount-dr has-amount">
|
||||
<div class="input-group">
|
||||
<div class="input-group-text">$</div>
|
||||
<input type="text" name="amount" value="" class="form-control">
|
||||
<input type="text" name="amount" class="form-control" oninput="changeAmount(this)">
|
||||
</div>
|
||||
</td>
|
||||
<td class="amount-cr"></td>
|
||||
@ -111,7 +111,7 @@
|
||||
<td class="amount-cr has-amount">
|
||||
<div class="input-group">
|
||||
<div class="input-group-text">$</div>
|
||||
<input type="text" name="amount" value="" class="form-control">
|
||||
<input type="text" name="amount" class="form-control" oninput="changeAmount(this)">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -149,12 +149,29 @@
|
||||
let trPosting = el.parentNode.parentNode.parentNode;
|
||||
let sign = trPosting.querySelector('select').value; // Use same sign as row clicked
|
||||
|
||||
let inputAmount = '<div class="input-group"><div class="input-group-text">$</div><input type="text" name="amount" class="form-control"></div>';
|
||||
let inputAmount = '<div class="input-group"><div class="input-group-text">$</div><input type="text" name="amount" class="form-control" oninput="changeAmount(this)"></div>';
|
||||
|
||||
// Add new posting row
|
||||
let trNew = document.createElement('tr');
|
||||
trNew.innerHTML = '<tr><td></td><td></td><td><div class="input-group"><select class="form-select" name="sign" style="flex-grow:0;min-width:5em" onchange="changeDrCr(this)"><option value="dr"' + (sign === 'dr' ? ' selected' : '') + '>Dr</option><option value="cr"' + (sign === 'cr' ? ' selected' : '') + '>Cr</option></select><input type="text" name="account" class="form-control"><a class="btn btn-outline-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a></div></td>' + (sign === 'dr' ? ('<td class="amount-dr has-amount">' + inputAmount + '</td>') : '<td class="amount-dr"></td>') + (sign === 'cr' ? ('<td class="amount-cr has-amount">' + inputAmount + '</td>') : '<td class="amount-cr"></td>') + '</tr>';
|
||||
trPosting.after(trNew);
|
||||
}
|
||||
|
||||
function changeAmount(el) {
|
||||
let amountInputs = document.querySelectorAll('input[name="amount"]');
|
||||
if (amountInputs.length === 2) {
|
||||
// Get other input
|
||||
let otherInput;
|
||||
for (inp of amountInputs) {
|
||||
if (inp !== el) {
|
||||
otherInput = inp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update other input with amount
|
||||
otherInput.value = el.value;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user