mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Remove some often used long calls with shorter ones.
This commit is contained in:
parent
43e738cb44
commit
6381408fba
@ -29,7 +29,7 @@ class GoogleChartController extends BaseController
|
||||
if ($current > Carbon::now()) {
|
||||
$row[] = null;
|
||||
} else {
|
||||
$row[] = $account->balance($current);
|
||||
$row[] = Steam::balance($account, $current);
|
||||
}
|
||||
|
||||
$chart->addRowArray($row);
|
||||
@ -203,12 +203,7 @@ class GoogleChartController extends BaseController
|
||||
$row = [clone $current];
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
//if ($current > Carbon::now()) {
|
||||
// $row[] = 0;
|
||||
//} else {
|
||||
$row[] = $account->balance($current);
|
||||
//}
|
||||
|
||||
$row[] = Steam::balance($account, $current);
|
||||
}
|
||||
|
||||
$chart->addRowArray($row);
|
||||
@ -573,8 +568,7 @@ class GoogleChartController extends BaseController
|
||||
/*
|
||||
* Get end of period for $current:
|
||||
*/
|
||||
$currentEnd = clone $current;
|
||||
DateKit::endOfPeriod($currentEnd, $entry->repeat_freq);
|
||||
$currentEnd = DateKit::endOfPeriod($current, $entry->repeat_freq);
|
||||
|
||||
/*
|
||||
* In the current session range?
|
||||
@ -599,7 +593,7 @@ class GoogleChartController extends BaseController
|
||||
/*
|
||||
* Add some time for the next loop!
|
||||
*/
|
||||
DateKit::addPeriod($current, $entry->repeat_freq, intval($entry->skip));
|
||||
$current = DateKit::addPeriod($current, $entry->repeat_freq, intval($entry->skip));
|
||||
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ class PiggybankController extends BaseController
|
||||
*/
|
||||
$account = $piggybank->account;
|
||||
if (!isset($accounts[$account->id])) {
|
||||
$accounts[$account->id] = ['name' => $account->name, 'balance' => $account->balance(),
|
||||
$accounts[$account->id] = ['name' => $account->name, 'balance' => Steam::balance($account),
|
||||
'leftForPiggybanks' => $repos->leftOnAccount($account), 'sumOfSaved' => $piggybank->savedSoFar,
|
||||
'sumOfTargets' => floatval($piggybank->targetamount), 'leftToSave' => $piggybank->leftToSave];
|
||||
} else {
|
||||
|
@ -264,7 +264,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
*/
|
||||
public function leftOnAccount(\Account $account)
|
||||
{
|
||||
$balance = $account->balance();
|
||||
$balance = Steam::balance($account);
|
||||
/** @var \Piggybank $p */
|
||||
foreach ($account->piggybanks()->get() as $p) {
|
||||
$balance -= $p->currentRelevantRep()->currentamount;
|
||||
|
@ -66,6 +66,15 @@ class FF3ServiceProvider extends ServiceProvider
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
* For models, various stuff:
|
||||
*/
|
||||
$this->app->bind(
|
||||
'steam', function() {
|
||||
return new \FireflyIII\Shared\Toolkit\Steam;
|
||||
}
|
||||
);
|
||||
|
||||
// preferences:
|
||||
$this->app->bind('FireflyIII\Shared\Preferences\PreferencesInterface', 'FireflyIII\Shared\Preferences\Preferences');
|
||||
|
||||
@ -81,6 +90,7 @@ class FF3ServiceProvider extends ServiceProvider
|
||||
$loader->alias('DateKit', 'FireflyIII\Shared\Facade\DateKit');
|
||||
$loader->alias('Navigation', 'FireflyIII\Shared\Facade\Navigation');
|
||||
$loader->alias('FFForm', 'FireflyIII\Shared\Facade\FFForm');
|
||||
$loader->alias('Steam', 'FireflyIII\Shared\Facade\Steam');
|
||||
}
|
||||
);
|
||||
|
||||
|
16
app/lib/FireflyIII/Shared/Facade/Steam.php
Normal file
16
app/lib/FireflyIII/Shared/Facade/Steam.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Shared\Facade;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class Steam extends Facade
|
||||
{
|
||||
|
||||
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'steam';
|
||||
}
|
||||
|
||||
}
|
34
app/lib/FireflyIII/Shared/Toolkit/Steam.php
Normal file
34
app/lib/FireflyIII/Shared/Toolkit/Steam.php
Normal 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')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -57,26 +57,6 @@ class Account extends Ardent
|
||||
return $this->belongsTo('AccountType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an accounts current balance.
|
||||
*
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
* @param \Carbon\Carbon $date
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function balance(\Carbon\Carbon $date = null)
|
||||
{
|
||||
$date = is_null($date) ? new \Carbon\Carbon : $date;
|
||||
|
||||
return floatval(
|
||||
$this->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions.
|
||||
*
|
||||
|
@ -15,7 +15,7 @@
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="{{route('accounts.show',$account->id)}}">{{{$account->name}}}</a></td>
|
||||
<td>{{mf($account->balance())}}</td>
|
||||
<td>{{mf(Steam::balance($account))}}</td>
|
||||
<td>
|
||||
@if($account->active)
|
||||
<i class="fa fa-fw fa-check"></i>
|
||||
|
Loading…
Reference in New Issue
Block a user