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 @@ _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 @@ +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 @@