mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some stuff moving around in test data generation.
This commit is contained in:
parent
7f54b70c24
commit
5f9cb61160
250
database/seeds/TestData.php
Normal file
250
database/seeds/TestData.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* TestData.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
* Class TestData
|
||||
*/
|
||||
class TestData
|
||||
{
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public static function createAssetAccounts(User $user)
|
||||
{
|
||||
$assets = ['TestData Checking Account', 'TestData Savings', 'TestData Shared', 'TestData Creditcard', 'Emergencies', 'STE'];
|
||||
// first two ibans match test-upload.csv
|
||||
$ibans = ['NL11XOLA6707795988', 'NL96DZCO4665940223', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708'];
|
||||
$assetMeta = [
|
||||
['accountRole' => 'defaultAsset'],
|
||||
['accountRole' => 'savingAsset',],
|
||||
['accountRole' => 'sharedAsset',],
|
||||
['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull',],
|
||||
['accountRole' => 'savingAsset',],
|
||||
['accountRole' => 'savingAsset',],
|
||||
];
|
||||
|
||||
foreach ($assets as $index => $name) {
|
||||
// create account:
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 3,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
'iban' => $ibans[$index],
|
||||
]
|
||||
);
|
||||
foreach ($assetMeta[$index] as $name => $value) {
|
||||
AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value,]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @param User $user
|
||||
*/
|
||||
public static function createPiggybanks(User $user)
|
||||
{
|
||||
$account = self::findAccount($user, 'TestData Savings');
|
||||
|
||||
$camera = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New camera',
|
||||
'targetamount' => 1000,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 1,
|
||||
]
|
||||
);
|
||||
$repetition = $camera->piggyBankRepetitions()->first();
|
||||
$repetition->currentamount = 735;
|
||||
$repetition->save();
|
||||
|
||||
// events:
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $camera->id,
|
||||
'date' => '2015-05-01',
|
||||
'amount' => '245',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $camera->id,
|
||||
'date' => '2015-06-01',
|
||||
'amount' => '245',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $camera->id,
|
||||
'date' => '2015-07-01',
|
||||
'amount' => '245',
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$phone = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New phone',
|
||||
'targetamount' => 600,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 2,
|
||||
]
|
||||
);
|
||||
$repetition = $phone->piggyBankRepetitions()->first();
|
||||
$repetition->currentamount = 333;
|
||||
$repetition->save();
|
||||
|
||||
// events:
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $phone->id,
|
||||
'date' => '2015-05-01',
|
||||
'amount' => '111',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $phone->id,
|
||||
'date' => '2015-06-01',
|
||||
'amount' => '111',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $phone->id,
|
||||
'date' => '2015-07-01',
|
||||
'amount' => '111',
|
||||
]
|
||||
);
|
||||
|
||||
$couch = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New couch',
|
||||
'targetamount' => 500,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 3,
|
||||
]
|
||||
);
|
||||
$repetition = $couch->piggyBankRepetitions()->first();
|
||||
$repetition->currentamount = 120;
|
||||
$repetition->save();
|
||||
|
||||
// events:
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $couch->id,
|
||||
'date' => '2015-05-01',
|
||||
'amount' => '40',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $couch->id,
|
||||
'date' => '2015-06-01',
|
||||
'amount' => '40',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $couch->id,
|
||||
'date' => '2015-07-01',
|
||||
'amount' => '40',
|
||||
]
|
||||
);
|
||||
|
||||
// empty one.
|
||||
PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New head set',
|
||||
'targetamount' => 500,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 4,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param $name
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public static function findAccount(User $user, $name)
|
||||
{
|
||||
/** @var Account $account */
|
||||
foreach ($user->accounts()->get() as $account) {
|
||||
if ($account->name == $name) {
|
||||
return $account;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public static function createBills(User $user)
|
||||
{
|
||||
Bill::create(
|
||||
[
|
||||
'name' => 'Rent',
|
||||
'match' => 'rent,land,lord',
|
||||
'amount_min' => 795,
|
||||
'amount_max' => 805,
|
||||
'user_id' => $user->id,
|
||||
'date' => '2015-01-01',
|
||||
'active' => 1,
|
||||
'automatch' => 1,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
]
|
||||
);
|
||||
Bill::create(
|
||||
[
|
||||
'name' => 'Health insurance',
|
||||
'match' => 'zilveren,kruis,health',
|
||||
'amount_min' => 120,
|
||||
'amount_max' => 140,
|
||||
'user_id' => $user->id,
|
||||
'date' => '2015-01-01',
|
||||
'active' => 1,
|
||||
'automatch' => 1,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -8,8 +8,6 @@ use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -40,7 +38,7 @@ class TestDataSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
||||
$user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
||||
User::create(['email' => 'thegrumpydictator+empty@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
|
||||
|
||||
|
||||
@ -49,10 +47,10 @@ class TestDataSeeder extends Seeder
|
||||
|
||||
|
||||
// create asset accounts for user #1.
|
||||
$this->createAssetAccounts($user);
|
||||
TestData::createAssetAccounts($user);
|
||||
|
||||
// create bills for user #1
|
||||
$this->createBills($user);
|
||||
TestData::createBills($user);
|
||||
|
||||
// create some budgets for user #1
|
||||
$this->createBudgets($user);
|
||||
@ -61,7 +59,7 @@ class TestDataSeeder extends Seeder
|
||||
$this->createCategories($user);
|
||||
|
||||
// create some piggy banks for user #1
|
||||
$this->createPiggybanks($user);
|
||||
TestData::createPiggybanks($user);
|
||||
|
||||
// create some expense accounts for user #1
|
||||
$this->createExpenseAccounts($user);
|
||||
@ -75,51 +73,14 @@ class TestDataSeeder extends Seeder
|
||||
// create opening balance for savings account:
|
||||
$this->openingBalanceSavings($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function createAssetAccounts(User $user)
|
||||
{
|
||||
$assets = ['TestData Checking Account', 'TestData Savings', 'TestData Shared', 'TestData Creditcard', 'Emergencies', 'STE'];
|
||||
// first two ibans match test-upload.csv
|
||||
$ibans = ['NL11XOLA6707795988', 'NL96DZCO4665940223', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708'];
|
||||
$assetMeta = [
|
||||
['accountRole' => 'defaultAsset'],
|
||||
['accountRole' => 'savingAsset',],
|
||||
['accountRole' => 'sharedAsset',],
|
||||
['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull',],
|
||||
['accountRole' => 'savingAsset',],
|
||||
['accountRole' => 'savingAsset',],
|
||||
];
|
||||
|
||||
foreach ($assets as $index => $name) {
|
||||
// create account:
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 3,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
'iban' => $ibans[$index],
|
||||
]
|
||||
);
|
||||
foreach ($assetMeta[$index] as $name => $value) {
|
||||
AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value,]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function createAttachments(User $user)
|
||||
{
|
||||
|
||||
$toAccount = $this->findAccount($user, 'TestData Checking Account');
|
||||
$fromAccount = $this->findAccount($user, 'Job');
|
||||
$toAccount = TestData::findAccount($user, 'TestData Checking Account');
|
||||
$fromAccount = TestData::findAccount($user, 'Job');
|
||||
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
@ -188,42 +149,6 @@ class TestDataSeeder extends Seeder
|
||||
file_put_contents(storage_path('upload/at-2.data'), $encrypted);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function createBills(User $user)
|
||||
{
|
||||
Bill::create(
|
||||
[
|
||||
'name' => 'Rent',
|
||||
'match' => 'rent,land,lord',
|
||||
'amount_min' => 795,
|
||||
'amount_max' => 805,
|
||||
'user_id' => $user->id,
|
||||
'date' => '2015-01-01',
|
||||
'active' => 1,
|
||||
'automatch' => 1,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
]
|
||||
);
|
||||
Bill::create(
|
||||
[
|
||||
'name' => 'Health insurance',
|
||||
'match' => 'zilveren,kruis,health',
|
||||
'amount_min' => 120,
|
||||
'amount_max' => 140,
|
||||
'user_id' => $user->id,
|
||||
'date' => '2015-01-01',
|
||||
'active' => 1,
|
||||
'automatch' => 1,
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $user
|
||||
*/
|
||||
@ -287,144 +212,6 @@ class TestDataSeeder extends Seeder
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @param User $user
|
||||
*/
|
||||
private function createPiggybanks(User $user)
|
||||
{
|
||||
$account = $this->findAccount($user, 'TestData Savings');
|
||||
|
||||
$camera = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New camera',
|
||||
'targetamount' => 1000,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 1,
|
||||
]
|
||||
);
|
||||
$repetition = $camera->piggyBankRepetitions()->first();
|
||||
$repetition->currentamount = 735;
|
||||
$repetition->save();
|
||||
|
||||
// events:
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $camera->id,
|
||||
'date' => '2015-05-01',
|
||||
'amount' => '245',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $camera->id,
|
||||
'date' => '2015-06-01',
|
||||
'amount' => '245',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $camera->id,
|
||||
'date' => '2015-07-01',
|
||||
'amount' => '245',
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$phone = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New phone',
|
||||
'targetamount' => 600,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 2,
|
||||
]
|
||||
);
|
||||
$repetition = $phone->piggyBankRepetitions()->first();
|
||||
$repetition->currentamount = 333;
|
||||
$repetition->save();
|
||||
|
||||
// events:
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $phone->id,
|
||||
'date' => '2015-05-01',
|
||||
'amount' => '111',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $phone->id,
|
||||
'date' => '2015-06-01',
|
||||
'amount' => '111',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $phone->id,
|
||||
'date' => '2015-07-01',
|
||||
'amount' => '111',
|
||||
]
|
||||
);
|
||||
|
||||
$couch = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New couch',
|
||||
'targetamount' => 500,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 3,
|
||||
]
|
||||
);
|
||||
$repetition = $couch->piggyBankRepetitions()->first();
|
||||
$repetition->currentamount = 120;
|
||||
$repetition->save();
|
||||
|
||||
// events:
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $couch->id,
|
||||
'date' => '2015-05-01',
|
||||
'amount' => '40',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $couch->id,
|
||||
'date' => '2015-06-01',
|
||||
'amount' => '40',
|
||||
]
|
||||
);
|
||||
PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $couch->id,
|
||||
'date' => '2015-07-01',
|
||||
'amount' => '40',
|
||||
]
|
||||
);
|
||||
|
||||
// empty one.
|
||||
PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'New head set',
|
||||
'targetamount' => 500,
|
||||
'startdate' => '2015-04-01',
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
'order' => 4,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@ -445,25 +232,6 @@ class TestDataSeeder extends Seeder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param $name
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
private function findAccount(User $user, $name)
|
||||
{
|
||||
/** @var Account $account */
|
||||
foreach ($user->accounts()->get() as $account) {
|
||||
if ($account->name == $name) {
|
||||
return $account;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@ -481,7 +249,7 @@ class TestDataSeeder extends Seeder
|
||||
);
|
||||
|
||||
// savings
|
||||
$savings = $this->findAccount($user, 'TestData Savings');
|
||||
$savings = TestData::findAccount($user, 'TestData Savings');
|
||||
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
@ -497,17 +265,17 @@ class TestDataSeeder extends Seeder
|
||||
// transactions
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $opposing->id,
|
||||
'account_id' => $opposing->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -10000,
|
||||
'amount' => -10000,
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'account_id' => $savings->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 10000,
|
||||
'amount' => 10000,
|
||||
]
|
||||
);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user