mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand API to return transaction groups.
This commit is contained in:
parent
7a2d4c9bd2
commit
02c906afe6
@ -148,7 +148,7 @@ class Controller extends BaseController
|
||||
$objects = $paginator->getCollection();
|
||||
|
||||
// the transformer, at this point, needs to collect information that ALL items in the collection
|
||||
// require, like meta data and stuff like that, and save it for later.
|
||||
// require, like meta-data and stuff like that, and save it for later.
|
||||
$transformer->collectMetaData($objects);
|
||||
|
||||
$resource = new FractalCollection($objects, $transformer, $key);
|
||||
|
@ -49,19 +49,17 @@ class AccountController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function listTransactions(ListRequest $request, Account $account): JsonResponse
|
||||
public function list(ListRequest $request, Account $account): JsonResponse
|
||||
{
|
||||
// collect transactions:
|
||||
$type = $request->get('type') ?? 'default';
|
||||
$limit = (int)$request->get('limit');
|
||||
$page = (int)$request->get('page');
|
||||
$limit = $request->getLimit();
|
||||
$page = $request->getPage();
|
||||
$page = max($page, 1);
|
||||
|
||||
if ($limit > 0 && $limit <= $this->pageSize) {
|
||||
$this->pageSize = $limit;
|
||||
}
|
||||
|
||||
$types = $this->mapTransactionTypes($type);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
@ -69,15 +67,23 @@ class AccountController extends Controller
|
||||
->withAPIInformation()
|
||||
->setLimit($this->pageSize)
|
||||
->setPage($page)
|
||||
->setTypes($types);
|
||||
->setTypes($request->getTransactionTypes());
|
||||
|
||||
// TODO date filter
|
||||
//if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
||||
// $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
//}
|
||||
$start = $request->getStartDate();
|
||||
$end = $request->getEndDate();
|
||||
if (null !== $start) {
|
||||
$collector->setStart($start);
|
||||
}
|
||||
if (null !== $end) {
|
||||
$collector->setEnd($start);
|
||||
}
|
||||
|
||||
$paginator = $collector->getPaginatedGroups();
|
||||
$paginator->setPath(route('api.v2.accounts.transactions', [$account->id])); // TODO . $this->buildParams()
|
||||
$paginator->setPath(
|
||||
sprintf('%s?%s',
|
||||
route('api.v2.accounts.transactions', [$account->id]),
|
||||
$request->buildParams())
|
||||
);
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer()))
|
||||
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/*
|
||||
* TransactionController.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Api\V2\Controllers\Transaction\List;
|
||||
|
||||
use FireflyIII\Api\V2\Controllers\Controller;
|
||||
use FireflyIII\Api\V2\Request\Transaction\ListRequest;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Transformers\V2\TransactionGroupTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* Class TransactionController
|
||||
*/
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ListRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function list(ListRequest $request): JsonResponse
|
||||
{
|
||||
// collect transactions:
|
||||
$limit = $request->getLimit();
|
||||
$page = $request->getPage();
|
||||
$page = max($page, 1);
|
||||
|
||||
if ($limit > 0 && $limit <= $this->pageSize) {
|
||||
$this->pageSize = $limit;
|
||||
}
|
||||
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUserGroup(auth()->user()->userGroup)
|
||||
->withAPIInformation()
|
||||
->setLimit($this->pageSize)
|
||||
->setPage($page)
|
||||
->setTypes($request->getTransactionTypes());
|
||||
|
||||
$start = $request->getStartDate();
|
||||
$end = $request->getEndDate();
|
||||
if (null !== $start) {
|
||||
$collector->setStart($start);
|
||||
}
|
||||
if (null !== $end) {
|
||||
$collector->setEnd($start);
|
||||
}
|
||||
|
||||
$paginator = $collector->getPaginatedGroups();
|
||||
$paginator->setPath(
|
||||
sprintf('%s?%s',
|
||||
route('api.v2.transactions.list'),
|
||||
$request->buildParams())
|
||||
);
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer()))
|
||||
->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,15 +24,84 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V2\Request\Transaction;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Support\Http\Api\TransactionFilter;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* Class ListRequest
|
||||
* Used specifically to list transactions.
|
||||
*/
|
||||
class ListRequest extends FormRequest
|
||||
{
|
||||
use ChecksLogin;
|
||||
use ConvertsDataTypes;
|
||||
use TransactionFilter;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function buildParams(): string
|
||||
{
|
||||
$array = [
|
||||
'page' => $this->getPage(),
|
||||
];
|
||||
|
||||
$start = $this->getStartDate();
|
||||
$end = $this->getEndDate();
|
||||
if (null !== $start && null !== $end) {
|
||||
$array['start'] = $start->format('Y-m-d');
|
||||
$array['end'] = $end->format('Y-m-d');
|
||||
}
|
||||
if (0 !== $this->getLimit()) {
|
||||
$array['limit'] = $this->getLimit();
|
||||
}
|
||||
return http_build_query($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPage(): int
|
||||
{
|
||||
$page = $this->convertInteger('page');
|
||||
return 0 === $page || $page > 65536 ? 1 : $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function getStartDate(): ?Carbon
|
||||
{
|
||||
return $this->getCarbonDate('start');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function getEndDate(): ?Carbon
|
||||
{
|
||||
return $this->getCarbonDate('end');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLimit(): int
|
||||
{
|
||||
return $this->convertInteger('limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactionTypes(): array
|
||||
{
|
||||
$type = (string)$this->get('type', 'default');
|
||||
return $this->mapTransactionTypes($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@ -675,6 +675,23 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the end time of the results to return.
|
||||
*
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setEnd(Carbon $end): GroupCollectorInterface
|
||||
{
|
||||
// always got to end of day / start of day for ranges.
|
||||
$endStr = $end->format('Y-m-d 23:59:59');
|
||||
|
||||
$this->query->where('transaction_journals.date', '<=', $endStr);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param string $field
|
||||
@ -822,6 +839,22 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the start time of the results to return.
|
||||
*
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setStart(Carbon $start): GroupCollectorInterface
|
||||
{
|
||||
$startStr = $start->format('Y-m-d 00:00:00');
|
||||
|
||||
$this->query->where('transaction_journals.date', '>=', $startStr);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect transactions updated on a specific date.
|
||||
*
|
||||
|
@ -1078,6 +1078,15 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setDestinationAccounts(Collection $accounts): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Set the end time of the results to return.
|
||||
*
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setEnd(Carbon $end): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* @param bool $expandGroupSearch
|
||||
*/
|
||||
@ -1262,6 +1271,15 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setSourceAccounts(Collection $accounts): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Set the start time of the results to return.
|
||||
*
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setStart(Carbon $start): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit results to a specific tag.
|
||||
*
|
||||
|
59
app/Support/Binder/UserGroupAccount.php
Normal file
59
app/Support/Binder/UserGroupAccount.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AccountList.php
|
||||
* Copyright (c) 2019 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\Account;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class UserGroupAccount.
|
||||
*/
|
||||
class UserGroupAccount implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Account
|
||||
* @throws NotFoundHttpException
|
||||
*
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): Account
|
||||
{
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$currency = Account::where('id', (int)$value)
|
||||
->where('user_group_id', $user->user_group_id)
|
||||
->first();
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ trait TransactionFilter
|
||||
*/
|
||||
protected function mapTransactionTypes(string $type): array
|
||||
{
|
||||
$types = [
|
||||
$types = [
|
||||
'all' => [
|
||||
TransactionType::WITHDRAWAL,
|
||||
TransactionType::DEPOSIT,
|
||||
@ -65,7 +65,11 @@ trait TransactionFilter
|
||||
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,],
|
||||
'default' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER,],
|
||||
];
|
||||
|
||||
return $types[$type] ?? $types['default'];
|
||||
$return = [];
|
||||
$parts = explode(',', $type);
|
||||
foreach ($parts as $part) {
|
||||
$return = array_merge($return, $types[$part] ?? $types['default']);
|
||||
}
|
||||
return array_unique($return);
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ abstract class AbstractTransformer extends TransformerAbstract
|
||||
protected ParameterBag $parameters;
|
||||
|
||||
/**
|
||||
* This method is called exactly ONCE from FireflyIII\Api\V2\Controllers\Controller::jsonApiList
|
||||
*
|
||||
* @param Collection $objects
|
||||
*
|
||||
* @return void
|
||||
|
@ -25,13 +25,19 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers\V2;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\Http\Api\ConvertsExchangeRates;
|
||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class TransactionGroupTransformer
|
||||
@ -40,9 +46,12 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
{
|
||||
use ConvertsExchangeRates;
|
||||
|
||||
private array $currencies = [];
|
||||
private TransactionCurrency $default;
|
||||
private array $meta;
|
||||
private ExchangeRateConverter $converter;
|
||||
private array $currencies = [];
|
||||
private TransactionCurrency $default;
|
||||
private array $meta;
|
||||
private array $notes;
|
||||
private array $tags;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
@ -55,15 +64,12 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
/** @var array $object */
|
||||
foreach ($objects as $object) {
|
||||
foreach ($object['sums'] as $sum) {
|
||||
$id = $sum['currency_id'];
|
||||
if (!array_key_exists($id, $currencies)) {
|
||||
$currencyObject = TransactionCurrency::find($sum['currency_id']);
|
||||
$currencies[$id] = $currencyObject;
|
||||
}
|
||||
$id = (int)$sum['currency_id'];
|
||||
$currencies[$id] = $currencies[$id] ?? TransactionCurrency::find($sum['currency_id']);
|
||||
}
|
||||
/** @var array $transaction */
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
$id = $transaction['transaction_journal_id'];
|
||||
$id = (int)$transaction['transaction_journal_id'];
|
||||
$journals[$id] = [];
|
||||
}
|
||||
}
|
||||
@ -77,6 +83,28 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
$id = (int)$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 = (int)$note->noteable_id;
|
||||
$this->notes[$id] = $note;
|
||||
}
|
||||
|
||||
// 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
|
||||
$this->converter = new ExchangeRateConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,6 +120,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'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'] ?? []),
|
||||
'links' => [
|
||||
@ -122,108 +151,102 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function transformTransaction(array $transaction): array
|
||||
{
|
||||
$transaction = new NullArrayObject($transaction);
|
||||
$journalId = (int)$transaction['transaction_journal_id'];
|
||||
$meta = new NullArrayObject($this->meta[$journalId] ?? []);
|
||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL);
|
||||
$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:
|
||||
*/
|
||||
$amount = app('steam')->positive((string)($transaction['amount'] ?? '0'));
|
||||
$currencyId = (int)$transaction['currency_id'];
|
||||
$nativeAmount = $this->converter->convert($this->default, $this->currencies[$currencyId], $transaction['date'], $amount);
|
||||
$foreignAmount = null;
|
||||
$nativeForeignAmount = null;
|
||||
if (null !== $transaction['foreign_amount']) {
|
||||
$foreignCurrencyId = (int)$transaction['foreign_currency_id'];
|
||||
$foreignAmount = app('steam')->positive($transaction['foreign_amount']);
|
||||
$nativeForeignAmount = $foreignAmount;
|
||||
if ($transaction['foreign_currency_id'] !== $this->default->id) {
|
||||
$rate = $this->getRate($this->currencies[$transaction['foreign_currency_id']], $this->default, $transaction['date']);
|
||||
$nativeForeignAmount = bcmul($foreignAmount, $rate);
|
||||
}
|
||||
}
|
||||
|
||||
$nativeAmount = $amount;
|
||||
if ($transaction['currency_id'] !== $this->default->id) {
|
||||
$rate = $this->getRate($this->currencies[$transaction['currency_id']], $this->default, $transaction['date']);
|
||||
$nativeAmount = bcmul($amount, $rate);
|
||||
$nativeForeignAmount = $this->converter->convert($this->default, $this->currencies[$foreignCurrencyId], $transaction['date'], $foreignAmount);
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => (string)$transaction['user_id'],
|
||||
'transaction_journal_id' => (string)$transaction['transaction_journal_id'],
|
||||
'type' => strtolower($type),
|
||||
'date' => $transaction['date']->toAtomString(),
|
||||
'order' => $transaction['order'],
|
||||
'currency_id' => (string)$transaction['currency_id'],
|
||||
'currency_code' => $transaction['currency_code'],
|
||||
'currency_name' => $transaction['currency_name'],
|
||||
'currency_symbol' => $transaction['currency_symbol'],
|
||||
'currency_decimal_places' => (int)$transaction['currency_decimal_places'],
|
||||
'user' => (string)$transaction['user_id'],
|
||||
'user_group' => (string)$transaction['user_group_id'],
|
||||
'transaction_journal_id' => (string)$transaction['transaction_journal_id'],
|
||||
'type' => strtolower($type),
|
||||
'date' => $transaction['date']->toAtomString(),
|
||||
'order' => $transaction['order'],
|
||||
'amount' => $amount,
|
||||
'native_amount' => $nativeAmount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'native_foreign_amount' => $nativeForeignAmount,
|
||||
'currency_id' => (string)$transaction['currency_id'],
|
||||
'currency_code' => $transaction['currency_code'],
|
||||
'currency_name' => $transaction['currency_name'],
|
||||
'currency_symbol' => $transaction['currency_symbol'],
|
||||
'currency_decimal_places' => (int)$transaction['currency_decimal_places'],
|
||||
|
||||
// converted to native currency
|
||||
'native_currency_converted' => $transaction['currency_id'] !== $this->default->id,
|
||||
'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' => (int)$this->default->decimal_places,
|
||||
'native_id' => (string)$this->default->id,
|
||||
'native_code' => $this->default->code,
|
||||
'native_name' => $this->default->name,
|
||||
'native_symbol' => $this->default->symbol,
|
||||
'native_decimal_places' => (int)$this->default->decimal_places,
|
||||
|
||||
// foreign currency amount:
|
||||
'foreign_currency_id' => $this->stringFromArray($transaction, 'foreign_currency_id', null),
|
||||
'foreign_currency_code' => $transaction['foreign_currency_code'],
|
||||
'foreign_currency_name' => $transaction['foreign_currency_name'],
|
||||
'foreign_currency_symbol' => $transaction['foreign_currency_symbol'],
|
||||
'foreign_currency_decimal_places' => $transaction['foreign_currency_decimal_places'],
|
||||
|
||||
// foreign converted to native currency:
|
||||
'foreign_currency_converted' => null !== $transaction['foreign_currency_id'] && $transaction['foreign_currency_id'] !== $this->default->id,
|
||||
|
||||
'amount' => $amount,
|
||||
'native_amount' => $nativeAmount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'native_foreign_amount' => $nativeForeignAmount,
|
||||
'description' => $transaction['description'],
|
||||
'source_id' => (string)$transaction['source_account_id'],
|
||||
'source_name' => $transaction['source_account_name'],
|
||||
'source_iban' => $transaction['source_account_iban'],
|
||||
'source_type' => $transaction['source_account_type'],
|
||||
'destination_id' => (string)$transaction['destination_account_id'],
|
||||
'destination_name' => $transaction['destination_account_name'],
|
||||
'destination_iban' => $transaction['destination_account_iban'],
|
||||
'destination_type' => $transaction['destination_account_type'],
|
||||
'budget_id' => $this->stringFromArray($transaction, 'budget_id', null),
|
||||
'budget_name' => $transaction['budget_name'],
|
||||
'category_id' => $this->stringFromArray($transaction, 'category_id', null),
|
||||
'category_name' => $transaction['category_name'],
|
||||
'bill_id' => $this->stringFromArray($transaction, 'bill_id', null),
|
||||
'bill_name' => $transaction['bill_name'],
|
||||
'reconciled' => $transaction['reconciled'],
|
||||
|
||||
//'notes' => $this->groupRepos->getNoteText((int) $row['transaction_journal_id']),
|
||||
//'tags' => $this->groupRepos->getTags((int) $row['transaction_journal_id']),
|
||||
|
||||
'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'],
|
||||
'bunq_payment_id' => $meta['bunq_payment_id'],
|
||||
'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']),
|
||||
// foreign converted to native:
|
||||
'description' => $transaction['description'],
|
||||
'source_id' => (string)$transaction['source_account_id'],
|
||||
'source_name' => $transaction['source_account_name'],
|
||||
'source_iban' => $transaction['source_account_iban'],
|
||||
'source_type' => $transaction['source_account_type'],
|
||||
'destination_id' => (string)$transaction['destination_account_id'],
|
||||
'destination_name' => $transaction['destination_account_name'],
|
||||
'destination_iban' => $transaction['destination_account_iban'],
|
||||
'destination_type' => $transaction['destination_account_type'],
|
||||
'budget_id' => $this->stringFromArray($transaction, 'budget_id', null),
|
||||
'budget_name' => $transaction['budget_name'],
|
||||
'category_id' => $this->stringFromArray($transaction, 'category_id', null),
|
||||
'category_name' => $transaction['category_name'],
|
||||
'bill_id' => $this->stringFromArray($transaction, 'bill_id', null),
|
||||
'bill_name' => $transaction['bill_name'],
|
||||
'reconciled' => $transaction['reconciled'],
|
||||
'notes' => $this->notes[$journalId] ?? null,
|
||||
'tags' => $this->tags[$journalId] ?? [],
|
||||
'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'],
|
||||
'bunq_payment_id' => $meta['bunq_payment_id'],
|
||||
'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,
|
||||
@ -237,6 +260,9 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
/**
|
||||
* TODO also in the old transformer.
|
||||
*
|
||||
* Used to extract a value from the given array, and fall back on a sensible default or NULL
|
||||
* if it can't be helped.
|
||||
*
|
||||
* @param NullArrayObject $array
|
||||
* @param string $key
|
||||
* @param string|null $default
|
||||
|
@ -60,6 +60,7 @@ use FireflyIII\Support\Binder\EitherConfigKey;
|
||||
use FireflyIII\Support\Binder\JournalList;
|
||||
use FireflyIII\Support\Binder\TagList;
|
||||
use FireflyIII\Support\Binder\TagOrId;
|
||||
use FireflyIII\Support\Binder\UserGroupAccount;
|
||||
use FireflyIII\TransactionRules\Actions\AddTag;
|
||||
use FireflyIII\TransactionRules\Actions\AppendDescription;
|
||||
use FireflyIII\TransactionRules\Actions\AppendDescriptionToNotes;
|
||||
@ -476,6 +477,9 @@ return [
|
||||
'dynamicConfigKey' => DynamicConfigKey::class,
|
||||
'eitherConfigKey' => EitherConfigKey::class,
|
||||
|
||||
// V2 API endpoints:
|
||||
'userGroupAccount' => UserGroupAccount::class,
|
||||
|
||||
|
||||
],
|
||||
'rule-actions' => [
|
||||
|
@ -58,7 +58,8 @@ Route::group(
|
||||
'as' => 'api.v2.',
|
||||
],
|
||||
static function () {
|
||||
Route::get('accounts/{account}/transactions', ['uses' => 'AccountController@listTransactions', 'as' => 'accounts.transactions']);
|
||||
Route::get('transactions', ['uses' => 'TransactionController@list', 'as' => 'transactions.list']);
|
||||
Route::get('accounts/{userGroupAccount}/transactions', ['uses' => 'AccountController@list', 'as' => 'accounts.transactions']);
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user