mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 01:06:46 +00:00
Add last activity column
This commit is contained in:
@@ -29,9 +29,11 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountMeta;
|
use FireflyIII\Models\AccountMeta;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
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\DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountTransformer
|
* Class AccountTransformer
|
||||||
@@ -39,6 +41,7 @@ use Illuminate\Support\Collection;
|
|||||||
class AccountTransformer extends AbstractTransformer
|
class AccountTransformer extends AbstractTransformer
|
||||||
{
|
{
|
||||||
private array $accountMeta;
|
private array $accountMeta;
|
||||||
|
private array $lastActivity;
|
||||||
private array $accountTypes;
|
private array $accountTypes;
|
||||||
private array $balances;
|
private array $balances;
|
||||||
private array $convertedBalances;
|
private array $convertedBalances;
|
||||||
@@ -50,9 +53,11 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
public function collectMetaData(Collection $objects): Collection
|
public function collectMetaData(Collection $objects): Collection
|
||||||
{
|
{
|
||||||
|
// TODO separate methods
|
||||||
$this->currencies = [];
|
$this->currencies = [];
|
||||||
$this->accountMeta = [];
|
$this->accountMeta = [];
|
||||||
$this->accountTypes = [];
|
$this->accountTypes = [];
|
||||||
|
$this->lastActivity = [];
|
||||||
$this->balances = app('steam')->balancesByAccounts($objects, $this->getDate());
|
$this->balances = app('steam')->balancesByAccounts($objects, $this->getDate());
|
||||||
$this->convertedBalances = app('steam')->balancesByAccountsConverted($objects, $this->getDate());
|
$this->convertedBalances = app('steam')->balancesByAccountsConverted($objects, $this->getDate());
|
||||||
|
|
||||||
@@ -62,6 +67,7 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
|
|
||||||
// get currencies:
|
// get currencies:
|
||||||
$accountIds = $objects->pluck('id')->toArray();
|
$accountIds = $objects->pluck('id')->toArray();
|
||||||
|
// TODO move query to repository
|
||||||
$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'])
|
||||||
@@ -79,6 +85,7 @@ 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;
|
||||||
|
// TODO move query to repository
|
||||||
$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'])
|
||||||
@@ -89,6 +96,16 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
$this->accountTypes[$row->id] = (string)config(sprintf('firefly.shortNamesByFullName.%s', $row->type));
|
$this->accountTypes[$row->id] = (string)config(sprintf('firefly.shortNamesByFullName.%s', $row->type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get last activity
|
||||||
|
// TODO move query to repository
|
||||||
|
$array = Transaction::whereIn('account_id',$accountIds)
|
||||||
|
->leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
|
||||||
|
->groupBy('transactions.account_id')
|
||||||
|
->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) as date_max')])->toArray();
|
||||||
|
foreach($array as $row){
|
||||||
|
$this->lastActivity[(int)$row['account_id']] = Carbon::parse($row['date_max'], config('app.timezone'));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO needs separate method.
|
// TODO needs separate method.
|
||||||
/** @var null|array $sort */
|
/** @var null|array $sort */
|
||||||
$sort = $this->parameters->get('sort');
|
$sort = $this->parameters->get('sort');
|
||||||
@@ -189,6 +206,7 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
'current_balance_date' => $this->getDate()->endOfDay()->toAtomString(),
|
'current_balance_date' => $this->getDate()->endOfDay()->toAtomString(),
|
||||||
|
|
||||||
// more meta
|
// more meta
|
||||||
|
'last_activity' => array_key_exists($id, $this->lastActivity) ? $this->lastActivity[$id]->toAtomString() : null,
|
||||||
|
|
||||||
// 'notes' => $this->repository->getNoteText($account),
|
// 'notes' => $this->repository->getNoteText($account),
|
||||||
// 'monthly_payment_date' => $monthlyPaymentDate,
|
// 'monthly_payment_date' => $monthlyPaymentDate,
|
||||||
|
@@ -93,13 +93,14 @@ let index = function () {
|
|||||||
active: current.attributes.active,
|
active: current.attributes.active,
|
||||||
name: current.attributes.name,
|
name: current.attributes.name,
|
||||||
type: current.attributes.type,
|
type: current.attributes.type,
|
||||||
// role: current.attributes.account_role,
|
role: current.attributes.account_role,
|
||||||
iban: null === current.attributes.iban ? '' : current.attributes.iban.match(/.{1,4}/g).join(' '),
|
iban: null === current.attributes.iban ? '' : current.attributes.iban.match(/.{1,4}/g).join(' '),
|
||||||
account_number: null === current.attributes.account_number ? '' : current.attributes.account_number,
|
account_number: null === current.attributes.account_number ? '' : current.attributes.account_number,
|
||||||
current_balance: current.attributes.current_balance,
|
current_balance: current.attributes.current_balance,
|
||||||
currency_code: current.attributes.currency_code,
|
currency_code: current.attributes.currency_code,
|
||||||
native_current_balance: current.attributes.native_current_balance,
|
native_current_balance: current.attributes.native_current_balance,
|
||||||
native_currency_code: current.attributes.native_currency_code,
|
native_currency_code: current.attributes.native_currency_code,
|
||||||
|
last_activity: null === current.attributes.last_activity ? '' : format(new Date(current.attributes.last_activity),'P'),
|
||||||
};
|
};
|
||||||
this.accounts.push(account);
|
this.accounts.push(account);
|
||||||
}
|
}
|
||||||
|
@@ -124,8 +124,10 @@
|
|||||||
<td>
|
<td>
|
||||||
<span x-text="formatMoney(account.current_balance, account.currency_code)"></span>
|
<span x-text="formatMoney(account.current_balance, account.currency_code)"></span>
|
||||||
</td>
|
</td>
|
||||||
<td>TODO</td>
|
<td>
|
||||||
<td>TODO</td>
|
<span x-text="account.last_activity"></span>
|
||||||
|
</td>
|
||||||
|
<td>TODO 2 </td>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
|
Reference in New Issue
Block a user