mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix methods and clean up code.
This commit is contained in:
parent
487b65b669
commit
66b322e844
12
.ci/php-cs-fixer/composer.lock
generated
12
.ci/php-cs-fixer/composer.lock
generated
@ -8,16 +8,16 @@
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/pcre",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/pcre.git",
|
||||
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9"
|
||||
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9",
|
||||
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9",
|
||||
"url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace",
|
||||
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -59,7 +59,7 @@
|
||||
],
|
||||
"support": {
|
||||
"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": [
|
||||
{
|
||||
@ -75,7 +75,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-10-11T07:11:09+00:00"
|
||||
"time": "2024-03-07T15:38:35+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/semver",
|
||||
|
@ -158,7 +158,7 @@ class Controller extends BaseController
|
||||
|
||||
// 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.
|
||||
$objects = $transformer->collectMetaData($objects);
|
||||
$objects = $transformer->collectMetaData($objects);
|
||||
$paginator->setCollection($objects);
|
||||
|
||||
$resource = new FractalCollection($objects, $transformer, $key);
|
||||
|
@ -47,7 +47,7 @@ class IndexController extends Controller
|
||||
function ($request, $next) {
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
// new way of user group validation
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
if (null !== $userGroup) {
|
||||
$this->repository->setUserGroup($userGroup);
|
||||
}
|
||||
@ -62,7 +62,6 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index(IndexRequest $request): JsonResponse
|
||||
{
|
||||
|
||||
$this->repository->resetAccountOrder();
|
||||
$types = $request->getAccountTypes();
|
||||
$instructions = $request->getSortInstructions('accounts');
|
||||
@ -78,7 +77,8 @@ class IndexController extends Controller
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList('accounts', $paginator, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE);
|
||||
->header('Content-Type', self::CONTENT_TYPE)
|
||||
;
|
||||
}
|
||||
|
||||
public function infiniteList(InfiniteListRequest $request): JsonResponse
|
||||
@ -86,7 +86,7 @@ class IndexController extends Controller
|
||||
$this->repository->resetAccountOrder();
|
||||
|
||||
// get accounts of the specified type, and return.
|
||||
$types = $request->getAccountTypes();
|
||||
$types = $request->getAccountTypes();
|
||||
|
||||
// get from repository
|
||||
$accounts = $this->repository->getAccountsInOrder($types, $request->getSortInstructions('accounts'), $request->getStartRow(), $request->getEndRow());
|
||||
@ -98,6 +98,7 @@ class IndexController extends Controller
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE);
|
||||
->header('Content-Type', self::CONTENT_TYPE)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ class InfiniteListRequest extends FormRequest
|
||||
use AccountFilter;
|
||||
use ChecksLogin;
|
||||
use ConvertsDataTypes;
|
||||
use TransactionFilter;
|
||||
use GetSortInstructions;
|
||||
use TransactionFilter;
|
||||
|
||||
public function buildParams(): string
|
||||
{
|
||||
@ -99,7 +99,6 @@ class InfiniteListRequest extends FormRequest
|
||||
return 0 === $page || $page > 65536 ? 1 : $page;
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionTypes(): array
|
||||
{
|
||||
$type = (string)$this->get('type', 'default');
|
||||
|
@ -74,20 +74,22 @@ class LoginController extends Controller
|
||||
*
|
||||
* @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())));
|
||||
app('log')->debug('User is trying to login.');
|
||||
|
||||
try {
|
||||
$this->validateLogin($request);
|
||||
} catch (ValidationException $e) {
|
||||
return redirect(route('login'))
|
||||
->withErrors(
|
||||
[
|
||||
$this->username => trans('auth.failed')
|
||||
$this->username => trans('auth.failed'),
|
||||
]
|
||||
)
|
||||
->onlyInput($this->username);
|
||||
->onlyInput($this->username)
|
||||
;
|
||||
}
|
||||
app('log')->debug('Login data is present.');
|
||||
|
||||
@ -125,7 +127,6 @@ class LoginController extends Controller
|
||||
|
||||
$this->sendFailedLoginResponse($request);
|
||||
|
||||
|
||||
// @noinspection PhpUnreachableStatementInspection
|
||||
return response()->json([]);
|
||||
}
|
||||
@ -166,8 +167,8 @@ class LoginController extends Controller
|
||||
*/
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$authGuard = config('firefly.authentication_guard');
|
||||
$logoutUrl = config('firefly.custom_logout_url');
|
||||
$authGuard = config('firefly.authentication_guard');
|
||||
$logoutUrl = config('firefly.custom_logout_url');
|
||||
if ('remote_user_guard' === $authGuard && '' !== $logoutUrl) {
|
||||
return redirect($logoutUrl);
|
||||
}
|
||||
@ -203,9 +204,9 @@ class LoginController extends Controller
|
||||
{
|
||||
Log::channel('audit')->info('Show login form (1.1).');
|
||||
|
||||
$count = \DB::table('users')->count();
|
||||
$guard = config('auth.defaults.guard');
|
||||
$title = (string)trans('firefly.login_page_title');
|
||||
$count = \DB::table('users')->count();
|
||||
$guard = config('auth.defaults.guard');
|
||||
$title = (string)trans('firefly.login_page_title');
|
||||
|
||||
if (0 === $count && 'web' === $guard) {
|
||||
return redirect(route('register'));
|
||||
@ -225,16 +226,15 @@ class LoginController extends Controller
|
||||
$allowReset = false;
|
||||
}
|
||||
|
||||
$email = $request->old('email');
|
||||
$remember = $request->old('remember');
|
||||
$email = $request->old('email');
|
||||
$remember = $request->old('remember');
|
||||
|
||||
$storeInCookie = config('google2fa.store_in_cookie', false);
|
||||
$storeInCookie = config('google2fa.store_in_cookie', false);
|
||||
if (false !== $storeInCookie) {
|
||||
$cookieName = config('google2fa.cookie_name', 'google2fa_token');
|
||||
request()->cookies->set($cookieName, 'invalid');
|
||||
}
|
||||
$usernameField = $this->username();
|
||||
|
||||
$usernameField = $this->username();
|
||||
|
||||
return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField'));
|
||||
}
|
||||
|
@ -95,21 +95,21 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @method static Builder|Account withTrashed()
|
||||
* @method static Builder|Account withoutTrashed()
|
||||
*
|
||||
* @property Carbon $lastActivityDate
|
||||
* @property string $startBalance
|
||||
* @property string $endBalance
|
||||
* @property string $difference
|
||||
* @property string $interest
|
||||
* @property string $interestPeriod
|
||||
* @property string $accountTypeString
|
||||
* @property Location $location
|
||||
* @property string $liability_direction
|
||||
* @property string $current_debt
|
||||
* @property int $user_group_id
|
||||
* @property Carbon $lastActivityDate
|
||||
* @property string $startBalance
|
||||
* @property string $endBalance
|
||||
* @property string $difference
|
||||
* @property string $interest
|
||||
* @property string $interestPeriod
|
||||
* @property string $accountTypeString
|
||||
* @property Location $location
|
||||
* @property string $liability_direction
|
||||
* @property string $current_debt
|
||||
* @property int $user_group_id
|
||||
*
|
||||
* @method static EloquentBuilder|Account whereUserGroupId($value)
|
||||
*
|
||||
* @property null|UserGroup $userGroup
|
||||
* @property null|UserGroup $userGroup
|
||||
*
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
@ -121,7 +121,7 @@ class Account extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
protected $casts
|
||||
= [
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'user_id' => 'integer',
|
||||
@ -130,9 +130,9 @@ class Account extends Model
|
||||
'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;
|
||||
|
||||
/**
|
||||
@ -146,10 +146,10 @@ class Account extends Model
|
||||
$accountId = (int)$value;
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var null|Account $account */
|
||||
$account = $user->accounts()->with(['accountType'])->find($accountId);
|
||||
$account = $user->accounts()->with(['accountType'])->find($accountId);
|
||||
if (null !== $account) {
|
||||
return $account;
|
||||
}
|
||||
@ -180,8 +180,9 @@ class Account extends Model
|
||||
{
|
||||
/** @var null|AccountMeta $metaValue */
|
||||
$metaValue = $this->accountMeta()
|
||||
->where('name', 'account_number')
|
||||
->first();
|
||||
->where('name', 'account_number')
|
||||
->first()
|
||||
;
|
||||
|
||||
return null !== $metaValue ? $metaValue->data : '';
|
||||
}
|
||||
@ -239,7 +240,7 @@ class Account extends Model
|
||||
|
||||
public function setVirtualBalanceAttribute(mixed $value): void
|
||||
{
|
||||
$value = (string)$value;
|
||||
$value = (string)$value;
|
||||
if ('' === $value) {
|
||||
$value = null;
|
||||
}
|
||||
@ -259,7 +260,7 @@ class Account extends Model
|
||||
protected function accountId(): Attribute
|
||||
{
|
||||
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
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn($value) => (int)$value,
|
||||
get: static fn ($value) => (int)$value,
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
protected function iban(): Attribute
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn($value) => (string)$value,
|
||||
get: static fn ($value) => (string)$value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$q1->where('account_meta.name', '=', 'account_number');
|
||||
$q1->where('account_meta.data', '=', $json);
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
|
||||
if (0 !== count($types)) {
|
||||
$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
|
||||
{
|
||||
$query = $this->userGroup->accounts();
|
||||
$query = $this->userGroup->accounts();
|
||||
|
||||
if (0 !== count($types)) {
|
||||
$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
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if (!in_array($type, $list, true)) {
|
||||
@ -269,11 +270,12 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
// search by group, not by user
|
||||
$dbQuery = $this->userGroup->accounts()
|
||||
->where('active', true)
|
||||
->orderBy('accounts.order', 'ASC')
|
||||
->orderBy('accounts.account_type_id', 'ASC')
|
||||
->orderBy('accounts.name', 'ASC')
|
||||
->with(['accountType']);
|
||||
->where('active', true)
|
||||
->orderBy('accounts.order', 'ASC')
|
||||
->orderBy('accounts.account_type_id', 'ASC')
|
||||
->orderBy('accounts.name', 'ASC')
|
||||
->with(['accountType'])
|
||||
;
|
||||
if ('' !== $query) {
|
||||
// split query on spaces just in case:
|
||||
$parts = explode(' ', $query);
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Support\Request;
|
||||
|
||||
trait GetSortInstructions
|
||||
{
|
||||
|
||||
final public function getSortInstructions(string $key): array
|
||||
{
|
||||
$allowed = config(sprintf('firefly.sorting.allowed.%s', $key));
|
||||
@ -50,5 +49,4 @@ trait GetSortInstructions
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,9 +37,6 @@ abstract class AbstractTransformer extends TransformerAbstract
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@ -32,7 +32,6 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class AccountTransformer
|
||||
@ -58,17 +57,18 @@ class AccountTransformer extends AbstractTransformer
|
||||
$this->convertedBalances = app('steam')->balancesByAccountsConverted($objects, $this->getDate());
|
||||
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->default = app('amount')->getDefaultCurrency();
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->default = app('amount')->getDefaultCurrency();
|
||||
|
||||
// get currencies:
|
||||
$accountIds = $objects->pluck('id')->toArray();
|
||||
$meta = AccountMeta::whereIn('account_id', $accountIds)
|
||||
->whereIn('name', ['currency_id','account_role','account_number'])
|
||||
->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']);
|
||||
$currencyIds = $meta->where('name','currency_id')->pluck('data')->toArray();
|
||||
$accountIds = $objects->pluck('id')->toArray();
|
||||
$meta = AccountMeta::whereIn('account_id', $accountIds)
|
||||
->whereIn('name', ['currency_id', 'account_role', 'account_number'])
|
||||
->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])
|
||||
;
|
||||
$currencyIds = $meta->where('name', 'currency_id')->pluck('data')->toArray();
|
||||
|
||||
$currencies = $repository->getByIds($currencyIds);
|
||||
$currencies = $repository->getByIds($currencyIds);
|
||||
foreach ($currencies as $currency) {
|
||||
$id = $currency->id;
|
||||
$this->currencies[$id] = $currency;
|
||||
@ -79,9 +79,10 @@ class AccountTransformer extends AbstractTransformer
|
||||
}
|
||||
// get account types:
|
||||
// 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')
|
||||
->whereIn('accounts.id', $accountIds)
|
||||
->get(['accounts.id', 'account_types.type']);
|
||||
$accountTypes = AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id')
|
||||
->whereIn('accounts.id', $accountIds)
|
||||
->get(['accounts.id', 'account_types.type'])
|
||||
;
|
||||
|
||||
/** @var AccountType $row */
|
||||
foreach ($accountTypes as $row) {
|
||||
@ -89,36 +90,38 @@ class AccountTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
// TODO needs separate method.
|
||||
$sort = $this->parameters->get('sort');
|
||||
$sort = $this->parameters->get('sort');
|
||||
if (count($sort) > 0) {
|
||||
foreach ($sort as $column => $direction) {
|
||||
// account_number + iban
|
||||
if ('iban' === $column) {
|
||||
$meta = $this->accountMeta;
|
||||
$objects = $objects->sort(function (Account $left, Account $right) use ($meta, $direction) {
|
||||
$leftIban = trim(sprintf('%s%s', $left->iban, ($meta[$left->id]['account_number'] ?? '')));
|
||||
$rightIban = trim(sprintf('%s%s', $right->iban, ($meta[$right->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'] ?? ''));
|
||||
if ('asc' === $direction) {
|
||||
return strcasecmp($leftIban, $rightIban);
|
||||
}
|
||||
|
||||
return strcasecmp($rightIban, $leftIban);
|
||||
});
|
||||
}
|
||||
if('balance' === $column) {
|
||||
$balances = $this->convertedBalances;
|
||||
$objects = $objects->sort(function (Account $left, Account $right) use ($balances, $direction) {
|
||||
$leftBalance = (float)($balances[$left->id]['native_balance'] ?? 0);
|
||||
if ('balance' === $column) {
|
||||
$balances = $this->convertedBalances;
|
||||
$objects = $objects->sort(function (Account $left, Account $right) use ($balances, $direction) {
|
||||
$leftBalance = (float)($balances[$left->id]['native_balance'] ?? 0);
|
||||
$rightBalance = (float)($balances[$right->id]['native_balance'] ?? 0);
|
||||
if ('asc' === $direction) {
|
||||
return $leftBalance <=> $rightBalance;
|
||||
}
|
||||
|
||||
return $rightBalance <=> $leftBalance;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//$objects = $objects->sortByDesc('name');
|
||||
|
||||
// $objects = $objects->sortByDesc('name');
|
||||
return $objects;
|
||||
}
|
||||
|
||||
@ -137,15 +140,15 @@ class AccountTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(Account $account): array
|
||||
{
|
||||
$id = $account->id;
|
||||
$id = $account->id;
|
||||
|
||||
// various meta
|
||||
$accountRole = $this->accountMeta[$id]['account_role'] ?? null;
|
||||
$accountType = $this->accountTypes[$id];
|
||||
$order = $account->order;
|
||||
$accountRole = $this->accountMeta[$id]['account_role'] ?? null;
|
||||
$accountType = $this->accountTypes[$id];
|
||||
$order = $account->order;
|
||||
|
||||
// no currency? use default
|
||||
$currency = $this->default;
|
||||
$currency = $this->default;
|
||||
if (array_key_exists($id, $this->accountMeta) && 0 !== (int)$this->accountMeta[$id]['currency_id']) {
|
||||
$currency = $this->currencies[(int)$this->accountMeta[$id]['currency_id']];
|
||||
}
|
||||
@ -159,20 +162,20 @@ class AccountTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (string)$account->id,
|
||||
'created_at' => $account->created_at->toAtomString(),
|
||||
'updated_at' => $account->updated_at->toAtomString(),
|
||||
'active' => $account->active,
|
||||
'order' => $order,
|
||||
'name' => $account->name,
|
||||
'iban' => '' === (string)$account->iban ? null : $account->iban,
|
||||
'account_number' => $this->accountMeta[$id]['account_number'] ?? null,
|
||||
'type' => strtolower($accountType),
|
||||
'account_role' => $accountRole,
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'id' => (string)$account->id,
|
||||
'created_at' => $account->created_at->toAtomString(),
|
||||
'updated_at' => $account->updated_at->toAtomString(),
|
||||
'active' => $account->active,
|
||||
'order' => $order,
|
||||
'name' => $account->name,
|
||||
'iban' => '' === (string)$account->iban ? null : $account->iban,
|
||||
'account_number' => $this->accountMeta[$id]['account_number'] ?? null,
|
||||
'type' => strtolower($accountType),
|
||||
'account_role' => $accountRole,
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
|
||||
'native_currency_id' => (string)$this->default->id,
|
||||
'native_currency_code' => $this->default->code,
|
||||
@ -206,7 +209,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/accounts/' . $account->id,
|
||||
'uri' => '/accounts/'.$account->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
@ -54,7 +54,7 @@ class BillTransformer extends AbstractTransformer
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function collectMetaData(Collection $objects): void
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
$currencies = [];
|
||||
$bills = [];
|
||||
@ -175,6 +175,8 @@ class BillTransformer extends AbstractTransformer
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,9 +37,10 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
'budget',
|
||||
];
|
||||
|
||||
public function collectMetaData(Collection $objects): void
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
// TODO: Implement collectMetaData() method.
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,9 +45,10 @@ class BudgetTransformer extends AbstractTransformer
|
||||
$this->parameters = new ParameterBag();
|
||||
}
|
||||
|
||||
public function collectMetaData(Collection $objects): void
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
// TODO: Implement collectMetaData() method.
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,10 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class CurrencyTransformer extends AbstractTransformer
|
||||
{
|
||||
public function collectMetaData(Collection $objects): void {}
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the currency.
|
||||
|
@ -69,7 +69,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
// $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)
|
||||
$piggyBanks = $objects->pluck('id')->toArray();
|
||||
@ -135,6 +135,8 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
|
||||
$this->default = app('amount')->getDefaultCurrencyByUserGroup(auth()->user()->userGroup);
|
||||
$this->converter = new ExchangeRateConverter();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,9 +31,10 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class PreferenceTransformer extends AbstractTransformer
|
||||
{
|
||||
public function collectMetaData(Collection $objects): void
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
// TODO: Implement collectMetaData() method.
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
// private array $journalCurrencies = [];
|
||||
// private array $foreignCurrencies = [];
|
||||
|
||||
public function collectMetaData(Collection $objects): void
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
$collectForObjects = false;
|
||||
|
||||
@ -94,6 +94,8 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
// source accounts
|
||||
// destination accounts
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
private function collectForArray(array $object): void
|
||||
|
@ -42,7 +42,7 @@ class UserGroupTransformer extends AbstractTransformer
|
||||
$this->memberships = [];
|
||||
}
|
||||
|
||||
public function collectMetaData(Collection $objects): void
|
||||
public function collectMetaData(Collection $objects): Collection
|
||||
{
|
||||
if (auth()->check()) {
|
||||
// collect memberships so they can be listed in the group.
|
||||
@ -67,6 +67,8 @@ class UserGroupTransformer extends AbstractTransformer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -432,7 +432,7 @@ return [
|
||||
'transfers' => 'fa-exchange',
|
||||
],
|
||||
|
||||
'bindables' => [
|
||||
'bindables' => [
|
||||
// models
|
||||
'account' => Account::class,
|
||||
'attachment' => Attachment::class,
|
||||
@ -490,7 +490,7 @@ return [
|
||||
'userGroupBill' => UserGroupBill::class,
|
||||
'userGroup' => UserGroup::class,
|
||||
],
|
||||
'rule-actions' => [
|
||||
'rule-actions' => [
|
||||
'set_category' => SetCategory::class,
|
||||
'clear_category' => ClearCategory::class,
|
||||
'set_budget' => SetBudget::class,
|
||||
@ -521,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',
|
||||
@ -540,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],
|
||||
@ -591,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,
|
||||
@ -681,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,
|
||||
@ -750,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,
|
||||
@ -815,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],
|
||||
@ -854,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',
|
||||
@ -888,33 +888,33 @@ 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'],
|
||||
|
||||
// allowed sort columns for API's
|
||||
'sorting' => [
|
||||
'sorting' => [
|
||||
'allowed' => [
|
||||
'transactions' => ['description', 'amount'],
|
||||
'accounts' => ['name', 'active', 'iban', 'balance'],
|
||||
|
Loading…
Reference in New Issue
Block a user