mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand new transaction form.
This commit is contained in:
parent
e6fe08dd61
commit
211526c032
@ -28,6 +28,7 @@ use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Rules\BelongsUserGroup;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Rules\IsDateOrTime;
|
||||
use FireflyIII\Rules\IsValidPositiveAmount;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use FireflyIII\Support\Request\AppendsLocationData;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
@ -74,7 +75,6 @@ class StoreRequest extends FormRequest
|
||||
'fire_webhooks' => $this->boolean('fire_webhooks', true),
|
||||
'transactions' => $this->getTransactionData(),
|
||||
];
|
||||
// TODO include location and ability to process it.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,8 +107,8 @@ class StoreRequest extends FormRequest
|
||||
'transactions.*.foreign_currency_code' => 'min:3|max:51|exists:transaction_currencies,code|nullable',
|
||||
|
||||
// amount
|
||||
'transactions.*.amount' => 'required|numeric|gt:0|max:1000000000',
|
||||
'transactions.*.foreign_amount' => 'numeric|gt:0|max:1000000000',
|
||||
'transactions.*.amount' => ['required', new IsValidPositiveAmount()],
|
||||
'transactions.*.foreign_amount' => ['nullable', new IsValidPositiveAmount()],
|
||||
|
||||
// description
|
||||
'transactions.*.description' => 'nullable|between:1,1000',
|
||||
@ -140,7 +140,8 @@ class StoreRequest extends FormRequest
|
||||
// other interesting fields
|
||||
'transactions.*.reconciled' => [new IsBoolean()],
|
||||
'transactions.*.notes' => 'min:1|max:50000|nullable',
|
||||
'transactions.*.tags' => 'between:0,255',
|
||||
'transactions.*.tags' => 'between:0,1024',
|
||||
'transactions.*.tags*' => 'between:0,1024',
|
||||
|
||||
// meta info fields
|
||||
'transactions.*.internal_reference' => 'min:1|max:255|nullable',
|
||||
@ -166,6 +167,9 @@ class StoreRequest extends FormRequest
|
||||
'transactions.*.due_date' => 'date|nullable',
|
||||
'transactions.*.payment_date' => 'date|nullable',
|
||||
'transactions.*.invoice_date' => 'date|nullable',
|
||||
|
||||
// TODO include location and ability to process it.
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@ -222,7 +226,7 @@ class StoreRequest extends FormRequest
|
||||
*/
|
||||
foreach ($this->get('transactions') as $transaction) {
|
||||
$object = new NullArrayObject($transaction);
|
||||
$return[] = [
|
||||
$result= [
|
||||
'type' => $this->clearString($object['type']),
|
||||
'date' => $this->dateFromValue($object['date']),
|
||||
'order' => $this->integerFromValue((string)$object['order']),
|
||||
@ -300,6 +304,8 @@ class StoreRequest extends FormRequest
|
||||
'payment_date' => $this->dateFromValue($object['payment_date']),
|
||||
'invoice_date' => $this->dateFromValue($object['invoice_date']),
|
||||
];
|
||||
$result = $this->addFromromTransactionStore($transaction, $result);
|
||||
$return[] = $result;
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
@ -28,6 +28,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\DuplicateTransactionException;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -318,10 +319,23 @@ class TransactionJournalFactory
|
||||
$this->storePiggyEvent($journal, $row);
|
||||
$this->storeTags($journal, $row['tags']);
|
||||
$this->storeMetaFields($journal, $row);
|
||||
$this->storeLocation($journal, $row);
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
private function storeLocation(TransactionJournal $journal, NullArrayObject $data): void
|
||||
{
|
||||
if (true === $data['store_location']) {
|
||||
$location = new Location();
|
||||
$location->longitude = $data['longitude'];
|
||||
$location->latitude = $data['latitude'];
|
||||
$location->zoom_level = $data['zoom_level'];
|
||||
$location->locatable()->associate($journal);
|
||||
$location->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function hashArray(NullArrayObject $row): string
|
||||
{
|
||||
$dataRow = $row->getArrayCopy();
|
||||
@ -360,16 +374,12 @@ class TransactionJournalFactory
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('data', json_encode($hash, JSON_THROW_ON_ERROR))
|
||||
->with(['transactionJournal', 'transactionJournal.transactionGroup'])
|
||||
->first()
|
||||
;
|
||||
->first(['journal_meta.*']);
|
||||
if (null !== $result) {
|
||||
app('log')->warning(sprintf('Found a duplicate in errorIfDuplicate because hash %s is not unique!', $hash));
|
||||
$journal = $result->transactionJournal()->withTrashed()->first();
|
||||
$group = $journal?->transactionGroup()->withTrashed()->first();
|
||||
$groupId = $group?->id;
|
||||
if (null === $group) {
|
||||
$groupId = 0;
|
||||
}
|
||||
$groupId = (int) $group?->id;
|
||||
|
||||
throw new DuplicateTransactionException(sprintf('Duplicate of transaction #%d.', $groupId));
|
||||
}
|
||||
|
@ -93,12 +93,14 @@ class Location extends Model
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the accounts.
|
||||
*/
|
||||
public function accounts(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Account::class, 'noteable');
|
||||
return $this->morphMany(Account::class, 'locatable');
|
||||
}
|
||||
|
||||
public function transactionJournals(): MorphMany
|
||||
{
|
||||
return $this->morphMany(TransactionJournal::class, 'locatable');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,6 +119,40 @@ trait AppendsLocationData
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $information
|
||||
* @param array $return
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addFromromTransactionStore(array $information, array $return): array
|
||||
{
|
||||
$return['store_location'] = false;
|
||||
if (true === $information['store_location']) {
|
||||
$long = array_key_exists('longitude', $information) ? $information['longitude'] : null;
|
||||
$lat = array_key_exists('latitude', $information) ? $information['latitude'] : null;
|
||||
if (null !== $long && null !== $lat && $this->validLongitude($long) && $this->validLatitude($lat)) {
|
||||
$return['store_location'] = true;
|
||||
$return['longitude'] = $information['longitude'];
|
||||
$return['latitude'] = $information['latitude'];
|
||||
$return['zoom_level'] = $information['zoom_level'];
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function validLongitude(string $longitude): bool
|
||||
{
|
||||
$number = (float) $longitude;
|
||||
return $number >= -180 && $number <= 180;
|
||||
}
|
||||
|
||||
private function validLatitude(string $latitude): bool
|
||||
{
|
||||
$number = (float) $latitude;
|
||||
return $number >= -90 && $number <= 90;
|
||||
}
|
||||
|
||||
private function getLocationKey(?string $prefix, string $key): string
|
||||
{
|
||||
if (null === $prefix) {
|
||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Transformers\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -47,11 +48,11 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
private TransactionCurrency $default;
|
||||
private array $meta;
|
||||
private array $notes;
|
||||
private array $locations;
|
||||
private array $tags;
|
||||
|
||||
public function collectMetaData(Collection $objects): void
|
||||
{
|
||||
// start with currencies:
|
||||
$currencies = [];
|
||||
$journals = [];
|
||||
|
||||
@ -89,12 +90,20 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
$this->notes[$id] = $note;
|
||||
}
|
||||
|
||||
// grab all locations for all journals:
|
||||
$locations = Location::whereLocatableType(TransactionJournal::class)->whereIn('locatable_id', array_keys($journals))->get();
|
||||
|
||||
/** @var Location $location */
|
||||
foreach ($locations as $location) {
|
||||
$id = $location->locatable_id;
|
||||
$this->locations[$id] = $location;
|
||||
}
|
||||
|
||||
// grab all tags for all journals:
|
||||
$tags = DB::table('tag_transaction_journal')
|
||||
->leftJoin('tags', 'tags.id', 'tag_transaction_journal.tag_id')
|
||||
->whereIn('tag_transaction_journal.transaction_journal_id', array_keys($journals))
|
||||
->get(['tag_transaction_journal.transaction_journal_id', 'tags.tag'])
|
||||
;
|
||||
->get(['tag_transaction_journal.transaction_journal_id', 'tags.tag']);
|
||||
|
||||
/** @var \stdClass $tag */
|
||||
foreach ($tags as $tag) {
|
||||
@ -167,6 +176,17 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
}
|
||||
$this->converter->summarize();
|
||||
|
||||
$longitude = null;
|
||||
$latitude = null;
|
||||
$zoomLevel = null;
|
||||
if (array_key_exists($journalId, $this->locations)) {
|
||||
/** @var Location $location */
|
||||
$location = $this->locations[$journalId];
|
||||
$latitude = (string) $location->latitude;
|
||||
$longitude = (string) $location->longitude;
|
||||
$zoomLevel = $location->zoom_level;
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => (string) $transaction['user_id'],
|
||||
'user_group' => (string) $transaction['user_group_id'],
|
||||
@ -241,9 +261,9 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'invoice_date' => $this->date($meta['invoice_date']),
|
||||
|
||||
// location data
|
||||
// 'longitude' => $longitude,
|
||||
// 'latitude' => $latitude,
|
||||
// 'zoom_level' => $zoomLevel,
|
||||
'longitude' => $longitude,
|
||||
'latitude' => $latitude,
|
||||
'zoom_level' => $zoomLevel,
|
||||
//
|
||||
// 'has_attachments' => $this->hasAttachments((int) $row['transaction_journal_id']),
|
||||
];
|
||||
|
@ -25,6 +25,8 @@ export default class Preferences {
|
||||
return api.get('/api/v1/preferences/' + name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
getByNameNow(name) {
|
||||
return api.get('/api/v1/preferences/' + name);
|
||||
}
|
||||
|
@ -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: '© <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: '© <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: '© <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;
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user