diff --git a/app/Events/RequestedReportOnJournals.php b/app/Events/RequestedReportOnJournals.php index b02b29d3ff..0e29b88ea7 100644 --- a/app/Events/RequestedReportOnJournals.php +++ b/app/Events/RequestedReportOnJournals.php @@ -55,7 +55,7 @@ class RequestedReportOnJournals public function __construct(int $userId, Collection $groups) { Log::debug('In event RequestedReportOnJournals.'); - $this->userId = $userId; + $this->userId = $userId; $this->groups = $groups; } diff --git a/app/Exceptions/DuplicateTransactionException.php b/app/Exceptions/DuplicateTransactionException.php index 322916860f..2b607ec9a9 100644 --- a/app/Exceptions/DuplicateTransactionException.php +++ b/app/Exceptions/DuplicateTransactionException.php @@ -20,6 +20,7 @@ */ namespace FireflyIII\Exceptions; + use Exception; /** @@ -27,5 +28,4 @@ use Exception; */ class DuplicateTransactionException extends Exception { - -} \ No newline at end of file +} diff --git a/app/Exceptions/FireflyException.php b/app/Exceptions/FireflyException.php index 5ef1449452..33aa8cad85 100644 --- a/app/Exceptions/FireflyException.php +++ b/app/Exceptions/FireflyException.php @@ -28,6 +28,7 @@ use Exception; /** * Class FireflyException. + * * @codeCoverageIgnore */ class FireflyException extends Exception diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.php index a59de42168..6c4ed1d45a 100644 --- a/app/Exceptions/GracefulNotFoundHandler.php +++ b/app/Exceptions/GracefulNotFoundHandler.php @@ -33,8 +33,11 @@ use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; use FireflyIII\User; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Log; +use Symfony\Component\HttpFoundation\Response; /** * Class GracefulNotFoundHandler @@ -134,7 +137,7 @@ class GracefulNotFoundHandler extends ExceptionHandler * @param Request $request * @param Exception $exception * - * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response + * @return \Illuminate\Http\Response|Response */ private function handleAccount($request, Exception $exception) { @@ -142,7 +145,7 @@ class GracefulNotFoundHandler extends ExceptionHandler /** @var User $user */ $user = auth()->user(); $route = $request->route(); - $accountId = (int)$route->parameter('account'); + $accountId = (int) $route->parameter('account'); /** @var Account $account */ $account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId); if (null === $account) { @@ -163,7 +166,7 @@ class GracefulNotFoundHandler extends ExceptionHandler /** @var User $user */ $user = auth()->user(); $route = $request->route(); - $attachmentId = (int)$route->parameter('attachment'); + $attachmentId = (int) $route->parameter('attachment'); /** @var Attachment $attachment */ $attachment = $user->attachments()->withTrashed()->find($attachmentId); if (null === $attachment) { @@ -199,7 +202,7 @@ class GracefulNotFoundHandler extends ExceptionHandler * @param $request * @param Exception $exception * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector|\Symfony\Component\HttpFoundation\Response + * @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response */ private function handleGroup($request, Exception $exception) { @@ -207,7 +210,7 @@ class GracefulNotFoundHandler extends ExceptionHandler /** @var User $user */ $user = auth()->user(); $route = $request->route(); - $groupId = (int)$route->parameter('transactionGroup'); + $groupId = (int) $route->parameter('transactionGroup'); /** @var TransactionGroup $group */ $group = $user->transactionGroups()->withTrashed()->find($groupId); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 384b5b4999..e079322857 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -82,15 +82,17 @@ class Handler extends ExceptionHandler 'line' => $exception->getLine(), 'file' => $exception->getFile(), 'trace' => $exception->getTrace(), - ], 500 + ], + 500 ); } return response()->json(['message' => 'Internal Firefly III Exception. See log files.', 'exception' => get_class($exception)], 500); } - if($exception instanceof NotFoundHttpException) { + if ($exception instanceof NotFoundHttpException) { $handler = app(GracefulNotFoundHandler::class); + return $handler->render($request, $exception); } @@ -113,13 +115,12 @@ class Handler extends ExceptionHandler * * @param Exception $exception * + * @throws Exception * @return mixed|void * - * @throws Exception */ public function report(Exception $exception) { - $doMailError = config('firefly.send_error_message'); // if the user wants us to mail: if (true === $doMailError @@ -149,7 +150,7 @@ class Handler extends ExceptionHandler // create job that will mail. $ipAddress = Request::ip() ?? '0.0.0.0'; - $job = new MailError($userData, (string)config('firefly.site_owner'), $ipAddress, $data); + $job = new MailError($userData, (string) config('firefly.site_owner'), $ipAddress, $data); dispatch($job); } diff --git a/app/Exceptions/NotImplementedException.php b/app/Exceptions/NotImplementedException.php index 2e95fce8fd..3bcf0c42d0 100644 --- a/app/Exceptions/NotImplementedException.php +++ b/app/Exceptions/NotImplementedException.php @@ -28,6 +28,7 @@ use Exception; /** * Class NotImplementedException. + * * @codeCoverageIgnore */ class NotImplementedException extends Exception diff --git a/app/Exceptions/ValidationException.php b/app/Exceptions/ValidationException.php index 9a010098ae..cc3b45fb21 100644 --- a/app/Exceptions/ValidationException.php +++ b/app/Exceptions/ValidationException.php @@ -28,6 +28,7 @@ use Exception; /** * Class ValidationExceptions. + * * @codeCoverageIgnore */ class ValidationException extends Exception diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php index e572e3a1ec..86c324f8ed 100644 --- a/app/Factory/AccountFactory.php +++ b/app/Factory/AccountFactory.php @@ -27,7 +27,6 @@ namespace FireflyIII\Factory; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; -use FireflyIII\Models\Location; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Services\Internal\Support\AccountServiceTrait; use FireflyIII\Services\Internal\Support\LocationServiceTrait; @@ -45,18 +44,16 @@ class AccountFactory /** @var AccountRepositoryInterface */ protected $accountRepository; - /** @var User */ - private $user; - - /** @var array */ - private $canHaveVirtual; - /** @var array */ protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth']; /** @var array */ protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth']; /** @var array */ protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth']; + /** @var array */ + private $canHaveVirtual; + /** @var User */ + private $user; /** * AccountFactory constructor. @@ -75,8 +72,8 @@ class AccountFactory /** * @param array $data * - * @return Account * @throws FireflyException + * @return Account */ public function create(array $data): Account { @@ -106,7 +103,7 @@ class AccountFactory 'iban' => $data['iban'], ]; - $currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null)); + $currency = $this->getCurrency((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null)); unset($data['currency_code']); $data['currency_id'] = $currency->id; @@ -159,8 +156,8 @@ class AccountFactory * @param string $accountName * @param string $accountType * - * @return Account * @throws FireflyException + * @return Account */ public function findOrCreate(string $accountName, string $accountType): Account { @@ -197,7 +194,7 @@ class AccountFactory } /** - * @param int|null $accountTypeId + * @param int|null $accountTypeId * @param null|string $accountType * * @return AccountType|null @@ -205,7 +202,7 @@ class AccountFactory */ protected function getAccountType(?int $accountTypeId, ?string $accountType): ?AccountType { - $accountTypeId = (int)$accountTypeId; + $accountTypeId = (int) $accountTypeId; $result = null; if ($accountTypeId > 0) { $result = AccountType::find($accountTypeId); diff --git a/app/Factory/AccountMetaFactory.php b/app/Factory/AccountMetaFactory.php index c88239511c..de6c2fe317 100644 --- a/app/Factory/AccountMetaFactory.php +++ b/app/Factory/AccountMetaFactory.php @@ -36,6 +36,7 @@ class AccountMetaFactory { /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() diff --git a/app/Factory/AttachmentFactory.php b/app/Factory/AttachmentFactory.php index bf4c225768..22c1d66e15 100644 --- a/app/Factory/AttachmentFactory.php +++ b/app/Factory/AttachmentFactory.php @@ -41,6 +41,7 @@ class AttachmentFactory /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -53,8 +54,8 @@ class AttachmentFactory /** * @param array $data * - * @return Attachment|null * @throws FireflyException + * @return Attachment|null */ public function create(array $data): ?Attachment { @@ -64,7 +65,7 @@ class AttachmentFactory // get journal instead of transaction. if (Transaction::class === $model) { /** @var Transaction $transaction */ - $transaction = $this->user->transactions()->find((int)$data['model_id']); + $transaction = $this->user->transactions()->find((int) $data['model_id']); if (null === $transaction) { throw new FireflyException('Unexpectedly could not find transaction'); // @codeCoverageIgnore } @@ -87,7 +88,7 @@ class AttachmentFactory 'uploaded' => 0, ] ); - $notes = (string)($data['notes'] ?? ''); + $notes = (string) ($data['notes'] ?? ''); if ('' !== $notes) { $note = new Note; $note->noteable()->associate($attachment); diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php index f347dbafce..79647a75e3 100644 --- a/app/Factory/BillFactory.php +++ b/app/Factory/BillFactory.php @@ -44,6 +44,7 @@ class BillFactory /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -56,15 +57,15 @@ class BillFactory /** * @param array $data * - * @return Bill|null * @throws FireflyException + * @return Bill|null */ public function create(array $data): ?Bill { /** @var TransactionCurrencyFactory $factory */ $factory = app(TransactionCurrencyFactory::class); /** @var TransactionCurrency $currency */ - $currency = $factory->find((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null)); + $currency = $factory->find((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null)); if (null === $currency) { $currency = app('amount')->getDefaultCurrencyByUser($this->user); @@ -86,7 +87,7 @@ class BillFactory 'active' => $data['active'] ?? true, ] ); - } catch(QueryException $e) { + } catch (QueryException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); throw new FireflyException('400000: Could not store bill.'); @@ -100,15 +101,15 @@ class BillFactory } /** - * @param int|null $billId + * @param int|null $billId * @param null|string $billName * * @return Bill|null */ public function find(?int $billId, ?string $billName): ?Bill { - $billId = (int)$billId; - $billName = (string)$billName; + $billId = (int) $billId; + $billName = (string) $billName; $bill = null; // first find by ID: if ($billId > 0) { diff --git a/app/Factory/BudgetFactory.php b/app/Factory/BudgetFactory.php index f91da72d5a..ce6f9923d1 100644 --- a/app/Factory/BudgetFactory.php +++ b/app/Factory/BudgetFactory.php @@ -38,6 +38,7 @@ class BudgetFactory /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -56,8 +57,8 @@ class BudgetFactory */ public function find(?int $budgetId, ?string $budgetName): ?Budget { - $budgetId = (int)$budgetId; - $budgetName = (string)$budgetName; + $budgetId = (int) $budgetId; + $budgetName = (string) $budgetName; if (0 === $budgetId && '' === $budgetName) { return null; diff --git a/app/Factory/CategoryFactory.php b/app/Factory/CategoryFactory.php index 90c6d65213..da55ff6cde 100644 --- a/app/Factory/CategoryFactory.php +++ b/app/Factory/CategoryFactory.php @@ -40,6 +40,7 @@ class CategoryFactory /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -63,13 +64,13 @@ class CategoryFactory * @param int|null $categoryId * @param null|string $categoryName * - * @return Category|null * @throws FireflyException + * @return Category|null */ public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category { - $categoryId = (int)$categoryId; - $categoryName = (string)$categoryName; + $categoryId = (int) $categoryId; + $categoryName = (string) $categoryName; Log::debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName)); diff --git a/app/Factory/PiggyBankEventFactory.php b/app/Factory/PiggyBankEventFactory.php index ffe8bd35c3..3eee4e3019 100644 --- a/app/Factory/PiggyBankEventFactory.php +++ b/app/Factory/PiggyBankEventFactory.php @@ -39,6 +39,7 @@ class PiggyBankEventFactory { /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -60,6 +61,7 @@ class PiggyBankEventFactory Log::debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type)); if (null === $piggyBank) { Log::debug('Piggy bank is null'); + return null; } diff --git a/app/Factory/PiggyBankFactory.php b/app/Factory/PiggyBankFactory.php index b53412c11d..0a67e45240 100644 --- a/app/Factory/PiggyBankFactory.php +++ b/app/Factory/PiggyBankFactory.php @@ -38,6 +38,7 @@ class PiggyBankFactory /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -56,8 +57,8 @@ class PiggyBankFactory */ public function find(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank { - $piggyBankId = (int)$piggyBankId; - $piggyBankName = (string)$piggyBankName; + $piggyBankId = (int) $piggyBankId; + $piggyBankName = (string) $piggyBankName; if ('' === $piggyBankName && 0 === $piggyBankId) { return null; } diff --git a/app/Factory/RecurrenceFactory.php b/app/Factory/RecurrenceFactory.php index 9ce038bd52..c406845313 100644 --- a/app/Factory/RecurrenceFactory.php +++ b/app/Factory/RecurrenceFactory.php @@ -39,16 +39,16 @@ use Log; */ class RecurrenceFactory { - /** @var User */ - private $user; - /** @var MessageBag */ private $errors; + /** @var User */ + private $user; use TransactionTypeTrait, RecurringTransactionTrait; /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -62,8 +62,8 @@ class RecurrenceFactory /** * @param array $data * - * @return Recurrence * @throws FireflyException + * @return Recurrence */ public function create(array $data): Recurrence { @@ -79,7 +79,7 @@ class RecurrenceFactory /** @var Carbon $firstDate */ $firstDate = $data['recurrence']['first_date']; - $repetitions = (int)$data['recurrence']['repetitions']; + $repetitions = (int) $data['recurrence']['repetitions']; $recurrence = new Recurrence( [ 'user_id' => $this->user->id, diff --git a/app/Factory/TagFactory.php b/app/Factory/TagFactory.php index 70e277fe60..8e8cdaf409 100644 --- a/app/Factory/TagFactory.php +++ b/app/Factory/TagFactory.php @@ -42,6 +42,7 @@ class TagFactory /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -58,9 +59,9 @@ class TagFactory */ public function create(array $data): ?Tag { - $zoomLevel = 0 === (int)$data['zoom_level'] ? null : (int)$data['zoom_level']; - $latitude = 0.0 === (float)$data['latitude'] ? null : (float)$data['latitude']; - $longitude = 0.0 === (float)$data['longitude'] ? null : (float)$data['longitude']; + $zoomLevel = 0 === (int) $data['zoom_level'] ? null : (int) $data['zoom_level']; + $latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude']; + $longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude']; $array = [ 'user_id' => $this->user->id, 'tag' => trim($data['tag']), diff --git a/app/Factory/TransactionCurrencyFactory.php b/app/Factory/TransactionCurrencyFactory.php index 8ae56ef91b..bd6a74ef73 100644 --- a/app/Factory/TransactionCurrencyFactory.php +++ b/app/Factory/TransactionCurrencyFactory.php @@ -52,8 +52,8 @@ class TransactionCurrencyFactory /** * @param array $data * - * @return TransactionCurrency * @throws FireflyException + * @return TransactionCurrency */ public function create(array $data): TransactionCurrency { @@ -86,8 +86,8 @@ class TransactionCurrencyFactory */ public function find(?int $currencyId, ?string $currencyCode): ?TransactionCurrency { - $currencyCode = (string)$currencyCode; - $currencyId = (int)$currencyId; + $currencyCode = (string) $currencyCode; + $currencyId = (int) $currencyId; if ('' === $currencyCode && 0 === $currencyId) { Log::debug('Cannot find anything on empty currency code and empty currency ID!'); diff --git a/app/Factory/TransactionFactory.php b/app/Factory/TransactionFactory.php index a601499a54..4ede4f858d 100644 --- a/app/Factory/TransactionFactory.php +++ b/app/Factory/TransactionFactory.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Factory; - use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\Transaction; @@ -39,21 +38,22 @@ use Log; */ class TransactionFactory { - /** @var TransactionJournal */ - private $journal; /** @var Account */ private $account; /** @var TransactionCurrency */ private $currency; /** @var TransactionCurrency */ private $foreignCurrency; - /** @var User */ - private $user; + /** @var TransactionJournal */ + private $journal; /** @var bool */ private $reconciled; + /** @var User */ + private $user; /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -64,50 +64,14 @@ class TransactionFactory $this->reconciled = false; } - /** - * @param bool $reconciled - * @codeCoverageIgnore - */ - public function setReconciled(bool $reconciled): void - { - $this->reconciled = $reconciled; - } - - /** - * @param Account $account - * @codeCoverageIgnore - */ - public function setAccount(Account $account): void - { - $this->account = $account; - } - - /** - * @param TransactionCurrency $currency - * @codeCoverageIgnore - */ - public function setCurrency(TransactionCurrency $currency): void - { - $this->currency = $currency; - } - - /** - * @param TransactionCurrency $foreignCurrency |null - * @codeCoverageIgnore - */ - public function setForeignCurrency(?TransactionCurrency $foreignCurrency): void - { - $this->foreignCurrency = $foreignCurrency; - } - /** * Create transaction with negative amount (for source accounts). * * @param string $amount * @param string|null $foreignAmount * - * @return Transaction * @throws FireflyException + * @return Transaction */ public function createNegative(string $amount, ?string $foreignAmount): Transaction { @@ -127,8 +91,8 @@ class TransactionFactory * @param string $amount * @param string|null $foreignAmount * - * @return Transaction * @throws FireflyException + * @return Transaction */ public function createPositive(string $amount, ?string $foreignAmount): Transaction { @@ -138,12 +102,43 @@ class TransactionFactory if (null !== $foreignAmount) { $foreignAmount = app('steam')->positive($foreignAmount); } + return $this->create(app('steam')->positive($amount), $foreignAmount); } + /** + * @param Account $account + * + * @codeCoverageIgnore + */ + public function setAccount(Account $account): void + { + $this->account = $account; + } + + /** + * @param TransactionCurrency $currency + * + * @codeCoverageIgnore + */ + public function setCurrency(TransactionCurrency $currency): void + { + $this->currency = $currency; + } + + /** + * @param TransactionCurrency $foreignCurrency |null + * + * @codeCoverageIgnore + */ + public function setForeignCurrency(?TransactionCurrency $foreignCurrency): void + { + $this->foreignCurrency = $foreignCurrency; + } /** * @param TransactionJournal $journal + * * @codeCoverageIgnore */ public function setJournal(TransactionJournal $journal): void @@ -151,8 +146,19 @@ class TransactionFactory $this->journal = $journal; } + /** + * @param bool $reconciled + * + * @codeCoverageIgnore + */ + public function setReconciled(bool $reconciled): void + { + $this->reconciled = $reconciled; + } + /** * @param User $user + * * @codeCoverageIgnore */ public function setUser(User $user): void @@ -164,8 +170,8 @@ class TransactionFactory * @param string $amount * @param string|null $foreignAmount * - * @return Transaction * @throws FireflyException + * @return Transaction */ private function create(string $amount, ?string $foreignAmount): Transaction { @@ -200,7 +206,11 @@ class TransactionFactory if (null !== $result) { Log::debug( sprintf( - 'Created transaction #%d (%s %s, account %s), part of journal #%d', $result->id, $this->currency->code, $amount, $this->account->name, + 'Created transaction #%d (%s %s, account %s), part of journal #%d', + $result->id, + $this->currency->code, + $amount, + $this->account->name, $this->journal->id ) ); @@ -209,7 +219,6 @@ class TransactionFactory if (null !== $this->foreignCurrency && null !== $foreignAmount && $this->foreignCurrency->id !== $this->currency->id && '' !== $foreignAmount) { $result->foreign_currency_id = $this->foreignCurrency->id; $result->foreign_amount = $foreignAmount; - } $result->save(); } diff --git a/app/Factory/TransactionGroupFactory.php b/app/Factory/TransactionGroupFactory.php index 045cdec5e4..34d5a2db8d 100644 --- a/app/Factory/TransactionGroupFactory.php +++ b/app/Factory/TransactionGroupFactory.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Factory; use FireflyIII\Exceptions\DuplicateTransactionException; -use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionGroup; use FireflyIII\User; use Log; @@ -54,8 +53,8 @@ class TransactionGroupFactory * * @param array $data * - * @return TransactionGroup * @throws DuplicateTransactionException + * @return TransactionGroup */ public function create(array $data): TransactionGroup { @@ -63,12 +62,12 @@ class TransactionGroupFactory $this->journalFactory->setErrorOnHash($data['error_if_duplicate_hash'] ?? false); try { $collection = $this->journalFactory->create($data); - } catch(DuplicateTransactionException $e) { + } catch (DuplicateTransactionException $e) { Log::warning('GroupFactory::create() caught journalFactory::create() with a duplicate!'); throw new DuplicateTransactionException($e->getMessage()); } - $title = $data['group_title'] ?? null; - $title = '' === $title ? null : $title; + $title = $data['group_title'] ?? null; + $title = '' === $title ? null : $title; if (null !== $title) { $title = substr($title, 0, 1000); diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php index b0a855b190..5326a64b32 100644 --- a/app/Factory/TransactionJournalFactory.php +++ b/app/Factory/TransactionJournalFactory.php @@ -64,6 +64,8 @@ class TransactionJournalFactory private $billRepository; /** @var CurrencyRepositoryInterface */ private $currencyRepository; + /** @var bool */ + private $errorOnHash; /** @var array */ private $fields; /** @var PiggyBankEventFactory */ @@ -76,8 +78,6 @@ class TransactionJournalFactory private $typeRepository; /** @var User The user */ private $user; - /** @var bool */ - private $errorOnHash; /** * Constructor. @@ -125,9 +125,9 @@ class TransactionJournalFactory * * @param array $data * - * @return Collection * @throws DuplicateTransactionException * @throws FireflyException + * @return Collection */ public function create(array $data): Collection { @@ -171,6 +171,17 @@ class TransactionJournalFactory return $collection; } + /** + * @param bool $errorOnHash + */ + public function setErrorOnHash(bool $errorOnHash): void + { + $this->errorOnHash = $errorOnHash; + if (true === $errorOnHash) { + Log::info('Will trigger duplication alert for this journal.'); + } + } + /** * Set the user. * @@ -199,7 +210,7 @@ class TransactionJournalFactory $set = [ 'journal' => $journal, 'name' => $field, - 'data' => (string)($data[$field] ?? ''), + 'data' => (string) ($data[$field] ?? ''), ]; Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data'])); @@ -212,9 +223,9 @@ class TransactionJournalFactory /** * @param NullArrayObject $row * - * @return TransactionJournal|null * @throws FireflyException * @throws DuplicateTransactionException + * @return TransactionJournal|null */ private function createJournal(NullArrayObject $row): ?TransactionJournal { @@ -226,11 +237,11 @@ class TransactionJournalFactory $type = $this->typeRepository->findTransactionType(null, $row['type']); $carbon = $row['date'] ?? new Carbon; $order = $row['order'] ?? 0; - $currency = $this->currencyRepository->findCurrency((int)$row['currency_id'], $row['currency_code']); + $currency = $this->currencyRepository->findCurrency((int) $row['currency_id'], $row['currency_code']); $foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']); - $bill = $this->billRepository->findBill((int)$row['bill_id'], $row['bill_name']); + $bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']); $billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null; - $description = app('steam')->cleanString((string)$row['description']); + $description = app('steam')->cleanString((string) $row['description']); /** Manipulate basic fields */ $carbon->setTimezone(config('app.timezone')); @@ -249,7 +260,7 @@ class TransactionJournalFactory } /** create or get source and destination accounts */ $sourceInfo = [ - 'id' => (int)$row['source_id'], + 'id' => (int) $row['source_id'], 'name' => $row['source_name'], 'iban' => $row['source_iban'], 'number' => $row['source_number'], @@ -257,7 +268,7 @@ class TransactionJournalFactory ]; $destInfo = [ - 'id' => (int)$row['destination_id'], + 'id' => (int) $row['destination_id'], 'name' => $row['destination_name'], 'iban' => $row['destination_iban'], 'number' => $row['destination_number'], @@ -325,7 +336,7 @@ class TransactionJournalFactory 'transaction_type_id' => $type->id, 'bill_id' => $billId, 'transaction_currency_id' => $currency->id, - 'description' => substr($description,0,1000), + 'description' => substr($description, 0, 1000), 'date' => $carbon->format('Y-m-d H:i:s'), 'order' => $order, 'tag_count' => 0, @@ -344,7 +355,7 @@ class TransactionJournalFactory $transactionFactory->setForeignCurrency($sourceForeignCurrency); $transactionFactory->setReconciled($row['reconciled'] ?? false); try { - $negative = $transactionFactory->createNegative((string)$row['amount'], (string)$row['foreign_amount']); + $negative = $transactionFactory->createNegative((string) $row['amount'], (string) $row['foreign_amount']); } catch (FireflyException $e) { Log::error('Exception creating negative transaction.'); Log::error($e->getMessage()); @@ -363,7 +374,7 @@ class TransactionJournalFactory $transactionFactory->setForeignCurrency($destForeignCurrency); $transactionFactory->setReconciled($row['reconciled'] ?? false); try { - $transactionFactory->createPositive((string)$row['amount'], (string)$row['foreign_amount']); + $transactionFactory->createPositive((string) $row['amount'], (string) $row['foreign_amount']); } catch (FireflyException $e) { Log::error('Exception creating positive transaction.'); Log::error($e->getMessage()); @@ -506,7 +517,7 @@ class TransactionJournalFactory $json = json_encode($dataRow); if (false === $json) { // @codeCoverageIgnoreStart - $json = json_encode((string)microtime()); + $json = json_encode((string) microtime()); Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow); // @codeCoverageIgnoreEnd } @@ -542,7 +553,7 @@ class TransactionJournalFactory return; } - $piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']); + $piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']); if (null !== $piggyBank) { $this->piggyEventFactory->create($journal, $piggyBank); @@ -565,7 +576,7 @@ class TransactionJournalFactory $this->accountValidator->setTransactionType($transactionType); // validate source account. - $sourceId = isset($data['source_id']) ? (int)$data['source_id'] : null; + $sourceId = isset($data['source_id']) ? (int) $data['source_id'] : null; $sourceName = $data['source_name'] ?? null; $validSource = $this->accountValidator->validateSource($sourceId, $sourceName); @@ -575,7 +586,7 @@ class TransactionJournalFactory } Log::debug('Source seems valid.'); // validate destination account - $destinationId = isset($data['destination_id']) ? (int)$data['destination_id'] : null; + $destinationId = isset($data['destination_id']) ? (int) $data['destination_id'] : null; $destinationName = $data['destination_name'] ?? null; $validDestination = $this->accountValidator->validateDestination($destinationId, $destinationName); // do something with result: @@ -584,16 +595,5 @@ class TransactionJournalFactory } } - /** - * @param bool $errorOnHash - */ - public function setErrorOnHash(bool $errorOnHash): void - { - $this->errorOnHash = $errorOnHash; - if (true === $errorOnHash) { - Log::info('Will trigger duplication alert for this journal.'); - } - } - } diff --git a/app/Factory/TransactionJournalMetaFactory.php b/app/Factory/TransactionJournalMetaFactory.php index 6e696196e4..88b0059749 100644 --- a/app/Factory/TransactionJournalMetaFactory.php +++ b/app/Factory/TransactionJournalMetaFactory.php @@ -36,6 +36,7 @@ class TransactionJournalMetaFactory { /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -71,7 +72,7 @@ class TransactionJournalMetaFactory Log::debug('Is a carbon object.'); $value = $data['data']->toW3cString(); } - if ('' === (string)$value) { + if ('' === (string) $value) { Log::debug('Is an empty string.'); // don't store blank strings. if (null !== $entry) { diff --git a/app/Factory/TransactionTypeFactory.php b/app/Factory/TransactionTypeFactory.php index eb509e1dda..45b0414c94 100644 --- a/app/Factory/TransactionTypeFactory.php +++ b/app/Factory/TransactionTypeFactory.php @@ -35,6 +35,7 @@ class TransactionTypeFactory { /** * Constructor. + * * @codeCoverageIgnore */ public function __construct() diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php index 6a8e160dcd..943ef66e5f 100644 --- a/app/Generator/Chart/Basic/ChartJsGenerator.php +++ b/app/Generator/Chart/Basic/ChartJsGenerator.php @@ -63,7 +63,7 @@ class ChartJsGenerator implements GeneratorInterface $amounts = array_column($data, 'amount'); $next = next($amounts); $sortFlag = SORT_ASC; - if (!is_bool($next) && 1 === bccomp((string)$next, '0')) { + if (!is_bool($next) && 1 === bccomp((string) $next, '0')) { $sortFlag = SORT_DESC; } array_multisort($amounts, $sortFlag, $data); @@ -72,7 +72,7 @@ class ChartJsGenerator implements GeneratorInterface $index = 0; foreach ($data as $key => $valueArray) { // make larger than 0 - $chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$valueArray['amount']); + $chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $valueArray['amount']); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['datasets'][0]['currency_symbol'][] = $valueArray['currency_symbol']; $chartData['labels'][] = $key; @@ -178,7 +178,7 @@ class ChartJsGenerator implements GeneratorInterface // different sort when values are positive and when they're negative. asort($data); $next = next($data); - if (!is_bool($next) && 1 === bccomp((string)$next, '0')) { + if (!is_bool($next) && 1 === bccomp((string) $next, '0')) { // next is positive, sort other way around. arsort($data); } @@ -187,7 +187,7 @@ class ChartJsGenerator implements GeneratorInterface $index = 0; foreach ($data as $key => $value) { // make larger than 0 - $chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$value); + $chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $value); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['labels'][] = $key; diff --git a/app/Generator/Report/Account/MonthReportGenerator.php b/app/Generator/Report/Account/MonthReportGenerator.php index d4538afee6..34c7c63b74 100644 --- a/app/Generator/Report/Account/MonthReportGenerator.php +++ b/app/Generator/Report/Account/MonthReportGenerator.php @@ -52,14 +52,14 @@ class MonthReportGenerator implements ReportGeneratorInterface public function generate(): string { $accountIds = implode(',', $this->accounts->pluck('id')->toArray()); - $doubleIds = implode(',', $this->expense->pluck('id')->toArray()); + $doubleIds = implode(',', $this->expense->pluck('id')->toArray()); $reportType = 'account'; $preferredPeriod = $this->preferredPeriod(); try { $result = view('reports.double.report', compact('accountIds', 'reportType', 'doubleIds', 'preferredPeriod')) ->with('start', $this->start)->with('end', $this->end) - ->with('doubles', $this->expense) - ->render(); + ->with('doubles', $this->expense) + ->render(); } catch (Throwable $e) { Log::error(sprintf('Cannot render reports.double.report: %s', $e->getMessage())); $result = sprintf('Could not render report view: %s', $e->getMessage()); diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php index e35e46b570..55757386c3 100644 --- a/app/Generator/Report/Audit/MonthReportGenerator.php +++ b/app/Generator/Report/Audit/MonthReportGenerator.php @@ -51,9 +51,9 @@ class MonthReportGenerator implements ReportGeneratorInterface /** * Generates the report. * - * @return string * @throws FireflyException * @codeCoverageIgnore + * @return string */ public function generate(): string { @@ -100,9 +100,9 @@ class MonthReportGenerator implements ReportGeneratorInterface * @param Account $account * @param Carbon $date * + * @throws FireflyException * @return array * - * @throws FireflyException */ public function getAuditReport(Account $account, Carbon $date): array { @@ -117,7 +117,7 @@ class MonthReportGenerator implements ReportGeneratorInterface /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation() - ->withBudgetInformation()->withCategoryInformation()->withBillInformation(); + ->withBudgetInformation()->withCategoryInformation()->withBillInformation(); $journals = $collector->getExtractedJournals(); $journals = array_reverse($journals, true); $dayBeforeBalance = app('steam')->balance($account, $date); @@ -159,9 +159,9 @@ class MonthReportGenerator implements ReportGeneratorInterface 'journals' => $journals, 'currency' => $currency, 'exists' => count($journals) > 0, - 'end' => $this->end->formatLocalized((string)trans('config.month_and_day')), + 'end' => $this->end->formatLocalized((string) trans('config.month_and_day')), 'endBalance' => app('steam')->balance($account, $this->end), - 'dayBefore' => $date->formatLocalized((string)trans('config.month_and_day')), + 'dayBefore' => $date->formatLocalized((string) trans('config.month_and_day')), 'dayBeforeBalance' => $dayBeforeBalance, ]; diff --git a/app/Generator/Report/Category/MonthReportGenerator.php b/app/Generator/Report/Category/MonthReportGenerator.php index 4836354b38..1bc8be9b89 100644 --- a/app/Generator/Report/Category/MonthReportGenerator.php +++ b/app/Generator/Report/Category/MonthReportGenerator.php @@ -76,7 +76,7 @@ class MonthReportGenerator implements ReportGeneratorInterface // render! try { - return view('reports.category.month', compact('accountIds', 'categoryIds', 'reportType',)) + return view('reports.category.month', compact('accountIds', 'categoryIds', 'reportType', )) ->with('start', $this->start)->with('end', $this->end) ->with('categories', $this->categories) ->with('accounts', $this->accounts) diff --git a/app/Generator/Report/ReportGeneratorFactory.php b/app/Generator/Report/ReportGeneratorFactory.php index ceeb641a0f..011cf97fc1 100644 --- a/app/Generator/Report/ReportGeneratorFactory.php +++ b/app/Generator/Report/ReportGeneratorFactory.php @@ -39,9 +39,9 @@ class ReportGeneratorFactory * @param Carbon $start * @param Carbon $end * + * @throws FireflyException * @return ReportGeneratorInterface * - * @throws FireflyException */ public static function reportGenerator(string $type, Carbon $start, Carbon $end): ReportGeneratorInterface { diff --git a/app/Generator/Report/Tag/MonthReportGenerator.php b/app/Generator/Report/Tag/MonthReportGenerator.php index 54784d10e7..c7b6b32a60 100644 --- a/app/Generator/Report/Tag/MonthReportGenerator.php +++ b/app/Generator/Report/Tag/MonthReportGenerator.php @@ -76,7 +76,8 @@ class MonthReportGenerator implements ReportGeneratorInterface // render! try { $result = view( - 'reports.tag.month', compact('accountIds', 'reportType', 'tagIds') + 'reports.tag.month', + compact('accountIds', 'reportType', 'tagIds') )->with('start', $this->start)->with('end', $this->end)->with('tags', $this->tags)->with('accounts', $this->accounts)->render(); } catch (Throwable $e) { Log::error(sprintf('Cannot render reports.tag.month: %s', $e->getMessage())); @@ -177,6 +178,4 @@ class MonthReportGenerator implements ReportGeneratorInterface return $this; } - - } diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 410f0a7519..ce4149c5a0 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -58,10 +58,12 @@ class GroupCollector implements GroupCollectorInterface private $hasBudgetInformation; /** @var bool Will be true if query result contains category info. */ private $hasCatInformation; - /** @var bool Will be true of the query has the tag info tables joined. */ - private $hasJoinedTagTables; /** @var bool Will be true for attachments */ private $hasJoinedAttTables; + /** @var bool Will be true of the query has the tag info tables joined. */ + private $hasJoinedTagTables; + /** @var array */ + private $integerFields; /** @var int The maximum number of results. */ private $limit; /** @var int The page to return. */ @@ -72,8 +74,6 @@ class GroupCollector implements GroupCollectorInterface private $total; /** @var User The user object. */ private $user; - /** @var array */ - private $integerFields; /** * Group collector constructor. @@ -210,7 +210,6 @@ class GroupCollector implements GroupCollectorInterface */ public function dumpQuery(): void { - echo $this->query->toSql(); echo '
';
         print_r($this->query->getBindings());
@@ -304,7 +303,6 @@ class GroupCollector implements GroupCollectorInterface
         }
 
         return $collection;
-
     }
 
     /**
@@ -331,7 +329,7 @@ class GroupCollector implements GroupCollectorInterface
         $sum      = '0';
         /** @var array $journal */
         foreach ($journals as $journal) {
-            $amount = (string)$journal['amount'];
+            $amount = (string) $journal['amount'];
             $sum    = bcadd($sum, $amount);
         }
 
@@ -510,6 +508,24 @@ class GroupCollector implements GroupCollectorInterface
         return $this;
     }
 
+    /**
+     * Collect transactions created on a specific date.
+     *
+     * @param Carbon $date
+     *
+     * @return GroupCollectorInterface
+     */
+    public function setCreatedAt(Carbon $date): GroupCollectorInterface
+    {
+        $after  = $date->format('Y-m-d 00:00:00');
+        $before = $date->format('Y-m-d 23:59:59');
+        $this->query->where('transaction_journals.created_at', '>=', $after);
+        $this->query->where('transaction_journals.created_at', '<=', $before);
+        Log::debug(sprintf('GroupCollector created_at is now after %s (inclusive)', $after));
+
+        return $this;
+    }
+
     /**
      * Limit results to a specific currency, either foreign or normal one.
      *
@@ -742,6 +758,24 @@ class GroupCollector implements GroupCollectorInterface
         return $this;
     }
 
+    /**
+     * Collect transactions updated on a specific date.
+     *
+     * @param Carbon $date
+     *
+     * @return GroupCollectorInterface
+     */
+    public function setUpdatedAt(Carbon $date): GroupCollectorInterface
+    {
+        $after  = $date->format('Y-m-d 00:00:00');
+        $before = $date->format('Y-m-d 23:59:59');
+        $this->query->where('transaction_journals.updated_at', '>=', $after);
+        $this->query->where('transaction_journals.updated_at', '<=', $before);
+        Log::debug(sprintf('GroupCollector created_at is now after %s (inclusive)', $after));
+
+        return $this;
+    }
+
     /**
      * Set the user object and start the query.
      *
@@ -757,6 +791,43 @@ class GroupCollector implements GroupCollectorInterface
         return $this;
     }
 
+    /**
+     * Either account can be set, but NOT both. This effectively excludes internal transfers.
+     *
+     * @param Collection $accounts
+     *
+     * @return GroupCollectorInterface
+     */
+    public function setXorAccounts(Collection $accounts): GroupCollectorInterface
+    {
+        if ($accounts->count() > 0) {
+            $accountIds = $accounts->pluck('id')->toArray();
+            $this->query->where(
+                static function (EloquentBuilder $q1) use ($accountIds) {
+                    // sourceAccount is in the set, and destination is NOT.
+
+                    $q1->where(
+                        static function (EloquentBuilder $q2) use ($accountIds) {
+                            $q2->whereIn('source.account_id', $accountIds);
+                            $q2->whereNotIn('destination.account_id', $accountIds);
+                        }
+                    );
+                    // destination is in the set, and source is NOT
+                    $q1->orWhere(
+                        static function (EloquentBuilder $q3) use ($accountIds) {
+                            $q3->whereNotIn('source.account_id', $accountIds);
+                            $q3->whereIn('destination.account_id', $accountIds);
+                        }
+                    );
+                }
+            );
+
+            app('log')->debug(sprintf('GroupCollector: setXorAccounts: %s', implode(', ', $accountIds)));
+        }
+
+        return $this;
+    }
+
     /**
      * Automatically include all stuff required to make API calls work.
      *
@@ -810,6 +881,17 @@ class GroupCollector implements GroupCollectorInterface
         return $this;
     }
 
+    /**
+     * @inheritDoc
+     */
+    public function withAttachmentInformation(): GroupCollectorInterface
+    {
+        $this->fields[] = 'attachments.id as attachment_id';
+        $this->joinAttachmentTables();
+
+        return $this;
+    }
+
     /**
      * Will include bill name + ID, if any.
      *
@@ -933,25 +1015,12 @@ class GroupCollector implements GroupCollectorInterface
     private function convertToInteger(array $array): array
     {
         foreach ($this->integerFields as $field) {
-            $array[$field] = isset($array[$field]) ? (int)$array[$field] : null;
+            $array[$field] = isset($array[$field]) ? (int) $array[$field] : null;
         }
 
         return $array;
     }
 
-    /**
-     * Join table to get tag information.
-     */
-    private function joinTagTables(): void
-    {
-        if (false === $this->hasJoinedTagTables) {
-            // join some extra tables:
-            $this->hasJoinedTagTables = true;
-            $this->query->leftJoin('tag_transaction_journal', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
-            $this->query->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id');
-        }
-    }
-
     /**
      * Join table to get attachment information.
      */
@@ -971,33 +1040,16 @@ class GroupCollector implements GroupCollectorInterface
     }
 
     /**
-     * @param array              $existingJournal
-     * @param TransactionJournal $newJournal
-     *
-     * @return array
+     * Join table to get tag information.
      */
-    private function mergeTags(array $existingJournal, TransactionJournal $newJournal): array
+    private function joinTagTables(): void
     {
-        $newArray = $newJournal->toArray();
-        if (isset($newArray['tag_id'])) { // assume the other fields are present as well.
-            $tagId = (int)$newJournal['tag_id'];
-
-            $tagDate = null;
-            try {
-                $tagDate = Carbon::parse($newArray['tag_date']);
-            } catch (InvalidDateException $e) {
-                Log::debug(sprintf('Could not parse date: %s', $e->getMessage()));
-            }
-
-            $existingJournal['tags'][$tagId] = [
-                'id'          => (int)$newArray['tag_id'],
-                'name'        => $newArray['tag_name'],
-                'date'        => $tagDate,
-                'description' => $newArray['tag_description'],
-            ];
+        if (false === $this->hasJoinedTagTables) {
+            // join some extra tables:
+            $this->hasJoinedTagTables = true;
+            $this->query->leftJoin('tag_transaction_journal', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
+            $this->query->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id');
         }
-
-        return $existingJournal;
     }
 
     /**
@@ -1010,7 +1062,7 @@ class GroupCollector implements GroupCollectorInterface
     {
         $newArray = $newJournal->toArray();
         if (isset($newArray['attachment_id'])) {
-            $attachmentId                                  = (int)$newJournal['tag_id'];
+            $attachmentId                                  = (int) $newJournal['tag_id'];
             $existingJournal['attachments'][$attachmentId] = [
                 'id' => $attachmentId,
             ];
@@ -1019,6 +1071,35 @@ class GroupCollector implements GroupCollectorInterface
         return $existingJournal;
     }
 
+    /**
+     * @param array              $existingJournal
+     * @param TransactionJournal $newJournal
+     *
+     * @return array
+     */
+    private function mergeTags(array $existingJournal, TransactionJournal $newJournal): array
+    {
+        $newArray = $newJournal->toArray();
+        if (isset($newArray['tag_id'])) { // assume the other fields are present as well.
+            $tagId = (int) $newJournal['tag_id'];
+
+            $tagDate = null;
+            try {
+                $tagDate = Carbon::parse($newArray['tag_date']);
+            } catch (InvalidDateException $e) {
+                Log::debug(sprintf('Could not parse date: %s', $e->getMessage()));
+            }
+
+            $existingJournal['tags'][$tagId] = [
+                'id'          => (int) $newArray['tag_id'],
+                'name'        => $newArray['tag_name'],
+                'date'        => $tagDate,
+                'description' => $newArray['tag_description'],
+            ];
+        }
+
+        return $existingJournal;
+    }
 
     /**
      * @param Collection $collection
@@ -1036,21 +1117,21 @@ class GroupCollector implements GroupCollectorInterface
                 // make new array
                 $parsedGroup                            = $this->parseAugmentedJournal($augumentedJournal);
                 $groupArray                             = [
-                    'id'               => (int)$augumentedJournal->transaction_group_id,
-                    'user_id'          => (int)$augumentedJournal->user_id,
+                    'id'               => (int) $augumentedJournal->transaction_group_id,
+                    'user_id'          => (int) $augumentedJournal->user_id,
                     'title'            => $augumentedJournal->transaction_group_title,
                     'transaction_type' => $parsedGroup['transaction_type_type'],
                     'count'            => 1,
                     'sums'             => [],
                     'transactions'     => [],
                 ];
-                $journalId                              = (int)$augumentedJournal->transaction_journal_id;
+                $journalId                              = (int) $augumentedJournal->transaction_journal_id;
                 $groupArray['transactions'][$journalId] = $parsedGroup;
                 $groups[$groupId]                       = $groupArray;
                 continue;
             }
             // or parse the rest.
-            $journalId = (int)$augumentedJournal->transaction_journal_id;
+            $journalId = (int) $augumentedJournal->transaction_journal_id;
             $groups[$groupId]['count']++;
 
             if (isset($groups[$groupId]['transactions'][$journalId])) {
@@ -1063,8 +1144,6 @@ class GroupCollector implements GroupCollectorInterface
                 // create second, third, fourth split:
                 $groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedJournal($augumentedJournal);
             }
-
-
         }
 
         $groups = $this->parseSums($groups);
@@ -1093,9 +1172,9 @@ class GroupCollector implements GroupCollectorInterface
         // convert values to integers:
         $result = $this->convertToInteger($result);
 
-        $result['reconciled'] = 1 === (int)$result['reconciled'];
+        $result['reconciled'] = 1 === (int) $result['reconciled'];
         if (isset($augumentedJournal['tag_id'])) { // assume the other fields are present as well.
-            $tagId   = (int)$augumentedJournal['tag_id'];
+            $tagId   = (int) $augumentedJournal['tag_id'];
             $tagDate = null;
             try {
                 $tagDate = Carbon::parse($augumentedJournal['tag_date']);
@@ -1104,7 +1183,7 @@ class GroupCollector implements GroupCollectorInterface
             }
 
             $result['tags'][$tagId] = [
-                'id'          => (int)$result['tag_id'],
+                'id'          => (int) $result['tag_id'],
                 'name'        => $result['tag_name'],
                 'date'        => $tagDate,
                 'description' => $result['tag_description'],
@@ -1113,7 +1192,7 @@ class GroupCollector implements GroupCollectorInterface
 
         // also merge attachments:
         if (isset($augumentedJournal['attachment_id'])) {
-            $attachmentId                         = (int)$augumentedJournal['attachment_id'];
+            $attachmentId                         = (int) $augumentedJournal['attachment_id'];
             $result['attachments'][$attachmentId] = [
                 'id' => $attachmentId,
             ];
@@ -1136,7 +1215,7 @@ class GroupCollector implements GroupCollectorInterface
         foreach ($groups as $groudId => $group) {
             /** @var array $transaction */
             foreach ($group['transactions'] as $transaction) {
-                $currencyId = (int)$transaction['currency_id'];
+                $currencyId = (int) $transaction['currency_id'];
 
                 // set default:
                 if (!isset($groups[$groudId]['sums'][$currencyId])) {
@@ -1149,7 +1228,7 @@ class GroupCollector implements GroupCollectorInterface
                 $groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount'] ?? '0');
 
                 if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
-                    $currencyId = (int)$transaction['foreign_currency_id'];
+                    $currencyId = (int) $transaction['foreign_currency_id'];
 
                     // set default:
                     if (!isset($groups[$groudId]['sums'][$currencyId])) {
@@ -1160,7 +1239,8 @@ class GroupCollector implements GroupCollectorInterface
                         $groups[$groudId]['sums'][$currencyId]['amount']                  = '0';
                     }
                     $groups[$groudId]['sums'][$currencyId]['amount'] = bcadd(
-                        $groups[$groudId]['sums'][$currencyId]['amount'], $transaction['foreign_amount'] ?? '0'
+                        $groups[$groudId]['sums'][$currencyId]['amount'],
+                        $transaction['foreign_amount'] ?? '0'
                     );
                 }
             }
@@ -1183,17 +1263,19 @@ class GroupCollector implements GroupCollectorInterface
 
             // join source transaction.
             ->leftJoin(
-                'transactions as source', function (JoinClause $join) {
-                $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
+                'transactions as source',
+                function (JoinClause $join) {
+                    $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
                      ->where('source.amount', '<', 0);
-            }
+                }
             )
             // join destination transaction
             ->leftJoin(
-                'transactions as destination', function (JoinClause $join) {
-                $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
+                'transactions as destination',
+                function (JoinClause $join) {
+                    $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
                      ->where('destination.amount', '>', 0);
-            }
+                }
             )
             // left join transaction type.
             ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
@@ -1209,88 +1291,4 @@ class GroupCollector implements GroupCollectorInterface
             ->orderBy('transaction_journals.description', 'DESC')
             ->orderBy('source.amount', 'DESC');
     }
-
-    /**
-     * Either account can be set, but NOT both. This effectively excludes internal transfers.
-     *
-     * @param Collection $accounts
-     *
-     * @return GroupCollectorInterface
-     */
-    public function setXorAccounts(Collection $accounts): GroupCollectorInterface
-    {
-        if ($accounts->count() > 0) {
-            $accountIds = $accounts->pluck('id')->toArray();
-            $this->query->where(
-                static function (EloquentBuilder $q1) use ($accountIds) {
-                    // sourceAccount is in the set, and destination is NOT.
-
-                    $q1->where(
-                        static function (EloquentBuilder $q2) use ($accountIds) {
-                            $q2->whereIn('source.account_id', $accountIds);
-                            $q2->whereNotIn('destination.account_id', $accountIds);
-                        }
-                    );
-                    // destination is in the set, and source is NOT
-                    $q1->orWhere(
-                        static function (EloquentBuilder $q3) use ($accountIds) {
-                            $q3->whereNotIn('source.account_id', $accountIds);
-                            $q3->whereIn('destination.account_id', $accountIds);
-                        }
-                    );
-                }
-            );
-
-            app('log')->debug(sprintf('GroupCollector: setXorAccounts: %s', implode(', ', $accountIds)));
-        }
-
-        return $this;
-    }
-
-    /**
-     * Collect transactions created on a specific date.
-     *
-     * @param Carbon $date
-     *
-     * @return GroupCollectorInterface
-     */
-    public function setCreatedAt(Carbon $date): GroupCollectorInterface
-    {
-        $after  = $date->format('Y-m-d 00:00:00');
-        $before = $date->format('Y-m-d 23:59:59');
-        $this->query->where('transaction_journals.created_at', '>=', $after);
-        $this->query->where('transaction_journals.created_at', '<=', $before);
-        Log::debug(sprintf('GroupCollector created_at is now after %s (inclusive)', $after));
-
-        return $this;
-    }
-
-    /**
-     * Collect transactions updated on a specific date.
-     *
-     * @param Carbon $date
-     *
-     * @return GroupCollectorInterface
-     */
-    public function setUpdatedAt(Carbon $date): GroupCollectorInterface
-    {
-        $after  = $date->format('Y-m-d 00:00:00');
-        $before = $date->format('Y-m-d 23:59:59');
-        $this->query->where('transaction_journals.updated_at', '>=', $after);
-        $this->query->where('transaction_journals.updated_at', '<=', $before);
-        Log::debug(sprintf('GroupCollector created_at is now after %s (inclusive)', $after));
-
-        return $this;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public function withAttachmentInformation(): GroupCollectorInterface
-    {
-        $this->fields[] = 'attachments.id as attachment_id';
-        $this->joinAttachmentTables();
-
-        return $this;
-    }
 }