mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up some lists [skip ci]
This commit is contained in:
@@ -153,12 +153,23 @@ class AccountController extends Controller
|
|||||||
* HERE WE ARE
|
* HERE WE ARE
|
||||||
*/
|
*/
|
||||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||||
|
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
|
// start balances:
|
||||||
|
$ids = [];
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$ids[] = $account->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$startBalances = Steam::balancesById($ids, $start);
|
||||||
|
$endBalances = Steam::balancesById($ids, $end);
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
function (Account $account) use ($start, $repository) {
|
function (Account $account) use ($startBalances, $endBalances) {
|
||||||
$account->lastActivityDate = $repository->getLastActivity($account);
|
$account->lastActivityDate = null;//$repository->getLastActivity($account);
|
||||||
$account->startBalance = Steam::balance($account, $start);
|
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
|
||||||
$account->endBalance = Steam::balance($account, clone Session::get('end', Carbon::now()->endOfMonth()));
|
$account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -42,12 +42,12 @@ use Watson\Validating\ValidatingTrait;
|
|||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account accountTypeIn($types)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account accountTypeIn($types)
|
||||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account hasMetaValue($name, $value)
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account hasMetaValue($name, $value)
|
||||||
* @property-read bool $joinedAccountTypes
|
* @property-read bool $joinedAccountTypes
|
||||||
* @property-read float $startBalance
|
* @property float $startBalance
|
||||||
* @property-read float $endBalance
|
* @property float $endBalance
|
||||||
* @property-read float $piggyBalance
|
* @property float $piggyBalance
|
||||||
* @property-read float $percentage
|
* @property float $percentage
|
||||||
* @property-read float $difference
|
* @property float $difference
|
||||||
* @property-read \Carbon\Carbon $lastActivityDate
|
* @property \Carbon\Carbon $lastActivityDate
|
||||||
*/
|
*/
|
||||||
class Account extends Model
|
class Account extends Model
|
||||||
{
|
{
|
||||||
|
@@ -68,7 +68,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
['accountmeta' => function (HasMany $query) {
|
['accountmeta' => function (HasMany $query) {
|
||||||
$query->where('name', 'accountRole');
|
$query->where('name', 'accountRole');
|
||||||
}]
|
}]
|
||||||
)->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
)->accountTypeIn($types)->get(['accounts.*']);
|
||||||
|
|
||||||
$result = $result->sortBy(
|
$result = $result->sortBy(
|
||||||
function (Account $account) {
|
function (Account $account) {
|
||||||
@@ -210,9 +210,9 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
{
|
{
|
||||||
$lastTransaction = $account->transactions()->leftJoin(
|
$lastTransaction = $account->transactions()->leftJoin(
|
||||||
'transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
|
'transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
|
||||||
)->orderBy('transaction_journals.date', 'DESC')->first(['transactions.*', 'transaction_journals.date']);
|
)->orderBy('transaction_journals.date', 'DESC')->first(['transactions.account_id', 'transaction_journals.date']);
|
||||||
if ($lastTransaction) {
|
if ($lastTransaction) {
|
||||||
return $lastTransaction->transactionjournal->date;
|
return $lastTransaction->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -35,10 +35,18 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getCurrencySymbol()
|
public function getCurrencySymbol()
|
||||||
{
|
{
|
||||||
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
|
$cache = new CacheProperties;
|
||||||
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
$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()
|
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();
|
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
||||||
if ($currency) {
|
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()
|
public function getDefaultCurrency()
|
||||||
{
|
{
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty('getDefaultCurrency');
|
||||||
|
if ($cache->has()) {
|
||||||
|
return $cache->get();
|
||||||
|
}
|
||||||
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
|
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
|
||||||
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
|
||||||
|
$cache->store($currency);
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@
|
|||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Steam
|
* Class Steam
|
||||||
@@ -47,4 +49,45 @@ class Steam
|
|||||||
return round($balance, 2);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>{{ account.iban }}</td>
|
<td>{{ account.iban }}</td>
|
||||||
<td data-value="{{ account|balance }}">{{ account|balance|formatAmount }}</td>
|
<td data-value="{{ account.startBalance }}">{{ account.startBalance|formatAmount }}</td>
|
||||||
<td class="hidden-sm hidden-xs" data-value="{{ account.active }}">
|
<td class="hidden-sm hidden-xs" data-value="{{ account.active }}">
|
||||||
{% if account.active %}
|
{% if account.active %}
|
||||||
<i class="fa fa-fw fa-check"></i>
|
<i class="fa fa-fw fa-check"></i>
|
||||||
|
Reference in New Issue
Block a user