2015-02-06 04:41:00 +01:00
|
|
|
<?php
|
2016-01-16 09:15:24 +01:00
|
|
|
|
2016-01-20 09:15:33 +01:00
|
|
|
use Carbon\Carbon;
|
2016-01-17 07:18:35 +01:00
|
|
|
use FireflyIII\Models\Account;
|
2016-01-20 10:47:29 +01:00
|
|
|
use FireflyIII\Models\Attachment;
|
2016-01-20 09:31:24 +01:00
|
|
|
use FireflyIII\Models\Category;
|
2016-01-24 16:05:14 +01:00
|
|
|
use FireflyIII\Models\Role;
|
2016-01-20 10:47:29 +01:00
|
|
|
use FireflyIII\Models\Transaction;
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2016-01-30 07:36:11 +01:00
|
|
|
use FireflyIII\Support\Migration\TestData;
|
2016-01-16 09:16:26 +01:00
|
|
|
use FireflyIII\User;
|
2015-02-11 07:35:10 +01:00
|
|
|
use Illuminate\Database\Seeder;
|
2015-02-06 04:41:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TestDataSeeder
|
|
|
|
*/
|
|
|
|
class TestDataSeeder extends Seeder
|
|
|
|
{
|
2016-01-24 20:38:58 +01:00
|
|
|
/** @var Carbon */
|
|
|
|
public $start;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TestDataSeeder constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->start = Carbon::create()->subYear()->startOfYear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-06 04:41:00 +01:00
|
|
|
/**
|
2016-01-16 09:15:24 +01:00
|
|
|
* Run the database seeds.
|
2015-06-29 15:23:50 +02:00
|
|
|
*
|
2016-01-16 09:15:24 +01:00
|
|
|
* @return void
|
2015-02-06 04:41:00 +01:00
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2016-01-29 13:24:33 +01:00
|
|
|
$user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
2016-01-28 21:50:20 +01:00
|
|
|
User::create(['email' => 'thegrumpydictator+empty@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
2016-02-04 11:00:26 +01:00
|
|
|
User::create(['email' => 'thegrumpydictator+deleteme@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
2016-01-17 07:18:35 +01:00
|
|
|
|
2016-01-24 16:05:14 +01:00
|
|
|
|
|
|
|
$admin = Role::where('name', 'owner')->first();
|
|
|
|
$user->attachRole($admin);
|
|
|
|
|
|
|
|
|
2016-01-17 07:18:35 +01:00
|
|
|
// create asset accounts for user #1.
|
2016-01-29 13:24:33 +01:00
|
|
|
TestData::createAssetAccounts($user);
|
2016-01-20 09:15:33 +01:00
|
|
|
|
2016-01-20 15:27:53 +01:00
|
|
|
// create bills for user #1
|
2016-01-29 13:24:33 +01:00
|
|
|
TestData::createBills($user);
|
2016-01-20 09:15:33 +01:00
|
|
|
|
|
|
|
// create some budgets for user #1
|
2016-02-04 11:00:26 +01:00
|
|
|
TestData::createBudgets($user);
|
2016-01-20 09:15:33 +01:00
|
|
|
|
2016-02-04 11:07:34 +01:00
|
|
|
// create budget limits for these budgets
|
|
|
|
TestData::createBudgetLimit($user, new Carbon, 'Groceries', 400);
|
|
|
|
TestData::createBudgetLimit($user, new Carbon, 'Bills', 1000);
|
|
|
|
TestData::createBudgetLimit($user, new Carbon, 'Car', 100);
|
|
|
|
|
2016-01-20 09:15:33 +01:00
|
|
|
// create some categories for user #1
|
|
|
|
$this->createCategories($user);
|
2016-01-20 09:31:24 +01:00
|
|
|
|
|
|
|
// create some piggy banks for user #1
|
2016-01-29 13:24:33 +01:00
|
|
|
TestData::createPiggybanks($user);
|
2016-01-20 10:47:29 +01:00
|
|
|
|
|
|
|
// create some expense accounts for user #1
|
|
|
|
$this->createExpenseAccounts($user);
|
|
|
|
|
|
|
|
// create some revenue accounts for user #1
|
|
|
|
$this->createRevenueAccounts($user);
|
|
|
|
|
|
|
|
// create journal + attachment:
|
|
|
|
$this->createAttachments($user);
|
2016-01-24 20:38:58 +01:00
|
|
|
|
|
|
|
// create opening balance for savings account:
|
|
|
|
$this->openingBalanceSavings($user);
|
2016-02-04 11:00:26 +01:00
|
|
|
|
|
|
|
// need at least one rule group and one rule:
|
|
|
|
TestData::createRules($user);
|
|
|
|
|
|
|
|
// create a tag:
|
|
|
|
TestData::createTags($user);
|
2016-01-17 07:18:35 +01:00
|
|
|
}
|
2016-01-30 07:36:11 +01:00
|
|
|
|
2016-01-24 20:38:58 +01:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
private function createAttachments(User $user)
|
|
|
|
{
|
|
|
|
|
2016-01-29 13:24:33 +01:00
|
|
|
$toAccount = TestData::findAccount($user, 'TestData Checking Account');
|
|
|
|
$fromAccount = TestData::findAccount($user, 'Job');
|
2016-01-24 20:38:58 +01:00
|
|
|
|
|
|
|
$journal = TransactionJournal::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'transaction_type_id' => 2,
|
|
|
|
'transaction_currency_id' => 1,
|
|
|
|
'description' => 'Some journal for attachment',
|
|
|
|
'completed' => 1,
|
2016-02-04 11:00:26 +01:00
|
|
|
'date' => $this->start->format('Y-m-d'),
|
2016-01-24 20:38:58 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
Transaction::create(
|
|
|
|
[
|
|
|
|
'account_id' => $fromAccount->id,
|
|
|
|
'transaction_journal_id' => $journal->id,
|
|
|
|
'amount' => -100,
|
|
|
|
|
|
|
|
]
|
|
|
|
);
|
|
|
|
Transaction::create(
|
|
|
|
[
|
|
|
|
'account_id' => $toAccount->id,
|
|
|
|
'transaction_journal_id' => $journal->id,
|
|
|
|
'amount' => 100,
|
|
|
|
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// and now attachments
|
|
|
|
$encrypted = Crypt::encrypt('I are secret');
|
|
|
|
Attachment::create(
|
|
|
|
[
|
|
|
|
'attachable_id' => $journal->id,
|
|
|
|
'attachable_type' => 'FireflyIII\Models\TransactionJournal',
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'md5' => md5('Hallo'),
|
|
|
|
'filename' => 'empty-file.txt',
|
|
|
|
'title' => 'Empty file',
|
|
|
|
'description' => 'This file is empty',
|
|
|
|
'notes' => 'What notes',
|
|
|
|
'mime' => 'text/plain',
|
|
|
|
'size' => strlen($encrypted),
|
|
|
|
'uploaded' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// and now attachment.
|
|
|
|
Attachment::create(
|
|
|
|
[
|
|
|
|
'attachable_id' => $journal->id,
|
|
|
|
'attachable_type' => 'FireflyIII\Models\TransactionJournal',
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'md5' => md5('Ook hallo'),
|
|
|
|
'filename' => 'empty-file-2.txt',
|
|
|
|
'title' => 'Empty file 2',
|
|
|
|
'description' => 'This file is empty too',
|
|
|
|
'notes' => 'What notes do',
|
|
|
|
'mime' => 'text/plain',
|
|
|
|
'size' => strlen($encrypted),
|
|
|
|
'uploaded' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// echo crypted data to the file.
|
|
|
|
file_put_contents(storage_path('upload/at-1.data'), $encrypted);
|
|
|
|
file_put_contents(storage_path('upload/at-2.data'), $encrypted);
|
|
|
|
|
|
|
|
}
|
2016-01-30 07:36:11 +01:00
|
|
|
|
2016-01-20 09:15:33 +01:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
private function createCategories(User $user)
|
|
|
|
{
|
|
|
|
Category::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
|
|
|
|
Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
|
|
|
|
}
|
2016-01-20 09:31:24 +01:00
|
|
|
|
2016-01-24 20:38:58 +01:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
private function createExpenseAccounts(User $user)
|
|
|
|
{
|
|
|
|
$expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl',
|
|
|
|
'coolblue', 'Shell',
|
|
|
|
'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord'];
|
|
|
|
foreach ($expenses as $name) {
|
|
|
|
// create account:
|
|
|
|
Account::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'account_type_id' => 4,
|
|
|
|
'name' => $name,
|
|
|
|
'active' => 1,
|
|
|
|
'encrypted' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-20 10:47:29 +01:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
2016-01-24 20:38:58 +01:00
|
|
|
private function createRevenueAccounts(User $user)
|
2016-01-20 10:47:29 +01:00
|
|
|
{
|
2016-01-24 20:38:58 +01:00
|
|
|
$revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google'];
|
|
|
|
foreach ($revenues as $name) {
|
2016-01-20 10:47:29 +01:00
|
|
|
// create account:
|
|
|
|
Account::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
2016-01-24 20:38:58 +01:00
|
|
|
'account_type_id' => 5,
|
2016-01-20 10:47:29 +01:00
|
|
|
'name' => $name,
|
|
|
|
'active' => 1,
|
|
|
|
'encrypted' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
2016-01-24 20:38:58 +01:00
|
|
|
private function openingBalanceSavings(User $user)
|
2016-01-20 10:47:29 +01:00
|
|
|
{
|
2016-01-24 20:38:58 +01:00
|
|
|
// opposing account for opening balance:
|
|
|
|
$opposing = Account::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'account_type_id' => 6,
|
|
|
|
'name' => 'Opposing for savings',
|
|
|
|
'active' => 1,
|
|
|
|
'encrypted' => 1,
|
|
|
|
]
|
|
|
|
);
|
2016-01-20 10:47:29 +01:00
|
|
|
|
2016-01-24 20:38:58 +01:00
|
|
|
// savings
|
2016-01-29 13:24:33 +01:00
|
|
|
$savings = TestData::findAccount($user, 'TestData Savings');
|
2016-01-20 10:47:29 +01:00
|
|
|
|
|
|
|
$journal = TransactionJournal::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
2016-01-24 20:38:58 +01:00
|
|
|
'transaction_type_id' => 4,
|
2016-01-20 10:47:29 +01:00
|
|
|
'transaction_currency_id' => 1,
|
2016-01-24 20:38:58 +01:00
|
|
|
'description' => 'Opening balance for savings account',
|
2016-01-20 10:47:29 +01:00
|
|
|
'completed' => 1,
|
2016-01-24 20:38:58 +01:00
|
|
|
'date' => $this->start->format('Y-m-d'),
|
2016-01-20 10:47:29 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2016-01-24 20:38:58 +01:00
|
|
|
// transactions
|
2016-01-20 10:47:29 +01:00
|
|
|
Transaction::create(
|
|
|
|
[
|
2016-01-29 13:24:33 +01:00
|
|
|
'account_id' => $opposing->id,
|
2016-01-20 10:47:29 +01:00
|
|
|
'transaction_journal_id' => $journal->id,
|
2016-01-29 13:24:33 +01:00
|
|
|
'amount' => -10000,
|
2016-01-20 10:47:29 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2016-01-24 20:38:58 +01:00
|
|
|
Transaction::create(
|
2016-01-20 10:47:29 +01:00
|
|
|
[
|
2016-01-29 13:24:33 +01:00
|
|
|
'account_id' => $savings->id,
|
2016-01-24 20:38:58 +01:00
|
|
|
'transaction_journal_id' => $journal->id,
|
2016-01-29 13:24:33 +01:00
|
|
|
'amount' => 10000,
|
2016-01-20 10:47:29 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-29 08:14:32 +02:00
|
|
|
}
|