diff --git a/app/Http/Controllers/Category/CreateController.php b/app/Http/Controllers/Category/CreateController.php
new file mode 100644
index 0000000000..f0cfb0a21a
--- /dev/null
+++ b/app/Http/Controllers/Category/CreateController.php
@@ -0,0 +1,103 @@
+.
+ */
+
+namespace FireflyIII\Http\Controllers\Category;
+
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Http\Requests\CategoryFormRequest;
+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
+use Illuminate\Http\Request;
+
+/**
+ * Class CreateController
+ */
+class CreateController extends Controller
+{
+ /** @var CategoryRepositoryInterface The category repository */
+ private $repository;
+
+ /**
+ * CategoryController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.categories'));
+ app('view')->share('mainTitleIcon', 'fa-bar-chart');
+ $this->repository = app(CategoryRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+
+ /**
+ * Create category.
+ *
+ * @param Request $request
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function create(Request $request)
+ {
+ if (true !== session('categories.create.fromStore')) {
+ $this->rememberPreviousUri('categories.create.uri');
+ }
+ $request->session()->forget('categories.create.fromStore');
+ $subTitle = (string)trans('firefly.create_new_category');
+
+ return view('categories.create', compact('subTitle'));
+ }
+
+
+ /**
+ * Store new category.
+ *
+ * @param CategoryFormRequest $request
+ *
+ * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function store(CategoryFormRequest $request)
+ {
+ $data = $request->getCategoryData();
+ $category = $this->repository->store($data);
+
+ $request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name]));
+ app('preferences')->mark();
+
+ $redirect = redirect(route('categories.index'));
+ if (1 === (int)$request->get('create_another')) {
+ // @codeCoverageIgnoreStart
+ $request->session()->put('categories.create.fromStore', true);
+
+ $redirect = redirect(route('categories.create'))->withInput();
+ // @codeCoverageIgnoreEnd
+ }
+
+ return $redirect;
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Category/DeleteController.php b/app/Http/Controllers/Category/DeleteController.php
new file mode 100644
index 0000000000..44cd8773c6
--- /dev/null
+++ b/app/Http/Controllers/Category/DeleteController.php
@@ -0,0 +1,92 @@
+.
+ */
+
+namespace FireflyIII\Http\Controllers\Category;
+
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Models\Category;
+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
+use Illuminate\Http\Request;
+
+/**
+ * Class DeleteController
+ */
+class DeleteController extends Controller
+{
+ /** @var CategoryRepositoryInterface The category repository */
+ private $repository;
+
+ /**
+ * CategoryController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.categories'));
+ app('view')->share('mainTitleIcon', 'fa-bar-chart');
+ $this->repository = app(CategoryRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+ /**
+ * Delete a category.
+ *
+ * @param Category $category
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function delete(Category $category)
+ {
+ $subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]);
+
+ // put previous url in session
+ $this->rememberPreviousUri('categories.delete.uri');
+
+ return view('categories.delete', compact('category', 'subTitle'));
+ }
+
+ /**
+ * Destroy a category.
+ *
+ * @param Request $request
+ * @param Category $category
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function destroy(Request $request, Category $category)
+ {
+ $name = $category->name;
+ $this->repository->destroy($category);
+
+ $request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name]));
+ app('preferences')->mark();
+
+ return redirect($this->getPreviousUri('categories.delete.uri'));
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Category/EditController.php b/app/Http/Controllers/Category/EditController.php
new file mode 100644
index 0000000000..76991b0369
--- /dev/null
+++ b/app/Http/Controllers/Category/EditController.php
@@ -0,0 +1,109 @@
+.
+ */
+
+namespace FireflyIII\Http\Controllers\Category;
+
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Http\Requests\CategoryFormRequest;
+use FireflyIII\Models\Category;
+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
+use Illuminate\Http\Request;
+
+/**
+ * Class EditController
+ */
+class EditController extends Controller
+{
+
+ /** @var CategoryRepositoryInterface The category repository */
+ private $repository;
+
+ /**
+ * CategoryController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.categories'));
+ app('view')->share('mainTitleIcon', 'fa-bar-chart');
+ $this->repository = app(CategoryRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+
+ /**
+ * Edit a category.
+ *
+ * @param Request $request
+ * @param Category $category
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function edit(Request $request, Category $category)
+ {
+ $subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]);
+
+ // put previous url in session if not redirect from store (not "return_to_edit").
+ if (true !== session('categories.edit.fromUpdate')) {
+ $this->rememberPreviousUri('categories.edit.uri');
+ }
+ $request->session()->forget('categories.edit.fromUpdate');
+
+ return view('categories.edit', compact('category', 'subTitle'));
+ }
+
+ /**
+ * Update category.
+ *
+ * @param CategoryFormRequest $request
+ * @param Category $category
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function update(CategoryFormRequest $request, Category $category)
+ {
+ $data = $request->getCategoryData();
+ $this->repository->update($category, $data);
+
+ $request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name]));
+ app('preferences')->mark();
+
+ $redirect = redirect($this->getPreviousUri('categories.edit.uri'));
+
+ if (1 === (int)$request->get('return_to_edit')) {
+ // @codeCoverageIgnoreStart
+ $request->session()->put('categories.edit.fromUpdate', true);
+
+ $redirect = redirect(route('categories.edit', [$category->id]));
+ // @codeCoverageIgnoreEnd
+ }
+
+ return $redirect;
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Category/IndexController.php b/app/Http/Controllers/Category/IndexController.php
new file mode 100644
index 0000000000..cd39646a2c
--- /dev/null
+++ b/app/Http/Controllers/Category/IndexController.php
@@ -0,0 +1,89 @@
+.
+ */
+
+namespace FireflyIII\Http\Controllers\Category;
+
+
+use FireflyIII\Http\Controllers\Controller;
+use FireflyIII\Models\Category;
+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
+use Illuminate\Http\Request;
+use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Collection;
+
+/**
+ * Class IndexController
+ */
+class IndexController extends Controller
+{
+ /** @var CategoryRepositoryInterface The category repository */
+ private $repository;
+
+ /**
+ * CategoryController constructor.
+ * @codeCoverageIgnore
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->middleware(
+ function ($request, $next) {
+ app('view')->share('title', (string)trans('firefly.categories'));
+ app('view')->share('mainTitleIcon', 'fa-bar-chart');
+ $this->repository = app(CategoryRepositoryInterface::class);
+
+ return $next($request);
+ }
+ );
+ }
+
+
+
+ /**
+ * Show all categories.
+ *
+ * @param Request $request
+ *
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function index(Request $request)
+ {
+ $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
+ $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
+ $collection = $this->repository->getCategories();
+ $total = $collection->count();
+ $collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
+
+ $collection->each(
+ function (Category $category) {
+ $category->lastActivity = $this->repository->lastUseDate($category, new Collection);
+ }
+ );
+
+ // paginate categories
+ $categories = new LengthAwarePaginator($collection, $total, $pageSize, $page);
+ $categories->setPath(route('categories.index'));
+
+ return view('categories.index', compact('categories'));
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php
index 803cb3498e..aa8df71950 100644
--- a/app/Http/Controllers/Category/NoCategoryController.php
+++ b/app/Http/Controllers/Category/NoCategoryController.php
@@ -46,6 +46,7 @@ class NoCategoryController extends Controller
/**
* CategoryController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php
index f3db0b5df3..da2e40a7f9 100644
--- a/app/Http/Controllers/Category/ShowController.php
+++ b/app/Http/Controllers/Category/ShowController.php
@@ -47,6 +47,7 @@ class ShowController extends Controller
/**
* CategoryController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -85,7 +86,8 @@ class ShowController extends Controller
$subTitleIcon = 'fa-bar-chart';
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
- $periods = $this->getCategoryPeriodOverview($category, $end);
+ $oldest = $this->repository->firstUseDate($category) ?? Carbon::create()->startOfYear();
+ $periods = $this->getCategoryPeriodOverview($category, $oldest, $end);
$path = route('categories.show', [$category->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$subTitle = trans(
'firefly.journals_in_period_for_category',
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index c051b36b1c..50ecaa557d 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -55,168 +55,11 @@ class CategoryController extends Controller
);
}
- /**
- * Create category.
- *
- * @param Request $request
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function create(Request $request)
- {
- if (true !== session('categories.create.fromStore')) {
- $this->rememberPreviousUri('categories.create.uri');
- }
- $request->session()->forget('categories.create.fromStore');
- $subTitle = (string)trans('firefly.create_new_category');
-
- return view('categories.create', compact('subTitle'));
- }
-
- /**
- * Delete a category.
- *
- * @param Category $category
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function delete(Category $category)
- {
- $subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]);
-
- // put previous url in session
- $this->rememberPreviousUri('categories.delete.uri');
-
- return view('categories.delete', compact('category', 'subTitle'));
- }
-
- /**
- * Destroy a category.
- *
- * @param Request $request
- * @param Category $category
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function destroy(Request $request, Category $category)
- {
- $name = $category->name;
- $this->repository->destroy($category);
-
- $request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name]));
- app('preferences')->mark();
-
- return redirect($this->getPreviousUri('categories.delete.uri'));
- }
-
- /**
- * Edit a category.
- *
- * @param Request $request
- * @param Category $category
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function edit(Request $request, Category $category)
- {
- $subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]);
-
- // put previous url in session if not redirect from store (not "return_to_edit").
- if (true !== session('categories.edit.fromUpdate')) {
- $this->rememberPreviousUri('categories.edit.uri');
- }
- $request->session()->forget('categories.edit.fromUpdate');
-
- return view('categories.edit', compact('category', 'subTitle'));
- }
-
- /**
- * Show all categories.
- *
- * @param Request $request
- *
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function index(Request $request)
- {
- $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
- $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
- $collection = $this->repository->getCategories();
- $total = $collection->count();
- $collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
-
- $collection->each(
- function (Category $category) {
- $category->lastActivity = $this->repository->lastUseDate($category, new Collection);
- }
- );
-
- // paginate categories
- $categories = new LengthAwarePaginator($collection, $total, $pageSize, $page);
- $categories->setPath(route('categories.index'));
-
- return view('categories.index', compact('categories'));
- }
- /**
- * Store new category.
- *
- * @param CategoryFormRequest $request
- * @param CategoryRepositoryInterface $repository
- *
- * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function store(CategoryFormRequest $request, CategoryRepositoryInterface $repository)
- {
- $data = $request->getCategoryData();
- $category = $repository->store($data);
-
- $request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name]));
- app('preferences')->mark();
-
- $redirect = redirect(route('categories.index'));
- if (1 === (int)$request->get('create_another')) {
- // @codeCoverageIgnoreStart
- $request->session()->put('categories.create.fromStore', true);
-
- $redirect = redirect(route('categories.create'))->withInput();
- // @codeCoverageIgnoreEnd
- }
-
- return $redirect;
- }
- /**
- * Update category.
- *
- * @param CategoryFormRequest $request
- * @param CategoryRepositoryInterface $repository
- * @param Category $category
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- public function update(CategoryFormRequest $request, CategoryRepositoryInterface $repository, Category $category)
- {
- $data = $request->getCategoryData();
- $repository->update($category, $data);
- $request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name]));
- app('preferences')->mark();
-
- $redirect = redirect($this->getPreviousUri('categories.edit.uri'));
-
- if (1 === (int)$request->get('return_to_edit')) {
- // @codeCoverageIgnoreStart
- $request->session()->put('categories.edit.fromUpdate', true);
-
- $redirect = redirect(route('categories.edit', [$category->id]));
- // @codeCoverageIgnoreEnd
- }
-
- return $redirect;
- }
}
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index 555ce5c9de..5335d0b8a5 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -62,6 +62,7 @@ class AccountController extends Controller
/**
* AccountController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -341,9 +342,8 @@ class AccountController extends Controller
Log::debug('Frontpage preference set is ', $frontPage->data);
if (0 === count($frontPage->data)) {
- $frontPage->data = $defaultSet;
+ app('preferences')->set('frontPageAccounts', $defaultSet);
Log::debug('frontpage set is empty!');
- $frontPage->save();
}
$accounts = $repository->getAccountsById($frontPage->data);
diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php
index f96e7a1f4e..bd079cb551 100644
--- a/app/Http/Controllers/Chart/BillController.php
+++ b/app/Http/Controllers/Chart/BillController.php
@@ -42,6 +42,7 @@ class BillController extends Controller
/**
* BillController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php
index a5a402a2bc..d6a1f36286 100644
--- a/app/Support/Http/Controllers/PeriodOverview.php
+++ b/app/Support/Http/Controllers/PeriodOverview.php
@@ -30,7 +30,6 @@ use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\CacheProperties;
@@ -52,6 +51,7 @@ use Log;
* earned (array),
* transferred_away (array)
* transferred_in (array)
+ * transferred (array)
*
* each array has the following format:
* currency_id => [
@@ -125,16 +125,15 @@ trait PeriodOverview
// loop dates
foreach ($dates as $currentDate) {
- $title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
-
+ $title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
$transferredAway = $this->filterTransferredAway($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
$transferredIn = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
$entries[] =
[
- 'title' => $title,
- 'route' =>
+ 'title' => $title,
+ 'route' =>
route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
@@ -153,19 +152,13 @@ trait PeriodOverview
* Overview for single category. Has been refactored recently.
*
* @param Category $category
- * @param Carbon $date
- *
- * @return Collection
+ * @param Carbon $start
+ * @param Carbon $end
+ * @return array
*/
- protected function getCategoryPeriodOverview(Category $category, Carbon $date): Collection
+ protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array
{
- die('not yet complete');
- /** @var JournalRepositoryInterface $journalRepository */
- $journalRepository = app(JournalRepositoryInterface::class);
- $range = app('preferences')->get('viewRange', '1M')->data;
- $first = $journalRepository->firstNull();
- $end = null === $first ? new Carbon : $first->date;
- $start = clone $date;
+ $range = app('preferences')->get('viewRange', '1M')->data;
if ($end < $start) {
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
@@ -180,39 +173,53 @@ trait PeriodOverview
$cache->addProperty($category->id);
if ($cache->has()) {
- return $cache->get(); // @codeCoverageIgnore
+ //return $cache->get(); // @codeCoverageIgnore
}
/** @var array $dates */
$dates = app('navigation')->blockPeriods($start, $end, $range);
- $entries = new Collection;
- /** @var CategoryRepositoryInterface $categoryRepository */
- $categoryRepository = app(CategoryRepositoryInterface::class);
+ $entries = [];
+
+ // collect all expenses in this period:
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->setCategory($category);
+ $collector->setRange($start, $end);
+ $collector->setTypes([TransactionType::DEPOSIT]);
+ $earnedSet = $collector->getExtractedJournals();
+
+ // collect all income in this period:
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->setCategory($category);
+ $collector->setRange($start, $end);
+ $collector->setTypes([TransactionType::WITHDRAWAL]);
+ $spentSet = $collector->getExtractedJournals();
+
+ // collect all transfers in this period:
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->setCategory($category);
+ $collector->setRange($start, $end);
+ $collector->setTypes([TransactionType::TRANSFER]);
+ $transferSet = $collector->getExtractedJournals();
+
foreach ($dates as $currentDate) {
- $spent = $categoryRepository->spentInPeriodCollection(new Collection([$category]), new Collection, $currentDate['start'], $currentDate['end']);
- $earned = $categoryRepository->earnedInPeriodCollection(new Collection([$category]), new Collection, $currentDate['start'], $currentDate['end']);
- $spent = $this->groupByCurrency($spent);
- $earned = $this->groupByCurrency($earned);
-
- // amount transferred
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
-
- $collector->setRange($currentDate['start'], $currentDate['end'])->setCategory($category)
- ->setTypes([TransactionType::TRANSFER]);
- $transferred = $this->groupByCurrency($collector->getExtractedJournals());
-
- $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
- $entries->push(
+ $spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
+ $earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
+ $transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);
+ $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
+ $entries[] =
[
- 'transactions' => 0,
- 'title' => $title,
- 'spent' => $spent,
- 'earned' => $earned,
- 'transferred' => $transferred,
- 'route' => route('categories.show', [$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
- ]
- );
+ 'transactions' => 0,
+ 'title' => $title,
+ 'route' => route('categories.show',
+ [$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
+ 'total_transactions' => count($spent) + count($earned) + count($transferred),
+ 'spent' => $this->groupByCurrency($spent),
+ 'earned' => $this->groupByCurrency($earned),
+ 'transferred' => $this->groupByCurrency($transferred),
+ ];
}
$cache->store($entries);
@@ -231,7 +238,7 @@ trait PeriodOverview
*/
protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array
{
- $range = app('preferences')->get('viewRange', '1M')->data;
+ $range = app('preferences')->get('viewRange', '1M')->data;
if ($end < $start) {
[$start, $end] = [$end, $start]; // @codeCoverageIgnore
@@ -258,12 +265,12 @@ trait PeriodOverview
$journals = $collector->getExtractedJournals();
foreach ($dates as $currentDate) {
- $set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
- $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
- $entries[] =
+ $set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
+ $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
+ $entries[] =
[
'title' => $title,
- 'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
+ 'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
'total_transactions' => count($set),
'spent' => $this->groupByCurrency($set),
'earned' => [],
@@ -277,18 +284,15 @@ trait PeriodOverview
}
/**
- * TODO has to be synced with the others.
- *
* Show period overview for no category view.
*
* @param Carbon $theDate
*
- * @return Collection
+ * @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- protected function getNoCategoryPeriodOverview(Carbon $theDate): Collection // period overview method.
+ protected function getNoCategoryPeriodOverview(Carbon $theDate): array
{
- die('not yet complete');
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
$range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->journalRepos->firstNull();
@@ -305,58 +309,51 @@ trait PeriodOverview
$cache->addProperty('no-category-period-entries');
if ($cache->has()) {
- return $cache->get(); // @codeCoverageIgnore
+ //return $cache->get(); // @codeCoverageIgnore
}
$dates = app('navigation')->blockPeriods($start, $end, $range);
- $entries = new Collection;
+ $entries = [];
- foreach ($dates as $date) {
+ // collect all expenses in this period:
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->withoutCategory();
+ $collector->setRange($start, $end);
+ $collector->setTypes([TransactionType::DEPOSIT]);
+ $earnedSet = $collector->getExtractedJournals();
- // count journals without category in this period:
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
- $collector->setRange($date['start'], $date['end'])->withoutCategory()
- ->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
- $count = count($collector->getExtractedJournals());
+ // collect all income in this period:
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->withoutCategory();
+ $collector->setRange($start, $end);
+ $collector->setTypes([TransactionType::WITHDRAWAL]);
+ $spentSet = $collector->getExtractedJournals();
- // amount transferred
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
- $collector->setRange($date['start'], $date['end'])->withoutCategory()
- ->setTypes([TransactionType::TRANSFER]);
- $transferred = app('steam')->positive((string)$collector->getSum());
+ // collect all transfers in this period:
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->withoutCategory();
+ $collector->setRange($start, $end);
+ $collector->setTypes([TransactionType::TRANSFER]);
+ $transferSet = $collector->getExtractedJournals();
- // amount spent
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
- $collector->setRange($date['start'], $date['end'])->withoutCategory()->setTypes(
- [TransactionType::WITHDRAWAL]
- );
- $spent = $collector->getSum();
-
- // amount earned
- /** @var GroupCollectorInterface $collector */
- $collector = app(GroupCollectorInterface::class);
- $collector->setRange($date['start'], $date['end'])->withoutCategory()->setTypes(
- [TransactionType::DEPOSIT]
- );
- $earned = $collector->getSum();
- /** @noinspection PhpUndefinedMethodInspection */
- $dateStr = $date['end']->format('Y-m-d');
- $dateName = app('navigation')->periodShow($date['end'], $date['period']);
- $entries->push(
+ /** @var array $currentDate */
+ foreach ($dates as $currentDate) {
+ $spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
+ $earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
+ $transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);
+ $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
+ $entries[] =
[
- 'string' => $dateStr,
- 'name' => $dateName,
- 'count' => $count,
- 'spent' => $spent,
- 'earned' => $earned,
- 'transferred' => $transferred,
- 'start' => clone $date['start'],
- 'end' => clone $date['end'],
- ]
- );
+ 'title' => $title,
+ 'route' => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
+ 'total_transactions' => count($spent) + count($earned) + count($transferred),
+ 'spent' => $this->groupByCurrency($spent),
+ 'earned' => $this->groupByCurrency($earned),
+ 'transferred' => $this->groupByCurrency($transferred),
+ ];
}
Log::debug('End of loops');
$cache->store($entries);
diff --git a/composer.lock b/composer.lock
index 212736344e..cdce73ba39 100644
--- a/composer.lock
+++ b/composer.lock
@@ -929,16 +929,16 @@
},
{
"name": "egulias/email-validator",
- "version": "2.1.8",
+ "version": "2.1.9",
"source": {
"type": "git",
"url": "https://github.com/egulias/EmailValidator.git",
- "reference": "c26463ff9241f27907112fbcd0c86fa670cfef98"
+ "reference": "128cc721d771ec2c46ce59698f4ca42b73f71b25"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/c26463ff9241f27907112fbcd0c86fa670cfef98",
- "reference": "c26463ff9241f27907112fbcd0c86fa670cfef98",
+ "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/128cc721d771ec2c46ce59698f4ca42b73f71b25",
+ "reference": "128cc721d771ec2c46ce59698f4ca42b73f71b25",
"shasum": ""
},
"require": {
@@ -982,7 +982,7 @@
"validation",
"validator"
],
- "time": "2019-05-16T22:02:54+00:00"
+ "time": "2019-06-23T10:14:27+00:00"
},
{
"name": "erusev/parsedown",
@@ -2309,16 +2309,16 @@
},
{
"name": "nesbot/carbon",
- "version": "2.19.2",
+ "version": "2.20.0",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
- "reference": "adcad3f3af52d0ad4ad7b05f43aa58243b6ca67b"
+ "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/adcad3f3af52d0ad4ad7b05f43aa58243b6ca67b",
- "reference": "adcad3f3af52d0ad4ad7b05f43aa58243b6ca67b",
+ "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bc671b896c276795fad8426b0aa24e8ade0f2498",
+ "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498",
"shasum": ""
},
"require": {
@@ -2365,7 +2365,7 @@
"datetime",
"time"
],
- "time": "2019-06-07T09:56:45+00:00"
+ "time": "2019-06-25T10:00:57+00:00"
},
{
"name": "opis/closure",
@@ -2587,16 +2587,16 @@
},
{
"name": "phpseclib/phpseclib",
- "version": "2.0.19",
+ "version": "2.0.20",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
- "reference": "d2085db7b7394baa071a69c8f9159723c250f2ba"
+ "reference": "d6819a55b05e123db1e881d8b230d57f912126be"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d2085db7b7394baa071a69c8f9159723c250f2ba",
- "reference": "d2085db7b7394baa071a69c8f9159723c250f2ba",
+ "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d6819a55b05e123db1e881d8b230d57f912126be",
+ "reference": "d6819a55b05e123db1e881d8b230d57f912126be",
"shasum": ""
},
"require": {
@@ -2675,7 +2675,7 @@
"x.509",
"x509"
],
- "time": "2019-06-20T03:34:11+00:00"
+ "time": "2019-06-23T16:33:11+00:00"
},
{
"name": "pragmarx/google2fa",
@@ -5555,16 +5555,16 @@
},
{
"name": "filp/whoops",
- "version": "2.3.2",
+ "version": "2.4.0",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
- "reference": "a28d5cef33627c069a2bd8fbb35ebe1a54881d35"
+ "reference": "1a1a1044ad00e285bd2825fac4c3a0443d90ad33"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/filp/whoops/zipball/a28d5cef33627c069a2bd8fbb35ebe1a54881d35",
- "reference": "a28d5cef33627c069a2bd8fbb35ebe1a54881d35",
+ "url": "https://api.github.com/repos/filp/whoops/zipball/1a1a1044ad00e285bd2825fac4c3a0443d90ad33",
+ "reference": "1a1a1044ad00e285bd2825fac4c3a0443d90ad33",
"shasum": ""
},
"require": {
@@ -5612,7 +5612,7 @@
"throwable",
"whoops"
],
- "time": "2019-06-21T09:00:00+00:00"
+ "time": "2019-06-23T09:00:00+00:00"
},
{
"name": "fzaninotto/faker",
@@ -6597,12 +6597,12 @@
"source": {
"type": "git",
"url": "https://github.com/Roave/SecurityAdvisories.git",
- "reference": "baeb6f512b5ec8f0fd58bf890082b179f985c5a4"
+ "reference": "a53a6f855cbff7edb078f87c72bb808c89443a00"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/baeb6f512b5ec8f0fd58bf890082b179f985c5a4",
- "reference": "baeb6f512b5ec8f0fd58bf890082b179f985c5a4",
+ "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/a53a6f855cbff7edb078f87c72bb808c89443a00",
+ "reference": "a53a6f855cbff7edb078f87c72bb808c89443a00",
"shasum": ""
},
"conflict": {
@@ -6640,6 +6640,7 @@
"drupal/core": ">=7,<7.67|>=8,<8.6.16|>=8.7,<8.7.1",
"drupal/drupal": ">=7,<7.67|>=8,<8.6.16|>=8.7,<8.7.1",
"erusev/parsedown": "<1.7.2",
+ "ezsystems/ezplatform-admin-ui": ">=1.3,<1.3.5|>=1.4,<1.4.4",
"ezsystems/ezpublish-kernel": ">=5.3,<5.3.12.1|>=5.4,<5.4.13.1|>=6,<6.7.9.1|>=6.8,<6.13.5.1|>=7,<7.2.4.1|>=7.3,<7.3.2.1",
"ezsystems/ezpublish-legacy": ">=5.3,<5.3.12.6|>=5.4,<5.4.12.3|>=2011,<2017.12.4.3|>=2018.6,<2018.6.1.4|>=2018.9,<2018.9.1.3",
"ezsystems/repository-forms": ">=2.3,<2.3.2.1",
@@ -6748,8 +6749,8 @@
"titon/framework": ">=0,<9.9.99",
"truckersmp/phpwhois": "<=4.3.1",
"twig/twig": "<1.38|>=2,<2.7",
- "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.25|>=9,<9.5.6",
- "typo3/cms-core": ">=8,<8.7.25|>=9,<9.5.6",
+ "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.27|>=9,<9.5.8",
+ "typo3/cms-core": ">=8,<8.7.27|>=9,<9.5.8",
"typo3/flow": ">=1,<1.0.4|>=1.1,<1.1.1|>=2,<2.0.1|>=2.3,<2.3.16|>=3,<3.0.10|>=3.1,<3.1.7|>=3.2,<3.2.7|>=3.3,<3.3.5",
"typo3/neos": ">=1.1,<1.1.3|>=1.2,<1.2.13|>=2,<2.0.4",
"typo3/phar-stream-wrapper": ">=1,<2.1.1|>=3,<3.1.1",
@@ -6803,7 +6804,7 @@
}
],
"description": "Prevents installation of composer packages with known security vulnerabilities: no API, simply require it",
- "time": "2019-06-14T17:56:32+00:00"
+ "time": "2019-06-25T10:37:35+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
diff --git a/phpunit.coverage.specific.xml b/phpunit.coverage.specific.xml
index 2437e877f1..2bd193e356 100644
--- a/phpunit.coverage.specific.xml
+++ b/phpunit.coverage.specific.xml
@@ -46,6 +46,9 @@
./tests/Feature/Controllers/Account
+ ./tests/Feature/Controllers/Admin
+ ./tests/Feature/Controllers/Budget
+ ./tests/Feature/Controllers/Category
diff --git a/phpunit.coverage.xml b/phpunit.coverage.xml
index d06dd51f11..5bb3cd9969 100644
--- a/phpunit.coverage.xml
+++ b/phpunit.coverage.xml
@@ -46,6 +46,9 @@
./tests/Feature/Controllers/Account
+ ./tests/Feature/Controllers/Admin
+ ./tests/Feature/Controllers/Budget
+ ./tests/Feature/Controllers/Category
diff --git a/phpunit.xml b/phpunit.xml
index e1fe86d3fb..3faf2448de 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -46,6 +46,9 @@
./tests/Feature/Controllers/Account
+ ./tests/Feature/Controllers/Admin
+ ./tests/Feature/Controllers/Budget
+ ./tests/Feature/Controllers/Category