I have a service implementation with date filter. I am sending those filters as query parameter. For example: http://localhost:8000/sales_report?start_date=2018-01-01&end_date=2018-01-02
This is the Controller code
public function salesReport(SalesDatatable $dataTable, Request $request)
{
if (!Auth::user()->can('access-sales-report')) {
abort(401);
}
return $dataTable->with([
'start_date' => $request->get('start_date'),
'end_date' => $request->get('end_date'),
])->render('reports.sales_reports.index');
}
This is the Datatables query code
public function query()
{
$query = Invoice::select(DB::raw('GROUP_CONCAT("i_p"."name") AS name'),
DB::raw('GROUP_CONCAT("i_p"."quantity") AS quantity'),
'invoices.id', 'invoices.invoice_no','i_p.invoice_id',
'invoices.created_at', 'invoices.product_price_exclusive_vat as
total_without_vat',
'invoices.card_received', 'invoices.cash_received',
'invoices.total_received', 'invoices.vat_amount',
'invoices.product_discount_amount as discount',
DB::raw('GROUP_CONCAT("product_combinations"."barcode") AS
barcode'), DB::raw('GROUP_CONCAT("i_p"."price") AS price'))
->join(DB::raw('(SELECT "invoice_products"."invoice_id",
"invoice_products"."product_id", "products"."name",
"invoice_products"."quantity",
"product_prices"."price" FROM "invoice_products" JOIN
"products" ON "invoice_products"."product_id" = "products"."id"
JOIN "product_prices" ON "products"."id" =
"product_prices"."product_id") AS i_p'), 'invoices.id', '=',
'i_p.invoice_id')
->join('product_combinations',
'product_combinations.product_id', '=', 'i_p.product_id');
if(!empty($this->request()->get('start_date'))) {
$query->where('invoices.created_at', '>=', $this->start_date);
} else {
$query->where('invoices.created_at', '>=', Carbon::today()->subDays(7)->toDateString());
}
if(!empty($this->request()->get('end_date'))) {
$query->where('invoices.created_at', '<=', $this->end_date);
} else {
$query->where('invoices.created_at', '<=', Carbon::today()->toDateString());
}
$query->groupBy('i_p.invoice_id');
return $query;
}
I am using the buttons like:
public function html()
{
return $this->builder()
->columns($this->getColumns())
->minifiedAjax()
->parameters([
'buttons' => ['excel','print'],
'dom' => 'lftiprB',
'pageLength' => 25
]);
}
The table works fine. Problem is when I export it doesn't consider the query params. It takes the default values. And the problem I found is when I click print the url it redirects to does not contain the query params that exist in the tables view page. Can anyone suggest a fix? Or is there no feature for the laravel-datatables for the thing that I want to do?
- Operating System: Mac Sierra
- PHP 7.1
- Laravel 5.4.*
- Laravel-Datatables 1.0