Revised the account selector to find the account codes from the form through the TransactionForm class, but not finding the codes by itself.

This commit is contained in:
依瑪貓 2023-03-13 21:04:39 +08:00
parent cdd31b1047
commit 82a6a53dc4
2 changed files with 58 additions and 5 deletions

View File

@ -150,14 +150,10 @@ class AccountSelector {
* @return {string[]} the account codes that are used in the form
*/
#getCodesUsedInForm() {
const accountCodes = Array.from(document.getElementsByClassName("accounting-" + this.#prefix + "-account-code"));
const inUse = [];
const inUse = TransactionForm.getAccountCodesUsed(this.#entryType);
if (this.#entryEditor.getAccountCode() !== null) {
inUse.push(this.#entryEditor.getAccountCode());
}
for (const accountCode of accountCodes) {
inUse.push(accountCode.value);
}
return inUse
}

View File

@ -178,6 +178,20 @@ class TransactionForm {
});
}
/**
* Returns the account codes used in the form.
*
* @param entryType {string} the entry type, either "debit" or "credit"
* @return {string[]} the account codes used in the form
*/
#getAccountCodesUsed(entryType) {
let inUse = [];
for (const currency of this.#currencies) {
inUse = inUse.concat(currency.getAccountCodesUsed(entryType));
}
return inUse;
}
/**
* Validates the form.
*
@ -266,6 +280,16 @@ class TransactionForm {
static initialize() {
this.#form = new TransactionForm()
}
/**
* Returns the account codes used in the form.
*
* @param entryType {string} the entry type, either "debit" or "credit"
* @return {string[]} the account codes used in the form
*/
static getAccountCodesUsed(entryType) {
return this.#form.#getAccountCodesUsed(entryType);
}
}
/**
@ -359,6 +383,21 @@ class CurrencySubForm {
};
}
/**
* Returns the account codes used in the form.
*
* @param entryType {string} the entry type, either "debit" or "credit"
* @return {string[]} the account codes used in the form
*/
getAccountCodesUsed(entryType) {
if (entryType === "debit") {
return this.#debit.getAccountCodesUsed();
} else if (entryType === "credit") {
return this.#credit.getAccountCodesUsed();
}
return []
}
/**
* Validates the form.
*
@ -577,6 +616,15 @@ class DebitCreditSideSubForm {
});
}
/**
* Returns the account codes used in the form.
*
* @return {string[]} the account codes used in the form
*/
getAccountCodesUsed() {
return this.#entries.filter((entry) => entry.getAccountCode() !== null).map((entry) => entry.getAccountCode());
}
/**
* Validates the form.
*
@ -735,6 +783,15 @@ class JournalEntrySubForm {
};
}
/**
* Returns the account code.
*
* @return {string|null} the account code
*/
getAccountCode() {
return this.#accountCode.value === ""? null: this.#accountCode.value;
}
/**
* Validates the form.
*