Skip to content

Firefly III: a personal finances manager

Category information. #159

James Cole622a97c8d857
diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php
index 9f521cff92..e5b103b553 100644
--- a/app/Http/Controllers/Popup/ReportController.php
+++ b/app/Http/Controllers/Popup/ReportController.php
@@ -16,6 +16,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
use FireflyIII\Support\Binder\AccountList;
use Illuminate\Http\Request;
use InvalidArgumentException;
@@ -51,6 +52,9 @@ class ReportController extends Controller
case 'income-entry':
$html = $this->incomeEntry($attributes);
break;
+ case 'category-entry':
+ $html = $this->categoryEntry($attributes);
+ break;
}
return Response::json(['html' => $html]);
@@ -87,20 +91,20 @@ class ReportController extends Controller
}
/**
- * Returns all the incomes that went to the given asset account.
+ * Returns all expenses in category in range.
*
* @param $attributes
*
* @return string
* @throws FireflyException
*/
- private function incomeEntry($attributes)
+ private function categoryEntry($attributes)
{
- /** @var AccountRepositoryInterface $repository */
- $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
- $account = $repository->find(intval($attributes['accountId']));
- $journals = $repository->getIncomeByDestination($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']);
- $view = view('popup.report.income-entry', compact('journals'))->render();
+ /** @var SingleCategoryRepositoryInterface $repository */
+ $repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
+ $category = $repository->find(intval($attributes['categoryId']));
+ $journals = $repository->getJournalsForAccountsInRange($category, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']);
+ $view = view('popup.report.category-entry', compact('journals'))->render();
return $view;
}
@@ -124,6 +128,25 @@ class ReportController extends Controller
return $view;
}
+ /**
+ * Returns all the incomes that went to the given asset account.
+ *
+ * @param $attributes
+ *
+ * @return string
+ * @throws FireflyException
+ */
+ private function incomeEntry($attributes)
+ {
+ /** @var AccountRepositoryInterface $repository */
+ $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
+ $account = $repository->find(intval($attributes['accountId']));
+ $journals = $repository->getIncomeByDestination($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']);
+ $view = view('popup.report.income-entry', compact('journals'))->render();
+
+ return $view;
+ }
+
/**
* @param array $attributes
*
diff --git a/app/Repositories/Category/SingleCategoryRepository.php b/app/Repositories/Category/SingleCategoryRepository.php
index 5637b94e26..1562ed4846 100644
--- a/app/Repositories/Category/SingleCategoryRepository.php
+++ b/app/Repositories/Category/SingleCategoryRepository.php
@@ -153,6 +153,28 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
}
+ /**
+ * @param Category $category
+ * @param Collection $accounts
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getJournalsForAccountsInRange(Category $category, Collection $accounts, Carbon $start, Carbon $end)
+ {
+ $ids = $accounts->pluck('id')->toArray();
+
+ return $category->transactionjournals()
+ ->after($start)
+ ->before($end)
+ ->expanded()
+ ->whereIn('source_account.id', $ids)
+ ->whereNotIn('destination_account.id', $ids)
+ ->get(TransactionJournal::QUERYFIELDS);
+ }
+
/**
* @param Category $category
* @param int $page
@@ -171,9 +193,6 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
->expanded()
->take(50)
->offset($offset)
- ->orderBy('transaction_journals.date', 'DESC')
- ->orderBy('transaction_journals.order', 'ASC')
- ->orderBy('transaction_journals.id', 'DESC')
->get(TransactionJournal::QUERYFIELDS);
}
diff --git a/app/Repositories/Category/SingleCategoryRepositoryInterface.php b/app/Repositories/Category/SingleCategoryRepositoryInterface.php
index 1a4bb6273c..88104b957b 100644
--- a/app/Repositories/Category/SingleCategoryRepositoryInterface.php
+++ b/app/Repositories/Category/SingleCategoryRepositoryInterface.php
@@ -79,6 +79,16 @@ interface SingleCategoryRepositoryInterface
*/
public function getJournals(Category $category, $page);
+ /**
+ * @param Category $category
+ * @param Collection $accounts
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getJournalsForAccountsInRange(Category $category, Collection $accounts, Carbon $start, Carbon $end);
/**
* @param Category $category
diff --git a/resources/views/popup/report/category-entry.twig b/resources/views/popup/report/category-entry.twig
new file mode 100644
index 0000000000..fb3e808fd1
--- /dev/null
+++ b/resources/views/popup/report/category-entry.twig
@@ -0,0 +1,15 @@
+<!-- Modal dialog to show category expenses -->
+<div class="modal-dialog modal-lg" role="document">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="{{ 'close'|_ }}"><span aria-hidden="true">&times;</span></button>
+ <h4 class="modal-title" id="expenseEntryTitle">{{ 'category_entry'|_ }}</h4>
+ </div>
+ <div class="modal-body">
+ {% include 'popup/list/journals.twig' %}
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button>
+ </div>
+ </div>
+</div>
diff --git a/resources/views/popup/report/expense-entry.twig b/resources/views/popup/report/expense-entry.twig
index 977ee599f1..65071a8ff0 100644
--- a/resources/views/popup/report/expense-entry.twig
+++ b/resources/views/popup/report/expense-entry.twig
@@ -1,4 +1,4 @@
-<!-- Modal dialog to show budget expenses -->
+<!-- Modal dialog to show expenses to an account -->
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
diff --git a/resources/views/popup/report/income-entry.twig b/resources/views/popup/report/income-entry.twig
index d77e4ea3c5..de93ce2af4 100644
--- a/resources/views/popup/report/income-entry.twig
+++ b/resources/views/popup/report/income-entry.twig
@@ -1,4 +1,4 @@
-<!-- Modal dialog to show budget expenses -->
+<!-- Modal dialog to show incomes to an account -->
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">