Fix methods and clean up code.

This commit is contained in:
James Cole
2024-03-09 19:46:16 +01:00
parent 487b65b669
commit 66b322e844
19 changed files with 153 additions and 139 deletions

View File

@@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "composer/pcre", "name": "composer/pcre",
"version": "3.1.1", "version": "3.1.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/composer/pcre.git", "url": "https://github.com/composer/pcre.git",
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9" "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9", "url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace",
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9", "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -59,7 +59,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/composer/pcre/issues", "issues": "https://github.com/composer/pcre/issues",
"source": "https://github.com/composer/pcre/tree/3.1.1" "source": "https://github.com/composer/pcre/tree/3.1.2"
}, },
"funding": [ "funding": [
{ {
@@ -75,7 +75,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-10-11T07:11:09+00:00" "time": "2024-03-07T15:38:35+00:00"
}, },
{ {
"name": "composer/semver", "name": "composer/semver",

View File

@@ -158,7 +158,7 @@ class Controller extends BaseController
// the transformer, at this point, needs to collect information that ALL items in the collection // 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.
$objects = $transformer->collectMetaData($objects); $objects = $transformer->collectMetaData($objects);
$paginator->setCollection($objects); $paginator->setCollection($objects);
$resource = new FractalCollection($objects, $transformer, $key); $resource = new FractalCollection($objects, $transformer, $key);

View File

@@ -47,7 +47,7 @@ class IndexController extends Controller
function ($request, $next) { function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
// new way of user group validation // new way of user group validation
$userGroup = $this->validateUserGroup($request); $userGroup = $this->validateUserGroup($request);
if (null !== $userGroup) { if (null !== $userGroup) {
$this->repository->setUserGroup($userGroup); $this->repository->setUserGroup($userGroup);
} }
@@ -62,7 +62,6 @@ class IndexController extends Controller
*/ */
public function index(IndexRequest $request): JsonResponse public function index(IndexRequest $request): JsonResponse
{ {
$this->repository->resetAccountOrder(); $this->repository->resetAccountOrder();
$types = $request->getAccountTypes(); $types = $request->getAccountTypes();
$instructions = $request->getSortInstructions('accounts'); $instructions = $request->getSortInstructions('accounts');
@@ -78,7 +77,8 @@ class IndexController extends Controller
return response() return response()
->json($this->jsonApiList('accounts', $paginator, $transformer)) ->json($this->jsonApiList('accounts', $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE); ->header('Content-Type', self::CONTENT_TYPE)
;
} }
public function infiniteList(InfiniteListRequest $request): JsonResponse public function infiniteList(InfiniteListRequest $request): JsonResponse
@@ -86,7 +86,7 @@ class IndexController extends Controller
$this->repository->resetAccountOrder(); $this->repository->resetAccountOrder();
// get accounts of the specified type, and return. // get accounts of the specified type, and return.
$types = $request->getAccountTypes(); $types = $request->getAccountTypes();
// get from repository // get from repository
$accounts = $this->repository->getAccountsInOrder($types, $request->getSortInstructions('accounts'), $request->getStartRow(), $request->getEndRow()); $accounts = $this->repository->getAccountsInOrder($types, $request->getSortInstructions('accounts'), $request->getStartRow(), $request->getEndRow());
@@ -98,6 +98,7 @@ class IndexController extends Controller
return response() return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer)) ->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE); ->header('Content-Type', self::CONTENT_TYPE)
;
} }
} }

View File

@@ -41,8 +41,8 @@ class InfiniteListRequest extends FormRequest
use AccountFilter; use AccountFilter;
use ChecksLogin; use ChecksLogin;
use ConvertsDataTypes; use ConvertsDataTypes;
use TransactionFilter;
use GetSortInstructions; use GetSortInstructions;
use TransactionFilter;
public function buildParams(): string public function buildParams(): string
{ {
@@ -99,7 +99,6 @@ class InfiniteListRequest extends FormRequest
return 0 === $page || $page > 65536 ? 1 : $page; return 0 === $page || $page > 65536 ? 1 : $page;
} }
public function getTransactionTypes(): array public function getTransactionTypes(): array
{ {
$type = (string)$this->get('type', 'default'); $type = (string)$this->get('type', 'default');

View File

@@ -74,20 +74,22 @@ class LoginController extends Controller
* *
* @throws ValidationException * @throws ValidationException
*/ */
public function login(Request $request): JsonResponse | RedirectResponse public function login(Request $request): JsonResponse|RedirectResponse
{ {
Log::channel('audit')->info(sprintf('User is trying to login using "%s"', $request->get($this->username()))); Log::channel('audit')->info(sprintf('User is trying to login using "%s"', $request->get($this->username())));
app('log')->debug('User is trying to login.'); app('log')->debug('User is trying to login.');
try { try {
$this->validateLogin($request); $this->validateLogin($request);
} catch (ValidationException $e) { } catch (ValidationException $e) {
return redirect(route('login')) return redirect(route('login'))
->withErrors( ->withErrors(
[ [
$this->username => trans('auth.failed') $this->username => trans('auth.failed'),
] ]
) )
->onlyInput($this->username); ->onlyInput($this->username)
;
} }
app('log')->debug('Login data is present.'); app('log')->debug('Login data is present.');
@@ -125,7 +127,6 @@ class LoginController extends Controller
$this->sendFailedLoginResponse($request); $this->sendFailedLoginResponse($request);
// @noinspection PhpUnreachableStatementInspection // @noinspection PhpUnreachableStatementInspection
return response()->json([]); return response()->json([]);
} }
@@ -166,8 +167,8 @@ class LoginController extends Controller
*/ */
public function logout(Request $request) public function logout(Request $request)
{ {
$authGuard = config('firefly.authentication_guard'); $authGuard = config('firefly.authentication_guard');
$logoutUrl = config('firefly.custom_logout_url'); $logoutUrl = config('firefly.custom_logout_url');
if ('remote_user_guard' === $authGuard && '' !== $logoutUrl) { if ('remote_user_guard' === $authGuard && '' !== $logoutUrl) {
return redirect($logoutUrl); return redirect($logoutUrl);
} }
@@ -203,9 +204,9 @@ class LoginController extends Controller
{ {
Log::channel('audit')->info('Show login form (1.1).'); Log::channel('audit')->info('Show login form (1.1).');
$count = \DB::table('users')->count(); $count = \DB::table('users')->count();
$guard = config('auth.defaults.guard'); $guard = config('auth.defaults.guard');
$title = (string)trans('firefly.login_page_title'); $title = (string)trans('firefly.login_page_title');
if (0 === $count && 'web' === $guard) { if (0 === $count && 'web' === $guard) {
return redirect(route('register')); return redirect(route('register'));
@@ -225,16 +226,15 @@ class LoginController extends Controller
$allowReset = false; $allowReset = false;
} }
$email = $request->old('email'); $email = $request->old('email');
$remember = $request->old('remember'); $remember = $request->old('remember');
$storeInCookie = config('google2fa.store_in_cookie', false); $storeInCookie = config('google2fa.store_in_cookie', false);
if (false !== $storeInCookie) { if (false !== $storeInCookie) {
$cookieName = config('google2fa.cookie_name', 'google2fa_token'); $cookieName = config('google2fa.cookie_name', 'google2fa_token');
request()->cookies->set($cookieName, 'invalid'); request()->cookies->set($cookieName, 'invalid');
} }
$usernameField = $this->username(); $usernameField = $this->username();
return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField')); return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField'));
} }

View File

@@ -95,21 +95,21 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|Account withTrashed() * @method static Builder|Account withTrashed()
* @method static Builder|Account withoutTrashed() * @method static Builder|Account withoutTrashed()
* *
* @property Carbon $lastActivityDate * @property Carbon $lastActivityDate
* @property string $startBalance * @property string $startBalance
* @property string $endBalance * @property string $endBalance
* @property string $difference * @property string $difference
* @property string $interest * @property string $interest
* @property string $interestPeriod * @property string $interestPeriod
* @property string $accountTypeString * @property string $accountTypeString
* @property Location $location * @property Location $location
* @property string $liability_direction * @property string $liability_direction
* @property string $current_debt * @property string $current_debt
* @property int $user_group_id * @property int $user_group_id
* *
* @method static EloquentBuilder|Account whereUserGroupId($value) * @method static EloquentBuilder|Account whereUserGroupId($value)
* *
* @property null|UserGroup $userGroup * @property null|UserGroup $userGroup
* *
* @mixin Eloquent * @mixin Eloquent
*/ */
@@ -121,7 +121,7 @@ class Account extends Model
use SoftDeletes; use SoftDeletes;
protected $casts protected $casts
= [ = [
'created_at' => 'datetime', 'created_at' => 'datetime',
'updated_at' => 'datetime', 'updated_at' => 'datetime',
'user_id' => 'integer', 'user_id' => 'integer',
@@ -130,9 +130,9 @@ class Account extends Model
'encrypted' => 'boolean', 'encrypted' => 'boolean',
]; ];
protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban']; protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
protected $hidden = ['encrypted']; protected $hidden = ['encrypted'];
private bool $joinedAccountTypes = false; private bool $joinedAccountTypes = false;
/** /**
@@ -146,10 +146,10 @@ class Account extends Model
$accountId = (int)$value; $accountId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var null|Account $account */ /** @var null|Account $account */
$account = $user->accounts()->with(['accountType'])->find($accountId); $account = $user->accounts()->with(['accountType'])->find($accountId);
if (null !== $account) { if (null !== $account) {
return $account; return $account;
} }
@@ -180,8 +180,9 @@ class Account extends Model
{ {
/** @var null|AccountMeta $metaValue */ /** @var null|AccountMeta $metaValue */
$metaValue = $this->accountMeta() $metaValue = $this->accountMeta()
->where('name', 'account_number') ->where('name', 'account_number')
->first(); ->first()
;
return null !== $metaValue ? $metaValue->data : ''; return null !== $metaValue ? $metaValue->data : '';
} }
@@ -239,7 +240,7 @@ class Account extends Model
public function setVirtualBalanceAttribute(mixed $value): void public function setVirtualBalanceAttribute(mixed $value): void
{ {
$value = (string)$value; $value = (string)$value;
if ('' === $value) { if ('' === $value) {
$value = null; $value = null;
} }
@@ -259,7 +260,7 @@ class Account extends Model
protected function accountId(): Attribute protected function accountId(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn($value) => (int)$value, get: static fn ($value) => (int)$value,
); );
} }
@@ -269,22 +270,21 @@ class Account extends Model
protected function accountTypeId(): Attribute protected function accountTypeId(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn($value) => (int)$value, get: static fn ($value) => (int)$value,
); );
} }
//
protected function iban(): Attribute protected function iban(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn($value) => null === $value ? null : trim(str_replace(' ', '', (string)$value)), get: static fn ($value) => null === $value ? null : trim(str_replace(' ', '', (string)$value)),
); );
} }
protected function order(): Attribute protected function order(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn($value) => (int)$value, get: static fn ($value) => (int)$value,
); );
} }
@@ -294,7 +294,7 @@ class Account extends Model
protected function virtualBalance(): Attribute protected function virtualBalance(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: static fn($value) => (string)$value, get: static fn ($value) => (string)$value,
); );
} }
} }

View File

@@ -62,7 +62,8 @@ class AccountRepository implements AccountRepositoryInterface
$q1->where('account_meta.name', '=', 'account_number'); $q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json); $q1->where('account_meta.data', '=', $json);
} }
); )
;
if (0 !== count($types)) { if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -88,7 +89,7 @@ class AccountRepository implements AccountRepositoryInterface
public function findByName(string $name, array $types): ?Account public function findByName(string $name, array $types): ?Account
{ {
$query = $this->userGroup->accounts(); $query = $this->userGroup->accounts();
if (0 !== count($types)) { if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -112,8 +113,8 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccountCurrency(Account $account): ?TransactionCurrency public function getAccountCurrency(Account $account): ?TransactionCurrency
{ {
$type = $account->accountType->type; $type = $account->accountType->type;
$list = config('firefly.valid_currency_account_types'); $list = config('firefly.valid_currency_account_types');
// return null if not in this list. // return null if not in this list.
if (!in_array($type, $list, true)) { if (!in_array($type, $list, true)) {
@@ -269,11 +270,12 @@ class AccountRepository implements AccountRepositoryInterface
{ {
// search by group, not by user // search by group, not by user
$dbQuery = $this->userGroup->accounts() $dbQuery = $this->userGroup->accounts()
->where('active', true) ->where('active', true)
->orderBy('accounts.order', 'ASC') ->orderBy('accounts.order', 'ASC')
->orderBy('accounts.account_type_id', 'ASC') ->orderBy('accounts.account_type_id', 'ASC')
->orderBy('accounts.name', 'ASC') ->orderBy('accounts.name', 'ASC')
->with(['accountType']); ->with(['accountType'])
;
if ('' !== $query) { if ('' !== $query) {
// split query on spaces just in case: // split query on spaces just in case:
$parts = explode(' ', $query); $parts = explode(' ', $query);

View File

@@ -25,7 +25,6 @@ namespace FireflyIII\Support\Request;
trait GetSortInstructions trait GetSortInstructions
{ {
final public function getSortInstructions(string $key): array final public function getSortInstructions(string $key): array
{ {
$allowed = config(sprintf('firefly.sorting.allowed.%s', $key)); $allowed = config(sprintf('firefly.sorting.allowed.%s', $key));
@@ -50,5 +49,4 @@ trait GetSortInstructions
return $result; return $result;
} }
} }

View File

@@ -37,9 +37,6 @@ abstract class AbstractTransformer extends TransformerAbstract
/** /**
* This method is called exactly ONCE from FireflyIII\Api\V2\Controllers\Controller::jsonApiList * This method is called exactly ONCE from FireflyIII\Api\V2\Controllers\Controller::jsonApiList
*
* @param Collection $objects
* @return Collection
*/ */
abstract public function collectMetaData(Collection $objects): Collection; abstract public function collectMetaData(Collection $objects): Collection;

View File

@@ -32,7 +32,6 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/** /**
* Class AccountTransformer * Class AccountTransformer
@@ -58,17 +57,18 @@ class AccountTransformer extends AbstractTransformer
$this->convertedBalances = app('steam')->balancesByAccountsConverted($objects, $this->getDate()); $this->convertedBalances = app('steam')->balancesByAccountsConverted($objects, $this->getDate());
/** @var CurrencyRepositoryInterface $repository */ /** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class); $repository = app(CurrencyRepositoryInterface::class);
$this->default = app('amount')->getDefaultCurrency(); $this->default = app('amount')->getDefaultCurrency();
// get currencies: // get currencies:
$accountIds = $objects->pluck('id')->toArray(); $accountIds = $objects->pluck('id')->toArray();
$meta = AccountMeta::whereIn('account_id', $accountIds) $meta = AccountMeta::whereIn('account_id', $accountIds)
->whereIn('name', ['currency_id','account_role','account_number']) ->whereIn('name', ['currency_id', 'account_role', 'account_number'])
->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']); ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])
$currencyIds = $meta->where('name','currency_id')->pluck('data')->toArray(); ;
$currencyIds = $meta->where('name', 'currency_id')->pluck('data')->toArray();
$currencies = $repository->getByIds($currencyIds); $currencies = $repository->getByIds($currencyIds);
foreach ($currencies as $currency) { foreach ($currencies as $currency) {
$id = $currency->id; $id = $currency->id;
$this->currencies[$id] = $currency; $this->currencies[$id] = $currency;
@@ -79,9 +79,10 @@ class AccountTransformer extends AbstractTransformer
} }
// get account types: // get account types:
// select accounts.id, account_types.type from account_types left join accounts on accounts.account_type_id = account_types.id; // select accounts.id, account_types.type from account_types left join accounts on accounts.account_type_id = account_types.id;
$accountTypes = AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id') $accountTypes = AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id')
->whereIn('accounts.id', $accountIds) ->whereIn('accounts.id', $accountIds)
->get(['accounts.id', 'account_types.type']); ->get(['accounts.id', 'account_types.type'])
;
/** @var AccountType $row */ /** @var AccountType $row */
foreach ($accountTypes as $row) { foreach ($accountTypes as $row) {
@@ -89,36 +90,38 @@ class AccountTransformer extends AbstractTransformer
} }
// TODO needs separate method. // TODO needs separate method.
$sort = $this->parameters->get('sort'); $sort = $this->parameters->get('sort');
if (count($sort) > 0) { if (count($sort) > 0) {
foreach ($sort as $column => $direction) { foreach ($sort as $column => $direction) {
// account_number + iban // account_number + iban
if ('iban' === $column) { if ('iban' === $column) {
$meta = $this->accountMeta; $meta = $this->accountMeta;
$objects = $objects->sort(function (Account $left, Account $right) use ($meta, $direction) { $objects = $objects->sort(function (Account $left, Account $right) use ($meta, $direction) {
$leftIban = trim(sprintf('%s%s', $left->iban, ($meta[$left->id]['account_number'] ?? ''))); $leftIban = trim(sprintf('%s%s', $left->iban, $meta[$left->id]['account_number'] ?? ''));
$rightIban = trim(sprintf('%s%s', $right->iban, ($meta[$right->id]['account_number'] ?? ''))); $rightIban = trim(sprintf('%s%s', $right->iban, $meta[$right->id]['account_number'] ?? ''));
if ('asc' === $direction) { if ('asc' === $direction) {
return strcasecmp($leftIban, $rightIban); return strcasecmp($leftIban, $rightIban);
} }
return strcasecmp($rightIban, $leftIban); return strcasecmp($rightIban, $leftIban);
}); });
} }
if('balance' === $column) { if ('balance' === $column) {
$balances = $this->convertedBalances; $balances = $this->convertedBalances;
$objects = $objects->sort(function (Account $left, Account $right) use ($balances, $direction) { $objects = $objects->sort(function (Account $left, Account $right) use ($balances, $direction) {
$leftBalance = (float)($balances[$left->id]['native_balance'] ?? 0); $leftBalance = (float)($balances[$left->id]['native_balance'] ?? 0);
$rightBalance = (float)($balances[$right->id]['native_balance'] ?? 0); $rightBalance = (float)($balances[$right->id]['native_balance'] ?? 0);
if ('asc' === $direction) { if ('asc' === $direction) {
return $leftBalance <=> $rightBalance; return $leftBalance <=> $rightBalance;
} }
return $rightBalance <=> $leftBalance; return $rightBalance <=> $leftBalance;
}); });
} }
} }
} }
//$objects = $objects->sortByDesc('name');
// $objects = $objects->sortByDesc('name');
return $objects; return $objects;
} }
@@ -137,15 +140,15 @@ class AccountTransformer extends AbstractTransformer
*/ */
public function transform(Account $account): array public function transform(Account $account): array
{ {
$id = $account->id; $id = $account->id;
// various meta // various meta
$accountRole = $this->accountMeta[$id]['account_role'] ?? null; $accountRole = $this->accountMeta[$id]['account_role'] ?? null;
$accountType = $this->accountTypes[$id]; $accountType = $this->accountTypes[$id];
$order = $account->order; $order = $account->order;
// no currency? use default // no currency? use default
$currency = $this->default; $currency = $this->default;
if (array_key_exists($id, $this->accountMeta) && 0 !== (int)$this->accountMeta[$id]['currency_id']) { if (array_key_exists($id, $this->accountMeta) && 0 !== (int)$this->accountMeta[$id]['currency_id']) {
$currency = $this->currencies[(int)$this->accountMeta[$id]['currency_id']]; $currency = $this->currencies[(int)$this->accountMeta[$id]['currency_id']];
} }
@@ -159,20 +162,20 @@ class AccountTransformer extends AbstractTransformer
} }
return [ return [
'id' => (string)$account->id, 'id' => (string)$account->id,
'created_at' => $account->created_at->toAtomString(), 'created_at' => $account->created_at->toAtomString(),
'updated_at' => $account->updated_at->toAtomString(), 'updated_at' => $account->updated_at->toAtomString(),
'active' => $account->active, 'active' => $account->active,
'order' => $order, 'order' => $order,
'name' => $account->name, 'name' => $account->name,
'iban' => '' === (string)$account->iban ? null : $account->iban, 'iban' => '' === (string)$account->iban ? null : $account->iban,
'account_number' => $this->accountMeta[$id]['account_number'] ?? null, 'account_number' => $this->accountMeta[$id]['account_number'] ?? null,
'type' => strtolower($accountType), 'type' => strtolower($accountType),
'account_role' => $accountRole, 'account_role' => $accountRole,
'currency_id' => (string)$currency->id, 'currency_id' => (string)$currency->id,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'native_currency_id' => (string)$this->default->id, 'native_currency_id' => (string)$this->default->id,
'native_currency_code' => $this->default->code, 'native_currency_code' => $this->default->code,
@@ -206,7 +209,7 @@ class AccountTransformer extends AbstractTransformer
'links' => [ 'links' => [
[ [
'rel' => 'self', 'rel' => 'self',
'uri' => '/accounts/' . $account->id, 'uri' => '/accounts/'.$account->id,
], ],
], ],
]; ];

View File

@@ -54,7 +54,7 @@ class BillTransformer extends AbstractTransformer
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
$currencies = []; $currencies = [];
$bills = []; $bills = [];
@@ -175,6 +175,8 @@ class BillTransformer extends AbstractTransformer
]; ];
} }
} }
return $objects;
} }
/** /**

View File

@@ -37,9 +37,10 @@ class BudgetLimitTransformer extends AbstractTransformer
'budget', 'budget',
]; ];
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
// TODO: Implement collectMetaData() method. // TODO: Implement collectMetaData() method.
return $objects;
} }
/** /**

View File

@@ -45,9 +45,10 @@ class BudgetTransformer extends AbstractTransformer
$this->parameters = new ParameterBag(); $this->parameters = new ParameterBag();
} }
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
// TODO: Implement collectMetaData() method. // TODO: Implement collectMetaData() method.
return $objects;
} }
/** /**

View File

@@ -31,7 +31,10 @@ use Illuminate\Support\Collection;
*/ */
class CurrencyTransformer extends AbstractTransformer class CurrencyTransformer extends AbstractTransformer
{ {
public function collectMetaData(Collection $objects): void {} public function collectMetaData(Collection $objects): Collection
{
return $objects;
}
/** /**
* Transform the currency. * Transform the currency.

View File

@@ -69,7 +69,7 @@ class PiggyBankTransformer extends AbstractTransformer
// $this->piggyRepos = app(PiggyBankRepositoryInterface::class); // $this->piggyRepos = app(PiggyBankRepositoryInterface::class);
} }
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
// TODO move to repository (does not exist yet) // TODO move to repository (does not exist yet)
$piggyBanks = $objects->pluck('id')->toArray(); $piggyBanks = $objects->pluck('id')->toArray();
@@ -135,6 +135,8 @@ class PiggyBankTransformer extends AbstractTransformer
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
$this->default = app('amount')->getDefaultCurrencyByUserGroup(auth()->user()->userGroup); $this->default = app('amount')->getDefaultCurrencyByUserGroup(auth()->user()->userGroup);
$this->converter = new ExchangeRateConverter(); $this->converter = new ExchangeRateConverter();
return $objects;
} }
/** /**

View File

@@ -31,9 +31,10 @@ use Illuminate\Support\Collection;
*/ */
class PreferenceTransformer extends AbstractTransformer class PreferenceTransformer extends AbstractTransformer
{ {
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
// TODO: Implement collectMetaData() method. // TODO: Implement collectMetaData() method.
return $objects;
} }
/** /**

View File

@@ -64,7 +64,7 @@ class TransactionGroupTransformer extends AbstractTransformer
// private array $journalCurrencies = []; // private array $journalCurrencies = [];
// private array $foreignCurrencies = []; // private array $foreignCurrencies = [];
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
$collectForObjects = false; $collectForObjects = false;
@@ -94,6 +94,8 @@ class TransactionGroupTransformer extends AbstractTransformer
// source accounts // source accounts
// destination accounts // destination accounts
} }
return $objects;
} }
private function collectForArray(array $object): void private function collectForArray(array $object): void

View File

@@ -42,7 +42,7 @@ class UserGroupTransformer extends AbstractTransformer
$this->memberships = []; $this->memberships = [];
} }
public function collectMetaData(Collection $objects): void public function collectMetaData(Collection $objects): Collection
{ {
if (auth()->check()) { if (auth()->check()) {
// collect memberships so they can be listed in the group. // collect memberships so they can be listed in the group.
@@ -67,6 +67,8 @@ class UserGroupTransformer extends AbstractTransformer
} }
} }
} }
return $objects;
} }
/** /**

View File

@@ -432,7 +432,7 @@ return [
'transfers' => 'fa-exchange', 'transfers' => 'fa-exchange',
], ],
'bindables' => [ 'bindables' => [
// models // models
'account' => Account::class, 'account' => Account::class,
'attachment' => Attachment::class, 'attachment' => Attachment::class,
@@ -490,7 +490,7 @@ return [
'userGroupBill' => UserGroupBill::class, 'userGroupBill' => UserGroupBill::class,
'userGroup' => UserGroup::class, 'userGroup' => UserGroup::class,
], ],
'rule-actions' => [ 'rule-actions' => [
'set_category' => SetCategory::class, 'set_category' => SetCategory::class,
'clear_category' => ClearCategory::class, 'clear_category' => ClearCategory::class,
'set_budget' => SetBudget::class, 'set_budget' => SetBudget::class,
@@ -521,7 +521,7 @@ return [
'set_source_to_cash' => SetSourceToCashAccount::class, 'set_source_to_cash' => SetSourceToCashAccount::class,
'set_destination_to_cash' => SetDestinationToCashAccount::class, 'set_destination_to_cash' => SetDestinationToCashAccount::class,
], ],
'context-rule-actions' => [ 'context-rule-actions' => [
'set_category', 'set_category',
'set_budget', 'set_budget',
'add_tag', 'add_tag',
@@ -540,13 +540,13 @@ return [
'convert_transfer', 'convert_transfer',
], ],
'test-triggers' => [ 'test-triggers' => [
'limit' => 10, 'limit' => 10,
'range' => 200, 'range' => 200,
], ],
// expected source types for each transaction type, in order of preference. // expected source types for each transaction type, in order of preference.
'expected_source_types' => [ 'expected_source_types' => [
'source' => [ 'source' => [
TransactionTypeModel::WITHDRAWAL => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], TransactionTypeModel::WITHDRAWAL => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
TransactionTypeEnum::DEPOSIT->value => [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::REVENUE, AccountType::CASH], TransactionTypeEnum::DEPOSIT->value => [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::REVENUE, AccountType::CASH],
@@ -591,7 +591,7 @@ return [
TransactionTypeModel::LIABILITY_CREDIT => [AccountType::LIABILITY_CREDIT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], TransactionTypeModel::LIABILITY_CREDIT => [AccountType::LIABILITY_CREDIT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
], ],
], ],
'allowed_opposing_types' => [ 'allowed_opposing_types' => [
'source' => [ 'source' => [
AccountType::ASSET => [ AccountType::ASSET => [
AccountType::ASSET, AccountType::ASSET,
@@ -681,7 +681,7 @@ return [
], ],
], ],
// depending on the account type, return the allowed transaction types: // depending on the account type, return the allowed transaction types:
'allowed_transaction_types' => [ 'allowed_transaction_types' => [
'source' => [ 'source' => [
AccountType::ASSET => [ AccountType::ASSET => [
TransactionTypeModel::WITHDRAWAL, TransactionTypeModel::WITHDRAWAL,
@@ -750,7 +750,7 @@ return [
], ],
// having the source + dest will tell you the transaction type. // having the source + dest will tell you the transaction type.
'account_to_transaction' => [ 'account_to_transaction' => [
AccountType::ASSET => [ AccountType::ASSET => [
AccountType::ASSET => TransactionTypeModel::TRANSFER, AccountType::ASSET => TransactionTypeModel::TRANSFER,
AccountType::CASH => TransactionTypeModel::WITHDRAWAL, AccountType::CASH => TransactionTypeModel::WITHDRAWAL,
@@ -815,7 +815,7 @@ return [
], ],
// allowed source -> destination accounts. // allowed source -> destination accounts.
'source_dests' => [ 'source_dests' => [
TransactionTypeModel::WITHDRAWAL => [ TransactionTypeModel::WITHDRAWAL => [
AccountType::ASSET => [AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::CASH], AccountType::ASSET => [AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::CASH],
AccountType::LOAN => [AccountType::EXPENSE, AccountType::CASH], AccountType::LOAN => [AccountType::EXPENSE, AccountType::CASH],
@@ -854,7 +854,7 @@ return [
], ],
], ],
// if you add fields to this array, don't forget to update the export routine (ExportDataGenerator). // if you add fields to this array, don't forget to update the export routine (ExportDataGenerator).
'journal_meta_fields' => [ 'journal_meta_fields' => [
// sepa // sepa
'sepa_cc', 'sepa_cc',
'sepa_ct_op', 'sepa_ct_op',
@@ -888,33 +888,33 @@ return [
'recurrence_count', 'recurrence_count',
'recurrence_date', 'recurrence_date',
], ],
'webhooks' => [ 'webhooks' => [
'max_attempts' => env('WEBHOOK_MAX_ATTEMPTS', 3), 'max_attempts' => env('WEBHOOK_MAX_ATTEMPTS', 3),
], ],
'can_have_virtual_amounts' => [AccountType::ASSET], 'can_have_virtual_amounts' => [AccountType::ASSET],
'can_have_opening_balance' => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], 'can_have_opening_balance' => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
'dynamic_creation_allowed' => [ 'dynamic_creation_allowed' => [
AccountType::EXPENSE, AccountType::EXPENSE,
AccountType::REVENUE, AccountType::REVENUE,
AccountType::INITIAL_BALANCE, AccountType::INITIAL_BALANCE,
AccountType::RECONCILIATION, AccountType::RECONCILIATION,
AccountType::LIABILITY_CREDIT, AccountType::LIABILITY_CREDIT,
], ],
'valid_asset_fields' => ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'], '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_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_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'],
// dynamic date ranges are as follows: // 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 // only used in v1
'allowed_sort_parameters' => ['order', 'name', 'iban'], 'allowed_sort_parameters' => ['order', 'name', 'iban'],
// preselected account lists possibilities: // preselected account lists possibilities:
'preselected_accounts' => ['all', 'assets', 'liabilities'], 'preselected_accounts' => ['all', 'assets', 'liabilities'],
// allowed sort columns for API's // allowed sort columns for API's
'sorting' => [ 'sorting' => [
'allowed' => [ 'allowed' => [
'transactions' => ['description', 'amount'], 'transactions' => ['description', 'amount'],
'accounts' => ['name', 'active', 'iban', 'balance'], 'accounts' => ['name', 'active', 'iban', 'balance'],