mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Database & seeds.
This commit is contained in:
parent
df165a817c
commit
ed475b1b9c
43
database/migrations/2014_06_27_163032_create_users_table.php
Normal file
43
database/migrations/2014_06_27_163032_create_users_table.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateUsersTable
|
||||
*/
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'users', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->string('email', 100)->unique();
|
||||
$table->string('password', 60);
|
||||
$table->rememberToken();
|
||||
$table->string('reset', 32)->nullable();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateAccountTypesTable
|
||||
*
|
||||
*/
|
||||
class CreateAccountTypesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('account_types');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'account_types', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->string('type', 30);
|
||||
$table->boolean('editable');
|
||||
|
||||
$table->unique('type');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateAccountsTable
|
||||
*
|
||||
*/
|
||||
class CreateAccountsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'accounts', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('account_type_id')->unsigned();
|
||||
$table->string('name', 100);
|
||||
$table->boolean('active');
|
||||
|
||||
// connect accounts to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// connect accounts to account_types
|
||||
$table->foreign('account_type_id')->references('id')->on('account_types')->onDelete('cascade');
|
||||
|
||||
// for a user, the account name must be unique.
|
||||
$table->unique(['user_id', 'account_type_id', 'name']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentsTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('components');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'components', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('name', 50);
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('class', 20);
|
||||
|
||||
// connect components to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// for a user, the component type & name must be unique.
|
||||
$table->unique(['user_id', 'class', 'name']);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePiggybanksTable
|
||||
*
|
||||
*/
|
||||
class CreatePiggybanksTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('piggybanks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'piggybanks', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->string('name', 100);
|
||||
$table->decimal('targetamount', 10, 2);
|
||||
$table->date('startdate')->nullable();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->boolean('repeats');
|
||||
$table->enum('rep_length', ['day', 'week', 'quarter', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('rep_every')->unsigned();
|
||||
$table->smallInteger('rep_times')->unsigned()->nullable();
|
||||
$table->enum('reminder', ['day', 'week', 'quarter', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('reminder_skip')->unsigned();
|
||||
$table->boolean('remind_me');
|
||||
$table->integer('order')->unsigned();
|
||||
|
||||
// connect account to piggy bank.
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
|
||||
// for an account, the name must be unique.
|
||||
$table->unique(['account_id', 'name']);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionCurrenciesTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionCurrenciesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_currencies');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_currencies', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('code', 3);
|
||||
|
||||
// code must be unique.
|
||||
$table->unique(['code']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionTypesTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionTypesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_types');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_types', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('type', 50);
|
||||
|
||||
// type must be unique.
|
||||
$table->unique(['type']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateRecurringTransactionsTable
|
||||
*
|
||||
*/
|
||||
class CreateRecurringTransactionsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('recurring_transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'recurring_transactions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('name', 50);
|
||||
$table->string('match', 255);
|
||||
$table->decimal('amount_min', 10, 2);
|
||||
$table->decimal('amount_max', 10, 2);
|
||||
$table->date('date');
|
||||
$table->boolean('active');
|
||||
|
||||
$table->boolean('automatch');
|
||||
$table->enum('repeat_freq', ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly']);
|
||||
$table->smallInteger('skip')->unsigned();
|
||||
|
||||
// connect user id to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// for a user, the name must be unique
|
||||
$table->unique(['user_id', 'name']);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionJournalsTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionJournalsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_journals');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('transaction_type_id')->unsigned();
|
||||
$table->integer('recurring_transaction_id')->unsigned()->nullable();
|
||||
$table->integer('transaction_currency_id')->unsigned();
|
||||
$table->string('description', 255)->nullable();
|
||||
$table->boolean('completed');
|
||||
$table->date('date');
|
||||
|
||||
// connect users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// connect transaction journals to transaction types
|
||||
$table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade');
|
||||
|
||||
// connect transaction journals to recurring transactions
|
||||
$table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('set null');
|
||||
|
||||
// connect transaction journals to transaction currencies
|
||||
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionsTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transactions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->integer('piggybank_id')->nullable()->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
$table->string('description', 255)->nullable();
|
||||
$table->decimal('amount', 10, 2);
|
||||
|
||||
// connect account id:
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
|
||||
// connect piggy banks
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('set null');
|
||||
|
||||
// connect transactions to transaction journals
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentTransactionTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentTransactionTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('component_transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'component_transaction', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->integer('transaction_id')->unsigned();
|
||||
|
||||
// connect to components
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
|
||||
// connect to transactions
|
||||
$table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade');
|
||||
|
||||
// combo must be unique:
|
||||
$table->unique(['component_id', 'transaction_id']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentTransactionJournalTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentTransactionJournalTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('component_transaction_journal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'component_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
|
||||
// link components with component_id
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
|
||||
// link transaction journals with transaction_journal_id
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
|
||||
// combo must be unique:
|
||||
$table->unique(['component_id', 'transaction_journal_id'], 'cid_tjid_unique');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePreferencesTable
|
||||
*
|
||||
*/
|
||||
class CreatePreferencesTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('preferences');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'preferences', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('name');
|
||||
$table->text('data');
|
||||
|
||||
// connect preferences to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// only one preference per name per user
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateSessionTable
|
||||
*
|
||||
*/
|
||||
class CreateSessionTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('sessions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'sessions', function (Blueprint $table) {
|
||||
$table->string('id')->unique();
|
||||
$table->text('payload');
|
||||
$table->integer('last_activity');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)\
|
||||
*
|
||||
*
|
||||
* Class CreateLimitsTable
|
||||
*
|
||||
*/
|
||||
class CreateLimitsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('limits');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'limits', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->decimal('amount', 10, 2);
|
||||
$table->boolean('repeats');
|
||||
$table->enum('repeat_freq', ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly']);
|
||||
|
||||
$table->unique(['component_id', 'startdate', 'repeat_freq'], 'unique_ci_combi');
|
||||
|
||||
// connect component
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateLimitRepeatTable
|
||||
*
|
||||
*/
|
||||
class CreateLimitRepeatTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('limit_repetitions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('limit_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->date('enddate');
|
||||
$table->decimal('amount', 10, 2);
|
||||
|
||||
$table->unique(['limit_id', 'startdate', 'enddate']);
|
||||
|
||||
// connect limit
|
||||
$table->foreign('limit_id')->references('id')->on('limits')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateComponentRecurringTransactionTable
|
||||
*
|
||||
*/
|
||||
class CreateComponentRecurringTransactionTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('component_recurring_transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'component_recurring_transaction', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('component_id')->unsigned();
|
||||
$table->integer('recurring_transaction_id')->unsigned();
|
||||
$table->boolean('optional');
|
||||
|
||||
// link components with component_id
|
||||
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
|
||||
|
||||
// link transaction journals with transaction_journal_id
|
||||
$table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('cascade');
|
||||
|
||||
// component and recurring transaction must be unique.
|
||||
$table->unique(['component_id', 'recurring_transaction_id'], 'cid_rtid_unique');
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePiggyInstance
|
||||
*
|
||||
*/
|
||||
class CreatePiggybankRepetitionsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('piggybank_repetitions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'piggybank_repetitions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('piggybank_id')->unsigned();
|
||||
$table->date('startdate')->nullable();
|
||||
$table->date('targetdate')->nullable();
|
||||
$table->decimal('currentamount', 10, 2);
|
||||
|
||||
$table->unique(['piggybank_id', 'startdate', 'targetdate']);
|
||||
|
||||
// connect instance to piggybank.
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreatePiggybankEventsTable
|
||||
*
|
||||
*/
|
||||
class CreatePiggybankEventsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('piggybank_events');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'piggybank_events', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('piggybank_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned()->nullable();
|
||||
|
||||
$table->date('date');
|
||||
$table->decimal('amount', 10, 2);
|
||||
|
||||
// connect instance to piggybank.
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('cascade');
|
||||
|
||||
// connect to journal:
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateRemindersTable
|
||||
*
|
||||
*/
|
||||
class CreateRemindersTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('reminders');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'reminders', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->date('enddate')->nullable();
|
||||
$table->boolean('active');
|
||||
$table->boolean('notnow')->default(0);
|
||||
$table->integer('remindersable_id')->unsigned()->nullable();
|
||||
$table->string('remindersable_type')->nullable();
|
||||
|
||||
// connect reminders to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUsersTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->string('password', 60);
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateAccountMetaTable
|
||||
*
|
||||
*/
|
||||
class CreateAccountMetaTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
Schema::drop('account_meta');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
Schema::create(
|
||||
'account_meta', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('account_id')->unsigned();
|
||||
$table->string('name');
|
||||
$table->text('data');
|
||||
|
||||
$table->unique(['account_id', 'name']);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*
|
||||
* Class CreateTransactionGroupsTable
|
||||
*
|
||||
*/
|
||||
class CreateTransactionGroupsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('transaction_groups');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create(
|
||||
'transaction_groups', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->enum('relation', ['balance']);
|
||||
|
||||
// connect reminders to users
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Class CreateTransactionGroupTransactionJournalTable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
class CreateTransactionGroupTransactionJournalTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
Schema::drop('transaction_group_transaction_journal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
Schema::create(
|
||||
'transaction_group_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('transaction_group_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
|
||||
// link to foreign tables.
|
||||
$table->foreign('transaction_group_id', 'tr_grp_id')->references('id')->on('transaction_groups')->onDelete('cascade');
|
||||
$table->foreign('transaction_journal_id', 'tr_trj_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
|
||||
// add unique.
|
||||
$table->unique(['transaction_group_id', 'transaction_journal_id'], 'tt_joined');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
497
database/migrations/2014_12_13_190730_changes_for_v321.php
Normal file
497
database/migrations/2014_12_13_190730_changes_for_v321.php
Normal file
@ -0,0 +1,497 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName) // method names are mandated by laravel.
|
||||
* @SuppressWarnings("TooManyMethods") // I'm fine with this
|
||||
*
|
||||
* Down:
|
||||
* 1. Create new Components based on Budgets.
|
||||
* 2. Create new Components based on Categories
|
||||
* 3. Recreate component_id in limits
|
||||
* 4. Update all budget_limits entries (component_id).
|
||||
* 5. Add the foreign key to component_id in budget_limits
|
||||
* 6. Drop column 'budget_id' in budget_limits.
|
||||
* 7. Create table journal_components.
|
||||
* 8. create entries for budgets in journal_components.
|
||||
* 9. create entries for categories in journal_components.
|
||||
* 10. drop table budget_journals
|
||||
* 11. drop table category_journals
|
||||
* 12. drop table budgets
|
||||
* 13. drop table categories.
|
||||
* 14. rename budget_limits to limits.
|
||||
* 15. Rename piggy_bank_events to piggybank_events
|
||||
* 16. Rename field 'budget_limit_id' to 'limit_id' in 'limit_repetitions'
|
||||
* 17. Do not recreate component_recurring_transaction
|
||||
* 18. Do not recreate component_transaction
|
||||
* 19. Do not recreate field 'piggybank_id' in 'transactions'
|
||||
* 20. Drop fields from currency table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Up:
|
||||
*
|
||||
* 1. Create new budget table.
|
||||
* 2. Create new category table.
|
||||
* 3. Create journal_budget table.
|
||||
* 4. Create journal_category table.
|
||||
* 5. Move budgets to new budgets table AND move journal_components to budget_components.
|
||||
* 6. Move categories to categories table AND move journal_components to category_components.
|
||||
* 7. Rename limits to budget_limits.
|
||||
* 8. Rename piggybank_events to piggy_bank_events
|
||||
* 9. Rename field 'limit_id' to 'budget_limit_id' in 'limit_repetitions'
|
||||
* 10. Create field budget_id in budget_limits.
|
||||
* 11. Update budget_limits with budgets (instead of components).
|
||||
* 12. drop table journal_components
|
||||
* 13. Drop table component_recurring_transaction
|
||||
* 14. Drop table component_transaction
|
||||
* 15. Drop field 'piggybank_id' from 'transactions'
|
||||
* 16. Drop field 'component_id' from 'budget_limits'
|
||||
* 17. Expand currency table with new fields.
|
||||
*
|
||||
* Class ChangesForV321
|
||||
*/
|
||||
class ChangesForV321 extends Migration
|
||||
{
|
||||
public function down()
|
||||
{
|
||||
|
||||
$this->moveBudgetsBack(); // 1.
|
||||
$this->moveCategoriesBack(); // 2.
|
||||
$this->createComponentId(); // 3.
|
||||
$this->updateComponentInBudgetLimits(); // 4.
|
||||
$this->createComponentIdForeignKey(); // 5.
|
||||
$this->dropBudgetIdColumnInBudgetLimits(); // 6.
|
||||
$createComponents = new CreateComponentTransactionJournalTable; // 7.
|
||||
$createComponents->up();
|
||||
$this->moveBackEntriesForBudgetsInJoinedTable(); // 8.
|
||||
$this->moveBackEntriesForCategoriesInJoinedTable(); // 9.
|
||||
$this->dropBudgetJournalTable(); // 10.
|
||||
$this->dropCategoryJournalTable(); // 11.
|
||||
$this->dropBudgetTable(); // 12.
|
||||
$this->dropCategoryTable(); // 13.
|
||||
$this->renameBudgetLimits(); // 14.
|
||||
$this->renamePiggyBankEvents(); // 15.
|
||||
$this->renameBudgetLimitToBudgetInRepetitions(); // 16.
|
||||
// 17, 18, 19
|
||||
$this->dropFieldsFromCurrencyTable(); // 20.
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function moveBudgetsBack()
|
||||
{
|
||||
Budget::get()->each(
|
||||
function (Budget $budget) {
|
||||
Component::firstOrCreate(
|
||||
[
|
||||
'name' => $budget->name,
|
||||
'user_id' => $budget->user_id,
|
||||
'class' => 'Budget'
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveCategoriesBack()
|
||||
{
|
||||
Category::get()->each(
|
||||
function (Category $category) {
|
||||
Component::firstOrCreate(
|
||||
[
|
||||
'name' => $category->name,
|
||||
'user_id' => $category->user_id,
|
||||
'class' => 'Category'
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createComponentId()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->integer('component_id')->unsigned();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function updateComponentInBudgetLimits()
|
||||
{
|
||||
BudgetLimit::get()->each(
|
||||
function (BudgetLimit $bl) {
|
||||
$budgetId = $bl->budget_id;
|
||||
$budget = Budget::find($budgetId);
|
||||
if ($budget) {
|
||||
$component = Component::where('class', 'Budget')->where('user_id', $budget->user_id)->where('name', $budget->name)->first();
|
||||
if ($component) {
|
||||
$bl->component_id = $component->id;
|
||||
$bl->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createComponentIdForeignKey()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->foreign('component_id', 'limits_component_id_foreign')->references('id')->on('components')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function dropBudgetIdColumnInBudgetLimits()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropForeign('bid_foreign');
|
||||
$table->dropColumn('budget_id'); // also drop foreign key!
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveBackEntriesForBudgetsInJoinedTable()
|
||||
{
|
||||
$set = DB::table('budget_transaction_journal')->get();
|
||||
foreach ($set as $entry) {
|
||||
$budget = Budget::find($entry->budget_id);
|
||||
if ($budget) {
|
||||
$component = Component::where('class', 'Budget')->where('name', $budget->name)->where('user_id', $budget->user_id)->first();
|
||||
if ($component) {
|
||||
DB::table('component_transaction_journal')->insert(
|
||||
[
|
||||
'component_id' => $component->id,
|
||||
'transaction_journal_id' => $entry->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function moveBackEntriesForCategoriesInJoinedTable()
|
||||
{
|
||||
$set = DB::table('category_transaction_journal')->get();
|
||||
foreach ($set as $entry) {
|
||||
$category = Category::find($entry->category_id);
|
||||
if ($category) {
|
||||
$component = Component::where('class', 'Category')->where('name', $category->name)->where('user_id', $category->user_id)->first();
|
||||
if ($component) {
|
||||
DB::table('component_transaction_journal')->insert(
|
||||
[
|
||||
'component_id' => $component->id,
|
||||
'transaction_journal_id' => $entry->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function dropBudgetJournalTable()
|
||||
{
|
||||
Schema::dropIfExists('budget_transaction_journal');
|
||||
}
|
||||
|
||||
public function dropCategoryJournalTable()
|
||||
{
|
||||
Schema::dropIfExists('category_transaction_journal');
|
||||
}
|
||||
|
||||
public function dropBudgetTable()
|
||||
{
|
||||
Schema::dropIfExists('budgets');
|
||||
}
|
||||
|
||||
public function dropCategoryTable()
|
||||
{
|
||||
Schema::dropIfExists('categories');
|
||||
}
|
||||
|
||||
public function renameBudgetLimits()
|
||||
{
|
||||
Schema::rename('budget_limits', 'limits');
|
||||
}
|
||||
|
||||
public function renamePiggyBankEvents()
|
||||
{
|
||||
Schema::rename('piggy_bank_events', 'piggybank_events');
|
||||
|
||||
}
|
||||
|
||||
public function renameBudgetLimitToBudgetInRepetitions()
|
||||
{
|
||||
Schema::table(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('budget_limit_id', 'limit_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function dropFieldsFromCurrencyTable()
|
||||
{
|
||||
|
||||
Schema::table(
|
||||
'transaction_currencies', function (Blueprint $table) {
|
||||
$table->dropColumn('symbol');
|
||||
$table->dropColumn('name');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->createBudgetTable(); // 1.
|
||||
$this->createCategoryTable(); // 2.
|
||||
$this->createBudgetJournalTable(); // 3
|
||||
$this->createCategoryJournalTable(); // 4.
|
||||
$this->moveBudgets(); // 5.
|
||||
$this->moveCategories(); // 6.
|
||||
$this->correctNameForBudgetLimits(); // 7.
|
||||
$this->correctNameForPiggyBankEvents(); // 8.
|
||||
$this->renameBudgetToBudgetLimitInRepetitions(); // 9.
|
||||
$this->addBudgetIdFieldToBudgetLimits(); // 10.
|
||||
$this->moveComponentIdToBudgetId(); // 11.
|
||||
$this->dropComponentJournalTable(); // 12.
|
||||
$this->dropComponentRecurringTransactionTable(); // 13.
|
||||
$this->dropComponentTransactionTable(); // 14.
|
||||
$this->dropPiggyBankIdFromTransactions(); // 15.
|
||||
$this->dropComponentIdFromBudgetLimits(); // 16.
|
||||
$this->expandCurrencyTable(); // 17.
|
||||
|
||||
}
|
||||
|
||||
public function createBudgetTable()
|
||||
{
|
||||
Schema::create(
|
||||
'budgets', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('name', 50);
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function createCategoryTable()
|
||||
{
|
||||
Schema::create(
|
||||
'categories', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->string('name', 50);
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createBudgetJournalTable()
|
||||
{
|
||||
Schema::create(
|
||||
'budget_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('budget_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
$table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
$table->unique(['budget_id', 'transaction_journal_id'], 'budid_tjid_unique');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function createCategoryJournalTable()
|
||||
{
|
||||
Schema::create(
|
||||
'category_transaction_journal', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('category_id')->unsigned();
|
||||
$table->integer('transaction_journal_id')->unsigned();
|
||||
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
|
||||
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
|
||||
$table->unique(['category_id', 'transaction_journal_id'], 'catid_tjid_unique');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveBudgets()
|
||||
{
|
||||
Component::where('class', 'Budget')->get()->each(
|
||||
function (Component $c) {
|
||||
$entry = [
|
||||
'user_id' => $c->user_id,
|
||||
'name' => $c->name
|
||||
|
||||
];
|
||||
$budget = Budget::firstOrCreate($entry);
|
||||
Log::debug('Migrated budget #' . $budget->id . ': ' . $budget->name);
|
||||
// create entry in budget_transaction_journal
|
||||
$connections = DB::table('component_transaction_journal')->where('component_id', $c->id)->get();
|
||||
foreach ($connections as $connection) {
|
||||
DB::table('budget_transaction_journal')->insert(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'transaction_journal_id' => $connection->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveCategories()
|
||||
{
|
||||
Component::where('class', 'Category')->get()->each(
|
||||
function (Component $c) {
|
||||
$entry = [
|
||||
'user_id' => $c->user_id,
|
||||
'name' => $c->name
|
||||
|
||||
];
|
||||
$category = Category::firstOrCreate($entry);
|
||||
Log::debug('Migrated category #' . $category->id . ': ' . $category->name);
|
||||
// create entry in category_transaction_journal
|
||||
$connections = DB::table('component_transaction_journal')->where('component_id', $c->id)->get();
|
||||
foreach ($connections as $connection) {
|
||||
DB::table('category_transaction_journal')->insert(
|
||||
[
|
||||
'category_id' => $category->id,
|
||||
'transaction_journal_id' => $connection->transaction_journal_id
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function correctNameForBudgetLimits()
|
||||
{
|
||||
Schema::rename('limits', 'budget_limits');
|
||||
}
|
||||
|
||||
public function correctNameForPiggyBankEvents()
|
||||
{
|
||||
Schema::rename('piggybank_events', 'piggy_bank_events');
|
||||
|
||||
}
|
||||
|
||||
public function renameBudgetToBudgetLimitInRepetitions()
|
||||
{
|
||||
Schema::table(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('limit_id', 'budget_limit_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function addBudgetIdFieldToBudgetLimits()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->integer('budget_id', false, true)->nullable()->after('updated_at');
|
||||
$table->foreign('budget_id', 'bid_foreign')->references('id')->on('budgets')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function moveComponentIdToBudgetId()
|
||||
{
|
||||
\Log::debug('Now in moveComponentIdToBudgetId()');
|
||||
BudgetLimit::get()->each(
|
||||
function (BudgetLimit $bl) {
|
||||
\Log::debug('Now at budgetLimit #' . $bl->id . ' with component_id: ' . $bl->component_id);
|
||||
$component = Component::find($bl->component_id);
|
||||
if ($component) {
|
||||
\Log::debug('Found component with id #' . $component->id . ' and name ' . $component->name);
|
||||
$budget = Budget::whereName($component->name)->whereUserId($component->user_id)->first();
|
||||
if ($budget) {
|
||||
\Log::debug('Found a budget with ID #' . $budget->id . ' and name ' . $budget->name);
|
||||
$bl->budget_id = $budget->id;
|
||||
$bl->save();
|
||||
\Log::debug('Connected budgetLimit #' . $bl->id . ' to budget_id' . $budget->id);
|
||||
} else {
|
||||
\Log::debug('Could not find a matching budget with name ' . $component->name);
|
||||
}
|
||||
} else {
|
||||
\Log::debug('Could not find a component with id ' . $bl->component_id);
|
||||
}
|
||||
}
|
||||
);
|
||||
\Log::debug('Done with moveComponentIdToBudgetId()');
|
||||
|
||||
}
|
||||
|
||||
public function dropComponentJournalTable()
|
||||
{
|
||||
Schema::dropIfExists('component_transaction_journal');
|
||||
}
|
||||
|
||||
public function dropComponentRecurringTransactionTable()
|
||||
{
|
||||
Schema::dropIfExists('component_recurring_transaction');
|
||||
}
|
||||
|
||||
public function dropComponentTransactionTable()
|
||||
{
|
||||
Schema::dropIfExists('component_transaction');
|
||||
}
|
||||
|
||||
public function dropPiggyBankIdFromTransactions()
|
||||
{
|
||||
|
||||
Schema::table(
|
||||
'transactions', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('transactions', 'piggybank_id')) {
|
||||
$table->dropForeign('transactions_piggybank_id_foreign');
|
||||
$table->dropColumn('piggybank_id');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function dropComponentIdFromBudgetLimits()
|
||||
{
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropForeign('limits_component_id_foreign');
|
||||
$table->dropColumn('component_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function expandCurrencyTable()
|
||||
{
|
||||
Schema::table(
|
||||
'transaction_currencies', function (Blueprint $table) {
|
||||
$table->string('name', 48)->nullable();
|
||||
$table->string('symbol', 8)->nullable();
|
||||
}
|
||||
);
|
||||
\DB::update('UPDATE `transaction_currencies` SET `symbol` = "€", `name` = "Euro" WHERE `code` = "EUR";');
|
||||
}
|
||||
|
||||
|
||||
}
|
172
database/migrations/2014_12_24_191544_changes_for_v322.php
Normal file
172
database/migrations/2014_12_24_191544_changes_for_v322.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
* @SuppressWarnings("MethodLength") // I don't mind this in case of migrations.
|
||||
|
||||
*
|
||||
* Class ChangesForV322
|
||||
*/
|
||||
class ChangesForV322 extends Migration
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// rename tables:
|
||||
Schema::rename('piggy_bank_repetitions', 'piggybank_repetitions');
|
||||
Schema::rename('piggy_banks', 'piggybanks');
|
||||
|
||||
// rename fields
|
||||
Schema::table(
|
||||
'piggy_bank_events', function (Blueprint $table) {
|
||||
$table->renameColumn('piggy_bank_id', 'piggybank_id');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'piggybank_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('piggy_bank_id', 'piggybank_id');
|
||||
}
|
||||
);
|
||||
|
||||
// remove soft delete to piggy banks
|
||||
Schema::table(
|
||||
'piggybanks', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
}
|
||||
);
|
||||
|
||||
// drop keys from bills (foreign bills_uid_for and unique uid_name_unique)
|
||||
Schema::table(
|
||||
'bills', function (Blueprint $table) {
|
||||
$table->dropForeign('bills_uid_for');
|
||||
$table->dropUnique('uid_name_unique');
|
||||
}
|
||||
);
|
||||
// drop foreign key from transaction_journals (bill_id_foreign)
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->dropForeign('bill_id_foreign');
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// drop foreign key from budget_limits:
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropForeign('bid_foreign');
|
||||
$table->dropUnique('unique_bl_combi');
|
||||
}
|
||||
);
|
||||
|
||||
// rename bills to recurring_transactions
|
||||
Schema::rename('bills', 'recurring_transactions');
|
||||
// recreate foreign key recurring_transactions_user_id_foreign in recurring_transactions
|
||||
// recreate unique recurring_transactions_user_id_name_unique in recurring_transactions
|
||||
Schema::table(
|
||||
'recurring_transactions', function (Blueprint $table) {
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unique(['user_id', 'name']);
|
||||
}
|
||||
);
|
||||
|
||||
// rename bill_id to recurring_transaction_id
|
||||
// recreate foreign transaction_journals_recurring_transaction_id_foreign in transaction_journals
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->renameColumn('bill_id', 'recurring_transaction_id');
|
||||
$table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// rename tables:
|
||||
Schema::rename('piggybank_repetitions', 'piggy_bank_repetitions');
|
||||
Schema::rename('piggybanks', 'piggy_banks');
|
||||
|
||||
// recreate it the correct way:
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->unique(['budget_id', 'startdate', 'repeat_freq'], 'unique_bl_combi');
|
||||
}
|
||||
);
|
||||
|
||||
// rename fields
|
||||
Schema::table(
|
||||
'piggy_bank_events', function (Blueprint $table) {
|
||||
$table->renameColumn('piggybank_id', 'piggy_bank_id');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'piggy_bank_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('piggybank_id', 'piggy_bank_id');
|
||||
}
|
||||
);
|
||||
|
||||
// add soft delete to piggy banks
|
||||
Schema::table(
|
||||
'piggy_banks', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
}
|
||||
);
|
||||
|
||||
// rename everything related to recurring transactions, aka bills:
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
|
||||
|
||||
// drop relation
|
||||
$table->dropForeign('transaction_journals_recurring_transaction_id_foreign');
|
||||
// rename column
|
||||
$table->renameColumn('recurring_transaction_id', 'bill_id');
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'recurring_transactions', function (Blueprint $table) {
|
||||
$table->dropForeign('recurring_transactions_user_id_foreign');
|
||||
$table->dropUnique('recurring_transactions_user_id_name_unique');
|
||||
}
|
||||
);
|
||||
// rename table:
|
||||
Schema::rename('recurring_transactions', 'bills');
|
||||
|
||||
// recreate foreign relation:
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->foreign('bill_id', 'bill_id_foreign')->references('id')->on('bills')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
|
||||
// recreate more foreign relations.
|
||||
Schema::table(
|
||||
'bills', function (Blueprint $table) {
|
||||
// connect user id to users
|
||||
$table->foreign('user_id', 'bills_uid_for')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// for a user, the name must be unique
|
||||
$table->unique(['user_id', 'name'], 'uid_name_unique');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
62
database/migrations/2015_01_18_082406_changes_for_v325.php
Normal file
62
database/migrations/2015_01_18_082406_changes_for_v325.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
* @SuppressWarnings("MethodLength") // I don't mind this in case of migrations.
|
||||
*
|
||||
* Class ChangesForV325
|
||||
*/
|
||||
class ChangesForV325 extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
|
||||
// delete an old index:
|
||||
try {
|
||||
Schema::table(
|
||||
'budget_limits', function (Blueprint $table) {
|
||||
$table->dropUnique('unique_ci_combi');
|
||||
|
||||
}
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
// don't care.
|
||||
}
|
||||
|
||||
// allow journal descriptions to be encrypted.
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->boolean('encrypted')->default(0);
|
||||
|
||||
}
|
||||
);
|
||||
try {
|
||||
DB::update('ALTER TABLE `transaction_journals` MODIFY `description` VARCHAR(1024)');
|
||||
} catch (PDOException $e) {
|
||||
// don't care.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
25
database/seeds/AccountTypeSeeder.php
Normal file
25
database/seeds/AccountTypeSeeder.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
|
||||
/**
|
||||
* Class AccountTypeSeeder
|
||||
*/
|
||||
class AccountTypeSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::table('account_types')->delete();
|
||||
|
||||
AccountType::create(['type' => 'Default account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Cash account', 'editable' => false]);
|
||||
AccountType::create(['type' => 'Asset account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Expense account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Revenue account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Initial balance account', 'editable' => false]);
|
||||
AccountType::create(['type' => 'Beneficiary account', 'editable' => true]);
|
||||
AccountType::create(['type' => 'Import account', 'editable' => false]);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,20 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DatabaseSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
// $this->call('UserTableSeeder');
|
||||
}
|
||||
$this->call('AccountTypeSeeder');
|
||||
$this->call('TransactionCurrencySeeder');
|
||||
$this->call('TransactionTypeSeeder');
|
||||
|
||||
if (App::environment() == 'testing' || App::environment() == 'homestead') {
|
||||
$this->call('TestDataSeeder');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
610
database/seeds/TestDataSeeder.php
Normal file
610
database/seeds/TestDataSeeder.php
Normal file
@ -0,0 +1,610 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
* @SuppressWarnings("TooManyMethods") // I'm fine with this
|
||||
* @SuppressWarnings("CouplingBetweenObjects") // I'm fine with this
|
||||
* @SuppressWarnings("MethodLength") // I'm fine with this
|
||||
*
|
||||
* Class TestDataSeeder
|
||||
*/
|
||||
class TestDataSeeder extends Seeder
|
||||
{
|
||||
/** @var string */
|
||||
public $eom;
|
||||
/** @var string */
|
||||
public $neom;
|
||||
/** @var string */
|
||||
public $nsom;
|
||||
/** @var string */
|
||||
public $som;
|
||||
/** @var string */
|
||||
public $today;
|
||||
/** @var string */
|
||||
public $yaeom;
|
||||
/** @var string */
|
||||
public $yasom;
|
||||
/** @var Carbon */
|
||||
protected $_endOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_nextEndOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_nextStartOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_startOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_today;
|
||||
/** @var Carbon */
|
||||
protected $_yearAgoEndOfMonth;
|
||||
/** @var Carbon */
|
||||
protected $_yearAgoStartOfMonth;
|
||||
|
||||
/**
|
||||
* A whole bunch of times and dates.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_startOfMonth = Carbon::now()->startOfMonth();
|
||||
$this->som = $this->_startOfMonth->format('Y-m-d');
|
||||
$this->_endOfMonth = Carbon::now()->endOfMonth();
|
||||
$this->eom = $this->_endOfMonth->format('Y-m-d');
|
||||
$this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();
|
||||
$this->nsom = $this->_nextStartOfMonth->format('Y-m-d');
|
||||
$this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();
|
||||
$this->neom = $this->_nextEndOfMonth->format('Y-m-d');
|
||||
$this->_yearAgoStartOfMonth = Carbon::now()->subYear()->startOfMonth();
|
||||
$this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d');
|
||||
$this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();
|
||||
$this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');
|
||||
$this->_today = Carbon::now();
|
||||
$this->today = $this->_today->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dates are always this month, the start of this month or earlier.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->createUsers();
|
||||
$this->createAssetAccounts();
|
||||
$this->createBudgets();
|
||||
$this->createCategories();
|
||||
$this->createPiggyBanks();
|
||||
$this->createReminders();
|
||||
$this->createRecurringTransactions();
|
||||
$this->createBills();
|
||||
$this->createExpenseAccounts();
|
||||
$this->createRevenueAccounts();
|
||||
|
||||
$current = clone $this->_yearAgoStartOfMonth;
|
||||
while ($current <= $this->_startOfMonth) {
|
||||
|
||||
// create expenses for rent, utilities, TV, phone on the 1st of the month.
|
||||
$this->createMonthlyExpenses(clone $current);
|
||||
$this->createGroceries(clone $current);
|
||||
$this->createBigExpense(clone $current);
|
||||
|
||||
echo 'Created test-content for ' . $current->format('F Y') . "\n";
|
||||
$current->addMonth();
|
||||
}
|
||||
$this->createPiggyBankEvent();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createUsers()
|
||||
{
|
||||
User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
|
||||
User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
|
||||
User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createAssetAccounts()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$assetType = AccountType::whereType('Asset account')->first();
|
||||
$ibType = AccountType::whereType('Initial balance account')->first();
|
||||
$obType = TransactionType::whereType('Opening balance')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
|
||||
|
||||
$acc_a = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
|
||||
$acc_b = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
|
||||
$acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
|
||||
|
||||
$acc_d = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Checking account initial balance', 'active' => 0]);
|
||||
$acc_e = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]);
|
||||
$acc_f = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Delete me initial balance', 'active' => 0]);
|
||||
|
||||
$this->createJournal(
|
||||
['from' => $acc_d, 'to' => $acc_a, 'amount' => 4000, 'transactionType' => $obType, 'description' => 'Initial Balance for Checking account',
|
||||
'date' => $this->yasom, 'transactionCurrency' => $euro]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $acc_e, 'to' => $acc_b, 'amount' => 10000, 'transactionType' => $obType, 'description' => 'Initial Balance for Savings account',
|
||||
'date' => $this->yasom, 'transactionCurrency' => $euro]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $acc_f, 'to' => $acc_c, 'amount' => 100, 'transactionType' => $obType, 'description' => 'Initial Balance for Delete me',
|
||||
'date' => $this->yasom, 'transactionCurrency' => $euro]
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function createJournal(array $data)
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$billID = isset($data['bill']) ? $data['bill']->id : null;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => $data['transactionType']->id,
|
||||
'transaction_currency_id' => $data['transactionCurrency']->id,
|
||||
'bill_id' => $billID,
|
||||
'description' => $data['description'],
|
||||
'completed' => 1,
|
||||
'date' => $data['date']
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(['account_id' => $data['from']->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount'] * -1]);
|
||||
Transaction::create(['account_id' => $data['to']->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount']]);
|
||||
|
||||
if (isset($data['budget'])) {
|
||||
$journal->budgets()->save($data['budget']);
|
||||
}
|
||||
if (isset($data['category'])) {
|
||||
$journal->categories()->save($data['category']);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createBudgets()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
$groceries = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
|
||||
$bills = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
|
||||
$deleteMe = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']);
|
||||
Budget::create(['user_id' => $user->id, 'name' => 'Budget without repetition']);
|
||||
$groceriesLimit = BudgetLimit::create(
|
||||
['startdate' => $this->som, 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $groceries->id]
|
||||
);
|
||||
$billsLimit = BudgetLimit::create(
|
||||
['startdate' => $this->som, 'amount' => 202, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $bills->id]
|
||||
);
|
||||
$deleteMeLimit = BudgetLimit::create(
|
||||
['startdate' => $this->som, 'amount' => 203, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $deleteMe->id]
|
||||
);
|
||||
|
||||
// and because we have no filters, some repetitions:
|
||||
LimitRepetition::create(['budget_limit_id' => $groceriesLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 201]);
|
||||
LimitRepetition::create(['budget_limit_id' => $billsLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 202]);
|
||||
LimitRepetition::create(['budget_limit_id' => $deleteMeLimit->id, 'startdate' => $this->som, 'enddate' => $this->eom, 'amount' => 203]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createCategories()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
Category::create(['user_id' => $user->id, 'name' => 'DailyGroceries']);
|
||||
Category::create(['user_id' => $user->id, 'name' => 'Lunch']);
|
||||
Category::create(['user_id' => $user->id, 'name' => 'House']);
|
||||
Category::create(['user_id' => $user->id, 'name' => 'Delete me']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createPiggyBanks()
|
||||
{
|
||||
// account
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
|
||||
// some dates
|
||||
$endDate = clone $this->_startOfMonth;
|
||||
$nextYear = clone $this->_startOfMonth;
|
||||
|
||||
$endDate->addMonths(4);
|
||||
$nextYear->addYear()->subDay();
|
||||
|
||||
$next = $nextYear->format('Y-m-d');
|
||||
$end = $endDate->format('Y-m-d');
|
||||
|
||||
// piggy bank
|
||||
$newCamera = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'New camera',
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => null,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
// and some events!
|
||||
PiggyBankEvent::create(['piggy_bank_id' => $newCamera->id, 'date' => $this->som, 'amount' => 100]);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $newCamera->id, 'startdate' => $this->som, 'targetdate' => null, 'currentamount' => 100]);
|
||||
|
||||
|
||||
$newClothes = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'New clothes',
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $end,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
PiggyBankEvent::create(['piggy_bank_id' => $newClothes->id, 'date' => $this->som, 'amount' => 100]);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $newClothes->id, 'startdate' => $this->som, 'targetdate' => $end, 'currentamount' => 100]);
|
||||
|
||||
// weekly reminder piggy bank
|
||||
$weekly = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'Weekly reminder for clothes',
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $next,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => 'week',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 1,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $weekly->id, 'startdate' => $this->som, 'targetdate' => $next, 'currentamount' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createReminders()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
// for weekly piggy bank (clothes)
|
||||
$nextWeek = clone $this->_startOfMonth;
|
||||
$piggyBank = PiggyBank::whereName('New clothes')->orderBy('id', 'DESC')->first();
|
||||
$nextWeek->addWeek();
|
||||
$week = $nextWeek->format('Y-m-d');
|
||||
|
||||
Reminder::create(
|
||||
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 1, 'notnow' => 0,
|
||||
'remindersable_id' => $piggyBank->id, 'remindersable_type' => 'PiggyBank']
|
||||
);
|
||||
|
||||
// a fake reminder::
|
||||
Reminder::create(
|
||||
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $week, 'active' => 0, 'notnow' => 0, 'remindersable_id' => 40,
|
||||
'remindersable_type' => 'Transaction']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createRecurringTransactions()
|
||||
{
|
||||
// account
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
$recurring = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'name' => 'Nieuwe spullen',
|
||||
'targetamount' => 1000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $this->eom,
|
||||
'repeats' => 1,
|
||||
'rep_length' => 'month',
|
||||
'rep_every' => 0,
|
||||
'rep_times' => 0,
|
||||
'reminder' => 'month',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 1,
|
||||
'order' => 0,
|
||||
]
|
||||
);
|
||||
PiggyBankRepetition::create(['piggy_bank_id' => $recurring->id, 'startdate' => $this->som, 'targetdate' => $this->eom, 'currentamount' => 0]);
|
||||
PiggyBankRepetition::create(
|
||||
['piggy_bank_id' => $recurring->id, 'startdate' => $this->nsom, 'targetdate' => $this->neom, 'currentamount' => 0]
|
||||
);
|
||||
Reminder::create(
|
||||
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $this->neom, 'active' => 1, 'notnow' => 0,
|
||||
'remindersable_id' => $recurring->id, 'remindersable_type' => 'PiggyBank']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createBills()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
// bill
|
||||
Bill::create(
|
||||
['user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord', 'amount_min' => 700, 'amount_max' => 900, 'date' => $this->som,
|
||||
'active' => 1, 'automatch' => 1, 'repeat_freq' => 'monthly', 'skip' => 0,]
|
||||
);
|
||||
|
||||
// bill
|
||||
Bill::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Gas licht',
|
||||
'match' => 'no,match',
|
||||
'amount_min' => 500, 'amount_max' => 700,
|
||||
'date' => $this->som,
|
||||
'active' => 1, 'automatch' => 1,
|
||||
'repeat_freq' => 'monthly', 'skip' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
// bill
|
||||
Bill::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Something something',
|
||||
'match' => 'mumble,mumble',
|
||||
'amount_min' => 500,
|
||||
'amount_max' => 700,
|
||||
'date' => $this->som,
|
||||
'active' => 0,
|
||||
'automatch' => 1,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createExpenseAccounts()
|
||||
{
|
||||
//// create expenses for rent, utilities, water, TV, phone on the 1st of the month.
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$expenseType = AccountType::whereType('Expense account')->first();
|
||||
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Land lord', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Utilities company', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Water company', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'TV company', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Phone agency', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Super savers', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Groceries House', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Lunch House', 'active' => 1]);
|
||||
|
||||
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Buy More', 'active' => 1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createRevenueAccounts()
|
||||
{
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
$revenueType = AccountType::whereType('Revenue account')->first();
|
||||
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
|
||||
Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Second job employer', 'active' => 1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function createMonthlyExpenses(Carbon $date)
|
||||
{
|
||||
// get some objects from the database:
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
|
||||
$utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
|
||||
$television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();
|
||||
$phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();
|
||||
$employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();
|
||||
$bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
|
||||
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$deposit = TransactionType::whereType('Deposit')->first();
|
||||
$transfer = TransactionType::whereType('Transfer')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$rentBill = Bill::where('name', 'Rent')->first();
|
||||
$cur = $date->format('Y-m-d');
|
||||
$formatted = $date->format('F Y');
|
||||
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $landLord, 'amount' => 800, 'transactionType' => $withdrawal, 'description' => 'Rent for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house, 'bill' => $rentBill]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $utilities, 'amount' => 150, 'transactionType' => $withdrawal, 'description' => 'Utilities for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house,]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $television, 'amount' => 50, 'transactionType' => $withdrawal, 'description' => 'TV for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house,]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $phone, 'amount' => 50, 'transactionType' => $withdrawal, 'description' => 'Phone bill for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills, 'category' => $house,]
|
||||
);
|
||||
|
||||
// two transactions. One without a budget, one without a category.
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $phone, 'amount' => 10, 'transactionType' => $withdrawal,
|
||||
'description' => 'Extra charges on phone bill for ' . $formatted, 'date' => $cur, 'transactionCurrency' => $euro, 'category' => $house]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $television, 'amount' => 5, 'transactionType' => $withdrawal,
|
||||
'description' => 'Extra charges on TV bill for ' . $formatted, 'date' => $cur, 'transactionCurrency' => $euro, 'budget' => $bills]
|
||||
);
|
||||
|
||||
// income from job:
|
||||
$this->createJournal(
|
||||
['from' => $employer, 'to' => $checking, 'amount' => rand(3500, 4000), 'transactionType' => $deposit, 'description' => 'Salary for ' . $formatted,
|
||||
'date' => $cur, 'transactionCurrency' => $euro]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $savings, 'amount' => 2000, 'transactionType' => $transfer,
|
||||
'description' => 'Salary to savings account in ' . $formatted, 'date' => $cur, 'transactionCurrency' => $euro]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function createGroceries(Carbon $date)
|
||||
{
|
||||
// variables we need:
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$shopOne = Account::whereName('Groceries House')->orderBy('id', 'DESC')->first();
|
||||
$shopTwo = Account::whereName('Super savers')->orderBy('id', 'DESC')->first();
|
||||
$lunchHouse = Account::whereName('Lunch House')->orderBy('id', 'DESC')->first();
|
||||
$lunch = Category::whereName('Lunch')->orderBy('id', 'DESC')->first();
|
||||
$daily = Category::whereName('DailyGroceries')->orderBy('id', 'DESC')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
|
||||
|
||||
|
||||
$shops = [$shopOne, $shopTwo];
|
||||
|
||||
// create groceries and lunch (daily, between 5 and 10 euro).
|
||||
$mStart = clone $date;
|
||||
$mEnd = clone $date;
|
||||
$mEnd->endOfMonth();
|
||||
while ($mStart <= $mEnd) {
|
||||
$mFormat = $mStart->format('Y-m-d');
|
||||
$shop = $shops[rand(0, 1)];
|
||||
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $shop, 'amount' => (rand(500, 1000) / 100), 'transactionType' => $withdrawal, 'description' => 'Groceries',
|
||||
'date' => $mFormat, 'transactionCurrency' => $euro, 'category' => $daily, 'budget' => $groceries]
|
||||
);
|
||||
$this->createJournal(
|
||||
['from' => $checking, 'to' => $lunchHouse, 'amount' => (rand(200, 600) / 100), 'transactionType' => $withdrawal, 'description' => 'Lunch',
|
||||
'date' => $mFormat, 'transactionCurrency' => $euro, 'category' => $lunch, 'budget' => $groceries]
|
||||
);
|
||||
|
||||
$mStart->addDay();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
*/
|
||||
public function createBigExpense($date)
|
||||
{
|
||||
$date->addDays(12);
|
||||
$dollar = TransactionCurrency::whereCode('USD')->first();
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$buyMore = Account::whereName('Buy More')->orderBy('id', 'DESC')->first();
|
||||
$withdrawal = TransactionType::whereType('Withdrawal')->first();
|
||||
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
|
||||
|
||||
|
||||
// create some big expenses, move some money around.
|
||||
$amount = rand(500, 2000);
|
||||
|
||||
$one = $this->createJournal(
|
||||
['from' => $savings, 'to' => $checking, 'amount' => $amount, 'transactionType' => $withdrawal,
|
||||
'description' => 'Money for big expense in ' . $date->format('F Y'), 'date' => $date->format('Y-m-d'), 'transactionCurrency' => $dollar]
|
||||
);
|
||||
$two = $this->createJournal(
|
||||
['from' => $checking, 'to' => $buyMore, 'amount' => $amount, 'transactionType' => $withdrawal,
|
||||
'description' => 'Big expense in ' . $date->format('F Y'), 'date' => $date->format('Y-m-d'), 'transactionCurrency' => $dollar]
|
||||
);
|
||||
$group = TransactionGroup::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'relation' => 'balance'
|
||||
]
|
||||
);
|
||||
$group->transactionjournals()->save($one);
|
||||
$group->transactionjournals()->save($two);
|
||||
$group->save();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function createPiggyBankEvent()
|
||||
{
|
||||
// piggy bank event
|
||||
// add money to this piggy bank
|
||||
// create a piggy bank event to match:
|
||||
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
|
||||
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
|
||||
$transfer = TransactionType::whereType('Transfer')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
|
||||
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
|
||||
$piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
|
||||
$intoPiggy = $this->createJournal(
|
||||
['from' => $checking, 'to' => $savings, 'amount' => 100, 'transactionType' => $transfer, 'description' => 'Money for piggy',
|
||||
'date' => $this->yaeom, 'transactionCurrency' => $euro, 'category' => $house, 'budget' => $groceries]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $piggyBank->id,
|
||||
'transaction_journal_id' => $intoPiggy->id,
|
||||
'date' => $this->yaeom,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
18
database/seeds/TransactionCurrencySeeder.php
Normal file
18
database/seeds/TransactionCurrencySeeder.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
/**
|
||||
* Class TransactionCurrencySeeder
|
||||
*/
|
||||
class TransactionCurrencySeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::table('transaction_currencies')->delete();
|
||||
|
||||
TransactionCurrency::create(['code' => 'EUR','name' => 'Euro','symbol' => '€']);
|
||||
TransactionCurrency::create(['code' => 'USD','name' => 'US Dollar','symbol' => '$']);
|
||||
TransactionCurrency::create(['code' => 'HUF','name' => 'Hungarian forint','symbol' => 'Ft']);
|
||||
}
|
||||
|
||||
}
|
20
database/seeds/TransactionTypeSeeder.php
Normal file
20
database/seeds/TransactionTypeSeeder.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Class TransactionTypeSeeder
|
||||
*/
|
||||
class TransactionTypeSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
||||
DB::table('transaction_types')->delete();
|
||||
|
||||
TransactionType::create(['type' => 'Withdrawal']);
|
||||
TransactionType::create(['type' => 'Deposit']);
|
||||
TransactionType::create(['type' => 'Transfer']);
|
||||
TransactionType::create(['type' => 'Opening balance']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user