Add budget limit currency ID.

This commit is contained in:
James Cole 2018-09-06 07:38:26 +02:00
parent 7bca2298a0
commit 28e7440726
8 changed files with 85 additions and 9 deletions

View File

@ -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".

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -29,7 +29,7 @@ class ChangesForV475 extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create(
'recurrences', function (Blueprint $table) {

View 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');
}
);
}
}