mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Clean up some lists [skip ci]
This commit is contained in:
@@ -153,12 +153,23 @@ class AccountController extends Controller
|
||||
* HERE WE ARE
|
||||
*/
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||
$start->subDay();
|
||||
|
||||
// start balances:
|
||||
$ids = [];
|
||||
foreach ($accounts as $account) {
|
||||
$ids[] = $account->id;
|
||||
}
|
||||
|
||||
$startBalances = Steam::balancesById($ids, $start);
|
||||
$endBalances = Steam::balancesById($ids, $end);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($start, $repository) {
|
||||
$account->lastActivityDate = $repository->getLastActivity($account);
|
||||
$account->startBalance = Steam::balance($account, $start);
|
||||
$account->endBalance = Steam::balance($account, clone Session::get('end', Carbon::now()->endOfMonth()));
|
||||
function (Account $account) use ($startBalances, $endBalances) {
|
||||
$account->lastActivityDate = null;//$repository->getLastActivity($account);
|
||||
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
|
||||
$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 hasMetaValue($name, $value)
|
||||
* @property-read bool $joinedAccountTypes
|
||||
* @property-read float $startBalance
|
||||
* @property-read float $endBalance
|
||||
* @property-read float $piggyBalance
|
||||
* @property-read float $percentage
|
||||
* @property-read float $difference
|
||||
* @property-read \Carbon\Carbon $lastActivityDate
|
||||
* @property float $startBalance
|
||||
* @property float $endBalance
|
||||
* @property float $piggyBalance
|
||||
* @property float $percentage
|
||||
* @property float $difference
|
||||
* @property \Carbon\Carbon $lastActivityDate
|
||||
*/
|
||||
class Account extends Model
|
||||
{
|
||||
|
@@ -68,7 +68,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
['accountmeta' => function (HasMany $query) {
|
||||
$query->where('name', 'accountRole');
|
||||
}]
|
||||
)->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
)->accountTypeIn($types)->get(['accounts.*']);
|
||||
|
||||
$result = $result->sortBy(
|
||||
function (Account $account) {
|
||||
@@ -210,9 +210,9 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$lastTransaction = $account->transactions()->leftJoin(
|
||||
'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) {
|
||||
return $lastTransaction->transactionjournal->date;
|
||||
return $lastTransaction->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@
|
||||
</td>
|
||||
{% endif %}
|
||||
<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 }}">
|
||||
{% if account.active %}
|
||||
<i class="fa fa-fw fa-check"></i>
|
||||
|
Reference in New Issue
Block a user