mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up balance methods.
This commit is contained in:
parent
a0e92b6969
commit
d90ac519f7
@ -116,13 +116,13 @@ class AccountController extends Controller
|
|||||||
];
|
];
|
||||||
// TODO this code is also present in the V2 chart account controller so this method is due to be deprecated.
|
// TODO this code is also present in the V2 chart account controller so this method is due to be deprecated.
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $start;
|
||||||
$range = app('steam')->balanceInRange($account, $start, clone $end);
|
$range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end);
|
||||||
// 2022-10-11 this method no longer converts to float.
|
// 2022-10-11 this method no longer converts to float.
|
||||||
$previous = array_values($range)[0];
|
$previous = array_values($range)[0];
|
||||||
while ($currentStart <= $end) {
|
while ($currentStart <= $end) {
|
||||||
$format = $currentStart->format('Y-m-d');
|
$format = $currentStart->format('Y-m-d');
|
||||||
$label = $currentStart->toAtomString();
|
$label = $currentStart->toAtomString();
|
||||||
$balance = array_key_exists($format, $range) ? $range[$format] : $previous;
|
$balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
$currentSet['entries'][$label] = $balance;
|
$currentSet['entries'][$label] = $balance;
|
||||||
|
@ -118,22 +118,21 @@ class AccountController extends Controller
|
|||||||
'native_entries' => [],
|
'native_entries' => [],
|
||||||
];
|
];
|
||||||
$currentStart = clone $params['start'];
|
$currentStart = clone $params['start'];
|
||||||
$range = app('steam')->balanceInRange($account, $params['start'], clone $params['end'], $currency);
|
$range = app('steam')->finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $currency);
|
||||||
$rangeConverted = app('steam')->balanceInRangeConverted($account, $params['start'], clone $params['end'], $this->default);
|
|
||||||
|
|
||||||
$previous = array_values($range)[0];
|
$previous = array_values($range)[0]['balance'];
|
||||||
$previousConverted = array_values($rangeConverted)[0];
|
$previousNative = array_values($range)[0]['native_balance'];
|
||||||
while ($currentStart <= $params['end']) {
|
while ($currentStart <= $params['end']) {
|
||||||
$format = $currentStart->format('Y-m-d');
|
$format = $currentStart->format('Y-m-d');
|
||||||
$label = $currentStart->toAtomString();
|
$label = $currentStart->toAtomString();
|
||||||
$balance = array_key_exists($format, $range) ? $range[$format] : $previous;
|
$balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous;
|
||||||
$balanceConverted = array_key_exists($format, $rangeConverted) ? $rangeConverted[$format] : $previousConverted;
|
$balanceNative = array_key_exists($format, $range) ? $range[$format]['balance_native'] : $previousNative;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
$previousConverted = $balanceConverted;
|
$previousNative = $balanceNative;
|
||||||
|
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
$currentSet['entries'][$label] = $balance;
|
$currentSet['entries'][$label] = $balance;
|
||||||
$currentSet['native_entries'][$label] = $balanceConverted;
|
$currentSet['native_entries'][$label] = $balanceNative;
|
||||||
}
|
}
|
||||||
$this->chartData->add($currentSet);
|
$this->chartData->add($currentSet);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class NetWorth implements NetWorthInterface
|
|||||||
'native_currency_decimal_places' => $default->decimal_places,
|
'native_currency_decimal_places' => $default->decimal_places,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$balances = app('steam')->balancesByAccountsConverted($accounts, $date);
|
$balances = app('steam')->finalAccountsBalance($accounts, $date);
|
||||||
|
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
@ -187,10 +187,10 @@ class NetWorth implements NetWorthInterface
|
|||||||
*/
|
*/
|
||||||
$accounts = $this->getAccounts();
|
$accounts = $this->getAccounts();
|
||||||
$return = [];
|
$return = [];
|
||||||
$balances = app('steam')->balancesByAccounts($accounts, $date);
|
$balances = app('steam')->finalAccountsBalance($accounts, $date);
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$currency = $this->getRepository()->getAccountCurrency($account);
|
$currency = $this->getRepository()->getAccountCurrency($account);
|
||||||
$balance = $balances[$account->id] ?? '0';
|
$balance = $balances[$account->id]['balance'] ?? '0';
|
||||||
|
|
||||||
// always subtract virtual balance.
|
// always subtract virtual balance.
|
||||||
$virtualBalance = $account->virtual_balance;
|
$virtualBalance = $account->virtual_balance;
|
||||||
|
@ -89,8 +89,8 @@ class IndexController extends Controller
|
|||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$startBalances = app('steam')->balancesByAccounts($accounts, $start);
|
$startBalances = app('steam')->finalAccountsBalance($accounts, $start);
|
||||||
$endBalances = app('steam')->balancesByAccounts($accounts, $end);
|
$endBalances = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
$activities = app('steam')->getLastActivities($ids);
|
$activities = app('steam')->getLastActivities($ids);
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
@ -149,8 +149,8 @@ class IndexController extends Controller
|
|||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$startBalances = app('steam')->balancesByAccounts($accounts, $start);
|
$startBalances = app('steam')->finalAccountsBalance($accounts, $start);
|
||||||
$endBalances = app('steam')->balancesByAccounts($accounts, $end);
|
$endBalances = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
$activities = app('steam')->getLastActivities($ids);
|
$activities = app('steam')->getLastActivities($ids);
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
|
@ -106,28 +106,27 @@ class AccountController extends Controller
|
|||||||
$accountNames = $this->extractNames($accounts);
|
$accountNames = $this->extractNames($accounts);
|
||||||
|
|
||||||
// grab all balances
|
// grab all balances
|
||||||
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
|
$startBalances = app('steam')->finalAccountsBalance($accounts, $start);
|
||||||
$endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);
|
$endBalances = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
|
|
||||||
// loop the end balances. This is an array for each account ($expenses)
|
// loop the end balances. This is an array for each account ($expenses)
|
||||||
foreach ($endBalances as $accountId => $expenses) {
|
foreach ($endBalances as $accountId => $expenses) {
|
||||||
$accountId = (int) $accountId;
|
$accountId = (int) $accountId;
|
||||||
// loop each expense entry (each entry can be a different currency).
|
// loop each expense entry (each entry can be a different currency).
|
||||||
foreach ($expenses as $currencyId => $endAmount) {
|
foreach ($expenses as $currencyCode => $endAmount) {
|
||||||
$currencyId = (int) $currencyId;
|
|
||||||
|
|
||||||
// see if there is an accompanying start amount.
|
// see if there is an accompanying start amount.
|
||||||
// grab the difference and find the currency.
|
// grab the difference and find the currency.
|
||||||
$startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0');
|
$startAmount = (string) ($startBalances[$accountId][$currencyCode] ?? '0');
|
||||||
$diff = bcsub((string) $endAmount, $startAmount);
|
$diff = bcsub((string) $endAmount, $startAmount);
|
||||||
$currencies[$currencyId] ??= $this->currencyRepository->find($currencyId);
|
$currencies[$currencyCode] ??= $this->currencyRepository->findByCode($currencyCode);
|
||||||
if (0 !== bccomp($diff, '0')) {
|
if (0 !== bccomp($diff, '0')) {
|
||||||
// store the values in a temporary array.
|
// store the values in a temporary array.
|
||||||
$tempData[] = [
|
$tempData[] = [
|
||||||
'name' => $accountNames[$accountId],
|
'name' => $accountNames[$accountId],
|
||||||
'difference' => $diff,
|
'difference' => $diff,
|
||||||
'diff_float' => (float) $diff, // intentional float
|
'diff_float' => (float) $diff, // intentional float
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => $currencies[$currencyCode]->id,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,11 +436,11 @@ class AccountController extends Controller
|
|||||||
if ('1D' === $step) {
|
if ('1D' === $step) {
|
||||||
// per day the entire period, balance for every day.
|
// per day the entire period, balance for every day.
|
||||||
$format = (string) trans('config.month_and_day_js', [], $locale);
|
$format = (string) trans('config.month_and_day_js', [], $locale);
|
||||||
$range = app('steam')->balanceInRange($account, $start, $end, $currency);
|
$range = app('steam')->finalAccountBalanceInRange($account, $start, $end);
|
||||||
$previous = array_values($range)[0];
|
$previous = array_values($range)[0];
|
||||||
while ($end >= $current) {
|
while ($end >= $current) {
|
||||||
$theDate = $current->format('Y-m-d');
|
$theDate = $current->format('Y-m-d');
|
||||||
$balance = $range[$theDate] ?? $previous;
|
$balance = $range[$theDate]['balance'] ?? $previous;
|
||||||
$label = $current->isoFormat($format);
|
$label = $current->isoFormat($format);
|
||||||
$entries[$label] = (float) $balance;
|
$entries[$label] = (float) $balance;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
@ -507,28 +506,27 @@ class AccountController extends Controller
|
|||||||
$accountNames = $this->extractNames($accounts);
|
$accountNames = $this->extractNames($accounts);
|
||||||
|
|
||||||
// grab all balances
|
// grab all balances
|
||||||
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
|
$startBalances = app('steam')->finalAccountsBalance($accounts, $start);
|
||||||
$endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);
|
$endBalances = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
|
|
||||||
// loop the end balances. This is an array for each account ($expenses)
|
// loop the end balances. This is an array for each account ($expenses)
|
||||||
foreach ($endBalances as $accountId => $expenses) {
|
foreach ($endBalances as $accountId => $expenses) {
|
||||||
$accountId = (int) $accountId;
|
$accountId = (int) $accountId;
|
||||||
// loop each expense entry (each entry can be a different currency).
|
// loop each expense entry (each entry can be a different currency).
|
||||||
foreach ($expenses as $currencyId => $endAmount) {
|
foreach ($expenses as $currencyCode => $endAmount) {
|
||||||
$currencyId = (int) $currencyId;
|
|
||||||
|
|
||||||
// see if there is an accompanying start amount.
|
// see if there is an accompanying start amount.
|
||||||
// grab the difference and find the currency.
|
// grab the difference and find the currency.
|
||||||
$startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0');
|
$startAmount = (string) ($startBalances[$accountId][$currencyCode] ?? '0');
|
||||||
$diff = bcsub((string) $endAmount, $startAmount);
|
$diff = bcsub((string) $endAmount, $startAmount);
|
||||||
$currencies[$currencyId] ??= $this->currencyRepository->find($currencyId);
|
$currencies[$currencyCode] ??= $this->currencyRepository->findByCode($currencyCode);
|
||||||
if (0 !== bccomp($diff, '0')) {
|
if (0 !== bccomp($diff, '0')) {
|
||||||
// store the values in a temporary array.
|
// store the values in a temporary array.
|
||||||
$tempData[] = [
|
$tempData[] = [
|
||||||
'name' => $accountNames[$accountId],
|
'name' => $accountNames[$accountId],
|
||||||
'difference' => $diff,
|
'difference' => $diff,
|
||||||
'diff_float' => (float) $diff, // intentional float
|
'diff_float' => (float) $diff, // intentional float
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => $currencies[$currencyCode]->id,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
{
|
{
|
||||||
$yesterday = clone $start;
|
$yesterday = clone $start;
|
||||||
$yesterday->subDay();
|
$yesterday->subDay();
|
||||||
$startSet = app('steam')->balancesByAccounts($accounts, $yesterday);
|
$startSet = app('steam')->finalAccountsBalance($accounts, $yesterday);
|
||||||
$endSet = app('steam')->balancesByAccounts($accounts, $end);
|
$endSet = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
app('log')->debug('Start of accountreport');
|
app('log')->debug('Start of accountreport');
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
@ -86,8 +86,8 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
|
|
||||||
// get first journal date:
|
// get first journal date:
|
||||||
$first = $repository->oldestJournal($account);
|
$first = $repository->oldestJournal($account);
|
||||||
$entry['start_balance'] = $startSet[$account->id] ?? '0';
|
$entry['start_balance'] = $startSet[$account->id]['balance'] ?? '0';
|
||||||
$entry['end_balance'] = $endSet[$account->id] ?? '0';
|
$entry['end_balance'] = $endSet[$account->id]['balance'] ?? '0';
|
||||||
|
|
||||||
// first journal exists, and is on start, then this is the actual opening balance:
|
// first journal exists, and is on start, then this is the actual opening balance:
|
||||||
if (null !== $first && $first->date->isSameDay($start) && TransactionType::OPENING_BALANCE === $first->transactionType->type) {
|
if (null !== $first && $first->date->isSameDay($start) && TransactionType::OPENING_BALANCE === $first->transactionType->type) {
|
||||||
|
@ -28,6 +28,7 @@ use FireflyIII\Models\TransactionCurrency;
|
|||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use NumberFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Amount.
|
* Class Amount.
|
||||||
@ -59,10 +60,10 @@ class Amount
|
|||||||
$rounded = app('steam')->bcround($amount, $decimalPlaces);
|
$rounded = app('steam')->bcround($amount, $decimalPlaces);
|
||||||
$coloured ??= true;
|
$coloured ??= true;
|
||||||
|
|
||||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
$fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
||||||
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
||||||
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$result = (string) $fmt->format((float) $rounded); // intentional float
|
$result = (string) $fmt->format((float) $rounded); // intentional float
|
||||||
|
|
||||||
if (true === $coloured) {
|
if (true === $coloured) {
|
||||||
@ -185,10 +186,10 @@ class Amount
|
|||||||
$info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
|
$info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
|
||||||
$info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
|
$info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
|
||||||
|
|
||||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
$fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
||||||
|
|
||||||
$info['mon_decimal_point'] = $fmt->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL);
|
$info['mon_decimal_point'] = $fmt->getSymbol(NumberFormatter::MONETARY_SEPARATOR_SYMBOL);
|
||||||
$info['mon_thousands_sep'] = $fmt->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
|
$info['mon_thousands_sep'] = $fmt->getSymbol(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
@ -30,13 +30,15 @@ use FireflyIII\Models\Role;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable;
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
use Illuminate\Contracts\Auth\UserProvider;
|
use Illuminate\Contracts\Auth\UserProvider;
|
||||||
|
use Override;
|
||||||
|
use Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RemoteUserProvider
|
* Class RemoteUserProvider
|
||||||
*/
|
*/
|
||||||
class RemoteUserProvider implements UserProvider
|
class RemoteUserProvider implements UserProvider
|
||||||
{
|
{
|
||||||
#[\Override]
|
#[Override]
|
||||||
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
|
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
|
||||||
{
|
{
|
||||||
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
||||||
@ -72,7 +74,7 @@ class RemoteUserProvider implements UserProvider
|
|||||||
'blocked' => false,
|
'blocked' => false,
|
||||||
'blocked_code' => null,
|
'blocked_code' => null,
|
||||||
'email' => $identifier,
|
'email' => $identifier,
|
||||||
'password' => bcrypt(\Str::random(64)),
|
'password' => bcrypt(Str::random(64)),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
// if this is the first user, give them admin as well.
|
// if this is the first user, give them admin as well.
|
||||||
|
@ -54,8 +54,7 @@ class Balance
|
|||||||
->orderBy('transaction_journals.order', 'asc')
|
->orderBy('transaction_journals.order', 'asc')
|
||||||
->orderBy('transaction_journals.description', 'desc')
|
->orderBy('transaction_journals.description', 'desc')
|
||||||
->orderBy('transactions.amount', 'desc')
|
->orderBy('transactions.amount', 'desc')
|
||||||
->where('transaction_journals.date', '<=', $date)
|
->where('transaction_journals.date', '<=', $date);
|
||||||
;
|
|
||||||
|
|
||||||
$result = $query->get(['transactions.account_id', 'transactions.transaction_currency_id', 'transactions.balance_after']);
|
$result = $query->get(['transactions.account_id', 'transactions.transaction_currency_id', 'transactions.balance_after']);
|
||||||
foreach ($result as $entry) {
|
foreach ($result as $entry) {
|
||||||
|
@ -46,8 +46,7 @@ class AccountList implements BinderInterface
|
|||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->whereIn('account_types.type', [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE])
|
->whereIn('account_types.type', [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE])
|
||||||
->orderBy('accounts.name', 'ASC')
|
->orderBy('accounts.name', 'ASC')
|
||||||
->get(['accounts.*'])
|
->get(['accounts.*']);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
if ('allAssetAccounts' !== $value) {
|
if ('allAssetAccounts' !== $value) {
|
||||||
$incoming = array_map('\intval', explode(',', $value));
|
$incoming = array_map('\intval', explode(',', $value));
|
||||||
@ -58,8 +57,7 @@ class AccountList implements BinderInterface
|
|||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->whereIn('accounts.id', $list)
|
->whereIn('accounts.id', $list)
|
||||||
->orderBy('accounts.name', 'ASC')
|
->orderBy('accounts.name', 'ASC')
|
||||||
->get(['accounts.*'])
|
->get(['accounts.*']);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($collection->count() > 0) {
|
if ($collection->count() > 0) {
|
||||||
|
@ -43,8 +43,7 @@ class BudgetList implements BinderInterface
|
|||||||
return auth()->user()->budgets()->where('active', true)
|
return auth()->user()->budgets()->where('active', true)
|
||||||
->orderBy('order', 'ASC')
|
->orderBy('order', 'ASC')
|
||||||
->orderBy('name', 'ASC')
|
->orderBy('name', 'ASC')
|
||||||
->get()
|
->get();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||||
@ -59,8 +58,7 @@ class BudgetList implements BinderInterface
|
|||||||
$collection = auth()->user()->budgets()
|
$collection = auth()->user()->budgets()
|
||||||
->where('active', true)
|
->where('active', true)
|
||||||
->whereIn('id', $list)
|
->whereIn('id', $list)
|
||||||
->get()
|
->get();
|
||||||
;
|
|
||||||
|
|
||||||
// add empty budget if applicable.
|
// add empty budget if applicable.
|
||||||
if (in_array(0, $list, true)) {
|
if (in_array(0, $list, true)) {
|
||||||
|
@ -42,8 +42,7 @@ class CategoryList implements BinderInterface
|
|||||||
if ('allCategories' === $value) {
|
if ('allCategories' === $value) {
|
||||||
return auth()->user()->categories()
|
return auth()->user()->categories()
|
||||||
->orderBy('name', 'ASC')
|
->orderBy('name', 'ASC')
|
||||||
->get()
|
->get();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||||
@ -54,8 +53,7 @@ class CategoryList implements BinderInterface
|
|||||||
/** @var Collection $collection */
|
/** @var Collection $collection */
|
||||||
$collection = auth()->user()->categories()
|
$collection = auth()->user()->categories()
|
||||||
->whereIn('id', $list)
|
->whereIn('id', $list)
|
||||||
->get()
|
->get();
|
||||||
;
|
|
||||||
|
|
||||||
// add empty category if applicable.
|
// add empty category if applicable.
|
||||||
if (in_array(0, $list, true)) {
|
if (in_array(0, $list, true)) {
|
||||||
|
@ -44,8 +44,7 @@ class TagList implements BinderInterface
|
|||||||
if ('allTags' === $value) {
|
if ('allTags' === $value) {
|
||||||
return auth()->user()->tags()
|
return auth()->user()->tags()
|
||||||
->orderBy('tag', 'ASC')
|
->orderBy('tag', 'ASC')
|
||||||
->get()
|
->get();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
$list = array_unique(array_map('\strtolower', explode(',', $value)));
|
$list = array_unique(array_map('\strtolower', explode(',', $value)));
|
||||||
app('log')->debug('List of tags is', $list);
|
app('log')->debug('List of tags is', $list);
|
||||||
|
@ -43,8 +43,7 @@ class UserGroupAccount implements BinderInterface
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$account = Account::where('id', (int) $value)
|
$account = Account::where('id', (int) $value)
|
||||||
->where('user_group_id', $user->user_group_id)
|
->where('user_group_id', $user->user_group_id)
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
if (null !== $account) {
|
if (null !== $account) {
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,7 @@ class UserGroupBill implements BinderInterface
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$currency = Bill::where('id', (int) $value)
|
$currency = Bill::where('id', (int) $value)
|
||||||
->where('user_group_id', $user->user_group_id)
|
->where('user_group_id', $user->user_group_id)
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,7 @@ class UserGroupExchangeRate implements BinderInterface
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$rate = CurrencyExchangeRate::where('id', (int) $value)
|
$rate = CurrencyExchangeRate::where('id', (int) $value)
|
||||||
->where('user_group_id', $user->user_group_id)
|
->where('user_group_id', $user->user_group_id)
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
if (null !== $rate) {
|
if (null !== $rate) {
|
||||||
return $rate;
|
return $rate;
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,7 @@ class UserGroupTransaction implements BinderInterface
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$group = TransactionGroup::where('id', (int) $value)
|
$group = TransactionGroup::where('id', (int) $value)
|
||||||
->where('user_group_id', $user->user_group_id)
|
->where('user_group_id', $user->user_group_id)
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
if (null !== $group) {
|
if (null !== $group) {
|
||||||
return $group;
|
return $group;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
|
use Cache;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use JsonException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CacheProperties.
|
* Class CacheProperties.
|
||||||
@ -55,7 +57,7 @@ class CacheProperties
|
|||||||
*/
|
*/
|
||||||
public function get()
|
public function get()
|
||||||
{
|
{
|
||||||
return \Cache::get($this->hash);
|
return Cache::get($this->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHash(): string
|
public function getHash(): string
|
||||||
@ -70,7 +72,7 @@ class CacheProperties
|
|||||||
}
|
}
|
||||||
$this->hash();
|
$this->hash();
|
||||||
|
|
||||||
return \Cache::has($this->hash);
|
return Cache::has($this->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function hash(): void
|
private function hash(): void
|
||||||
@ -79,7 +81,7 @@ class CacheProperties
|
|||||||
foreach ($this->properties as $property) {
|
foreach ($this->properties as $property) {
|
||||||
try {
|
try {
|
||||||
$content .= json_encode($property, JSON_THROW_ON_ERROR);
|
$content .= json_encode($property, JSON_THROW_ON_ERROR);
|
||||||
} catch (\JsonException $e) {
|
} catch (JsonException $e) {
|
||||||
// @ignoreException
|
// @ignoreException
|
||||||
$content .= hash('sha256', (string) time());
|
$content .= hash('sha256', (string) time());
|
||||||
}
|
}
|
||||||
@ -92,6 +94,6 @@ class CacheProperties
|
|||||||
*/
|
*/
|
||||||
public function store($data): void
|
public function store($data): void
|
||||||
{
|
{
|
||||||
\Cache::forever($this->hash, $data);
|
Cache::forever($this->hash, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Support\Calendar;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\IntervalException;
|
use FireflyIII\Exceptions\IntervalException;
|
||||||
|
use SplObjectStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Calculator
|
* Class Calculator
|
||||||
@ -33,7 +34,7 @@ use FireflyIII\Exceptions\IntervalException;
|
|||||||
class Calculator
|
class Calculator
|
||||||
{
|
{
|
||||||
public const int DEFAULT_INTERVAL = 1;
|
public const int DEFAULT_INTERVAL = 1;
|
||||||
private static ?\SplObjectStorage $intervalMap = null;
|
private static ?SplObjectStorage $intervalMap = null;
|
||||||
private static array $intervals = [];
|
private static array $intervals = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,12 +66,12 @@ class Calculator
|
|||||||
/**
|
/**
|
||||||
* @SuppressWarnings(PHPMD.MissingImport)
|
* @SuppressWarnings(PHPMD.MissingImport)
|
||||||
*/
|
*/
|
||||||
private static function loadIntervalMap(): \SplObjectStorage
|
private static function loadIntervalMap(): SplObjectStorage
|
||||||
{
|
{
|
||||||
if (null !== self::$intervalMap) {
|
if (null !== self::$intervalMap) {
|
||||||
return self::$intervalMap;
|
return self::$intervalMap;
|
||||||
}
|
}
|
||||||
self::$intervalMap = new \SplObjectStorage();
|
self::$intervalMap = new SplObjectStorage();
|
||||||
foreach (Periodicity::cases() as $interval) {
|
foreach (Periodicity::cases() as $interval) {
|
||||||
$periodicityClass = __NAMESPACE__ . "\\Periodicity\\{$interval->name}";
|
$periodicityClass = __NAMESPACE__ . "\\Periodicity\\{$interval->name}";
|
||||||
self::$intervals[] = $interval->name;
|
self::$intervals[] = $interval->name;
|
||||||
|
@ -27,6 +27,7 @@ use Eloquent;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Support\Form\FormSupport;
|
use FireflyIII\Support\Form\FormSupport;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExpandedForm.
|
* Class ExpandedForm.
|
||||||
@ -56,7 +57,7 @@ class ExpandedForm
|
|||||||
// }
|
// }
|
||||||
try {
|
try {
|
||||||
$html = view('form.amount-no-currency', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.amount-no-currency', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Could not render amountNoCurrency(): %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not render amountNoCurrency(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render amountNoCurrency.';
|
$html = 'Could not render amountNoCurrency.';
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.checkbox', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.checkbox', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render checkbox(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render checkbox(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render checkbox.';
|
$html = 'Could not render checkbox.';
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.date', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.date', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render date(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render date(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render date.';
|
$html = 'Could not render date.';
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.file', compact('classes', 'name', 'label', 'options'))->render();
|
$html = view('form.file', compact('classes', 'name', 'label', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render file(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render file(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render file.';
|
$html = 'Could not render file.';
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.integer', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.integer', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render integer(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render integer(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render integer.';
|
$html = 'Could not render integer.';
|
||||||
|
|
||||||
@ -189,7 +190,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.location', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.location', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render location(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render location(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render location.';
|
$html = 'Could not render location.';
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ class ExpandedForm
|
|||||||
$selectList[0] = '(none)';
|
$selectList[0] = '(none)';
|
||||||
$fields = ['title', 'name', 'description'];
|
$fields = ['title', 'name', 'description'];
|
||||||
|
|
||||||
/** @var \Eloquent $entry */
|
/** @var Eloquent $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
// All Eloquent models have an ID
|
// All Eloquent models have an ID
|
||||||
$entryId = $entry->id; // @phpstan-ignore-line
|
$entryId = $entry->id; // @phpstan-ignore-line
|
||||||
@ -242,7 +243,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.object_group', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.object_group', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render objectGroup(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render objectGroup(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render objectGroup.';
|
$html = 'Could not render objectGroup.';
|
||||||
|
|
||||||
@ -259,7 +260,7 @@ class ExpandedForm
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$html = view('form.options', compact('type', 'name'))->render();
|
$html = view('form.options', compact('type', 'name'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render optionsList.';
|
$html = 'Could not render optionsList.';
|
||||||
|
|
||||||
@ -280,7 +281,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.password', compact('classes', 'name', 'label', 'options'))->render();
|
$html = view('form.password', compact('classes', 'name', 'label', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render password(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render password(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render password.';
|
$html = 'Could not render password.';
|
||||||
|
|
||||||
@ -301,7 +302,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.password', compact('classes', 'value', 'name', 'label', 'options'))->render();
|
$html = view('form.password', compact('classes', 'value', 'name', 'label', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render passwordWithValue(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render passwordWithValue(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render passwordWithValue.';
|
$html = 'Could not render passwordWithValue.';
|
||||||
|
|
||||||
@ -329,7 +330,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.percentage', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.percentage', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render percentage(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render percentage(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render percentage.';
|
$html = 'Could not render percentage.';
|
||||||
|
|
||||||
@ -352,7 +353,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render staticText(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render staticText(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render staticText.';
|
$html = 'Could not render staticText.';
|
||||||
|
|
||||||
@ -376,7 +377,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.text', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.text', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render text(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render text(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render text.';
|
$html = 'Could not render text.';
|
||||||
|
|
||||||
@ -405,7 +406,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.textarea', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.textarea', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render textarea(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render textarea(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render textarea.';
|
$html = 'Could not render textarea.';
|
||||||
|
|
||||||
|
@ -736,8 +736,7 @@ class ExportDataGenerator
|
|||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setUser($this->user);
|
$collector->setUser($this->user);
|
||||||
$collector->setRange($this->start, $this->end)->withAccountInformation()->withCategoryInformation()->withBillInformation()
|
$collector->setRange($this->start, $this->end)->withAccountInformation()->withCategoryInformation()->withBillInformation()
|
||||||
->withBudgetInformation()->withTagInformation()->withNotes()
|
->withBudgetInformation()->withTagInformation()->withNotes();
|
||||||
;
|
|
||||||
if (0 !== $this->accounts->count()) {
|
if (0 !== $this->accounts->count()) {
|
||||||
$collector->setAccounts($this->accounts);
|
$collector->setAccounts($this->accounts);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
|
use Cache;
|
||||||
|
use Exception;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Configuration;
|
use FireflyIII\Models\Configuration;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
@ -38,8 +40,8 @@ class FireflyConfig
|
|||||||
public function delete(string $name): void
|
public function delete(string $name): void
|
||||||
{
|
{
|
||||||
$fullName = 'ff-config-' . $name;
|
$fullName = 'ff-config-' . $name;
|
||||||
if (\Cache::has($fullName)) {
|
if (Cache::has($fullName)) {
|
||||||
\Cache::forget($fullName);
|
Cache::forget($fullName);
|
||||||
}
|
}
|
||||||
Configuration::where('name', $name)->forceDelete();
|
Configuration::where('name', $name)->forceDelete();
|
||||||
}
|
}
|
||||||
@ -80,19 +82,19 @@ class FireflyConfig
|
|||||||
public function get(string $name, $default = null): ?Configuration
|
public function get(string $name, $default = null): ?Configuration
|
||||||
{
|
{
|
||||||
$fullName = 'ff-config-' . $name;
|
$fullName = 'ff-config-' . $name;
|
||||||
if (\Cache::has($fullName)) {
|
if (Cache::has($fullName)) {
|
||||||
return \Cache::get($fullName);
|
return Cache::get($fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var null|Configuration $config */
|
/** @var null|Configuration $config */
|
||||||
$config = Configuration::where('name', $name)->first(['id', 'name', 'data']);
|
$config = Configuration::where('name', $name)->first(['id', 'name', 'data']);
|
||||||
} catch (\Exception|QueryException $e) {
|
} catch (Exception | QueryException $e) {
|
||||||
throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage()), 0, $e);
|
throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage()), 0, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $config) {
|
if (null !== $config) {
|
||||||
\Cache::forever($fullName, $config);
|
Cache::forever($fullName, $config);
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
@ -122,13 +124,13 @@ class FireflyConfig
|
|||||||
$item->name = $name;
|
$item->name = $name;
|
||||||
$item->data = $value;
|
$item->data = $value;
|
||||||
$item->save();
|
$item->save();
|
||||||
\Cache::forget('ff-config-'.$name);
|
Cache::forget('ff-config-' . $name);
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
$config->data = $value;
|
$config->data = $value;
|
||||||
$config->save();
|
$config->save();
|
||||||
\Cache::forget('ff-config-'.$name);
|
Cache::forget('ff-config-' . $name);
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountForm
|
* Class AccountForm
|
||||||
@ -125,7 +126,7 @@ class AccountForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.assetAccountCheckList', compact('classes', 'selected', 'name', 'label', 'options', 'grouped'))->render();
|
$html = view('form.assetAccountCheckList', compact('classes', 'selected', 'name', 'label', 'options', 'grouped'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render assetAccountCheckList.';
|
$html = 'Could not render assetAccountCheckList.';
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CurrencyForm
|
* Class CurrencyForm
|
||||||
@ -90,7 +91,7 @@ class CurrencyForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render currencyField.';
|
$html = 'Could not render currencyField.';
|
||||||
|
|
||||||
@ -159,7 +160,7 @@ class CurrencyForm
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render currencyField.';
|
$html = 'Could not render currencyField.';
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ use Carbon\Carbon;
|
|||||||
use Carbon\Exceptions\InvalidDateException;
|
use Carbon\Exceptions\InvalidDateException;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait FormSupport
|
* Trait FormSupport
|
||||||
@ -46,7 +47,7 @@ trait FormSupport
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view('form.multi-select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
$html = view('form.multi-select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Could not render multi-select(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Could not render multi-select(): %s', $e->getMessage()));
|
||||||
$html = 'Could not render multi-select.';
|
$html = 'Could not render multi-select.';
|
||||||
}
|
}
|
||||||
@ -54,28 +55,6 @@ trait FormSupport
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $selected
|
|
||||||
*/
|
|
||||||
public function select(string $name, ?array $list = null, $selected = null, ?array $options = null): string
|
|
||||||
{
|
|
||||||
$list ??= [];
|
|
||||||
$label = $this->label($name, $options);
|
|
||||||
$options = $this->expandOptionArray($name, $label, $options);
|
|
||||||
$classes = $this->getHolderClasses($name);
|
|
||||||
$selected = $this->fillFieldValue($name, $selected);
|
|
||||||
unset($options['autocomplete'], $options['placeholder']);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
|
|
||||||
$html = 'Could not render select.';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function label(string $name, ?array $options = null): string
|
protected function label(string $name, ?array $options = null): string
|
||||||
{
|
{
|
||||||
$options ??= [];
|
$options ??= [];
|
||||||
@ -139,6 +118,28 @@ trait FormSupport
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $selected
|
||||||
|
*/
|
||||||
|
public function select(string $name, ?array $list = null, $selected = null, ?array $options = null): string
|
||||||
|
{
|
||||||
|
$list ??= [];
|
||||||
|
$label = $this->label($name, $options);
|
||||||
|
$options = $this->expandOptionArray($name, $label, $options);
|
||||||
|
$classes = $this->getHolderClasses($name);
|
||||||
|
$selected = $this->fillFieldValue($name, $selected);
|
||||||
|
unset($options['autocomplete'], $options['placeholder']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
|
||||||
|
$html = 'Could not render select.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getAccountRepository(): AccountRepositoryInterface
|
protected function getAccountRepository(): AccountRepositoryInterface
|
||||||
{
|
{
|
||||||
return app(AccountRepositoryInterface::class);
|
return app(AccountRepositoryInterface::class);
|
||||||
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Http\Api;
|
namespace FireflyIII\Support\Http\Api;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DateTimeInterface;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +67,7 @@ trait ConvertsExchangeRates
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
foreach ($set['entries'] as $date => $entry) {
|
foreach ($set['entries'] as $date => $entry) {
|
||||||
$carbon = Carbon::createFromFormat(\DateTimeInterface::ATOM, $date);
|
$carbon = Carbon::createFromFormat(DateTimeInterface::ATOM, $date);
|
||||||
$rate = $this->getRate($currency, $native, $carbon);
|
$rate = $this->getRate($currency, $native, $carbon);
|
||||||
$rate = '0' === $rate ? '1' : $rate;
|
$rate = '0' === $rate ? '1' : $rate;
|
||||||
app('log')->debug(sprintf('bcmul("%s", "%s")', (string) $entry, $rate));
|
app('log')->debug(sprintf('bcmul("%s", "%s")', (string) $entry, $rate));
|
||||||
|
@ -172,8 +172,7 @@ class ExchangeRateConverter
|
|||||||
->where('to_currency_id', $to)
|
->where('to_currency_id', $to)
|
||||||
->where('date', '<=', $date)
|
->where('date', '<=', $date)
|
||||||
->orderBy('date', 'DESC')
|
->orderBy('date', 'DESC')
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
++$this->queryCount;
|
++$this->queryCount;
|
||||||
$rate = (string) $result?->rate;
|
$rate = (string) $result?->rate;
|
||||||
|
|
||||||
@ -278,8 +277,7 @@ class ExchangeRateConverter
|
|||||||
->where('to_currency_id', $to->id)
|
->where('to_currency_id', $to->id)
|
||||||
->where('date', '<=', $end->format('Y-m-d'))
|
->where('date', '<=', $end->format('Y-m-d'))
|
||||||
->where('date', '>=', $start->format('Y-m-d'))
|
->where('date', '>=', $start->format('Y-m-d'))
|
||||||
->orderBy('date', 'DESC')->get()
|
->orderBy('date', 'DESC')->get();
|
||||||
;
|
|
||||||
++$this->queryCount;
|
++$this->queryCount;
|
||||||
if (0 === $set->count()) {
|
if (0 === $set->count()) {
|
||||||
Log::debug('No prepared rates found in this period, use the fallback');
|
Log::debug('No prepared rates found in this period, use the fallback');
|
||||||
|
@ -38,7 +38,7 @@ trait BasicDataSupport
|
|||||||
*/
|
*/
|
||||||
protected function isInArray(array $array, int $entryId)
|
protected function isInArray(array $array, int $entryId)
|
||||||
{
|
{
|
||||||
return $array[$entryId] ?? '0';
|
return $array[$entryId]['balance'] ?? '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +46,6 @@ trait BasicDataSupport
|
|||||||
*/
|
*/
|
||||||
protected function isInArrayDate(array $array, int $entryId): ?Carbon
|
protected function isInArrayDate(array $array, int $entryId): ?Carbon
|
||||||
{
|
{
|
||||||
return $array[$entryId] ?? null;
|
return $array[$entryId]['balance'] ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,7 +86,7 @@ trait ChartGeneration
|
|||||||
];
|
];
|
||||||
|
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $start;
|
||||||
$range = $convertToNative ? app('steam')->balanceInRangeNative($account, $start, clone $end) : app('steam')->balanceInRange($account, $start, clone $end);
|
$range = Steam::finalAccountBalanceInRange($account, $start, clone $end);
|
||||||
$previous = array_values($range)[0];
|
$previous = array_values($range)[0];
|
||||||
while ($currentStart <= $end) {
|
while ($currentStart <= $end) {
|
||||||
$format = $currentStart->format('Y-m-d');
|
$format = $currentStart->format('Y-m-d');
|
||||||
@ -93,7 +94,7 @@ trait ChartGeneration
|
|||||||
$balance = $range[$format] ?? $previous;
|
$balance = $range[$format] ?? $previous;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
$currentSet['entries'][$label] = $balance;
|
$currentSet['entries'][$label] = $balance['balance']; // TODO or native_balance
|
||||||
}
|
}
|
||||||
$chartData[] = $currentSet;
|
$chartData[] = $currentSet;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ use FireflyIII\Models\Tag;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait ModelInformation
|
* Trait ModelInformation
|
||||||
@ -55,7 +56,7 @@ trait ModelInformation
|
|||||||
'count' => 1,
|
'count' => 1,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Throwable was thrown in getActionsForBill(): %s', $e->getMessage()));
|
app('log')->error(sprintf('Throwable was thrown in getActionsForBill(): %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
$result = 'Could not render view. See log files.';
|
$result = 'Could not render view. See log files.';
|
||||||
@ -142,7 +143,7 @@ trait ModelInformation
|
|||||||
'triggers' => $triggers,
|
'triggers' => $triggers,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
|
||||||
app('log')->debug($e->getTraceAsString());
|
app('log')->debug($e->getTraceAsString());
|
||||||
|
|
||||||
@ -258,7 +259,7 @@ trait ModelInformation
|
|||||||
'triggers' => $triggers,
|
'triggers' => $triggers,
|
||||||
];
|
];
|
||||||
$string = view('rules.partials.trigger', $renderInfo)->render();
|
$string = view('rules.partials.trigger', $renderInfo)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Throwable was thrown in getTriggersForJournal(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Throwable was thrown in getTriggersForJournal(): %s', $e->getMessage()));
|
||||||
app('log')->debug($e->getTraceAsString());
|
app('log')->debug($e->getTraceAsString());
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait RenderPartialViews
|
* Trait RenderPartialViews
|
||||||
@ -68,7 +69,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
|
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$result = view('reports.options.budget', compact('budgets'))->render();
|
$result = view('reports.options.budget', compact('budgets'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
|
|
||||||
@ -123,7 +124,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
|
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
|
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$result = view('reports.options.category', compact('categories'))->render();
|
$result = view('reports.options.category', compact('categories'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Cannot render reports.options.category: %s', $e->getMessage()));
|
app('log')->error(sprintf('Cannot render reports.options.category: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
|
|
||||||
@ -215,7 +216,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$result = view('reports.options.double', compact('set'))->render();
|
$result = view('reports.options.double', compact('set'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
|
|
||||||
@ -248,7 +249,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
|
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||||
|
|
||||||
@ -284,7 +285,7 @@ trait RenderPartialViews
|
|||||||
'count' => $count,
|
'count' => $count,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
|
|
||||||
@ -339,7 +340,7 @@ trait RenderPartialViews
|
|||||||
'triggers' => $triggers,
|
'triggers' => $triggers,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
|
|
||||||
@ -375,7 +376,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
|
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
|
||||||
$view = 'Firefly III could not render the view. Please see the log files.';
|
$view = 'Firefly III could not render the view. Please see the log files.';
|
||||||
|
|
||||||
@ -394,7 +395,7 @@ trait RenderPartialViews
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = view('reports.options.no-options')->render();
|
$result = view('reports.options.no-options')->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage()));
|
app('log')->error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
|
|
||||||
@ -417,7 +418,7 @@ trait RenderPartialViews
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$result = view('reports.options.tag', compact('tags'))->render();
|
$result = view('reports.options.tag', compact('tags'))->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ use FireflyIII\Http\Requests\RuleFormRequest;
|
|||||||
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
||||||
use FireflyIII\Support\Binder\AccountList;
|
use FireflyIII\Support\Binder\AccountList;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Hash;
|
||||||
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
|
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
@ -169,7 +170,7 @@ trait RequestInformation
|
|||||||
*/
|
*/
|
||||||
final protected function validatePassword(User $user, string $current, string $new): bool // get request info
|
final protected function validatePassword(User $user, string $current, string $new): bool // get request info
|
||||||
{
|
{
|
||||||
if (!\Hash::check($current, $user->password)) {
|
if (!Hash::check($current, $user->password)) {
|
||||||
throw new ValidationException((string) trans('firefly.invalid_current_password'));
|
throw new ValidationException((string) trans('firefly.invalid_current_password'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait RuleManagement
|
* Trait RuleManagement
|
||||||
@ -54,7 +55,7 @@ trait RuleManagement
|
|||||||
'count' => $index + 1,
|
'count' => $index + 1,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->error(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
|
app('log')->error(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ trait RuleManagement
|
|||||||
'triggers' => $triggers,
|
'triggers' => $triggers,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ trait RuleManagement
|
|||||||
'triggers' => $triggers,
|
'triggers' => $triggers,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
|
|
||||||
|
@ -46,8 +46,7 @@ trait TransactionCalculation
|
|||||||
$collector->setAccounts($total)
|
$collector->setAccounts($total)
|
||||||
->setRange($start, $end)
|
->setRange($start, $end)
|
||||||
->withAccountInformation()
|
->withAccountInformation()
|
||||||
->setTypes([TransactionType::WITHDRAWAL])
|
->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
;
|
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
@ -61,8 +60,7 @@ trait TransactionCalculation
|
|||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setTags($tags)->withAccountInformation()
|
->setTags($tags)->withAccountInformation();
|
||||||
;
|
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
@ -75,8 +73,7 @@ trait TransactionCalculation
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setBudgets($budgets)->withAccountInformation()
|
->setBudgets($budgets)->withAccountInformation();
|
||||||
;
|
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
@ -93,8 +90,7 @@ trait TransactionCalculation
|
|||||||
->setRange($start, $end)
|
->setRange($start, $end)
|
||||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setCategories($categories)
|
->setCategories($categories)
|
||||||
->withAccountInformation()
|
->withAccountInformation();
|
||||||
;
|
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
@ -107,8 +103,7 @@ trait TransactionCalculation
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setCategories($categories)->withAccountInformation()
|
->setCategories($categories)->withAccountInformation();
|
||||||
;
|
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
@ -135,8 +130,7 @@ trait TransactionCalculation
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setTags($tags)->withAccountInformation()
|
->setTags($tags)->withAccountInformation();
|
||||||
;
|
|
||||||
|
|
||||||
return $collector->getExtractedJournals();
|
return $collector->getExtractedJournals();
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\JsonApi\Enrichments;
|
namespace FireflyIII\Support\JsonApi\Enrichments;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\ObjectGroup;
|
use FireflyIII\Models\ObjectGroup;
|
||||||
@ -36,6 +37,8 @@ use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Override;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountEnrichment
|
* Class AccountEnrichment
|
||||||
@ -63,7 +66,7 @@ class AccountEnrichment implements EnrichmentInterface
|
|||||||
$this->end = null;
|
$this->end = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\Override]
|
#[Override]
|
||||||
public function enrichSingle(Model $model): Account
|
public function enrichSingle(Model $model): Account
|
||||||
{
|
{
|
||||||
Log::debug(__METHOD__);
|
Log::debug(__METHOD__);
|
||||||
@ -73,7 +76,7 @@ class AccountEnrichment implements EnrichmentInterface
|
|||||||
return $collection->first();
|
return $collection->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\Override]
|
#[Override]
|
||||||
/**
|
/**
|
||||||
* Do the actual enrichment.
|
* Do the actual enrichment.
|
||||||
*/
|
*/
|
||||||
@ -239,12 +242,11 @@ class AccountEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
private function getObjectGroups(): void
|
private function getObjectGroups(): void
|
||||||
{
|
{
|
||||||
$set = \DB::table('object_groupables')
|
$set = DB::table('object_groupables')
|
||||||
->where('object_groupable_type', Account::class)
|
->where('object_groupable_type', Account::class)
|
||||||
->whereIn('object_groupable_id', $this->collection->pluck('id')->toArray())
|
->whereIn('object_groupable_id', $this->collection->pluck('id')->toArray())
|
||||||
->distinct()
|
->distinct()
|
||||||
->get(['object_groupables.object_groupable_id', 'object_groupables.object_group_id'])
|
->get(['object_groupables.object_groupable_id', 'object_groupables.object_group_id']);
|
||||||
;
|
|
||||||
// get the groups:
|
// get the groups:
|
||||||
$groupIds = $set->pluck('object_group_id')->toArray();
|
$groupIds = $set->pluck('object_group_id')->toArray();
|
||||||
$groups = ObjectGroup::whereIn('id', $groupIds)->get();
|
$groups = ObjectGroup::whereIn('id', $groupIds)->get();
|
||||||
@ -254,7 +256,7 @@ class AccountEnrichment implements EnrichmentInterface
|
|||||||
$this->objectGroups[$group->id] = $group;
|
$this->objectGroups[$group->id] = $group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \stdClass $entry */
|
/** @var stdClass $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$this->grouped[(int) $entry->object_groupable_id] = (int) $entry->object_group_id;
|
$this->grouped[(int) $entry->object_groupable_id] = (int) $entry->object_group_id;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,7 @@ class AccountBalanceCalculator
|
|||||||
->orderBy('transaction_journals.order', 'desc')
|
->orderBy('transaction_journals.order', 'desc')
|
||||||
->orderBy('transaction_journals.id', 'asc')
|
->orderBy('transaction_journals.id', 'asc')
|
||||||
->orderBy('transaction_journals.description', 'asc')
|
->orderBy('transaction_journals.description', 'asc')
|
||||||
->orderBy('transactions.amount', 'asc')
|
->orderBy('transactions.amount', 'asc');
|
||||||
;
|
|
||||||
if ($accounts->count() > 0) {
|
if ($accounts->count() > 0) {
|
||||||
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
|
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
|
||||||
}
|
}
|
||||||
@ -137,8 +136,7 @@ class AccountBalanceCalculator
|
|||||||
->orderBy('transaction_journals.id', 'DESC')
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
->orderBy('transaction_journals.description', 'DESC')
|
->orderBy('transaction_journals.description', 'DESC')
|
||||||
->orderBy('transactions.amount', 'DESC')
|
->orderBy('transactions.amount', 'DESC')
|
||||||
->where('transactions.account_id', $accountId)
|
->where('transactions.account_id', $accountId);
|
||||||
;
|
|
||||||
$notBefore->startOfDay();
|
$notBefore->startOfDay();
|
||||||
$query->where('transaction_journals.date', '<', $notBefore);
|
$query->where('transaction_journals.date', '<', $notBefore);
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
|||||||
use FireflyIII\Support\Calendar\Calculator;
|
use FireflyIII\Support\Calendar\Calculator;
|
||||||
use FireflyIII\Support\Calendar\Periodicity;
|
use FireflyIII\Support\Calendar\Periodicity;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Navigation.
|
* Class Navigation.
|
||||||
@ -93,7 +94,7 @@ class Navigation
|
|||||||
return $this->calculator->nextDateByInterval($epoch, $periodicity, $skipInterval);
|
return $this->calculator->nextDateByInterval($epoch, $periodicity, $skipInterval);
|
||||||
} catch (IntervalException $exception) {
|
} catch (IntervalException $exception) {
|
||||||
Log::warning($exception->getMessage(), ['exception' => $exception]);
|
Log::warning($exception->getMessage(), ['exception' => $exception]);
|
||||||
} catch (\Throwable $exception) { // @phpstan-ignore-line
|
} catch (Throwable $exception) { // @phpstan-ignore-line
|
||||||
Log::error($exception->getMessage(), ['exception' => $exception]);
|
Log::error($exception->getMessage(), ['exception' => $exception]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
|
use ArrayObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class NullArrayObject
|
* Class NullArrayObject
|
||||||
*/
|
*/
|
||||||
class NullArrayObject extends \ArrayObject
|
class NullArrayObject extends ArrayObject
|
||||||
{
|
{
|
||||||
/** @var null|mixed */
|
/** @var null|mixed */
|
||||||
public $default;
|
public $default;
|
||||||
|
@ -52,8 +52,7 @@ class Preferences
|
|||||||
$q->whereNull('user_group_id');
|
$q->whereNull('user_group_id');
|
||||||
$q->orWhere('user_group_id', $user->user_group_id);
|
$q->orWhere('user_group_id', $user->user_group_id);
|
||||||
})
|
})
|
||||||
->get()
|
->get();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(string $name, null | array | bool | int | string $default = null): ?Preference
|
public function get(string $name, null | array | bool | int | string $default = null): ?Preference
|
||||||
@ -179,8 +178,7 @@ class Preferences
|
|||||||
$q->orWhere('user_group_id', $user->user_group_id);
|
$q->orWhere('user_group_id', $user->user_group_id);
|
||||||
})
|
})
|
||||||
->whereIn('name', $list)
|
->whereIn('name', $list)
|
||||||
->get(['id', 'name', 'data'])
|
->get(['id', 'name', 'data']);
|
||||||
;
|
|
||||||
|
|
||||||
/** @var Preference $preference */
|
/** @var Preference $preference */
|
||||||
foreach ($preferences as $preference) {
|
foreach ($preferences as $preference) {
|
||||||
@ -277,19 +275,6 @@ class Preferences
|
|||||||
Session::forget('first');
|
Session::forget('first');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEncrypted(string $name, mixed $value): Preference
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$encrypted = encrypt($value);
|
|
||||||
} catch (EncryptException $e) {
|
|
||||||
Log::error(sprintf('Could not encrypt preference "%s": %s', $name, $e->getMessage()));
|
|
||||||
|
|
||||||
throw new FireflyException(sprintf('Could not encrypt preference "%s". Cowardly refuse to continue.', $name));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->set($name, $encrypted);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set(string $name, null | array | bool | int | string $value): Preference
|
public function set(string $name, null | array | bool | int | string $value): Preference
|
||||||
{
|
{
|
||||||
/** @var null|User $user */
|
/** @var null|User $user */
|
||||||
@ -305,4 +290,17 @@ class Preferences
|
|||||||
|
|
||||||
return $this->setForUser($user, $name, $value);
|
return $this->setForUser($user, $name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setEncrypted(string $name, mixed $value): Preference
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$encrypted = encrypt($value);
|
||||||
|
} catch (EncryptException $e) {
|
||||||
|
Log::error(sprintf('Could not encrypt preference "%s": %s', $name, $e->getMessage()));
|
||||||
|
|
||||||
|
throw new FireflyException(sprintf('Could not encrypt preference "%s". Cowardly refuse to continue.', $name));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->set($name, $encrypted);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,7 @@ trait UserGroupTrait
|
|||||||
{
|
{
|
||||||
$memberships = GroupMembership::where('user_id', $this->user->id)
|
$memberships = GroupMembership::where('user_id', $this->user->id)
|
||||||
->where('user_group_id', $userGroupId)
|
->where('user_group_id', $userGroupId)
|
||||||
->count()
|
->count();
|
||||||
;
|
|
||||||
if (0 === $memberships) {
|
if (0 === $memberships) {
|
||||||
throw new FireflyException(sprintf('User #%d has no access to administration #%d', $this->user->id, $userGroupId));
|
throw new FireflyException(sprintf('User #%d has no access to administration #%d', $this->user->id, $userGroupId));
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,6 @@ namespace FireflyIII\Support\Request;
|
|||||||
/**
|
/**
|
||||||
* Trait ConvertAPIDataTypes
|
* Trait ConvertAPIDataTypes
|
||||||
*/
|
*/
|
||||||
trait ConvertAPIDataTypes {}
|
trait ConvertAPIDataTypes
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -96,24 +96,6 @@ trait ConvertsDataTypes
|
|||||||
return Steam::filterSpaces($string);
|
return Steam::filterSpaces($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convertIban(string $field): string
|
|
||||||
{
|
|
||||||
return Steam::filterSpaces($this->convertString($field));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return string value.
|
|
||||||
*/
|
|
||||||
public function convertString(string $field, string $default = ''): string
|
|
||||||
{
|
|
||||||
$entry = $this->get($field);
|
|
||||||
if (!is_scalar($entry)) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (string) $this->clearString((string) $entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clearString(?string $string): ?string
|
public function clearString(?string $string): ?string
|
||||||
{
|
{
|
||||||
$string = $this->clearStringKeepNewlines($string);
|
$string = $this->clearStringKeepNewlines($string);
|
||||||
@ -147,12 +129,22 @@ trait ConvertsDataTypes
|
|||||||
return trim((string) $string);
|
return trim((string) $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function convertIban(string $field): string
|
||||||
* Return integer value.
|
|
||||||
*/
|
|
||||||
public function convertInteger(string $field): int
|
|
||||||
{
|
{
|
||||||
return (int) $this->get($field);
|
return Steam::filterSpaces($this->convertString($field));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return string value.
|
||||||
|
*/
|
||||||
|
public function convertString(string $field, string $default = ''): string
|
||||||
|
{
|
||||||
|
$entry = $this->get($field);
|
||||||
|
if (!is_scalar($entry)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $this->clearString((string) $entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,6 +153,14 @@ trait ConvertsDataTypes
|
|||||||
*/
|
*/
|
||||||
abstract public function get(string $key, mixed $default = null): mixed;
|
abstract public function get(string $key, mixed $default = null): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return integer value.
|
||||||
|
*/
|
||||||
|
public function convertInteger(string $field): int
|
||||||
|
{
|
||||||
|
return (int) $this->get($field);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO duplicate, see SelectTransactionsRequest
|
* TODO duplicate, see SelectTransactionsRequest
|
||||||
*
|
*
|
||||||
|
@ -63,8 +63,7 @@ class AccountSearch implements GenericSearchInterface
|
|||||||
$searchQuery = $this->user->accounts()
|
$searchQuery = $this->user->accounts()
|
||||||
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
||||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||||
->whereIn('account_types.type', $this->types)
|
->whereIn('account_types.type', $this->types);
|
||||||
;
|
|
||||||
$like = sprintf('%%%s%%', $this->query);
|
$like = sprintf('%%%s%%', $this->query);
|
||||||
$originalQuery = $this->query;
|
$originalQuery = $this->query;
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ use Gdbots\QueryParser\Node\Word;
|
|||||||
use Gdbots\QueryParser\QueryParser;
|
use Gdbots\QueryParser\QueryParser;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use LogicException;
|
||||||
|
use TypeError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OperatorQuerySearch
|
* Class OperatorQuerySearch
|
||||||
@ -149,7 +151,7 @@ class OperatorQuerySearch implements SearchInterface
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$query1 = $parser->parse($query);
|
$query1 = $parser->parse($query);
|
||||||
} catch (\LogicException|\TypeError $e) {
|
} catch (LogicException | TypeError $e) {
|
||||||
app('log')->error($e->getMessage());
|
app('log')->error($e->getMessage());
|
||||||
app('log')->error(sprintf('Could not parse search: "%s".', $query));
|
app('log')->error(sprintf('Could not parse search: "%s".', $query));
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Carbon\Exceptions\InvalidFormatException;
|
|
||||||
use DB;
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
@ -32,7 +31,6 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
@ -44,468 +42,72 @@ use ValueError;
|
|||||||
*/
|
*/
|
||||||
class Steam
|
class Steam
|
||||||
{
|
{
|
||||||
/**
|
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||||
* @throws FireflyException
|
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function balanceInRangeConverted(Account $account, Carbon $start, Carbon $end, TransactionCurrency $native): array
|
|
||||||
{
|
{
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
$type = $account->accountType->type;
|
||||||
|
$list = config('firefly.valid_currency_account_types');
|
||||||
|
|
||||||
|
// return null if not in this list.
|
||||||
|
if (!in_array($type, $list, true)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$result = $account->accountMeta->where('name', 'currency_id')->first();
|
||||||
|
if (null === $result) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return TransactionCurrency::find((int) $result->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sumTransactions(array $transactions, string $key): string
|
||||||
|
{
|
||||||
|
$sum = '0';
|
||||||
|
|
||||||
|
/** @var array $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$value = (string) ($transaction[$key] ?? '0');
|
||||||
|
$value = '' === $value ? '0' : $value;
|
||||||
|
$sum = bcadd($sum, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function finalAccountBalanceInRange(Account $account, Carbon $start, Carbon $end): array
|
||||||
|
{
|
||||||
|
// expand period.
|
||||||
|
$start->subDay()->startOfDay();
|
||||||
|
$end->addDay()->endOfDay();
|
||||||
|
|
||||||
|
// set up cache
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
$cache->addProperty('balance-in-range-converted');
|
$cache->addProperty('final-balance-in-range');
|
||||||
$cache->addProperty($native->id);
|
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return $cache->get();
|
// return $cache->get();
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('balanceInRangeConverted for account #%d to %s', $account->id, $native->code));
|
|
||||||
$start->subDay();
|
|
||||||
$end->addDay();
|
|
||||||
$balances = [];
|
$balances = [];
|
||||||
$formatted = $start->format('Y-m-d');
|
$formatted = $start->format('Y-m-d');
|
||||||
$currencies = [];
|
$startBalance = $this->finalAccountBalance($account, $start);
|
||||||
$startBalance = $this->balanceConverted($account, $start, $native); // already converted to native amount
|
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||||
|
$currency = $this->getAccountCurrency($account) ?? $defaultCurrency;
|
||||||
|
$currencies = [
|
||||||
|
$currency->id => $currency,
|
||||||
|
$defaultCurrency->id => $defaultCurrency,
|
||||||
|
];
|
||||||
|
$startBalance[$defaultCurrency->code] ??= '0';
|
||||||
|
$startBalance[$currency->code] ??= '0';
|
||||||
$balances[$formatted] = $startBalance;
|
$balances[$formatted] = $startBalance;
|
||||||
|
|
||||||
Log::debug(sprintf('Start balance on %s is %s', $formatted, $startBalance));
|
|
||||||
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
|
|
||||||
$converter = new ExchangeRateConverter();
|
|
||||||
|
|
||||||
// not sure why this is happening:
|
// sums up the balance changes per day, for foreign, native and normal amounts.
|
||||||
$start->addDay();
|
|
||||||
|
|
||||||
// grab all transactions between start and end:
|
|
||||||
$set = $account->transactions()
|
$set = $account->transactions()
|
||||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s'))
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d H:i:s'))
|
||||||
->orderBy('transaction_journals.date', 'ASC')
|
|
||||||
->whereNull('transaction_journals.deleted_at')
|
|
||||||
->get(
|
|
||||||
[
|
|
||||||
'transaction_journals.date',
|
|
||||||
'transactions.transaction_currency_id',
|
|
||||||
'transactions.amount',
|
|
||||||
'transactions.foreign_currency_id',
|
|
||||||
'transactions.foreign_amount',
|
|
||||||
]
|
|
||||||
)->toArray();
|
|
||||||
|
|
||||||
// loop the set and convert if necessary:
|
|
||||||
$currentBalance = $startBalance;
|
|
||||||
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
$day = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$day = Carbon::parse($transaction['date'], config('app.timezone'));
|
|
||||||
} catch (InvalidFormatException $e) {
|
|
||||||
Log::error(sprintf('Could not parse date "%s" in %s: %s', $transaction['date'], __METHOD__, $e->getMessage()));
|
|
||||||
}
|
|
||||||
if (false === $day) {
|
|
||||||
$day = today(config('app.timezone'));
|
|
||||||
}
|
|
||||||
$format = $day->format('Y-m-d');
|
|
||||||
// if the transaction is in the expected currency, change nothing.
|
|
||||||
if ((int) $transaction['transaction_currency_id'] === $native->id) {
|
|
||||||
// change the current balance, set it to today, continue the loop.
|
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['amount']);
|
|
||||||
$balances[$format] = $currentBalance;
|
|
||||||
Log::debug(sprintf('%s: transaction in %s, new balance is %s.', $format, $native->code, $currentBalance));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if foreign currency is in the expected currency, do nothing:
|
|
||||||
if ((int) $transaction['foreign_currency_id'] === $native->id) {
|
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['foreign_amount']);
|
|
||||||
$balances[$format] = $currentBalance;
|
|
||||||
Log::debug(sprintf('%s: transaction in %s (foreign), new balance is %s.', $format, $native->code, $currentBalance));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// otherwise, convert 'amount' to the necessary currency:
|
|
||||||
$currencyId = (int) $transaction['transaction_currency_id'];
|
|
||||||
$currency = $currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
|
||||||
$currencies[$currencyId] = $currency;
|
|
||||||
|
|
||||||
$rate = $converter->getCurrencyRate($currency, $native, $day);
|
|
||||||
$convertedAmount = bcmul($transaction['amount'], $rate);
|
|
||||||
$currentBalance = bcadd($currentBalance, $convertedAmount);
|
|
||||||
$balances[$format] = $currentBalance;
|
|
||||||
|
|
||||||
Log::debug(sprintf(
|
|
||||||
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
|
|
||||||
$format,
|
|
||||||
$currency->code,
|
|
||||||
$rate,
|
|
||||||
$currency->code,
|
|
||||||
$transaction['amount'],
|
|
||||||
$native->code,
|
|
||||||
$convertedAmount
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$cache->store($balances);
|
|
||||||
$converter->summarize();
|
|
||||||
|
|
||||||
return $balances;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws FireflyException
|
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
* @deprecated
|
|
||||||
* selection of transactions
|
|
||||||
* 1: all normal transactions. No foreign currency info. In $currency. Need conversion.
|
|
||||||
* 2: all normal transactions. No foreign currency info. In $native. Need NO conversion.
|
|
||||||
* 3: all normal transactions. No foreign currency info. In neither currency. Need conversion.
|
|
||||||
* Then, select everything with foreign currency info:
|
|
||||||
* 4. All transactions with foreign currency info in $native. Normal currency value is ignored. Do not need
|
|
||||||
* conversion.
|
|
||||||
* 5. All transactions with foreign currency info NOT in $native, but currency info in $currency. Need conversion.
|
|
||||||
* 6. All transactions with foreign currency info NOT in $native, and currency info NOT in $currency. Need
|
|
||||||
* conversion.
|
|
||||||
*
|
|
||||||
* Gets balance at the end of current month by default. Returns the balance converted
|
|
||||||
* to the indicated currency ($native).
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function balanceConverted(Account $account, Carbon $date, TransactionCurrency $native): string
|
|
||||||
{
|
|
||||||
Log::debug(sprintf('Now in balanceConverted (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code));
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($account->id);
|
|
||||||
$cache->addProperty('balance-converted');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
$cache->addProperty($native->id);
|
|
||||||
if ($cache->has()) {
|
|
||||||
Log::debug('Cached!');
|
|
||||||
// return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$currency = $repository->getAccountCurrency($account);
|
|
||||||
$currency = null === $currency ? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup) : $currency;
|
|
||||||
if ($native->id === $currency->id) {
|
|
||||||
Log::debug('No conversion necessary!');
|
|
||||||
|
|
||||||
return $this->balance($account, $date);
|
|
||||||
}
|
|
||||||
|
|
||||||
$new = [];
|
|
||||||
$existing = [];
|
|
||||||
$new[] = $account->transactions() // 1
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.transaction_currency_id', $currency->id)
|
|
||||||
->whereNull('transactions.foreign_currency_id')
|
|
||||||
->get(['transaction_journals.date', 'transactions.amount'])->toArray();
|
|
||||||
Log::debug(sprintf('%d transaction(s) in set #1', count($new[0])));
|
|
||||||
$existing[] = $account->transactions() // 2
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.transaction_currency_id', $native->id)
|
|
||||||
->whereNull('transactions.foreign_currency_id')
|
|
||||||
->get(['transactions.amount'])->toArray();
|
|
||||||
Log::debug(sprintf('%d transaction(s) in set #2', count($existing[0])));
|
|
||||||
$new[] = $account->transactions() // 3
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.transaction_currency_id', '!=', $currency->id)
|
|
||||||
->where('transactions.transaction_currency_id', '!=', $native->id)
|
|
||||||
->whereNull('transactions.foreign_currency_id')
|
|
||||||
->get(['transaction_journals.date', 'transactions.amount'])->toArray();
|
|
||||||
Log::debug(sprintf('%d transactions in set #3', count($new[1])));
|
|
||||||
$existing[] = $account->transactions() // 4
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.foreign_currency_id', $native->id)
|
|
||||||
->whereNotNull('transactions.foreign_amount')
|
|
||||||
->get(['transactions.foreign_amount'])->toArray();
|
|
||||||
Log::debug(sprintf('%d transactions in set #4', count($existing[1])));
|
|
||||||
$new[] = $account->transactions()// 5
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.transaction_currency_id', $currency->id)
|
|
||||||
->where('transactions.foreign_currency_id', '!=', $native->id)
|
|
||||||
->whereNotNull('transactions.foreign_amount')
|
|
||||||
->get(['transaction_journals.date', 'transactions.amount'])->toArray();
|
|
||||||
Log::debug(sprintf('%d transactions in set #5', count($new[2])));
|
|
||||||
$new[] = $account->transactions()// 6
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.transaction_currency_id', '!=', $currency->id)
|
|
||||||
->where('transactions.foreign_currency_id', '!=', $native->id)
|
|
||||||
->whereNotNull('transactions.foreign_amount')
|
|
||||||
->get(['transaction_journals.date', 'transactions.amount'])->toArray();
|
|
||||||
Log::debug(sprintf('%d transactions in set #6', count($new[3])));
|
|
||||||
|
|
||||||
// process both sets of transactions. Of course, no need to convert set "existing".
|
|
||||||
$balance = $this->sumTransactions($existing[0], 'amount');
|
|
||||||
$balance = bcadd($balance, $this->sumTransactions($existing[1], 'foreign_amount'));
|
|
||||||
Log::debug(sprintf('Balance from set #2 and #4 is %f', $balance));
|
|
||||||
|
|
||||||
// need to convert the others. All sets use the "amount" value as their base (that's easy)
|
|
||||||
// but we need to convert each transaction separately because the date difference may
|
|
||||||
// incur huge currency changes.
|
|
||||||
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
|
|
||||||
$start = clone $date;
|
|
||||||
$end = clone $date;
|
|
||||||
$converter = new ExchangeRateConverter();
|
|
||||||
foreach ($new as $set) {
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
$currentDate = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$currentDate = Carbon::parse($transaction['date'], config('app.timezone'));
|
|
||||||
} catch (InvalidFormatException $e) {
|
|
||||||
Log::error(sprintf('Could not parse date "%s" in %s', $transaction['date'], __METHOD__));
|
|
||||||
}
|
|
||||||
if (false === $currentDate) {
|
|
||||||
$currentDate = today(config('app.timezone'));
|
|
||||||
}
|
|
||||||
if ($currentDate->lte($start)) {
|
|
||||||
$start = clone $currentDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($currentDate);
|
|
||||||
$converter->prepare($currency, $native, $start, $end);
|
|
||||||
|
|
||||||
foreach ($new as $set) {
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
$currentDate = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$currentDate = Carbon::parse($transaction['date'], config('app.timezone'));
|
|
||||||
} catch (InvalidFormatException $e) {
|
|
||||||
Log::error(sprintf('Could not parse date "%s" in %s', $transaction['date'], __METHOD__));
|
|
||||||
}
|
|
||||||
if (false === $currentDate) {
|
|
||||||
$currentDate = today(config('app.timezone'));
|
|
||||||
}
|
|
||||||
$rate = $converter->getCurrencyRate($currency, $native, $currentDate);
|
|
||||||
$convertedAmount = bcmul($transaction['amount'], $rate);
|
|
||||||
$balance = bcadd($balance, $convertedAmount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add virtual balance (also needs conversion)
|
|
||||||
$virtual = null === $account->virtual_balance ? '0' : $account->virtual_balance;
|
|
||||||
$virtual = $converter->convert($currency, $native, $account->created_at, $virtual);
|
|
||||||
$balance = bcadd($balance, $virtual);
|
|
||||||
$converter->summarize();
|
|
||||||
|
|
||||||
$cache->store($balance);
|
|
||||||
$converter->summarize();
|
|
||||||
|
|
||||||
return $balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets balance at the end of current month by default
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
private function balance(Account $account, Carbon $date, ?TransactionCurrency $currency = null): string
|
|
||||||
{
|
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
|
||||||
// abuse chart properties:
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($account->id);
|
|
||||||
$cache->addProperty('balance');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
$cache->addProperty(null !== $currency ? $currency->id : 0);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
if (null === $currency) {
|
|
||||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
|
||||||
}
|
|
||||||
// first part: get all balances in own currency:
|
|
||||||
$transactions = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.transaction_currency_id', $currency->id)
|
|
||||||
->get(['transactions.amount'])->toArray();
|
|
||||||
$nativeBalance = $this->sumTransactions($transactions, 'amount');
|
|
||||||
// get all balances in foreign currency:
|
|
||||||
$transactions = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.foreign_currency_id', $currency->id)
|
|
||||||
->where('transactions.transaction_currency_id', '!=', $currency->id)
|
|
||||||
->get(['transactions.foreign_amount'])->toArray();
|
|
||||||
$foreignBalance = $this->sumTransactions($transactions, 'foreign_amount');
|
|
||||||
$balance = bcadd($nativeBalance, $foreignBalance);
|
|
||||||
$virtual = null === $account->virtual_balance ? '0' : $account->virtual_balance;
|
|
||||||
$balance = bcadd($balance, $virtual);
|
|
||||||
|
|
||||||
$cache->store($balance);
|
|
||||||
|
|
||||||
return $balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
*/
|
|
||||||
public function balanceInRangeNative(Account $account, Carbon $start, Carbon $end): array
|
|
||||||
{
|
|
||||||
$native = app('amount')->getDefaultCurrency();
|
|
||||||
Log::debug(sprintf('balanceInRangeNative for account #%d, to %s', $account->id, $native->code));
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser($account->user);
|
|
||||||
$currency = $repository->getAccountCurrency($account) ?? $native;
|
|
||||||
if ($native->id === $currency->id) {
|
|
||||||
Log::debug('No need to get native balance, account prefers this currency.');
|
|
||||||
return $this->balanceInRange($account, $start, $end, $native);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($account->id);
|
|
||||||
$cache->addProperty('balance-in-range-native');
|
|
||||||
$cache->addProperty($native->id);
|
|
||||||
$cache->addProperty($start);
|
|
||||||
$cache->addProperty($end);
|
|
||||||
if ($cache->has()) {
|
|
||||||
$value = $cache->get();
|
|
||||||
Log::debug('Return cached values');
|
|
||||||
//return $value;
|
|
||||||
}
|
|
||||||
$start->subDay();
|
|
||||||
$end->addDay();
|
|
||||||
$balances = [];
|
|
||||||
$formatted = $start->format('Y-m-d');
|
|
||||||
$startBalance = $this->balanceNative($account, $start); // already converted to native amount
|
|
||||||
|
|
||||||
$balances[$formatted] = $startBalance;
|
|
||||||
|
|
||||||
Log::debug(sprintf('Start balance on %s is %s', $formatted, $startBalance));
|
|
||||||
|
|
||||||
// not sure why this is happening:
|
|
||||||
$start->addDay();
|
|
||||||
|
|
||||||
// grab all transactions between start and end:
|
|
||||||
$set = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
|
|
||||||
->orderBy('transaction_journals.date', 'ASC')
|
|
||||||
->whereNull('transaction_journals.deleted_at')
|
|
||||||
->get(
|
|
||||||
[
|
|
||||||
'transaction_journals.date',
|
|
||||||
'transactions.transaction_currency_id',
|
|
||||||
'transactions.amount',
|
|
||||||
'transactions.native_amount',
|
|
||||||
'transactions.foreign_currency_id',
|
|
||||||
'transactions.foreign_amount',
|
|
||||||
]
|
|
||||||
)->toArray();
|
|
||||||
|
|
||||||
// loop the set
|
|
||||||
$currentBalance = $startBalance;
|
|
||||||
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
$day = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$day = Carbon::parse($transaction['date'], config('app.timezone'));
|
|
||||||
} catch (InvalidFormatException $e) {
|
|
||||||
Log::error(sprintf('Could not parse date "%s" in %s: %s', $transaction['date'], __METHOD__, $e->getMessage()));
|
|
||||||
}
|
|
||||||
if (false === $day) {
|
|
||||||
$day = today(config('app.timezone'));
|
|
||||||
}
|
|
||||||
$format = $day->format('Y-m-d');
|
|
||||||
|
|
||||||
// first, check the native amount. If not NULL, add it, and continue.
|
|
||||||
if (null !== $transaction['native_amount']) {
|
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['native_amount']);
|
|
||||||
$balances[$format] = $currentBalance;
|
|
||||||
Log::debug(sprintf('%s: transaction in %s (native), new balance is %s.', $format, $native->code, $currentBalance));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the foreign amount is in the native currency, add it and continue.
|
|
||||||
if ((int) $transaction['foreign_currency_id'] === $native->id) {
|
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['foreign_amount']);
|
|
||||||
$balances[$format] = $currentBalance;
|
|
||||||
Log::debug(sprintf('%s: transaction in %s (foreign), new balance is %s.', $format, $native->code, $currentBalance));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// anything else is added as is. Warning in logs.
|
|
||||||
Log::warning(sprintf('Account "%s" (#%d) has transactions that are not converted in the native currency. Please run "php artisan firefly-iii:recalculate-native-amounts"', $account->name, $account->id));
|
|
||||||
$currentBalance = bcadd($currentBalance, $transaction['amount']);
|
|
||||||
$balances[$format] = $currentBalance;
|
|
||||||
Log::debug(sprintf('%s: transaction BAD currency, new balance is %s.', $format, $currentBalance));
|
|
||||||
}
|
|
||||||
|
|
||||||
$cache->store($balances);
|
|
||||||
|
|
||||||
return $balances;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the balance for the given account during the whole range, using this format:.
|
|
||||||
*
|
|
||||||
* [yyyy-mm-dd] => 123,2
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array
|
|
||||||
{
|
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($account->id);
|
|
||||||
$cache->addProperty('balance-in-range');
|
|
||||||
$cache->addProperty(null !== $currency ? $currency->id : 0);
|
|
||||||
$cache->addProperty($start);
|
|
||||||
$cache->addProperty($end);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
$start->subDay();
|
|
||||||
$end->addDay();
|
|
||||||
$balances = [];
|
|
||||||
$formatted = $start->format('Y-m-d');
|
|
||||||
$startBalance = $this->balance($account, $start, $currency);
|
|
||||||
|
|
||||||
$balances[$formatted] = $startBalance;
|
|
||||||
if (null === $currency) {
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser($account->user);
|
|
||||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
|
||||||
}
|
|
||||||
$currencyId = $currency->id;
|
|
||||||
|
|
||||||
$start->addDay();
|
|
||||||
|
|
||||||
// query!
|
|
||||||
$set = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
|
|
||||||
->groupBy('transaction_journals.date')
|
->groupBy('transaction_journals.date')
|
||||||
->groupBy('transactions.transaction_currency_id')
|
->groupBy('transactions.transaction_currency_id')
|
||||||
->groupBy('transactions.foreign_currency_id')
|
->groupBy('transactions.foreign_currency_id')
|
||||||
@ -518,6 +120,7 @@ class Steam
|
|||||||
DB::raw('SUM(transactions.amount) AS modified'),
|
DB::raw('SUM(transactions.amount) AS modified'),
|
||||||
'transactions.foreign_currency_id',
|
'transactions.foreign_currency_id',
|
||||||
DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
|
DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
|
||||||
|
DB::raw('SUM(transactions.native_amount) AS modified_native'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -525,235 +128,43 @@ class Steam
|
|||||||
|
|
||||||
/** @var Transaction $entry */
|
/** @var Transaction $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
// normal amount and foreign amount
|
|
||||||
|
// normal, native and foreign amount
|
||||||
|
$carbon = new Carbon($entry->date, $entry->date_tz);
|
||||||
$modified = (string) (null === $entry->modified ? '0' : $entry->modified);
|
$modified = (string) (null === $entry->modified ? '0' : $entry->modified);
|
||||||
$foreignModified = (string) (null === $entry->modified_foreign ? '0' : $entry->modified_foreign);
|
$foreignModified = (string) (null === $entry->modified_foreign ? '0' : $entry->modified_foreign);
|
||||||
$amount = '0';
|
$nativeModified = (string) (null === $entry->modified_native ? '0' : $entry->modified_native);
|
||||||
if ($currencyId === (int) $entry->transaction_currency_id || 0 === $currencyId) {
|
|
||||||
// use normal amount:
|
// add "modified" to amount if the currency id matches the account currency id.
|
||||||
$amount = $modified;
|
if ($entry->transaction_currency_id === $currency->id) {
|
||||||
}
|
$currentBalance['balance'] = bcadd($currentBalance['balance'], $modified);
|
||||||
if ($currencyId === (int) $entry->foreign_currency_id) {
|
$currentBalance[$currency->code] = bcadd($currentBalance[$currency->code], $modified);
|
||||||
// use foreign amount:
|
|
||||||
$amount = $foreignModified;
|
|
||||||
}
|
|
||||||
// Log::debug(sprintf('Trying to add %s and %s.', var_export($currentBalance, true), var_export($amount, true)));
|
|
||||||
$currentBalance = bcadd($currentBalance, $amount);
|
|
||||||
$carbon = new Carbon($entry->date, config('app.timezone'));
|
|
||||||
$date = $carbon->format('Y-m-d');
|
|
||||||
$balances[$date] = $currentBalance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// always add the native balance, even if it ends up at zero.
|
||||||
|
$currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeModified);
|
||||||
|
|
||||||
|
// add modified foreign to the array
|
||||||
|
if (null !== $entry->foreign_currency_id) {
|
||||||
|
$foreignId = $entry->foreign_currency_id;
|
||||||
|
$currencies[$foreignId] ??= TransactionCurrency::find($foreignId);
|
||||||
|
$foreignCurrency = $currencies[$foreignId];
|
||||||
|
$currentBalance[$foreignCurrency->code] ??= '0';
|
||||||
|
$currentBalance[$foreignCurrency->code] = bcadd($currentBalance[$foreignCurrency->code], $foreignModified);
|
||||||
|
}
|
||||||
|
$balances[$carbon->format('Y-m-d')] = $currentBalance;
|
||||||
|
}
|
||||||
$cache->store($balances);
|
$cache->store($balances);
|
||||||
|
|
||||||
return $balances;
|
return $balances;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function finalAccountsBalance(Collection $accounts, Carbon $date): array {
|
||||||
* Balance of an (asset) account in the user's native currency.
|
$balances = [];
|
||||||
* Is calculated by summing up three numbers.
|
|
||||||
*
|
|
||||||
* - Transactions in foreign amount that happen to be in the native currency.
|
|
||||||
* - The rest of the transactions in the native currency.
|
|
||||||
* - Where both are zero or NULL, the normal amount converted (and stored!)
|
|
||||||
*
|
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
private function balanceNative(Account $account, Carbon $date): string
|
|
||||||
{
|
|
||||||
$native = app('amount')->getDefaultCurrency();
|
|
||||||
Log::debug(sprintf('Now in balanceNative (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code));
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($account->id);
|
|
||||||
$cache->addProperty('balance-native');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
$cache->addProperty($native->id);
|
|
||||||
if ($cache->has()) {
|
|
||||||
$value = $cache->get();
|
|
||||||
Log::debug(sprintf('Return cached value %s', $value));
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$currency = $repository->getAccountCurrency($account);
|
|
||||||
$currency = null === $currency ? $native : $currency;
|
|
||||||
if ($native->id === $currency->id) {
|
|
||||||
Log::debug('No conversion necessary!');
|
|
||||||
|
|
||||||
return $this->balance($account, $date);
|
|
||||||
}
|
|
||||||
$balance = '0';
|
|
||||||
// transactions in foreign amount that happen to be in the native currency:
|
|
||||||
$set = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->where('transactions.foreign_currency_id', $native->id)
|
|
||||||
->get(['transactions.foreign_amount'])->toArray();
|
|
||||||
$balance = bcadd($this->sumTransactions($set, 'foreign_amount'), $balance);
|
|
||||||
Log::debug(sprintf('The balance is now %s', $balance));
|
|
||||||
|
|
||||||
// transactions in the native amount.
|
|
||||||
$set = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->whereNull('transactions.foreign_currency_id')
|
|
||||||
->whereNotNull('transactions.native_amount')
|
|
||||||
->get(['transactions.native_amount'])->toArray();
|
|
||||||
$balance = bcadd($this->sumTransactions($set, 'native_amount'), $balance);
|
|
||||||
Log::debug(sprintf('The balance is now %s', $balance));
|
|
||||||
|
|
||||||
// transactions in the normal amount with no native amount set.
|
|
||||||
$set = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->whereNull('transactions.foreign_currency_id')
|
|
||||||
->whereNull('transactions.native_amount')
|
|
||||||
->get(['transactions.amount'])->toArray();
|
|
||||||
$balance = bcadd($this->sumTransactions($set, 'amount'), $balance);
|
|
||||||
Log::debug(sprintf('The balance is now %s', $balance));
|
|
||||||
|
|
||||||
// add virtual balance (also needs conversion)
|
|
||||||
$virtualNative = null === $account->native_virtual_balance ? '0' : $account->native_virtual_balance;
|
|
||||||
$final = bcadd($virtualNative, $balance);
|
|
||||||
Log::debug(sprintf('Final balance is %s', $final));
|
|
||||||
$cache->store($final);
|
|
||||||
return $final;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method always ignores the virtual balance.
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function balancesByAccounts(Collection $accounts, Carbon $date): array
|
|
||||||
{
|
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
|
||||||
// cache this property.
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($ids);
|
|
||||||
$cache->addProperty('balances');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to do this per account.
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$result[$account->id] = $this->balance($account, $date);
|
$balances[$account->id] = $this->finalAccountBalance($account, $date);
|
||||||
}
|
}
|
||||||
|
return $balances;
|
||||||
$cache->store($result);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method always ignores the virtual balance.
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function balancesByAccountsConverted(Collection $accounts, Carbon $date): array
|
|
||||||
{
|
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
|
||||||
// cache this property.
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($ids);
|
|
||||||
$cache->addProperty('balances-converted');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to do this per account.
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$default = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
|
||||||
$result[$account->id]
|
|
||||||
= [
|
|
||||||
'balance' => $this->balance($account, $date),
|
|
||||||
'native_balance' => $this->balanceConverted($account, $date, $default),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$cache->store($result);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as above, but also groups per currency.
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date): array
|
|
||||||
{
|
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
|
||||||
// cache this property.
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($ids);
|
|
||||||
$cache->addProperty('balances-per-currency');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to do this per account.
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$result[$account->id] = $this->balancePerCurrency($account, $date);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cache->store($result);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Account $account
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
private function balancePerCurrency(Account $account, Carbon $date): array
|
|
||||||
{
|
|
||||||
// Log::warning(sprintf('Deprecated method %s, do not use.', __METHOD__));
|
|
||||||
// abuse chart properties:
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($account->id);
|
|
||||||
$cache->addProperty('balance-per-currency');
|
|
||||||
$cache->addProperty($date);
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
$query = $account->transactions()
|
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
|
||||||
->groupBy('transactions.transaction_currency_id');
|
|
||||||
$balances = $query->get(['transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) as sum_for_currency')]); // @phpstan-ignore-line
|
|
||||||
$return = [];
|
|
||||||
|
|
||||||
/** @var stdClass $entry */
|
|
||||||
foreach ($balances as $entry) {
|
|
||||||
$return[(int) $entry->transaction_currency_id] = (string) $entry->sum_for_currency;
|
|
||||||
}
|
|
||||||
$cache->store($return);
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -899,36 +310,6 @@ class Steam
|
|||||||
return array_merge($return, $others);
|
return array_merge($return, $others);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
|
||||||
{
|
|
||||||
$type = $account->accountType->type;
|
|
||||||
$list = config('firefly.valid_currency_account_types');
|
|
||||||
|
|
||||||
// return null if not in this list.
|
|
||||||
if (!in_array($type, $list, true)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$result = $account->accountMeta->where('name', 'currency_id')->first();
|
|
||||||
if (null === $result) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return TransactionCurrency::find((int) $result->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sumTransactions(array $transactions, string $key): string
|
|
||||||
{
|
|
||||||
$sum = '0';
|
|
||||||
|
|
||||||
/** @var array $transaction */
|
|
||||||
foreach ($transactions as $transaction) {
|
|
||||||
$value = (string) ($transaction[$key] ?? '0');
|
|
||||||
$value = '' === $value ? '0' : $value;
|
|
||||||
$sum = bcadd($sum, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function groupAndSumTransactions(array $array, string $group, string $field): array
|
private function groupAndSumTransactions(array $array, string $group, string $field): array
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
|
@ -24,6 +24,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support\System;
|
namespace FireflyIII\Support\System;
|
||||||
|
|
||||||
|
use Artisan;
|
||||||
|
use Crypt;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Laravel\Passport\Console\KeysCommand;
|
use Laravel\Passport\Console\KeysCommand;
|
||||||
@ -87,16 +89,16 @@ class OAuthKeys
|
|||||||
|
|
||||||
public static function generateKeys(): void
|
public static function generateKeys(): void
|
||||||
{
|
{
|
||||||
\Artisan::registerCommand(new KeysCommand());
|
Artisan::registerCommand(new KeysCommand());
|
||||||
\Artisan::call('firefly-iii:laravel-passport-keys');
|
Artisan::call('firefly-iii:laravel-passport-keys');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function storeKeysInDB(): void
|
public static function storeKeysInDB(): void
|
||||||
{
|
{
|
||||||
$private = storage_path('oauth-private.key');
|
$private = storage_path('oauth-private.key');
|
||||||
$public = storage_path('oauth-public.key');
|
$public = storage_path('oauth-public.key');
|
||||||
app('fireflyconfig')->set(self::PRIVATE_KEY, \Crypt::encrypt(file_get_contents($private)));
|
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private)));
|
||||||
app('fireflyconfig')->set(self::PUBLIC_KEY, \Crypt::encrypt(file_get_contents($public)));
|
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,8 +110,8 @@ class OAuthKeys
|
|||||||
$publicKey = (string) app('fireflyconfig')->get(self::PUBLIC_KEY)?->data;
|
$publicKey = (string) app('fireflyconfig')->get(self::PUBLIC_KEY)?->data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$privateContent = \Crypt::decrypt($privateKey);
|
$privateContent = Crypt::decrypt($privateKey);
|
||||||
$publicContent = \Crypt::decrypt($publicKey);
|
$publicContent = Crypt::decrypt($publicKey);
|
||||||
} catch (DecryptException $e) {
|
} catch (DecryptException $e) {
|
||||||
app('log')->error('Could not decrypt pub/private keypair.');
|
app('log')->error('Could not decrypt pub/private keypair.');
|
||||||
app('log')->error($e->getMessage());
|
app('log')->error($e->getMessage());
|
||||||
|
@ -282,7 +282,7 @@ class General extends AbstractExtension
|
|||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$route = $args[0]; // name of the route.
|
$route = $args[0]; // name of the route.
|
||||||
|
|
||||||
if (\Route::getCurrentRoute()->getName() === $route) {
|
if (Route::getCurrentRoute()->getName() === $route) {
|
||||||
return 'active';
|
return 'active';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ class General extends AbstractExtension
|
|||||||
static function (): string {
|
static function (): string {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$route = $args[0]; // name of the route.
|
$route = $args[0]; // name of the route.
|
||||||
$name = \Route::getCurrentRoute()->getName() ?? '';
|
$name = Route::getCurrentRoute()->getName() ?? '';
|
||||||
if (str_contains($name, $route)) {
|
if (str_contains($name, $route)) {
|
||||||
return 'active';
|
return 'active';
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ class General extends AbstractExtension
|
|||||||
|
|
||||||
if ($objectType === $activeObjectType
|
if ($objectType === $activeObjectType
|
||||||
&& false !== stripos(
|
&& false !== stripos(
|
||||||
\Route::getCurrentRoute()->getName(),
|
Route::getCurrentRoute()->getName(),
|
||||||
$route
|
$route
|
||||||
)) {
|
)) {
|
||||||
return 'active';
|
return 'active';
|
||||||
@ -349,7 +349,7 @@ class General extends AbstractExtension
|
|||||||
static function (): string {
|
static function (): string {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$route = $args[0]; // name of the route.
|
$route = $args[0]; // name of the route.
|
||||||
$name = \Route::getCurrentRoute()->getName() ?? '';
|
$name = Route::getCurrentRoute()->getName() ?? '';
|
||||||
if (str_contains($name, $route)) {
|
if (str_contains($name, $route)) {
|
||||||
return 'menu-open';
|
return 'menu-open';
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support\Twig;
|
namespace FireflyIII\Support\Twig;
|
||||||
|
|
||||||
|
use Config;
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ class Rule extends AbstractExtension
|
|||||||
'allRuleActions',
|
'allRuleActions',
|
||||||
static function () {
|
static function () {
|
||||||
// array of valid values for actions
|
// array of valid values for actions
|
||||||
$ruleActions = array_keys(\Config::get('firefly.rule-actions'));
|
$ruleActions = array_keys(Config::get('firefly.rule-actions'));
|
||||||
$possibleActions = [];
|
$possibleActions = [];
|
||||||
foreach ($ruleActions as $key) {
|
foreach ($ruleActions as $key) {
|
||||||
$possibleActions[$key] = (string) trans('firefly.rule_action_' . $key . '_choice');
|
$possibleActions[$key] = (string) trans('firefly.rule_action_' . $key . '_choice');
|
||||||
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Twig;
|
namespace FireflyIII\Support\Twig;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@ -223,12 +224,11 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
return new TwigFunction(
|
return new TwigFunction(
|
||||||
'journalHasMeta',
|
'journalHasMeta',
|
||||||
static function (int $journalId, string $metaField) {
|
static function (int $journalId, string $metaField) {
|
||||||
$count = \DB::table('journal_meta')
|
$count = DB::table('journal_meta')
|
||||||
->where('name', $metaField)
|
->where('name', $metaField)
|
||||||
->where('transaction_journal_id', $journalId)
|
->where('transaction_journal_id', $journalId)
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->count()
|
->count();
|
||||||
;
|
|
||||||
|
|
||||||
return 1 === $count;
|
return 1 === $count;
|
||||||
}
|
}
|
||||||
@ -241,12 +241,11 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
'journalGetMetaDate',
|
'journalGetMetaDate',
|
||||||
static function (int $journalId, string $metaField) {
|
static function (int $journalId, string $metaField) {
|
||||||
/** @var null|TransactionJournalMeta $entry */
|
/** @var null|TransactionJournalMeta $entry */
|
||||||
$entry = \DB::table('journal_meta')
|
$entry = DB::table('journal_meta')
|
||||||
->where('name', $metaField)
|
->where('name', $metaField)
|
||||||
->where('transaction_journal_id', $journalId)
|
->where('transaction_journal_id', $journalId)
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
if (null === $entry) {
|
if (null === $entry) {
|
||||||
return today(config('app.timezone'));
|
return today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
@ -262,12 +261,11 @@ class TransactionGroupTwig extends AbstractExtension
|
|||||||
'journalGetMetaField',
|
'journalGetMetaField',
|
||||||
static function (int $journalId, string $metaField) {
|
static function (int $journalId, string $metaField) {
|
||||||
/** @var null|TransactionJournalMeta $entry */
|
/** @var null|TransactionJournalMeta $entry */
|
||||||
$entry = \DB::table('journal_meta')
|
$entry = DB::table('journal_meta')
|
||||||
->where('name', $metaField)
|
->where('name', $metaField)
|
||||||
->where('transaction_journal_id', $journalId)
|
->where('transaction_journal_id', $journalId)
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->first()
|
->first();
|
||||||
;
|
|
||||||
if (null === $entry) {
|
if (null === $entry) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
private function getMetaBalances(Collection $accounts): void
|
private function getMetaBalances(Collection $accounts): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->convertedBalances = app('steam')->balancesByAccountsConverted($accounts, $this->getDate());
|
$this->convertedBalances = app('steam')->finalAccountsBalance($accounts, $this->getDate());
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
@ -172,14 +172,15 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
|
|
||||||
private function getBalanceDifference(Collection $accounts, Carbon $start, Carbon $end): void
|
private function getBalanceDifference(Collection $accounts, Carbon $start, Carbon $end): void
|
||||||
{
|
{
|
||||||
|
throw new FireflyException('Used deprecated method, rethink this.');
|
||||||
// collect balances, start and end for both native and converted.
|
// collect balances, start and end for both native and converted.
|
||||||
// yes the b is usually used for boolean by idiots but here it's for balance.
|
// yes the b is usually used for boolean by idiots but here it's for balance.
|
||||||
$bStart = [];
|
$bStart = [];
|
||||||
$bEnd = [];
|
$bEnd = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$bStart = app('steam')->balancesByAccountsConverted($accounts, $start);
|
$bStart = app('steam')->finalAccountsBalance($accounts, $start);
|
||||||
$bEnd = app('steam')->balancesByAccountsConverted($accounts, $end);
|
$bEnd = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user