Remove some often used long calls with shorter ones.

This commit is contained in:
James Cole
2014-11-21 19:33:09 +01:00
parent 43e738cb44
commit 6381408fba
8 changed files with 67 additions and 33 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace FireflyIII\Shared\Toolkit;
use Carbon\Carbon;
/**
*
* Steam is a special class used for those small often occurring things you need your application to do.
*
* Class Steam
*
* @package FireflyIII\Shared\Toolkit
*/
class Steam
{
/**
* @param \Account $account
* @param Carbon $date
*
* @return float
*/
public function balance(\Account $account, Carbon $date = null)
{
$date = is_null($date) ? Carbon::now() : $date;
return floatval(
$account->transactions()->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
);
}
}