Added the TransactionForm instance to the constructor of the JournalEntryEditor instance, so that the journal entry editor holds an instance of the transaction form, too. It does not need to find the transaction form all the way from the side property that may not be available. Retired the redundant getTransactionForm method from the JournalEntryEditor class.

This commit is contained in:
依瑪貓 2023-03-18 17:52:37 +08:00
parent 67e2b06d37
commit 38c394c0af
4 changed files with 14 additions and 15 deletions

View File

@ -146,7 +146,7 @@ class AccountSelector {
* @return {string[]} the account codes that are used in the form * @return {string[]} the account codes that are used in the form
*/ */
#getCodesUsedInForm() { #getCodesUsedInForm() {
const inUse = this.#entryEditor.getTransactionForm().getAccountCodesUsed(this.#entryType); const inUse = this.#entryEditor.form.getAccountCodesUsed(this.#entryType);
if (this.#entryEditor.accountCode !== null) { if (this.#entryEditor.accountCode !== null) {
inUse.push(this.#entryEditor.accountCode); inUse.push(this.#entryEditor.accountCode);
} }

View File

@ -28,6 +28,12 @@
*/ */
class JournalEntryEditor { class JournalEntryEditor {
/**
* The transaction form
* @type {TransactionForm}
*/
form;
/** /**
* The journal entry editor * The journal entry editor
* @type {HTMLFormElement} * @type {HTMLFormElement}
@ -193,8 +199,10 @@ class JournalEntryEditor {
/** /**
* Constructs a new journal entry editor. * Constructs a new journal entry editor.
* *
* @param form {TransactionForm} the transaction form
*/ */
constructor() { constructor(form) {
this.form = form;
this.#element = document.getElementById(this.#prefix); this.#element = document.getElementById(this.#prefix);
this.#modal = document.getElementById(this.#prefix + "-modal"); this.#modal = document.getElementById(this.#prefix + "-modal");
this.#originalEntryContainer = document.getElementById(this.#prefix + "-original-entry-container"); this.#originalEntryContainer = document.getElementById(this.#prefix + "-original-entry-container");
@ -288,15 +296,6 @@ class JournalEntryEditor {
return this.#side.currency.getCurrencyCode(); return this.#side.currency.getCurrencyCode();
} }
/**
* Returns the transaction form.
*
* @return {TransactionForm} the transaction form
*/
getTransactionForm() {
return this.#side.currency.form;
}
/** /**
* Saves the summary from the summary editor. * Saves the summary from the summary editor.
* *
@ -554,7 +553,7 @@ class JournalEntryEditor {
if (this.originalEntryId === null) { if (this.originalEntryId === null) {
return null; return null;
} }
return OriginalEntrySelector.getNetBalance(this.entry, this.getTransactionForm(), this.originalEntryId); return OriginalEntrySelector.getNetBalance(this.entry, this.form, this.originalEntryId);
} }
/** /**

View File

@ -127,7 +127,7 @@ class OriginalEntrySelector {
* *
*/ */
#updateNetBalances() { #updateNetBalances() {
const otherEntries = this.entryEditor.getTransactionForm().getEntries().filter((entry) => entry !== this.entryEditor.entry); const otherEntries = this.entryEditor.form.getEntries().filter((entry) => entry !== this.entryEditor.entry);
const otherOffsets = {} const otherOffsets = {}
for (const otherEntry of otherEntries) { for (const otherEntry of otherEntries) {
const otherOriginalEntryId = otherEntry.getOriginalEntryId(); const otherOriginalEntryId = otherEntry.getOriginalEntryId();
@ -379,7 +379,7 @@ class OriginalEntry {
*/ */
isMatched(entryType, currencyCode, query = null) { isMatched(entryType, currencyCode, query = null) {
return this.netBalance.greaterThan(0) return this.netBalance.greaterThan(0)
&& this.date <= this.#selector.entryEditor.getTransactionForm().getDate() && this.date <= this.#selector.entryEditor.form.getDate()
&& this.#isEntryTypeMatches(entryType) && this.#isEntryTypeMatches(entryType)
&& this.#currencyCode === currencyCode && this.#currencyCode === currencyCode
&& this.#isQueryMatches(query); && this.#isQueryMatches(query);

View File

@ -121,7 +121,7 @@ class TransactionForm {
this.#addCurrencyButton = document.getElementById("accounting-add-currency"); this.#addCurrencyButton = document.getElementById("accounting-add-currency");
this.#note = document.getElementById("accounting-note"); this.#note = document.getElementById("accounting-note");
this.#noteError = document.getElementById("accounting-note-error"); this.#noteError = document.getElementById("accounting-note-error");
this.entryEditor = new JournalEntryEditor(); this.entryEditor = new JournalEntryEditor(this);
this.#addCurrencyButton.onclick = () => { this.#addCurrencyButton.onclick = () => {
const newIndex = 1 + (this.#currencies.length === 0? 0: Math.max(...this.#currencies.map((currency) => currency.index))); const newIndex = 1 + (this.#currencies.length === 0? 0: Math.max(...this.#currencies.map((currency) => currency.index)));