firefly-iii/database/seeds/TestData.php

250 lines
7.4 KiB
PHP
Raw Normal View History

<?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,
]
);
}
}