diff --git a/app/controllers/JsonController.php b/app/controllers/JsonController.php index d74a923a8a..3e62c3470c 100644 --- a/app/controllers/JsonController.php +++ b/app/controllers/JsonController.php @@ -184,7 +184,7 @@ class JsonController extends BaseController * Build query: */ $query = \TransactionJournal::transactionTypes($parameters['transactionTypes'])->withRelevantData(); - + $query->where('completed',1); /* * This is complex. Join `transactions` twice, once for the "to" account and once for the * "from" account. Then get the amount from one of these (depends on type). diff --git a/app/controllers/SearchController.php b/app/controllers/SearchController.php index c3ad87bbf3..205933400b 100644 --- a/app/controllers/SearchController.php +++ b/app/controllers/SearchController.php @@ -21,20 +21,30 @@ class SearchController extends BaseController public function index() { $subTitle = null; + $rawQuery = null; + $result = []; if (!is_null(Input::get('q'))) { $rawQuery = trim(Input::get('q')); $words = explode(' ', $rawQuery); $subTitle = 'Results for "' . e($rawQuery) . '"'; - /* - * Search for transactions: - */ - $result = $this->_helper->transactions($words); + $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); + $result = [ + 'transactions' => $transactions, + 'accounts' => $accounts, + 'categories' => $categories, + 'budgets' => $budgets, + 'tags' => $tags + ]; } return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with( 'mainTitleIcon', 'fa-search' - ); + )->with('query', $rawQuery)->with('result',$result); } } \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Controllers/Search.php b/app/lib/Firefly/Helper/Controllers/Search.php index 03ece09fed..743f109121 100644 --- a/app/lib/Firefly/Helper/Controllers/Search.php +++ b/app/lib/Firefly/Helper/Controllers/Search.php @@ -8,6 +8,8 @@ namespace Firefly\Helper\Controllers; +use Illuminate\Support\Collection; + /** * Class Search * @@ -18,26 +20,89 @@ class Search implements SearchInterface /** * @param array $words + * + * @return Collection */ - public function transactions(array $words) + public function searchTransactions(array $words) { - $query = \TransactionJournal::withRelevantData(); - - $fullCount = $query->count(); - - $query->where( + return \Auth::user()->transactionjournals()->withRelevantData()->where( function ($q) use ($words) { foreach ($words as $word) { $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); } } - ); - $count = $query->count(); - $set = $query->get(); - /* - * Build something with JSON? - */ - return $set; + )->get(); } -} \ No newline at end of file + /** + * @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 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 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 searchTags(array $words) + { + return new Collection; + } +} \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Controllers/SearchInterface.php b/app/lib/Firefly/Helper/Controllers/SearchInterface.php index 3c0e5b78f2..51b925d146 100644 --- a/app/lib/Firefly/Helper/Controllers/SearchInterface.php +++ b/app/lib/Firefly/Helper/Controllers/SearchInterface.php @@ -18,5 +18,26 @@ interface SearchInterface /** * @param array $words */ - public function transactions(array $words); -} \ No newline at end of file + public function searchTransactions(array $words); + + /** + * @param array $words + */ + public function searchAccounts(array $words); + + /** + * @param array $words + */ + public function searchCategories(array $words); + + /** + * @param array $words + */ + public function searchBudgets(array $words); + + /** + * @param array $words + */ + public function searchTags(array $words); + +} \ No newline at end of file diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php index c44ec99b06..943512aed4 100644 --- a/app/models/LimitRepetition.php +++ b/app/models/LimitRepetition.php @@ -42,7 +42,7 @@ class LimitRepetition extends Ardent /** * How much money is left in this? */ - public function left() + public function leftInRepetition() { $left = floatval($this->amount); diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php index 9bd8ec33b7..3a6e000df9 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -211,6 +211,10 @@ use LaravelBook\Ardent\Builder; * 'Budget[] $budgets * @property-read \Illuminate\Database\Eloquent\Collection|\ * 'Category[] $categories + * @property-read \Illuminate\Database\Eloquent\Collection|\ + * 'Budget[] $budgets + * @property-read \Illuminate\Database\Eloquent\Collection|\ + * 'Category[] $categories */ class TransactionJournal extends Ardent { diff --git a/app/views/budgets/indexByBudget.blade.php b/app/views/budgets/indexByBudget.blade.php index 96bd10c9f8..c4596e92a6 100644 --- a/app/views/budgets/indexByBudget.blade.php +++ b/app/views/budgets/indexByBudget.blade.php @@ -58,14 +58,14 @@ {{mf($rep->amount,false)}}
Bla bla
+ @include('transactions.journals-small-noaccount',['transactions' => $result['transactions']])Bla bla
+Bla bla
Bla bla
+Bla bla
+- | Description | -Date | -Amount | -
---|---|---|---|
- @if($journal->transactiontype->type == 'Withdrawal') - - @endif - @if($journal->transactiontype->type == 'Deposit') - - @endif - @if($journal->transactiontype->type == 'Transfer') - - @endif + @if($journal->transactiontype->type == 'Withdrawal') + + @endif + @if($journal->transactiontype->type == 'Deposit') + + @endif + @if($journal->transactiontype->type == 'Transfer') + + @endif - | -{{{$journal->description}}} | -{{$journal->date->format('jS M Y')}} | -- @foreach($journal->transactions as $t) - @if($t->account_id == $account->id) - {{mf($t->amount)}} - @endif - @endforeach - - | -