Auto commit for release 'develop' on 2024-08-05

This commit is contained in:
github-actions
2024-08-05 05:06:53 +02:00
parent d2e9b64bf5
commit ed265f68ba
32 changed files with 574 additions and 564 deletions

View File

@@ -27,7 +27,6 @@ use Carbon\Carbon;
trait CollectsCustomParameters
{
protected function getOtherParams(array $params): array
{
$return = [];
@@ -37,7 +36,7 @@ trait CollectsCustomParameters
if (array_key_exists('endPeriod', $params)) {
$return['end'] = Carbon::parse($params['endPeriod']);
}
if(array_key_exists('currentMoment', $params)) {
if (array_key_exists('currentMoment', $params)) {
$return['today'] = Carbon::parse($params['currentMoment']);
}

View File

@@ -117,8 +117,8 @@ class AccountEnrichment implements EnrichmentInterface
$default = $this->default;
// get start and end, so the balance difference can be generated.
$start = null;
$end = null;
$start = null;
$end = null;
if (null !== $this->start) {
$start = Balance::getAccountBalances($this->collection, $this->start);
}
@@ -140,7 +140,7 @@ class AccountEnrichment implements EnrichmentInterface
'balance_difference' => null,
];
if (array_key_exists($account->id, $balances)) {
$set = [];
$set = [];
foreach ($balances[$account->id] as $currencyId => $entry) {
$left = $start[$account->id][$currencyId]['balance'] ?? null;
$right = $end[$account->id][$currencyId]['balance'] ?? null;
@@ -176,7 +176,6 @@ class AccountEnrichment implements EnrichmentInterface
}
}
return $account;
});
}
@@ -205,7 +204,7 @@ class AccountEnrichment implements EnrichmentInterface
$metaFields = $this->repository->getMetaValues($this->collection, ['is_multi_currency', '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 ($this->currencyRepository->getByIds($currencyIds) as $currency) {
$id = $currency->id;
$currencies[$id] = $currency;
@@ -250,31 +249,33 @@ class AccountEnrichment implements EnrichmentInterface
private function getObjectGroups(): void
{
$set = \DB::table('object_groupables')
->where('object_groupable_type', Account::class)
->whereIn('object_groupable_id', $this->collection->pluck('id')->toArray())
->distinct()
->get(['object_groupables.object_groupable_id', 'object_groupables.object_group_id']);
$set = \DB::table('object_groupables')
->where('object_groupable_type', Account::class)
->whereIn('object_groupable_id', $this->collection->pluck('id')->toArray())
->distinct()
->get(['object_groupables.object_groupable_id', 'object_groupables.object_group_id'])
;
// get the groups:
$groupIds = $set->pluck('object_group_id')->toArray();
$groups = ObjectGroup::whereIn('id', $groupIds)->get();
/** @var ObjectGroup $group */
foreach ($groups as $group) {
$this->objectGroups[$group->id] = $group;
}
/** @var \stdClass $entry */
foreach ($set as $entry) {
$this->grouped[(int) $entry->object_groupable_id] = (int) $entry->object_group_id;
}
$this->collection->transform(function (Account $account) {
$this->collection->transform(function (Account $account) {
$account->object_group_id = $this->grouped[$account->id] ?? null;
if(null !== $account->object_group_id) {
if (null !== $account->object_group_id) {
$account->object_group_title = $this->objectGroups[$account->object_group_id]->title;
$account->object_group_order = $this->objectGroups[$account->object_group_id]->order;
}
return $account;
});
}
}

View File

@@ -62,6 +62,7 @@ trait ExpandsQuery
foreach ($value as $entry) {
$return = array_merge($return, $this->mapAccountTypes($entry));
}
return array_unique($return);
}
@@ -70,7 +71,7 @@ trait ExpandsQuery
$config = config('api.valid_api_filters')[$class];
$parsed = [];
foreach ($filters->all() as $filter) {
$key = $filter->key();
$key = $filter->key();
if (!in_array($key, $config, true)) {
continue;
}
@@ -86,12 +87,16 @@ trait ExpandsQuery
switch ($filter->key()) {
case 'name':
$parsed['name'] = $value;
break;
case 'type':
$parsed['type'] = $this->parseAccountTypeFilter($value);
break;
}
}
return $parsed;
}
@@ -122,14 +127,13 @@ trait ExpandsQuery
});
// TODO this is special treatment, but alas, unavoidable right now.
if ($class === Account::class && array_key_exists('type', $parsed)) {
if (Account::class === $class && array_key_exists('type', $parsed)) {
if (count($parsed['type']) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $parsed['type']);
}
}
return $query;
}
}

View File

@@ -31,24 +31,18 @@ use LaravelJsonApi\Core\Query\SortFields;
trait SortsQueryResults
{
final protected function postQuerySort(string $class, Collection $collection, SortFields $parameters): Collection
{
Log::debug(__METHOD__);
foreach ($parameters->all() as $field) {
$collection = $this->sortQueryCollection($class, $collection, $field);
}
return $collection;
}
/**
* TODO improve this.
*
* @param string $class
* @param Collection $collection
* @param SortField $field
*
* @return Collection
*/
private function sortQueryCollection(string $class, Collection $collection, SortField $field): Collection
{
@@ -59,6 +53,7 @@ trait SortsQueryResults
$collection = $collection->sort(function (Account $left, Account $right) use ($ascending): int {
$leftSum = $this->sumBalance($left->balance);
$rightSum = $this->sumBalance($right->balance);
return $ascending ? bccomp($leftSum, $rightSum) : bccomp($rightSum, $leftSum);
});
}
@@ -67,6 +62,7 @@ trait SortsQueryResults
$collection = $collection->sort(function (Account $left, Account $right) use ($ascending): int {
$leftSum = $this->sumBalanceDifference($left->balance);
$rightSum = $this->sumBalanceDifference($right->balance);
return $ascending ? bccomp($leftSum, $rightSum) : bccomp($rightSum, $leftSum);
});
}
@@ -76,6 +72,7 @@ trait SortsQueryResults
$collection = $collection->sort(function (Account $left, Account $right) use ($ascending): int {
$leftNr = sprintf('%s%s', $left->iban, $left->account_number);
$rightNr = sprintf('%s%s', $right->iban, $right->account_number);
return $ascending ? strcmp($leftNr, $rightNr) : strcmp($rightNr, $leftNr);
});
}
@@ -86,17 +83,17 @@ trait SortsQueryResults
$collection = $collection->sort(function (Account $left, Account $right) use ($ascending): int {
$leftNr = (int)$left->last_activity?->format('U');
$rightNr = (int)$right->last_activity?->format('U');
if($ascending){
if ($ascending) {
return $leftNr <=> $rightNr;
}
return $rightNr <=> $leftNr;
//return (int) ($ascending ? $rightNr < $leftNr : $leftNr < $rightNr );
// return (int) ($ascending ? $rightNr < $leftNr : $leftNr < $rightNr );
});
}
// sort by balance difference.
return $collection;
}
@@ -112,6 +109,7 @@ trait SortsQueryResults
foreach ($balance as $entry) {
$sum = bcadd($sum, $entry['balance']);
}
return $sum;
}
@@ -127,7 +125,7 @@ trait SortsQueryResults
foreach ($balance as $entry) {
$sum = bcadd($sum, $entry['balance_difference']);
}
return $sum;
}
}

View File

@@ -38,6 +38,7 @@ trait ValidateSortParameters
foreach ($params->all() as $field) {
if (in_array($field->name(), $config, true)) {
Log::debug('TRUE');
return true;
}
}