diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.php index 240afe1edb..b8f85c3950 100644 --- a/app/Support/Migration/TestData.php +++ b/app/Support/Migration/TestData.php @@ -14,6 +14,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; use FireflyIII\Models\Bill; use FireflyIII\Models\Budget; +use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\Rule; @@ -31,6 +32,7 @@ use Log; */ class TestData { + /** * @param User $user */ @@ -103,6 +105,31 @@ class TestData } + /** + * @param User $user + * @param Carbon $current + * @param $name + * @param $amount + */ + public static function createBudgetLimit(User $user, Carbon $current, $name, $amount) + { + $start = clone $current; + $end = clone $current; + $budget = self::findBudget($user, $name); + $start->startOfMonth(); + $end->endOfMonth(); + + BudgetLimit::create( + [ + 'budget_id' => $budget->id, + 'startdate' => $start->format('Y-m-d'), + 'amount' => $amount, + 'repeats' => 0, + 'repeat_freq' => 'monthly', + ] + ); + } + /** * @param User $user */ @@ -110,6 +137,7 @@ class TestData { Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]); Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]); + Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); // some empty budgets. foreach (['A', 'B', 'C', 'D', "E"] as $letter) { @@ -378,5 +406,24 @@ class TestData return null; } + /** + * @param User $user + * @param $name + * + * @return Budget|null + */ + public static function findBudget(User $user, $name) + { + /** @var Budget $budget */ + foreach (Budget::get() as $budget) { + if ($budget->name == $name && $user->id == $budget->user_id) { + return $budget; + break; + } + } + + return null; + } + } diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index 3d7e29562e..ae2df0622c 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -3,8 +3,6 @@ use Carbon\Carbon; use FireflyIII\Models\Account; use FireflyIII\Models\Attachment; -use FireflyIII\Models\Budget; -use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\Category; use FireflyIII\Models\Role; use FireflyIII\Models\Transaction; @@ -55,6 +53,11 @@ class TestDataSeeder extends Seeder // create some budgets for user #1 TestData::createBudgets($user); + // create budget limits for these budgets + TestData::createBudgetLimit($user, new Carbon, 'Groceries', 400); + TestData::createBudgetLimit($user, new Carbon, 'Bills', 1000); + TestData::createBudgetLimit($user, new Carbon, 'Car', 100); + // create some categories for user #1 $this->createCategories($user); diff --git a/database/seeds/VisualTestDataSeeder.php b/database/seeds/VisualTestDataSeeder.php index 3445684e61..b158bb283b 100644 --- a/database/seeds/VisualTestDataSeeder.php +++ b/database/seeds/VisualTestDataSeeder.php @@ -487,9 +487,9 @@ class VisualTestDataSeeder extends Seeder $this->createCar($current); // budget limit for this month, on "Groceries". - $this->createBudgetLimit($current, 'Groceries', 400); - $this->createBudgetLimit($current, 'Bills', 1000); - $this->createBudgetLimit($current, 'Car', 100); + TestData::createBudgetLimit($current, 'Groceries', 400); + TestData::createBudgetLimit($current, 'Bills', 1000); + TestData::createBudgetLimit($current, 'Car', 100); echo 'Created test data for ' . $month . "\n"; $current->addMonth(); @@ -497,30 +497,6 @@ class VisualTestDataSeeder extends Seeder } - /** - * @param Carbon $current - * @param $name - * @param $amount - */ - protected function createBudgetLimit(Carbon $current, $name, $amount) - { - $start = clone $current; - $end = clone $current; - $budget = $this->findBudget($name); - $start->startOfMonth(); - $end->endOfMonth(); - - BudgetLimit::create( - [ - 'budget_id' => $budget->id, - 'startdate' => $start->format('Y-m-d'), - 'amount' => $amount, - 'repeats' => 0, - 'repeat_freq' => 'monthly', - ] - ); - } - /** * @param $date * @@ -1085,24 +1061,6 @@ class VisualTestDataSeeder extends Seeder return null; } - /** - * @param $name - * - * @return Budget|null - */ - protected function findBudget($name) - { - /** @var Budget $budget */ - foreach (Budget::get() as $budget) { - if ($budget->name == $name && $this->user->id == $budget->user_id) { - return $budget; - break; - } - } - - return null; - } - /** * @param $name *