mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-15 11:12:08 -06:00
Verify routine will check currency usage.
This commit is contained in:
parent
e491dda229
commit
5cc840e390
@ -28,12 +28,15 @@ namespace FireflyIII\Console\Commands;
|
|||||||
use Crypt;
|
use Crypt;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\AccountMeta;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\LinkType;
|
use FireflyIII\Models\LinkType;
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
@ -41,6 +44,7 @@ use FireflyIII\User;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Schema;
|
use Schema;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
@ -95,6 +99,7 @@ class VerifyDatabase extends Command
|
|||||||
$this->fixDoubleAmounts();
|
$this->fixDoubleAmounts();
|
||||||
$this->fixBadMeta();
|
$this->fixBadMeta();
|
||||||
$this->removeBills();
|
$this->removeBills();
|
||||||
|
$this->enableCurrencies();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -150,6 +155,45 @@ class VerifyDatabase extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will make sure that all currencies in use are actually enabled.
|
||||||
|
*/
|
||||||
|
private function enableCurrencies(): void
|
||||||
|
{
|
||||||
|
$found = [];
|
||||||
|
// get all meta entries
|
||||||
|
/** @var Collection $meta */
|
||||||
|
$meta = AccountMeta::where('name', 'currency_id')->groupBy('data')->get(['data']);
|
||||||
|
foreach ($meta as $entry) {
|
||||||
|
$found[] = (int)$entry->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all from journals:
|
||||||
|
/** @var Collection $journals */
|
||||||
|
$journals = TransactionJournal::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
|
||||||
|
foreach ($journals as $entry) {
|
||||||
|
$found[] = (int)$entry->transaction_currency_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all from transactions
|
||||||
|
/** @var Collection $transactions */
|
||||||
|
$transactions = Transaction::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
|
||||||
|
foreach ($transactions as $entry) {
|
||||||
|
$found[] = (int)$entry->transaction_currency_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all from budget limits
|
||||||
|
/** @var Collection $limits */
|
||||||
|
$limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
|
||||||
|
foreach ($limits as $entry) {
|
||||||
|
$found[] = (int)$entry->transaction_currency_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$found = array_unique($found);
|
||||||
|
TransactionCurrency::whereIn('id', $found)->update(['enabled' => true]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix the situation where the matching transactions of a journal somehow have non-matching categories or budgets.
|
* Fix the situation where the matching transactions of a journal somehow have non-matching categories or budgets.
|
||||||
*
|
*
|
||||||
|
@ -95,4 +95,13 @@ class TransactionCurrency extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Transaction::class);
|
return $this->hasMany(Transaction::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function budgetLimits(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(BudgetLimit::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Currency;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||||
use FireflyIII\Models\AccountMeta;
|
use FireflyIII\Models\AccountMeta;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\CurrencyExchangeRate;
|
use FireflyIII\Models\CurrencyExchangeRate;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
@ -93,6 +94,14 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is being used in budget limits
|
||||||
|
$budgetLimit = BudgetLimit::where('transaction_currency_id', $currency->id)->count();
|
||||||
|
if ($budgetLimit > 0) {
|
||||||
|
Log::debug(sprintf('Used in %d budget limits as currency, return true. ', $budgetLimit));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// is the default currency for the user or the system
|
// is the default currency for the user or the system
|
||||||
$defaultCode = app('preferences')->getForUser($this->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
$defaultCode = app('preferences')->getForUser($this->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
||||||
if ($currency->code === $defaultCode) {
|
if ($currency->code === $defaultCode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user