Skip to content

Commit

Permalink
fixed #62
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Oct 30, 2017
1 parent b7f9e8b commit beb78d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 32 deletions.
11 changes: 8 additions & 3 deletions app/Filters/Banking/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ class Transactions extends ModelFilter
* @var array
*/
public $relations = [];

public function search($query)

public function account($account_id)
{
return $this->where('account_id', $account_id);
}

public function category($category_id)
{
return $this->whereLike('payment.name', $query)->whereLike('revenue.name', $query);
return $this->where('category_id', $category_id);
}
}
72 changes: 44 additions & 28 deletions app/Http/Controllers/Banking/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Http\Controllers\Banking;

use App\Http\Controllers\Controller;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Expense\Payment;
use App\Models\Income\Revenue;
use App\Models\Setting\Category;

class Transactions extends Controller
{
Expand All @@ -17,37 +19,51 @@ class Transactions extends Controller
*/
public function index()
{
//$transactions = Transaction::index();
$request = request();

$payments = Payment::collect('paid_at');


$transactions = array();

foreach ($payments as $payment) {
$transactions[] = (object)[
'paid_at' => $payment->paid_at,
'account_name' => $payment->account->name,
'type' => trans_choice('general.expenses', 1),
'category_name' => $payment->category->name,
'description' => $payment->description,
'amount' => $payment->amount,
'currency_code' => $payment->currency_code,
];

$accounts = collect(Account::enabled()->pluck('name', 'id'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.accounts', 2)]), '');

$types = collect(['expense' => 'Expense', 'income' => 'Income'])
->prepend(trans('general.all_type', ['type' => trans_choice('general.types', 2)]), '');

$categories = collect(Category::enabled()->type('income')->pluck('name', 'id'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');

$type = $request->get('type');

if ($type != 'income') {
$payments = Payment::collect('paid_at');

foreach ($payments as $payment) {
$transactions[] = (object)[
'paid_at' => $payment->paid_at,
'account_name' => $payment->account->name,
'type' => trans_choice('general.expenses', 1),
'category_name' => $payment->category->name,
'description' => $payment->description,
'amount' => $payment->amount,
'currency_code' => $payment->currency_code,
];
}
}

$revenues = Revenue::collect('paid_at');

foreach ($revenues as $revenue) {
$transactions[] = (object)[
'paid_at' => $revenue->paid_at,
'account_name' => $revenue->account->name,
'type' => trans_choice('general.incomes', 1),
'category_name' => $revenue->category->name,
'description' => $revenue->description,
'amount' => $revenue->amount,
'currency_code' => $revenue->currency_code,
];
if ($type != 'expense') {
$revenues = Revenue::collect('paid_at');

foreach ($revenues as $revenue) {
$transactions[] = (object)[
'paid_at' => $revenue->paid_at,
'account_name' => $revenue->account->name,
'type' => trans_choice('general.incomes', 1),
'category_name' => $revenue->category->name,
'description' => $revenue->description,
'amount' => $revenue->amount,
'currency_code' => $revenue->currency_code,
];
}
}

$special_key = array(
Expand Down Expand Up @@ -75,6 +91,6 @@ public function index()

$transactions = (object) $transactions;

return view('banking.transactions.index', compact('transactions'));
return view('banking.transactions.index', compact('transactions', 'accounts', 'types', 'categories'));
}
}
4 changes: 3 additions & 1 deletion resources/views/banking/transactions/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
{!! Form::open(['url' => 'banking/transactions', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<span class="title-filter hidden-xs">{{ trans('general.search') }}:</span>
{!! Form::text('search', request('search'), ['class' => 'form-control input-filter input-sm', 'placeholder' => trans('general.search_placeholder')]) !!}
{!! Form::select('account', $accounts, request('account'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('type', $types, request('type'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('category', $categories, request('category'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::button('<span class="fa fa-filter"></span> &nbsp;' . trans('general.filter'), ['type' => 'submit', 'class' => 'btn btn-sm btn-default btn-filter']) !!}
</div>
<div class="pull-right">
Expand Down

0 comments on commit beb78d2

Please sign in to comment.