Clean up some lists [skip ci]

This commit is contained in:
James Cole
2015-07-10 07:39:59 +02:00
parent b6960fb0e5
commit 308da6dc6e
6 changed files with 100 additions and 23 deletions

View File

@@ -35,10 +35,18 @@ class Amount
*/
public function getCurrencySymbol()
{
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
$cache = new CacheProperties;
$cache->addProperty('getCurrencySymbol');
if ($cache->has()) {
return $cache->get();
} else {
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
return $currency->symbol;
$cache->store($currency->symbol);
return $currency->symbol;
}
}
/**
@@ -142,15 +150,24 @@ class Amount
public function getCurrencyCode()
{
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
$cache = new CacheProperties;
$cache->addProperty('getCurrencyCode');
if ($cache->has()) {
return $cache->get();
} else {
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
if ($currency) {
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
if ($currency) {
return $currency->code;
$cache->store($currency->code);
return $currency->code;
}
$cache->store('EUR');
return 'EUR'; // @codeCoverageIgnore
}
return 'EUR'; // @codeCoverageIgnore
}
/**
@@ -158,8 +175,14 @@ class Amount
*/
public function getDefaultCurrency()
{
$cache = new CacheProperties;
$cache->addProperty('getDefaultCurrency');
if ($cache->has()) {
return $cache->get();
}
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
$cache->store($currency);
return $currency;
}

View File

@@ -3,7 +3,9 @@
namespace FireflyIII\Support;
use Carbon\Carbon;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
/**
* Class Steam
@@ -47,4 +49,45 @@ class Steam
return round($balance, 2);
}
/**
*
* @param array $ids
* @param \Carbon\Carbon $date
*
* @return float
*/
public function balancesById(array $ids, Carbon $date)
{
// abuse chart properties:
$cache = new CacheProperties;
$cache->addProperty($ids);
$cache->addProperty('balances');
$cache->addProperty($date);
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
bcscale(2);
$balances = Transaction::
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->groupBy('transactions.account_id')
->whereIn('transactions.account_id', $ids)
->get(['transactions.account_id', DB::Raw('sum(`transactions`.`amount`) as aggregate')]);
$result = [];
foreach ($balances as $entry) {
$accountId = intval($entry->account_id);
$balance = round($entry->aggregate, 2);
$result[$accountId] = $balance;
}
$cache->store($result);
return $result;
}
}