mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand edit transaction form.
This commit is contained in:
parent
bd2ecb13b8
commit
2e0d90c685
44
app/Api/V2/Controllers/Model/Transaction/ShowController.php
Normal file
44
app/Api/V2/Controllers/Model/Transaction/ShowController.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* ShowController.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V2\Controllers\Model\Transaction;
|
||||
|
||||
use FireflyIII\Api\V2\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Transformers\V2\TransactionGroupTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ShowController extends Controller
|
||||
{
|
||||
/**
|
||||
* TODO this endpoint is not yet reachable.
|
||||
*/
|
||||
public function show(TransactionGroup $transactionGroup): JsonResponse
|
||||
{
|
||||
$transformer = new TransactionGroupTransformer();
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
return response()->api($this->jsonApiObject('transactions', $transactionGroup, $transformer))->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
}
|
@ -25,7 +25,6 @@ namespace FireflyIII\Helpers\Collector;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\Exceptions\InvalidFormatException;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\Extensions\AccountCollection;
|
||||
use FireflyIII\Helpers\Collector\Extensions\AmountCollection;
|
||||
@ -62,12 +61,12 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->postFilters = [];
|
||||
$this->tags = [];
|
||||
$this->user = null;
|
||||
$this->userGroup = null;
|
||||
$this->limit = null;
|
||||
$this->page = null;
|
||||
$this->postFilters = [];
|
||||
$this->tags = [];
|
||||
$this->user = null;
|
||||
$this->userGroup = null;
|
||||
$this->limit = null;
|
||||
$this->page = null;
|
||||
|
||||
$this->hasAccountInfo = false;
|
||||
$this->hasCatInformation = false;
|
||||
@ -106,6 +105,9 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transaction_groups.created_at as created_at',
|
||||
'transaction_groups.updated_at as updated_at',
|
||||
'transaction_groups.title as transaction_group_title',
|
||||
'transaction_groups.created_at as group_created_at',
|
||||
'transaction_groups.updated_at as group_updated_at',
|
||||
|
||||
|
||||
// journal
|
||||
'transaction_journals.id as transaction_journal_id',
|
||||
@ -285,9 +287,9 @@ class GroupCollector implements GroupCollectorInterface
|
||||
foreach ($params as $param) {
|
||||
$replace = sprintf('"%s"', $param);
|
||||
if (is_int($param)) {
|
||||
$replace = (string)$param;
|
||||
$replace = (string) $param;
|
||||
}
|
||||
$pos = strpos($query, '?');
|
||||
$pos = strpos($query, '?');
|
||||
if (false !== $pos) {
|
||||
$query = substr_replace($query, $replace, $pos, 1);
|
||||
}
|
||||
@ -455,13 +457,13 @@ class GroupCollector implements GroupCollectorInterface
|
||||
// add to query:
|
||||
$this->query->orWhereIn('transaction_journals.transaction_group_id', $groupIds);
|
||||
}
|
||||
$result = $this->query->get($this->fields);
|
||||
$result = $this->query->get($this->fields);
|
||||
|
||||
// now to parse this into an array.
|
||||
$collection = $this->parseArray($result);
|
||||
$collection = $this->parseArray($result);
|
||||
|
||||
// filter the array using all available post filters:
|
||||
$collection = $this->postFilterCollection($collection);
|
||||
$collection = $this->postFilterCollection($collection);
|
||||
|
||||
// count it and continue:
|
||||
$this->total = $collection->count();
|
||||
@ -667,12 +669,11 @@ class GroupCollector implements GroupCollectorInterface
|
||||
// include source + destination account name and type.
|
||||
$this->withAccountInformation()
|
||||
// include category ID + name (if any)
|
||||
->withCategoryInformation()
|
||||
->withCategoryInformation()
|
||||
// include budget ID + name (if any)
|
||||
->withBudgetInformation()
|
||||
->withBudgetInformation()
|
||||
// include bill ID + name (if any)
|
||||
->withBillInformation()
|
||||
;
|
||||
->withBillInformation();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -691,24 +692,26 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/** @var TransactionJournal $augumentedJournal */
|
||||
foreach ($collection as $augumentedJournal) {
|
||||
$groupId = (int)$augumentedJournal->transaction_group_id;
|
||||
$groupId = (int) $augumentedJournal->transaction_group_id;
|
||||
|
||||
if (!array_key_exists($groupId, $groups)) {
|
||||
// make new array
|
||||
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
|
||||
$groupArray = [
|
||||
'id' => (int)$augumentedJournal->transaction_group_id,
|
||||
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
|
||||
$groupArray = [
|
||||
'id' => (int) $augumentedJournal->transaction_group_id,
|
||||
'user_id' => $augumentedJournal->user_id,
|
||||
'user_group_id' => $augumentedJournal->user_group_id,
|
||||
// Field transaction_group_title was added by the query.
|
||||
'title' => $augumentedJournal->transaction_group_title, // @phpstan-ignore-line
|
||||
'created_at' => new Carbon($augumentedJournal->group_created_at, config('app.timezone')),
|
||||
'updated_at' => new Carbon($augumentedJournal->group_updated_at, config('app.timezone')),
|
||||
'transaction_type' => $parsedGroup['transaction_type_type'],
|
||||
'count' => 1,
|
||||
'sums' => [],
|
||||
'transactions' => [],
|
||||
];
|
||||
// Field transaction_journal_id was added by the query.
|
||||
$journalId = (int)$augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
|
||||
$journalId = (int) $augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
|
||||
$groupArray['transactions'][$journalId] = $parsedGroup;
|
||||
$groups[$groupId] = $groupArray;
|
||||
|
||||
@ -716,7 +719,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
// or parse the rest.
|
||||
// Field transaction_journal_id was added by the query.
|
||||
$journalId = (int)$augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
|
||||
$journalId = (int) $augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
|
||||
if (array_key_exists($journalId, $groups[$groupId]['transactions'])) {
|
||||
// append data to existing group + journal (for multiple tags or multiple attachments)
|
||||
$groups[$groupId]['transactions'][$journalId] = $this->mergeTags($groups[$groupId]['transactions'][$journalId], $augumentedJournal);
|
||||
@ -766,24 +769,24 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
// try to process meta date value (if present)
|
||||
$dates = ['interest_date', 'payment_date', 'invoice_date', 'book_date', 'due_date', 'process_date'];
|
||||
$dates = ['interest_date', 'payment_date', 'invoice_date', 'book_date', 'due_date', 'process_date'];
|
||||
if (array_key_exists('meta_name', $result) && in_array($result['meta_name'], $dates, true)) {
|
||||
$name = $result['meta_name'];
|
||||
if (array_key_exists('meta_data', $result) && '' !== (string)$result['meta_data']) {
|
||||
if (array_key_exists('meta_data', $result) && '' !== (string) $result['meta_data']) {
|
||||
$result[$name] = Carbon::createFromFormat('!Y-m-d', substr(json_decode($result['meta_data']), 0, 10));
|
||||
}
|
||||
}
|
||||
|
||||
// convert values to integers:
|
||||
$result = $this->convertToInteger($result);
|
||||
$result = $this->convertToInteger($result);
|
||||
|
||||
// convert back to strings because SQLite is dumb like that.
|
||||
$result = $this->convertToStrings($result);
|
||||
$result = $this->convertToStrings($result);
|
||||
|
||||
$result['reconciled'] = 1 === (int)$result['reconciled'];
|
||||
$result['reconciled'] = 1 === (int) $result['reconciled'];
|
||||
if (array_key_exists('tag_id', $result) && null !== $result['tag_id']) { // assume the other fields are present as well.
|
||||
$tagId = (int)$augumentedJournal['tag_id'];
|
||||
$tagDate = null;
|
||||
$tagId = (int) $augumentedJournal['tag_id'];
|
||||
$tagDate = null;
|
||||
|
||||
try {
|
||||
$tagDate = Carbon::parse($augumentedJournal['tag_date']);
|
||||
@ -792,7 +795,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
$result['tags'][$tagId] = [
|
||||
'id' => (int)$result['tag_id'],
|
||||
'id' => (int) $result['tag_id'],
|
||||
'name' => $result['tag_name'],
|
||||
'date' => $tagDate,
|
||||
'description' => $result['tag_description'],
|
||||
@ -801,8 +804,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
// also merge attachments:
|
||||
if (array_key_exists('attachment_id', $result)) {
|
||||
$uploaded = 1 === (int)$result['attachment_uploaded'];
|
||||
$attachmentId = (int)$augumentedJournal['attachment_id'];
|
||||
$uploaded = 1 === (int) $result['attachment_uploaded'];
|
||||
$attachmentId = (int) $augumentedJournal['attachment_id'];
|
||||
if (0 !== $attachmentId && $uploaded) {
|
||||
$result['attachments'][$attachmentId] = [
|
||||
'id' => $attachmentId,
|
||||
@ -828,7 +831,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
private function convertToInteger(array $array): array
|
||||
{
|
||||
foreach ($this->integerFields as $field) {
|
||||
$array[$field] = array_key_exists($field, $array) ? (int)$array[$field] : null;
|
||||
$array[$field] = array_key_exists($field, $array) ? (int) $array[$field] : null;
|
||||
}
|
||||
|
||||
return $array;
|
||||
@ -837,7 +840,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
private function convertToStrings(array $array): array
|
||||
{
|
||||
foreach ($this->stringFields as $field) {
|
||||
$array[$field] = array_key_exists($field, $array) && null !== $array[$field] ? (string)$array[$field] : null;
|
||||
$array[$field] = array_key_exists($field, $array) && null !== $array[$field] ? (string) $array[$field] : null;
|
||||
}
|
||||
|
||||
return $array;
|
||||
@ -847,9 +850,9 @@ class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
$newArray = $newJournal->toArray();
|
||||
if (array_key_exists('tag_id', $newArray)) { // assume the other fields are present as well.
|
||||
$tagId = (int)$newJournal['tag_id'];
|
||||
$tagId = (int) $newJournal['tag_id'];
|
||||
|
||||
$tagDate = null;
|
||||
$tagDate = null;
|
||||
|
||||
try {
|
||||
$tagDate = Carbon::parse($newArray['tag_date']);
|
||||
@ -858,7 +861,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
$existingJournal['tags'][$tagId] = [
|
||||
'id' => (int)$newArray['tag_id'],
|
||||
'id' => (int) $newArray['tag_id'],
|
||||
'name' => $newArray['tag_name'],
|
||||
'date' => $tagDate,
|
||||
'description' => $newArray['tag_description'],
|
||||
@ -872,7 +875,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
$newArray = $newJournal->toArray();
|
||||
if (array_key_exists('attachment_id', $newArray)) {
|
||||
$attachmentId = (int)$newJournal['attachment_id'];
|
||||
$attachmentId = (int) $newJournal['attachment_id'];
|
||||
|
||||
$existingJournal['attachments'][$attachmentId] = [
|
||||
'id' => $attachmentId,
|
||||
@ -891,7 +894,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
foreach ($groups as $groudId => $group) {
|
||||
/** @var array $transaction */
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$currencyId = (int)$transaction['currency_id'];
|
||||
$currencyId = (int) $transaction['currency_id'];
|
||||
if (null === $transaction['amount']) {
|
||||
throw new FireflyException(sprintf('Amount is NULL for a transaction in group #%d, please investigate.', $groudId));
|
||||
}
|
||||
@ -907,7 +910,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']);
|
||||
|
||||
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
|
||||
$currencyId = (int)$transaction['foreign_currency_id'];
|
||||
$currencyId = (int) $transaction['foreign_currency_id'];
|
||||
|
||||
// set default:
|
||||
if (!array_key_exists($currencyId, $groups[$groudId]['sums'])) {
|
||||
@ -936,7 +939,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
foreach ($this->postFilters as $function) {
|
||||
app('log')->debug('Applying filter...');
|
||||
$nextCollection = new Collection();
|
||||
$nextCollection = new Collection();
|
||||
|
||||
// loop everything in the current collection
|
||||
// and save it (or not) in the new collection.
|
||||
@ -951,11 +954,11 @@ class GroupCollector implements GroupCollectorInterface
|
||||
continue;
|
||||
}
|
||||
// if the result is a bool, use the unedited results.
|
||||
if(true === $result) {
|
||||
if (true === $result) {
|
||||
$nextCollection->push($item);
|
||||
}
|
||||
// if the result is an array, the filter has changed what's being returned.
|
||||
if(is_array($result)) {
|
||||
if (is_array($result)) {
|
||||
$nextCollection->push($result);
|
||||
}
|
||||
}
|
||||
@ -983,8 +986,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as source',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source.amount', '<', 0)
|
||||
;
|
||||
->where('source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
// join destination transaction
|
||||
@ -992,8 +994,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as destination',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination.amount', '>', 0)
|
||||
;
|
||||
->where('destination.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
// left join transaction type.
|
||||
@ -1008,8 +1009,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('source.amount', 'DESC')
|
||||
;
|
||||
->orderBy('source.amount', 'DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1027,8 +1027,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as source',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source.amount', '<', 0)
|
||||
;
|
||||
->where('source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
// join destination transaction
|
||||
@ -1036,8 +1035,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as destination',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination.amount', '>', 0)
|
||||
;
|
||||
->where('destination.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
// left join transaction type.
|
||||
@ -1052,7 +1050,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('source.amount', 'DESC')
|
||||
;
|
||||
->orderBy('source.amount', 'DESC');
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +88,40 @@ class EditController extends Controller
|
||||
$search = sprintf('?%s', $parts['query'] ?? '');
|
||||
$previousUrl = str_replace($search, '', $previousUrl);
|
||||
|
||||
// settings necessary for v2
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
if (!is_array($optionalFields)) {
|
||||
$optionalFields = [];
|
||||
}
|
||||
// not really a fan of this, but meh.
|
||||
$optionalDateFields = [
|
||||
'interest_date' => $optionalFields['interest_date'] ?? false,
|
||||
'book_date' => $optionalFields['book_date'] ?? false,
|
||||
'process_date' => $optionalFields['process_date'] ?? false,
|
||||
'due_date' => $optionalFields['due_date'] ?? false,
|
||||
'payment_date' => $optionalFields['payment_date'] ?? false,
|
||||
'invoice_date' => $optionalFields['invoice_date'] ?? false,
|
||||
];
|
||||
$optionalFields['external_url'] ??= false;
|
||||
$optionalFields['location'] ??= false;
|
||||
$optionalFields['location'] = $optionalFields['location'] && true === config('firefly.enable_external_map');
|
||||
|
||||
// map info:
|
||||
$longitude = config('firefly.default_location.longitude');
|
||||
$latitude = config('firefly.default_location.latitude');
|
||||
$zoomLevel = config('firefly.default_location.zoom_level');
|
||||
|
||||
return view(
|
||||
'transactions.edit',
|
||||
compact(
|
||||
'cash',
|
||||
'allowedSourceDests',
|
||||
'expectedSourceTypes',
|
||||
'optionalDateFields',
|
||||
'longitude',
|
||||
'latitude',
|
||||
'zoomLevel',
|
||||
'optionalFields',
|
||||
'subTitle',
|
||||
'subTitleIcon',
|
||||
'transactionGroup',
|
||||
|
@ -41,12 +41,12 @@ class UserGroupAccount implements BinderInterface
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$currency = Account::where('id', (int)$value)
|
||||
$account = Account::where('id', (int)$value)
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first()
|
||||
;
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
if (null !== $account) {
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
|
51
app/Support/Binder/UserGroupTransaction.php
Normal file
51
app/Support/Binder/UserGroupTransaction.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UserGroupTransaction.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class UserGroupTransaction.
|
||||
*/
|
||||
class UserGroupTransaction implements BinderInterface
|
||||
{
|
||||
public static function routeBinder(string $value, Route $route): TransactionGroup
|
||||
{
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$group = TransactionGroup::where('id', (int) $value)
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first();
|
||||
if (null !== $group) {
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
@ -26,9 +26,13 @@ namespace FireflyIII\Transformers\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
@ -36,108 +40,222 @@ use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class TransactionGroupTransformer
|
||||
*/
|
||||
class TransactionGroupTransformer extends AbstractTransformer
|
||||
{
|
||||
private ExchangeRateConverter $converter;
|
||||
private array $currencies = [];
|
||||
private array $accountTypes = []; // account types collection.
|
||||
private array $journals = []; // collection of all journals and some important meta-data.
|
||||
private array $objects = [];
|
||||
private array $currencies = []; // collection of all currencies for this transformer.
|
||||
private TransactionCurrency $default;
|
||||
private array $meta = [];
|
||||
private array $notes = [];
|
||||
private array $locations = [];
|
||||
private array $tags = [];
|
||||
private ExchangeRateConverter $converter;
|
||||
|
||||
// private array $currencies = [];
|
||||
// private array $transactionTypes = [];
|
||||
// private array $meta = [];
|
||||
// private array $notes = [];
|
||||
// private array $locations = [];
|
||||
// private array $tags = [];
|
||||
// private array $amounts = [];
|
||||
// private array $foreignAmounts = [];
|
||||
// private array $journalCurrencies = [];
|
||||
// private array $foreignCurrencies = [];
|
||||
|
||||
public function collectMetaData(Collection $objects): void
|
||||
{
|
||||
$currencies = [];
|
||||
$journals = [];
|
||||
|
||||
$collectForObjects = false;
|
||||
/** @var array $object */
|
||||
foreach ($objects as $object) {
|
||||
foreach ($object['sums'] as $sum) {
|
||||
$id = (int) $sum['currency_id'];
|
||||
$currencies[$id] ??= TransactionCurrency::find($sum['currency_id']);
|
||||
if (is_array($object)) {
|
||||
$this->collectForArray($object);
|
||||
}
|
||||
|
||||
/** @var array $transaction */
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
$id = (int) $transaction['transaction_journal_id'];
|
||||
$journals[$id] = [];
|
||||
if ($object instanceof TransactionGroup) {
|
||||
$this->collectForObject($object);
|
||||
$collectForObjects = true;
|
||||
}
|
||||
}
|
||||
$this->currencies = $currencies;
|
||||
$this->default = app('amount')->getDefaultCurrency();
|
||||
|
||||
// grab meta for all journals:
|
||||
$meta = TransactionJournalMeta::whereIn('transaction_journal_id', array_keys($journals))->get();
|
||||
$this->default = app('amount')->getDefaultCurrency();
|
||||
$this->converter = new ExchangeRateConverter();
|
||||
|
||||
$this->collectAllMetaData();
|
||||
$this->collectAllNotes();
|
||||
$this->collectAllLocations();
|
||||
$this->collectAllTags();
|
||||
if ($collectForObjects) {
|
||||
$this->collectAllCurrencies();
|
||||
// $this->collectAllAmounts();
|
||||
// $this->collectTransactionTypes();
|
||||
// $this->collectAccounts();
|
||||
// source accounts
|
||||
// destination accounts
|
||||
|
||||
/** @var TransactionJournalMeta $entry */
|
||||
foreach ($meta as $entry) {
|
||||
$id = $entry->transaction_journal_id;
|
||||
$this->meta[$id][$entry->name] = $entry->data;
|
||||
}
|
||||
|
||||
// grab all notes for all journals:
|
||||
$notes = Note::whereNoteableType(TransactionJournal::class)->whereIn('noteable_id', array_keys($journals))->get();
|
||||
|
||||
/** @var Note $note */
|
||||
foreach ($notes as $note) {
|
||||
$id = $note->noteable_id;
|
||||
$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'])
|
||||
;
|
||||
|
||||
/** @var \stdClass $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$id = (int) $tag->transaction_journal_id;
|
||||
$this->tags[$id][] = $tag->tag;
|
||||
}
|
||||
|
||||
// create converter
|
||||
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
|
||||
$this->converter = new ExchangeRateConverter();
|
||||
}
|
||||
|
||||
public function transform(array $group): array
|
||||
public function transform(array | TransactionGroup $group): array
|
||||
{
|
||||
$first = reset($group['transactions']);
|
||||
if (is_array($group)) {
|
||||
$first = reset($group['transactions']);
|
||||
|
||||
return [
|
||||
'id' => (string) $group['id'],
|
||||
'created_at' => $group['created_at']->toAtomString(),
|
||||
'updated_at' => $group['updated_at']->toAtomString(),
|
||||
'user' => (string) $first['user_id'],
|
||||
'user_group' => (string) $first['user_group_id'],
|
||||
'group_title' => $group['title'] ?? null,
|
||||
'transactions' => $this->transformTransactions($group['transactions'] ?? []),
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => sprintf('/transactions/%d', $group['id']),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
return [
|
||||
'id' => (string) $group['id'],
|
||||
'created_at' => $first['created_at']->toAtomString(),
|
||||
'updated_at' => $first['updated_at']->toAtomString(),
|
||||
'user' => (string) $first['user_id'],
|
||||
'user_group' => (string) $first['user_group_id'],
|
||||
'group_title' => $group['title'] ?? null,
|
||||
'transactions' => $this->transformTransactions($group['transactions'] ?? []),
|
||||
'id' => (string) $group->id,
|
||||
'created_at' => $group->created_at->toAtomString(),
|
||||
'updated_at' => $group->created_at->toAtomString(),
|
||||
'user' => (string) $group->user_id,
|
||||
'user_group' => (string) $group->user_group_id,
|
||||
'group_title' => $group->title ?? null,
|
||||
'transactions' => $this->transformJournals($group),
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => sprintf('/transactions/%d', $group['id']),
|
||||
'uri' => sprintf('/transactions/%d', $group->id),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function transformJournals(TransactionGroup $group): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($group->transactionJournals as $journal) {
|
||||
$return[] = $this->transformJournal($journal);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function transformJournal(TransactionJournal $journal): array
|
||||
{
|
||||
$id = $journal->id;
|
||||
/** @var TransactionCurrency|null $foreignCurrency */
|
||||
$foreignCurrency = null;
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $this->currencies[$this->journals[$id]['currency_id']];
|
||||
$nativeForeignAmount = null;
|
||||
$amount = $this->journals[$journal->id]['amount'];
|
||||
$foreignAmount = $this->journals[$journal->id]['foreign_amount'];
|
||||
$meta = new NullArrayObject($this->meta[$id] ?? []);
|
||||
|
||||
// has foreign amount?
|
||||
if (null !== $foreignAmount) {
|
||||
$foreignCurrency = $this->currencies[$this->journals[$id]['foreign_currency_id']];
|
||||
$nativeForeignAmount = $this->converter->convert($this->default, $foreignCurrency, $journal->date, $foreignAmount);
|
||||
}
|
||||
|
||||
$nativeAmount = $this->converter->convert($this->default, $currency, $journal->date, $amount);
|
||||
|
||||
$longitude = null;
|
||||
$latitude = null;
|
||||
$zoomLevel = null;
|
||||
if (array_key_exists('location', $this->journals[$id])) {
|
||||
$latitude = (string) $this->journals[$id]['location']['latitude'];
|
||||
$longitude = (string) $this->journals[$id]['location']['longitude'];
|
||||
$zoomLevel = $this->journals[$id]['location']['zoom_level'];
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => (string) $journal->user_id,
|
||||
'user_group' => (string) $journal->user_group_id,
|
||||
'transaction_journal_id' => (string) $journal->id,
|
||||
'type' => $this->journals[$journal->id]['type'],
|
||||
'date' => $journal->date->toAtomString(),
|
||||
'order' => $journal->order,
|
||||
'amount' => $amount,
|
||||
'native_amount' => $nativeAmount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'native_foreign_amount' => $nativeForeignAmount,
|
||||
'currency_id' => (string) $currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
|
||||
// converted to native currency
|
||||
'native_currency_id' => (string) $this->default->id,
|
||||
'native_currency_code' => $this->default->code,
|
||||
'native_currency_name' => $this->default->name,
|
||||
'native_currency_symbol' => $this->default->symbol,
|
||||
'native_currency_decimal_places' => $this->default->decimal_places,
|
||||
|
||||
// foreign currency amount:
|
||||
'foreign_currency_id' => $foreignCurrency?->id,
|
||||
'foreign_currency_code' => $foreignCurrency?->code,
|
||||
'foreign_currency_name' => $foreignCurrency?->name,
|
||||
'foreign_currency_symbol' => $foreignCurrency?->symbol,
|
||||
'foreign_currency_decimal_places' => $foreignCurrency?->decimal_places,
|
||||
|
||||
'description' => $journal->description,
|
||||
'source_id' => (string) $this->journals[$id]['source_account_id'],
|
||||
'source_name' => $this->journals[$id]['source_account_name'],
|
||||
'source_iban' => $this->journals[$id]['source_account_iban'],
|
||||
'source_type' => $this->journals[$id]['source_account_type'],
|
||||
|
||||
'destination_id' => (string) $this->journals[$id]['destination_account_id'],
|
||||
'destination_name' => $this->journals[$id]['destination_account_name'],
|
||||
'destination_iban' => $this->journals[$id]['destination_account_iban'],
|
||||
'destination_type' => $this->journals[$id]['destination_account_type'],
|
||||
|
||||
'budget_id' => $this->journals[$id]['budget_id'],
|
||||
'budget_name' => $this->journals[$id]['budget_name'],
|
||||
'category_id' => $this->journals[$id]['category_id'],
|
||||
'category_name' => $this->journals[$id]['category_name'],
|
||||
'bill_id' => $this->journals[$id]['bill_id'],
|
||||
'bill_name' => $this->journals[$id]['bill_name'],
|
||||
'reconciled' => $this->journals[$id]['reconciled'],
|
||||
'notes' => $this->journals[$id]['notes'] ?? null,
|
||||
'tags' => $this->journals[$id]['tags'] ?? [],
|
||||
'internal_reference' => $meta['internal_reference'],
|
||||
'external_id' => $meta['external_id'],
|
||||
'original_source' => $meta['original_source'],
|
||||
'recurrence_id' => $meta['recurrence_id'],
|
||||
'recurrence_total' => $meta['recurrence_total'],
|
||||
'recurrence_count' => $meta['recurrence_count'],
|
||||
'external_url' => $meta['external_url'],
|
||||
'import_hash_v2' => $meta['import_hash_v2'],
|
||||
'sepa_cc' => $meta['sepa_cc'],
|
||||
'sepa_ct_op' => $meta['sepa_ct_op'],
|
||||
'sepa_ct_id' => $meta['sepa_ct_id'],
|
||||
'sepa_db' => $meta['sepa_db'],
|
||||
'sepa_country' => $meta['sepa_country'],
|
||||
'sepa_ep' => $meta['sepa_ep'],
|
||||
'sepa_ci' => $meta['sepa_ci'],
|
||||
'sepa_batch_id' => $meta['sepa_batch_id'],
|
||||
'interest_date' => $this->date($meta['interest_date']),
|
||||
'book_date' => $this->date($meta['book_date']),
|
||||
'process_date' => $this->date($meta['process_date']),
|
||||
'due_date' => $this->date($meta['due_date']),
|
||||
'payment_date' => $this->date($meta['payment_date']),
|
||||
'invoice_date' => $this->date($meta['invoice_date']),
|
||||
|
||||
// location data
|
||||
'longitude' => $longitude,
|
||||
'latitude' => $latitude,
|
||||
'zoom_level' => $zoomLevel,
|
||||
//
|
||||
// 'has_attachments' => $this->hasAttachments((int) $row['transaction_journal_id']),
|
||||
];
|
||||
}
|
||||
|
||||
private function transformTransactions(array $transactions): array
|
||||
{
|
||||
$return = [];
|
||||
@ -157,10 +275,10 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
*/
|
||||
private function transformTransaction(array $transaction): array
|
||||
{
|
||||
$transaction = new NullArrayObject($transaction);
|
||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
|
||||
$journalId = (int) $transaction['transaction_journal_id'];
|
||||
$meta = new NullArrayObject($this->meta[$journalId] ?? []);
|
||||
$transaction = new NullArrayObject($transaction);
|
||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
|
||||
$journalId = (int) $transaction['transaction_journal_id'];
|
||||
$meta = new NullArrayObject($this->meta[$journalId] ?? []);
|
||||
|
||||
/**
|
||||
* Convert and use amount:
|
||||
@ -177,15 +295,13 @@ 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;
|
||||
$longitude = null;
|
||||
$latitude = null;
|
||||
$zoomLevel = null;
|
||||
if (array_key_exists('location', $this->journals[$journalId])) {
|
||||
$latitude = (string) $this->journals[$journalId]['location']['latitude'];
|
||||
$longitude = (string) $this->journals[$journalId]['location']['longitude'];
|
||||
$zoomLevel = $this->journals[$journalId]['location']['zoom_level'];
|
||||
}
|
||||
|
||||
return [
|
||||
@ -333,4 +449,163 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function collectForArray(array $object): void
|
||||
{
|
||||
foreach ($object['sums'] as $sum) {
|
||||
$this->currencies[(int) $sum['currency_id']] ??= TransactionCurrency::find($sum['currency_id']);
|
||||
}
|
||||
|
||||
/** @var array $transaction */
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
$this->journals[(int) $transaction['transaction_journal_id']] = [];
|
||||
}
|
||||
}
|
||||
|
||||
private function collectAllMetaData(): void
|
||||
{
|
||||
$meta = TransactionJournalMeta::whereIn('transaction_journal_id', array_keys($this->journals))->get();
|
||||
|
||||
/** @var TransactionJournalMeta $entry */
|
||||
foreach ($meta as $entry) {
|
||||
$id = $entry->transaction_journal_id;
|
||||
$this->journals[$id]['meta'] ??= [];
|
||||
$this->journals[$id]['meta'][$entry->name] = $entry->data;
|
||||
}
|
||||
}
|
||||
|
||||
private function collectAllNotes(): void
|
||||
{
|
||||
// grab all notes for all journals:
|
||||
$notes = Note::whereNoteableType(TransactionJournal::class)->whereIn('noteable_id', array_keys($this->journals))->get();
|
||||
|
||||
/** @var Note $note */
|
||||
foreach ($notes as $note) {
|
||||
$id = $note->noteable_id;
|
||||
$this->journals[$id]['notes'] = $note->text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function collectAllLocations(): void
|
||||
{
|
||||
// grab all locations for all journals:
|
||||
$locations = Location::whereLocatableType(TransactionJournal::class)->whereIn('locatable_id', array_keys($this->journals))->get();
|
||||
/** @var Location $location */
|
||||
foreach ($locations as $location) {
|
||||
$id = $location->locatable_id;
|
||||
$this->journals[$id]['location'] = [
|
||||
'latitude' => $location->latitude,
|
||||
'longitude' => $location->longitude,
|
||||
'zoom_level' => $location->zoom_level,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
private function collectAllTags(): void
|
||||
{
|
||||
// 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($this->journals))
|
||||
->get(['tag_transaction_journal.transaction_journal_id', 'tags.tag']);
|
||||
|
||||
/** @var \stdClass $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$id = (int) $tag->transaction_journal_id;
|
||||
$this->journals[$id]['tags'][] = $tag->tag;
|
||||
}
|
||||
}
|
||||
|
||||
private function collectForObject(TransactionGroup $object): void
|
||||
{
|
||||
foreach ($object->transactionJournals as $journal) {
|
||||
$this->journals[$journal->id] = [];
|
||||
$this->objects[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
private function collectAllCurrencies(): void
|
||||
{
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($this->objects as $journal) {
|
||||
$id = $journal->id;
|
||||
$this->journals[$id]['reconciled'] = false;
|
||||
$this->journals[$id]['foreign_amount'] = null;
|
||||
$this->journals[$id]['foreign_currency_id'] = null;
|
||||
$this->journals[$id]['amount'] = null;
|
||||
$this->journals[$id]['currency_id'] = null;
|
||||
$this->journals[$id]['type'] = $journal->transactionType->type;
|
||||
$this->journals[$id]['budget_id'] = null;
|
||||
$this->journals[$id]['budget_name'] = null;
|
||||
$this->journals[$id]['category_id'] = null;
|
||||
$this->journals[$id]['category_name'] = null;
|
||||
$this->journals[$id]['bill_id'] = null;
|
||||
$this->journals[$id]['bill_name'] = null;
|
||||
|
||||
// collect budget:
|
||||
/** @var Budget|null $budget */
|
||||
$budget = $journal->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
$this->journals[$id]['budget_id'] = (string) $budget->id;
|
||||
$this->journals[$id]['budget_name'] = $budget->name;
|
||||
}
|
||||
|
||||
// collect category:
|
||||
/** @var Category|null $category */
|
||||
$category = $journal->categories()->first();
|
||||
if (null !== $category) {
|
||||
$this->journals[$id]['category_id'] = (string) $category->id;
|
||||
$this->journals[$id]['category_name'] = $category->name;
|
||||
}
|
||||
|
||||
// collect bill:
|
||||
if (null !== $journal->bill_id) {
|
||||
$bill = $journal->bill;
|
||||
$this->journals[$id]['bill_id'] = (string) $bill->id;
|
||||
$this->journals[$id]['bill_name'] = $bill->name;
|
||||
}
|
||||
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
if (-1 === bccomp($transaction->amount, '0')) {
|
||||
// only collect source account info
|
||||
$account = $transaction->account;
|
||||
$this->accountTypes[$account->account_type_id] ??= $account->accountType->type;
|
||||
$this->journals[$id]['source_account_name'] = $account->name;
|
||||
$this->journals[$id]['source_account_iban'] = $account->iban;
|
||||
$this->journals[$id]['source_account_type'] = $this->accountTypes[$account->account_type_id];
|
||||
$this->journals[$id]['source_account_id'] = $transaction->account_id;
|
||||
$this->journals[$id]['reconciled'] = $transaction->reconciled;
|
||||
continue;
|
||||
}
|
||||
|
||||
// add account
|
||||
$account = $transaction->account;
|
||||
$this->accountTypes[$account->account_type_id] ??= $account->accountType->type;
|
||||
$this->journals[$id]['destination_account_name'] = $account->name;
|
||||
$this->journals[$id]['destination_account_iban'] = $account->iban;
|
||||
$this->journals[$id]['destination_account_type'] = $this->accountTypes[$account->account_type_id];
|
||||
$this->journals[$id]['destination_account_id'] = $transaction->account_id;
|
||||
|
||||
// find and set currency
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
$this->currencies[$currencyId] ??= $transaction->transactionCurrency;
|
||||
$this->journals[$id]['currency_id'] = $currencyId;
|
||||
$this->journals[$id]['amount'] = $transaction->amount;
|
||||
// find and set foreign currency
|
||||
if (null !== $transaction->foreign_currency_id) {
|
||||
$foreignCurrencyId = $transaction->foreign_currency_id;
|
||||
$this->currencies[$foreignCurrencyId] ??= $transaction->foreignCurrency;
|
||||
$this->journals[$id]['foreign_currency_id'] = $foreignCurrencyId;
|
||||
$this->journals[$id]['foreign_amount'] = $transaction->foreign_amount;
|
||||
}
|
||||
|
||||
// find and set destination account info.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
changelog.md
17
changelog.md
@ -3,6 +3,23 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 6.1.5 - 2024-01-07
|
||||
|
||||
### Added
|
||||
|
||||
- More audit logs
|
||||
- Sanity check in date ranges
|
||||
- More uniform length and size validations
|
||||
|
||||
### Changed
|
||||
|
||||
- Slightly changed text, thanks @maureenferreira!
|
||||
|
||||
### Fixed
|
||||
|
||||
- [Issue 8328](https://github.com/firefly-iii/firefly-iii/issues/8328) Some extra fixes for non-zero foreign amounts
|
||||
- Updated links in `.env.example`, thanks @lemuelroberto!
|
||||
|
||||
## 6.1.4 - 2024-01-03
|
||||
|
||||
### Fixed
|
||||
|
@ -63,6 +63,7 @@ use FireflyIII\Support\Binder\TagList;
|
||||
use FireflyIII\Support\Binder\TagOrId;
|
||||
use FireflyIII\Support\Binder\UserGroupAccount;
|
||||
use FireflyIII\Support\Binder\UserGroupBill;
|
||||
use FireflyIII\Support\Binder\UserGroupTransaction;
|
||||
use FireflyIII\TransactionRules\Actions\AddTag;
|
||||
use FireflyIII\TransactionRules\Actions\AppendDescription;
|
||||
use FireflyIII\TransactionRules\Actions\AppendDescriptionToNotes;
|
||||
@ -114,7 +115,7 @@ return [
|
||||
'handle_debts' => true,
|
||||
// see cer.php for exchange rates feature flag.
|
||||
],
|
||||
'version' => '6.1.4',
|
||||
'version' => '6.1.5',
|
||||
'api_version' => '2.0.12',
|
||||
'db_version' => 22,
|
||||
|
||||
@ -431,64 +432,65 @@ return [
|
||||
'transfers' => 'fa-exchange',
|
||||
],
|
||||
|
||||
'bindables' => [
|
||||
'bindables' => [
|
||||
// models
|
||||
'account' => Account::class,
|
||||
'attachment' => Attachment::class,
|
||||
'availableBudget' => AvailableBudget::class,
|
||||
'bill' => Bill::class,
|
||||
'budget' => Budget::class,
|
||||
'budgetLimit' => BudgetLimit::class,
|
||||
'category' => Category::class,
|
||||
'linkType' => LinkType::class,
|
||||
'transactionType' => TransactionTypeModel::class,
|
||||
'journalLink' => TransactionJournalLink::class,
|
||||
'currency' => TransactionCurrency::class,
|
||||
'objectGroup' => ObjectGroup::class,
|
||||
'piggyBank' => PiggyBank::class,
|
||||
'preference' => Preference::class,
|
||||
'tj' => TransactionJournal::class,
|
||||
'tag' => Tag::class,
|
||||
'recurrence' => Recurrence::class,
|
||||
'rule' => Rule::class,
|
||||
'ruleGroup' => RuleGroup::class,
|
||||
'transactionGroup' => TransactionGroup::class,
|
||||
'user' => User::class,
|
||||
'webhook' => Webhook::class,
|
||||
'webhookMessage' => WebhookMessage::class,
|
||||
'webhookAttempt' => WebhookAttempt::class,
|
||||
'invitedUser' => InvitedUser::class,
|
||||
'account' => Account::class,
|
||||
'attachment' => Attachment::class,
|
||||
'availableBudget' => AvailableBudget::class,
|
||||
'bill' => Bill::class,
|
||||
'budget' => Budget::class,
|
||||
'budgetLimit' => BudgetLimit::class,
|
||||
'category' => Category::class,
|
||||
'linkType' => LinkType::class,
|
||||
'transactionType' => TransactionTypeModel::class,
|
||||
'journalLink' => TransactionJournalLink::class,
|
||||
'currency' => TransactionCurrency::class,
|
||||
'objectGroup' => ObjectGroup::class,
|
||||
'piggyBank' => PiggyBank::class,
|
||||
'preference' => Preference::class,
|
||||
'tj' => TransactionJournal::class,
|
||||
'tag' => Tag::class,
|
||||
'recurrence' => Recurrence::class,
|
||||
'rule' => Rule::class,
|
||||
'ruleGroup' => RuleGroup::class,
|
||||
'transactionGroup' => TransactionGroup::class,
|
||||
'user' => User::class,
|
||||
'webhook' => Webhook::class,
|
||||
'webhookMessage' => WebhookMessage::class,
|
||||
'webhookAttempt' => WebhookAttempt::class,
|
||||
'invitedUser' => InvitedUser::class,
|
||||
|
||||
// strings
|
||||
'currency_code' => CurrencyCode::class,
|
||||
'currency_code' => CurrencyCode::class,
|
||||
|
||||
// dates
|
||||
'start_date' => Date::class,
|
||||
'end_date' => Date::class,
|
||||
'date' => Date::class,
|
||||
'start_date' => Date::class,
|
||||
'end_date' => Date::class,
|
||||
'date' => Date::class,
|
||||
|
||||
// lists
|
||||
'accountList' => AccountList::class,
|
||||
'doubleList' => AccountList::class,
|
||||
'budgetList' => BudgetList::class,
|
||||
'journalList' => JournalList::class,
|
||||
'categoryList' => CategoryList::class,
|
||||
'tagList' => TagList::class,
|
||||
'accountList' => AccountList::class,
|
||||
'doubleList' => AccountList::class,
|
||||
'budgetList' => BudgetList::class,
|
||||
'journalList' => JournalList::class,
|
||||
'categoryList' => CategoryList::class,
|
||||
'tagList' => TagList::class,
|
||||
|
||||
// others
|
||||
'fromCurrencyCode' => CurrencyCode::class,
|
||||
'toCurrencyCode' => CurrencyCode::class,
|
||||
'cliToken' => CLIToken::class,
|
||||
'tagOrId' => TagOrId::class,
|
||||
'dynamicConfigKey' => DynamicConfigKey::class,
|
||||
'eitherConfigKey' => EitherConfigKey::class,
|
||||
'fromCurrencyCode' => CurrencyCode::class,
|
||||
'toCurrencyCode' => CurrencyCode::class,
|
||||
'cliToken' => CLIToken::class,
|
||||
'tagOrId' => TagOrId::class,
|
||||
'dynamicConfigKey' => DynamicConfigKey::class,
|
||||
'eitherConfigKey' => EitherConfigKey::class,
|
||||
|
||||
// V2 API endpoints:
|
||||
'userGroupAccount' => UserGroupAccount::class,
|
||||
'userGroupBill' => UserGroupBill::class,
|
||||
'userGroup' => UserGroup::class,
|
||||
'userGroupAccount' => UserGroupAccount::class,
|
||||
'userGroupTransaction' => UserGroupTransaction::class,
|
||||
'userGroupBill' => UserGroupBill::class,
|
||||
'userGroup' => UserGroup::class,
|
||||
],
|
||||
'rule-actions' => [
|
||||
'rule-actions' => [
|
||||
'set_category' => SetCategory::class,
|
||||
'clear_category' => ClearCategory::class,
|
||||
'set_budget' => SetBudget::class,
|
||||
@ -519,7 +521,7 @@ return [
|
||||
'set_source_to_cash' => SetSourceToCashAccount::class,
|
||||
'set_destination_to_cash' => SetDestinationToCashAccount::class,
|
||||
],
|
||||
'context-rule-actions' => [
|
||||
'context-rule-actions' => [
|
||||
'set_category',
|
||||
'set_budget',
|
||||
'add_tag',
|
||||
@ -538,13 +540,13 @@ return [
|
||||
'convert_transfer',
|
||||
],
|
||||
|
||||
'test-triggers' => [
|
||||
'test-triggers' => [
|
||||
'limit' => 10,
|
||||
'range' => 200,
|
||||
],
|
||||
|
||||
// expected source types for each transaction type, in order of preference.
|
||||
'expected_source_types' => [
|
||||
'expected_source_types' => [
|
||||
'source' => [
|
||||
TransactionTypeModel::WITHDRAWAL => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
|
||||
TransactionTypeEnum::DEPOSIT->value => [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::REVENUE, AccountType::CASH],
|
||||
@ -589,7 +591,7 @@ return [
|
||||
TransactionTypeModel::LIABILITY_CREDIT => [AccountType::LIABILITY_CREDIT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
|
||||
],
|
||||
],
|
||||
'allowed_opposing_types' => [
|
||||
'allowed_opposing_types' => [
|
||||
'source' => [
|
||||
AccountType::ASSET => [
|
||||
AccountType::ASSET,
|
||||
@ -679,7 +681,7 @@ return [
|
||||
],
|
||||
],
|
||||
// depending on the account type, return the allowed transaction types:
|
||||
'allowed_transaction_types' => [
|
||||
'allowed_transaction_types' => [
|
||||
'source' => [
|
||||
AccountType::ASSET => [
|
||||
TransactionTypeModel::WITHDRAWAL,
|
||||
@ -748,7 +750,7 @@ return [
|
||||
],
|
||||
|
||||
// having the source + dest will tell you the transaction type.
|
||||
'account_to_transaction' => [
|
||||
'account_to_transaction' => [
|
||||
AccountType::ASSET => [
|
||||
AccountType::ASSET => TransactionTypeModel::TRANSFER,
|
||||
AccountType::CASH => TransactionTypeModel::WITHDRAWAL,
|
||||
@ -813,7 +815,7 @@ return [
|
||||
],
|
||||
|
||||
// allowed source -> destination accounts.
|
||||
'source_dests' => [
|
||||
'source_dests' => [
|
||||
TransactionTypeModel::WITHDRAWAL => [
|
||||
AccountType::ASSET => [AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::CASH],
|
||||
AccountType::LOAN => [AccountType::EXPENSE, AccountType::CASH],
|
||||
@ -852,7 +854,7 @@ return [
|
||||
],
|
||||
],
|
||||
// if you add fields to this array, don't forget to update the export routine (ExportDataGenerator).
|
||||
'journal_meta_fields' => [
|
||||
'journal_meta_fields' => [
|
||||
// sepa
|
||||
'sepa_cc',
|
||||
'sepa_ct_op',
|
||||
@ -886,28 +888,28 @@ return [
|
||||
'recurrence_count',
|
||||
'recurrence_date',
|
||||
],
|
||||
'webhooks' => [
|
||||
'webhooks' => [
|
||||
'max_attempts' => env('WEBHOOK_MAX_ATTEMPTS', 3),
|
||||
],
|
||||
'can_have_virtual_amounts' => [AccountType::ASSET],
|
||||
'can_have_opening_balance' => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
|
||||
'dynamic_creation_allowed' => [
|
||||
'can_have_virtual_amounts' => [AccountType::ASSET],
|
||||
'can_have_opening_balance' => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
|
||||
'dynamic_creation_allowed' => [
|
||||
AccountType::EXPENSE,
|
||||
AccountType::REVENUE,
|
||||
AccountType::INITIAL_BALANCE,
|
||||
AccountType::RECONCILIATION,
|
||||
AccountType::LIABILITY_CREDIT,
|
||||
],
|
||||
'valid_asset_fields' => ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
|
||||
'valid_cc_fields' => ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
|
||||
'valid_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'],
|
||||
'valid_asset_fields' => ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
|
||||
'valid_cc_fields' => ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
|
||||
'valid_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'],
|
||||
|
||||
// dynamic date ranges are as follows:
|
||||
'dynamic_date_ranges' => ['last7', 'last30', 'last90', 'last365', 'MTD', 'QTD', 'YTD'],
|
||||
'dynamic_date_ranges' => ['last7', 'last30', 'last90', 'last365', 'MTD', 'QTD', 'YTD'],
|
||||
|
||||
// only used in v1
|
||||
'allowed_sort_parameters' => ['order', 'name', 'iban'],
|
||||
'allowed_sort_parameters' => ['order', 'name', 'iban'],
|
||||
|
||||
// preselected account lists possibilities:
|
||||
'preselected_accounts' => ['all', 'assets', 'liabilities'],
|
||||
'preselected_accounts' => ['all', 'assets', 'liabilities'],
|
||||
];
|
||||
|
@ -31,4 +31,7 @@ export default class Get {
|
||||
list(params) {
|
||||
return api.get('/api/v2/transactions', {params: params});
|
||||
}
|
||||
show(id, params){
|
||||
return api.get('/api/v2/transactions/' + id, {params: params});
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import {loadPiggyBanks} from "./shared/load-piggy-banks.js";
|
||||
import {loadSubscriptions} from "./shared/load-subscriptions.js";
|
||||
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
import {addAutocomplete} from "./shared/add-autocomplete.js";
|
||||
import {addAutocomplete, getUrls} from "./shared/add-autocomplete.js";
|
||||
import {
|
||||
changeCategory,
|
||||
changeDescription,
|
||||
@ -47,6 +47,9 @@ import {spliceErrorsIntoTransactions} from "./shared/splice-errors-into-transact
|
||||
import Tags from "bootstrap5-tags";
|
||||
import {addLocation} from "./shared/manage-locations.js";
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO upload attachments to other file
|
||||
// TODO fix two maps, perhaps disconnect from entries entirely.
|
||||
// TODO group title
|
||||
@ -55,12 +58,7 @@ import {addLocation} from "./shared/manage-locations.js";
|
||||
|
||||
let i18n;
|
||||
|
||||
const urls = {
|
||||
description: '/api/v2/autocomplete/transaction-descriptions',
|
||||
account: '/api/v2/autocomplete/accounts',
|
||||
category: '/api/v2/autocomplete/categories',
|
||||
tag: '/api/v2/autocomplete/tags',
|
||||
};
|
||||
const urls = getUrls();
|
||||
|
||||
let transactions = function () {
|
||||
return {
|
||||
@ -265,44 +263,7 @@ let transactions = function () {
|
||||
},
|
||||
|
||||
addedSplit() {
|
||||
// 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">' + i18n.t('firefly.account_type_' + item.type) + '</small>';
|
||||
};
|
||||
console.log(this.filters);
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-source',
|
||||
serverUrl: urls.account,
|
||||
filters: this.filters.source,
|
||||
onRenderItem: renderAccount,
|
||||
onChange: changeSourceAccount,
|
||||
onSelectItem: selectSourceAccount
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-dest',
|
||||
serverUrl: urls.account,
|
||||
filters: this.filters.destination,
|
||||
onRenderItem: renderAccount,
|
||||
onChange: changeDestinationAccount,
|
||||
onSelectItem: selectDestinationAccount
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-category',
|
||||
serverUrl: urls.category,
|
||||
valueField: 'id',
|
||||
labelField: 'name',
|
||||
onChange: changeCategory,
|
||||
onSelectItem: changeCategory
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-description',
|
||||
serverUrl: urls.description,
|
||||
valueField: 'id',
|
||||
labelField: 'description',
|
||||
onChange: changeDescription,
|
||||
onSelectItem: changeDescription,
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
|
||||
@ -508,6 +469,46 @@ let transactions = function () {
|
||||
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">' + i18n.t('firefly.account_type_' + item.type) + '</small>';
|
||||
};
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-source',
|
||||
serverUrl: urls.account,
|
||||
// filters: this.filters.source,
|
||||
// onRenderItem: renderAccount,
|
||||
onChange: changeSourceAccount,
|
||||
onSelectItem: selectSourceAccount,
|
||||
hiddenValue: this.items[count].source_account.alpine_name,
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-dest',
|
||||
serverUrl: urls.account,
|
||||
filters: this.filters.destination,
|
||||
onRenderItem: renderAccount,
|
||||
onChange: changeDestinationAccount,
|
||||
onSelectItem: selectDestinationAccount
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-category',
|
||||
serverUrl: urls.category,
|
||||
valueField: 'id',
|
||||
labelField: 'name',
|
||||
onChange: changeCategory,
|
||||
onSelectItem: changeCategory
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-description',
|
||||
serverUrl: urls.description,
|
||||
valueField: 'id',
|
||||
labelField: 'description',
|
||||
onChange: changeDescription,
|
||||
onSelectItem: changeDescription,
|
||||
});
|
||||
|
||||
}, 150);
|
||||
},
|
||||
|
||||
|
@ -23,17 +23,34 @@ import dates from '../../pages/shared/dates.js';
|
||||
import {getVariable} from "../../store/get-variable.js";
|
||||
import {I18n} from "i18n-js";
|
||||
import {loadTranslations} from "../../support/load-translations.js";
|
||||
import formatMoney from "../../util/format-money.js";
|
||||
import Get from "../../api/v2/model/transaction/get.js";
|
||||
import {parseDownloadedSplits} from "./shared/parse-downloaded-splits.js";
|
||||
import {addAutocomplete, getUrls} from "./shared/add-autocomplete.js";
|
||||
import {
|
||||
changeCategory,
|
||||
changeDescription,
|
||||
changeDestinationAccount,
|
||||
changeSourceAccount,
|
||||
selectDestinationAccount,
|
||||
selectSourceAccount
|
||||
} from "./shared/autocomplete-functions.js";
|
||||
import {loadCurrencies} from "./shared/load-currencies.js";
|
||||
import {loadBudgets} from "./shared/load-budgets.js";
|
||||
import {loadPiggyBanks} from "./shared/load-piggy-banks.js";
|
||||
import {loadSubscriptions} from "./shared/load-subscriptions.js";
|
||||
import Tags from "bootstrap5-tags";
|
||||
|
||||
// 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
|
||||
// TODO filters
|
||||
// TODO parse amount
|
||||
|
||||
let i18n;
|
||||
|
||||
|
||||
|
||||
const urls = getUrls();
|
||||
|
||||
let transactions = function () {
|
||||
return {
|
||||
@ -41,20 +58,228 @@ let transactions = function () {
|
||||
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: true,
|
||||
rulesButton: true,
|
||||
webhooksButton: true,
|
||||
},
|
||||
|
||||
// form behaviour during transaction
|
||||
formBehaviour: {
|
||||
formType: 'create', foreignCurrencyEnabled: true,
|
||||
},
|
||||
|
||||
// form data (except transactions) is stored in formData
|
||||
formData: {
|
||||
defaultCurrency: null,
|
||||
enabledCurrencies: [],
|
||||
nativeCurrencies: [],
|
||||
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: [],
|
||||
},
|
||||
|
||||
addedSplit() {
|
||||
setTimeout(() => {
|
||||
// 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">' + i18n.t('firefly.account_type_' + item.type) + '</small>';
|
||||
};
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-source',
|
||||
serverUrl: urls.account,
|
||||
filters: this.filters.source,
|
||||
onRenderItem: renderAccount,
|
||||
onChange: changeSourceAccount,
|
||||
onSelectItem: selectSourceAccount
|
||||
});
|
||||
console.log('ok');
|
||||
console.log(this.entries[0].source_account.alpine_name);
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-dest',
|
||||
serverUrl: urls.account,
|
||||
filters: this.filters.destination,
|
||||
onRenderItem: renderAccount,
|
||||
onChange: changeDestinationAccount,
|
||||
onSelectItem: selectDestinationAccount
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-category',
|
||||
serverUrl: urls.category,
|
||||
valueField: 'id',
|
||||
labelField: 'name',
|
||||
onChange: changeCategory,
|
||||
onSelectItem: changeCategory
|
||||
});
|
||||
addAutocomplete({
|
||||
selector: 'input.ac-description',
|
||||
serverUrl: urls.description,
|
||||
valueField: 'id',
|
||||
labelField: 'description',
|
||||
onChange: changeDescription,
|
||||
onSelectItem: changeDescription,
|
||||
});
|
||||
}, 250);
|
||||
|
||||
},
|
||||
|
||||
// events in the form
|
||||
changedDateTime(event) {
|
||||
console.warn('changedDateTime, event is not used');
|
||||
},
|
||||
|
||||
changedDescription(event) {
|
||||
console.warn('changedDescription, event is not used');
|
||||
},
|
||||
|
||||
changedDestinationAccount(event) {
|
||||
console.warn('changedDestinationAccount, event is not used');
|
||||
},
|
||||
|
||||
changedSourceAccount(event) {
|
||||
console.warn('changedSourceAccount, event is not used');
|
||||
},
|
||||
|
||||
// duplicate function but this is easier.
|
||||
formattedTotalAmount() {
|
||||
if (this.entries.length === 0) {
|
||||
return formatMoney(this.groupProperties.totalAmount, 'EUR');
|
||||
}
|
||||
return formatMoney(this.groupProperties.totalAmount, this.entries[0].currency_code ?? 'EUR');
|
||||
},
|
||||
|
||||
|
||||
getTransactionGroup() {
|
||||
const page = window.location.href.split('/');
|
||||
const groupId = parseInt(page[page.length - 1]);
|
||||
const getter = new Get();
|
||||
getter.show(groupId, {}).then((response) => {
|
||||
const data = response.data.data;
|
||||
this.groupProperties.id = parseInt(data.id);
|
||||
this.groupProperties.transactionType = data.attributes.transactions[0].type;
|
||||
this.groupProperties.title = data.attributes.title ?? data.attributes.transactions[0].description;
|
||||
this.entries = parseDownloadedSplits(data.attributes.transactions);
|
||||
//console.log(this.entries);
|
||||
|
||||
// remove waiting thing.
|
||||
this.notifications.wait.show = false;
|
||||
}).then(() => {
|
||||
|
||||
setTimeout(() => {
|
||||
// render tags:
|
||||
Tags.init('select.ac-tags', {
|
||||
allowClear: true,
|
||||
// server: urls.tag,
|
||||
// liveServer: true,
|
||||
// clearEnd: true,
|
||||
selected: [{label:'Bla bla',value:1,selected:true}],
|
||||
//allowNew: true,
|
||||
//notFoundMessage: i18n.t('firefly.nothing_found'),
|
||||
// noCache: true,
|
||||
// fetchOptions: {
|
||||
// headers: {
|
||||
// 'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').content
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}, 250);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
init() {
|
||||
// download translations and get the transaction group.
|
||||
Promise.all([getVariable('language', 'en_US')]).then((values) => {
|
||||
i18n = new I18n();
|
||||
const locale = values[0].replace('-', '_');
|
||||
i18n.locale = locale;
|
||||
loadTranslations(i18n, locale).then(() => {
|
||||
//this.addSplit();
|
||||
this.notifications.wait.show = true;
|
||||
this.notifications.wait.text = i18n.t('firefly.wait_loading_transaction');
|
||||
this.getTransactionGroup();
|
||||
});
|
||||
});
|
||||
|
||||
// load meta data.
|
||||
loadCurrencies().then(data => {
|
||||
this.formStates.loadingCurrencies = false;
|
||||
this.formData.defaultCurrency = data.defaultCurrency;
|
||||
this.formData.enabledCurrencies = data.enabledCurrencies;
|
||||
this.formData.nativeCurrencies = data.nativeCurrencies;
|
||||
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;
|
||||
});
|
||||
|
||||
// add some event listeners
|
||||
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;
|
||||
});
|
||||
},
|
||||
}
|
||||
|
@ -20,6 +20,14 @@
|
||||
|
||||
import Autocomplete from "bootstrap5-autocomplete";
|
||||
|
||||
export function getUrls() {
|
||||
return {
|
||||
description: '/api/v2/autocomplete/transaction-descriptions',
|
||||
account: '/api/v2/autocomplete/accounts',
|
||||
category: '/api/v2/autocomplete/categories',
|
||||
tag: '/api/v2/autocomplete/tags',
|
||||
}
|
||||
}
|
||||
|
||||
export function addAutocomplete(options) {
|
||||
const params = {
|
||||
@ -31,19 +39,14 @@ export function addAutocomplete(options) {
|
||||
}
|
||||
},
|
||||
hiddenInput: true,
|
||||
preventBrowserAutocomplete: true,
|
||||
// preventBrowserAutocomplete: true,
|
||||
highlightTyped: true,
|
||||
liveServer: true,
|
||||
// onChange: this.changeSourceAccount,
|
||||
// onSelectItem: this.selectSourceAccount
|
||||
// onSelectItem: this.changeCategory,
|
||||
// onChange: this.changeCategory,
|
||||
};
|
||||
if (typeof options.filters !== 'undefined' && options.filters.length > 0) {
|
||||
params.serverParams.types = options.filters;
|
||||
}
|
||||
if (typeof options.onRenderItem !== 'undefined' && null !== options.onRenderItem) {
|
||||
console.log('add on render item');
|
||||
params.onRenderItem = options.onRenderItem;
|
||||
}
|
||||
if (options.valueField) {
|
||||
@ -58,6 +61,9 @@ export function addAutocomplete(options) {
|
||||
if (options.onChange) {
|
||||
params.onChange = options.onChange;
|
||||
}
|
||||
if(options.hiddenValue) {
|
||||
params.hiddenValue = options.hiddenValue;
|
||||
}
|
||||
|
||||
Autocomplete.init(options.selector, params);
|
||||
}
|
||||
|
@ -101,11 +101,9 @@ export function createEmptySplit() {
|
||||
|
||||
// map
|
||||
hasLocation: false,
|
||||
map: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
zoomLevel: null,
|
||||
marker: null,
|
||||
|
||||
|
||||
// date and time
|
||||
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* parse-downloaded-splits.js
|
||||
* Copyright (c) 2024 james@firefly-iii.org
|
||||
*
|
||||
* 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 {createEmptySplit} from "./create-empty-split.js";
|
||||
import {format} from "date-fns";
|
||||
import formatMoney from "../../../util/format-money.js";
|
||||
|
||||
export function parseDownloadedSplits(downloads) {
|
||||
let returnArray = [];
|
||||
for (let i in downloads) {
|
||||
if (downloads.hasOwnProperty(i)) {
|
||||
// we have at least all default values!
|
||||
let download = downloads[i];
|
||||
let current = createEmptySplit();
|
||||
|
||||
// meta data
|
||||
current.bill_id = download.bill_id;
|
||||
current.budget_id = download.budget_id;
|
||||
current.category_name = download.category_name;
|
||||
current.piggy_bank_id = download.piggy_bank_id;
|
||||
|
||||
// meta dates
|
||||
current.book_date = download.book_date;
|
||||
current.due_date = download.due_date;
|
||||
current.interest_date = download.interest_date;
|
||||
current.invoice_date = download.invoice_date;
|
||||
current.payment_date = download.payment_date;
|
||||
current.process_date = download.process_date;
|
||||
|
||||
// more meta
|
||||
current.external_url = download.external_url;
|
||||
current.internal_reference = download.internal_reference;
|
||||
current.notes = download.notes;
|
||||
current.tags = download.tags;
|
||||
|
||||
// amount
|
||||
current.amount = parseFloat(download.amount).toFixed(download.currency_decimal_places);
|
||||
current.currency_code = download.currency_code;
|
||||
if(null !== download.foreign_amount) {
|
||||
current.forein_currency_code = download.foreign_currency_code;
|
||||
current.foreign_amount = parseFloat(download.foreign_amount).toFixed(download.foreign_currency_decimal_places);
|
||||
}
|
||||
|
||||
// date and description
|
||||
current.date = format(new Date(download.date), 'yyyy-MM-dd HH:mm');
|
||||
current.description = download.description;
|
||||
|
||||
// source and destination
|
||||
current.destination_account = {
|
||||
id: download.destination_id,
|
||||
name: download.destination_name,
|
||||
alpine_name: download.destination_name,
|
||||
};
|
||||
|
||||
current.source_account = {
|
||||
id: download.source_id,
|
||||
name: download.source_name,
|
||||
alpine_name: download.source_name,
|
||||
};
|
||||
|
||||
if(null !== download.latitude) {
|
||||
current.hasLocation = true;
|
||||
current.latitude = download.latitude;
|
||||
current.longitude = download.longitude;
|
||||
current.zoomLevel = download.zoom_level;
|
||||
}
|
||||
|
||||
// hasLocation: false
|
||||
// latitude: null
|
||||
// longitude: null
|
||||
// piggy_bank_id: null
|
||||
// zoomLevel: null
|
||||
console.log('download:');
|
||||
console.log(download);
|
||||
console.log('current:');
|
||||
console.log(current);
|
||||
returnArray.push(current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return returnArray;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@
|
||||
x-model="transaction.budget_id"
|
||||
>
|
||||
<template x-for="budget in formData.budgets">
|
||||
<option :label="budget.name" :value="budget.id"
|
||||
<option :label="budget.name" :value="budget.id" :selected="budget.id == transaction.budget_id"
|
||||
x-text="budget.name"></option>
|
||||
</template>
|
||||
</select>
|
||||
|
@ -17,6 +17,7 @@
|
||||
x-for="subscription in group.subscriptions">
|
||||
<option :label="subscription.name"
|
||||
:value="subscription.id"
|
||||
:selected="subscription.id == transaction.bill_id"
|
||||
x-text="subscription.name"></option>
|
||||
</template>
|
||||
</optgroup>
|
||||
|
@ -7,10 +7,20 @@
|
||||
<select
|
||||
class="form-select ac-tags"
|
||||
:id="'tags_' + index"
|
||||
x-model="transaction.tags"
|
||||
:name="'tags['+index+'][]'"
|
||||
multiple>
|
||||
<option value="">{{ __('firefly.select_tag') }}</option>
|
||||
<template x-for="tag in transaction.tags" :key="tag">
|
||||
<option :value="tag" x-text="tag" selected="selected"></option>
|
||||
</template>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
:value="tag"
|
||||
<template x-for="(tag, index) in transaction.tags" :key="index">
|
||||
<option value="bla">bla</option>
|
||||
</template>
|
||||
-->
|
||||
|
@ -9,11 +9,18 @@
|
||||
<x-messages></x-messages>
|
||||
<x-transaction-tab-list></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"></x-transaction-split>
|
||||
</template>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end">
|
||||
<button class="btn btn-success" :disabled="submitting" @click="submitTransaction()">Update</button>
|
||||
<button class="btn btn-success" :disabled="formStates.isSubmitting" @click="submitTransaction()">Update</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -156,6 +156,7 @@ Route::group(
|
||||
],
|
||||
static function (): void {
|
||||
Route::post('', ['uses' => 'StoreController@post', 'as' => 'store']);
|
||||
Route::get('{userGroupTransaction}', ['uses' => 'ShowController@show', 'as' => 'show']);
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user