Skip to content

Firefly III: a personal finances manager

Make method nullable.

James Colec5051b3e4655
diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php
index e5a08761c9..7a7ee2a158 100644
--- a/app/Http/Controllers/Account/ShowController.php
+++ b/app/Http/Controllers/Account/ShowController.php
@@ -145,7 +145,7 @@ class ShowController extends Controller
}
$end = new Carbon;
$today = new Carbon;
- $start = $this->repository->oldestJournalDate($account);
+ $start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
@@ -190,7 +190,7 @@ class ShowController extends Controller
private function getPeriodOverview(Account $account, ?Carbon $date): Collection
{
$range = app('preferences')->get('viewRange', '1M')->data;
- $start = $this->repository->oldestJournalDate($account);
+ $start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = $date ?? new Carbon;
if ($end < $start) {
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index d05ca1dc5e..5a6bbdcd79 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -166,7 +166,7 @@ class AccountController extends Controller
*/
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
- $start = $repository->oldestJournalDate($account);
+ $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseBudget($account, $start, $end);
@@ -229,7 +229,7 @@ class AccountController extends Controller
*/
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
- $start = $repository->oldestJournalDate($account);
+ $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->expenseCategory($account, $start, $end);
@@ -320,7 +320,7 @@ class AccountController extends Controller
*/
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
{
- $start = $repository->oldestJournalDate($account);
+ $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$end = Carbon::now();
return $this->incomeCategory($account, $start, $end);
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 0961ba3f9b..27e1c0a695 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -410,11 +410,11 @@ class AccountRepository implements AccountRepositoryInterface
*
* @param Account $account
*
- * @return Carbon
+ * @return Carbon|null
*/
- public function oldestJournalDate(Account $account): Carbon
+ public function oldestJournalDate(Account $account): ?Carbon
{
- $result = new Carbon;
+ $result = null;
$journal = $this->oldestJournal($account);
if (null !== $journal) {
$result = $journal->date;
diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php
index 8f88884e1a..d5e02ab19c 100644
--- a/app/Repositories/Account/AccountRepositoryInterface.php
+++ b/app/Repositories/Account/AccountRepositoryInterface.php
@@ -184,9 +184,9 @@ interface AccountRepositoryInterface
*
* @param Account $account
*
- * @return Carbon
+ * @return Carbon|null
*/
- public function oldestJournalDate(Account $account): Carbon;
+ public function oldestJournalDate(Account $account): ?Carbon;
/**
* @param User $user