Expand new transaction form.

This commit is contained in:
James Cole
2024-01-03 17:43:05 +01:00
parent e6fe08dd61
commit 211526c032
10 changed files with 262 additions and 100 deletions

View File

@@ -25,6 +25,8 @@ export default class Preferences {
return api.get('/api/v1/preferences/' + name);
}
getByNameNow(name) {
return api.get('/api/v1/preferences/' + name);
}

View File

@@ -40,6 +40,10 @@ import L from "leaflet";
import 'leaflet/dist/leaflet.css';
// TODO upload attachments to other file
// TODO fix two maps, perhaps disconnect from entries entirely.
// TODO group title
// TODO map location from preferences
let i18n;
@@ -186,7 +190,7 @@ let transactions = function () {
budgets: [],
piggyBanks: {},
subscriptions: [],
dateFields: ['interest_date','book_date','process_date','due_date','payment_date','invoice_date'],
dateFields: ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'],
foreignAmountEnabled: true,
filters: {
@@ -754,19 +758,41 @@ let transactions = function () {
let fieldName;
// todo add 'was-validated' to form.
console.log('Now processing errors.');
for (const key in data.errors) {
if (data.errors.hasOwnProperty(key)) {
if (key === 'group_title') {
console.log('Handling group title error.');
// todo handle group errors.
//this.group_title_errors = errors.errors[key];
}
if (key !== 'group_title') {
console.log('Handling errors for ' + key);
// lol, the dumbest way to explode "transactions.0.something" ever.
transactionIndex = parseInt(key.split('.')[1]);
fieldName = key.split('.')[2];
console.log('Transaction index: ' + transactionIndex);
console.log('Field name: ' + fieldName);
console.log('Errors');
console.log(data.errors[key]);
// set error in this object thing.
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':
@@ -779,6 +805,10 @@ let transactions = function () {
case 'source_id':
this.entries[transactionIndex].errors.source_account = this.entries[transactionIndex].errors.source_account.concat(data.errors[key]);
break;
case 'type':
// put the error in the description:
this.entries[transactionIndex].errors.description = this.entries[transactionIndex].errors.source_account.concat(data.errors[key]);
break;
case 'destination_name':
case 'destination_id':
this.entries[transactionIndex].errors.destination_account = this.entries[transactionIndex].errors.destination_account.concat(data.errors[key]);
@@ -810,6 +840,7 @@ let transactions = function () {
server: urls.tag,
liveServer: true,
clearEnd: true,
allowNew: true,
notFoundMessage: '(nothing found)',
noCache: true,
fetchOptions: {
@@ -819,14 +850,28 @@ let transactions = function () {
}
});
const count = this.entries.length - 1;
this.entries[count].map = L.map('mappie').setView([this.latitude, this.longitude], this.zoomLevel);
//let map = L.map('location_map_' + count).setView([this.latitude, this.longitude], this.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(this.entries[count].map);
this.entries[count].map.on('click', this.addPointToMap);
this.entries[count].map.on('zoomend', this.saveZoomOfMap);
// L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
// maxZoom: 19,
// attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap '+count+'</a>'
// }).addTo(map);
// map.on('click', this.addPointToMap);
// map.on('zoomend', this.saveZoomOfMap);
const id = 'location_map_' + count;
const map = () => {
const el = document.getElementById(id),
map = L.map(id).setView([this.latitude, this.longitude], this.zoomLevel)
L.tileLayer(
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
{attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap '+count+'</a>'}
).addTo(map)
map.on('click', this.addPointToMap);
map.on('zoomend', this.saveZoomOfMap);
return map
}
this.entries[count].map = map();
}, 250);
@@ -878,13 +923,6 @@ let transactions = function () {
document.querySelector('#form')._x_dataStack[0].$data.entries[index].longitude = e.latlng.lng;
document.querySelector('#form')._x_dataStack[0].$data.entries[index].zoomLevel = map.getZoom();
}
//this.entries[index].hasLocation = true;
// map.on('click', function (e) {
// if (false === this.hasLocation) {
// let marker = new L.marker(e.latlng).addTo(map);
// this.hasLocation = true;
// }
// });
}
}
}

View File

@@ -76,11 +76,43 @@ export function createEmptySplit() {
invoice_date: '',
errors: {
'amount': [],
'foreign_amount': [],
'budget_id': [],
'category_name': [],
'piggy_bank_id': [],
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: [],
},
};
}

View File

@@ -55,14 +55,24 @@ export function parseFromEntries(entries, transactionType) {
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;

View File

@@ -343,6 +343,7 @@
<select
class="form-select ac-tags"
:id="'tags_' + index"
x-model="transaction.tags"
:name="'tags['+index+'][]'"
multiple>
<option value="">Type a tag...</option>
@@ -406,12 +407,19 @@
<i class="fa-solid fa-link"></i>
</label>
<div class="col-sm-10">
<input type="search"
<input type="text"
class="form-control"
:id="'external_url_' + index"
x-model="transaction.external_url"
:data-index="index"
placeholder="{{ __('firefly.external_url') }}">
:class="{'is-invalid': transaction.errors.external_url.length > 0, 'form-control': true}"
placeholder="{{ __('firefly.external_url') }}" />
<template x-if="transaction.errors.external_url.length > 0">
<div class="invalid-feedback"
x-text="transaction.errors.external_url[0]">
</div>
</template>
</div>
</div>
<div class="row mb-3">
@@ -420,7 +428,7 @@
<i class="fa-solid fa-earth-europe"></i>
</label>
<div class="col-sm-10">
<div id="mappie" style="height:300px;" :data-index="index"></div>
<div :id="'location_map_' + index" style="height:300px;" :data-index="index"></div>
<span class="muted small">
<template x-if="!transaction.hasLocation">
<span>Tap the map to add a location</span>