Code optimizations.

This commit is contained in:
James Cole
2018-07-23 21:49:15 +02:00
parent 4fa5f4e5a3
commit 06d22e843a
33 changed files with 784 additions and 603 deletions

View File

@@ -84,8 +84,7 @@ class RecurrenceRequest extends Request
*/ */
public function rules(): array public function rules(): array
{ {
$today = new Carbon; $today = Carbon::create()->addDay();
$today->addDay();
return [ return [
'type' => 'required|in:withdrawal,transfer,deposit', 'type' => 'required|in:withdrawal,transfer,deposit',

View File

@@ -44,7 +44,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* Generate the report. * Generate the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -51,7 +51,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
* Generates the report. * Generates the report.
* *
* @return string * @return string
* @throws FireflyException
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -64,7 +64,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
* Generates the report. * Generates the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -68,7 +68,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
* Generates the report. * Generates the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -43,7 +43,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* Generates the report. * Generates the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -42,7 +42,7 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
* Generates the report. * Generates the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -42,7 +42,7 @@ class YearReportGenerator implements ReportGeneratorInterface
* Generates the report. * Generates the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -70,8 +70,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
* Generate the report. * Generate the report.
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@@ -80,13 +80,6 @@ class VersionCheckEventHandler
// last check time was more than a week ago. // last check time was more than a week ago.
Log::debug('Have not checked for a new version in a week!'); Log::debug('Have not checked for a new version in a week!');
// have actual permission?
if ($permission->data === -1) {
// never asked before.
//session()->flash('info', (string)trans('firefly.check_for_updates_permission', ['link' => route('admin.update-check')]));
//return;
}
$latestRelease = $this->getLatestRelease(); $latestRelease = $this->getLatestRelease();
$versionCheck = $this->versionCheck($latestRelease); $versionCheck = $this->versionCheck($latestRelease);
$resultString = $this->parseResult($latestRelease, $versionCheck); $resultString = $this->parseResult($latestRelease, $versionCheck);

View File

@@ -83,7 +83,8 @@ class BudgetController extends Controller
*/ */
public function budget(Budget $budget): JsonResponse public function budget(Budget $budget): JsonResponse
{ {
$start = $this->repository->firstUseDate($budget); /** @var Carbon $start */
$start = $this->repository->firstUseDate($budget) ?? session('start', new Carbon);
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end', new Carbon); $end = session('end', new Carbon);
$cache = new CacheProperties(); $cache = new CacheProperties();

View File

@@ -274,8 +274,7 @@ class ReportController extends Controller
$attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate']); $attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate']);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Log::debug(sprintf('Not important error message: %s', $e->getMessage())); Log::debug(sprintf('Not important error message: %s', $e->getMessage()));
$date = new Carbon; $date = Carbon::create()->startOfMonth();
$date->startOfMonth();
$attributes['startDate'] = $date; $attributes['startDate'] = $date;
} }
@@ -283,8 +282,7 @@ class ReportController extends Controller
$attributes['endDate'] = Carbon::createFromFormat('Ymd', $attributes['endDate']); $attributes['endDate'] = Carbon::createFromFormat('Ymd', $attributes['endDate']);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Log::debug('Not important error message: %s', $e->getMessage()); Log::debug('Not important error message: %s', $e->getMessage());
$date = new Carbon; $date = Carbon::create()->startOfMonth();
$date->startOfMonth();
$attributes['endDate'] = $date; $attributes['endDate'] = $date;
} }

View File

@@ -262,8 +262,7 @@ class TransactionController extends Controller
{ {
$range = app('preferences')->get('viewRange', '1M')->data; $range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->repository->firstNull(); $first = $this->repository->firstNull();
$start = new Carbon; $start = Carbon::create()->subYear();
$start->subYear();
$types = config('firefly.transactionTypesByWhat.' . $what); $types = config('firefly.transactionTypesByWhat.' . $what);
$entries = new Collection; $entries = new Collection;
if (null !== $first) { if (null !== $first) {

View File

@@ -124,8 +124,7 @@ class Range
// ignore preference. set the range to be the current month: // ignore preference. set the range to be the current month:
if (!app('session')->has('start') && !app('session')->has('end')) { if (!app('session')->has('start') && !app('session')->has('end')) {
$viewRange = app('preferences')->get('viewRange', '1M')->data; $viewRange = app('preferences')->get('viewRange', '1M')->data;
$start = new Carbon; $start = app('navigation')->updateStartDate($viewRange, new Carbon);
$start = app('navigation')->updateStartDate($viewRange, $start);
$end = app('navigation')->updateEndDate($viewRange, $start); $end = app('navigation')->updateEndDate($viewRange, $start);
app('session')->put('start', $start); app('session')->put('start', $start);

View File

@@ -149,8 +149,7 @@ class RecurrenceFormRequest extends Request
public function rules(): array public function rules(): array
{ {
$today = new Carbon; $today = new Carbon;
$tomorrow = clone $today; $tomorrow = Carbon::create()->addDay();
$tomorrow->addDay();
$rules = [ $rules = [
// mandatory info for recurrence. // mandatory info for recurrence.
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title', 'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',

View File

@@ -38,6 +38,7 @@ class BroadcastServiceProvider extends ServiceProvider
{ {
Broadcast::routes(); Broadcast::routes();
/** @noinspection PhpIncludeInspection */
require base_path('routes/channels.php'); require base_path('routes/channels.php');
} }
} }

View File

@@ -23,23 +23,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Account; namespace FireflyIII\Repositories\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService; use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use FireflyIII\Services\Internal\Update\AccountUpdateService; use FireflyIII\Services\Internal\Update\AccountUpdateService;
use FireflyIII\Services\Internal\Update\JournalUpdateService;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/** /**
* Class AccountRepository. * Class AccountRepository.
*/ */
class AccountRepository implements AccountRepositoryInterface class AccountRepository implements AccountRepositoryInterface
{ {
use FindAccountsTrait;
/** @var User */ /** @var User */
private $user; private $user;
@@ -72,6 +73,89 @@ class AccountRepository implements AccountRepositoryInterface
return true; return true;
} }
/**
* @param string $number
* @param array $types
*
* @return Account|null
*/
public function findByAccountNumber(string $number, array $types): ?Account
{
$query = $this->user->accounts()
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
->where('account_meta.name', 'accountNumber')
->where('account_meta.data', json_encode($number));
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
/** @var Collection $accounts */
$accounts = $query->get(['accounts.*']);
if ($accounts->count() > 0) {
return $accounts->first();
}
return null;
}
/**
* @param string $iban
* @param array $types
*
* @return Account|null
*/
public function findByIbanNull(string $iban, array $types): ?Account
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->iban === $iban) {
return $account;
}
}
return null;
}
/**
* @param string $name
* @param array $types
*
* @return Account|null
*/
public function findByName(string $name, array $types): ?Account
{
$query = $this->user->accounts();
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name) {
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
return $account;
}
}
Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
return null;
}
/** /**
* @param int $accountId * @param int $accountId
* *
@@ -82,6 +166,96 @@ class AccountRepository implements AccountRepositoryInterface
return $this->user->accounts()->find($accountId); return $this->user->accounts()->find($accountId);
} }
/**
* @param array $accountIds
*
* @return Collection
*/
public function getAccountsById(array $accountIds): Collection
{
/** @var Collection $result */
$query = $this->user->accounts();
if (\count($accountIds) > 0) {
$query->whereIn('accounts.id', $accountIds);
}
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @param array $types
*
* @return Collection
*/
public function getAccountsByType(array $types): Collection
{
/** @var Collection $result */
$query = $this->user->accounts();
if (\count($types) > 0) {
$query->accountTypeIn($types);
}
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @param array $types
*
* @return Collection
*/
public function getActiveAccountsByType(array $types): Collection
{
/** @var Collection $result */
$query = $this->user->accounts()->with(
['accountmeta' => function (HasMany $query) {
$query->where('name', 'accountRole');
}]
);
if (\count($types) > 0) {
$query->accountTypeIn($types);
}
$query->where('active', 1);
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @return Account
*
* @throws FireflyException
*/
public function getCashAccount(): Account
{
/** @var AccountType $type */
$type = AccountType::where('type', AccountType::CASH)->first();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user);
return $factory->findOrCreate('Cash account', $type->type);
}
/** /**
* Return meta value for account. Null if not found. * Return meta value for account. Null if not found.
* *
@@ -163,11 +337,41 @@ class AccountRepository implements AccountRepositoryInterface
return $journal->date->format('Y-m-d'); return $journal->date->format('Y-m-d');
} }
/**
* @param Account $account
*
* @return Account|null
*
* @throws FireflyException
*/
public function getReconciliation(Account $account): ?Account
{
if (AccountType::ASSET !== $account->accountType->type) {
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
}
$name = $account->name . ' reconciliation';
/** @var AccountType $type */
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
$accounts = $this->user->accounts()->where('account_type_id', $type->id)->get();
/** @var Account $current */
foreach ($accounts as $current) {
if ($current->name === $name) {
return $current;
}
}
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($account->user);
$account = $factory->findOrCreate($name, $type->type);
return $account;
}
/** /**
* Returns the date of the very first transaction in this account. * Returns the date of the very first transaction in this account.
* *
* @param Account $account * @param Account $account
* * @deprecated
* @return TransactionJournal * @return TransactionJournal
*/ */
public function oldestJournal(Account $account): TransactionJournal public function oldestJournal(Account $account): TransactionJournal

View File

@@ -164,7 +164,7 @@ interface AccountRepositoryInterface
* Returns the date of the very first transaction in this account. * Returns the date of the very first transaction in this account.
* *
* @param Account $account * @param Account $account
* * @deprecated
* @return TransactionJournal * @return TransactionJournal
*/ */
public function oldestJournal(Account $account): TransactionJournal; public function oldestJournal(Account $account): TransactionJournal;

View File

@@ -1,248 +0,0 @@
<?php
/**
* FindAccountsTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\Account;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
use Log;
/**
* @property User $user
*
* Trait FindAccountsTrait
*/
trait FindAccountsTrait
{
/**
* @param string $number
* @param array $types
*
* @return Account|null
*/
public function findByAccountNumber(string $number, array $types): ?Account
{
$query = $this->user->accounts()
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
->where('account_meta.name', 'accountNumber')
->where('account_meta.data', json_encode($number));
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
/** @var Collection $accounts */
$accounts = $query->get(['accounts.*']);
if ($accounts->count() > 0) {
return $accounts->first();
}
return null;
}
/**
* @param string $iban
* @param array $types
*
* @return Account|null
*/
public function findByIbanNull(string $iban, array $types): ?Account
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->iban === $iban) {
return $account;
}
}
return null;
}
/**
* @param string $name
* @param array $types
*
* @return Account|null
*/
public function findByName(string $name, array $types): ?Account
{
$query = $this->user->accounts();
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name) {
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
return $account;
}
if ($account->name !== $name) {
Log::debug(sprintf('"%s" does not equal "%s"', $account->name, $name));
}
}
Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
return null;
}
/**
* @param array $accountIds
*
* @return Collection
*/
public function getAccountsById(array $accountIds): Collection
{
/** @var Collection $result */
$query = $this->user->accounts();
if (\count($accountIds) > 0) {
$query->whereIn('accounts.id', $accountIds);
}
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @param array $types
*
* @return Collection
*/
public function getAccountsByType(array $types): Collection
{
/** @var Collection $result */
$query = $this->user->accounts();
if (\count($types) > 0) {
$query->accountTypeIn($types);
}
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @param array $types
*
* @return Collection
*/
public function getActiveAccountsByType(array $types): Collection
{
/** @var Collection $result */
$query = $this->user->accounts()->with(
['accountmeta' => function (HasMany $query) {
$query->where('name', 'accountRole');
}]
);
if (\count($types) > 0) {
$query->accountTypeIn($types);
}
$query->where('active', 1);
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @return Account
*
* @throws FireflyException
*/
public function getCashAccount(): Account
{
/** @var AccountType $type */
$type = AccountType::where('type', AccountType::CASH)->first();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user);
return $factory->findOrCreate('Cash account', $type->type);
}
/**
* @param Account $account
*
* @return Account|null
*
* @throws FireflyException
*/
public function getReconciliation(Account $account): ?Account
{
if (AccountType::ASSET !== $account->accountType->type) {
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
}
$name = $account->name . ' reconciliation';
/** @var AccountType $type */
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
$accounts = $this->user->accounts()->where('account_type_id', $type->id)->get();
/** @var Account $current */
foreach ($accounts as $current) {
if ($current->name === $name) {
return $current;
}
}
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($account->user);
$account = $factory->findOrCreate($name, $type->type);
return $account;
}
}

View File

@@ -80,14 +80,14 @@ class AttachmentRepository implements AttachmentRepositoryInterface
} }
/** /**
* @param int $id * @param int $attachmentId
* * @deprecated
* @return Attachment * @return Attachment
*/ */
public function findWithoutUser(int $id): Attachment public function findWithoutUser(int $attachmentId): Attachment
{ {
$attachment = Attachment::find($id); $attachment = Attachment::find($attachmentId);
if (null === $attachment) { if (null === $attachment) {
return new Attachment; return new Attachment;
} }

View File

@@ -49,11 +49,11 @@ interface AttachmentRepositoryInterface
public function exists(Attachment $attachment): bool; public function exists(Attachment $attachment): bool;
/** /**
* @param int $id * @param int $attachmentId
* * @deprecated
* @return Attachment * @return Attachment
*/ */
public function findWithoutUser(int $id): Attachment; public function findWithoutUser(int $attachmentId): Attachment;
/** /**
* @return Collection * @return Collection

View File

@@ -136,21 +136,8 @@ class BillRepository implements BillRepositoryInterface
*/ */
public function getBillsForAccounts(Collection $accounts): Collection public function getBillsForAccounts(Collection $accounts): Collection
{ {
$fields = ['bills.id', $fields = ['bills.id', 'bills.created_at', 'bills.updated_at', 'bills.deleted_at', 'bills.user_id', 'bills.name', 'bills.match', 'bills.amount_min',
'bills.created_at', 'bills.amount_max', 'bills.date', 'bills.repeat_freq', 'bills.skip', 'bills.automatch', 'bills.active', 'bills.name_encrypted',
'bills.updated_at',
'bills.deleted_at',
'bills.user_id',
'bills.name',
'bills.match',
'bills.amount_min',
'bills.amount_max',
'bills.date',
'bills.repeat_freq',
'bills.skip',
'bills.automatch',
'bills.active',
'bills.name_encrypted',
'bills.match_encrypted',]; 'bills.match_encrypted',];
$ids = $accounts->pluck('id')->toArray(); $ids = $accounts->pluck('id')->toArray();
$set = $this->user->bills() $set = $this->user->bills()
@@ -336,28 +323,22 @@ class BillRepository implements BillRepositoryInterface
public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
{ {
$set = new Collection; $set = new Collection;
Log::debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
// Start at 2016-10-01, see when we expect the bill to hit:
$currentStart = clone $start; $currentStart = clone $start;
Log::debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
Log::debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d'))); Log::debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
while ($currentStart <= $end) { while ($currentStart <= $end) {
Log::debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d'))); Log::debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
$nextExpectedMatch = $this->nextDateMatch($bill, $currentStart); $nextExpectedMatch = $this->nextDateMatch($bill, $currentStart);
Log::debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d'))); Log::debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
// If nextExpectedMatch is after end, we continue: if ($nextExpectedMatch > $end) {// If nextExpectedMatch is after end, we continue
if ($nextExpectedMatch > $end) {
Log::debug( Log::debug(
sprintf('nextExpectedMatch %s is after %s, so we skip this bill now.', $nextExpectedMatch->format('Y-m-d'), $end->format('Y-m-d')) sprintf('nextExpectedMatch %s is after %s, so we skip this bill now.', $nextExpectedMatch->format('Y-m-d'), $end->format('Y-m-d'))
); );
break; break;
} }
// add to set
$set->push(clone $nextExpectedMatch); $set->push(clone $nextExpectedMatch);
Log::debug(sprintf('Now %d dates in set.', $set->count())); Log::debug(sprintf('Now %d dates in set.', $set->count()));
// add day if necessary.
$nextExpectedMatch->addDay(); $nextExpectedMatch->addDay();
Log::debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d'))); Log::debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));

View File

@@ -85,6 +85,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/** /**
* @return bool * @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 5.
*/ */
public function cleanupBudgets(): bool public function cleanupBudgets(): bool
{ {
@@ -123,6 +124,8 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param Carbon $end * @param Carbon $end
* *
* @return array * @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
{ {
@@ -138,7 +141,6 @@ class BudgetRepository implements BudgetRepositoryInterface
$return[$budgetId] = [ $return[$budgetId] = [
'spent' => $this->spentInPeriod(new Collection([$budget]), $accounts, $start, $end), 'spent' => $this->spentInPeriod(new Collection([$budget]), $accounts, $start, $end),
'budgeted' => '0', 'budgeted' => '0',
'currentRep' => false,
]; ];
$budgetLimits = $this->getBudgetLimits($budget, $start, $end); $budgetLimits = $this->getBudgetLimits($budget, $start, $end);
$otherLimits = new Collection; $otherLimits = new Collection;
@@ -244,12 +246,11 @@ class BudgetRepository implements BudgetRepositoryInterface
* Will cache result. * Will cache result.
* *
* @param Budget $budget * @param Budget $budget
*
* @return Carbon * @return Carbon
*/ */
public function firstUseDate(Budget $budget): Carbon public function firstUseDate(Budget $budget): ?Carbon
{ {
$oldest = Carbon::create()->startOfYear(); $oldest = null;
$journal = $budget->transactionJournals()->orderBy('date', 'ASC')->first(); $journal = $budget->transactionJournals()->orderBy('date', 'ASC')->first();
if (null !== $journal) { if (null !== $journal) {
$oldest = $journal->date < $oldest ? $journal->date : $oldest; $oldest = $journal->date < $oldest ? $journal->date : $oldest;

View File

@@ -105,7 +105,7 @@ interface BudgetRepositoryInterface
* *
* @return Carbon * @return Carbon
*/ */
public function firstUseDate(Budget $budget): Carbon; public function firstUseDate(Budget $budget): ?Carbon;
/** /**
* @return Collection * @return Collection

View File

@@ -81,6 +81,7 @@ class ExportJobRepository implements ExportJobRepositoryInterface
/** /**
* @return ExportJob * @return ExportJob
* @deprecated
*/ */
public function create(): ExportJob public function create(): ExportJob
{ {
@@ -120,6 +121,7 @@ class ExportJobRepository implements ExportJobRepositoryInterface
/** /**
* @param string $key * @param string $key
*
* @deprecated * @deprecated
* @return ExportJob * @return ExportJob
*/ */

View File

@@ -45,6 +45,7 @@ interface ExportJobRepositoryInterface
/** /**
* @return ExportJob * @return ExportJob
* @deprecated
*/ */
public function create(): ExportJob; public function create(): ExportJob;
@@ -57,6 +58,7 @@ interface ExportJobRepositoryInterface
/** /**
* @param string $key * @param string $key
*
* @deprecated * @deprecated
* @return ExportJob * @return ExportJob
*/ */

View File

@@ -27,14 +27,11 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag; use Illuminate\Support\MessageBag;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Log; use Log;
use SplFileObject;
use Storage; use Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -118,6 +115,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
* @param string $key * @param string $key
* *
* @return ImportJob * @return ImportJob
* @deprecated
*/ */
public function findByKey(string $key): ImportJob public function findByKey(string $key): ImportJob
{ {

View File

@@ -56,6 +56,7 @@ interface ImportJobRepositoryInterface
* @param string $key * @param string $key
* *
* @return ImportJob * @return ImportJob
* @deprecated
*/ */
public function findByKey(string $key): ImportJob; public function findByKey(string $key): ImportJob;

View File

@@ -193,122 +193,34 @@ class RecurringRepository implements RecurringRepositoryInterface
*/ */
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array
{ {
$return = []; $occurrences = [];
$mutator = clone $start; $mutator = clone $start;
$mutator->startOfDay(); $mutator->startOfDay();
$skipMod = $repetition->repetition_skip + 1; $skipMod = $repetition->repetition_skip + 1;
$attempts = 0;
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type)); Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d'))); Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
switch ($repetition->repetition_type) {
default:
throw new FireflyException(
sprintf('Cannot calculate occurrences for recurring transaction repetition type "%s"', $repetition->repetition_type)
);
case 'daily':
Log::debug('Rep is daily. Start of loop.');
while ($mutator <= $end) {
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
if (0 === $attempts % $skipMod) {
Log::debug(sprintf('Attempts modulo skipmod is zero, include %s', $mutator->format('Y-m-d')));
$return[] = clone $mutator;
}
$mutator->addDay();
$attempts++;
}
break;
case 'weekly':
Log::debug('Rep is weekly.');
// monday = 1
// sunday = 7
$dayOfWeek = (int)$repetition->repetition_moment;
Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $mutator->dayOfWeekIso));
if ($mutator->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
$mutator->addWeek();
Log::debug(sprintf('Jump to next week, so mutator is now: %s', $mutator->format('Y-m-d')));
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
$dayDifference = $dayOfWeek - $mutator->dayOfWeekIso;
$mutator->addDays($dayDifference);
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
while ($mutator <= $end) {
if (0 === $attempts % $skipMod && $start->lte($mutator) && $end->gte($mutator)) {
Log::debug('Date is in range of start+end, add to set.');
$return[] = clone $mutator;
}
$attempts++;
$mutator->addWeek();
Log::debug(sprintf('Mutator is now (end of loop): %s', $mutator->format('Y-m-d')));
}
break;
case 'monthly':
$dayOfMonth = (int)$repetition->repetition_moment;
Log::debug(sprintf('Day of month in repetition is %d', $dayOfMonth));
Log::debug(sprintf('Start is %s.', $start->format('Y-m-d')));
Log::debug(sprintf('End is %s.', $end->format('Y-m-d')));
if ($mutator->day > $dayOfMonth) {
Log::debug('Add a month.');
// day has passed already, add a month.
$mutator->addMonth();
}
Log::debug(sprintf('Start is now %s.', $mutator->format('Y-m-d')));
Log::debug('Start loop.');
while ($mutator < $end) {
Log::debug(sprintf('Mutator is now %s.', $mutator->format('Y-m-d')));
$domCorrected = min($dayOfMonth, $mutator->daysInMonth);
Log::debug(sprintf('DoM corrected is %d', $domCorrected));
$mutator->day = $domCorrected;
Log::debug(sprintf('Mutator is now %s.', $mutator->format('Y-m-d')));
Log::debug(sprintf('$attempts %% $skipMod === 0 is %s', var_export(0 === $attempts % $skipMod, true)));
Log::debug(sprintf('$start->lte($mutator) is %s', var_export($start->lte($mutator), true)));
Log::debug(sprintf('$end->gte($mutator) is %s', var_export($end->gte($mutator), true)));
if (0 === $attempts % $skipMod && $start->lte($mutator) && $end->gte($mutator)) {
Log::debug(sprintf('ADD %s to return!', $mutator->format('Y-m-d')));
$return[] = clone $mutator;
}
$attempts++;
$mutator->endOfMonth()->startOfDay()->addDay();
}
break;
case 'ndom':
$mutator->startOfMonth();
// this feels a bit like a cop out but why reinvent the wheel?
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth',];
$daysOfWeek = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday',];
$parts = explode(',', $repetition->repetition_moment);
while ($mutator <= $end) {
$string = sprintf('%s %s of %s %s', $counters[$parts[0]], $daysOfWeek[$parts[1]], $mutator->format('F'), $mutator->format('Y'));
$newCarbon = new Carbon($string);
$return[] = clone $newCarbon;
$mutator->endOfMonth()->addDay();
}
break;
case 'yearly':
$date = new Carbon($repetition->repetition_moment);
$date->year = $mutator->year;
if ($mutator > $date) {
$date->addYear();
} if ('daily' === $repetition->repetition_type) {
$occurrences = $this->getDailyInRange($mutator, $end, $skipMod);
// is $date between $start and $end? }
$obj = clone $date; if ('weekly' === $repetition->repetition_type) {
$count = 0; $occurrences = $this->getWeeklyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
while ($obj <= $end && $obj >= $mutator && $count < 10) { }
if ('monthly' === $repetition->repetition_type) {
$return[] = clone $obj; $occurrences = $this->getMonthlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
$obj->addYears(1); }
$count++; if ('ndom' === $repetition->repetition_type) {
} $occurrences = $this->getNdomInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
break; }
if ('yearly' === $repetition->repetition_type) {
$occurrences = $this->getYearlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
} }
// filter out all the weekend days:
$return = $this->filterWeekends($repetition, $return);
return $return;
// filter out all the weekend days:
$occurrences = $this->filterWeekends($repetition, $occurrences);
return $occurrences;
} }
/** /**
@@ -399,112 +311,31 @@ class RecurringRepository implements RecurringRepositoryInterface
* @param int $count * @param int $count
* *
* @return array * @return array
* @throws FireflyException
*/ */
public function getXOccurrences(RecurrenceRepetition $repetition, Carbon $date, int $count): array public function getXOccurrences(RecurrenceRepetition $repetition, Carbon $date, int $count): array
{ {
$return = []; $skipMod = $repetition->repetition_skip + 1;
$mutator = clone $date; $occurrences = [];
$skipMod = $repetition->repetition_skip + 1; if ('daily' === $repetition->repetition_type) {
$total = 0; $occurrences = $this->getXDailyOccurrences($date, $count, $skipMod);
$attempts = 0; }
switch ($repetition->repetition_type) { if ('weekly' === $repetition->repetition_type) {
default: $occurrences = $this->getXWeeklyOccurrences($date, $count, $skipMod, $repetition->repetition_moment);
throw new FireflyException( }
sprintf('Cannot calculate occurrences for recurring transaction repetition type "%s"', $repetition->repetition_type) if ('monthly' === $repetition->repetition_type) {
); $occurrences = $this->getXMonthlyOccurrences($date, $count, $skipMod, $repetition->repetition_moment);
case 'daily': }
while ($total < $count) { if ('ndom' === $repetition->repetition_type) {
$mutator->addDay(); $occurrences = $this->getXNDomOccurrences($date, $count, $skipMod, $repetition->repetition_moment);
if (0 === $attempts % $skipMod) { }
$return[] = clone $mutator; if ('yearly' === $repetition->repetition_type) {
$total++; $occurrences = $this->getXYearlyOccurrences($date, $count, $skipMod, $repetition->repetition_moment);
}
$attempts++;
}
break;
case 'weekly':
// monday = 1
// sunday = 7
$mutator->addDay(); // always assume today has passed.
$dayOfWeek = (int)$repetition->repetition_moment;
if ($mutator->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
$mutator->addWeek();
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
$dayDifference = $dayOfWeek - $mutator->dayOfWeekIso;
$mutator->addDays($dayDifference);
while ($total < $count) {
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
}
$attempts++;
$mutator->addWeek();
}
break;
case 'monthly':
$mutator->addDay(); // always assume today has passed.
$dayOfMonth = (int)$repetition->repetition_moment;
if ($mutator->day > $dayOfMonth) {
// day has passed already, add a month.
$mutator->addMonth();
}
while ($total < $count) {
$domCorrected = min($dayOfMonth, $mutator->daysInMonth);
$mutator->day = $domCorrected;
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
}
$attempts++;
$mutator->endOfMonth()->addDay();
}
break;
case 'ndom':
$mutator->addDay(); // always assume today has passed.
$mutator->startOfMonth();
// this feels a bit like a cop out but why reinvent the wheel?
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth',];
$daysOfWeek = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday',];
$parts = explode(',', $repetition->repetition_moment);
while ($total < $count) {
$string = sprintf('%s %s of %s %s', $counters[$parts[0]], $daysOfWeek[$parts[1]], $mutator->format('F'), $mutator->format('Y'));
$newCarbon = new Carbon($string);
if (0 === $attempts % $skipMod) {
$return[] = clone $newCarbon;
$total++;
}
$attempts++;
$mutator->endOfMonth()->addDay();
}
break;
case 'yearly':
$date = new Carbon($repetition->repetition_moment);
$date->year = $mutator->year;
if ($mutator > $date) {
$date->addYear();
}
$obj = clone $date;
while ($total < $count) {
if (0 === $attempts % $skipMod) {
$return[] = clone $obj;
$total++;
}
$obj->addYears(1);
$attempts++;
}
break;
} }
// filter out all the weekend days:
$return = $this->filterWeekends($repetition, $return);
return $return; // filter out all the weekend days:
$occurrences = $this->filterWeekends($repetition, $occurrences);
return $occurrences;
} }
/** /**
@@ -545,8 +376,7 @@ class RecurringRepository implements RecurringRepositoryInterface
break; break;
case 'yearly': case 'yearly':
// //
$today = new Carbon; $today = Carbon::create()->endOfYear();
$today->endOfYear();
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment); $repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
$diffInYears = $today->diffInYears($repDate); $diffInYears = $today->diffInYears($repDate);
$repDate->addYears($diffInYears); // technically not necessary. $repDate->addYears($diffInYears); // technically not necessary.
@@ -658,4 +488,378 @@ class RecurringRepository implements RecurringRepositoryInterface
return $return; return $return;
} }
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
*
* @return array
*/
private function getDailyInRange(Carbon $start, Carbon $end, int $skipMod): array
{
$return = [];
$attempts = 0;
Log::debug('Rep is daily. Start of loop.');
while ($start <= $end) {
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
if (0 === $attempts % $skipMod) {
Log::debug(sprintf('Attempts modulo skipmod is zero, include %s', $start->format('Y-m-d')));
$return[] = clone $start;
}
$start->addDay();
$attempts++;
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getMonthlyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
$return = [];
$attempts = 0;
$dayOfMonth = (int)$moment;
Log::debug(sprintf('Day of month in repetition is %d', $dayOfMonth));
Log::debug(sprintf('Start is %s.', $start->format('Y-m-d')));
Log::debug(sprintf('End is %s.', $end->format('Y-m-d')));
if ($start->day > $dayOfMonth) {
Log::debug('Add a month.');
// day has passed already, add a month.
$start->addMonth();
}
Log::debug(sprintf('Start is now %s.', $start->format('Y-m-d')));
Log::debug('Start loop.');
while ($start < $end) {
Log::debug(sprintf('Mutator is now %s.', $start->format('Y-m-d')));
$domCorrected = min($dayOfMonth, $start->daysInMonth);
Log::debug(sprintf('DoM corrected is %d', $domCorrected));
$start->day = $domCorrected;
Log::debug(sprintf('Mutator is now %s.', $start->format('Y-m-d')));
Log::debug(sprintf('$attempts %% $skipMod === 0 is %s', var_export(0 === $attempts % $skipMod, true)));
Log::debug(sprintf('$start->lte($mutator) is %s', var_export($start->lte($start), true)));
Log::debug(sprintf('$end->gte($mutator) is %s', var_export($end->gte($start), true)));
if (0 === $attempts % $skipMod && $start->lte($start) && $end->gte($start)) {
Log::debug(sprintf('ADD %s to return!', $start->format('Y-m-d')));
$return[] = clone $start;
}
$attempts++;
$start->endOfMonth()->startOfDay()->addDay();
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getNdomInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
$return = [];
$attempts = 0;
$start->startOfMonth();
// this feels a bit like a cop out but why reinvent the wheel?
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth',];
$daysOfWeek = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday',];
$parts = explode(',', $moment);
while ($start <= $end) {
$string = sprintf('%s %s of %s %s', $counters[$parts[0]], $daysOfWeek[$parts[1]], $start->format('F'), $start->format('Y'));
$newCarbon = new Carbon($string);
if (0 === $attempts % $skipMod) {
$return[] = clone $newCarbon;
}
$attempts++;
$start->endOfMonth()->addDay();
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getWeeklyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
$return = [];
$attempts = 0;
Log::debug('Rep is weekly.');
// monday = 1
// sunday = 7
$dayOfWeek = (int)$moment;
Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso));
if ($start->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
$start->addWeek();
Log::debug(sprintf('Jump to next week, so mutator is now: %s', $start->format('Y-m-d')));
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
$dayDifference = $dayOfWeek - $start->dayOfWeekIso;
$start->addDays($dayDifference);
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
while ($start <= $end) {
if (0 === $attempts % $skipMod && $start->lte($start) && $end->gte($start)) {
Log::debug('Date is in range of start+end, add to set.');
$return[] = clone $start;
}
$attempts++;
$start->addWeek();
Log::debug(sprintf('Mutator is now (end of loop): %s', $start->format('Y-m-d')));
}
return $return;
}
/**
* Calculates the number of daily occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip
* over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
*
* @return array
*/
private function getXDailyOccurrences(Carbon $date, int $count, int $skipMod): array
{
$return = [];
$mutator = clone $date;
$total = 0;
$attempts = 0;
while ($total < $count) {
$mutator->addDay();
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
}
$attempts++;
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Calculates the number of monthly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip
* over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getXMonthlyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
$return = [];
$mutator = clone $date;
$total = 0;
$attempts = 0;
$mutator->addDay(); // always assume today has passed.
$dayOfMonth = (int)$moment;
if ($mutator->day > $dayOfMonth) {
// day has passed already, add a month.
$mutator->addMonth();
}
while ($total < $count) {
$domCorrected = min($dayOfMonth, $mutator->daysInMonth);
$mutator->day = $domCorrected;
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
}
$attempts++;
$mutator->endOfMonth()->addDay();
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Calculates the number of NDOM occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip
* over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getXNDomOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
$return = [];
$total = 0;
$attempts = 0;
$mutator = clone $date;
$mutator->addDay(); // always assume today has passed.
$mutator->startOfMonth();
// this feels a bit like a cop out but why reinvent the wheel?
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth',];
$daysOfWeek = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday',];
$parts = explode(',', $moment);
while ($total < $count) {
$string = sprintf('%s %s of %s %s', $counters[$parts[0]], $daysOfWeek[$parts[1]], $mutator->format('F'), $mutator->format('Y'));
$newCarbon = new Carbon($string);
if (0 === $attempts % $skipMod) {
$return[] = clone $newCarbon;
$total++;
}
$attempts++;
$mutator->endOfMonth()->addDay();
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Calculates the number of weekly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip
* over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getXWeeklyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
$return = [];
$total = 0;
$attempts = 0;
$mutator = clone $date;
// monday = 1
// sunday = 7
$mutator->addDay(); // always assume today has passed.
$dayOfWeek = (int)$moment;
if ($mutator->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
$mutator->addWeek();
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
$dayDifference = $dayOfWeek - $mutator->dayOfWeekIso;
$mutator->addDays($dayDifference);
while ($total < $count) {
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
}
$attempts++;
$mutator->addWeek();
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Calculates the number of yearly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip
* over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getXYearlyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
$return = [];
$mutator = clone $date;
$total = 0;
$attempts = 0;
$date = new Carbon($moment);
$date->year = $mutator->year;
if ($mutator > $date) {
$date->addYear();
}
$obj = clone $date;
while ($total < $count) {
if (0 === $attempts % $skipMod) {
$return[] = clone $obj;
$total++;
}
$obj->addYears(1);
$attempts++;
}
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*/
private function getYearlyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
$attempts = 0;
$date = new Carbon($moment);
$date->year = $start->year;
$return = [];
if ($start > $date) {
$date->addYear();
}
// is $date between $start and $end?
$obj = clone $date;
$count = 0;
while ($obj <= $end && $obj >= $start && $count < 10) {
if (0 === $attempts % $skipMod) {
$return[] = clone $obj;
}
$obj->addYears(1);
$count++;
$attempts++;
}
return $return;
}
} }

View File

@@ -27,7 +27,6 @@ use DB;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter; use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
@@ -101,6 +100,7 @@ class TagRepository implements TagRepositoryInterface
* @param string $tag * @param string $tag
* *
* @return Tag * @return Tag
* @deprecated
*/ */
public function findByTag(string $tag): Tag public function findByTag(string $tag): Tag
{ {
@@ -129,6 +129,7 @@ class TagRepository implements TagRepositoryInterface
* @param Tag $tag * @param Tag $tag
* *
* @return Carbon * @return Carbon
* @deprecated
*/ */
public function firstUseDate(Tag $tag): Carbon public function firstUseDate(Tag $tag): Carbon
{ {
@@ -160,6 +161,7 @@ class TagRepository implements TagRepositoryInterface
* @param Tag $tag * @param Tag $tag
* *
* @return Carbon * @return Carbon
* @deprecated
*/ */
public function lastUseDate(Tag $tag): Carbon public function lastUseDate(Tag $tag): Carbon
{ {
@@ -306,9 +308,7 @@ class TagRepository implements TagRepositoryInterface
} }
if (null !== $year) { if (null !== $year) {
Log::debug(sprintf('Get tags with year %s.', $year)); Log::debug(sprintf('Get tags with year %s.', $year));
$start = $year . '-01-01 00:00:00'; $tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59');
$end = $year . '-12-31 23:59:59';
$tagQuery->where('tags.date', '>=', $start)->where('tags.date', '<=', $end);
} }
$result = $tagQuery->get(['tags.id', 'tags.tag', DB::raw('SUM(transactions.amount) as amount_sum')]); $result = $tagQuery->get(['tags.id', 'tags.tag', DB::raw('SUM(transactions.amount) as amount_sum')]);

View File

@@ -24,7 +24,6 @@ namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -68,6 +67,7 @@ interface TagRepositoryInterface
* @param string $tag * @param string $tag
* *
* @return Tag * @return Tag
* @deprecated
*/ */
public function findByTag(string $tag): Tag; public function findByTag(string $tag): Tag;
@@ -82,6 +82,7 @@ interface TagRepositoryInterface
* @param Tag $tag * @param Tag $tag
* *
* @return Carbon * @return Carbon
* @deprecated
*/ */
public function firstUseDate(Tag $tag): Carbon; public function firstUseDate(Tag $tag): Carbon;
@@ -96,6 +97,7 @@ interface TagRepositoryInterface
* @param Tag $tag * @param Tag $tag
* *
* @return Carbon * @return Carbon
* @deprecated
*/ */
public function lastUseDate(Tag $tag): Carbon; public function lastUseDate(Tag $tag): Carbon;

View File

@@ -49,12 +49,14 @@ class ExpandedForm
{ {
/** /**
* @param string $name * @param string $name
* @param null $options * @param mixed $value
* @param array $options
* *
* @return string * @return string
*/ */
public function activeAssetAccountList(string $name, $value = null, array $options = []): string public function activeAssetAccountList(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
// make repositories // make repositories
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
@@ -87,26 +89,28 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function amount(string $name, $value = null, array $options = []): string public function amount(string $name, $value = null, array $options = null): string
{ {
return $this->currencyField($name, 'amount', $value, $options); return $this->currencyField($name, 'amount', $value, $options);
} }
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function amountNoCurrency(string $name, $value = null, array $options = []): string public function amountNoCurrency(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -126,24 +130,25 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function amountSmall(string $name, $value = null, array $options = []): string public function amountSmall(string $name, $value = null, array $options = null): string
{ {
return $this->currencyField($name, 'amount-small', $value, $options); return $this->currencyField($name, 'amount-small', $value, $options);
} }
/** /**
* @param string $name * @param string $name
* @param null $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function assetAccountCheckList(string $name, $options = null): string public function assetAccountCheckList(string $name, array $options = null): string
{ {
$options = $options ?? []; $options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
@@ -175,13 +180,14 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
*/ */
public function assetAccountList(string $name, $value = null, array $options = []): string public function assetAccountList(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
// make repositories // make repositories
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
@@ -195,9 +201,9 @@ class ExpandedForm
/** @var Account $account */ /** @var Account $account */
foreach ($assetAccounts as $account) { foreach ($assetAccounts as $account) {
$balance = app('steam')->balance($account, new Carbon); $balance = app('steam')->balance($account, new Carbon);
$currencyId = (int)$repository->getMetaValue($account,'currency_id'); $currencyId = (int)$repository->getMetaValue($account, 'currency_id');
$currency = $currencyRepos->findNull($currencyId); $currency = $currencyRepos->findNull($currencyId);
$role = $repository->getMetaValue($account,'accountRole'); $role = $repository->getMetaValue($account, 'accountRole');
if (0 === \strlen($role)) { if (0 === \strlen($role)) {
$role = 'no_account_type'; // @codeCoverageIgnore $role = 'no_account_type'; // @codeCoverageIgnore
} }
@@ -215,27 +221,31 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function balance(string $name, $value = null, array $options = []): string public function balance(string $name, $value = null, array $options = null): string
{ {
return $this->currencyField($name, 'balance', $value, $options); return $this->currencyField($name, 'balance', $value, $options);
} }
/** @noinspection MoreThanThreeArgumentsInspection */
/** /**
* @param string $name * @param string $name
* @param int $value * @param int $value
* @param null $checked * @param mixed $checked
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function checkbox(string $name, $value = 1, $checked = null, $options = []): string public function checkbox(string $name, int $value = null, $checked = null, array $options = null): string
{ {
$options = $options ?? [];
$value = $value ?? 1;
$options['checked'] = true === $checked ? true : false; $options['checked'] = true === $checked ? true : false;
if (Session::has('preFilled')) { if (Session::has('preFilled')) {
@@ -257,13 +267,14 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
*/ */
public function currencyList(string $name, $value = null, array $options = []): string public function currencyList(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class); $currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -274,20 +285,20 @@ class ExpandedForm
foreach ($list as $currency) { foreach ($list as $currency) {
$array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')'; $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
} }
$res = $this->select($name, $array, $value, $options);
return $res; return $this->select($name, $array, $value, $options);
} }
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
*/ */
public function currencyListEmpty(string $name, $value = null, array $options = []): string public function currencyListEmpty(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class); $currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -307,13 +318,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function date(string $name, $value = null, array $options = []): string public function date(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -329,9 +342,11 @@ class ExpandedForm
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function file(string $name, array $options = []): string public function file(string $name, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -342,13 +357,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function integer(string $name, $value = null, array $options = []): string public function integer(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -361,13 +378,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function location(string $name, $value = null, array $options = []): string public function location(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -430,16 +449,21 @@ class ExpandedForm
return $selectList; return $selectList;
} }
/** @noinspection MoreThanThreeArgumentsInspection */
/** /**
* @param string $name * @param string $name
* @param array $list * @param array $list
* @param null $selected * @param mixed $selected
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function multiRadio(string $name, array $list = [], $selected = null, array $options = []): string public function multiRadio(string $name, array $list = null, $selected = null, array $options = null): string
{ {
$options = $options ?? [];
$list = $list ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -453,14 +477,16 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
public function nonSelectableAmount(string $name, $value = null, array $options = []): string public function nonSelectableAmount(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -481,14 +507,16 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
public function nonSelectableBalance(string $name, $value = null, array $options = []): string public function nonSelectableBalance(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -510,13 +538,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function number(string $name, $value = null, array $options = []): string public function number(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -534,12 +564,11 @@ class ExpandedForm
* @param string $name * @param string $name
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function optionsList(string $type, string $name): string public function optionsList(string $type, string $name): string
{ {
$html = view('form.options', compact('type', 'name'))->render(); return view('form.options', compact('type', 'name'))->render();
return $html;
} }
/** /**
@@ -547,9 +576,11 @@ class ExpandedForm
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function password(string $name, array $options = null): string public function password(string $name, array $options = null): string
{ {
$options = $options ?? []; $options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
@@ -561,7 +592,7 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
@@ -586,13 +617,14 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
*/ */
public function ruleGroupList(string $name, $value = null, array $options = []): string public function ruleGroupList(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
/** @var RuleGroupRepositoryInterface $groupRepos */ /** @var RuleGroupRepositoryInterface $groupRepos */
$groupRepos = app(RuleGroupRepositoryInterface::class); $groupRepos = app(RuleGroupRepositoryInterface::class);
@@ -609,12 +641,12 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param null $options * @param array $options
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
public function ruleGroupListWithEmpty(string $name, $value = null, $options = null) public function ruleGroupListWithEmpty(string $name, $value = null, array $options = null)
{ {
$options = $options ?? []; $options = $options ?? [];
$options['class'] = 'form-control'; $options['class'] = 'form-control';
@@ -636,16 +668,20 @@ class ExpandedForm
return Form::select($name, $array, $value, $options); return Form::select($name, $array, $value, $options);
} }
/** @noinspection MoreThanThreeArgumentsInspection */
/** /**
* @param string $name * @param string $name
* @param array $list * @param array $list
* @param null $selected * @param mixed $selected
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function select(string $name, array $list = [], $selected = null, array $options = []): string public function select(string $name, array $list = null, $selected = null, array $options = null): string
{ {
$list = $list ?? [];
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -658,13 +694,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function staticText(string $name, $value, array $options = []): string public function staticText(string $name, $value, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -675,13 +713,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function tags(string $name, $value = null, array $options = []): string public function tags(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -694,13 +734,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function text(string $name, $value = null, array $options = []): string public function text(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -712,13 +754,15 @@ class ExpandedForm
/** /**
* @param string $name * @param string $name
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function textarea(string $name, $value = null, array $options = []): string public function textarea(string $name, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
@@ -736,8 +780,9 @@ class ExpandedForm
* *
* @return array * @return array
*/ */
protected function expandOptionArray(string $name, $label, array $options): array protected function expandOptionArray(string $name, $label, array $options = null): array
{ {
$options = $options ?? [];
$name = str_replace('[]', '', $name); $name = str_replace('[]', '', $name);
$options['class'] = 'form-control'; $options['class'] = 'form-control';
$options['id'] = 'ffInput_' . $name; $options['id'] = 'ffInput_' . $name;
@@ -808,18 +853,21 @@ class ExpandedForm
return (string)trans('form.' . $name); return (string)trans('form.' . $name);
} }
/** @noinspection MoreThanThreeArgumentsInspection */
/** /**
* @param string $name * @param string $name
* @param string $view * @param string $view
* @param null $value * @param mixed $value
* @param array $options * @param array $options
* *
* @return string * @return string
* *
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
private function currencyField(string $name, string $view, $value = null, array $options = []): string private function currencyField(string $name, string $view, $value = null, array $options = null): string
{ {
$options = $options ?? [];
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);

View File

@@ -87,10 +87,7 @@ class SingleControllerTest extends TestCase
$journalRepos->shouldReceive('getMetaField')->andReturnNull(); $journalRepos->shouldReceive('getMetaField')->andReturnNull();
$note = new Note(); $journalRepos->shouldReceive('getNoteText')->andReturn('I see you...')->once();
$note->id = 5;
$note->text = 'I see you...';
$journalRepos->shouldReceive('getNote')->andReturn($note)->once();
$this->be($this->user()); $this->be($this->user());