diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index e591d7c506a9..99edab3c8d3a 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -18,6 +18,7 @@ use App\Models\Invoice; use App\Repositories\BaseRepository; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; +use Yajra\DataTables\Html\Builder; /** * Class InvoiceController @@ -29,16 +30,6 @@ class InvoiceController extends Controller use MakesHash; - - /** - * InvoiceController constructor. - * - */ - public function __construct() - { - - } - /** * Show the list of Invoices * @@ -46,12 +37,38 @@ class InvoiceController extends Controller * * @return \Illuminate\Http\Response */ - public function index(InvoiceFilters $filters) + public function index(InvoiceFilters $filters, Builder $builder) { - // $invoices = Invoice::filter($filters); + if (request()->ajax()) { + + return DataTables::of(Invoice::all()) + ->make(true); + } + + $builder->addAction(); + $builder->addCheckbox(); + + $html = $builder->columns([ + ['data' => 'checkbox', 'name' => 'checkbox', 'title' => '', 'searchable' => false, 'orderable' => false], + ['data' => 'invoice_number', 'name' => 'invoice_number', 'title' => trans('texts.invoice_number'), 'visible'=> true], + // ['data' => 'full_name', 'name' => 'full_name', 'title' => trans('texts.contact'), 'visible'=> true], + // ['data' => 'email', 'name' => 'email', 'title' => trans('texts.email'), 'visible'=> true], + // ['data' => 'created_at', 'name' => 'created_at', 'title' => trans('texts.date_created'), 'visible'=> true], + // ['data' => 'last_login', 'name' => 'last_login', 'title' => trans('texts.last_login'), 'visible'=> true], + // ['data' => 'balance', 'name' => 'balance', 'title' => trans('texts.balance'), 'visible'=> true], + // ['data' => 'action', 'name' => 'action', 'title' => '', 'searchable' => false, 'orderable' => false], + ]); + + $builder->ajax([ + 'url' => route('client.invoices.index'), + 'type' => 'GET', + 'data' => 'function(d) { d.key = "value"; }', + ]); + + $data['html'] = $html; - return view('portal.default.invoices.index'); + return view('portal.default.invoices.index', $data); } diff --git a/composer.json b/composer.json index 8aeee5dd5e75..9dc764e3636e 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,7 @@ "superbalist/laravel-google-cloud-storage": "^2.2", "webpatser/laravel-countries": "dev-master#75992ad", "wildbit/postmark-php": "^2.6", + "yajra/laravel-datatables-html": "^4.0", "yajra/laravel-datatables-oracle": "~9.0" }, "require-dev": { diff --git a/config/datatables.php b/config/datatables.php new file mode 100644 index 000000000000..fbb0e9293139 --- /dev/null +++ b/config/datatables.php @@ -0,0 +1,116 @@ + [ + /* + * Smart search will enclose search keyword with wildcard string "%keyword%". + * SQL: column LIKE "%keyword%" + */ + 'smart' => true, + + /* + * Multi-term search will explode search keyword using spaces resulting into multiple term search. + */ + 'multi_term' => true, + + /* + * Case insensitive will search the keyword in lower case format. + * SQL: LOWER(column) LIKE LOWER(keyword) + */ + 'case_insensitive' => true, + + /* + * Wild card will add "%" in between every characters of the keyword. + * SQL: column LIKE "%k%e%y%w%o%r%d%" + */ + 'use_wildcards' => false, + ], + + /* + * DataTables internal index id response column name. + */ + 'index_column' => 'DT_RowIndex', + + /* + * List of available builders for DataTables. + * This is where you can register your custom dataTables builder. + */ + 'engines' => [ + 'eloquent' => \Yajra\DataTables\EloquentDataTable::class, + 'query' => \Yajra\DataTables\QueryDataTable::class, + 'collection' => \Yajra\DataTables\CollectionDataTable::class, + 'resource' => \Yajra\DataTables\ApiResourceDataTable::class, + ], + + /* + * DataTables accepted builder to engine mapping. + * This is where you can override which engine a builder should use + * Note, only change this if you know what you are doing! + */ + 'builders' => [ + //Illuminate\Database\Eloquent\Relations\Relation::class => 'eloquent', + //Illuminate\Database\Eloquent\Builder::class => 'eloquent', + //Illuminate\Database\Query\Builder::class => 'query', + //Illuminate\Support\Collection::class => 'collection', + ], + + /* + * Nulls last sql pattern for Posgresql & Oracle. + * For MySQL, use '-%s %s' + */ + 'nulls_last_sql' => '%s %s NULLS LAST', + + /* + * User friendly message to be displayed on user if error occurs. + * Possible values: + * null - The exception message will be used on error response. + * 'throw' - Throws a \Yajra\DataTables\Exceptions\Exception. Use your custom error handler if needed. + * 'custom message' - Any friendly message to be displayed to the user. You can also use translation key. + */ + 'error' => env('DATATABLES_ERROR', null), + + /* + * Default columns definition of dataTable utility functions. + */ + 'columns' => [ + /* + * List of columns hidden/removed on json response. + */ + 'excess' => ['rn', 'row_num'], + + /* + * List of columns to be escaped. If set to *, all columns are escape. + * Note: You can set the value to empty array to disable XSS protection. + */ + 'escape' => '*', + + /* + * List of columns that are allowed to display html content. + * Note: Adding columns to list will make us available to XSS attacks. + */ + 'raw' => ['action'], + + /* + * List of columns are are forbidden from being searched/sorted. + */ + 'blacklist' => ['password', 'remember_token'], + + /* + * List of columns that are only allowed fo search/sort. + * If set to *, all columns are allowed. + */ + 'whitelist' => '*', + ], + + /* + * JsonResponse header and options config. + */ + 'json' => [ + 'header' => [], + 'options' => 0, + ], + +]; diff --git a/resources/views/portal/default/invoices/index.blade.php b/resources/views/portal/default/invoices/index.blade.php index bca187a568cc..76b24aafe064 100644 --- a/resources/views/portal/default/invoices/index.blade.php +++ b/resources/views/portal/default/invoices/index.blade.php @@ -3,7 +3,6 @@ @section('header') @parent - @stop @section('body') @@ -13,7 +12,13 @@