diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php index 5bc4cc2871..99f95c0ee8 100644 --- a/app/Api/V1/Controllers/Controller.php +++ b/app/Api/V1/Controllers/Controller.php @@ -46,6 +46,7 @@ abstract class Controller extends BaseController protected const CONTENT_TYPE = 'application/vnd.api+json'; protected ParameterBag $parameters; + protected array $allowedSort; /** * Controller constructor. @@ -53,7 +54,8 @@ abstract class Controller extends BaseController public function __construct() { // get global parameters - $this->parameters = $this->getParameters(); + $this->allowedSort = config('firefly.allowed_sort_parameters'); + $this->parameters = $this->getParameters(); $this->middleware( function ($request, $next) { if (auth()->check()) { @@ -106,10 +108,42 @@ abstract class Controller extends BaseController } } - return $bag; + // sort fields: + $bag = $this->getSortParameters($bag); + return $bag; } + /** + * @param ParameterBag $bag + * + * @return ParameterBag + */ + private function getSortParameters(ParameterBag $bag): ParameterBag + { + $sortParameters = []; + $param = (string)request()->query->get('sort'); + if ('' === $param) { + return $bag; + } + $parts = explode(',', $param); + foreach ($parts as $part) { + $part = trim($part); + $direction = 'asc'; + if ('-' === $part[0]) { + $part = substr($part, 1); + $direction = 'desc'; + } + if (in_array($part, $this->allowedSort, true)) { + $sortParameters[] = [$part, $direction]; + } + } + $bag->set('sort', $sortParameters); + + return $bag; + } + + /** * Method to help build URI's. * diff --git a/app/Api/V1/Controllers/Models/Account/ShowController.php b/app/Api/V1/Controllers/Models/Account/ShowController.php index 2a96fc56dc..e2c37b4096 100644 --- a/app/Api/V1/Controllers/Models/Account/ShowController.php +++ b/app/Api/V1/Controllers/Models/Account/ShowController.php @@ -84,8 +84,12 @@ class ShowController extends Controller // get list of accounts. Count it and split it. $this->repository->resetAccountOrder(); - $collection = $this->repository->getAccountsByType($types); + $collection = $this->repository->getAccountsByType($types, $this->parameters->get('sort') ?? []); $count = $collection->count(); + + // continue sort: + + $accounts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); // make paginator: diff --git a/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php b/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php index 1167326e7f..6c036b7648 100644 --- a/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php +++ b/app/Api/V1/Requests/Data/Bulk/MoveTransactionsRequest.php @@ -76,8 +76,6 @@ class MoveTransactionsRequest extends FormRequest } if ($originalCurrency->code !== $destinationCurrency->code) { $validator->errors()->add('title', (string)trans('validation.same_account_currency')); - - return; } } } diff --git a/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php b/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php index 972952d600..6432808af9 100644 --- a/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php +++ b/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php @@ -135,8 +135,6 @@ class StoreRequest extends FormRequest */ public function rules(): array { - $today = Carbon::now()->addDay(); - return [ 'type' => 'required|in:withdrawal,transfer,deposit', 'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title', diff --git a/app/Api/V1/Requests/Models/Transaction/StoreRequest.php b/app/Api/V1/Requests/Models/Transaction/StoreRequest.php index 07ffdb674d..81fb1afa4e 100644 --- a/app/Api/V1/Requests/Models/Transaction/StoreRequest.php +++ b/app/Api/V1/Requests/Models/Transaction/StoreRequest.php @@ -53,15 +53,13 @@ class StoreRequest extends FormRequest public function getAll(): array { Log::debug('get all data in TransactionStoreRequest'); - $data = [ + return [ 'group_title' => $this->string('group_title'), 'error_if_duplicate_hash' => $this->boolean('error_if_duplicate_hash'), 'apply_rules' => $this->boolean('apply_rules', true), 'transactions' => $this->getTransactionData(), ]; - // TODO location - return $data; } /** diff --git a/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php b/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php index dc4a0593ce..677afd1469 100644 --- a/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php +++ b/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php @@ -366,7 +366,7 @@ class UpdateRequest extends FormRequest $this->validateJournalIds($validator, $transactionGroup); // all transaction types must be equal: - $this->validateTransactionTypesForUpdate($validator, $transactionGroup); + $this->validateTransactionTypesForUpdate($validator); // validate source/destination is equal, depending on the transaction journal type. $this->validateEqualAccountsForUpdate($validator, $transactionGroup); diff --git a/app/Api/V1/Requests/Models/TransactionCurrency/UpdateRequest.php b/app/Api/V1/Requests/Models/TransactionCurrency/UpdateRequest.php index 9b5efb00e2..9b570af6f2 100644 --- a/app/Api/V1/Requests/Models/TransactionCurrency/UpdateRequest.php +++ b/app/Api/V1/Requests/Models/TransactionCurrency/UpdateRequest.php @@ -54,10 +54,8 @@ class UpdateRequest extends FormRequest 'enabled' => ['enabled', 'boolean'], ]; - $return = $this->getAllData($fields); - - return $return; - + return $this->getAllData($fields); +// return $return; } /** diff --git a/app/Console/Commands/Correction/FixFrontpageAccounts.php b/app/Console/Commands/Correction/FixFrontpageAccounts.php index 865b11a3da..fc6bdebb32 100644 --- a/app/Console/Commands/Correction/FixFrontpageAccounts.php +++ b/app/Console/Commands/Correction/FixFrontpageAccounts.php @@ -56,7 +56,7 @@ class FixFrontpageAccounts extends Command */ public function handle(): int { - $start = microtime(true); + $start = microtime(true); $users = User::get(); /** @var User $user */ @@ -88,16 +88,12 @@ class FixFrontpageAccounts extends Command if (is_array($data)) { /** @var string $accountId */ foreach ($data as $accountId) { - $accountId = (int)$accountId; - $account = $repository->findNull($accountId); - if (null !== $account) { - if ( - in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true) - && true === $account->active - ) { - $fixed[] = $account->id; - continue; - } + $accountIdInt = (int)$accountId; + $account = $repository->findNull($accountIdInt); + if (null !== $account + && in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true) + && true === $account->active) { + $fixed[] = $account->id; } } } diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 846d1874dc..e5129dbbde 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -227,16 +227,6 @@ class GroupCollector implements GroupCollectorInterface */ public function getGroups(): Collection { - $filterQuery = false; - - // now filter the query according to the page and the limit (if necessary) - if ($filterQuery) { - if (null !== $this->limit && null !== $this->page) { - $offset = ($this->page - 1) * $this->limit; - $this->query->take($this->limit)->skip($offset); - } - } - /** @var Collection $result */ $result = $this->query->get($this->fields); @@ -245,12 +235,10 @@ class GroupCollector implements GroupCollectorInterface $this->total = $collection->count(); // now filter the array according to the page and the limit (if necessary) - if (!$filterQuery) { - if (null !== $this->limit && null !== $this->page) { - $offset = ($this->page - 1) * $this->limit; + if (null !== $this->limit && null !== $this->page) { + $offset = ($this->page - 1) * $this->limit; - return $collection->slice($offset, $this->limit); - } + return $collection->slice($offset, $this->limit); } return $collection; diff --git a/app/Models/WebhookAttempt.php b/app/Models/WebhookAttempt.php index b138bdd80d..346b613749 100644 --- a/app/Models/WebhookAttempt.php +++ b/app/Models/WebhookAttempt.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Models; + use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -31,14 +32,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class WebhookAttempt * - * @property int $id - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property string|null $deleted_at - * @property int $webhook_message_id - * @property int $status_code - * @property string|null $logs - * @property string|null $response + * @property int $id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property string|null $deleted_at + * @property int $webhook_message_id + * @property int $status_code + * @property string|null $logs + * @property string|null $response * @property-read \FireflyIII\Models\WebhookMessage $webhookMessage * @method static \Illuminate\Database\Eloquent\Builder|WebhookAttempt newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|WebhookAttempt newQuery() @@ -59,6 +60,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class WebhookAttempt extends Model { use SoftDeletes; + /** * @codeCoverageIgnore * @return BelongsTo @@ -84,10 +86,8 @@ class WebhookAttempt extends Model $user = auth()->user(); /** @var WebhookAttempt $attempt */ $attempt = self::find($attemptId); - if (null !== $attempt) { - if($attempt->webhookMessage->webhook->user_id === $user->id) { - return $attempt; - } + if (null !== $attempt && $attempt->webhookMessage->webhook->user_id === $user->id) { + return $attempt; } } throw new NotFoundHttpException; diff --git a/app/Models/WebhookMessage.php b/app/Models/WebhookMessage.php index be3bc14a6c..42d20744bb 100644 --- a/app/Models/WebhookMessage.php +++ b/app/Models/WebhookMessage.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Models; + use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -31,18 +32,18 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\WebhookMessage * - * @property int $id - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property string|null $deleted_at - * @property int $webhook_id - * @property bool $sent - * @property bool $errored - * @property int $attempts - * @property string $uuid - * @property array $message - * @property array|null $logs - * @property-read \FireflyIII\Models\Webhook $webhook + * @property int $id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property string|null $deleted_at + * @property int $webhook_id + * @property bool $sent + * @property bool $errored + * @property int $attempts + * @property string $uuid + * @property array $message + * @property array|null $logs + * @property-read \FireflyIII\Models\Webhook $webhook * @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage newQuery() * @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage query() @@ -59,7 +60,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage whereWebhookId($value) * @mixin \Eloquent * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\WebhookAttempt[] $webhookAttempts - * @property-read int|null $webhook_attempts_count + * @property-read int|null $webhook_attempts_count */ class WebhookMessage extends Model { @@ -70,7 +71,7 @@ class WebhookMessage extends Model 'errored' => 'boolean', 'uuid' => 'string', 'message' => 'json', - 'logs' => 'json', + 'logs' => 'json', ]; /** @@ -89,10 +90,8 @@ class WebhookMessage extends Model $user = auth()->user(); /** @var WebhookMessage $message */ $message = self::find($messageId); - if (null !== $message) { - if($message->webhook->user_id === $user->id) { - return $message; - } + if (null !== $message && $message->webhook->user_id === $user->id) { + return $message; } } throw new NotFoundHttpException; diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index a35794052b..ed0c0be8a0 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -233,25 +233,35 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param array $types + * @param array $types + * @param array|null $sort * * @return Collection */ - public function getAccountsByType(array $types): Collection + public function getAccountsByType(array $types, ?array $sort = []): Collection { + $res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types); $query = $this->user->accounts(); if (0 !== count($types)) { $query->accountTypeIn($types); } - $res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types); - if (0 !== count($res)) { - $query->orderBy('accounts.order', 'ASC'); + + // add sort parameters. At this point they're filtered to allowed fields to sort by: + if (count($sort) > 0) { + foreach ($sort as $param) { + $query->orderBy($param[0], $param[1]); + } + } + + if (0 === count($sort)) { + if (0 !== count($res)) { + $query->orderBy('accounts.order', 'ASC'); + } + $query->orderBy('accounts.active', 'DESC'); + $query->orderBy('accounts.name', 'ASC'); } - $query->orderBy('accounts.active', 'DESC'); - $query->orderBy('accounts.name', 'ASC'); return $query->get(['accounts.*']); - } /** diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index f2f8e6876a..ee570d8e7a 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -121,11 +121,12 @@ interface AccountRepositoryInterface public function getAccountsById(array $accountIds): Collection; /** - * @param array $types + * @param array $types + * @param array|null $sort * * @return Collection */ - public function getAccountsByType(array $types): Collection; + public function getAccountsByType(array $types, ?array $sort = []): Collection; /** * @param array $types diff --git a/app/Repositories/Account/OperationsRepository.php b/app/Repositories/Account/OperationsRepository.php index ed24597cc8..0fbbca6fed 100644 --- a/app/Repositories/Account/OperationsRepository.php +++ b/app/Repositories/Account/OperationsRepository.php @@ -88,7 +88,7 @@ class OperationsRepository implements OperationsRepositoryInterface */ public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null ): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, $expense, $currency, TransactionType::WITHDRAWAL); + $journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency); return $this->groupByCurrency($journals, 'negative'); @@ -100,7 +100,7 @@ class OperationsRepository implements OperationsRepositoryInterface public function sumExpensesByDestination( Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null ): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, $expense, $currency, TransactionType::WITHDRAWAL); + $journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency); return $this->groupByDirection($journals, 'destination', 'negative'); } @@ -111,7 +111,7 @@ class OperationsRepository implements OperationsRepositoryInterface public function sumExpensesBySource( Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null ): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, $expense, $currency, TransactionType::WITHDRAWAL); + $journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency); return $this->groupByDirection($journals, 'source', 'negative'); } @@ -121,7 +121,7 @@ class OperationsRepository implements OperationsRepositoryInterface */ public function sumIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null ): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, $revenue, $currency, TransactionType::DEPOSIT); + $journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency); return $this->groupByCurrency($journals, 'positive'); } @@ -132,7 +132,7 @@ class OperationsRepository implements OperationsRepositoryInterface public function sumIncomeByDestination( Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null ): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, $revenue, $currency, TransactionType::DEPOSIT); + $journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency); return $this->groupByDirection($journals, 'destination', 'positive'); } @@ -143,7 +143,7 @@ class OperationsRepository implements OperationsRepositoryInterface public function sumIncomeBySource( Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null ): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, $revenue, $currency, TransactionType::DEPOSIT); + $journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency); return $this->groupByDirection($journals, 'source', 'positive'); } @@ -153,7 +153,7 @@ class OperationsRepository implements OperationsRepositoryInterface */ public function sumTransfers(Carbon $start, Carbon $end, ?Collection $accounts = null, ?TransactionCurrency $currency = null): array { - $journals = $this->getTransactionsForSum($start, $end, $accounts, null, $currency, TransactionType::TRANSFER); + $journals = $this->getTransactionsForSum(TransactionType::TRANSFER, $start, $end, $accounts, null, $currency); return $this->groupByEither($journals); } @@ -234,8 +234,8 @@ class OperationsRepository implements OperationsRepositoryInterface * @return array */ private function getTransactionsForSum( - Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $opposing = null, ?TransactionCurrency $currency = null, - string $type + string $type, Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $opposing = null, ?TransactionCurrency $currency = null + ): array { $start->startOfDay(); $end->endOfDay(); @@ -261,11 +261,9 @@ class OperationsRepository implements OperationsRepositoryInterface $collector->setSourceAccounts($opposing); } } - if(TransactionType::TRANSFER === $type) { - // supports only accounts, not opposing. - if(null !== $accounts) { - $collector->setAccounts($accounts); - } + // supports only accounts, not opposing. + if (TransactionType::TRANSFER === $type && null !== $accounts) { + $collector->setAccounts($accounts); } if (null !== $currency) { diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.php index b7923a4370..0d1b363425 100644 --- a/app/Repositories/Attachment/AttachmentRepository.php +++ b/app/Repositories/Attachment/AttachmentRepository.php @@ -174,10 +174,8 @@ class AttachmentRepository implements AttachmentRepositoryInterface $attachment->title = $data['title']; } - if (array_key_exists('filename', $data)) { - if ('' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) { - $attachment->filename = $data['filename']; - } + if (array_key_exists('filename', $data) && '' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) { + $attachment->filename = $data['filename']; } // update model (move attachment) // should be validated already: diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index bae560b7c9..6e697e3112 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -505,14 +505,6 @@ class BillRepository implements BillRepositoryInterface $currentStart = clone $nextExpectedMatch; } - $simple = $set->each( - static function (Carbon $date) { - return $date->format('Y-m-d'); - } - ); - - //Log::debug(sprintf('Found dates between %s and %s:', $start->format('Y-m-d'), $end->format('Y-m-d')), $simple->toArray()); - return $set; } @@ -657,12 +649,6 @@ class BillRepository implements BillRepositoryInterface while ($start < $date) { $start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); } - - $end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); - - //Log::debug('nextDateMatch: Final start is ' . $start->format('Y-m-d')); - //Log::debug('nextDateMatch: Matching end is ' . $end->format('Y-m-d')); - $cache->store($start); return $start; diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 9f6ce7bc85..7f7bfec617 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -151,7 +151,7 @@ class TagRepository implements TagRepositoryInterface $disk = Storage::disk('upload'); return $set->each( - static function (Attachment $attachment, int $index) use ($disk) { + static function (Attachment $attachment) use ($disk) { /** @var Note $note */ $note = $attachment->notes()->first(); // only used in v1 view of tags diff --git a/app/Repositories/Webhook/WebhookRepository.php b/app/Repositories/Webhook/WebhookRepository.php index 871fc9e8b6..f9ee12bb74 100644 --- a/app/Repositories/Webhook/WebhookRepository.php +++ b/app/Repositories/Webhook/WebhookRepository.php @@ -116,7 +116,7 @@ class WebhookRepository implements WebhookRepositoryInterface */ public function store(array $data): Webhook { - $secret = $random = Str::random(24); + $secret = Str::random(24); $fullData = [ 'user_id' => $this->user->id, 'active' => $data['active'] ?? false, @@ -144,7 +144,7 @@ class WebhookRepository implements WebhookRepositoryInterface $webhook->url = $data['url'] ?? $webhook->url; if (true === $data['secret']) { - $secret = $random = Str::random(24); + $secret = Str::random(24); $webhook->secret = $secret; } diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index 68b4076e16..c2bae2535c 100644 --- a/app/Services/Internal/Support/AccountServiceTrait.php +++ b/app/Services/Internal/Support/AccountServiceTrait.php @@ -522,7 +522,7 @@ trait AccountServiceTrait ], ], ]; - Log::debug('Going for submission', $submission); + Log::debug('Going for submission in createOBGroupV2', $submission); /** @var TransactionGroupFactory $factory */ $factory = app(TransactionGroupFactory::class); @@ -595,7 +595,7 @@ trait AccountServiceTrait ], ], ]; - Log::debug('Going for submission', $submission); + Log::debug('Going for submission in createCreditTransaction', $submission); /** @var TransactionGroupFactory $factory */ $factory = app(TransactionGroupFactory::class); @@ -688,7 +688,7 @@ trait AccountServiceTrait ], ], ]; - Log::debug('Going for submission', $submission); + Log::debug('Going for submission in createOBGroup', $submission); /** @var TransactionGroupFactory $factory */ $factory = app(TransactionGroupFactory::class); diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index 2d3e09d394..a1928482ea 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -55,7 +55,6 @@ class CreditRecalculateService */ public function recalculate(): void { - Log::debug(sprintf('Now in %s', __METHOD__)); if (true !== config('firefly.feature_flags.handle_debts')) { Log::debug('handle_debts is disabled.'); @@ -83,7 +82,6 @@ class CreditRecalculateService private function processWork(): void { $this->repository = app(AccountRepositoryInterface::class); - Log::debug(sprintf('Now in %s', __METHOD__)); foreach ($this->work as $account) { $this->processWorkAccount($account); } @@ -127,7 +125,6 @@ class CreditRecalculateService */ private function processGroup(): void { - Log::debug(sprintf('Now in %s', __METHOD__)); /** @var TransactionJournal $journal */ foreach ($this->group->transactionJournals as $journal) { if (0 === count($this->work)) { @@ -149,7 +146,6 @@ class CreditRecalculateService */ private function findByJournal(TransactionJournal $journal): void { - Log::debug(sprintf('Now in %s', __METHOD__)); $source = $this->getSourceAccount($journal); $destination = $this->getDestinationAccount($journal); @@ -190,12 +186,12 @@ class CreditRecalculateService if (null === $transaction) { throw new FireflyException(sprintf('Cannot find "%s"-transaction of journal #%d', $direction, $journal->id)); } - $account = $transaction->account; - if (null === $account) { + $foundAccount = $transaction->account; + if (null === $foundAccount) { throw new FireflyException(sprintf('Cannot find "%s"-account of transaction #%d of journal #%d', $direction, $transaction->id, $journal->id)); } - return $account; + return $foundAccount; } /** @@ -214,7 +210,6 @@ class CreditRecalculateService */ private function processAccount(): void { - Log::debug(sprintf('Now in %s', __METHOD__)); $valid = config('firefly.valid_liabilities'); if (in_array($this->account->accountType->type, $valid)) { Log::debug(sprintf('Account type is "%s", include it.', $this->account->accountType->type)); diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php index 6520cabdad..1db4e1c845 100644 --- a/app/Services/Internal/Update/CategoryUpdateService.php +++ b/app/Services/Internal/Update/CategoryUpdateService.php @@ -167,8 +167,6 @@ class CategoryUpdateService } $dbNote->text = trim($note); $dbNote->save(); - - return; } } diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.php index f5ab52986a..0144dea99d 100644 --- a/app/Support/Authentication/RemoteUserGuard.php +++ b/app/Support/Authentication/RemoteUserGuard.php @@ -98,9 +98,7 @@ class RemoteUserGuard implements Guard */ public function check(): bool { - $result = !is_null($this->user()); - - return $result; + return !is_null($this->user()); } /** diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php index 03657a2201..2d11087c7b 100644 --- a/app/Support/Export/ExportDataGenerator.php +++ b/app/Support/Export/ExportDataGenerator.php @@ -75,6 +75,9 @@ class ExportDataGenerator private Carbon $start; private User $user; + private const ADD_RECORD_ERR = 'Could not add record to set: %s'; + private const EXPORT_ERR = 'Could not export to string: %s'; + public function __construct() { $this->accounts = new Collection; @@ -142,10 +145,10 @@ class ExportDataGenerator /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $repository->setUser($this->user); - $accounts = $repository->getAccountsByType([]); - $records = []; + $allAccounts = $repository->getAccountsByType([]); + $records = []; /** @var Account $account */ - foreach ($accounts as $account) { + foreach ($allAccounts as $account) { $currency = $repository->getAccountCurrency($account); $records[] = [ $this->user->id, @@ -175,7 +178,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -184,7 +187,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -229,7 +232,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -238,7 +241,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -293,7 +296,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -302,7 +305,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -342,7 +345,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -351,7 +354,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -406,7 +409,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -415,7 +418,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -504,7 +507,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -513,7 +516,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -571,7 +574,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -580,7 +583,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -621,7 +624,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -630,7 +633,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; @@ -741,7 +744,7 @@ class ExportDataGenerator try { $csv->insertOne($header); } catch (CannotInsertRecord $e) { - throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::ADD_RECORD_ERR, $e->getMessage()), 0, $e); } //insert all the records @@ -750,7 +753,7 @@ class ExportDataGenerator try { $string = $csv->toString(); } catch (Exception $e) { - throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } return $string; diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 6692be0952..54a9be581f 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -259,9 +259,9 @@ class OperatorQuerySearch implements SearchInterface case Emoticon::class: case Emoji::class: case Mention::class: - $words = (string)$searchNode->getValue(); - Log::debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $words, $class)); - $this->words[] = $words; + $allWords = (string)$searchNode->getValue(); + Log::debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class)); + $this->words[] = $allWords; break; case Field::class: Log::debug(sprintf('Now handle Node class %s', $class)); @@ -836,11 +836,11 @@ class OperatorQuerySearch implements SearchInterface if ($parser->isDateRange($value)) { return $parser->parseRange($value, $this->date); } - $date = $parser->parseDate($value); + $parsedDate = $parser->parseDate($value); return [ - 'start' => $date, - 'end' => $date, + 'start' => $parsedDate, + 'end' => $parsedDate, ]; } diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php index 71327d2b6b..9c1e061f1f 100644 --- a/app/TransactionRules/Engine/SearchRuleEngine.php +++ b/app/TransactionRules/Engine/SearchRuleEngine.php @@ -293,11 +293,9 @@ class SearchRuleEngine implements RuleEngineInterface $journalTrigger = false; $dateTrigger = false; foreach ($array as $triggerName => $values) { - if ('journal_id' === $triggerName) { - if (is_array($values) && 1 === count($values)) { - Log::debug('Found a journal_id trigger with 1 journal, true.'); - $journalTrigger = true; - } + if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) { + Log::debug('Found a journal_id trigger with 1 journal, true.'); + $journalTrigger = true; } if (in_array($triggerName, ['date_is', 'date', 'on', 'date_before', 'before', 'date_after', 'after'], true)) { Log::debug('Found a date related trigger, set to true.'); @@ -320,11 +318,9 @@ class SearchRuleEngine implements RuleEngineInterface Log::debug('Now in setDateFromJournalTrigger()'); $journalId = 0; foreach ($array as $triggerName => $values) { - if ('journal_id' === $triggerName) { - if (is_array($values) && 1 === count($values)) { - $journalId = (int)trim(($values[0] ?? '"0"'), '"'); // follows format "123". - Log::debug(sprintf('Found journal ID #%d', $journalId)); - } + if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) { + $journalId = (int)trim(($values[0] ?? '"0"'), '"'); // follows format "123". + Log::debug(sprintf('Found journal ID #%d', $journalId)); } } if (0 !== $journalId) { diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php index 300dab679b..d75d311aeb 100644 --- a/app/Transformers/BillTransformer.php +++ b/app/Transformers/BillTransformer.php @@ -255,9 +255,7 @@ class BillTransformer extends AbstractTransformer return $date->format('Y-m-d'); } ); - $array = $simple->toArray(); - - return $array; + return $simple->toArray(); } /** diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php index dd4f1d6dbc..eed310d3a9 100644 --- a/app/Validation/RecurrenceValidation.php +++ b/app/Validation/RecurrenceValidation.php @@ -182,8 +182,6 @@ trait RecurrenceValidation if ($reps > 0 && null !== $repeatUntil) { $validator->errors()->add('nr_of_repetitions', trans('validation.require_repeat_until')); $validator->errors()->add('repeat_until', trans('validation.require_repeat_until')); - - return; } } diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 6dd17d06ed..b49a0c11e3 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -331,9 +331,8 @@ trait TransactionValidation * All types of splits must be equal. * * @param Validator $validator - * @param TransactionGroup $transactionGroup */ - public function validateTransactionTypesForUpdate(Validator $validator, TransactionGroup $transactionGroup): void + public function validateTransactionTypesForUpdate(Validator $validator): void { Log::debug('Now in validateTransactionTypesForUpdate()'); $transactions = $this->getTransactionsArray($validator); diff --git a/frontend/src/components/accounts/Index.vue b/frontend/src/components/accounts/Index.vue index a4d6d3e90e..30f4911315 100644 --- a/frontend/src/components/accounts/Index.vue +++ b/frontend/src/components/accounts/Index.vue @@ -36,8 +36,8 @@
- -