mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-21 03:42:54 +00:00
Clean up some lists [skip ci]
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user