Replaced the JavaScript getXXX methods with the "get XXX" getters.

This commit is contained in:
依瑪貓 2023-03-23 08:11:11 +08:00
parent fa1dedf207
commit 57a4177037
5 changed files with 66 additions and 64 deletions

View File

@ -1019,7 +1019,7 @@ class RecurringTransactionTab extends TabPlane {
* @return {string} the description of the recurring item
*/
#getDescription(itemButton) {
const today = new Date(this.editor.lineItemEditor.form.getDate());
const today = new Date(this.editor.lineItemEditor.form.date);
const thisMonth = today.getMonth() + 1;
const lastMonth = (thisMonth + 10) % 12 + 1;
const lastBimonthlyFrom = ((thisMonth + thisMonth % 2 + 8) % 12 + 1);

View File

@ -213,7 +213,7 @@ class JournalEntryForm {
* @return {string[]} the account codes used in the form
*/
getAccountCodesUsed(debitCredit) {
return this.getLineItems(debitCredit).map((lineItem) => lineItem.getAccountCode())
return this.getLineItems(debitCredit).map((lineItem) => lineItem.accountCode)
.filter((code) => code !== null);
}
@ -222,7 +222,7 @@ class JournalEntryForm {
*
* @return {string} the date
*/
getDate() {
get date() {
return this.#date.value;
}
@ -233,7 +233,7 @@ class JournalEntryForm {
updateMinDate() {
let lastOriginalLineItemDate = null;
for (const lineItem of this.getLineItems()) {
const date = lineItem.getOriginalLineItemDate();
const date = lineItem.originalLineItemDate;
if (date !== null) {
if (lastOriginalLineItemDate === null || lastOriginalLineItemDate < date) {
lastOriginalLineItemDate = date;
@ -444,7 +444,7 @@ class CurrencySubForm {
*
* @return {string} the currency code
*/
getCurrencyCode() {
get currencyCode() {
return this.#code.value;
}
@ -473,7 +473,7 @@ class CurrencySubForm {
updateCodeSelectorStatus() {
let isEnabled = true;
for (const lineItem of this.getLineItems()) {
if (lineItem.getOriginalLineItemId() !== null) {
if (lineItem.originalLineItemId !== null) {
isEnabled = false;
break;
}
@ -505,7 +505,7 @@ class CurrencySubForm {
*/
validateBalance() {
if (this.#debit !== null && this.#credit !== null) {
if (!this.#debit.getTotal().equals(this.#credit.getTotal())) {
if (!this.#debit.total.equals(this.#credit.total)) {
this.#control.classList.add("is-invalid");
this.#error.innerText = A_("The totals of the debit and credit amounts do not match.");
return false;
@ -664,10 +664,10 @@ class DebitCreditSubForm {
*
* @return {Decimal} the total amount
*/
getTotal() {
get total() {
let total = new Decimal("0");
for (const lineItem of this.lineItems) {
const amount = lineItem.getAmount();
const amount = lineItem.amount;
if (amount !== null) {
total = total.plus(amount);
}
@ -680,7 +680,7 @@ class DebitCreditSubForm {
*
*/
updateTotal() {
this.#total.innerText = formatDecimal(this.getTotal());
this.#total.innerText = formatDecimal(this.total);
this.currency.validateBalance();
}
@ -881,7 +881,7 @@ class LineItemSubForm {
*
* @return {boolean} true if the line item needs offset, or false otherwise
*/
isNeedOffset() {
get isNeedOffset() {
return "isNeedOffset" in this.element.dataset;
}
@ -890,7 +890,7 @@ class LineItemSubForm {
*
* @return {string|null} the ID of the original line item
*/
getOriginalLineItemId() {
get originalLineItemId() {
return this.#originalLineItemId.value === ""? null: this.#originalLineItemId.value;
}
@ -899,7 +899,7 @@ class LineItemSubForm {
*
* @return {string|null} the date of the original line item
*/
getOriginalLineItemDate() {
get originalLineItemDate() {
return this.#originalLineItemId.dataset.date === ""? null: this.#originalLineItemId.dataset.date;
}
@ -908,7 +908,7 @@ class LineItemSubForm {
*
* @return {string|null} the text of the original line item
*/
getOriginalLineItemText() {
get originalLineItemText() {
return this.#originalLineItemId.dataset.text === ""? null: this.#originalLineItemId.dataset.text;
}
@ -917,7 +917,7 @@ class LineItemSubForm {
*
* @return {string|null} the description
*/
getDescription() {
get description() {
return this.#description.value === ""? null: this.#description.value;
}
@ -926,7 +926,7 @@ class LineItemSubForm {
*
* @return {string|null} the account code
*/
getAccountCode() {
get accountCode() {
return this.#accountCode.value === ""? null: this.#accountCode.value;
}
@ -935,7 +935,7 @@ class LineItemSubForm {
*
* @return {string|null} the account text
*/
getAccountText() {
get accountText() {
return this.#accountCode.dataset.text === ""? null: this.#accountCode.dataset.text;
}
@ -944,7 +944,7 @@ class LineItemSubForm {
*
* @return {Decimal|null} the amount
*/
getAmount() {
get amount() {
return this.#amount.value === ""? null: new Decimal(this.#amount.value);
}
@ -953,7 +953,7 @@ class LineItemSubForm {
*
* @return {Decimal|null} the minimal amount
*/
getAmountMin() {
get amountMin() {
return this.#amount.dataset.min === ""? null: new Decimal(this.#amount.dataset.min);
}

View File

@ -190,12 +190,6 @@ class JournalEntryLineItemEditor {
*/
description = null;
/**
* The amount
* @type {string}
*/
amount = "";
/**
* The description editors
* @type {{debit: DescriptionEditor, credit: DescriptionEditor}}
@ -249,7 +243,6 @@ class JournalEntryLineItemEditor {
if (this.lineItem === null) {
this.lineItem = this.#debitCreditSubForm.addLineItem();
}
this.amount = this.#amountInput.value;
this.lineItem.save(this);
bootstrap.Modal.getInstance(this.#modal).hide();
}
@ -257,6 +250,24 @@ class JournalEntryLineItemEditor {
};
}
/**
* Returns the amount.
*
* @return {string} the amount
*/
get amount() {
return this.#amountInput.value;
}
/**
* Returns the currency code.
*
* @return {string} the currency code
*/
get currencyCode() {
return this.#debitCreditSubForm.currency.currencyCode;
}
/**
* Saves the original line item from the original line item selector.
*
@ -308,15 +319,6 @@ class JournalEntryLineItemEditor {
this.#amountInput.max = "";
}
/**
* Returns the currency code.
*
* @return {string} the currency code
*/
getCurrencyCode() {
return this.#debitCreditSubForm.currency.getCurrencyCode();
}
/**
* Saves the description from the description editor.
*
@ -520,10 +522,10 @@ class JournalEntryLineItemEditor {
this.lineItem = lineItem;
this.#debitCreditSubForm = lineItem.debitCreditSubForm;
this.debitCredit = this.#debitCreditSubForm.debitCredit;
this.isNeedOffset = lineItem.isNeedOffset();
this.originalLineItemId = lineItem.getOriginalLineItemId();
this.originalLineItemDate = lineItem.getOriginalLineItemDate();
this.originalLineItemText = lineItem.getOriginalLineItemText();
this.isNeedOffset = lineItem.isNeedOffset;
this.originalLineItemId = lineItem.originalLineItemId;
this.originalLineItemDate = lineItem.originalLineItemDate;
this.originalLineItemText = lineItem.originalLineItemText;
this.#originalLineItemText.innerText = this.originalLineItemText;
if (this.originalLineItemId === null) {
this.#originalLineItemContainer.classList.add("d-none");
@ -533,25 +535,25 @@ class JournalEntryLineItemEditor {
this.#originalLineItemControl.classList.add("accounting-not-empty");
}
this.#setEnableDescriptionAccount(!lineItem.isMatched && this.originalLineItemId === null);
this.description = lineItem.getDescription();
this.description = lineItem.description;
if (this.description === null) {
this.#descriptionControl.classList.remove("accounting-not-empty");
} else {
this.#descriptionControl.classList.add("accounting-not-empty");
}
this.#descriptionText.innerText = this.description === null? "": this.description;
if (lineItem.getAccountCode() === null) {
if (lineItem.accountCode === null) {
this.#accountControl.classList.remove("accounting-not-empty");
} else {
this.#accountControl.classList.add("accounting-not-empty");
}
this.accountCode = lineItem.getAccountCode();
this.accountText = lineItem.getAccountText();
this.accountCode = lineItem.accountCode;
this.accountText = lineItem.accountText;
this.#accountText.innerText = this.accountText;
this.#amountInput.value = lineItem.getAmount() === null? "": String(lineItem.getAmount());
this.#amountInput.value = lineItem.amount === null? "": String(lineItem.amount);
const maxAmount = this.#getMaxAmount();
this.#amountInput.max = maxAmount === null? "": maxAmount;
this.#amountInput.min = lineItem.getAmountMin() === null? "": String(lineItem.getAmountMin());
this.#amountInput.min = lineItem.amountMin === null? "": String(lineItem.amountMin);
this.#validate();
}

View File

@ -467,7 +467,7 @@ class RecurringItemSubForm {
*
* @return {string|null} the name
*/
getName() {
get name() {
return this.#name.value === ""? null: this.#name.value;
}
@ -476,7 +476,7 @@ class RecurringItemSubForm {
*
* @return {string|null} the account code
*/
getAccountCode() {
get accountCode() {
return this.#accountCode.value === ""? null: this.#accountCode.value;
}
@ -485,7 +485,7 @@ class RecurringItemSubForm {
*
* @return {string|null} the account text
*/
getAccountText() {
get accountText() {
return this.#accountCode.dataset.text === ""? null: this.#accountCode.dataset.text;
}
@ -494,7 +494,7 @@ class RecurringItemSubForm {
*
* @return {string|null} the description template
*/
getDescriptionTemplate() {
get descriptionTemplate() {
return this.#descriptionTemplate.value === ""? null: this.#descriptionTemplate.value;
}
@ -504,12 +504,12 @@ class RecurringItemSubForm {
* @param editor {RecurringItemEditor} the recurring item editor
*/
save(editor) {
this.#name.value = editor.getName() === null? "": editor.getName();
this.#name.value = editor.name === null? "": editor.name;
this.#nameText.innerText = this.#name.value;
this.#accountCode.value = editor.accountCode;
this.#accountCode.dataset.text = editor.accountText;
this.#accountText.innerText = editor.accountText;
this.#descriptionTemplate.value = editor.getDescriptionTemplate() === null? "": editor.getDescriptionTemplate();
this.#descriptionTemplate.value = editor.descriptionTemplate === null? "": editor.descriptionTemplate;
this.#descriptionTemplateText.innerText = this.#descriptionTemplate.value;
this.validate();
}
@ -677,7 +677,7 @@ class RecurringItemEditor {
*
* @return {string|null} the name
*/
getName() {
get name() {
return this.#name.value === ""? null: this.#name.value;
}
@ -686,7 +686,7 @@ class RecurringItemEditor {
*
* @return {string|null} the description template
*/
getDescriptionTemplate() {
get descriptionTemplate() {
return this.#descriptionTemplate.value === ""? null: this.#descriptionTemplate.value;
}
@ -742,16 +742,16 @@ class RecurringItemEditor {
*/
onEdit(item) {
this.#item = item;
this.#name.value = item.getName() === null? "": item.getName();
this.accountCode = item.getAccountCode();
this.accountText = item.getAccountText();
this.#name.value = item.name === null? "": item.name;
this.accountCode = item.accountCode;
this.accountText = item.accountText;
if (this.accountText === null) {
this.#accountControl.classList.remove("accounting-not-empty");
} else {
this.#accountControl.classList.add("accounting-not-empty");
}
this.#accountContainer.innerText = item.getAccountText() == null? "": item.getAccountText();
this.#descriptionTemplate.value = item.getDescriptionTemplate() === null? "": item.getDescriptionTemplate();
this.#accountContainer.innerText = this.accountText === null? "": this.accountText;
this.#descriptionTemplate.value = item.descriptionTemplate === null? "": item.descriptionTemplate;
this.#validate();
}

View File

@ -113,8 +113,8 @@ class OriginalLineItemSelector {
const otherLineItems = form.getLineItems().filter((lineItem) => lineItem !== currentLineItem);
let otherOffset = new Decimal(0);
for (const otherLineItem of otherLineItems) {
if (otherLineItem.getOriginalLineItemId() === originalLineItemId) {
const amount = otherLineItem.getAmount();
if (otherLineItem.originalLineItemId === originalLineItemId) {
const amount = otherLineItem.amount;
if (amount !== null) {
otherOffset = otherOffset.plus(amount);
}
@ -131,8 +131,8 @@ class OriginalLineItemSelector {
const otherLineItems = this.lineItemEditor.form.getLineItems().filter((lineItem) => lineItem !== this.lineItemEditor.lineItem);
const otherOffsets = {}
for (const otherLineItem of otherLineItems) {
const otherOriginalLineItemId = otherLineItem.getOriginalLineItemId();
const amount = otherLineItem.getAmount();
const otherOriginalLineItemId = otherLineItem.originalLineItemId;
const amount = otherLineItem.amount;
if (otherOriginalLineItemId === null || amount === null) {
continue;
}
@ -178,7 +178,7 @@ class OriginalLineItemSelector {
*
*/
onOpen() {
this.#currencyCode = this.lineItemEditor.getCurrencyCode();
this.#currencyCode = this.lineItemEditor.currencyCode;
this.#debitCredit = this.lineItemEditor.debitCredit;
for (const option of this.#options) {
option.setActive(option.id === this.lineItemEditor.originalLineItemId);
@ -341,7 +341,7 @@ class OriginalLineItem {
*/
isMatched(debitCredit, currencyCode, query = null) {
return this.netBalance.greaterThan(0)
&& this.date <= this.#selector.lineItemEditor.form.getDate()
&& this.date <= this.#selector.lineItemEditor.form.date
&& this.#isDebitCreditMatches(debitCredit)
&& this.#currencyCode === currencyCode
&& this.#isQueryMatches(query);