mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 14:46:37 +00:00
Expand and fix sort columns
This commit is contained in:
@@ -73,7 +73,7 @@ class IndexController extends Controller
|
|||||||
// depending on the sort parameters, this list must not be split, because the
|
// depending on the sort parameters, this list must not be split, because the
|
||||||
// order is calculated in the account transformer and by that time it's too late.
|
// order is calculated in the account transformer and by that time it's too late.
|
||||||
$first = array_key_first($sorting);
|
$first = array_key_first($sorting);
|
||||||
$disablePagination = in_array($first, ['last_activity', 'balance_difference'], true);
|
$disablePagination = in_array($first, ['last_activity','balance', 'balance_difference'], true);
|
||||||
if (!$disablePagination) {
|
if (!$disablePagination) {
|
||||||
$accounts = $accounts->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$accounts = $accounts->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
}
|
}
|
||||||
|
@@ -87,14 +87,18 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
// get object groups
|
// get object groups
|
||||||
$this->getObjectGroups($objects);
|
$this->getObjectGroups($objects);
|
||||||
|
|
||||||
|
// sort:
|
||||||
|
$objects = $this->sortAccounts($objects);
|
||||||
|
|
||||||
// if pagination is disabled, do it now:
|
// if pagination is disabled, do it now:
|
||||||
if(true === $this->parameters->get('disablePagination')) {
|
if (true === $this->parameters->get('disablePagination')) {
|
||||||
$page = (int) $this->parameters->get('page');
|
$page = (int) $this->parameters->get('page');
|
||||||
$size = (int) $this->parameters->get('pageSize');
|
$size = (int) $this->parameters->get('pageSize');
|
||||||
$objects = $objects->slice(($page-1) * $size, $size);
|
$objects = $objects->slice(($page - 1) * $size, $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->sortAccounts($objects);
|
return $objects;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDate(): Carbon
|
private function getDate(): Carbon
|
||||||
@@ -112,12 +116,12 @@ 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;
|
||||||
|
|
||||||
// liability type
|
// liability type
|
||||||
$liabilityType = 'liabilities' === $accountType ? $this->fullTypes[$id] : null;
|
$liabilityType = 'liabilities' === $accountType ? $this->fullTypes[$id] : null;
|
||||||
@@ -127,13 +131,13 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
$currentDebt = $this->accountMeta[$id]['current_debt'] ?? null;
|
$currentDebt = $this->accountMeta[$id]['current_debt'] ?? null;
|
||||||
|
|
||||||
// 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'] ?? 0)) {
|
if (array_key_exists($id, $this->accountMeta) && 0 !== (int) ($this->accountMeta[$id]['currency_id'] ?? 0)) {
|
||||||
$currency = $this->currencies[(int) $this->accountMeta[$id]['currency_id']];
|
$currency = $this->currencies[(int) $this->accountMeta[$id]['currency_id']];
|
||||||
}
|
}
|
||||||
// amounts and calculation.
|
// amounts and calculation.
|
||||||
$balance = $this->balances[$id]['balance'] ?? null;
|
$balance = $this->balances[$id]['balance'] ?? null;
|
||||||
$nativeBalance = $this->convertedBalances[$id]['native_balance'] ?? null;
|
$nativeBalance = $this->convertedBalances[$id]['native_balance'] ?? null;
|
||||||
|
|
||||||
// no order for some accounts:
|
// no order for some accounts:
|
||||||
if (!in_array(strtolower($accountType), ['liability', 'liabilities', 'asset'], true)) {
|
if (!in_array(strtolower($accountType), ['liability', 'liabilities', 'asset'], true)) {
|
||||||
@@ -141,15 +145,15 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// object group
|
// object group
|
||||||
$objectGroupId = $this->objectGroups[$id]['id'] ?? null;
|
$objectGroupId = $this->objectGroups[$id]['id'] ?? null;
|
||||||
$objectGroupOrder = $this->objectGroups[$id]['order'] ?? null;
|
$objectGroupOrder = $this->objectGroups[$id]['order'] ?? null;
|
||||||
$objectGroupTitle = $this->objectGroups[$id]['title'] ?? null;
|
$objectGroupTitle = $this->objectGroups[$id]['title'] ?? null;
|
||||||
|
|
||||||
// balance difference
|
// balance difference
|
||||||
$diffStart = null;
|
$diffStart = null;
|
||||||
$diffEnd = null;
|
$diffEnd = null;
|
||||||
$balanceDiff = null;
|
$balanceDiff = null;
|
||||||
$nativeBalanceDiff = null;
|
$nativeBalanceDiff = null;
|
||||||
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
||||||
$diffStart = $this->parameters->get('start')->toAtomString();
|
$diffStart = $this->parameters->get('start')->toAtomString();
|
||||||
$diffEnd = $this->parameters->get('end')->toAtomString();
|
$diffEnd = $this->parameters->get('end')->toAtomString();
|
||||||
@@ -158,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,
|
||||||
@@ -218,7 +222,7 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
'uri' => '/accounts/'.$account->id,
|
'uri' => '/accounts/' . $account->id,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -241,14 +245,14 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
private function collectAccountMetaData(Collection $accounts): void
|
private function collectAccountMetaData(Collection $accounts): void
|
||||||
{
|
{
|
||||||
/** @var CurrencyRepositoryInterface $repository */
|
/** @var CurrencyRepositoryInterface $repository */
|
||||||
$repository = app(CurrencyRepositoryInterface::class);
|
$repository = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $accountRepository */
|
/** @var AccountRepositoryInterface $accountRepository */
|
||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
$accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$metaFields = $accountRepository->getMetaValues($accounts, ['currency_id', 'account_role', 'account_number', 'liability_direction', 'interest', 'interest_period', 'current_debt']);
|
$metaFields = $accountRepository->getMetaValues($accounts, ['currency_id', 'account_role', 'account_number', 'liability_direction', 'interest', 'interest_period', 'current_debt']);
|
||||||
$currencyIds = $metaFields->where('name', 'currency_id')->pluck('data')->toArray();
|
$currencyIds = $metaFields->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;
|
||||||
|
Reference in New Issue
Block a user