mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Remove the use of deprecated methods.
This commit is contained in:
@@ -30,6 +30,6 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|||||||
|
|
||||||
# Do static code analysis.
|
# Do static code analysis.
|
||||||
# ./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress
|
# ./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress
|
||||||
./vendor/bin/phpstan analyse -c .ci/phpstan.neon --xdebug --error-format=table > phpstan-report.txt
|
./vendor/bin/phpstan analyse -c .ci/phpstan.neon --error-format=table > phpstan-report.txt
|
||||||
|
|
||||||
echo 'The PHPstan report can be found in phpstan-report.txt'
|
echo 'The PHPstan report can be found in phpstan-report.txt'
|
||||||
|
@@ -79,7 +79,7 @@ class UpdateController extends Controller
|
|||||||
$account = $this->repository->update($account, $data);
|
$account = $this->repository->update($account, $data);
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
$account->refresh();
|
$account->refresh();
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
|
|
||||||
/** @var AccountTransformer $transformer */
|
/** @var AccountTransformer $transformer */
|
||||||
$transformer = app(AccountTransformer::class);
|
$transformer = app(AccountTransformer::class);
|
||||||
|
@@ -107,8 +107,8 @@ class BasicController extends Controller
|
|||||||
$balanceData = $this->getBalanceInformation($start, $end);
|
$balanceData = $this->getBalanceInformation($start, $end);
|
||||||
$billData = $this->getBillInformation($start, $end);
|
$billData = $this->getBillInformation($start, $end);
|
||||||
$spentData = $this->getLeftToSpendInfo($start, $end);
|
$spentData = $this->getLeftToSpendInfo($start, $end);
|
||||||
$networthData = $this->getNetWorthInfo($start, $end);
|
$netWorthData = $this->getNetWorthInfo($start, $end);
|
||||||
$total = array_merge($balanceData, $billData, $spentData, $networthData);
|
$total = array_merge($balanceData, $billData, $spentData, $netWorthData);
|
||||||
|
|
||||||
// give new keys
|
// give new keys
|
||||||
$return = [];
|
$return = [];
|
||||||
@@ -368,30 +368,30 @@ class BasicController extends Controller
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$netWorthSet = $netWorthHelper->getNetWorthByCurrency($filtered, $date);
|
$netWorthSet = $netWorthHelper->byAccounts($filtered, $date);
|
||||||
$return = [];
|
$return = [];
|
||||||
foreach ($netWorthSet as $data) {
|
foreach ($netWorthSet as $key => $data) {
|
||||||
/** @var TransactionCurrency $currency */
|
if('native' === $key) {
|
||||||
$currency = $data['currency'];
|
continue;
|
||||||
|
}
|
||||||
$amount = $data['balance'];
|
$amount = $data['balance'];
|
||||||
if (0 === bccomp($amount, '0')) {
|
if (0 === bccomp($amount, '0')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// return stuff
|
// return stuff
|
||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('net-worth-in-%s', $currency->code),
|
'key' => sprintf('net-worth-in-%s', $data['currency_code']),
|
||||||
'title' => trans('firefly.box_net_worth_in_currency', ['currency' => $currency->symbol]),
|
'title' => trans('firefly.box_net_worth_in_currency', ['currency' => $data['currency_symbol']]),
|
||||||
'monetary_value' => $amount,
|
'monetary_value' => $amount,
|
||||||
'currency_id' => (string)$currency->id,
|
'currency_id' => (string)$data['currency_id'],
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $data['currency_code'],
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $data['currency_symbol'],
|
||||||
'currency_decimal_places' => $currency->decimal_places,
|
'currency_decimal_places' => $data['currency_decimal_places'],
|
||||||
'value_parsed' => app('amount')->formatAnything($currency, $data['balance'], false),
|
'value_parsed' => app('amount')->formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false),
|
||||||
'local_icon' => 'line-chart',
|
'local_icon' => 'line-chart',
|
||||||
'sub_title' => '',
|
'sub_title' => '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,11 @@ class NetWorth implements NetWorthInterface
|
|||||||
private null | UserGroup $userGroup;
|
private null | UserGroup $userGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This method collects the user's net worth in ALL the user's currencies
|
||||||
|
* (1, 4 and 8) and also in the 'native' currency for ease of use.
|
||||||
|
*
|
||||||
|
* The set of accounts has to be fed to it.
|
||||||
|
*
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
@@ -150,88 +155,6 @@ class NetWorth implements NetWorthInterface
|
|||||||
return $this->adminAccountRepository;
|
return $this->adminAccountRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the user's net worth in an array with the following layout:
|
|
||||||
*
|
|
||||||
* -
|
|
||||||
* - currency: TransactionCurrency object
|
|
||||||
* - date: the current date
|
|
||||||
* - amount: the user's net worth in that currency.
|
|
||||||
*
|
|
||||||
* This repeats for each currency the user has transactions in.
|
|
||||||
* Result of this method is cached.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws JsonException
|
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function getNetWorthByCurrency(Collection $accounts, Carbon $date): array
|
|
||||||
{
|
|
||||||
// start in the past, end in the future? use $date
|
|
||||||
$cache = new CacheProperties();
|
|
||||||
$cache->addProperty($date);
|
|
||||||
$cache->addProperty('net-worth-by-currency');
|
|
||||||
$cache->addProperty(implode(',', $accounts->pluck('id')->toArray()));
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
$netWorth = [];
|
|
||||||
$result = [];
|
|
||||||
// Log::debug(sprintf('Now in getNetWorthByCurrency(%s)', $date->format('Y-m-d')));
|
|
||||||
|
|
||||||
// get default currency
|
|
||||||
$default = app('amount')->getDefaultCurrencyByUser($this->user);
|
|
||||||
|
|
||||||
// get all balances:
|
|
||||||
$balances = app('steam')->balancesByAccounts($accounts, $date);
|
|
||||||
|
|
||||||
// get the preferred currency for this account
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
// Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
|
|
||||||
$currencyId = (int)$this->getRepository()->getMetaValue($account, 'currency_id');
|
|
||||||
$currencyId = 0 === $currencyId ? $default->id : $currencyId;
|
|
||||||
|
|
||||||
// Log::debug(sprintf('Currency ID is #%d', $currencyId));
|
|
||||||
|
|
||||||
// balance in array:
|
|
||||||
$balance = $balances[$account->id] ?? '0';
|
|
||||||
|
|
||||||
//Log::debug(sprintf('Balance for %s is %s', $date->format('Y-m-d'), $balance));
|
|
||||||
|
|
||||||
// always subtract virtual balance.
|
|
||||||
$virtualBalance = (string)$account->virtual_balance;
|
|
||||||
if ('' !== $virtualBalance) {
|
|
||||||
$balance = bcsub($balance, $virtualBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log::debug(sprintf('Balance corrected to %s because of virtual balance (%s)', $balance, $virtualBalance));
|
|
||||||
|
|
||||||
if (!array_key_exists($currencyId, $netWorth)) {
|
|
||||||
$netWorth[$currencyId] = '0';
|
|
||||||
}
|
|
||||||
$netWorth[$currencyId] = bcadd($balance, $netWorth[$currencyId]);
|
|
||||||
// Log::debug(sprintf('Total net worth for currency #%d is %s', $currencyId, $netWorth[$currencyId]));
|
|
||||||
}
|
|
||||||
ksort($netWorth);
|
|
||||||
|
|
||||||
// loop results and add currency information:
|
|
||||||
foreach ($netWorth as $currencyId => $balance) {
|
|
||||||
$result[] = [
|
|
||||||
'currency' => $this->currencyRepos->find($currencyId),
|
|
||||||
'balance' => $balance,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$cache->store($result);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User|Authenticatable|null $user
|
* @param User|Authenticatable|null $user
|
||||||
*/
|
*/
|
||||||
|
@@ -50,27 +50,6 @@ interface NetWorthInterface
|
|||||||
*/
|
*/
|
||||||
public function byAccounts(Collection $accounts, Carbon $date): array;
|
public function byAccounts(Collection $accounts, Carbon $date): array;
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO unsure why this is deprecated.
|
|
||||||
*
|
|
||||||
* Returns the user's net worth in an array with the following layout:
|
|
||||||
*
|
|
||||||
* -
|
|
||||||
* - currency: TransactionCurrency object
|
|
||||||
* - date: the current date
|
|
||||||
* - amount: the user's net worth in that currency.
|
|
||||||
*
|
|
||||||
* This repeats for each currency the user has transactions in.
|
|
||||||
* Result of this method is cached.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function getNetWorthByCurrency(Collection $accounts, Carbon $date): array;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User|Authenticatable|null $user
|
* @param User|Authenticatable|null $user
|
||||||
*/
|
*/
|
||||||
|
@@ -109,19 +109,22 @@ class ReportController extends Controller
|
|||||||
|
|
||||||
while ($current < $end) {
|
while ($current < $end) {
|
||||||
// get balances by date, grouped by currency.
|
// get balances by date, grouped by currency.
|
||||||
$result = $helper->getNetWorthByCurrency($filtered, $current);
|
$result = $helper->byAccounts($filtered, $current);
|
||||||
|
|
||||||
// loop result, add to array.
|
// loop result, add to array.
|
||||||
/** @var array $netWorthItem */
|
/** @var array $netWorthItem */
|
||||||
foreach ($result as $netWorthItem) {
|
foreach ($result as $key => $netWorthItem) {
|
||||||
$currencyId = $netWorthItem['currency']->id;
|
if('native' === $key) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$currencyId = $netWorthItem['currency_id'];
|
||||||
$label = $current->isoFormat((string)trans('config.month_and_day_js', [], $locale));
|
$label = $current->isoFormat((string)trans('config.month_and_day_js', [], $locale));
|
||||||
if (!array_key_exists($currencyId, $chartData)) {
|
if (!array_key_exists($currencyId, $chartData)) {
|
||||||
$chartData[$currencyId] = [
|
$chartData[$currencyId] = [
|
||||||
'label' => 'Net worth in ' . $netWorthItem['currency']->name,
|
'label' => 'Net worth in ' . $netWorthItem['currency_name'],
|
||||||
'type' => 'line',
|
'type' => 'line',
|
||||||
'currency_symbol' => $netWorthItem['currency']->symbol,
|
'currency_symbol' => $netWorthItem['currency_symbol'],
|
||||||
'currency_code' => $netWorthItem['currency']->code,
|
'currency_code' => $netWorthItem['currency_code'],
|
||||||
'entries' => [],
|
'entries' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -268,12 +268,13 @@ class BoxController extends Controller
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$netWorthSet = $netWorthHelper->getNetWorthByCurrency($filtered, $date);
|
$netWorthSet = $netWorthHelper->byAccounts($filtered, $date);
|
||||||
$return = [];
|
$return = [];
|
||||||
foreach ($netWorthSet as $data) {
|
foreach ($netWorthSet as $key => $data) {
|
||||||
/** @var TransactionCurrency $currency */
|
if('native' === $key) {
|
||||||
$currency = $data['currency'];
|
continue;
|
||||||
$return[$currency->id] = app('amount')->formatAnything($currency, $data['balance'], false);
|
}
|
||||||
|
$return[$data['currency_id']] = app('amount')->formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false);
|
||||||
}
|
}
|
||||||
$return = [
|
$return = [
|
||||||
'net_worths' => array_values($return),
|
'net_worths' => array_values($return),
|
||||||
|
@@ -158,7 +158,7 @@ class InstallController extends Controller
|
|||||||
}
|
}
|
||||||
// clear cache as well.
|
// clear cache as well.
|
||||||
Cache::clear();
|
Cache::clear();
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -54,23 +54,23 @@ class InterestingMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->groupMessage($request)) {
|
if ($this->groupMessage($request)) {
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
$this->handleGroupMessage($request);
|
$this->handleGroupMessage($request);
|
||||||
}
|
}
|
||||||
if ($this->accountMessage($request)) {
|
if ($this->accountMessage($request)) {
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
$this->handleAccountMessage($request);
|
$this->handleAccountMessage($request);
|
||||||
}
|
}
|
||||||
if ($this->billMessage($request)) {
|
if ($this->billMessage($request)) {
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
$this->handleBillMessage($request);
|
$this->handleBillMessage($request);
|
||||||
}
|
}
|
||||||
if ($this->webhookMessage($request)) {
|
if ($this->webhookMessage($request)) {
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
$this->handleWebhookMessage($request);
|
$this->handleWebhookMessage($request);
|
||||||
}
|
}
|
||||||
if ($this->currencyMessage($request)) {
|
if ($this->currencyMessage($request)) {
|
||||||
Preferences::mark();
|
app('preferences')->mark();
|
||||||
$this->handleCurrencyMessage($request);
|
$this->handleCurrencyMessage($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -535,7 +535,7 @@ class Steam
|
|||||||
$result = [];
|
$result = [];
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$default = app('amount')->getDefaultCurrencyByUser($account->user);
|
$default = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||||
$result[(int)$account->id]
|
$result[(int)$account->id]
|
||||||
= [
|
= [
|
||||||
'balance' => $this->balance($account, $date),
|
'balance' => $this->balance($account, $date),
|
||||||
|
Reference in New Issue
Block a user