mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
First attempt at new last activity thing.
This commit is contained in:
parent
3c2952009e
commit
c3dc193f3e
@ -167,10 +167,11 @@ class AccountController extends Controller
|
||||
|
||||
$startBalances = Steam::balancesById($ids, $start);
|
||||
$endBalances = Steam::balancesById($ids, $end);
|
||||
$activities = $repository->getLastActivities($ids);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($startBalances, $endBalances) {
|
||||
$account->lastActivityDate = null;//$repository->getLastActivity($account);
|
||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||
$account->lastActivityDate = isset($activities[$account->id]) ? $activities[$account->id] : null;
|
||||
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
|
||||
$account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
|
||||
}
|
||||
|
@ -207,6 +207,27 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLastActivities(array $accounts)
|
||||
{
|
||||
$list = [];
|
||||
|
||||
$set = Auth::user()->transactions()
|
||||
->whereIn('account_id', $accounts)
|
||||
->groupBy('account_id')
|
||||
->get(['transactions.account_id', DB::Raw('MAX(`transaction_journals`.`date`) as `max_date`')]);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$list[intval($entry->account_id)] = new Carbon($entry->max_date);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user