Skip to content

Firefly III: a personal finances manager

add view details

Sander Dorigo77137b126530
diff --git a/app/View/Components/Transaction/Messages.php b/app/View/Components/Transaction/Messages.php
new file mode 100644
index 0000000000..3b0892f56c
--- /dev/null
+++ b/app/View/Components/Transaction/Messages.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace FireflyIII\View\Components\Transaction;
+
+use Closure;
+use Illuminate\Contracts\View\View;
+use Illuminate\View\Component;
+
+class Messages extends Component
+{
+ /**
+ * Create a new component instance.
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * Get the view / contents that represent the component.
+ */
+ public function render(): View|Closure|string
+ {
+ return view('components.transaction.messages');
+ }
+}
diff --git a/app/View/Components/Transaction/Split.php b/app/View/Components/Transaction/Split.php
new file mode 100644
index 0000000000..76f9f997cd
--- /dev/null
+++ b/app/View/Components/Transaction/Split.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace FireflyIII\View\Components\Transaction;
+
+use Closure;
+use Illuminate\Contracts\View\View;
+use Illuminate\View\Component;
+
+class Split extends Component
+{
+ /**
+ * Create a new component instance.
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * Get the view / contents that represent the component.
+ */
+ public function render(): View|Closure|string
+ {
+ return view('components.transaction.split');
+ }
+}
diff --git a/app/View/Components/Transaction/TabList.php b/app/View/Components/Transaction/TabList.php
new file mode 100644
index 0000000000..28ec63930a
--- /dev/null
+++ b/app/View/Components/Transaction/TabList.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace FireflyIII\View\Components\Transaction;
+
+use Closure;
+use Illuminate\Contracts\View\View;
+use Illuminate\View\Component;
+
+class TabList extends Component
+{
+ /**
+ * Create a new component instance.
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * Get the view / contents that represent the component.
+ */
+ public function render(): View|Closure|string
+ {
+ return view('components.transaction.tab-list');
+ }
+}
diff --git a/package.json b/package.json
index b3f3cd49cd..dbb72ac91c 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,6 @@
},
"workspaces": [
"resources/assets/v1",
- "resources/assets/v2",
"resources/assets/v3"
],
"devDependencies": {
diff --git a/resources/assets/v3/js/api/model/transaction/post.js b/resources/assets/v3/js/api/model/transaction/post.js
new file mode 100644
index 0000000000..eed5340dc8
--- /dev/null
+++ b/resources/assets/v3/js/api/model/transaction/post.js
@@ -0,0 +1,28 @@
+/*
+ * post.js
+ * Copyright (c) 2023 [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 {api} from "../../../boot/axios";
+
+export default class Post {
+ post(submission) {
+ let url = '/api/v1/transactions';
+ return api.post(url, submission);
+ }
+}
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
new file mode 100644
index 0000000000..e5c914ba1d
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -0,0 +1,590 @@
+/*
+ * create.js
+ * Copyright (c) 2023 [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 '../../boot/bootstrap.js';
+import sidebar from '../../pages/shared/sidebar.js';
+import dates from '../shared/dates.js';
+import {createEmptySplit, defaultErrorSet} from "./shared/create-empty-split.js";
+// import {parseFromEntries} from "./shared/parse-from-entries.js";
+import formatMoney from "../../util/format-money.js";
+// import Post from "../../api/model/transaction/post.js";
+// import {loadCurrencies} from "./shared/load-currencies.js";
+// import {loadBudgets} from "./shared/load-budgets.js";
+// import {loadBudgets} from "./shared/load-budgets.js";
+// import {loadPiggyBanks} from "./shared/load-piggy-banks.js";
+// import {loadSubscriptions} from "./shared/load-subscriptions.js";
+//
+// import 'leaflet/dist/leaflet.css';
+import {addAutocomplete, getUrls} from "./shared/add-autocomplete.js";
+// import {
+// changeCategory,
+// changeDescription,
+// changeDestinationAccount,
+// changeSourceAccount,
+// selectDestinationAccount,
+// selectSourceAccount
+// } from "./shared/autocomplete-functions.js";
+// import {processAttachments} from "./shared/process-attachments.js";
+// import {spliceErrorsIntoTransactions} from "./shared/splice-errors-into-transactions.js";
+// import Tags from "bootstrap5-tags";
+// import {addLocation} from "./shared/manage-locations.js";
+// import i18next from "i18next";
+// TODO upload attachments to other file
+// TODO fix two maps, perhaps disconnect from entries entirely.
+// TODO group title
+// TODO map location from preferences
+// TODO field preferences
+
+const urls = getUrls();
+
+let create = function () {
+ return {
+ // transactions are stored in "entries":
+ entries: [],
+ //
+ // // state of the form is stored in formState:
+ // formStates: {
+ // loadingCurrencies: true,
+ // loadingBudgets: true,
+ // loadingPiggyBanks: true,
+ // loadingSubscriptions: true,
+ // isSubmitting: false,
+ // returnHereButton: false,
+ // saveAsNewButton: false, // edit form only
+ // resetButton: false,
+ // rulesButton: true,
+ // webhooksButton: true,
+ // categorySelectVisible: false
+ // },
+ //
+ // // form behavior during transaction
+ // formBehaviour: {
+ // formType: 'create',
+ // foreignCurrencyEnabled: true,
+ // },
+ //
+ // // form data (except transactions) is stored in formData
+ formData: {
+ defaultCurrency: null,
+ enabledCurrencies: [],
+ primaryCurrencies: [],
+ foreignCurrencies: [],
+ budgets: [],
+ piggyBanks: [],
+ subscriptions: [],
+ },
+ //
+ // // properties for the entire transaction group
+ groupProperties: {
+ transactionType: 'unknown',
+ title: null,
+ id: null,
+ totalAmount: 0,
+ },
+ //
+ // // notifications
+ notifications: {
+ error: {
+ show: false, text: '', url: '',
+ }, success: {
+ show: false, text: '', url: '',
+ }, wait: {
+ show: false, text: '',
+
+ }
+ },
+ //
+ //
+ // // part of the account selection auto-complete
+ // filters: {
+ // source: [], destination: [],
+ // },
+ //
+ // // events in the form
+ // changedDateTime(event) {
+ // console.warn('changedDateTime, event is not used');
+ // },
+ //
+ // changedDescription(event) {
+ // console.warn('changedDescription, event is not used');
+ // },
+ //
+ // changedDestinationAccount(event) {
+ // this.detectTransactionType();
+ // },
+ //
+ // changedSourceAccount(event) {
+ // this.detectTransactionType();
+ // },
+ //
+ // detectTransactionType() {
+ // const sourceType = this.entries[0].source_account.type ?? 'unknown';
+ // const destType = this.entries[0].destination_account.type ?? 'unknown';
+ // if ('unknown' === sourceType && 'unknown' === destType) {
+ // this.groupProperties.transactionType = 'unknown';
+ // console.warn('Cannot infer transaction type from two unknown accounts.');
+ // return;
+ // }
+ //
+ // // transfer: both are the same and in strict set of account types
+ // if (sourceType === destType && ['Asset account', 'Loan', 'Debt', 'Mortgage'].includes(sourceType)) {
+ // this.groupProperties.transactionType = 'transfer';
+ // console.log('Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ //
+ // // this also locks the amount into the amount of the source account
+ // // and the foreign amount (if different) in that of the destination account.
+ // console.log('filter down currencies for transfer.');
+ // this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
+ // this.filterForeignCurrencies(this.entries[0].destination_account.currency_code);
+ // return;
+ // }
+ // // withdrawals:
+ // if ('Asset account' === sourceType && ['Expense account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
+ // this.groupProperties.transactionType = 'withdrawal';
+ // console.log('[a] Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ // this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
+ // return;
+ // }
+ // if ('Asset account' === sourceType && 'unknown' === destType) {
+ // this.groupProperties.transactionType = 'withdrawal';
+ // console.log('[b] Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ // console.log(this.entries[0].source_account);
+ // this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
+ // return;
+ // }
+ // if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Expense account' === destType) {
+ // this.groupProperties.transactionType = 'withdrawal';
+ // console.log('[c] Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ // this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
+ // return;
+ // }
+ //
+ // // deposits:
+ // if ('Revenue account' === sourceType && ['Asset account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
+ // this.groupProperties.transactionType = 'deposit';
+ // console.log('Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ // return;
+ // }
+ // if ('unknown' === sourceType && ['Asset account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
+ // this.groupProperties.transactionType = 'deposit';
+ // console.log('Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ // return;
+ // }
+ // if ('Expense account' === sourceType && ['Asset account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
+ // this.groupProperties.transactionType = 'deposit';
+ // console.warn('FORCE transaction type to be "' + this.groupProperties.transactionType + '".');
+ // this.entries[0].source_account.id = '';
+ // return;
+ // }
+ // if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Asset account' === destType) {
+ // this.groupProperties.transactionType = 'deposit';
+ // console.log('Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
+ // return;
+ // }
+ // console.warn('Unknown account combination between "' + sourceType + '" and "' + destType + '".');
+ // },
+ //
+ 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 = [];
+ // let currency;
+ // for (let i in this.formData.enabledCurrencies) {
+ // if (this.formData.enabledCurrencies.hasOwnProperty(i)) {
+ // let current = this.formData.enabledCurrencies[i];
+ // if (current.code === code) {
+ // currency = current;
+ // }
+ // }
+ // }
+ // list.push(currency);
+ // this.formData.foreignCurrencies = list;
+ // // is he source account currency anyway:
+ // if (1 === list.length && list[0].code === this.entries[0].source_account.currency_code) {
+ // console.log('Foreign currency is same as source currency. Disable foreign amount.');
+ // this.formBehaviour.foreignCurrencyEnabled = false;
+ // }
+ // if (1 === list.length && list[0].code !== this.entries[0].source_account.currency_code) {
+ // console.log('Foreign currency is NOT same as source currency. Enable foreign amount.');
+ // this.formBehaviour.foreignCurrencyEnabled = true;
+ // }
+ //
+ // // this also forces the currency_code on ALL entries.
+ // for (let i in this.entries) {
+ // if (this.entries.hasOwnProperty(i)) {
+ // this.entries[i].foreign_currency_code = code;
+ // }
+ // }
+ // },
+ //
+ // filterPrimaryCurrencies(code) {
+ // let list = [];
+ // let currency;
+ // for (let i in this.formData.enabledCurrencies) {
+ // if (this.formData.enabledCurrencies.hasOwnProperty(i)) {
+ // let current = this.formData.enabledCurrencies[i];
+ // if (current.code === code) {
+ // currency = current;
+ // }
+ // }
+ // }
+ // list.push(currency);
+ // this.formData.primaryCurrencies = list;
+ //
+ // // this also forces the currency_code on ALL entries.
+ // for (let i in this.entries) {
+ // if (this.entries.hasOwnProperty(i)) {
+ // this.entries[i].currency_code = code;
+ // }
+ // }
+ // },
+ //
+ // changedAmount(e) {
+ // const index = parseInt(e.target.dataset.index);
+ // this.entries[index].amount = parseFloat(e.target.value);
+ // this.groupProperties.totalAmount = 0;
+ // for (let i in this.entries) {
+ // if (this.entries.hasOwnProperty(i)) {
+ // this.groupProperties.totalAmount = this.groupProperties.totalAmount + parseFloat(this.entries[i].amount);
+ // }
+ // }
+ // },
+ //
+ addedSplit() {
+
+
+ },
+ //
+ // processUpload(event) {
+ // this.showMessageOrRedirectUser();
+ // },
+ //
+ // 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.error(event);
+ // },
+ //
+ init() {
+ console.log('init()');
+ this.addSplit();
+ //
+ // // load currencies and save in form data.
+ // loadCurrencies().then(data => {
+ // this.formStates.loadingCurrencies = false;
+ // this.formData.defaultCurrency = data.defaultCurrency;
+ // this.formData.enabledCurrencies = data.enabledCurrencies;
+ // this.formData.primaryCurrencies = data.primaryCurrencies;
+ // this.formData.foreignCurrencies = data.foreignCurrencies;
+ // });
+ //
+ // loadBudgets().then(data => {
+ // this.formData.budgets = data;
+ // this.formStates.loadingBudgets = false;
+ // });
+ // loadPiggyBanks().then(data => {
+ // this.formData.piggyBanks = data;
+ // this.formStates.loadingPiggyBanks = false;
+ // });
+ // loadSubscriptions().then(data => {
+ // this.formData.subscriptions = data;
+ // this.formStates.loadingSubscriptions = false;
+ // });
+ //
+ // document.addEventListener('upload-success', (event) => {
+ // this.processUpload(event);
+ // document.querySelectorAll("input[type=file]").value = "";
+ // });
+ //
+ // document.addEventListener('upload-error', (event) => {
+ // this.processUploadError(event);
+ // });
+ // document.addEventListener('location-move', (event) => {
+ // this.entries[event.detail.index].latitude = event.detail.latitude;
+ // this.entries[event.detail.index].longitude = event.detail.longitude;
+ // });
+ //
+ // document.addEventListener('location-set', (event) => {
+ // this.entries[event.detail.index].hasLocation = true;
+ // this.entries[event.detail.index].latitude = event.detail.latitude;
+ // this.entries[event.detail.index].longitude = event.detail.longitude;
+ // this.entries[event.detail.index].zoomLevel = event.detail.zoomLevel;
+ // });
+ //
+ // document.addEventListener('location-zoom', (event) => {
+ // this.entries[event.detail.index].hasLocation = true;
+ // this.entries[event.detail.index].zoomLevel = event.detail.zoomLevel;
+ // });
+ //
+ //
+ // // source can never be expense account
+ // this.filters.source = ['Asset account', 'Loan', 'Debt', 'Mortgage', 'Revenue account'];
+ // // destination can never be revenue account
+ // this.filters.destination = ['Expense account', 'Loan', 'Debt', 'Mortgage', 'Asset account'];
+ },
+ // keyUpFromCategory(e) {
+ // if (e.key === 'Enter' && false === this.formStates.categorySelectVisible) {
+ // this.submitTransaction();
+ // return;
+ // }
+ // this.formStates.categorySelectVisible = document.querySelector('input.ac-category').nextSibling.classList.contains('show');
+ // },
+ // submitTransaction() {
+ // // reset all messages:
+ // this.notifications.error.show = false;
+ // this.notifications.success.show = false;
+ // this.notifications.wait.show = false;
+ //
+ // // reset all errors in the entries array:
+ // for (let i in this.entries) {
+ // if (this.entries.hasOwnProperty(i)) {
+ // this.entries[i].errors = defaultErrorSet();
+ // }
+ // }
+ //
+ // // form is now submitting:
+ // this.formStates.isSubmitting = true;
+ //
+ // // final check on transaction type.
+ // this.detectTransactionType();
+ //
+ // // parse transaction:
+ // let transactions = parseFromEntries(this.entries, null, 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:
+ // // TODO later this must be handled with more care (ie use the group title input)
+ // if (transactions.length > 1) {
+ // submission.group_title = transactions[0].description;
+ // }
+ //
+ // // submit the transaction. Multi-stage process thing going on here!
+ // let poster = new Post();
+ // console.log(submission);
+ // poster.post(submission).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
+ // console.log('group title is now: ', this.groupProperties.title);
+ //
+ // // 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.submitting = false;
+ // console.log(error);
+ // // todo put errors in form
+ // if (typeof error.response !== 'undefined') {
+ // this.parseErrors(error.response.data);
+ // }
+ //
+ //
+ // });
+ // },
+ //
+ // showMessageOrRedirectUser() {
+ // // disable all messages:
+ // this.notifications.error.show = false;
+ // this.notifications.success.show = false;
+ // this.notifications.wait.show = false;
+ //
+ // if (this.formStates.returnHereButton) {
+ // this.notifications.success.show = true;
+ // this.notifications.success.url = 'transactions/show/' + this.groupProperties.id;
+ // this.notifications.success.text = i18next.t('firefly.stored_journal_js', {
+ // description: this.groupProperties.title,
+ // interpolation: {escapeValue: false}
+ // });
+ // this.formStates.isSubmitting = false;
+ // // reset group title again
+ // this.groupProperties.title = null;
+ //
+ // if (this.formStates.resetButton) {
+ // this.entries = [];
+ // this.addSplit();
+ // this.groupProperties.totalAmount = 0;
+ // }
+ // return;
+ // }
+ // window.location = 'transactions/show/' + this.groupProperties.id + '?transaction_group_id=' + this.groupProperties.id + '&message=created';
+ // },
+ //
+ // parseErrors(data) {
+ // // disable all messages:
+ // this.notifications.error.show = true;
+ // this.notifications.success.show = false;
+ // this.notifications.wait.show = false;
+ // this.formStates.isSubmitting = false;
+ // this.notifications.error.text = i18next.t('firefly.errors_submission_v2', {errorMessage: data.message});
+ //
+ // if (data.hasOwnProperty('errors')) {
+ // this.entries = spliceErrorsIntoTransactions(data.errors, this.entries);
+ // }
+ // },
+ //
+ addSplit() {
+ console.log('addSplit()');
+ this.entries.push(createEmptySplit());
+
+ // setTimeout(() => {
+ // // render tags:
+ // Tags.init('select.ac-tags', {
+ // allowClear: true,
+ // server: urls.tag,
+ // liveServer: true,
+ // clearEnd: true,
+ // labelField: 'title',
+ // valueField: 'id',
+ // queryParam: 'filter[query]',
+ // allowNew: true,
+ // serverDataKey: 'data',
+ // notFoundMessage: i18next.t('firefly.nothing_found'),
+ // noCache: true,
+ // fetchOptions: {
+ // headers: {
+ // 'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').content
+ // }
+ // }
+ // });
+ // const count = this.entries.length - 1;
+ // // if(document.querySelector('#location_map_' + count)) { }
+ // addLocation(count);
+ //
+ // // addedSplit, is called from the HTML
+ // // for source account
+ // const renderAccount = function (item, b, c) {
+ // return item.name_with_balance + '<br><small class="text-muted">' + i18next.t('firefly.account_type_' + item.type) + '</small>';
+ // };
+ // console.log('here we are in');
+ // addAutocomplete({
+ // selector: 'input.ac-source',
+ // serverUrl: urls.account,
+ // onRenderItem: renderAccount,
+ // valueField: 'id',
+ // labelField: 'name_with_balance',
+ // onChange: changeSourceAccount,
+ // onSelectItem: selectSourceAccount,
+ // hiddenValue: this.entries[count].source_account.alpine_name
+ // });
+ // addAutocomplete({
+ // selector: 'input.ac-dest',
+ // serverUrl: urls.account,
+ // account_types: this.filters.destination,
+ // valueField: 'id',
+ // labelField: 'name_with_balance',
+ // onRenderItem: renderAccount,
+ // onChange: changeDestinationAccount,
+ // onSelectItem: selectDestinationAccount
+ // });
+ // addAutocomplete({
+ // selector: 'input.ac-category',
+ // serverUrl: urls.category,
+ // valueField: 'id',
+ // labelField: 'title',
+ // onChange: changeCategory,
+ // onSelectItem: changeCategory
+ // });
+ // addAutocomplete({
+ // selector: 'input.ac-description',
+ // serverUrl: urls.description,
+ // valueField: 'id',
+ // labelField: 'title',
+ // onChange: changeDescription,
+ // onSelectItem: changeDescription,
+ // });
+ //
+ // }, 150);
+ },
+ //
+ // removeSplit(index) {
+ // this.entries.splice(index, 1);
+ // // fall back to index 0
+ // const triggerFirstTabEl = document.querySelector('#split-0-tab')
+ // triggerFirstTabEl.click();
+ // },
+ //
+ // clearLocation(e) {
+ // e.preventDefault();
+ // // remove location from entry, fire event, do nothing else (the map is somebody else's problem).
+ //
+ // const target = e.currentTarget;
+ // const index = parseInt(target.attributes['data-index'].value);
+ // this.entries[index].hasLocation = false;
+ // this.entries[index].latitude = null;
+ // this.entries[index].longitude = null;
+ // this.entries[index].zoomLevel = null;
+ //
+ // const removeEvent = new CustomEvent('location-remove', {
+ // detail: {
+ // index: index
+ // }
+ // });
+ // document.dispatchEvent(removeEvent);
+ //
+ // return false;
+ // },
+ }
+}
+
+let comps = {create, sidebar, dates};
+
+function loadPage() {
+ Object.keys(comps).forEach(comp => {
+ console.log(`Loading page component "${comp}"`);
+ let data = comps[comp]();
+ Alpine.data(comp, () => data);
+ });
+ Alpine.start();
+}
+
+// wait for load until bootstrapped event is received.
+document.addEventListener('firefly-iii-bootstrapped', () => {
+ console.log('Loaded through event listener.');
+ loadPage();
+});
+// or is bootstrapped before event is triggered.
+if (window.bootstrapped) {
+ console.log('Loaded through window variable.');
+ loadPage();
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js b/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
new file mode 100644
index 0000000000..a71dcf023e
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
@@ -0,0 +1,71 @@
+/*
+ * add-autocomplete.js
+ * Copyright (c) 2024 [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 Autocomplete from "bootstrap5-autocomplete";
+
+export function getUrls() {
+ return {
+ description: '/api/v1/autocomplete/transaction-descriptions',
+ account: '/api/v1/autocomplete/accounts',
+ category: '/api/v1/autocomplete/categories',
+ tag: '/api/v1/autocomplete/tags',
+ }
+}
+
+export function addAutocomplete(options) {
+ const params = {
+ server: options.serverUrl,
+ serverParams: {},
+ fetchOptions: {
+ headers: {
+ 'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').content
+ }
+ },
+ queryParam: 'query',
+ hiddenInput: true,
+ // preventBrowserAutocomplete: true,
+ highlightTyped: true,
+ liveServer: true,
+ };
+ if (typeof options.account_types !== 'undefined' && options.account_types.length > 0) {
+ params.serverParams['types'] = options.account_types;
+ }
+ if (typeof options.onRenderItem !== 'undefined' && null !== options.onRenderItem) {
+ console.log('overrule onRenderItem.');
+ params.onRenderItem = options.onRenderItem;
+ }
+ if (options.valueField) {
+ params.valueField = options.valueField;
+ }
+ if (options.labelField) {
+ params.labelField = options.labelField;
+ }
+ if (options.onSelectItem) {
+ params.onSelectItem = options.onSelectItem;
+ }
+ if (options.onChange) {
+ params.onChange = options.onChange;
+ }
+ if(options.hiddenValue) {
+ params.hiddenValue = options.hiddenValue;
+ }
+
+ Autocomplete.init(options.selector, params);
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/autocomplete-functions.js b/resources/assets/v3/js/pages/transactions/shared/autocomplete-functions.js
new file mode 100644
index 0000000000..4755f2e33c
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/autocomplete-functions.js
@@ -0,0 +1,84 @@
+/*
+ * autocomplete-functions.js
+ * Copyright (c) 2024 [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/>.
+ */
+
+export function changeCategory(item, ac) {
+ const index = parseInt(ac._searchInput.attributes['data-index'].value);
+ if (typeof item !== 'undefined' && item.name) {
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].category_name = item.name;
+ return;
+ }
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].category_name = ac._searchInput.value;
+}
+
+export function changeDescription(item, ac) {
+ const index = parseInt(ac._searchInput.attributes['data-index'].value);
+ if (typeof item !== 'undefined' && item.description) {
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].description = item.description;
+ return;
+ }
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].description = ac._searchInput.value;
+}
+
+export function changeDestinationAccount(item, ac) {
+ if (typeof item === 'undefined') {
+ const index = parseInt(ac._searchInput.attributes['data-index'].value);
+ let destination = document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account;
+
+ if (destination.name === ac._searchInput.value) {
+ console.warn('Ignore hallucinated destination account name change to "' + ac._searchInput.value + '"');
+ return;
+ }
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account = {
+ name: ac._searchInput.value, alpine_name: ac._searchInput.value,
+ };
+ document.querySelector('#form')._x_dataStack[0].changedDestinationAccount();
+ }
+}
+
+export function selectDestinationAccount(item, ac) {
+ const index = parseInt(ac._searchInput.attributes['data-index'].value);
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account = {
+ id: item.id, name: item.name, alpine_name: item.name, type: item.type, currency_code: item.currency_code,
+ };
+ document.querySelector('#form')._x_dataStack[0].changedDestinationAccount();
+}
+
+export function changeSourceAccount(item, ac) {
+ if (typeof item === 'undefined') {
+ const index = parseInt(ac._searchInput.attributes['data-index'].value);
+ let source = document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account;
+ if (source.name === ac._searchInput.value) {
+ return;
+ }
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account = {
+ name: ac._searchInput.value, alpine_name: ac._searchInput.value,
+ };
+
+ document.querySelector('#form')._x_dataStack[0].changedSourceAccount();
+ }
+}
+
+export function selectSourceAccount(item, ac) {
+ const index = parseInt(ac._searchInput.attributes['data-index'].value);
+ document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account = {
+ id: item.id, name: item.name, alpine_name: item.name, type: item.type, currency_code: item.currency_code,
+ };
+ document.querySelector('#form')._x_dataStack[0].changedSourceAccount();
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/create-empty-split.js b/resources/assets/v3/js/pages/transactions/shared/create-empty-split.js
new file mode 100644
index 0000000000..95ea4c61dd
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/create-empty-split.js
@@ -0,0 +1,120 @@
+/*
+ * create-empty-split.js
+ * Copyright (c) 2023 [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 format from "date-fns/format";
+
+function getAccount() {
+ return {
+ id: '',
+ name: '',
+ alpine_name: '',
+ };
+}
+
+export function defaultErrorSet() {
+ return {
+ description: [],
+
+ // amount information:
+ amount: [],
+ currency_code: [],
+ foreign_amount: [],
+ foreign_currency_code: [],
+
+ // source and destination
+ source_account: [],
+ destination_account: [],
+
+ // meta data information:
+ budget_id: [],
+ category_name: [],
+ piggy_bank_id: [],
+ bill_id: [],
+ tags: [],
+ notes: [],
+
+ // other meta fields:
+ internal_reference: [],
+ external_url: [],
+
+ // map
+ latitude: [],
+ longitude: [],
+ zoom_level: [],
+
+ // date and time
+ date: [],
+ interest_date: [],
+ book_date: [],
+ process_date: [],
+ due_date: [],
+ payment_date: [],
+ invoice_date: [],
+ };
+}
+
+export function createEmptySplit() {
+ let now = new Date();
+ let formatted = format(now, 'yyyy-MM-dd HH:mm');
+ return {
+ description: '',
+
+ // amount information:
+ amount: '',
+ currency_code: 'EUR',
+ foreign_amount: '',
+ foreign_currency_code: '',
+
+ // source and destination
+ source_account: getAccount(),
+ destination_account: getAccount(),
+
+ // meta data information:
+ budget_id: null,
+ category_name: '',
+ piggy_bank_id: null,
+ bill_id: null,
+ tags: [],
+ notes: '',
+
+ // other meta fields:
+ internal_reference: '',
+ external_url: '',
+
+ // map
+ hasLocation: false,
+ latitude: null,
+ longitude: null,
+ zoomLevel: null,
+
+
+ // date and time
+ date: formatted,
+ interest_date: '',
+ book_date: '',
+ process_date: '',
+ due_date: '',
+ payment_date: '',
+ invoice_date: '',
+
+ errors: defaultErrorSet(),
+ };
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/load-budgets.js b/resources/assets/v3/js/pages/transactions/shared/load-budgets.js
new file mode 100644
index 0000000000..8416953fc3
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/load-budgets.js
@@ -0,0 +1,46 @@
+/*
+ * load-budgets.js
+ * Copyright (c) 2024 [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 Get from "../../../api/v1/model/budget/get.js";
+
+export function loadBudgets() {
+ let params = {
+ page: 1, limit: 1337
+ };
+ let getter = new Get();
+ return getter.list(params).then((response) => {
+ let returnData = [{
+ id: 0, name: '(no budget)',
+ }];
+
+ for (let i in response.data.data) {
+ if (response.data.data.hasOwnProperty(i)) {
+ let current = response.data.data[i];
+ let obj = {
+ id: current.id, name: current.attributes.name,
+ };
+ returnData.push(obj);
+ }
+ }
+ return returnData;
+ });
+
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/load-currencies.js b/resources/assets/v3/js/pages/transactions/shared/load-currencies.js
new file mode 100644
index 0000000000..2580a1389b
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/load-currencies.js
@@ -0,0 +1,65 @@
+/*
+ * load-currencies.js
+ * Copyright (c) 2024 [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 Get from "../../../api/v1/model/currency/get.js";
+
+export function loadCurrencies() {
+ let params = {
+ page: 1, limit: 1337
+ };
+ let getter = new Get();
+ return getter.list(params).then((response) => {
+ let returnData = {
+ primaryCurrency: {},
+ primaryCurrencies: [],
+ foreignCurrencies: [],
+ enabledCurrencies: [],
+ };
+
+ returnData.foreignCurrencies.push({
+ id: 0, name: '(no foreign currency)', code: '', default: false, symbol: '', decimal_places: 2,
+ });
+ for (let i in response.data.data) {
+ if (response.data.data.hasOwnProperty(i)) {
+ let current = response.data.data[i];
+ if (current.attributes.enabled) {
+ let obj =
+ {
+ id: current.id,
+ name: current.attributes.name,
+ code: current.attributes.code,
+ primary: current.attributes.primary,
+ symbol: current.attributes.symbol,
+ decimal_places: current.attributes.decimal_places,
+
+ };
+ if (obj.primary) {
+ returnData.primaryCurrency = obj;
+ }
+ returnData.enabledCurrencies.push(obj);
+ returnData.primaryCurrencies.push(obj);
+ returnData.foreignCurrencies.push(obj);
+ }
+ }
+ }
+ return returnData;
+ });
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/load-piggy-banks.js b/resources/assets/v3/js/pages/transactions/shared/load-piggy-banks.js
new file mode 100644
index 0000000000..c014345539
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/load-piggy-banks.js
@@ -0,0 +1,63 @@
+/*
+ * load-piggy-banks.js
+ * Copyright (c) 2024 [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 Get from "../../../api/v1/model/piggy-bank/get.js";
+
+export function loadPiggyBanks() {
+ let params = {
+ page: 1, limit: 1337
+ };
+ let getter = new Get();
+ return getter.list(params).then((response) => {
+ let piggyBanks = {
+ '0': {
+ id: 0, name: '(no group)', order: 0, piggyBanks: [{
+ id: 0, name: '(no piggy bank)', order: 0,
+ }]
+ }
+ };
+
+ for (let i in response.data.data) {
+ if (response.data.data.hasOwnProperty(i)) {
+ let current = response.data.data[i];
+ let objectGroupId = current.attributes.object_group_id ?? '0';
+ let objectGroupTitle = current.attributes.object_group_title ?? '(no group)';
+ let piggyBank = {
+ id: current.id, name: current.attributes.name, order: current.attributes.order,
+ };
+ if (!piggyBanks.hasOwnProperty(objectGroupId)) {
+ piggyBanks[objectGroupId] = {
+ id: objectGroupId,
+ name: objectGroupTitle,
+ order: current.attributes.object_group_order ?? 0,
+ piggyBanks: []
+ };
+ }
+ piggyBanks[objectGroupId].piggyBanks.push(piggyBank);
+ piggyBanks[objectGroupId].piggyBanks.sort((a, b) => a.order - b.order);
+ }
+ }
+ //tempObject.sort((a,b) => a.order - b.order);
+ return Object.keys(piggyBanks).sort().reduce((obj, key) => {
+ obj[key] = piggyBanks[key];
+ return obj;
+ }, {});
+ });
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/load-subscriptions.js b/resources/assets/v3/js/pages/transactions/shared/load-subscriptions.js
new file mode 100644
index 0000000000..a3ecb8b657
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/load-subscriptions.js
@@ -0,0 +1,61 @@
+/*
+ * load-subscriptions.js
+ * Copyright (c) 2024 [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 SubscriptionGet from "../../../api/v1/model/subscription/get.js";
+
+export function loadSubscriptions() {
+ let params = {
+ page: 1, limit: 1337
+ };
+ let getter = new SubscriptionGet();
+ return getter.list(params).then((response) => {
+ let subscriptions = {
+ '0': {
+ id: 0, name: '(no group)', order: 0, subscriptions: [{
+ id: 0, name: '(no subscription)', order: 0,
+ }]
+ }
+ };
+ for (let i in response.data.data) {
+ if (response.data.data.hasOwnProperty(i)) {
+ let current = response.data.data[i];
+ let objectGroupId = current.attributes.object_group_id ?? '0';
+ let objectGroupTitle = current.attributes.object_group_title ?? '(no group)';
+ let piggyBank = {
+ id: current.id, name: current.attributes.name, order: current.attributes.order,
+ };
+ if (!subscriptions.hasOwnProperty(objectGroupId)) {
+ subscriptions[objectGroupId] = {
+ id: objectGroupId,
+ name: objectGroupTitle,
+ order: current.attributes.object_group_order ?? 0,
+ subscriptions: []
+ };
+ }
+ subscriptions[objectGroupId].subscriptions.push(piggyBank);
+ subscriptions[objectGroupId].subscriptions.sort((a, b) => a.order - b.order);
+ }
+ }
+ return Object.keys(subscriptions).sort().reduce((obj, key) => {
+ obj[key] = subscriptions[key];
+ return obj;
+ }, {});
+ });
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/manage-locations.js b/resources/assets/v3/js/pages/transactions/shared/manage-locations.js
new file mode 100644
index 0000000000..92fce38165
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/manage-locations.js
@@ -0,0 +1,105 @@
+/*
+ * manage-locations.js
+ * Copyright (c) 2024 [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 L from "leaflet";
+
+let maps = [];
+let markers = [];
+
+// listen to event to remove marker:
+
+// location-remove
+
+document.addEventListener('location-remove', (event) => {
+ markers[event.detail.index].remove();
+});
+
+
+function addPointToMap(e) {
+ // index is always 0.
+ // let index = parseInt(e.originalEvent.currentTarget.attributes['data-index'].value);
+ let index = 0;
+ let hasLocation = document.querySelector('#form')._x_dataStack[0].$data.entries[index].hasLocation;
+
+ if (false === hasLocation) {
+ markers[index] = new L.marker(e.latlng, {draggable: true});
+ markers[index].on('dragend', dragEnd);
+ markers[index].addTo(maps[index]);
+
+ const setEvent = new CustomEvent('location-set', {
+ detail: {
+ latitude: e.latlng.lat,
+ longitude: e.latlng.lng,
+ index: index,
+ zoomLevel: maps[index].getZoom()
+ }
+ });
+ document.dispatchEvent(setEvent);
+ }
+}
+
+function saveZoomOfMap(e) {
+ //let index = parseInt(e.sourceTarget._container.attributes['data-index'].value);
+ let index = 0;
+ const zoomEvent = new CustomEvent('location-zoom', {
+ detail: {
+ index: index,
+ zoomLevel: maps[index].getZoom()
+ }
+ });
+ document.dispatchEvent(zoomEvent);
+}
+
+function dragEnd(event) {
+ let marker = event.target;
+ let position = marker.getLatLng();
+ marker.setLatLng(new L.LatLng(position.lat, position.lng), {draggable: 'true'});
+ const moveEvent = new CustomEvent('location-move', {
+ detail: {
+ latitude: position.lat,
+ longitude: position.lng,
+ index: 0
+ }
+ });
+ document.dispatchEvent(moveEvent);
+}
+
+export function addLocation(index) {
+ if (index > 0) {
+ console.warn('Corwardly refuse to add a map on split #' + (index + 1));
+ return;
+ }
+ if (typeof maps[index] === 'undefined') {
+ // map holder is always the same:
+
+ //let holder = document.getElementById('location_map_' + index);
+ let holder = document.getElementById('location_map');
+ if (holder) {
+ maps[index] = L.map(holder).setView([holder.dataset.latitude, holder.dataset.longitude], holder.dataset.zoomLevel);
+
+ L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
+ maxZoom: 19,
+ attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
+ }).addTo(maps[index]);
+ maps[index].on('click', addPointToMap);
+ maps[index].on('zoomend', saveZoomOfMap);
+ }
+ }
+}
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.js
new file mode 100644
index 0000000000..f3e0c93fea
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js
@@ -0,0 +1,108 @@
+/*
+ * parse-from-entries.js
+ * Copyright (c) 2023 [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/>.
+ */
+
+/**
+ *
+ */
+export function parseFromEntries(entries, originals, transactionType) {
+ let returnArray = [];
+ for (let i in entries) {
+ if (entries.hasOwnProperty(i)) {
+ const entry = entries[i];
+ let compare = false;
+ let original = {};
+ if (originals !== null && originals.hasOwnProperty(i)) {
+ compare = true;
+ let original = originals[i];
+ }
+ let current = {};
+
+ // fields for transaction
+ if ((compare && original.description !== entry.description) || !compare) {
+ current.description = entry.description;
+ }
+
+ // source and destination
+ current.source_name = entry.source_account.name;
+ current.destination_name = entry.destination_account.name;
+
+ // amount information:
+ current.amount = entry.amount;
+ current.currency_code = entry.currency_code;
+
+
+ // dates
+ current.date = entry.date;
+ current.interest_date = entry.interest_date;
+ current.book_date = entry.book_date;
+ current.process_date = entry.process_date;
+ current.due_date = entry.due_date;
+ current.payment_date = entry.payment_date;
+ current.invoice_date = entry.invoice_date;
+
+ // meta
+ current.budget_id = entry.budget_id;
+ current.category_name = entry.category_name;
+ current.piggy_bank_id = entry.piggy_bank_id;
+ current.bill_id = entry.bill_id;
+ current.tags = entry.tags;
+ current.notes = entry.notes;
+
+ // more meta
+ current.internal_reference = entry.internal_reference;
+ current.external_url = entry.external_url;
+
+ // location
+ current.store_location = false;
+ if (entry.hasLocation) {
+ current.store_location = true;
+ current.longitude = entry.longitude.toString();
+ current.latitude = entry.latitude.toString();
+ current.zoom_level = entry.zoomLevel;
+ }
+
+ // if foreign amount currency code is set:
+ if (typeof entry.foreign_currency_code !== 'undefined' && '' !== entry.foreign_currency_code.toString()) {
+ current.foreign_currency_code = entry.foreign_currency_code;
+ if (typeof entry.foreign_amount !== 'undefined' && '' !== entry.foreign_amount.toString()) {
+ current.foreign_amount = entry.foreign_amount;
+ }
+ if (typeof entry.foreign_amount === 'undefined' || '' === entry.foreign_amount.toString()) {
+ delete current.foreign_amount;
+ delete current.foreign_currency_code;
+ }
+ }
+
+ // if ID is set:
+ if (typeof entry.source_account.id !== 'undefined' && '' !== entry.source_account.id.toString()) {
+ current.source_id = entry.source_account.id;
+ }
+ if (typeof entry.destination_account.id !== 'undefined' && '' !== entry.destination_account.id.toString()) {
+ current.destination_id = entry.destination_account.id;
+ }
+
+ current.type = transactionType;
+
+
+ returnArray.push(current);
+ }
+ }
+ return returnArray;
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/process-attachments.js b/resources/assets/v3/js/pages/transactions/shared/process-attachments.js
new file mode 100644
index 0000000000..dc0ef5e13b
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/process-attachments.js
@@ -0,0 +1,114 @@
+/*
+ * process-attachments.js
+ * Copyright (c) 2024 [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 AttachmentPost from "../../../api/v1/model/attachment/post.js";
+
+let uploadFiles = function (fileData) {
+ let count = fileData.length;
+ let uploads = 0;
+ let hasError = false;
+
+ for (const key in fileData) {
+ if (fileData.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294 && false === hasError) {
+ let poster = new AttachmentPost();
+ poster.post(fileData[key].name, 'TransactionJournal', fileData[key].journal).then(response => {
+ let attachmentId = parseInt(response.data.data.id);
+ poster.upload(attachmentId, fileData[key].content).then(attachmentResponse => {
+ uploads++;
+ if (uploads === count) {
+ const event = new CustomEvent('upload-success', {some: 'details'});
+ document.dispatchEvent(event);
+ }
+ }).catch(error => {
+ console.error('[a] Could not upload');
+ console.error(error);
+ uploads++;
+ // break right away
+ const event = new CustomEvent('upload-failed', {error: error});
+ document.dispatchEvent(event);
+ hasError = true;
+ });
+ }).catch(error => {
+ console.error('Could not create upload.');
+ console.error(error);
+ uploads++;
+ const event = new CustomEvent('upload-failed', {error: error});
+ document.dispatchEvent(event);
+ hasError = true;
+ });
+ }
+ }
+}
+
+
+export function processAttachments(groupId, transactions) {
+ // reverse list of transactions
+ transactions = transactions.reverse();
+
+ // array of all files to be uploaded:
+ let toBeUploaded = [];
+ let count = 0;
+ // array with all file data.
+ let fileData = [];
+
+ // all attachments
+ let attachments = document.querySelectorAll('input[name="attachments[]"]');
+
+ // loop over all attachments, and add references to this array:
+ for (const key in attachments) {
+ if (attachments.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
+ for (const fileKey in attachments[key].files) {
+ if (attachments[key].files.hasOwnProperty(fileKey) && /^0$|^[1-9]\d*$/.test(fileKey) && fileKey <= 4294967294) {
+ // include journal thing.
+ toBeUploaded.push({
+ journal: transactions[key].transaction_journal_id,
+ file: attachments[key].files[fileKey]
+ });
+ count++;
+ }
+ }
+ }
+ }
+
+ // loop all uploads. This is async.
+ for (const key in toBeUploaded) {
+ if (toBeUploaded.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
+
+ // create file reader thing that will read all of these uploads
+ (function (f, key) {
+ let fileReader = new FileReader();
+ fileReader.onloadend = function (evt) {
+ if (evt.target.readyState === FileReader.DONE) { // DONE == 2
+ fileData.push({
+ name: toBeUploaded[key].file.name,
+ journal: toBeUploaded[key].journal,
+ content: new Blob([evt.target.result])
+ });
+ if (fileData.length === count) {
+ uploadFiles(fileData);
+ }
+ }
+ };
+ fileReader.readAsArrayBuffer(f.file);
+ })(toBeUploaded[key], key,);
+ }
+ }
+ return count;
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/splice-errors-into-transactions.js b/resources/assets/v3/js/pages/transactions/shared/splice-errors-into-transactions.js
new file mode 100644
index 0000000000..8df406d30e
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/splice-errors-into-transactions.js
@@ -0,0 +1,106 @@
+/*
+ * splice-errors-into-transactions.js
+ * Copyright (c) 2024 [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";
+
+function cleanupErrors(fullName, shortName, errors) {
+ let newErrors = [];
+ let message = '';
+ for (let i in errors) {
+ if (errors.hasOwnProperty(i)) {
+ newErrors.push(errors[i].replace(fullName, shortName));
+ }
+ }
+ return newErrors;
+}
+
+export function spliceErrorsIntoTransactions(errors, transactions) {
+ let transactionIndex;
+ let fieldName;
+ let errorArray;
+ for (const key in errors) {
+ if (errors.hasOwnProperty(key)) {
+ if (key === 'group_title') {
+ console.error('Cannot handle error in group title.');
+ // todo handle group errors.
+ //this.group_title_errors = errors.errors[key];
+ continue;
+ }
+ transactionIndex = parseInt(key.split('.')[1]);
+ fieldName = key.split('.')[2];
+ errorArray = cleanupErrors(key, fieldName, errors[key]);
+ if (!transactions.hasOwnProperty(transactionIndex)) {
+ console.error('Cannot handle errors in index #' + transactionIndex);
+ continue;
+ }
+ switch (fieldName) {
+ case 'currency_code':
+ case 'foreign_currency_code':
+ case 'category_name':
+ case 'piggy_bank_id':
+ case 'notes':
+ case 'internal_reference':
+ case 'external_url':
+ case 'latitude':
+ case 'longitude':
+ case 'zoom_level':
+ case 'interest_date':
+ case 'book_date':
+ case 'process_date':
+ case 'due_date':
+ case 'payment_date':
+ case 'invoice_date':
+ case 'amount':
+ case 'date':
+ case 'budget_id':
+ case 'bill_id':
+ case 'description':
+ case 'tags':
+ transactions[transactionIndex].errors[fieldName] = errorArray;
+ break;
+ case 'source_name':
+ case 'source_id':
+ transactions[transactionIndex].errors.source_account = transactions[transactionIndex].errors.source_account.concat(errorArray);
+ break;
+ case 'type':
+ // add custom error to source and destination account
+ transactions[transactionIndex].errors.source_account = transactions[transactionIndex].errors.source_account.concat([i18next.t('validation.bad_type_source')]);
+ transactions[transactionIndex].errors.destination_account = transactions[transactionIndex].errors.destination_account.concat([i18next.t('validation.bad_type_destination')]);
+ break;
+ case 'destination_name':
+ case 'destination_id':
+ transactions[transactionIndex].errors.destination_account = transactions[transactionIndex].errors.destination_account.concat(errorArray);
+ break;
+ case 'foreign_amount':
+ case 'foreign_currency_id':
+ transactions[transactionIndex].errors.foreign_amount = transactions[transactionIndex].errors.foreign_amount.concat(errorArray);
+ break;
+ }
+ // unique some errors.
+ if (typeof transactions[transactionIndex] !== 'undefined') {
+ transactions[transactionIndex].errors.source_account = Array.from(new Set(transactions[transactionIndex].errors.source_account));
+ transactions[transactionIndex].errors.destination_account = Array.from(new Set(transactions[transactionIndex].errors.destination_account));
+ }
+ }
+ }
+ console.log(transactions[0].errors);
+
+ return transactions;
+
+}
diff --git a/resources/assets/v3/vite.config.js b/resources/assets/v3/vite.config.js
index e387aa6430..a7ddff822f 100644
--- a/resources/assets/v3/vite.config.js
+++ b/resources/assets/v3/vite.config.js
@@ -61,6 +61,7 @@ export default defineConfig(({command, mode, isSsrBuild, isPreview}) => {
// transactions
'js/pages/transactions/index.js',
+ 'js/pages/transactions/create.js',
// piggy banks
'js/pages/piggy-banks/index.js',
diff --git a/resources/views/components/transaction/messages.blade.php b/resources/views/components/transaction/messages.blade.php
new file mode 100644
index 0000000000..2d90bd8d00
--- /dev/null
+++ b/resources/views/components/transaction/messages.blade.php
@@ -0,0 +1,33 @@
+<div class="row mb-2">
+ <div class="col">
+ <template x-if="notifications.success.show">
+ <div class="alert alert-success alert-dismissible fade show" role="alert">
+ <template x-if="notifications.success.url != ''">
+ <a :href="notifications.success.url" class="alert-link" x-text="notifications.success.text"></a>
+ </template>
+ <template x-if="notifications.success.url == ''">
+ <span x-text="notifications.success.text"></span>
+ </template>
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('firefly.close') }}"></button>
+ </div>
+ </template>
+ <template x-if="notifications.error.show">
+ <div class="alert alert-danger alert-dismissible fade show" role="alert">
+ <template x-if="notifications.error.url != ''">
+ <a :href="notifications.error.url" class="alert-link" x-text="notifications.error.text"></a>
+ </template>
+ <template x-if="notifications.error.url == ''">
+ <span x-text="notifications.error.text"></span>
+ </template>
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('firefly.close') }}"></button>
+ </div>
+ </template>
+ <template x-if="notifications.wait.show">
+ <div class="alert alert-info alert-dismissible fade show" role="alert">
+ <em class="fa-solid fa-spinner fa-spin"></em>
+ <span x-text="notifications.wait.text"></span>
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ __('firefly.close') }}"></button>
+ </div>
+ </template>
+ </div>
+</div>
diff --git a/resources/views/components/transaction/split.blade.php b/resources/views/components/transaction/split.blade.php
new file mode 100644
index 0000000000..a3252a64d5
--- /dev/null
+++ b/resources/views/components/transaction/split.blade.php
@@ -0,0 +1,130 @@
+<div :class="{'tab-pane fade pt-2':true, 'show active': index ===0}" :id="'split-'+index+'-pane'" role="tabpanel" :aria-labelledby="'split-'+index+'-tab'" tabindex="0" x-init="addedSplit()">
+ <div class="row mb-2">
+ <div class="col-xl-6 col-lg-6 col-md-12 col-xs-12 mb-2">
+ <!-- BASIC TRANSACTION INFORMATION -->
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title">{{ __('firefly.basic_journal_information') }}</h3>
+ </div>
+ <div class="card-body">
+ <!-- DESCRIPTION -->
+ include('partials.form.transaction.description')
+
+ <!-- SOURCE ACCOUNT -->
+ include('partials.form.transaction.source-account')
+
+ <!-- DESTINATION ACCOUNT -->
+ include('partials.form.transaction.destination-account')
+
+ <!-- DATE AND TIME -->
+ include('partials.form.transaction.date-time')
+ </div>
+ </div>
+ </div>
+ <div class="col-xl-6 col-lg-6 col-md-12 col-xs-12 mb-2">
+
+ <!-- AMOUNTS -->
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title">
+ {{ __('firefly.transaction_journal_amount') }}
+ </h3>
+ </div>
+ <div class="card-body">
+ <!-- AMOUNT -->
+ include('partials.form.transaction.amount')
+
+ <!-- FOREIGN AMOUNT -->
+ include('partials.form.transaction.foreign-amount')
+ </div>
+ </div>
+ </div>
+ <!-- META DATA -->
+ <div class="col-xl-4 col-lg-6 col-md-12 col-xs-12 mb-2">
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title">
+ {{ __('firefly.transaction_journal_meta') }}
+ </h3>
+ </div>
+ <div class="card-body">
+ <!-- BUDGET -->
+ include('partials.form.transaction.budget')
+
+ <!-- CATEGORY -->
+ include('partials.form.transaction.category')
+
+ <!-- PIGGY BANK -->
+ include('partials.form.transaction.piggy-bank')
+
+ <!-- SUBSCRIPTION -->
+ include('partials.form.transaction.subscription')
+
+ <!-- TAGS -->
+ include('partials.form.transaction.tags')
+
+ <!-- NOTES -->
+ include('partials.form.transaction.notes')
+ </div>
+ </div>
+
+ </div>
+ <!-- EXTRA THINGS -->
+ <div class="col-xl-4 col-lg-6 col-md-12 col-xs-12 mb-2">
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title">
+ {{ __('firefly.transaction_journal_extra') }}
+ </h3>
+ </div>
+ <div class="card-body">
+ <!-- ATTACHMENTS -->
+ include('partials.form.transaction.attachments')
+
+ <!-- INTERNAL REFERENCE -->
+ include('partials.form.transaction.internal-reference')
+
+ <!-- EXTERNAL URL -->
+ include('partials.form.transaction.external-url')
+
+ <!-- LOCATION -->
+ include('partials.form.transaction.location')
+
+ <!-- DATE FIELDS -->
+ include('partials.form.transaction.date-fields')
+ </div>
+ </div>
+ </div>
+ <div class="col-xl-4 col-lg-6 col-md-12 col-xs-12 mb-2">
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title">
+ {{ __('firefly.submission_options') }}
+ </h3>
+ </div>
+ <div class="card-body">
+ include('partials.form.transaction.submission-options')
+ </div>
+ <div class="card-footer">
+ <div class="row">
+ <div class="col text-end">
+ <div class="btn-group">
+ <button @click="addSplit()" class="btn btn-secondary"
+ :disabled="formStates.isSubmitting">{{ __('firefly.add_another_split') }}</button>
+ <template x-if="1 !== entries.length">
+ <button :disabled="formStates.isSubmitting" class="btn btn-danger text-white"
+ @click="removeSplit(index)">{{ __('firefly.transaction_remove_split') }}</button>
+ </template>
+ <button class="btn btn-success text-white" :disabled="formStates.isSubmitting"
+ @click="submitTransaction()">{{ __('firefly.submit') }}</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="col-12">
+
+ </div>
+ </div>
+</div>
diff --git a/resources/views/components/transaction/tab-list.blade.php b/resources/views/components/transaction/tab-list.blade.php
new file mode 100644
index 0000000000..ebe95b5fd2
--- /dev/null
+++ b/resources/views/components/transaction/tab-list.blade.php
@@ -0,0 +1,32 @@
+<div class="row">
+ <div class="col">
+ <ul class="nav nav-tabs" id="splitTabs" role="tablist">
+ <template x-for="transaction,index in entries">
+ <li class="nav-item" role="presentation">
+ <button :id="'split-'+index+'-tab'"
+ :class="{'nav-link': true, 'active': index === 0 }"
+ data-bs-toggle="tab"
+ :data-bs-target="'#split-'+index+'-pane'"
+ type="button" role="tab"
+ :aria-controls="'split-'+index+'-pane'"
+ aria-selected="true">{{ __('firefly.single_split') }} #
+ <span x-text="index+1"></span>
+ </button>
+ </li>
+ </template>
+ <li class="nav-item" role="presentation">
+ <button class="nav-link" type="button" role="tab" @click="addSplit()"
+ ><em class="fa-solid fa-plus-circle"></em>
+ </button>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" aria-disabled="true">
+ {{ __('firefly.total') }}:
+ <span x-text="formattedTotalAmount()"></span>
+ </a>
+ </li>
+
+
+ </ul>
+ </div>
+</div>
diff --git a/resources/views/layout/v3/session.blade.php b/resources/views/layout/v3/session.blade.php
index 82e60a7d13..aa13fa96bd 100644
--- a/resources/views/layout/v3/session.blade.php
+++ b/resources/views/layout/v3/session.blade.php
@@ -107,14 +107,6 @@
<span class="d-none d-xxl-inline">xxl</span>
</span>
</li>
- <!--begin::Navbar Search-->
- <li class="nav-item">
- <a class="nav-link" data-widget="navbar-search" href="{{route('search.index')}}" role="button">
- <em class="bi bi-search"></em>
- </a>
- </li>
- <!--end::Navbar Search-->
-
<!--begin::Fullscreen Toggle-->
<li class="nav-item">
<a class="nav-link" href="#" data-lte-toggle="fullscreen">
diff --git a/resources/views/transactions/create.blade.php b/resources/views/transactions/create.blade.php
new file mode 100644
index 0000000000..94ff1b350a
--- /dev/null
+++ b/resources/views/transactions/create.blade.php
@@ -0,0 +1,21 @@
+@extends('layout.v3.session')
+@section('content')
+<div x-data="create" id="form">
+ <x-transaction.messages />
+ <x-transaction.tab-list />
+ <div class="tab-content" id="splitTabsContent">
+ <template x-for="transaction, index in entries">
+ <x-transaction.split
+ :zoomLevel="$zoomLevel"
+ :latitude="$latitude"
+ :longitude="$longitude"
+ :optionalFields="$optionalFields"
+ :optionalDateFields="$optionalDateFields" />
+ </template>
+ </div>
+ </div>
+
+@endsection
+@section('scripts')
+ @vite(['js/pages/transactions/create.js'])
+@endsection
diff --git a/resources/views/transactions/create.twig b/resources/views/transactions/old-create.twig
similarity index 100%
rename from resources/views/transactions/create.twig
rename to resources/views/transactions/old-create.twig