Rapport-Laravel/resources/views/metricreport/report.blade.php

1079 lines
62 KiB
PHP

@extends('layouts.vertical', ["page_title"=> "Dashboard", "mode" => $mode ?? "", "demo" => $demo ?? ""])
@section('css')
<!-- third party css -->
<link href="{{asset('assets/libs/flatpickr/flatpickr.min.css')}}" rel="stylesheet" type="text/css" />
<link href="{{asset('assets/libs/selectize/selectize.min.css')}}" rel="stylesheet" type="text/css" />
<!-- third party css end -->
@endsection
@section('content')
<div id="pageloader">
<img src="{{asset('assets/images/loader-large.gif')}}" alt="processing..." />
</div>
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<h4 class="page-title">Metric Report</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="graph-wrapper">
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="header-title mb-2">{{$graph->name}}</h4>
@php
$showUserAttrs = ($graph->show_user_attributes ?? 'no') === 'yes';
$userAttrs = ($showUserAttrs && isset($graph->user_attributes) && is_array($graph->user_attributes)) ? $graph->user_attributes : [];
$userAttrLabels = $user_attribute_labels ?? [];
@endphp
<div class="row">
<div class="col-6 pt-1">
<p class="text-muted"> {!!$graph->agg_type == 'team' ? '<i class="mdi mdi-account-group" aria-hidden="true"></i>' : '<i class="mdi mdi-account" aria-hidden="true"></i>' !!} {{ucwords($graph->agg_type)}} Report</p>
</div>
<div class="col-6 pt-1">
<p class="text-end" text-muted><i class="mdi mdi-chart-box-plus-outline" aria-hidden="true"></i> {{ucwords($graph->type)}} Metric</p>
</div>
<div class="col-8">
<p class="text-muted"><i class="mdi mdi-calendar" aria-hidden="true"></i> Report Validity: {{$graph->valid_from}} to {{$graph->valid_till}}</p>
</div>
<div class="col-8">
<p class="text-muted"><i class="mdi mdi-calendar" aria-hidden="true"></i> Date Range Selected: {{$graph->first_day}} to {{$graph->last_day}}</p>
</div>
<div class="col-4 text-end">
<button type="button" class="btn btn-info btn-xs" id="refresh-data">Refresh Data</button>
@if((in_array($post['type'], ['trend','leaderboard']) && !in_array($post['chart'], ['line', 'bar']) ) || ($post['type'] == 'graphical' && $graph->type == 'grouped') || ($post['type'] == 'details' && $graph->chart == 'tabular') || ($post['type'] == 'contacts' && $graph->chart == 'contacts') || ($post['type'] == 'scoreboard' && $graph->chart == 'leaderboard') || ($post['type'] == 'incremental' && $graph->chart == 'incremental') )
<button class="btn btn-dark btn-xs" id="export">Export</button>
<button class="btn btn-warning btn-xs" id="email-export">Send me Email</button>
@endif
<button type="button" class="btn btn-success btn-xs" data-bs-toggle="modal" data-bs-target="#metric-filter-modal"><i class="mdi mdi-filter"></i></button>
<div class="modal fade" id="metric-filter-modal" tabindex="-1" aria-labelledby="mySmallModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="mySmallModalLabel">Filter out Metrics</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body text-start">
@foreach($graph->metrics as $val)
<div class="form-check mb-2 form-check-primary">
<input class="form-check-input" type="checkbox" name="metric-filter[]" value="{{$val->metric}}" id="filter-{{$val->metric}}" {{isset($post['metrics']) ? (in_array($val->metric,$post['metrics']) ? 'checked' : '' ): 'checked' }}>
<label class="form-check-label ps-2" for="filter-{{$val->metric}}">{{$val->display}}</label>
</div>
@endforeach
<button type="button" class="btn btn-success btn-xs" id="apply-metric-filter">Apply Filter</button>
<button type="button" class="btn btn-info btn-xs" id="clear-metric-filter">Clear Filter</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</div>
<div class="col-md-8">
<div class="button-list">
@foreach($charts as $chart)
@if(sizeof($chart->charts)>0)
<a href="/metricreport/report?id={{$graph->id}}&type={{$chart->type}}&chart={{$chart->charts[0]}}&period={{$periods[0]->value}}" class="btn {{($chart->type == $post['type']) ? 'btn-soft-warning' : 'btn-soft-blue' }} btn-rounded">{{$chart->name}}</a>
@endif
@endforeach
</div>
</div>
<div class="col-md-4">
<div class="row mb-3">
<label for="period" class="col-3 col-form-label">Period</label>
<div class="col-9">
<select class="form-control" id="period" name="period">
@foreach($periods as $v)
<option value="{{$v->value}}" {{$post['period'] == $v->value ? "selected":""}}>{{$v->label}}</option>
@endforeach
<option value="custom-date" {{$post['period'] == 'custom-date' ? "selected":""}}>Custom Date</option>
</select>
@php
$dates = isset($post['dates'])?explode('--', $post['dates']):["",""];
@endphp
<div class="input-group input-group-sm" id="period-daterange-wrapper">
<input type="text" class="form-control border datetime" id="period-startdate" value="{{ $dates[0] }}">
<input type="text" class="form-control border datetime" id="period-enddate" value="{{ $dates[1] }}">
<span class="input-group-text bg-blue border-blue text-white" id="custom-date-submit">
<i class="mdi mdi-arrow-right-bold"></i>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="button-list">
@foreach($charts as $chart)
@if($chart->type == $post['type'] && sizeof($chart->charts) > 1)
@foreach($chart->charts as $ch)
<a href="/metricreport/report?id={{$graph->id}}&type={{$chart->type}}&chart={{$ch}}&period={{$periods[0]->value}}" class="btn btn-soft-warning btn-rounded">{{ucwords($ch)}}</a>
@endforeach
@endif
@endforeach
</div>
<div class="widget-chart text-center" dir="ltr">
@switch(true)
@case($graph->chart == 'leaderboard')
<div id="cardCollpase4" class="collapse pt-3 show">
@if($graph->agg_type == 'team')
@if(sizeof($breadcrumbs) == 0)
<div class="btn-group mb-2">
<button type="button" class="btn btn-info leaderboard-prev" {{$graph->current_level==$graph->level?'disabled':''}}><i class="mdi mdi-play mdi-rotate-180 mdi-18px"></i></button>
<button type="button" class="btn btn-info">Level {{$graph->current_level}}</button>
<button type="button" class="btn btn-info leaderboard-next" {{$graph->current_level==1?'disabled':''}}><i class="mdi mdi-play mdi-18px"></i></button>
</div>
<div class="btn-group mb-2">
<button type="button" class="btn btn-warning dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> Select Level <i class="mdi mdi-chevron-down"></i> </button>
<div class="dropdown-menu" style="">
@php
$level = $graph->level;
@endphp
@while($level > 0)
<a class="dropdown-item leaderboard-dd-level" href="#" level="{{$level}}">Level {{$level}}</a>
@php
$level--;
@endphp
@endwhile
</div>
</div>
@else
<ol class="breadcrumb m-2">
<li class="breadcrumb-item"><a href="{{url()->current().'?'.http_build_query(request()->except("username", "hid","level"))}}">Your Team</a></li>
@foreach($breadcrumbs as $bc)
<li class="breadcrumb-item"><a href="{{request()->fullUrlWithQuery($bc)}}">{{$bc['username']}}</a></li>
@endforeach
</ol>
@endif
@endif
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0" id="leaderboard-table">
<thead class="table-light">
<tr>
@if($post['type'] == 'leaderboard' && $graph->agg_type == 'team' && $graph->current_level > 1) <th>View Childs</th> @endif
@if($graph->agg_type != 'team' || $post['type'] != 'leaderboard')<th>Rank</th>@endif
<th colspan="2">User</th>
<th>Employee Code</th>
<th>Designation</th>
@foreach($userAttrs as $attr)
<th>{{ $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', $attr)) }}</th>
@endforeach
<th>Zone</th>
<th>Region</th>
<th>Area</th>
<th>Territory</th>
<th>Active User</th>
<!-- @if(count($graph->values) > 0 && isset($graph->values[0]->stats->prescribers) )
<th>Prescribers</th>
@endif -->
@foreach($graph->metrics as $val)
@if(isset($val->is_visible) && $val->is_visible)
<th>{{$val->display}}</th>
@endif
@endforeach
</tr>
</thead>
<tbody>
@php
$leader_id = '';
@endphp
@foreach($graph->values as $i => $val)
@if($leader_id != $val->user->id)
<tr hid="{{isset($val->hierarchy)?$val->hierarchy:''}}" username="{{ isset($val->user->name) ? $val->user->name : '' }}">
@if($post['type'] == 'leaderboard' && $graph->agg_type == 'team' && $graph->current_level > 1)
<td>
<button type="button" class="btn btn-primary btn-childs" title="See Childs" hid="{{isset($val->hierarchy)?$val->hierarchy:''}}" username="{{ isset($val->user->name) ? $val->user->name : '' }}">
<i class="mdi mdi-file-tree text-white"></i>
</button>
</td>
@endif
@if($graph->agg_type != 'team' || $post['type'] != 'leaderboard')
<td><img src="https://ui-avatars.com/api/?background={{$i>3?$colors[4]:$colors[$i]}}&name={{$val->rank}}" class="avatar-md"></td>
@endif
<td><img src="{{isset($val->user->avatar)?$val->user->avatar:'https://ui-avatars.com/api/?background=random&name='.(isset($val->user->name) ? $val->user->name : '')}}" class="avatar-sm rounded-circle"></td>
<td style="text-align:left;">
{{ isset($val->user->name) ? $val->user->name : '' }}
</td>
<td>
{{ isset($val->user->employee_code) ? $val->user->employee_code : '-' }}
</td>
<td>
{{ isset($val->user->designation) ? $val->user->designation : '-' }}
</td>
@foreach($userAttrs as $attr)
<td>{{ $val->user->{$attr} ?? '-' }}</td>
@endforeach
<td>{{ isset($val->user->positions->Zone) ? $val->user->positions->Zone : (isset($val->user->positions->Country) ? $val->user->positions->Country : '-' ) }}</td>
<td>{{ isset($val->user->positions->Region) ? $val->user->positions->Region : '-' }}</td>
<td>{{ isset($val->user->positions->Area) ? $val->user->positions->Area : '-' }}</td>
<td>{{ isset($val->user->positions->Territory) ? $val->user->positions->Territory : '-' }}</td>
@if($graph->type == 'verses')
@foreach($graph->metrics as $m)
@if(isset($m->is_visible) && $m->is_visible)
@php
$statVal = isset($val->stats->{$m->metric}) ? $val->stats->{$m->metric} : (isset($val->stats->{$m->display}) ? $val->stats->{$m->display} : null);
@endphp
<td>{{ $statVal !== null ? $statVal : '-' }}</td>
@endif
@endforeach
@else
<td>{{ isset($val->stats->ucount) ? $val->stats->ucount : '0' }}</td>
<!-- @if(isset($val->stats->prescribers) )
<td>{{ $val->stats->prescribers }}</td>
@endif -->
@foreach($graph->metrics as $m)
@if(isset($m->is_visible) && $m->is_visible)
@php
$statVal = isset($val->stats->{$m->metric}) ? $val->stats->{$m->metric} : (isset($val->stats->{$m->display}) ? $val->stats->{$m->display} : null);
@endphp
<td>{{ $statVal !== null ? $statVal : '-' }}</td>
@endif
@endforeach
@endif
</tr>
@endif
@php
$leader_id = $val->user->id;
@endphp
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($graph->type == 'simple' && $post['type'] == 'trend' && $graph->chart == 'tabular')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Periods</th>
<th>{{$graph->label}}</th>
</tr>
</thead>
<tbody>
@foreach($graph->values as $i => $val)
<tr>
<td>{{$val->x}}</td>
<td>{{$val->y}}</td>
</tr>
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($graph->type == 'grouped' && $post['type'] == 'trend' && $graph->chart == 'tabular')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Periods</th>
@foreach($graph->values as $met)
<th>{{$met->metric}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values[0]->stats as $i => $stat)
<tr>
<td>{{$stat->x}}</td>
@foreach($graph->values as $met)
<td>{{isset($met->stats[$i])?$met->stats[$i]->y:0}}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($post['type'] == 'details' && $graph->chart == 'tabular')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
@if(isset($graph->values->metrics))
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th colspan="2">User</th>
<th>Employee Code</th>
@foreach($userAttrs as $attr)
<th>{{ $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', $attr)) }}</th>
@endforeach
@if(!isset($graph->show_positions) || (isset($graph->show_positions) && $graph->show_positions))
<th>Zone</th>
<th>Region</th>
<th>Area</th>
<th>Territory</th>
@endif
<th>Role</th>
@foreach($graph->values->metrics as $metric)
<th>{{$metric->metric}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values->users as $user)
<tr>
<td><img src="{{isset($user->avatar) ? $user->avatar : 'https://ui-avatars.com/api/?background=random&name='.$user->name}}" class="avatar-sm rounded-circle"></td>
<td>{{ isset($user->name) ? $user->name : '-' }} <br/>{{isset($user->designation) ? $user->designation : '-'}}</td>
<td>{{ isset($user->employee_code) ? $user->employee_code:''}}</td>
@foreach($userAttrs as $attr)
<td>{{ $user->{$attr} ?? '-' }}</td>
@endforeach
@if(!isset($graph->show_positions) || (isset($graph->show_positions) && $graph->show_positions))
<td>{{ isset($user->positions->Zone) ? $user->positions->Zone : '-' }}</td>
<td>{{ isset($user->positions->Region) ? $user->positions->Region : '-' }}</td>
<td>{{ isset($user->positions->Area) ? $user->positions->Area : '-' }}</td>
<td>{{ isset($user->positions->Territory) ? $user->positions->Territory : '-' }}</td>
@endif
<td>{{ isset($user->roles) ? (is_array($user->roles) ? implode(',', $user->roles) : $user->roles) : '-' }}</td>
@foreach($graph->values->metrics as $metric)
<td>{{ isset($metric->stats->{$user->id}) ? $metric->stats->{$user->id} : '-' }}</th>
@endforeach
</tr>
@endforeach
</tbody>
</table>
@endif
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($post['type'] == 'contacts' && $graph->chart == 'contacts')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
@if(isset($graph->values->metrics))
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Doctor</th>
<th>MSL Code</th>
@foreach($graph->contact_attributes as $attr)
<th>{{ $contact_attribute_labels[$attr] ?? ucwords($attr) }}</th>
@endforeach
<th>User</th>
<th>Employee Code</th>
<th>Zone</th>
<th>Region</th>
<th>Area</th>
<th>Territory</th>
@foreach($graph->values->metrics as $metric)
@if(isset($metric->is_visible) && $metric->is_visible)
<th>{{$metric->metric}}</th>
@endif
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values->contacts as $contact)
<tr>
<td>{{ $contact->name }}</td>
<td>{{ $contact->msl_code }}</td>
@foreach($graph->contact_attributes as $attr)
<td>{{ isset($contact->{$attr}) ? $contact->{$attr} : '' }}</td>
@endforeach
@php
$user = isset($graph->values->users->{$contact->id}) ? $graph->values->users->{$contact->id} : false;
@endphp
@if($user)
<td>{{ $user->name }} <br/>{{$user->designation}}</td>
<td>{{ isset($user->employee_code) ? $user->employee_code:''}}</td>
<td>{{ isset($user->positions->Zone) ? $user->positions->Zone : '-' }}</td>
<td>{{ isset($user->positions->Region) ? $user->positions->Region : '-' }}</td>
<td>{{ isset($user->positions->Area) ? $user->positions->Area : '-' }}</td>
<td>{{ isset($user->positions->Territory) ? $user->positions->Territory : '-' }}</td>
@else
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
@endif
@foreach($graph->values->metrics as $metric)
@if(isset($metric->is_visible) && $metric->is_visible)
<td>{{ isset($metric->stats->{$contact->id}) ? $metric->stats->{$contact->id} : '-' }}</td>
@endif
@endforeach
</tr>
@endforeach
</tbody>
</table>
@endif
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($post['type'] == 'trend' && $graph->type == 'verses' && $graph->chart == 'tabular' )
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Periods</th>
<th>Actual</th>
<th>Target</th>
<th>Percent</th>
</tr>
</thead>
<tbody>
@foreach($graph->values[0]->stats as $i => $val)
<tr>
<td>{{$val->x}}</td>
<td>{{$val->actual}}</td>
<td>{{$val->target}}</td>
<td>{{$val->y}}%</td>
</tr>
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@case($post['type'] == 'incremental' && $graph->chart == 'incremental')
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
@if(isset($graph->values->metrics))
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
@php
$period = explode('-', $post['period'])[0];
$interval = 'P1D';
if($period == 'week') {
$interval = 'P1W';
} elseif($period == 'month') {
$interval = 'P1M';
}
$first_day = strtotime($graph->first_day);
$last_day = strtotime($graph->last_day);
$start = new DateTime($graph->first_day);
$end = new DateTime($graph->last_day);
$interval = new DateInterval($interval);
$periods = new DatePeriod($start, $interval, $end);
$colspan = 0;
foreach($periods as $date) {
$colspan++;
}
@endphp
<tr>
<th colspan="2" rowspan="2">User</th>
<th rowspan="2">Employee Code</th>
@if(!isset($graph->show_positions) || (isset($graph->show_positions) && $graph->show_positions))
<th rowspan="2">Zone</th>
<th rowspan="2">Region</th>
<th rowspan="2">Area</th>
<th rowspan="2">Territory</th>
@endif
<th rowspan="2">Role</th>
@foreach($graph->values->metrics as $metric)
<th colspan="{{$colspan}}" style="border-left: 1px solid #ccc;">{{$metric->metric}}</th>
@endforeach
</tr>
<tr>
@foreach($graph->values->metrics as $metric)
@foreach($periods as $date)
<th>{{ $date->format('d M Y') }}</th>
@endforeach
@endforeach
</tr>
</thead>
<tbody>
@foreach($graph->values->users as $user)
<tr>
<td><img src="{{isset($user->avatar) ? $user->avatar : ''}}" class="avatar-sm rounded-circle"></td>
<td>{{ $user->name }} <br/>{{$user->designation}}</td>
<td>{{ isset($user->employee_code) ? $user->employee_code:''}}</td>
@if(!isset($graph->show_positions) || (isset($graph->show_positions) && $graph->show_positions))
<td>{{ isset($user->positions->Zone) ? $user->positions->Zone : '-' }}</td>
<td>{{ isset($user->positions->Region) ? $user->positions->Region : '-' }}</td>
<td>{{ isset($user->positions->Area) ? $user->positions->Area : '-' }}</td>
<td>{{ isset($user->positions->Territory) ? $user->positions->Territory : '-' }}</td>
@endif
<td>{{ isset($user->roles) ? (is_array($user->roles) ? implode(',', $user->roles) : $user->roles) : '-' }}</td>
@foreach($graph->values->metrics as $metric)
@foreach($periods as $date)
<th>{{ isset($metric->stats->{$user->id}->{$date->getTimestamp().'000'}) ? $metric->stats->{$user->id}->{$date->getTimestamp().'000'} : '-' }}</th>
@endforeach
@endforeach
</tr>
@endforeach
</tbody>
</table>
@endif
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@break
@default
<div id="chart-{{$graph->id}}" class="mt-0" data-colors="#f1556c"></div>
@if(($post['type'] == 'value' && $graph->type != 'verses') || ($post['type'] == 'graphical' && $graph->chart = 'percentile' && $graph->type == 'simple' ))
<h5 class="text-muted mt-0">{{ $graph->type == 'simple' ? $graph->label : 'Total ' . $graph->name }}</h5>
<h2>{{$graph->value}}</h2>
@endif
@if(($post['type'] == 'graphical' || $post['type'] == 'value') && $graph->type == 'verses' )
<h5 class="text-muted mt-0">{{ $graph->type == 'simple' ? $graph->label : 'Total ' . $graph->name }}</h5>
<h2>{{$graph->value}} / {{$graph->max}}</h2>
@endif
@if($post['type'] == 'trend' && $graph->type == 'verses' )
<div id="cardCollpase4" class="collapse pt-3 show">
<div class="table-responsive">
<table class="table table-centered table-nowrap table-borderless mb-0">
<thead class="table-light">
<tr>
<th>Periods</th>
<th>Actual</th>
<th>Target</th>
</tr>
</thead>
<tbody>
@foreach($graph->values[0]->stats as $i => $val)
<tr>
<td>{{$val->x}}</td>
<td>{{$val->actual}}</td>
<td>{{$val->target}}</td>
</tr>
@endforeach
</tbody>
</table>
</div> <!-- .table-responsive -->
</div> <!-- end collapse-->
@endif
@break
@endswitch
</div>
</div>
</div> <!-- end card -->
</div> <!-- end col-->
</div>
<!-- end row -->
</div> <!-- container -->
<style type="text/css">
#pageloader {
background: rgba( 255, 255, 255, 0.8 );
display: none;
height: 100%;
position: fixed;
width: 100%;
z-index: 9999;
}
#pageloader img {
left: 50%;
margin-left: -32px;
margin-top: -32px;
position: absolute;
top: 50%;
}
</style>
@endsection
@section('script')
<!-- third party js -->
<script src="{{asset('assets/libs/flatpickr/flatpickr.min.js')}}"></script>
<script src="{{asset('assets/libs/apexcharts/apexcharts.min.js')}}"></script>
<!-- third party js ends -->
<script type="text/javascript">
jQuery(document).ready(function($){
@if($post['period'] != 'custom-date')
$('#period-daterange-wrapper').hide()
@endif
$('#apply-metric-filter').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
var searchIDs = $("#metric-filter-modal input:checkbox:checked").map(function(){
return $(this).val();
}).get();
href.searchParams.set('metrics', searchIDs.join(',') );
window.location.href = href.toString()
})
$('#clear-metric-filter').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.delete('metrics')
window.location.href = href.toString()
})
$('#period').change(function(){
if($(this).val() == 'custom-date') {
$('#period-daterange-wrapper').show()
} else {
$('#period-daterange-wrapper').hide()
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.delete('dates')
href.searchParams.set('period', $(this).val() );
window.location.href = href.toString()
}
});
$('.datetime').flatpickr({
dateFormat: "Y-m-d"
});
$('#period-daterange').flatpickr({
altInput: true,
mode: "range",
altFormat: "F j, y",
defaultDate: 'today'
});
$('#custom-date-submit').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('period', $('#period').val() );
href.searchParams.set('dates', $('#period-startdate').val() + "--" + $('#period-enddate').val() )
window.location.href = href.toString()
})
$('#graph-wrapper .button-list a').click(function(event) {
event.preventDefault();
$("#pageloader").fadeIn();
console.log($(this).attr('href'))
let href = new URL(document.location.origin + $(this).attr('href'));
href.searchParams.delete('refresh')
href.searchParams.set('period', $('#period').val() );
if($('#period').val() == 'custom-date'){
href.searchParams.set('dates', $('#period-startdate').val() + "--" + $('#period-enddate').val() )
}
window.location.href = href.toString()
});
@if($graph->agg_type == 'team')
$('.leaderboard-next').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('level', {{$graph->current_level}}-1 );
window.location.href = href.toString()
})
$('.leaderboard-prev').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('level', {{$graph->current_level}}+1 );
window.location.href = href.toString()
})
$('.leaderboard-dd-level').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('level', $(this).attr('level') );
window.location.href = href.toString()
})
@endif
$('#export').click(function(){
//$("#pageloader").fadeIn();
let href = new URL(window.location.href);
window.location.href = href.origin + '/metricreport/export' + href.search
})
// $('#export').click(function(){
// let href = new URL(window.location.href);
// $('.loader').show()
// $.get( href.origin + '/metricreport/export' + href.search + '&download=1&s3=1', function( data ) {
// console.log(data)
// $('.loader').hide()
// $('#graph-wrapper').prepend('<div class="button-list pe-xl-4 d-grid"><a href="" download class="btn btn--md btn-pink waves-effect waves-light">Download Report</a></div>');
// });
// })
$('#email-export').click(function(){
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
$.get( href.origin + '/metricreport/export' + href.search + '&email=1', function( data ) {
$("#pageloader").fadeOut();
alert( "Email has been sent to your email id." );
});
})
$('#refresh-data').click(function(){
$("#pageloader").fadeIn();
window.location.href = '{!! request()->fullUrlWithQuery(['refresh' => true]) !!}'
})
@if($post['type'] == 'leaderboard' && $graph->agg_type == 'team')
$('#leaderboard-table .btn-childs').click(function(){
console.log( $(this).attr('hid') )
$("#pageloader").fadeIn();
let href = new URL(window.location.href);
href.searchParams.delete('refresh')
href.searchParams.set('level', {{$graph->current_level}}-1 );
href.searchParams.set('hid', $(this).attr('hid') );
href.searchParams.set('username', $(this).attr('username') );
window.location.href = href.toString()
})
@endif
@if($graph->chart != 'leaderboard')
let colors = {!!json_encode($colors)!!};
colors = colors.map(c => '#'+c)
let options = {}
let chart = {}
let values = []
colors.shift()
@if($graph->type == 'grouped' || $graph->type == 'verses')
@switch($post['type'])
@case('graphical')
values = {!!json_encode($graph->values)!!}
@if($post['chart'] == 'pie')
options = {
series: values.map(a => a.value),
chart: {
width: 500,
type: 'pie',
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
labels: values.map(a => a.label),
responsive: [{
breakpoint: 480,
options: {
chart: {
width: 300
},
legend: {
position: 'bottom'
}
}
}]
};
@elseif($post['chart'] == 'bar')
options = {
series: [{
name: "{{$graph->label}}",
data: values.map(a => a.value)
}],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values.map(a => a.label),
}
};
@elseif($graph->type == 'verses' && $post['chart'] == 'progress')
options = {
series: [{{ $graph->max > 0 ? ceil(($graph->value/$graph->max)*100) : 0 }}],
chart: {
height: 250,
type: 'radialBar',
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
plotOptions: {
radialBar: {
startAngle: -90,
endAngle: 270,
hollow: {
size: '58%',
}
},
},
fill: {
type: 'gradient',
gradient: {
shade: 'dark',
shadeIntensity: 0.15,
inverseColors: false,
opacityFrom: 1,
opacityTo: 1,
stops: [0, 50, 65, 91]
},
},
stroke: {
dashArray: 7
},
colors: colors,
labels: ['{{$graph->label}}'],
};
@endif
@break
@case('trend')
values = {!!json_encode($graph->values)!!}
options = {
@if($graph->type == 'verses')
series: [
{
name: 'Actual',
data: values.length > 0 ? values[0].stats.map(a => a.y) : []
},
{
name: 'Target',
data: values.length > 0 ? values[0].stats.map(a => a.target ?? null) : []
}
],
@else
series: values.map(m => {
return {
name: m.metric,
data: m.stats.map(a => a.y)
}
}),
@endif
// series: [{
// name: "{{$graph->label}}",
// data: values.map(a => a.y)
// }],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values[0].stats.map(a => a.x),
}
};
console.log(options)
@break
@endswitch
@elseif($graph->type == 'simple')
@switch($post['type'])
@case('graphical')
options = {
series: [{{ $graph->max > 0 ? ceil(($graph->value/$graph->max)*100) : 0 }}],
chart: {
height: 250,
type: 'radialBar',
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
plotOptions: {
radialBar: {
startAngle: -90,
endAngle: 270,
hollow: {
size: '58%',
}
},
},
fill: {
type: 'gradient',
gradient: {
shade: 'dark',
shadeIntensity: 0.15,
inverseColors: false,
opacityFrom: 1,
opacityTo: 1,
stops: [0, 50, 65, 91]
},
},
stroke: {
dashArray: 7
},
colors: colors,
labels: ['{{$graph->label}}'],
};
@break
@case('trend')
values = {!!json_encode($graph->values)!!}
options = {
series: [{
name: "{{$graph->label}}",
data: values.map(a => a.y)
}],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values.map(a => a.x),
}
};
@break
@endswitch
@elseif($graph->type == 'verses')
@switch($post['type'])
@case('graphical')
options = {
series: [{{ $graph->max > 0 ? ceil(($graph->value/$graph->max)*100) : 0 }}, {{$graph->actual}}, {{$graph->target}}],
chart: {
height: 250,
type: 'radialBar',
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
plotOptions: {
radialBar: {
startAngle: -90,
endAngle: 270,
hollow: {
size: '58%',
}
},
},
fill: {
type: 'gradient',
gradient: {
shade: 'dark',
shadeIntensity: 0.15,
inverseColors: false,
opacityFrom: 1,
opacityTo: 1,
stops: [0, 50, 65, 91]
},
},
stroke: {
dashArray: 7
},
colors: colors,
labels: ['{{$graph->label}}'],
};
@break
@case('trend')
values = {!!json_encode($graph->values)!!}
options = {
series: [{
name: "{{$graph->label}}",
data: values.map(a => a.y)
},{
name: "Actual",
data: values.map(a => a.actual)
},{
name: "Target",
data: values.map(a => a.target)
},],
chart: {
height: 350,
type: '{{$post['chart']}}',
zoom: {
enabled: false
},
animations: {
enabled: true,
easing: 'easeinout',
speed: 2000,
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
grid: {
row: {
colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
opacity: 0.5
},
},
xaxis: {
categories: values.map(a => a.x),
}
};
@break
@endswitch
@endif
chart = new ApexCharts(document.querySelector("#chart-{{$graph->id}}"), options);
chart.render();
@endif
});
</script>
@endsection