2015-02-22 09:46:21 +01:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* BudgetRepositoryInterface.php
|
2017-10-21 08:40:00 +02:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 12:41:23 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 14:44:05 +01:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2015-02-22 09:46:21 +01:00
|
|
|
|
|
|
|
namespace FireflyIII\Repositories\Budget;
|
2015-02-23 21:19:16 +01:00
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2018-06-24 08:33:06 +02:00
|
|
|
use FireflyIII\Models\AvailableBudget;
|
2015-02-22 09:46:21 +01:00
|
|
|
use FireflyIII\Models\Budget;
|
2016-04-05 22:00:03 +02:00
|
|
|
use FireflyIII\Models\BudgetLimit;
|
2016-12-22 16:36:56 +01:00
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2017-01-30 16:40:49 +01:00
|
|
|
use FireflyIII\User;
|
2015-04-05 10:36:28 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2015-02-23 21:19:16 +01:00
|
|
|
|
2015-02-22 09:46:21 +01:00
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Interface BudgetRepositoryInterface.
|
2015-02-22 09:46:21 +01:00
|
|
|
*/
|
|
|
|
interface BudgetRepositoryInterface
|
|
|
|
{
|
2018-05-07 20:35:14 +02:00
|
|
|
|
2018-03-24 06:46:37 +01:00
|
|
|
/**
|
|
|
|
* A method that returns the amount of money budgeted per day for this budget,
|
|
|
|
* on average.
|
|
|
|
*
|
|
|
|
* @param Budget $budget
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function budgetedPerDay(Budget $budget): string;
|
|
|
|
|
2018-04-02 15:10:40 +02:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function cleanupBudgets(): bool;
|
|
|
|
|
2017-09-27 08:45:27 +02:00
|
|
|
/**
|
|
|
|
* This method collects various info on budgets, used on the budget page and on the index.
|
|
|
|
*
|
|
|
|
* @param Collection $budgets
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
|
|
*/
|
|
|
|
public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array;
|
|
|
|
|
2018-06-24 13:20:29 +02:00
|
|
|
/**
|
|
|
|
* Deletes a budget limit.
|
|
|
|
*
|
|
|
|
* @param BudgetLimit $budgetLimit
|
|
|
|
*/
|
|
|
|
public function deleteBudgetLimit(BudgetLimit $budgetLimit): void;
|
|
|
|
|
2016-05-06 06:15:46 +02:00
|
|
|
/**
|
|
|
|
* @param Budget $budget
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function destroy(Budget $budget): bool;
|
|
|
|
|
2018-06-24 08:33:06 +02:00
|
|
|
/**
|
|
|
|
* @param AvailableBudget $availableBudget
|
|
|
|
*/
|
|
|
|
public function destroyAvailableBudget(AvailableBudget $availableBudget): void;
|
|
|
|
|
2016-11-19 13:37:44 +01:00
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Filters entries from the result set generated by getBudgetPeriodReport.
|
2016-11-19 13:37:44 +01:00
|
|
|
*
|
|
|
|
* @param Collection $set
|
|
|
|
* @param int $budgetId
|
|
|
|
* @param array $periods
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function filterAmounts(Collection $set, int $budgetId, array $periods): array;
|
|
|
|
|
2015-12-29 08:27:13 +01:00
|
|
|
/**
|
2016-05-06 06:15:46 +02:00
|
|
|
* Find a budget.
|
2015-12-29 08:27:13 +01:00
|
|
|
*
|
2016-05-06 06:15:46 +02:00
|
|
|
* @param int $budgetId
|
2018-03-10 22:38:20 +01:00
|
|
|
*
|
2018-02-16 15:19:19 +01:00
|
|
|
* @deprecated
|
2016-05-06 06:15:46 +02:00
|
|
|
*
|
|
|
|
* @return Budget
|
2015-12-29 08:27:13 +01:00
|
|
|
*/
|
2016-05-06 06:15:46 +02:00
|
|
|
public function find(int $budgetId): Budget;
|
2015-12-29 08:27:13 +01:00
|
|
|
|
2018-02-16 15:19:19 +01:00
|
|
|
/**
|
2018-03-10 22:38:20 +01:00
|
|
|
* Find a budget.
|
2018-02-16 15:19:19 +01:00
|
|
|
*
|
2018-03-10 22:38:20 +01:00
|
|
|
* @param string $name
|
2018-02-16 15:19:19 +01:00
|
|
|
*
|
|
|
|
* @return Budget|null
|
|
|
|
*/
|
2018-03-10 22:38:20 +01:00
|
|
|
public function findByName(string $name): ?Budget;
|
2018-02-16 15:19:19 +01:00
|
|
|
|
2016-07-24 18:47:55 +02:00
|
|
|
/**
|
2018-03-10 22:38:20 +01:00
|
|
|
* Find a budget or return NULL
|
2016-07-24 18:47:55 +02:00
|
|
|
*
|
2018-03-10 22:38:20 +01:00
|
|
|
* @param int $budgetId
|
2016-07-24 18:47:55 +02:00
|
|
|
*
|
2018-02-16 15:19:19 +01:00
|
|
|
* @return Budget|null
|
2016-07-24 18:47:55 +02:00
|
|
|
*/
|
2018-03-10 22:38:20 +01:00
|
|
|
public function findNull(int $budgetId): ?Budget;
|
2016-07-24 18:47:55 +02:00
|
|
|
|
2016-05-06 10:32:26 +02:00
|
|
|
/**
|
|
|
|
* This method returns the oldest journal or transaction date known to this budget.
|
|
|
|
* Will cache result.
|
2016-05-11 09:08:18 +02:00
|
|
|
*
|
2016-05-06 10:32:26 +02:00
|
|
|
* @param Budget $budget
|
|
|
|
*
|
|
|
|
* @return Carbon
|
|
|
|
*/
|
|
|
|
public function firstUseDate(Budget $budget): Carbon;
|
|
|
|
|
2016-04-01 13:17:07 +02:00
|
|
|
/**
|
2016-05-06 06:15:46 +02:00
|
|
|
* @return Collection
|
2016-04-01 13:17:07 +02:00
|
|
|
*/
|
2016-05-06 06:15:46 +02:00
|
|
|
public function getActiveBudgets(): Collection;
|
2016-04-01 13:17:07 +02:00
|
|
|
|
2016-12-30 13:47:23 +01:00
|
|
|
/**
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2018-06-24 13:20:29 +02:00
|
|
|
public function getAllBudgetLimits(Carbon $start = null, Carbon $end = null): Collection;
|
2016-12-30 13:47:23 +01:00
|
|
|
|
2016-12-22 16:36:56 +01:00
|
|
|
/**
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string;
|
|
|
|
|
2018-06-24 08:33:06 +02:00
|
|
|
/**
|
|
|
|
* Returns all available budget objects.
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getAvailableBudgets(): Collection;
|
|
|
|
|
2016-12-29 20:48:33 +01:00
|
|
|
/**
|
|
|
|
* @param Budget $budget
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2018-06-24 13:20:29 +02:00
|
|
|
public function getBudgetLimits(Budget $budget, Carbon $start = null, Carbon $end = null): Collection;
|
2016-12-29 20:48:33 +01:00
|
|
|
|
2016-11-19 13:37:44 +01:00
|
|
|
/**
|
|
|
|
* @param Collection $budgets
|
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
2016-11-26 07:18:20 +01:00
|
|
|
* @return array
|
2016-11-19 13:37:44 +01:00
|
|
|
*/
|
2016-12-04 18:02:19 +01:00
|
|
|
public function getBudgetPeriodReport(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array;
|
2016-11-19 13:37:44 +01:00
|
|
|
|
2016-05-06 06:15:46 +02:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getBudgets(): Collection;
|
|
|
|
|
2018-06-06 21:23:00 +02:00
|
|
|
/**
|
|
|
|
* Get all budgets with these ID's.
|
|
|
|
*
|
|
|
|
* @param array $budgetIds
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getByIds(array $budgetIds): Collection;
|
|
|
|
|
2015-02-22 15:40:13 +01:00
|
|
|
/**
|
2016-01-20 15:21:27 +01:00
|
|
|
* @return Collection
|
2015-02-22 15:40:13 +01:00
|
|
|
*/
|
2016-05-06 06:15:46 +02:00
|
|
|
public function getInactiveBudgets(): Collection;
|
2015-02-22 09:46:21 +01:00
|
|
|
|
2016-12-04 18:02:19 +01:00
|
|
|
/**
|
2016-12-15 17:16:46 +01:00
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-12-04 18:02:19 +01:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
|
|
|
|
2016-12-22 16:36:56 +01:00
|
|
|
/**
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
* @param string $amount
|
|
|
|
*
|
2018-06-24 08:33:06 +02:00
|
|
|
* @return AvailableBudget
|
2016-12-22 16:36:56 +01:00
|
|
|
*/
|
2018-06-24 08:33:06 +02:00
|
|
|
public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget;
|
2016-12-22 16:36:56 +01:00
|
|
|
|
2017-01-30 16:46:30 +01:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
public function setUser(User $user);
|
|
|
|
|
2017-01-05 09:07:04 +01:00
|
|
|
/**
|
|
|
|
* @param Collection $budgets
|
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-05 09:08:35 +01:00
|
|
|
public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string;
|
2017-01-05 09:07:04 +01:00
|
|
|
|
2018-06-24 08:33:06 +02:00
|
|
|
|
2017-01-05 09:07:04 +01:00
|
|
|
/**
|
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-05 09:10:04 +01:00
|
|
|
public function spentInPeriodWoBudget(Collection $accounts, Carbon $start, Carbon $end): string;
|
2017-01-05 09:07:04 +01:00
|
|
|
|
2015-02-22 15:40:13 +01:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return Budget
|
|
|
|
*/
|
2016-04-05 22:00:03 +02:00
|
|
|
public function store(array $data): Budget;
|
2015-02-22 15:40:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Budget $budget
|
2015-02-23 21:19:16 +01:00
|
|
|
* @param array $data
|
2015-02-22 15:40:13 +01:00
|
|
|
*
|
|
|
|
* @return Budget
|
|
|
|
*/
|
2016-12-03 21:03:20 +01:00
|
|
|
public function update(Budget $budget, array $data): Budget;
|
2015-02-22 15:40:13 +01:00
|
|
|
|
2018-06-24 08:33:06 +02:00
|
|
|
/**
|
|
|
|
* @param AvailableBudget $availableBudget
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return AvailableBudget
|
|
|
|
*/
|
|
|
|
public function updateAvailableBudget(AvailableBudget $availableBudget, array $data): AvailableBudget;
|
|
|
|
|
2018-06-24 13:20:29 +02:00
|
|
|
/**
|
|
|
|
* @param BudgetLimit $budgetLimit
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return BudgetLimit
|
|
|
|
*/
|
|
|
|
public function updateBudgetLimit(BudgetLimit $budgetLimit, array $data): BudgetLimit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return BudgetLimit
|
|
|
|
*/
|
|
|
|
public function storeBudgetLimit(array $data): BudgetLimit;
|
|
|
|
|
2015-02-22 15:40:13 +01:00
|
|
|
/**
|
2015-04-06 09:15:59 +02:00
|
|
|
* @param Budget $budget
|
2016-04-28 10:59:36 +02:00
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2017-11-25 08:54:52 +01:00
|
|
|
* @param string $amount
|
2015-02-22 15:40:13 +01:00
|
|
|
*
|
2016-04-05 22:00:03 +02:00
|
|
|
* @return BudgetLimit
|
2015-02-22 15:40:13 +01:00
|
|
|
*/
|
2017-11-18 11:32:35 +01:00
|
|
|
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit;
|
2015-03-29 08:14:32 +02:00
|
|
|
}
|