mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 10:53:37 +00:00
Refactor journal repositories.
This commit is contained in:
@@ -26,6 +26,7 @@ use Exception;
|
|||||||
use FireflyIII\Factory\TransactionGroupFactory;
|
use FireflyIII\Factory\TransactionGroupFactory;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
@@ -58,6 +59,8 @@ class MigrateToGroups extends Command
|
|||||||
private $groupFactory;
|
private $groupFactory;
|
||||||
/** @var JournalRepositoryInterface */
|
/** @var JournalRepositoryInterface */
|
||||||
private $journalRepository;
|
private $journalRepository;
|
||||||
|
/** @var JournalCLIRepositoryInterface */
|
||||||
|
private $cliRepository;
|
||||||
/** @var JournalDestroyService */
|
/** @var JournalDestroyService */
|
||||||
private $service;
|
private $service;
|
||||||
private $count;
|
private $count;
|
||||||
@@ -122,6 +125,7 @@ class MigrateToGroups extends Command
|
|||||||
$this->journalRepository = app(JournalRepositoryInterface::class);
|
$this->journalRepository = app(JournalRepositoryInterface::class);
|
||||||
$this->service = app(JournalDestroyService::class);
|
$this->service = app(JournalDestroyService::class);
|
||||||
$this->groupFactory = app(TransactionGroupFactory::class);
|
$this->groupFactory = app(TransactionGroupFactory::class);
|
||||||
|
$this->cliRepository = app(JournalCLIRepositoryInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,7 +199,7 @@ class MigrateToGroups extends Command
|
|||||||
*/
|
*/
|
||||||
private function makeGroupsFromAll(): void
|
private function makeGroupsFromAll(): void
|
||||||
{
|
{
|
||||||
$orphanedJournals = $this->journalRepository->getJournalsWithoutGroup();
|
$orphanedJournals = $this->cliRepository->getJournalsWithoutGroup();
|
||||||
$count = count($orphanedJournals);
|
$count = count($orphanedJournals);
|
||||||
if ($count > 0) {
|
if ($count > 0) {
|
||||||
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $count));
|
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $count));
|
||||||
@@ -215,7 +219,7 @@ class MigrateToGroups extends Command
|
|||||||
*/
|
*/
|
||||||
private function makeGroupsFromSplitJournals(): void
|
private function makeGroupsFromSplitJournals(): void
|
||||||
{
|
{
|
||||||
$splitJournals = $this->journalRepository->getSplitJournals();
|
$splitJournals = $this->cliRepository->getSplitJournals();
|
||||||
if ($splitJournals->count() > 0) {
|
if ($splitJournals->count() > 0) {
|
||||||
$this->info(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count()));
|
$this->info(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count()));
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
@@ -248,6 +252,7 @@ class MigrateToGroups extends Command
|
|||||||
|
|
||||||
$this->journalRepository->setUser($journal->user);
|
$this->journalRepository->setUser($journal->user);
|
||||||
$this->groupFactory->setUser($journal->user);
|
$this->groupFactory->setUser($journal->user);
|
||||||
|
$this->cliRepository->setUser($journal->user);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
// mandatory fields.
|
// mandatory fields.
|
||||||
@@ -255,32 +260,31 @@ class MigrateToGroups extends Command
|
|||||||
'transactions' => [],
|
'transactions' => [],
|
||||||
];
|
];
|
||||||
$destTransactions = $this->getDestinationTransactions($journal);
|
$destTransactions = $this->getDestinationTransactions($journal);
|
||||||
$budgetId = $this->journalRepository->getJournalBudgetId($journal);
|
$budgetId = $this->cliRepository->getJournalBudgetId($journal);
|
||||||
$categoryId = $this->journalRepository->getJournalCategoryId($journal);
|
$categoryId = $this->cliRepository->getJournalCategoryId($journal);
|
||||||
$notes = $this->journalRepository->getNoteText($journal);
|
$notes = $this->cliRepository->getNoteText($journal);
|
||||||
$tags = $this->journalRepository->getTags($journal);
|
$tags = $this->cliRepository->getTags($journal);
|
||||||
$internalRef = $this->journalRepository->getMetaField($journal, 'internal-reference');
|
$internalRef = $this->cliRepository->getMetaField($journal, 'internal-reference');
|
||||||
$sepaCC = $this->journalRepository->getMetaField($journal, 'sepa_cc');
|
$sepaCC = $this->cliRepository->getMetaField($journal, 'sepa_cc');
|
||||||
$sepaCtOp = $this->journalRepository->getMetaField($journal, 'sepa_ct_op');
|
$sepaCtOp = $this->cliRepository->getMetaField($journal, 'sepa_ct_op');
|
||||||
$sepaCtId = $this->journalRepository->getMetaField($journal, 'sepa_ct_id');
|
$sepaCtId = $this->cliRepository->getMetaField($journal, 'sepa_ct_id');
|
||||||
$sepaDb = $this->journalRepository->getMetaField($journal, 'sepa_db');
|
$sepaDb = $this->cliRepository->getMetaField($journal, 'sepa_db');
|
||||||
$sepaCountry = $this->journalRepository->getMetaField($journal, 'sepa_country');
|
$sepaCountry = $this->cliRepository->getMetaField($journal, 'sepa_country');
|
||||||
$sepaEp = $this->journalRepository->getMetaField($journal, 'sepa_ep');
|
$sepaEp = $this->cliRepository->getMetaField($journal, 'sepa_ep');
|
||||||
$sepaCi = $this->journalRepository->getMetaField($journal, 'sepa_ci');
|
$sepaCi = $this->cliRepository->getMetaField($journal, 'sepa_ci');
|
||||||
$sepaBatchId = $this->journalRepository->getMetaField($journal, 'sepa_batch_id');
|
$sepaBatchId = $this->cliRepository->getMetaField($journal, 'sepa_batch_id');
|
||||||
$externalId = $this->journalRepository->getMetaField($journal, 'external-id');
|
$externalId = $this->cliRepository->getMetaField($journal, 'external-id');
|
||||||
$originalSource = $this->journalRepository->getMetaField($journal, 'original-source');
|
$originalSource = $this->cliRepository->getMetaField($journal, 'original-source');
|
||||||
$recurrenceId = $this->journalRepository->getMetaField($journal, 'recurrence_id');
|
$recurrenceId = $this->cliRepository->getMetaField($journal, 'recurrence_id');
|
||||||
$bunq = $this->journalRepository->getMetaField($journal, 'bunq_payment_id');
|
$bunq = $this->cliRepository->getMetaField($journal, 'bunq_payment_id');
|
||||||
$hash = $this->journalRepository->getMetaField($journal, 'import_hash');
|
$hash = $this->cliRepository->getMetaField($journal, 'import_hash');
|
||||||
$hashTwo = $this->journalRepository->getMetaField($journal, 'import_hash_v2');
|
$hashTwo = $this->cliRepository->getMetaField($journal, 'import_hash_v2');
|
||||||
$interestDate = $this->journalRepository->getMetaDate($journal, 'interest_date');
|
$interestDate = $this->cliRepository->getMetaDate($journal, 'interest_date');
|
||||||
$bookDate = $this->journalRepository->getMetaDate($journal, 'book_date');
|
$bookDate = $this->cliRepository->getMetaDate($journal, 'book_date');
|
||||||
$processDate = $this->journalRepository->getMetaDate($journal, 'process_date');
|
$processDate = $this->cliRepository->getMetaDate($journal, 'process_date');
|
||||||
$dueDate = $this->journalRepository->getMetaDate($journal, 'due_date');
|
$dueDate = $this->cliRepository->getMetaDate($journal, 'due_date');
|
||||||
$paymentDate = $this->journalRepository->getMetaDate($journal, 'payment_date');
|
$paymentDate = $this->cliRepository->getMetaDate($journal, 'payment_date');
|
||||||
$invoiceDate = $this->journalRepository->getMetaDate($journal, 'invoice_date');
|
$invoiceDate = $this->cliRepository->getMetaDate($journal, 'invoice_date');
|
||||||
|
|
||||||
|
|
||||||
Log::debug(sprintf('Will use %d positive transactions to create a new group.', $destTransactions->count()));
|
Log::debug(sprintf('Will use %d positive transactions to create a new group.', $destTransactions->count()));
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ namespace FireflyIII\Console\Commands\Upgrade;
|
|||||||
|
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
@@ -51,6 +52,9 @@ class TransactionIdentifier extends Command
|
|||||||
/** @var JournalRepositoryInterface */
|
/** @var JournalRepositoryInterface */
|
||||||
private $journalRepository;
|
private $journalRepository;
|
||||||
|
|
||||||
|
/** @var JournalCLIRepositoryInterface */
|
||||||
|
private $cliRepository;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $count;
|
private $count;
|
||||||
|
|
||||||
@@ -81,7 +85,7 @@ class TransactionIdentifier extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
$journals = $this->journalRepository->getSplitJournals();
|
$journals = $this->cliRepository->getSplitJournals();
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$this->updateJournalIdentifiers($journal);
|
$this->updateJournalIdentifiers($journal);
|
||||||
@@ -111,6 +115,7 @@ class TransactionIdentifier extends Command
|
|||||||
private function stupidLaravel(): void
|
private function stupidLaravel(): void
|
||||||
{
|
{
|
||||||
$this->journalRepository = app(JournalRepositoryInterface::class);
|
$this->journalRepository = app(JournalRepositoryInterface::class);
|
||||||
|
$this->cliRepository = app(JournalCLIRepositoryInterface::class);
|
||||||
$this->count = 0;
|
$this->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -60,6 +61,8 @@ class TransferCurrenciesCorrections extends Command
|
|||||||
private $currencyRepos;
|
private $currencyRepos;
|
||||||
/** @var JournalRepositoryInterface */
|
/** @var JournalRepositoryInterface */
|
||||||
private $journalRepos;
|
private $journalRepos;
|
||||||
|
/** @var JournalCLIRepositoryInterface */
|
||||||
|
private $cliRepos;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $count;
|
private $count;
|
||||||
|
|
||||||
@@ -125,6 +128,7 @@ class TransferCurrenciesCorrections extends Command
|
|||||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||||
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
$this->journalRepos = app(JournalRepositoryInterface::class);
|
$this->journalRepos = app(JournalRepositoryInterface::class);
|
||||||
|
$this->cliRepos = app(JournalCLIRepositoryInterface::class);
|
||||||
$this->accountCurrencies = [];
|
$this->accountCurrencies = [];
|
||||||
$this->resetInformation();
|
$this->resetInformation();
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,8 @@ use FireflyIII\Helpers\Collector\GroupCollector;
|
|||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalAPIRepository;
|
use FireflyIII\Repositories\Journal\JournalAPIRepository;
|
||||||
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepository;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepository;
|
use FireflyIII\Repositories\Journal\JournalRepository;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepository;
|
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepository;
|
||||||
@@ -63,7 +65,7 @@ class JournalServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
GroupCollectorInterface::class,
|
GroupCollectorInterface::class,
|
||||||
function (Application $app) {
|
static function (Application $app) {
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollector::class);
|
$collector = app(GroupCollector::class);
|
||||||
if ($app->auth->check()) {
|
if ($app->auth->check()) {
|
||||||
@@ -82,7 +84,7 @@ class JournalServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
TransactionGroupRepositoryInterface::class,
|
TransactionGroupRepositoryInterface::class,
|
||||||
function (Application $app) {
|
static function (Application $app) {
|
||||||
/** @var TransactionGroupRepositoryInterface $repository */
|
/** @var TransactionGroupRepositoryInterface $repository */
|
||||||
$repository = app(TransactionGroupRepository::class);
|
$repository = app(TransactionGroupRepository::class);
|
||||||
if ($app->auth->check()) {
|
if ($app->auth->check()) {
|
||||||
@@ -101,7 +103,7 @@ class JournalServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
JournalRepositoryInterface::class,
|
JournalRepositoryInterface::class,
|
||||||
function (Application $app) {
|
static function (Application $app) {
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepository::class);
|
$repository = app(JournalRepository::class);
|
||||||
if ($app->auth->check()) {
|
if ($app->auth->check()) {
|
||||||
@@ -115,7 +117,7 @@ class JournalServiceProvider extends ServiceProvider
|
|||||||
// also bind new API repository
|
// also bind new API repository
|
||||||
$this->app->bind(
|
$this->app->bind(
|
||||||
JournalAPIRepositoryInterface::class,
|
JournalAPIRepositoryInterface::class,
|
||||||
function (Application $app) {
|
static function (Application $app) {
|
||||||
/** @var JournalAPIRepositoryInterface $repository */
|
/** @var JournalAPIRepositoryInterface $repository */
|
||||||
$repository = app(JournalAPIRepository::class);
|
$repository = app(JournalAPIRepository::class);
|
||||||
if ($app->auth->check()) {
|
if ($app->auth->check()) {
|
||||||
@@ -125,5 +127,19 @@ class JournalServiceProvider extends ServiceProvider
|
|||||||
return $repository;
|
return $repository;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// also bind new CLI repository
|
||||||
|
$this->app->bind(
|
||||||
|
JournalCLIRepositoryInterface::class,
|
||||||
|
static function (Application $app) {
|
||||||
|
/** @var JournalCLIRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalCLIRepository::class);
|
||||||
|
if ($app->auth->check()) {
|
||||||
|
$repository->setUser(auth()->user());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $repository;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
275
app/Repositories/Journal/JournalCLIRepository.php
Normal file
275
app/Repositories/Journal/JournalCLIRepository.php
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* JournalCLIRepository.php
|
||||||
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
|
use Exception;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class JournalCLIRepository
|
||||||
|
*/
|
||||||
|
class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||||
|
{
|
||||||
|
/** @var User */
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all transaction journals with a specific type, regardless of user.
|
||||||
|
*
|
||||||
|
* @param array $types
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAllJournals(array $types): Collection
|
||||||
|
{
|
||||||
|
return TransactionJournal
|
||||||
|
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
|
->whereIn('transaction_types.type', $types)
|
||||||
|
->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account'])
|
||||||
|
->get(['transaction_journals.*']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getJournalBudgetId(TransactionJournal $journal): int
|
||||||
|
{
|
||||||
|
$budget = $journal->budgets()->first();
|
||||||
|
if (null !== $budget) {
|
||||||
|
return $budget->id;
|
||||||
|
}
|
||||||
|
/** @noinspection NullPointerExceptionInspection */
|
||||||
|
$budget = $journal->transactions()->first()->budgets()->first();
|
||||||
|
if (null !== $budget) {
|
||||||
|
return $budget->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getJournalCategoryId(TransactionJournal $journal): int
|
||||||
|
{
|
||||||
|
$category = $journal->categories()->first();
|
||||||
|
if (null !== $category) {
|
||||||
|
return $category->id;
|
||||||
|
}
|
||||||
|
/** @noinspection NullPointerExceptionInspection */
|
||||||
|
$category = $journal->transactions()->first()->categories()->first();
|
||||||
|
if (null !== $category) {
|
||||||
|
return $category->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all journals without a group, used in an upgrade routine.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getJournalsWithoutGroup(): array
|
||||||
|
{
|
||||||
|
return TransactionJournal::whereNull('transaction_group_id')->get(['id', 'user_id'])->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Carbon value of a meta field (or NULL).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return null|Carbon
|
||||||
|
*/
|
||||||
|
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon
|
||||||
|
{
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty('journal-meta-updated');
|
||||||
|
$cache->addProperty($journal->id);
|
||||||
|
$cache->addProperty($field);
|
||||||
|
|
||||||
|
if ($cache->has()) {
|
||||||
|
$result = null;
|
||||||
|
try {
|
||||||
|
$result = new Carbon($cache->get()); // @codeCoverageIgnore
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||||
|
if (null === $entry) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$value = null;
|
||||||
|
try {
|
||||||
|
$value = new Carbon($entry->data);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$e->getMessage();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache->store($entry->data);
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return value of a meta field (or NULL) as a string.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function getMetaField(TransactionJournal $journal, string $field): ?string
|
||||||
|
{
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty('journal-meta-updated');
|
||||||
|
$cache->addProperty($journal->id);
|
||||||
|
$cache->addProperty($field);
|
||||||
|
|
||||||
|
if ($cache->has()) {
|
||||||
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||||
|
if (null === $entry) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $entry->data;
|
||||||
|
|
||||||
|
if (is_array($value)) {
|
||||||
|
$return = implode(',', $value);
|
||||||
|
$cache->store($return);
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return when something else:
|
||||||
|
try {
|
||||||
|
$return = (string)$value;
|
||||||
|
$cache->store($return);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return text of a note attached to journal, or NULL
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getNoteText(TransactionJournal $journal): ?string
|
||||||
|
{
|
||||||
|
$note = $journal->notes()->first();
|
||||||
|
if (null === $note) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $note->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all journals with more than 2 transactions. Should only return empty collections
|
||||||
|
* in Firefly III > v4.8.0.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getSplitJournals(): Collection
|
||||||
|
{
|
||||||
|
$query = TransactionJournal
|
||||||
|
::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->groupBy('transaction_journals.id');
|
||||||
|
$result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]);
|
||||||
|
$journalIds = [];
|
||||||
|
/** @var stdClass $row */
|
||||||
|
foreach ($result as $row) {
|
||||||
|
if ((int)$row->transaction_count > 2) {
|
||||||
|
$journalIds[] = (int)$row->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$journalIds = array_unique($journalIds);
|
||||||
|
|
||||||
|
return TransactionJournal
|
||||||
|
::with(['transactions'])
|
||||||
|
->whereIn('id', $journalIds)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all tags as strings in an array.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTags(TransactionJournal $journal): array
|
||||||
|
{
|
||||||
|
return $journal->tags()->get()->pluck('tag')->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function setUser(User $user): void
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
}
|
@@ -21,7 +21,10 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface JournalCLIRepositoryInterface
|
* Interface JournalCLIRepositoryInterface
|
||||||
@@ -33,4 +36,84 @@ interface JournalCLIRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function setUser(User $user);
|
public function setUser(User $user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all tags as strings in an array.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTags(TransactionJournal $journal): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all journals with more than 2 transactions. Should only return empty collections
|
||||||
|
* in Firefly III > v4.8.0.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getSplitJournals(): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return text of a note attached to journal, or NULL
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getNoteText(TransactionJournal $journal): ?string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return value of a meta field (or NULL).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function getMetaField(TransactionJournal $journal, string $field): ?string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Carbon value of a meta field (or NULL).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return null|Carbon
|
||||||
|
*/
|
||||||
|
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all journals without a group, used in an upgrade routine.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getJournalsWithoutGroup(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all transaction journals with a specific type, regardless of user.
|
||||||
|
*
|
||||||
|
* @param array $types
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAllJournals(array $types): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getJournalBudgetId(TransactionJournal $journal): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getJournalCategoryId(TransactionJournal $journal): int;
|
||||||
|
|
||||||
}
|
}
|
@@ -23,27 +23,19 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
|
||||||
use Exception;
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\AccountType;
|
|
||||||
use FireflyIII\Models\Note;
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionJournalLink;
|
use FireflyIII\Models\TransactionJournalLink;
|
||||||
use FireflyIII\Models\TransactionJournalMeta;
|
use FireflyIII\Models\TransactionJournalMeta;
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
||||||
use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
|
use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
|
||||||
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
|
||||||
use Log;
|
use Log;
|
||||||
use stdClass;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JournalRepository.
|
* Class JournalRepository.
|
||||||
@@ -159,79 +151,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getJournalBudgetId(TransactionJournal $journal): int
|
|
||||||
{
|
|
||||||
$budget = $journal->budgets()->first();
|
|
||||||
if (null !== $budget) {
|
|
||||||
return $budget->id;
|
|
||||||
}
|
|
||||||
/** @noinspection NullPointerExceptionInspection */
|
|
||||||
$budget = $journal->transactions()->first()->budgets()->first();
|
|
||||||
if (null !== $budget) {
|
|
||||||
return $budget->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getJournalCategoryId(TransactionJournal $journal): int
|
|
||||||
{
|
|
||||||
$category = $journal->categories()->first();
|
|
||||||
if (null !== $category) {
|
|
||||||
return $category->id;
|
|
||||||
}
|
|
||||||
/** @noinspection NullPointerExceptionInspection */
|
|
||||||
$category = $journal->transactions()->first()->categories()->first();
|
|
||||||
if (null !== $category) {
|
|
||||||
return $category->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return Carbon value of a meta field (or NULL).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
* @param string $field
|
|
||||||
*
|
|
||||||
* @return null|Carbon
|
|
||||||
*/
|
|
||||||
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon
|
|
||||||
{
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty('journal-meta-updated');
|
|
||||||
$cache->addProperty($journal->id);
|
|
||||||
$cache->addProperty($field);
|
|
||||||
|
|
||||||
if ($cache->has()) {
|
|
||||||
return new Carbon($cache->get()); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
|
||||||
if (null === $entry) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$value = new Carbon($entry->data);
|
|
||||||
$cache->store($entry->data);
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of all destination accounts related to journal.
|
* Return a list of all destination accounts related to journal.
|
||||||
*
|
*
|
||||||
@@ -312,16 +231,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $amount;
|
return $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all journals without a group, used in an upgrade routine.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getJournalsWithoutGroup(): array
|
|
||||||
{
|
|
||||||
return TransactionJournal::whereNull('transaction_group_id')->get(['id', 'user_id'])->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournalLink $link
|
* @param TransactionJournalLink $link
|
||||||
*
|
*
|
||||||
@@ -339,109 +248,13 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return value of a meta field (or NULL) as a string.
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
* @param string $field
|
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
||||||
*/
|
|
||||||
public function getMetaField(TransactionJournal $journal, string $field): ?string
|
|
||||||
{
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty('journal-meta-updated');
|
|
||||||
$cache->addProperty($journal->id);
|
|
||||||
$cache->addProperty($field);
|
|
||||||
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
|
||||||
if (null === $entry) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $entry->data;
|
|
||||||
|
|
||||||
if (is_array($value)) {
|
|
||||||
$return = implode(',', $value);
|
|
||||||
$cache->store($return);
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return when something else:
|
|
||||||
try {
|
|
||||||
$return = (string)$value;
|
|
||||||
$cache->store($return);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return text of a note attached to journal, or NULL
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getNoteText(TransactionJournal $journal): ?string
|
|
||||||
{
|
|
||||||
$note = $journal->notes()->first();
|
|
||||||
if (null === $note) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $note->text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all journals with more than 2 transactions. Should only return empty collections
|
|
||||||
* in Firefly III > v4.8.0.
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getSplitJournals(): Collection
|
|
||||||
{
|
|
||||||
$query = TransactionJournal
|
|
||||||
::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->groupBy('transaction_journals.id');
|
|
||||||
$result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]);
|
|
||||||
$journalIds = [];
|
|
||||||
/** @var stdClass $row */
|
|
||||||
foreach ($result as $row) {
|
|
||||||
if ((int)$row->transaction_count > 2) {
|
|
||||||
$journalIds[] = (int)$row->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$journalIds = array_unique($journalIds);
|
|
||||||
|
|
||||||
return TransactionJournal
|
|
||||||
::with(['transactions'])
|
|
||||||
->whereIn('id', $journalIds)->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all tags as strings in an array.
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getTags(TransactionJournal $journal): array
|
|
||||||
{
|
|
||||||
return $journal->tags()->get()->pluck('tag')->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $transactionId
|
* @param int $transactionId
|
||||||
@@ -536,21 +349,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $journal;
|
return $journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all transaction journals with a specific type, regardless of user.
|
|
||||||
*
|
|
||||||
* @param array $types
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAllJournals(array $types): Collection
|
|
||||||
{
|
|
||||||
return TransactionJournal
|
|
||||||
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
|
||||||
->whereIn('transaction_types.type', $types)
|
|
||||||
->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account'])
|
|
||||||
->get(['transaction_journals.*']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Carbon value of a meta field (or NULL).
|
* Return Carbon value of a meta field (or NULL).
|
||||||
*
|
*
|
||||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionJournalLink;
|
use FireflyIII\Models\TransactionJournalLink;
|
||||||
@@ -33,7 +32,6 @@ use Illuminate\Support\Collection;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface JournalRepositoryInterface.
|
* Interface JournalRepositoryInterface.
|
||||||
* TODO needs cleaning up. Remove unused methods.
|
|
||||||
*/
|
*/
|
||||||
interface JournalRepositoryInterface
|
interface JournalRepositoryInterface
|
||||||
{
|
{
|
||||||
@@ -48,16 +46,6 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function searchJournalDescriptions(string $search): Collection;
|
public function searchJournalDescriptions(string $search): Collection;
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO maybe create command line repository?
|
|
||||||
*
|
|
||||||
* Get all transaction journals with a specific type, regardless of user.
|
|
||||||
*
|
|
||||||
* @param array $types
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAllJournals(array $types): Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a transaction group.
|
* Deletes a transaction group.
|
||||||
*
|
*
|
||||||
@@ -101,28 +89,6 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function firstNull(): ?TransactionJournal;
|
public function firstNull(): ?TransactionJournal;
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO console repository?
|
|
||||||
*
|
|
||||||
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getJournalBudgetId(TransactionJournal $journal): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO console repository?
|
|
||||||
*
|
|
||||||
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getJournalCategoryId(TransactionJournal $journal): int;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO this method is no longer well-fitted in 4.8.0. Should be refactored and/or removed.
|
* TODO this method is no longer well-fitted in 4.8.0. Should be refactored and/or removed.
|
||||||
* Return a list of all destination accounts related to journal.
|
* Return a list of all destination accounts related to journal.
|
||||||
@@ -152,14 +118,6 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournalTotal(TransactionJournal $journal): string;
|
public function getJournalTotal(TransactionJournal $journal): string;
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO only used on command line.
|
|
||||||
* Return all journals without a group, used in an upgrade routine.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getJournalsWithoutGroup(): array;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO used only in transformer, so only for API use.
|
* TODO used only in transformer, so only for API use.
|
||||||
* @param TransactionJournalLink $link
|
* @param TransactionJournalLink $link
|
||||||
@@ -168,16 +126,6 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getLinkNoteText(TransactionJournalLink $link): string;
|
public function getLinkNoteText(TransactionJournalLink $link): string;
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO used only on console
|
|
||||||
* Return Carbon value of a meta field (or NULL).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
* @param string $field
|
|
||||||
*
|
|
||||||
* @return null|Carbon
|
|
||||||
*/
|
|
||||||
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Carbon value of a meta field (or NULL).
|
* Return Carbon value of a meta field (or NULL).
|
||||||
@@ -189,49 +137,9 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getMetaDateById(int $journalId, string $field): ?Carbon;
|
public function getMetaDateById(int $journalId, string $field): ?Carbon;
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO used only on the console.
|
|
||||||
*
|
|
||||||
* Return value of a meta field (or NULL).
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
* @param string $field
|
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
public function getMetaField(TransactionJournal $journal, string $field): ?string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO used only on the console.
|
|
||||||
*
|
|
||||||
* Return text of a note attached to journal, or NULL
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getNoteText(TransactionJournal $journal): ?string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO used only on the console.
|
|
||||||
*
|
|
||||||
* Returns all journals with more than 2 transactions. Should only return empty collections
|
|
||||||
* in Firefly III > v4.8.0.
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getSplitJournals(): Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO used only on the console.
|
|
||||||
*
|
|
||||||
* Return all tags as strings in an array.
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getTags(TransactionJournal $journal): array;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO maybe move to account repository?
|
* TODO maybe move to account repository?
|
||||||
|
@@ -28,6 +28,7 @@ use FireflyIII\Factory\TransactionGroupFactory;
|
|||||||
use FireflyIII\Models\Configuration;
|
use FireflyIII\Models\Configuration;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -59,12 +60,13 @@ class MigrateToGroupsTest extends TestCase
|
|||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$service = $this->mock(JournalDestroyService::class);
|
$service = $this->mock(JournalDestroyService::class);
|
||||||
$groupFactory = $this->mock(TransactionGroupFactory::class);
|
$groupFactory = $this->mock(TransactionGroupFactory::class);
|
||||||
|
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$journalRepos->shouldReceive('getSplitJournals')
|
$cliRepos->shouldReceive('getSplitJournals')
|
||||||
->atLeast()->once()
|
->atLeast()->once()
|
||||||
->andReturn(new Collection);
|
->andReturn(new Collection);
|
||||||
$journalRepos->shouldReceive('getJournalsWithoutGroup')
|
$cliRepos->shouldReceive('getJournalsWithoutGroup')
|
||||||
->atLeast()->once()
|
->atLeast()->once()
|
||||||
->andReturn([]);
|
->andReturn([]);
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@ class MigrateToGroupsTest extends TestCase
|
|||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$service = $this->mock(JournalDestroyService::class);
|
$service = $this->mock(JournalDestroyService::class);
|
||||||
$groupFactory = $this->mock(TransactionGroupFactory::class);
|
$groupFactory = $this->mock(TransactionGroupFactory::class);
|
||||||
|
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
|
||||||
|
|
||||||
$asset = $this->getRandomAsset();
|
$asset = $this->getRandomAsset();
|
||||||
$expense = $this->getRandomExpense();
|
$expense = $this->getRandomExpense();
|
||||||
@@ -121,10 +124,10 @@ class MigrateToGroupsTest extends TestCase
|
|||||||
$array = $journal->toArray();
|
$array = $journal->toArray();
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$journalRepos->shouldReceive('getSplitJournals')
|
$cliRepos->shouldReceive('getSplitJournals')
|
||||||
->atLeast()->once()
|
->atLeast()->once()
|
||||||
->andReturn(new Collection);
|
->andReturn(new Collection);
|
||||||
$journalRepos->shouldReceive('getJournalsWithoutGroup')
|
$cliRepos->shouldReceive('getJournalsWithoutGroup')
|
||||||
->atLeast()->once()
|
->atLeast()->once()
|
||||||
->andReturn([$array]);
|
->andReturn([$array]);
|
||||||
|
|
||||||
@@ -203,19 +206,21 @@ class MigrateToGroupsTest extends TestCase
|
|||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$service = $this->mock(JournalDestroyService::class);
|
$service = $this->mock(JournalDestroyService::class);
|
||||||
$factory = $this->mock(TransactionGroupFactory::class);
|
$factory = $this->mock(TransactionGroupFactory::class);
|
||||||
|
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
|
$cliRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
|
||||||
// mock journal things:
|
// mock journal things:
|
||||||
$journalRepos->shouldReceive('getJournalBudgetId')->atLeast()->once()->andReturn(0);
|
$cliRepos->shouldReceive('getJournalBudgetId')->atLeast()->once()->andReturn(0);
|
||||||
$journalRepos->shouldReceive('getJournalCategoryId')->atLeast()->once()->andReturn(0);
|
$cliRepos->shouldReceive('getJournalCategoryId')->atLeast()->once()->andReturn(0);
|
||||||
$journalRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('Some note.');
|
$cliRepos->shouldReceive('getNoteText')->atLeast()->once()->andReturn('Some note.');
|
||||||
$journalRepos->shouldReceive('getTags')->atLeast()->once()->andReturn(['A', 'B']);
|
$cliRepos->shouldReceive('getTags')->atLeast()->once()->andReturn(['A', 'B']);
|
||||||
$journalRepos->shouldReceive('getMetaField')->atLeast()
|
$cliRepos->shouldReceive('getMetaField')->atLeast()
|
||||||
->withArgs([Mockery::any(), Mockery::any()])
|
->withArgs([Mockery::any(), Mockery::any()])
|
||||||
->once()->andReturn(null);
|
->once()->andReturn(null);
|
||||||
$journalRepos->shouldReceive('getMetaDate')->atLeast()
|
$cliRepos->shouldReceive('getMetaDate')->atLeast()
|
||||||
->withArgs([Mockery::any(), Mockery::any()])
|
->withArgs([Mockery::any(), Mockery::any()])
|
||||||
->once()->andReturn(null);
|
->once()->andReturn(null);
|
||||||
|
|
||||||
@@ -225,10 +230,10 @@ class MigrateToGroupsTest extends TestCase
|
|||||||
|
|
||||||
$factory->shouldReceive('setUser')->atLeast()->once();
|
$factory->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
|
||||||
$journalRepos->shouldReceive('getSplitJournals')
|
$cliRepos->shouldReceive('getSplitJournals')
|
||||||
->atLeast()->once()
|
->atLeast()->once()
|
||||||
->andReturn(new Collection([$journal]));
|
->andReturn(new Collection([$journal]));
|
||||||
$journalRepos->shouldReceive('getJournalsWithoutGroup')
|
$cliRepos->shouldReceive('getJournalsWithoutGroup')
|
||||||
->atLeast()->once()
|
->atLeast()->once()
|
||||||
->andReturn([]);
|
->andReturn([]);
|
||||||
|
|
||||||
|
@@ -107,11 +107,12 @@ class MigrateToRulesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testHandleEvenBill(): void
|
public function testHandleEvenBill(): void
|
||||||
{
|
{
|
||||||
$bill = Bill::create(
|
$billName = 'I am a bill #' . $this->randomInt();
|
||||||
|
$bill = Bill::create(
|
||||||
[
|
[
|
||||||
'user_id' => $this->user()->id,
|
'user_id' => $this->user()->id,
|
||||||
'transaction_currency_id' => null,
|
'transaction_currency_id' => null,
|
||||||
'name' => 'I am a bill',
|
'name' => $billName,
|
||||||
'match' => 'some,kind,of,match',
|
'match' => 'some,kind,of,match',
|
||||||
'amount_min' => '30',
|
'amount_min' => '30',
|
||||||
'amount_max' => '30',
|
'amount_max' => '30',
|
||||||
@@ -137,8 +138,8 @@ class MigrateToRulesTest extends TestCase
|
|||||||
'active' => true,
|
'active' => true,
|
||||||
'strict' => false,
|
'strict' => false,
|
||||||
'stop_processing' => false, // field is no longer used.
|
'stop_processing' => false, // field is no longer used.
|
||||||
'title' => 'Auto-generated rule for bill "I am a bill"',
|
'title' => sprintf('Auto-generated rule for bill "%s"', $billName),
|
||||||
'description' => 'This rule is auto-generated to try to match bill "I am a bill".',
|
'description' => sprintf('This rule is auto-generated to try to match bill "%s".', $billName),
|
||||||
'trigger' => 'store-journal',
|
'trigger' => 'store-journal',
|
||||||
'triggers' => [
|
'triggers' => [
|
||||||
[
|
[
|
||||||
@@ -214,11 +215,12 @@ class MigrateToRulesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testHandleUnevenBill(): void
|
public function testHandleUnevenBill(): void
|
||||||
{
|
{
|
||||||
$bill = Bill::create(
|
$billName = 'I am a bill #' . $this->randomInt();
|
||||||
|
$bill = Bill::create(
|
||||||
[
|
[
|
||||||
'user_id' => $this->user()->id,
|
'user_id' => $this->user()->id,
|
||||||
'transaction_currency_id' => null,
|
'transaction_currency_id' => null,
|
||||||
'name' => 'I am a bill',
|
'name' => $billName,
|
||||||
'match' => 'some,kind,of,match',
|
'match' => 'some,kind,of,match',
|
||||||
'amount_min' => '30',
|
'amount_min' => '30',
|
||||||
'amount_max' => '40',
|
'amount_max' => '40',
|
||||||
@@ -244,8 +246,8 @@ class MigrateToRulesTest extends TestCase
|
|||||||
'active' => true,
|
'active' => true,
|
||||||
'strict' => false,
|
'strict' => false,
|
||||||
'stop_processing' => false, // field is no longer used.
|
'stop_processing' => false, // field is no longer used.
|
||||||
'title' => 'Auto-generated rule for bill "I am a bill"',
|
'title' => sprintf('Auto-generated rule for bill "%s"', $billName),
|
||||||
'description' => 'This rule is auto-generated to try to match bill "I am a bill".',
|
'description' => sprintf('This rule is auto-generated to try to match bill "%s".', $billName),
|
||||||
'trigger' => 'store-journal',
|
'trigger' => 'store-journal',
|
||||||
'triggers' => [
|
'triggers' => [
|
||||||
[
|
[
|
||||||
|
@@ -26,6 +26,7 @@ use FireflyConfig;
|
|||||||
use FireflyIII\Models\Configuration;
|
use FireflyIII\Models\Configuration;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -54,9 +55,9 @@ class TransactionIdentifierTest extends TestCase
|
|||||||
{
|
{
|
||||||
// mock classes:
|
// mock classes:
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
|
||||||
// commands:
|
// commands:
|
||||||
$journalRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
|
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
|
||||||
->atLeast()->once();
|
->atLeast()->once();
|
||||||
|
|
||||||
// configuration
|
// configuration
|
||||||
@@ -127,9 +128,9 @@ class TransactionIdentifierTest extends TestCase
|
|||||||
|
|
||||||
// mock classes:
|
// mock classes:
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
|
||||||
// commands:
|
// commands:
|
||||||
$journalRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
|
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
|
||||||
->atLeast()->once();
|
->atLeast()->once();
|
||||||
|
|
||||||
// configuration
|
// configuration
|
||||||
|
Reference in New Issue
Block a user