mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Warn about expensive code in test environment.
This commit is contained in:
parent
0f70cc5780
commit
2710a30a7c
@ -202,6 +202,9 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getAllCurrencies(): Collection
|
public function getAllCurrencies(): Collection
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
return TransactionCurrency::orderBy('code', 'ASC')->get();
|
return TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +213,9 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getCurrencies(): Collection
|
public function getCurrencies(): Collection
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
|
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +224,9 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getCurrencyCode(): string
|
public function getCurrencyCode(): string
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty('getCurrencyCode');
|
$cache->addProperty('getCurrencyCode');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
@ -241,6 +250,9 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getCurrencySymbol(): string
|
public function getCurrencySymbol(): string
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty('getCurrencySymbol');
|
$cache->addProperty('getCurrencySymbol');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
@ -261,6 +273,9 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getDefaultCurrency(): TransactionCurrency
|
public function getDefaultCurrency(): TransactionCurrency
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
@ -276,6 +291,9 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getDefaultCurrencyByUser(User $user): TransactionCurrency
|
public function getDefaultCurrencyByUser(User $user): TransactionCurrency
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty('getDefaultCurrency');
|
$cache->addProperty('getDefaultCurrency');
|
||||||
$cache->addProperty($user->id);
|
$cache->addProperty($user->id);
|
||||||
|
@ -53,8 +53,8 @@ class ExpandedForm
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -93,8 +93,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -140,11 +140,10 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function amount(string $name, $value = null, array $options = null): string
|
public function amount(string $name, $value = null, array $options = null): string
|
||||||
{
|
{
|
||||||
@ -153,8 +152,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -185,7 +184,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -227,8 +226,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -267,8 +266,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@ -280,8 +279,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@ -293,9 +292,9 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param int $value
|
* @param int $value
|
||||||
* @param mixed $checked
|
* @param mixed $checked
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -331,8 +330,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -354,8 +353,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -379,8 +378,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -404,7 +403,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -427,8 +426,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -453,8 +452,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -478,8 +477,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -580,8 +579,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -611,8 +610,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -656,7 +655,7 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -681,8 +680,8 @@ class ExpandedForm
|
|||||||
* Function to render a percentage.
|
* Function to render a percentage.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -707,8 +706,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -732,8 +731,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -754,8 +753,8 @@ class ExpandedForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param null $value
|
* @param null $value
|
||||||
* @param array|null $options
|
* @param array|null $options
|
||||||
*
|
*
|
||||||
* @return HtmlString
|
* @return HtmlString
|
||||||
@ -785,9 +784,9 @@ class ExpandedForm
|
|||||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* @param mixed $selected
|
* @param mixed $selected
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -811,8 +810,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -834,8 +833,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -859,8 +858,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -883,8 +882,8 @@ class ExpandedForm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
@ -916,8 +915,8 @@ class ExpandedForm
|
|||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $view
|
* @param string $view
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
@ -969,8 +968,8 @@ class ExpandedForm
|
|||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $view
|
* @param string $view
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
@ -26,7 +26,7 @@ use FireflyIII\Models\Preference;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
use Log;
|
||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
* Class Preferences.
|
* Class Preferences.
|
||||||
@ -44,6 +44,11 @@ use Illuminate\Support\Facades\Facade;
|
|||||||
*/
|
*/
|
||||||
class Preferences extends Facade
|
class Preferences extends Facade
|
||||||
{
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
Log::warning('Hi there');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the registered name of the component.
|
* Get the registered name of the component.
|
||||||
*
|
*
|
||||||
|
@ -32,11 +32,15 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class FireflyConfig
|
class FireflyConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function delete(string $name): void
|
public function delete(string $name): void
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$fullName = 'ff-config-' . $name;
|
$fullName = 'ff-config-' . $name;
|
||||||
if (Cache::has($fullName)) {
|
if (Cache::has($fullName)) {
|
||||||
Cache::forget($fullName);
|
Cache::forget($fullName);
|
||||||
@ -51,12 +55,15 @@ class FireflyConfig
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
*
|
*
|
||||||
* @return \FireflyIII\Models\Configuration|null
|
* @return \FireflyIII\Models\Configuration|null
|
||||||
*/
|
*/
|
||||||
public function get(string $name, $default = null): ?Configuration
|
public function get(string $name, $default = null): ?Configuration
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$fullName = 'ff-config-' . $name;
|
$fullName = 'ff-config-' . $name;
|
||||||
if (Cache::has($fullName)) {
|
if (Cache::has($fullName)) {
|
||||||
return Cache::get($fullName);
|
return Cache::get($fullName);
|
||||||
@ -79,12 +86,15 @@ class FireflyConfig
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
*
|
*
|
||||||
* @return \FireflyIII\Models\Configuration|null
|
* @return \FireflyIII\Models\Configuration|null
|
||||||
*/
|
*/
|
||||||
public function getFresh(string $name, $default = null): ?Configuration
|
public function getFresh(string $name, $default = null): ?Configuration
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$config = Configuration::where('name', $name)->first(['id', 'name', 'data']);
|
$config = Configuration::where('name', $name)->first(['id', 'name', 'data']);
|
||||||
if ($config) {
|
if ($config) {
|
||||||
|
|
||||||
@ -106,6 +116,10 @@ class FireflyConfig
|
|||||||
*/
|
*/
|
||||||
public function put(string $name, $value): Configuration
|
public function put(string $name, $value): Configuration
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
|
|
||||||
return $this->set($name, $value);
|
return $this->set($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +131,9 @@ class FireflyConfig
|
|||||||
*/
|
*/
|
||||||
public function set(string $name, $value): Configuration
|
public function set(string $name, $value): Configuration
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
Log::debug('Set new value for ', ['name' => $name]);
|
Log::debug('Set new value for ', ['name' => $name]);
|
||||||
/** @var Configuration $config */
|
/** @var Configuration $config */
|
||||||
$config = Configuration::whereName($name)->first();
|
$config = Configuration::whereName($name)->first();
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Http\Controllers;
|
|||||||
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
@ -74,8 +75,8 @@ trait ModelInformation
|
|||||||
* Get the destination account. Is complex.
|
* Get the destination account. Is complex.
|
||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param TransactionType $destinationType
|
* @param TransactionType $destinationType
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Account
|
* @return Account
|
||||||
*
|
*
|
||||||
@ -115,9 +116,9 @@ trait ModelInformation
|
|||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $data['destination_account_expense'],
|
'name' => $data['destination_account_expense'],
|
||||||
'account_type' => 'expense',
|
'account_type' => 'expense',
|
||||||
'account_type_id' => null,
|
'account_type_id' => null,
|
||||||
'virtual_balance' => 0,
|
'virtual_balance' => 0,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'iban' => null,
|
'iban' => null,
|
||||||
];
|
];
|
||||||
@ -137,8 +138,8 @@ trait ModelInformation
|
|||||||
* Get the source account.
|
* Get the source account.
|
||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param TransactionType $destinationType
|
* @param TransactionType $destinationType
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Account
|
* @return Account
|
||||||
*
|
*
|
||||||
@ -171,8 +172,8 @@ trait ModelInformation
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $data['source_account_revenue'],
|
'name' => $data['source_account_revenue'],
|
||||||
'account_type' => 'revenue',
|
'account_type' => 'revenue',
|
||||||
'virtual_balance' => 0,
|
'virtual_balance' => 0,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'account_type_id' => null,
|
'account_type_id' => null,
|
||||||
'iban' => null,
|
'iban' => null,
|
||||||
@ -238,6 +239,43 @@ trait ModelInformation
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getRoles(): array
|
||||||
|
{
|
||||||
|
$roles = [];
|
||||||
|
foreach (config('firefly.accountRoles') as $role) {
|
||||||
|
$roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getLiabilityTypes(): array
|
||||||
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
// types of liability:
|
||||||
|
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
|
||||||
|
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
|
||||||
|
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||||
|
/** @noinspection NullPointerExceptionInspection */
|
||||||
|
$liabilityTypes = [
|
||||||
|
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
||||||
|
$loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
||||||
|
$mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
||||||
|
];
|
||||||
|
asort($liabilityTypes);
|
||||||
|
|
||||||
|
return $liabilityTypes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is transaction opening balance?
|
* Is transaction opening balance?
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Support\Http\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Collector\GroupSumCollectorInterface;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
@ -135,34 +134,6 @@ trait PeriodOverview
|
|||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $journals
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function groupByCurrency(array $journals): array
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
/** @var array $journal */
|
|
||||||
foreach ($journals as $journal) {
|
|
||||||
$currencyId = (int)$journal['currency_id'];
|
|
||||||
if (!isset($return[$currencyId])) {
|
|
||||||
$currency = new TransactionCurrency;
|
|
||||||
$currency->symbol = $journal['currency_symbol'];
|
|
||||||
$currency->decimal_places = $journal['currency_decimal_places'];
|
|
||||||
$currency->name = $journal['currency_name'];
|
|
||||||
$return[$currencyId] = [
|
|
||||||
'amount' => '0',
|
|
||||||
'currency' => $currency,
|
|
||||||
//'currency' => 'x',//$currency,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overview for single category. Has been refactored recently.
|
* Overview for single category. Has been refactored recently.
|
||||||
*
|
*
|
||||||
@ -469,16 +440,11 @@ trait PeriodOverview
|
|||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
|
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
|
|
||||||
/** @var GroupSumCollectorInterface $sumCollector */
|
|
||||||
$sumCollector = app(GroupSumCollectorInterface::class);
|
|
||||||
$sumCollector->setTypes($types)->setRange($currentDate['start'], $currentDate['end']);
|
|
||||||
$amounts = $sumCollector->getSum();
|
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setTypes($types)->setRange($currentDate['start'], $currentDate['end']);
|
$collector->setTypes($types)->setRange($currentDate['start'], $currentDate['end']);
|
||||||
$amounts = $collector->getSum();
|
$journals = $collector->getExtractedJournals();
|
||||||
|
$amounts = $this->getJournalsSum($journals);
|
||||||
|
|
||||||
$spent = [];
|
$spent = [];
|
||||||
$earned = [];
|
$earned = [];
|
||||||
@ -553,4 +519,80 @@ trait PeriodOverview
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $journals
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function groupByCurrency(array $journals): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$currencyId = (int)$journal['currency_id'];
|
||||||
|
if (!isset($return[$currencyId])) {
|
||||||
|
$currency = new TransactionCurrency;
|
||||||
|
$currency->symbol = $journal['currency_symbol'];
|
||||||
|
$currency->decimal_places = $journal['currency_decimal_places'];
|
||||||
|
$currency->name = $journal['currency_name'];
|
||||||
|
$return[$currencyId] = [
|
||||||
|
'amount' => '0',
|
||||||
|
'currency' => $currency,
|
||||||
|
//'currency' => 'x',//$currency,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $journals
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getJournalsSum(array $journals): array
|
||||||
|
{
|
||||||
|
$return = [
|
||||||
|
'count' => 0,
|
||||||
|
'sums' => [],
|
||||||
|
];
|
||||||
|
if (0 === count($journals)) {
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($journals as $row) {
|
||||||
|
$return['count']++;
|
||||||
|
$currencyId = (int)$row['currency_id'];
|
||||||
|
if (!isset($return['sums'][$currencyId])) {
|
||||||
|
$return['sums'][$currencyId] = [
|
||||||
|
'sum' => '0',
|
||||||
|
'currency_id' => $currencyId,
|
||||||
|
'currency_code' => $row['currency_code'],
|
||||||
|
'currency_symbol' => $row['currency_symbol'],
|
||||||
|
'currency_name' => $row['currency_name'],
|
||||||
|
'currency_decimal_places' => (int)$row['currency_decimal_places'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// add amounts:
|
||||||
|
$return['sums'][$currencyId]['sum'] = bcadd($return['sums'][$currencyId]['sum'], (string)$row['amount']);
|
||||||
|
|
||||||
|
// same but for foreign amounts:
|
||||||
|
if (null !== $row['foreign_currency_id'] && 0 !== $row['foreign_currency_id']) {
|
||||||
|
$foreignCurrencyId = (int)$row['foreign_currency_id'];
|
||||||
|
$return['sums'][$foreignCurrencyId] = [
|
||||||
|
'sum' => '0',
|
||||||
|
'currency_id' => $foreignCurrencyId,
|
||||||
|
'currency_code' => $row['foreign_currency_code'],
|
||||||
|
'currency_symbol' => $row['foreign_currency_symbol'],
|
||||||
|
'currency_name' => $row['foreign_currency_name'],
|
||||||
|
'currency_decimal_places' => (int)$row['foreign_currency_decimal_places'],
|
||||||
|
];
|
||||||
|
$return['sums'][$foreignCurrencyId]['sum'] = bcadd($return['sums'][$foreignCurrencyId]['sum'], (string)$row['foreign_amount']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,16 @@ use Session;
|
|||||||
class Preferences
|
class Preferences
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param string $search
|
* @param string $search
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function beginsWith(User $user, string $search): Collection
|
public function beginsWith(User $user, string $search): Collection
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$set = Preference::where('user_id', $user->id)->where('name', 'LIKE', $search . '%')->get();
|
$set = Preference::where('user_id', $user->id)->where('name', 'LIKE', $search . '%')->get();
|
||||||
|
|
||||||
return $set;
|
return $set;
|
||||||
@ -55,6 +58,9 @@ class Preferences
|
|||||||
*/
|
*/
|
||||||
public function delete(string $name): bool
|
public function delete(string $name): bool
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$fullName = sprintf('preference%s%s', auth()->user()->id, $name);
|
$fullName = sprintf('preference%s%s', auth()->user()->id, $name);
|
||||||
if (Cache::has($fullName)) {
|
if (Cache::has($fullName)) {
|
||||||
Cache::forget($fullName);
|
Cache::forget($fullName);
|
||||||
@ -76,17 +82,24 @@ class Preferences
|
|||||||
*/
|
*/
|
||||||
public function findByName(string $name): Collection
|
public function findByName(string $name): Collection
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
|
|
||||||
return Preference::where('name', $name)->get();
|
return Preference::where('name', $name)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
*
|
*
|
||||||
* @return \FireflyIII\Models\Preference|null
|
* @return \FireflyIII\Models\Preference|null
|
||||||
*/
|
*/
|
||||||
public function get(string $name, $default = null): ?Preference
|
public function get(string $name, $default = null): ?Preference
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
if (null === $user) {
|
if (null === $user) {
|
||||||
@ -98,12 +111,15 @@ class Preferences
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \FireflyIII\User $user
|
* @param \FireflyIII\User $user
|
||||||
* @param array $list
|
* @param array $list
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getArrayForUser(User $user, array $list): array
|
public function getArrayForUser(User $user, array $list): array
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$result = [];
|
$result = [];
|
||||||
$preferences = Preference::where('user_id', $user->id)->whereIn('name', $list)->get(['id', 'name', 'data']);
|
$preferences = Preference::where('user_id', $user->id)->whereIn('name', $list)->get(['id', 'name', 'data']);
|
||||||
/** @var Preference $preference */
|
/** @var Preference $preference */
|
||||||
@ -121,13 +137,16 @@ class Preferences
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \FireflyIII\User $user
|
* @param \FireflyIII\User $user
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param null|string $default
|
* @param null|string $default
|
||||||
*
|
*
|
||||||
* @return \FireflyIII\Models\Preference|null
|
* @return \FireflyIII\Models\Preference|null
|
||||||
*/
|
*/
|
||||||
public function getForUser(User $user, string $name, $default = null): ?Preference
|
public function getForUser(User $user, string $name, $default = null): ?Preference
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||||
if (Cache::has($fullName)) {
|
if (Cache::has($fullName)) {
|
||||||
return Cache::get($fullName);
|
return Cache::get($fullName);
|
||||||
@ -162,6 +181,9 @@ class Preferences
|
|||||||
*/
|
*/
|
||||||
public function lastActivity(): string
|
public function lastActivity(): string
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$lastActivity = microtime();
|
$lastActivity = microtime();
|
||||||
$preference = $this->get('lastActivity', microtime());
|
$preference = $this->get('lastActivity', microtime());
|
||||||
|
|
||||||
@ -186,7 +208,7 @@ class Preferences
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
*
|
||||||
* @return \FireflyIII\Models\Preference
|
* @return \FireflyIII\Models\Preference
|
||||||
*/
|
*/
|
||||||
@ -207,8 +229,8 @@ class Preferences
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \FireflyIII\User $user
|
* @param \FireflyIII\User $user
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
*
|
||||||
* @return Preference
|
* @return Preference
|
||||||
*/
|
*/
|
||||||
|
@ -28,6 +28,7 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +45,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function balance(Account $account, Carbon $date): string
|
public function balance(Account $account, Carbon $date): string
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
// abuse chart properties:
|
// abuse chart properties:
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
@ -93,6 +97,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function balanceIgnoreVirtual(Account $account, Carbon $date): string
|
public function balanceIgnoreVirtual(Account $account, Carbon $date): string
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
// abuse chart properties:
|
// abuse chart properties:
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
@ -139,6 +146,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function balanceInRange(Account $account, Carbon $start, Carbon $end): array
|
public function balanceInRange(Account $account, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
// abuse chart properties:
|
// abuse chart properties:
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
@ -225,7 +235,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function balancePerCurrency(Account $account, Carbon $date): array
|
public function balancePerCurrency(Account $account, Carbon $date): array
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
// abuse chart properties:
|
// abuse chart properties:
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
@ -259,6 +271,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function balancesByAccounts(Collection $accounts, Carbon $date): array
|
public function balancesByAccounts(Collection $accounts, Carbon $date): array
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
// cache this property.
|
// cache this property.
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
@ -291,6 +306,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date): array
|
public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date): array
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
// cache this property.
|
// cache this property.
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
@ -383,6 +401,9 @@ class Steam
|
|||||||
*/
|
*/
|
||||||
public function getLastActivities(array $accounts): array
|
public function getLastActivities(array $accounts): array
|
||||||
{
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
$set = auth()->user()->transactions()
|
$set = auth()->user()->transactions()
|
||||||
|
@ -26,6 +26,7 @@ use FireflyIII\Models\Account as AccountModel;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use Log;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
use Twig_SimpleFilter;
|
use Twig_SimpleFilter;
|
||||||
use Twig_SimpleFunction;
|
use Twig_SimpleFunction;
|
||||||
@ -83,7 +84,12 @@ class AmountFormat extends Twig_Extension
|
|||||||
{
|
{
|
||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'formatAmountByAccount',
|
'formatAmountByAccount',
|
||||||
function (AccountModel $account, string $amount, bool $coloured = null): string {
|
static function (AccountModel $account, string $amount, bool $coloured = null): string {
|
||||||
|
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
|
|
||||||
$coloured = $coloured ?? true;
|
$coloured = $coloured ?? true;
|
||||||
/** @var AccountRepositoryInterface $accountRepos */
|
/** @var AccountRepositoryInterface $accountRepos */
|
||||||
$accountRepos = app(AccountRepositoryInterface::class);
|
$accountRepos = app(AccountRepositoryInterface::class);
|
||||||
|
@ -27,6 +27,7 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use League\CommonMark\CommonMarkConverter;
|
use League\CommonMark\CommonMarkConverter;
|
||||||
|
use Log;
|
||||||
use Route;
|
use Route;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
use Twig_SimpleFilter;
|
use Twig_SimpleFilter;
|
||||||
@ -145,13 +146,17 @@ class General extends Twig_Extension
|
|||||||
{
|
{
|
||||||
return new Twig_SimpleFilter(
|
return new Twig_SimpleFilter(
|
||||||
'balance',
|
'balance',
|
||||||
function (?Account $account): string {
|
static function (?Account $account): string {
|
||||||
if (null === $account) {
|
if (null === $account) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
}
|
}
|
||||||
/** @var Carbon $date */
|
/** @var Carbon $date */
|
||||||
$date = session('end', Carbon::now()->endOfMonth());
|
$date = session('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
|
|
||||||
return app('steam')->balance($account, $date);
|
return app('steam')->balance($account, $date);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -207,6 +212,10 @@ class General extends Twig_Extension
|
|||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'accountGetMetaField',
|
'accountGetMetaField',
|
||||||
static function (Account $account, string $field): string {
|
static function (Account $account, string $field): string {
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$result = $repository->getMetaValue($account, $field);
|
$result = $repository->getMetaValue($account, $field);
|
||||||
@ -228,7 +237,10 @@ class General extends Twig_Extension
|
|||||||
{
|
{
|
||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'hasRole',
|
'hasRole',
|
||||||
function (string $role): bool {
|
static function (string $role): bool {
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$repository = app(UserRepositoryInterface::class);
|
$repository = app(UserRepositoryInterface::class);
|
||||||
if ($repository->hasRole(auth()->user(), $role)) {
|
if ($repository->hasRole(auth()->user(), $role)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -38,7 +38,7 @@ class Rule extends Twig_Extension
|
|||||||
{
|
{
|
||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'allRuleActions',
|
'allRuleActions',
|
||||||
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 = [];
|
||||||
@ -60,7 +60,7 @@ class Rule extends Twig_Extension
|
|||||||
{
|
{
|
||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'allJournalTriggers',
|
'allJournalTriggers',
|
||||||
function () {
|
static function () {
|
||||||
return [
|
return [
|
||||||
'store-journal' => (string)trans('firefly.rule_trigger_store_journal'),
|
'store-journal' => (string)trans('firefly.rule_trigger_store_journal'),
|
||||||
'update-journal' => (string)trans('firefly.rule_trigger_update_journal'),
|
'update-journal' => (string)trans('firefly.rule_trigger_update_journal'),
|
||||||
@ -76,7 +76,7 @@ class Rule extends Twig_Extension
|
|||||||
{
|
{
|
||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'allRuleTriggers',
|
'allRuleTriggers',
|
||||||
function () {
|
static function () {
|
||||||
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
|
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
|
||||||
$possibleTriggers = [];
|
$possibleTriggers = [];
|
||||||
foreach ($ruleTriggers as $key) {
|
foreach ($ruleTriggers as $key) {
|
||||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Support\Twig\Extension;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use Log;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
use Twig_SimpleFunction;
|
use Twig_SimpleFunction;
|
||||||
|
|
||||||
@ -94,7 +95,9 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'journalGetMetaDate',
|
'journalGetMetaDate',
|
||||||
static function (int $journalId, string $metaField) {
|
static function (int $journalId, string $metaField) {
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$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)
|
||||||
@ -117,7 +120,9 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'journalGetMetaField',
|
'journalGetMetaField',
|
||||||
static function (int $journalId, string $metaField) {
|
static function (int $journalId, string $metaField) {
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$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)
|
||||||
@ -140,6 +145,9 @@ class TransactionGroupTwig extends Twig_Extension
|
|||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'journalHasMeta',
|
'journalHasMeta',
|
||||||
static function (int $journalId, string $metaField) {
|
static function (int $journalId, string $metaField) {
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||||
|
}
|
||||||
$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)
|
||||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\Api\V1\Controllers;
|
namespace Tests\Api\V1\Controllers;
|
||||||
|
|
||||||
|
use Preferences;
|
||||||
use Amount;
|
use Amount;
|
||||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||||
use FireflyIII\Models\AvailableBudget;
|
use FireflyIII\Models\AvailableBudget;
|
||||||
@ -61,6 +61,7 @@ class AvailableBudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore(): void
|
public function testStore(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||||
@ -101,6 +102,7 @@ class AvailableBudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStoreNoCurrencyAtAll(): void
|
public function testStoreNoCurrencyAtAll(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||||
@ -142,6 +144,7 @@ class AvailableBudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStoreNoCurrencyId(): void
|
public function testStoreNoCurrencyId(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
/** @var AvailableBudget $availableBudget */
|
/** @var AvailableBudget $availableBudget */
|
||||||
$availableBudget = $this->user()->availableBudgets()->first();
|
$availableBudget = $this->user()->availableBudgets()->first();
|
||||||
|
|
||||||
@ -188,11 +191,15 @@ class AvailableBudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(): void
|
public function testUpdate(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
// mock repositories
|
// mock repositories
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||||
|
$euro = $this->getEuro();
|
||||||
|
// mock facades:
|
||||||
|
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||||
|
|
||||||
// mock transformer
|
// mock transformer
|
||||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||||
|
@ -55,6 +55,7 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testOverview(): void
|
public function testOverview(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
// mock repositories
|
// mock repositories
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
@ -93,6 +94,7 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRevenueOverview(): void
|
public function testRevenueOverview(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
// mock repositories
|
// mock repositories
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
@ -134,6 +136,7 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExpenseOverview(): void
|
public function testExpenseOverview(): void
|
||||||
{
|
{
|
||||||
|
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||||
// mock repositories
|
// mock repositories
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
@ -34,7 +34,7 @@ use Laravel\Passport\Passport;
|
|||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use Amount;
|
||||||
/**
|
/**
|
||||||
* Class CurrencyControllerTest
|
* Class CurrencyControllerTest
|
||||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
@ -65,7 +65,7 @@ class CurrencyControllerTest extends TestCase
|
|||||||
$currency = TransactionCurrency::first();
|
$currency = TransactionCurrency::first();
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$transformer = $this->mock(CurrencyTransformer::class);
|
$transformer = $this->mock(CurrencyTransformer::class);
|
||||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
$this->mock(UserRepositoryInterface::class);
|
||||||
|
|
||||||
// mock transformer
|
// mock transformer
|
||||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||||
@ -74,6 +74,9 @@ class CurrencyControllerTest extends TestCase
|
|||||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||||
|
|
||||||
|
// mock facades.
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$repository->shouldReceive('setUser')->once();
|
$repository->shouldReceive('setUser')->once();
|
||||||
$repository->shouldReceive('store')->andReturn($currency);
|
$repository->shouldReceive('store')->andReturn($currency);
|
||||||
|
Loading…
Reference in New Issue
Block a user