Renamed "summary" to "description" in the voucher line item.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/* The Mia! Accounting Flask Project
|
||||
* summary-editor.js: The JavaScript for the summary editor
|
||||
* description-editor.js: The JavaScript for the description editor
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2023 imacat.
|
||||
@ -23,10 +23,10 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* A summary editor.
|
||||
* A description editor.
|
||||
*
|
||||
*/
|
||||
class SummaryEditor {
|
||||
class DescriptionEditor {
|
||||
|
||||
/**
|
||||
* The line item editor
|
||||
@ -35,7 +35,7 @@ class SummaryEditor {
|
||||
#lineItemEditor;
|
||||
|
||||
/**
|
||||
* The summary editor form
|
||||
* The description editor form
|
||||
* @type {HTMLFormElement}
|
||||
*/
|
||||
#form;
|
||||
@ -47,7 +47,7 @@ class SummaryEditor {
|
||||
prefix;
|
||||
|
||||
/**
|
||||
* The modal of the summary editor
|
||||
* The modal of the description editor
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#modal;
|
||||
@ -65,10 +65,10 @@ class SummaryEditor {
|
||||
currentTab;
|
||||
|
||||
/**
|
||||
* The summary input
|
||||
* The description input
|
||||
* @type {HTMLInputElement}
|
||||
*/
|
||||
summary;
|
||||
description;
|
||||
|
||||
/**
|
||||
* The button to the original line item selector
|
||||
@ -107,7 +107,7 @@ class SummaryEditor {
|
||||
tabPlanes = {};
|
||||
|
||||
/**
|
||||
* Constructs a summary editor.
|
||||
* Constructs a description editor.
|
||||
*
|
||||
* @param lineItemEditor {VoucherLineItemEditor} the line item editor
|
||||
* @param side {string} the side, either "debit" or "credit"
|
||||
@ -115,10 +115,10 @@ class SummaryEditor {
|
||||
constructor(lineItemEditor, side) {
|
||||
this.#lineItemEditor = lineItemEditor;
|
||||
this.side = side;
|
||||
this.prefix = "accounting-summary-editor-" + side;
|
||||
this.prefix = "accounting-description-editor-" + side;
|
||||
this.#form = document.getElementById(this.prefix);
|
||||
this.#modal = document.getElementById(this.prefix + "-modal");
|
||||
this.summary = document.getElementById(this.prefix + "-summary");
|
||||
this.description = document.getElementById(this.prefix + "-description");
|
||||
this.#offsetButton = document.getElementById(this.prefix + "-offset");
|
||||
this.number = document.getElementById(this.prefix + "-annotation-number");
|
||||
this.note = document.getElementById(this.prefix + "-annotation-note");
|
||||
@ -131,7 +131,7 @@ class SummaryEditor {
|
||||
}
|
||||
this.currentTab = this.tabPlanes.general;
|
||||
this.#initializeSuggestedAccounts();
|
||||
this.summary.onchange = () => this.#onSummaryChange();
|
||||
this.description.onchange = () => this.#onDescriptionChange();
|
||||
this.#offsetButton.onclick = () => this.#lineItemEditor.originalLineItemSelector.onOpen();
|
||||
this.#form.onsubmit = () => {
|
||||
if (this.currentTab.validate()) {
|
||||
@ -142,11 +142,11 @@ class SummaryEditor {
|
||||
}
|
||||
|
||||
/**
|
||||
* The callback when the summary input is changed.
|
||||
* The callback when the description input is changed.
|
||||
*
|
||||
*/
|
||||
#onSummaryChange() {
|
||||
this.summary.value = this.summary.value.trim();
|
||||
#onDescriptionChange() {
|
||||
this.description.value = this.description.value.trim();
|
||||
for (const tabPlane of [this.tabPlanes.bus, this.tabPlanes.travel, this.tabPlanes.general]) {
|
||||
if (tabPlane.populate()) {
|
||||
break;
|
||||
@ -209,34 +209,34 @@ class SummaryEditor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the summary.
|
||||
* Submits the description.
|
||||
*
|
||||
*/
|
||||
#submit() {
|
||||
bootstrap.Modal.getOrCreateInstance(this.#modal).hide();
|
||||
if (this.#selectedAccount !== null) {
|
||||
this.#lineItemEditor.saveSummaryWithAccount(this.summary.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text, this.#selectedAccount.classList.contains("accounting-account-is-need-offset"));
|
||||
this.#lineItemEditor.saveDescriptionWithAccount(this.description.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text, this.#selectedAccount.classList.contains("accounting-account-is-need-offset"));
|
||||
} else {
|
||||
this.#lineItemEditor.saveSummary(this.summary.value);
|
||||
this.#lineItemEditor.saveDescription(this.description.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The callback when the summary editor is shown.
|
||||
* The callback when the description editor is shown.
|
||||
*
|
||||
*/
|
||||
onOpen() {
|
||||
this.#reset();
|
||||
this.summary.value = this.#lineItemEditor.summary === null? "": this.#lineItemEditor.summary;
|
||||
this.#onSummaryChange();
|
||||
this.description.value = this.#lineItemEditor.description === null? "": this.#lineItemEditor.description;
|
||||
this.#onDescriptionChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the summary editor.
|
||||
* Resets the description editor.
|
||||
*
|
||||
*/
|
||||
#reset() {
|
||||
this.summary.value = "";
|
||||
this.description.value = "";
|
||||
for (const tabPlane of Object.values(this.tabPlanes)) {
|
||||
tabPlane.reset();
|
||||
}
|
||||
@ -244,16 +244,16 @@ class SummaryEditor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary editor instances.
|
||||
* Returns the description editor instances.
|
||||
*
|
||||
* @param lineItemEditor {VoucherLineItemEditor} the line item editor
|
||||
* @return {{debit: SummaryEditor, credit: SummaryEditor}}
|
||||
* @return {{debit: DescriptionEditor, credit: DescriptionEditor}}
|
||||
*/
|
||||
static getInstances(lineItemEditor) {
|
||||
const editors = {}
|
||||
const forms = Array.from(document.getElementsByClassName("accounting-summary-editor"));
|
||||
const forms = Array.from(document.getElementsByClassName("accounting-description-editor"));
|
||||
for (const form of forms) {
|
||||
editors[form.dataset.side] = new SummaryEditor(lineItemEditor, form.dataset.side);
|
||||
editors[form.dataset.side] = new DescriptionEditor(lineItemEditor, form.dataset.side);
|
||||
}
|
||||
return editors;
|
||||
}
|
||||
@ -268,8 +268,8 @@ class SummaryEditor {
|
||||
class TabPlane {
|
||||
|
||||
/**
|
||||
* The parent summary editor
|
||||
* @type {SummaryEditor}
|
||||
* The parent description editor
|
||||
* @type {DescriptionEditor}
|
||||
*/
|
||||
editor;
|
||||
|
||||
@ -294,7 +294,7 @@ class TabPlane {
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param editor {SummaryEditor} the parent summary editor
|
||||
* @param editor {DescriptionEditor} the parent description editor
|
||||
*/
|
||||
constructor(editor) {
|
||||
this.editor = editor;
|
||||
@ -320,9 +320,9 @@ class TabPlane {
|
||||
reset() { throw new Error("Method not implemented."); }
|
||||
|
||||
/**
|
||||
* Populates the tab plane with the summary input.
|
||||
* Populates the tab plane with the description input.
|
||||
*
|
||||
* @return {boolean} true if the summary input matches this tab, or false otherwise
|
||||
* @return {boolean} true if the description input matches this tab, or false otherwise
|
||||
* @abstract
|
||||
*/
|
||||
populate() { throw new Error("Method not implemented."); }
|
||||
@ -383,7 +383,7 @@ class TagTabPlane extends TabPlane {
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param editor {SummaryEditor} the parent summary editor
|
||||
* @param editor {DescriptionEditor} the parent description editor
|
||||
* @override
|
||||
*/
|
||||
constructor(editor) {
|
||||
@ -395,7 +395,7 @@ class TagTabPlane extends TabPlane {
|
||||
this.initializeTagButtons();
|
||||
this.tag.onchange = () => {
|
||||
this.onTagChange();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
};
|
||||
}
|
||||
|
||||
@ -424,11 +424,11 @@ class TagTabPlane extends TabPlane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the summary according to the input in the tab plane.
|
||||
* Updates the description according to the input in the tab plane.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
updateSummary() { throw new Error("Method not implemented."); }
|
||||
updateDescription() { throw new Error("Method not implemented."); }
|
||||
|
||||
/**
|
||||
* Switches to the tab plane.
|
||||
@ -461,7 +461,7 @@ class TagTabPlane extends TabPlane {
|
||||
tagButton.classList.add("btn-primary");
|
||||
this.tag.value = tagButton.dataset.value;
|
||||
this.editor.filterSuggestedAccounts(tagButton);
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -532,28 +532,28 @@ class GeneralTagTab extends TagTabPlane {
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the summary according to the input in the tab plane.
|
||||
* Updates the description according to the input in the tab plane.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
updateSummary() {
|
||||
const pos = this.editor.summary.value.indexOf("—");
|
||||
updateDescription() {
|
||||
const pos = this.editor.description.value.indexOf("—");
|
||||
const prefix = this.tag.value === ""? "": this.tag.value + "—";
|
||||
if (pos === -1) {
|
||||
this.editor.summary.value = prefix + this.editor.summary.value;
|
||||
this.editor.description.value = prefix + this.editor.description.value;
|
||||
} else {
|
||||
this.editor.summary.value = prefix + this.editor.summary.value.substring(pos + 1);
|
||||
this.editor.description.value = prefix + this.editor.description.value.substring(pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the tab plane with the summary input.
|
||||
* Populates the tab plane with the description input.
|
||||
*
|
||||
* @return {boolean} true if the summary input matches this tab, or false otherwise
|
||||
* @return {boolean} true if the description input matches this tab, or false otherwise
|
||||
* @override
|
||||
*/
|
||||
populate() {
|
||||
const found = this.editor.summary.value.match(/^([^—]+)—/);
|
||||
const found = this.editor.description.value.match(/^([^—]+)—/);
|
||||
if (found === null) {
|
||||
return false;
|
||||
}
|
||||
@ -622,7 +622,7 @@ class GeneralTripTab extends TagTabPlane {
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param editor {SummaryEditor} the parent summary editor
|
||||
* @param editor {DescriptionEditor} the parent description editor
|
||||
* @override
|
||||
*/
|
||||
constructor(editor) {
|
||||
@ -635,7 +635,7 @@ class GeneralTripTab extends TagTabPlane {
|
||||
this.#directionButtons = Array.from(document.getElementsByClassName(this.prefix + "-direction"));
|
||||
this.#from.onchange = () => {
|
||||
this.#from.value = this.#from.value.trim();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
this.validateFrom();
|
||||
};
|
||||
for (const directionButton of this.#directionButtons) {
|
||||
@ -646,12 +646,12 @@ class GeneralTripTab extends TagTabPlane {
|
||||
}
|
||||
directionButton.classList.remove("btn-outline-primary");
|
||||
directionButton.classList.add("btn-primary");
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
};
|
||||
}
|
||||
this.#to.onchange = () => {
|
||||
this.#to.value = this.#to.value.trim();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
this.validateTo();
|
||||
};
|
||||
}
|
||||
@ -667,11 +667,11 @@ class GeneralTripTab extends TagTabPlane {
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the summary according to the input in the tab plane.
|
||||
* Updates the description according to the input in the tab plane.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
updateSummary() {
|
||||
updateDescription() {
|
||||
let direction;
|
||||
for (const directionButton of this.#directionButtons) {
|
||||
if (directionButton.classList.contains("btn-primary")) {
|
||||
@ -679,7 +679,7 @@ class GeneralTripTab extends TagTabPlane {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.editor.summary.value = this.tag.value + "—" + this.#from.value + direction + this.#to.value;
|
||||
this.editor.description.value = this.tag.value + "—" + this.#from.value + direction + this.#to.value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -707,13 +707,13 @@ class GeneralTripTab extends TagTabPlane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the tab plane with the summary input.
|
||||
* Populates the tab plane with the description input.
|
||||
*
|
||||
* @return {boolean} true if the summary input matches this tab, or false otherwise
|
||||
* @return {boolean} true if the description input matches this tab, or false otherwise
|
||||
* @override
|
||||
*/
|
||||
populate() {
|
||||
const found = this.editor.summary.value.match(/^([^—]+)—([^—→↔]+)([→↔])(.+?)(?:[*×]\d+)?(?:\([^()]+\))?$/);
|
||||
const found = this.editor.description.value.match(/^([^—]+)—([^—→↔]+)([→↔])(.+?)(?:[*×]\d+)?(?:\([^()]+\))?$/);
|
||||
if (found === null) {
|
||||
return false;
|
||||
}
|
||||
@ -834,7 +834,7 @@ class BusTripTab extends TagTabPlane {
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param editor {SummaryEditor} the parent summary editor
|
||||
* @param editor {DescriptionEditor} the parent description editor
|
||||
* @override
|
||||
*/
|
||||
constructor(editor) {
|
||||
@ -847,17 +847,17 @@ class BusTripTab extends TagTabPlane {
|
||||
this.#toError = document.getElementById(this.prefix + "-to-error")
|
||||
this.#route.onchange = () => {
|
||||
this.#route.value = this.#route.value.trim();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
this.validateRoute();
|
||||
};
|
||||
this.#from.onchange = () => {
|
||||
this.#from.value = this.#from.value.trim();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
this.validateFrom();
|
||||
};
|
||||
this.#to.onchange = () => {
|
||||
this.#to.value = this.#to.value.trim();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
this.validateTo();
|
||||
};
|
||||
}
|
||||
@ -873,12 +873,12 @@ class BusTripTab extends TagTabPlane {
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the summary according to the input in the tab plane.
|
||||
* Updates the description according to the input in the tab plane.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
updateSummary() {
|
||||
this.editor.summary.value = this.tag.value + "—" + this.#route.value + "—" + this.#from.value + "→" + this.#to.value;
|
||||
updateDescription() {
|
||||
this.editor.description.value = this.tag.value + "—" + this.#route.value + "—" + this.#from.value + "→" + this.#to.value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -900,13 +900,13 @@ class BusTripTab extends TagTabPlane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the tab plane with the summary input.
|
||||
* Populates the tab plane with the description input.
|
||||
*
|
||||
* @return {boolean} true if the summary input matches this tab, or false otherwise
|
||||
* @return {boolean} true if the description input matches this tab, or false otherwise
|
||||
* @override
|
||||
*/
|
||||
populate() {
|
||||
const found = this.editor.summary.value.match(/^([^—]+)—([^—]+)—([^—→]+)→(.+?)(?:[*×]\d+)?(?:\([^()]+\))?$/);
|
||||
const found = this.editor.description.value.match(/^([^—]+)—([^—]+)—([^—→]+)→(.+?)(?:[*×]\d+)?(?:\([^()]+\))?$/);
|
||||
if (found === null) {
|
||||
return false;
|
||||
}
|
||||
@ -1001,7 +1001,7 @@ class RegularPaymentTab extends TabPlane {
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param editor {SummaryEditor} the parent summary editor
|
||||
* @param editor {DescriptionEditor} the parent description editor
|
||||
* @override
|
||||
*/
|
||||
constructor(editor) {
|
||||
@ -1033,9 +1033,9 @@ class RegularPaymentTab extends TabPlane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the tab plane with the summary input.
|
||||
* Populates the tab plane with the description input.
|
||||
*
|
||||
* @return {boolean} true if the summary input matches this tab, or false otherwise
|
||||
* @return {boolean} true if the description input matches this tab, or false otherwise
|
||||
* @override
|
||||
*/
|
||||
populate() {
|
||||
@ -1063,15 +1063,15 @@ class AnnotationTab extends TabPlane {
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param editor {SummaryEditor} the parent summary editor
|
||||
* @param editor {DescriptionEditor} the parent description editor
|
||||
* @override
|
||||
*/
|
||||
constructor(editor) {
|
||||
super(editor);
|
||||
this.editor.number.onchange = () => this.updateSummary();
|
||||
this.editor.number.onchange = () => this.updateDescription();
|
||||
this.editor.note.onchange = () => {
|
||||
this.editor.note.value = this.editor.note.value.trim();
|
||||
this.updateSummary();
|
||||
this.updateDescription();
|
||||
};
|
||||
}
|
||||
|
||||
@ -1086,20 +1086,20 @@ class AnnotationTab extends TabPlane {
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the summary according to the input in the tab plane.
|
||||
* Updates the description according to the input in the tab plane.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
updateSummary() {
|
||||
const found = this.editor.summary.value.match(/^(.*?)(?:[*×]\d+)?(?:\([^()]+\))?$/);
|
||||
updateDescription() {
|
||||
const found = this.editor.description.value.match(/^(.*?)(?:[*×]\d+)?(?:\([^()]+\))?$/);
|
||||
if (found !== null) {
|
||||
this.editor.summary.value = found[1];
|
||||
this.editor.description.value = found[1];
|
||||
}
|
||||
if (parseInt(this.editor.number.value) > 1) {
|
||||
this.editor.summary.value = this.editor.summary.value + "×" + this.editor.number.value;
|
||||
this.editor.description.value = this.editor.description.value + "×" + this.editor.number.value;
|
||||
}
|
||||
if (this.editor.note.value !== "") {
|
||||
this.editor.summary.value = this.editor.summary.value + "(" + this.editor.note.value + ")";
|
||||
this.editor.description.value = this.editor.description.value + "(" + this.editor.note.value + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1114,25 +1114,25 @@ class AnnotationTab extends TabPlane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the tab plane with the summary input.
|
||||
* Populates the tab plane with the description input.
|
||||
*
|
||||
* @return {boolean} true if the summary input matches this tab, or false otherwise
|
||||
* @return {boolean} true if the description input matches this tab, or false otherwise
|
||||
* @override
|
||||
*/
|
||||
populate() {
|
||||
const found = this.editor.summary.value.match(/^(.*?)(?:[*×](\d+))?(?:\(([^()]+)\))?$/);
|
||||
this.editor.summary.value = found[1];
|
||||
const found = this.editor.description.value.match(/^(.*?)(?:[*×](\d+))?(?:\(([^()]+)\))?$/);
|
||||
this.editor.description.value = found[1];
|
||||
if (found[2] === undefined || parseInt(found[2]) === 1) {
|
||||
this.editor.number.value = "";
|
||||
} else {
|
||||
this.editor.number.value = found[2];
|
||||
this.editor.summary.value = this.editor.summary.value + "×" + this.editor.number.value;
|
||||
this.editor.description.value = this.editor.description.value + "×" + this.editor.number.value;
|
||||
}
|
||||
if (found[3] === undefined) {
|
||||
this.editor.note.value = "";
|
||||
} else {
|
||||
this.editor.note.value = found[3];
|
||||
this.editor.summary.value = this.editor.summary.value + "(" + this.editor.note.value + ")";
|
||||
this.editor.description.value = this.editor.description.value + "(" + this.editor.note.value + ")";
|
||||
}
|
||||
return true;
|
||||
}
|
@ -244,10 +244,10 @@ class OriginalLineItem {
|
||||
accountText;
|
||||
|
||||
/**
|
||||
* The summary
|
||||
* The description
|
||||
* @type {string}
|
||||
*/
|
||||
summary;
|
||||
description;
|
||||
|
||||
/**
|
||||
* The net balance, without the offset amounts on the form
|
||||
@ -294,7 +294,7 @@ class OriginalLineItem {
|
||||
this.#currencyCode = element.dataset.currencyCode;
|
||||
this.accountCode = element.dataset.accountCode;
|
||||
this.accountText = element.dataset.accountText;
|
||||
this.summary = element.dataset.summary;
|
||||
this.description = element.dataset.description;
|
||||
this.bareNetBalance = new Decimal(element.dataset.netBalance);
|
||||
this.netBalance = this.bareNetBalance;
|
||||
this.netBalanceText = document.getElementById("accounting-original-line-item-selector-option-" + this.id + "-net-balance");
|
||||
|
@ -808,16 +808,16 @@ class LineItemSubForm {
|
||||
#accountText;
|
||||
|
||||
/**
|
||||
* The summary
|
||||
* The description
|
||||
* @type {HTMLInputElement}
|
||||
*/
|
||||
#summary;
|
||||
#description;
|
||||
|
||||
/**
|
||||
* The text display of the summary
|
||||
* The text display of the description
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#summaryText;
|
||||
#descriptionText;
|
||||
|
||||
/**
|
||||
* The ID of the original line item
|
||||
@ -873,8 +873,8 @@ class LineItemSubForm {
|
||||
this.no = document.getElementById(this.#prefix + "-no");
|
||||
this.#accountCode = document.getElementById(this.#prefix + "-account-code");
|
||||
this.#accountText = document.getElementById(this.#prefix + "-account-text");
|
||||
this.#summary = document.getElementById(this.#prefix + "-summary");
|
||||
this.#summaryText = document.getElementById(this.#prefix + "-summary-text");
|
||||
this.#description = document.getElementById(this.#prefix + "-description");
|
||||
this.#descriptionText = document.getElementById(this.#prefix + "-description-text");
|
||||
this.#originalLineItemId = document.getElementById(this.#prefix + "-original-line-item-id");
|
||||
this.#originalLineItemText = document.getElementById(this.#prefix + "-original-line-item-text");
|
||||
this.#offsets = document.getElementById(this.#prefix + "-offsets");
|
||||
@ -925,12 +925,12 @@ class LineItemSubForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary.
|
||||
* Returns the description.
|
||||
*
|
||||
* @return {string|null} the summary
|
||||
* @return {string|null} the description
|
||||
*/
|
||||
getSummary() {
|
||||
return this.#summary.value === ""? null: this.#summary.value;
|
||||
getDescription() {
|
||||
return this.#description.value === ""? null: this.#description.value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1014,8 +1014,8 @@ class LineItemSubForm {
|
||||
this.#accountCode.value = editor.accountCode === null? "": editor.accountCode;
|
||||
this.#accountCode.dataset.text = editor.accountText === null? "": editor.accountText;
|
||||
this.#accountText.innerText = editor.accountText === null? "": editor.accountText;
|
||||
this.#summary.value = editor.summary === null? "": editor.summary;
|
||||
this.#summaryText.innerText = editor.summary === null? "": editor.summary;
|
||||
this.#description.value = editor.description === null? "": editor.description;
|
||||
this.#descriptionText.innerText = editor.description === null? "": editor.description;
|
||||
this.#amount.value = editor.amount;
|
||||
this.#amountText.innerText = formatDecimal(new Decimal(editor.amount));
|
||||
this.validate();
|
||||
|
@ -89,22 +89,22 @@ class VoucherLineItemEditor {
|
||||
#originalLineItemDelete;
|
||||
|
||||
/**
|
||||
* The control of the summary
|
||||
* The control of the description
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#summaryControl;
|
||||
#descriptionControl;
|
||||
|
||||
/**
|
||||
* The summary
|
||||
* The description
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#summaryText;
|
||||
#descriptionText;
|
||||
|
||||
/**
|
||||
* The error message of the summary
|
||||
* The error message of the description
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#summaryError;
|
||||
#descriptionError;
|
||||
|
||||
/**
|
||||
* The control of the account
|
||||
@ -185,10 +185,10 @@ class VoucherLineItemEditor {
|
||||
accountText = null;
|
||||
|
||||
/**
|
||||
* The summary
|
||||
* The description
|
||||
* @type {string|null}
|
||||
*/
|
||||
summary = null;
|
||||
description = null;
|
||||
|
||||
/**
|
||||
* The amount
|
||||
@ -197,10 +197,10 @@ class VoucherLineItemEditor {
|
||||
amount = "";
|
||||
|
||||
/**
|
||||
* The summary editors
|
||||
* @type {{debit: SummaryEditor, credit: SummaryEditor}}
|
||||
* The description editors
|
||||
* @type {{debit: DescriptionEditor, credit: DescriptionEditor}}
|
||||
*/
|
||||
#summaryEditors;
|
||||
#descriptionEditors;
|
||||
|
||||
/**
|
||||
* The account selectors
|
||||
@ -228,20 +228,20 @@ class VoucherLineItemEditor {
|
||||
this.#originalLineItemText = document.getElementById(this.#prefix + "-original-line-item");
|
||||
this.#originalLineItemError = document.getElementById(this.#prefix + "-original-line-item-error");
|
||||
this.#originalLineItemDelete = document.getElementById(this.#prefix + "-original-line-item-delete");
|
||||
this.#summaryControl = document.getElementById(this.#prefix + "-summary-control");
|
||||
this.#summaryText = document.getElementById(this.#prefix + "-summary");
|
||||
this.#summaryError = document.getElementById(this.#prefix + "-summary-error");
|
||||
this.#descriptionControl = document.getElementById(this.#prefix + "-description-control");
|
||||
this.#descriptionText = document.getElementById(this.#prefix + "-description");
|
||||
this.#descriptionError = document.getElementById(this.#prefix + "-description-error");
|
||||
this.#accountControl = document.getElementById(this.#prefix + "-account-control");
|
||||
this.#accountText = document.getElementById(this.#prefix + "-account");
|
||||
this.#accountError = document.getElementById(this.#prefix + "-account-error")
|
||||
this.#amountInput = document.getElementById(this.#prefix + "-amount");
|
||||
this.#amountError = document.getElementById(this.#prefix + "-amount-error");
|
||||
this.#summaryEditors = SummaryEditor.getInstances(this);
|
||||
this.#descriptionEditors = DescriptionEditor.getInstances(this);
|
||||
this.#accountSelectors = AccountSelector.getInstances(this);
|
||||
this.originalLineItemSelector = new OriginalLineItemSelector(this);
|
||||
this.#originalLineItemControl.onclick = () => this.originalLineItemSelector.onOpen()
|
||||
this.#originalLineItemDelete.onclick = () => this.clearOriginalLineItem();
|
||||
this.#summaryControl.onclick = () => this.#summaryEditors[this.side].onOpen();
|
||||
this.#descriptionControl.onclick = () => this.#descriptionEditors[this.side].onOpen();
|
||||
this.#accountControl.onclick = () => this.#accountSelectors[this.side].onOpen();
|
||||
this.#amountInput.onchange = () => this.#validateAmount();
|
||||
this.#element.onsubmit = () => {
|
||||
@ -270,14 +270,14 @@ class VoucherLineItemEditor {
|
||||
this.originalLineItemDate = originalLineItem.date;
|
||||
this.originalLineItemText = originalLineItem.text;
|
||||
this.#originalLineItemText.innerText = originalLineItem.text;
|
||||
this.#setEnableSummaryAccount(false);
|
||||
if (originalLineItem.summary === "") {
|
||||
this.#summaryControl.classList.remove("accounting-not-empty");
|
||||
this.#setEnableDescriptionAccount(false);
|
||||
if (originalLineItem.description === "") {
|
||||
this.#descriptionControl.classList.remove("accounting-not-empty");
|
||||
} else {
|
||||
this.#summaryControl.classList.add("accounting-not-empty");
|
||||
this.#descriptionControl.classList.add("accounting-not-empty");
|
||||
}
|
||||
this.summary = originalLineItem.summary === ""? null: originalLineItem.summary;
|
||||
this.#summaryText.innerText = originalLineItem.summary;
|
||||
this.description = originalLineItem.description === ""? null: originalLineItem.description;
|
||||
this.#descriptionText.innerText = originalLineItem.description;
|
||||
this.#accountControl.classList.add("accounting-not-empty");
|
||||
this.accountCode = originalLineItem.accountCode;
|
||||
this.accountText = originalLineItem.accountText;
|
||||
@ -300,7 +300,7 @@ class VoucherLineItemEditor {
|
||||
this.originalLineItemDate = null;
|
||||
this.originalLineItemText = null;
|
||||
this.#originalLineItemText.innerText = "";
|
||||
this.#setEnableSummaryAccount(true);
|
||||
this.#setEnableDescriptionAccount(true);
|
||||
this.#accountControl.classList.remove("accounting-not-empty");
|
||||
this.accountCode = null;
|
||||
this.accountText = null;
|
||||
@ -318,38 +318,38 @@ class VoucherLineItemEditor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the summary from the summary editor.
|
||||
* Saves the description from the description editor.
|
||||
*
|
||||
* @param summary {string} the summary
|
||||
* @param description {string} the description
|
||||
*/
|
||||
saveSummary(summary) {
|
||||
if (summary === "") {
|
||||
this.#summaryControl.classList.remove("accounting-not-empty");
|
||||
saveDescription(description) {
|
||||
if (description === "") {
|
||||
this.#descriptionControl.classList.remove("accounting-not-empty");
|
||||
} else {
|
||||
this.#summaryControl.classList.add("accounting-not-empty");
|
||||
this.#descriptionControl.classList.add("accounting-not-empty");
|
||||
}
|
||||
this.summary = summary === ""? null: summary;
|
||||
this.#summaryText.innerText = summary;
|
||||
this.#validateSummary();
|
||||
this.description = description === ""? null: description;
|
||||
this.#descriptionText.innerText = description;
|
||||
this.#validateDescription();
|
||||
bootstrap.Modal.getOrCreateInstance(this.#modal).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the summary with the suggested account from the summary editor.
|
||||
* Saves the description with the suggested account from the description editor.
|
||||
*
|
||||
* @param summary {string} the summary
|
||||
* @param description {string} the description
|
||||
* @param accountCode {string} the account code
|
||||
* @param accountText {string} the account text
|
||||
* @param isAccountNeedOffset {boolean} true if the line items in the account need offset, or false otherwise
|
||||
*/
|
||||
saveSummaryWithAccount(summary, accountCode, accountText, isAccountNeedOffset) {
|
||||
saveDescriptionWithAccount(description, accountCode, accountText, isAccountNeedOffset) {
|
||||
this.isNeedOffset = isAccountNeedOffset;
|
||||
this.#accountControl.classList.add("accounting-not-empty");
|
||||
this.accountCode = accountCode;
|
||||
this.accountText = accountText;
|
||||
this.#accountText.innerText = accountText;
|
||||
this.#validateAccount();
|
||||
this.saveSummary(summary)
|
||||
this.saveDescription(description)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -389,7 +389,7 @@ class VoucherLineItemEditor {
|
||||
#validate() {
|
||||
let isValid = true;
|
||||
isValid = this.#validateOriginalLineItem() && isValid;
|
||||
isValid = this.#validateSummary() && isValid;
|
||||
isValid = this.#validateDescription() && isValid;
|
||||
isValid = this.#validateAccount() && isValid;
|
||||
isValid = this.#validateAmount() && isValid
|
||||
return isValid;
|
||||
@ -408,14 +408,14 @@ class VoucherLineItemEditor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the summary.
|
||||
* Validates the description.
|
||||
*
|
||||
* @return {boolean} true if valid, or false otherwise
|
||||
* @private
|
||||
*/
|
||||
#validateSummary() {
|
||||
this.#summaryText.classList.remove("is-invalid");
|
||||
this.#summaryError.innerText = "";
|
||||
#validateDescription() {
|
||||
this.#descriptionText.classList.remove("is-invalid");
|
||||
this.#descriptionError.innerText = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -492,12 +492,12 @@ class VoucherLineItemEditor {
|
||||
this.originalLineItemDate = null;
|
||||
this.originalLineItemText = null;
|
||||
this.#originalLineItemText.innerText = "";
|
||||
this.#setEnableSummaryAccount(true);
|
||||
this.#summaryControl.classList.remove("accounting-not-empty");
|
||||
this.#summaryControl.classList.remove("is-invalid");
|
||||
this.summary = null;
|
||||
this.#summaryText.innerText = ""
|
||||
this.#summaryError.innerText = ""
|
||||
this.#setEnableDescriptionAccount(true);
|
||||
this.#descriptionControl.classList.remove("accounting-not-empty");
|
||||
this.#descriptionControl.classList.remove("is-invalid");
|
||||
this.description = null;
|
||||
this.#descriptionText.innerText = ""
|
||||
this.#descriptionError.innerText = ""
|
||||
this.#accountControl.classList.remove("accounting-not-empty");
|
||||
this.#accountControl.classList.remove("is-invalid");
|
||||
this.accountCode = null;
|
||||
@ -532,14 +532,14 @@ class VoucherLineItemEditor {
|
||||
this.#originalLineItemContainer.classList.remove("d-none");
|
||||
this.#originalLineItemControl.classList.add("accounting-not-empty");
|
||||
}
|
||||
this.#setEnableSummaryAccount(!lineItem.isMatched && this.originalLineItemId === null);
|
||||
this.summary = lineItem.getSummary();
|
||||
if (this.summary === null) {
|
||||
this.#summaryControl.classList.remove("accounting-not-empty");
|
||||
this.#setEnableDescriptionAccount(!lineItem.isMatched && this.originalLineItemId === null);
|
||||
this.description = lineItem.getDescription();
|
||||
if (this.description === null) {
|
||||
this.#descriptionControl.classList.remove("accounting-not-empty");
|
||||
} else {
|
||||
this.#summaryControl.classList.add("accounting-not-empty");
|
||||
this.#descriptionControl.classList.add("accounting-not-empty");
|
||||
}
|
||||
this.#summaryText.innerText = this.summary === null? "": this.summary;
|
||||
this.#descriptionText.innerText = this.description === null? "": this.description;
|
||||
if (lineItem.getAccountCode() === null) {
|
||||
this.#accountControl.classList.remove("accounting-not-empty");
|
||||
} else {
|
||||
@ -568,25 +568,25 @@ class VoucherLineItemEditor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enable status of the summary and account.
|
||||
* Sets the enable status of the description and account.
|
||||
*
|
||||
* @param isEnabled {boolean} true to enable, or false otherwise
|
||||
*/
|
||||
#setEnableSummaryAccount(isEnabled) {
|
||||
#setEnableDescriptionAccount(isEnabled) {
|
||||
if (isEnabled) {
|
||||
this.#summaryControl.dataset.bsToggle = "modal";
|
||||
this.#summaryControl.dataset.bsTarget = "#accounting-summary-editor-" + this.#sideSubForm.side + "-modal";
|
||||
this.#summaryControl.classList.remove("accounting-disabled");
|
||||
this.#summaryControl.classList.add("accounting-clickable");
|
||||
this.#descriptionControl.dataset.bsToggle = "modal";
|
||||
this.#descriptionControl.dataset.bsTarget = "#accounting-description-editor-" + this.#sideSubForm.side + "-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.classList.remove("accounting-disabled");
|
||||
this.#accountControl.classList.add("accounting-clickable");
|
||||
} else {
|
||||
this.#summaryControl.dataset.bsToggle = "";
|
||||
this.#summaryControl.dataset.bsTarget = "";
|
||||
this.#summaryControl.classList.add("accounting-disabled");
|
||||
this.#summaryControl.classList.remove("accounting-clickable");
|
||||
this.#descriptionControl.dataset.bsToggle = "";
|
||||
this.#descriptionControl.dataset.bsTarget = "";
|
||||
this.#descriptionControl.classList.add("accounting-disabled");
|
||||
this.#descriptionControl.classList.remove("accounting-clickable");
|
||||
this.#accountControl.dataset.bsToggle = "";
|
||||
this.#accountControl.dataset.bsTarget = "";
|
||||
this.#accountControl.classList.add("accounting-disabled");
|
||||
|
Reference in New Issue
Block a user