From 3bbecfe830d555294c0c8fad1e9d9ee7e8dd3b4e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 27 Sep 2014 06:06:31 +0200 Subject: [PATCH] Various bug fixes. --- app/controllers/JsonController.php | 2 +- app/controllers/SearchController.php | 20 +++- app/lib/Firefly/Helper/Controllers/Search.php | 93 ++++++++++++++++--- .../Helper/Controllers/SearchInterface.php | 25 ++++- app/models/LimitRepetition.php | 2 +- app/models/TransactionJournal.php | 4 + app/views/budgets/indexByBudget.blade.php | 6 +- app/views/budgets/show.blade.php | 3 +- app/views/search/index.blade.php | 63 +++++++++++-- .../journals-small-index.blade.php | 8 +- .../journals-small-noaccount.blade.php | 60 ++++++------ public/assets/javascript/firefly/index.js | 4 +- 12 files changed, 218 insertions(+), 72 deletions(-) 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)}}
- @if($rep->left < 0) + @if($rep->leftInRepetition() < 0) - {{mf($rep->left,false)}} + {{mf($rep->leftInRepetition(),false)}} @else - {{mf($rep->left,false)}} + {{mf($rep->leftInRepetition(),false)}} @endif
diff --git a/app/views/budgets/show.blade.php b/app/views/budgets/show.blade.php index 96ed5af5e6..5be4b68fa6 100644 --- a/app/views/budgets/show.blade.php +++ b/app/views/budgets/show.blade.php @@ -77,7 +77,8 @@ {{$repetition['date']}} - {{mf($repetition['limit']->amount,false)}} (left: {{mf($repetition['limitrepetition']->left(),false)}}) + {{mf($repetition['limit']->amount,false)}} + (left: {{mf($repetition['limitrepetition']->leftInRepetition(),false)}}) @endif @if($repetition['paginated'] == true) diff --git a/app/views/search/index.blade.php b/app/views/search/index.blade.php index 282e6418d8..5ac821defb 100644 --- a/app/views/search/index.blade.php +++ b/app/views/search/index.blade.php @@ -1,49 +1,87 @@ @extends('layouts.default') @section('content') +@if(!is_null($query))
+ @if(isset($result['transactions']) && $result['transactions']->count() > 0)
- Transactions + Transactions ({{$result['transactions']->count()}})
-

Bla bla

+ @include('transactions.journals-small-noaccount',['transactions' => $result['transactions']])
+
+ @endif + @if(isset($result['categories']) && $result['categories']->count() > 0) +
- Categories + Categories ({{$result['categories']->count()}})
-

Bla bla

+
+ @foreach($result['categories'] as $category) + + {{{$category->name}}} + + @endforeach +
+
+ @endif + @if(isset($result['tags']) && $result['tags']->count() > 0) +
- Tags + Tags ({{$result['tags']->count()}})

Bla bla

+ @endif + @if(isset($result['accounts']) && $result['accounts']->count() > 0)
- Accounts + Accounts ({{$result['accounts']->count()}})
-

Bla bla

+
+ @foreach($result['accounts'] as $account) + + {{{$account->name}}} + + @endforeach +
+
+ @endif + @if(isset($result['budgets']) && $result['budgets']->count() > 0) +
- Budgets + Budgets ({{$result['budgets']->count()}})
-

Bla bla

+
+ @foreach($result['budgets'] as $budget) + + {{{$budget->name}}} + + @endforeach +
+
+ @endif +
+@endif +@stop +@section('scripts') + @stop \ No newline at end of file diff --git a/app/views/transactions/journals-small-index.blade.php b/app/views/transactions/journals-small-index.blade.php index ece329cca1..e8e5be5a4f 100644 --- a/app/views/transactions/journals-small-index.blade.php +++ b/app/views/transactions/journals-small-index.blade.php @@ -16,10 +16,10 @@ @foreach($journal->transactions as $t) - @if($t->account_id == $account->id) - {{mf($t->amount)}} - @endif - @endforeach + @if($t->account_id == $account->id) + {{mf($t->amount)}} + @endif + @endforeach diff --git a/app/views/transactions/journals-small-noaccount.blade.php b/app/views/transactions/journals-small-noaccount.blade.php index 39786eb10a..0cb8c04855 100644 --- a/app/views/transactions/journals-small-noaccount.blade.php +++ b/app/views/transactions/journals-small-noaccount.blade.php @@ -1,35 +1,33 @@ - - - - - - - +
@foreach($transactions as $journal) -
+ - - - - - + {{{$journal->description}}} + + + @foreach($journal->transactions as $t) + @if($journal->transactiontype->type == 'Withdrawal' && $t->amount < 0) + {{mf($t->amount)}} + @endif + @if($journal->transactiontype->type == 'Deposit' && $t->amount > 0) + {{mf($t->amount)}} + @endif + @if($journal->transactiontype->type == 'Transfer' && $t->amount > 0) + {{mf($t->amount)}} + @endif + @endforeach + + + @endforeach -
 DescriptionDateAmount
- @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 - -
\ No newline at end of file +
\ No newline at end of file diff --git a/public/assets/javascript/firefly/index.js b/public/assets/javascript/firefly/index.js index 6cf42b88a5..26e245a0e9 100644 --- a/public/assets/javascript/firefly/index.js +++ b/public/assets/javascript/firefly/index.js @@ -188,7 +188,9 @@ $(function () { cursor: 'pointer', events: { click: function (e) { - alert('klik!!'); + if(e.point.url != null) { + window.location = e.point.url; + } } }, dataLabels: {