This commit is contained in:
denisdulici 2017-10-31 00:50:41 +03:00
parent b7f9e8bf63
commit beb78d21ee
3 changed files with 53 additions and 30 deletions

View File

@ -14,8 +14,13 @@ class Transactions extends ModelFilter
*/
public $relations = [];
public function search($query)
public function account($account_id)
{
return $this->whereLike('payment.name', $query)->whereLike('revenue.name', $query);
return $this->where('account_id', $account_id);
}
public function category($category_id)
{
return $this->where('category_id', $category_id);
}
}

View File

@ -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
{
@ -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');
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,
];
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(
@ -75,6 +91,6 @@ class Transactions extends Controller
$transactions = (object) $transactions;
return view('banking.transactions.index', compact('transactions'));
return view('banking.transactions.index', compact('transactions', 'accounts', 'types', 'categories'));
}
}

View File

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