Replaced the accountCode and accountText getters with the account getter in the JavaScript LineItemSubForm class.

This commit is contained in:
依瑪貓 2023-04-01 00:14:47 +08:00
parent 94391b02a6
commit a1d6844e52
2 changed files with 8 additions and 26 deletions

View File

@ -207,8 +207,8 @@ class JournalEntryForm {
* @return {string[]} the account codes used in the form
*/
getAccountCodesUsed(debitCredit) {
return this.getLineItems(debitCredit).map((lineItem) => lineItem.accountCode)
.filter((code) => code !== null);
return this.getLineItems(debitCredit).filter((lineItem) => lineItem.account !== null)
.map((lineItem) => lineItem.account.code);
}
/**
@ -940,15 +940,6 @@ class LineItemSubForm {
this.#no.value = String(siblings.indexOf(this.#element) + 1);
}
/**
* Returns whether the line item needs offset.
*
* @return {boolean} true if the line item needs offset, or false otherwise
*/
get isNeedOffset() {
return "isNeedOffset" in this.#element.dataset;
}
/**
* Returns the ID of the original line item.
*
@ -986,21 +977,12 @@ class LineItemSubForm {
}
/**
* Returns the account code.
* Returns the account.
*
* @return {string|null} the account code
* @return {JournalEntryAccount|null} the account
*/
get accountCode() {
return this.#accountCode.value === ""? null: this.#accountCode.value;
}
/**
* Returns the account text.
*
* @return {string|null} the account text
*/
get accountText() {
return this.#accountCode.dataset.text === ""? null: this.#accountCode.dataset.text;
get account() {
return this.#accountCode.value === null? null: new JournalEntryAccount(this.#accountCode.value, this.#accountCode.dataset.text, "isNeedOffset" in this.#element.dataset);
}
/**

View File

@ -517,12 +517,12 @@ class JournalEntryLineItemEditor {
this.#descriptionControl.classList.add("accounting-not-empty");
}
this.#descriptionText.innerText = this.description === null? "": this.description;
if (lineItem.accountCode === null) {
this.account = lineItem.account;
if (this.account === null) {
this.#accountControl.classList.remove("accounting-not-empty");
} else {
this.#accountControl.classList.add("accounting-not-empty");
}
this.account = new JournalEntryAccount(lineItem.accountCode, lineItem.accountText, lineItem.isNeedOffset);
this.#accountText.innerText = this.account.text;
this.#amountInput.value = lineItem.amount === null? "": String(lineItem.amount);
const maxAmount = this.#getMaxAmount();