Renamed "side" to "debit-credit".
This commit is contained in:
@ -35,10 +35,10 @@ class AccountSelector {
|
||||
#lineItemEditor;
|
||||
|
||||
/**
|
||||
* The side, either "debit" or "credit"
|
||||
* Either "debit" or "credit"
|
||||
* @type {string}
|
||||
*/
|
||||
#side;
|
||||
#debitCredit;
|
||||
|
||||
/**
|
||||
* The prefix of the HTML ID and class
|
||||
@ -86,12 +86,12 @@ class AccountSelector {
|
||||
* Constructs an account selector.
|
||||
*
|
||||
* @param lineItemEditor {VoucherLineItemEditor} the line item editor
|
||||
* @param side {string} the side, either "debit" or "credit"
|
||||
* @param debitCredit {string} either "debit" or "credit"
|
||||
*/
|
||||
constructor(lineItemEditor, side) {
|
||||
constructor(lineItemEditor, debitCredit) {
|
||||
this.#lineItemEditor = lineItemEditor
|
||||
this.#side = side;
|
||||
this.#prefix = "accounting-account-selector-" + side;
|
||||
this.#debitCredit = debitCredit;
|
||||
this.#prefix = "accounting-account-selector-" + debitCredit;
|
||||
this.#query = document.getElementById(this.#prefix + "-query");
|
||||
this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result");
|
||||
this.#optionList = document.getElementById(this.#prefix + "-option-list");
|
||||
@ -143,7 +143,7 @@ class AccountSelector {
|
||||
* @return {string[]} the account codes that are used in the form
|
||||
*/
|
||||
#getCodesUsedInForm() {
|
||||
const inUse = this.#lineItemEditor.form.getAccountCodesUsed(this.#side);
|
||||
const inUse = this.#lineItemEditor.form.getAccountCodesUsed(this.#debitCredit);
|
||||
if (this.#lineItemEditor.accountCode !== null) {
|
||||
inUse.push(this.#lineItemEditor.accountCode);
|
||||
}
|
||||
@ -217,7 +217,7 @@ class AccountSelector {
|
||||
const selectors = {}
|
||||
const modals = Array.from(document.getElementsByClassName("accounting-account-selector"));
|
||||
for (const modal of modals) {
|
||||
selectors[modal.dataset.side] = new AccountSelector(lineItemEditor, modal.dataset.side);
|
||||
selectors[modal.dataset.debitCredit] = new AccountSelector(lineItemEditor, modal.dataset.debitCredit);
|
||||
}
|
||||
return selectors;
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ class DescriptionEditor {
|
||||
#modal;
|
||||
|
||||
/**
|
||||
* The side, either "debit" or "credit"
|
||||
* Either "debit" or "credit"
|
||||
* @type {string}
|
||||
*/
|
||||
side;
|
||||
debitCredit;
|
||||
|
||||
/**
|
||||
* The current tab
|
||||
@ -110,12 +110,12 @@ class DescriptionEditor {
|
||||
* Constructs a description editor.
|
||||
*
|
||||
* @param lineItemEditor {VoucherLineItemEditor} the line item editor
|
||||
* @param side {string} the side, either "debit" or "credit"
|
||||
* @param debitCredit {string} either "debit" or "credit"
|
||||
*/
|
||||
constructor(lineItemEditor, side) {
|
||||
constructor(lineItemEditor, debitCredit) {
|
||||
this.#lineItemEditor = lineItemEditor;
|
||||
this.side = side;
|
||||
this.prefix = "accounting-description-editor-" + side;
|
||||
this.debitCredit = debitCredit;
|
||||
this.prefix = "accounting-description-editor-" + debitCredit;
|
||||
this.#form = document.getElementById(this.prefix);
|
||||
this.#modal = document.getElementById(this.prefix + "-modal");
|
||||
this.description = document.getElementById(this.prefix + "-description");
|
||||
@ -253,7 +253,7 @@ class DescriptionEditor {
|
||||
const editors = {}
|
||||
const forms = Array.from(document.getElementsByClassName("accounting-description-editor"));
|
||||
for (const form of forms) {
|
||||
editors[form.dataset.side] = new DescriptionEditor(lineItemEditor, form.dataset.side);
|
||||
editors[form.dataset.debitCredit] = new DescriptionEditor(lineItemEditor, form.dataset.debitCredit);
|
||||
}
|
||||
return editors;
|
||||
}
|
||||
|
@ -77,9 +77,9 @@ class OriginalLineItemSelector {
|
||||
#currencyCode;
|
||||
|
||||
/**
|
||||
* The side, either "credit" or "debit"
|
||||
* Either "credit" or "debit"
|
||||
*/
|
||||
#side;
|
||||
#debitCredit;
|
||||
|
||||
/**
|
||||
* Constructs an original line item selector.
|
||||
@ -157,7 +157,7 @@ class OriginalLineItemSelector {
|
||||
#filterOptions() {
|
||||
let hasAnyMatched = false;
|
||||
for (const option of this.#options) {
|
||||
if (option.isMatched(this.#side, this.#currencyCode, this.#query.value)) {
|
||||
if (option.isMatched(this.#debitCredit, this.#currencyCode, this.#query.value)) {
|
||||
option.setShown(true);
|
||||
hasAnyMatched = true;
|
||||
} else {
|
||||
@ -179,7 +179,7 @@ class OriginalLineItemSelector {
|
||||
*/
|
||||
onOpen() {
|
||||
this.#currencyCode = this.lineItemEditor.getCurrencyCode();
|
||||
this.#side = this.lineItemEditor.side;
|
||||
this.#debitCredit = this.lineItemEditor.debitCredit;
|
||||
for (const option of this.#options) {
|
||||
option.setActive(option.id === this.lineItemEditor.originalLineItemId);
|
||||
}
|
||||
@ -220,10 +220,10 @@ class OriginalLineItem {
|
||||
date;
|
||||
|
||||
/**
|
||||
* The side, either "debit" or "credit"
|
||||
* Either "debit" or "credit"
|
||||
* @type {string}
|
||||
*/
|
||||
#side;
|
||||
#debitCredit;
|
||||
|
||||
/**
|
||||
* The currency code
|
||||
@ -290,7 +290,7 @@ class OriginalLineItem {
|
||||
this.#element = element;
|
||||
this.id = element.dataset.id;
|
||||
this.date = element.dataset.date;
|
||||
this.#side = element.dataset.side;
|
||||
this.#debitCredit = element.dataset.debitCredit;
|
||||
this.#currencyCode = element.dataset.currencyCode;
|
||||
this.accountCode = element.dataset.accountCode;
|
||||
this.accountText = element.dataset.accountText;
|
||||
@ -335,27 +335,27 @@ class OriginalLineItem {
|
||||
/**
|
||||
* Returns whether the original matches.
|
||||
*
|
||||
* @param side {string} the side, either "debit" or "credit"
|
||||
* @param debitCredit {string} either "debit" or "credit"
|
||||
* @param currencyCode {string} the currency code
|
||||
* @param query {string|null} the query term
|
||||
*/
|
||||
isMatched(side, currencyCode, query = null) {
|
||||
isMatched(debitCredit, currencyCode, query = null) {
|
||||
return this.netBalance.greaterThan(0)
|
||||
&& this.date <= this.#selector.lineItemEditor.form.getDate()
|
||||
&& this.#isSideMatches(side)
|
||||
&& this.#isDebitCreditMatches(debitCredit)
|
||||
&& this.#currencyCode === currencyCode
|
||||
&& this.#isQueryMatches(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the original line item matches the debit or credit side.
|
||||
* Returns whether the original line item matches the debit or credit.
|
||||
*
|
||||
* @param side {string} the side, either "debit" or credit
|
||||
* @param debitCredit {string} either "debit" or credit
|
||||
* @return {boolean} true if the option matches, or false otherwise
|
||||
*/
|
||||
#isSideMatches(side) {
|
||||
return (side === "debit" && this.#side === "credit")
|
||||
|| (side === "credit" && this.#side === "debit");
|
||||
#isDebitCreditMatches(debitCredit) {
|
||||
return (debitCredit === "debit" && this.#debitCredit === "credit")
|
||||
|| (debitCredit === "credit" && this.#debitCredit === "debit");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,13 +195,13 @@ class VoucherForm {
|
||||
/**
|
||||
* Returns all the line items in the form.
|
||||
*
|
||||
* @param side {string|null} the side, either "debit" or "credit", or null for both
|
||||
* @param debitCredit {string|null} Either "debit" or "credit", or null for both
|
||||
* @return {LineItemSubForm[]} all the line item sub-forms
|
||||
*/
|
||||
getLineItems(side = null) {
|
||||
getLineItems(debitCredit = null) {
|
||||
const lineItems = [];
|
||||
for (const currency of this.#currencies) {
|
||||
lineItems.push(...currency.getLineItems(side));
|
||||
lineItems.push(...currency.getLineItems(debitCredit));
|
||||
}
|
||||
return lineItems;
|
||||
}
|
||||
@ -209,11 +209,11 @@ class VoucherForm {
|
||||
/**
|
||||
* Returns the account codes used in the form.
|
||||
*
|
||||
* @param side {string} the side, either "debit" or "credit"
|
||||
* @param debitCredit {string} either "debit" or "credit"
|
||||
* @return {string[]} the account codes used in the form
|
||||
*/
|
||||
getAccountCodesUsed(side) {
|
||||
return this.getLineItems(side).map((lineItem) => lineItem.getAccountCode())
|
||||
getAccountCodesUsed(debitCredit) {
|
||||
return this.getLineItems(debitCredit).map((lineItem) => lineItem.getAccountCode())
|
||||
.filter((code) => code !== null);
|
||||
}
|
||||
|
||||
@ -406,14 +406,14 @@ class CurrencySubForm {
|
||||
deleteButton;
|
||||
|
||||
/**
|
||||
* The debit side
|
||||
* @type {SideSubForm|null}
|
||||
* The debit sub-form
|
||||
* @type {DebitCreditSubForm|null}
|
||||
*/
|
||||
#debit;
|
||||
|
||||
/**
|
||||
* The credit side
|
||||
* @type {SideSubForm|null}
|
||||
* The credit sub-form
|
||||
* @type {DebitCreditSubForm|null}
|
||||
*/
|
||||
#credit;
|
||||
|
||||
@ -435,9 +435,9 @@ class CurrencySubForm {
|
||||
this.#codeSelect = document.getElementById(this.#prefix + "-code-select");
|
||||
this.deleteButton = document.getElementById(this.#prefix + "-delete");
|
||||
const debitElement = document.getElementById(this.#prefix + "-debit");
|
||||
this.#debit = debitElement === null? null: new SideSubForm(this, debitElement, "debit");
|
||||
this.#debit = debitElement === null? null: new DebitCreditSubForm(this, debitElement, "debit");
|
||||
const creditElement = document.getElementById(this.#prefix + "-credit");
|
||||
this.#credit = creditElement == null? null: new SideSubForm(this, creditElement, "credit");
|
||||
this.#credit = creditElement == null? null: new DebitCreditSubForm(this, creditElement, "credit");
|
||||
this.#codeSelect.onchange = () => this.#code.value = this.#codeSelect.value;
|
||||
this.deleteButton.onclick = () => {
|
||||
this.element.parentElement.removeChild(this.element);
|
||||
@ -457,15 +457,15 @@ class CurrencySubForm {
|
||||
/**
|
||||
* Returns all the line items in the form.
|
||||
*
|
||||
* @param side {string|null} the side, either "debit" or "credit", or null for both
|
||||
* @param debitCredit {string|null} either "debit" or "credit", or null for both
|
||||
* @return {LineItemSubForm[]} all the line item sub-forms
|
||||
*/
|
||||
getLineItems(side = null) {
|
||||
getLineItems(debitCredit = null) {
|
||||
const lineItems = []
|
||||
for (const sideSubForm of [this.#debit, this.#credit]) {
|
||||
if (sideSubForm !== null ) {
|
||||
if (side === null || sideSubForm.side === side) {
|
||||
lineItems.push(...sideSubForm.lineItems);
|
||||
for (const debitCreditSubForm of [this.#debit, this.#credit]) {
|
||||
if (debitCreditSubForm !== null ) {
|
||||
if (debitCredit === null || debitCreditSubForm.debitCredit === debitCredit) {
|
||||
lineItems.push(...debitCreditSubForm.lineItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -524,10 +524,10 @@ class CurrencySubForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* The debit or credit side sub-form
|
||||
* The debit or credit sub-form
|
||||
*
|
||||
*/
|
||||
class SideSubForm {
|
||||
class DebitCreditSubForm {
|
||||
|
||||
/**
|
||||
* The currency sub-form
|
||||
@ -548,10 +548,10 @@ class SideSubForm {
|
||||
#currencyIndex;
|
||||
|
||||
/**
|
||||
* The side, either "debit" or "credit"
|
||||
* Either "debit" or "credit"
|
||||
* @type {string}
|
||||
*/
|
||||
side;
|
||||
debitCredit;
|
||||
|
||||
/**
|
||||
* The prefix of the HTML ID and class
|
||||
@ -590,18 +590,18 @@ class SideSubForm {
|
||||
#addLineItemButton;
|
||||
|
||||
/**
|
||||
* Constructs a debit or credit side sub-form
|
||||
* Constructs a debit or credit sub-form
|
||||
*
|
||||
* @param currency {CurrencySubForm} the currency sub-form
|
||||
* @param element {HTMLDivElement} the element
|
||||
* @param side {string} the side, either "debit" or "credit"
|
||||
* @param debitCredit {string} either "debit" or "credit"
|
||||
*/
|
||||
constructor(currency, element, side) {
|
||||
constructor(currency, element, debitCredit) {
|
||||
this.currency = currency;
|
||||
this.#element = element;
|
||||
this.#currencyIndex = currency.index;
|
||||
this.side = side;
|
||||
this.#prefix = "accounting-currency-" + String(this.#currencyIndex) + "-" + side;
|
||||
this.debitCredit = debitCredit;
|
||||
this.#prefix = "accounting-currency-" + String(this.#currencyIndex) + "-" + debitCredit;
|
||||
this.#error = document.getElementById(this.#prefix + "-error");
|
||||
this.#lineItemList = document.getElementById(this.#prefix + "-list");
|
||||
// noinspection JSValidateTypes
|
||||
@ -622,7 +622,7 @@ class SideSubForm {
|
||||
const newIndex = 1 + (this.lineItems.length === 0? 0: Math.max(...this.lineItems.map((lineItem) => lineItem.lineItemIndex)));
|
||||
const html = this.currency.form.lineItemTemplate
|
||||
.replaceAll("CURRENCY_INDEX", escapeHtml(String(this.#currencyIndex)))
|
||||
.replaceAll("SIDE", escapeHtml(this.side))
|
||||
.replaceAll("DEBIT_CREDIT", escapeHtml(this.debitCredit))
|
||||
.replaceAll("LINE_ITEM_INDEX", escapeHtml(String(newIndex)));
|
||||
this.#lineItemList.insertAdjacentHTML("beforeend", html);
|
||||
const lineItem = new LineItemSubForm(this, document.getElementById(this.#prefix + "-" + String(newIndex)));
|
||||
@ -742,10 +742,10 @@ class SideSubForm {
|
||||
class LineItemSubForm {
|
||||
|
||||
/**
|
||||
* The debit or credit side sub-form
|
||||
* @type {SideSubForm}
|
||||
* The debit or credit sub-form
|
||||
* @type {DebitCreditSubForm}
|
||||
*/
|
||||
sideSubForm;
|
||||
debitCreditSubForm;
|
||||
|
||||
/**
|
||||
* The element
|
||||
@ -754,10 +754,10 @@ class LineItemSubForm {
|
||||
element;
|
||||
|
||||
/**
|
||||
* The side, either "debit" or "credit"
|
||||
* Either "debit" or "credit"
|
||||
* @type {string}
|
||||
*/
|
||||
side;
|
||||
debitCredit;
|
||||
|
||||
/**
|
||||
* The line item index
|
||||
@ -858,16 +858,16 @@ class LineItemSubForm {
|
||||
/**
|
||||
* Constructs the line item sub-form.
|
||||
*
|
||||
* @param side {SideSubForm} the debit or credit side sub-form
|
||||
* @param debitCredit {DebitCreditSubForm} the debit or credit sub-form
|
||||
* @param element {HTMLLIElement} the element
|
||||
*/
|
||||
constructor(side, element) {
|
||||
this.sideSubForm = side;
|
||||
constructor(debitCredit, element) {
|
||||
this.debitCreditSubForm = debitCredit;
|
||||
this.element = element;
|
||||
this.side = element.dataset.side;
|
||||
this.debitCredit = element.dataset.debitCredit;
|
||||
this.lineItemIndex = parseInt(element.dataset.lineItemIndex);
|
||||
this.isMatched = element.classList.contains("accounting-matched-line-item");
|
||||
this.#prefix = "accounting-currency-" + element.dataset.currencyIndex + "-" + this.side + "-" + this.lineItemIndex;
|
||||
this.#prefix = "accounting-currency-" + element.dataset.currencyIndex + "-" + this.debitCredit + "-" + this.lineItemIndex;
|
||||
this.#control = document.getElementById(this.#prefix + "-control");
|
||||
this.#error = document.getElementById(this.#prefix + "-error");
|
||||
this.no = document.getElementById(this.#prefix + "-no");
|
||||
@ -881,10 +881,10 @@ class LineItemSubForm {
|
||||
this.#amount = document.getElementById(this.#prefix + "-amount");
|
||||
this.#amountText = document.getElementById(this.#prefix + "-amount-text");
|
||||
this.deleteButton = document.getElementById(this.#prefix + "-delete");
|
||||
this.#control.onclick = () => this.sideSubForm.currency.form.lineItemEditor.onEdit(this);
|
||||
this.#control.onclick = () => this.debitCreditSubForm.currency.form.lineItemEditor.onEdit(this);
|
||||
this.deleteButton.onclick = () => {
|
||||
this.element.parentElement.removeChild(this.element);
|
||||
this.sideSubForm.deleteLineItem(this);
|
||||
this.debitCreditSubForm.deleteLineItem(this);
|
||||
};
|
||||
}
|
||||
|
||||
@ -1019,9 +1019,9 @@ class LineItemSubForm {
|
||||
this.#amount.value = editor.amount;
|
||||
this.#amountText.innerText = formatDecimal(new Decimal(editor.amount));
|
||||
this.validate();
|
||||
this.sideSubForm.updateTotal();
|
||||
this.sideSubForm.currency.updateCodeSelectorStatus();
|
||||
this.sideSubForm.currency.form.updateMinDate();
|
||||
this.debitCreditSubForm.updateTotal();
|
||||
this.debitCreditSubForm.currency.updateCodeSelectorStatus();
|
||||
this.debitCreditSubForm.currency.form.updateMinDate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ class VoucherLineItemEditor {
|
||||
#modal;
|
||||
|
||||
/**
|
||||
* The side, either "debit" or "credit"
|
||||
* Either "debit" or "credit"
|
||||
* @type {string}
|
||||
*/
|
||||
side;
|
||||
debitCredit;
|
||||
|
||||
/**
|
||||
* The prefix of the HTML ID and class
|
||||
@ -143,10 +143,10 @@ class VoucherLineItemEditor {
|
||||
lineItem;
|
||||
|
||||
/**
|
||||
* The debit or credit side sub-form
|
||||
* @type {SideSubForm}
|
||||
* The debit or credit sub-form
|
||||
* @type {DebitCreditSubForm}
|
||||
*/
|
||||
#sideSubForm;
|
||||
#debitCreditSubForm;
|
||||
|
||||
/**
|
||||
* Whether the voucher line item needs offset
|
||||
@ -241,13 +241,13 @@ class VoucherLineItemEditor {
|
||||
this.originalLineItemSelector = new OriginalLineItemSelector(this);
|
||||
this.#originalLineItemControl.onclick = () => this.originalLineItemSelector.onOpen()
|
||||
this.#originalLineItemDelete.onclick = () => this.clearOriginalLineItem();
|
||||
this.#descriptionControl.onclick = () => this.#descriptionEditors[this.side].onOpen();
|
||||
this.#accountControl.onclick = () => this.#accountSelectors[this.side].onOpen();
|
||||
this.#descriptionControl.onclick = () => this.#descriptionEditors[this.debitCredit].onOpen();
|
||||
this.#accountControl.onclick = () => this.#accountSelectors[this.debitCredit].onOpen();
|
||||
this.#amountInput.onchange = () => this.#validateAmount();
|
||||
this.#element.onsubmit = () => {
|
||||
if (this.#validate()) {
|
||||
if (this.lineItem === null) {
|
||||
this.lineItem = this.#sideSubForm.addLineItem();
|
||||
this.lineItem = this.#debitCreditSubForm.addLineItem();
|
||||
}
|
||||
this.amount = this.#amountInput.value;
|
||||
this.lineItem.save(this);
|
||||
@ -314,7 +314,7 @@ class VoucherLineItemEditor {
|
||||
* @return {string} the currency code
|
||||
*/
|
||||
getCurrencyCode() {
|
||||
return this.#sideSubForm.currency.getCurrencyCode();
|
||||
return this.#debitCreditSubForm.currency.getCurrencyCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,12 +478,12 @@ class VoucherLineItemEditor {
|
||||
/**
|
||||
* The callback when adding a new voucher line item.
|
||||
*
|
||||
* @param side {SideSubForm} the debit or credit side sub-form
|
||||
* @param debitCredit {DebitCreditSubForm} the debit or credit sub-form
|
||||
*/
|
||||
onAddNew(side) {
|
||||
onAddNew(debitCredit) {
|
||||
this.lineItem = null;
|
||||
this.#sideSubForm = side;
|
||||
this.side = this.#sideSubForm.side;
|
||||
this.#debitCreditSubForm = debitCredit;
|
||||
this.debitCredit = this.#debitCreditSubForm.debitCredit;
|
||||
this.isNeedOffset = false;
|
||||
this.#originalLineItemContainer.classList.add("d-none");
|
||||
this.#originalLineItemControl.classList.remove("accounting-not-empty");
|
||||
@ -518,8 +518,8 @@ class VoucherLineItemEditor {
|
||||
*/
|
||||
onEdit(lineItem) {
|
||||
this.lineItem = lineItem;
|
||||
this.#sideSubForm = lineItem.sideSubForm;
|
||||
this.side = this.#sideSubForm.side;
|
||||
this.#debitCreditSubForm = lineItem.debitCreditSubForm;
|
||||
this.debitCredit = this.#debitCreditSubForm.debitCredit;
|
||||
this.isNeedOffset = lineItem.isNeedOffset();
|
||||
this.originalLineItemId = lineItem.getOriginalLineItemId();
|
||||
this.originalLineItemDate = lineItem.getOriginalLineItemDate();
|
||||
@ -575,11 +575,11 @@ class VoucherLineItemEditor {
|
||||
#setEnableDescriptionAccount(isEnabled) {
|
||||
if (isEnabled) {
|
||||
this.#descriptionControl.dataset.bsToggle = "modal";
|
||||
this.#descriptionControl.dataset.bsTarget = "#accounting-description-editor-" + this.#sideSubForm.side + "-modal";
|
||||
this.#descriptionControl.dataset.bsTarget = "#accounting-description-editor-" + this.#debitCreditSubForm.debitCredit + "-modal";
|
||||
this.#descriptionControl.classList.remove("accounting-disabled");
|
||||
this.#descriptionControl.classList.add("accounting-clickable");
|
||||
this.#accountControl.dataset.bsToggle = "modal";
|
||||
this.#accountControl.dataset.bsTarget = "#accounting-account-selector-" + this.#sideSubForm.side + "-modal";
|
||||
this.#accountControl.dataset.bsTarget = "#accounting-account-selector-" + this.#debitCreditSubForm.debitCredit + "-modal";
|
||||
this.#accountControl.classList.remove("accounting-disabled");
|
||||
this.#accountControl.classList.add("accounting-clickable");
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user