2015-02-05 21:41:00 -06:00
|
|
|
<?php
|
2016-01-16 02:15:24 -06:00
|
|
|
|
2016-01-20 02:15:33 -06:00
|
|
|
use Carbon\Carbon;
|
2016-01-17 00:18:35 -06:00
|
|
|
use FireflyIII\Models\Account;
|
2016-01-20 03:47:29 -06:00
|
|
|
use FireflyIII\Models\Attachment;
|
2016-01-20 02:31:24 -06:00
|
|
|
use FireflyIII\Models\Category;
|
2016-01-24 09:05:14 -06:00
|
|
|
use FireflyIII\Models\Role;
|
2016-01-20 03:47:29 -06:00
|
|
|
use FireflyIII\Models\Transaction;
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2016-01-30 00:36:11 -06:00
|
|
|
use FireflyIII\Support\Migration\TestData;
|
2016-01-16 02:16:26 -06:00
|
|
|
use FireflyIII\User;
|
2015-02-11 00:35:10 -06:00
|
|
|
use Illuminate\Database\Seeder;
|
2015-02-05 21:41:00 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TestDataSeeder
|
|
|
|
*/
|
|
|
|
class TestDataSeeder extends Seeder
|
|
|
|
{
|
2016-01-24 13:38:58 -06:00
|
|
|
/** @var Carbon */
|
|
|
|
public $start;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TestDataSeeder constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->start = Carbon::create()->subYear()->startOfYear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-05 21:41:00 -06:00
|
|
|
/**
|
2016-01-16 02:15:24 -06:00
|
|
|
* Run the database seeds.
|
2015-06-29 08:23:50 -05:00
|
|
|
*
|
2016-01-16 02:15:24 -06:00
|
|
|
* @return void
|
2015-02-05 21:41:00 -06:00
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2016-01-29 06:24:33 -06:00
|
|
|
$user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
2016-01-28 14:50:20 -06:00
|
|
|
User::create(['email' => 'thegrumpydictator+empty@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
2016-02-04 04:00:26 -06:00
|
|
|
User::create(['email' => 'thegrumpydictator+deleteme@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
2016-01-17 00:18:35 -06:00
|
|
|
|
2016-01-24 09:05:14 -06:00
|
|
|
|
|
|
|
$admin = Role::where('name', 'owner')->first();
|
|
|
|
$user->attachRole($admin);
|
|
|
|
|
|
|
|
|
2016-01-17 00:18:35 -06:00
|
|
|
// create asset accounts for user #1.
|
2016-01-29 06:24:33 -06:00
|
|
|
TestData::createAssetAccounts($user);
|
2016-01-20 02:15:33 -06:00
|
|
|
|
2016-01-20 08:27:53 -06:00
|
|
|
// create bills for user #1
|
2016-01-29 06:24:33 -06:00
|
|
|
TestData::createBills($user);
|
2016-01-20 02:15:33 -06:00
|
|
|
|
|
|
|
// create some budgets for user #1
|
2016-02-04 04:00:26 -06:00
|
|
|
TestData::createBudgets($user);
|
2016-01-20 02:15:33 -06:00
|
|
|
|
2016-02-04 04:07:34 -06: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 02:15:33 -06:00
|
|
|
// create some categories for user #1
|
|
|
|
$this->createCategories($user);
|
2016-01-20 02:31:24 -06:00
|
|
|
|
|
|
|
// create some piggy banks for user #1
|
2016-01-29 06:24:33 -06:00
|
|
|
TestData::createPiggybanks($user);
|
2016-01-20 03:47:29 -06:00
|
|
|
|
|
|
|
// create some expense accounts for user #1
|
|
|
|
$this->createExpenseAccounts($user);
|
|
|
|
|
|
|
|
// create some revenue accounts for user #1
|
|
|
|
$this->createRevenueAccounts($user);
|
|
|
|
|
|
|
|
// create journal + attachment:
|
2016-02-04 10:13:58 -06:00
|
|
|
TestData::createAttachments($user, $this->start);
|
2016-01-24 13:38:58 -06:00
|
|
|
|
|
|
|
// create opening balance for savings account:
|
|
|
|
$this->openingBalanceSavings($user);
|
2016-02-04 04:00:26 -06:00
|
|
|
|
|
|
|
// need at least one rule group and one rule:
|
|
|
|
TestData::createRules($user);
|
|
|
|
|
|
|
|
// create a tag:
|
|
|
|
TestData::createTags($user);
|
2016-01-17 00:18:35 -06:00
|
|
|
}
|
2016-01-30 00:36:11 -06:00
|
|
|
|
2016-01-20 02:15:33 -06: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 02:31:24 -06:00
|
|
|
|
2016-01-24 13:38:58 -06: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 03:47:29 -06:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
2016-01-24 13:38:58 -06:00
|
|
|
private function createRevenueAccounts(User $user)
|
2016-01-20 03:47:29 -06:00
|
|
|
{
|
2016-01-24 13:38:58 -06:00
|
|
|
$revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google'];
|
|
|
|
foreach ($revenues as $name) {
|
2016-01-20 03:47:29 -06:00
|
|
|
// create account:
|
|
|
|
Account::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
2016-01-24 13:38:58 -06:00
|
|
|
'account_type_id' => 5,
|
2016-01-20 03:47:29 -06:00
|
|
|
'name' => $name,
|
|
|
|
'active' => 1,
|
|
|
|
'encrypted' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
2016-01-24 13:38:58 -06:00
|
|
|
private function openingBalanceSavings(User $user)
|
2016-01-20 03:47:29 -06:00
|
|
|
{
|
2016-01-24 13:38:58 -06: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 03:47:29 -06:00
|
|
|
|
2016-01-24 13:38:58 -06:00
|
|
|
// savings
|
2016-01-29 06:24:33 -06:00
|
|
|
$savings = TestData::findAccount($user, 'TestData Savings');
|
2016-01-20 03:47:29 -06:00
|
|
|
|
|
|
|
$journal = TransactionJournal::create(
|
|
|
|
[
|
|
|
|
'user_id' => $user->id,
|
2016-01-24 13:38:58 -06:00
|
|
|
'transaction_type_id' => 4,
|
2016-01-20 03:47:29 -06:00
|
|
|
'transaction_currency_id' => 1,
|
2016-01-24 13:38:58 -06:00
|
|
|
'description' => 'Opening balance for savings account',
|
2016-01-20 03:47:29 -06:00
|
|
|
'completed' => 1,
|
2016-01-24 13:38:58 -06:00
|
|
|
'date' => $this->start->format('Y-m-d'),
|
2016-01-20 03:47:29 -06:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2016-01-24 13:38:58 -06:00
|
|
|
// transactions
|
2016-01-20 03:47:29 -06:00
|
|
|
Transaction::create(
|
|
|
|
[
|
2016-01-29 06:24:33 -06:00
|
|
|
'account_id' => $opposing->id,
|
2016-01-20 03:47:29 -06:00
|
|
|
'transaction_journal_id' => $journal->id,
|
2016-01-29 06:24:33 -06:00
|
|
|
'amount' => -10000,
|
2016-01-20 03:47:29 -06:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2016-01-24 13:38:58 -06:00
|
|
|
Transaction::create(
|
2016-01-20 03:47:29 -06:00
|
|
|
[
|
2016-01-29 06:24:33 -06:00
|
|
|
'account_id' => $savings->id,
|
2016-01-24 13:38:58 -06:00
|
|
|
'transaction_journal_id' => $journal->id,
|
2016-01-29 06:24:33 -06:00
|
|
|
'amount' => 10000,
|
2016-01-20 03:47:29 -06:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-29 01:14:32 -05:00
|
|
|
}
|