firefly-iii/database/seeds/TestDataSeeder.php

95 lines
2.8 KiB
PHP
Raw Normal View History

2015-02-05 21:41:00 -06:00
<?php
2016-02-05 08:01:33 -06:00
declare(strict_types = 1);
/**
* TestDataSeeder.php
2016-04-01 09:46:11 -05:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-05 08:01:33 -06:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2016-01-16 02:15:24 -06:00
2016-01-20 02:15:33 -06:00
use Carbon\Carbon;
2016-01-30 00:36:11 -06:00
use FireflyIII\Support\Migration\TestData;
2015-02-11 00:35:10 -06:00
use Illuminate\Database\Seeder;
2015-02-05 21:41:00 -06:00
/**
* Class TestDataSeeder
*/
class TestDataSeeder extends Seeder
{
2016-02-05 08:01:33 -06:00
/** @var Carbon */
public $end;
2016-01-24 13:38:58 -06:00
/** @var Carbon */
public $start;
/**
* TestDataSeeder constructor.
*/
public function __construct()
{
2016-02-05 08:01:33 -06:00
$this->start = Carbon::create()->subYears(2)->startOfYear();
$this->end = Carbon::now();
2016-01-24 13:38:58 -06:00
}
2015-02-05 21:41:00 -06:00
/**
2016-01-16 02:15:24 -06:00
* Run the database seeds.
2015-06-29 08:23:50 -05:00
*
2016-01-16 02:15:24 -06:00
* @return void
2015-02-05 21:41:00 -06:00
*/
public function run()
{
2016-02-05 08:01:33 -06:00
// start by creating all users:
// method will return the first user.
$user = TestData::createUsers();
2016-01-24 09:05:14 -06:00
2016-02-05 08:01:33 -06:00
// create all kinds of static data:
TestData::createAssetAccounts($user);
TestData::createBills($user);
2016-02-04 04:00:26 -06:00
TestData::createBudgets($user);
2016-02-05 08:01:33 -06:00
TestData::createCategories($user);
TestData::createPiggybanks($user);
2016-02-05 08:01:33 -06:00
TestData::createExpenseAccounts($user);
TestData::createRevenueAccounts($user);
2016-02-04 10:13:58 -06:00
TestData::createAttachments($user, $this->start);
2016-02-05 08:01:33 -06:00
TestData::openingBalanceSavings($user, $this->start);
TestData::createRules($user);
2016-01-24 13:38:58 -06:00
2016-02-05 08:01:33 -06:00
// loop from start to end, create dynamic info.
$current = clone $this->start;
while ($current < $this->end) {
$month = $current->format('F Y');
// create salaries:
TestData::createIncome($user, 'Salary ' . $month, $current, strval(rand(2000, 2100)));
2016-02-04 04:00:26 -06:00
2016-02-05 08:01:33 -06:00
// pay bills:
TestData::createRent($user, 'Rent for ' . $month, $current, '800');
2016-02-05 08:20:44 -06:00
TestData::createWater($user, 'Water bill for ' . $month, $current, '15');
TestData::createTV($user, 'TV bill for ' . $month, $current, '60');
TestData::createPower($user, 'Power bill for ' . $month, $current, '120');
2016-01-30 00:36:11 -06:00
2016-02-05 08:01:33 -06:00
// pay daily groceries:
2016-02-05 08:20:44 -06:00
TestData::createGroceries($user, $current);
2016-01-20 02:31:24 -06:00
2016-02-05 08:01:33 -06:00
// create tag (each type of tag, for date):
2016-02-05 08:20:44 -06:00
TestData::createTags($user, $current);
2016-01-24 13:38:58 -06:00
2016-02-05 08:01:33 -06:00
// go out for drinks:
2016-02-05 08:20:44 -06:00
TestData::createDrinksAndOthers($user, $current);
2016-01-24 13:38:58 -06:00
2016-02-05 08:01:33 -06:00
// save money every month:
2016-02-05 08:20:44 -06:00
TestData::createSavings($user, $current);
2016-01-20 03:47:29 -06:00
2016-02-05 08:01:33 -06:00
// buy gas for the car every month:
2016-02-05 08:20:44 -06:00
TestData::createCar($user, $current);
2016-01-20 03:47:29 -06:00
2016-02-05 08:01:33 -06:00
// create budget limits.
TestData::createBudgetLimit($user, $current, 'Groceries', '400');
TestData::createBudgetLimit($user, $current, 'Bills', '1000');
TestData::createBudgetLimit($user, $current, 'Car', '100');
2016-01-20 03:47:29 -06:00
2016-02-05 08:01:33 -06:00
$current->addMonth();
}
2016-01-20 03:47:29 -06:00
}
2015-03-29 01:14:32 -05:00
}