|
|
@@ -6,18 +6,18 @@ use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
-class DataTablesController extends Controller
|
|
|
+class ReportsController extends Controller
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
- public function dynamicDataTable($datatableName, Request $request)
|
|
|
+ public function dynamicDataTable($reportName, Request $request)
|
|
|
{
|
|
|
// Fetch the DataTable configuration
|
|
|
- $datatableConfig = DB::table('datatables')->where('name', $datatableName)->first();
|
|
|
+ $reportConfig = DB::table('reports')->where('name', $reportName)->first();
|
|
|
|
|
|
- if (!$datatableConfig) {
|
|
|
- return response()->json(['error' => 'DataTable configuration not found'], 404);
|
|
|
+ if (!$reportConfig) {
|
|
|
+ return response()->json(['error' => 'Report configuration not found'], 404);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -26,17 +26,17 @@ class DataTablesController extends Controller
|
|
|
|
|
|
|
|
|
// Start building the query
|
|
|
- $query = DB::table($datatableConfig->base_table);
|
|
|
+ $query = DB::table($reportConfig->base_table);
|
|
|
|
|
|
|
|
|
// Apply columns
|
|
|
- $select_columns = json_decode($datatableConfig->select_columns, true);
|
|
|
+ $select_columns = json_decode($reportConfig->select_columns, true);
|
|
|
foreach ($select_columns as $column) {
|
|
|
$query->selectRaw($column['select_exp']);
|
|
|
}
|
|
|
|
|
|
// Apply joins
|
|
|
- $joins = json_decode($datatableConfig->joins, true);
|
|
|
+ $joins = json_decode($reportConfig->joins, true);
|
|
|
if (!empty($joins)) {
|
|
|
foreach ($joins as $join) {
|
|
|
if (str_contains($join['table'], '(')) { // Detect subquery joins
|
|
|
@@ -49,7 +49,7 @@ class DataTablesController extends Controller
|
|
|
}
|
|
|
|
|
|
// Apply conditions (filters)
|
|
|
- $conditions = json_decode($datatableConfig->conditions, true);
|
|
|
+ $conditions = json_decode($reportConfig->conditions, true);
|
|
|
if (!empty($conditions)) {
|
|
|
foreach ($conditions as $condition) {
|
|
|
if (isset($condition['raw'])) {
|
|
|
@@ -67,8 +67,8 @@ class DataTablesController extends Controller
|
|
|
|
|
|
|
|
|
|
|
|
- $columnHeaders = json_decode($datatableConfig->column_headers, true);
|
|
|
- $columnConfig = json_decode($datatableConfig->columns_config, true);
|
|
|
+ $columnHeaders = json_decode($reportConfig->column_headers, true);
|
|
|
+ $columnConfig = json_decode($reportConfig->columns_config, true);
|
|
|
|
|
|
|
|
|
//Apply search filters
|
|
|
@@ -119,7 +119,7 @@ class DataTablesController extends Controller
|
|
|
}
|
|
|
|
|
|
// Apply sorting
|
|
|
- $sorting = $request->order[0] ?? json_decode($datatableConfig->default_sorting, true)[0];
|
|
|
+ $sorting = $request->order[0] ?? json_decode($reportConfig->default_sorting, true)[0];
|
|
|
|
|
|
$query->orderBy($sorting['name'], $sorting['dir']);
|
|
|
|