mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Some new data thing.
This commit is contained in:
@@ -44,38 +44,76 @@ class TestData
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
|
* @param array $assets
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function createAssetAccounts(User $user): bool
|
public static function createAssetAccounts(User $user, array $assets): bool
|
||||||
{
|
{
|
||||||
$assets = ['TestData Checking Account', 'TestData Savings', 'TestData Shared', 'TestData Creditcard', 'Emergencies', 'STE'];
|
if (count($assets) == 0) {
|
||||||
// first two ibans match test-upload.csv
|
$assets = [
|
||||||
$ibans = ['NL11XOLA6707795988', 'NL96DZCO4665940223', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708'];
|
[
|
||||||
$assetMeta = [
|
'name' => 'TestData Checking Account',
|
||||||
['accountRole' => 'defaultAsset'],
|
'iban' => 'NL11XOLA6707795988',
|
||||||
['accountRole' => 'savingAsset',],
|
'meta' => [
|
||||||
['accountRole' => 'sharedAsset',],
|
'accountRole' => 'defaultAsset',
|
||||||
['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull',],
|
],
|
||||||
['accountRole' => 'savingAsset',],
|
],
|
||||||
['accountRole' => 'savingAsset',],
|
[
|
||||||
];
|
'name' => 'TestData Savings',
|
||||||
|
'iban' => 'NL96DZCO4665940223',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'savingAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'TestData Shared',
|
||||||
|
'iban' => 'NL81RCQZ7160379858',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'sharedAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'TestData Creditcard',
|
||||||
|
'iban' => 'NL19NRAP2367994221',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'ccAsset',
|
||||||
|
'ccMonthlyPaymentDate' => '2015-05-27',
|
||||||
|
'ccType' => 'monthlyFull',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Emergencies',
|
||||||
|
'iban' => 'NL40UKBK3619908726',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'savingAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'STE',
|
||||||
|
'iban' => 'NL38SRMN4325934708',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'savingAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($assets as $index => $name) {
|
foreach ($assets as $index => $entry) {
|
||||||
// create account:
|
// create account:
|
||||||
$account = Account::create(
|
$account = Account::create(
|
||||||
[
|
[
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'account_type_id' => 3,
|
'account_type_id' => 3,
|
||||||
'name' => $name,
|
'name' => $entry['name'],
|
||||||
'active' => 1,
|
'active' => 1,
|
||||||
'encrypted' => 1,
|
'encrypted' => 1,
|
||||||
'iban' => $ibans[$index],
|
'iban' => $entry['iban'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
foreach ($assetMeta[$index] as $name => $value) {
|
foreach ($entry['meta'] as $name => $value) {
|
||||||
AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value,]);
|
AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,15 +490,16 @@ class TestData
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
|
* @param string $accountName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function createPiggybanks(User $user): bool
|
public static function createPiggybanks(User $user, string $accountName): bool
|
||||||
{
|
{
|
||||||
$account = self::findAccount($user, 'TestData Savings');
|
|
||||||
|
|
||||||
|
$account = self::findAccount($user, $accountName);
|
||||||
$camera = PiggyBank::create(
|
$camera = PiggyBank::create(
|
||||||
[
|
[
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
|
@@ -32,8 +32,6 @@ class SplitDataSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,18 +41,50 @@ class SplitDataSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$skipWithdrawal = false;
|
||||||
|
$skipDeposit = true;
|
||||||
|
$skipTransfer = true;
|
||||||
// start by creating all users:
|
// start by creating all users:
|
||||||
// method will return the first user.
|
// method will return the first user.
|
||||||
$user = TestData::createUsers();
|
$user = TestData::createUsers();
|
||||||
|
|
||||||
|
|
||||||
// create all kinds of static data:
|
// create all kinds of static data:
|
||||||
TestData::createAssetAccounts($user);
|
$assets = [
|
||||||
|
[
|
||||||
|
'name' => 'Checking Account',
|
||||||
|
'iban' => 'NL11XOLA6707795988',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'defaultAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Alternate Checking Account',
|
||||||
|
'iban' => 'NL40UKBK3619908726',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'defaultAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Savings Account',
|
||||||
|
'iban' => 'NL96DZCO4665940223',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'savingAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Shared Checking Account',
|
||||||
|
'iban' => 'NL81RCQZ7160379858',
|
||||||
|
'meta' => [
|
||||||
|
'accountRole' => 'sharedAsset',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
TestData::createAssetAccounts($user, $assets);
|
||||||
TestData::createBudgets($user);
|
TestData::createBudgets($user);
|
||||||
TestData::createCategories($user);
|
TestData::createCategories($user);
|
||||||
TestData::createExpenseAccounts($user);
|
TestData::createExpenseAccounts($user);
|
||||||
TestData::createRevenueAccounts($user);
|
TestData::createRevenueAccounts($user);
|
||||||
TestData::createPiggybanks($user);
|
TestData::createPiggybanks($user, 'Savings Account');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create splitted expense of 66,-
|
* Create splitted expense of 66,-
|
||||||
@@ -62,154 +92,156 @@ class SplitDataSeeder extends Seeder
|
|||||||
$today = new Carbon;
|
$today = new Carbon;
|
||||||
$today->subDays(6);
|
$today->subDays(6);
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
if (!$skipWithdrawal) {
|
||||||
[
|
$journal = TransactionJournal::create(
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1, // withdrawal
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Split Expense (journal)',
|
|
||||||
'completed' => 1,
|
|
||||||
'date' => $today->format('Y-m-d'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// split in 6 transactions (multiple destinations). 22,- each
|
|
||||||
// source is TestData Checking Account.
|
|
||||||
// also attach some budgets and stuff.
|
|
||||||
$destinations = ['Albert Heijn', 'PLUS', 'Apple'];
|
|
||||||
$budgets = ['Groceries', 'Groceries', 'Car'];
|
|
||||||
$categories = ['Bills', 'Bills', 'Car'];
|
|
||||||
$source = TestData::findAccount($user, 'TestData Checking Account');
|
|
||||||
foreach ($destinations as $index => $dest) {
|
|
||||||
$bud = $budgets[$index];
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$destination = TestData::findAccount($user, $dest);
|
|
||||||
|
|
||||||
$one = Transaction::create(
|
|
||||||
[
|
[
|
||||||
'account_id' => $source->id,
|
'user_id' => $user->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_type_id' => 1, // withdrawal
|
||||||
'amount' => '-22',
|
'transaction_currency_id' => 1,
|
||||||
|
'description' => 'Split Expense (journal)',
|
||||||
|
'completed' => 1,
|
||||||
|
'date' => $today->format('Y-m-d'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$two = Transaction::create(
|
// split in 6 transactions (multiple destinations). 22,- each
|
||||||
[
|
// source is TestData Checking Account.
|
||||||
'account_id' => $destination->id,
|
// also attach some budgets and stuff.
|
||||||
'transaction_journal_id' => $journal->id,
|
$destinations = ['Albert Heijn', 'PLUS', 'Apple'];
|
||||||
'amount' => '22',
|
$budgets = ['Groceries', 'Groceries', 'Car'];
|
||||||
|
$categories = ['Bills', 'Bills', 'Car'];
|
||||||
|
$source = TestData::findAccount($user, 'Checking Account');
|
||||||
|
foreach ($destinations as $index => $dest) {
|
||||||
|
$bud = $budgets[$index];
|
||||||
|
$cat = $categories[$index];
|
||||||
|
$destination = TestData::findAccount($user, $dest);
|
||||||
|
|
||||||
]
|
$one = Transaction::create(
|
||||||
);
|
[
|
||||||
|
'account_id' => $source->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => '-22',
|
||||||
|
|
||||||
$one->budgets()->save(TestData::findBudget($user, $bud));
|
]
|
||||||
$two->budgets()->save(TestData::findBudget($user, $bud));
|
);
|
||||||
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
$two = Transaction::create(
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
[
|
||||||
|
'account_id' => $destination->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => '22',
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$one->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
$two->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
|
||||||
|
$one->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
$two->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create splitted income of 99,-
|
// create splitted income of 99,-
|
||||||
$today->addDay();
|
$today->addDay();
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
if (!$skipDeposit) {
|
||||||
[
|
$journal = TransactionJournal::create(
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 2, // expense
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Split Income (journal)',
|
|
||||||
'completed' => 1,
|
|
||||||
'date' => $today->format('Y-m-d'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// split in 6 transactions (multiple destinations). 22,- each
|
|
||||||
// source is TestData Checking Account.
|
|
||||||
// also attach some budgets and stuff.
|
|
||||||
$destinations = ['TestData Checking Account', 'TestData Savings', 'TestData Shared'];
|
|
||||||
$source = TestData::findAccount($user, 'Belastingdienst');
|
|
||||||
$budgets = ['Groceries', 'Groceries', 'Car'];
|
|
||||||
$categories = ['Bills', 'Bills', 'Car'];
|
|
||||||
foreach ($destinations as $index => $dest) {
|
|
||||||
$bud = $budgets[$index];
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$destination = TestData::findAccount($user, $dest);
|
|
||||||
|
|
||||||
$one = Transaction::create(
|
|
||||||
[
|
[
|
||||||
'account_id' => $source->id,
|
'user_id' => $user->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_type_id' => 2, // expense
|
||||||
'amount' => '-33',
|
'transaction_currency_id' => 1,
|
||||||
|
'description' => 'Split Income (journal)',
|
||||||
|
'completed' => 1,
|
||||||
|
'date' => $today->format('Y-m-d'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$two = Transaction::create(
|
// split in 6 transactions (multiple destinations). 22,- each
|
||||||
[
|
// source is TestData Checking Account.
|
||||||
'account_id' => $destination->id,
|
// also attach some budgets and stuff.
|
||||||
'transaction_journal_id' => $journal->id,
|
$destinations = ['Checking Account', 'Savings Account', 'Shared Checking Account'];
|
||||||
'amount' => '33',
|
$source = TestData::findAccount($user, 'Belastingdienst');
|
||||||
|
$budgets = ['Groceries', 'Groceries', 'Car'];
|
||||||
|
$categories = ['Bills', 'Bills', 'Car'];
|
||||||
|
foreach ($destinations as $index => $dest) {
|
||||||
|
$bud = $budgets[$index];
|
||||||
|
$cat = $categories[$index];
|
||||||
|
$destination = TestData::findAccount($user, $dest);
|
||||||
|
|
||||||
]
|
$one = Transaction::create(
|
||||||
);
|
[
|
||||||
|
'account_id' => $source->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => '-33',
|
||||||
|
|
||||||
$one->budgets()->save(TestData::findBudget($user, $bud));
|
]
|
||||||
$two->budgets()->save(TestData::findBudget($user, $bud));
|
);
|
||||||
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
$two = Transaction::create(
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
[
|
||||||
|
'account_id' => $destination->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => '33',
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$one->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
$two->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
|
||||||
|
$one->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
$two->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a splitted transfer of 57,- (19)
|
// create a splitted transfer of 57,- (19)
|
||||||
$today->addDay();
|
$today->addDay();
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
if (!$skipTransfer) {
|
||||||
[
|
$journal = TransactionJournal::create(
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 3, // transfer
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Split Transfer (journal)',
|
|
||||||
'completed' => 1,
|
|
||||||
'date' => $today->format('Y-m-d'),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$source = TestData::findAccount($user, 'Emergencies');
|
|
||||||
$destinations = ['TestData Checking Account', 'TestData Savings', 'TestData Shared'];
|
|
||||||
$budgets = ['Groceries', 'Groceries', 'Car'];
|
|
||||||
$categories = ['Bills', 'Bills', 'Car'];
|
|
||||||
foreach ($destinations as $index => $dest) {
|
|
||||||
$bud = $budgets[$index];
|
|
||||||
$cat = $categories[$index];
|
|
||||||
$destination = TestData::findAccount($user, $dest);
|
|
||||||
|
|
||||||
$one = Transaction::create(
|
|
||||||
[
|
[
|
||||||
'account_id' => $source->id,
|
'user_id' => $user->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_type_id' => 3, // transfer
|
||||||
'amount' => '-19',
|
'transaction_currency_id' => 1,
|
||||||
|
'description' => 'Split Transfer (journal)',
|
||||||
|
'completed' => 1,
|
||||||
|
'date' => $today->format('Y-m-d'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$two = Transaction::create(
|
|
||||||
[
|
|
||||||
'account_id' => $destination->id,
|
|
||||||
'transaction_journal_id' => $journal->id,
|
|
||||||
'amount' => '19',
|
|
||||||
|
|
||||||
]
|
$source = TestData::findAccount($user, 'Alternate Checking Account');
|
||||||
);
|
$destinations = ['Checking Account', 'Savings Account', 'Shared Checking Account'];
|
||||||
|
$budgets = ['Groceries', 'Groceries', 'Car'];
|
||||||
|
$categories = ['Bills', 'Bills', 'Car'];
|
||||||
|
foreach ($destinations as $index => $dest) {
|
||||||
|
$bud = $budgets[$index];
|
||||||
|
$cat = $categories[$index];
|
||||||
|
$destination = TestData::findAccount($user, $dest);
|
||||||
|
|
||||||
$one->budgets()->save(TestData::findBudget($user, $bud));
|
$one = Transaction::create(
|
||||||
$two->budgets()->save(TestData::findBudget($user, $bud));
|
[
|
||||||
|
'account_id' => $source->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => '-19',
|
||||||
|
|
||||||
$one->categories()->save(TestData::findCategory($user, $cat));
|
]
|
||||||
$two->categories()->save(TestData::findCategory($user, $cat));
|
);
|
||||||
|
|
||||||
|
$two = Transaction::create(
|
||||||
|
[
|
||||||
|
'account_id' => $destination->id,
|
||||||
|
'transaction_journal_id' => $journal->id,
|
||||||
|
'amount' => '19',
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$one->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
$two->budgets()->save(TestData::findBudget($user, $bud));
|
||||||
|
|
||||||
|
$one->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
$two->categories()->save(TestData::findCategory($user, $cat));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,11 +46,11 @@ class TestDataSeeder extends Seeder
|
|||||||
$user = TestData::createUsers();
|
$user = TestData::createUsers();
|
||||||
|
|
||||||
// create all kinds of static data:
|
// create all kinds of static data:
|
||||||
TestData::createAssetAccounts($user);
|
TestData::createAssetAccounts($user, []);
|
||||||
TestData::createBills($user);
|
TestData::createBills($user);
|
||||||
TestData::createBudgets($user);
|
TestData::createBudgets($user);
|
||||||
TestData::createCategories($user);
|
TestData::createCategories($user);
|
||||||
TestData::createPiggybanks($user);
|
TestData::createPiggybanks($user, 'TestData Savings');
|
||||||
TestData::createExpenseAccounts($user);
|
TestData::createExpenseAccounts($user);
|
||||||
TestData::createRevenueAccounts($user);
|
TestData::createRevenueAccounts($user);
|
||||||
TestData::createAttachments($user, $this->start);
|
TestData::createAttachments($user, $this->start);
|
||||||
|
Reference in New Issue
Block a user