added multi-select filters everywhere

This commit is contained in:
denisdulici
2018-11-02 11:32:42 +03:00
parent b0a7e98e4e
commit 9a85bb9f5a
25 changed files with 202 additions and 86 deletions

View File

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

View File

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

View File

@ -19,8 +19,8 @@ class Items extends ModelFilter
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);
}
}

View File

@ -19,14 +19,19 @@ class Bills extends ModelFilter
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)

View File

@ -19,19 +19,19 @@ class Payments extends ModelFilter
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)

View File

@ -19,14 +19,19 @@ class Invoices extends ModelFilter
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)

View File

@ -19,19 +19,19 @@ class Revenues extends ModelFilter
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)

View File

@ -19,8 +19,8 @@ class Categories extends ModelFilter
return $this->whereLike('name', $query);
}
public function type($type)
public function types($types)
{
return $this->where('type', $type);
return $this->whereIn('type', (array) $types);
}
}

View File

@ -20,8 +20,7 @@ class Reconciliations extends Controller
{
$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'));
}

View File

@ -25,8 +25,7 @@ class Transactions extends Controller
{
$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)]), '');
@ -34,8 +33,7 @@ class Transactions extends Controller
$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));

View File

@ -26,8 +26,7 @@ class Items extends Controller
{
$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'));
}

View File

@ -47,13 +47,13 @@ class Bills extends Controller
{
$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'));
}
/**

View File

@ -27,14 +27,11 @@ class Payments extends Controller
{
$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();

View File

@ -52,13 +52,13 @@ class Invoices extends Controller
{
$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'));
}
/**

View File

@ -29,14 +29,11 @@ class Revenues extends Controller
{
$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();

View File

@ -25,7 +25,7 @@ class Categories extends Controller
'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'));
}