mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Auto commit for release 'develop' on 2024-05-13
This commit is contained in:
@@ -27,7 +27,6 @@ use FireflyIII\Models\UserGroup;
|
||||
|
||||
trait UsergroupAware
|
||||
{
|
||||
|
||||
protected UserGroup $userGroup;
|
||||
|
||||
public function getUserGroup(): UserGroup
|
||||
@@ -40,9 +39,10 @@ trait UsergroupAware
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
public function withUserGroup(UserGroup $userGroup): self {
|
||||
public function withUserGroup(UserGroup $userGroup): self
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,28 +34,28 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AccountEnrichment implements EnrichmentInterface
|
||||
{
|
||||
|
||||
private Collection $collection;
|
||||
private array $currencies;
|
||||
|
||||
|
||||
#[\Override] public function enrich(Collection $collection): Collection
|
||||
#[\Override]
|
||||
public function enrich(Collection $collection): Collection
|
||||
{
|
||||
$this->collection = $collection;
|
||||
$this->currencies = [];
|
||||
// do everything here:
|
||||
$this->getLastActivity();
|
||||
//$this->getMetaBalances();
|
||||
// $this->getMetaBalances();
|
||||
$this->collectAccountTypes();
|
||||
$this->collectMetaData();
|
||||
|
||||
$this->collection->transform(function (Account $account) {
|
||||
$account->user_array = ['id' => 1,'bla bla' => 'bla'];
|
||||
$account->balances = collect([
|
||||
['balance_id' => 1,'balance' => 5],
|
||||
['balance_id' => 2,'balance' => 5],
|
||||
['balance_id' => 3,'balance' => 5],
|
||||
]);
|
||||
$account->user_array = ['id' => 1, 'bla bla' => 'bla'];
|
||||
$account->balances = collect([
|
||||
['balance_id' => 1, 'balance' => 5],
|
||||
['balance_id' => 2, 'balance' => 5],
|
||||
['balance_id' => 3, 'balance' => 5],
|
||||
]);
|
||||
|
||||
return $account;
|
||||
});
|
||||
|
||||
@@ -64,8 +64,6 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
|
||||
/**
|
||||
* TODO this method refers to a single-use method inside Steam that could be moved here.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function getLastActivity(): void
|
||||
{
|
||||
@@ -74,14 +72,11 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
$lastActivity = $accountRepository->getLastActivity($this->collection);
|
||||
foreach ($lastActivity as $row) {
|
||||
$this->collection->where('id', $row['account_id'])->first()->last_activity = Carbon::parse($row['date_max'], config('app.timezone'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO this method refers to a single-use method inside Steam that could be moved here.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function getMetaBalances(): void
|
||||
{
|
||||
@@ -89,6 +84,7 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
$array = app('steam')->balancesByAccountsConverted($this->collection, today());
|
||||
} catch (FireflyException $e) {
|
||||
Log::error(sprintf('Could not load balances: %s', $e->getMessage()));
|
||||
|
||||
return;
|
||||
}
|
||||
foreach ($array as $accountId => $row) {
|
||||
@@ -99,8 +95,6 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
|
||||
/**
|
||||
* TODO this method refers to a single-use method inside Steam that could be moved here.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function collectAccountTypes(): void
|
||||
{
|
||||
@@ -115,6 +109,7 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
}
|
||||
$this->collection->transform(function (Account $account) use ($types) {
|
||||
$account->type = $types[$account->id];
|
||||
|
||||
return $account;
|
||||
});
|
||||
}
|
||||
@@ -123,19 +118,19 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
{
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
$metaFields = $accountRepository->getMetaValues($this->collection, ['currency_id', 'account_role', 'account_number', 'liability_direction', 'interest', 'interest_period', 'current_debt']);
|
||||
$currencyIds = $metaFields->where('name', 'currency_id')->pluck('data')->toArray();
|
||||
$metaFields = $accountRepository->getMetaValues($this->collection, ['currency_id', 'account_role', 'account_number', 'liability_direction', 'interest', 'interest_period', 'current_debt']);
|
||||
$currencyIds = $metaFields->where('name', 'currency_id')->pluck('data')->toArray();
|
||||
|
||||
$currencies = [];
|
||||
$currencies = [];
|
||||
foreach ($repository->getByIds($currencyIds) as $currency) {
|
||||
$id = $currency->id;
|
||||
$currencies[$id] = $currency;
|
||||
}
|
||||
|
||||
|
||||
$this->collection->transform(function (Account $account) use ($metaFields, $currencies) {
|
||||
$set = $metaFields->where('account_id', $account->id);
|
||||
foreach ($set as $entry) {
|
||||
@@ -147,6 +142,7 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
$account->currency_decimal_places = $currencies[$id]?->decimal_places;
|
||||
}
|
||||
}
|
||||
|
||||
return $account;
|
||||
});
|
||||
}
|
||||
|
@@ -28,5 +28,4 @@ use Illuminate\Support\Collection;
|
||||
interface EnrichmentInterface
|
||||
{
|
||||
public function enrich(Collection $collection): Collection;
|
||||
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ trait ExpandsQuery
|
||||
final protected function addPagination(Builder $query, array $pagination): Builder
|
||||
{
|
||||
$skip = ($pagination['number'] - 1) * $pagination['size'];
|
||||
|
||||
return $query->skip($skip)->take($pagination['size']);
|
||||
}
|
||||
|
||||
@@ -46,6 +47,7 @@ trait ExpandsQuery
|
||||
foreach ($sort->all() as $sortField) {
|
||||
$query->orderBy($sortField->name(), $sortField->isAscending() ? 'ASC' : 'DESC');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@@ -54,11 +56,11 @@ trait ExpandsQuery
|
||||
if (null === $filters) {
|
||||
return $query;
|
||||
}
|
||||
$config = config(sprintf('firefly.valid_query_filters.%s', $class)) ?? [];
|
||||
if (count($filters->all()) === 0) {
|
||||
$config = config(sprintf('firefly.valid_query_filters.%s', $class)) ?? [];
|
||||
if (0 === count($filters->all())) {
|
||||
return $query;
|
||||
}
|
||||
$query->where(function (Builder $q) use ($config, $filters) {
|
||||
$query->where(function (Builder $q) use ($config, $filters): void {
|
||||
foreach ($filters->all() as $filter) {
|
||||
if (in_array($filter->key(), $config, true)) {
|
||||
foreach ($filter->value() as $value) {
|
||||
@@ -80,5 +82,4 @@ trait ExpandsQuery
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ namespace FireflyIII\Support\JsonApi;
|
||||
|
||||
trait FiltersPagination
|
||||
{
|
||||
|
||||
protected function filtersPagination(?array $pagination): array
|
||||
{
|
||||
if (null === $pagination) {
|
||||
@@ -39,8 +38,8 @@ trait FiltersPagination
|
||||
$pagination['number'] = min(65536, max($pagination['number'], 1));
|
||||
|
||||
// clean up page size
|
||||
$pagination['size'] = (int) ($pagination['size'] ?? $this->getPageSize());
|
||||
$pagination['size'] = min(1337, max($pagination['size'], 1));
|
||||
$pagination['size'] = (int) ($pagination['size'] ?? $this->getPageSize());
|
||||
$pagination['size'] = min(1337, max($pagination['size'], 1));
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
@@ -50,6 +49,7 @@ trait FiltersPagination
|
||||
if (auth()->check()) {
|
||||
return (int) app('preferences')->get('listPageSize', 50)->data;
|
||||
}
|
||||
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
@@ -28,16 +28,15 @@ use LaravelJsonApi\Core\Query\SortFields;
|
||||
|
||||
trait SortsCollection
|
||||
{
|
||||
protected function sortCollection(Collection $collection, ?SortFields $sortFields): Collection {
|
||||
|
||||
if(null === $sortFields) {
|
||||
protected function sortCollection(Collection $collection, ?SortFields $sortFields): Collection
|
||||
{
|
||||
if (null === $sortFields) {
|
||||
return $collection;
|
||||
}
|
||||
foreach($sortFields->all() as $sortField) {
|
||||
$collection = $sortField->isAscending() ? $collection->sortBy($sortField->name()) : $collection->sortByDesc($sortField->name());
|
||||
foreach ($sortFields->all() as $sortField) {
|
||||
$collection = $sortField->isAscending() ? $collection->sortBy($sortField->name()) : $collection->sortByDesc($sortField->name());
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,21 +27,20 @@ use LaravelJsonApi\Core\Query\SortFields;
|
||||
|
||||
trait ValidateSortParameters
|
||||
{
|
||||
function validateParams(string $class, ?SortFields $params): bool
|
||||
public function validateParams(string $class, ?SortFields $params): bool
|
||||
{
|
||||
if(null === $params) {
|
||||
if (null === $params) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = config(sprintf('firefly.full_data_set.%s', $class)) ?? [];
|
||||
|
||||
|
||||
foreach ($params->all() as $field) {
|
||||
if (in_array($field->name(), $config, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user