mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add budget limit currency ID.
This commit is contained in:
parent
7bca2298a0
commit
28e7440726
@ -35,6 +35,7 @@ use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Rule;
|
||||
@ -63,6 +64,7 @@ use UnexpectedValueException;
|
||||
* Upgrade user database.
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class UpgradeDatabase extends Command
|
||||
@ -95,6 +97,7 @@ class UpgradeDatabase extends Command
|
||||
$this->migrateNotes();
|
||||
$this->migrateAttachmentData();
|
||||
$this->migrateBillsToRules();
|
||||
$this->budgetLimitCurrency();
|
||||
|
||||
$this->info('Firefly III database is up to date.');
|
||||
|
||||
@ -435,6 +438,31 @@ class UpgradeDatabase extends Command
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function budgetLimitCurrency(): void
|
||||
{
|
||||
$budgetLimits = BudgetLimit::get();
|
||||
/** @var BudgetLimit $budgetLimit */
|
||||
foreach ($budgetLimits as $budgetLimit) {
|
||||
if (null === $budgetLimit->transaction_currency_id) {
|
||||
$budget = $budgetLimit->budget;
|
||||
if (null !== $budget) {
|
||||
$user = $budget->user;
|
||||
if (null !== $user) {
|
||||
$currency = \Amount::getDefaultCurrencyByUser($user);
|
||||
$budgetLimit->transaction_currency_id = $currency->id;
|
||||
$budgetLimit->save();
|
||||
$this->line(
|
||||
sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).', $budgetLimit->id, $budget->name, $currency->name)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createNewTypes(): void
|
||||
{
|
||||
// create transaction type "Reconciliation".
|
||||
|
@ -39,6 +39,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property string $amount
|
||||
* @property int $budget_id
|
||||
* @property string spent
|
||||
* @property int $transaction_currency_id
|
||||
*/
|
||||
class BudgetLimit extends Model
|
||||
{
|
||||
@ -89,4 +90,13 @@ class BudgetLimit extends Model
|
||||
{
|
||||
return $this->belongsTo(Budget::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function transactionCurrency(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TransactionCurrency::class);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class CreateOauthPersonalAccessClientsTable extends Migration
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down()
|
||||
public function down(): void
|
||||
{
|
||||
Schema::drop('oauth_personal_access_clients');
|
||||
}
|
||||
@ -42,7 +42,7 @@ class CreateOauthPersonalAccessClientsTable extends Migration
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create(
|
||||
'oauth_personal_access_clients', function (Blueprint $table) {
|
||||
|
@ -35,7 +35,7 @@ class ChangesForV472 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -45,7 +45,7 @@ class ChangesForV472 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table(
|
||||
'attachments',
|
||||
|
@ -36,8 +36,9 @@ class ChangesForV473 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +46,7 @@ class ChangesForV473 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table(
|
||||
'bills',
|
||||
|
@ -35,7 +35,7 @@ class ChangesForV474 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class ChangesForV474 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table(
|
||||
'import_jobs',
|
||||
|
@ -29,7 +29,7 @@ class ChangesForV475 extends Migration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create(
|
||||
'recurrences', function (Blueprint $table) {
|
||||
|
37
database/migrations/2018_09_05_195147_changes_for_v477.php
Normal file
37
database/migrations/2018_09_05_195147_changes_for_v477.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ChangesForV477
|
||||
*/
|
||||
class ChangesForV477 extends Migration
|
||||
{
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits',
|
||||
function (Blueprint $table) {
|
||||
$table->integer('transaction_currency_id', false, true)->nullable()->after('budget_id');
|
||||
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user