mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-07 06:33:57 -06:00
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace FireflyIII\Support;
|
|
|
|
use Carbon\Carbon;
|
|
use FireflyIII\Models\Account;
|
|
|
|
/**
|
|
* Class Steam
|
|
*
|
|
* @package FireflyIII\Support
|
|
*/
|
|
class Steam
|
|
{
|
|
/**
|
|
*
|
|
* @param \FireflyIII\Models\Account $account
|
|
* @param \Carbon\Carbon $date
|
|
* @param bool $ignoreVirtualBalance
|
|
*
|
|
* @return float
|
|
*/
|
|
public function balance(Account $account, Carbon $date, $ignoreVirtualBalance = false)
|
|
{
|
|
|
|
// abuse chart properties:
|
|
$cache = new CacheProperties;
|
|
$cache->addProperty($account->id);
|
|
$cache->addProperty('balance');
|
|
$cache->addProperty($date);
|
|
$cache->addProperty($ignoreVirtualBalance);
|
|
if ($cache->has()) {
|
|
return $cache->get(); // @codeCoverageIgnore
|
|
}
|
|
|
|
bcscale(2);
|
|
|
|
$balance = $account->transactions()->leftJoin(
|
|
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
|
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount');
|
|
|
|
if (!$ignoreVirtualBalance) {
|
|
$balance = bcadd($balance, $account->virtual_balance);
|
|
}
|
|
$cache->store(round($balance, 2));
|
|
|
|
return round($balance, 2);
|
|
}
|
|
|
|
}
|