Various bug fixes.

This commit is contained in:
James Cole 2014-09-27 06:06:31 +02:00
parent 9ab3679d49
commit 3bbecfe830
12 changed files with 218 additions and 72 deletions

View File

@ -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).

View File

@ -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);
}
}

View File

@ -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();
}
}
/**
* @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;
}
}

View File

@ -18,5 +18,26 @@ interface SearchInterface
/**
* @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);
}

View File

@ -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);

View File

@ -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
{

View File

@ -58,14 +58,14 @@
{{mf($rep->amount,false)}}</span>
</div>
<div class="col-sm-2">
@if($rep->left < 0)
@if($rep->leftInRepetition() < 0)
<span class="label label-danger">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left,false)}}</span>
{{mf($rep->leftInRepetition(),false)}}</span>
@else
<span class="label label-success">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left,false)}}</span>
{{mf($rep->leftInRepetition(),false)}}</span>
@endif
</div>
<div class="col-sm-3">

View File

@ -77,7 +77,8 @@
{{$repetition['date']}}
</a>
</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
</h4>
@if($repetition['paginated'] == true)

View File

@ -1,49 +1,87 @@
@extends('layouts.default')
@section('content')
@if(!is_null($query))
<div class="row">
@if(isset($result['transactions']) && $result['transactions']->count() > 0)
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-repeat"></i> Transactions
<i class="fa fa-repeat"></i> Transactions ({{$result['transactions']->count()}})
</div>
<div class="panel-body">
<p>Bla bla</p>
@include('transactions.journals-small-noaccount',['transactions' => $result['transactions']])
</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-heading">
<i class="fa fa-bar-chart"></i> Categories
<i class="fa fa-bar-chart"></i> Categories ({{$result['categories']->count()}})
</div>
<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>
@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-heading">
<i class="fa fa-bar-chart"></i> Tags
<i class="fa fa-bar-chart"></i> Tags ({{$result['tags']->count()}})
</div>
<div class="panel-body">
<p>Bla bla</p>
</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="panel panel-default">
<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 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>
@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-heading">
<i class="fa fa-tasks"></i> Budgets
<i class="fa fa-tasks"></i> Budgets ({{$result['budgets']->count()}})
</div>
<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>
@endif
<!--
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-search-plus"></i> Other results
@ -53,8 +91,15 @@
</div>
</div>
</div>
-->
</div>
@endif
@stop
@section('scripts')
<script type="text/javascript">
var query = '{{{$query}}}';
</script>
@stop

View File

@ -16,10 +16,10 @@
<span class="pull-right small">
@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
</span>
</a>

View File

@ -1,35 +1,33 @@
<table class="table table-bordered table-striped table-condensed">
<tr>
<th><small>&nbsp;</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>
<div class="list-group">
@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')
<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>
@endif
@if($journal->transactiontype->type == 'Deposit')
<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>
@endif
@if($journal->transactiontype->type == 'Transfer')
<span class="glyphicon glyphicon-resize-full" title="Transfer"></span>
@endif
@if($journal->transactiontype->type == 'Withdrawal')
<i class="fa fa-long-arrow-left fa-fw" title="Withdrawal"></i>
@endif
@if($journal->transactiontype->type == 'Deposit')
<i class="fa fa-long-arrow-right fa-fw" title="Deposit"></i>
@endif
@if($journal->transactiontype->type == 'Transfer')
<i class="fa fa-arrows-h fa-fw" title="Transfer"></i>
@endif
</td>
<td><small><a href="{{route('transactions.show',$journal->id)}}">{{{$journal->description}}}</a></small></td>
<td><small>{{$journal->date->format('jS M Y')}}</small></td>
<td><small>
@foreach($journal->transactions as $t)
@if($t->account_id == $account->id)
{{mf($t->amount)}}
@endif
@endforeach
</small>
</td>
</tr>
{{{$journal->description}}}
<span class="pull-right small">
@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
</span>
</a>
@endforeach
</table>
</div>

View File

@ -188,7 +188,9 @@ $(function () {
cursor: 'pointer',
events: {
click: function (e) {
alert('klik!!');
if(e.point.url != null) {
window.location = e.point.url;
}
}
},
dataLabels: {