Code cleanup that (hopefully) matches style CI

This commit is contained in:
James Cole
2020-03-17 14:57:04 +01:00
parent b0c9fc0792
commit bd2f064eeb
30 changed files with 318 additions and 298 deletions

View File

@@ -20,6 +20,7 @@
*/ */
namespace FireflyIII\Exceptions; namespace FireflyIII\Exceptions;
use Exception; use Exception;
/** /**
@@ -27,5 +28,4 @@ use Exception;
*/ */
class DuplicateTransactionException extends Exception class DuplicateTransactionException extends Exception
{ {
} }

View File

@@ -28,6 +28,7 @@ use Exception;
/** /**
* Class FireflyException. * Class FireflyException.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class FireflyException extends Exception class FireflyException extends Exception

View File

@@ -33,8 +33,11 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Log; use Log;
use Symfony\Component\HttpFoundation\Response;
/** /**
* Class GracefulNotFoundHandler * Class GracefulNotFoundHandler
@@ -134,7 +137,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Request $request * @param Request $request
* @param Exception $exception * @param Exception $exception
* *
* @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response * @return \Illuminate\Http\Response|Response
*/ */
private function handleAccount($request, Exception $exception) private function handleAccount($request, Exception $exception)
{ {
@@ -199,7 +202,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param $request * @param $request
* @param Exception $exception * @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) private function handleGroup($request, Exception $exception)
{ {

View File

@@ -82,7 +82,8 @@ class Handler extends ExceptionHandler
'line' => $exception->getLine(), 'line' => $exception->getLine(),
'file' => $exception->getFile(), 'file' => $exception->getFile(),
'trace' => $exception->getTrace(), 'trace' => $exception->getTrace(),
], 500 ],
500
); );
} }
@@ -91,6 +92,7 @@ class Handler extends ExceptionHandler
if ($exception instanceof NotFoundHttpException) { if ($exception instanceof NotFoundHttpException) {
$handler = app(GracefulNotFoundHandler::class); $handler = app(GracefulNotFoundHandler::class);
return $handler->render($request, $exception); return $handler->render($request, $exception);
} }
@@ -113,13 +115,12 @@ class Handler extends ExceptionHandler
* *
* @param Exception $exception * @param Exception $exception
* *
* @throws Exception
* @return mixed|void * @return mixed|void
* *
* @throws Exception
*/ */
public function report(Exception $exception) public function report(Exception $exception)
{ {
$doMailError = config('firefly.send_error_message'); $doMailError = config('firefly.send_error_message');
// if the user wants us to mail: // if the user wants us to mail:
if (true === $doMailError if (true === $doMailError

View File

@@ -28,6 +28,7 @@ use Exception;
/** /**
* Class NotImplementedException. * Class NotImplementedException.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class NotImplementedException extends Exception class NotImplementedException extends Exception

View File

@@ -28,6 +28,7 @@ use Exception;
/** /**
* Class ValidationExceptions. * Class ValidationExceptions.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class ValidationException extends Exception class ValidationException extends Exception

View File

@@ -27,7 +27,6 @@ namespace FireflyIII\Factory;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Location;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Support\AccountServiceTrait; use FireflyIII\Services\Internal\Support\AccountServiceTrait;
use FireflyIII\Services\Internal\Support\LocationServiceTrait; use FireflyIII\Services\Internal\Support\LocationServiceTrait;
@@ -45,18 +44,16 @@ class AccountFactory
/** @var AccountRepositoryInterface */ /** @var AccountRepositoryInterface */
protected $accountRepository; protected $accountRepository;
/** @var User */
private $user;
/** @var array */
private $canHaveVirtual;
/** @var array */ /** @var array */
protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth']; protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
/** @var array */ /** @var array */
protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth']; protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
/** @var array */ /** @var array */
protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth']; protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];
/** @var array */
private $canHaveVirtual;
/** @var User */
private $user;
/** /**
* AccountFactory constructor. * AccountFactory constructor.
@@ -75,8 +72,8 @@ class AccountFactory
/** /**
* @param array $data * @param array $data
* *
* @return Account
* @throws FireflyException * @throws FireflyException
* @return Account
*/ */
public function create(array $data): Account public function create(array $data): Account
{ {
@@ -159,8 +156,8 @@ class AccountFactory
* @param string $accountName * @param string $accountName
* @param string $accountType * @param string $accountType
* *
* @return Account
* @throws FireflyException * @throws FireflyException
* @return Account
*/ */
public function findOrCreate(string $accountName, string $accountType): Account public function findOrCreate(string $accountName, string $accountType): Account
{ {

View File

@@ -36,6 +36,7 @@ class AccountMetaFactory
{ {
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@@ -41,6 +41,7 @@ class AttachmentFactory
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
@@ -53,8 +54,8 @@ class AttachmentFactory
/** /**
* @param array $data * @param array $data
* *
* @return Attachment|null
* @throws FireflyException * @throws FireflyException
* @return Attachment|null
*/ */
public function create(array $data): ?Attachment public function create(array $data): ?Attachment
{ {

View File

@@ -44,6 +44,7 @@ class BillFactory
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
@@ -56,8 +57,8 @@ class BillFactory
/** /**
* @param array $data * @param array $data
* *
* @return Bill|null
* @throws FireflyException * @throws FireflyException
* @return Bill|null
*/ */
public function create(array $data): ?Bill public function create(array $data): ?Bill
{ {

View File

@@ -38,6 +38,7 @@ class BudgetFactory
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@@ -40,6 +40,7 @@ class CategoryFactory
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
@@ -63,8 +64,8 @@ class CategoryFactory
* @param int|null $categoryId * @param int|null $categoryId
* @param null|string $categoryName * @param null|string $categoryName
* *
* @return Category|null
* @throws FireflyException * @throws FireflyException
* @return Category|null
*/ */
public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category
{ {

View File

@@ -39,6 +39,7 @@ class PiggyBankEventFactory
{ {
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
@@ -60,6 +61,7 @@ class PiggyBankEventFactory
Log::debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type)); Log::debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type));
if (null === $piggyBank) { if (null === $piggyBank) {
Log::debug('Piggy bank is null'); Log::debug('Piggy bank is null');
return null; return null;
} }

View File

@@ -38,6 +38,7 @@ class PiggyBankFactory
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@@ -39,16 +39,16 @@ use Log;
*/ */
class RecurrenceFactory class RecurrenceFactory
{ {
/** @var User */
private $user;
/** @var MessageBag */ /** @var MessageBag */
private $errors; private $errors;
/** @var User */
private $user;
use TransactionTypeTrait, RecurringTransactionTrait; use TransactionTypeTrait, RecurringTransactionTrait;
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
@@ -62,8 +62,8 @@ class RecurrenceFactory
/** /**
* @param array $data * @param array $data
* *
* @return Recurrence
* @throws FireflyException * @throws FireflyException
* @return Recurrence
*/ */
public function create(array $data): Recurrence public function create(array $data): Recurrence
{ {

View File

@@ -42,6 +42,7 @@ class TagFactory
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@@ -52,8 +52,8 @@ class TransactionCurrencyFactory
/** /**
* @param array $data * @param array $data
* *
* @return TransactionCurrency
* @throws FireflyException * @throws FireflyException
* @return TransactionCurrency
*/ */
public function create(array $data): TransactionCurrency public function create(array $data): TransactionCurrency
{ {

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -39,21 +38,22 @@ use Log;
*/ */
class TransactionFactory class TransactionFactory
{ {
/** @var TransactionJournal */
private $journal;
/** @var Account */ /** @var Account */
private $account; private $account;
/** @var TransactionCurrency */ /** @var TransactionCurrency */
private $currency; private $currency;
/** @var TransactionCurrency */ /** @var TransactionCurrency */
private $foreignCurrency; private $foreignCurrency;
/** @var User */ /** @var TransactionJournal */
private $user; private $journal;
/** @var bool */ /** @var bool */
private $reconciled; private $reconciled;
/** @var User */
private $user;
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
@@ -64,50 +64,14 @@ class TransactionFactory
$this->reconciled = false; $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). * Create transaction with negative amount (for source accounts).
* *
* @param string $amount * @param string $amount
* @param string|null $foreignAmount * @param string|null $foreignAmount
* *
* @return Transaction
* @throws FireflyException * @throws FireflyException
* @return Transaction
*/ */
public function createNegative(string $amount, ?string $foreignAmount): Transaction public function createNegative(string $amount, ?string $foreignAmount): Transaction
{ {
@@ -127,8 +91,8 @@ class TransactionFactory
* @param string $amount * @param string $amount
* @param string|null $foreignAmount * @param string|null $foreignAmount
* *
* @return Transaction
* @throws FireflyException * @throws FireflyException
* @return Transaction
*/ */
public function createPositive(string $amount, ?string $foreignAmount): Transaction public function createPositive(string $amount, ?string $foreignAmount): Transaction
{ {
@@ -138,12 +102,43 @@ class TransactionFactory
if (null !== $foreignAmount) { if (null !== $foreignAmount) {
$foreignAmount = app('steam')->positive($foreignAmount); $foreignAmount = app('steam')->positive($foreignAmount);
} }
return $this->create(app('steam')->positive($amount), $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 * @param TransactionJournal $journal
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function setJournal(TransactionJournal $journal): void public function setJournal(TransactionJournal $journal): void
@@ -151,8 +146,19 @@ class TransactionFactory
$this->journal = $journal; $this->journal = $journal;
} }
/**
* @param bool $reconciled
*
* @codeCoverageIgnore
*/
public function setReconciled(bool $reconciled): void
{
$this->reconciled = $reconciled;
}
/** /**
* @param User $user * @param User $user
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function setUser(User $user): void public function setUser(User $user): void
@@ -164,8 +170,8 @@ class TransactionFactory
* @param string $amount * @param string $amount
* @param string|null $foreignAmount * @param string|null $foreignAmount
* *
* @return Transaction
* @throws FireflyException * @throws FireflyException
* @return Transaction
*/ */
private function create(string $amount, ?string $foreignAmount): Transaction private function create(string $amount, ?string $foreignAmount): Transaction
{ {
@@ -200,7 +206,11 @@ class TransactionFactory
if (null !== $result) { if (null !== $result) {
Log::debug( Log::debug(
sprintf( 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 $this->journal->id
) )
); );
@@ -209,7 +219,6 @@ class TransactionFactory
if (null !== $this->foreignCurrency && null !== $foreignAmount && $this->foreignCurrency->id !== $this->currency->id && '' !== $foreignAmount) { if (null !== $this->foreignCurrency && null !== $foreignAmount && $this->foreignCurrency->id !== $this->currency->id && '' !== $foreignAmount) {
$result->foreign_currency_id = $this->foreignCurrency->id; $result->foreign_currency_id = $this->foreignCurrency->id;
$result->foreign_amount = $foreignAmount; $result->foreign_amount = $foreignAmount;
} }
$result->save(); $result->save();
} }

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\User; use FireflyIII\User;
use Log; use Log;
@@ -54,8 +53,8 @@ class TransactionGroupFactory
* *
* @param array $data * @param array $data
* *
* @return TransactionGroup
* @throws DuplicateTransactionException * @throws DuplicateTransactionException
* @return TransactionGroup
*/ */
public function create(array $data): TransactionGroup public function create(array $data): TransactionGroup
{ {

View File

@@ -64,6 +64,8 @@ class TransactionJournalFactory
private $billRepository; private $billRepository;
/** @var CurrencyRepositoryInterface */ /** @var CurrencyRepositoryInterface */
private $currencyRepository; private $currencyRepository;
/** @var bool */
private $errorOnHash;
/** @var array */ /** @var array */
private $fields; private $fields;
/** @var PiggyBankEventFactory */ /** @var PiggyBankEventFactory */
@@ -76,8 +78,6 @@ class TransactionJournalFactory
private $typeRepository; private $typeRepository;
/** @var User The user */ /** @var User The user */
private $user; private $user;
/** @var bool */
private $errorOnHash;
/** /**
* Constructor. * Constructor.
@@ -125,9 +125,9 @@ class TransactionJournalFactory
* *
* @param array $data * @param array $data
* *
* @return Collection
* @throws DuplicateTransactionException * @throws DuplicateTransactionException
* @throws FireflyException * @throws FireflyException
* @return Collection
*/ */
public function create(array $data): Collection public function create(array $data): Collection
{ {
@@ -171,6 +171,17 @@ class TransactionJournalFactory
return $collection; 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. * Set the user.
* *
@@ -212,9 +223,9 @@ class TransactionJournalFactory
/** /**
* @param NullArrayObject $row * @param NullArrayObject $row
* *
* @return TransactionJournal|null
* @throws FireflyException * @throws FireflyException
* @throws DuplicateTransactionException * @throws DuplicateTransactionException
* @return TransactionJournal|null
*/ */
private function createJournal(NullArrayObject $row): ?TransactionJournal private function createJournal(NullArrayObject $row): ?TransactionJournal
{ {
@@ -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.');
}
}
} }

View File

@@ -36,6 +36,7 @@ class TransactionJournalMetaFactory
{ {
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@@ -35,6 +35,7 @@ class TransactionTypeFactory
{ {
/** /**
* Constructor. * Constructor.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function __construct() public function __construct()

View File

@@ -51,9 +51,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
/** /**
* Generates the report. * Generates the report.
* *
* @return string
* @throws FireflyException * @throws FireflyException
* @codeCoverageIgnore * @codeCoverageIgnore
* @return string
*/ */
public function generate(): string public function generate(): string
{ {
@@ -100,9 +100,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Account $account * @param Account $account
* @param Carbon $date * @param Carbon $date
* *
* @throws FireflyException
* @return array * @return array
* *
* @throws FireflyException
*/ */
public function getAuditReport(Account $account, Carbon $date): array public function getAuditReport(Account $account, Carbon $date): array
{ {

View File

@@ -39,9 +39,9 @@ class ReportGeneratorFactory
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
* @throws FireflyException
* @return ReportGeneratorInterface * @return ReportGeneratorInterface
* *
* @throws FireflyException
*/ */
public static function reportGenerator(string $type, Carbon $start, Carbon $end): ReportGeneratorInterface public static function reportGenerator(string $type, Carbon $start, Carbon $end): ReportGeneratorInterface
{ {

View File

@@ -76,7 +76,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
// render! // render!
try { try {
$result = view( $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(); )->with('start', $this->start)->with('end', $this->end)->with('tags', $this->tags)->with('accounts', $this->accounts)->render();
} catch (Throwable $e) { } catch (Throwable $e) {
Log::error(sprintf('Cannot render reports.tag.month: %s', $e->getMessage())); Log::error(sprintf('Cannot render reports.tag.month: %s', $e->getMessage()));
@@ -177,6 +178,4 @@ class MonthReportGenerator implements ReportGeneratorInterface
return $this; return $this;
} }
} }

View File

@@ -58,10 +58,12 @@ class GroupCollector implements GroupCollectorInterface
private $hasBudgetInformation; private $hasBudgetInformation;
/** @var bool Will be true if query result contains category info. */ /** @var bool Will be true if query result contains category info. */
private $hasCatInformation; 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 */ /** @var bool Will be true for attachments */
private $hasJoinedAttTables; 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. */ /** @var int The maximum number of results. */
private $limit; private $limit;
/** @var int The page to return. */ /** @var int The page to return. */
@@ -72,8 +74,6 @@ class GroupCollector implements GroupCollectorInterface
private $total; private $total;
/** @var User The user object. */ /** @var User The user object. */
private $user; private $user;
/** @var array */
private $integerFields;
/** /**
* Group collector constructor. * Group collector constructor.
@@ -210,7 +210,6 @@ class GroupCollector implements GroupCollectorInterface
*/ */
public function dumpQuery(): void public function dumpQuery(): void
{ {
echo $this->query->toSql(); echo $this->query->toSql();
echo '<pre>'; echo '<pre>';
print_r($this->query->getBindings()); print_r($this->query->getBindings());
@@ -304,7 +303,6 @@ class GroupCollector implements GroupCollectorInterface
} }
return $collection; return $collection;
} }
/** /**
@@ -510,6 +508,24 @@ class GroupCollector implements GroupCollectorInterface
return $this; 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. * Limit results to a specific currency, either foreign or normal one.
* *
@@ -742,6 +758,24 @@ class GroupCollector implements GroupCollectorInterface
return $this; 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. * Set the user object and start the query.
* *
@@ -757,6 +791,43 @@ class GroupCollector implements GroupCollectorInterface
return $this; 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. * Automatically include all stuff required to make API calls work.
* *
@@ -810,6 +881,17 @@ class GroupCollector implements GroupCollectorInterface
return $this; 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. * Will include bill name + ID, if any.
* *
@@ -939,19 +1021,6 @@ class GroupCollector implements GroupCollectorInterface
return $array; 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. * Join table to get attachment information.
*/ */
@@ -970,6 +1039,38 @@ class GroupCollector implements GroupCollectorInterface
} }
} }
/**
* 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');
}
}
/**
* @param array $existingJournal
* @param TransactionJournal $newJournal
*
* @return array
*/
private function mergeAttachments(array $existingJournal, TransactionJournal $newJournal): array
{
$newArray = $newJournal->toArray();
if (isset($newArray['attachment_id'])) {
$attachmentId = (int) $newJournal['tag_id'];
$existingJournal['attachments'][$attachmentId] = [
'id' => $attachmentId,
];
}
return $existingJournal;
}
/** /**
* @param array $existingJournal * @param array $existingJournal
* @param TransactionJournal $newJournal * @param TransactionJournal $newJournal
@@ -1000,26 +1101,6 @@ class GroupCollector implements GroupCollectorInterface
return $existingJournal; return $existingJournal;
} }
/**
* @param array $existingJournal
* @param TransactionJournal $newJournal
*
* @return array
*/
private function mergeAttachments(array $existingJournal, TransactionJournal $newJournal): array
{
$newArray = $newJournal->toArray();
if (isset($newArray['attachment_id'])) {
$attachmentId = (int)$newJournal['tag_id'];
$existingJournal['attachments'][$attachmentId] = [
'id' => $attachmentId,
];
}
return $existingJournal;
}
/** /**
* @param Collection $collection * @param Collection $collection
* *
@@ -1063,8 +1144,6 @@ class GroupCollector implements GroupCollectorInterface
// create second, third, fourth split: // create second, third, fourth split:
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedJournal($augumentedJournal); $groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedJournal($augumentedJournal);
} }
} }
$groups = $this->parseSums($groups); $groups = $this->parseSums($groups);
@@ -1160,7 +1239,8 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groudId]['sums'][$currencyId]['amount'] = '0'; $groups[$groudId]['sums'][$currencyId]['amount'] = '0';
} }
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd( $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,14 +1263,16 @@ class GroupCollector implements GroupCollectorInterface
// join source transaction. // join source transaction.
->leftJoin( ->leftJoin(
'transactions as source', function (JoinClause $join) { 'transactions as source',
function (JoinClause $join) {
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id') $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
->where('source.amount', '<', 0); ->where('source.amount', '<', 0);
} }
) )
// join destination transaction // join destination transaction
->leftJoin( ->leftJoin(
'transactions as destination', function (JoinClause $join) { 'transactions as destination',
function (JoinClause $join) {
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id') $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
->where('destination.amount', '>', 0); ->where('destination.amount', '>', 0);
} }
@@ -1209,88 +1291,4 @@ class GroupCollector implements GroupCollectorInterface
->orderBy('transaction_journals.description', 'DESC') ->orderBy('transaction_journals.description', 'DESC')
->orderBy('source.amount', '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;
}
} }