Skip to content

Commit

Permalink
added multi-select filters everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Nov 2, 2018
1 parent b0a7e98 commit 9a85bb9
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 86 deletions.
4 changes: 2 additions & 2 deletions app/Filters/Banking/Reconciliations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Reconciliations extends ModelFilter
*/
public $relations = [];

public function account($account)
public function accounts($accounts)
{
return $this->where('account_id', $account);
return $this->whereIn('account_id', (array) $accounts);
}
}
8 changes: 4 additions & 4 deletions app/Filters/Banking/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class Transactions extends ModelFilter
*/
public $relations = [];

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

public function category($category_id)
public function categories($categories)
{
// No category for bills/invoices
if (in_array($this->getModel()->getTable(), ['bill_payments', 'invoice_payments'])) {
return $this;
}

return $this->where('category_id', $category_id);
return $this->whereIn('category_id', (array) $categories);
}

public function date($date)
Expand Down
4 changes: 2 additions & 2 deletions app/Filters/Common/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function search($query)
return $this->whereLike('name', $query);
}

public function category($id)
public function categories($ids)
{
return $this->where('category_id', $id);
return $this->whereIn('category_id', (array) $ids);
}
}
13 changes: 9 additions & 4 deletions app/Filters/Expenses/Bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ public function search($query)
return $this->whereLike('vendor_name', $query);
}

public function vendor($vendor)
public function vendors($vendors)
{
return $this->where('vendor_id', $vendor);
return $this->whereIn('vendor_id', (array) $vendors);
}

public function status($status)
public function categories($categories)
{
return $this->where('bill_status_code', $status);
return $this->whereIn('category_id', (array) $categories);
}

public function statuses($statuses)
{
return $this->whereIn('bill_status_code', (array) $statuses);
}

public function billDate($date)
Expand Down
12 changes: 6 additions & 6 deletions app/Filters/Expenses/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public function search($query)
return $this->whereLike('description', $query);
}

public function vendor($vendor)
public function vendors($vendors)
{
return $this->where('vendor_id', $vendor);
return $this->whereIn('vendor_id', (array) $vendors);
}

public function category($category)
public function categories($categories)
{
return $this->where('category_id', $category);
return $this->whereIn('category_id', (array) $categories);
}

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

public function date($date)
Expand Down
13 changes: 9 additions & 4 deletions app/Filters/Incomes/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ public function search($query)
return $this->whereLike('customer_name', $query);
}

public function customer($customer)
public function customers($customers)
{
return $this->where('customer_id', $customer);
return $this->whereIn('customer_id', (array) $customers);
}

public function status($status)
public function categories($categories)
{
return $this->where('invoice_status_code', $status);
return $this->whereIn('category_id', (array) $categories);
}

public function statuses($statuses)
{
return $this->whereIn('invoice_status_code', (array) $statuses);
}

public function invoiceDate($date)
Expand Down
12 changes: 6 additions & 6 deletions app/Filters/Incomes/Revenues.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public function search($query)
return $this->whereLike('description', $query);
}

public function customer($customer)
public function customers($customers)
{
return $this->where('customer_id', $customer);
return $this->whereIn('customer_id', (array) $customers);
}

public function category($category)
public function categories($categories)
{
return $this->where('category_id', $category);
return $this->whereIn('category_id', (array) $categories);
}

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

public function date($date)
Expand Down
4 changes: 2 additions & 2 deletions app/Filters/Settings/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function search($query)
return $this->whereLike('name', $query);
}

public function type($type)
public function types($types)
{
return $this->where('type', $type);
return $this->whereIn('type', (array) $types);
}
}
3 changes: 1 addition & 2 deletions app/Http/Controllers/Banking/Reconciliations.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public function index()
{
$reconciliations = Reconciliation::collect();

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

return view('banking.reconciliations.index', compact('reconciliations', 'accounts'));
}
Expand Down
6 changes: 2 additions & 4 deletions app/Http/Controllers/Banking/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ public function index()
{
$request = request();

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

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

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

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

if ($type != 'income') {
$this->addTransactions(Payment::collect(['paid_at'=> 'desc']), trans_choice('general.expenses', 1));
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Common/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function index()
{
$items = Item::with('category')->collect();

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

return view('common.items.index', compact('items', 'categories'));
}
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Expenses/Bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function index()
{
$bills = Bill::with(['vendor', 'status', 'items', 'payments', 'histories'])->collect(['billed_at'=> 'desc']);

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

$statuses = collect(BillStatus::all()->pluck('name', 'code'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.statuses', 2)]), '');
$categories = collect(Category::enabled()->type('expense')->orderBy('name')->pluck('name', 'id'));

return view('expenses.bills.index', compact('bills', 'vendors', 'statuses'));
$statuses = collect(BillStatus::all()->pluck('name', 'code'));

return view('expenses.bills.index', compact('bills', 'vendors', 'categories', 'statuses'));
}

/**
Expand Down
9 changes: 3 additions & 6 deletions app/Http/Controllers/Expenses/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ public function index()
{
$payments = Payment::with(['vendor', 'account', 'category'])->isNotTransfer()->collect(['paid_at'=> 'desc']);

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

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

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

$transfer_cat_id = Category::transfer();

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Incomes/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public function index()
{
$invoices = Invoice::with(['customer', 'status', 'items', 'payments', 'histories'])->collect(['invoice_number'=> 'desc']);

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

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

return view('incomes.invoices.index', compact('invoices', 'customers', 'status'));
$statuses = collect(InvoiceStatus::all()->pluck('name', 'code'));

return view('incomes.invoices.index', compact('invoices', 'customers', 'categories', 'statuses'));
}

/**
Expand Down
9 changes: 3 additions & 6 deletions app/Http/Controllers/Incomes/Revenues.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ public function index()
{
$revenues = Revenue::with(['account', 'category', 'customer'])->isNotTransfer()->collect(['paid_at'=> 'desc']);

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

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

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

$transfer_cat_id = Category::transfer();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Settings/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function index()
'income' => trans_choice('general.incomes', 1),
'item' => trans_choice('general.items', 1),
'other' => trans_choice('general.others', 1),
])->prepend(trans('general.all_type', ['type' => trans_choice('general.types', 2)]), '');
]);

return view('settings.categories.index', compact('categories', 'types', 'transfer_id'));
}
Expand Down
13 changes: 11 additions & 2 deletions resources/views/banking/reconciliations/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<div class="box box-success">
<div class="box-header with-border">
{!! Form::open(['url' => 'banking/reconciliations', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<div id="items" class="pull-left box-filter">
<span class="title-filter hidden-xs">{{ trans('general.search') }}:</span>
{!! Form::select('account', $accounts, request('account'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('accounts[]', $accounts, request('accounts'), ['id' => 'filter-accounts', 'class' => 'form-control input-filter input-lg', 'multiple' => 'multiple']) !!}
{!! 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 Expand Up @@ -83,3 +83,12 @@
<!-- /.box -->
@endsection

@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$("#filter-accounts").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.accounts', 1)]) }}"
});
});
</script>
@endpush
22 changes: 18 additions & 4 deletions resources/views/banking/transactions/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<div class="box box-success">
<div class="box-header with-border">
{!! Form::open(['url' => 'banking/transactions', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<div id="items" class="pull-left box-filter">
<span class="title-filter hidden-xs">{{ trans('general.search') }}:</span>
{!! 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::dateRange('date', trans('general.date'), 'calendar', []) !!}
{!! Form::select('accounts[]', $accounts, request('accounts'), ['id' => 'filter-accounts', 'class' => 'form-control input-filter input-lg', 'multiple' => 'multiple']) !!}
{!! Form::select('type', $types, request('type'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('categories[]', $categories, request('categories'), ['id' => 'filter-categories', 'class' => 'form-control input-filter input-lg', 'multiple' => 'multiple']) !!}
{!! 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 Expand Up @@ -71,3 +71,17 @@
<link rel="stylesheet" href="{{ asset('vendor/almasaeed2010/adminlte/plugins/daterangepicker/daterangepicker.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/almasaeed2010/adminlte/plugins/datepicker/datepicker3.css') }}">
@endpush

@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$("#filter-accounts").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.accounts', 1)]) }}"
});
$("#filter-categories").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
});
</script>
@endpush
2 changes: 1 addition & 1 deletion resources/views/banking/transfers/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
{!! Form::open(['url' => 'banking/transfers', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<span class="title-filter hidden-xs">{{ trans('general.search') }}:</span>
{!! Form::dateRange('date', trans('general.date'), 'calendar', []) !!}
{!! Form::select('from_account', $accounts, request('from_account'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('to_account', $accounts, request('to_account'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::dateRange('date', trans('general.date'), 'calendar', []) !!}
{!! 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
14 changes: 12 additions & 2 deletions resources/views/common/items/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<div class="box box-success">
<div class="box-header with-border">
{!! Form::open(['route' => 'items.index', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<div id="items" class="pull-left box-filter">
<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('category', $categories, request('category'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('categories[]', $categories, request('categories'), ['id' => 'filter-categories', 'class' => 'form-control input-filter input-lg', 'multiple' => 'multiple']) !!}
{!! 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 Expand Up @@ -98,3 +98,13 @@
</div>
<!-- /.box -->
@endsection

@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$("#filter-categories").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
});
</script>
@endpush

0 comments on commit 9a85bb9

Please sign in to comment.