Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Unify some methods, fix piggy view.
James Cole2525b0694d3d
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.jsindex 853d9d689b..52d356d9a3 100644--- a/resources/assets/v3/js/pages/transactions/create.js+++ b/resources/assets/v3/js/pages/transactions/create.js@@ -35,8 +35,11 @@ import {loadSubscriptions} from "./shared/load-subscriptions.js";import {addAllAutocompleteToForm, getUrls} from "./shared/add-autocomplete.js";import {processAttachments} from "./shared/process-attachments.js";import {spliceErrorsIntoTransactions} from "./shared/splice-errors-into-transactions.js";+import {disableSplitAccounts} from './shared/disable-split-accounts.js';+import {parseTotalAmount} from "./shared/parse-total-amount.js";// import {addLocation} from "./shared/manage-locations.js";import i18next from "i18next";+import {processUploadError} from "./shared/process-upload-error.js";// TODO fix tags// TODO upload attachments to other file// TODO fix two maps, perhaps disconnect from entries entirely.@@ -48,9 +51,20 @@ const urls = getUrls();let create = function () {return {+ // needed for translations.+ i18next: null,+// transactions are stored in "entries":entries: [],- i18next: null,++ // properties for the entire transaction group+ groupProperties: {+ transactionType: 'unknown',+ titleErrors: [],+ title: null,+ id: null,+ totalAmount: 0,+ },// state of the form is stored in formState:formStates: {@@ -67,7 +81,7 @@ let create = function () {categorySelectVisible: false},- // form behavior during transaction+ // form behavior during transaction, for shared components.formBehaviour: {formType: 'create',foreignCurrencyEnabled: true,@@ -79,21 +93,14 @@ let create = function () {// defaultCurrency: null,amountCurrency: null, // this is the currency of the amount fieldenabledCurrencies: [],- primaryCurrencies: [],- foreignCurrencies: [],+ primaryCurrencies: [], // TODO this list is not being used.+ foreignCurrencies: [], // this is the select list for foreign currencies.budgets: [],piggyBanks: [],subscriptions: [],},- // properties for the entire transaction group- groupProperties: {- transactionType: 'unknown',- titleErrors: [],- title: null,- id: null,- totalAmount: 0,- },+// notificationsnotifications: {@@ -103,14 +110,14 @@ let create = function () {show: false, text: '', url: '',}, wait: {show: false, text: '',-}},// part of the account selection auto-completefilters: {- source: [], destination: [],+ source: [],+ destination: [],},// events in the form@@ -129,23 +136,10 @@ let create = function () {changedSourceAccount(event) {this.detectTransactionType();},- disableSplitAccounts() {- if(this.entries.length > 1) {- // disable source and/or destination, based on account type.- for(let i = 1;i<this.entries.length;i++) {- // disable source when withdrawal or transfer- if('transfer' === this.groupProperties.transactionType || 'withdrawal' === this.groupProperties.transactionType) {- this.entries[i].source_account.disabled = true;- console.log('Disable source account #' + i);- }- // disable destination when deposit or transfer- if('transfer' === this.groupProperties.transactionType || 'deposit' === this.groupProperties.transactionType) {- this.entries[i].destination_account.disabled = true;- console.log('Disable destination account #' + i);- }- }- }- },+ // shared functions with edit/create transaction.+ disableSplitAccounts: disableSplitAccounts,+ parseTotalAmount: parseTotalAmount,+ processUploadError: processUploadError,detectTransactionType() {const sourceType = this.entries[0].source_account.type ?? 'unknown';@@ -227,12 +221,6 @@ let create = function () {this.disableSplitAccounts();},- formattedTotalAmount() {- if (this.entries.length === 0) {- return formatMoney(this.groupProperties.totalAmount, 'EUR');- }- return formatMoney(this.groupProperties.totalAmount, this.entries[0].currency_code ?? 'EUR');- },filterForeignCurrencies(code) {let list = [];@@ -317,23 +305,6 @@ let create = function () {console.log('Now in processUpload()');this.showMessageOrRedirectUser();},-- processUploadError(event) {- console.log('Now in processUploadError()');- this.notifications.success.show = false;- this.notifications.wait.show = false;- this.notifications.error.show = true;- this.formStates.isSubmitting = false;- this.notifications.error.text = i18next.t('firefly.errors_upload');- console.log(event.detail.error.response.status);- if(413 === event.detail.error.response.status) {- this.notifications.error.text = i18next.t('firefly.upload_too_large');- }- // delete transaction and let user try again.- let del = new Delete();- del.delete(this.groupProperties.id);- // console.error(event);- },clearDescription(index) {this.entries[index].description = '';},diff --git a/resources/assets/v3/js/pages/transactions/edit.js b/resources/assets/v3/js/pages/transactions/edit.jsindex 6d9d238136..036c7eedb0 100644--- a/resources/assets/v3/js/pages/transactions/edit.js+++ b/resources/assets/v3/js/pages/transactions/edit.js@@ -27,6 +27,7 @@ import {addAllAutocompleteToForm, getUrls} from "./shared/add-autocomplete.js";import {loadCurrencies} from "./shared/load-currencies.js";import {loadBudgets} from "./shared/load-budgets.js";import {loadPiggyBanks} from "./shared/load-piggy-banks.js";+import {processUploadError} from "./shared/process-upload-error.js";import {loadSubscriptions} from "./shared/load-subscriptions.js";import Tags from "bootstrap5-tags";import i18next from "i18next";@@ -36,6 +37,8 @@ import Put from "../../api/model/transaction/put.js";import {processAttachments} from "./shared/process-attachments.js";import {spliceErrorsIntoTransactions} from "./shared/splice-errors-into-transactions.js";import sidebar from "../shared/sidebar.js";+import {disableSplitAccounts} from "./shared/disable-split-accounts.js";+import {parseTotalAmount} from "./shared/parse-total-amount.js";// TODO upload attachments to other file// TODO fix two maps, perhaps disconnect from entries entirely.@@ -49,7 +52,9 @@ const urls = getUrls();let transactions = function () {return {+ // needed for translationsi18next: null,+// transactions are stored in "entries":entries: [],originals: [],@@ -107,118 +112,24 @@ let transactions = function () {}},- keyUpFromCategory(e) {- if (e.key === 'Enter' && false === this.formBehaviour.categorySelectVisible) {- this.save();- return;- }- this.formBehaviour.categorySelectVisible = document.querySelector('input.ac-category').nextSibling.classList.contains('show');- },- changedForeignAmount(e) {- const index = parseInt(e.target.dataset.index);- if('' === e.target.value) {- this.entries[index].foreign_amount = '';- return;- }- this.entries[index].foreign_amount = parseFloat(e.target.value);- },-- // submit the transaction form.- // basically the same as store.js.- save() {- this.notifications.error.show = false;- this.notifications.success.show = false;- this.notifications.wait.show = false;- this.formStates.isSubmitting = true;-- // reset all errors in the entries array:- for (let i in this.entries) {- if (this.entries.hasOwnProperty(i)) {- this.entries[i].errors = defaultErrorSet();- }- }- // parse transaction:- let transactions = parseFromEntries(this.entries, this.originals, this.groupProperties.transactionType);- let submission = {- group_title: this.groupProperties.title,- fire_webhooks: this.formStates.webhooksButton,- apply_rules: this.formStates.rulesButton,- transactions: transactions- };-- // catch for group title:- if (null === this.groupProperties.title && transactions.length > 1) {- submission.group_title = transactions[0].description;- }- if(1 === transactions.length) {- submission.group_title = null;- }-- // submit the transaction. Multi-stage process thing going on here!- let putter = new Put();- putter.put(submission, {id: this.groupProperties.id}).then((response) => {- const group = response.data.data;-- // submission was a success!- this.groupProperties.id = parseInt(group.id);- this.groupProperties.title = group.attributes.group_title ?? group.attributes.transactions[0].description-- // process attachments, if any:- const attachmentCount = processAttachments(this.groupProperties.id, group.attributes.transactions);-- if (attachmentCount > 0) {- // if count is more than zero, system is processing transactions in the background.- this.notifications.wait.show = true;- this.notifications.wait.text = i18next.t('firefly.wait_attachments');- return;- }-- // if not, respond to user options:- this.showMessageOrRedirectUser();- }).catch((error) => {- this.formStates.isSubmitting = false;- if (typeof error.response !== 'undefined') {- this.parseErrors(error.response.data);- }- });- },+ // shared functions between edit/create+ parseTotalAmount: parseTotalAmount,+ disableSplitAccounts: disableSplitAccounts,+ processUploadError: processUploadError,// part of the account selection auto-completefilters: {source: [], destination: [],},- addSplit() {- console.log('addSplit()');- this.entries.push(createEmptySplit());- this.disableSplitAccounts();- addAllAutocompleteToForm(this.filters);- },- addedSplit() {- console.log('addedSplit()');- this.disableSplitAccounts();- addAllAutocompleteToForm(this.filters);- },-- disableSplitAccounts() {- if(this.entries.length > 1) {- // disable source and/or destination, based on account type.- for(let i = 1;i<this.entries.length;i++) {- // disable source when withdrawal or transfer- if('transfer' === this.groupProperties.transactionType || 'withdrawal' === this.groupProperties.transactionType) {- this.entries[i].source_account.disabled = true;- console.log('Disable source account #' + i);- }- // disable destination when deposit or transfer- if('transfer' === this.groupProperties.transactionType || 'deposit' === this.groupProperties.transactionType) {- this.entries[i].destination_account.disabled = true;- console.log('Disable destination account #' + i);- }- }+ // events in the form+ keyUpFromCategory(e) {+ if (e.key === 'Enter' && false === this.formBehaviour.categorySelectVisible) {+ this.save();+ return;}+ this.formBehaviour.categorySelectVisible = document.querySelector('input.ac-category').nextSibling.classList.contains('show');},-- // events in the formchangedDateTime(event) {console.warn('changedDateTime, event is not used');},@@ -235,13 +146,6 @@ let transactions = function () {console.warn('changedSourceAccount, event is not used');},- // duplicate function but this is easier.- formattedTotalAmount() {- if (this.entries.length === 0) {- return formatMoney(this.groupProperties.totalAmount, 'EUR');- }- return formatMoney(this.groupProperties.totalAmount, this.entries[0].currency_code ?? 'EUR');- },getTags(index) {return this.entries[index].tags ?? [];},@@ -417,15 +321,88 @@ let transactions = function () {processUpload(event) {this.showMessageOrRedirectUser();},- // TODO is a duplicate- processUploadError(event) {++ changedForeignAmount(e) {+ const index = parseInt(e.target.dataset.index);+ if('' === e.target.value) {+ this.entries[index].foreign_amount = '';+ return;+ }+ this.entries[index].foreign_amount = parseFloat(e.target.value);+ },++ // submit the transaction form.+ // basically the same as store.js.+ save() {+ this.notifications.error.show = false;this.notifications.success.show = false;this.notifications.wait.show = false;- this.notifications.error.show = true;- this.formStates.isSubmitting = false;- this.notifications.error.text = i18next.t('firefly.errors_upload');- console.error(event);+ this.formStates.isSubmitting = true;++ // reset all errors in the entries array:+ for (let i in this.entries) {+ if (this.entries.hasOwnProperty(i)) {+ this.entries[i].errors = defaultErrorSet();+ }+ }+ // parse transaction:+ let transactions = parseFromEntries(this.entries, this.originals, this.groupProperties.transactionType);+ let submission = {+ group_title: this.groupProperties.title,+ fire_webhooks: this.formStates.webhooksButton,+ apply_rules: this.formStates.rulesButton,+ transactions: transactions+ };++ // catch for group title:+ if (null === this.groupProperties.title && transactions.length > 1) {+ submission.group_title = transactions[0].description;+ }+ if(1 === transactions.length) {+ submission.group_title = null;+ }++ // submit the transaction. Multi-stage process thing going on here!+ let putter = new Put();+ putter.put(submission, {id: this.groupProperties.id}).then((response) => {+ const group = response.data.data;++ // submission was a success!+ this.groupProperties.id = parseInt(group.id);+ this.groupProperties.title = group.attributes.group_title ?? group.attributes.transactions[0].description++ // process attachments, if any:+ const attachmentCount = processAttachments(this.groupProperties.id, group.attributes.transactions);++ if (attachmentCount > 0) {+ // if count is more than zero, system is processing transactions in the background.+ this.notifications.wait.show = true;+ this.notifications.wait.text = i18next.t('firefly.wait_attachments');+ return;+ }++ // if not, respond to user options:+ this.showMessageOrRedirectUser();+ }).catch((error) => {+ this.formStates.isSubmitting = false;+ if (typeof error.response !== 'undefined') {+ this.parseErrors(error.response.data);+ }+ });+ },++ addSplit() {+ console.log('addSplit()');+ this.entries.push(createEmptySplit());+ this.disableSplitAccounts();+ addAllAutocompleteToForm(this.filters);},+ addedSplit() {+ console.log('addedSplit()');+ this.disableSplitAccounts();+ addAllAutocompleteToForm(this.filters);+ },+}}diff --git a/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.js b/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.jsnew file mode 100644index 0000000000..aaddaf9976--- /dev/null+++ b/resources/assets/v3/js/pages/transactions/shared/disable-split-accounts.js@@ -0,0 +1,41 @@+/*+ * disable-split-accounts.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */+++// what happens when a user adds more than one split?+export function disableSplitAccounts() {+ console.log('Call disableSplitAccounts');+ if(this.entries.length > 1) {+ console.log('Activate disableSplitAccounts');+ // disable source and/or destination, based on account type.+ for(let i = 1;i<this.entries.length;i++) {+ // disable source when withdrawal or transfer+ if('transfer' === this.groupProperties.transactionType || 'withdrawal' === this.groupProperties.transactionType) {+ this.entries[i].source_account.disabled = true;+ console.log('Disable source account #' + i + 1);+ }+ // disable destination when deposit or transfer+ if('transfer' === this.groupProperties.transactionType || 'deposit' === this.groupProperties.transactionType) {+ this.entries[i].destination_account.disabled = true;+ console.log('Disable destination account #' + i + 1);+ }+ }+ }+}diff --git a/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.jsindex f62a1a589b..011d4960c7 100644--- a/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js+++ b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js@@ -90,16 +90,8 @@ export function parseFromEntries(entries, originals, transactionType) {current.foreign_amount = entry.foreign_amount;console.log('There is also a foreign amount set, ', current.foreign_amount);}- // if (typeof entry.foreign_amount === 'undefined' || '' === entry.foreign_amount.toString() || 0.0 === entry.foreign_amount) {- // delete current.foreign_amount;- // delete current.foreign_currency_code;- // current.foreign_amount = null;- // current.foreign_currency_code = null;- // console.log('Remove or reset foreign currency info.');- // }}if (null === current.foreign_amount || null === current.foreign_currency_code) {- console.log('Set both to NULL because one of them is NULL.');current.foreign_amount = '0';current.foreign_currency_code = '';}diff --git a/resources/assets/v3/js/pages/transactions/shared/parse-total-amount.js b/resources/assets/v3/js/pages/transactions/shared/parse-total-amount.jsnew file mode 100644index 0000000000..7dff9449fc--- /dev/null+++ b/resources/assets/v3/js/pages/transactions/shared/parse-total-amount.js@@ -0,0 +1,28 @@+/*+ * parse-total-amount.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++import formatMoney from "../../../util/format-money.js";++export function parseTotalAmount() {+ if (this.entries.length === 0) {+ return formatMoney(this.groupProperties.totalAmount, 'EUR');+ }+ return formatMoney(this.groupProperties.totalAmount, this.entries[0].currency_code ?? 'EUR');+}diff --git a/resources/assets/v3/js/pages/transactions/shared/process-upload-error.js b/resources/assets/v3/js/pages/transactions/shared/process-upload-error.jsnew file mode 100644index 0000000000..943c3b7c78--- /dev/null+++ b/resources/assets/v3/js/pages/transactions/shared/process-upload-error.js@@ -0,0 +1,39 @@+/*+ * process-upload-error.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++import i18next from "i18next";+import Delete from "../../../api/model/transaction/delete.js";++export function processUploadError(event){+ this.notifications.success.show = false;+ this.notifications.wait.show = false;+ this.notifications.error.show = true;+ this.formStates.isSubmitting = false;+ this.notifications.error.text = i18next.t('firefly.errors_upload');+ console.log(event.detail.error.response.status);+ if(413 === event.detail.error.response.status) {+ this.notifications.error.text = i18next.t('firefly.upload_too_large');+ }+ if('create' === this.formBehaviour.formType) {+ // delete transaction and let user try again.+ let del = new Delete();+ del.delete(this.groupProperties.id);+ }+}diff --git a/resources/views/components/transaction/tab-list.blade.php b/resources/views/components/transaction/tab-list.blade.phpindex 59ff93c860..b33e087be9 100644--- a/resources/views/components/transaction/tab-list.blade.php+++ b/resources/views/components/transaction/tab-list.blade.php@@ -26,7 +26,7 @@<li class="nav-item"><a class="nav-link disabled" aria-disabled="true">{{ __('firefly.total') }}:- <span x-text="formattedTotalAmount()"></span>+ <span x-text="parseTotalAmount()"></span></a></li>diff --git a/resources/views/piggy-banks/show.blade.php b/resources/views/piggy-banks/show.blade.phpindex 8cd98d857e..5c9c4ae951 100644--- a/resources/views/piggy-banks/show.blade.php+++ b/resources/views/piggy-banks/show.blade.php@@ -131,7 +131,7 @@<div class="card-header"><h3 class="card-title">{{ trans('form.notes') }}</h3></div>- <div class="box-body markdown">{!! parse_markdown($piggy['notes']) !!}+ <div class="card-body markdown">{!! parse_markdown($piggy['notes']) !!}</div></div>