Added the JavaScript JournalEntryAccount class, and added the account field to the JournalEntryLineItemEditor class to replace the accountCode, accountText, and isNeedOffset fields.
This commit is contained in:
parent
63f0f28948
commit
1cb8a7563e
@ -139,8 +139,8 @@ class JournalEntryAccountSelector {
|
|||||||
*/
|
*/
|
||||||
#getCodesUsedInForm() {
|
#getCodesUsedInForm() {
|
||||||
const inUse = this.lineItemEditor.form.getAccountCodesUsed(this.#debitCredit);
|
const inUse = this.lineItemEditor.form.getAccountCodesUsed(this.#debitCredit);
|
||||||
if (this.lineItemEditor.accountCode !== null) {
|
if (this.lineItemEditor.account !== null) {
|
||||||
inUse.push(this.lineItemEditor.accountCode);
|
inUse.push(this.lineItemEditor.account.code);
|
||||||
}
|
}
|
||||||
return inUse
|
return inUse
|
||||||
}
|
}
|
||||||
@ -155,9 +155,9 @@ class JournalEntryAccountSelector {
|
|||||||
this.#more.classList.remove("d-none");
|
this.#more.classList.remove("d-none");
|
||||||
this.#filterOptions();
|
this.#filterOptions();
|
||||||
for (const option of this.#options) {
|
for (const option of this.#options) {
|
||||||
option.setActive(option.code === this.lineItemEditor.accountCode);
|
option.setActive(this.lineItemEditor.account !== null && option.code === this.lineItemEditor.account.code);
|
||||||
}
|
}
|
||||||
if (this.lineItemEditor.accountCode === null) {
|
if (this.lineItemEditor.account === null) {
|
||||||
this.#clearButton.classList.add("btn-secondary");
|
this.#clearButton.classList.add("btn-secondary");
|
||||||
this.#clearButton.classList.remove("btn-danger");
|
this.#clearButton.classList.remove("btn-danger");
|
||||||
this.#clearButton.disabled = true;
|
this.#clearButton.disabled = true;
|
||||||
|
@ -1061,7 +1061,7 @@ class LineItemSubForm {
|
|||||||
* @param editor {JournalEntryLineItemEditor} the line item editor
|
* @param editor {JournalEntryLineItemEditor} the line item editor
|
||||||
*/
|
*/
|
||||||
save(editor) {
|
save(editor) {
|
||||||
if (editor.isNeedOffset) {
|
if (editor.account.isNeedOffset) {
|
||||||
this.#offsets.classList.remove("d-none");
|
this.#offsets.classList.remove("d-none");
|
||||||
} else {
|
} else {
|
||||||
this.#offsets.classList.add("d-none");
|
this.#offsets.classList.add("d-none");
|
||||||
@ -1076,9 +1076,9 @@ class LineItemSubForm {
|
|||||||
this.#originalLineItemText.classList.remove("d-none");
|
this.#originalLineItemText.classList.remove("d-none");
|
||||||
this.#originalLineItemText.innerText = A_("Offset %(item)s", {item: editor.originalLineItemText});
|
this.#originalLineItemText.innerText = A_("Offset %(item)s", {item: editor.originalLineItemText});
|
||||||
}
|
}
|
||||||
this.#accountCode.value = editor.accountCode === null? "": editor.accountCode;
|
this.#accountCode.value = editor.account === null? "": editor.account.code;
|
||||||
this.#accountCode.dataset.text = editor.accountText === null? "": editor.accountText;
|
this.#accountCode.dataset.text = editor.account === null? "": editor.account.text;
|
||||||
this.#accountText.innerText = editor.accountText === null? "": editor.accountText;
|
this.#accountText.innerText = editor.account === null? "": editor.account.text;
|
||||||
this.#description.value = editor.description === null? "": editor.description;
|
this.#description.value = editor.description === null? "": editor.description;
|
||||||
this.#descriptionText.innerText = editor.description === null? "": editor.description;
|
this.#descriptionText.innerText = editor.description === null? "": editor.description;
|
||||||
this.#amount.value = editor.amount;
|
this.#amount.value = editor.amount;
|
||||||
|
@ -148,12 +148,6 @@ class JournalEntryLineItemEditor {
|
|||||||
*/
|
*/
|
||||||
#debitCreditSubForm;
|
#debitCreditSubForm;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the journal entry line item needs offset
|
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
isNeedOffset = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the original line item
|
* The ID of the original line item
|
||||||
* @type {string|null}
|
* @type {string|null}
|
||||||
@ -173,16 +167,10 @@ class JournalEntryLineItemEditor {
|
|||||||
originalLineItemText = null;
|
originalLineItemText = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The account code
|
* The account
|
||||||
* @type {string|null}
|
* @type {JournalEntryAccount|null}
|
||||||
*/
|
*/
|
||||||
accountCode = null;
|
account = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The account text
|
|
||||||
* @type {string|null}
|
|
||||||
*/
|
|
||||||
accountText = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description
|
* The description
|
||||||
@ -276,7 +264,6 @@ class JournalEntryLineItemEditor {
|
|||||||
* @param originalLineItem {OriginalLineItem} the original line item
|
* @param originalLineItem {OriginalLineItem} the original line item
|
||||||
*/
|
*/
|
||||||
saveOriginalLineItem(originalLineItem) {
|
saveOriginalLineItem(originalLineItem) {
|
||||||
this.isNeedOffset = false;
|
|
||||||
this.#originalLineItemContainer.classList.remove("d-none");
|
this.#originalLineItemContainer.classList.remove("d-none");
|
||||||
this.#originalLineItemControl.classList.add("accounting-not-empty");
|
this.#originalLineItemControl.classList.add("accounting-not-empty");
|
||||||
this.originalLineItemId = originalLineItem.id;
|
this.originalLineItemId = originalLineItem.id;
|
||||||
@ -292,9 +279,8 @@ class JournalEntryLineItemEditor {
|
|||||||
this.description = originalLineItem.description === ""? null: originalLineItem.description;
|
this.description = originalLineItem.description === ""? null: originalLineItem.description;
|
||||||
this.#descriptionText.innerText = originalLineItem.description;
|
this.#descriptionText.innerText = originalLineItem.description;
|
||||||
this.#accountControl.classList.add("accounting-not-empty");
|
this.#accountControl.classList.add("accounting-not-empty");
|
||||||
this.accountCode = originalLineItem.accountCode;
|
this.account = new JournalEntryAccount(originalLineItem.accountCode, originalLineItem.accountText, false);
|
||||||
this.accountText = originalLineItem.accountText;
|
this.#accountText.innerText = this.account.text;
|
||||||
this.#accountText.innerText = originalLineItem.accountText;
|
|
||||||
this.#amountInput.value = String(originalLineItem.netBalance);
|
this.#amountInput.value = String(originalLineItem.netBalance);
|
||||||
this.#amountInput.max = String(originalLineItem.netBalance);
|
this.#amountInput.max = String(originalLineItem.netBalance);
|
||||||
this.#amountInput.min = "0";
|
this.#amountInput.min = "0";
|
||||||
@ -306,7 +292,6 @@ class JournalEntryLineItemEditor {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
clearOriginalLineItem() {
|
clearOriginalLineItem() {
|
||||||
this.isNeedOffset = false;
|
|
||||||
this.#originalLineItemContainer.classList.add("d-none");
|
this.#originalLineItemContainer.classList.add("d-none");
|
||||||
this.#originalLineItemControl.classList.remove("accounting-not-empty");
|
this.#originalLineItemControl.classList.remove("accounting-not-empty");
|
||||||
this.originalLineItemId = null;
|
this.originalLineItemId = null;
|
||||||
@ -315,8 +300,7 @@ class JournalEntryLineItemEditor {
|
|||||||
this.#originalLineItemText.innerText = "";
|
this.#originalLineItemText.innerText = "";
|
||||||
this.#setEnableDescriptionAccount(true);
|
this.#setEnableDescriptionAccount(true);
|
||||||
this.#accountControl.classList.remove("accounting-not-empty");
|
this.#accountControl.classList.remove("accounting-not-empty");
|
||||||
this.accountCode = null;
|
this.account = null;
|
||||||
this.accountText = null;
|
|
||||||
this.#accountText.innerText = "";
|
this.#accountText.innerText = "";
|
||||||
this.#amountInput.max = "";
|
this.#amountInput.max = "";
|
||||||
}
|
}
|
||||||
@ -347,10 +331,8 @@ class JournalEntryLineItemEditor {
|
|||||||
* @param isAccountNeedOffset {boolean} true if the line items in the account need offset, or false otherwise
|
* @param isAccountNeedOffset {boolean} true if the line items in the account need offset, or false otherwise
|
||||||
*/
|
*/
|
||||||
saveDescriptionWithAccount(description, accountCode, accountText, isAccountNeedOffset) {
|
saveDescriptionWithAccount(description, accountCode, accountText, isAccountNeedOffset) {
|
||||||
this.isNeedOffset = isAccountNeedOffset;
|
|
||||||
this.#accountControl.classList.add("accounting-not-empty");
|
this.#accountControl.classList.add("accounting-not-empty");
|
||||||
this.accountCode = accountCode;
|
this.account = new JournalEntryAccount(accountCode, accountText, isAccountNeedOffset);
|
||||||
this.accountText = accountText;
|
|
||||||
this.#accountText.innerText = accountText;
|
this.#accountText.innerText = accountText;
|
||||||
this.#validateAccount();
|
this.#validateAccount();
|
||||||
this.saveDescription(description)
|
this.saveDescription(description)
|
||||||
@ -361,10 +343,8 @@ class JournalEntryLineItemEditor {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
clearAccount() {
|
clearAccount() {
|
||||||
this.isNeedOffset = false;
|
|
||||||
this.#accountControl.classList.remove("accounting-not-empty");
|
this.#accountControl.classList.remove("accounting-not-empty");
|
||||||
this.accountCode = null;
|
this.account = null;
|
||||||
this.accountText = null;
|
|
||||||
this.#accountText.innerText = "";
|
this.#accountText.innerText = "";
|
||||||
this.#validateAccount();
|
this.#validateAccount();
|
||||||
}
|
}
|
||||||
@ -375,10 +355,8 @@ class JournalEntryLineItemEditor {
|
|||||||
* @param account {JournalEntryAccountOption} the selected account
|
* @param account {JournalEntryAccountOption} the selected account
|
||||||
*/
|
*/
|
||||||
saveAccount(account) {
|
saveAccount(account) {
|
||||||
this.isNeedOffset = account.isNeedOffset;
|
|
||||||
this.#accountControl.classList.add("accounting-not-empty");
|
this.#accountControl.classList.add("accounting-not-empty");
|
||||||
this.accountCode = account.code;
|
this.account = new JournalEntryAccount(account.code, account.text, account.isNeedOffset);
|
||||||
this.accountText = account.text;
|
|
||||||
this.#accountText.innerText = account.text;
|
this.#accountText.innerText = account.text;
|
||||||
this.#validateAccount();
|
this.#validateAccount();
|
||||||
}
|
}
|
||||||
@ -427,7 +405,7 @@ class JournalEntryLineItemEditor {
|
|||||||
* @return {boolean} true if valid, or false otherwise
|
* @return {boolean} true if valid, or false otherwise
|
||||||
*/
|
*/
|
||||||
#validateAccount() {
|
#validateAccount() {
|
||||||
if (this.accountCode === null) {
|
if (this.account === null) {
|
||||||
this.#accountControl.classList.add("is-invalid");
|
this.#accountControl.classList.add("is-invalid");
|
||||||
this.#accountError.innerText = A_("Please select the account.");
|
this.#accountError.innerText = A_("Please select the account.");
|
||||||
return false;
|
return false;
|
||||||
@ -486,7 +464,6 @@ class JournalEntryLineItemEditor {
|
|||||||
this.lineItem = null;
|
this.lineItem = null;
|
||||||
this.#debitCreditSubForm = debitCredit;
|
this.#debitCreditSubForm = debitCredit;
|
||||||
this.debitCredit = this.#debitCreditSubForm.debitCredit;
|
this.debitCredit = this.#debitCreditSubForm.debitCredit;
|
||||||
this.isNeedOffset = false;
|
|
||||||
this.#originalLineItemContainer.classList.add("d-none");
|
this.#originalLineItemContainer.classList.add("d-none");
|
||||||
this.#originalLineItemControl.classList.remove("accounting-not-empty");
|
this.#originalLineItemControl.classList.remove("accounting-not-empty");
|
||||||
this.#originalLineItemControl.classList.remove("is-invalid");
|
this.#originalLineItemControl.classList.remove("is-invalid");
|
||||||
@ -502,8 +479,7 @@ class JournalEntryLineItemEditor {
|
|||||||
this.#descriptionError.innerText = ""
|
this.#descriptionError.innerText = ""
|
||||||
this.#accountControl.classList.remove("accounting-not-empty");
|
this.#accountControl.classList.remove("accounting-not-empty");
|
||||||
this.#accountControl.classList.remove("is-invalid");
|
this.#accountControl.classList.remove("is-invalid");
|
||||||
this.accountCode = null;
|
this.account = null;
|
||||||
this.accountText = null;
|
|
||||||
this.#accountText.innerText = "";
|
this.#accountText.innerText = "";
|
||||||
this.#accountError.innerText = "";
|
this.#accountError.innerText = "";
|
||||||
this.#amountInput.value = "";
|
this.#amountInput.value = "";
|
||||||
@ -522,7 +498,6 @@ class JournalEntryLineItemEditor {
|
|||||||
this.lineItem = lineItem;
|
this.lineItem = lineItem;
|
||||||
this.#debitCreditSubForm = lineItem.debitCreditSubForm;
|
this.#debitCreditSubForm = lineItem.debitCreditSubForm;
|
||||||
this.debitCredit = this.#debitCreditSubForm.debitCredit;
|
this.debitCredit = this.#debitCreditSubForm.debitCredit;
|
||||||
this.isNeedOffset = lineItem.isNeedOffset;
|
|
||||||
this.originalLineItemId = lineItem.originalLineItemId;
|
this.originalLineItemId = lineItem.originalLineItemId;
|
||||||
this.originalLineItemDate = lineItem.originalLineItemDate;
|
this.originalLineItemDate = lineItem.originalLineItemDate;
|
||||||
this.originalLineItemText = lineItem.originalLineItemText;
|
this.originalLineItemText = lineItem.originalLineItemText;
|
||||||
@ -547,9 +522,8 @@ class JournalEntryLineItemEditor {
|
|||||||
} else {
|
} else {
|
||||||
this.#accountControl.classList.add("accounting-not-empty");
|
this.#accountControl.classList.add("accounting-not-empty");
|
||||||
}
|
}
|
||||||
this.accountCode = lineItem.accountCode;
|
this.account = new JournalEntryAccount(lineItem.accountCode, lineItem.accountText, lineItem.isNeedOffset);
|
||||||
this.accountText = lineItem.accountText;
|
this.#accountText.innerText = this.account.text;
|
||||||
this.#accountText.innerText = this.accountText;
|
|
||||||
this.#amountInput.value = lineItem.amount === null? "": String(lineItem.amount);
|
this.#amountInput.value = lineItem.amount === null? "": String(lineItem.amount);
|
||||||
const maxAmount = this.#getMaxAmount();
|
const maxAmount = this.#getMaxAmount();
|
||||||
this.#amountInput.max = maxAmount === null? "": maxAmount;
|
this.#amountInput.max = maxAmount === null? "": maxAmount;
|
||||||
@ -596,3 +570,41 @@ class JournalEntryLineItemEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A journal entry account.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class JournalEntryAccount {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The account code
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The account text
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the line items in the account needs offset
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
isNeedOffset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a journal entry account.
|
||||||
|
*
|
||||||
|
* @param code {string} the account code
|
||||||
|
* @param text {string} the account text
|
||||||
|
* @param isNeedOffset {boolean} true if the line items in the account needs offset, or false otherwise
|
||||||
|
*/
|
||||||
|
constructor(code, text, isNeedOffset) {
|
||||||
|
this.code = code;
|
||||||
|
this.text = text;
|
||||||
|
this.isNeedOffset = isNeedOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user