mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Code reordering and reformatting. I should really start employing style CI.
This commit is contained in:
@@ -40,6 +40,7 @@ use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
use Log;
|
||||
use Storage;
|
||||
|
||||
@@ -115,6 +116,41 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account
|
||||
{
|
||||
return $this->user->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findByAccountNumber(string $number, array $types): ?Account
|
||||
{
|
||||
$dbQuery = $this->user
|
||||
->accounts()
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->where('accounts.active', true)
|
||||
->where(
|
||||
function (EloquentBuilder $q1) use ($number) {
|
||||
$json = json_encode($number);
|
||||
$q1->where('account_meta.name', '=', 'account_number');
|
||||
$q1->where('account_meta.data', '=', $json);
|
||||
}
|
||||
);
|
||||
|
||||
if (!empty($types)) {
|
||||
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$dbQuery->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
||||
return $dbQuery->first(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
@@ -162,16 +198,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account
|
||||
{
|
||||
return $this->user->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
@@ -310,6 +336,23 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $factory->findOrCreate('Cash account', $type->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup
|
||||
{
|
||||
$journal = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->transactionTypes([TransactionType::LIABILITY_CREDIT])
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $journal) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $journal->transactionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
@@ -731,7 +774,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
@@ -741,46 +784,4 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $service->update($account, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup
|
||||
{
|
||||
$journal = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->transactionTypes([TransactionType::LIABILITY_CREDIT])
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $journal) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $journal->transactionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findByAccountNumber(string $number, array $types): ?Account
|
||||
{
|
||||
$dbQuery = $this->user
|
||||
->accounts()
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->where('accounts.active', true)
|
||||
->where(
|
||||
function (EloquentBuilder $q1) use ($number) {
|
||||
$json = json_encode($number);
|
||||
$q1->where('account_meta.name', '=', 'account_number');
|
||||
$q1->where('account_meta.data', '=', $json);
|
||||
}
|
||||
);
|
||||
|
||||
if (!empty($types)) {
|
||||
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$dbQuery->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
||||
return $dbQuery->first(['accounts.*']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,13 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function expandWithDoubles(Collection $accounts): Collection;
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account;
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
* @param array $types
|
||||
@@ -90,13 +97,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function findByName(string $name, array $types): ?Account;
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
@@ -147,6 +147,13 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getCashAccount(): Account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
@@ -208,13 +215,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getOpeningBalanceDate(Account $account): ?string;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
|
||||
@@ -78,21 +78,6 @@ interface OperationsRepositoryInterface
|
||||
public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumExpensesBySource(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per destination / currency. Amounts are always negative.
|
||||
*
|
||||
@@ -108,6 +93,21 @@ interface OperationsRepositoryInterface
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumExpensesBySource(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of income journals in period for a set of accounts, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
@@ -133,7 +133,8 @@ interface OperationsRepositoryInterface
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumIncomeByDestination(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
|
||||
public function sumIncomeByDestination(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
@@ -147,7 +148,8 @@ interface OperationsRepositoryInterface
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumIncomeBySource(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
|
||||
public function sumIncomeBySource(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ use FireflyIII\User;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
use Log;
|
||||
use Storage;
|
||||
|
||||
@@ -623,7 +624,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function nextDateMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
@@ -652,7 +653,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
|
||||
@@ -425,6 +425,48 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleActions(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['set_budget',];
|
||||
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_actions.action_type', $types)
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*']);
|
||||
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
$action->action_value = $newName;
|
||||
$action->save();
|
||||
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleTriggers(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['budget_is',];
|
||||
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_triggers.trigger_type', $types)
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*']);
|
||||
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$trigger->trigger_value = $newName;
|
||||
$trigger->save();
|
||||
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
@@ -473,46 +515,4 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
$autoBudget->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleActions(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['set_budget',];
|
||||
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_actions.action_type', $types)
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*']);
|
||||
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
$action->action_value = $newName;
|
||||
$action->save();
|
||||
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleTriggers(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['budget_is',];
|
||||
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_triggers.trigger_type', $types)
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*']);
|
||||
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$trigger->trigger_value = $newName;
|
||||
$trigger->save();
|
||||
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +347,17 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getBudgets(): Collection
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repos */
|
||||
$repos = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $repos->getActiveBudgets();
|
||||
}
|
||||
|
||||
/**
|
||||
* For now, simply refer to whichever repository holds this function.
|
||||
* See reference nr. 14
|
||||
@@ -364,15 +375,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
return $blRepository->getBudgetLimits($budget, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getBudgets(): Collection
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repos */
|
||||
$repos = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $repos->getActiveBudgets();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,18 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function find(int $categoryId): ?Category
|
||||
{
|
||||
return $this->user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
@@ -118,18 +130,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function find(int $categoryId): ?Category
|
||||
{
|
||||
return $this->user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
|
||||
@@ -46,6 +46,15 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function find(int $categoryId): ?Category;
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
@@ -63,15 +72,6 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function findCategory(?int $categoryId, ?string $categoryName): ?Category;
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function find(int $categoryId): ?Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
@@ -98,7 +99,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [
|
||||
'amount' => app('steam')->negative($journal['amount']),
|
||||
'date' => $journal['date'],
|
||||
@@ -175,7 +176,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [
|
||||
'amount' => app('steam')->positive($journal['amount']),
|
||||
'date' => $journal['date'],
|
||||
|
||||
@@ -69,9 +69,9 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
$notes = $attachment->notes()->first();
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes = $notes ? $notes->text : '';
|
||||
$attachment->notes = $notes ? $notes->text : '';
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@@ -117,7 +118,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon
|
||||
{
|
||||
@@ -129,7 +130,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
if ($cache->has()) {
|
||||
$result = null;
|
||||
try {
|
||||
$result = new Carbon($cache->get());
|
||||
$result = new Carbon($cache->get());
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
@@ -161,7 +162,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getMetaField(TransactionJournal $journal, string $field): ?string
|
||||
{
|
||||
@@ -171,7 +172,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
|
||||
@@ -37,6 +37,7 @@ use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
|
||||
/**
|
||||
* Class JournalRepository.
|
||||
@@ -68,18 +69,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$service->destroy($journal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findByType(array $types): Collection
|
||||
{
|
||||
return $this->user
|
||||
->transactionJournals()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->get(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a specific journal.
|
||||
*
|
||||
@@ -92,6 +81,18 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $this->user->transactionJournals()->find($journalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findByType(array $types): Collection
|
||||
{
|
||||
return $this->user
|
||||
->transactionJournals()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->get(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users first transaction journal or NULL.
|
||||
*
|
||||
@@ -129,7 +130,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getJournalTotal(TransactionJournal $journal): string
|
||||
{
|
||||
@@ -137,7 +138,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('amount-positive');
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
// saves on queries:
|
||||
@@ -186,7 +187,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getMetaDateById(int $journalId, string $field): ?Carbon
|
||||
{
|
||||
@@ -196,7 +197,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return new Carbon($cache->get());
|
||||
return new Carbon($cache->get());
|
||||
}
|
||||
$entry = TransactionJournalMeta::where('transaction_journal_id', $journalId)
|
||||
->where('name', $field)->first();
|
||||
|
||||
@@ -50,13 +50,6 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function destroyJournal(TransactionJournal $journal): void;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function findByType(array $types): Collection;
|
||||
|
||||
/**
|
||||
* See reference nr. 1
|
||||
* Find a specific journal.
|
||||
@@ -67,6 +60,13 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function find(int $journalId): ?TransactionJournal;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function findByType(array $types): Collection;
|
||||
|
||||
/**
|
||||
* Get users very first transaction journal.
|
||||
*
|
||||
|
||||
@@ -80,6 +80,16 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function find(int $linkTypeId): ?LinkType
|
||||
{
|
||||
return LinkType::find($linkTypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
*
|
||||
@@ -111,16 +121,6 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return $count + $opposingCount > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function find(int $linkTypeId): ?LinkType
|
||||
{
|
||||
return LinkType::find($linkTypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if such a link already exists (and get it).
|
||||
*
|
||||
|
||||
@@ -55,6 +55,13 @@ interface LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function destroyLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function find(int $linkTypeId): ?LinkType;
|
||||
|
||||
/**
|
||||
* Find link type by name.
|
||||
*
|
||||
@@ -74,13 +81,6 @@ interface LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function findLink(TransactionJournal $one, TransactionJournal $two): bool;
|
||||
|
||||
/**
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function find(int $linkTypeId): ?LinkType;
|
||||
|
||||
/**
|
||||
* See if such a link already exists (and get it).
|
||||
*
|
||||
|
||||
@@ -88,7 +88,7 @@ trait ModifiesPiggyBanks
|
||||
*/
|
||||
public function canAddAmount(PiggyBank $piggyBank, string $amount): bool
|
||||
{
|
||||
$today = today(config('app.timezone'));
|
||||
$today = today(config('app.timezone'));
|
||||
$leftOnAccount = $this->leftOnAccount($piggyBank, $today);
|
||||
$savedSoFar = (string)$this->getRepetition($piggyBank)->currentamount;
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
|
||||
@@ -54,6 +54,16 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
$this->user->piggyBanks()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function find(int $piggyBankId): ?PiggyBank
|
||||
{
|
||||
return $this->user->piggyBanks()->find($piggyBankId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
@@ -66,16 +76,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function find(int $piggyBankId): ?PiggyBank
|
||||
{
|
||||
return $this->user->piggyBanks()->find($piggyBankId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
@@ -302,6 +302,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
$currentAmount = $this->getRepetition($piggy)->currentamount ?? '0';
|
||||
$piggy->name = $piggy->name . ' (' . app('amount')->formatAnything($currency, $currentAmount, false) . ')';
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,13 @@ interface PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function find(int $piggyBankId): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
@@ -110,13 +117,6 @@ interface PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function find(int $piggyBankId): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
|
||||
@@ -132,15 +132,15 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|string
|
||||
* @return null|int
|
||||
*/
|
||||
public function getCategoryName(RecurrenceTransaction $recTransaction): ?string
|
||||
public function getCategoryId(RecurrenceTransaction $recTransaction): ?int
|
||||
{
|
||||
$return = '';
|
||||
/** @var RecurrenceTransactionMeta $meta */
|
||||
foreach ($recTransaction->recurrenceTransactionMeta as $meta) {
|
||||
if ('category_name' === $meta->name) {
|
||||
$return = (string)$meta->value;
|
||||
if ('category_id' === $meta->name) {
|
||||
$return = (int)$meta->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,15 +152,15 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
* @return null|string
|
||||
*/
|
||||
public function getCategoryId(RecurrenceTransaction $recTransaction): ?int
|
||||
public function getCategoryName(RecurrenceTransaction $recTransaction): ?string
|
||||
{
|
||||
$return = '';
|
||||
/** @var RecurrenceTransactionMeta $meta */
|
||||
foreach ($recTransaction->recurrenceTransactionMeta as $meta) {
|
||||
if ('category_id' === $meta->name) {
|
||||
$return = (int)$meta->value;
|
||||
if ('category_name' === $meta->name) {
|
||||
$return = (string)$meta->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ use FireflyIII\Models\RecurrenceTransaction;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface RecurringRepositoryInterface
|
||||
*
|
||||
@@ -77,18 +78,18 @@ interface RecurringRepositoryInterface
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|string
|
||||
* @return null|int
|
||||
*/
|
||||
public function getCategoryName(RecurrenceTransaction $recTransaction): ?string;
|
||||
public function getCategoryId(RecurrenceTransaction $recTransaction): ?int;
|
||||
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
* @return null|string
|
||||
*/
|
||||
public function getCategoryId(RecurrenceTransaction $recTransaction): ?int;
|
||||
public function getCategoryName(RecurrenceTransaction $recTransaction): ?string;
|
||||
|
||||
/**
|
||||
* Returns the count of journals created for this recurrence, possibly limited by time.
|
||||
|
||||
@@ -190,26 +190,15 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
->get(['rules.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHighestOrderRuleGroup(): int
|
||||
{
|
||||
$entry = $this->user->ruleGroups()->max('order');
|
||||
|
||||
return (int)$entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getRuleGroupsWithRules(?string $filter): Collection
|
||||
public function getAllRuleGroupsWithRules(?string $filter): Collection
|
||||
{
|
||||
$groups = $this->user->ruleGroups()
|
||||
->orderBy('order', 'ASC')
|
||||
->where('active', true)
|
||||
->with(
|
||||
[
|
||||
'rules' => static function (HasMany $query) {
|
||||
@@ -253,15 +242,26 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHighestOrderRuleGroup(): int
|
||||
{
|
||||
$entry = $this->user->ruleGroups()->max('order');
|
||||
|
||||
return (int)$entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllRuleGroupsWithRules(?string $filter): Collection
|
||||
public function getRuleGroupsWithRules(?string $filter): Collection
|
||||
{
|
||||
$groups = $this->user->ruleGroups()
|
||||
->orderBy('order', 'ASC')
|
||||
->where('active', true)
|
||||
->with(
|
||||
[
|
||||
'rules' => static function (HasMany $query) {
|
||||
|
||||
@@ -102,6 +102,15 @@ interface RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function getActiveUpdateRules(RuleGroup $group): Collection;
|
||||
|
||||
/**
|
||||
* Also inactive groups.
|
||||
*
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllRuleGroupsWithRules(?string $filter): Collection;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -114,15 +123,6 @@ interface RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function getRuleGroupsWithRules(?string $filter): Collection;
|
||||
|
||||
/**
|
||||
* Also inactive groups.
|
||||
*
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllRuleGroupsWithRules(?string $filter): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
|
||||
@@ -99,16 +99,6 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag
|
||||
{
|
||||
return $this->user->tags()->where('tag', $tag)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
*
|
||||
@@ -119,6 +109,16 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $this->user->tags()->find($tagId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag
|
||||
{
|
||||
return $this->user->tags()->where('tag', $tag)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
|
||||
@@ -62,13 +62,6 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function expenseInPeriod(Tag $tag, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag;
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
*
|
||||
@@ -76,6 +69,13 @@ interface TagRepositoryInterface
|
||||
*/
|
||||
public function find(int $tagId): ?Tag;
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\TransactionGroup;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
@@ -359,12 +360,12 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
return $factory->create($data);
|
||||
} catch (DuplicateTransactionException $e) {
|
||||
Log::warning('Group repository caught group factory with a duplicate exception!');
|
||||
throw new DuplicateTransactionException($e->getMessage(),0, $e);
|
||||
throw new DuplicateTransactionException($e->getMessage(), 0, $e);
|
||||
} catch (FireflyException $e) {
|
||||
Log::warning('Group repository caught group factory with an exception!');
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
throw new FireflyException($e->getMessage(),0, $e);
|
||||
throw new FireflyException($e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,6 +381,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
{
|
||||
/** @var GroupUpdateService $service */
|
||||
$service = app(GroupUpdateService::class);
|
||||
|
||||
return $service->update($transactionGroup, $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,16 +169,6 @@ class UserRepository implements UserRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
return User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
*
|
||||
@@ -189,6 +179,16 @@ class UserRepository implements UserRepositoryInterface
|
||||
return User::find($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
return User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first user in the DB. Generally only works when there is just one.
|
||||
*
|
||||
|
||||
@@ -102,13 +102,6 @@ interface UserRepositoryInterface
|
||||
*/
|
||||
public function destroy(User $user): bool;
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function findByEmail(string $email): ?User;
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
*
|
||||
@@ -116,6 +109,13 @@ interface UserRepositoryInterface
|
||||
*/
|
||||
public function find(int $userId): ?User;
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function findByEmail(string $email): ?User;
|
||||
|
||||
/**
|
||||
* Returns the first user in the DB. Generally only works when there is just one.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user