mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup that (hopefully) matches style CI
This commit is contained in:
parent
b0c9fc0792
commit
bd2f064eeb
@ -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;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
@ -27,5 +28,4 @@ use Exception;
|
||||
*/
|
||||
class DuplicateTransactionException extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ use Exception;
|
||||
|
||||
/**
|
||||
* Class FireflyException.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FireflyException extends Exception
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ use Exception;
|
||||
|
||||
/**
|
||||
* Class NotImplementedException.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class NotImplementedException extends Exception
|
||||
|
@ -28,6 +28,7 @@ use Exception;
|
||||
|
||||
/**
|
||||
* Class ValidationExceptions.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ValidationException extends Exception
|
||||
|
@ -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);
|
||||
|
@ -36,6 +36,7 @@ class AccountMetaFactory
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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']),
|
||||
|
@ -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!');
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -35,6 +35,7 @@ class TransactionTypeFactory
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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,
|
||||
];
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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 '<pre>';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user