First attempt at new last activity thing.

This commit is contained in:
James Cole 2015-07-25 19:22:41 +02:00
parent 3c2952009e
commit c3dc193f3e
2 changed files with 24 additions and 2 deletions

View File

@ -167,10 +167,11 @@ class AccountController extends Controller
$startBalances = Steam::balancesById($ids, $start); $startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end); $endBalances = Steam::balancesById($ids, $end);
$activities = $repository->getLastActivities($ids);
$accounts->each( $accounts->each(
function (Account $account) use ($startBalances, $endBalances) { function (Account $account) use ($activities, $startBalances, $endBalances) {
$account->lastActivityDate = null;//$repository->getLastActivity($account); $account->lastActivityDate = isset($activities[$account->id]) ? $activities[$account->id] : null;
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null; $account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
$account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null; $account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
} }

View File

@ -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 * @param Account $account
* *