Skip to content

Firefly III: a personal finances manager

Fixed the charts, added some todo items.

James Cole58d8b6f95b0c
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index ad7d48710b..61c520089b 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -464,8 +464,8 @@ class GoogleChartController extends BaseController
$chart->addColumn('Name', 'string');
$chart->addColumn('Amount', 'number');
- /** @var \FireflyIII\Database\RecurringTransaction $rcr */
- $rcr = App::make('FireflyIII\Database\RecurringTransaction');
+ /** @var \FireflyIII\Database\Recurring $rcr */
+ $rcr = App::make('FireflyIII\Database\Recurring');
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = App::make('FireflyIII\Shared\Toolkit\Date');
diff --git a/app/controllers/SearchController.php b/app/controllers/SearchController.php
index 6217bdcac2..e1588d8e3b 100644
--- a/app/controllers/SearchController.php
+++ b/app/controllers/SearchController.php
@@ -1,5 +1,4 @@
<?php
-use FireflyIII\Exception\NotImplementedException;
/**
* Class SearchController
@@ -11,7 +10,10 @@ class SearchController extends BaseController
*/
public function index()
{
- throw new NotImplementedException;
+
+ /** @var \FireflyIII\Search\Search $searcher */
+ $searcher = App::make('FireflyIII\Search\Search');
+
$subTitle = null;
$rawQuery = null;
$result = [];
@@ -20,11 +22,11 @@ class SearchController extends BaseController
$words = explode(' ', $rawQuery);
$subTitle = 'Results for "' . e($rawQuery) . '"';
- $transactions = $this->_helper->searchTransactions($words);
- $accounts = $this->_helper->searchAccounts($words);
- $categories = $this->_helper->searchCategories($words);
- $budgets = $this->_helper->searchBudgets($words);
- $tags = $this->_helper->searchTags($words);
+ $transactions = $searcher->searchTransactions($words);
+ $accounts = $searcher->searchAccounts($words);
+ $categories = $searcher->searchCategories($words);
+ $budgets = $searcher->searchBudgets($words);
+ $tags = $searcher->searchTags($words);
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
}
diff --git a/app/lib/FireflyIII/Database/Recurring.php b/app/lib/FireflyIII/Database/Recurring.php
index 7265f57f88..2590052736 100644
--- a/app/lib/FireflyIII/Database/Recurring.php
+++ b/app/lib/FireflyIII/Database/Recurring.php
@@ -330,7 +330,6 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
* @param \RecurringTransaction $recurring
*
* @return bool
- * @throws NotImplementedException
*/
public function scanEverything(\RecurringTransaction $recurring)
{
diff --git a/app/lib/FireflyIII/Search/Search.php b/app/lib/FireflyIII/Search/Search.php
new file mode 100644
index 0000000000..e04cef733f
--- /dev/null
+++ b/app/lib/FireflyIII/Search/Search.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sander
+ * Date: 13/11/14
+ * Time: 21:01
+ */
+
+namespace FireflyIII\Search;
+
+
+use Illuminate\Support\Collection;
+
+class Search
+{
+ /**
+ * @param array $words
+ *
+ * @return Collection
+ */
+ public function searchAccounts(array $words)
+ {
+ return \Auth::user()->accounts()->with('accounttype')->where(
+ function ($q) use ($words) {
+ foreach ($words as $word) {
+ $q->orWhere('name', 'LIKE', '%' . e($word) . '%');
+ }
+ }
+ )->get();
+ }
+
+ /**
+ * @param array $words
+ *
+ * @return Collection
+ */
+ public function searchBudgets(array $words)
+ {
+ /** @var Collection $set */
+ $set = \Auth::user()->budgets()->get();
+ $newSet = $set->filter(
+ function (\Budget $b) use ($words) {
+ $found = 0;
+ foreach ($words as $word) {
+ if (!(strpos(strtolower($b->name), strtolower($word)) === false)) {
+ $found++;
+ }
+ }
+
+ return $found > 0;
+ }
+ );
+
+ return $newSet;
+ }
+
+ /**
+ * @param array $words
+ *
+ * @return Collection
+ */
+ public function searchCategories(array $words)
+ {
+ /** @var Collection $set */
+ $set = \Auth::user()->categories()->get();
+ $newSet = $set->filter(
+ function (\Category $c) use ($words) {
+ $found = 0;
+ foreach ($words as $word) {
+ if (!(strpos(strtolower($c->name), strtolower($word)) === false)) {
+ $found++;
+ }
+ }
+
+ return $found > 0;
+ }
+ );
+
+ return $newSet;
+ }
+
+ /**
+ * @param array $words
+ *
+ * @return Collection
+ */
+ public function searchTags(array $words)
+ {
+ return new Collection;
+ }
+
+ /**
+ * @param array $words
+ *
+ * @return Collection
+ */
+ public function searchTransactions(array $words)
+ {
+ return \Auth::user()->transactionjournals()->withRelevantData()->where(
+ function ($q) use ($words) {
+ foreach ($words as $word) {
+ $q->orWhere('description', 'LIKE', '%' . e($word) . '%');
+ }
+ }
+ )->get();
+ }
+}
\ No newline at end of file
diff --git a/app/models/Transaction.php b/app/models/Transaction.php
index 07de125d31..a60d5535eb 100644
--- a/app/models/Transaction.php
+++ b/app/models/Transaction.php
@@ -85,6 +85,7 @@ class Transaction extends Ardent
*/
public function connectPiggybank(\Piggybank $piggybank = null)
{
+ // TODO connect a piggy bank to a transaction.
throw new NotImplementedException;
// if (is_null($piggybank)) {
// return true;
diff --git a/app/views/partials/menu.blade.php b/app/views/partials/menu.blade.php
index b27ec1f4ad..bf070e6cdb 100644
--- a/app/views/partials/menu.blade.php
+++ b/app/views/partials/menu.blade.php
@@ -41,7 +41,7 @@
<li class="sidebar-search">
<form action="{{route('search')}}" method="GET" class="form-inline">
<div class="input-group custom-search-form">
- <input type="text" name="q" class="form-control" placeholder="Search...">
+ <input type="text" name="q" class="form-control" value="@if(Input::get('q')){{{Input::get('q')}}}@endif" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="fa fa-search"></i>
diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js
index 2582f55ac5..aec0f44a7a 100644
--- a/public/assets/javascript/firefly/gcharts.js
+++ b/public/assets/javascript/firefly/gcharts.js
@@ -228,6 +228,11 @@ function googleSankeyChart(URL, container) {
}
}
+/**
+ * TODO fix this method so the layout is nice and dandy.
+ * @param URL
+ * @param container
+ */
function googleTable(URL, container) {
if ($('#' + container).length == 1) {
$.getJSON(URL).success(function (data) {