Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some stuff moving around in test data generation.
James Cole5f9cb6116090
diff --git a/database/seeds/TestData.php b/database/seeds/TestData.phpnew file mode 100644index 0000000000..9c2a3fe5fb--- /dev/null+++ b/database/seeds/TestData.php@@ -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,+ ]+ );+ }+++}\ No newline at end of filediff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.phpindex 83cb5bac94..8e454e974a 100644--- a/database/seeds/TestDataSeeder.php+++ b/database/seeds/TestDataSeeder.php@@ -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' => '[email protected]', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);+ $user = User::create(['email' => '[email protected]', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);User::create(['email' => '[email protected]', '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 Seederfile_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// transactionsTransaction::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,]);diff --git a/database/seeds/VisualTestDataSeeder.php b/database/seeds/VisualTestDataSeeder.phpindex b099d2db30..aa2030390b 100644--- a/database/seeds/VisualTestDataSeeder.php+++ b/database/seeds/VisualTestDataSeeder.php@@ -7,7 +7,6 @@ use FireflyIII\Models\Budget;use FireflyIII\Models\BudgetLimit;use FireflyIII\Models\Category;use FireflyIII\Models\PiggyBank;-use FireflyIII\Models\PiggyBankEvent;use FireflyIII\Models\Preference;use FireflyIII\Models\Role;use FireflyIII\Models\Rule;@@ -32,15 +31,6 @@ class VisualTestDataSeeder extends Seeder/** @var User */protected $user;-- /**- *- */- public function __construct()- {-- }-/*** @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/@@ -448,11 +438,11 @@ class VisualTestDataSeeder extends Seeder$this->createUsers();// create accounts:- $this->createAssetAccounts();+ TestData::createAssetAccounts($this->user);$this->createExpenseAccounts();$this->createRevenueAccounts();- $this->createBills();- $this->createPiggybanks();+ TestData::createBills($this->user);+ TestData::createPiggybanks($this->user);$this->createRules();@@ -504,339 +494,50 @@ class VisualTestDataSeeder extends Seeder}/**- * @param Carbon $date- */- protected function createTags(Carbon $date)- {- Tag::create(- [- 'user_id' => $this->user->id,- 'tag' => 'SomeTag' . $date->month . '.' . $date->year . '.nothing',- 'tagMode' => 'nothing',- 'date' => $date->format('Y-m-d'),--- ]- );- }-- /**- *- */- protected function createUsers()- {- User::create(['email' => '[email protected]', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);- $this->user = User::whereEmail('[email protected]')->first();-- // create rights:- $role = Role::find(1);- $this->user->roles()->save($role);-- }-- /**- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)- */- protected function createAssetAccounts()- {- $assets = ['MyBank Checking Account', 'Savings', 'Shared', 'Creditcard', 'Emergencies', 'STE'];- $ibans = ['NL47JDYU6179706202', 'NL51WGBP5832453599', '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' => $this->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,]);- }- }- }-- protected function createExpenseAccounts()- {- $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' => $this->user->id,- 'account_type_id' => 4,- 'name' => $name,- 'active' => 1,- 'encrypted' => 1,- ]- );- }-- }-- /**- *+ * @param Carbon $current+ * @param $name+ * @param $amount*/- protected function createRevenueAccounts()+ protected function createBudgetLimit(Carbon $current, $name, $amount){- $revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google'];- foreach ($revenues as $name) {- // create account:- Account::create(- [- 'user_id' => $this->user->id,- 'account_type_id' => 5,- 'name' => $name,- 'active' => 1,- 'encrypted' => 1,- ]- );- }- }+ $start = clone $current;+ $end = clone $current;+ $budget = $this->findBudget($name);+ $start->startOfMonth();+ $end->endOfMonth();- public function createBills()- {- Bill::create(- [- 'name' => 'Rent',- 'match' => 'rent,land,lord',- 'amount_min' => 795,- 'amount_max' => 805,- 'user_id' => $this->user->id,- 'date' => '2015-01-01',- 'active' => 1,- 'automatch' => 1,- 'repeat_freq' => 'monthly',- 'skip' => 0,- ]- );- Bill::create(+ BudgetLimit::create([- 'name' => 'Health insurance',- 'match' => 'zilveren,kruis,health',- 'amount_min' => 120,- 'amount_max' => 140,- 'user_id' => $this->user->id,- 'date' => '2015-01-01',- 'active' => 1,- 'automatch' => 1,+ 'budget_id' => $budget->id,+ 'startdate' => $start->format('Y-m-d'),+ 'amount' => $amount,+ 'repeats' => 0,'repeat_freq' => 'monthly',- 'skip' => 0,- ]- );- }-- /**- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)- */- protected function createPiggybanks()- {- $account = $this->findAccount('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 $name- *- * @return Account|null- */- protected function findAccount($name)- {- /** @var Account $account */- foreach (Account::get() as $account) {- if ($account->name == $name && $this->user->id == $account->user_id) {- return $account;- break;- }- }-- return null;}/**- * @param $description- * @param Carbon $date- * @param $amount+ * @param $date*+ * @return static* @SuppressWarnings(PHPMD.ExcessiveMethodLength)- *- * @return TransactionJournal*/- protected function createIncome($description, Carbon $date, $amount)+ protected function createCar($date){- $date = new Carbon($date->format('Y-m') . '-23'); // paid on 23rd.- $today = new Carbon;- if ($date >= $today) {- return null;- }- $toAccount = $this->findAccount('MyBank Checking Account');- $fromAccount = $this->findAccount('Job');- $category = Category::firstOrCreateEncrypted(['name' => 'Salary', 'user_id' => $this->user->id]);- // create journal:-- $journal = TransactionJournal::create(+ // twice:+ $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'Shell');+ $category = Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $this->user->id]);+ $budget = Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $this->user->id]);+ $amount = rand(4000, 5000) / 100;+ $journal = TransactionJournal::create(['user_id' => $this->user->id,- 'transaction_type_id' => 2,+ 'transaction_type_id' => 1,'transaction_currency_id' => 1,- 'description' => $description,+ 'description' => 'Bought gas','completed' => 1,'date' => $date,]@@ -858,31 +559,19 @@ class VisualTestDataSeeder extends Seeder]);$journal->categories()->save($category);+ $journal->budgets()->save($budget);- return $journal;+ // and again!+ $date = new Carbon($date->format('Y-m') . '-20'); // paid on 20th+ $amount = rand(4000, 5000) / 100;- }- /**- * @param $description- * @param Carbon $date- * @param $amount- *- * @return TransactionJournal- */- protected function createRent($description, Carbon $date, $amount)- {- $fromAccount = $this->findAccount('MyBank Checking Account');- $toAccount = $this->findAccount('Land lord');- $category = Category::firstOrCreateEncrypted(['name' => 'Rent', 'user_id' => $this->user->id]);- $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);- $journal = TransactionJournal::create(+ $journal = TransactionJournal::create(['user_id' => $this->user->id,'transaction_type_id' => 1,'transaction_currency_id' => 1,- 'bill_id' => 1,- 'description' => $description,+ 'description' => 'Gas for car','completed' => 1,'date' => $date,]@@ -903,34 +592,176 @@ class VisualTestDataSeeder extends Seeder]);- $journal->categories()->save($category);- $journal->budgets()->save($budget);- return $journal;+ // and again!+ return $journal;}/**- * @param $description* @param Carbon $date- * @param $amount- *- * @return TransactionJournal+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/- protected function createWater($description, Carbon $date, $amount)+ protected function createDrinksAndOthers(Carbon $date){- $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th- $fromAccount = $this->findAccount('MyBank Checking Account');- $toAccount = $this->findAccount('Vitens');- $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]);- $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);- $journal = TransactionJournal::create(- [- 'user_id' => $this->user->id,- 'transaction_type_id' => 1,- 'transaction_currency_id' => 1,- 'description' => $description,- 'completed' => 1,+ $start = clone $date;+ $end = clone $date;+ $today = new Carbon;+ $start->startOfMonth();+ $end->endOfMonth();+ $current = clone $start;+ while ($current < $end && $current < $today) {++ // weekly drink:+ $thisDate = clone $current;+ $thisDate->addDay();+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'Cafe Central');+ $category = Category::firstOrCreateEncrypted(['name' => 'Drinks', 'user_id' => $this->user->id]);+ $budget = Budget::firstOrCreateEncrypted(['name' => 'Going out', 'user_id' => $this->user->id]);+ $amount = rand(1500, 3600) / 100;+ $journal = TransactionJournal::create(+ [+ 'user_id' => $this->user->id,+ 'transaction_type_id' => 1,+ 'transaction_currency_id' => 1,+ 'description' => 'Going out for drinks',+ 'completed' => 1,+ 'date' => $thisDate,+ ]+ );+ Transaction::create(+ [+ 'account_id' => $fromAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount * -1,++ ]+ );+ Transaction::create(+ [+ 'account_id' => $toAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount,++ ]+ );+ $journal->categories()->save($category);+ $journal->budgets()->save($budget);++ // shopping at some (online) shop:+++ $current->addWeek();+ }+ }++ protected function createExpenseAccounts()+ {+ $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' => $this->user->id,+ 'account_type_id' => 4,+ 'name' => $name,+ 'active' => 1,+ 'encrypted' => 1,+ ]+ );+ }++ }++ /**+ * @param Carbon $date+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)+ */+ protected function createGroceries(Carbon $date)+ {+ $start = clone $date;+ $end = clone $date;+ $today = new Carbon;+ $start->startOfMonth();+ $end->endOfMonth();++ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $stores = ['Albert Heijn', 'PLUS', 'Bakker'];+ $descriptions = ['Groceries', 'Bought some groceries', 'Got groceries'];+ $category = Category::firstOrCreateEncrypted(['name' => 'Daily groceries', 'user_id' => $this->user->id]);+ $budget = Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $this->user->id]);++ $current = clone $start;+ while ($current < $end && $current < $today) {+ // daily groceries:+ $amount = rand(1500, 2500) / 100;+ $toAccount = TestData::findAccount($this->user, $stores[rand(0, count($stores) - 1)]);++ $journal = TransactionJournal::create(+ [+ 'user_id' => $this->user->id,+ 'transaction_type_id' => 1,+ 'transaction_currency_id' => 1,+ 'description' => $descriptions[rand(0, count($descriptions) - 1)],+ 'completed' => 1,+ 'date' => $current,+ ]+ );+ Transaction::create(+ [+ 'account_id' => $fromAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount * -1,++ ]+ );+ Transaction::create(+ [+ 'account_id' => $toAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount,++ ]+ );+ $journal->categories()->save($category);+ $journal->budgets()->save($budget);+++ $current->addDay();+ }+ }++ /**+ * @param $description+ * @param Carbon $date+ * @param $amount+ *+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)+ *+ * @return TransactionJournal+ */+ protected function createIncome($description, Carbon $date, $amount)+ {+ $date = new Carbon($date->format('Y-m') . '-23'); // paid on 23rd.+ $today = new Carbon;+ if ($date >= $today) {+ return null;+ }+ $toAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $fromAccount = TestData::findAccount($this->user, 'Job');+ $category = Category::firstOrCreateEncrypted(['name' => 'Salary', 'user_id' => $this->user->id]);+ // create journal:++ $journal = TransactionJournal::create(+ [+ 'user_id' => $this->user->id,+ 'transaction_type_id' => 2,+ 'transaction_currency_id' => 1,+ 'description' => $description,+ 'completed' => 1,'date' => $date,]);@@ -951,7 +782,6 @@ class VisualTestDataSeeder extends Seeder]);$journal->categories()->save($category);- $journal->budgets()->save($budget);return $journal;@@ -964,11 +794,11 @@ class VisualTestDataSeeder extends Seeder** @return TransactionJournal*/- protected function createTV($description, Carbon $date, $amount)+ protected function createPower($description, Carbon $date, $amount){- $date = new Carbon($date->format('Y-m') . '-15'); // paid on 10th- $fromAccount = $this->findAccount('MyBank Checking Account');- $toAccount = $this->findAccount('XS4All');+ $date = new Carbon($date->format('Y-m') . '-06'); // paid on 10th+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'Greenchoice');$category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]);$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);$journal = TransactionJournal::create(@@ -1004,6 +834,15 @@ class VisualTestDataSeeder extends Seeder}+ protected function createPreferences()+ {+ $preference = new Preference;+ $preference->name = 'frontPageAccounts';+ $preference->data = [1];+ $preference->user()->associate($this->user);+ $preference->save();+ }+/*** @param $description* @param Carbon $date@@ -1011,18 +850,18 @@ class VisualTestDataSeeder extends Seeder** @return TransactionJournal*/- protected function createPower($description, Carbon $date, $amount)+ protected function createRent($description, Carbon $date, $amount){- $date = new Carbon($date->format('Y-m') . '-06'); // paid on 10th- $fromAccount = $this->findAccount('MyBank Checking Account');- $toAccount = $this->findAccount('Greenchoice');- $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]);+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'Land lord');+ $category = Category::firstOrCreateEncrypted(['name' => 'Rent', 'user_id' => $this->user->id]);$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);$journal = TransactionJournal::create(['user_id' => $this->user->id,'transaction_type_id' => 1,'transaction_currency_id' => 1,+ 'bill_id' => 1,'description' => $description,'completed' => 1,'date' => $date,@@ -1047,123 +886,27 @@ class VisualTestDataSeeder extends Seeder$journal->categories()->save($category);$journal->budgets()->save($budget);- return $journal;-- }-- /**- * @param Carbon $date- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)- */- protected function createGroceries(Carbon $date)- {- $start = clone $date;- $end = clone $date;- $today = new Carbon;- $start->startOfMonth();- $end->endOfMonth();-- $fromAccount = $this->findAccount('MyBank Checking Account');- $stores = ['Albert Heijn', 'PLUS', 'Bakker'];- $descriptions = ['Groceries', 'Bought some groceries', 'Got groceries'];- $category = Category::firstOrCreateEncrypted(['name' => 'Daily groceries', 'user_id' => $this->user->id]);- $budget = Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $this->user->id]);-- $current = clone $start;- while ($current < $end && $current < $today) {- // daily groceries:- $amount = rand(1500, 2500) / 100;- $toAccount = $this->findAccount($stores[rand(0, count($stores) - 1)]);-- $journal = TransactionJournal::create(- [- 'user_id' => $this->user->id,- 'transaction_type_id' => 1,- 'transaction_currency_id' => 1,- 'description' => $descriptions[rand(0, count($descriptions) - 1)],- 'completed' => 1,- 'date' => $current,- ]- );- Transaction::create(- [- 'account_id' => $fromAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount * -1,-- ]- );- Transaction::create(- [- 'account_id' => $toAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount,-- ]- );- $journal->categories()->save($category);- $journal->budgets()->save($budget);--- $current->addDay();- }- }-- /**- * @param Carbon $date- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)- */- protected function createDrinksAndOthers(Carbon $date)- {- $start = clone $date;- $end = clone $date;- $today = new Carbon;- $start->startOfMonth();- $end->endOfMonth();- $current = clone $start;- while ($current < $end && $current < $today) {-- // weekly drink:- $thisDate = clone $current;- $thisDate->addDay();- $fromAccount = $this->findAccount('MyBank Checking Account');- $toAccount = $this->findAccount('Cafe Central');- $category = Category::firstOrCreateEncrypted(['name' => 'Drinks', 'user_id' => $this->user->id]);- $budget = Budget::firstOrCreateEncrypted(['name' => 'Going out', 'user_id' => $this->user->id]);- $amount = rand(1500, 3600) / 100;- $journal = TransactionJournal::create(- [- 'user_id' => $this->user->id,- 'transaction_type_id' => 1,- 'transaction_currency_id' => 1,- 'description' => 'Going out for drinks',- 'completed' => 1,- 'date' => $thisDate,- ]- );- Transaction::create(- [- 'account_id' => $fromAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount * -1,-- ]- );- Transaction::create(- [- 'account_id' => $toAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount,-- ]- );- $journal->categories()->save($category);- $journal->budgets()->save($budget);-- // shopping at some (online) shop:+ return $journal;+ }- $current->addWeek();+ /**+ *+ */+ protected function createRevenueAccounts()+ {+ $revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google'];+ foreach ($revenues as $name) {+ // create account:+ Account::create(+ [+ 'user_id' => $this->user->id,+ 'account_type_id' => 5,+ 'name' => $name,+ 'active' => 1,+ 'encrypted' => 1,+ ]+ );}}@@ -1175,8 +918,8 @@ class VisualTestDataSeeder extends Seederprotected function createSavings(Carbon $date){$date = new Carbon($date->format('Y-m') . '-24'); // paid on 24th.- $toAccount = $this->findAccount('Savings');- $fromAccount = $this->findAccount('MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'Savings');+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');$category = Category::firstOrCreateEncrypted(['name' => 'Money management', 'user_id' => $this->user->id]);// create journal:@@ -1213,45 +956,128 @@ class VisualTestDataSeeder extends Seeder}/**- * @param Carbon $current- * @param $name+ * @param $description+ * @param Carbon $date* @param $amount+ *+ * @return TransactionJournal*/- protected function createBudgetLimit(Carbon $current, $name, $amount)+ protected function createTV($description, Carbon $date, $amount){- $start = clone $current;- $end = clone $current;- $budget = $this->findBudget($name);- $start->startOfMonth();- $end->endOfMonth();+ $date = new Carbon($date->format('Y-m') . '-15'); // paid on 10th+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'XS4All');+ $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]);+ $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);+ $journal = TransactionJournal::create(+ [+ 'user_id' => $this->user->id,+ 'transaction_type_id' => 1,+ 'transaction_currency_id' => 1,+ 'description' => $description,+ 'completed' => 1,+ 'date' => $date,+ ]+ );+ Transaction::create(+ [+ 'account_id' => $fromAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount * -1,- BudgetLimit::create(+ ]+ );+ Transaction::create([- 'budget_id' => $budget->id,- 'startdate' => $start->format('Y-m-d'),- 'amount' => $amount,- 'repeats' => 0,- 'repeat_freq' => 'monthly',+ 'account_id' => $toAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount,++ ]+ );+ $journal->categories()->save($category);+ $journal->budgets()->save($budget);++ return $journal;++ }++ /**+ * @param Carbon $date+ */+ protected function createTags(Carbon $date)+ {+ Tag::create(+ [+ 'user_id' => $this->user->id,+ 'tag' => 'SomeTag' . $date->month . '.' . $date->year . '.nothing',+ 'tagMode' => 'nothing',+ 'date' => $date->format('Y-m-d'),++]);}/**- * @param $name*- * @return Budget|null*/- protected function findBudget($name)+ protected function createUsers(){- /** @var Budget $budget */- foreach (Budget::get() as $budget) {- if ($budget->name == $name && $this->user->id == $budget->user_id) {- return $budget;- break;- }- }+ User::create(['email' => '[email protected]', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);+ $this->user = User::whereEmail('[email protected]')->first();++ // create rights:+ $role = Role::find(1);+ $this->user->roles()->save($role);++ }++ /**+ * @param $description+ * @param Carbon $date+ * @param $amount+ *+ * @return TransactionJournal+ */+ protected function createWater($description, Carbon $date, $amount)+ {+ $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th+ $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account');+ $toAccount = TestData::findAccount($this->user, 'Vitens');+ $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]);+ $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);+ $journal = TransactionJournal::create(+ [+ 'user_id' => $this->user->id,+ 'transaction_type_id' => 1,+ 'transaction_currency_id' => 1,+ 'description' => $description,+ 'completed' => 1,+ 'date' => $date,+ ]+ );+ Transaction::create(+ [+ 'account_id' => $fromAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount * -1,++ ]+ );+ Transaction::create(+ [+ 'account_id' => $toAccount->id,+ 'transaction_journal_id' => $journal->id,+ 'amount' => $amount,++ ]+ );+ $journal->categories()->save($category);+ $journal->budgets()->save($budget);++ return $journal;- return null;}/**@@ -1272,6 +1098,24 @@ class VisualTestDataSeeder extends Seederreturn null;}+ /**+ * @param $name+ *+ * @return Budget|null+ */+ protected function findBudget($name)+ {+ /** @var Budget $budget */+ foreach (Budget::get() as $budget) {+ if ($budget->name == $name && $this->user->id == $budget->user_id) {+ return $budget;+ break;+ }+ }++ return null;+ }+/*** @param $name*@@ -1330,95 +1174,5 @@ class VisualTestDataSeeder extends Seederreturn null;}- /**- * @param $date- *- * @return static- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)- */- protected function createCar($date)- {- // twice:- $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th- $fromAccount = $this->findAccount('MyBank Checking Account');- $toAccount = $this->findAccount('Shell');- $category = Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $this->user->id]);- $budget = Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $this->user->id]);- $amount = rand(4000, 5000) / 100;- $journal = TransactionJournal::create(- [- 'user_id' => $this->user->id,- 'transaction_type_id' => 1,- 'transaction_currency_id' => 1,- 'description' => 'Bought gas',- 'completed' => 1,- 'date' => $date,- ]- );- Transaction::create(- [- 'account_id' => $fromAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount * -1,-- ]- );- Transaction::create(- [- 'account_id' => $toAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount,-- ]- );- $journal->categories()->save($category);- $journal->budgets()->save($budget);-- // and again!- $date = new Carbon($date->format('Y-m') . '-20'); // paid on 20th- $amount = rand(4000, 5000) / 100;--- $journal = TransactionJournal::create(- [- 'user_id' => $this->user->id,- 'transaction_type_id' => 1,- 'transaction_currency_id' => 1,- 'description' => 'Gas for car',- 'completed' => 1,- 'date' => $date,- ]- );- Transaction::create(- [- 'account_id' => $fromAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount * -1,-- ]- );- Transaction::create(- [- 'account_id' => $toAccount->id,- 'transaction_journal_id' => $journal->id,- 'amount' => $amount,-- ]- );-- // and again!-- return $journal;- }-- protected function createPreferences()- {- $preference = new Preference;- $preference->name = 'frontPageAccounts';- $preference->data = [1];- $preference->user()->associate($this->user);- $preference->save();- }-}