mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	Remove unused code.
This commit is contained in:
		| @@ -1,415 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * AccountRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Account; | ||||
| 
 | ||||
| use FireflyIII\Enums\AccountTypeEnum; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\AccountMeta; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\ObjectGroup; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Services\Internal\Update\AccountUpdateService; | ||||
| use FireflyIII\Support\Facades\Amount; | ||||
| use FireflyIII\Support\Facades\Steam; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Override; | ||||
| use stdClass; | ||||
| 
 | ||||
| use function Safe\json_encode; | ||||
| 
 | ||||
| /** | ||||
|  * Class AccountRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class AccountRepository implements AccountRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function countAccounts(array $types): int | ||||
|     { | ||||
|         $query = $this->userGroup->accounts(); | ||||
|         if (0 !== count($types)) { | ||||
|             $query->accountTypeIn($types); | ||||
|         } | ||||
| 
 | ||||
|         return $query->count(); | ||||
|     } | ||||
| 
 | ||||
|     public function findByAccountNumber(string $number, array $types): ?Account | ||||
|     { | ||||
|         $dbQuery = $this->userGroup | ||||
|             ->accounts() | ||||
|             ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') | ||||
|             ->where('accounts.active', true) | ||||
|             ->where( | ||||
|                 static function (EloquentBuilder $q1) use ($number): void { | ||||
|                     $json = json_encode($number); | ||||
|                     $q1->where('account_meta.name', '=', 'account_number'); | ||||
|                     $q1->where('account_meta.data', '=', $json); | ||||
|                 } | ||||
|             ) | ||||
|         ; | ||||
| 
 | ||||
|         if (0 !== count($types)) { | ||||
|             $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); | ||||
|             $dbQuery->whereIn('account_types.type', $types); | ||||
|         } | ||||
| 
 | ||||
|         /** @var null|Account */ | ||||
|         return $dbQuery->first(['accounts.*']); | ||||
|     } | ||||
| 
 | ||||
|     public function findByIbanNull(string $iban, array $types): ?Account | ||||
|     { | ||||
|         $iban  = Steam::filterSpaces($iban); | ||||
|         $query = $this->userGroup->accounts()->where('iban', '!=', '')->whereNotNull('iban'); | ||||
| 
 | ||||
|         if (0 !== count($types)) { | ||||
|             $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); | ||||
|             $query->whereIn('account_types.type', $types); | ||||
|         } | ||||
| 
 | ||||
|         /** @var null|Account */ | ||||
|         return $query->where('iban', $iban)->first(['accounts.*']); | ||||
|     } | ||||
| 
 | ||||
|     public function findByName(string $name, array $types): ?Account | ||||
|     { | ||||
|         $query   = $this->userGroup->accounts(); | ||||
| 
 | ||||
|         if (0 !== count($types)) { | ||||
|             $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); | ||||
|             $query->whereIn('account_types.type', $types); | ||||
|         } | ||||
|         app('log')->debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]); | ||||
| 
 | ||||
|         $query->where('accounts.name', $name); | ||||
| 
 | ||||
|         /** @var null|Account $account */ | ||||
|         $account = $query->first(['accounts.*']); | ||||
|         if (null === $account) { | ||||
|             app('log')->debug(sprintf('There is no account with name "%s" of types', $name), $types); | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
|         app('log')->debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id)); | ||||
| 
 | ||||
|         return $account; | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getAccountBalances(Account $account): Collection | ||||
|     { | ||||
|         return $account->accountBalances; | ||||
|     } | ||||
| 
 | ||||
|     public function getAccountCurrency(Account $account): ?TransactionCurrency | ||||
|     { | ||||
|         $type       = $account->accountType->type; | ||||
|         $list       = config('firefly.valid_currency_account_types'); | ||||
| 
 | ||||
|         // return null if not in this list.
 | ||||
|         if (!in_array($type, $list, true)) { | ||||
|             return null; | ||||
|         } | ||||
|         $currencyId = (int) $this->getMetaValue($account, 'currency_id'); | ||||
|         if ($currencyId > 0) { | ||||
|             return Amount::getTransactionCurrencyById($currencyId); | ||||
|         } | ||||
| 
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Return meta value for account. Null if not found. | ||||
|      */ | ||||
|     public function getMetaValue(Account $account, string $field): ?string | ||||
|     { | ||||
|         $result = $account->accountMeta->filter( | ||||
|             static fn (AccountMeta $meta) => strtolower($meta->name) === strtolower($field) | ||||
|         ); | ||||
|         if (0 === $result->count()) { | ||||
|             return null; | ||||
|         } | ||||
|         if (1 === $result->count()) { | ||||
|             return (string) $result->first()->data; | ||||
|         } | ||||
| 
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     public function find(int $accountId): ?Account | ||||
|     { | ||||
|         $account = $this->user->accounts()->find($accountId); | ||||
|         if (null === $account) { | ||||
|             /** @var null|Account */ | ||||
|             return $this->userGroup->accounts()->find($accountId); | ||||
|         } | ||||
| 
 | ||||
|         /** @var null|Account */ | ||||
|         return $account; | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getAccountTypes(Collection $accounts): Collection | ||||
|     { | ||||
|         return AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id') | ||||
|             ->whereIn('accounts.id', $accounts->pluck('id')->toArray()) | ||||
|             ->get(['accounts.id', 'account_types.type']) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function getAccountsById(array $accountIds): Collection | ||||
|     { | ||||
|         $query = $this->userGroup->accounts(); | ||||
| 
 | ||||
|         if (0 !== count($accountIds)) { | ||||
|             $query->whereIn('accounts.id', $accountIds); | ||||
|         } | ||||
|         $query->orderBy('accounts.order', 'ASC'); | ||||
|         $query->orderBy('accounts.active', 'DESC'); | ||||
|         $query->orderBy('accounts.name', 'ASC'); | ||||
| 
 | ||||
|         return $query->get(['accounts.*']); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getAccountsInOrder(array $types, array $sort, int $startRow, int $endRow): Collection | ||||
|     { | ||||
|         $query = $this->userGroup->accounts(); | ||||
|         if (0 !== count($types)) { | ||||
|             $query->accountTypeIn($types); | ||||
|         } | ||||
|         $query->skip($startRow); | ||||
|         $query->take($endRow - $startRow); | ||||
| 
 | ||||
|         // add sort parameters. At this point they're filtered to allowed fields to sort by:
 | ||||
|         if (0 !== count($sort)) { | ||||
|             foreach ($sort as $label => $direction) { | ||||
|                 $query->orderBy(sprintf('accounts.%s', $label), $direction); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (0 === count($sort)) { | ||||
|             $query->orderBy('accounts.order', 'ASC'); | ||||
|             $query->orderBy('accounts.active', 'DESC'); | ||||
|             $query->orderBy('accounts.name', 'ASC'); | ||||
|         } | ||||
| 
 | ||||
|         return $query->get(['accounts.*']); | ||||
|     } | ||||
| 
 | ||||
|     public function getActiveAccountsByType(array $types): Collection | ||||
|     { | ||||
|         $query = $this->userGroup->accounts(); | ||||
|         if (0 !== count($types)) { | ||||
|             $query->accountTypeIn($types); | ||||
|         } | ||||
|         $query->where('active', true); | ||||
|         $query->orderBy('accounts.account_type_id', 'ASC'); | ||||
|         $query->orderBy('accounts.order', 'ASC'); | ||||
|         $query->orderBy('accounts.name', 'ASC'); | ||||
| 
 | ||||
|         return $query->get(['accounts.*']); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getLastActivity(Collection $accounts): array | ||||
|     { | ||||
|         return Transaction::whereIn('account_id', $accounts->pluck('id')->toArray())->leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')->groupBy('transactions.account_id')->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) as date_max')])->toArray(); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getMetaValues(Collection $accounts, array $fields): Collection | ||||
|     { | ||||
|         $query = AccountMeta::whereIn('account_id', $accounts->pluck('id')->toArray()); | ||||
|         if (count($fields) > 0) { | ||||
|             $query->whereIn('name', $fields); | ||||
|         } | ||||
| 
 | ||||
|         return $query->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getObjectGroups(Collection $accounts): array | ||||
|     { | ||||
|         $groupIds = []; | ||||
|         $return   = []; | ||||
|         $set      = DB::table('object_groupables')->where('object_groupable_type', Account::class) | ||||
|             ->whereIn('object_groupable_id', $accounts->pluck('id')->toArray())->get() | ||||
|         ; | ||||
| 
 | ||||
|         /** @var stdClass $row */ | ||||
|         foreach ($set as $row) { | ||||
|             $groupIds[] = $row->object_group_id; | ||||
|         } | ||||
|         $groupIds = array_unique($groupIds); | ||||
|         $groups   = ObjectGroup::whereIn('id', $groupIds)->get(); | ||||
| 
 | ||||
|         /** @var stdClass $row */ | ||||
|         foreach ($set as $row) { | ||||
|             if (!array_key_exists($row->object_groupable_id, $return)) { | ||||
|                 /** @var null|ObjectGroup $group */ | ||||
|                 $group = $groups->firstWhere('id', '=', $row->object_group_id); | ||||
|                 if (null !== $group) { | ||||
|                     $return[$row->object_groupable_id] = ['title' => $group->title, 'order' => $group->order, 'id' => $group->id]; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $return; | ||||
|     } | ||||
| 
 | ||||
|     public function resetAccountOrder(): void | ||||
|     { | ||||
|         $sets = [ | ||||
|             [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value], | ||||
|             [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value], | ||||
|         ]; | ||||
|         foreach ($sets as $set) { | ||||
|             $list  = $this->getAccountsByType($set); | ||||
|             $index = 1; | ||||
|             foreach ($list as $account) { | ||||
|                 if (false === $account->active) { | ||||
|                     $account->order = 0; | ||||
| 
 | ||||
|                     continue; | ||||
|                 } | ||||
|                 if ($index !== (int) $account->order) { | ||||
|                     app('log')->debug(sprintf('Account #%d ("%s"): order should %d be but is %d.', $account->id, $account->name, $index, $account->order)); | ||||
|                     $account->order = $index; | ||||
|                     $account->save(); | ||||
|                 } | ||||
|                 ++$index; | ||||
|             } | ||||
|         } | ||||
|         // reset the rest to zero.
 | ||||
|         $all  = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value]; | ||||
|         $this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') | ||||
|             ->whereNotIn('account_types.type', $all) | ||||
|             ->update(['order' => 0]) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection | ||||
|     { | ||||
|         $sortable        = ['name', 'active']; // TODO yes this is a duplicate array.
 | ||||
|         $res             = array_intersect([AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value], $types); | ||||
|         $query           = $this->userGroup->accounts(); | ||||
|         if (0 !== count($types)) { | ||||
|             $query->accountTypeIn($types); | ||||
|         } | ||||
| 
 | ||||
|         // process filters
 | ||||
|         // TODO this should be repeatable, it feels like a hack when you do it here.
 | ||||
|         // TODO some fields cannot be filtered using the query, and a second filter must be applied on the collection.
 | ||||
|         foreach ($filters as $column => $value) { | ||||
|             // filter on NULL values
 | ||||
|             if (null === $value) { | ||||
|                 continue; | ||||
|             } | ||||
|             if ('active' === $column) { | ||||
|                 $query->where('accounts.active', $value); | ||||
|             } | ||||
|             if ('name' === $column) { | ||||
|                 $query->whereLike('accounts.name', sprintf('%%%s%%', $value)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         // add sort parameters. At this point they're filtered to allowed fields to sort by:
 | ||||
|         $hasActiveColumn = array_key_exists('active', $sort); | ||||
|         if (count($sort) > 0) { | ||||
|             if (false === $hasActiveColumn) { | ||||
|                 $query->orderBy('accounts.active', 'DESC'); | ||||
|             } | ||||
|             foreach ($sort as $column => $direction) { | ||||
|                 if (in_array($column, $sortable, true)) { | ||||
|                     $query->orderBy(sprintf('accounts.%s', $column), $direction); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (0 === count($sort)) { | ||||
|             if (0 !== count($res)) { | ||||
|                 $query->orderBy('accounts.active', 'DESC'); | ||||
|             } | ||||
|             $query->orderBy('accounts.order', 'ASC'); | ||||
|             $query->orderBy('accounts.name', 'ASC'); | ||||
|             $query->orderBy('accounts.account_type_id', 'ASC'); | ||||
|             $query->orderBy('accounts.id', 'ASC'); | ||||
|         } | ||||
| 
 | ||||
|         return $query->get(['accounts.*']); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function update(Account $account, array $data): Account | ||||
|     { | ||||
|         /** @var AccountUpdateService $service */ | ||||
|         $service = app(AccountUpdateService::class); | ||||
| 
 | ||||
|         return $service->update($account, $data); | ||||
|     } | ||||
| 
 | ||||
|     public function searchAccount(string $query, array $types, int $page, int $limit): Collection | ||||
|     { | ||||
|         // search by group, not by user
 | ||||
|         $dbQuery = $this->userGroup->accounts() | ||||
|             ->where('active', true) | ||||
|             ->orderBy('accounts.updated_at', 'ASC') | ||||
|             ->orderBy('accounts.order', 'ASC') | ||||
|             ->orderBy('accounts.account_type_id', 'ASC') | ||||
|             ->orderBy('accounts.name', 'ASC') | ||||
|             ->with(['accountType']) | ||||
|         ; | ||||
| 
 | ||||
|         // split query on spaces just in case:
 | ||||
|         if ('' !== trim($query)) { | ||||
|             $dbQuery->where(function (EloquentBuilder $q) use ($query): void { | ||||
|                 $parts = explode(' ', $query); | ||||
|                 foreach ($parts as $part) { | ||||
|                     $search = sprintf('%%%s%%', $part); | ||||
|                     $q->orWhereLike('name', $search); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         if (0 !== count($types)) { | ||||
|             $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); | ||||
|             $dbQuery->whereIn('account_types.type', $types); | ||||
|         } | ||||
| 
 | ||||
|         $dbQuery->skip(($page - 1) * $limit)->take($limit); | ||||
| 
 | ||||
|         return $dbQuery->get(['accounts.*']); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| @@ -1,84 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * AccountRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Account; | ||||
| 
 | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface AccountRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface AccountRepositoryInterface | ||||
| { | ||||
|     public function countAccounts(array $types): int; | ||||
| 
 | ||||
|     public function find(int $accountId): ?Account; | ||||
| 
 | ||||
|     public function findByAccountNumber(string $number, array $types): ?Account; | ||||
| 
 | ||||
|     public function findByIbanNull(string $iban, array $types): ?Account; | ||||
| 
 | ||||
|     public function findByName(string $name, array $types): ?Account; | ||||
| 
 | ||||
|     public function getAccountBalances(Account $account): Collection; | ||||
| 
 | ||||
|     public function getAccountCurrency(Account $account): ?TransactionCurrency; | ||||
| 
 | ||||
|     public function getAccountTypes(Collection $accounts): Collection; | ||||
| 
 | ||||
|     public function getAccountsById(array $accountIds): Collection; | ||||
| 
 | ||||
|     public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection; | ||||
| 
 | ||||
|     /** | ||||
|      * Used in the infinite accounts list. | ||||
|      */ | ||||
|     public function getAccountsInOrder(array $types, array $sort, int $startRow, int $endRow): Collection; | ||||
| 
 | ||||
|     public function getActiveAccountsByType(array $types): Collection; | ||||
| 
 | ||||
|     public function getLastActivity(Collection $accounts): array; | ||||
| 
 | ||||
|     /** | ||||
|      * Return meta value for account. Null if not found. | ||||
|      */ | ||||
|     public function getMetaValue(Account $account, string $field): ?string; | ||||
| 
 | ||||
|     public function getMetaValues(Collection $accounts, array $fields): Collection; | ||||
| 
 | ||||
|     public function getObjectGroups(Collection $accounts): array; | ||||
| 
 | ||||
|     /** | ||||
|      * Reset order types of the mentioned accounts. | ||||
|      */ | ||||
|     public function resetAccountOrder(): void; | ||||
| 
 | ||||
|     public function searchAccount(string $query, array $types, int $page, int $limit): Collection; | ||||
| 
 | ||||
|     public function update(Account $account, array $data): Account; | ||||
| } | ||||
| @@ -1,236 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * BillRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Bill; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\Bill; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use FireflyIII\Support\Http\Api\ExchangeRateConverter; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| 
 | ||||
| /** | ||||
|  * Class BillRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class BillRepository implements BillRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     /** | ||||
|      * Correct order of piggies in case of issues. | ||||
|      */ | ||||
|     public function correctOrder(): void | ||||
|     { | ||||
|         $set     = $this->userGroup->bills()->orderBy('order', 'ASC')->get(); | ||||
|         $current = 1; | ||||
|         foreach ($set as $bill) { | ||||
|             if ($bill->order !== $current) { | ||||
|                 $bill->order = $current; | ||||
|                 $bill->save(); | ||||
|             } | ||||
|             ++$current; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public function getBills(): Collection | ||||
|     { | ||||
|         return $this->userGroup->bills() | ||||
|             ->orderBy('bills.name', 'ASC') | ||||
|             ->get(['bills.*']) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function sumPaidInRange(Carbon $start, Carbon $end): array | ||||
|     { | ||||
|         Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); | ||||
|         $bills     = $this->getActiveBills(); | ||||
|         $primary   = app('amount')->getPrimaryCurrency(); | ||||
|         $return    = []; | ||||
|         $converter = new ExchangeRateConverter(); | ||||
| 
 | ||||
|         /** @var Bill $bill */ | ||||
|         foreach ($bills as $bill) { | ||||
|             /** @var Collection $set */ | ||||
|             $set        = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); | ||||
|             $currency   = $bill->transactionCurrency; | ||||
|             $currencyId = $bill->transaction_currency_id; | ||||
| 
 | ||||
|             $return[$currencyId] ??= [ | ||||
|                 'currency_id'                     => (string) $currency->id, | ||||
|                 'currency_name'                   => $currency->name, | ||||
|                 'currency_symbol'                 => $currency->symbol, | ||||
|                 'currency_code'                   => $currency->code, | ||||
|                 'currency_decimal_places'         => $currency->decimal_places, | ||||
|                 'primary_currency_id'             => (string) $primary->id, | ||||
|                 'primary_currency_name'           => $primary->name, | ||||
|                 'primary_currency_symbol'         => $primary->symbol, | ||||
|                 'primary_currency_code'           => $primary->code, | ||||
|                 'primary_currency_decimal_places' => $primary->decimal_places, | ||||
|                 'sum'                             => '0', | ||||
|                 'pc_sum'                          => '0', | ||||
|             ]; | ||||
| 
 | ||||
|             /** @var TransactionJournal $transactionJournal */ | ||||
|             foreach ($set as $transactionJournal) { | ||||
|                 /** @var null|Transaction $sourceTransaction */ | ||||
|                 $sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first(); | ||||
|                 if (null !== $sourceTransaction) { | ||||
|                     $amount                        = $sourceTransaction->amount; | ||||
|                     if ((int) $sourceTransaction->foreign_currency_id === $currency->id) { | ||||
|                         // use foreign amount instead!
 | ||||
|                         $amount = (string) $sourceTransaction->foreign_amount; | ||||
|                     } | ||||
|                     // convert to primary currency
 | ||||
|                     $pcAmount                      = $amount; | ||||
|                     if ($currencyId !== $primary->id) { | ||||
|                         // get rate and convert.
 | ||||
|                         $pcAmount = $converter->convert($currency, $primary, $transactionJournal->date, $amount); | ||||
|                     } | ||||
|                     if ((int) $sourceTransaction->foreign_currency_id === $primary->id) { | ||||
|                         // ignore conversion, use foreign amount
 | ||||
|                         $pcAmount = (string) $sourceTransaction->foreign_amount; | ||||
|                     } | ||||
|                     $return[$currencyId]['sum']    = bcadd($return[$currencyId]['sum'], (string) $amount); | ||||
|                     $return[$currencyId]['pc_sum'] = bcadd($return[$currencyId]['pc_sum'], (string) $pcAmount); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         $converter->summarize(); | ||||
| 
 | ||||
|         return $return; | ||||
|     } | ||||
| 
 | ||||
|     public function getActiveBills(): Collection | ||||
|     { | ||||
|         return $this->userGroup->bills() | ||||
|             ->where('active', true) | ||||
|             ->orderBy('bills.name', 'ASC') | ||||
|             ->get(['bills.*']) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function sumUnpaidInRange(Carbon $start, Carbon $end): array | ||||
|     { | ||||
|         Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); | ||||
|         $bills     = $this->getActiveBills(); | ||||
|         $return    = []; | ||||
|         $primary   = app('amount')->getPrimaryCurrency(); | ||||
|         $converter = new ExchangeRateConverter(); | ||||
| 
 | ||||
|         /** @var Bill $bill */ | ||||
|         foreach ($bills as $bill) { | ||||
|             $dates = $this->getPayDatesInRange($bill, $start, $end); | ||||
|             $count = $bill->transactionJournals()->after($start)->before($end)->count(); | ||||
|             $total = $dates->count() - $count; | ||||
| 
 | ||||
|             if ($total > 0) { | ||||
|                 $currency                      = $bill->transactionCurrency; | ||||
|                 $currencyId                    = $bill->transaction_currency_id; | ||||
|                 $average                       = bcdiv(bcadd((string) $bill->amount_max, (string) $bill->amount_min), '2'); | ||||
|                 $pcAverage                     = $converter->convert($currency, $primary, $start, $average); | ||||
|                 $return[$currencyId] ??= [ | ||||
|                     'currency_id'                     => (string) $currency->id, | ||||
|                     'currency_name'                   => $currency->name, | ||||
|                     'currency_symbol'                 => $currency->symbol, | ||||
|                     'currency_code'                   => $currency->code, | ||||
|                     'currency_decimal_places'         => $currency->decimal_places, | ||||
|                     'primary_currency_id'             => (string) $primary->id, | ||||
|                     'primary_currency_name'           => $primary->name, | ||||
|                     'primary_currency_symbol'         => $primary->symbol, | ||||
|                     'primary_currency_code'           => $primary->code, | ||||
|                     'primary_currency_decimal_places' => $primary->decimal_places, | ||||
|                     'sum'                             => '0', | ||||
|                     'pc_sum'                          => '0', | ||||
|                 ]; | ||||
|                 $return[$currencyId]['sum']    = bcadd($return[$currencyId]['sum'], bcmul($average, (string) $total)); | ||||
|                 $return[$currencyId]['pc_sum'] = bcadd($return[$currencyId]['pc_sum'], bcmul($pcAverage, (string) $total)); | ||||
|             } | ||||
|         } | ||||
|         $converter->summarize(); | ||||
| 
 | ||||
|         return $return; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Between start and end, tells you on which date(s) the bill is expected to hit. | ||||
|      * TODO duplicate of function in other billrepositoryinterface | ||||
|      */ | ||||
|     public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection | ||||
|     { | ||||
|         $set          = new Collection(); | ||||
|         $currentStart = clone $start; | ||||
|         // app('log')->debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
 | ||||
|         // app('log')->debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
 | ||||
| 
 | ||||
|         while ($currentStart <= $end) { | ||||
|             // app('log')->debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
 | ||||
|             $nextExpectedMatch = $this->nextDateMatch($bill, $currentStart); | ||||
|             // app('log')->debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
 | ||||
|             if ($nextExpectedMatch > $end) {// If nextExpectedMatch is after end, we continue
 | ||||
|                 break; | ||||
|             } | ||||
|             $set->push(clone $nextExpectedMatch); | ||||
|             // app('log')->debug(sprintf('Now %d dates in set.', $set->count()));
 | ||||
|             $nextExpectedMatch->addDay(); | ||||
| 
 | ||||
|             // app('log')->debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
 | ||||
| 
 | ||||
|             $currentStart      = clone $nextExpectedMatch; | ||||
|         } | ||||
| 
 | ||||
|         return $set; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Given a bill and a date, this method will tell you at which moment this bill expects its next | ||||
|      * transaction. Whether it is there already, is not relevant. | ||||
|      * | ||||
|      * TODO duplicate of other repos | ||||
|      */ | ||||
|     public function nextDateMatch(Bill $bill, Carbon $date): Carbon | ||||
|     { | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($bill->id); | ||||
|         $cache->addProperty('nextDateMatch'); | ||||
|         $cache->addProperty($date); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); | ||||
|         } | ||||
|         // find the most recent date for this bill NOT in the future. Cache this date:
 | ||||
|         $start = clone $bill->date; | ||||
| 
 | ||||
|         while ($start < $date) { | ||||
|             $start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); | ||||
|         } | ||||
|         $cache->store($start); | ||||
| 
 | ||||
|         return $start; | ||||
|     } | ||||
| } | ||||
| @@ -1,72 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * BillRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Bill; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\Bill; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface BillRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface BillRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * TODO duplicate of other repos | ||||
|      * Add correct order to bills. | ||||
|      */ | ||||
|     public function correctOrder(): void; | ||||
| 
 | ||||
|     public function getActiveBills(): Collection; | ||||
| 
 | ||||
|     public function getBills(): Collection; | ||||
| 
 | ||||
|     /** | ||||
|      * Between start and end, tells you on which date(s) the bill is expected to hit. | ||||
|      * | ||||
|      * TODO duplicate of method in other billrepositoryinterface | ||||
|      */ | ||||
|     public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection; | ||||
| 
 | ||||
|     /** | ||||
|      * Given a bill and a date, this method will tell you at which moment this bill expects its next | ||||
|      * transaction. Whether it is there already, is not relevant. | ||||
|      * | ||||
|      * TODO duplicate of method in other bill repos | ||||
|      */ | ||||
|     public function nextDateMatch(Bill $bill, Carbon $date): Carbon; | ||||
| 
 | ||||
|     /** | ||||
|      * Collect multi-currency of sum of bills already paid. | ||||
|      */ | ||||
|     public function sumPaidInRange(Carbon $start, Carbon $end): array; | ||||
| 
 | ||||
|     /** | ||||
|      * Collect multi-currency of sum of bills yet to pay. | ||||
|      */ | ||||
|     public function sumUnpaidInRange(Carbon $start, Carbon $end): array; | ||||
| } | ||||
| @@ -1,78 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * AvailableBudgetRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Budget; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\AvailableBudget; | ||||
| use FireflyIII\Support\Http\Api\ExchangeRateConverter; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| 
 | ||||
| /** | ||||
|  * Class AvailableBudgetRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array | ||||
|     { | ||||
|         Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); | ||||
|         $return           = []; | ||||
|         $converter        = new ExchangeRateConverter(); | ||||
|         $primary          = app('amount')->getPrimaryCurrency(); | ||||
|         $availableBudgets = $this->userGroup->availableBudgets() | ||||
|             ->where('start_date', $start->format('Y-m-d')) | ||||
|             ->where('end_date', $end->format('Y-m-d'))->get() | ||||
|         ; | ||||
| 
 | ||||
|         /** @var AvailableBudget $availableBudget */ | ||||
|         foreach ($availableBudgets as $availableBudget) { | ||||
|             $currencyId                       = $availableBudget->transaction_currency_id; | ||||
|             $return[$currencyId] ??= [ | ||||
|                 'currency_id'                     => $currencyId, | ||||
|                 'currency_code'                   => $availableBudget->transactionCurrency->code, | ||||
|                 'currency_symbol'                 => $availableBudget->transactionCurrency->symbol, | ||||
|                 'currency_name'                   => $availableBudget->transactionCurrency->name, | ||||
|                 'currency_decimal_places'         => $availableBudget->transactionCurrency->decimal_places, | ||||
|                 'primary_currency_id'             => $primary->id, | ||||
|                 'primary_currency_code'           => $primary->code, | ||||
|                 'primary_currency_symbol'         => $primary->symbol, | ||||
|                 'primary_currency_name'           => $primary->name, | ||||
|                 'primary_currency_decimal_places' => $primary->decimal_places, | ||||
|                 'amount'                          => '0', | ||||
|                 'pc_amount'                       => '0', | ||||
|             ]; | ||||
|             $pcAmount                         = $converter->convert($availableBudget->transactionCurrency, $primary, $availableBudget->start_date, $availableBudget->amount); | ||||
|             $return[$currencyId]['amount']    = bcadd($return[$currencyId]['amount'], (string) $availableBudget->amount); | ||||
|             $return[$currencyId]['pc_amount'] = bcadd($return[$currencyId]['pc_amount'], $pcAmount); | ||||
|         } | ||||
|         $converter->summarize(); | ||||
| 
 | ||||
|         return $return; | ||||
|     } | ||||
| } | ||||
| @@ -1,37 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * AvailableBudgetRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Budget; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| 
 | ||||
| /** | ||||
|  * Interface AvailableBudgetRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface AvailableBudgetRepositoryInterface | ||||
| { | ||||
|     public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array; | ||||
| } | ||||
| @@ -1,56 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * BudgetRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Budget; | ||||
| 
 | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Class BudgetRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class BudgetRepository implements BudgetRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     public function getActiveBudgets(): Collection | ||||
|     { | ||||
|         return $this->userGroup->budgets()->where('active', true) | ||||
|             ->orderBy('order', 'ASC') | ||||
|             ->orderBy('name', 'ASC') | ||||
|             ->get() | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function getBudgets(): Collection | ||||
|     { | ||||
|         return $this->userGroup->budgets() | ||||
|             ->orderBy('order', 'ASC') | ||||
|             ->orderBy('name', 'ASC') | ||||
|             ->get() | ||||
|         ; | ||||
|     } | ||||
| } | ||||
| @@ -1,39 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * BudgetRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Budget; | ||||
| 
 | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface BudgetRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface BudgetRepositoryInterface | ||||
| { | ||||
|     public function getActiveBudgets(): Collection; | ||||
| 
 | ||||
|     public function getBudgets(): Collection; | ||||
| } | ||||
| @@ -1,136 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * OperationsRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Budget; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Enums\TransactionTypeEnum; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Helpers\Collector\GroupCollectorInterface; | ||||
| use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Class OperationsRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class OperationsRepository implements OperationsRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     /** | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array | ||||
|     { | ||||
|         /** @var GroupCollectorInterface $collector */ | ||||
|         $collector = app(GroupCollectorInterface::class); | ||||
|         $collector->setUserGroup($this->userGroup)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); | ||||
|         if ($accounts instanceof Collection && $accounts->count() > 0) { | ||||
|             $collector->setAccounts($accounts); | ||||
|         } | ||||
|         if ($budgets instanceof Collection && $budgets->count() > 0) { | ||||
|             $collector->setBudgets($budgets); | ||||
|         } | ||||
|         if (!$budgets instanceof Collection || (0 === $budgets->count())) { | ||||
|             $collector->setBudgets($this->getBudgets()); | ||||
|         } | ||||
|         $collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation(); | ||||
|         $journals  = $collector->getExtractedJournals(); | ||||
|         $array     = []; | ||||
| 
 | ||||
|         foreach ($journals as $journal) { | ||||
|             $currencyId                                                                   = (int) $journal['currency_id']; | ||||
|             $budgetId                                                                     = (int) $journal['budget_id']; | ||||
|             $budgetName                                                                   = (string) $journal['budget_name']; | ||||
| 
 | ||||
|             // catch "no budget" entries.
 | ||||
|             if (0 === $budgetId) { | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             // info about the currency:
 | ||||
|             $array[$currencyId]                       ??= [ | ||||
|                 'budgets'                 => [], | ||||
|                 'currency_id'             => $currencyId, | ||||
|                 'currency_name'           => $journal['currency_name'], | ||||
|                 'currency_symbol'         => $journal['currency_symbol'], | ||||
|                 'currency_code'           => $journal['currency_code'], | ||||
|                 'currency_decimal_places' => $journal['currency_decimal_places'], | ||||
|             ]; | ||||
| 
 | ||||
|             // info about the budgets:
 | ||||
|             $array[$currencyId]['budgets'][$budgetId] ??= [ | ||||
|                 'id'                   => $budgetId, | ||||
|                 'name'                 => $budgetName, | ||||
|                 'transaction_journals' => [], | ||||
|             ]; | ||||
| 
 | ||||
|             // add journal to array:
 | ||||
|             // only a subset of the fields.
 | ||||
|             $journalId                                                                    = (int) $journal['transaction_journal_id']; | ||||
|             $final                                                                        = [ | ||||
|                 'amount'                          => app('steam')->negative($journal['amount']), | ||||
|                 'currency_id'                     => $journal['currency_id'], | ||||
|                 'foreign_amount'                  => null, | ||||
|                 'foreign_currency_id'             => null, | ||||
|                 'foreign_currency_code'           => null, | ||||
|                 'foreign_currency_symbol'         => null, | ||||
|                 'foreign_currency_name'           => null, | ||||
|                 'foreign_currency_decimal_places' => null, | ||||
|                 'destination_account_id'          => $journal['destination_account_id'], | ||||
|                 'destination_account_name'        => $journal['destination_account_name'], | ||||
|                 'source_account_id'               => $journal['source_account_id'], | ||||
|                 'source_account_name'             => $journal['source_account_name'], | ||||
|                 'category_name'                   => $journal['category_name'], | ||||
|                 'description'                     => $journal['description'], | ||||
|                 'transaction_group_id'            => $journal['transaction_group_id'], | ||||
|                 'date'                            => $journal['date'], | ||||
|             ]; | ||||
|             if (null !== $journal['foreign_amount']) { | ||||
|                 $final['foreign_amount']                  = app('steam')->negative($journal['foreign_amount']); | ||||
|                 $final['foreign_currency_id']             = $journal['foreign_currency_id']; | ||||
|                 $final['foreign_currency_code']           = $journal['foreign_currency_code']; | ||||
|                 $final['foreign_currency_symbol']         = $journal['foreign_currency_symbol']; | ||||
|                 $final['foreign_currency_name']           = $journal['foreign_currency_name']; | ||||
|                 $final['foreign_currency_decimal_places'] = $journal['foreign_currency_decimal_places']; | ||||
|             } | ||||
| 
 | ||||
|             $array[$currencyId]['budgets'][$budgetId]['transaction_journals'][$journalId] = $final; | ||||
|         } | ||||
| 
 | ||||
|         return $array; | ||||
|     } | ||||
| 
 | ||||
|     private function getBudgets(): Collection | ||||
|     { | ||||
|         /** @var BudgetRepositoryInterface $repository */ | ||||
|         $repository = app(BudgetRepositoryInterface::class); | ||||
|         $repository->setUserGroup($this->getUserGroup()); | ||||
| 
 | ||||
|         return $repository->getActiveBudgets(); | ||||
|     } | ||||
| } | ||||
| @@ -1,43 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * OperationsRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Budget; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface OperationsRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface OperationsRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * This method returns a list of all the withdrawal transaction journals (as arrays) set in that period | ||||
|      * which have the specified budget set to them. It's grouped per currency, with as few details in the array | ||||
|      * as possible. Amounts are always negative. | ||||
|      */ | ||||
|     public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array; | ||||
| } | ||||
| @@ -1,58 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * CategoryRepository.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Category; | ||||
| 
 | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Class CategoryRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class CategoryRepository implements CategoryRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     public function searchCategory(array $query, int $limit): Collection | ||||
|     { | ||||
|         $search = $this->userGroup->categories(); | ||||
|         if (count($query) > 0) { | ||||
|             // split query on spaces just in case:
 | ||||
|             $search->where(function (EloquentBuilder $q) use ($query): void { | ||||
|                 foreach ($query as $line) { | ||||
|                     $parts = explode(' ', $line); | ||||
|                     foreach ($parts as $part) { | ||||
|                         $search = sprintf('%%%s%%', $part); | ||||
|                         $q->orWhereLike('name', $search); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         return $search->take($limit)->get(); | ||||
|     } | ||||
| } | ||||
| @@ -1,40 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * CategoryRepositoryInterface.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Category; | ||||
| 
 | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface CategoryRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface CategoryRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * Search for a category using wild cards. Uses the database, so case sensitive. | ||||
|      */ | ||||
|     public function searchCategory(array $query, int $limit): Collection; | ||||
| } | ||||
| @@ -1,392 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * CurrencyRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Currency; | ||||
| 
 | ||||
| use FireflyIII\Events\Preferences\UserGroupChangedPrimaryCurrency; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Factory\TransactionCurrencyFactory; | ||||
| use FireflyIII\Models\AccountMeta; | ||||
| use FireflyIII\Models\AvailableBudget; | ||||
| use FireflyIII\Models\Bill; | ||||
| use FireflyIII\Models\BudgetLimit; | ||||
| use FireflyIII\Models\RecurrenceTransaction; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\User\UserRepositoryInterface; | ||||
| use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService; | ||||
| use FireflyIII\Services\Internal\Update\CurrencyUpdateService; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| 
 | ||||
| use function Safe\json_encode; | ||||
| 
 | ||||
| /** | ||||
|  * Class CurrencyRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class CurrencyRepository implements CurrencyRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     /** | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function currencyInUse(TransactionCurrency $currency): bool | ||||
|     { | ||||
|         $result = $this->currencyInUseAt($currency); | ||||
| 
 | ||||
|         return null !== $result; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function currencyInUseAt(TransactionCurrency $currency): ?string | ||||
|     { | ||||
|         Log::debug(sprintf('Now in currencyInUse() for #%d ("%s")', $currency->id, $currency->code)); | ||||
|         $countJournals    = $this->countJournals($currency); | ||||
|         if ($countJournals > 0) { | ||||
|             Log::info(sprintf('Count journals is %d, return true.', $countJournals)); | ||||
| 
 | ||||
|             return 'journals'; | ||||
|         } | ||||
| 
 | ||||
|         // is the only currency left
 | ||||
|         if (1 === $this->getAll()->count()) { | ||||
|             Log::info('Is the last currency in the system, return true. '); | ||||
| 
 | ||||
|             return 'last_left'; | ||||
|         } | ||||
| 
 | ||||
|         // is being used in accounts:
 | ||||
|         $meta             = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string) $currency->id))->count(); | ||||
|         if ($meta > 0) { | ||||
|             Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); | ||||
| 
 | ||||
|             return 'account_meta'; | ||||
|         } | ||||
| 
 | ||||
|         // second search using integer check.
 | ||||
|         $meta             = AccountMeta::where('name', 'currency_id')->where('data', json_encode((int) $currency->id))->count(); | ||||
|         if ($meta > 0) { | ||||
|             Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); | ||||
| 
 | ||||
|             return 'account_meta'; | ||||
|         } | ||||
| 
 | ||||
|         // is being used in bills:
 | ||||
|         $bills            = Bill::where('transaction_currency_id', $currency->id)->count(); | ||||
|         if ($bills > 0) { | ||||
|             Log::info(sprintf('Used in %d bills as currency, return true. ', $bills)); | ||||
| 
 | ||||
|             return 'bills'; | ||||
|         } | ||||
| 
 | ||||
|         // is being used in recurring transactions
 | ||||
|         $recurringAmount  = RecurrenceTransaction::where('transaction_currency_id', $currency->id)->count(); | ||||
|         $recurringForeign = RecurrenceTransaction::where('foreign_currency_id', $currency->id)->count(); | ||||
| 
 | ||||
|         if ($recurringAmount > 0 || $recurringForeign > 0) { | ||||
|             Log::info(sprintf('Used in %d recurring transactions as (foreign) currency id, return true. ', $recurringAmount + $recurringForeign)); | ||||
| 
 | ||||
|             return 'recurring'; | ||||
|         } | ||||
| 
 | ||||
|         // is being used in accounts (as integer)
 | ||||
|         $meta             = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') | ||||
|             ->whereNull('accounts.deleted_at') | ||||
|             ->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count() | ||||
|         ; | ||||
|         if ($meta > 0) { | ||||
|             Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); | ||||
| 
 | ||||
|             return 'account_meta'; | ||||
|         } | ||||
| 
 | ||||
|         // is being used in available budgets
 | ||||
|         $availableBudgets = AvailableBudget::where('transaction_currency_id', $currency->id)->count(); | ||||
|         if ($availableBudgets > 0) { | ||||
|             Log::info(sprintf('Used in %d available budgets as currency, return true. ', $availableBudgets)); | ||||
| 
 | ||||
|             return 'available_budgets'; | ||||
|         } | ||||
| 
 | ||||
|         // is being used in budget limits
 | ||||
|         $budgetLimit      = BudgetLimit::where('transaction_currency_id', $currency->id)->count(); | ||||
|         if ($budgetLimit > 0) { | ||||
|             Log::info(sprintf('Used in %d budget limits as currency, return true. ', $budgetLimit)); | ||||
| 
 | ||||
|             return 'budget_limits'; | ||||
|         } | ||||
| 
 | ||||
|         // is the default currency for the user or the system
 | ||||
|         $count            = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count(); | ||||
|         if ($count > 0) { | ||||
|             Log::info('Is the default currency of the user, return true.'); | ||||
| 
 | ||||
|             return 'current_default'; | ||||
|         } | ||||
| 
 | ||||
|         // is the default currency for the user or the system
 | ||||
|         $count            = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count(); | ||||
|         if ($count > 0) { | ||||
|             Log::info('Is the default currency of the user group, return true.'); | ||||
| 
 | ||||
|             return 'current_default'; | ||||
|         } | ||||
| 
 | ||||
|         Log::debug('Currency is not used, return false.'); | ||||
| 
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     private function countJournals(TransactionCurrency $currency): int | ||||
|     { | ||||
|         $count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count(); | ||||
| 
 | ||||
|         // also count foreign:
 | ||||
|         return $count + Transaction::where('foreign_currency_id', $currency->id)->count(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Returns ALL currencies, regardless of whether they are enabled or not. | ||||
|      */ | ||||
|     public function getAll(): Collection | ||||
|     { | ||||
|         $all   = TransactionCurrency::orderBy('code', 'ASC')->get(); | ||||
|         $local = $this->get(); | ||||
| 
 | ||||
|         return $all->map(static function (TransactionCurrency $current) use ($local) { | ||||
|             $hasId                     = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id); | ||||
|             $isPrimary                 = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id); | ||||
|             $current->userGroupEnabled = $hasId; | ||||
|             $current->userGroupNative  = $isPrimary; | ||||
| 
 | ||||
|             return $current; | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     public function get(): Collection | ||||
|     { | ||||
|         $all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get(); | ||||
|         $all->map(static function (TransactionCurrency $current) { // @phpstan-ignore-line
 | ||||
|             $current->userGroupEnabled = true; | ||||
|             $current->userGroupNative  = 1 === (int) $current->pivot->group_default; | ||||
| 
 | ||||
|             return $current; | ||||
|         }); | ||||
| 
 | ||||
|         /** @var Collection */ | ||||
|         return $all; | ||||
|     } | ||||
| 
 | ||||
|     public function destroy(TransactionCurrency $currency): bool | ||||
|     { | ||||
|         /** @var UserRepositoryInterface $repository */ | ||||
|         $repository = app(UserRepositoryInterface::class); | ||||
|         if ($repository->hasRole($this->user, 'owner')) { | ||||
|             /** @var CurrencyDestroyService $service */ | ||||
|             $service = app(CurrencyDestroyService::class); | ||||
|             $service->destroy($currency); | ||||
|         } | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Disables a currency | ||||
|      */ | ||||
|     public function disable(TransactionCurrency $currency): void | ||||
|     { | ||||
|         $this->userGroup->currencies()->detach($currency->id); | ||||
|         $currency->enabled = false; | ||||
|         $currency->save(); | ||||
|     } | ||||
| 
 | ||||
|     public function findByName(string $name): ?TransactionCurrency | ||||
|     { | ||||
|         return TransactionCurrency::where('name', $name)->first(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find by object, ID or code. Returns user default or system default. | ||||
|      * | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency | ||||
|     { | ||||
|         $result = $this->findCurrencyNull($currencyId, $currencyCode); | ||||
| 
 | ||||
|         if (!$result instanceof TransactionCurrency) { | ||||
|             Log::debug('Grabbing default currency for this user...'); | ||||
| 
 | ||||
|             /** @var null|TransactionCurrency $result */ | ||||
|             $result = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); | ||||
|         } | ||||
| 
 | ||||
|         Log::debug(sprintf('Final result: %s', $result->code)); | ||||
|         if (false === $result->enabled) { | ||||
|             Log::debug(sprintf('Also enabled currency %s', $result->code)); | ||||
|             $this->enable($result); | ||||
|         } | ||||
| 
 | ||||
|         return $result; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find by object, ID or code. Returns NULL if nothing found. | ||||
|      */ | ||||
|     public function findCurrencyNull(?int $currencyId, ?string $currencyCode): ?TransactionCurrency | ||||
|     { | ||||
|         Log::debug(sprintf('Now in findCurrencyNull("%s", "%s")', $currencyId, $currencyCode)); | ||||
|         $result = $this->find((int) $currencyId); | ||||
|         if (!$result instanceof TransactionCurrency) { | ||||
|             Log::debug(sprintf('Searching for currency with code "%s"...', $currencyCode)); | ||||
|             $result = $this->findByCode((string) $currencyCode); | ||||
|         } | ||||
|         if ($result instanceof TransactionCurrency && false === $result->enabled) { | ||||
|             Log::debug(sprintf('Also enabled currency %s', $result->code)); | ||||
|             $this->enable($result); | ||||
|         } | ||||
| 
 | ||||
|         return $result; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find by ID, return NULL if not found. | ||||
|      */ | ||||
|     public function find(int $currencyId): ?TransactionCurrency | ||||
|     { | ||||
|         return TransactionCurrency::find($currencyId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find by currency code, return NULL if unfound. | ||||
|      */ | ||||
|     public function findByCode(string $currencyCode): ?TransactionCurrency | ||||
|     { | ||||
|         return TransactionCurrency::where('code', $currencyCode)->first(); | ||||
|     } | ||||
| 
 | ||||
|     public function enable(TransactionCurrency $currency): void | ||||
|     { | ||||
|         $this->userGroup->currencies()->syncWithoutDetaching([$currency->id]); | ||||
|         $currency->enabled = false; | ||||
|         $currency->save(); | ||||
|     } | ||||
| 
 | ||||
|     public function getByIds(array $ids): Collection | ||||
|     { | ||||
|         return TransactionCurrency::orderBy('code', 'ASC')->whereIn('id', $ids)->get(); | ||||
|     } | ||||
| 
 | ||||
|     public function isFallbackCurrency(TransactionCurrency $currency): bool | ||||
|     { | ||||
|         return $currency->code === config('firefly.default_currency', 'EUR'); | ||||
|     } | ||||
| 
 | ||||
|     public function searchCurrency(string $search, int $limit): Collection | ||||
|     { | ||||
|         $query = TransactionCurrency::where('enabled', true); | ||||
|         if ('' !== $search) { | ||||
|             $query->whereLike('name', sprintf('%%%s%%', $search)); | ||||
|         } | ||||
| 
 | ||||
|         return $query->take($limit)->get(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function store(array $data): TransactionCurrency | ||||
|     { | ||||
|         /** @var TransactionCurrencyFactory $factory */ | ||||
|         $factory = app(TransactionCurrencyFactory::class); | ||||
|         $result  = $factory->create($data); | ||||
| 
 | ||||
|         if (true === $data['enabled']) { | ||||
|             $this->userGroup->currencies()->attach($result->id); | ||||
|         } | ||||
| 
 | ||||
|         return $result; | ||||
|     } | ||||
| 
 | ||||
|     public function update(TransactionCurrency $currency, array $data): TransactionCurrency | ||||
|     { | ||||
|         Log::debug('Now in update()'); | ||||
|         // can be true, false, null
 | ||||
|         $enabled = array_key_exists('enabled', $data) ? $data['enabled'] : null; | ||||
|         // can be true, false, but method only responds to "true".
 | ||||
|         $default = array_key_exists('default', $data) ? $data['default'] : false; | ||||
| 
 | ||||
|         // remove illegal combo's:
 | ||||
|         if (false === $enabled && true === $default) { | ||||
|             $enabled = true; | ||||
|         } | ||||
| 
 | ||||
|         // update currency with current user specific settings
 | ||||
|         $currency->refreshForUser($this->user); | ||||
| 
 | ||||
|         // currency is enabled, must be disabled.
 | ||||
|         if (false === $enabled) { | ||||
|             Log::debug(sprintf('Disabled currency %s for user #%d', $currency->code, $this->userGroup->id)); | ||||
|             $this->userGroup->currencies()->detach($currency->id); | ||||
|         } | ||||
|         // currency must be enabled
 | ||||
|         if (true === $enabled) { | ||||
|             Log::debug(sprintf('Enabled currency %s for user #%d', $currency->code, $this->userGroup->id)); | ||||
|             $this->userGroup->currencies()->detach($currency->id); | ||||
|             $this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => false]]); | ||||
|         } | ||||
| 
 | ||||
|         // currency must be made default.
 | ||||
|         if (true === $default) { | ||||
|             $this->makePrimary($currency); | ||||
|         } | ||||
| 
 | ||||
|         /** @var CurrencyUpdateService $service */ | ||||
|         $service = app(CurrencyUpdateService::class); | ||||
| 
 | ||||
|         return $service->update($currency, $data); | ||||
|     } | ||||
| 
 | ||||
|     public function makePrimary(TransactionCurrency $currency): void | ||||
|     { | ||||
|         $current = app('amount')->getPrimaryCurrencyByUserGroup($this->userGroup); | ||||
|         Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id)); | ||||
|         $this->userGroup->currencies()->detach($currency->id); | ||||
|         foreach ($this->userGroup->currencies()->get() as $item) { | ||||
|             $this->userGroup->currencies()->updateExistingPivot($item->id, ['group_default' => false]); | ||||
|         } | ||||
|         $this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]); | ||||
|         if ($current->id !== $currency->id) { | ||||
|             Log::debug('Trigger on a different default currency.'); | ||||
|             // clear all primary currency amounts through an event.
 | ||||
|             event(new UserGroupChangedPrimaryCurrency($this->userGroup)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,102 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * CurrencyRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Currency; | ||||
| 
 | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface CurrencyRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface CurrencyRepositoryInterface | ||||
| { | ||||
|     public function currencyInUse(TransactionCurrency $currency): bool; | ||||
| 
 | ||||
|     /** | ||||
|      * Currency is in use where exactly. | ||||
|      */ | ||||
|     public function currencyInUseAt(TransactionCurrency $currency): ?string; | ||||
| 
 | ||||
|     public function destroy(TransactionCurrency $currency): bool; | ||||
| 
 | ||||
|     /** | ||||
|      * Disables a currency | ||||
|      */ | ||||
|     public function disable(TransactionCurrency $currency): void; | ||||
| 
 | ||||
|     /** | ||||
|      * Enables a currency | ||||
|      */ | ||||
|     public function enable(TransactionCurrency $currency): void; | ||||
| 
 | ||||
|     /** | ||||
|      * Find by ID, return NULL if not found. | ||||
|      */ | ||||
|     public function find(int $currencyId): ?TransactionCurrency; | ||||
| 
 | ||||
|     public function findByCode(string $currencyCode): ?TransactionCurrency; | ||||
| 
 | ||||
|     public function findByName(string $name): ?TransactionCurrency; | ||||
| 
 | ||||
|     /** | ||||
|      * Find by object, ID or code. Returns user default or system default. | ||||
|      */ | ||||
|     public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency; | ||||
| 
 | ||||
|     /** | ||||
|      * Find by object, ID or code. Returns NULL if nothing found. | ||||
|      */ | ||||
|     public function findCurrencyNull(?int $currencyId, ?string $currencyCode): ?TransactionCurrency; | ||||
| 
 | ||||
|     /** | ||||
|      * Get the user group's currencies. | ||||
|      * | ||||
|      * @return Collection<TransactionCurrency> | ||||
|      */ | ||||
|     public function get(): Collection; | ||||
| 
 | ||||
|     /** | ||||
|      * Get ALL currencies. | ||||
|      */ | ||||
|     public function getAll(): Collection; | ||||
| 
 | ||||
|     public function getByIds(array $ids): Collection; | ||||
| 
 | ||||
|     public function isFallbackCurrency(TransactionCurrency $currency): bool; | ||||
| 
 | ||||
|     public function makePrimary(TransactionCurrency $currency): void; | ||||
| 
 | ||||
|     public function searchCurrency(string $search, int $limit): Collection; | ||||
| 
 | ||||
|     /** | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function store(array $data): TransactionCurrency; | ||||
| 
 | ||||
|     public function update(TransactionCurrency $currency, array $data): TransactionCurrency; | ||||
| } | ||||
| @@ -1,119 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * ExchangeRateRepository.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org. | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\ExchangeRate; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\CurrencyExchangeRate; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Database\Eloquent\Builder; | ||||
| use Illuminate\Support\Collection; | ||||
| use Override; | ||||
| 
 | ||||
| /** | ||||
|  * Class ExchangeRateRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class ExchangeRateRepository implements ExchangeRateRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function deleteRate(CurrencyExchangeRate $rate): void | ||||
|     { | ||||
|         $this->userGroup->currencyExchangeRates()->where('id', $rate->id)->delete(); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getAll(): Collection | ||||
|     { | ||||
|         return $this->userGroup->currencyExchangeRates()->orderBy('date', 'ASC')->get(); | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection | ||||
|     { | ||||
|         // orderBy('date', 'DESC')->toRawSql();
 | ||||
|         return | ||||
|             $this->userGroup->currencyExchangeRates() | ||||
|                 ->where(function (Builder $q1) use ($from, $to): void { | ||||
|                     $q1->where(function (Builder $q) use ($from, $to): void { | ||||
|                         $q->where('from_currency_id', $from->id) | ||||
|                             ->where('to_currency_id', $to->id) | ||||
|                         ; | ||||
|                     })->orWhere(function (Builder $q) use ($from, $to): void { | ||||
|                         $q->where('from_currency_id', $to->id) | ||||
|                             ->where('to_currency_id', $from->id) | ||||
|                         ; | ||||
|                     }); | ||||
|                 }) | ||||
|                 ->orderBy('date', 'DESC') | ||||
|                 ->get(['currency_exchange_rates.*']) | ||||
|         ; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate | ||||
|     { | ||||
|         /** @var null|CurrencyExchangeRate */ | ||||
|         return | ||||
|             $this->userGroup->currencyExchangeRates() | ||||
|                 ->where('from_currency_id', $from->id) | ||||
|                 ->where('to_currency_id', $to->id) | ||||
|                 ->where('date', $date->format('Y-m-d')) | ||||
|                 ->first() | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function storeExchangeRate(TransactionCurrency $from, TransactionCurrency $to, string $rate, Carbon $date): CurrencyExchangeRate | ||||
|     { | ||||
|         $object                   = new CurrencyExchangeRate(); | ||||
|         $object->user_id          = auth()->user()->id; | ||||
|         $object->user_group_id    = $this->userGroup->id; | ||||
|         $object->from_currency_id = $from->id; | ||||
|         $object->to_currency_id   = $to->id; | ||||
|         $object->rate             = $rate; | ||||
|         $object->date             = $date; | ||||
|         $object->date_tz          = $date->format('e'); | ||||
|         $object->save(); | ||||
| 
 | ||||
|         return $object; | ||||
|     } | ||||
| 
 | ||||
|     #[Override]
 | ||||
|     public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate | ||||
|     { | ||||
|         $object->rate = $rate; | ||||
|         if ($date instanceof Carbon) { | ||||
|             $object->date = $date; | ||||
|         } | ||||
|         $object->save(); | ||||
| 
 | ||||
|         return $object; | ||||
|     } | ||||
| } | ||||
| @@ -1,50 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * ExchangeRateRepositoryInterface.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org. | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\ExchangeRate; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\CurrencyExchangeRate; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface ExchangeRateRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface ExchangeRateRepositoryInterface | ||||
| { | ||||
|     public function deleteRate(CurrencyExchangeRate $rate): void; | ||||
| 
 | ||||
|     public function getAll(): Collection; | ||||
| 
 | ||||
|     public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection; | ||||
| 
 | ||||
|     public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate; | ||||
| 
 | ||||
|     public function storeExchangeRate(TransactionCurrency $from, TransactionCurrency $to, string $rate, Carbon $date): CurrencyExchangeRate; | ||||
| 
 | ||||
|     public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate; | ||||
| } | ||||
| @@ -1,60 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * JournalRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Journal; | ||||
| 
 | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Class JournalRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class JournalRepository implements JournalRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     public function searchJournalDescriptions(array $query, int $limit): Collection | ||||
|     { | ||||
|         $search = $this->userGroup->transactionJournals() | ||||
|             ->orderBy('date', 'DESC') | ||||
|         ; | ||||
|         if (count($query) > 0) { | ||||
|             // split query on spaces just in case:
 | ||||
|             $search->where(function (EloquentBuilder $q) use ($query): void { | ||||
|                 foreach ($query as $line) { | ||||
|                     $parts = explode(' ', $line); | ||||
|                     foreach ($parts as $part) { | ||||
|                         $search = sprintf('%%%s%%', $part); | ||||
|                         $q->orWhereLike('description', $search); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         return $search->take($limit)->get(); | ||||
|     } | ||||
| } | ||||
| @@ -1,40 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * JournalRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Journal; | ||||
| 
 | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface JournalRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface JournalRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * Search in journal descriptions. | ||||
|      */ | ||||
|     public function searchJournalDescriptions(array $query, int $limit): Collection; | ||||
| } | ||||
| @@ -1,53 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * PiggyBankRepository.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\PiggyBank; | ||||
| 
 | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Class PiggyBankRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class PiggyBankRepository implements PiggyBankRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     public function getPiggyBanks(): Collection | ||||
|     { | ||||
|         return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') | ||||
|             ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') | ||||
|             ->where('accounts.user_group_id', $this->userGroup->id) | ||||
|             ->with( | ||||
|                 [ | ||||
|                     'objectGroups', | ||||
|                 ] | ||||
|             ) | ||||
|             ->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*']) | ||||
|         ; | ||||
|     } | ||||
| } | ||||
| @@ -1,40 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * PiggyBankRepositoryInterface.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\PiggyBank; | ||||
| 
 | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface PiggyBankRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface PiggyBankRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * Return all piggy banks. | ||||
|      */ | ||||
|     public function getPiggyBanks(): Collection; | ||||
| } | ||||
| @@ -1,58 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * TagRepository.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Tag; | ||||
| 
 | ||||
| use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; | ||||
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Class TagRepository | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| class TagRepository implements TagRepositoryInterface | ||||
| { | ||||
|     use UserGroupTrait; | ||||
| 
 | ||||
|     public function searchTag(array $query, int $limit): Collection | ||||
|     { | ||||
|         $search = $this->userGroup->tags(); | ||||
|         if (count($query) > 0) { | ||||
|             // split query on spaces just in case:
 | ||||
|             $search->where(function (EloquentBuilder $q) use ($query): void { | ||||
|                 foreach ($query as $line) { | ||||
|                     $parts = explode(' ', $line); | ||||
|                     foreach ($parts as $part) { | ||||
|                         $search = sprintf('%%%s%%', $part); | ||||
|                         $q->orWhereLike('tag', $search); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         return $search->take($limit)->get(['tags.*']); | ||||
|     } | ||||
| } | ||||
| @@ -1,40 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * TagRepositoryInterface.php | ||||
|  * Copyright (c) 2024 james@firefly-iii.org | ||||
|  * | ||||
|  * This file is part of Firefly III (https://github.com/firefly-iii). | ||||
|  * | ||||
|  * 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. | ||||
|  * | ||||
|  * This program 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 Affero General Public License for more details. | ||||
|  * | ||||
|  * 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/>. | ||||
|  */ | ||||
| 
 | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| namespace FireflyIII\Repositories\UserGroups\Tag; | ||||
| 
 | ||||
| use Illuminate\Support\Collection; | ||||
| 
 | ||||
| /** | ||||
|  * Interface TagRepositoryInterface | ||||
|  * | ||||
|  * @deprecated | ||||
|  */ | ||||
| interface TagRepositoryInterface | ||||
| { | ||||
|     /** | ||||
|      * Find one or more tags based on the query. | ||||
|      */ | ||||
|     public function searchTag(array $query, int $limit): Collection; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user