mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-07 10:28:22 +00:00
Updated test data.
This commit is contained in:
@@ -30,7 +30,6 @@ use FireflyIII\Models\Tag;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TestData
|
* Class TestData
|
||||||
@@ -90,20 +89,16 @@ class TestData
|
|||||||
public static function createAttachments(User $user, Carbon $start): TransactionJournal
|
public static function createAttachments(User $user, Carbon $start): TransactionJournal
|
||||||
{
|
{
|
||||||
|
|
||||||
$toAccount = TestData::findAccount($user, 'TestData Checking Account');
|
$args = [
|
||||||
$fromAccount = TestData::findAccount($user, 'Job');
|
'user' => $user,
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 2,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Some journal for attachment',
|
'description' => 'Some journal for attachment',
|
||||||
'completed' => 1,
|
'date' => $start,
|
||||||
'date' => $start->format('Y-m-d'),
|
'from' => 'Job',
|
||||||
]
|
'to' => 'TestData Checking Account',
|
||||||
);
|
'amount' => '100',
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, '100');
|
'transaction_type' => 2,
|
||||||
|
];
|
||||||
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
// and now attachments
|
// and now attachments
|
||||||
$encrypted = Crypt::encrypt('I are secret');
|
$encrypted = Crypt::encrypt('I are secret');
|
||||||
@@ -245,45 +240,24 @@ class TestData
|
|||||||
public static function createCar(User $user, Carbon $date): TransactionJournal
|
public static function createCar(User $user, Carbon $date): TransactionJournal
|
||||||
{
|
{
|
||||||
// twice:
|
// twice:
|
||||||
$date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th
|
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
|
||||||
$toAccount = TestData::findAccount($user, 'Shell');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
|
|
||||||
$amount = strval(rand(4000, 5000) / 100);
|
$amount = strval(rand(4000, 5000) / 100);
|
||||||
$journal = TransactionJournal::create(
|
$args = [
|
||||||
[
|
'user' => $user,
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Bought gas',
|
'description' => 'Bought gas',
|
||||||
'completed' => 1,
|
'date' => new Carbon($date->format('Y-m') . '-10'),// paid on 10th
|
||||||
'date' => $date,
|
'from' => 'TestData Checking Account',
|
||||||
]
|
'to' => 'Shell',
|
||||||
);
|
'amount' => $amount,
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'category' => 'Car',
|
||||||
|
'budget' => 'Car',
|
||||||
|
];
|
||||||
|
self::createJournal($args);
|
||||||
|
|
||||||
$journal->categories()->save($category);
|
// again!
|
||||||
$journal->budgets()->save($budget);
|
$args['date'] = new Carbon($date->format('Y-m') . '-20'); // paid on 20th
|
||||||
|
$args['amount'] = strval(rand(4000, 5000) / 100);
|
||||||
// and again!
|
$args['description'] = 'Gas for car';
|
||||||
$date = new Carbon($date->format('Y-m') . '-20'); // paid on 20th
|
$journal = self::createJournal($args);
|
||||||
$amount = rand(4000, 5000) / 100;
|
|
||||||
|
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Gas for car',
|
|
||||||
'completed' => 1,
|
|
||||||
'date' => $date,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, strval($amount));
|
|
||||||
|
|
||||||
// and again!
|
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
}
|
}
|
||||||
@@ -322,28 +296,18 @@ class TestData
|
|||||||
// weekly drink:
|
// weekly drink:
|
||||||
$thisDate = clone $current;
|
$thisDate = clone $current;
|
||||||
$thisDate->addDay();
|
$thisDate->addDay();
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
|
||||||
$toAccount = TestData::findAccount($user, 'Cafe Central');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'Drinks', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Going out', 'user_id' => $user->id]);
|
|
||||||
$amount = strval(rand(1500, 3600) / 100);
|
$amount = strval(rand(1500, 3600) / 100);
|
||||||
$journal = TransactionJournal::create(
|
$args = [
|
||||||
[
|
'user' => $user,
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Going out for drinks',
|
'description' => 'Going out for drinks',
|
||||||
'completed' => 1,
|
|
||||||
'date' => $thisDate,
|
'date' => $thisDate,
|
||||||
]
|
'from' => 'TestData Checking Account',
|
||||||
);
|
'to' => 'Cafe Central',
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'amount' => $amount,
|
||||||
|
'category' => 'Drinks',
|
||||||
$journal->categories()->save($category);
|
'budget' => 'Going out',
|
||||||
$journal->budgets()->save($budget);
|
];
|
||||||
|
self::createJournal($args);
|
||||||
// shopping at some (online) shop:
|
|
||||||
|
|
||||||
|
|
||||||
$current->addWeek();
|
$current->addWeek();
|
||||||
}
|
}
|
||||||
@@ -395,35 +359,25 @@ class TestData
|
|||||||
$start->startOfMonth();
|
$start->startOfMonth();
|
||||||
$end->endOfMonth();
|
$end->endOfMonth();
|
||||||
|
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
|
||||||
$stores = ['Albert Heijn', 'PLUS', 'Bakker'];
|
$stores = ['Albert Heijn', 'PLUS', 'Bakker'];
|
||||||
$descriptions = ['Groceries', 'Bought some groceries', 'Got groceries'];
|
$descriptions = ['Groceries', 'Bought some groceries', 'Got groceries'];
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'Daily groceries', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
|
|
||||||
|
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
while ($current < $end && $current < $today) {
|
while ($current < $end && $current < $today) {
|
||||||
// daily groceries:
|
// daily groceries:
|
||||||
$toAccount = TestData::findAccount($user, $stores[rand(0, count($stores) - 1)]);
|
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => $descriptions[rand(0, count($descriptions) - 1)],
|
|
||||||
'completed' => 1,
|
|
||||||
'date' => $current,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
if ($journal->id) {
|
|
||||||
$amount = (string)round((rand(1500, 2500) / 100), 2);
|
$amount = (string)round((rand(1500, 2500) / 100), 2);
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
|
||||||
$journal->categories()->save($category);
|
|
||||||
$journal->budgets()->save($budget);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$args = [
|
||||||
|
'user' => $user,
|
||||||
|
'description' => $descriptions[rand(0, count($descriptions) - 1)],
|
||||||
|
'date' => $current,
|
||||||
|
'from' => 'TestData Checking Account',
|
||||||
|
'to' => $stores[rand(0, count($stores) - 1)],
|
||||||
|
'amount' => $amount,
|
||||||
|
'category' => 'Daily groceries',
|
||||||
|
'budget' => 'Groceries',
|
||||||
|
];
|
||||||
|
self::createJournal($args);
|
||||||
$current->addDay();
|
$current->addDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,28 +399,54 @@ class TestData
|
|||||||
if ($date >= $today) {
|
if ($date >= $today) {
|
||||||
return new TransactionJournal;
|
return new TransactionJournal;
|
||||||
}
|
}
|
||||||
$toAccount = TestData::findAccount($user, 'TestData Checking Account');
|
|
||||||
$fromAccount = TestData::findAccount($user, 'Job');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'Salary', 'user_id' => $user->id]);
|
|
||||||
// create journal:
|
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
// create journal:
|
||||||
[
|
$args = [
|
||||||
'user_id' => $user->id,
|
'user' => $user,
|
||||||
'transaction_type_id' => 2,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'completed' => 1,
|
|
||||||
'date' => $date,
|
'date' => $date,
|
||||||
]
|
'from' => 'Job',
|
||||||
);
|
'to' => 'TestData Checking Account',
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'amount' => $amount,
|
||||||
$journal->categories()->save($category);
|
'category' => 'Salary',
|
||||||
|
'transaction_type' => 2,
|
||||||
|
];
|
||||||
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $opt
|
||||||
|
*
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public static function createJournal(array $opt): TransactionJournal
|
||||||
|
{
|
||||||
|
$type = $opt['transaction_type'] ?? 1;
|
||||||
|
|
||||||
|
$journal = TransactionJournal::create(
|
||||||
|
[
|
||||||
|
'user_id' => $opt['user']->id,
|
||||||
|
'transaction_type_id' => $type,
|
||||||
|
'transaction_currency_id' => 1,
|
||||||
|
'description' => $opt['description'],
|
||||||
|
'completed' => 1,
|
||||||
|
'date' => $opt['date'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
self::createTransactions($journal, self::findAccount($opt['user'], $opt['from']), self::findAccount($opt['user'], $opt['to']), $opt['amount']);
|
||||||
|
if (isset($opt['category'])) {
|
||||||
|
$journal->categories()->save(self::findCategory($opt['user'], $opt['category']));
|
||||||
|
}
|
||||||
|
if (isset($opt['budget'])) {
|
||||||
|
$journal->budgets()->save(self::findBudget($opt['user'], $opt['budget']));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $journal;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
@@ -619,24 +599,17 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createPower(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
public static function createPower(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
||||||
{
|
{
|
||||||
$date = new Carbon($date->format('Y-m') . '-06'); // paid on 10th
|
$args = [
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
'user' => $user,
|
||||||
$toAccount = TestData::findAccount($user, 'Greenchoice');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'completed' => 1,
|
'date' => new Carbon($date->format('Y-m') . '-06'),// paid on 10th
|
||||||
'date' => $date,
|
'from' => 'TestData Checking Account',
|
||||||
]
|
'to' => 'Greenchoice',
|
||||||
);
|
'amount' => $amount,
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'category' => 'House',
|
||||||
$journal->categories()->save($category);
|
'budget' => 'Bills',
|
||||||
$journal->budgets()->save($budget);
|
];
|
||||||
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
@@ -652,25 +625,17 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createRent(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
public static function createRent(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
||||||
{
|
{
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
$args = [
|
||||||
$toAccount = TestData::findAccount($user, 'Land lord');
|
'user' => $user,
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'Rent', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'bill_id' => 1,
|
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'completed' => 1,
|
|
||||||
'date' => $date,
|
'date' => $date,
|
||||||
]
|
'from' => 'TestData Checking Account',
|
||||||
);
|
'to' => 'Land lord',
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'amount' => $amount,
|
||||||
|
'category' => 'Rent',
|
||||||
$journal->categories()->save($category);
|
'budget' => 'Bills',
|
||||||
$journal->budgets()->save($budget);
|
];
|
||||||
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
@@ -791,24 +756,17 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createSavings(User $user, Carbon $date): TransactionJournal
|
public static function createSavings(User $user, Carbon $date): TransactionJournal
|
||||||
{
|
{
|
||||||
$date = new Carbon($date->format('Y-m') . '-24'); // paid on 24th.
|
$args = [
|
||||||
$toAccount = TestData::findAccount($user, 'TestData Savings');
|
'user' => $user,
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'Money management', 'user_id' => $user->id]);
|
|
||||||
// create journal:
|
|
||||||
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 3,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => 'Save money',
|
'description' => 'Save money',
|
||||||
'completed' => 1,
|
'date' => new Carbon($date->format('Y-m') . '-24'),// paid on 24th.
|
||||||
'date' => $date,
|
'from' => 'TestData Checking Account',
|
||||||
]
|
'to' => 'TestData Savings',
|
||||||
);
|
'amount' => '150',
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, '150');
|
'category' => 'Money management',
|
||||||
$journal->categories()->save($category);
|
'transaction_type' => 3,
|
||||||
|
];
|
||||||
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
@@ -824,25 +782,17 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createTV(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
public static function createTV(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
||||||
{
|
{
|
||||||
$date = new Carbon($date->format('Y-m') . '-15'); // paid on 10th
|
$args = [
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
'user' => $user,
|
||||||
$toAccount = TestData::findAccount($user, 'XS4All');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'completed' => 1,
|
'date' => new Carbon($date->format('Y-m') . '-15'),
|
||||||
'date' => $date,
|
'from' => 'TestData Checking Account',
|
||||||
]
|
'to' => 'XS4All',
|
||||||
);
|
'amount' => $amount,
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'category' => 'House',
|
||||||
|
'budget' => 'Bills',
|
||||||
$journal->categories()->save($category);
|
];
|
||||||
$journal->budgets()->save($budget);
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
@@ -882,8 +832,8 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createTransactions(TransactionJournal $journal, Account $from, Account $to, string $amount): bool
|
public static function createTransactions(TransactionJournal $journal, Account $from, Account $to, string $amount): bool
|
||||||
{
|
{
|
||||||
Log::debug('---- Transaction From: ' . bcmul($amount, '-1'));
|
// Log::debug('---- Transaction From: ' . bcmul($amount, '-1'));
|
||||||
Log::debug('---- Transaction To : ' . $amount);
|
// Log::debug('---- Transaction To : ' . $amount);
|
||||||
Transaction::create(
|
Transaction::create(
|
||||||
[
|
[
|
||||||
'account_id' => $from->id,
|
'account_id' => $from->id,
|
||||||
@@ -930,24 +880,17 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createWater(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
public static function createWater(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
||||||
{
|
{
|
||||||
$date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th
|
$args = [
|
||||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
'user' => $user,
|
||||||
$toAccount = TestData::findAccount($user, 'Vitens');
|
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $user->id]);
|
|
||||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
|
||||||
$journal = TransactionJournal::create(
|
|
||||||
[
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'transaction_type_id' => 1,
|
|
||||||
'transaction_currency_id' => 1,
|
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'completed' => 1,
|
'date' => new Carbon($date->format('Y-m') . '-10'), // paid on 10th
|
||||||
'date' => $date,
|
'from' => 'TestData Checking Account',
|
||||||
]
|
'to' => 'Vitens',
|
||||||
);
|
'amount' => $amount,
|
||||||
self::createTransactions($journal, $fromAccount, $toAccount, $amount);
|
'category' => 'House',
|
||||||
$journal->categories()->save($category);
|
'budget' => 'Bills',
|
||||||
$journal->budgets()->save($budget);
|
];
|
||||||
|
$journal = self::createJournal($args);
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
@@ -986,7 +929,25 @@ class TestData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Budget;
|
return Budget::firstOrCreateEncrypted(['name' => $name, 'user_id' => $user->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param $name
|
||||||
|
*
|
||||||
|
* @return Category
|
||||||
|
*/
|
||||||
|
public static function findCategory(User $user, string $name): Category
|
||||||
|
{
|
||||||
|
/** @var Category $category */
|
||||||
|
foreach (Category::get() as $category) {
|
||||||
|
if ($category->name == $name && $user->id == $category->user_id) {
|
||||||
|
return $category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Category::firstOrCreateEncrypted(['name' => $name, 'user_id' => $user->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1022,6 +983,7 @@ class TestData
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
self::createTransactions($journal, $opposing, $savings, '10000');
|
self::createTransactions($journal, $opposing, $savings, '10000');
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user