mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various bug fixes.
This commit is contained in:
@@ -184,7 +184,7 @@ class JsonController extends BaseController
|
|||||||
* Build query:
|
* Build query:
|
||||||
*/
|
*/
|
||||||
$query = \TransactionJournal::transactionTypes($parameters['transactionTypes'])->withRelevantData();
|
$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
|
* 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).
|
* "from" account. Then get the amount from one of these (depends on type).
|
||||||
|
@@ -21,20 +21,30 @@ class SearchController extends BaseController
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$subTitle = null;
|
$subTitle = null;
|
||||||
|
$rawQuery = null;
|
||||||
|
$result = [];
|
||||||
if (!is_null(Input::get('q'))) {
|
if (!is_null(Input::get('q'))) {
|
||||||
$rawQuery = trim(Input::get('q'));
|
$rawQuery = trim(Input::get('q'));
|
||||||
$words = explode(' ', $rawQuery);
|
$words = explode(' ', $rawQuery);
|
||||||
$subTitle = 'Results for "' . e($rawQuery) . '"';
|
$subTitle = 'Results for "' . e($rawQuery) . '"';
|
||||||
|
|
||||||
/*
|
$transactions = $this->_helper->searchTransactions($words);
|
||||||
* Search for transactions:
|
$accounts = $this->_helper->searchAccounts($words);
|
||||||
*/
|
$categories = $this->_helper->searchCategories($words);
|
||||||
$result = $this->_helper->transactions($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(
|
return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with(
|
||||||
'mainTitleIcon', 'fa-search'
|
'mainTitleIcon', 'fa-search'
|
||||||
);
|
)->with('query', $rawQuery)->with('result',$result);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
namespace Firefly\Helper\Controllers;
|
namespace Firefly\Helper\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Search
|
* Class Search
|
||||||
*
|
*
|
||||||
@@ -18,26 +20,89 @@ class Search implements SearchInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $words
|
* @param array $words
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function transactions(array $words)
|
public function searchTransactions(array $words)
|
||||||
{
|
{
|
||||||
$query = \TransactionJournal::withRelevantData();
|
return \Auth::user()->transactionjournals()->withRelevantData()->where(
|
||||||
|
|
||||||
$fullCount = $query->count();
|
|
||||||
|
|
||||||
$query->where(
|
|
||||||
function ($q) use ($words) {
|
function ($q) use ($words) {
|
||||||
foreach ($words as $word) {
|
foreach ($words as $word) {
|
||||||
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
|
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
)->get();
|
||||||
$count = $query->count();
|
|
||||||
$set = $query->get();
|
|
||||||
/*
|
|
||||||
* Build something with JSON?
|
|
||||||
*/
|
|
||||||
return $set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,5 +18,26 @@ interface SearchInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $words
|
* @param array $words
|
||||||
*/
|
*/
|
||||||
public function transactions(array $words);
|
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);
|
||||||
|
|
||||||
|
}
|
@@ -42,7 +42,7 @@ class LimitRepetition extends Ardent
|
|||||||
/**
|
/**
|
||||||
* How much money is left in this?
|
* How much money is left in this?
|
||||||
*/
|
*/
|
||||||
public function left()
|
public function leftInRepetition()
|
||||||
{
|
{
|
||||||
$left = floatval($this->amount);
|
$left = floatval($this->amount);
|
||||||
|
|
||||||
|
@@ -211,6 +211,10 @@ use LaravelBook\Ardent\Builder;
|
|||||||
* 'Budget[] $budgets
|
* 'Budget[] $budgets
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
* 'Category[] $categories
|
* 'Category[] $categories
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Budget[] $budgets
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||||
|
* 'Category[] $categories
|
||||||
*/
|
*/
|
||||||
class TransactionJournal extends Ardent
|
class TransactionJournal extends Ardent
|
||||||
{
|
{
|
||||||
|
@@ -58,14 +58,14 @@
|
|||||||
{{mf($rep->amount,false)}}</span>
|
{{mf($rep->amount,false)}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
@if($rep->left < 0)
|
@if($rep->leftInRepetition() < 0)
|
||||||
<span class="label label-danger">
|
<span class="label label-danger">
|
||||||
<span class="glyphicon glyphicon-envelope"></span>
|
<span class="glyphicon glyphicon-envelope"></span>
|
||||||
{{mf($rep->left,false)}}</span>
|
{{mf($rep->leftInRepetition(),false)}}</span>
|
||||||
@else
|
@else
|
||||||
<span class="label label-success">
|
<span class="label label-success">
|
||||||
<span class="glyphicon glyphicon-envelope"></span>
|
<span class="glyphicon glyphicon-envelope"></span>
|
||||||
{{mf($rep->left,false)}}</span>
|
{{mf($rep->leftInRepetition(),false)}}</span>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
|
@@ -77,7 +77,8 @@
|
|||||||
{{$repetition['date']}}
|
{{$repetition['date']}}
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
<small>{{mf($repetition['limit']->amount,false)}} (left: {{mf($repetition['limitrepetition']->left(),false)}})</small>
|
<small>{{mf($repetition['limit']->amount,false)}}
|
||||||
|
(left: {{mf($repetition['limitrepetition']->leftInRepetition(),false)}})</small>
|
||||||
@endif
|
@endif
|
||||||
</h4>
|
</h4>
|
||||||
@if($repetition['paginated'] == true)
|
@if($repetition['paginated'] == true)
|
||||||
|
@@ -1,49 +1,87 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
@if(!is_null($query))
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@if(isset($result['transactions']) && $result['transactions']->count() > 0)
|
||||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-repeat"></i> Transactions
|
<i class="fa fa-repeat"></i> Transactions ({{$result['transactions']->count()}})
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>Bla bla</p>
|
@include('transactions.journals-small-noaccount',['transactions' => $result['transactions']])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@if(isset($result['categories']) && $result['categories']->count() > 0)
|
||||||
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-bar-chart"></i> Categories
|
<i class="fa fa-bar-chart"></i> Categories ({{$result['categories']->count()}})
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>Bla bla</p>
|
<div class="list-group">
|
||||||
|
@foreach($result['categories'] as $category)
|
||||||
|
<a class="list-group-item" title="{{$category->name}}" href="{{route('categories.show',$category->id)}}">
|
||||||
|
{{{$category->name}}}
|
||||||
|
</a>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@if(isset($result['tags']) && $result['tags']->count() > 0)
|
||||||
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-bar-chart"></i> Tags
|
<i class="fa fa-bar-chart"></i> Tags ({{$result['tags']->count()}})
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>Bla bla</p>
|
<p>Bla bla</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
|
@if(isset($result['accounts']) && $result['accounts']->count() > 0)
|
||||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-credit-card"></i> Accounts
|
<i class="fa fa-credit-card"></i> Accounts ({{$result['accounts']->count()}})
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>Bla bla</p>
|
<div class="list-group">
|
||||||
|
@foreach($result['accounts'] as $account)
|
||||||
|
<a class="list-group-item" title="{{$account->name}}" href="{{route('accounts.show',$account->id)}}">
|
||||||
|
{{{$account->name}}}
|
||||||
|
</a>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@if(isset($result['budgets']) && $result['budgets']->count() > 0)
|
||||||
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-tasks"></i> Budgets
|
<i class="fa fa-tasks"></i> Budgets ({{$result['budgets']->count()}})
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>Bla bla</p>
|
<div class="list-group">
|
||||||
|
@foreach($result['budgets'] as $budget)
|
||||||
|
<a class="list-group-item" title="{{$budget->name}}" href="{{route('budgets.show',$budget->id)}}">
|
||||||
|
{{{$budget->name}}}
|
||||||
|
</a>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<!--
|
||||||
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-search-plus"></i> Other results
|
<i class="fa fa-search-plus"></i> Other results
|
||||||
@@ -53,8 +91,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@stop
|
||||||
|
@section('scripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
var query = '{{{$query}}}';
|
||||||
|
</script>
|
||||||
@stop
|
@stop
|
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
<span class="pull-right small">
|
<span class="pull-right small">
|
||||||
@foreach($journal->transactions as $t)
|
@foreach($journal->transactions as $t)
|
||||||
@if($t->account_id == $account->id)
|
@if($t->account_id == $account->id)
|
||||||
{{mf($t->amount)}}
|
{{mf($t->amount)}}
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
|
@@ -1,35 +1,33 @@
|
|||||||
<table class="table table-bordered table-striped table-condensed">
|
<div class="list-group">
|
||||||
<tr>
|
|
||||||
<th><small> </small></th>
|
|
||||||
<th><small>Description</small></th>
|
|
||||||
<th style="min-width:100px;"><small>Date</small></th>
|
|
||||||
<th style="min-width:80px;"><small>Amount</small></th>
|
|
||||||
</tr>
|
|
||||||
@foreach($transactions as $journal)
|
@foreach($transactions as $journal)
|
||||||
<tr>
|
<a class="list-group-item" title="{{$journal->date->format('jS M Y')}}" href="{{route('transactions.show',$journal->id)}}">
|
||||||
|
|
||||||
<td>
|
@if($journal->transactiontype->type == 'Withdrawal')
|
||||||
@if($journal->transactiontype->type == 'Withdrawal')
|
<i class="fa fa-long-arrow-left fa-fw" title="Withdrawal"></i>
|
||||||
<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>
|
@endif
|
||||||
@endif
|
@if($journal->transactiontype->type == 'Deposit')
|
||||||
@if($journal->transactiontype->type == 'Deposit')
|
<i class="fa fa-long-arrow-right fa-fw" title="Deposit"></i>
|
||||||
<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>
|
@endif
|
||||||
@endif
|
@if($journal->transactiontype->type == 'Transfer')
|
||||||
@if($journal->transactiontype->type == 'Transfer')
|
<i class="fa fa-arrows-h fa-fw" title="Transfer"></i>
|
||||||
<span class="glyphicon glyphicon-resize-full" title="Transfer"></span>
|
@endif
|
||||||
@endif
|
|
||||||
|
|
||||||
</td>
|
{{{$journal->description}}}
|
||||||
<td><small><a href="{{route('transactions.show',$journal->id)}}">{{{$journal->description}}}</a></small></td>
|
|
||||||
<td><small>{{$journal->date->format('jS M Y')}}</small></td>
|
<span class="pull-right small">
|
||||||
<td><small>
|
@foreach($journal->transactions as $t)
|
||||||
@foreach($journal->transactions as $t)
|
@if($journal->transactiontype->type == 'Withdrawal' && $t->amount < 0)
|
||||||
@if($t->account_id == $account->id)
|
{{mf($t->amount)}}
|
||||||
{{mf($t->amount)}}
|
@endif
|
||||||
@endif
|
@if($journal->transactiontype->type == 'Deposit' && $t->amount > 0)
|
||||||
@endforeach
|
{{mf($t->amount)}}
|
||||||
</small>
|
@endif
|
||||||
</td>
|
@if($journal->transactiontype->type == 'Transfer' && $t->amount > 0)
|
||||||
</tr>
|
{{mf($t->amount)}}
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</table>
|
</div>
|
@@ -188,7 +188,9 @@ $(function () {
|
|||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
events: {
|
events: {
|
||||||
click: function (e) {
|
click: function (e) {
|
||||||
alert('klik!!');
|
if(e.point.url != null) {
|
||||||
|
window.location = e.point.url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dataLabels: {
|
dataLabels: {
|
||||||
|
Reference in New Issue
Block a user