Fix product list filter

This commit is contained in:
Hillel Coren 2016-10-18 21:15:08 +03:00
parent ffaea75c01
commit 89088e5517
4 changed files with 15 additions and 4 deletions

View File

@ -71,7 +71,7 @@ class ProductController extends BaseController
*/
public function getDatatable()
{
return $this->productService->getDatatable(Auth::user()->account_id);
return $this->productService->getDatatable(Auth::user()->account_id, Input::get('sSearch'));
}
/**

View File

@ -17,7 +17,7 @@ class ProductRepository extends BaseRepository
->get();
}
public function find($accountId)
public function find($accountId, $filter = null)
{
$query = DB::table('products')
->leftJoin('tax_rates', function($join) {
@ -35,6 +35,13 @@ class ProductRepository extends BaseRepository
'products.deleted_at'
);
if ($filter) {
$query->where(function ($query) use ($filter) {
$query->where('products.product_key', 'like', '%'.$filter.'%')
->orWhere('products.notes', 'like', '%'.$filter.'%');
});
}
if (!\Session::get('show_trash:product')) {
$query->where('products.deleted_at', '=', null);
}

View File

@ -41,10 +41,10 @@ class ProductService extends BaseService
* @param $accountId
* @return \Illuminate\Http\JsonResponse
*/
public function getDatatable($accountId)
public function getDatatable($accountId, $search)
{
$datatable = new ProductDatatable(true);
$query = $this->productRepo->find($accountId);
$query = $this->productRepo->find($accountId, $search);
if(!Utils::hasPermission('view_all')){
$query->where('products.user_id', '=', Auth::user()->id);

View File

@ -83,6 +83,10 @@
if (window.onDatatableReady) {
window.onDatatableReady();
}
},
"stateLoadParams": function (settings, data) {
// don't save filter to local storage
data.search.search = "";
}
});
}