Эх сурвалжийг харах

Stat tree line reports (wip)

Vijayakrishnan 3 жил өмнө
parent
commit
20f08d3ac1

+ 105 - 1
app/Http/Controllers/StatTreeLineController.php

@@ -16,10 +16,26 @@ use Ramsey\Uuid\Uuid;
 
 
 class StatTreeLineController extends Controller
 class StatTreeLineController extends Controller
 {
 {
+    public function reports()
+    {
+        $statTreeLines = StatTreeLine::whereNull('stat_tree_id')->get();
+        return view('app.stat-tree.stat-tree-line-reports.list', compact('statTreeLines'));
+    }
+
+    public function editReport(StatTreeLine $statTreeLine) {
+        $allClauses = Clause::orderByRaw('position_index ASC NULLS FIRST')->get();
+        return view('app.stat-tree.stat-tree-line-reports.edit', compact('statTreeLine', 'allClauses'));
+    }
+
+    public function viewReport(StatTreeLine $statTreeLine) {
+
+    }
+
+
     public function list()
     public function list()
     {
     {
         $statTreeLines = StatTreeLine::all();
         $statTreeLines = StatTreeLine::all();
-        return view('app.stat-tree-lines.list', compact('statTreeLines'));
+        return view('app.stat-tree.stat-tree-lines.list', compact('statTreeLines'));
     }
     }
     public function dashboard(StatTreeLine $statTreeLine)
     public function dashboard(StatTreeLine $statTreeLine)
     {
     {
@@ -321,4 +337,92 @@ class StatTreeLineController extends Controller
         DB::select("delete from stat_tree_line where id = {$statTreeLine->id}");
         DB::select("delete from stat_tree_line where id = {$statTreeLine->id}");
         return $this->pass();
         return $this->pass();
     }
     }
+
+    // eps for reports
+    public function createReport(Request $request) {
+        $statTreeLine = new StatTreeLine();
+        $nextId = DB::select("select nextval('stat_tree_line_id_seq')");
+        $statTreeLine->id = $nextId[0]->nextval;
+        $statTreeLine->uid = Uuid::uuid4();
+        $statTreeLine->title = $request->input('title');
+        $statTreeLine->created_at = date('Y-m-d h:i:s');
+        $statTreeLine->save();
+        return $this->pass();
+    }
+    public function removeReport(Request $request) {
+        $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
+        if(!$statTreeLine) return $this->fail('Stat tree line not found!');
+        // TODO: disallow if this has children
+        DB::select("delete from stat_tree_line where id = {$statTreeLine->id}");
+        return $this->pass();
+    }
+    public function updateTitle(Request $request) {
+        $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
+        if(!$statTreeLine) return $this->fail('Stat tree line not found!');
+        $statTreeLine->title = $request->input('title');
+        $statTreeLine->save();
+        return $this->pass();
+    }
+    public function updateModel(Request $request) {
+        $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
+        if(!$statTreeLine) return $this->fail('Stat tree line not found!');
+        $statTreeLine->model = $request->input('model');
+        $statTreeLine->save();
+        return $this->pass();
+    }
+    public function addExistingClause(Request $request) {
+        $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
+        if(!$statTreeLine) return $this->fail('Stat tree line not found!');
+        $clause = Clause::where('uid', $request->input('clauseUid'))->first();
+        if(!$clause) return $this->fail('Clause not found!');
+
+        $nextStatLineClauseId = DB::select("select nextval('stat_tree_line_clause_id_seq')");
+        $statTreeLineClause = new StatTreeLineClause;
+        $statTreeLineClause->id = $nextStatLineClauseId[0]->nextval;
+        $statTreeLineClause->uid = Uuid::uuid4();
+        $statTreeLineClause->stat_tree_line_id = $statTreeLine->id;
+        $statTreeLineClause->clause_id = $clause->id;
+        $statTreeLineClause->clause_label = $clause->label;
+        $positionIndex = DB::select("select max(position_index) from stat_tree_line_clause where stat_tree_line_id = {$statTreeLine->id}");
+        $statTreeLineClause->position_index = is_numeric($positionIndex[0]->max) ? $positionIndex[0]->max + 1 : 1;
+        $statTreeLineClause->save();
+
+        return $this->pass();
+    }
+    public function addNewClause(Request $request) {
+        $statTreeLine = StatTreeLine::where('uid', $request->input('uid'))->first();
+        if(!$statTreeLine) return $this->fail('Stat tree line not found!');
+
+        $clauseId = DB::select("select nextval('clause_id_seq')");
+        $clause = new Clause();
+        $clause->id = $clauseId[0]->nextval;
+        $clause->uid = Uuid::uuid4();
+        $clause->model = $request->input('model');
+        $clause->question = $request->input('question');
+        $clause->answer = $request->input('answer');
+        $clause->label = $request->input('label');
+        $clause->clause_text = $request->input('clauseText');
+        $positionIndex = DB::select("select max(position_index) from clause");
+        $clause->position_index = is_numeric($positionIndex[0]->max) ? $positionIndex[0]->max + 1 : 1;
+        $clause->save();
+
+        $nextStatLineClauseId = DB::select("select nextval('stat_tree_line_clause_id_seq')");
+        $statTreeLineClause = new StatTreeLineClause;
+        $statTreeLineClause->id = $nextStatLineClauseId[0]->nextval;
+        $statTreeLineClause->uid = Uuid::uuid4();
+        $statTreeLineClause->stat_tree_line_id = $statTreeLine->id;
+        $statTreeLineClause->clause_id = $clause->id;
+        $statTreeLineClause->clause_label = $clause->label;
+        $positionIndex = DB::select("select max(position_index) from stat_tree_line_clause where stat_tree_line_id = {$statTreeLine->id}");
+        $statTreeLineClause->position_index = is_numeric($positionIndex[0]->max) ? $positionIndex[0]->max + 1 : 1;
+        $statTreeLineClause->save();
+
+        return $this->pass();
+    }
+    public function removeClause(Request $request) {
+        $statTreeLineClause = StatTreeLineClause::where('uid', $request->input('uid'))->first();
+        if(!$statTreeLineClause) return $this->fail('Stat tree line not found!');
+        DB::select("delete from stat_tree_line_clause where id = {$statTreeLineClause->id}");
+        return $this->pass();
+    }
 }
 }

+ 5 - 0
public/css/style.css

@@ -416,6 +416,11 @@ body>nav.navbar {
     min-width: unset !important;
     min-width: unset !important;
     max-width: unset !important;
     max-width: unset !important;
 }
 }
+.mcp-theme-1 .width-500px {
+    width: 500px;
+    min-width: unset !important;
+    max-width: unset !important;
+}
 .mcp-theme-1 .width-100pc {
 .mcp-theme-1 .width-100pc {
     width: 100% !important;
     width: 100% !important;
     min-width: unset !important;
     min-width: unset !important;

+ 154 - 0
resources/views/app/stat-tree/stat-tree-line-reports/edit.blade.php

@@ -0,0 +1,154 @@
+@extends ('layouts/template')
+@section('content')
+
+<div class="mcp-theme-1 body-height d-flex flex-column" id="stat-tree-line-report-edit-{{$statTreeLine->uid}}">
+    <div class="d-flex align-items-baseline p-3 border-bottom">
+        <h5 class="m-0 font-size-16">{{$statTreeLine->title}}</h5>
+        <div moe wide class="ml-3">
+            <a href="#" start show class="">Edit Title</a>
+            <form url="{{ route("practice-management.api.statTreeLineReport.updateTitle") }}">
+                @csrf
+                <input type="hidden" name="uid" value="{{$statTreeLine->uid}}">
+                <div class="mb-2">
+                    <label class="mb-1 text-secondary text-sm">Report Title *</label>
+                    <input type="text" name="title" class="form-control form-control-sm" required value="{{$statTreeLine->title}}">
+                </div>
+                <div class="d-flex align-items-center">
+                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                </div>
+            </form>
+        </div>
+    </div>
+    <div class="row mx-0 flex-grow-1">
+        <div class="col-5 px-0 border-right">
+            <div class="p-3 border-bottom">
+                <div class="d-flex align-items-baseline">
+                    <span class="font-weight-bold text-secondary">Model</span>
+                    <div moe wide class="ml-3">
+                        <a href="#" start show class="">Edit</a>
+                        <form url="{{ route("practice-management.api.statTreeLineReport.updateModel") }}">
+                            @csrf
+                            <input type="hidden" name="uid" value="{{$statTreeLine->uid}}">
+                            <div class="mb-2">
+                                <label class="mb-1 text-secondary text-sm">Report Model *</label>
+                                <input type="text" name="model" class="form-control form-control-sm" required value="{{$statTreeLine->model}}">
+                            </div>
+                            <div class="d-flex align-items-center">
+                                <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+                <div class="mt-2 text-info font-weight-bold border p-2">{{$statTreeLine->model}}</div>
+            </div>
+            <div class="p-3">
+                <div class="d-flex align-items-baseline">
+                    <span class="font-weight-bold text-secondary mr-3">Clauses</span>
+                    <div moe>
+                        <a start show href="#">Add Existing</a>
+                        <form url="{{ route("practice-management.api.statTreeLineReport.addExistingClause") }}">
+                            @csrf
+                            <input type="hidden" name="uid" value="{{$statTreeLine->uid}}">
+                            <div class="mb-2">
+                                <label class="mb-1 text-secondary text-sm">Clause *</label>
+                                <select name="clauseUid" class="form-control form-control-sm" required>
+                                    <option value="">-- select --</option>
+                                    @foreach($allClauses as $clause)
+                                        <option value="{{$clause->uid}}">{{$clause->label}} ({{$clause->model}})</option>
+                                    @endforeach
+                                </select>
+                            </div>
+                            <div class="d-flex align-items-center">
+                                <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                            </div>
+                        </form>
+                    </div>
+                    <span class="mx-2 text-sm text-secondary">|</span>
+                    <div moe wide>
+                        <a href="#" start show>Add New</a>
+                        <form url="{{ route("practice-management.api.statTreeLineReport.addNewClause") }}" class="frm-clause-add-edit">
+                            @csrf
+                            <input type="hidden" name="uid" value="{{$statTreeLine->uid}}">
+                            <div class="mb-2">
+                                <label class="text-secondary text-sm mb-1">Model</label>
+                                <input type="text" class="form-control form-control-sm" name="model" readonly value="{{$statTreeLine->model}}">
+                            </div>
+                            <div class="mb-2">
+                                <label class="text-secondary text-sm mb-1">Question</label>
+                                <input type="text" class="form-control form-control-sm" name="question" autofocus>
+                            </div>
+                            <div class="mb-2">
+                                <label class="text-secondary text-sm mb-1">Answer</label>
+                                <input type="text" class="form-control form-control-sm" name="answer">
+                            </div>
+                            <div class="mb-2">
+                                <label class="text-secondary text-sm mb-1">Label</label>
+                                <input type="text" class="form-control form-control-sm" name="label" readonly>
+                            </div>
+                            <div class="mb-2">
+                                <label class="text-secondary text-sm mb-1">Clause Text *</label>
+                                <textarea type="text" class="form-control form-control-sm" required name="clauseText"></textarea>
+                            </div>
+                            <div class="d-flex align-items-center">
+                                <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
+                                <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+                @if(count($statTreeLine->lineClauses))
+                    <table class="table table-sm table-bordered mt-2">
+                    @foreach($statTreeLine->lineClauses as $lineClause)
+                        <tr>
+                            <td class="width-30px">{{$lineClause->position_index}}</td>
+                            <td class="text-nowrap text-info font-weight-bold">{{$lineClause->clause_label}}</td>
+                            <td class="text-monospace">{{$lineClause->clause->clause_text}}</td>
+                            <td class="width-100px">
+                                <div moe>
+                                    <a start show href="#" class="text-danger on-hover-opaque">Remove</a>
+                                    <form url="{{ route("practice-management.api.statTreeLineReport.removeClause") }}">
+                                        @csrf
+                                        <input type="hidden" name="uid" value="{{$lineClause->uid}}">
+                                        <p class="mb-2 text-nowrap">Are you sure?</p>
+                                        <div class="d-flex align-items-center">
+                                            <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            </td>
+                        </tr>
+                    @endforeach
+                    </table>
+                @endif
+            </div>
+        </div>
+        <div class="col-7 px-0">
+            <div class="p-3">
+                <div class="d-flex align-items-baseline">
+                    <span class="font-weight-bold text-secondary mr-3">Report columns</span>
+                    <a>Add New</a>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    (function() {
+        function init() {
+            $(document)
+                .off('input change paste', '.frm-clause-add-edit input[name="question"], .frm-clause-add-edit input[name="answer"]')
+                .on('input change paste', '.frm-clause-add-edit input[name="question"], .frm-clause-add-edit input[name="answer"]', function() {
+                    let form = $(this).closest('.frm-clause-add-edit');
+                    let label = $.trim(form.find('input[name="question"]').val()) + ' ' +
+                        $.trim(form.find('input[name="answer"]').val());
+                    form.find('input[name="label"]').val(label);
+                });
+        }
+        addMCInitializer('stat-tree-line-report-edit-{{$statTreeLine->uid}}', init, '#stat-tree-line-report-edit-{{$statTreeLine->uid}}');
+    }).call(window);
+</script>
+@endsection

+ 55 - 0
resources/views/app/stat-tree/stat-tree-line-reports/line-properties.blade.php

@@ -0,0 +1,55 @@
+<div id="line-properties-column" class="d-none">
+
+    <div class="d-flex align-items-baseline mb-2">
+        <h6 class="font-weight-bold m-0">Argument Values</h6>
+    </div>
+    <div>
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0 w-35">Arg</th>
+                <th class="border-bottom-0 w-35">Value</th>
+                <th class="border-bottom-0">Access</th>
+            </tr>
+            </thead>
+            <tbody line-args>
+            </tbody>
+        </table>
+    </div>
+
+    <div class="d-flex align-items-baseline mb-2">
+        <h6 class="font-weight-bold m-0">Report Columns</h6>
+    </div>
+    <div>
+        <div class="mb-2 d-flex align-items-baseline">
+            <span class="text-secondary mr-1">Node:</span>
+            <span line-label></span>
+        </div>
+        <div class="mb-2 d-flex align-items-baseline">
+            <span class="text-secondary mr-1 text-nowrap">Quick Add:</span>
+            <div class="flex-grow-1 position-relative">
+                <input type="text"
+                       name="displayKey"
+                       class="form-control form-control-sm"
+                       placeholder="Column name"
+                       stag-suggest stag-suggest-left
+                       stag-suggest-ep="/column-suggest"
+                       stag-suggest-extra="table={{$statTree->model}}"
+                       autocomplete="donotdoit">
+            </div>
+        </div>
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0 width-30px">#</th>
+                <th class="border-bottom-0 w-35">Label</th>
+                <th class="border-bottom-0">Column</th>
+                <th class="border-bottom-0 width-60px"></th>
+            </tr>
+            </thead>
+            <tbody line-columns>
+            </tbody>
+        </table>
+    </div>
+
+</div>

+ 65 - 0
resources/views/app/stat-tree/stat-tree-line-reports/list.blade.php

@@ -0,0 +1,65 @@
+@extends ('layouts/template')
+@section('content')
+
+<div class="mcp-theme-1 p-3">
+    <div class="d-flex align-items-end mb-3">
+        <h5 class="m-0 font-size-16">Stat Tree Line Reports</h5>
+        <div moe wide class="ml-4">
+            <a href="#" start show class="btn btn-sm btn-primary text-white">Create Report</a>
+            <form url="{{ route("practice-management.api.statTreeLineReport.create") }}">
+                @csrf
+                <div class="mb-2">
+                    <label class="mb-1 text-secondary text-sm">Report Title *</label>
+                    <input type="text" name="title" class="form-control form-control-sm" required>
+                </div>
+                <div class="d-flex align-items-center">
+                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                </div>
+            </form>
+        </div>
+    </div>
+    <div class="table-responsive">
+        <table class="table table-sm table-bordered border-bottom">
+            <thead>
+            <tr class="bg-light">
+                <th class="border-bottom-0 text-secondary width-200px">Created</th>
+                <th class="border-bottom-0 text-secondary width-500px">Title</th>
+                <th class="border-bottom-0 text-secondary width-100px">Count</th>
+                <th class="border-bottom-0 text-secondary"></th>
+            </tr>
+            </thead>
+            @if(!count($statTreeLines))
+                <tr>
+                    <td colspan="4" class="p-3 text-secondary">No stat tree line reports yet!</td>
+                </tr>
+            @endif
+            @foreach($statTreeLines as $line)
+                <tr>
+                    <td>{{ friendly_date_time($line->created_at) }}</a></td>
+                    <td><a href="#">{{ $line->title }}</a></td>
+                    <td> - </td>
+                    <td>
+                        <div class="d-flex align-items-center flex-nowrap">
+                            <a href="{{ route("practice-management.statTreeLineReports.edit", ['statTreeLine' => $line]) }}">Edit</a>
+                            <span class="mx-2 text-secondary text-sm">|</span>
+                            <div moe>
+                                <a href="#" start show>Delete</a>
+                                <form url="{{ route("practice-management.api.statTreeLineReport.remove") }}">
+                                    @csrf
+                                    <input type="hidden" name="uid" value="{{$line->uid}}">
+                                    <p class="mb-2">Remove this report?</p>
+                                    <div class="d-flex align-items-center">
+                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        </div>
+                    </td>
+                </tr>
+            @endforeach
+        </table>
+    </div>
+</div>
+@endsection

+ 38 - 0
resources/views/app/stat-tree/stat-tree-line-reports/single.blade.php

@@ -0,0 +1,38 @@
+@extends ('layouts/template')
+@section('content')
+    <div class="p-3 mcp-theme-1">
+        <div class="card">
+            <div class="card-header">
+                <div class="d-flex align-items-center justify-content-between">
+                    <div class="d-flex align-items-center">
+                        <div class="mr-3">
+                            <span>Tree Name:</span>
+                            <span class="font-weight-bold">{{ $statTreeLine->statTree->name }}</span>
+                        </div>
+                        <div class="mr-3">
+                            <span>Tree Model:</span>
+                            <span class="font-weight-bold">{{ $statTreeLine->statTree->model }}</span>
+                        </div>
+                        <div class="mr-3">
+                            <span>Tree Slug:</span>
+                            <span class="font-weight-bold">{{ $statTreeLine->statTree->slug }}</span>
+                        </div>
+                    </div>
+                    <div>
+                        <a href="{{ route('practice-management.statTrees.view.dashboard', $statTreeLine->statTree) }}" class="btn btn-sm btn-primary text-white"><i class="fas fa-network-wired"></i> View Tree</a>
+                    </div>
+                </div>
+            </div>
+            <div class="card-body">
+                <div class="border p-3 mb-3">
+                <span> SELECT COUNT(*) FROM {{ $statTreeLine->statTree->model }} WHERE
+                            @foreach($statTreeLine->lineClauses as $c)
+                            {{ $c->clause->clause_text ?? '' }} @if(!$loop->last) AND @endif
+                            @endforeach</span>
+                </div>
+                <?php dump($response); ?>
+            </div>
+        </div>
+    </div>
+
+@endsection

+ 178 - 0
resources/views/app/stat-tree/stat-tree-line-reports/view-data.blade.php

@@ -0,0 +1,178 @@
+<div class="mcp-theme-1 popup-content-container p-3">
+    @if(@$rows === 'error')
+        <div class="text-secondary">
+            <i class="fa fa-exclamation-triangle"></i>
+            Query error / missing arg values!
+        </div>
+    @else
+        @if(!count($columns))
+            <div class="text-secondary">
+                <i class="fa fa-exclamation-triangle"></i>
+                Report columns not configured for this report!
+            </div>
+        @else
+            <div class="mb-2 d-flex flex-wrap">
+                @foreach($line->lineClauses as $lineClause)
+                    <div class="border rounded px-2 py-1 mr-2 bg-light clause-label-part">{{$lineClause->clause_label}}
+                        @if(count($lineClause->lineClauseArgs))
+                            <?php
+                            $argsLabel = [];
+                            foreach($lineClause->lineClauseArgs as $lineClauseArg) {
+                                $argLabel = $lineClauseArg->clauseArg->arg_text . ': ' . $lineClauseArg->value;
+                                $argsLabel[] = $argLabel;
+                            }
+                            ?>
+                            [{{implode(', ', $argsLabel)}}]
+                        @endif
+                    </div>
+                @endforeach
+            </div>
+
+            <!-- filters -->
+            <a href="#" class="toggle-filters" onclick="$('#view-data-filters-form').toggle(); return false;">Toggle Filter</a>
+            <form action="" id="view-data-filters-form">
+                <input type="hidden" name="sort_by" value="{{request()->input('sort_by')}}">
+                <input type="hidden" name="sort_dir" value="{{request()->input('sort_dir')}}">
+                <table class="table table-sm table-striped table-bordered mb-0 mt-2 bg-aliceblue">
+                    <thead>
+                        <?php $lastColumnRendered = false; ?>
+                        @foreach($columns as $column)
+                            <tr>
+                                <th class="border-bottom-0 width-150px font-weight-normal text-nowrap {{request()->input($column['as'] . '_op') ? 'font-weight-bold text-info' : ''}}">{{$column['label']}}</th>
+
+                                <th class="border-bottom-0 width-150px p-0">
+                                    <select class="form-control form-control-sm min-width-unset border-0 rounded-0 shadow-none" name="{{$column['as']}}_op">
+                                        <option value="">-- select --</option>
+                                        <?php
+                                        switch($column['type']) {
+                                            case 'integer':
+                                            case 'bigint':
+                                            case 'decimal':
+                                                ?>
+                                                <option {{request()->input($column['as'] . '_op') === '=' ? 'selected' : ''}} value="=">Equal</option>
+                                                <option {{request()->input($column['as'] . '_op') === '!=' ? 'selected' : ''}} value="!=">Not equal</option>
+                                                <option {{request()->input($column['as'] . '_op') === '<' ? 'selected' : ''}} value="<">Lesser than</option>
+                                                <option {{request()->input($column['as'] . '_op') === '<=' ? 'selected' : ''}} value="<=">Lesser than or equal to</option>
+                                                <option {{request()->input($column['as'] . '_op') === '>' ? 'selected' : ''}} value=">">Greater than</option>
+                                                <option {{request()->input($column['as'] . '_op') === '>=' ? 'selected' : ''}} value=">=">Greater than or equal to</option>
+                                                <?php
+                                                break;
+                                            case 'string':
+                                            case 'text':
+                                            case 'varchar':
+                                                ?>
+                                                <option {{request()->input($column['as'] . '_op') === '=' ? 'selected' : ''}} value="=">Is</option>
+                                                <option {{request()->input($column['as'] . '_op') === '!=' ? 'selected' : ''}} value="!=">Is Not</option>
+                                                <option {{request()->input($column['as'] . '_op') === 'ILIKE' ? 'selected' : ''}} value="ILIKE">Contains</option>
+                                                <option {{request()->input($column['as'] . '_op') === 'NOT ILIKE' ? 'selected' : ''}} value="NOT ILIKE">Does not contain</option>
+                                                <?php
+                                                break;
+                                            case 'bool':
+                                            case 'boolean':
+                                                ?>
+                                                <option {{request()->input($column['as'] . '_op') === '=' ? 'selected' : ''}} value="=">Is</option>
+                                                <?php
+                                                break;
+                                            case 'date':
+                                            case 'datetime':
+                                                ?>
+                                                <option {{request()->input($column['as'] . '_op') === '=' ? 'selected' : ''}} value="=">Start/End</option>
+                                                <?php
+                                                break;
+                                        }
+                                        ?>
+                                    </select>
+                                </th>
+
+                                <th class="border-bottom-0 p-0">
+                                    <div class="d-flex align-items-center">
+                                    <?php
+                                    switch($column['type']) {
+                                        case 'integer':
+                                        case 'bigint':
+                                        case 'decimal':
+                                            ?>
+                                            <input type="number" name="{{$column['as']}}_value" value="{{request()->input($column['as'] . '_value')}}" class="min-width-unset shadow-none form-control form-control-sm border-0 rounded-0">
+                                            <?php
+                                            break;
+                                        case 'string':
+                                        case 'text':
+                                        case 'varchar':
+                                            ?>
+                                            <input type="text" name="{{$column['as']}}_value" value="{{request()->input($column['as'] . '_value')}}" class="min-width-unset shadow-none form-control form-control-sm border-0 rounded-0">
+                                            <?php
+                                            break;
+                                        case 'bool':
+                                        case 'boolean':
+                                            ?>
+                                            <select class="form-control form-control-sm min-width-unset shadow-none border-0 rounded-0" name="{{$column['as']}}_value">
+                                                <option {{request()->input($column['as'] . '_value') === 'TRUE' ? 'selected' : ''}} value="TRUE">True</option>
+                                                <option {{request()->input($column['as'] . '_value') === 'FALSE' ? 'selected' : ''}} value="FALSE">False</option>
+                                            </select>
+                                            <?php
+                                            break;
+                                        case 'date':
+                                        case 'datetime':
+                                            ?>
+                                            <input type="date" name="{{$column['as']}}_value_start" value="{{request()->input($column['as'] . '_value_start')}}" class="min-width-unset shadow-none width-200px form-control form-control-sm border-0 rounded-0" placeholder="Start">
+                                            <input type="date" name="{{$column['as']}}_value_end" value="{{request()->input($column['as'] . '_value_end')}}" class="min-width-unset shadow-none width-200px form-control form-control-sm border-top-0 border-bottom-0 rounded-0" placeholder="End">
+                                            <?php
+                                            break;
+                                    }
+                                    ?>
+                                    </div>
+                                </th>
+
+                                @if(!$lastColumnRendered)
+                                    <th class="border-bottom-0 width-200px align-top bg-white" rowspan="{{count($columns)}}">
+                                        <div class="d-flex align-items-center">
+                                            <button class="btn btn-sm btn-primary mr-2"
+                                                    onclick="return refreshDynamicStagPopup('{{route('practice-management.statTreeLines.view-data', compact('line'))}}?' + $('#view-data-filters-form').serialize())">
+                                                Filter
+                                            </button>
+                                            <button class="btn btn-sm btn-default border"
+                                                    onclick="$('#view-data-filters-form table').find('input, select').val(''); return refreshDynamicStagPopup('{{route('practice-management.statTreeLines.view-data', compact('line'))}}?' + $('#view-data-filters-form').serialize())">
+                                                Reset
+                                            </button>
+                                        </div>
+                                    </th>
+                                    <?php $lastColumnRendered = true; ?>
+                                @endif
+                            </tr>
+                        @endforeach
+                    </thead>
+                </table>
+            </form>
+
+            <table class="table table-sm table-striped table-bordered mt-3">
+                <thead>
+                <tr>
+                    @foreach($columns as $column)
+                    <th class="border-bottom-0 text-left">
+                        @include('app.stat-tree._sort_header', ['route' => route('practice-management.statTreeLines.view-data', compact('line')), 'label' => $column['label'], 'key' => $column['as']])
+                    </th>
+                    @endforeach
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($rows as $row)
+                    <tr>
+                        @foreach($columns as $column)
+                            <td>
+                                @if($column['type'] === 'date')
+                                    {{friendly_date($row->{$column['as']})}}
+                                @elseif($column['type'] === 'datetime')
+                                    {{friendly_date_time($row->{$column['as']})}}
+                                @else
+                                    {{ $row->{$column['as']} }}
+                                @endif
+                            </td>
+                        @endforeach
+                    </tr>
+                @endforeach
+                </tbody>
+            </table>
+            {!! $paginator->withQueryString()->links() !!}
+        @endif
+    @endif
+</div>

+ 19 - 0
routes/web.php

@@ -358,6 +358,12 @@ Route::middleware('pro.auth')->group(function () {
             Route::get('view-data/{line}', 'StatTreeLineController@viewData')->name('view-data');
             Route::get('view-data/{line}', 'StatTreeLineController@viewData')->name('view-data');
         });
         });
 
 
+        Route::name('statTreeLineReports.')->prefix('stat-tree-line-reports/')->group(function () {
+            Route::get('', 'StatTreeLineController@reports')->name('reports');
+            Route::get('edit/{statTreeLine}', 'StatTreeLineController@editReport')->name('edit');
+            Route::get('view/{statTreeLine}', 'StatTreeLineController@viewReport')->name('view');
+        });
+
 
 
         // APIs
         // APIs
         Route::name('api.')->group(function () {
         Route::name('api.')->group(function () {
@@ -402,6 +408,19 @@ Route::middleware('pro.auth')->group(function () {
                 Route::post('update', 'StatTreeLineReportColumnController@update')->name('update');
                 Route::post('update', 'StatTreeLineReportColumnController@update')->name('update');
                 Route::post('remove', 'StatTreeLineReportColumnController@remove')->name('remove');
                 Route::post('remove', 'StatTreeLineReportColumnController@remove')->name('remove');
             });
             });
+
+            //Stat Tree Line Reports
+            Route::name('statTreeLineReport.')->prefix('stat-tree-line-report/')->group(function () {
+                Route::post('refresh-count-query', 'StatTreeLineController@refreshCountQuery')->name('refreshCountQuery');
+                Route::post('create', 'StatTreeLineController@createReport')->name('create');
+                Route::post('remove', 'StatTreeLineController@removeReport')->name('remove');
+                Route::post('updateTitle', 'StatTreeLineController@updateTitle')->name('updateTitle');
+                Route::post('updateModel', 'StatTreeLineController@updateModel')->name('updateModel');
+                Route::post('addExistingClause', 'StatTreeLineController@addExistingClause')->name('addExistingClause');
+                Route::post('addNewClause', 'StatTreeLineController@addNewClause')->name('addNewClause');
+                Route::post('removeClause', 'StatTreeLineController@removeClause')->name('removeClause');
+
+            });
         });
         });
 
 
     });
     });