mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-10-25 14:40:19 -05:00
Expand transaction links
This commit is contained in:
1 parent
6263408b0a
commit
d303205465
6 files changed
+86
-7
No files matched your search
@@ -32,6 +32,8 @@ use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\Facades\Steam;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -119,4 +121,41 @@ final class TransactionController extends Controller
|
||||
|
||||
return response()->api($array);
|
||||
}
|
||||
|
||||
public function transactionsWithMeta(AutocompleteApiRequest $request): JsonResponse
|
||||
{
|
||||
$result = new Collection();
|
||||
if (is_numeric($request->attributes->get('query'))) {
|
||||
// search for group, not journal.
|
||||
$firstResult = $this->groupRepository->find((int) $request->attributes->get('query'));
|
||||
if ($firstResult instanceof TransactionGroup) {
|
||||
// group may contain multiple journals, each a result:
|
||||
foreach ($firstResult->transactionJournals as $journal) {
|
||||
$result->push($journal);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!is_numeric($request->attributes->get('query'))) {
|
||||
$result = $this->repository->searchJournalDescriptions($request->attributes->get('query'), $request->attributes->get('limit'));
|
||||
}
|
||||
|
||||
// limit and unique
|
||||
$array = [];
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($result as $journal) {
|
||||
$currency = Amount::getCurrencyFromJournal($journal);
|
||||
$array[] = [
|
||||
'id' => (string) $journal->id,
|
||||
'transaction_group_id' => (string) $journal->transaction_group_id,
|
||||
'name' => $journal->description,
|
||||
'description' => $journal->description,
|
||||
'date' => $journal->date,
|
||||
'currency_code' => $currency->code,
|
||||
'amount' => Steam::positive(Amount::getAmountFromJournalObject($journal)),
|
||||
];
|
||||
}
|
||||
|
||||
return response()->api($array);
|
||||
}
|
||||
}
|
||||
@@ -41,11 +41,18 @@ class StoresAuditLogEntry implements ShouldQueue
|
||||
'before' => $event->before,
|
||||
'after' => $event->after,
|
||||
];
|
||||
if ('' === trim((string) $event->before) && '' === trim((string) $event->after)) {
|
||||
if (!is_array($event->before) && !is_array($event->after) && '' === trim((string) $event->before) && '' === trim((string) $event->after)) {
|
||||
Log::debug('Will not store event log because before and after are both empty.');
|
||||
|
||||
return;
|
||||
}
|
||||
// both empty arrays:
|
||||
if (is_array($event->before) && is_array($event->after) && 0 === count($event->before) && 0 === count($event->after)) {
|
||||
Log::debug('Will not store event log because before and after are both empty array.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($event->before === $event->after) {
|
||||
Log::debug('Will not store event log because before and after are the same.');
|
||||
|
||||
|
||||
@@ -219,6 +219,15 @@ class Amount
|
||||
return (string) $amount;
|
||||
}
|
||||
|
||||
public function getCurrencyFromJournal(TransactionJournal $journal): TransactionCurrency {
|
||||
/** @var Transaction|null $first */
|
||||
$first = $journal->transactions->first();
|
||||
if(null === $first){
|
||||
return $this->getPrimaryCurrency();
|
||||
}
|
||||
return $first->transactionCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Experimental function to see if we can quickly and quietly get the amount from a journal.
|
||||
* This depends on the user's default currency and the wish to have it converted.
|
||||
|
||||
@@ -54,6 +54,7 @@ import {clearLocation} from './shared/clear-location.js';
|
||||
import bootstrap from "bootstrap/dist/js/bootstrap.bundle.js";
|
||||
import {removeSplit} from "./shared/remove-split.js";
|
||||
import {loadTransactionLinks} from './shared/load-transaction-links.js';
|
||||
import Autocomplete from "bootstrap5-autocomplete";
|
||||
|
||||
|
||||
let create = function () {
|
||||
@@ -244,11 +245,31 @@ let create = function () {
|
||||
// TODO don't do this on a timeout!
|
||||
}, 500);
|
||||
},
|
||||
manageTransactionLinks() {
|
||||
console.log('here we are!');
|
||||
let modal1 = bootstrap.Modal.getOrCreateInstance('#linksModal');
|
||||
modal1.show();
|
||||
},
|
||||
createAutocomplete(fieldIdentifier, url) {
|
||||
let token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
|
||||
const renderJournal = function (item, b, c) {
|
||||
return item.description + '<br><small class="text-muted">'+item.currency_code +' '+item.amount+ ' @ ' +item.date+'</small>';
|
||||
};
|
||||
console.log('Make autocomplete.');
|
||||
Autocomplete.init('#' + fieldIdentifier, {
|
||||
|
||||
server: url + '?_token=' + token,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
liveServer: true,
|
||||
onRenderItem: renderJournal,
|
||||
fetchOptions: {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': token
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
init() {
|
||||
this.i18next = i18next;
|
||||
@@ -286,6 +307,8 @@ let create = function () {
|
||||
//console.log(data);
|
||||
this.formData.linkTypes = data;
|
||||
this.formStates.loadingLinks = false;
|
||||
this.createAutocomplete('linksModal_search_0','api/v1/autocomplete/transactions-with-meta');
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col">
|
||||
<input type="text" name="search" class="form-control linked-transactions-search" placeholder="TODO Search here..." aria-label="TODO Search here...">
|
||||
<input type="text" name="search" :id="'linksModal_search_' + index" class="form-control linked-transactions-search" placeholder="TODO Search here..." aria-label="TODO Search here...">
|
||||
</div>
|
||||
<div class="col w-15 text-end">
|
||||
<input type="submit" name="submit" value="TODO Save" class="btn btn-primary">
|
||||
|
||||
@@ -85,6 +85,7 @@ Route::group(
|
||||
Route::get('tags', ['uses' => 'TagController@tags', 'as' => 'tags']);
|
||||
Route::get('transactions', ['uses' => 'TransactionController@transactions', 'as' => 'transactions']);
|
||||
Route::get('transactions-with-id', ['uses' => 'TransactionController@transactionsWithID', 'as' => 'transactions-with-id']);
|
||||
Route::get('transactions-with-meta', ['uses' => 'TransactionController@transactionsWithMeta', 'as' => 'transactions-with-meta']);
|
||||
Route::get('transaction-types', ['uses' => 'TransactionTypeController@transactionTypes', 'as' => 'transaction-types']);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user