2015-04-05 13:47:19 -05:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* CurrencyRepositoryInterface.php
|
2017-10-21 01:40:00 -05:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 05:41:23 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
2016-10-04 23:52:15 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05: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 07:44:05 -06:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 05:41:23 -05:00
|
|
|
*/
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
2015-04-05 13:47:19 -05:00
|
|
|
|
|
|
|
namespace FireflyIII\Repositories\Currency;
|
|
|
|
|
2017-04-13 13:47:59 -05:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Models\CurrencyExchangeRate;
|
2015-04-05 13:47:19 -05:00
|
|
|
use FireflyIII\Models\Preference;
|
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2017-01-30 09:40:49 -06:00
|
|
|
use FireflyIII\User;
|
2015-04-05 13:47:19 -05:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Interface CurrencyRepositoryInterface.
|
2015-04-05 13:47:19 -05:00
|
|
|
*/
|
|
|
|
interface CurrencyRepositoryInterface
|
|
|
|
{
|
2016-12-11 09:25:46 -06:00
|
|
|
/**
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*
|
2018-12-08 14:26:20 -06:00
|
|
|
* @return int
|
2016-12-11 09:25:46 -06:00
|
|
|
*/
|
2018-12-08 14:26:20 -06:00
|
|
|
public function countJournals(TransactionCurrency $currency): int;
|
2016-12-11 09:25:46 -06:00
|
|
|
|
2015-04-05 13:47:19 -05:00
|
|
|
/**
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*
|
2018-12-08 14:26:20 -06:00
|
|
|
* @return bool
|
2015-04-05 13:47:19 -05:00
|
|
|
*/
|
2018-12-08 14:26:20 -06:00
|
|
|
public function currencyInUse(TransactionCurrency $currency): bool;
|
2015-04-05 13:47:19 -05:00
|
|
|
|
2019-08-18 01:46:36 -05:00
|
|
|
/**
|
|
|
|
* Currency is in use where exactly.
|
|
|
|
*
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function currencyInUseAt(TransactionCurrency $currency): ?string;
|
|
|
|
|
2016-12-11 09:25:46 -06:00
|
|
|
/**
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function destroy(TransactionCurrency $currency): bool;
|
|
|
|
|
2018-11-10 03:04:46 -06:00
|
|
|
/**
|
|
|
|
* Disables a currency
|
|
|
|
*
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*/
|
|
|
|
public function disable(TransactionCurrency $currency): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables a currency
|
|
|
|
*
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*/
|
|
|
|
public function enable(TransactionCurrency $currency): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find by ID, return NULL if not found.
|
|
|
|
*
|
|
|
|
* @param int $currencyId
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency|null
|
|
|
|
*/
|
|
|
|
public function find(int $currencyId): ?TransactionCurrency;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find by currency code, return NULL if unfound.
|
|
|
|
*
|
|
|
|
* @param string $currencyCode
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency|null
|
|
|
|
*/
|
|
|
|
public function findByCode(string $currencyCode): ?TransactionCurrency;
|
|
|
|
|
2018-02-16 08:19:19 -06:00
|
|
|
/**
|
|
|
|
* Find by currency code, return NULL if unfound.
|
|
|
|
*
|
|
|
|
* @param string $currencyCode
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency|null
|
|
|
|
*/
|
|
|
|
public function findByCodeNull(string $currencyCode): ?TransactionCurrency;
|
|
|
|
|
2018-11-10 03:04:46 -06:00
|
|
|
/**
|
|
|
|
* Find by currency name.
|
|
|
|
*
|
|
|
|
* @param string $currencyName
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency
|
|
|
|
*/
|
|
|
|
public function findByName(string $currencyName): ?TransactionCurrency;
|
|
|
|
|
2016-04-01 07:10:08 -05:00
|
|
|
/**
|
2018-03-24 04:35:42 -05:00
|
|
|
* Find by currency name.
|
|
|
|
*
|
|
|
|
* @param string $currencyName
|
2016-04-01 07:10:08 -05:00
|
|
|
*
|
2018-03-24 04:35:42 -05:00
|
|
|
* @return TransactionCurrency
|
|
|
|
*/
|
|
|
|
public function findByNameNull(string $currencyName): ?TransactionCurrency;
|
|
|
|
|
2018-11-10 03:04:46 -06:00
|
|
|
/**
|
|
|
|
* Find by currency symbol.
|
|
|
|
*
|
|
|
|
* @param string $currencySymbol
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency
|
|
|
|
*/
|
|
|
|
public function findBySymbol(string $currencySymbol): ?TransactionCurrency;
|
|
|
|
|
2018-03-24 04:35:42 -05:00
|
|
|
/**
|
|
|
|
* Find by currency symbol.
|
|
|
|
*
|
|
|
|
* @param string $currencySymbol
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency
|
|
|
|
*/
|
|
|
|
public function findBySymbolNull(string $currencySymbol): ?TransactionCurrency;
|
|
|
|
|
2019-03-07 22:47:51 -06:00
|
|
|
/**
|
|
|
|
* Find by object, ID or code. Returns user default or system default.
|
|
|
|
*
|
2019-04-06 01:10:50 -05:00
|
|
|
* @param int|null $currencyId
|
|
|
|
* @param string|null $currencyCode
|
2019-03-07 22:47:51 -06:00
|
|
|
*
|
|
|
|
* @return TransactionCurrency|null
|
|
|
|
*/
|
2019-03-31 06:36:49 -05:00
|
|
|
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency;
|
2019-03-07 22:47:51 -06:00
|
|
|
|
2019-04-06 01:10:50 -05:00
|
|
|
/**
|
|
|
|
* Find by object, ID or code. Returns NULL if nothing found.
|
|
|
|
*
|
|
|
|
* @param int|null $currencyId
|
|
|
|
* @param string|null $currencyCode
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency|null
|
|
|
|
*/
|
|
|
|
public function findCurrencyNull(?int $currencyId, ?string $currencyCode): ?TransactionCurrency;
|
|
|
|
|
2018-02-16 08:19:19 -06:00
|
|
|
/**
|
|
|
|
* Find by ID, return NULL if not found.
|
|
|
|
*
|
|
|
|
* @param int $currencyId
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency|null
|
|
|
|
*/
|
|
|
|
public function findNull(int $currencyId): ?TransactionCurrency;
|
|
|
|
|
2015-04-05 13:47:19 -05:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2016-04-05 15:00:03 -05:00
|
|
|
public function get(): Collection;
|
2015-04-05 13:47:19 -05:00
|
|
|
|
2018-11-10 03:04:46 -06:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getAll(): Collection;
|
|
|
|
|
2017-08-18 08:14:44 -05:00
|
|
|
/**
|
|
|
|
* @param array $ids
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getByIds(array $ids): Collection;
|
|
|
|
|
2015-04-05 13:47:19 -05:00
|
|
|
/**
|
|
|
|
* @param Preference $preference
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency
|
|
|
|
*/
|
2016-04-05 15:00:03 -05:00
|
|
|
public function getCurrencyByPreference(Preference $preference): TransactionCurrency;
|
2015-04-05 13:47:19 -05:00
|
|
|
|
2019-08-31 02:35:35 -05:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getEnabled(): Collection;
|
|
|
|
|
2017-04-13 13:47:59 -05:00
|
|
|
/**
|
2018-06-28 00:32:58 -05:00
|
|
|
* Get currency exchange rate.
|
|
|
|
*
|
2017-04-13 13:47:59 -05:00
|
|
|
* @param TransactionCurrency $fromCurrency
|
|
|
|
* @param TransactionCurrency $toCurrency
|
|
|
|
* @param Carbon $date
|
|
|
|
*
|
2018-06-28 00:32:58 -05:00
|
|
|
* @return CurrencyExchangeRate|null
|
2017-04-13 13:47:59 -05:00
|
|
|
*/
|
2018-06-28 00:32:58 -05:00
|
|
|
public function getExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): ?CurrencyExchangeRate;
|
2017-04-13 13:47:59 -05:00
|
|
|
|
2018-12-08 14:26:20 -06:00
|
|
|
/**
|
|
|
|
* Return a list of exchange rates with this currency.
|
|
|
|
*
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getExchangeRates(TransactionCurrency $currency): Collection;
|
|
|
|
|
2019-08-31 02:35:35 -05:00
|
|
|
/**
|
|
|
|
* @param string $search
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function searchCurrency(string $search): Collection;
|
|
|
|
|
2017-01-30 09:46:30 -06:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
*/
|
|
|
|
public function setUser(User $user);
|
|
|
|
|
2015-04-05 13:47:19 -05:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
2018-05-10 02:10:16 -05:00
|
|
|
* @return TransactionCurrency|null
|
2015-04-05 13:47:19 -05:00
|
|
|
*/
|
2018-05-10 02:10:16 -05:00
|
|
|
public function store(array $data): ?TransactionCurrency;
|
2015-04-05 13:47:19 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param TransactionCurrency $currency
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return TransactionCurrency
|
|
|
|
*/
|
2016-04-05 15:00:03 -05:00
|
|
|
public function update(TransactionCurrency $currency, array $data): TransactionCurrency;
|
2015-04-07 11:25:21 -05:00
|
|
|
}
|