mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Moved test data around.
This commit is contained in:
258
app/Support/Migration/TestData.php
Normal file
258
app/Support/Migration/TestData.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
namespace FireflyIII\Support\Migration;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class TestData
|
||||
*
|
||||
* @package FireflyIII\Support\Migration
|
||||
*/
|
||||
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,]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
Log::debug('Trying to find "' . $name . '" in "' . $account->name . '", and found it!');
|
||||
|
||||
return $account;
|
||||
}
|
||||
Log::debug('Trying to find "' . $name . '" in "' . $account->name . '".');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user