Files
firefly-iii/app/Services/Internal/Destroy/BudgetDestroyService.php

56 lines
1.7 KiB
PHP
Raw Normal View History

2019-01-11 16:57:40 +01:00
<?php
2019-01-11 16:57:40 +01:00
/**
* BudgetDestroyService.php
2020-02-16 13:56:35 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2019-01-11 16:57:40 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2019-01-11 16:57:40 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2019-01-11 16:57:40 +01:00
*
* This program is distributed in the hope that it will be useful,
2019-01-11 16:57:40 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2019-01-11 16:57:40 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-01-11 16:57:40 +01:00
*/
declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
use FireflyIII\Models\Budget;
2025-02-23 12:47:04 +01:00
use Illuminate\Support\Facades\DB;
2019-01-11 16:57:40 +01:00
/**
* Class BudgetDestroyService
*/
class BudgetDestroyService
{
public function destroy(Budget $budget): void
{
2022-12-30 20:38:54 +01:00
$budget->delete();
2019-01-11 16:57:40 +01:00
// also delete auto budget:
foreach ($budget->autoBudgets()->get() as $autoBudget) {
$autoBudget->delete();
}
2019-01-11 16:57:40 +01:00
// also delete all relations between categories and transaction journals:
2025-02-23 12:47:04 +01:00
DB::table('budget_transaction_journal')->where('budget_id', $budget->id)->delete();
2019-01-11 16:57:40 +01:00
// also delete all relations between categories and transactions:
2025-02-23 12:47:04 +01:00
DB::table('budget_transaction')->where('budget_id', $budget->id)->delete();
2020-02-11 05:34:36 +01:00
// also delete all budget limits
2023-05-29 13:56:55 +02:00
foreach ($budget->budgetlimits()->get() as $limit) {
2023-05-13 06:17:22 +02:00
$limit->delete();
}
2019-01-11 16:57:40 +01:00
}
}